window.onload=function(){criaElementos(); verificaInt=setInterval("verifica()", 100);}
page="";
prefix="[pagina]";
index="homeBackState";
is_ie=(navigator.userAgent.toLowerCase().indexOf("msie")!=-1)?true:false;
idObj="";

if (idObj="")
idObj= "conteudo";

function criaElementos(){
	var theBody=document.getElementsByTagName("body")[0];
	var iframe=document.createElement("iframe");
	if (is_ie) {
		prefix="[pagina]";
		var hash=(typeof((hash=location.href.split("#")[1]))!="undefined"?hash:"");
		if (hash != "") {
			page=hash.replace(prefix,"");
			iframe.setAttribute("src", "ajaxBack/control.htm?id="+prefix+page);
		}
		else
		iframe.setAttribute("src", "ajaxBack/control.htm?id="+prefix+index);
	}
	else
	iframe.setAttribute("src", "ajaxBack/control.htm?id="+prefix+index);
	iframe.setAttribute("id", "bmr-ajaxControl");
	iframe.style.display="none";
	theBody.appendChild(iframe);
}

function volta_index(){
	location="http://"+location.host+location.pathname+"#"; location.reload();
}

function ajaxRequestBack(id,pag){
	var iframe=document.getElementById('bmr-ajaxControl');
	idObj = id;
	if(is_ie){
		iframe.src="ajaxBack/control.htm?id="+prefix+pag;
	}
	else
	{
		if(pag!=index){
			location.hash=prefix+pag;
		}
		else {
			volta_index();
		}
	}
}

function verifica(){
	var hash=(typeof((hash=location.href.split("#")[1]))!="undefined"?hash:"");
	if (hash.indexOf(prefix) != -1) {
		if (idObj == "")
		idObj = "conteudo";
		if(hash!=page)
		{
			if(hash!="" && hash.indexOf(prefix)!=-1)
			{
				carregaConteudo(hash.replace(prefix,""), idObj, true);
				page=hash; ajaxRequestBack(idObj,hash.replace(prefix,""));
			}
			else {
				clearInterval(verificaInt);
				location.hash=page; //Index
				ajaxRequestBack(idObj,index);
			}
		}
		if(document.getElementById('conteudo').className == "home")
		document.getElementById('conteudo').className = "interna";
		if(document.getElementById('bg_luzes').className == "home_luzes")
		document.getElementById('bg_luzes').className = "interna_luzes";
	}
}