var deslocaBrowser;
var voltando=0;
var bannerCorrente = 0;
//-------------------
if (document.layers) {deslocaBrowser = false;}
if (document.all) {
	deslocaBrowser = false;
	}//IE
if (window.navigator.userAgent.toLowerCase().match("gecko")) {deslocaBrowser= true;}


//VALIDACAO=======================
function validaIE(){
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	 	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
		return ieversion;
		}
	}
function validarData(campo) {
    var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
    var msgErro = 'Formato inválido de data.';
	if(campo.value!=""){
		if ((campo.value.match(expReg)) && (campo.value!='')) {
			return true;
		} else {
			alert(msgErro);
			campo.focus();
			return false;
		}
	}
	else{
		return true;
		}

}
var reDigits = /^\d+$/;

function doDigits(pStr){
	if (reDigits.test(pStr.value)) {
	} else if (pStr.value != null && pStr.value != "") {
		pStr.value="";
		
	}
}
//FUNCOES DIVERSAS=======================
function alinhamento(){
	//alinha a pizza e as dicas
	var pratos =  document.getElementById("imgOverContent");
//	var dicas =  document.getElementById("dicaContent");
	deslocamento = (screen.width/2)+436-318+deslocaBrowser;
	deslocamento2 = (screen.width/2)+366-265+deslocaBrowser;

	pratos.style.marginLeft = deslocamento+"px";
	//dicas.style.marginLeft = deslocamento2+"px";

	pratos.style.marginTop = 226+"px";
	//dicas.style.marginTop = 540+"px";
//se estiver na home, alinha o footer
	var footer_home =  document.getElementById("myContentFooter");
	if(footer_home){
		if(deslocaBrowser){
			footer_home.style.height+=10;
			}
		else{
			versao =  validaIE();
			 if (versao>=7){
	 			 //alert("You're using IE7.x");
				 var bottom_home =  document.getElementById("institucional_home_bottom");
				 if(bottom_home){
					 bottom_home.style.height=218;
					 }				 
			 	}
			}
		
		}
	}
function prato(valor) {
	var movie = document.getElementById("prato_padrao");
	movie.funcaoPrato(valor);
	}
function linkRelacionamento(valor) {
	//var m = document.getElementById("links_rel");
	//m.funcaoLink(valor);
	}
function mostraPrato(){
	var apagaPrato = document.getElementById("imgOverContent");
	apagaPrato.style.display="block";
	}
function apagaPrato(){
	var apagaPrato = document.getElementById("imgOverContent");
	apagaPrato.style.display="none";
	}

function mostraDica(){
	//var apaga = document.getElementById("dicaContent");
	//apaga.style.display="block";
	}
function apagaDica(){
	//var apaga = document.getElementById("dicaContent");
	//apaga.style.display="none";
	}

function carregado(){
		///mostraPrato();
		//apagaDica();
		alinhamento();
		}
//MENUS=================

//======================
var funcaoRetorno = new Array('1');
var valorRetorno = new Array('9');
function voltar(){
		voltando=1;	
		if(funcaoRetorno.length>1){
			
			funcaoRetorno=funcaoRetorno.slice(0,funcaoRetorno.length-1);
			valorRetorno=valorRetorno.slice(0,valorRetorno.length-1);	
			indice=funcaoRetorno.length-1;
			funcao=funcaoRetorno[indice];
			valor=valorRetorno[indice];
			}
		else{
			funcao=1;
			valor=9;
			}
		if(funcao=='1' && valor=='9'){
			funcao=1;
			valor=9;
			}
		switch (funcao) {
			case 1:
				//alert(valor+'d');
				menu_topo(valor);
				//alert(valor+"topo");
				break;
			case 2:
				menu_footer(valor);
				//alert(valor+"topo");
				break;
			case 3:
				visualizaCategoria(valor);
				//alert(valor+"visualiza");
				break;
			case 4:
				menu_institucional(valor);
				//alert(valor+"visualiza");
				break;
			case 5:
				telentrega_espera(valor)
				//alert(valor+"visualiza");
				break;
			case 6:
				menu_lojas(valor)
				//alert(valor+"visualiza");
				break;  
			case 7:
				menu_telentrega(valor);
				//alert(valor+"visualiza");
				break;
			case 8:
				menu_contato(valor);
				//alert(valor+"visualiza");
				break;
			}
		}
		
function atribuiVoltar(funcao,valor){
		valorRetorno.push(valor);
		funcaoRetorno.push(funcao);
		}
//-------------------------------------------------

function visualizaCategoria(id){
		atribuiVoltar(3,id);
		ajaxGet('includes/categorias.php?id='+id,document.getElementById("corpoContent"),true);
		id=id-1;
		prato(id);
		}
		



function menu_topo(indice,qual){
		//alinhamento();
	
		if (voltando == 0) { 
			atribuiVoltar('1',indice);
		} voltando = 0;
		var urls = new Array('institucional','cardapio','telentrega','lojas','cadastre','categorias','diversos','painel','kids','home');
		if(indice=='2'){
  		ajaxGet('includes/banner_tele.php',document.getElementById("bannerContent"),true);
			bannerCorrente= indice;
			}
		else{
			if(bannerCorrente=='2'){
				ajaxGet('includes/banner_main.php',document.getElementById("bannerContent"),true)
				bannerCorrente= indice;
				}
			}
		
		switch (indice) {
			case 0:
				//mostraDica();
				//linkRelacionamento(1);
				mostraPrato();
				prato(13);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true);
				break
			case 1:
				//apagaDica();
				mostraPrato();
				prato(12);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true);
				break
			case 2:
				//apagaDica();
				//mostraPrato();
				//prato(16);
				apagaPrato();
				ajaxGet('includes/'+urls[indice]+'.php?qual=' + qual,document.getElementById("corpoContent"),true);
				break
			case 3:
				//apagaDica();
				mostraPrato();
				prato(12);				
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			case 4:
				//mostraDica();
				//linkRelacionamento(2);
			//	mostraPrato();				
			//	prato(14);
		     	apagaPrato();	
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			case 5:
				mostraPrato();
				prato(15);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			case 6:
				mostraPrato();
				prato(14);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			case 8:
				mostraPrato();
				prato(14);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			case 9:
				apagaPrato();
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			}//switch
		//para retorno
		}
function menu_footer(indice){
		if(voltando==0){ atribuiVoltar(2,indice);} voltando=0;
		var urls = new Array('sac','trabalhe','parceiros','contato');		
			if(bannerCorrente==2){
				ajaxGet('includes/banner_main.php',document.getElementById("bannerContent"),true)
				bannerCorrente= indice+20;
				}
		switch (indice) {
			case 0:
		
				mostraPrato();
				//mostraDica();
				prato(15);
				//linkRelacionamento(3);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			case 1:
				mostraPrato();
				prato(14);
				//linkRelacionamento(4);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			case 2:
				mostraPrato();
				mostraDica();
				prato(14);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			case 3:
				mostraPrato();
				apagaDica();
				prato(14);
				//linkRelacionamento(10);
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("corpoContent"),true)
				break
			default:
				//loadContent('corpoContent','includes/404','GET',"")
			}
		
		}




function menu_institucional(indice){
		if(voltando==0){ atribuiVoltar(4,indice);} voltando=0;
		var urls = new Array('institucional_historico','institucional_padrao','institucional_curiosidades');
			if(bannerCorrente==2){
				ajaxGet('includes/banner_main.php',document.getElementById("bannerContent"),true)
				bannerCorrente= indice+20;
				}
		switch (indice) {
			case 0:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			case 1:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			case  2:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			default:
				ajaxGet('includes/'+urls[1]+'.php?ativo='+indice,document.getElementById("divTextoInstitucional"),true)
			}
		
		}
function menu_contato(indice){
		//alinhamento();
		if(voltando==0){ atribuiVoltar(8,indice);} voltando=0;
		var urls = new Array('contato_formulario','contato_fornecedor','contato_endereco');
		switch (indice) {
			case 0:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			case 1:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			case 2:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			default:
				//loadContent('corpoContent','includes/404','GET',"")
			}
		
		}
function menu_telentrega (indice){
		//apagaPrato();
		bannerCorrente=2;
		if(voltando==0){ atribuiVoltar(7,indice);} voltando=0;
		var urls = new Array('telentrega_itens','telentrega_pesquisa');
		ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional2"),true)
		}
function telentrega_espera(indice){
		if(voltando==0){ atribuiVoltar(5,indice);} voltando=0;
		ajaxGet('includes/telentrega_itens.php?id='+indice,document.getElementById("divTextoInstitucional2"),true)
		}



function menu_lojas(indice){
var urls = new Array('lojas_1','lojas_2','lojas_3','lojas_4','lojas_5');
		if(voltando==0){ atribuiVoltar(6,indice);} voltando=0;
		switch (indice) {
			case 0:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("myContentLojas"),true)
				break
			case 1:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("myContentLojas"),true)
				break
			case 2:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("myContentLojas"),true)
				break
			case 3:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("myContentLojas"),true)
				break
			case 4:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("myContentLojas"),true)
				break
			default:
				//loadContent('corpoContent','includes/404','GET',"")
			}
		}
function menu_cadastre(indice){
var urls = new Array('cadastre_formulario','cadastre_vantagens');
		switch (indice) {
			case 0:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			case 1:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			default:
				//loadContent('corpoContent','includes/404','GET',"")
			}
		}

function menu_trabalhe(indice){
var urls = new Array('trabalhe_curriculo','trabalhe_area');
		switch (indice) {
			case 0:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			case 1:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			default:
				//loadContent('corpoContent','includes/404','GET',"")
			}
		}
function menu_sac(indice){
var urls = new Array('sac_formulario','sac_faq');
		switch (indice) {
			case 0:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			case 1:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			default:
				//loadContent('corpoContent','includes/404','GET',"")
			}
		}
function menu_parceiros(indice){
var urls = new Array('parceiros_alimentos','parceiros_logistica');
		switch (indice) {
			case 0:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			case 1:
				ajaxGet('includes/'+urls[indice]+'.php',document.getElementById("divTextoInstitucional"),true)
				break
			default:
				//loadContent('corpoContent','includes/404','GET',"")
			}
		}
