﻿// JScript File
function popUp(URL,tamX,tamY,nombre) {
	window.name = "miPrincipal";
	eval( nombre + " = window.open(URL, '" + nombre + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=500,left=50,top=25');");
	eval(nombre+".focus()");
}

function deleteDate(obj){
	if(obj.value=='dd/mm/yyyy') obj.value=''
	return;
}


function esBisiesto(anyo)
    {
        /**
        * si el año introducido es de dos cifras lo pasamos al periodo de 1900. Ejemplo: 25 > 1925
        */
        if (anyo < 100)
            var fin = anyo + 1900;
        else
            var fin = anyo ;

        /*
        * primera condicion: si el resto de dividir el año entre 4 no es cero > el año no es bisiesto
        * es decir, obtenemos año modulo 4, teniendo que cumplirse anyo mod(4)=0 para bisiesto
        */
        if (fin % 4 != 0)
            return false;
        else
        {
            if (fin % 100 == 0)
            {
                /**
                * si el año es divisible por 4 y por 100 y divisible por 400 > es bisiesto
                */
                if (fin % 400 == 0)
                {
                    return true;
                }
                /**
                * si es divisible por 4 y por 100 pero no lo es por 400 > no es bisiesto
                */
                else
                {
                    return false;
                }
            }
            /**
            * si es divisible por 4 y no es divisible por 100 > el año es bisiesto
            */
            else
            {
                return true;
            }
        }
    }

function checkDate(Cadena){
	var Fecha= new String(Cadena)	// Crea un string
	var RealFecha= new Date()	// Para sacar la fecha de hoy
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))
	var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))
	
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900 || Ano.length>4){
        	
		return false
	}
	if (isNaN(Mes) || Mes.length>2 || Mes.length<1 || parseFloat(Mes)<1 || parseFloat(Mes)>12){
		
		return false
	}
	if (isNaN(Dia) || Dia.length<1 || Dia.length>2 || parseFloat(Dia)<1 || parseFloat(Dia)>31){
		
		return false
	}
	var bisiesto=esBisiesto(Ano)
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if ( ((Mes==2) && (Dia > 28) && !(bisiesto) ) || (Dia>30) || ((bisiesto) && (Mes==2) && (Dia>29))) 																																	{    			
			return false
		}
	}
 	return true	
}

function checkEmail(email) {
	caracNoValidos = " /:,;";
	if(email == "") return false; 							// debe rellenarse
	for(i = 0; i < caracNoValidos.length; i++) {			// ¿hay algún carácter no válido?
		caracMal = caracNoValidos.charAt(i);
		if(email.indexOf(caracMal,0) > -1) return false;
	}
	posArroba = email.indexOf("@",1); 						// debe haber una @
	if(posArroba == -1) return false;
	if(email.indexOf("@",posArroba+1) != -1) return false;	// y sólo una
	posPunto = email.indexOf(".",posArroba);
	if(posPunto == -1) return false;  						// y al menos un . después de la @
	if(posPunto+3 > email.length) return false; 			// debe haber al menos 2 caracteres tras el .
	return true;
}

function IsNumeric(sText){
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (zk = 0; zk < sText.length && IsNumber == true; zk++){ 
      Char = sText.charAt(zk); 
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;
}



