function Trim(strStr){
	return strStr.replace(/^\s+|\s+$/g,"");
}

function Agree(str){
	if(confirm(str))
		return true;
	else
		return false;
}

function menuClick(strPagina){
	self.location.href = 'index.php?getx='+strPagina;
}

//Função que oculta/exibe a tela de loading do login
function divLogin(bolRestart){
	var divLoginErrorContainer = document.getElementById('divLoginErrorContainer');
	var divLoginError = document.getElementById('divLoginError');
	
	if(divLoginError.style.display == 'none' || divLoginError.style.display == ''){
		divLoginError.style.display = 'block';
		divLoginErrorContainer.style.display = 'block';
	}else{
		divLoginError.style.display = 'none';
		divLoginErrorContainer.style.display = 'none';
	}
	
	if(bolRestart)
		divLoginError.innerHTML = "<p>&nbsp;<br />&nbsp;</p>\
								  <p><img src='images/loading_blackbg.gif' border='0' align='middle' /></p>\
								  <p>Efetuando Login...</p>";
}

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 checkLogin(objForm){
	var divLoginError = document.getElementById('divLoginError');
	strLogin = Trim(objForm.strLogin.value);
	pwdSenha = Trim(objForm.pwdSenha.value);
	
	divLogin();
	
	if(xmlhttp){
		xmlhttp.open("GET", "incloodes/index_login.php?strLogin="+strLogin+"&pwdSenha="+pwdSenha, true);
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					strResponse = xmlhttp.responseText;
					if(!strResponse){ // OK
						divLoginEntrar();
						divLogin();
					}else // Erro
						divLoginError.innerHTML = strResponse;
				}else
					divLoginError.innerHTML = "Ocorreu um erro: (" + xmlhttp.status + ")" + xmlhttp.statusText;
			}
		} 
	}
	xmlhttp.send(null);
	
	return false;
}

function divLoginEntrar(){
	var divLoginContainer = document.getElementById('divLoginContainer');
	
	if(xmlhttp){
		xmlhttp.open("GET", "incloodes/index_logado.php", true);
		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					strResponse = xmlhttp.responseText;
					divLoginContainer.innerHTML = strResponse;
				}else
					divLoginContainer.innerHTML = "Ocorreu um erro: (" + xmlhttp.status + ")" + xmlhttp.statusText;
			}
		}
	} 
	xmlhttp.send(null);
}
