// JavaScript Document
 if (location.href.indexOf("arteccom.com.br") > -1) {
//	  document.location.href='http://www.foruminternacional.com.br/inscricoes_bra.php';
  }

  function esqueci_senha()  {
	 if ((document.form_ja_cad.email.value.indexOf("@",0))== -1 || 
  (document.form_ja_cad.email.value.indexOf("@",0)) < 1 || 
  (document.form_ja_cad.email.value.indexOf(".",0))== -1 ||
  (document.form_ja_cad.email.value.indexOf("@",0))== document.form_ja_cad.email.value.length - 1 ||
  (document.form_ja_cad.email.value.indexOf(".",0))== document.form_ja_cad.email.value.length - 1)  {
	    alert("Informe seu email corretamente para o reenvio da senha");
		document.form_ja_cad.email.focus();
	    document.form_ja_cad.email.select();
	 }
	 else {
		document.getElementById("ajax_esqueci_senha").innerHTML = "";
//		if (location.href.indexOf("arteccom.com.br") == -1) {
			url = "esqueci_senha.php?email=" + document.form_ja_cad.email.value;
//		}
//		else  {
	//		url = "http://www.arteccom.com.br/encontro/ewd-14/wp-content/themes/ewd-14/esqueci_senha.php?email=" + document.form2.email.value;
		//}
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4) {
			document.getElementById("ajax_esqueci_senha").innerHTML = xmlhttp.responseText;
	    }
		}
		 xmlhttp.send(null)
	}
  }
  
  function esqueci_senha2()  {
	 if ((document.form2.login.value.indexOf("@",0))== -1 || 
  (document.form2.login.value.indexOf("@",0)) < 1 || 
  (document.form2.login.value.indexOf(".",0))== -1 ||
  (document.form2.login.value.indexOf("@",0))== document.form2.login.value.length - 1 ||
  (document.form2.login.value.indexOf(".",0))== document.form2.login.value.length - 1)  {
	    alert("Informe seu email corretamente para o reenvio da senha");
		document.form2.login.focus();
	    document.form2.login.select();
	 }
	 else {
		document.getElementById("ajax_esqueci_senha").innerHTML = "";
//		if (location.href.indexOf("arteccom.com.br") == -1) {
			url = "esqueci_senha.php?email=" + document.form2.login.value;
//		}
//		else  {
	//		url = "http://www.arteccom.com.br/encontro/ewd-14/wp-content/themes/ewd-14/esqueci_senha.php?email=" + document.form2.email.value;
		//}
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4) {
			document.getElementById("ajax_esqueci_senha").innerHTML = '<br>' + xmlhttp.responseText;
	    }
		}
		 xmlhttp.send(null)
	}
  }


function outro_conhec() {
	if (document.form1.conhecimento.value =='Outra Newsletter' || document.form1.conhecimento.value =='Outro blog' || document.form1.conhecimento.value =='Outro site')  {
		document.getElementById("outro_conhecimento").style.display = '';
	}
	else {
		document.getElementById("outro_conhecimento").style.display = 'none';
	}
	
}

function valida_data()  {
	 if (document.form1.dd.value && document.form1.mm.value && document.form1.aaaa.value)   {
         hoje = new Date();
         anoAtual = hoje.getFullYear();
		 data_ = document.form1.dd.value + "/" + document.form1.mm.value + "/" + document.form1.aaaa.value;
         barras = data_.split("/");
         if (barras.length == 3){
                   dia = barras[0];
                   mes = barras[1];
                   ano = barras[2];
                   resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual && ano >= 1900));
                   if (!resultado) {
                             alert("Formato de data inválido! Favor utilizar quatro dígitos. Ex: 1975");
		 				     document.form1.dd.value = '';
		 				     document.form1.mm.value = '';
		 				     document.form1.aaaa.value = '';
                             document.form1.dd.focus();
                             return false;
                   }
         } //else {
         //          alert("A data é inválida!");
		//		   c_data.value = '';
           //        c_data.focus();
            //       return false;
         //}
		 if (document.form1.dd.value.length == 1) {
			 document.form1.dd.value = "0" + document.form1.dd.value; 
		 }
		 if (document.form1.mm.value.length == 1) {
			 document.form1.mm.value = "0" + document.form1.mm.value; 
		 }
	  }
}


function Verifica_campo_CPF(campo) {
var CPF = campo.value; // Recebe o valor digitado no campo

// 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(' Seu CPF parece estar incorreto.');
      campo.value = '';
      campo.focus();
      return false;

   } 
}
//-->


function bloqueia_copia(valor,nome_campo)  {
    valor1 = valor.substr(2,valor.length -2);
    for(i=0;i<5;i++) {
		valor1 = valor1.replace(".","");
		valor1 = valor1.replace(",","");
	}
	if (isNaN(valor1))  {
		alert("Digite apenas números neste campo");
		nome_campo.value = "";
		nome_campo.focus();
	}
}		
		
function OnlyNumbers(e) { 

    if (window.event) //IE 
    { 
    tecla = e.keyCode; 
    } 

   else if (e.which) //FF 
   { 
    tecla = e.which; 
   } 
    //teclas dos numemros(0 - 9) de 48 a 57
   //techa==8 é para permitir o backspace funcionar para apagar
    
       if ( (tecla >= 48 && tecla <= 57)||(tecla == 8 ) ) {
               return true;
          }
          else {
               return false;
          }
}


function formatar(src, mask) 
{
  var i = src.value.length;
  var saida = mask.substring(0,1);
  var texto = mask.substring(i)
if (texto.substring(0,1) != saida) 
  {
	src.value += texto.substring(0,1);
  }
}

function PadDigits(n) {

       n = n.toString();
       var pd = '';
       if (2 > n.length) { 
           for (i=0; i < (2 - n.length); i++) { 
               pd += '0'; 
           } 
       } 
       return pd + n.toString();
} 


function checar_form() {
  if (!document.form1.email.value)  {
     alert("O campo email é de preenchimento obrigatório");
	 document.form1.email.focus();
  }
  else if ((document.form1.email.value.indexOf("@",0))== -1 || 
  (document.form1.email.value.indexOf("@",0)) < 1 || 
  (document.form1.email.value.indexOf(".",0))== -1 ||
  (document.form1.email.value.indexOf("@",0))== document.form1.email.value.length - 1 ||
  (document.form1.email.value.indexOf(".",0))== document.form1.email.value.length - 1) {
    alert("Formato de e-mail incorreto");
	document.form1.email.focus();
    document.form1.email.select();
  }
  else if (!document.form1.senha.value)  {
     alert("O campo senha é de preenchimento obrigatório");
	 document.form1.senha.focus();
  }
  else if (document.form1.senha.value.length < 5)  {
     alert("Informe sua senha com no mínimo 5 caracteres");
	 document.form1.senha.focus();
  }
  else if (document.form1.senha.value != document.form1.re_senha.value)  {
     alert("Redigite sua senha corretamente");
	 document.form1.senha.focus();
  }
//  else if (!document.form1.nome.value)  {
//     alert("Informe seu nome completo");
//	 document.form1.nome.focus();
//  }
//  else if (document.form1.tipo_participacao.value == 2 && document.getElementById("sis_qtde_int").style.display == '') { //Se for grupos and não escolheu a quantidade de integrantes...
//    alert("Informe os integrantes do grupo!");
//	document.form1.qtde_integ.focus();	
//  }
//  else if (!checa_int_grupo()) {
	
//  }
  else if (!document.form1.nome_cracha.value)  {
     alert("Informe o nome que vai constar no seu crachá do evento");
	 document.form1.nome_cracha.focus();
  }
  else if (document.form1.nome_cracha.value.indexOf("@",0) > -1 || document.form1.nome_cracha.value.indexOf("#",0) > -1)  {
     alert("Não são permitidos caracteres especiais no nome (@ ou #)");
	 document.form1.nome_cracha.focus();
  }
  else if (!document.form1.dd.value)  {
     alert("Informe o dia do seu nascimento");
	 document.form1.dd.focus();
  }
  else if (!document.form1.mm.value)  {
     alert("Informe o mês do seu nascimento");
	 document.form1.mm.focus();
  }
  else if (!document.form1.aaaa.value)  {
     alert("Informe o ano do seu nascimento");
	 document.form1.aaaa.focus();
  }
  else if (!document.form1.cpf.value)  {
     alert("Informe seu CPF");
	 document.form1.cpf.focus();
  }
  else if (!document.form1.ddd.value)  {
     alert("Informe o DDD do seu telefone");
	 document.form1.ddd.focus();
  }
  else if (!document.form1.telefone.value)  {
     alert("Informe o seu telefone");
	 document.form1.telefone.focus();
  }
  else if (!document.form1.cep.value)  {
     alert("Informe o seu CEP");
	 document.form1.cep.focus();
  }
  else if (!document.form1.endereco.value)  {
     alert("Informe o seu endereço");
	 document.form1.endereco.focus();
  }
  else if (!document.form1.numero.value)  {
     alert("Informe o número do seu endereço. Caso não tenha, informe s/n.");
	 document.form1.numero.focus();
  }
  else if (!document.form1.bairro.value)  {
     alert("Informe o seu bairro");
	 document.form1.bairro.focus();
  }
  else if (!document.form1.estado.value)  {
     alert("Informe o seu estado");
	 document.form1.estado.focus();
  }
  else if (!document.form1.municipio.value)  {
     alert("Informe o seu município");
	 document.form1.municipio.focus();
  }
  else if (!document.form1.ocupacao.value)  {
     alert("Informe a ocupação");
	 document.form1.ocupacao.focus();
  }
  else if (!document.form1.escolaridade.value)  {
     alert("Informe a escolaridade");
	 document.form1.escolaridade.focus();
  }
  else if (!document.form1.conhecimento.value)  {
     alert("Informe como conheceu o evento");
	 document.form1.conhecimento.focus();
  }
  else if (!document.form1.areas_atuacao.value)  {
     alert("Informe as áreas de atuação");
	 document.form1.areas_atuacao.focus();
  }
  else {
    document.form1.submit();
  }
}

function validar_tp_part() {
	var Campo;
	for (i=0; i<document.form1.tipo_participacao.length; i++) {
		if (document.form1.tipo_participacao[i].checked)  {
		Campo= true; 
		}
	}
	if (!Campo){
		alert("Informe o tipo de inscrição!");
		return false;
	}
	else {
		return true;
	}
}


function checa_int_grupo() {
//	alert(document.form1.sis_qtde_integrantes.value);
   if (document.form1.tipo_participacao.value == '2') { //Se o tipo de participação for grupos
	 for(i=1;i<=document.form1.sis_qtde_integrantes.value;i++){
			if(document.getElementById("nome_"+i).value == ""){
				alert("Informe o nome do integrante "+i+".");
				document.getElementById("nome_"+i).focus();
				return false;
			}
			
			//if(document.getElementById("empresa_"+i).value == ""){
				//alert("Informe a empresa do integrante "+document.getElementById("empresa_"+i).value+".");
				//document.getElementById("empresa_"+i).focus();
				//return false;
			//}
			
			if(document.getElementById("email_"+i).value == ""){
				alert("Informe o email do integrante "+document.getElementById("nome_"+i).value+".");
				document.getElementById("email_"+i).focus();
				return false;
			}
			
			if ((document.getElementById("email_"+i).value.indexOf("@",0))== -1 || 
				  (document.getElementById("email_"+i).value.indexOf("@",0)) < 1 || 
				  (document.getElementById("email_"+i).value.indexOf(".",0))== -1 ||
				  (document.getElementById("email_"+i).value.indexOf("@",0))== document.getElementById("email_"+i).value.length - 1 ||
				  (document.getElementById("email_"+i).value.indexOf(".",0))== document.getElementById("email_"+i).value.length - 1) {
				  alert("Formato de e-mail incorreto do integrante  "+document.getElementById("nome_"+i).value+".");
				  document.getElementById("email_"+i).focus();
				  document.getElementById("email_"+i).select();
				  return false;
			}
			
			if(document.getElementById("areas_atuacao_"+i).value == ""){
				alert("Informe a área de atuação do integrante "+document.getElementById("nome_"+i).value+".");
				document.getElementById("areas_atuacao_"+i).focus();
				return false;
			}
	
			if(document.getElementById("escolaridade_"+i).value == ""){
				alert("Informe a escolaridade do integrante "+document.getElementById("nome_"+i).value+".");
				document.getElementById("escolaridade_"+i).focus();
				return false;
			}
	  }
	  return true;
   }
   else {
	  return true;
   }
}

var sis_c = 0;
function exibe_oculta(nome_div) {
	sis_c = sis_c + 1;
	if (sis_c % 2 ==0) {
		document.getElementById(nome_div).style.display = 'none';
	}
	else {
		document.getElementById(nome_div).style.display = '';
	}
}

function checa_re_senha()  {
	if (document.form1.senha.value != document.form1.re_senha.value) {
		alert('Redigite sua senha corretamente.');
		document.form1.senha.value = '';
		document.form1.re_senha.value = '';
	}
}


var data1 = '';
var data2 = '';
var data3 = '';

function envia_form(tp_part) {
	document.form1.tp_inscricao.value = tp_part;
	document.form1.submit();
}

function pula_campo(campo) {
	  if (campo.name == 'dd' && campo.value.length == 2) {
		 document.form1.mm.focus();
	  }
	  if (campo.name == 'mm' && campo.value.length == 2) {
		 document.form1.aaaa.focus();
	  }
	  if (campo.name == 'aaaa' && campo.value.length == 4) {
		 document.form1.cpf.focus();
	  }
	  if (campo.name == 'cpf' && campo.value.length == 11) {
		 document.form1.ddd.focus();
	  }
	  if (campo.name == 'ddd' && campo.value.length == 2) {
		 document.form1.telefone.focus();
	  }
	  if (campo.name == 'telefone' && campo.value.length == 8) {
		 document.form1.ddd2.focus();
	  }
	  if (campo.name == 'ddd2' && campo.value.length == 2) {
		 document.form1.telefone_celular.focus();
	  }
	  if (campo.name == 'telefone_celular' && campo.value.length == 8) {
		 document.form1.cep.focus();
	  }
}


