function iecompattest(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function centerLayers() {

	var ie5=document.all&&document.getElementById
	var ns6=document.getElementById&&!document.all
	
	//winWidth = ns6? window.innerWidth-20 : iecompattest().clientWidth;
	var winWidth = 780;
	var winHeight = ns6? window.innerHeight-20 : iecompattest().clientHeight;	
	
	var popupWidth	= document.getElementById("FloatingLayer").style.width;	
	var popupWidth	= popupWidth.substr(0,popupWidth.length-2);
	
	var popupHeight 	= document.getElementById("FloatingLayer").style.height;	
	var popupHeight	= popupHeight.substr(0,popupHeight.length-2);
	
	var winX = Math.ceil((winWidth - popupWidth) / 2);
	var winY = Math.ceil((winHeight - popupHeight	) / 2);
	
	// CARREGANDO
	//document.getElementById("LoadingContent").style.left = Math.ceil((winWidth - 130) / 2);
	document.getElementById("LoadingContent").style.left = '640px';
	
	// POPUP
	document.getElementById("FloatingLayer").style.left = winX;
	document.getElementById("FloatingLayer").style.top = (scrollY() + winY) + 'px';

}

function scrollY() {
	
	var scrolledY = 0;
	
	var ie5=document.all&&document.getElementById
	var ns6=document.getElementById&&!document.all
	
	if (ns6)  {
		scrolledY = window.pageYOffset;
	} else  {
		scrolledY = document.body.scrollTop;
	}
	
	return scrolledY;
	
}

/*******************************************************************************************
CARREGANDO
*******************************************************************************************/

function tiraFocusLinks() {
	
	var links = document.getElementsByTagName('a')
	
	for (i = 0; i <  links.length; ++i)	{				
		 links[i].onfocus = function() {  this.blur(); }		
	}
	
}

function mostraCarregando() {		
	
	// fecha a popup
	fechaPopup();
	
	// esconde selects
	cmControlChild("SELECT",1);
		
	// abre o carregando
	ToggleFloatingLayer("LoadingContent",1);
	
}

function escondeCarregando() {	
	
	// rola a página para o topo
	//scrollTo(0,0);
	
	// mostra os selects
	cmControlChild("SELECT",0);
	
	// tira o focus dos links
	tiraFocusLinks();
	
	// esconde o carregando
	ToggleFloatingLayer("LoadingContent",0);
	
}

function cmControlChild (tagName,a) {
	
	for (i = 0; i < document.getElementsByTagName(tagName).length; ++i)	{
		var obj = document.getElementsByTagName(tagName)[i];
		if(a == 0) {
			obj.style.visibility = "visible";
		} else {
			obj.style.visibility = "hidden";
		}
	}
	
}



/*******************************************************************************************
EVENTOS
*******************************************************************************************/

window.onresize	= centerLayers;
window.onscroll	= centerLayers;



