function JxResultado(){	
	if (JxResultado.arguments.length>0){				
		var parametros=JxResultado.arguments[0];
		var direccion=window.location.href;
		var strHref;
		var resultado;
		
		//SACO EL TIPO DE XMLHTTP DEPENDIENDO DEL NAVEGADOR
		var xmlhttp=null;
		try {
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e1){
				try{
					xmlhttp=new XMLHttpRequest();
				}catch(e2){xmlhttp=null;};
			};
		};
		
		if (xmlhttp!=null){
		    //SACO LA RUTA Y LOS PARÁMETROS
		    if (direccion.indexOf("#") >0){direccion = direccion.substring(0, direccion.indexOf("#"));};
						
			if ((direccion.charAt(direccion.length-1)=="/")||(direccion.charAt(direccion.length-1)=="\\")){
				strHref="Default.aspx";
			}else{
				if (direccion.indexOf("?")>=0){
					strHref=direccion.substring(0,direccion.indexOf("?"));
				}else{
					strHref=direccion;
				};
			};
						
			if (parametros!=''){strHref+="?" + parametros;};
			
			//ENVÍO LA CONSULTA
			xmlhttp.open("POST",strHref,false );		
			xmlhttp.send(null);	 				
			resultado=xmlhttp.responseText;
		};

		if (resultado != "") {
		    if (JxResultado.arguments[1] != null) {
		        return resultado;
		    } else {
		        eval(resultado);
		    };
		}
	};
}

function checknumber(object){
	var x=object.value;
	var i;
	var patron;

	patron="0123456789";
	
	for(i = 0; i <= x.length - 1; i++){
		if(patron.search(x.charAt(i)) < 0){
			alert('Número incorrecto, por favor introduzca un número entero.');
			object.value="0";
			object.focus();		
			return 1
		};				
	};
	return 0
};

function isNum(object,Decimales){
	var error=0;
	var Resul="";
	var Coma=false;
	var Neg=false;
		
	if (object.value!=""){	    
		var orden=object.value;
		if (orden.length>=1 && orden.charAt(0)=='-'){		    
			orden=orden.substring(1,orden.length);
			if (orden.charAt(0)==' '){orden=orden.substring(1,orden.length);};
			Neg=true;
		};
		var i;
		var patron1;
		patron1="0123456789";
		
		for(i=orden.length-1; i>=0; i--){
			if (orden.charAt(i)!=',' && orden.charAt(i)!='.'){
				Resul=orden.charAt(i) + Resul;
				if(patron1.search(orden.charAt(i))<0){
					error=1;					
				};
			}else{
				if (!Coma){
					Coma=true;
					Resul="." + Resul;
				};
			};
		};
		if (error==0){
			if (Decimales=='1'){
				var ResulAux=Math.round(Resul * Math.pow(10, 1)) / Math.pow(10, 1);
			};
			if (Decimales=='2'){
				var ResulAux=Math.round(Resul * Math.pow(10, 2)) / Math.pow(10, 2);
			};
			if (Decimales=='3'){
				var ResulAux=Math.round(Resul * Math.pow(10, 3)) / Math.pow(10, 3);
			};
			if (Decimales=='4'){
				var ResulAux=Math.round(Resul * Math.pow(10, 4)) / Math.pow(10, 4);
			};
			if (Neg){ResulAux="-" + ResulAux;};
			object.value=ResulAux;
		}else{
			alert('Número incorrecto');
			object.value="0";
			object.focus();
		};
	};
}

function isNumM(object, Decimales) {
    var error = 0;
    var Resul = "";
    var Coma = false;
    var Neg = false;

    if (object.value != "") {
        var orden = object.value;
        if (orden.length >= 1 && orden.charAt(0) == '-') {
            orden = orden.substring(1, orden.length);
            if (orden.charAt(0) == ' ') { orden = orden.substring(1, orden.length); };
            Neg = true;
        };
        var i;
        var patron1;
        patron1 = "0123456789";

        for (i = orden.length - 1; i >= 0; i--) {
            if (orden.charAt(i) != ',' && orden.charAt(i) != '.') {
                Resul = orden.charAt(i) + Resul;
                if (patron1.search(orden.charAt(i)) < 0) {
                    error = 1;
                };
            } else {
                if (!Coma) {
                    Coma = true;
                    Resul = "." + Resul;
                };
            };
        };
        if (error == 0) {
            if (Decimales == '1') {
                var ResulAux = Math.round(Resul * Math.pow(10, 1)) / Math.pow(10, 1);
            };
            if (Decimales == '2') {
                var ResulAux = Math.round(Resul * Math.pow(10, 2)) / Math.pow(10, 2);
            };
            if (Decimales == '3') {
                var ResulAux = Math.round(Resul * Math.pow(10, 3)) / Math.pow(10, 3);
            };
            if (Decimales == '4') {
                var ResulAux = Math.round(Resul * Math.pow(10, 4)) / Math.pow(10, 4);
            };
            if (Neg) { ResulAux = "-" + ResulAux; };
            object.value = ResulAux;
        } else {
            alert('Número incorrecto');
            object.value = "";
            object.focus();
        };
    };
}

function validarHora(object){
	var hora=object.value;
	var error=0;
	var i;
	var patron="0123456789:";
	var longitud=hora.length-1;
	var encontrado;
	var contador;
		
	if (hora!=""){
		if ((hora.charAt(0)==':')||(hora.charAt(longitud)==':')){error=1;};
	
		encontrado=false
		contador=0;
		for(i = 0; i <= longitud; i++){
			if(patron.search(hora.charAt(i)) < 0){
				error=1;
			}else{
				if (encontrado){
					contador++;
				}else{
					contador++;
					if (hora.charAt(i)==':'){
						if (contador<3){error=1;};
						contador=0;
						encontrado=true;
					};
				};			
			};				
		};	
		if (((encontrado)&&(contador<2))||(!encontrado)){error=1;};
	};
	
	if (error==1){
		alert('Hora incorrecta, formato hh:mm.');
		object.value="";
		object.focus();
	};
};

function checkdate(objName) {
var datefield = objName;
var error;

error=0;

if (objName.value!=""){
	if ((objName.value.length<10)||(objName.value.length>10)){
		alert("La fecha es incorrecta.Formato: dd/mm/aaaa");
		datefield.value="";
		datefield.focus();
		return false;
	}else{
		var dias=objName.value.charAt(0) + objName.value.charAt(1);
		var meses=objName.value.charAt(3) + objName.value.charAt(4);
		var anos=objName.value.charAt(6) + objName.value.charAt(7) + objName.value.charAt(8) + objName.value.charAt(9);
		var i;
		var patron1;
		patron1="0123456789";	
		
		if ((objName.value.charAt(2)!='/')||(objName.value.charAt(5)!='/')){
			error=1;
			alert("La fecha es incorrecta.Formato: dd/mm/aaaa");
			datefield.value="";
			datefield.focus();
			return false;	
		};
		
		if (error==0){
			for(i = 0; i <= 3; i++){
				if(patron1.search(anos.charAt(i)) < 0){
					error=1;
					alert("La fecha es incorrecta.Formato: dd/mm/aaaa");
					datefield.value="";
					datefield.focus();
					return false;	
				};				
			};
		};
		
		if (error==0){
			if (chkdate(objName) == false) {
				datefield.select();
				alert("La fecha es incorrecta.Formato: dd/mm/aaaa");
				datefield.value=""
				datefield.focus();
				return false;
			}else {
				return true;
			};
		};
	};
};
};

function chkdate(objName) {
	var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("/");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "01";
	strMonthArray[1] = "02";
	strMonthArray[2] = "03";
	strMonthArray[3] = "04";
	strMonthArray[4] = "05";
	strMonthArray[5] = "06";
	strMonthArray[6] = "07";
	strMonthArray[7] = "08";
	strMonthArray[8] = "09";
	strMonthArray[9] = "10";
	strMonthArray[10] = "11";
	strMonthArray[11] = "12";
	strDate = datefield.value;
	if (strDate.length < 1) {
		return true;
	}
	if (strDate.indexOf("/")==-1){
		return false;
	}
	
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
	if (intday<10){
		datefield.value = "0" + intday + "/" + strMonthArray[intMonth-1] + "/" + strYear;
	}else{
		datefield.value = intday + "/" + strMonthArray[intMonth-1] + "/" + strYear;
	}
}
return true;
}

function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}




