//validação do formulario de cadastro ADSL
// ############################# VISA #####################################

function checkCC(creditCard) {  return checkCreditCard(creditCard, "Visa"); }

function valida_visa()
{
     
	    var form = document.form_email_visa;
		var today;
		
		
		if (form.login.value == "") {
			alert('O campo LOGIN é obrigatório!');
			form.login.focus();
			return false;
		}
		if (form.cardOwner.value == "") {
			alert('Digite o nome do portador do cartão!');
			form.cardOwner.focus();
			return false;
		}
		if (form.cardNumber.value == "") {
			alert('Digite o número do cartão!');
			form.cardNumber.focus();
			return false;
		}
		if (!checkCC(form.cardNumber.value)) {
			alert('Número do cartão inválido');
			form.cardNumber.focus();
			return false;
		}
		today = new Date();
		if (((form.cardExpirationYear.value % 100) < (today.getYear() % 100)) || (((form.cardExpirationYear.value % 100) == (today.getYear() % 100)) && (form.cardExpirationMonth.value < (today.getMonth() + 1)))) {
			alert('Data de validade inválida');
			form.cardExpirationMonth.focus();
			return false;
		}
		if (form.cardSecurityCode.value == "") {
			alert('Digite o código de segurança do cartão!');
			form.cardSecurityCode.focus();
			return false;
		}  
	 
	 document.form_email_visa.submit();  	
}





function valida_adsl(){
	 
		   d = document.cadastro_adsl;
           //validar nome
           if((d.razao_social.value == "Razao Social") && (d.fantasia.value == "Nome Fantasia")){
		  		 if (d.nome.value == "Nome"){
                     alert("O campo Nome deve ser preenchido!");
                     d.nome.focus();
                     return false;
					 erro = 1;
           		}
		   		if ((d.cpf.value == "CPF") || (d.cpf.value.length == 1)){
                     alert("O campo CPF deve ser preenchido!");
                     d.cpf.focus();
                     return false;
					 erro = 2;
           		}
		   		erro = 4;
				d.razao_social.value = "";
				d.fantasia.value = "";
				d.cnpj.value = "";
				d.inscricao.value = "";
		   }
			if((d.razao_social.value != "Razao Social") && (d.nome.value == "Nome")){
				if (d.razao_social.value == ""){
                     alert("O campo Razão Social deve ser preenchido!");
                     d.razao_social.focus();
                     return false;
           		}
		   		if (d.cnpj.value == "CNPJ"){
                     alert("O campo CNPJ/CPF deve ser preenchido!");
                     d.cnpj.focus();
                     return false;
           		}
				if (d.fantasia.value == "Nome Fantasia"){
                     d.fantasia.value = "";
           		}
				if (d.inscricao.value == "Inscrição Estadual"){
                     d.inscricao.value = "";
           		}
				d.nome.value = "";
				d.cpf.value = "";
			}
			if (d.email.value == "E-mail"){
                     alert("O campo E-mail deve ser preenchido!");
                     d.email.focus();
                     return false;
			}
			if (d.email.value != "E-mail"){
					var filtro=/^.+@.+\..{2,3}$/;
        			if (filtro.test(d.email.value) == false){
			        	alert("O E-mail informado não é válido");
						d.email.focus();
                    	return false;
					}
			}
			if (d.email_alt.value != "E-mail Alternativo"){
					var filtro2=/^.+@.+\..{2,3}$/;
        			if (filtro2.test(d.email_alt.value) == false){
			        	alert("O E-mail Alternativo informado não é válido");
						d.email_alt.focus();
                    	return false;
					}
			}
			if (d.cidade.value == "Cidade"){
                     alert("O campo Cidade deve ser preenchido!");
                     d.cidade.focus();
                     return false;
			}
			if (d.uf.value == "0"){
                     alert("Selecione o Estado!");
                     d.uf.focus();
                     return false;
			}
			if (d.valor.value == "0"){
                     alert("Selecione o Plano!");
                     d.valor.focus();
                     return false;
			}
			if (d.forma_pagamento.value == "0"){
                     alert("Selecione a Forma de Pagamento!");
                     d.forma_pagamento.focus();
                     return false;
			}
			if (d.login.value == ""){
                     alert("O campo Login deve ser preenchido!");
                     d.login.focus();
                     return false;
			}
			if ((d.senha.value == "") || (d.senha.value == "Sua Senha")){
                     alert("O campo Senha deve ser preenchido!");
                     d.senha.focus();
                     return false;
			}
		/*	if (d.nao.checked == true){
                     alert("O Contrato não foi aceito!");
                     return false;
			}*/
	
					    	
		
		   if (window.document.getElementById("visa").checked == true){
						   
			
				 
				var today;
				
				if (d.cardOwner.value == "") {
					alert('Digite o nome do portador do cartão!');
					form.cardOwner.focus();
					return false;
				}
				if (d.cardNumber.value == "") {
					alert('Digite o número do cartão!');
					d.cardNumber.focus();
					return false;
				}
				if (!checkCC(d.cardNumber.value)) {
					alert('Número do cartão inválido');
					d.cardNumber.focus();
					return false;
				}
				today = new Date();
				if (((d.cardExpirationYear.value % 100) < (today.getYear() % 100)) || (((d.cardExpirationYear.value % 100) == (today.getYear() % 100)) && (form.cardExpirationMonth.value < (today.getMonth() + 1)))) {
					alert('Data de validade inválida');
					d.cardExpirationMonth.focus();
					return false;
				}
				if (d.cardSecurityCode.value == "") {
					alert('Digite o código de segurança do cartão!');
					d.cardSecurityCode.focus();
					return false;
				}  
						   
			}
			
document.getElementById('captcha').src = '../securimage/securimage_show.php?' + Math.random();	
return true;
}
//Somente valores
function SomenteNumero(campo){  
 var digits="0123456789";
 var campo_temp
     for (var i=0;i<campo.value.length;i++){  
         campo_temp=campo.value.substring(i,i+1)   
         if (digits.indexOf(campo_temp)==-1){  
             campo.value = campo.value.substring(0,i);  
         }  
     }  
 }

function valida_contato(){
		   t = document.contato;
           //validar nome
		  		 if ((t.nome.value == "") || (t.nome.value == "Nome")){
                     alert("O campo Nome deve ser preenchido!");
                     t.nome.focus();
                     return false;
					 erro = 1;
           		}
		   		if ((t.email.value == "") || (t.email.value == "E-mail")){
                     alert("O campo E-mail deve ser preenchido!");
                     t.email.focus();
                     return false;
					 erro = 2;
				}
				if ((t.ddd.value == "XX") || (t.ddd.value == "")){
                     alert("O campo DDD deve ser preenchido!");
                     t.ddd.focus();
                     return false;
					 erro = 3;
				}
				if ((t.numero.value == "") || (t.numero.value == "Telefone")){
                     alert("O campo Telefone deve ser preenchido!");
                     t.numero.focus();
                     return false;
					 erro = 4;
				}
				if ((t.texto.value == "") || (t.texto.value == "Digite aqui sua mensagem!")){
                     alert("Digite sua mensagem!");
                     t.texto.focus();
                     return false;
					 erro = 4;
				}
}


function validar(){

    if (window.document.getElementById("cnpj").value == "")	
	{						
				var CPF = window.document.getElementById("cpf").value; // Recebe o valor digitado no campo
				
				// Verifica se o campo é nulo
				if (CPF == '') {
				  alert('CPF é de preenchimento obrigatório!');
				  return false;
				   }
				
				// Aqui começa a checagem do CPF
				var POSICAO, I, SOMA, DV, DV_INFORMADO;
				var DIGITO = new Array(10);
				DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado
				
				// Desemembra o número do CPF na array DIGITO
				for (I=0; I<=8; I++) {
				  DIGITO[I] = CPF.substr( I, 1);
				}
				
				// Calcula o valor do 10º dígito da verificação
				POSICAO = 10;
				SOMA = 0;
				   for (I=0; I<=8; I++) {
					  SOMA = SOMA + DIGITO[I] * POSICAO;
					  POSICAO = POSICAO - 1;
				   }
				DIGITO[9] = SOMA % 11;
				   if (DIGITO[9] < 2) {
						DIGITO[9] = 0;
				}
				   else{
					   DIGITO[9] = 11 - DIGITO[9];
				}
				
				// Calcula o valor do 11º dígito da verificação
				POSICAO = 11;
				SOMA = 0;
				   for (I=0; I<=9; I++) {
					  SOMA = SOMA + DIGITO[I] * POSICAO;
					  POSICAO = POSICAO - 1;
				   }
				DIGITO[10] = SOMA % 11;
				   if (DIGITO[10] < 2) {
						DIGITO[10] = 0;
				   }
				   else {
						DIGITO[10] = 11 - DIGITO[10];
				   }
				
				// Verifica se os valores dos dígitos verificadores conferem
				DV = DIGITO[9] * 10 + DIGITO[10];
				   if (DV != DV_INFORMADO) {
					  alert('CPF inválido');
					  window.document.getElementById("cpf").value = '';
					  window.document.getElementById("cpf").focus();
					  return false;
				   } 
	}

      if (window.document.getElementById("email").value == 
	       window.document.getElementById("email_alt").value)
	   {
		      alert('Email identico ao E-mail Alternativo !!');
			  window.document.getElementById("email_alt").focus();
			  return false;		
	   }   

      if (window.document.getElementById("nome").value == "")	
	   {
			  alert('O nome está nulo.');
			  window.document.getElementById("nome").focus();
			  return false;
       }
	   
	   if (window.document.getElementById("rg").value == "")	
	   {
			  alert('O RG está nulo.');
			  window.document.getElementById("rg").focus();
			  return false;
    	}
		
				
		 if (window.document.getElementById("ddd").value == "")	
	   {
			  alert('O DDD está nulo.');
			  window.document.getElementById("ddd").focus();
			  return false;
    	}
	      if (window.document.getElementById("tel").value == "")	
	   {
			  alert('O Telefone está nulo.');
			  window.document.getElementById("tel").focus();
			  return false;
    	}
	 
	  if (window.document.getElementById("email").value == "")	
	   {
			  alert('O e-mail está nulo.');
			  window.document.getElementById("email").focus();
			  return false;
    	}
      else if (window.document.getElementById("email").value != "")
		  {
		
			// checa se o email tem @
			if (window.document.getElementById("email").value.indexOf('@', 0) == -1)
			{
			  alert('O e-mail está incorreto.');
			  window.document.getElementById("email").focus();
			  return false;
			}
		
			// checa o TAMANHO do campo de e-mail - padrao minimo 7 caracteres
			if (window.document.getElementById("email").value.length < 7)
			{
			  alert('O  e-mail é inválido.');
			  window.document.getElementById("email").focus();
			  return false;
			}
       }
       
	   	  if (window.document.getElementById("endereco").value == "")	
	        {
			  alert('O ENDEREÇO está nulo.');
			  window.document.getElementById("endereco").focus();
			  return false;
    	    }
		   if (window.document.getElementById("bairro").value == "")	
	        {
			  alert('O BAIRRO está nulo.');
			  window.document.getElementById("bairro").focus();
			  return false;
    	    }
			
			 if (window.document.getElementById("complemento").value == "")	
	        {
			  alert('O COMPLEMENTO está nulo.');
			  window.document.getElementById("complemento").focus();
			  return false;
    	    }
			 if (window.document.getElementById("cep").value == "")	
	        {
			  alert('O CEP está nulo.');
			  window.document.getElementById("cep").focus();
			  return false;
    	    }	
	   
	   
     document.form_dominio.submit();  

}

function change_background(tag,classe)
{tag.className = classe;}



// ############################# VISA #####################################


function abre_visa(id){
	
	 if(id == 'visa')
				{
					document.getElementById("box_visa").style.display="block";	
				}
				
	 if(id == 'visa_nao')
				{
					window.document.getElementById("box_visa").style.display="none";	
				}
	
}
