var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var padrao_fone = /\(?\d{2}\) ?\d{4}-\d{4}/;
var padrao_data = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;
var padrao_cep = /\d{5}\-\d{3}/;
function $(ID) { return document.getElementById(ID); }
function $$(tag) { return document.getElementByTagName(tag); }
function mostrar_esconder(area) { if ($(area).style.visibility=='visible') { esconder(area,'nao'); } else { $(area).style.visibility='visible'; $(area).style.display = 'block'; } }
function mostrar(area) { $(area).style.visibility='visible'; $(area).style.display = 'block'; } 
function esconder(area,limpa) { $(area).style.visibility='hidden'; $(area).style.display = 'none'; if (!limpa) { $(area).innerHTML = ''; } }
function menu(estado,menu_salta,menu_corpo,fundo,cor,margem) { if (estado=='over') { if (ie5) { tag_esconde('esconde'); margem=margem-756; }  $(menu_corpo).style.visibility='visible'; $(menu_corpo).style.marginLeft=margem+'px'; $(menu_salta).style.backgroundColor=fundo; $(menu_salta).style.color=cor; $(menu_salta).style.cursor='pointer'; } if (estado=='out') { if (ie5) { tag_esconde('mostra'); } $(menu_corpo).style.visibility='hidden'; $(menu_salta).style.backgroundColor=fundo; $(menu_salta).style.color=cor; } }
function tag_esconde(tipo){ var oSelects=document.getElementsByTagName("select"); if (tipo=='esconde') { tipo='hidden'; } if (tipo=='mostra') { tipo='visible'; } for(var i=0;i<oSelects.length;i++) oSelects[i].style.visibility=tipo; }
function abre_url(ligar) { window.location.href=ligar; }
function carregando(acao,larg,alt)
{
 if (acao=='mostra') { 
 car = $('id_carregando'); 
 car.style.position="absolute"; 
 car.style.visibility='visible'; car.style.display = 'block'; 
 car.style.zIndex="300"; car.style.background="#CC0000"; 
 car.style.color= "#fff"; 
 car.style.padding="7px 16px 8px 16px"; 
 car.style.margin= "0"; 
 car.style.fontSize= "15px"; 
 car.style.fontWeight= "bold"; 
 car.innerHTML="Carregando..."; 
 centralizar(car,larg,alt); 
}
 if (acao=='esconde') { esconder('id_carregando'); }
}

function centralizar(obj,larg,alt)
{
 var largura = larg; 
 var altura  = alt; 
 var coord = new coordenadas(); 
 var scroll_top  = coord.topo(); 
 var scroll_left = coord.esquerda(); 
 var doc_largura = coord.largura(); 
 var doc_altura = coord.altura(); 
 var top_posicao = (doc_altura>altura)? (((scroll_top+doc_altura)/2)-(altura/2))+"px" : (scroll_top+10)+"px";
 obj.style.left = ((doc_largura/2)-(largura/2))+"px"; 
 obj.style.top  = Math.floor(parseInt(top_posicao))+"px";
}
/*****************
// FORMULARIOS
*****************/
function campo_errado(rotulo,campo,msg) { alert(msg); if (rotulo) { $(rotulo).className = 'rotulo_errado'; } $(campo).className = 'campo_errado'; $(campo).focus(); }
function campo_correto(rotulo,campo) { if (rotulo) { $(rotulo).className = 'rotulo_correto'; } $(campo).className = 'campo_correto'; }
function formatar_mascara(src, mascara) { var campo = src.value.length; var saida = mascara.substring(0,1); var texto = mascara.substring(campo); if(texto.substring(0,1) != saida) { src.value += texto.substring(0,1); } }
function formata_fone(objeto) { var obj = $(objeto).value; separador1 = '('; separador2 = ')'; separador3 = '-'; conjunto1 = 0; conjunto2 = 3; conjunto3 = 8; if (obj.length == 0) { obj = '(' + obj ; } if (obj.length == 3) { obj = obj + ') ' ; } if (obj.length == 9) { obj = obj + "-" ; } $(objeto).value = obj; }
function valida_email(str) { var pass = 0; if (window.RegExp) { var tempStr = "a"; var tempReg = new RegExp(tempStr); if (tempReg.test(tempStr)) pass = 1;} if (!pass)return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)"); var r2 = new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"); return (!r1.test(str) && r2.test(str)); }
function busca_geral() { var area = $('area_busca'); mostrar('area_busca'); key = $('key').value; local = $('local').value; if (key=='') { campo_errado('key1','key','Por favor digite o algo para efetuar a busca.'); return false; } else { campo_correto('key1','key'); } if($('tipo_busca_todas').checked)    { tipo_busca = 'TODAS PALAVRAS'; } if($('tipo_busca_qualquer').checked) { tipo_busca = 'QUALQUER PALAVRA'; } if($('tipo_busca_frase').checked)    { tipo_busca = 'FRASE'; } var pag="include/pesquisar.php?key="+key+'&tipo_busca='+tipo_busca+'&local='+local; abre(pag,"area_busca",false,false,true); }
/*///////////////
//  funções FADE
*////////////////
function fade(id, opacStart, opacEnd, millisec) 
{
 var speed = Math.round(millisec / 100);
 var timer = 0;
 if(opacStart > opacEnd) { for(i = opacStart; i >= opacEnd; i--) { setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); timer++; } } 
 else if(opacStart < opacEnd) { for(i = opacStart; i <= opacEnd; i++) { setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); timer++; } }
}
function changeOpac(opacity, id) 
{
 var object = $(id).style;
 object.opacity = (opacity / 100);
 object.MozOpacity = (opacity / 100);
 object.KhtmlOpacity = (opacity / 100);
 object.filter = "alpha(opacity=" + opacity + ")";
}  
// FUNCAO Q MONTA AS ABAS
function abas(area,id,titulo_fundo,titulo_fonte,titulo_fundo2)
{
 var area = 'aba_'+area; var ullist = $(area).getElementsByTagName('li');
 for (var i=0; i<ullist.length; i++) { if (i!=id) { var abas_t = area+'_'+i; $(abas_t).style.background=titulo_fundo2; $(abas_t).style.color='#444'; $(abas_t).style.top = '0'; var corpo = area+'_'+i+'_corpo'; $(corpo).style.display = 'none'; } }
 var a = area+'_'+id; $(a).style.background = titulo_fundo; $(a).style.color = titulo_fonte; $(a).style.position = 'relative'; $(a).style.top = '1px'; $(a).style.borderBottom = 'none'; var corpo = area+'_'+id+'_corpo'; $(corpo).style.display = 'block';
}
/*////////////////////
// funções de IMAGENS
*/////////////////////
function coordenadas() 
{
 if (ie5) { standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body; }
 this.topo = function(){ return (ie5)? standardbody.scrollTop : window.pageYOffset; }
 this.esquerda = function(){ return (ie5)? standardbody.scrollLeft : window.pageXOffset; }
 this.largura = function(){ return (ie5)? standardbody.clientWidth : window.innerWidth-16; }
 this.altura = function(){ return (ie5)? standardbody.clientHeight: window.innerHeight; }
}
function video_tamanho(elem,larg,alt){ var video = $(elem); var obj = video.getElementsByTagName('object')[0]; obj.setAttribute('width', larg); obj.setAttribute('height', alt); var embed = video.getElementsByTagName('embed')[0]; embed.setAttribute('width', larg); embed.setAttribute('height', alt); }
// AUMENTA TAMANHO DA FONTE DE UMA DETERMINA ID
var fs = new Array('12px','16px','20px' );
var contador = 0;
function tamanhoFonte(x,area)
{
 if(x == 1) { if(contador < fs.length - 1) { contador++; $(area).style.fontSize = fs[contador]; } }
 if( x == 0) { if(contador > 0) { contador--; $(area).style.fontSize = fs[contador]; } }
}
/**************
//	Light v1.00
**************/
function foto_light(foto,larg,alt,pai)
{
 var objBody = pai.document.getElementsByTagName("body").item(0);
 var pag_larg = objBody.offsetWidth; var pag_alt = objBody.offsetHeight+8;
 if (ie5) { tag_esconde('esconde'); pag_larg = pag_larg-21; pag_alt = pag_alt+148; }
 var objAntes = pai.document.createElement("div"); objAntes.setAttribute('id','div_antes'); objAntes.style.background = '#000'; objAntes.style.position = 'absolute'; objAntes.style.zIndex = '80'; objAntes.style.width = pag_larg+'px'; objAntes.style.height = pag_alt+'px'; objAntes.style.top = objAntes.style.bottom = objAntes.style.left = '0'; objAntes.style.opacity = objAntes.style.MozOpacity = objAntes.style.KhtmlOpacity = (0.75); objAntes.style.filter = "alpha(opacity=75)";
 objBody.appendChild(objAntes);
 var objLytebox = pai.document.createElement("div"); objLytebox.setAttribute('id','div_borda'); objLytebox.style.position = 'absolute'; objLytebox.style.zIndex = '100'; objLytebox.style.background = "#fff"; objLytebox.style.padding="5px"; 
 objBody.appendChild(objLytebox);
 pai.centralizar(objLytebox,larg,alt);
 var objImage = pai.document.createElement("img"); objImage.setAttribute('border','0'); objImage.setAttribute('src',foto); objImage.setAttribute('id','id_foto'); objImage.setAttribute('name','id_foto'); objImage.setAttribute('width',larg+'px'); objImage.setAttribute('height',alt+'px'); 
 objLytebox.appendChild(objImage);
 var objBoxRodape = pai.document.createElement("div"); objBoxRodape.setAttribute('id','div_borda_rodape'); objBoxRodape.style.zIndex = '100'; objBoxRodape.style.background = "#eee"; objBoxRodape.style.padding = "4px"; objBoxRodape.style.textAlign = "center"; objBoxRodape.innerHTML = "<input id='botao_fecha' value='fechar' type='submit'>"; 
 objLytebox.appendChild(objBoxRodape);
 objAntes.onclick = pai.$('botao_fecha').onclick = function() { foto_apaga(pai); };
}
function foto_apaga(pai) { if (ie5) { tag_esconde('mostra'); } var Body = pai.document.getElementsByTagName("body").item(0); Body.removeChild(pai.$('div_antes')); Body.removeChild(pai.$('div_borda')); }

function frame_light(html,larg,alt,barra,pai)
{
  var objBody = pai.document.getElementsByTagName("body").item(0);

  var pag_larg = objBody.offsetWidth;  
  var pag_alt = objBody.offsetHeight+8;

  if (ie5) { tag_esconde('esconde'); pag_larg = pag_larg-21; pag_alt = pag_alt+148; }

  var objAntes = pai.document.createElement("div"); 
  objAntes.setAttribute('id','div_antes'); 
  objAntes.style.background = '#000'; 
  objAntes.style.position = 'absolute'; 
  objAntes.style.zIndex = '80'; 
  objAntes.style.width = pag_larg+'px'; 
  objAntes.style.height = pag_alt+'px'; 
  objAntes.style.top = objAntes.style.bottom = objAntes.style.left = '0'; objAntes.style.opacity = objAntes.style.MozOpacity = objAntes.style.KhtmlOpacity = (0.75); objAntes.style.filter = "alpha(opacity=75)";
  objBody.appendChild(objAntes);

  
  var objLytebox = pai.document.createElement("div"); objLytebox.setAttribute('id','div_frame'); objLytebox.style.position = 'absolute'; objLytebox.style.zIndex = '100'; objLytebox.style.background = "#fff"; 
  objBody.appendChild(objLytebox);
  pai.centralizar(objLytebox,larg,alt);
//  fade('div_frame', 30, 100, 1000);

  pai.carregando('mostra',150,20);

  var objIframe = pai.document.createElement("iframe"); objIframe.setAttribute('frameborder','0'); 
  if (barra) { objIframe.style.overflow = 'auto'; } else { objIframe.setAttribute('scrolling','no'); }
  objIframe.setAttribute('src',html); objIframe.setAttribute('id','id_frame'); objIframe.setAttribute('name','id_frame'); objIframe.setAttribute('width',larg+'px'); objIframe.setAttribute('height',alt+'px');
  objLytebox.appendChild(objIframe);

  var objBoxRodape = pai.document.createElement("div"); objBoxRodape.setAttribute('id','div_frame_rodape'); objBoxRodape.style.zIndex = '100'; objBoxRodape.style.background = "#eee"; objBoxRodape.style.padding = "4px"; objBoxRodape.style.borderTop = "1px solid #ccc"; objBoxRodape.style.textAlign = "center"; objBoxRodape.innerHTML = "<input id='botao_fecha' value='fechar' type='submit'>"; 
  objLytebox.appendChild(objBoxRodape);

  objAntes.onclick = pai.$('botao_fecha').onclick = function() { frame_apaga(pai); };

}
function frame_apaga(pai)
{
 if (ie5) { tag_esconde('mostra'); }
 var Body = pai.document.getElementsByTagName("body").item(0);
 Body.removeChild(pai.$('div_antes')); Body.removeChild(pai.$('div_frame'));
 pai.carregando('esconde');
}
/********
* Ajax 
*********/
function OpenAjax() { var obj; try { obj = new XMLHttpRequest(); } catch(ee) { try { obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { obj=false; } } } return obj; }
function extrai_script(texto) { var ini = 0; while (ini!=-1) { ini = texto.indexOf('<script', ini); if (ini >=0) { ini = texto.indexOf('>', ini) + 1; var fim = texto.indexOf('</script>', ini); codigo = texto.substring(ini,fim); eval(codigo); } } }
function abre(pag,area,esconder,area_seta,carregando) 
{ 
 if (area_seta) { seta_muda(area_seta); } 
 var Area = $(area); 
 if (esconder) { if(Area.innerHTML) { Area.innerHTML = ''; Area.style.display = 'none'; Area.style.visibility='hidden'; return; } else { Area.style.display = 'block'; Area.style.visibility = 'visible'; } } 
 var obj = new OpenAjax(); obj.open('GET', pag, true); 
 obj.setRequestHeader('Cache-Control','no-store, no-cache, must-revalidate'); 
 obj.setRequestHeader('Cache-Control','post-check=0, pre-check=0'); 
 obj.setRequestHeader('Pragma','no-cache'); 
 obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
 obj.onreadystatechange = function() 
 { 
  if (carregando) { car = $('id_carregando'); car.style.position='absolute'; car.style.visibility='visible'; car.style.display = 'block'; car.style.zIndex='300'; car.style.background='#CC0000'; car.style.color= '#fff'; car.style.padding='7px 16px 8px 16px'; car.style.margin= '0'; car.style.fontSize= '15px'; car.style.fontWeight= 'bold'; car.innerHTML='Carregando...'; centralizar(car,car.offsetWidth,car.offsetHeight); } 
  if (obj.readyState == 4) 
  { 
   var resultado = obj.responseText; 
   resultado = resultado.replace(/\+/g,' '); 
   resultado = unescape(resultado); 
   Area.innerHTML = resultado; 
   extrai_script(resultado); 
   mostrar(area); 
   if (carregando) { car.style.visibility='hidden'; car.style.display = 'none'; } 
  }
 } 
 obj.send(null); 
}
/*
// CONTATO
*/
function email_validar()
{
 nome = $('nome').value; fone = $('fone').value; 
 email_cont = $('email_contato').value; 
 assunto = $('assunto').value; 
 mensagem = $('mensagem').value; 
 OK = padrao_fone.exec(fone);
 if (nome=='') { campo_errado('nome1','nome','Por favor digite o NOME de Contato.'); return; } else { campo_correto('nome1','nome'); }
 if (fone=='') { campo_errado('fone1','fone','O campo TELEFONE de contato é obrigatório!\nUse o formato (99) 9999-9999'); return; } else { campo_correto('fone1','fone'); }
 if (!OK) { campo_errado('fone1','fone','Digite o campo TELEFONE de contato corretamente\nusando o formato (99) 9999-9999'); return; } else { campo_correto('fone1','fone'); }
 if (!valida_email(email_cont)) { campo_errado('email1','email_contato','Por favor digite o seu E-MAIL corretamente.'); return; } else { campo_correto('email1','email_contato'); }
 if (assunto=='') { campo_errado('assunto1','assunto','Por favor digite o ASSUNTO da mensagem.'); return; } else { campo_correto('assunto1','assunto'); }
 if (mensagem=='') { campo_errado('mensagem1','mensagem','Por favor digite a MENSAGEM.'); return; } else { campo_correto('mensagem1','mensagem'); }
 document.form_email.submit();
}