///////////////////////////////////////////////////////////////////////////////////////////////////////

	function IsNumeric(valor) 
	{ 
		var log=valor.length; var sw="S"; 
		for (x=0; x<log; x++) 
		{ v1=valor.substr(x,1); 
		v2 = parseInt(v1); 
		//Compruebo si es un valor numérico 
		if (isNaN(v2)) { sw= "N";} 
		} 
		if (sw=="S") {return true;} else {return false; } 
	} 
	
///////////////////////////////////////////////////////////////////////////////////////////////////////

	var primerslap=false; 
	var segundoslap=false; 
	
	function formateafecha(fecha) 
	{ 
		var long = fecha.length; 
		var dia; 
		var mes; 
		var ano; 

		if ((long>=2) && (primerslap==false)) { dia=fecha.substr(0,2); 
		if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7); primerslap=true; } 
		else { fecha=""; primerslap=false;} 
		} 
		else 
		{ dia=fecha.substr(0,1); 
		if (IsNumeric(dia)==false) 
		{fecha="";} 
		if ((long<=2) && (primerslap=true)) {fecha=fecha.substr(0,1); primerslap=false; } 
		} 
		if ((long>=5) && (segundoslap==false)) 
		{ mes=fecha.substr(3,2); 
		if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); segundoslap=true; } 
		else { fecha=fecha.substr(0,3);; segundoslap=false;} 
		} 
		else { if ((long<=5) && (segundoslap=true)) { fecha=fecha.substr(0,4); segundoslap=false; } } 
		if (long>=7) 
		{ ano=fecha.substr(6,4); 
		if (IsNumeric(ano)==false) { fecha=fecha.substr(0,6); } 
		else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { fecha=fecha.substr(0,6); } } } 
		} 

		if (long>=10) 
		{ 
		fecha=fecha.substr(0,10); 
		dia=fecha.substr(0,2); 
		mes=fecha.substr(3,2); 
		ano=fecha.substr(6,4); 
		// Año no viciesto y es febrero y el dia es mayor a 28 
		if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { fecha=fecha.substr(0,2)+"/"; } 
		} 
		return (fecha); 
	} 
	   
///////////////////////////////////////////////////////////////////////////////////////////////////////
	
    function NumberFormat(num, numDec, decSep, thousandSep)
    { 
		var arg; 
		var Dec; 
		Dec = Math.pow(10, numDec); 
		if (typeof(num) == 'undefined') return; 
		if (typeof(decSep) == 'undefined') decSep = ','; 
		if (typeof(thousandSep) == 'undefined') thousandSep = '.'; 
		if (thousandSep == '.') 
		arg=/./g; 
		else 
		if (thousandSep == ',') arg=/,/g; 
		if (typeof(arg) != 'undefined') num = num.toString().replace(arg,''); 
		num = num.toString().replace(/,/g, '.'); 
		if (isNaN(num)) num = "0"; 
		sign = (num == (num = Math.abs(num))); 
		num = Math.floor(num * Dec + 0.50000000001); 
		cents = num % Dec; 
		num = Math.floor(num/Dec).toString(); 
		if (cents < (Dec / 10)) cents = "0" + cents; 
		for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) 
		num = num.substring(0, num.length - (4 * i + 3)) + thousandSep + num.substring(num.length - (4 * i + 3)); 
		if (Dec == 1) 
		return (((sign)? '': '-') + num); 
		else 
		return (((sign)? '': '-') + num + decSep + cents); 
   } 
	
///////////////////////////////////////////////////////////////////////////////////////////////////////

   function EvaluateText(cadena, obj)
   { 
		opc = false; 
		if (cadena == "%d") 
		if (event.keyCode > 47 && event.keyCode < 58) 
		opc = true; 
		if (cadena == "%f"){ 
		if (event.keyCode > 47 && event.keyCode < 58) 
		opc = true; 
		if (obj.value.search("[.*]") == -1 && obj.value.length != 0) 
		if (event.keyCode == 46) 
		opc = true; 
		} 
		if(opc == false) 
		event.returnValue = false; 
   } 
///////////////////////////////////////////////////////////////////////////////////////////////////////
	function nifcif(cif)
	{
		par = 0
		non = 0
		letras="ABCDEFGHKLMNPQS"
		let=cif.charAt(0)

		if (!isNaN(let))
		{
		nif=cif
		validar(nif)
		return false
		}

		if (cif.length!=9)
		{
		alert('El Cif debe tener 9 digitos')
		//cif.focus()
		return false
		}

		if (letras.indexOf(let.toUpperCase())==-1)
		{
		alert("El comienzo del Cif no es válido")
		//cif.focus()
		return false
		}

		for (zz=2;zz<8;zz+=2)
		{
		par = par+parseInt(cif.charAt(zz))
		}

		for (zz=1;zz<9;zz+=2)
		{
		nn = 2*parseInt(cif.charAt(zz))
		if (nn > 9) nn = 1+(nn-10)
		non = non+nn
		}

		parcial = par + non

		control = (10 - ( parcial % 10))

		if (control!=cif.charAt(8))
		{
		alert("El Cif no es valido")
		//cif.focus()
		return false
		}
		}

		function validar(abc)
		{
		dni=abc.substring(0,abc.length-1)
		let=abc.charAt(abc.length-1)
		if (!isNaN(let))
		{
		alert('Falta la letra')
		//cif.focus()
		return false
		}
		else
		{
		cadena="TRWAGMYFPDXBNJZSQVHLCKET"
		posicion = dni % 23
		letra = cadena.substring(posicion,posicion+1)
		if (letra!=let.toUpperCase())
		{
			alert("Nif no valido")
			//cif.focus()
			return false
		}
		}
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////////	

	function emailCheck(email) {
		txt=email;
		if (txt.indexOf("@")<3){
		alert("La direccion e-mail no es valida. Por favor"
		+" introduzca una direccion que contenga el simbolo '@'.");
		}
		if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5)
		&&(txt.indexOf(".biz")<5)&&(txt.indexOf(".net")<5)
		&&(txt.indexOf(".es")<5)){
		alert("La direccion e-mail no es valida."
		+" La direccion e-mail debe contener un sufijo del tipo "
		+".com,.net,.org,.biz o .es");
		}
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////
    function CheckLOPD()
    {
		if(document.Form1("LOPD").checked){
			document.Form1("hiddenLOPD").value="YES";
			document.Form1.submit();
		}
		else{
			document.Form1("hiddenLOPD").value="NO";
			alert("Debe aceptar la Ley de Proteccion de Datos")
			return;
		}
    }
