
/*inicio formatear fecha*/

function formateafecha(fecha)
{
    var long1 = fecha.length;
    var dia;
    var mes;
    var ano;

    if ((long1>=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 ((long1<=2) && (primerslap=true)) {
            fecha=fecha.substr(0,1);
            primerslap=false;
        }
    }
    if ((long1>=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 ((long1<=5) && (segundoslap=true)) {
            fecha=fecha.substr(0,4);
            segundoslap=false;
        }
    }
    if (long1>=7)
    {
        ano=fecha.substr(6,4);
        if (IsNumeric(ano)==false) {
            fecha=fecha.substr(0,6);
        }
        else {
            if (long1==10){
                if ((ano==0) || (ano<1900) || (ano>2100)) {
                    fecha=fecha.substr(0,6);
                }
            }
        }
    }

    if (long1>=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);
}

/*fin de formtear fecha*/




function envia(pag){
    document.frm.action= pag
    document.frm.submit()
	
}

function SoloNumero(pObj)
{
    if (event.keyCode >= 48 && event.keyCode <= 57)
    {
        event.keyCode = event.keyCode;
    }
    else{
        event.keyCode = 0;
    }
}

function validarsololetras(e) {
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true;
    patron =/[A-Za-zñÑ\s]/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}
/*funciones para validar correo*/

function numero_veces(cadena,caracter)
{
    var numVeces=0;

    while (cadena.indexOf(caracter,0)!=-1)
    {
        numVeces++;
        cadena=cadena.substr(cadena.indexOf(caracter,0)+1);
    }
    return numVeces;
}


function reversa(cadena)
{
    var resultado="";

    while (cadena!="")
    {
        resultado=resultado.concat(cadena.substr(cadena.length-1));
        cadena=cadena.substr(0,cadena.length-2);
    }
    return resultado;
}

function valida_mail(txtObject)
{
    if (txtObject.value.length!=0)
    {
        if (es_email(txtObject))
            return true;
        else
            return false;
    }
    else
        return false;
}

function es_email(txtObject)
{
    var cadena=txtObject.value;
    var flag=true;

    //si hay espacios en blanco...
    if (cadena.indexOf(" ")!=-1)
        flag=false;
    //debe haber un único "@" en el medio de la cadena, así como no son
    //permitidos: "@.", ".@" o ".."
    //no puede empezar o terminar en "." o "@"
    //por lo menos debe haber un "."
    if ((numero_veces(cadena,"@")!=1) || (cadena.indexOf("@")==0) ||
        (numero_veces(cadena,".")==0) || (cadena.indexOf(".")==0) ||
        (cadena.indexOf("..")!=-1) ||
        (cadena.indexOf("@.")!=-1) || (cadena.indexOf(".@")!=-1) ||
        (reversa(cadena).indexOf(".")==0) ||
        (reversa(cadena).indexOf("@")==0))
        flag=false;
    //por lo menos debe haber un "." después de "@"
    cadena=cadena.substr(cadena.indexOf("@")+1);
    if (cadena.indexOf(".")==-1)
        flag=false;
    return flag;
}


function validarDni(dni){

    if (dni.value != ""){ // Si escribió algo
        if (dni.value.length < 8 ) {
            alert ("Introduzca un D.N.I. válido.");
            dni.focus();
            return false;
        }
    }
    return true;
}

function validar(theForm)
{
    if ( document.frm.txtnombre.value == "" )
    {
        alert ("Ingrese su Nombre...!");
        document.frm.txtnombre.focus ()
        return (false);
    }


    if ( document.frm.txtapellido.value == "" )
    {
        alert ("Ingrese su Apellido...!");
        document.frm.txtapellido.focus ()
        return (false);
    }


    if ( document.frm.txtDNI.value == "" )
    {
        alert ("Ingrese su número de DNI...!");
        document.frm.txtDNI.focus ()
        return (false);
    }

    if ( document.frm.txtedad.value == "" )
    {
        alert ("Ingrese su Edad...!");
        document.frm.txtedad.focus ()
        return (false);
    }

    if ( document.frm.txtcorreo.value == "" )
    {
        alert ("Ingrese su Correo...!");
        document.frm.txtcorreo.focus ()
        return (false);
    }

    else
    {
        val = valida_mail(document.frm("txtcorreo"));
        if (!val)
        {
            alert("El Correo electrónico no es válido")
            document.frm.txtcorreo.focus();
            return false;
        }


    }




    return(true)
}



function validarescribenos(theForm)
{
    if ( document.frm.txtnombre.value == "" )
    {
        alert ("Ingrese su Nombre...!");
        document.frm.txtnombre.focus ()
        return (false);
    }


    if ( document.frm.txtapellido.value == "" )
    {
        alert ("Ingrese su Apellido...!");
        document.frm.txtapellido.focus ()
        return (false);
    }


    if ( document.frm.txtDNI.value == "" )
    {
        alert ("Ingrese su número de DNI...!");
        document.frm.txtDNI.focus ()
        return (false);
    }

    if ( document.frm.txtedad.value == "" )
    {
        alert ("Ingrese su Edad...!");
        document.frm.txtedad.focus ()
        return (false);
    }

    if ( document.frm.txtcorreo.value == "" )
    {
        alert ("Ingrese su Correo...!");
        document.frm.txtcorreo.focus ()
        return (false);
    }



    if(document.frm.comentario.value == "")
    {
        alert("¡Ingrese el comentario!");
        document.frm.comentario.focus();
        return (false);
    }




    else
    {
        val = valida_mail(document.frm("txtcorreo"));
        if (!val)
        {
            alert("El Correo electrónico no es válido")
            document.frm.txtcorreo.focus();
            return false;
        }


    }




    return(true)
}



function validarcontactenos(theForm)
{
    if ( document.frm.txtnombre.value == "" )
    {
        alert ("Ingrese su Nombre...!");
        document.frm.txtnombre.focus ()
        return (false);
    }


    if ( document.frm.txtapellido.value == "" )
    {
        alert ("Ingrese su Apellido...!");
        document.frm.txtapellido.focus ()
        return (false);
    }


    if ( document.frm.txtDNI.value == "" )
    {
        alert ("Ingrese su número de DNI...!");
        document.frm.txtDNI.focus ()
        return (false);
    }

    if ( document.frm.txtedad.value == "" )
    {
        alert ("Ingrese su Edad...!");
        document.frm.txtedad.focus ()
        return (false);
    }

    if ( document.frm.txtcorreo.value == "" )
    {
        alert ("Ingrese su Correo...!");
        document.frm.txtcorreo.focus ()
        return (false);
    }

    else
    {
        val = valida_mail(document.frm("txtcorreo"));
        if (!val)
        {
            alert("El Correo electrónico no es válido")
            document.frm.txtcorreo.focus();
            return false;
        }


    }




    return(true)
}



function validarRecomienda(theForm)
{
    if ( document.frm.txtnombreremitente.value == "" )
    {
        alert ("Ingrese su Nombre...!");
        document.frm.txtnombreremitente.focus ()
        return (false);
    }


    if ( document.frm.txtnombredestino.value == "" )
    {
        alert ("Ingrese el nombre de su Amigo...!");
        document.frm.txtnombredestino.focus ()
        return (false);
    }


    if ( document.frm.txtcdestino.value == "" )
    {
        alert ("Ingrese su correo ...!");
        document.frm.txtcdestino.focus ()
        return (false);
    }


    else
    {
        val = valida_mail(document.frm("txtcdestino"));
        if (!val)
        {
            alert("El Correo electrónico no es válido")
            document.frm.txtcdestino.focus();
            return false;
        }


    }


    if ( document.frm.txtdestino.value == "" )
    {
        alert ("Ingrese el correo de su amigo...!");
        document.frm.txtdestino.focus ()
        return (false);
    }


    else
    {
        val = valida_mail(document.frm("txtdestino"));
        if (!val)
        {
            alert("El Correo electrónico no es válido")
            document.frm.txtdestino.focus();
            return false;
        }


    }




    return(true)
}


function validarRecomiendaNoticia(theForm)
{
    if ( document.fo3.txtnombre1.value == "" )
    {
        alert ("Ingrese su Nombre...!");
        document.fo3.txtnombre1.focus ()
        return (false);
    }


    if ( document.fo3.txtnombre2.value == "" )
    {
        alert ("Ingrese el nombre de su Amigo...!");
        document.fo3.txtnombre2.focus ()
        return (false);
    }


    if ( document.fo3.txtemail2.value == "" )
    {
        alert ("Ingrese su correo ...!");
        document.fo3.txtemail2.focus ()
        return (false);
    }


    if(!valida_mail(document.fo3("txtcdestino") == false))
    {
        alert("El Correo electrónico no es válido")
        document.fo3.txtcdestino.focus();
        return false;
    }

    return(true)

}
