/*<RMJSDep>BrowserUtils;WindowUtils</RMJSDep>*/
/*
Arquivo que tem funções especíoficas do Login.aspx
*/
function DoLoginFocus()
{
	var txtUser = document.getElementById("tbUser");
	var txtPass = document.getElementById("tbPass");
	
	if ((txtUser!=null) &&
		(txtPass!=null))
	{
		if (txtUser.value!="")
			txtPass.focus();
		else
			txtUser.focus();
	}
}

/*
Verifica se há histórico no atual Browser, se houver, fecha e abre nova janela
*/
function CheckHistory(LoginUrl, WindowFeatures)
{
	if (((isIE()) && history.length >= 1) || 
		(history.length > 1))
	{
		OpenCorporeWindow(LoginUrl,WindowFeatures);
	}
}

function SetUserPass(Pass)
{
	var txtPass = document.getElementById("tbPass");
	if (txtPass!=null)
	{
		txtPass.value = Pass;
	}
}

function SetLoginLayout(DefaultWindowTop,DefaultWindowLeft)
{
	SetLoginDivLayout(DefaultWindowTop,DefaultWindowLeft);
}

function SetLoginDivLayout(DefaultWindowTop,DefaultWindowLeft)
{
	var LoginDiv = document.getElementById('floater');
	var sizex = (screen.width > 800) ? 900 : 800;
	var sizey = (screen.width > 800) ? 670 : 600;
	
	posx = (screen.availWidth  - sizex) / 2;
	posy = (screen.availHeight - sizey) / 2;
	
	if ((posx > 0) && (posy > 0) && (screen.width > 800))
	{
		self.moveTo(posx, posy);
	}
	else
	{
		self.moveTo(DefaultWindowTop,DefaultWindowLeft);
	}

	var AvailWidth;
	var AvailHeight;
	if (isIE())
	{
		AvailWidth = document.body.offsetWidth;
		AvailHeight = document.body.offsetHeight;
	}
	else
	{
		AvailWidth = window.innerWidth;
		AvailHeight = window.innerHeight;
	}
	
	posx = (AvailWidth  - parseInt(LoginDiv.style.width, 10)) / 2;
	posy = (AvailHeight - parseInt(LoginDiv.style.height, 10)) / 2;
	
	LoginDiv.style.left = posx;
	LoginDiv.style.top  = posy;
	LoginDiv.style.display = '';
}

function LoginOnLoad()
{
	DoLoginFocus();
}

function DoFormSubmit()
{
	ShowLoadingDiv();
}

function ShowLoadingDiv()
{
	document.getElementById('floater').style.visibility = 'hidden';
	document.getElementById('pnLoading').style.visibility = '';
}

function RefreshImage(ImageId)
{
	var img = document.getElementById(ImageId);
	var tmpSrc = img.src;

	img.src = '';
	img.src = tmpSrc;
}

function ShowPopupNotAlowedMessage()
{
   var message = 'O seu browser está configurado para não permitir a abertura de novas janelas. '+
		'O CorporeRM.Net abre outra janela para que a mesma possa ser configurada '+
		'da melhor forma possível para se utilizar a solução. Sendo assim, solicitamos '+
		'que seja liberada a abertura de novas janelas para o site do CorporeRM.Net.\n\n\n'
		
   if (window.navigator.userAgent.indexOf("SV1") != -1)
   {
		message += 'Foi detectada a instalação do ServicePack2 do WindowsXP na sua máquina, '+
			'pode ser ele que está impedindo a abertura da nova janela. Para liberar a '+
			'abertura de pop-ups apenas para o CorporeRM.Net siga os seguintes passos: \n'+
			'1 - Vá até o menu Ferramentas | Opções da Internet do seu Internet Explorer.\n'+
			'2 - Na tela de configurações que será aberta, vá até a aba Privacidade.\n'+
			'3 - Abra as configurações do Bloqueador de Pop-ups\n'+
			'4 - Adicione o site do CorporeRM.Net na lista de sites permitidos';
   }
   else
   {
		message += 'Para maiores informações, procure o fabricante do seu bloqueador de Pop-ups.';
   }
   
   alert(message);
}

function OpenCorporeWindow(Url, WindowFeatures)
{
	var OpenedWindow = OpenWindow(Url, '_blank', WindowFeatures);
	
	if (OpenedWindow == null)
		ShowPopupNotAlowedMessage();

	if (isIE())
	{
		window.opener = OpenedWindow;
		if (OpenedWindow!=null)
			window.close();
	}
	else
	{
		//Verificando se pode fechar a janela de acordo com o valor passado 
		//por querystring 'NewWindow=0'
		if ((window.location.href.indexOf('NewWindow=0')!=-1))
			window.close();
	}
}