function abreJanela()
{
	var altura = document.body.style.height;

	obj('camadaLogin').style.display='block';	
	frm =obj('frmLogin');
	x=document.body.clientWidth;
	y=document.body.clientHeight;
	frm.style.left=x/2-100;
	//frm.style.top=y/2-55;
	frm.style.display='block';
	printf('Digite seu Login e Senha');
	document.body.scrollTop=document.body.scrollHeight;
	obj('txtLogin').value='';
	obj('txtSenha').value='';
	obj('txtLogin').focus();

	return false;
}

function scanf(e,codObj)
{
	t=e.keyCode;
	
	if(t==13)
	{
		if(codObj==0){obj('txtSenha').focus();}
		if(codObj==1){obj('btnEntrar').click();}

		return false;
	}
}

function fechaJanela()
{
	obj('camadaLogin').style.display='none';	
	obj('frmLogin').style.display='none';	
}

function printf(txt)
{
	obj('lblStatus').innerHTML=txt;
}

function mostraStatus(txt)
{
	if(txt=='-1')
	{
		printf('Dados incorretos');
		return false;
	}
	
	if(txt=='1')
	{
		printf('Bem Vindo!');
		document.location='mostra_cond.asp';
	}
	else
	{
		printf('Usuário não encontrado');
	}
}

function obj(nome)
{
	return document.getElementById(nome);
}

function abreAjax(){
	var ajax;
	
	try
	{
		ajax = new XMLHttpRequest();
	}
	catch(ee)
	{
		try
		{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
					ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(E)
			{
					ajax = false;
			}
		}
	}
	
	return ajax;
}


function entrar(login,senha)
{
	if(login!='' && senha.length!='')
	{
		var ajax = abreAjax();
		
		url='../loginA.asp';
		dados='txtLogin='+encodeURI(login)+'&txtPassword='+encodeURI(senha);
		ajax.onreadystatechange=function(){atualizaStatus(ajax);}
		ajax.open('POST',url,true);
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.setRequestHeader('Content-Length',dados.length);
		ajax.send(dados);
	}
	else
	{
		alert('Digite seu login e senha');
		obj('txtLogin').focus();
	}

	return false;
}

function atualizaStatus(ajax)
{
  	if(ajax.readyState==4){mostraStatus(ajax.responseText);};
}