var xmlHttp

function VerificaLogin(pagina){ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return} 
	var email=document.getElementById('formlogin').email.value
	var password=document.getElementById('formlogin').password.value
	var url="Login_verifica.asp"
	url=url+"?act=verify&email=" + email + "&password=" + password + "&page=" + pagina
	xmlHttp.onreadystatechange=EstadoVerificaLogin
	xmlHttp.open("POST",url,true)
	xmlHttp.send(null)
}

function EstadoVerificaLogin(){ 
	if(xmlHttp.readyState == 1) {
		var conteudo=document.getElementById("carrega")
		conteudo.innerHTML='<table width="200" cellpadding="0" cellspacing="0" border="0"><tr><td height="150" align="center" valign="middle">Aguarde por favor...<br><img src="images/Ajax/bigrotation2.gif"></td></tr></table>'
		conteudo.style.visibility = "visible";
		conteudo.style.display="block";}
	if(xmlHttp.readyState == 4||xmlHttp.readyState=="Complete"){ 
		var conteudo2=document.getElementById("carrega")
		conteudo2.innerHTML=''
		conteudo2.innerHTML=xmlHttp.responseText} 
} 

function NovoRegisto(){ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return}
	var pnome=document.getElementById('novoregisto').pnome.value
	var unome=document.getElementById('novoregisto').unome.value
	var email=document.getElementById('novoregisto').email.value
	var telefone=document.getElementById('novoregisto').telefone.value
	var password=document.getElementById('novoregisto').password.value
	var password1=document.getElementById('novoregisto').password1.value
	var condicoes=document.getElementById('novoregisto').condicoes.checked
	var newsletter=document.getElementById('novoregisto').newsletter.checked
	var url="NovoRegisto_Processa.asp"
	url=url+"?pnome=" + pnome + "&unome=" + unome
	url=url+"&email=" + email + "&telefone=" + telefone
	url=url+"&password=" + password + "&password1=" + password1
	url=url+"&condicoes=" + condicoes + "&newsletter=" + newsletter
	xmlHttp.onreadystatechange=ProcessaNovoRegisto
	xmlHttp.open("POST",url,true)
	xmlHttp.send(null)
}

function ProcessaNovoRegisto(){ 
	if(xmlHttp.readyState == 1) {
		var conteudo=document.getElementById("carrega")
		conteudo.innerHTML='<table width="200" cellpadding="0" cellspacing="0" border="0"><tr><td height="150" align="center" valign="middle">Aguarde por favor...<br><img src="images/Ajax/bigrotation2.gif"></td></tr></table>'
		conteudo.style.visibility = "visible";
		conteudo.style.display="block";}
	if(xmlHttp.readyState == 4||xmlHttp.readyState=="Complete"){
		if(xmlHttp.responseText=="False"){
			document.getElementById("RegistoConcluido").style.visibility= "visible"
			document.getElementById("RegistoConcluido").style.display= "block"
			document.getElementById("carrega").style.visibility= "hidden"
			document.getElementById("carrega").style.display= "none"
			document.getElementById("FormularioRegisto").style.visibility= "hidden"
			document.getElementById("FormularioRegisto").style.display= "none"}
		else{	
			var conteudo2=document.getElementById("carrega")
			conteudo2.innerHTML=''
			conteudo2.innerHTML=xmlHttp.responseText} 
}
}

function EnviaPassword(){ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return} 
	var email=document.getElementById('loginlembra').email.value
	var url="Login_verifica.asp"
	url=url+"?act=remember&email=" + email
	xmlHttp.onreadystatechange=EstadoEnviaPassword
	xmlHttp.open("POST",url,true)
	xmlHttp.send(null)
}
function EstadoEnviaPassword(){ 
	if(xmlHttp.readyState == 1) {
		document.getElementById("lembrapassword").style.visibility= "hidden"
		document.getElementById("lembrapassword").style.display= "none"
		var conteudo=document.getElementById("carrega")
		conteudo.innerHTML='<table width="200" cellpadding="0" cellspacing="0" border="0"><tr><td height="150" align="center" valign="middle">Aguarde por favor...<br><img src="images/Ajax/bigrotation2.gif"></td></tr></table>'
		conteudo.style.visibility = "visible";
		conteudo.style.display="block";}
	if(xmlHttp.readyState == 4||xmlHttp.readyState=="Complete"){ 
		var conteudo2=document.getElementById("carrega")
		conteudo2.innerHTML=''
		conteudo2.innerHTML=xmlHttp.responseText} 
} 

function Login(Pagina){ //Função que efectua o Login
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return} 
		var url="Login_Mostra.asp?page=" + Pagina
		xmlHttp.onreadystatechange=EstadoLogin
		xmlHttp.open("POST",url,true)
		xmlHttp.send(null)
}
function EstadoLogin(){ 
	if(xmlHttp.readyState == 4||xmlHttp.readyState=="Complete"){ 
		document.getElementById("Logout").innerHTML=xmlHttp.responseText
		document.getElementById("Logout").style.visibility= "visible"
		document.getElementById("Logout").style.display= "block"
		document.getElementById("Login").style.visibility= "hidden"
		document.getElementById("Login").style.display= "none"} 
} 

function Logout(){ //Função que efectua o Logout
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return} 
		var url="Login_Verifica.asp?act=logout"
		xmlHttp.onreadystatechange=EstadoLogout
		xmlHttp.open("POST",url,true)
		xmlHttp.send(null)
}

function ActualizaFavoritos(action){ //Função que efectua o Logout
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return} 
		var url="ImoveisFavoritos.asp?act=" + action
		xmlHttp.onreadystatechange=EstadoActualizaFavoritos
		xmlHttp.open("POST",url,true)
		xmlHttp.send(null)
}
function EstadoActualizaFavoritos(){ 
	if(xmlHttp.readyState == 4||xmlHttp.readyState=="Complete")
		{ 
		document.getElementById("ImoveisFavoritos").innerHTML=''
		document.getElementById("ImoveisFavoritos").innerHTML=xmlHttp.responseText
		} 
} 

function EstadoLogout(){ 
	if(xmlHttp.readyState == 4||xmlHttp.readyState=="Complete"){ 
		document.getElementById("Logout").innerHTML=''
		document.getElementById("Logout").style.visibility= "hidden"
		document.getElementById("Logout").style.display= "none"
		document.getElementById("Login").style.visibility= "visible"
		document.getElementById("Login").style.display= "block"
		document.getElementById('formlogin').email.value=""
		document.getElementById('formlogin').password.value=""} 
} 

function MostraLembraPWD(){
	document.getElementById("lembrapassword").style.visibility= "visible"
	document.getElementById("lembrapassword").style.display= "block"
}

function MostraCondicoes(){
	document.getElementById("TermosCondicoes").style.visibility= "visible"
	document.getElementById("TermosCondicoes").style.display= "block"
	document.getElementById("FormularioRegisto").style.visibility= "hidden"
	document.getElementById("FormularioRegisto").style.display= "none"
}
function EscondeCondicoes(){
	document.getElementById("TermosCondicoes").style.visibility= "hidden"
	document.getElementById("TermosCondicoes").style.display= "none"
	document.getElementById("FormularioRegisto").style.visibility= "visible"
	document.getElementById("FormularioRegisto").style.display= "block"
}
function MostraDetalhes(){
	document.getElementById("tabfotos").style.visibility= "hidden"
	document.getElementById("tabfotos").style.display= "none"
	document.getElementById("tabdetalhes").style.visibility= "visible"
	document.getElementById("tabdetalhes").style.display= "block"
	document.getElementById("MostraFotos").style.visibility= "hidden"
	document.getElementById("MostraFotos").style.display= "none"
	document.getElementById("MostraDetalhes").style.visibility= "visible"
	document.getElementById("MostraDetalhes").style.display= "block"
}
function MostraFotos(){
	document.getElementById("tabdetalhes").style.visibility= "hidden"
	document.getElementById("tabdetalhes").style.display= "none"
	document.getElementById("tabfotos").style.visibility= "visible"
	document.getElementById("tabfotos").style.display= "block"
	document.getElementById("MostraDetalhes").style.visibility= "hidden"
	document.getElementById("MostraDetalhes").style.display= "none"
	document.getElementById("MostraFotos").style.visibility= "visible"
	document.getElementById("MostraFotos").style.display= "block"
}

function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 

function FechaErro()
{
document.getElementById("carrega").style.visibility= "hidden"
document.getElementById("carrega").style.display= "none"
}
function FechaLembra()
{
document.getElementById("lembrapassword").style.visibility= "hidden"
document.getElementById("lembrapassword").style.display= "none"
}

