//Constructor d'objet smForm
function smForm(name){
	this.name = name;
	this.fields = new Array();
	this.add = addField;
	this.check = check;
}
smForm.prototype.toString = function(){ return "[object smForm]"; }
//Method pour associer un objet smField a un objet smForm
function addField(p_smField){
	if (!p_smField)
		return null;
	var i = this.fields.length;
	this.fields[i] = p_smField;
	return this;
}

//Constructor d'objet smField
function smField(fieldObj){
	this.objField = fieldObj;
	this.methods = new Array();
	this.add = addMethod;
	this.boolDouble = false;
}
smField.prototype.toString = function(){ return "[object smField]"; }

//Constructor d'object smFieldDouble
function smFieldDouble(fieldObj_A,fieldObj_B){
	this.objField_A = fieldObj_A;
	this.objField_B = fieldObj_B;
	this.methods = new Array();
	this.add = addMethod;
	this.boolDouble = true;
}
smField.prototype.toString = function(){ return "[object smFieldDouble]"; }

//Method pour associer un objet smMethod a un objet smField
function addMethod(p_smMethod){
	if (!p_smMethod)
		return null;
	var i = this.methods.length;
	this.methods[i] = p_smMethod;
	return this;
}

//Constructor d'objet smMethod
function smMethod(functionName,errorMessage,params){
	this.functionName = functionName;
	this.errorMessage = errorMessage;
	this.parameters = new Array();
	this.add = addParam;
}
smMethod.prototype.toString = function(){ return "[object smMethod]"; }

//Method pour ajouter les parameters a un methode
function addParam(p_strParam){
	if (!p_strParam)
		return null;
	var i = this.parameters.length;
	this.parameters[i] = p_strParam;
	return this;
}

//Method pour verifier l'objet smForm
function check(){
	try {
		if(this.fields.length < 1)
			return true;
		var tmpField = "";
		var tmpMethod = "";
		var bool = false;
		for(i=0; i<this.fields.length; i++){
			tmpField = this.fields[i];
			for(j=0; j<tmpField.methods.length; j++){
				tmpMethod = tmpField.methods[j];
				if(tmpField.boolDouble)
					bool = eval(""+tmpMethod.functionName+"(tmpField.objField_A,tmpField.objField_B, '"+tmpMethod.errorMessage+"','"+tmpMethod.parameters.toString()+"')");
				else{
					bool = eval(""+tmpMethod.functionName+"(tmpField.objField, '"+tmpMethod.errorMessage+"','"+tmpMethod.parameters.toString()+"')");
				}
				if(!bool)
					return bool;
			}
		}
		return bool;
	}catch (e){
		//alert(e);
		return false;
	}
}
