// JavaScript Document

function trim(valor)
{	
	while(valor.indexOf(" ")==0)
	{
		valor=valor.substr(1,valor.length);
		if(valor.length==0)break;
	}
	while(valor.lastIndexOf(" ")==(valor.length-1))
	{
		valor=valor.substr(0,valor.length-1);
		if(valor.length==0)break;
	}
	return valor;
}

function valida_cpf(cpf)
{
	   soma1=0;
	   soma2=0;
	   igual=0; 
	  
	  
	   for(x=1;x<=10;x++) 
		  {
			 if (cpf.charAt(x-1) != cpf.charAt(x))
				break;
			 else
				igual++ 
		  }
	   if (igual == 10)
			return false;
	   
	   for (i=0;i<9;i++)
		{
		   numero1=parseInt(cpf.charAt(i))*(i+1);
		   soma1=soma1+numero1;
		}
		for (i=1;i<10;i++)
		{
		   numero2=parseInt(cpf.charAt(i))*i;
		   soma2=soma2+numero2;
		}
		v1=soma1%11;
		v2=soma2%11;
			
		if (v1 == 10) v1=0;
		if (v2 == 10) v2=0;
		if (!(v1 == parseInt(cpf.charAt(9)) && v2 == parseInt(cpf.charAt(10))))
			 {
				return false;
			  }
		else
				return true;
}



function valida()
{
	if(document.getElementById('nome').value=='')
	{
		alert('EL CAMPO DEL NOMBRE DEBE COMPLETARSE');
		document.getElementById('nome').focus();
		return false;
	}
	var erEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	if( !(erEmail.test(document.getElementById("email").value)) )
	{
		alert("E-MAIL INCORRETO");
		document.getElementById("email").focus();
		return false;
	}
	if(document.getElementById("telefone").value=="")
	{
		alert("DIGITE EL TELEFONO");
		document.getElementById("telefone").focus();
		return false;
	}
	if(document.getElementById("servico").value=="")
	{
		alert("ESCOJA EL TEMA");
		document.getElementById("servico").focus();
		return false;
	}
	if(document.getElementById("mensagem").value=="")
	{
		alert("INTRODUCE EL MENSAJE");
		document.getElementById("mensagem").focus();
		return false;
	}	
	return true;
}


function valida_login()
{

	if(trim(document.getElementById("cpf").value)=='')
		{
			alert("EL CPF DEBE SER LLENADO!");
			document.getElementById("cpf").focus();
			return false;
		}
	else
		{
			if(!valida_cpf(document.getElementById("cpf").value))
				{
					alert("CPF INVALIDOS!");
					document.getElementById("cpf").focus();
					return false;
				}
		}
		
	if (trim(document.getElementById("senha").value)=='')
		{
			alert("LA CONTRASE&ntilde;A QUE SE PREENCHIDA!");
			document.getElementById("senha").focus();
			return false;
		}
	else if(document.getElementById("senha").value.length < 4)
		{
			alert("LA CONTRASE&ntilde;A DEBE TENER AL MINIMO 4 CARACTERES!");
			document.getElementById('senha').focus();
			return false;
		}
  
   return true;
}
