/* ***************** 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 erro_galeria() {
	alert("Não existe imagem cadastrada!");
	return false;
}

function AbrirMapa(){
    window.open('imagens/mapa_g.jpg','','toolbar=0,location=0,directories=0,status=no,menubar=0,scrollbars=1,resizable=1,width=600,height=385,top=20,left=20');
}

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');");
}


/* *******************  MENU  ********************* */

var menu_ativo = null;
var submenu_ativo = null;

function selecionar_menu(menu, submenu, seletor){
    if(document.getElementById(submenu).style.display == 'none'){
        if(submenu_ativo != null){ $("#"+submenu_ativo).hide("slow"); }
		if(menu_ativo != null){ document.getElementById(menu_ativo).className = "menu_item"; }
		if(seletor == 1){
		    if($("#"+submenu+" div").size() > 0){
		        $("#"+submenu).show("slow");
		    }
		} else {
		    if($("#"+submenu+" div").size() > 0){
		        $("#"+submenu).show();
		    }
		}
		$("#"+menu).toggleClass("menu_item_over");
		menu_ativo = menu;
		submenu_ativo = submenu;
	}
}

function configurar_menu() {
	var id = document.getElementById('h_menu');
	if(id.value!=0) {
		var menu = document.getElementById("menu_" + id.value).id;
		var submenu = document.getElementById("submenu_" + id.value).id;
		var refer = document.referrer;
        if(refer.search("pM="+menu.replace("menu_","")) != "-1"){
            selecionar_menu(menu,submenu,2);
        } else {
            selecionar_menu(menu,submenu,1);
        }		
	}
}

/* ***************** DEFAULT ************************** */

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 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 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_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') { 
		alert('O campo email é 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;
}

/* ******************* 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_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;
}

/* ******************* 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_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;
}

/* ******************  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=='Pesquisar' || document.getElementById('buscar').value=='') {
        alert('Digite o termo a ser pesquisado!');
		document.getElementById('buscar').focus();	
		return false;
    }
    return true;
}

	function abrirpopup(pagina){
	window.open('galeria.html','popup','width=784,height=590,toolbar= no,scrollbars=no');
	}