function validate_forgot()
{
	var message="";
	
	if( document.getElementById('forgot_email') != 'undefined' && (isEmpty(document.getElementById('forgot_email').value) == true))
	{
		message=message+"Digite o seu endereço de e-mail\n";
		 document.getElementById('forgot_email').focus();
	}
	
	if(document.getElementById('forgot_email').value!="")
	{
	 if(isEmail(document.getElementById('forgot_email').value) == false)
	 {
		message=message+"Endereço de email válido\n";
		document.getElementById('forgot_email').focus();
	 }
	}
	
	if(message!="")
	{
		alert(message);	
		return false;
	}	
}



function validate_login()
{
	var message="";
	
	if( document.getElementById('login_email') != 'undefined' && (isEmpty(document.getElementById('login_email').value) == true))
	{
		message=message+"Digite o seu endereço de e-mail\n";
	//	document.getElementById('login_email').focus();
	}
	
	if(document.getElementById('login_email').value!="")
	{
	 if(isEmail(document.getElementById('login_email').value) == false)
	 {
		message=message+"Endereço de email válido\n";
	//	document.getElementById('login_email').focus();
	 }
	}
	
	if( document.getElementById('login_password') != 'undefined' && (isEmpty(document.getElementById('login_password').value) == true))
	{
		message=message+"Digite sua senha\n";
	//	document.getElementById('login_password').focus();
	}
	
	if(message!="")
	{
		alert(message);	
		return false;
	}	
	
}



function inner_validate_login()
{
	var message="";
	
	if( document.getElementById('inner_login_email') != 'undefined' && (isEmpty(document.getElementById('inner_login_email').value) == true))
	{
		message=message+"Digite o seu endereço de e-mail\n";
	//	document.getElementById('login_email').focus();
	}
	
	if(document.getElementById('inner_login_email').value!="")
	{
	 if(isEmail(document.getElementById('inner_login_email').value) == false)
	 {
		message=message+"Endereço de email válido\n";
	//	document.getElementById('login_email').focus();
	 }
	}
	
	if( document.getElementById('inner_login_password') != 'undefined' && (isEmpty(document.getElementById('inner_login_password').value) == true))
	{
		message=message+"Digite sua senha\n";
	//	document.getElementById('login_password').focus();
	}
	
	if(message!="")
	{
		alert(message);	
		return false;
	}	
	
}


function validate_reg()
{
	var message="";
	var focusname = ""
	if((isEmpty(document.getElementById('name').value) == true))
	{
		message=message+"Por favor introduza um nome ou apelido\n";
		focusname="name";
	}
	
	if( document.getElementById('email') != 'undefined' && (isEmpty(document.getElementById('email').value) == true))
	{
		message=message+"Digite o seu endereço de e-mail\n";
		
		if(focusname=="")
		{
			focusname="email";
		}
	}
	
	if(document.getElementById('email').value!="")
	{
	 if(isEmail(document.getElementById('email').value) == false)
	 {
		message=message+"Endereço de email válido\n";
		if(focusname=="")
		{
			focusname="email";
		}
	 }
	}
	
	if( document.getElementById('password') != 'undefined' && (isEmpty(document.getElementById('password').value) == true) )
	{
		message=message+"Digite sua senha\n";
		if(focusname=="")
		{
			focusname="password";
		}
	}
	
	if(document.getElementById('password').value !="")
	{
	if(document.getElementById('password').value.length > 4 && document.getElementById('password').value.length < 21)
	{
	}
	else
	{
		message=message+"Digite uma senha entre 5-20 caracteres\n";
		if(focusname=="")
		{
			focusname="password";
		}
	}
	}
	
	if( document.getElementById('confirm_password') != 'undefined' && (isEmpty(document.getElementById('confirm_password').value) == true) )
	{
		message=message+"Digite sua senha para verificação\n";
		if(focusname=="")
		{
			focusname="confirm_password";
		}
	}


	if(document.getElementById('confirm_password').value !="")
	{
if(document.getElementById('confirm_password').value.length > 4 && document.getElementById('confirm_password').value.length < 21)
	{
	}
	else
	{
		message=message+"Confirme uma senha entre 5-20 caracteres\n";
		if(focusname=="")
		{
			focusname="confirm_password";
		}
	}
	}


	if(document.getElementById('password').value!="" && document.getElementById('confirm_password').value!="")
	{
	if(document.getElementById('password').value != document.getElementById('confirm_password').value)
	{
		message=message+"Senha e confirmar senha não correspondem\n";
		if(focusname=="")
		{
			focusname="password";
		}
	}
	}


	if( document.getElementById('user_type') != 'undefined' && (isEmpty(document.getElementById('user_type').value) == true) )
	{
		message=message+"Selecione um tipo de usuário\n";
		if(focusname=="")
		{
			focusname="user_type";
		}
	}

if(document.getElementById('checkLocation').value!="10")
{
	if( document.getElementById('location') != 'undefined' && (isEmpty(document.getElementById('location').value) == true) )
	{
		message=message+"localização\n";
		if(focusname=="")
		{
			focusname="location";
		}
	}
}
/*
if(document.getElementById('phoneNumber').value!="")
{
	if(isNaN(document.getElementById('phoneNumber').value))
	{
		message=message+"Por favor, indique o número de telefone correto\n";
		if(focusname=="")
		{
			focusname="phoneNumber";
		}
	}
	else if(document.getElementById('phoneNumber').value.length<10)
	{
		message=message+"Por favor, indique o número de telefone correto\n";
		if(focusname=="")
		{
			focusname="phoneNumber";
		}
	}
}
*/
	if( document.getElementById('verificationCode') != 'undefined' && (isEmpty(document.getElementById('verificationCode').value) == true) )
	{
		message=message+"Indique o  código de verificação\n";
		if(focusname=="")
		{
			focusname="verificationCode";
		}
	}

	if(message!="")
	{
		document.getElementById(focusname).focus();
		alert(message);	
		return false;
	}	
}


function isEmpty(s)
{
	  s=trim(s);
	  return ((s == null) || (s.length == 0))
}

function isEmail(s)
{
	var regex = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i
	var regex =	/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return regex.test(s);
}






function checkEmailAddress(val,path)
{
	
var str1 = val.value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 
 
  
var url=path;
url=url+"?value="+str1;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function stateChanged() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	document.getElementById("email_message").innerHTML=xmlHttp.responseText 
 } 
}

 

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

















function loginEmailAddress(val,path)
{

var str1 = val.value;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
}


var url=path;
url=url+"?value="+str1;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedlogin;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function stateChangedlogin() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
  	document.getElementById("password_message").innerHTML="" 
 	document.getElementById("login_message").innerHTML=xmlHttp.responseText
 } 
}

 

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}






function loginEmailAddressthree(val,path)
{
var str1 = val.value;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
}
 
  
var url=path;
url=url+"?value="+str1;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedlogin2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function stateChangedlogin2() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
  	document.getElementById("password_message_inner").innerHTML=""
 	document.getElementById("login_message_inner").innerHTML=xmlHttp.responseText
 } 
}

 

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}








function checkEmailPass(path)
{
var str1 = document.getElementById('login_email').value;
var str2 = document.getElementById('login_password').value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 
 
  
var url=path;
url=url+"?email="+str1;
url=url+"&password="+str2;


url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedcheck;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function stateChangedcheck() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 	document.getElementById("login_message").innerHTML=""
 	document.getElementById("password_message").innerHTML=xmlHttp.responseText 
 } 
}

 

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}






function checkEmailPass_in(path)
{
var str1 = document.getElementById('inner_login_email').value;
var str2 = document.getElementById('inner_login_password').value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
} 
 
  
var url=path;
url=url+"?email="+str1;
url=url+"&password="+str2;


url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedcheckin;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function stateChangedcheckin() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 	document.getElementById("login_message_inner").innerHTML=""
 	document.getElementById("password_message_inner").innerHTML=xmlHttp.responseText 
 } 
}

 

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}





















function forgotEmailAddress(val,path)
{
var str1 = val.value;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
  alert ("Your browser does not support AJAX!");
  return;
}


var url=path;
url=url+"?value="+str1;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedforgot;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function stateChangedforgot() 
{
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	document.getElementById("forgot_message").innerHTML=xmlHttp.responseText 
 } 
}

 

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



function changeCountry()
{
	document.getElementById('idCountry').style.display = "block";
	document.getElementById('idBack').style.display = "block";
	document.getElementById('idLocation').style.display = "none";
	document.getElementById('idNocountry').style.display = "none";
	document.getElementById('cityExample').style.display = "none";
	document.getElementById('checkLocation').value="10";
	document.getElementById('location').value="";
}

function hideCountry()
{
	document.getElementById('idCountry').style.display = "none";
	document.getElementById('idBack').style.display = "none";
	document.getElementById('idLocation').style.display = "block";
	document.getElementById('idNocountry').style.display = "block";
	document.getElementById('cityExample').style.display = "block";
	document.getElementById('checkLocation').value="1";
	document.getElementById('location').value="";
}
