function criaObjeto() {
	try{
	    xmlhttp = new XMLHttpRequest();
	}catch(ee){
	    try{
	        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    }catch(e){
	        try{
	            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	        }catch(E){
	            xmlhttp = false;
	        }
	    }
	}
}

function logado() {
	if (xmlhttp.readyState==4) {
		document.getElementById("loginstatus").style.visibility = 'hidden';
		if (xmlhttp.responseText == 'true') self.location.replace("defaultuser.asp");
		else if (xmlhttp.responseText == '1') alert("O Login utilizado não existe.");
		else if (xmlhttp.responseText == '2') alert("Login e Senha não conferem.");
		else alert("Sistema indisponível no momento.\nTente em outro momento ou contate-nos.");
	}
}

function loginer() {
	var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
	var query = createQuery();

	document.getElementById('loginstatus').style.visibility = 'visible';

	criaObjeto();
	xmlhttp.open("post", "login.asp", true);
	xmlhttp.onreadystatechange = logado;
	xmlhttp.setRequestHeader("Content-Type", contentType);
	xmlhttp.send(query);
		
	return true;
}

function createQuery()
{
    var pairs = new Array();
    pairs.push("login=" + encodeURIComponent(document.ident.login.value));
    pairs.push("senha=" + encodeURIComponent(document.ident.senha.value));
    return pairs.join("&");
}

function verificaLogin(xlogin) {
	criaObjeto();
	xmlhttp.open("get", "verificalogin.asp?login="+xlogin, true);	
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.responseText == 'true') {
				document.getElementById('statusLogin').style.display = 'inline';
				document.cadastro.login.style.background = '#FFA4A4';
			}
			else {
				document.getElementById('statusLogin').style.display = 'none';
				document.cadastro.login.style.background = '#96BBE0';
			}
				
		}
	};
	xmlhttp.send(null);
	
	return true;
}