/**
 * => Mootools 1.2
 * 	=> Core
 * @classDescription
 * Classe qui vérifie si l'utilisateur choisit bien par lui même le type de produit
 * @author M@nu/Baphira
 */
var AttributesChecker = new Class({
	/**
	 * Constructor
	 * @param {String} attributesClass la "class" de(s) la/les liste(s) d'es attributs
	 * @param {String} errMsg
	 * @param {String} errSep
	 */
	initialize: function(attributesClass, errMsg, errSep){
		this.attributes = $$('.'+attributesClass);
		this.attributesClass = attributesClass;
		this.errMsg = errMsg;
		this.errSep = errSep;
		
		this.addEmptyLine();
    },
	
	addEmptyLine: function() {
		for(var i = 0; i < this.attributes.length; i++) {
			var title = this.attributes[i].getProperty('title');
			if($chk(title) && title.trim().length > 0) {
				var newLine = new Element('option', {'value':'-1'});
				newLine.set('text', title);
				newLine.inject(this.attributes[i], 'top');
				this.attributes[i].selectedIndex = 0;
			}
		}
	},
	
	check: function(form){
		var attributes = this.getAttributes(form);
		var strErr = '';
		for (var j = 0; j < attributes.length; j++) {
			if (attributes[j].get('value') == "-1" && !attributes[j].hasClass('notMandatory')) {
				strErr += '\n' + this.errSep + $$('label[for=' + attributes[j].id + ']')[0].get('text');
			}
		}
		return strErr == ''? '' : this.errMsg + strErr;
	},
	
	getAttributes: function(form){
		return form.getElements('.'+this.attributesClass);
	}
});