// JavaScript Document
function validaBranco( campoParam ){
	var campo = document.getElementById(campoParam);
	
	if( campo.value == "" ){
		alert( "O campo " + campo.name + " deve ser preenchido." );
		campo.focus();
		return false;
	}
	return true;
}
function validaBranco2( campoParam ){
	var campo = document.getElementById(campoParam);
	
	if( campo.value == "" ){
		return false;
	}
	return true;
}

var loginacess = 0;
var senhaacess = 0;

function limpaLogin() {
	if(loginacess == 0) {
		document.getElementById("nome_news").value = "";
		loginacess = 1;
	}
}

function limpaEmail() {
	if(senhaacess == 0) {
		document.getElementById("email_news").value = "";
		senhaacess = 1;
	}
}

function restituicampo(campo) {
	if(!document.getElementById(campo).value && campo == "nome_news") {
		document.getElementById(campo).value = "Nome"
		loginacess = 0;
	}
	if(!document.getElementById(campo).value && campo == "email_news") {
		document.getElementById(campo).value = "Email"
		//document.getElementById("senha").type = "text";
		senhaacess = 0;
	}
}
//Controles de mudança de cor de fundo de tabela
function mover(local){
	local.bgColor = "#FCE600";
}
function mout(local){
	local.bgColor = "";
}
//Link para o destino do flash
function destLogo(){
	document.location.href = "default.asp";
}
//function de esconde e exibe
function ExibeEsconde(destino, fundoTotal){
	if(document.getElementById(destino).style.display == "block") {
		document.getElementById(destino).style.display = "none";
		CorFundo(fundoTotal, 0);
		document.location.href = "#";
	} else {
		document.getElementById(destino).style.display = "block";
		CorFundo(fundoTotal, 1);
		document.location.href = "#" + fundoTotal;
	}
}
function CorFundo(destino, oquefazer) {
	if(oquefazer == 1){
		document.getElementById(destino).style.border = "1px solid #006600";
		document.getElementById(destino).style.backgroundColor = "#FDFDFD";
	} else {
		document.getElementById(destino).style.border = "0px solid #FFFFFF";
		document.getElementById(destino).style.backgroundColor = "#FFFFFF";
	}
}
//Validação de email
function valida_email(campoform)
{
	email = campoform.value;
    if (email)
		{
		p=email.indexOf('@');
		pont=email.indexOf('.');
		if (p<1 || p==(email.length-1) || pont<1 || pont==(email.length-1))
			{
				alert ('O e-mail deve ser um endereço de e-mail válido.');
	    		campoform.value = '';
	    		campoform.focus();
				return false;
			}
		} else {
			alert ('O e-mail deve ser um endereço de e-mail válido.');
  		campoform.value = '';
	    campoform.focus();
		return false;
		}
		return true;
}
//Validação de Telefone
function valida_tel(campo) {
   var valor='';
   var digito = false;
   a = campo.value;
   if (a) {
   num = a.length;
   for (f=0;f<num;f++)
     {
     if (parseInt(a.substr(f,1)) || a.substr(f,1)=='0') 
        if ((a.substr(f,1) != '0') || digito) valor = valor + '' + a.substr(f,1);
        if (parseInt(a.substr(f,1)) && a.substr(f,1) != '0') digito = true;
     };
   num = valor.length;
   if (num < 9 || num > 10)
      {
      alert ('- Número de telefone inválido. \nEntre com o DDD e o número do telefone.\nExemplo: (11) 1234-5678');
      campo.value = '';
      campo.focus();
      }
	  else
	  {
	  if (num == 9) valor = '(' + valor.substr(0, 2) + ') ' + valor.substr(num-7, 3) + '-' + valor.substr(num-4, 4);
	  if (num == 10) valor = '(' + valor.substr(0, 2) + ') ' + valor.substr(num-8, 4) + '-' + valor.substr(num-4, 4);
	  campo.value = valor;
	  }
   }
}
//Função para validar CNPJ
function valida_cnpj(campoform) {
	num_cpf = '';
	campo = campoform.value;

	if (!campo) return true;
	
	for (i=0;i<campo.length;i++)
		{
		resposta=campo.charAt(i) ;
		num = parseFloat(resposta);
		if (resposta==''+num) num_cpf=num_cpf+resposta; 
		}

	if (num_cpf.length == 14)
		{
		d1= 0;
		d4= 0;
		xx= 1;
		for (nCount = 0;nCount< num_cpf.length-2;nCount++)
			{
			if (xx < 5) fator= 6 - xx; else fator= 14 - xx;
			d1 = d1 + num_cpf.charAt(nCount) * fator;
			if (xx < 6) fator = 7 - xx; else fator = 15 - xx;
			d4 = d4 + num_cpf.charAt(nCount) * fator;
	    	xx = xx+1;
			}
		resto = d1%11;
		if (resto < 2) digito1 = 0; else digito1 = 11 - resto;
		d4 = d4 + 2 * digito1;
		resto = d4%11;
		if (resto < 2) digito2 = 0; else digito2 = 11 - resto;
		Check = digito1+''+digito2;
        if (Check != num_cpf.substring(num_cpf.length-2,num_cpf.length))
			{
			alert ('- CNPJ inválido. \nEntre com o CNPJ correto.');
    		campoform.value = '';
    		campoform.focus();
			return false;
			}
		else 
			{
			campoform.value= num_cpf.substring(0,2)
			+ '.' + num_cpf.substring(2,5) + '.' + num_cpf.substring(5,8) + '/' + num_cpf.substring(8,12)
			+ '-' + num_cpf.substring(12,14);
			return true;
			};
		}
	else
		{
		alert ('- CNPJ inválido. \nEntre com o CNPJ correto.');
    	campoform.value = '';
    	campoform.focus();
		return false;
		}
}
//Valida CPF
function valida_cpf(campoform) {
	num_cpf = '';
	campo = campoform.value;
	if (campo == "00000000000" || campo == "11111111111" || campo == "22222222222" || campo == "33333333333" || campo == "44444444444" || campo == "55555555555" || campo == "66666666666" || campo == "77777777777"  || campo == "88888888888"  || campo == "99999999999"){
		alert ('- CPF inválido. \nEntre com o CPF correto.');
    	campoform.value = '';
    	campoform.focus();
		return false;
	}
	if (campo == "000.000.000-00" || campo == "111.111.111-11" || campo == "222.222.222-22" || campo == "333.333.333-33" || campo == "444.444.444-44" || campo == "555.555.555-55" || campo == "666.666.666-66" || campo == "777.777.777-77"  || campo == "888.888.888-88"  || campo == "999.999.999-99"){
		alert ('- CPF inválido. \nEntre com o CPF correto.');
    	campoform.value = '';
    	campoform.focus();
		return false;
	}
	if (!campo) return true;
	for (i=0;i<campo.length;i++)
		{
		resposta=campo.charAt(i) ;
		num = parseFloat(resposta);
		if (resposta==''+num) num_cpf=num_cpf+resposta; 
		}

	if (num_cpf.length == 11)
		{
		soma = 0;
		for (i=0; i < 9; i ++) soma += parseInt(num_cpf.charAt(i)) * (10 - i);
		resto = 11 - (soma % 11);
		if (resto == 10 || resto == 11)	resto = 0;
		soma = 0;
		for (i = 0; i < 10; i ++) soma += parseInt(num_cpf.charAt(i)) * (11 - i);
		resto2 = 11 - (soma % 11);
		if (resto2 == 10 || resto2 == 11) resto2 = 0;
		if ((resto != parseInt(num_cpf.charAt(9))) || (resto2 != parseInt(num_cpf.charAt(10))))
			{
			alert ('- CPF inválido. \nEntre com o CPF correto.');
    		campoform.value = '';
    		campoform.focus();
			return false;
			}
		else
			{
			campoform.value= num_cpf.substring(0,3) + '.' + num_cpf.substring(3,6) + '.'
			+ num_cpf.substring(6,9) + '-' + num_cpf.substring(9,11);
			return true;
			}
		}
	else
		{
		alert ('- CPF inválido. \nEntre com o CPF correto.');
   		campoform.value = '';
   		campoform.focus();
		return false;
		}	
}
//Validação do cadastro de senha
function validaSenha(){
	if ((document.getElementById("senhaatual").value == document.getElementById("confSenha").value) && (document.getElementById("senhaatual").value.length == document.getElementById("confSenha").value.length)) {		
		return false;
	} else {
		return true;
		document.getElementById("senhaatual").value = "";
		document.getElementById("confSenha").value = "";
		document.getElementById("senha").focus();
	}
}
function validaData(campo){
	var data = document.getElementById(campo);

	hoje = new Date();
    anoAtual = hoje.getFullYear();
   	barras = data.value.split("/");
    if (barras.length == 3){
		dia = barras[1];
        mes = barras[0];
   	    ano = barras[2];
        resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) );
   	    if (!resultado) {
			alert("O formato da data é invalido!");
            data.focus();
            return false;
		}
	}
	else {
		alert("O formato da data é invalido!");
		data.focus();
        return false;
   	}
	return true;
}