// JavaScript Document


// NOVA JANELA
function NovaJanela(mypage, myname, w, h, scroll, status) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+', status='+status+''
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus();
}
}

// janela menu
function JanelaMenu(mypage, myname, w, h, scroll, status, menu) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+', status='+status+', menubar='+menu+''
win = window.open(mypage, myname, winprops)
	if(parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}

// FAVORITOS
function bookmarksite(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}


// tira o controle do flash
function flash(arqflash,largura,altura) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
	document.write('<param name="movie" value="' + arqflash + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="' + arqflash + '" width="' + largura + '" height="' + altura + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" wmode="transparent"></embed>');
	document.write('</object>');
}
// EMAIL
function mail(email){
	var email = decode64(email);
	document.location.href='mailto:'+email;
}

// 
function decode64(input) {

   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

// TROCA ENTRE
function trocaEnter(campo, evt) {
    var e = evt || event;
    k = e.keyCode;
    
    if(k == 13) {
		buscar();
        return false;
    }
}


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 cancelarContato(){
	if(confirm("Deseja realmente cancelar seu contato?")){
		window.top.location = "index.php";
	}
}
function confirmarContato(){
	nome = document.frmContato.NOME.value;
	empresa = document.frmContato.EMPRESA.value;
	cidade = document.frmContato.CIDADE.value;
	estado = document.frmContato.ESTADO.value;
	assunto = document.frmContato.ASSUNTO.value;
	mensagem = document.frmContato.MENSAGEM.value;
	retorno = document.frmContato.RETORNO.value;
	telefone = document.frmContato.TELEFONE.value;
	email = document.frmContato.EMAIL.value;
	motivo = document.frmContato.MOTIVO.value;
		
		if((nome != "") && (cidade != "") && (assunto != "") && (mensagem != "") && (telefone != "") && (email != "")){
			if(checkMail(email)) {
				document.frmContato.submit();
			} else {
				alert("O email informado não é válido!")
			}
		} else {
			alert("Preencha todos os campos marcados com asterisco (*)!")
		}
}

// BUSCA
// LIMPA CAMPO
function limpaCampo(){
	if(document.getElementById("BUSCA").value == "Efetue sua busca aqui!"){
		document.getElementById("BUSCA").value = "";
		document.getElementById("BUSCA").style.fontSize = "12px";
		document.getElementById("BUSCA").style.color = "#000000";
		document.getElementById("BUSCA").style.padding = "3 0 0 5";
	}
}
function mostraCampo(){
	if(document.getElementById("BUSCA").value == ""){
		document.getElementById("BUSCA").value = "Efetue sua busca aqui!";
		document.getElementById("BUSCA").style.fontSize = "10px";
		document.getElementById("BUSCA").style.color = "#999999";
	}
}

// VALIDA BUSCA
function validaBusca(){
	if(document.getElementById("BUSCA").value == "Efetue sua busca aqui!"){
		alert("Informe no campo busca a palavra que deseja buscar!");		
	} else {
		if(document.getElementById("BUSCA").value == ""){
			alert("Informe no campo busca a palavra que deseja buscar!");		
		} else {
			window.location='index.php?action=busca&b='+document.getElementById("BUSCA").value;
		}
	}
}

// TROCA ENTRE
function trocaEnterBusca(campo, evt) {
    var e = evt || event;
    k = e.keyCode;
    
    if(k == 13) {
		validaBusca();
        return false;
    }
}

// EXCLUIR SALVO
function contaClick(id){
	var head = document.getElementsByTagName('head').item(0);
	var eScript = document.createElement("script");
	eScript.setAttribute('src','acoes.php?acao=click&id='+id);
	head.appendChild(eScript);
}

// BOTOES
function mostraSetaVoltar(){
	document.getElementById("setaVoltar").style.display = "block";
}
function ocultaSetaVoltar(){
	document.getElementById("setaVoltar").style.display = "none";
}
function mostraSetaAvancar(){
	document.getElementById("setaAvancar").style.display = "block";
}
function ocultaSetaAvancar(){
	document.getElementById("setaAvancar").style.display = "none";
}


function fotoMover(i,id,tipo){
	f = document.getElementById("fotoAtual").value;
	m = document.getElementById("maximoFotos").value;
	var head = document.getElementsByTagName('head').item(0);
	var eScript = document.createElement("script");
	eScript.setAttribute('src','acoes.php?acao=foto&fotoatual='+f+'&i='+i+'&id='+id+'&tipo='+tipo+'&m='+m);
	head.appendChild(eScript);
}


// NOTICIAS
function noticias(){
	i = document.getElementById("LAYER_ATUAL").value; // i
	var head = document.getElementsByTagName('head').item(0);
	var eScript = document.createElement("script");
	eScript.setAttribute('src','acoes.php?acao=noticia&i='+i+'&op=andar');
	head.appendChild(eScript);
}

function mostraNoticia(i){
	document.getElementById("LAYER_ATUAL").value = i;
	var head = document.getElementsByTagName('head').item(0);
	var eScript = document.createElement("script");
	eScript.setAttribute('src','acoes.php?acao=noticia&i='+i+'&op=parar');
	head.appendChild(eScript);
}
// LAYERS
function ajustaLayers(){
	if (navigator.appName=="Microsoft Internet Explorer"){
//		var alturaLayerTitulo = document.getElementById("noticiaPrincipal").clientHeight;
//		document.getElementById("fundoTitulo").style.height = (alturaLayerTitulo + 5);
	} else {
//		var alturaLayerTitulo = document.getElementById("noticiaPrincipal").offsetHeight;
//		document.getElementById("fundoTitulo").style.height = (alturaLayerTitulo + 60);
	}
}
