function myForm(nombre, defaultMsgErr)
{
this.nombre=nombre;
this.reglas = new Array();
this.alertas = new Array();
this.msgErr = "";

if(defaultMsgErr==null)
this.defaultMsgErr = "Revise los datos:";
else
this.defaultMsgErr = defaultMsgErr;
this.defaultMsgErr = this.defaultMsgErr + "\n";

this.primerCampoError=null;


/* Prototipos */

this.addRule = myForm_addRule;
this.eval = myForm_eval;
this.evalRule = myForm_evalRule;

/* Depuracion   */

/* 
this.debug=""
this.chkFields = myForm_chkFields;
this.chkFieldsInRule = myForm_chkFieldsInRule; */
}

function myForm_addRule(regla, alerta)
{
nueva =(this.reglas.length +=1) - 1;
this.reglas[nueva]=regla;
this.alertas[nueva]=alerta;
}

function myForm_evalRule(index)
{
pattcampos = /@([\w\.]+)@/g;
pattcampo = /.+@([\w\.]+)@.+/;

ok=true;
//alert(this.reglas[index].replace(pattcampos, "window.document." + this.nombre + "[\"" + "$1"+"\"]"));
var ok=eval(this.reglas[index].replace(pattcampos, "window.document." + this.nombre + "[\"" + "$1"+"\"]"));
if (!ok){
	if(this.msgErr=="")
		this.msgErr = this.defaultMsgErr;
	 this.msgErr = this.msgErr + "\n" + this.alertas[index];
	 if (this.primerCampoError==null)
	 {
	 this.primerCampoError=eval(this.reglas[index].replace(pattcampo, "window.document." + this.nombre + "[\"" + "$1"+"\"]"));
	 }
}

}


function myForm_eval()
{

this.primerCampoError=null;
this.msgErr="";
for(var iter=0;iter<this.reglas.length;iter++)
{
	this.evalRule(iter);
}
if (this.msgErr!=""){
	alert(this.msgErr);
	if(this.primerCampoError.type!="hidden")
		this.primerCampoError.focus();
	if (this.primerCampoError.type=="password" || 
		this.primerCampoError.type=="text" ||
		this.primerCampoError.type=="textarea"
		)
	{
	this.primerCampoError.select();
	}
	}
else
	{
	f=eval("window.document." + this.nombre);
	f.submit();
	}


}




