// JavaScript Document
function validatecontact()
{
	if(trim(document.form1.txtname.value) == "")
	{
		alert("Please enter your name");
		document.form1.txtname.focus();
		return false;
	}
	if(SpecialValidate(document.form1.txtname,"your name")==false) {return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.form1.txtemail.value == "")
	{
		alert("Please enter your email address");		
		document.form1.txtemail.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.txtemail.value)) 	{
		alert("Please enter a valid Email");
		document.form1.txtemail.focus();	   	
		document.form1.txtemail.select();
		return false;
	}
	if(trim(document.form1.txtsubject.value) == "")
	{
		alert("Please enter subject");
		document.form1.txtsubject.focus();
		return false;
	}
	if(SpecialValidate(document.form1.txtsubject,"subject")==false) {return false;}
	if(trim(document.form1.txtmessage.value) == "")
	{
		alert("Please enter message");
		document.form1.txtmessage.focus();
		return false;
	}
	if(document.form1.txtmessage,"message"==false) {return false;}
	document.form1.action = "contactUs.php?status=email";
	document.form1.submit();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  win = window.open(theURL,winName,features);
}
function showtype(value)
{
	//alert(value);
	var value_final = value;
 	if(value_final == "buyer")
	{
 		document.getElementById("buyerform").style.display="";
		document.getElementById("sellerform").style.display="none";
	}else if(value_final == "seller"){
 		document.getElementById("sellerform").style.display="";
		document.getElementById("buyerform").style.display="none";
	}
}
function validatebuyer()
{
	if(trim(document.form1.buyer_name.value) == "")
	{
		alert("Please enter your name");
		document.form1.buyer_name.focus();
		return false;
	}
	if(SpecialValidate(document.form1.buyer_name,"your name without special characters")==false) {return false;}
	if(trim(document.form1.buyer_password.value) == "")
	{
		alert("Please enter a password");
		document.form1.buyer_password.focus();
		return false;
	}
	if(SpecialValidate(document.form1.buyer_password,"a password without special characters")==false) {return false;}
	if(trim(document.form1.buyer_confirmpassword.value) == "")
	{
		alert("Please confirm your password");
		document.form1.buyer_confirmpassword.focus();
		return false;
	}
	if(SpecialValidate(document.form1.buyer_confirmpassword,"a password without special characters")==false) {return false;}
	if(document.form1.buyer_password.value != document.form1.buyer_confirmpassword.value)
	{
		alert("The password and the confirmation password do not match");	
		document.form1.buyer_confirmpassword.focus();
		return false;
	}
	if(trim(document.form1.buyer_address1.value) == "")
	{
		alert("Please enter the first line of your address");
		document.form1.buyer_address1.focus();
		return false;
	}	
	if(trim(document.form1.buyer_town.value) == "")
	{
		alert("Please enter the name of the town/city where you live");
		document.form1.buyer_town.focus();
		return false;
	}	
	/*if(trim(document.form1.buyer_postcode.value) == "")
	{
		alert("Please enter your post / zip code");
		document.form1.buyer_postcode.focus();
		return false;
	}	*/
	if(document.form1.buyer_country.value == 0)
	{
		alert("Please select a Country");
		document.form1.buyer_country.focus();
		return false;
	}	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.form1.buyer_email.value == "")
	{
		alert("Please enter your email address");		
		document.form1.buyer_email.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.buyer_email.value)) 	{
		alert("Please enter a valid Email address");
		document.form1.buyer_email.focus();	   	
		document.form1.buyer_email.select();
		return false;
	}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.form1.buyer_confirmemail.value == "")
	{
		alert("Please confirm your email address");		
		document.form1.buyer_confirmemail.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.buyer_confirmemail.value)) 	{
		alert("Please enter a valid Email address");
		document.form1.buyer_confirmemail.focus();	   	
		document.form1.buyer_confirmemail.select();
		return false;
	}
	if(document.form1.buyer_email.value != document.form1.buyer_confirmemail.value)
	{
		alert("The email address and confirmation email address do not match");	
		document.form1.buyer_confirmemail.focus();
		return false;
	}
	if(trim(document.form1.buyer_phone.value) == "")
	{
		alert("Please enter your telephone number");
		document.form1.buyer_phone.focus();
		return false;
	}	
	if(trim(document.form1.buyer_captcha.value) == "")
	{
		alert("Please enter the text below");
		document.form1.buyer_captcha.focus();
		return false;
	}	
	if(document.form1.mail_updates.checked == true)
	{
		document.form1.hidden_mail_update.value = 1;	
	}else{
		document.form1.hidden_mail_update.value = 0;	
	}
	document.form1.action = "register.php?type=buyer";
	document.form1.submit();
}
function validateseller()
{
	if(trim(document.form1.seller_name.value) == "")
	{
		alert("Please enter a point of contact");
		document.form1.seller_name.focus();
		return false;
	}
	if(SpecialValidate(document.form1.seller_name,"a point of contact without special characters")==false) {return false;}
	/*if(trim(document.form1.seller_businessname.value) == "")
	{
		alert("Please enter a business name");
		document.form1.seller_businessname.focus();
		return false;
	}*/
	//if(SpecialValidate(document.form1.seller_businessname,"a business name without special characters")==false) {return false;}
	/*if(trim(document.form1.seller_logo.value) == "")
	{
		alert("Please upload a Company logo");
		document.form1.seller_logo.focus();
		return false;
	}*/
	if(trim(document.form1.seller_logo.value)!=""){
		if(File_Extentsion_Validate(document.form1.seller_logo,"the logo")==false) {return false;}
	}
 	if(trim(document.form1.seller_address1.value) == "")
	{
		alert("Please enter the first line of your address");
		document.form1.seller_address1.focus();
		return false;
	}	
	if(trim(document.form1.seller_town.value) == "")
	{
		alert("Please enter the name of the town/city where you live");
		document.form1.seller_town.focus();
		return false;
	}	
	/*if(trim(document.form1.seller_postcode.value) == "")
	{
		alert("Please enter your post / zip code");
		document.form1.seller_postcode.focus();
		return false;
	}*/	
	if(document.form1.seller_country.value == 0)
	{
		alert("Please select a Country");
		document.form1.seller_country.focus();
		return false;
	}	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.form1.seller_email.value == "")
	{
		alert("Please enter your email address");		
		document.form1.seller_email.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.seller_email.value)) 	{
		alert("Please enter a valid Email address");
		document.form1.seller_email.focus();	   	
		document.form1.seller_email.select();
		return false;
	}
 	if(document.form1.seller_confirmemail.value == "")
	{
		alert("Please confirm your email address");		
		document.form1.seller_confirmemail.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.seller_confirmemail.value)) 	{
		alert("Please enter a valid Email address");
		document.form1.seller_confirmemail.focus();	   	
		document.form1.seller_confirmemail.select();
		return false;
	}
	if(document.form1.seller_email.value != document.form1.seller_confirmemail.value)
	{
		alert("The email address and confirmation email address do not match");	
		document.form1.seller_confirmemail.focus();
		return false;
	}
	if(trim(document.form1.seller_password.value) == "")
	{
		alert("Please enter a password");
		document.form1.seller_password.focus();
		return false;
	}
	if(SpecialValidate(document.form1.seller_password,"a password without special characters")==false) {return false;}
	if(trim(document.form1.seller_confirmpassword.value) == "")
	{
		alert("Please confirm your password");
		document.form1.seller_confirmpassword.focus();
		return false;
	}
	if(SpecialValidate(document.form1.seller_confirmpassword,"a password without special characters")==false) {return false;}
	if(document.form1.seller_password.value != document.form1.seller_confirmpassword.value)
	{
		alert("The password and the confirmation password do not match");	
		document.form1.seller_confirmpassword.focus();
		return false;
	}

	if(trim(document.form1.seller_phone.value) == "")
	{
		alert("Please enter your telephone number");
		document.form1.seller_phone.focus();
		return false;
	}	
	if(trim(document.form1.seller_captcha.value) == "")
	{
		alert("Please enter the text below");
		document.form1.seller_captcha.focus();
		return false;
	}
	document.form1.action = "register.php?type=seller";
	document.form1.submit();
}
function validatepassword()
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.form1.txtemail.value == "")
	{
		alert("Please enter your email address");		
		document.form1.txtemail.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.txtemail.value)) 	{
		alert("Please enter a valid Email");
		document.form1.txtemail.focus();	   	
		document.form1.txtemail.select();
		return false;
	}
	/*if(document.form1.user_type[0].checked == false && document.form1.user_type[1].checked == false)
	{
		alert("Please select a type: buyer or seller");
		return false;
	}*/
	document.form1.action = "forgotpassword.php?status=email";
	document.form1.submit();
	
}
function validatelogin()
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.form1.login_email.value == "")
	{
		alert("Please enter your email address");		
		document.form1.login_email.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.login_email.value)) 	{
		alert("Please enter a valid Email");
		document.form1.login_email.focus();	   	
		document.form1.login_email.select();
		return false;
	}
	if(trim(document.form1.login_password.value) == "")
	{
		alert("Please enter a password");
		document.form1.login_password.focus();
		return false;
	}
	if(SpecialValidate(document.form1.login_password,"a password without special characters")==false) {return false;}
	/*if(document.form1.login_type[0].checked == false && document.form1.login_type[1].checked == false)
	{
		alert("Please select a type: buyer or seller");
		return false;
	}*/
	document.form1.action = "loginprocess2.php";
	document.form1.submit();
}
function validatetoplogin()
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.formtop.toplogin_email.value == "")
	{
		alert("Please enter your email address");		
		document.formtop.toplogin_email.focus();   	
		return false;		
	}	else if (!filter.test(document.formtop.toplogin_email.value)) 	{
		alert("Please enter a valid Email");
		document.formtop.toplogin_email.focus();	   	
		document.formtop.toplogin_email.select();
		return false;
	}
	document.getElementById('typetext').style.display = "none";
	document.getElementById('typepassword').style.display = "";
	if(trim(document.formtop.toplogin_password2.value) == "" || trim(document.formtop.toplogin_password2.value) == "password")
	{
		alert("Please enter a password");
		document.formtop.toplogin_password2.focus();
		return false;
	}
	if(SpecialValidate(document.formtop.toplogin_password2,"a password without special characters")==false) {return false;}
	/*if(document.formtop.toplogin_type[0].checked == false && document.formtop.toplogin_type[1].checked == false)
	{
		alert("Please select a type: buyer or seller");
		return false;
	}*/
	document.formtop.action = "loginprocess.php";
	document.formtop.submit();
}
function validatelogout()
{
	document.formtop.action="logout.php";
	document.formtop.submit();
}
function ClearValue(field, strCheck)
{
	/*document.getElementById('typepassword').style.display = "";
	document.getElementById('typetext').style.display = "none";	
	document.getElementById('toplogin_password2').focus();*/
	if(field.value == strCheck)
	field.value = "";				
}
function ClearValue_email(field, strCheck)
{
	if(field.value == strCheck)
	field.value = "";				
}
function Repopulate_email(field, strCheck)
{
	if(field.value == "")
	field.value = strCheck;
}
function changetype()
{
	if((document.getElementById('typetext').style.display == "") && (document.getElementById('typepassword').style.display == "none")){
		document.getElementById('typetext').style.display = "none";
		document.getElementById('typepassword').style.display = "";
		document.getElementById('toplogin_password2').focus();
	}
}
function changetype2()
{
	document.getElementById('typetext').style.display = "";
	document.getElementById('toplogin_password2').value = "";
	document.getElementById('typepassword').style.display = "none";
	//document.getElementById('toplogin_password2').focus();
}
function Repopulate(field, strCheck)
{
	if(field.value == ""){
		document.getElementById('typetext').style.display = "";	
		document.getElementById('typepassword').style.display = "none";	
		field.value = strCheck;
	}else{
		document.getElementById('typetext').style.display = "none";	
		document.getElementById('typepassword').style.display = "";	
	}
}
function updatebuyer()
{
	if(trim(document.form1.buyer_name.value) == "")
	{
		alert("Please enter your name");
		document.form1.buyer_name.focus();
		return false;
	}
	if(SpecialValidate(document.form1.buyer_name,"your name without special characters")==false) {return false;}
	if(trim(document.form1.buyer_address1.value) == "")
	{
		alert("Please enter the first line of your address");
		document.form1.buyer_address1.focus();
		return false;
	}	
	if(trim(document.form1.buyer_town.value) == "")
	{
		alert("Please enter the name of the town/city where you live");
		document.form1.buyer_town.focus();
		return false;
	}	
	/*if(trim(document.form1.buyer_postcode.value) == "")
	{
		alert("Please enter your post / zip code");
		document.form1.buyer_postcode.focus();
		return false;
	}*/	
	if(document.form1.buyer_country.value == 0)
	{
		alert("Please select a Country");
		document.form1.buyer_country.focus();
		return false;
	}	
	if(trim(document.form1.buyer_phone.value) == "")
	{
		alert("Please enter your telephone number");
		document.form1.buyer_phone.focus();
		return false;
	}	
	if(document.form1.mail_updates.checked == true)
	{
		document.form1.hidden_mail_update.value = 1;	
	}else{
		document.form1.hidden_mail_update.value = 0;	
	}
	document.form1.action = "myaccount.php?type=buyer&status=update";
	document.form1.submit();
}
function updateseller()
{
	if(trim(document.form1.seller_name.value) == "")
	{
		alert("Please enter a point of contact");
		document.form1.seller_name.focus();
		return false;
	}
	if(SpecialValidate(document.form1.seller_name,"a point of contact without special characters")==false) {return false;}
	if(trim(document.form1.seller_businessname.value) == "")
	{
		alert("Please enter a business name");
		document.form1.seller_businessname.focus();
		return false;
	}
	if(SpecialValidate(document.form1.seller_businessname,"a business name without special characters")==false) {return false;}
 	if(trim(document.form1.seller_logo.value)!=""){
		if(File_Extentsion_Validate(document.form1.seller_logo,"the logo")==false) {return false;}
	}
 	if(trim(document.form1.seller_address1.value) == "")
	{
		alert("Please enter the first line of your address");
		document.form1.seller_address1.focus();
		return false;
	}	
	if(trim(document.form1.seller_town.value) == "")
	{
		alert("Please enter the name of the town/city where you live");
		document.form1.seller_town.focus();
		return false;
	}	
	/*if(trim(document.form1.seller_postcode.value) == "")
	{
		alert("Please enter your post / zip code");
		document.form1.seller_postcode.focus();
		return false;
	}*/	
	if(document.form1.seller_country.value == 0)
	{
		alert("Please select a Country");
		document.form1.seller_country.focus();
		return false;
	}	
	if(trim(document.form1.seller_phone.value) == "")
	{
		alert("Please enter your telephone number");
		document.form1.seller_phone.focus();
		return false;
	}	
	document.form1.action = "myaccount.php?type=seller&status=update";
	document.form1.submit();
}
function updatepassword(type)
{
	if(trim(document.form1.password.value) == "")
	{
		alert("Please enter a password");
		document.form1.password.focus();
		return false;
	}
	if(SpecialValidate(document.form1.password,"a password without special characters")==false) {return false;}
	if(trim(document.form1.confirmpassword.value) == "")
	{
		alert("Please confirm your password");
		document.form1.confirmpassword.focus();
		return false;
	}
	if(SpecialValidate(document.form1.confirmpassword,"a password without special characters")==false) {return false;}
	if(document.form1.password.value != document.form1.confirmpassword.value)
	{
		alert("The password and the confirm Password do not match");	
		document.form1.confirmpassword.focus();
		return false;
	}
	document.form1.action = "changepassword.php?type="+type+"&status=update";
	document.form1.submit();
}
function updatesellerpassword()
{
	if(trim(document.form1.seller_password.value) == "")
	{
		alert("Please enter a password");
		document.form1.seller_password.focus();
		return false;
	}
	if(SpecialValidate(document.form1.seller_password,"a password without special characters")==false) {return false;}
	if(trim(document.form1.seller_confirmpassword.value) == "")
	{
		alert("Please confirm your password");
		document.form1.seller_confirmpassword.focus();
		return false;
	}
	if(SpecialValidate(document.form1.seller_confirmpassword,"a password without special characters")==false) {return false;}
	if(document.form1.seller_password.value != document.form1.seller_confirmpassword.value)
	{
		alert("The password and the confirmation password do not match");	
		document.form1.seller_confirmpassword.focus();
		return false;
	}
	document.form1.action = "changepassword.php?type=seller&status=update";
	document.form1.submit();
}
function validateproperty()
{
	/*if(trim(document.form1.property_reference.value) == "")
	{
		alert("Please enter a reference number");
		document.form1.property_reference.focus();
		return false;
	}*/
	if(document.form1.property_looking.value == 0)
	{
		alert("Please select an option to look for: To buy, holiday rent or long term rental");
		document.form1.property_looking.focus();
		return false;
	}
 	if(document.form1.property_type.value == 0)
	{
		alert("Please select a type option: Villa, Townhouse, Apartment, Studio or Commercial");
		document.form1.property_type.focus();
		return false;
	}
	if(document.form1.type[0].checked == false && document.form1.type[1].checked == false)
	{
		alert("Please select a type: uk or overseas");
		return false;
	}
 	if(document.getElementById("country_value").value == 0 && document.getElementById("property_country").value == "")
	{
		alert("Please select a country");
		document.form1.property_country.focus();
		return false;
	}
	if(trim(document.form1.property_price.value) == "")
	{
		alert("Please enter a price for your property");
		document.form1.property_price.focus();
		return false;
	}
	if(PriceValidate(document.form1.property_price,"numeric value for price")==false) {return false;}
	if(document.form1.property_currency.value == "")
	{
		alert("Please select a currency from the list");
		document.form1.property_currency.focus();
		return false;
	}
	if(trim(document.form1.property_bedrooms.value) != "")
	{
		if(PriceValidate2(document.form1.property_bedrooms,"numeric value for no of bedrooms")==false) {return false;}
	}
	if(trim(document.form1.property_bathrooms.value) != "")
	{
		if(PriceValidate2(document.form1.property_bathrooms,"numeric value for no of bathrooms")==false) {return false;}		
	}
	
	document.form1.action = "addproperty.php?status=add";
	document.form1.submit();
}
function addproperty()
{
	window.location.href = "addproperty.php";
}
function viewproperty(id)
{
 	var propertyid = id;
 	document.form1.action = "viewproperty.php?id="+propertyid;
	document.form1.submit();
}
function deleteproperty(id)
{
 	var propertyid = id;
	if(confirm("Are you sure you want to delete this property?")){
		document.form1.action = "myproperties.php?status=delete&id="+propertyid;
		document.form1.submit();
	}
}
function validatecancel()
{
	document.form1.action = "myproperties.php";
	document.form1.submit();
}
function validateback()
{
	document.form1.action = "myproperties.php";
	document.form1.submit();
}
function showcountry(type)
{

	//alert(type);
	if(type == "uk"){
		document.getElementById("property_region_uk_display").style.display = "";
		document.getElementById("property_country_display").style.display = "none";
		document.getElementById("property_region_display").style.display = "none";		
 		//document.getElementById("property_country").value = "GB";
		document.getElementById("country_value").value = "1";
		document.getElementById("property_sale_type").value = "uk";
	}
	if(type == "over"){
		document.getElementById("property_country_display").style.display = "";
		document.getElementById("property_region_display").style.display = "";
		document.getElementById("property_region_uk_display").style.display = "none";
		document.getElementById("country_value").value = "0";
		//alert("inside");
		//alert(document.form1.property_country.value);
		if(document.form1.property_country.value!="")
		{
			validatecountry();
			document.getElementById("property_region_uk_display").style.display = "none";  			
		}else{
			document.getElementById("property_region_display").style.display = "none";	
			document.getElementById("property_region_uk_display").style.display = "none";
		}
		document.getElementById("country_value").value = "0";
		document.getElementById("property_sale_type").value = "over";
	}
}
/*function validatecountry()
{
	document.form1.action = "addproperty.php?country="+document.form1.property_country.value;
	document.form1.submit();
}*/
function validatecountry()
{
	var xmlhttp = false;
	// If the user is using Mozilla/Firefox/Safari/etc	
	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
			//xmlhttp.setHeader("Cache-Control", "no-cache");
			//Set the mime type
			//xmlhttp.overrideMimeType('text/xml');
	}
	// If the user is using IE
	else if (window.ActiveXObject) { 
			//Intiate the object
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			//xmlhttp.setHeader("Cache-Control", "no-cache");
			//Http.get(params, callback_args)
	}	
	//Calling 
		var country = document.form1.property_country.value;		
		var url = 'ajaxprocess.php?country='+country+'&region='+document.form1.region_hidden.value;
  		//alert(url);
		//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method		
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
 		xmlhttp.onreadystatechange = function() {
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;	
					//alert(response);
					//return false;
					document.getElementById("property_region_display").style.display = "";
					document.getElementById("listbox_display").innerHTML = response;
 			}
		}
		xmlhttp.send(null);  
}
function validatecountry_search()
{
	var xmlhttp = false;
	// If the user is using Mozilla/Firefox/Safari/etc	
	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
			//xmlhttp.setHeader("Cache-Control", "no-cache");
			//Set the mime type
			//xmlhttp.overrideMimeType('text/xml');
	}
	// If the user is using IE
	else if (window.ActiveXObject) { 
			//Intiate the object
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			//xmlhttp.setHeader("Cache-Control", "no-cache");
			//Http.get(params, callback_args)
	}	
	//Calling 
		var country = document.frmsearch.property_country.value;
 		var url = 'ajaxprocess_search.php?country='+country;
  		//alert(url);
		//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method		
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
 		xmlhttp.onreadystatechange = function() {
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;						
					//alert(response);
				    //return false; 					
					var response_temp = response.split("##");
					document.getElementById("region_search").innerHTML = response_temp[0];
					if(document.frmsearch.property_country.value!=""){
						document.getElementById("price_currency_display").style.display = "";
						document.getElementById("price_currency_display2").style.display = "none";						
						document.getElementById("price_currency_display_temp").innerHTML = response_temp[1];
						document.getElementById("price_listbox").style.display = "";
						document.getElementById("price_listbox_temp").style.display = "none";
					}else{
						document.getElementById("price_currency_display").style.display = "none";
						document.getElementById("price_listbox_temp").style.display = "";
						document.getElementById("price_listbox").style.display = "none";					
					}
					//document.getElementById("region_search_temp").style.display = "none";
 			}
		}
		xmlhttp.send(null);  
}

function validateeditcountry(id)
{
	//?image_id="+id+"&id="+propertyid+"&status=removeimage"
	/*document.form1.action = "editproperty.php?country="+document.form1.property_country.value+"&id="+id;
	document.form1.submit();*/
	
	var xmlhttp = false;
	// If the user is using Mozilla/Firefox/Safari/etc	
	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
			//xmlhttp.setHeader("Cache-Control", "no-cache");
			//Set the mime type
			//xmlhttp.overrideMimeType('text/xml');
	}
	// If the user is using IE
	else if (window.ActiveXObject) { 
			//Intiate the object
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			//xmlhttp.setHeader("Cache-Control", "no-cache");
			//Http.get(params, callback_args)
	}	
	//Calling 
		var country = document.form1.property_country.value;		
		var url = 'ajaxprocess.php?country='+country;
  		//alert(url);
		//Open the URL above "asynchronously" (that's what the "true" is for) using the GET method		
		xmlhttp.open('GET', url, true);
		//Check that the PHP script has finished sending us the result
 		xmlhttp.onreadystatechange = function() {
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					var response     = xmlhttp.responseText;	
					//alert(response);
					//return false;
					document.getElementById("property_region_display").style.display = "";
					document.getElementById("property_region_edit_display").style.display = "none";
  					document.getElementById("listbox_display").innerHTML = response;
 			}
		}
		xmlhttp.send(null);  
	
}
function editproperty(id)
{
 	var propertyid = id;
 	document.form1.action = "editproperty.php?id="+propertyid;
	document.form1.submit();
}
function updateproperty(id)
{
	if(document.form1.property_looking.value == 0)
	{
		alert("Please select an option to look for: To buy, holiday rent or long term rental");
		document.form1.property_looking.focus();
		return false;
	}

	if(document.form1.property_type.value == 0)
	{
		alert("Please select a type option: Villa, Townhouse, Apartment, Studio or Commercial");
		document.form1.property_type.focus();
		return false;
	}
	//alert(document.getElementById("country_value").value);
	//alert(document.getElementById("property_country").value);
 	if(document.getElementById("property_country").value == "" && document.getElementById("country_value").value == "over")
	{
		alert("Please select a country");
		document.form1.property_country.focus();
		return false;
	}
	if(trim(document.form1.property_price.value) == "")
	{
		alert("Please enter a price for your property");
		document.form1.property_price.focus();
		return false;
	}
	if(PriceValidate(document.form1.property_price,"numeric value for price")==false) {return false;}
	if(document.form1.property_currency.value == "")
	{
		alert("Please select a currency from the list");
		document.form1.property_currency.focus();
		return false;
	}
	if(trim(document.form1.property_bedrooms.value) != "")
	{
		if(PriceValidate2(document.form1.property_bedrooms,"numeric value for no of bedrooms")==false) {return false;}
	}
	if(trim(document.form1.property_bathrooms.value) != "")
	{
		if(PriceValidate2(document.form1.property_bathrooms,"numeric value for no of bathrooms")==false) {return false;}		
	}
	
	document.form1.action = "editproperty.php?id="+id+"&status=update";
	document.form1.submit();
}
function removeimage(id,propertyid)
{
	if(confirm("Are you sure you want to delete this image?")){
		document.form1.action = "editproperty.php?image_id="+id+"&id="+propertyid+"&status=removeimage";
		document.form1.submit();
	}
}
 function OnBookmarkOwn(title,url)
{
	//alert(url);
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all) { // ie
		window.external.AddFavorite(url, title);
	}else {
		alert("Please press Ctrl+D to add this page to your bookmarks");
		return false;
	}
}
function searchoverproperty()
{
	if(document.frmsearch.debug.value!="" && document.frmsearch.debug2.value=="")
	{
		alert("Please select the to date");
		return false;
	}
	if(document.frmsearch.debug2.value!="" && document.frmsearch.debug.value=="")
	{
		alert("Please select the from date");
		return false;
	}
	if(document.frmsearch.price_minimum.value!="" && document.frmsearch.price_maximum.value!="")
	{	
 		if(parseInt(document.frmsearch.price_maximum.value) < parseInt(document.frmsearch.price_minimum.value))
		{
			alert("The maximum price must be greater than the minimum price");
			document.frmsearch.price_maximum.focus();
			return false;
		}
	}
 	if(document.frmsearch.debug.value!="" && document.frmsearch.debug2.value!="")
	{
		var fdate = document.frmsearch.debug.value;
		var tdate = document.frmsearch.debug2.value;
		var strarrfdate = fdate.split("/");	
		splitterfdate=fdate.substr(2,1);
		strarrfdate = fdate.split(splitterfdate);	
		var d = strarrfdate[1];
		var m = strarrfdate[0];
		var y = strarrfdate[2];
		var strarrtdate = tdate.split("/");
		splittertdate=tdate.substr(2,1);
		strarrtdate = tdate.split(splittertdate);
		var d1 = strarrtdate[1];
		var m1 = strarrtdate[0];
		var y1 = strarrtdate[2];
		/*alert(d);
		alert(m);
		alert(y);
		alert(d1);
		alert(m1);
		alert(y1);*/
		//return false;	
		if( y == y1)
		{
			//alert(m);
			//alert(m1);
			if(m == m1)
			{
				if(parseInt(d,10) > parseInt(d1,10))
				{
					alert("The To date must be greater than the From date");		
					document.frmsearch.debug2.focus();
					document.frmsearch.debug2.select();
					return false;
				}
			}			
			else if (parseInt(m1,10) < parseInt(m,10))
			{				
				alert("The To date must be greater than the From date");		
				document.frmsearch.debug2.focus();
				document.frmsearch.debug2.select();
				return false;
			}
		}	
		if(parseInt(y,10) > parseInt(y1,10))				
		{
			alert("The To date must be greater than the From date");		
			document.frmsearch.debug2.focus();
			document.frmsearch.debug2.select();
			return false;			
		}
}
if(document.frmsearch.property_looking[0].checked == true)
{
	var looking = document.frmsearch.property_looking[0].value;
}else if(document.frmsearch.property_looking[1].checked == true)
{
	var looking = document.frmsearch.property_looking[1].value;
}else if(document.frmsearch.property_looking[2].checked == true)
{
	var looking = document.frmsearch.property_looking[2].value;
}else{
	var looking = "";	
}
if(document.frmsearch.property_country.value!="")
{
	var city = document.frmsearch.property_city.value;
}else{
	var city = "";
}
	window.location.href = "overseasPropertySearch.php?property_looking="+looking+"&property_type="+document.frmsearch.property_type.value+"&property_country="+document.frmsearch.property_country.value+"&property_city="+city+"&property_bedrooms="+document.frmsearch.property_bedrooms.value+"&price_minimum="+document.frmsearch.price_minimum.value+"&price_maximum="+document.frmsearch.price_maximum.value+"&debug="+document.frmsearch.debug.value+"&debug2="+document.frmsearch.debug2.value+"&withimage="+document.frmsearch.withimage.value;
	//document.frmsearch.submit();
}
function searchwithimage()
{
	if(document.frmsearch.property_image.checked == true)
	{
		document.frmsearch.withimage.value = 1;
	}else{
		document.frmsearch.withimage.value = 0;
	}	
	//alert(document.frmsearch.withimage.value);
}
function searchukproperty()
{
 	if(document.frmsearch.debug.value!="" && document.frmsearch.debug2.value=="")
	{
		alert("Please select the to date");
		return false;
	}
	if(document.frmsearch.debug2.value!="" && document.frmsearch.debug.value=="")
	{
		alert("Please select the from date");
		return false;
	}
	if(document.frmsearch.price_minimum.value!="" && document.frmsearch.price_maximum.value!="")
	{	
 		if(parseInt(document.frmsearch.price_maximum.value) < parseInt(document.frmsearch.price_minimum.value))
		{
			alert("The maximum price must be greater than the minimum price");
			document.frmsearch.price_maximum.focus();
			return false;
		}
	}
 	if(document.frmsearch.debug.value!="" && document.frmsearch.debug2.value!="")
	{
		var fdate = document.frmsearch.debug.value;
		var tdate = document.frmsearch.debug2.value;
		var strarrfdate = fdate.split("/");	
		splitterfdate=fdate.substr(2,1);
		strarrfdate = fdate.split(splitterfdate);	
		var d = strarrfdate[1];
		var m = strarrfdate[0];
		var y = strarrfdate[2];
		var strarrtdate = tdate.split("/");
		splittertdate=tdate.substr(2,1);
		strarrtdate = tdate.split(splittertdate);
		var d1 = strarrtdate[1];
		var m1 = strarrtdate[0];
		var y1 = strarrtdate[2];
		/*alert(d);
		alert(m);
		alert(y);
		alert(d1);
		alert(m1);
		alert(y1);*/
		//return false;	
		if( y == y1)
		{
			//alert(m);
			//alert(m1);
			if(m == m1)
			{
				if(parseInt(d,10) > parseInt(d1,10))
				{
					alert("The To date must be greater than the From date");		
					document.frmsearch.debug2.focus();
					document.frmsearch.debug2.select();
					return false;
				}
			}			
			else if (parseInt(m1,10) < parseInt(m,10))
			{				
				alert("The To date must be greater than the From date");		
				document.frmsearch.debug2.focus();
				document.frmsearch.debug2.select();
				return false;
			}
		}	
		if(parseInt(y,10) > parseInt(y1,10))				
		{
			alert("The To date must be greater than the From date");		
			document.frmsearch.debug2.focus();
			document.frmsearch.debug2.select();
			return false;			
		}
}
	if(document.frmsearch.property_looking[0].checked == true)
	{
		var looking = document.frmsearch.property_looking[0].value;
	}else if(document.frmsearch.property_looking[1].checked == true)
	{
		var looking = document.frmsearch.property_looking[1].value;
	}else if(document.frmsearch.property_looking[2].checked == true)
	{
		var looking = document.frmsearch.property_looking[2].value;
	}else{
		var looking = "";	
	}
		window.location.href = "ukPropertySearch.php?property_looking="+looking+"&property_type="+document.frmsearch.property_type.value+"&property_region="+document.frmsearch.property_region.value+"&property_city="+document.frmsearch.property_city.value+"&property_bedrooms="+document.frmsearch.property_bedrooms.value+"&price_minimum="+document.frmsearch.price_minimum.value+"&price_maximum="+document.frmsearch.price_maximum.value+"&debug="+document.frmsearch.debug.value+"&debug2="+document.frmsearch.debug2.value+"&withimage="+document.frmsearch.withimage.value;

	//document.frmsearch.action = "ukPropertySearch.php";
	//document.frmsearch.submit();
}
function searchukwithimage()
{
	if(document.frmsearch.property_image.checked == true)
	{
		document.frmsearch.withimage.value = 1;
	}else{
		document.frmsearch.withimage.value = 0;
	}	
}
function contactowner(id,type)
{
	//alert("inside");
	document.frmdetail.action = "contactowner.php?property_id="+id+"&type="+type;
	document.frmdetail.submit();
}
function validateowner(id,type)
{
	if(trim(document.form1.name.value) == "")
	{
		alert("Please enter your name");
		document.form1.name.focus();
		return false;
	}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.form1.email.value == "")
	{
		alert("Please enter your email address");		
		document.form1.email.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.email.value)) 	{
		alert("Please enter a valid Email address");
		document.form1.email.focus();	   	
		document.form1.email.select();
		return false;
	}
	if(trim(document.form1.phone.value) == "")
	{
		alert("Please enter your phone number");
		document.form1.phone.focus();
		return false;
	}

	/*if(document.form1.terms.checked == false)
	{
		alert("Please agree to the terms and conditions");	
		document.form1.terms.focus();
		return false;
	}*/
	document.form1.action = "contactowner.php?status=mail&property_id="+id+"&type="+type;
	document.form1.submit();
}
function validatecheck1()
{
	if(document.form1.currency_exchange.checked == true)
	{
		document.form1.currency_hidden.value = "Yes";	
	}else{
		document.form1.currency_hidden.value = "No";	
	}
}
function validatecheck2()
{
	if(document.form1.mortgage_quote.checked == true)
	{
		document.form1.mortgage_hidden.value = "Yes";	
	}else{
		document.form1.mortgage_hidden.value = "No";	
	}
}
function validateemailfriend(id,type)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;	
	if(document.form1.email_friend.value == "")
	{
		alert("Please enter an email address");		
		document.form1.email_friend.focus();   	
		return false;		
	}	else if (!filter.test(document.form1.email_friend.value)) 	{
		alert("Please enter a valid Email address");
		document.form1.email_friend.focus();	   	
		document.form1.email_friend.select();
		return false;
	}
	if(document.form1.email_friend2.value!="")
	{
		if (!filter.test(document.form1.email_friend2.value)){
				alert("Please enter a valid Email address");
				document.form1.email_friend2.focus();	   	
				document.form1.email_friend2.select();
				return false;
		}
	}
	if(document.form1.email_friend3.value!="")
	{
		if (!filter.test(document.form1.email_friend3.value)){
				alert("Please enter a valid Email address");
				document.form1.email_friend3.focus();	   	
				document.form1.email_friend3.select();
				return false;
		}
	}
	if(document.form1.email_friend4.value!="")
	{
		if (!filter.test(document.form1.email_friend4.value)){
				alert("Please enter a valid Email address");
				document.form1.email_friend4.focus();	   	
				document.form1.email_friend4.select();
				return false;
		}
	}

	if(document.form1.email_friend5.value!="")
	{
		if (!filter.test(document.form1.email_friend5.value)){
				alert("Please enter a valid Email address");
				document.form1.email_friend5.focus();	   	
				document.form1.email_friend5.select();
				return false;
		}
	}
	document.form1.action = "response_mail.php?status=mail&property_id="+id+"&type="+type;
 	document.form1.submit();
}
function validatecontactback(id,type)
{
	if(type == "uk")
	{
		document.form1.action = "ukDetail.php?property_id="+id;
		document.form1.submit();
	}
	if(type == "over")
	{
		document.form1.action = "overseasDetail.php?property_id="+id;
		document.form1.submit();
	}
}
function validateregion()
{
	if(document.form1.property_region_ajax.value!="")
	{
		document.form1.region_hidden.value = document.form1.property_region_ajax.value;
	}
}