function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function doClock(){ 
  var t=new Date(),a=doClock.arguments,str="",i,a1,lang="8";
  var month=new Array('Janeiro','Jan','Fevereiro', 'Fev','Março', 'Mar','Abril', 'Abr','Maio', 'Mai','Junho', 'Jun','Julho', 'Jul','Agosto', 'Ago','Setembro', 'Set','Outubro', 'Out','Novermbro', 'Nov','Dezembro', 'Dez');
  var tday= new Array('Domingo', 'Dom','Segunda-feira', 'Seg','Terça-feira', 'Ter','Quarta-feira', 'Qua','Quinta-feira', 'Qui','Sexta-feira', 'Sex','Sábado', 'Sab');
  for(i=0;i<a.length;i++) {a1=a[i].charAt(1);switch (a[i].charAt(0)) {
  case "M":if  ((Number(a1)==3) && ((t.getMonth()+1)<10)) str+="0";
  str+=(Number(a1)>1)?t.getMonth()+1:month[t.getMonth()*2+Number(a1)];break;
  case "D": if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;
  case "Y": str+=(a1=='0')?t.getFullYear():t.getFullYear().toString().substring(2);break;
  case "W":str+=tday[t.getDay()*2+Number(a1)];break; default: str+=unescape(a[i]);}}return str;
}

function isEmailAddr(email) {
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0) {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function filtro_SoNumeros() {
	if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;
}

function mascara_FONE(Campo, teclapres){
	var tecla = teclapres.keyCode;
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1 ;
	if (tam > 4)
		Campo.value = vr.substr(0, 4) + '-' + vr.substr(4, tam);
}

function mudacampo(campo, tam, proximo) {
	if (campo.value.length == tam) {
		proximo.focus();
	}
}

function voto_poll() {
   var remote = null;
   remote = window.open('', 'votacao', 'width=300, height=350, resizable=0');
}

function voto_pollTJ() {
   var remote = null;
   remote = window.open('', 'votacao1', 'width=300, height=370, resizable=0');
}
function makingof(foto, w, h) {
	window.open('makingof.php?id=' + foto, 'foto', 'width=' + w + ', height=' + h + ', resizable=0')
}

function standard1(parm) {
	window.document.tv.SetVariable("volta", parm);
}
function standard2(parm) {
	window.document.tv.SetVariable("avanca", parm);
}

function val_contato() {
	var frm = document.forms[0];
	if (frm.nome.value == "") {
		alert("Você deve preencher o seu NOME");
		frm.nome.focus();
		return false;
	}
	if (frm.email.value == "") {
		alert("Você deve preencher o seu E-MAIL");
		frm.email.focus();
		return false;
	} else {
		if (!isEmailAddr(frm.email.value)) {
			alert("Informe um endereço de E-MAIL válido!");
			frm.email.value = "";
			frm.email.focus();
			return false;
		}
	}
	if (frm.msg.value == "") {
		alert("Digite sua MENSAGEM");
		frm.msg.focus();
		return false;
	}
	frm.submit();
	return true;
}

function openprint(id) {
	window.open('not-print.php?id=' + id, 'printnot', 'scrollbars=1, width=570, height=450');
}

function openreceitaprint(id) {
	window.open('receita-print.php?id=' + id, 'printrec', 'scrollbars=1, width=570, height=450');
}

function val_indicacao() {
	var frm = document.formu;
	var doc = document;
	if (frm.nome1.value == "" || frm.email1.value == "" || frm.nome2.value == "" || frm.email2.value == "") {
		show('alerta1');
		if (frm.nome1.value == "")
			doc.getElementById('nome1').style.color='#FF0000';
		if (frm.email1.value == "")
			doc.getElementById('email1').style.color='#FF0000';
		if (frm.nome2.value == "")
			doc.getElementById('nome2').style.color='#FF0000';
		if (frm.email2.value == "")
			doc.getElementById('email2').style.color='#FF0000';
		return false;
	} else {
		if (!isEmailAddr(frm.email1.value) || !isEmailAddr(frm.email2.value)) {
			show('alerta2');
			if (!isEmailAddr(frm.email1.value)) {
				doc.getElementById('email1').style.color='#FF0000';
				frm.email1.value = "";
			} else {
				doc.getElementById('email2').style.color='#FF0000';
				frm.email2.value = "";
			}
			return false;
		}
	}
	hide('form');
	frm.submit();
	return true;
}

function val_news() {
	var frm = document.news;
	if (frm.news_nome.value == "") {
		alert("Preencha o campo com seu NOME");
		frm.news_nome.focus();
		return;
	}
	if (frm.news_mail.value == "") {
		alert("Preencha o campo com seu E-MAIL");
		frm.news_mail.focus();
		return;
	} else {
		if (!isEmailAddr(frm.news_mail.value)) {
			alert("Informe um endereço de E-MAIL válido!");
			frm.news_mail.value = "";
			frm.news_mail.focus();
			return;
		}
	}
	frm.submit();
	return true;
}

function val_pesq() {
	var frm = document.pesquisa;
	if (frm.nome.value == "") {
		alert("Informe seu NOME");
		frm.nome.focus();
		return false;
	}
	if (frm.email.value == "") {
		alert("Informe seu E-MAIL");
		frm.email.focus();
		return false;
	} else {
		if (!isEmailAddr(frm.email.value)) {
			alert("Informe um endereço de e-mail VÁLIDO");
			frm.email.value = "";
			frm.email.focus();
		}
	}
	frm.submit();
	return true;
}

function rand(n) {
        seed = (0x015a4e35 * seed) % 0x7fffffff;
        return (seed >> 16) % n;
}

 var now = new Date();
 var seed = now.getTime() % 0xffffffff;

// array
function makeArray(len) {
        for (var i=0; i < len; i++) {
                this[i] = null;
                this.lenght = len;
        }
}
function akeru(id) {
   var remote = null;
   remote = window.open('video1_pop.php?id='+id,'video_miru',  'width=320,height=266,resizable=no,status=no,toolbar=no,menubar=no,scrollbars=no');
}

/* ********************************************
 * Retorna o document.getElementById
 */
function ge(e) { return document.getElementById(e); }

/* ********************************************
 * Outras categorias
 */
function outras_categorias() {
	if (ge('outras_categorias')) {
		var outras_categorias = ge('outras_categorias');
		outras_categorias.onclick = function(){
			var cat = ge('cat').value;
			if (cat != '') {
				document.location = cat;
			}
		}
	}
}

/* ********************************************
 * Limpa campo busca com o foco no campo
 */
function limpaBusca() {
	if (document.getElementById('cidade_busca')) {
		var cidade_busca = document.getElementById('cidade_busca');
		cidade_busca.onfocus = function() {
			if (this.value == 'Digite o nome da Cidade') {
				this.value = '';
			}
		}
		cidade_busca.onblur = function () {
			if (this.value == '') {
				this.value = 'Digite o nome da Cidade';
			}
		}
	}
}

function verifica_login() {
	if (ge('verifica_login_form')) {
		ge('verifica_login_form').onsubmit = function() {
			if (ge('verifica_login')) {
				var verifica_login = ge('verifica_login');
				var usuario = ge('usuario');
				var senha = ge('senha');
				if (usuario.value == '') {
					alert('Favor preencher o campo com seu nome de usuario!');
					usuario.focus();
					return false
				}
				if (senha.value == ''){
					alert('Favor preencher o campo com sua senha!');
					senha.focus();
					return false;
				}
				return true;
			}
			return false;
		}
	}
}

function botaoVoltar() {
	if (ge('voltar')) { 
		var voltar = ge('voltar');
		voltar.onclick = function () {
			history.back();
			return false;
		}
	}
}

/* ********************************************
 * Adicionar aos favoritos
 */
function addFav(){
	if (ge('adicionar_favoritos')) {
		ge('adicionar_favoritos').onclick = function() {
			var agent 	= window.navigator.userAgent.toLowerCase();
			var msie 	= agent.indexOf('msie') >= 0;
			var firefox = agent.indexOf('firefox') >= 0;
			if (firefox) {
				window.sidebar.addPanel(title, url, true);
			}
			else if (msie) {
				window.external.AddFavorite(url, title);
			}
			else {
				alert('Para adicionar aos favoritos aperte Ctrl+D');
			}
			return false;
		}
	}
}

/* ********************************************
 * Valida email
 */
function is_email(email) {
	var er = /^[a-zA-Z0-9][a-zA-Z0-9\._-]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/;
	return er.exec(email) ? true : false;
}

/* ********************************************
 * Resgata width e height da pagina e browser
 */
function getPageSize(){		 
	 var xScroll, yScroll;		 
	 if (window.innerHeight && window.scrollMaxY) {    
		  xScroll = document.body.scrollWidth;
		  yScroll = window.innerHeight + window.scrollMaxY;
	 } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		  xScroll = document.body.scrollWidth;
		  yScroll = document.body.scrollHeight;
	 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		  xScroll = document.body.offsetWidth;
		  yScroll = document.body.offsetHeight;
	 }		 
	 var windowWidth, windowHeight;
	 if (self.innerHeight) {    // all except Explorer
		  windowWidth = self.innerWidth;
		  windowHeight = self.innerHeight;
	 } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		  windowWidth = document.documentElement.clientWidth;
		  windowHeight = document.documentElement.clientHeight;
	 } else if (document.body) { // other Explorers
		  windowWidth = document.body.clientWidth;
		  windowHeight = document.body.clientHeight;
	 }   		 
	 // for small pages with total height less then height of the viewport
	 if(yScroll < windowHeight){
		  pageHeight = windowHeight;
	 } else {
		  pageHeight = yScroll;
	 }
	 // for small pages with total width less then width of the viewport
	 if(xScroll < windowWidth){    
		  pageWidth = windowWidth;
	 } else {
		  pageWidth = xScroll;
	 }
	 arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
}

/* ********************************************
 * Busca geral
 */
function busca_geral() {
	if (ge('busca_geral')) {
		var busca_restaurante = ge('busca_geral');
		busca_restaurante.onclick = function(){
			var cat = ge('cat').value;
			if (cat != '') {
				document.location = cat;
			}
		}
	}
}

/* ********************************************
 * Busca microregião
 */
function busca_microregiao() {
	if (ge('busca_microregiao')) {
		var busca_restaurante = ge('busca_microregiao');
		busca_restaurante.onclick = function(){
			var cat = ge('micro').value;
			if (cat != '') {
				document.location = cat;
			}
		}
	}
}

/* ********************************************
 * Busca mesoregião
 */
function busca_mesoregiao() {
	if (ge('busca_mesoregiao')) {
		var busca_restaurante = ge('busca_mesoregiao');
		busca_restaurante.onclick = function(){
			var cat = ge('meso').value;
			if (cat != '') {
				document.location = cat;
			}
		}
	}
}

/* ********************************************
 * Busca mesoregião
 */
function busca_hoteis() {
	if (ge('busca_hoteis')) {
		var busca_hoteis = ge('busca_hoteis');
		busca_hoteis.onclick = function(){
			var cat = ge('cat').value;
			document.location = cat;
		}
	}
}

/* ********************************************
 * Replace all
 */ 
function replaceAll(str, de, para){
	var pos = str.indexOf(de);
	while (pos > -1){
		str = str.replace(de, para);
		pos = str.indexOf(de);
	}
	return (str);
}

/* ********************************************
 * Validação de CPF
 */ 
function validaCPF(cpf){ 
	var i;
	var s = cpf;
	s = replaceAll(s, '.', '');
	s = replaceAll(s, '/', '');
	s = replaceAll(s, '-', '');
	if (isNaN(s)) {
		return false;
	}
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++) {
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0){ return false; }
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1) { return false; }
	d1 *= 2;
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(11-i);
	} 
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) { return false; }
	return true;
}

/* ********************************************
 * Validação de CNPJ
 */ 
function validaCNPJ(cnpj) {
	var s = cnpj;
	s = replaceAll(s, '.', '');
	s = replaceAll(s, '/', '');
	s = replaceAll(s, '-', '');
	if (isNaN(s)) {
		return false;
	}
	var i;
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i <12; i++){
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
	if (d1 == 0)
	return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}
	d1 *= 2;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9)
		d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}
	return true;
}

/* ********************************************
 * Funções ao carregar a pagina
 */
window.onload = function() {
	limpaBusca();
	outras_categorias();
	verifica_login();
	botaoVoltar();
	addFav();
	busca_geral();
	busca_microregiao();
	busca_mesoregiao();
	busca_hoteis();
}