/**
 * => 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) des 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++) {
			if (this.attributes.get('tag') == 'select') {
				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].hasClass('notMandatory')) {
				if (attributes[j].get('tag') == 'select' && attributes[j].get('value') == "-1") {
					 //select
					strErr += '\n' + this.errSep + $$('label[for=' + attributes[j].id + ']')[0].get('text');
				} else if (attributes[j].get('tag') == 'input' && new Helper().getRadioValue(attributes[j]) == -1) {
					//radio buttons
					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);
	}
	
});
