window.onload=function(){criaElementos(); verificaInt=setInterval("verifica()", 100);}
page=""; prefix="[page]"; index="homeBackState"; is_ie=(navigator.userAgent.toLowerCase().indexOf("msie")!=-1)?true:false;
var showLoading = true;
function criaElementos()
	{var theBody=document.getElementsByTagName("body")[0];
    var iframe=document.createElement("iframe");
		iframe.setAttribute("src", "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 ajax(pag,show)
	{showLoading=show; var iframe=document.getElementById('bmr-ajaxControl');
	if(is_ie){iframe.src="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!=page) 
		{if(hash!="" && hash.indexOf(prefix)!=-1) 
			{openPage(hash.replace(prefix,""), showLoading);
			page=hash; ajax(hash.replace(prefix,""));}
		else {clearInterval(verificaInt);
			location.hash=page; //Index
			ajax(index);}}}
