//-----------Funções relacionadas a consulta de cep-----------------------------------------------------------------------

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
        xmlhttp = false;
        }
      }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp = false;
      }
    }
  return xmlhttp;
  }
var http = getHTTPObject();

function funcaowebservicecep() 
{
	http.open('GET', 'conef_act_buscarendereco.php?urlcep='+document.frminscricao.txtcep.value, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);

	var arr; //array com os dados retornados
	function handleHttpResponse() 
	{
		if (http.readyState == 4) 
		{
			var response = http.responseText;
			eval('var arr = '+response); //cria objeto com o resultado
			document.frminscricao.txtendereco.value = arr.endereco;
			document.frminscricao.txtbairro.value = arr.bairro;
			document.frminscricao.txtmunicipio.value = arr.municipio;
		}
	}
}

//----------------fim CEP -------------------------------------------------------------------------------------------------


function ChecaCamposInscricao()
{
	msg='';
	erro=false;
	if(document.frminscricao.txtnome.value == '')
	{
		erro=true;
		msg=msg+'O campo NOME deve ser preenchido!\n'; 
	}
	if(document.frminscricao.txtrg.value == '')
	{
		erro=true;
		msg=msg+'O campo RG deve ser preenchido!\n';
	}
	if(document.frminscricao.txttelefone.value == '')
	{
		erro=true;
		msg=msg+'O campo TELEFONE deve ser preenchido!\n';
	}
	if(document.frminscricao.txtcep.value == '')
	{
		erro=true;
		msg=msg+'O campo CEP deve ser preenchido!\n';
	}
	if(document.frminscricao.txtnumero.value == '')
	{
		erro=true;
		msg=msg+'O campo NUMERO deve ser preenchido!\n';
	}
	if(document.frminscricao.txtemail.value == '')
	{
		erro=true;
		msg=msg+'O campo E-MAIL deve ser preenchido!\n';
	}
	if(document.frminscricao.txtinstituicao.value == '')
	{
		erro=true;
		msg=msg+'O campo INSTITUICAO deve ser preenchido!\n';
	}

	/*testar categoria e pacote --------------------------------------------------------*/
	if(document.frminscricao.txtcategoria.value == '')
	{
		erro=true;
		msg=msg+'Selecione a CATEGORIA!\n';
	}
	else 
	{
		checado_pacote = -1
		for (i=0; i<document.frminscricao.pacote.length; i++) 
		{
			if (document.frminscricao.pacote[i].checked) 
			{
				checado_pacote = document.frminscricao.pacote[i].value
			}
		}
		if (checado_pacote == -1) 
		{
			erro=true;
			msg=msg+'Selecione o PACOTE!\n';
		}

	}

	/*testar minicurso --------------------------------------------------------*/
	mini='';
	checado_minicurso = 0;
	sexta=0;
	sexto=0;
	
	for (i2=0; i2<document.frminscricao.txtminicurso.length; i2++) 
	{
		if (document.frminscricao.txtminicurso[i2].checked) 
		{
			checado_minicurso++;
			mini=mini+document.frminscricao.txtminicurso[i2].value;
			if(document.frminscricao.txtminicurso[i2].value == 1 || document.frminscricao.txtminicurso[i2].value == 2)
			{
				sexta++;
			}	

	        else
		    {
			   if(document.frminscricao.txtminicurso[i2].value == 4 || document.frminscricao.txtminicurso[i2].value == 5)
			   {
				    sexto++;
			   }
		     }
			 
			   
		}	
	}


	
	
	if (checado_minicurso == 0) 
	{
		erro=true;
		msg=msg+'Selecione o(s) MINI-CURSO(s)!\n';
	}
	else
	{
		if((checado_pacote == 1) && (checado_minicurso != 3))
		{
			erro=true;
			msg=msg+'Selecione 3 MINI-CURSOS!\n';
		}
		if(sexta==2)
		{
			erro=true;
			msg=msg+'Aviso!! Os minicursos 1 e 2 serao no mesmo horario!\n';
		}
		if(sexto==2)
		{
			erro=true;
			msg=msg+'Aviso!! Os minicursos 4 e 5 serao no mesmo horario!\n';
		}
		if((checado_pacote == 2 || checado_pacote == 4) && (checado_minicurso != 2))
		{
			erro=true;
			msg=msg+'Selecione 2 MINI-CURSOS!\n';
		}
		if((checado_pacote == 3 || checado_pacote == 5) && (checado_minicurso > 1))	
		{
			erro=true;
			msg=msg+'Selecione apenas 1 MINI-CURSO!\n';
		}
		
		

	 }
	    
	
	/*testar se houve algum em branco ---------------------------------------------- */
	if (erro)
	{
		alert(msg);
	}
	else
	{
		document.frminscricao.action='conef_act_envia_email_inscricao.php?mini='+mini;
		document.frminscricao.submit();
	}

}
function ChecaCamposInscricaoPre()
{
	msg='';
	erro=false;
	if(document.frminscricao.txtnome.value == '')
	{
		erro=true;
		msg=msg+'O campo NOME deve ser preenchido!\n'; 
	}
	if(document.frminscricao.txtrg.value == '')
	{
		erro=true;
		msg=msg+'O campo RG deve ser preenchido!\n';
	}
	if(document.frminscricao.txttelefone.value == '')
	{
		erro=true;
		msg=msg+'O campo TELEFONE deve ser preenchido!\n';
	}
	if(document.frminscricao.txtcep.value == '')
	{
		erro=true;
		msg=msg+'O campo CEP deve ser preenchido!\n';
	}
	if(document.frminscricao.txtemail.value == '')
	{
		erro=true;
		msg=msg+'O campo E-MAIL deve ser preenchido!\n';
	}
	if(document.frminscricao.txtinstituicao.value == '')
	{
		erro=true;
		msg=msg+'O campo INSTITUICAO deve ser preenchido!\n';
	}

	/*testar categoria  --------------------------------------------------------*/
	if(document.frminscricao.txtcategoria.value == '')
	{
		erro=true;
		msg=msg+'Selecione a CATEGORIA!\n';
	}
	/*testar se houve algum em branco ---------------------------------------------- */
	if (erro)
	{
		alert(msg);
	}
	else
	{
		document.frminscricao.action='preconef_act_envia_email_inscricao.php';
		document.frminscricao.submit();
	}

}

function ChecaCamposContato()
{
	msg='';
	erro=false;
	if(document.frmcontato.txtnome.value == '')
	{
		erro=true;
		msg=msg+'O campo NOME deve ser preenchido!\n'; 
	}
	if(document.frmcontato.txtemail.value == '')
	{
		erro=true;
		msg=msg+'O campo E-MAIL deve ser preenchido!\n';
	}
	if(document.frmcontato.txtassunto.value == '')
	{
		erro=true;
		msg=msg+'O campo ASSUNTO deve ser preenchido!\n';
	}
	if(document.frmcontato.mensagem.value == '')
	{
		erro=true;
		msg=msg+'O campo MENSAGEM deve ser preenchido!\n';
	}

	/*testar se houve algum em branco ---------------------------------------------- */
	if (erro)
	{
		alert(msg);
	}
	else
	{
		document.frmcontato.action='conef_act_envia_email_contato.php';
		document.frmcontato.submit();
	}

}


function AtivaDesativaPacote()
{
	if (document.frminscricao.txtcategoria.value == '')
	{
		document.getElementById('pacote_tit').style.display = 'none';
		document.getElementById('pacote_graduando').style.display = 'none';
		document.getElementById('pacote_graduado').style.display = 'none';
		for (i=0; i<document.frminscricao.pacote.length; i++) 
		{
			if (document.frminscricao.pacote[i].checked) 
			{
				document.frminscricao.pacote[i].checked = false;
				
			}
		}

	}
	else if (document.frminscricao.txtcategoria.value == 'graduando')
	{
		document.getElementById('pacote_tit').style.display = 'block';
		document.getElementById('pacote_graduando').style.display = 'block';
		document.getElementById('pacote_graduado').style.display = 'none';
		for (i=0; i<document.frminscricao.pacote.length; i++) 
		{
			if (document.frminscricao.pacote[i].checked) 
			{
				document.frminscricao.pacote[i].checked = false;
				
			}
		}
		
	}
	else if (document.frminscricao.txtcategoria.value == 'graduado')
	{
		document.getElementById('pacote_tit').style.display = 'block';
		document.getElementById('pacote_graduando').style.display = 'none';
		document.getElementById('pacote_graduado').style.display = 'block';
		for (i=0; i<document.frminscricao.pacote.length; i++) 
		{
			if (document.frminscricao.pacote[i].checked) 
			{
				document.frminscricao.pacote[i].checked = false;
				
			}
		}
		
	}
}	

function AtivaValorPre()
{
	if (document.frminscricao.txtcategoria.value == '')
	{
		document.getElementById('valor_tit').style.display = 'none';
		document.getElementById('valor_div').style.display = 'none';
	}
	else if (document.frminscricao.txtcategoria.value == 'graduando')
	{
		document.getElementById('valor_tit').style.display = 'block';
		document.getElementById('valor_div').style.display = 'block';
		document.frminscricao.valor.value = '15,00';
	}
	else if (document.frminscricao.txtcategoria.value == 'graduado')
	{
		document.getElementById('valor_tit').style.display = 'block';
		document.getElementById('valor_div').style.display = 'block';
		document.frminscricao.valor.value = '20,00';
		
	}
}	

function DigitaNum(caixa,strExcecao)
{     
 //04/04/2006 Permite apenas a digitação de números e caracteres de controle e navegação em uma caixa de texto. Evento OnKeyPress.
 codigo = event.keyCode
 if(strExcecao!=undefined&&strExcecao.indexOf(String.fromCharCode(codigo))!=-1) 
 	return    
 if(isNaN(parseInt(String.fromCharCode(codigo)))&&codigo!=8&&codigo!=9&&codigo!=37&&codigo!=39&&codigo!=46) 
 	event.returnValue=false
}



function ValidaEmail(email)
{
	var exprg =/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/;   

	if((!exprg.test(email.value)) && (email.value != ''))
	{ 
		alert('E-mail Invalido!');
		email.value='';
		email.focus();
	}
}



function ValidaTelefone(tel)
{
	var exprg = /\(\d{2}\)\ \d{4}\-\d{4}/
	
	if((!exprg.test(tel.value)) && (tel.value != ''))
	{
		if(tel.name == 'txttelefone')
			alert('Telefone Invalido!');
		else
			alert('Celular Invalido!');
			
		tel.value='';
		tel.focus();
	}
}

function FormataCampo(campo, Mascara, evento)
{
	var boleanoMascara;			
	var Digitato = evento.keyCode;
	exp = /\-|\.|\/|\(|\)| /g
	campoSoNumeros = campo.value.toString().replace( exp, "" );
  
	var posicaoCampo = 0;    
	var NovoValorCampo="";
	var TamanhoMascara = campoSoNumeros.length;;
	
	if (Digitato != 8) { // backspace
		for(i=0; i<= TamanhoMascara; i++) {
			boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
								|| (Mascara.charAt(i) == "/"))
			boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(")
								|| (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " "))
			if (boleanoMascara) {
				NovoValorCampo += Mascara.charAt(i);
				  TamanhoMascara++;
			}else {
				NovoValorCampo += campoSoNumeros.charAt(posicaoCampo);
				posicaoCampo++;
			  }           
		  }    
		campo.value = NovoValorCampo;
		  return true;
	}else {
		return true;
	}
}


