//HTTP Request AjAX
function ObjAjax(){
	try{return new XMLHttpRequest()}
	catch(e){try{return new ActiveXObject("Msxml2.XMLHTTP")}
	catch(e){return new ActiveXObject("Microsoft.XMLHTTP")}}
	return null;
}

function navegar(pg){
	ajax = new ObjAjax;
	div = document.getElementById('navegar');
	
	ajax.onreadystatechange = function(){
		if(ajax.readyState == 1){div.innerHTML = '<img src=imagens/carregando.gif>'};
		if(ajax.readyState == 4){
				div.innerHTML = ajax.responseText
				doScript(ajax.responseText)
		};
		//alert(ajax.responseText);
		}
		
	ajax.open("GET",pg,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.send(null);
	
	}	

var persistclose=0 
var startX = 0 
var startY = 0 
var verticalpos="fromtop"

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function closebar(){
if (persistclose)
document.cookie="remainclosed=1"
document.getElementById("nav").style.visibility="hidden"
}

function staticbar(){
	return false;
	barheight=document.getElementById("nav").offsetHeight
	var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
	var d = document;
	function ml(id){
		var el=d.getElementById(id);
		if (!persistclose || persistclose && get_cookie("remainclosed")=="")
		el.style.visibility="visible"
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function(){
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : iecompattest().scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/1;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
		ftlObj.y += (pY - startY - ftlObj.y)/0;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 1);
	}
	ftlObj = ml("nav");
	stayTopLeft();
}

if (window.addEventListener)
window.addEventListener("load", staticbar, false)
else if (window.attachEvent)
window.attachEvent("onload", staticbar)
else if (document.getElementById)
window.onload=staticbar

function sDiv(obj){
	div = document.getElementById(obj);
	if(div.style.display == 'none'){div.style.display='Block'}else{div.style.display='none'};
	}
	
function popUp(url){
     window.open( "popImg.asp?URL="+url, "","resizable=0,HEIGHT=200,WIDTH=200");
	}

function valPesq(){
	var frm = document.form1;
	var err = "";
	
	if(!frm.nome.value)err+="* Nome\n";
	if(!frm.tel.value)err+="* Telefone\n";
	if(!frm.aniversario.value)err+="* Aniversário\n";
	if(!frm.email.value)err+="* E-mail\n";
	
	if(!err){frm.submit()}else{alert(err)}
	}
	
function doScript(texto){
    var ini, pos_src, fim, codigo;
    var objScript = null;
    ini = texto.indexOf('<script', 0);
    while (ini!=-1){
        var objScript = document.createElement("script");
        //Busca se tem algum src a partir do inicio do script
        pos_src = texto.indexOf(' src', ini)
        ini = texto.indexOf('>', ini) + 1;

        //Verifica se este e um bloco de script ou include para um arquivo de scripts
        if (pos_src < ini && pos_src >=0){//Se encontrou um "src" dentro da tag script, esta e um include de um arquivo script
            //Marca como sendo o inicio do nome do arquivo para depois do src
            ini = pos_src + 4;
            //Procura pelo ponto do nome da extencao do arquivo e marca para depois dele
            fim = texto.indexOf('.', ini)+4;
            //Pega o nome do arquivo
            codigo = texto.substring(ini,fim);
            //Elimina do nome do arquivo os caracteres que possam ter sido pegos por engano
            codigo = codigo.replace("=","").replace(" ","").replace("\"","").replace("\"","").replace("\'","").replace("\'","").replace(">","");
            // Adiciona o arquivo de script ao objeto que sera adicionado ao documento
            objScript.src = codigo;
        }else{//Se nao encontrou um "src" dentro da tag script, esta e um bloco de codigo script
            // Procura o final do script
            fim = texto.indexOf('</script>', ini);
            // Extrai apenas o script
            codigo = texto.substring(ini,fim);
            // Adiciona o bloco de script ao objeto que sera adicionado ao documento
            objScript.text = codigo;
        }

        //Adiciona o script ao documento
        document.body.appendChild(objScript);
        // Procura a proxima tag de <script
        ini = texto.indexOf('<script', fim);

        //Limpa o objeto de script
        objScript = null;
    }
}
