// JavaScript Document
var ID = "";

function $div(quem)
{
	return document.getElementById(quem);
}

function __openWindow(page,option)
{
	window.open(page,"_blank",option);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function detectVersion()
{
	version = parseInt(navigator.appVersion);
	return version;
}

function detectOS()
{

	if(navigator.userAgent.indexOf('Win') == -1) {

		OS = 'Macintosh';

	} else {

		OS = 'Windows';

	}

	return OS;

}



function detectBrowser()

{

	if(navigator.appName.indexOf('Netscape') == -1) {

		browser = 'IE';

	} else {

		browser = 'Netscape';

	}

	return browser;

}



function extraiScript(texto){

	

    var ini = 0;

    // loop enquanto achar um script

    while (ini!=-1){

        // procura uma tag de script

        ini = texto.indexOf('<script', ini);

        // se encontrar

        if (ini >=0){

            // define o inicio para depois do fechamento dessa tag

            ini = texto.indexOf('>', ini) + 1;

            // procura o final do script

            var fim = texto.indexOf('</script>', ini);

            // extrai apenas o script

            codigo = texto.substring(ini,fim);

            // executa o script

            eval(codigo);

        }

    }	

}



function __fecharOpcoes()
{
	__carregarPagina('opcoes.php');
	//document.getElementById('txtOpcoes').style.display = "none";	
	//document.getElementById('txtMnuOpcoes').style.display = "block";
}

/* ROTINA DE LOGIN DE USUÁRIOS */
function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        'dynamic_cardapios.php?ID=' + ID,
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(url)
{
	var Caminho = url.replace("small","large");
    return '<a href="' + Caminho + '" rel="lightbox[roadtrip]" title=""><img src="' + url + '" width="75" height="75" border="0" alt="" /></a>';
};

function __carregarPagina(pagina){
	
	try {
		
		document.getElementById('divConteudo').innerHTML = "";
		
		jQuery("#divConteudo").load(pagina);
		/*
		document.getElementById('divConteudo').innerHTML = "";
			
		var ajax = _initXML_http();

		if(ajax) {//se tiver suporte ajax

			ajax.open("GET", pagina, true);

			ajax.onreadystatechange = function() {

				if(ajax.readyState == 4) {

					if(ajax.status == 200) {

						document.getElementById('divConteudo').innerHTML = ajax.responseText
					
						texto	= unescape(ajax.responseText.replace(/\+/g," "));

						extraiScript(texto)						
						
					} else {
						<!-- ajax.statusText; -->
					}

				}

			}		

			ajax.send(null);			

		}*/

  	} catch(e) {
		alert("Ocorreu um erro ao tentar executar sua solicitação, tente novamente");
  	}		
}

function __carregarCardapio(pagina, opcao){
	
	try {
		
		ID = opcao;
		
		document.getElementById('divConteudo').innerHTML = "";
		
		jQuery("#divConteudo").load(pagina);
										
		/*
		document.getElementById('divConteudo').innerHTML = "";
			
		var ajax = _initXML_http();

		if(ajax) {//se tiver suporte ajax

			ajax.open("GET", pagina, true);

			ajax.onreadystatechange = function() {

				if(ajax.readyState == 4) {

					if(ajax.status == 200) {

						document.getElementById('divConteudo').innerHTML = ajax.responseText;																		
						
						texto	= unescape(ajax.responseText.replace(/\+/g," "));

						extraiScript(texto);												
						
					} else {
						<!-- ajax.statusText; -->
					}

				}

			}		

			ajax.send(null);			

		}*/

  	} catch(e) {
		alert("Ocorreu um erro ao tentar executar sua solicitação, tente novamente");
  	}		
}

function __postarContato()
{

	try {				

		var ajax = _initXML_http();

		if(ajax) {//se tiver suporte ajax

			ajax.open("POST", 'contato.php', true);			

        	ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");

    	    ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");

	        ajax.setRequestHeader("Pragma", "no-cache");

			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

			ajax.onreadystatechange = function() {

				if(ajax.readyState == 4) {

					if(ajax.status == 200) {			

						document.getElementById('divConteudo').innerHTML = ajax.responseText

					} else {

						<!-- ajax.statusText; -->

					}

				}

			}		

			

			var params =  [

			'action=enviar',

			'Nome=' + document.frmCadastro.Nome.value,

			'Telefone=' + document.frmCadastro.Telefone.value,

			'email=' + document.frmCadastro.email.value,

			'assunto=' + document.frmCadastro.assunto.value,

			'comentario=' + document.frmCadastro.comentario.value ].join('&');			

			ajax.send(params);

			

		}



		

  	} catch(e) {

		alert("Ocorreu um erro ao tentar executar sua solicitação, tente novamente");

  	}		

}



function __carregarOpcoes(pagina)
{

	try {				

		var ajax = _initXML_http();

		if(ajax) {//se tiver suporte ajax

			ajax.open("GET", pagina, true);

			ajax.onreadystatechange = function() {

				if(ajax.readyState == 4) {

					if(ajax.status == 200) {						

						document.getElementById('txtOpcoes').innerHTML = ajax.responseText
						document.getElementById('txtOpcoes').style.display = "block";						
						document.getElementById('txtMnuOpcoes').style.display = "none";						

						texto	= unescape(ajax.responseText.replace(/\+/g," "));

						extraiScript(texto)										

					} else {
						<!-- ajax.statusText; -->
					}

				}

			}		

			ajax.send(null);
			
		}
		

  	} catch(e) {

		alert("Ocorreu um erro ao tentar executar sua solicitação, tente novamente");

  	}		

}

function __verFotos(pagina, Categoria){
	
	try {
				
		var ajax = null;
		ajax = _initXML_http();
		if(ajax) {//se tiver suporte ajax
	
			var params =  [
			'CatID=' + Categoria ].join('&');

			ajax.open("GET", pagina + "?" + params, true);

			ajax.onreadystatechange = function() {
				
				//enquanto estiver processando...emite a msg de carregando			
				if(ajax.readyState == 1) {
				   //iframePortifolio.$div('divPortifolio').innerHTML = "";
				   //iframePortifolio.$div('carregando').style.display 	= "block";
				}
				
				if(ajax.readyState == 4) {
					
					if(ajax.status == 200) {
				       	
						//iframePortifolio.$div('carregando').style.display 	= "none";					
						//iframePortifolio.$div('divConteudo').style.top = "0px";
						
						$div('divConteudo').innerHTML = ajax.responseText;												
		                texto	= unescape(ajax.responseText.replace(/\+/g," "));
				        extraiScript(texto);												
						
					} else {
						
					}
				}
			
			}							
			ajax.send(params);
			
		}
			
  	} catch(e) {
		alert("Ocorreu um erro ao tentar executar sua solicitação, tente novamente");
  	}
	
}
