var menu_atual = "";

$(document).ready(function(){
    $('#menu .menu_item').mouseover(function(event) {
        var menu = $(this).attr('id');
        var sub = $('#'+menu+' > div').attr('id');
        var iframe = $('#'+menu+' > iframe').attr("id");
//        if(menu != menu_atual){
//            var subatual = $('#'+menu_atual+' > div').attr('id');
//            $('#'+subatual).hide();
//            var iframeatual = $('#'+menu_atual+' > iframe').attr('id');
//            $('#'+iframeatual).hide();
//            $('#'+menu_atual).removeClass('menu_item_over');
//        }
        if($('#'+sub+' div').size() > 0){
            $('#'+sub).show();
            $('#'+iframe).show();
            $('#'+iframe).width($('#'+sub).width());
            $('#'+iframe).height($('#'+sub).height());
        }
        $('#'+menu).addClass('menu_item_over');
        menu_atual = "menu_"+menu;
    });
    
    $('#menu .menu_item').mouseout(function(event) {
        var menu = $(this).attr('id');
        var sub = $('#'+menu+' > div').attr('id');
        $('#'+sub).hide();
        var iframe = $('#'+menu+' > iframe').attr("id");
        $('#'+iframe).hide();
        $('#'+menu).removeClass('menu_item_over');
        menu_atual = "";
    });
    
    if(screen.width=="800") {
		document.body.background = "imagens/back800.jpg";
	} else if(screen.width=="1024") {
		document.body.background = "imagens/back1024.jpg";
	} else if(screen.width=="1280") {
		document.body.background = "imagens/back1280.jpg";
	} else{
		document.body.background = "imagens/back1024.jpg";
	}
});

function initLightbox(){
  $('a[@rel*=lightbox]').lightBox();
}

function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.style.width) newElm.style.width = oldElm.style.width;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string") {
        if(er.test(mail)) { return true; }
	}
	else if(typeof(mail) == "object") {
		if(er.test(mail.value)) { return true; }
	}
    else {
        return false;
    }
}

function replaceAll(string, token, newtoken)
{
    while (string.indexOf(token) != -1) {
         string = string.replace(token, newtoken);
    }
    return string;
}

function validaCPF(cpf) {
    var nonNumbers = /\D/;
    cpf = replaceAll(cpf,".","");
    cpf = cpf.replace("-","");
    if (cpf.length < 11) {
        return false;
    }    
    if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
        return false;
    }
    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])){
        return false;
    }
    return true;
}

function validaCNPJ(CNPJ) {
	if (CNPJ.length < 18) { return false; }
	if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")) {
		return false;
	}

	if (document.layers && parseInt(navigator.appVersion) == 4) {
		x = CNPJ.substr(0, 2);
		x += CNPJ.substr(3, 3);
		x += CNPJ.substr(7, 3);
		x += CNPJ.substr(11, 4);
		x += CNPJ.substr(16, 2);
		CNPJ = x;
	} else {
		CNPJ = CNPJ.replace(".", "");
		CNPJ = CNPJ.replace(".", "");
		CNPJ = CNPJ.replace("-", "");
		CNPJ = CNPJ.replace("/", "");
	}
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) { return false; }
	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])) {
		return false;
	}
	return true;
}

function validaTelefone (telefone) {
    var regExpAllowChars = /^((\+?\d{1,4}|\(\+?\d{1,4}\))?[ -.])?(([\d\*]{1,5}|\([\d\*]{1,5}\))[ -]?)?\d{1,5}[ -.]?\d{4}$/;
    
    if (typeof (telefone) == "string")
        if (regExpAllowChars.test (telefone))
            return true;
    else
        if (typeof (telefone) == "object")
            if (regExpAllowChars .test (telefone.value))
                return true;
        
    return false;    
}

function validaCep (cep) {
    var regExpAllowChars = /^\d+[\-\. ]?\d+[\-\. ]?\d+$/
    
    if (typeof (cep) == "string")
        if (regExpAllowChars.test(cep))
            return true;
    else
        if (typeof (cep) == "object")
            if (regExpAllowChars.test (cep.value))
                return true;
    return false;
}

function configurar_nome(oElem,iValue,blankValue) {
	if(oElem.value==iValue || oElem.value=='') {
		oElem.value = (blankValue)?'':iValue;
	}
}

function configurar_nome_senha() {
	if(document.getElementById("pS").value=='senha') {
		changeInputType(document.getElementById("pS"),'password','senha',true,false)
	}
}

function limiteTexto(field, countfield, maxlimit) {
    if (field.value.length > maxlimit){
        field.value = field.value.substring(0, maxlimit);
    } else {
        $('#'+countfield).val(maxlimit - field.value.length);
    }
}

function AbrirPlantaFeira(){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imagem.aspx', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=665,height=498,top=20,left=20');");
}

function AbrirGaleria(){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('galeria.aspx', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=632');");
}

function ImprimirProg(){
    expositor = $('#h_expositor').val();
    data = $('#h_data').val();
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir_prog.aspx?pE=" + expositor + "&pD=" + data + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568');");
}

function ImprimirProgInfantil(){
    expositor = $('#h_expositor').val();
    data = $('#h_data').val();
    hora = $('#h_hora').val();
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir_proginfantil.aspx?pE=" + expositor + "&pD=" + data + "&pH=" + hora + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568');");
}

function ImprimirProgCult(){
    local = $('#h_local').val();
    data = $('#h_data').val();
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir_progcult.aspx?pL=" + local + "&pD=" + data + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568');");
}

function ImprimirExpositores(){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir_expositores.aspx', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568');");
}

function Imprimir(escola){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir.aspx?pP=" + escola + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568,left=440,top=312');");
}

function VerDados(expositor){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('expositorform.aspx?expositor=" + expositor + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=450');");
}

function VerDetalhesProgExpositores(expositor) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('getprogexpositores.aspx?pP=" + expositor + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=450');");
}

function validar_visitas(){
    if(document.getElementById('h_totalvisitas').value == 0){
        alert("Adicione uma visita para a escola!");
        return false;
    }
    return true;
}

function validar_add(){
    if(document.getElementById('d_data').value == 0){
        alert("Selecione uma data!");
        return false;        
    }
    if(document.getElementById('d_hora').value == 0){
        alert("Selecione uma hora!");
        return false;        
    }
    if(document.getElementById('t_qtdealunos').value == 0 || document.getElementById('t_qtdealunos').value == ""){
        alert("Digite a quantidade de alunos!");
        return false;        
    }
    if(document.getElementById('t_qtdealunos').value < 40){
        alert("Quantidade mínima: 40 alunos");
        return false;        
    }
    if(document.getElementById('t_qtdeveiculos').value == 0 || document.getElementById('t_qtdeveiculos').value == ""){
        alert("Digite a quantidade de veículos!");
        return false;        
    }
    return true;
}

function isNum(event)
{
  var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if(Key==8 || Key==13 || Key==127 || (Key >= 48 && Key <=57)) return true;
  else return false;
}

function onTopPage() {
	document.body.scrollTop=0;
}

function configurar_comosoube() {	
	if(document.getElementById('d_como_soube').value == 99) { 
		document.getElementById('linha_como_soube').style.display = 'block';
	}
	else { 
		document.getElementById('linha_como_soube').style.display = 'none';
	}		
}	

function validar_login() {
	if(document.getElementById('pL').value=='login' || document.getElementById('pL').value=='') { 
		alert('O campo login é obrigatório!');
		document.getElementById('pL').focus();
		return false; 
	}
	if(document.getElementById('pS').value=='senha' || document.getElementById('pS').value=='') { 
		alert('O campo senha é obrigatório!');
		document.getElementById('pS').focus();
		return false;
	}
	return true;
}

function validar_newsletter() {
	if(document.getElementById('t_email_news').value=='digite o seu e-mail' || document.getElementById('t_email_news').value=='') { 
		alert('O campo e-mail é obrigatório!');
		document.getElementById('t_email_news').focus();
		return false; 
	}
	if(!checkMail(document.getElementById("t_email_news").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("t_email_news").focus();	
		return false;
	}
	return true;
}

function validar_newsletter_roda() {
	if(document.getElementById('t_email_news_roda').value=='digite o seu e-mail' || document.getElementById('t_email_news').value=='') { 
		alert('O campo e-mail é obrigatório!');
		document.getElementById('t_email_news_roda').focus();
		return false; 
	}
	if(!checkMail(document.getElementById("t_email_news_roda").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("t_email_news_roda").focus();	
		return false;
	}
	return true;
}

function validar_contato() {
	if(document.getElementById('t_nome').value=='') {
		alert('O campo nome é obrigatório!');
		document.getElementById('t_nome').focus();
		return false;
	}
	if(document.getElementById('t_email').value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById('t_email').focus();
		return false;
	}
	if(!checkMail(document.getElementById("t_email").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("t_email").focus();	
		return false;
	}
	if(document.getElementById('t_empresa').value=='') {
		alert('O campo empresa é obrigatório!');
		document.getElementById('t_empresa').focus();
		return false;
	}
	if(document.getElementById('t_cargo').value=='') {
		alert('O campo cargo é obrigatório!');
		document.getElementById('t_cargo').focus();
		return false;
	}	
	if(document.getElementById('t_endereco').value=='') {
		alert('O campo endereço é obrigatório!');
		document.getElementById('t_endereco').focus();
		return false;
	}
	if(document.getElementById('t_cidade').value=='') {
		alert('O campo cidade é obrigatório!');
		document.getElementById('t_cidade').focus();
		return false;
	}
	if(document.getElementById('t_bairro').value=='') {
		alert('O campo bairro é obrigatório!');
		document.getElementById('t_bairro').focus();
		return false;
	}
	if(document.getElementById('t_estado').value=='') {
		alert('O campo estado é obrigatório!');
		document.getElementById('t_estado').focus();
		return false;
	}
	if(document.getElementById('t_pais').value=='') {
		alert('O campo país é obrigatório!');
		document.getElementById('t_pais').focus();
		return false;
	}
	if(document.getElementById('t_cep').value=='') {
		alert('O campo cep é obrigatório!');
		document.getElementById('t_cep').focus();
		return false;
	}
	if(document.getElementById('t_telefone').value=='') {
		alert('O campo telefone é obrigatório!');
		document.getElementById('t_telefone').focus();
		return false;
	}	
	if(document.getElementById('d_como_soube').value==0) { 
		alert('O campo como soube é obrigatório!');
		document.getElementById('d_como_soube').focus();
		return false 
	}
	if(document.getElementById('d_como_soube').value==99 && document.getElementById('t_como_soube').value=='') {
		alert('O campo como soube - outros é obrigatório!');
		document.getElementById('t_como_soube').focus();
		return false;
	}
	if(document.getElementById('t_mensagem').value=='') { 
		alert('O campo mensagem é obrigatório!');
		document.getElementById('t_mensagem').focus();
		return false 
	}		
	return true;
}

/*function validaCepComMascara(){
	cep = document.getElementById("t_cep")
    if (cep == "") {
        alert('O Campo CEP é obrigatório!');
		cpf.focus();
		return false
    }
    else {
        if(cep.length != 9){
            alert("O campo CEP não está no formato correto. Por favor verifique o valor digitado!");
			cep.focus();
			return false
        }
		else{
			return true;
		}
    }
}

function validaCpfComMascara(){
	cpf = document.getElementById("t_cpf")
    if (cpf == "") {
        alert('O Campo CEP é obrigatório!');
		cpf.focus();
		return false
    }
    else {
        if(cpf.length != 14){
            alert("O campo CEP não está no formato correto. Por favor verifique o valor digitado!");
			cpf.focus();
			return false;
        }
		else{
			return true;
		}
    }
}

function validaTelefoneComMascara(){
	telefone = document.getElementById("t_telefone")
    if (telefone == "") {
        alert('O Campo Telefone é obrigatório!');
		telefone.focus();
		return false
    }
    else {
        if(telefone.length != 13){
            alert("O campo Telefone não está no formato correto. Por favor verifique o valor digitado!");
			telefone.focus();
			return false;
        }
		else{
			return true;
		}
    }
}

function validaCelularComMascara(telefone){
	telefone = document.getElementById("t_celular")
    if (telefone == "") {
        alert('O Campo Celular é obrigatório!');
		telefone.focus();
		return false;
    }
    else {
        if(telefone.length != 13){
            alert("O campo Celular não está no formato correto. Por favor verifique o valor digitado!");
			return false;
			telefone.focus();
        }
		else{
			return true;
		}
    }
}*/

function validar_credencial() {
	if(document.getElementById('t_nome_completo').value=='') {
		alert('O campo nome completo é obrigatório!');
		document.getElementById('t_nome_completo').focus();
		return false;
	}

	//validaCpfComMascara();
	
	cpf = document.getElementById("t_cpf")
    if (cpf.value == "") {
        alert('O Campo CPF é obrigatório!');
		cpf.focus();
		return false
    }
    else {
        if(cpf.value.length != 14){
            alert("O campo CPF não está no formato correto. Por favor verifique o valor digitado!");
			cpf.focus();
			return false;
        }
    }

	if (document.getElementById ("t_rg").value == "") {
	    alert ("O campo RG é obrigatório!");
	    document.getElementById ("t_rg").focus();
	    return false;
	}
	if(document.getElementById('t_email').value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById('t_email').focus();
		return false;
	}
	if(!checkMail(document.getElementById("t_email").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("t_email").focus();	
		return false;
	}
	if(document.getElementById('t_empresa').value=='') {
		alert('O campo empresa é obrigatório!');
		document.getElementById('t_empresa').focus();
		return false;
	}
	/*if(document.getElementById("t_ramo").value=="") {
		alert("O campo ramo é obrigatório!");
		document.getElementById("t_ramo").focus();
		return false;
	}*/
	if(document.getElementById("t_cargo").value=="") {
		alert("O campo cargo é obrigatório!");
		document.getElementById("t_cargo").focus();
		return false;
	}	
	if(document.getElementById('t_endereco').value=='') {
		alert('O campo endereço é obrigatório!');
		document.getElementById('t_endereco').focus();
		return false;
	}
	if(document.getElementById('t_cidade').value=='') {
		alert('O campo cidade é obrigatório!');
		document.getElementById('t_cidade').focus();
		return false;
	}
    
	cep = document.getElementById("t_cep")
    if (cep.value == "") {
        alert('O Campo CEP é obrigatório!');
		cep.focus();
		return false
    }
    else {
        if(cep.value.length != 9){
            alert("O campo CEP não está no formato correto. Por favor verifique o valor digitado!");
			cep.focus();
			return false
        }
    }
	
	telefone = document.getElementById("t_telefone")
    if (telefone.value == "") {
        alert('O Campo Telefone é obrigatório!');
		telefone.focus();
		return false
    }
    else {
        if(telefone.value.length != 13){
            alert("O campo Telefone não está no formato correto. Por favor verifique o valor digitado!");
			telefone.focus();
			return false;
        }
    }
	
	//Validando Celular (Campo não obrigatório)
	celular = document.getElementById("t_celular")
    if (celular.value != "") {
		if(celular.value.length != 13){
            alert("O campo Celular não está no formato correto. Por favor verifique o valor digitado!");
			celular.focus();
			return false;
        }
	}
    //validaCepComMascara();
	//validaTelefoneComMascara();
	//validaCelularComMascara();
	
}

function validar_assinante() {
	if(document.getElementById("t_nome").value=='') {
		alert('O campo nome é obrigatório!');
		document.getElementById("t_nome").focus();
		return false;
	}
	if(document.getElementById("t_email").value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById("t_email").focus();
		return false;
	}
	if(!checkMail(document.getElementById("t_email").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("t_email").focus();	
		return false;
	}	
	if(document.getElementById("t_empresa").value=='') {
		alert('O campo empresa é obrigatório!');
		document.getElementById("t_empresa").focus();
		return false;
	}		
	if(document.getElementById("d_idioma").value==0) {
		alert('O campo idioma é obrigatório!');
		document.getElementById("d_idioma").focus();
		return false;
	}
	return true;
}

function validar_busca(){
    if(document.getElementById('t_busca').value=='') {
        alert('Digite o termo a ser pesquisado!');
		document.getElementById('t_busca').focus();	
		return false;
    }
    return true;
}

function validar_visitacao(){
    if(document.getElementById('ddlCategory').value==0) {
		alert('O campo categoria é obrigatório!');
		document.getElementById('ddlCategory').focus();
		return false;
    }
    if (document.getElementById('txtCNPJ').value == '') {
        alert('O campo CNPJ é obrigatório!');
        document.getElementById('txtCNPJ').focus();
        return false;
    }	
	if (!validaCNPJ(document.getElementById('txtCNPJ').value)) {
		alert('O CNPJ informado é inválido!');
		document.getElementById('txtCNPJ').focus();
		return false;
	}
	 if (document.getElementById('txtName').value == '') {
		alert('O campo nome da escola é obrigatório!');
		document.getElementById('txtName').focus();
		return false;
	}
	if(document.getElementById('txtPrincipal').value=='') {
		alert('O campo diretor é obrigatório!');
		document.getElementById('txtPrincipal').focus();
		return false;
	}
	if(document.getElementById('txtAddress').value=='') {
        alert('O campo endereço é obrigatório!');
		document.getElementById('txtAddress').focus();
		return false;
	}
	if(document.getElementById('txtAddressNumber').value=='') {
		alert('O campo número é obrigatório!');
		document.getElementById('txtAddressNumber').focus();
		return false;
	}
	if(document.getElementById('txtNeighborhood').value=='') {
		alert('O campo bairro é obrigatório!');
		document.getElementById('txtNeighborhood').focus();
		return false;
	}
	if(document.getElementById('txtCity').value=='') {
		alert('O campo cidade é obrigatório!');
		document.getElementById('txtCity').focus();
		return false;
	}
	if(document.getElementById('txtCEP').value=='') {
		alert('O campo cep é obrigatório!');
		document.getElementById('txtCEP').focus();
		return false;
	}	
	if(document.getElementById('txtPhone').value=='') {
		alert('O campo telefone é obrigatório!');
		document.getElementById('txtPhone').focus();
		return false;
	}
	if(document.getElementById('txtEmail').value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById('txtEmail').focus();
		return false;
	}	
	if(!checkMail(document.getElementById("txtEmail").value)) {
		alert('E-mail inválido!');
		document.getElementById("txtEmail").focus();	
		return false;
	}
	if (document.getElementById ("txtAnswerable1").value == "") {
	    alert ("O campo nome do primeiro responsável é obrigatório!");
	    document .getElementById ("txtAnswerable1").focus();
	    return false;
	}
	if (document.getElementById ("txtAnswerable1Job").value == "") {
	    alert ("O campo cargo do primeiro responsável é obrigatório!");
	    document .getElementById ("txtAnswerable1Job").focus();
	    return false;
	}
	if (document.getElementById ("txtAnswerable1Email").value == "") {
	    alert ("O campo e-mail do primeiro responsável é obrigatório!");
	    document .getElementById ("txtAnswerable1Email").focus();
	    return false;
	}
	if(!checkMail(document.getElementById("txtAnswerable1Email").value)) {
		alert('E-mail do primeiro responsável inválido!');
		document.getElementById("txtAnswerable1Email").focus();	
		return false;
	}
	if (document.getElementById ("txtAnswerable2").value == "") {
	    alert ("O campo nome do segundo responsável é obrigatório!");
	    document .getElementById ("txtAnswerable2").focus();
	    return false;
	}
	if (document.getElementById ("txtAnswerable2Job").value == "") {
	    alert ("O campo cargo do segundo responsável é obrigatório!");
	    document .getElementById ("txtAnswerable2Job").focus();
	    return false;
	}
	if (document.getElementById ("txtAnswerable2Email").value == "") {
	    alert ("O campo e-mail do segundo responsável é obrigatório!");
	    document .getElementById ("txtAnswerable2Email").focus();
	    return false;
	}
	if(!checkMail(document.getElementById("txtAnswerable2Email").value)) {
		alert('E-mail do segundo responsável inválido!');
		document.getElementById("txtAnswerable2Email").focus();	
		return false;
	}
	if(document.getElementById('h_visit_manual').value==0 && document.getElementById('txtQtdeAlunos').value=='') {
		alert('O campo quantidade de alunos desejada é obrigatório!');
		document.getElementById('txtQtdeAlunos').focus();
		return false;
	}
	if(document.getElementById('txtDescricao').value=='') {
		alert('O campo projeto pedagógico é obrigatório!');
		document.getElementById('txtDescricao').focus();
		return false;
	}
	return true;
}

function validar_visitacao_login(){
    if(document.getElementById('h_categoria').value==1 && document.getElementById('t_login').value=='') {
		alert('O campo login é obrigatório!');
		document.getElementById('t_login').focus();
		return false;
	}
	if(document.getElementById('h_categoria').value==2 && document.getElementById('t_cre').value==0) {
		alert('O campo CRE é obrigatório!');
		document.getElementById('t_cre').focus();
		return false;
	}
	if(document.getElementById('h_categoria').value==2 && document.getElementById('t_designacao').value=='') {
		alert('O campo designação é obrigatório!');
		document.getElementById('t_designacao').focus();
		return false;
	}
	if(document.getElementById('t_senha').value=='') {
		alert('O campo senha é obrigatório!');
		document.getElementById('t_senha').focus();
		return false;
	}
	return true;
}

function validar_cadastro(){
    if(document.getElementById("t_nome").value=='') {
		alert('O campo nome é obrigatório!');
		document.getElementById("t_nome").focus();
		return false;
	}
	if(document.getElementById("t_email").value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById("t_email").focus();
		return false;
	}
	if(!checkMail(document.getElementById("t_email").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("t_email").focus();	
		return false;
	}    
	if(document.getElementById("t_veiculo").value=='') {
		alert('O campo veículo é obrigatório!');
		document.getElementById("t_veiculo").focus();
		return false;
	}
	if(document.getElementById("t_telefone").value=='') {
		alert('O campo telefone é obrigatório!');
		document.getElementById("t_telefone").focus();
		return false;
	}
}

function validar_login_fotos(){
    if(document.getElementById("t_email_login").value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById("t_email_login").focus();
		return false;
	}
	if(!checkMail(document.getElementById("t_email_login").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("t_email_login").focus();	
		return false;
	}
}

function imprime_cadastro(v_id, v_cat){
    window.open("credform.aspx?pP=" + v_id + "&pC=" + v_cat,'','toolbar=0,location=0,directories=0,status=no,menubar=0,scrollbars=1,resizable=1,width=600,height=800,top=20,left=30');
}

function validar_caravanas() {
	if(document.getElementById('t_nome').value=='') {
		alert('O campo nome completo é obrigatório!');
		document.getElementById('t_nome').focus();
		return false;
	}
	if(document.getElementById('t_email').value=='') {
		alert('O campo e-mail é obrigatório!');
		document.getElementById('t_email').focus();
		return false;
	}
	if(!checkMail(document.getElementById("t_email").value)) {
		alert('O e-mail é inválido!');
		document.getElementById("t_email").focus();	
		return false;
	}
	if(document.getElementById("t_cnpj").value == "" && document.getElementById("t_cpf").value == "") {
	    alert("O campo CNPJ/CPF é obrigatório!");
	    document.getElementById("t_cnpj").focus();
	    return false;
	} else if(document.getElementById("t_cnpj").value != "" && document.getElementById("t_cpf").value == "") {
	    if(!validaCNPJ(document.getElementById("t_cnpj").value)) {
            alert ("O CNPJ é inválido!");
            document.getElementById ("t_cnpj").focus;
            return false;
	    }   
	} else if(document.getElementById("t_cnpj").value == "" && document.getElementById("t_cpf").value != "") {
	    if(!validaCPF(document.getElementById("t_cpf").value)) {
	        alert("O CPF é inválido!");
	        document.getElementById("t_cpf").focus;
	        return false;
	    }
	}
	if(document.getElementById('t_telefone').value=='') {
		alert('O campo telefone é obrigatório!');
		document.getElementById('t_telefone').focus();
		return false;
	}
	if(document.getElementById('t_endereco').value=='') {
		alert('O campo endereço é obrigatório!');
		document.getElementById('t_endereco').focus();
		return false;
	}
	if(document.getElementById('t_bairro').value=='') {
		alert('O campo bairro é obrigatório!');
		document.getElementById('t_bairro').focus();
		return false;
	}
	if(document.getElementById('t_cidade').value=='') {
		alert('O campo cidade é obrigatório!');
		document.getElementById('t_cidade').focus();
		return false;
	}
	if(document.getElementById('t_estado').value=='') {
		alert('O campo estado é obrigatório!');
		document.getElementById('t_estado').focus();
		return false;
	}
	if(document.getElementById('t_pais').value=='') {
		alert('O campo país é obrigatório!');
		document.getElementById('t_pais').focus();
		return false;
	}
	if(document.getElementById('t_cep').value=='') {
		alert('O campo CEP é obrigatório!');
		document.getElementById('t_cep').focus();
		return false;
	}
	if(document.getElementById('t_quantidade').value=='') {
		alert('O campo quantidade de componentes é obrigatório!');
		document.getElementById('t_quantidade').focus();
		return false;
	}
	if(document.getElementById('t_quantidade').value<20) {
		alert('Quantidade mínima é de 20 componentes!');
		document.getElementById('t_quantidade').value = "20";
		document.getElementById('t_quantidade').focus();
		return false;
	}
	if($('#coluna_esquerda #textos form input[type=checkbox]:checked').size() == 0){
	    alert('Selecione o(s) dia(s) da visita(s)!');
		return false;
	} else {
	    var bool = false;
	    $('#coluna_esquerda #textos form input[type=checkbox]:checked').each(function(){
	        var id = $(this).attr("id");
	        if($("#t_horario_chegada_"+id.replace("cb_dias_","")).val() == ""){
	            var data = $(this).parent().children("label").html();
	            alert('O campo horário de chegada do dia'+data.substr(0,6)+' é obrigatório!');
	            bool = true;
	        } else {
	            var cont = $(this).parent().children("label").html();
	            if(cont.search("limite") != "-1"){
	                var valor = $("#t_horario_chegada_"+id.replace("cb_dias_","")).val();
	                if(parseFloat(valor.replace(":",".")) > 12){
	                    var data = $(this).parent().children("label").html();
	                    alert('O horário limite de chegada do dia'+data.substr(0,6)+' é até as 12h!');
	                    $("#t_horario_chegada_"+id.replace("cb_dias_","")).val("");
	                    bool = true;
	                }
	            }
	        }
	    });
	    if(bool){
	        return false;
	    }
	}
	if(document.getElementById('t_texto').value=='') {
		alert('O campo nome e cpf dos componentes é obrigatório!');
		document.getElementById('t_texto').focus();
		return false;
	}
	return true;
}