// JavaScript Document
function inicio(){
  window.location = "../index.php";	
}
 function validaCNPJ(CNPJ) {
                 //CNPJ = document.validacao.CNPJID.value;
                 erro = new String;
                if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! \n\n"; 
                 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
                 if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
                 }
                 //substituir os caracteres que não são números
               if(document.layers && parseInt(navigator.appVersion) == 4){
                       x = CNPJ.substring(0,2);
                       x += CNPJ. substring (3,6);
                       x += CNPJ. substring (7,10);
                       x += CNPJ. substring (11,15);
                       x += CNPJ. substring (16,18);
                       CNPJ = x; 
               } else {
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace ("-","");                      CNPJ = CNPJ. replace ("/","");
               }
               var nonNumbers = /\D/;
              if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n"; 
              var a = [];
               var b = new Number;
               var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
			   for (i=0; i<12; i++){
                       a[i] = CNPJ.charAt(i);
                       b += a[i] * c[i+1];
 }
              if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
               b = 0;
               for (y=0; y<13; y++) {
                       b += (a[y] * c[y]); 
               }
               if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
               if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                       erro +="Dígito verificador com problema!";
               }
               if (erro.length > 0){
                       alert(erro);
                       return false;
               } else {
                       alert("CNPJ valido!");
               }
               return true;
       }

	  

function valida_campos(form){

	 if(cadastro.nome.value==""){
	   alert("Campo Nome é obrigatório!");
	    cadastro.nome.focus();
		cadastro.nome.style.backgroundColor ="#FFE4E4";
		cadastro.nome.select();
	   return false;
	 }
     if(cadastro.cpf_cnpj.value==""){
	   alert("Campo CPF é obrigatório!");
	    cadastro.cpf_cnpj.focus();
		cadastro.cpf_cnpj.style.backgroundColor ="#FFE4E4";
		cadastro.cpf_cnpj.select();
	   return false;
	 }
     if(cadastro.cep.value==""){
	   alert("Campo CEP é obrigatório!");
	    cadastro.cep.focus();
		cadastro.cep.style.backgroundColor ="#FFE4E4";
		cadastro.cep.select();
	   return false;
	 }
     if(cadastro.cep.length<9){
	   alert("Campo CEP esta incorreto!");
	    cadastro.cep.focus();
		cadastro.cep.style.backgroundColor ="#FFE4E4";
		cadastro.cep.select();
	   return false;
	 }
 
     if(cadastro.endereco.value==""){
	   alert("Campo Endereço é obrigatório!");
	    cadastro.endereco.focus();
		cadastro.endereco.style.backgroundColor ="#FFE4E4";
		cadastro.endereco.select();
	   return false;
	 }	 	
     if(cadastro.bairro.value==""){
	   alert("Campo Bairro é obrigatório!");
	    cadastro.bairro.focus();
		cadastro.bairro.style.backgroundColor ="#FFE4E4";
		cadastro.bairro.select();
	   return false;
	 }	 	 
     if(cadastro.cidade.value==""){
	   alert("Campo Cidade é obrigatório!");
	    cadastro.cidade.focus();
		cadastro.cidade.style.backgroundColor ="#FFE4E4";
		cadastro.cidade.select();
	   return false;
	 }
     if(cadastro.telefone.value==""){
	   alert("Campo Telefone é obrigatório!");
	    cadastro.telefone.focus();
		cadastro.telefone.style.backgroundColor ="#FFE4E4";
		cadastro.telefone.select();
	   return false;
	 }
     if(cadastro.telefone.length<13){
	   alert("Campo Telefone é obrigatório!");
	    cadastro.telefone.focus();
		cadastro.telefone.style.backgroundColor ="#FFE4E4";
		cadastro.telefone.select();
	   return false;
	 }
     if(cadastro.email.value==""){
	   alert("Campo E-mail é obrigatório!\nImportante para envio de boleto e Login.");
	    cadastro.email.focus();
		cadastro.email.style.backgroundColor ="#FFE4E4";
		cadastro.email.select();
	   return false;
	 }
     if(cadastro.senha.value==""){
	   alert("Campo Senha é obrigatório!");
	    cadastro.senha.focus();
		cadastro.senha.style.backgroundColor ="#FFE4E4";
		cadastro.senha.select();
	   return false;
	 }
     if(cadastro.rept_senha.value==""){
	   alert("Campo Senha é obrigatório!");
	    cadastro.rept_senha.focus();
		cadastro.rept_senha.style.backgroundColor ="#FFE4E4";
		cadastro.rept_senha.select();
	   return false;
	 }	
     if(cadastro.rept_senha.value!=cadastro.senha.value){
	   alert("Campo Repetir senha diferente da Senha!");
	    cadastro.rept_senha.focus();
		cadastro.rept_senha.style.backgroundColor ="#FFE4E4";
		cadastro.rept_senha.select();
	   return false;
	 }	 
}
function valida_campos2(form){

	 if(cadastro.nome.value==""){
	   alert("Campo Nome é obrigatório!");
	    cadastro.nome.focus();
		cadastro.nome.style.backgroundColor ="#FFE4E4";
		cadastro.nome.select();
	   return false;
	 }
	 if(cadastro.pessoa.value==""){
	   alert("Campo Tipo Pessoa é obrigatório!");
	   return false;
	 }
     if(cadastro.cpf_cnpj.value==""){
	   alert("Campo CPF é obrigatório!");
	    cadastro.cpf_cnpj.focus();
		cadastro.cpf_cnpj.style.backgroundColor ="#FFE4E4";
		cadastro.cpf_cnpj.select();
	   return false;
	 }
     if(cadastro.cep.value==""){
	   alert("Campo CEP é obrigatório!");
	    cadastro.cep.focus();
		cadastro.cep.style.backgroundColor ="#FFE4E4";
		cadastro.cep.select();
	   return false;
	 }
     if(cadastro.cep.length<9){
	   alert("Campo CEP esta incorreto!");
	    cadastro.cep.focus();
		cadastro.cep.style.backgroundColor ="#FFE4E4";
		cadastro.cep.select();
	   return false;
	 }
 
     if(cadastro.endereco.value==""){
	   alert("Campo Endereço é obrigatório!");
	    cadastro.endereco.focus();
		cadastro.endereco.style.backgroundColor ="#FFE4E4";
		cadastro.endereco.select();
	   return false;
	 }	 	
     if(cadastro.bairro.value==""){
	   alert("Campo Bairro é obrigatório!");
	    cadastro.bairro.focus();
		cadastro.bairro.style.backgroundColor ="#FFE4E4";
		cadastro.bairro.select();
	   return false;
	 }	 	 
     if(cadastro.cidade.value==""){
	   alert("Campo Cidade é obrigatório!");
	    cadastro.cidade.focus();
		cadastro.cidade.style.backgroundColor ="#FFE4E4";
		cadastro.cidade.select();
	   return false;
	 }
     if(cadastro.telefone.value==""){
	   alert("Campo Telefone é obrigatório!");
	    cadastro.telefone.focus();
		cadastro.telefone.style.backgroundColor ="#FFE4E4";
		cadastro.telefone.select();
	   return false;
	 }
     if(cadastro.telefone.length<13){
	   alert("Campo Telefone é obrigatório!");
	    cadastro.telefone.focus();
		cadastro.telefone.style.backgroundColor ="#FFE4E4";
		cadastro.telefone.select();
	   return false;
	 }
     if(cadastro.email.value==""){
	   alert("Campo E-mail é obrigatório!\nImportante para envio de boleto e Login.");
	    cadastro.email.focus();
		cadastro.email.style.backgroundColor ="#FFE4E4";
		cadastro.email.select();
	   return false;
	 }
     if(cadastro.senha.value==""){
	   alert("Campo Senha é obrigatório!");
	    cadastro.senha.focus();
		cadastro.senha.style.backgroundColor ="#FFE4E4";
		cadastro.senha.select();
	   return false;
	 }
     if(cadastro.rept_senha.value==""){
	   alert("Campo Senha é obrigatório!");
	    cadastro.rept_senha.focus();
		cadastro.rept_senha.style.backgroundColor ="#FFE4E4";
		cadastro.rept_senha.select();
	   return false;
	 }	
     if(cadastro.rept_senha.value!=cadastro.senha.value){
	   alert("Campo Repetir senha diferente da Senha!");
	    cadastro.rept_senha.focus();
		cadastro.rept_senha.style.backgroundColor ="#FFE4E4";
		cadastro.rept_senha.select();
	   return false;
	 }	 
}

function cria_socios(campo){

var num = campo.value;
var valor2="";

 for (i=1;i<=num;i++){
 //  valor ='<table bgcolor=#CCF0FF><tr><td><div align="right">Nome:</div></td><td><input type="text" name="partcipante'+i+'" size="40"></td><td><select name="estudante'+i+'"><option value="N">Não Estudante</option><option values="S" onClick="javascript getElementById("alert").hidden=false;">Estudante</option></select></td></tr></table><br>'; 
//   valor2 = valor2+valor;
   
 }
 document.getElementById("campos_socios").innerHTML = valor2;
 
}

function alerta(r){
var e = r.value;

  if(e=="S"){
    document.getElementById("alerta").style.display ="block";
  }
  if(e=="N"){
    document.getElementById("alerta").style.display ="none";
  }
}

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
        return true;
      } 
    }
    else {
      return true;
    }
  }

function cria_participantes(campo){

var num = campo.value;
var valor2="";

 for (i=1;i<=num;i++){
   valor ='<br><table><tr bgcolor="#E0F6ED"><td><div align="right">*<b>Nome Completo:</b></div></td><td><input type="text" name="participante'+i+'" size="40" class="inputForm" onKeyUp="javascript:this.value=this.value.toUpperCase();"></td></tr><tr><td><div align="right">*<b>E-mail:</b></div></td><td><input type="text" name="email'+i+'" size="40" class="inputForm"></td></tr><tr bgcolor="#E0F6ED"><td><div align="right">*<b>Estudante?</b></div></td><td><input name="estudante'+i+'" type="radio" value="S" onClick="alerta(this);"><b>Sim  <input name="estudante'+i+'" type="radio" value="N" checked onClick="alerta(this);">Não</b></td></tr></table><br>'; 
   valor2 = valor2+valor;
   
 }
 if(valor2!=""){
 document.getElementById("campos_socios").innerHTML = valor2+'<input name="enviar"  type="submit" value="Confirmar Participantes>>" class="btn">';
 }
 else
  document.getElementById("campos_socios").innerHTML = valor2

}
function cria_participantes2(campo){

var num = campo.value;
var valor2="";

 for (i=1;i<=num;i++){
   valor ='<br><table><tr bgcolor="#E0F6ED"><td>*<div align="right"><b>Nome Completo:</b></div></td><td><input type="text" name="participante'+i+'" size="40" class="inputForm"></td></tr><tr bgcolor="#E0F6ED"><td>*<div align="right"><b>Estudante?</b></div></td><td><input name="estudante'+i+'" type="radio" value="S" onClick="alerta(this);"><b>Sim  <input name="estudante'+i+'" type="radio" value="N" checked onClick="alerta(this);">Não</b></td></tr></table><br>'; 
   valor2 = valor2+valor;
   
 }
 if(valor2!=""){
 document.getElementById("campos_socios").innerHTML = valor2;
 }
 else
  document.getElementById("campos_socios").innerHTML = valor2

}

function cria_participantes3(campo){

var num = campo.value;
var valor2="";

 for (i=1;i<=num;i++){
   valor ='<br><table><tr bgcolor="#E0F6ED"><td><div align="right">*<b>Nome Completo:</b></div></td><td><input type="text" name="participante'+i+'" size="40" class="inputForm"></td></tr><tr><td><div align="right">*<b>E-mail:</b></div></td><td><input type="text" name="email'+i+'" size="40" class="inputForm"></td></tr></table><br>'; 
   valor2 = valor2+valor;
   
 }
 if(valor2!=""){
 document.getElementById("campos_socios").innerHTML = valor2+'<input name="enviar"  type="submit" value="Confirmar Participantes>>" class="btn">';
 }
 else
  document.getElementById("campos_socios").innerHTML = valor2

}
function boleto(){
   
   document.getElementById("myForm").submit();

}


//ajax cpf  cnpj
var xmlHttp

function verifica_cpf(str)
{
if (str.length==0)
  { 
  document.getElementById("retorno_cpf").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="dados.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("retorno_cpf").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


