﻿/*
NOMBRE 			script_cita
DESCRIPCION 	validaFormularios_cita
AUTOR        	DAVID DE LA SOTA PINEDA
FECHA           28/05/2009
MODIFICACION    00/00/0000
*/

function disqualifyEndWorkDate( trabaja){


if(trabaja)
{
document.getElementById("FFINTRAB2").disabled = true; 
document.getElementById("FFINTRAB1").value = "0000/00/00"; 

}
else {
	document.getElementById("FFINTRAB1").value = "2009/01/01"; 
	document.getElementById("FFINTRAB2").disabled= false;	
}
}
function restartForm()
{
		

	document.getElementById("DNOMBRES1").value = '* Tu Nombre';
	document.getElementById("NTELEFON1").value = '* Tu Nombre';
	document.getElementById("NCELULAR1").value = '* Tu Nombre';
	document.getElementById("DCORREOE1").value = '* Tu Nombre';
	document.getElementById("NSUELMEN1").value = '* Tu Nombre';

}


// Submits the first form
function ValidateForm_cita()
{
	
	

	isvalid=true;

	DNOMBRES=document.getElementById("DNOMBRES1");
	NTELEFON=document.getElementById("NTELEFON1");
	NCELULAR=document.getElementById("NCELULAR1");
	DCORREOE=document.getElementById("DCORREOE1");
	NSUELMEN=document.getElementById("NSUELMEN1");

	

if ((document.getElementById("DNOMBRES1").value.length<1)||document.getElementById("DNOMBRES1").value=="Nombre")
    {
        document.getElementById("DIV_DNOMBRES").style.display="block";
        isvalid=false;
    }
    else
    {
        document.getElementById("DIV_DNOMBRES").style.display="none";
    }


if (
	(document.getElementById("NTELEFON1").value.length<8)
  ||(document.getElementById("NTELEFON1").value=="Numero telefonico")
  || isNaN(document.getElementById("NTELEFON1").value)
   )
    {

        document.getElementById("DIV_NTELEFON").style.display="block";
        isvalid=false;
    }
    else
    {

     var er_numero = /^([0-9])*$/;
	  if(!er_numero.test(document.getElementById("NTELEFON1").value)) {
	        isvalid=false;
		}else{
        document.getElementById("DIV_NTELEFON").style.display="none";
		}			
		
		
}
	
if (
	(document.getElementById("NANOIMSS1").value<=9)
  ||(document.getElementById("NANOIMSS1").value=="0")
  ||(document.getElementById("NANOIMSS1").value>50)
  || isNaN(document.getElementById("NANOIMSS1").value)
   )
    {

        document.getElementById("DIV_NANOIMSS1").style.display="block";
        isvalid=false;
    }
    else{
        document.getElementById("DIV_NANOIMSS1").style.display="none";
		}	
		


	
	
/*if (
	(document.getElementById("NCELULAR1").value.length<10)||(document.getElementById("NCELULAR1").value=="Numero movil")
     || isNaN(document.getElementById("NCELULAR1").value)
	)
    {
//        document.getElementById("DIV_NCELULAR").style.display="block";
        document.getElementById("DIV_NCELULAR").style.display="none";
        isvalid=true;
    }
    else
    {


	var er_numero = /^([0-9])*$/;
	  if(!er_numero.test(document.getElementById("NCELULAR1").value)) {
	        isvalid=true;
		}else{
        document.getElementById("DIV_NCELULAR").style.display="none";
		}			

		
    
    }

*/
  
if (
	(document.getElementById("DCORREOE1").value.length<1)
  ||(document.getElementById("DCORREOE1").value=="Correo electronico")
  ||(  !checkEmail("DCORREOE1"))
    )  
    {
        document.getElementById("DIV_DCORREOE").style.display="block";
        isvalid=false;
    }
    else
    {
        document.getElementById("DIV_DCORREOE").style.display="none";

    }

	
if ((document.getElementById("NSUELMEN1").value < 1500)||document.getElementById("NSUELMEN1").value=="Sueldo")
    {
        document.getElementById("DIV_NSUELMEN").style.display="block";
        isvalid=false;
    }
	 else{
    	var er_monto = /^([0-9])*$/;

	        document.getElementById("DIV_NSUELMEN").style.display="block";
	  if(!er_monto.test(document.getElementById("NSUELMEN1").value)) {
	        isvalid=false;
		}else{
	        document.getElementById("DIV_NSUELMEN").style.display="none";
		}		
    
	 }

	if(isvalid){

	document.FormCita.submit()	

	}	else{
	alert("Verifique la informacion introducida. GRACIAS")	
	}

	
  

	
	

}

function isInteger(s)
{
	var k;
    for (k = 0; k < s.length; k++)
    {   
        // Check that current character is number.
        var c = s.charAt(k);
        if (((c < "0") || (c > "9")))
        {
            return false;
        }
    }
    // All characters are numbers.
    return true;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

// check for valid email
function checkEmail(name)
{		
	// email filter
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;



	// test email regexp
	if (!filter.test(document.getElementById(name).value))
	{
		
        return false;
	}
	else
	{
	
		return true;
	}
	

}

function checkRadio(id)
{
    var count = 0;
    for (i = 0; i < 2; i++)
    {
        if (document.getElementById(id + i).checked)
        {
            count++;
        }
    }
    if (count>0)
    {
        return true;
    }
    return false;
}
