/************************/
/* Autor: Felipe Jaekel */
/***********************************/
/* Funções usadas apenas em popups */
/***********************************/

/*************************************/
/* Maximiza automaticamente um popup */
/*************************************/
function autoMaximize()
{
	if(janelaPrincipalAtiva()) //Evita que o tamanho da janela seja reduzido quando não é popup
	{
		top.window.moveTo(0,0);
		if (document.all)
		{
			top.window.resizeTo(screen.availWidth,screen.availHeight);
		}
		else if (document.layers || document.getElementById)
		{
			if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth)
			{
				top.window.outerHeight = top.screen.availHeight;
				top.window.outerWidth = top.screen.availWidth;
			}
		}
	}
}

/***********************************************************/
/* Verifica, em um popup, se a janela principal está ativa */
/***********************************************************/
function janelaPrincipalAtiva()
{
	//No IE é necessário usar a propriedade closed para o teste funcionar
	return isIE() ? !window.opener.closed : window.opener;
}

/*********************************************************/
/* Fecha o popup se a janela principal não estiver ativa */
/*********************************************************/
function checkOpener()
{
	if(!janelaPrincipalAtiva())
	{
		alert('Janela principal não está ativa');
		window.close();
	}
}

/*****************************************************************/
/* Fecha um popup e posiciona na janela principal se ela existir */
/*****************************************************************/
function fechaPopup()
{
   window.close();

	if(janelaPrincipalAtiva())
	{
   	window.opener.focus();
   }
}

/***********************************************/
/* Posiciona em uma âncora da janela principal */
/***********************************************/
function setAnchor(anchor, campo)
{
   if(janelaPrincipalAtiva())
	{
   	window.opener.focus();

      //Altera o atributo ancora da url
   	window.opener.location.hash = anchor;

   	if(campo)
   	{
  			window.opener.document.getElementById(campo).focus();
  		}
	}
	else
	{
   	alert('Janela principal não está ativa');
	}
}

function toggleFastNavMenu(e)
{
	//var activeElement = document.all ? event.srcElement.parentElement : e.target.parentNode;
	var activeElement = document.all ? event.srcElement : e.target;

	if(activeElement.id)
	{
		if(activeElement.id == 'btnFastNav' && field('fastNav').style.display == 'none')
		{
			show('fastNav');
		}
		else
		{
			if(activeElement.id == 'btnFastNav' && field('fastNav').style.display == '')
			{
				hide('fastNav');
			}
			else
			{
				if(activeElement.id != 'fastNav')
				{
					hide('fastNav');
				}				
			}
		}
	}
	else
	{
		hide('fastNav');
	}
}

function fastNavMenu()
{
	document.onclick = toggleFastNavMenu;
}