 
/*
*
* POPUP
*
*/
var win;

function popup(mypage, myname, w, h, scroll, resizable, menubar) {

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable='+resizable+',menubar='+menubar+''
	var win = window.open(mypage, myname, winprops)

if (parseInt(navigator.appVersion) >= 4) 
{ 
	win.window.focus(); 
}

}

function closePopup() {
	if (!win.closed)
		setInterval("win.close()", 2000);
	else
		clearInterval();
}

function escondeLayerPopUp(nomeLayerPopUp)
{
	timer_is_on=0;
	c=0;
	
	var layer=document.getElementById(nomeLayerPopUp);
	layer.style.visibility="hidden";
	layer.style.display = "none"; 

	layerWindowXeo = parent.document.getElementById(nomeLayerPopUp);
	if (layerWindowXeo!=null)
	{
		layerWindowXeo.style.visibility="hidden";
		layerWindowXeo.style.display = "none"; 
	}

}

function mostraLayerPopUp(nomeLayerPopUp)
{

	layerWindowXeo = parent.document.getElementById(nomeLayerPopUp);
	if (layerWindowXeo!=null)
	{
		layerWindowXeo.style.visibility="hidden";
		layerWindowXeo.style.display = "none"; 
	}

	var layer=document.getElementById(nomeLayerPopUp); 
	layer.style.visibility="visible";
	layer.style.display = "block";
	if (nomeLayerPopUp=='layerWait')
		setTimeout("document.getElementById('esperaAnim').src='/img/indicadores/wait_animated.gif';",100); 


}
 


/* novo */
function alternaLayerLoad(nomeLayerPopUp)
{
	mostraMensagem("","erro");

	var layer=document.getElementById(nomeLayerPopUp); 
	if (layer.style.display=="block")
	{
		layer.style.visibility="hidden";
		layer.style.display = "none"; 
	}
	else
	{
		layer.style.visibility="visible"
		layer.style.display = "block";
	}
 	
}



/*
toggle Geography codes
*/
function changeClassDisplay(className) {
	var theRules = new Array();
	
	for (var i=0; i<document.styleSheets.length; i++)
   	{
		if (document.styleSheets[i].cssRules) {
			theRules = document.styleSheets[i].cssRules;
		} else if (document.styleSheets[i].rules) {
			theRules = document.styleSheets[i].rules;
		}
		
		for (var k=0; k<theRules.length; k++)
		{

			if (theRules[k].selectorText.toUpperCase()==className.toUpperCase())
			{
				if (theRules[k].style.display=="inline") 
					theRules[k].style.display="none";
				else
					theRules[k].style.display="inline";
			}
		}						   
    }	   	   	
}




/* =================================================
* mostrar as mensagens de ajuda/erro
* ================================================= */
function mostraMensagem(mensagem, tipo)
{
	var elemento = document.getElementById("areaMensagensAjuda");

	var elementoChild = document.createElement("SPAN");
	var new_txt = document.createTextNode(mensagem);
	
/*
	var myImg=document.createElement("IMG");

	if (mensagem=="")	
		myImg.setAttribute("src", "/img/indicadores/pontoTransparente.gif");
	else
	{
		if (tipo=="erro")
			myImg.setAttribute("src", "/img/indicadores/errorIcon.gif");
		else
			myImg.setAttribute("src", "/img/indicadores/infoIcon.gif");		
	}
	
	myImg.setAttribute("style", "vertical-align: middle");

	
	
	
	elementoChild.appendChild(myImg);
	*/
	elementoChild.appendChild(new_txt);
	
	
	if (tipo=="erro")
		elemento.style.color="red";
	else
		//elemento.style.color="#566270";  
		//elemento.style.color="#1ba009";    
		elemento.style.color="#178508";      		
		
	
	//elemento.replaceChild(new_txt, elemento.childNodes[0]);      
	elemento.replaceChild(elementoChild, elemento.childNodes[0]);      
}




function clicked_X(e) {
	var x=0;
	if (!e)
		var e = window.event;
	
	if (document.layers) 
	{
		x = e.pageX;
	}
	else if (document.all) 
	  {
		x = window.event.x;
	  }
	  else
	  {
		x=e.clientX;
	  }
	
	return x;
}

function clicked_Y(e) {
	var y=0;
	
	if (document.layers) 
	{
		y = e.pageY;
	}
	else 
	  if (document.all) // IE
	  {
		y = window.event.y ;
	  }
	  else
	  {
		y=e.clientY;
	  }
	
	return y;
}


function posicionaLayerPopUp(e, nomeLayerPopUp, largura, altura)
{
	//coordenadas por defeito
	var x=313; 
	var y=50; 
	
	
	if (window.event || document.layers || e.clientX) 
	  x=clicked_X(e);
	  
	if (window.event || document.layers || e.clientY) 
	  y=clicked_Y(e);
	  
	var layer=document.getElementById(nomeLayerPopUp);        
	layer.style.top=y-2;
	layer.style.left=x;//(largura-40);
	
	layer.style.width=largura;
	layer.style.height=altura;        
	
	
	mostraLayerPopUp(nomeLayerPopUp);
}




/*
*  carregar os mXtodos SelectNode eSelectSingleNode para o InternetExplorer
*/
// mozXPath [http://km0ti0n.blunted.co.uk/mozxpath/] km0ti0n@gmail.com
// Code licensed under Creative Commons Attribution-ShareAlike License 
// http://creativecommons.org/licenses/by-sa/2.5/
if( document.implementation.hasFeature("XPath", "3.0") )
{

	
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++)
		{
			aResult[i] =  aItems.snapshotItem(i);
		}
		
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; } 

		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 )
		{
			return xItems[0];
		}
		else
		{
			return null;
		}
	}

	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

	Element.prototype.selectSingleNode = function(cXPathString)
	{	
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}

}    

/*
*  fim carregamento os mXtodos SelectNode eSelectSingleNode para o FireFox
*/



