
/// check messages
msg_error["FIELD_EMPTY"]				= new Array();
msg_error["FIELD_EMPTY"]["es"]			= "Tiene que rellenar el campo.";
msg_error["FIELD_EMPTY"]["en"]			= "You must fill the field.";
msg_error["FIELD_EMPTY"]["CA-es"]		= "Ha d'omplir el camp.";
///
msg_error["INVALID_INTEGER"]				= new Array();
msg_error["INVALID_INTEGER"]["es"]		= "Introduzca un valor numérico entero.";
msg_error["INVALID_INTEGER"]["en"]		= "Must be a integer number.";
msg_error["INVALID_INTEGER"]["CA-es"]	= "Introdueixi un valor numéric enter.";
///
msg_error["INVALID_DOUBLE"]				= new Array();
msg_error["INVALID_DOUBLE"]["es"]		= "Introduzca un valor numérico decimal.";
msg_error["INVALID_DOUBLE"]["en"]		= "Must be a decimal number.";
msg_error["INVALID_DOUBLE"]["CA-es"]	= "Introdueixi un valor numéric decimal.";
///
msg_error["INVALID_NUMBER"]				= new Array();
msg_error["INVALID_NUMBER"]["es"]		= "Introduzca un valor numérico.";
msg_error["INVALID_NUMBER"]["en"]		= "Must be a number.";
msg_error["INVALID_NUMBER"]["CA-es"]	= "Introdueixi un valor numéric.";
///
msg_error["INVALID_EMAIL"]				= new Array();
msg_error["INVALID_EMAIL"]["es"]		= "El formato del email es incorrecto.";
msg_error["INVALID_EMAIL"]["en"]		= "Email format is wrong.";
msg_error["INVALID_EMAIL"]["CA-es"]		= "El format del email és incorrecte.";
///
msg_error["INVALID_DNI"]				= new Array();
msg_error["INVALID_DNI"]["es"]			= "El NIF/DNI es incorrecto.";
msg_error["INVALID_DNI"]["en"]			= "NIF/DNI is wrong.";
msg_error["INVALID_DNI"]["CA-es"]		= "El NIF/DNI és incorrecte.";
//////////////////////////////////////////////////////////////

//// TForm Class ////
function TForm(htmlForm, tMsg) {
	// attributes
	this.htmlForm		= htmlForm;
	this.tMsg			= tMsg;
	this.fieldsToCheck	= new Array();
	// methods
	this.getField		= TForm_getField;
	this.setValidation	= TForm_setValidation;
	this.check			= TForm_check;
	this.isEmpty		= TForm_isEmpty;
	this.isInteger		= TForm_isInteger;
	this.isDouble		= TForm_isDouble;
	this.isNumber		= TForm_isNumber;
	this.isEmail		= TForm_isEmail;
	this.isDNI			= TForm_isDNI;
	this.checkField		= TForm_checkField;
	this.validate		= TForm_validate;
	// implementation
	function TForm_getField(key) {
		return this.htmlForm[key];
	}
	function TForm_setValidation(key, validation) {
		this.fieldsToCheck[key]	= validation;
	}
	function TForm_check(condition, msgid) {
		if (condition) return true;
		alert( this.tMsg.getMessage(msgid) );
		return false;
	}
	function TForm_isEmpty(key) {
		return !this.check( !isEmpty(this.getField(key).value), 'FIELD_EMPTY' );
	}
	function TForm_isInteger(key) {
		return this.check( isInteger(this.getField(key).value), 'INVALID_INTEGER' );
	}
	function TForm_isDouble(key) {
		return this.check( isDouble(this.getField(key).value), 'INVALID_DOUBLE' );
	}
	function TForm_isNumber(key) {
		return this.check( isInteger(this.getField(key).value)||isDouble(this.getField(key).value), 'INVALID_NUMBER' );
	}
	function TForm_isEmail(key) {
		return this.check( isEmail(this.getField(key).value), 'INVALID_EMAIL' );
	}
	function TForm_isDNI(key) {
		return this.check( isDNI(this.getField(key).value), 'INVALID_DNI' );
	}
	function TForm_checkField(key) {
		obj = this.getField(key);
		if (obj==null||obj=="undefined"||this.fieldsToCheck[key]==null||this.fieldsToCheck[key]=="undefined") {
			return true;
		}
		var ok = false;
		//alert(this.fieldsToCheck[key]);
		eval("ok="+this.fieldsToCheck[key]);
		//alert(ok);
		if (!ok) {
			obj.focus();
			obj.select();
		}
		return ok;
	}
	function TForm_validate() {
		var ok = true;
		for (i=0; ok&&i<this.htmlForm.length; i++) {
			//alert("name=<<"+this.htmlForm[i].name+">>");
			ok = ok&&this.checkField( this.htmlForm[i].name );
		}
		//alert("ok="+ok);
		return ok;
	}
}
