//-----------------------------------------------------------------------------------------

function PegaXmlHttpObjeto(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("Esta funcionalidade não funciona no Opera") 
return 
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{ 
alert("ERRO: Script para ActiveX deve estar desabilitado") 
return 
} 
} 
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler 
return objXmlHttp
}
} 

//-----------------------------------------------------------------------------------------

function marcaEX(idcmp) {document.getElementById(idcmp).style.color='#FF0000'} 
function marcaOK(idcmp) {document.getElementById(idcmp).style.color='#000000'}

// ----- FUNCAO PARA RECONHECER O ENTER NO CAMPO DE senha ----- //

function Exec_Login(e){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		vrPassTESTE() //document.forms[0].submit() //submit the form
		return false 
	}
	else{
		return true 
	}
}

//-----------------------------------------------------------------------------------------

function formOnload(){showRelped()}

function showRelped() {var url="PRO_Box_Restrito_Logado.asp?ID="+Math.random()+"&O=SR"; xmlHttp=PegaXmlHttpObjeto(stCh_showRelped); xmlHttp.open("GET", url , true); xmlHttp.send(null)}

function stCh_showRelped(){ if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { var rsp_pass=xmlHttp.responseText; if(rsp_pass=='@BLK@') {showBlocked()} else {if(rsp_pass=='@EXP@') {showLogin()} else {document.getElementById('td_pr').innerHTML=rsp_pass;}}}}

function showBlocked() {var url="PRO_Box_Restrito_Blocked.asp?ID="+Math.random(); xmlHttp=PegaXmlHttpObjeto(stCh_showBlocked); xmlHttp.open("GET", url , true); xmlHttp.send(null)}

function stCh_showBlocked(){if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){var rsp_pass=xmlHttp.responseText; document.getElementById('td_pr').innerHTML=rsp_pass}}

function showLogin() {var url="PRO_Box_Restrito_Login.asp?ID="+Math.random()+"&O=SL"; xmlHttp=PegaXmlHttpObjeto(stCh_showLogin); xmlHttp.open("GET", url , true); xmlHttp.send(null)}

function stCh_showLogin(){if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){var rsp_pass=xmlHttp.responseText; document.getElementById('td_pr').innerHTML=rsp_pass}}

function vrPassTESTE() {var url="PRO_Box_Restrito_Vrpass.asp?ID="+Math.random()+"&O=VP&LO="+document.getElementById('acesso_login').value+"&SE="+document.getElementById('acesso_senha').value; xmlHttp=PegaXmlHttpObjeto(stCh_vrPassTESTE); xmlHttp.open("GET", url , true); xmlHttp.send(null)}

function stCh_vrPassTESTE()  //TRAZ O RETORNO DA PAGINA DE VERIFICAÇÃO
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
	var rsp_pass=xmlHttp.responseText; 
	var s_pass		= rsp_pass.split(",");
	if (s_pass[0]=='EX_TE') // DEU ERRO NO FORMULARIO
		{
			alert('Numero de tentativas excedido!\n\nPor questões de segurança, não é possivel novas tentativas.\nPor favor, para tentar novamente acesse o site em uma nova janela.'); showRelped(); 
		}
		else
		{
			if (s_pass[0]=='EX_FO') // DEU ERRO NO FORMULARIO
			{
				alert('Por favor, preencha corretamente o login e a senha.'); marcaEX('s_acesso_login'); document.getElementById('acesso_login').value=''; marcaEX('s_acesso_senha'); document.getElementById('acesso_senha').value=''; document.getElementById('acesso_login').focus()
			}
			else
			{
				if (s_pass[0]=='EX_LO') // DEU ERRO NO BANCO DE DADOS - LOGIN
				{
					alert('Esse login nao existe em nosso sistema.\nPor favor, digite novamente.'); marcaEX('s_acesso_login'); document.getElementById('acesso_login').value=''; marcaEX('s_acesso_senha'); document.getElementById('acesso_senha').value=''; document.getElementById('acesso_login').focus()
				}
				else  // DEU OK E ACESSOU A AREA RESTRITA
				{
					if (s_pass[0]=='EX_SE') // DEU ERRO NO BANCO DE DADOS - SENHA
					{
						alert('A senha está incorreta!\nPor favor, digite novamente.'); marcaEX('s_acesso_senha'); document.getElementById('acesso_senha').value=''; document.getElementById('acesso_senha').focus()
					}
					else  // DEU OK NO LOGIN E SENHA - ACESSOU A AREA RESTRITA
					{
						if (s_pass[0]=='EX_IN') // DEU ERRO NO BANCO DE DADOS - INATIVO
						{
							alert('Este usuário está inativo!\nPor favor, entre em contato conosco.'); marcaEX('s_acesso_senha'); document.getElementById('acesso_senha').value=''; document.getElementById('acesso_senha').focus()
						}
						else  // DEU OK NO LOGIN E SENHA E ATIVO - ACESSOU A AREA RESTRITA
						{					
							FuncoesOrcamento();
							//LiberaFinalizacao('SIM');  //era para a finalização do orcamento...
							showRelped();
							window.top.location.href='PRO_Index.asp';
							//if (s_pass[1]!='') 
							//{window.top.location.href=s_pass[1];}							
						}
					}
				}
			}
		}
	}
}

//-----------------------------------------------------------------------------------------

function vrLogout(){
	if (confirm("Se você possui um orçamento não finalizado, os dados serão perdidos.\nDeseja efetuar o logout?")) {var url="PRO_Box_Restrito_Logout.asp?ID="+Math.random(); xmlHttp=PegaXmlHttpObjeto(st_vrLogout); xmlHttp.open("GET", url , true); xmlHttp.send(null)}
	}

function st_vrLogout(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var rsp_pass=xmlHttp.responseText; 
		if(rsp_pass=='@EXP@') 
		{showLogin()} 
		else 
		{document.getElementById('td_pr').innerHTML=rsp_pass;}
		}
	// para resolver o bug de logou dentro de uma pagina restrita
	window.top.location.href='PRO_Restrito_Exit.asp';	
	}