// JavaScript Document

// validação para o formulário de clientes
function CheckFormcliente() {

if (document.form1.email.value == ""){
alert("Por favor informe seu Email");
document.form1.email.focus(); 
return false;
}
if (document.form1.senha.value == ""){
alert("Por favor cadastre sua Senha de Acesso para Cadastro Pessoal da Sollus");
document.form1.senha.focus(); 
return false;
}
if (document.form1.nome.value == ""){
alert("Por favor informe seu Nome ou Razão Social");
document.form1.nome.focus(); 
return false;
}
if (document.form1.endereco.value == ""){
alert("Por favor informe seu Endereço.");
document.form1.endereco.focus(); 
return false;
}
if (document.form1.cep.value == ""){
alert("Por favor informe o CEP.");
document.form1.cep.focus(); 
return false;
}
if (document.form1.bairro.value == ""){
alert("Por favor informe o Bairro.");
document.form1.bairro.focus(); 
return false;
}
if (document.form1.cidade.value == ""){
alert("Por favor informe sua Cidade.");
document.form1.cidade.focus(); 
return false;
}
if (document.form1.estado.value == ""){
alert("Por favor informe o Estado.");
document.form1.estado.focus(); 
return false;
}
if (document.form1.ddd.value == ""){
alert("Por favor informe DDD.");
document.form1.ddd.focus(); 
return false;
}
if (document.form1.tel.value == ""){
alert("Por favor informe DDD.");
document.form1.tel.focus(); 
return false;
}
if (document.form1.cpf.value == "" && document.form1.cnpj.value == ""){
alert("Por favor informe seu CPF ou CNPJ.");
document.form1.cpf.focus(); 
return false;
}

return true
}




function validarCPF(campo){
   var cpf = document.form1.cpf.value;

   
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
    
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  window.alert("CPF inválido. Tente novamente.");
	  	 document.form1.cpf.focus(); 
	  return false;
   }

   soma = 0;
   for(i = 0; i < 9; i++)
   	 soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(9))){
	 window.alert("CPF inválido. Tente novamente.");
	 	 document.form1.cpf.focus(); 
	 return false;
   }
   soma = 0;
   for(i = 0; i < 10; i ++)
	 soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(10))){
     window.alert("CPF inválido. Tente novamente.");
	 	 document.form1.cpf.focus(); 
	 return false;
   }
   return true;
 }
 
 function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }
 

 function ValidaCNPJ(cnpj) {

  var i = 0;
  var l = 0;
  var strNum = "";
  var strMul = "6543298765432";
  var character = "";
  var iValido = 1;
  var iSoma = 0;
  var strNum_base = "";
  var iLenNum_base = 0;
  var iLenMul = 0;
  var iSoma = 0;
  var strNum_base = 0;
  var iLenNum_base = 0;

  if (cnpj == "" && document.form1.cpf.value == "")
        return ("Preencha o campo CNPJ.");

  l = cnpj.length;
  for (i = 0; i < l; i++) {
        caracter = cnpj.substring(i,i+1)
        if ((caracter >= '0') && (caracter <= '9'))
           strNum = strNum + caracter;
  };

  if(strNum.length != 14 && document.form1.cpf.value == "")
        return ("CNPJ deve conter 14 caracteres.");

  strNum_base = strNum.substring(0,12);
  iLenNum_base = strNum_base.length - 1;
  iLenMul = strMul.length - 1;
  for(i = 0;i < 12; i++)
        iSoma = iSoma +
                        parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
                        parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10);

  iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
  if(iSoma == 11 || iSoma == 10)
        iSoma = 0;

  strNum_base = strNum_base + iSoma;
  iSoma = 0;
  iLenNum_base = strNum_base.length - 1
  for(i = 0; i < 13; i++)
        iSoma = iSoma +
                        parseInt(strNum_base.substring((iLenNum_base-i),(iLenNum_base-i)+1),10) *
                        parseInt(strMul.substring((iLenMul-i),(iLenMul-i)+1),10)

  iSoma = 11 - (iSoma - Math.floor(iSoma/11) * 11);
  if(iSoma == 11 || iSoma == 10)
        iSoma = 0;
  strNum_base = strNum_base + iSoma;
  if(strNum != strNum_base)
        return ("CNPJ inválido.");

  return ("CNPJ validado.");

}