var menu_atual = "";
var menuvert_atual = "";
var prog_atual = "";

function initLightbox(){
  $('a[@rel*=lightbox]').lightBox();
}

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 configurar_nome(oElem,iValue,blankValue) {
	if(oElem.value==iValue || oElem.value=='') {
		oElem.value = (blankValue)?'':iValue;
	}
}

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 AbrirGaleria(galeria){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('galeria.aspx?pG="+galeria+"', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568,left=440,top=312');");
}

function ImprimirProg(){
    expositor = $('#h_expositor').val();
    data = $('#h_data').val();
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimirprog.aspx?pE=" + expositor + "&pD=" + data + "', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=800,height=568,left=440,top=312');");
}

function ImprimirProgCult(){
    local = $('#h_local').val();
    data = $('#h_data').val();
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimirprogcult.aspx?pL=" + local + "&pD=" + data + "', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568,left=440,top=312');");
}

function Imprimir(escola){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('visitacao_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=600,height=450');");
}

function selInicial(){
    $('#menu_1').addClass('menu_item_over');    
    menu_atual = "menu_1";
}

function VerIntegra(){
    $('#integraCordel').show();
}

$(document).ready(function(){
    $('#menu .menu_item').mouseover(function(){
        var menu = $(this).attr('id');
        var sub = $('#'+menu+' div.submenu').attr('id');
        var iframe = $('#'+menu+' iframe').attr('id'); 
                
        if(menu != menu_atual && menu_atual != ""){
            var subatual = $('#'+menu_atual+' div.submenu').attr('id');
            $('#'+subatual).hide();
            var iframeatual = $('#'+menu_atual+' iframe').attr('id'); 
            $('#'+iframeatual).hide(); 
            $('#'+menu_atual).removeClass('menu_item_over');
        }
        $('#'+menu).addClass('menu_item_over');

        if($('#'+sub+' div').size() > 0){
            $('#'+sub).show();
            $('#'+iframe).show();
            $('#'+iframe).width($('#'+sub).width()+2);
            $('#'+iframe).height($('#'+sub).height());
        }    
        
        menu_atual = "menu_"+menu;
    });
    
    $('#menu .menu_item').mouseout(function(){
        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 = "";
    });
    
    $('#menuvert .menuvert_item a').click(function(){
        var sub = $(this).attr('rel');
        return true;
    });
    
    var menu = $('#h_menu').val();
    if($('#menu_'+menu+' > div').size() > 0){
        var sub = $('#menu_'+menu+' > div').attr('id');
        $('#menu_'+menu).addClass('menu_item_over');    
        menu_atual = "menu_"+menu;
    } else {
        var sub = "submenuvert_"+menu;
        $('#'+sub).show();
        menuvert_atual = sub;
    }
});

function showTooltip(cat, tipo){
    $('a.tooltip').each(function(){
        var id = $(this).attr("id").replace("prog_","");
        
        if(tipo == "progexpo"){
            url = "getprogexpositores.aspx";
        } else if(tipo == "progcultural"){
            url = "getprogcultural.aspx";
        }
        
        $(this).simpletip('Carregando...', { 
            width: '400px',
            showOn: 'click',
            hideOn: { element: '.close', event: 'click' },
            delay: 200,
            position: 'bottom',
            hook: { tooltip: 'topRight', target: 'topLeft' }, 
            stem: { corner: 'rightMiddle', color: '#ccc' }, 
            parentClass: 'tooltip-light', 
            onShow: function(){ this.load(url+'?pC='+cat+'&pP='+id); }
        });        
    });
    
    $('a.tooltip').bind("click", function(e){
        if(prog_atual != ""){
            $('div[class*=id-'+$('#'+prog_atual).attr("id")+']').hide();
        }
    });
}

function showTooltip2(cat, tipo){
    $('#vDtg tr.grid-item-peq').each(function(){
        var id = $(this).attr("id").replace("prog_","");
        
        if(tipo == "progexpo"){
            url = "getprogexpositores.aspx";
        } else if(tipo == "progcultural"){
            url = "getprogcultural.aspx";
        }
        
        $(this).simpletip('Carregando...', { 
            width: '400px',
            showOn: 'click',
            hideOn: { element: '.close', event: 'click' },
            delay: 200,
            position: 'bottom',
            hook: { tooltip: 'topMiddle', target: 'bottomMiddle' }, 
            stem: { corner: 'topMiddle', color: '#ccc' }, 
            parentClass: 'tooltip-light', 
            onShow: function(){ this.load(url+'?pC='+cat+'&pP='+id); }
        });        
    });
    
    $('#vDtg tr').bind("click", function(e){
        if(prog_atual != ""){
            $('div[class*=id-'+$('#'+prog_atual).attr("id")+']').hide();
        }
    });
}

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_qtdeveiculos').value == 0 || document.getElementById('t_qtdeveiculos').value == ""){
        alert("Digite a quantidade de veículos!");
        return false;        
    }
    return true;
}

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=='') { 
		alert('O campo login é obrigatório!');
		document.getElementById('pL').focus();
		return false; 
	}
	if(document.getElementById('pS').value=='') { 
		alert('O campo senha é obrigatório!');
		document.getElementById('pS').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 validar_credencial() {
	if(document.getElementById('t_nome_completo').value=='') {
		alert('O campo nome completo é obrigatório!');
		document.getElementById('t_nome_completo').focus();
		return false;
	}
	if(document.getElementById('t_nome_cracha').value=='') {
		alert('O campo nome pra crachá é obrigatório!');
		document.getElementById('t_nome_cracha').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;
	}		
	return true;
}

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('d_categoria').value==0) {
		alert('O campo categoria é obrigatório!');
		document.getElementById('d_categoria').focus();
		return false;
	}
    if(document.getElementById('t_nome').value=='') {
		alert('O campo nome é obrigatório!');
		document.getElementById('t_nome').focus();
		return false;
	}
	if(document.getElementById('t_diretor').value=='') {
		alert('O campo diretor é obrigatório!');
		document.getElementById('t_diretor').focus();
		return false;
	}
	if(document.getElementById('t_registro').value=='') {
	    if(document.getElementById('d_categoria').value==1){
		    alert('O campo cnpj é obrigatório!');
		} else {
		    alert('O campo e/cre é obrigatório!');
		}
		document.getElementById('t_registro').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_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('t_responsavel').value=='') {
		alert('O campo responsável é obrigatório!');
		document.getElementById('t_responsavel').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_descricao').value=='') {
		alert('O campo porque sua escola quer visitar a Bienal do Livro é obrigatório!');
		document.getElementById('t_descricao').focus();
		return false;
	}
}
