// JavaScript Document

function AvxForm(id) {
	this.id=id;
	this.campos=new Array();
	this.addCampo= function (campo) { this.campos[this.campos.length] = campo; };
	this.filtros=new Array();
	this.addFiltro= function (filtro) { this.filtros[this.filtros.length] = filtro; };
	this.send= function () { 
		var ok=true;
		for (i=0;i<this.campos.length;i++) {
			var campo=this.campos[i];
			var valor=document.getElementById(campo.id).value;
			if ((campo.required) && (valor=="")) {
				alert ("El campo '"+campo.name+"' es obligatorio.");
				document.getElementById(campo.id).focus();
				ok=false;
				break;
			}
			if ((campo.charMinimun>-1) && (valor.length<campo.charMinimun)) {
				alert ("El campo '"+campo.name+"' requiere al menos "+campo.charMinimun+" caracteres.");
				document.getElementById(campo.id).focus();
				ok=false;
				break;
			}
		}
		if (ok) {
			for (i=0;i<this.filtros.length;i++) {
				var filtro=this.filtros[i];
				if (filtro.type=="equal") {
					var valor1=document.getElementById(filtro.idCampo1).value;
					var valor2=document.getElementById(filtro.idCampo2).value;
					if (valor1!=valor2) {
						alert ("Los valores de '"+filtro.name1+"' y '"+filtro.name2+"' no son identicos.");
						document.getElementById(filtro.idCampo1).focus();
						ok=false;
						break;
					}
				}
			}
		}
		
		if (ok) {
			document.getElementById(this.id).submit();
		}
		
	};
}


function AvxFormCampo(id, name, required, charMinimun) {
	this.id=id;
	this.name=name;
	this.required=required;
	this.charMinimun=charMinimun;
}

function AvxFormFilter_equal(idCampo1, name1, idCampo2, name2) {
	this.type="equal";
	this.idCampo1=idCampo1;
	this.name1=name1;
	this.idCampo2=idCampo2;
	this.name2=name2;
}