
/***********************************************
 * Enable/Disable "Enter" key in Form script
 ***********************************************/
  function handleEnter (field, event, nCampo) 
  {

    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

    if (keyCode == 13) 
    {

			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
            field.form.elements[i].focus();
			return false;
	 } 
	 else
	 return true;
   }




// **************************************************
// ********** Funções dos Form´s ********************
// **************************************************
function ObrigadoFormLogin()
{
  window.location="obrigado.asp";
}

function LimparFormLogin()
{
  document.form1.reset();
}

function ConfereFormLogin()
{
	var texto, msgaux, erro, controle, i, s;  
	 msgaux = 'Foram encontrados os seguintes erros:\n' 
	 erro=false;

	 // campo AS_matr 
	 texto = document.form1.AS_matr.value; 
	 if (texto.length < 6) 
	 { 
	        msgaux+='\n- Matrícula sindical incorreta'; 
	        erro=true;        
	 } 

	// campo AS_func
	 texto = document.form1.AS_func.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- A matrícula funcional não pode ficar em branco'; 
	        erro=true;        
	 } 

	// campo AS_empr
	 texto = document.form1.AS_empr.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- A empresa não pode ficar em branco'; 
	        erro=true;        
	 } 

	if (erro) 
	{
	alert(msgaux);  
	document.form1.AS_matr.focus();       
	}
	else
	{
	document.form1.submit();
    }
}

function RefazerFormLogin()
{
	var texto, msgaux, erro, controle, i, s;  
	 msgaux = 'Foram encontrados os seguintes erros:\n' 
	 erro=false;

	 // campo AS_matr 
	 texto = document.form1.AS_matr.value; 
	 if (texto.length < 6) 
	 { 
	        msgaux+='\n- Matrícula sindical incorreta'; 
	        erro=true;        
	 } 

	// campo AS_func
	 texto = document.form1.AS_func.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- A matrícula funcional não pode ficar em branco'; 
	        erro=true;        
	 } 

	// campo AS_empr
	 texto = document.form1.AS_empr.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- A empresa não pode ficar em branco'; 
	        erro=true;        
	 } 

	if (erro) 
	{
	   var_passo_Refazer="";
	   alert(msgaux);
	   document.form1.AS_matr.focus(); 
	}
	else
	{
	var_passo_Refazer="Refazer";
    document.form1.passoR.value ="Refazer";
	document.form1.submit();
    }
}



// ************* Dados Cadastrais *************************
function closedados()
{
  window.close();
}

function limpardados()
{
  document.form1.AS_End.value="";
  document.form1.AS_EndNum.value="";
  document.form1.AS_EndCompl.value="";
  document.form1.AS_Cep.value="";
  document.form1.AS_Bairro.value="";
  document.form1.AS_UF.value="";
  document.form1.AS_Cidade.value="";
  document.form1.AS_Resfoneddd.value="";
  document.form1.AS_Resfone.value="";
  document.form1.AS_Comfoneddd.value="";
  document.form1.AS_Comfone.value="";
  document.form1.AS_AdmEmp.value="";
  document.form1.AS_DtNasc.value="";
  document.form1.AS_Rgnum.value="";
  document.form1.AS_cpf.value="";
  document.form1.AS_email.value="";
}

function conferedados()
{
	var texto, msgaux, erro, controle, i, s;  
	 msgaux = 'Foram encontrados os seguintes erros:\n' 
	 erro=false;

	// campo endereco
	 texto = document.form1.AS_End.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- O endereço não pode ficar em branco'; 
	        erro=true;        
	 } 

	// campo endereco numero
	 texto = document.form1.AS_EndNum.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- O número do endereço não pode ficar em branco'; 
	        erro=true;        
	 } 

	// campo bairro 
	 texto = document.form1.AS_Bairro.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- O bairro não pode ficar em branco'; 
	        erro=true;        
	 } 

	// campo cidade
	 texto = document.form1.AS_Cidade.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- A cidade não pode ficar em branco'; 
	        erro=true;        
	 } 

	// campo uf 
	 texto = document.form1.AS_UF.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- O estado não pode ficar em branco'; 
	        erro=true;        
	 } 

	// campo CEP
	 texto = document.form1.AS_Cep.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- O CEP não pode ficar em branco'; 
	        erro=true;        
	 }
       else 
       {
	       document.form1.AS_Cep.value=limpa_string(document.form1.AS_Cep.value); 
	 }
 


    // campo Data de nascimento ++++++++++++++++++++++++++++++++++++++++++++++
    texto = document.form1.AS_DtNasc.value; 
	if (texto.length == 0)        // Se Data for em branco
	{ 
	    msgaux+='\n- A Data de nascimento não pode ficar em branco'; 
	    erro=true;        
	} 	
	else if(texto.length < 10)   // Se Data não for dd/mm/yyyy
	{ 
	    msgaux+='\n- Data de nascimento inválida';
	    msgaux+='\n- Entre com a data no formato dd/mm/yyyy';  
	    erro=true;        
	} 
	else                        // Se Data é valida
	{
	   var strSeperator = "/";
       var mDay = document.form1.AS_DtNasc.value.substr(0,2);
       var mMonth = document.form1.AS_DtNasc.value.substr(3,2);
       var mYear = document.form1.AS_DtNasc.value.substr(6,4);

       var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
	   if(dateValid(vDateValueCheck) == false )  // verifica data inteira
	   {			
	      msgaux+='\n- Data de nascimento inválida'; 
	      erro=true;        
	   }
	}

   // campo Data de Admissão no Banco 
    texto = document.form1.AS_AdmEmp.value; 
	if (texto.length != 0)        // Se Data não for em branco
	{        
	   if(texto.length < 10)   // Se Data não for dd/mm/yyyy
	   { 
	      msgaux+='\n- Data de admissão na empresa inválida';
	      msgaux+='\n- Entre com a data no formato dd/mm/yyyy';  
	      erro=true;        
	   }    	
       else                        // Se Data é valida
	   {
	      var strSeperator = "/";
          var mDay = document.form1.AS_AdmEmp.value.substr(0,2);
          var mMonth = document.form1.AS_AdmEmp.value.substr(3,2);
          var mYear = document.form1.AS_AdmEmp.value.substr(6,4);

          var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
	      if(dateValid(vDateValueCheck) == false )  // verifica data inteira
	      {			
	         msgaux+='\n- Data de admissão na empresa inválida'; 
	         erro=true;        
	      }
	   }
	}   

	// campo rg 
	// texto = document.form1.AS_Rgnum.value; 
	// if (texto.length == 0) 
	// { 
	//        msgaux+='\n- O RG não pode ficar em branco'; 
	//        erro=true;        
	// } 

	// campo email  
	 texto = document.form1.AS_email.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- O E-mail não pode ficar em branco'; 
	        erro=true;        
	 } 	
	else 
	{
		if(valida_Email(document.form1.AS_email.value) == false ) 
	   {
          msgaux+='\n- Formato de E-mail inválido'; 
	      erro=true;       
	   }
	}


	// campo cpf 
	 texto = document.form1.AS_cpf.value; 
	 if (texto.length == 0) 
	 { 
	        msgaux+='\n- O CPF não pode ficar em branco'; 
	        erro=true;        
	 } 	
	else 
	{
	   if (valida_CPF(document.form1.AS_cpf.value) == false )
	{			
	        msgaux+='\n- O CPF é inválido'; 
	        erro=true;
	}
	   else
	   {
	       document.form1.AS_cpf.value=limpa_string(document.form1.AS_cpf.value);  
	   }
	              
	}


	if (erro) 
	{
	   alert(msgaux);      
	}
	else
	document.form1.submit();
} 
/*****************************************************************************/
  function ShowButton(x, id)
  {
    if (x == 1) 
	  { 
	     var obj = document.getElementById(id.id);
    	 obj.style.backgroundImage = 'url(img/button/buttonS.gif)';     
      } 
    else
      {
	     var obj=document.getElementById(id.id);
	     obj.style.backgroundImage = 'url(img/button/button.gif)';     
      }  	
  }
