// JavaScript Document

document.write("<script src='jquery/jquery.js' type='text/javascript'></script><script src='jquery/scroll/jquery.scrollTo.js' type='text/javascript'></script> ");

function curso(what) {
   if(what.value != '') { 
      var opcao = what.value; 
	  nivel = document.getElementById('nivel').value;
	   
	  location.href="index.php?"+opcao+"&nivel="+nivel; 
   }  
} 

function alteraCursoNivel(campoNivel, curso){
    campoNivel.value;
    location.href="index.php?cod="+curso+"&nivel="+campoNivel.value;
}



function caadata() {
	 
    if (document.relatorio.data_inicio.value == "") {
	    window.alert("Escolha uma data inicial.");
		 document.relatorio.data_inicio.focus();	
		return false;
	}
    if (document.relatorio.data_fim.value.length < 2) {
	    window.alert("Escolha uma data final.");
		 document.relatorio.data_fim.focus();
		return false;
	}
	
}

function aceite() { 

if (document.forms[0].checkbox[0].checked == false){
	  alert('É necessário estar de acordo com os "TERMOS DO CONTRATO".');
	  document.forms[0].checkbox[0].focus();	 
} else 
if (document.forms[0].checkbox[1].checked == false){
	  alert('É necessário estar de acordo com os "DADOS CADASTRAIS".');
	  document.forms[0].checkbox[1].focus();
} else 

if (document.forms[0].txtsenha.value == '') {
	  alert('O campo senha não pode estar em branco.');
	  document.forms[0].txtsenha.focus();
} else 	  
	   

 if ((document.forms[0].checkbox[0].checked == true) &&  (document.forms[0].checkbox[1].checked == true ))
 <!--(document.forms[0].rdSMS[0].checked == false ) &&  (document.forms[0].rdSMS[1].checked == false ) -->
	 {
	  <!--alert('SIM!!!.');-->
	  <!--var id = document.getElementById('nn1').value;-->
	  document.forms[0].action = 'formulario_contratop.php?cod=as&ins='+document.getElementById('nn1').value+'&cc='+document.getElementById('cod_curso').value+'&s='+document.getElementById('senha').value;
	 //alert(document.forms[0].action = 'formulario_contratop.php?cod=as&ins='+document.getElementById('nn1').value+'&cc='+document.getElementById('cod_curso').value+'&s='+document.getElementById('senha').value)
      document.forms[0].submit();
	 	return true;
	  }
} 



function aceiteTeste() { 

if (document.forms[0].checkbox[0].checked == false){
	  alert('É necessário estar de acordo com os "TERMOS DO CONTRATO".');
	  document.forms[0].checkbox[0].focus();	 
} else 
if (document.forms[0].checkbox[1].checked == false){
	  alert('É necessário estar de acordo com os "DADOS CADASTRAIS".');
	  document.forms[0].checkbox[1].focus();
} else 

if (document.forms[0].txtsenha.value == '') {
	  alert('O campo senha não pode estar em branco.');
	  document.forms[0].txtsenha.focus();
} else 	  
	   

 if ((document.forms[0].checkbox[0].checked == true) &&  (document.forms[0].checkbox[1].checked == true ))
 <!--(document.forms[0].rdSMS[0].checked == false ) &&  (document.forms[0].rdSMS[1].checked == false ) -->
	 {
	  <!--alert('SIM!!!.');-->
	  <!--var id = document.getElementById('nn1').value;-->
	  document.forms[0].action = 'formulario_contratop_teste.php?cod=as&ins='+document.getElementById('nn1').value+'&cc='+document.getElementById('cod_curso').value+'&s='+document.getElementById('senha').value;
	 //alert(document.forms[0].action = 'formulario_contratop.php?cod=as&ins='+document.getElementById('nn1').value+'&cc='+document.getElementById('cod_curso').value+'&s='+document.getElementById('senha').value)
      document.forms[0].submit();
	 	return true;
	  }
} 



function aceiteextensao() { 
  
if (document.forms[0].checkbox[0].checked == false){
	  alert('É necessário estar de acordo com os "TERMOS DO CONTRATO".');
	  document.forms[0].checkbox[0].focus();	 
} else 
if (document.forms[0].checkbox[1].checked == false){
	  alert('É necessário estar de acordo com os "DADOS CADASTRAIS".');
	  document.forms[0].checkbox[1].focus();
} else 

if (document.forms[0].txtsenha.value == '') {
	  alert('O campo senha não pode estar em branco.');
	  document.forms[0].txtsenha.focus();
} else {	  

 if ((document.forms[0].checkbox[0].checked == true) &&  (document.forms[0].checkbox[1].checked == true ))
	 {
	  <!--alert('SIM!!!.');-->
	  <!--var id = document.getElementById('nn1').value;-->
	  document.forms[0].action = "formulario_contratoe.php?cod=as&ins="+document.getElementById('nn1').value+"&cc="+document.getElementById('cod_curso').value+"&s="+document.getElementById('senha').value+"&seq_ministrado="+document.getElementById('seq_ministrado').value;
	    //colocado para apresentar mensagem aos cursos de lojas
		setTimeout(function(){alert('Seu Cadastro foi efetuado com sucesso.');},1000);
		//setTimeout(function(){parent.document.getElementById('divMensagemConclusao').style.display='block'},1000);
		//setTimeout( function(){ mostrarDivMensagem();},1000);
		document.forms[0].submit();
	 	return true;
	  }
  }
} 

/*function mostrarDivMensagem(){
	parent.$('#divMensagemConclusao').show();
	$.scrollTo(parent.document.getElementById('divMensagemConclusao'), 1000); 
	$.scrollTo.defaults;
}*/

function boleto() {

	var minha_image = "<?= $string ?>";
	alert(minha_image);

	//location.href = "bloquete/bloquete.php?nome=$string;";
	//document.forms[0].action = '/bloquete/bloquete.php<? print $string; ?>';
    //document.forms[0].submit();
	 	return false;
}

function confirmacaosenha(){ 
 if (document.frmEntra.txtsenha.value == '') {
	  alert('O campo senha não pode estar em branco.');
	  document.frmEntra.txtsenha.focus();
	  
	  } else if(document.frmEntra.txtsenha.value != document.frmEntra.txtsenhaconfirmacao.value) {
		alert('Certifique-se que a confirmação da senha está correta!'); 
		 document.frmEntra.txtsenhaconfirmacao.focus();
		 
		} else {
		
		document.frmEntra.action = '';
 	 	document.frmEntra.submit();
	 	return true;
	 }
 }
 
function senha(){
    if(document.form1.cpf.value == "") { 
		alert("O CPF não pode ser vazio.");
		document.form1.cpf.focus();
	}else  if(!validaCPF(limpaCPF(document.form1.cpf.value))) {
		document.form1.cpf.focus();
		return;
	}else if (document.form1.txtsenha.value == '') {
	    alert('O campo senha não pode estar em branco.');
        document.form1.txtsenha.focus();
	} else {
        document.form1.action = '';
 	 	document.form1.submit();
	 	return true;
	}
}

function caa(){
if(document.form1.cpf.value == "") { 
		alert("O CPF não pode ser vazio.");
		document.form1.cpf.focus();
	
	 } 
	 
	else  if(!validaCPF(limpaCPF(document.form1.cpf.value))) {
		document.form1.cpf.focus();
		return;
		
	} else {	
		 document.form1.action = '';
 	 	document.form1.submit();
	 	return true;
	 }
}
  

function aluno(){
	 document.form1.action = 'formulario_3.php';
 	 document.form1.submit();
}



function enviaFormulario() {

if(document.form1.cursos.selectedIndex == 0){
	alert("Escolha um curso.");
		document.form1.cursos.focus();
	
	} else 


 if(document.form1.cpf.value == "") { 
		alert("O CPF não pode ser vazio.");
		document.form1.cpf.focus();
	
	 } 
	 
	else  if(!validaCPF(limpaCPF(document.form1.cpf.value))) {
		document.form1.cpf.focus();
		return;
		
	}
	 else {
		
		 document.form1.action = '';
 	 	document.form1.submit();
	 	return true;
	 }

}

function enviaemail_senha() {

 if(document.form1.cpf.value == "") { 
		alert("O CPF não pode ser vazio.");
		document.form1.cpf.focus();
	
	 } 
	 
	else  if(!validaCPF(limpaCPF(document.form1.cpf.value))) {
		document.form1.cpf.focus();
		return;
		
	}
	 else {
		
		 document.form1.action = '';
 	 	document.form1.submit();
	 	return true;
	 }

}

function enviaFormulariosenha() {

if(document.form1.cursos.selectedIndex == 0){
	alert("Escolha um curso.");
		document.form1.cursos.focus();
	
	} else 

if(document.form1.cpf.value == "") { 
		alert("O CPF não pode ser vazio.");
		document.form1.cpf.focus();
	
	 } 
	 
	else  if(!validaCPF(limpaCPF(document.form1.cpf.value))) {
		document.form1.cpf.focus();
		return;
		
	}
else if(document.form1.senha.value == "") { 
		alert("O campo senha não pode estar vazio.");
		document.form1.senha.focus();
	 } 	
	 else {
		document.form1.action = 'controle_senha.php';
 	 	document.form1.submit();
	 	return true;
	 }

}

		function blockCHAR()	{
		cpf = document.form1.cpf.value;			
		len = cpf.length;
		if(cpf.substr(len-1,len)=="." || cpf.substr(len-1,len)=="-" )
		document.form1.cpf.value = cpf.substr(0,len-1);			
		}


		function limpaCPF(cpf)	  {	
		cpf = cpf.replace(".","");
		cpf = cpf.replace(".","");
		cpf = cpf.replace("-","");		
//        alert(cpf);
//		alert(cpf.length);
		return cpf;
		
		}


 		function formataCPF() {
		blockCHAR();
		cpf = document.form1.cpf.value;	
		pos = cpf.length;
		
			switch (pos)
			{
			case 3:		cpf += "."; break;
			case 7:		cpf += "."; break;
			case 11:	cpf += "-"; break;		
			}

		document.form1.cpf.value=cpf;
		}
 
 //@Author: William Mello
//@Created: 21/07/2008
//@Last Update: 21/07/2008
//@Function: Formatar(mascarar) campo
//@parameter: campo = campo que será formatado (só o campo, não o valor Ex: this, formulario.nome_campo)
//@parameter: formato = formato que será mascarado. Os valores são representado por 'X' Ex: 'XX/XX/XX, XXX.XXX.XXX-XX'
//@parameter: Evento = evento é a tecla que foi precionada. É só passar event como parâmetro. Ex: mascara(this, event, 'xx/xx/xx') 
//Chamar a função: onKeyUp = mascara(this,event,'xx/xx/xxxx'), ou onKeyPress = mascara(formulario.nome_campo,event,'xx.xxx.xx.-x') 
/*<input type="text" onKeyUp="mascara(this, event,'xxx.xxx.xxx/xxx-xx')">*/
	 function mascara(campo, evento, formato){
		
		var tecla = evento.keyCode? evento.keyCode :
					evento.carCode? evento.carCode:
					evento.which  ? evento.which :
					 0;		
					 
		  if(tecla !=8){
			if(campo.value.length > formato.length){
			  campo.value = campo.value.substring(0,formato.length);
			}else{
			  formato = formato.toUpperCase();
			  if(formato.charAt(campo.value.length) != 'X'){
				campo.value += formato.charAt(campo.value.length);  
			  }
			}
		  }else{
			  return true;  
		  } 	
	 } 
	 

function validaCPF(cpf){
   returno = true;
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  returno = 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))){
	 returno =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))){
	 returno = false;
   }
   if(returno == false){
	  alert("Verifique seu CPF");   
   }
   return returno;
}



 function validaCPF2(cpf) {

 erro = new String;
 //if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF. \n\n";
 var nonNumbers = /\D/;
 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros. \n\n";
 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
 erro += "Numero de CPF invalido."
 }
 var a = [];
 var b = new Number;
 var c = 11;
 for (i=0; i<11; i++){
 a[i] = cpf.charAt(i);
 if (i < 9) b += (a[i] * --c);
 }
 if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
 b = 0;
 c = 11;
 for (y=0; y<10; y++) b += (a[y] * c--);
 if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
 if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
 erro +="Verifique seu CPF";
 }
 if (erro.length > 0){
 alert(erro);
 return false;
 }
 return true;
 }
