﻿var menu_atual = "";
var tamanho_atual = 0;
var tamanho_menu = 0;

$(document).ready(function(){
    /* *******************  MENU  ********************* */
    $('#menu div.menu_item').mouseover(function(){
        var menu = $(this).attr('id');
        var sub = $('#submenu_'+menu.replace("menu_", "")).attr('id');
        var iframe = $('#iframe_'+menu.replace("menu_", "")).attr('id');
        
        if(menu_atual != "" && menu != menu_atual){
            $('#'+menu_atual).removeClass("menu_item_over");
            var subatual = $('#submenu_'+menu_atual.replace("menu_", "")).attr('id');
            $('#'+subatual).css("width", tamanho_menu);
            $('#'+subatual).hide();
            var iframeatual = $('#iframe_'+menu_atual.replace("menu_", "")).attr('id'); 
            $('#'+iframeatual).hide(); 
            tamanho_atual = 0;
        }
        
        $(this).addClass("menu_item_over");
        
        if($('#'+sub+' div').size() > 1){
            $('#'+sub).show();
            if($('#'+sub).width() != tamanho_atual){
                tamanho_menu = $('#'+sub).width();
                $('#'+sub).css("width", $('#'+sub).width()+15);
                tamanho_atual = $('#'+sub).width();
            }
            $('#'+iframe).show();
            $('#'+iframe).width($('#'+sub).width()+1);
            $('#'+iframe).height($('#'+sub).height()+1);
        }
        menu_atual = menu;
    });
    
    $('#menu div.menu_item').mouseout(function(){
        var menu = $(this).attr('id');
        var sub = $('#submenu_'+menu.replace("menu_", "")).attr('id');
        $(this).removeClass("menu_item_over");
        $('#'+sub).css("width", tamanho_menu);
        $('#'+sub).hide();
        var iframe = $('#iframe_'+menu.replace("menu_", "")).attr('id'); 
        $('#'+iframe).hide(); 
        tamanho_atual = 0;
    });
    
    selecionarMenu();
    
    criarbox();    
    $(document).pngFix();
});

function selecionarMenu(){
    menu_atual = "menu_"+$('#h_menu').val();
    $('#'+menu_atual).addClass("menu_item_over");
}

function criarbox(){
    $('#painel div.foot').each(function(){
        $(this).html('<img src="imagens/bg_box_bot_esq.jpg" alt="" class="left" /><img src="imagens/bg_box_bot_dir.jpg" alt="" class="right" />');
    });
    
    $('#corpo div.box div.topo').each(function(){
        $(this).html('<img src="imagens/bg_box_top_esq.jpg" alt="" class="left" /><img src="imagens/bg_box_top_dir.jpg" alt="" class="right" />');
    });
    
    $('#corpo div.boxesc div.topo').each(function(){
        $(this).html('<img src="imagens/bg_boxesc_top_esq.jpg" alt="" class="left" /><img src="imagens/bg_boxesc_top_dir.jpg" alt="" class="right" />');
    });
    
    $('#corpo div.box div.foot, #corpo div.boxesc div.foot').each(function(){
        $(this).html('<img src="imagens/bg_box_bot_esq.jpg" alt="" class="left" /><img src="imagens/bg_box_bot_dir.jpg" alt="" class="right" />');
    });
}

/* ***************** FUNCAO *************************** */
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 isNum(event)
{
  var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if(Key==13 || (Key >= 48 && Key <=57)) return true;
  else return false;
}

function onTopPage() {
	document.body.scrollTop=0;
}

function AbrirGaleria(galeria){
    day = new Date();
    id = day.getTime();
    pG = 0;
    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=565,left=440,top=312');");
}

function AbrirMapa(caminho){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imagem.aspx?pP="+ caminho +"', '" + id + "', 'toolbar=0,location=0,directories=0,status=no,menubar=0,scrollbars=1,resizable=1,width=800,height=600,top=20,left=20');");
}

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 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 erro_galeria() {
	alert("Não existe imagem cadastrada!");
	return false;
}

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 validaCPF(cpf) {
    var nonNumbers = /\D/;
    if (nonNumbers.test(cpf)) {
        alert("Use apenas números no campo CPF! \n\n");
        return false;
    }
    if (cpf.length < 11) {
        alert("CPF inválido. Tente novamente!");
        return false;
    }    
    if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
        alert("CPF inválido. Tente novamente!");
        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])){
        alert("CPF inválido. Tente Novamente!");
        return false;
    }
    return true;
}

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=='Digite a sua senha') {
		changeInputType(document.getElementById("pS"),'password','Digite a sua senha',true,false)
	}
}

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 configurar_area_interesse_outro(campo) {
	if(document.getElementById('cb_interesses_'+campo).checked) { 
		document.getElementById('linha_area_interesse_outro').style.display = 'block';
	} else { 
		document.getElementById('linha_area_interesse_outro').style.display = 'none';
	}		
}

function configurar_newsletter() {		
	if(document.getElementById('cb_newsletter').checked == true) { 
		document.getElementById('linha_idioma').style.display = 'block';
	} else { 
		document.getElementById('linha_idioma').style.display = 'none';
	}		
}	


function validar_login() {
	if(document.getElementById('pL').value=='Digite o seu login' || document.getElementById('pL').value=='') { 
		alert('O campo login é obrigatório!');
		document.getElementById('pL').focus();
		return false; 
	}
	if (document.getElementById('pS').value=='Digite a sua 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_nome_news').value=='Nome' || document.getElementById('t_nome_news').value=='') { 
		alert('O campo nome é obrigatório!');
		document.getElementById('t_nome_news').focus();
		return false;
	}
	if (document.getElementById('t_email_news').value=='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;
	}
	if (document.getElementById('t_empresa_news').value=='E-mail' || document.getElementById('t_empresa_news').value=='') { 
		alert('O campo empresa é obrigatório!');
		document.getElementById('t_empresa_news').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;
}

/* ******************* CONTATO ****************************** */
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_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_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;
}

/* ******************* PATROCINAR E EXPOR ****************************** */
function validar_exporpatro() {
	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_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_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_atividade').value=='') {
		alert('O campo atividade da empresa é obrigatório!');
		document.getElementById('t_atividade').focus();
		return false;
	}	
	if(document.getElementById('t_mensagem').value=='') { 
		alert('O campo mensagem é obrigatório!');
		document.getElementById('t_mensagem').focus();
		return false 
	}		
	return true;
}

/* ******************* CREDENCIAMENTO ****************************** */
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_cpf').value=='') {
		alert('O campo CPF é obrigatório!');
		document.getElementById('t_cpf').focus();
		return false;
	}
	if(document.getElementById('t_cpf').value=='') {
		alert('O campo CPF é obrigatório!');
		document.getElementById('t_cpf').focus();
		return false;
	}
	if(!validaCPF(document.getElementById('t_cpf').value)) {
		document.getElementById('t_cpf').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_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_telefone').value=='') {
		alert('O campo telefone é obrigatório!');
		document.getElementById('t_telefone').focus();
		return false;
	}
	if($('input:checkbox[id*=cb_interesses]:checked').size() == 0){
	    alert('Selecione pelo menos uma área de interesse!');
		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_atividade').value=='') {
		alert('O campo atividade da empresa é obrigatório!');
		document.getElementById('t_atividade').focus();
		return false;
	}
	return true;
}

/* ******************  NEWSLETTER *********************** */

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;
}


/* ******************  BUSCA *********************** */

function validar_pesquisa(){
    if(document.getElementById('buscar').value=='buscar no site...' || document.getElementById('buscar').value=='') {
        alert('Digite o termo a ser pesquisado!');
		document.getElementById('buscar').focus();	
		return false;
    }
    return true;
}