var last_period_lastnight = "";
var date_duplicate_count = 0;
function ComparedatePrevoiusEnquiry(fdate,tdate) { 
 	var strarrfdate = fdate.value.split("/"); 
	splitterfdate=fdate.value.substr(2,1); 
	strarrfdate = fdate.value.split(splitterfdate); 
	var d = strarrfdate[0]; 
	var m = strarrfdate[1]; 
	var y = strarrfdate[2]; 
	var strarrtdate = tdate.value.split("/"); 
	splittertdate=tdate.value.substr(2,1); 
	strarrtdate = tdate.value.split(splittertdate); 
	var d1 = strarrtdate[0]; 
	var m1 = strarrtdate[1]; 
	var y1 = strarrtdate[2]; 
	var error = 0;
	if( y == y1) {
		if(m == m1) {
			if(parseInt(d,10) > parseInt(d1,10)) {
				var error = 1;
				//alert("inside1");
				alert("Last night should be greater than First night"); 
				return false; 
			} 
		} else if (parseInt(m,10) > parseInt(m1,10)) { 
			var error = 1;
			//alert("inside2");
			alert("Last night should be greater than First night"); 
			return false; 
		} 
	} if(parseInt(y,10) > parseInt(y1,10)) { 
		var error = 1;
		//alert("inside3");
		alert("Last night should be greater than First night"); 		
		return false; 
	} 
	//alert(error);
	return true;
	//return error;
}
function ComparedateSpecialofferdate(fdate,tdate) { 
	//alert(fdate);
	var strarrfdate = fdate.value.split("/"); 
	splitterfdate=fdate.value.substr(2,1); 
	strarrfdate = fdate.value.split(splitterfdate); 
	var d = strarrfdate[0]; 
	var m = strarrfdate[1]; 
	var y = strarrfdate[2]; 
	//alert(strarrfdate);
	//return false;
	var strarrtdate = tdate.value.split("/"); 
	splittertdate=tdate.value.substr(2,1); 
	strarrtdate = tdate.value.split(splittertdate); 
	var d1 = strarrtdate[0]; 
	var m1 = strarrtdate[1]; 
	var y1 = strarrtdate[2]; 
	//alert(strarrtdate);
	//return false;
	var error = 0;
	if( y == y1) {
		if(m == m1) {
			if(parseInt(d,10) > parseInt(d1,10)) {
				var error = 1;
				//alert("inside1");
				alert("Special offer date should be greater than current date"); 
				return false; 
			} 
		} else if (parseInt(m,10) > parseInt(m1,10)) { 
			var error = 1;
			//alert("inside2");
			alert("Special offer date should be greater than current date"); 
			return false; 
		} 
	} if(parseInt(y,10) > parseInt(y1,10)) { 
		var error = 1;
		//alert("inside3");
		alert("Special offer date should be greater than current date"); 		
		return false; 
	} 
	//alert(error);
	return true;
	//return error;
}

function RegisterPageValidate(){
	if(TextValidate(document.frmproperty.agent_firstname,"First name")==false) { return false;	}
	if(TextValidate(document.frmproperty.agent_lastname,"Last name")==false) { return false;	}
	if(TextValidate(document.frmproperty.agent_email,"Email address")==false) { return false;	}
	if(EmailValidate(document.frmproperty.agent_email,"Email address")==false) { return false;	}
	
	//Address
	if(TextValidate(document.frmproperty.agent_address1,"Address")==false) { return false;	}
	if(document.frmproperty.agent_address1.value == "Address Line1")
	{
		alert("Please enter the Address");
		document.frmproperty.agent_address1.focus();
		return false;
	}
	/*if(document.frmproperty.agent_address.value == "Owners personal address not the address of the holiday property"){
			alert("Please enter Address");
			document.frmproperty.agent_address.focus();
			
			document.frmproperty.agent_address.value = "";
			return false;
	}*/
	
	
	if(TextValidate(document.frmproperty.agent_town,"Town/City")==false) { return false;	}
	if(TextValidate(document.frmproperty.agent_postcode,"Post/Zip code")==false) { return false;	}
	if(SelectValidate(document.frmproperty.agent_country,"Country")==false) { return false;	}
	//if(TextValidate(document.frmproperty.agent_languagespoken,"Languages spoken")==false) { return false;	}
	if(SelectValidate(document.frmproperty.agent_find,"How did you find us")==false) { return false;	}
	
	if(TextValidate(document.frmproperty.agent_username,"Username")==false) { return false;	} // username
	if(trim(document.frmproperty.agent_username.value) == "Minimum of 6 characters"){
			alert("Please enter Username");
			document.frmproperty.agent_username.focus();
			document.frmproperty.agent_username.value = "";
			return false;
	}
	if(trim(document.frmproperty.agent_username.value).length < 6)
	{
		alert("The username should be a minimum of 6 characters");	
		document.frmproperty.agent_username.focus();
		return false;
	}
 	/*if(MinumumLengthValidate(document.frmproperty.agent_username,6)==false) { return false;	}
	
	///Passowrd	
	if(TextValidate(document.frmproperty.agent_password,"Password")==false) { return false;	} // password
	if(document.frmproperty.agent_password.value == "Minimum of 6 characters"){
			alert("Please enter Password");
			document.frmproperty.agent_password.focus();
			document.frmproperty.agent_password.value = "";
			return false;
	}	
	if(MinumumLengthValidate(document.frmproperty.agent_password,6)==false) { return false;}*/
	//if(TextValidate(document.frmproperty.agent_password,"Password")==false) { return false;	}
	if(trim(document.frmproperty.agent_password.value) == "")
	{
		alert("The password should be a minimum of 6 characters");	
		document.frmproperty.agent_password.focus();
		return false;
	}
	if(trim(document.frmproperty.agent_password.value).length < 6)
	{
		alert("The password should be a minimum of 6 characters");	
		document.frmproperty.agent_password.focus();
		return false;
	}
	//if(TextValidate(document.frmproperty.agent_confirm_password,"Confirm Password")==false) { return false;	}
	if(trim(document.frmproperty.agent_confirm_password.value) == "")
	{
		alert("The Confirmation password should be a minimum of 6 characters");	
		document.frmproperty.agent_confirm_password.focus();
		return false;
	}
	if(document.frmproperty.agent_confirm_password.value.length < 6)
	{
		alert("The Confirmation Password should be minumum 6 characters");	
		document.frmproperty.agent_confirm_password.focus();
		return false;
	}
	if(Comparetextboxes(document.frmproperty.agent_password,document.frmproperty.agent_confirm_password)==false) { return false;	}
	/*if(TextValidate(document.frmproperty.agent_phone,"Telephone number")==false) { return false;}
	if(document.frmproperty.agent_phone.value == "+")
	{
		alert("Please enter the Telephone number");
		document.frmproperty.agent_phone.focus();
		return false;
	}
	if(TextValidate(document.frmproperty.agent_mobile,"Mobile number")==false) { return false;}	
	if(document.frmproperty.agent_mobile.value == "+")
	{
		alert("Please enter the Mobile number");
		document.frmproperty.agent_mobile.focus();
		return false;
	}*/
	//if(TextValidate(document.frmproperty.agent_phone,"Telephone")==false) { return false;	} // contact numbers
	/*if(document.frmproperty.agent_phone.value == "+"){
			alert("Please enter Telephone");
			document.frmproperty.agent_phone.focus();
			return false;
	}	*/
	
	
	//if(TextValidate(document.frmproperty.agent_mobile,"Mobile phone")==false) { return false;	} // contact numbers
	/*if(document.frmproperty.agent_mobile.value == "+"){
			alert("Please enter Mobile phone");
			document.frmproperty.agent_mobile.focus();
			return false;
	}*/
	//alert(document.frmproperty.agent_terms.checked);
	//return false;
	//alert(document.frmproperty.agent_alerts.checked);
	if(document.frmproperty.agent_alerts.checked == true)
	{
		
		if(trim(document.frmproperty.agent_mobile.value) == "")
		{
 			alert("Please enter a mobile number");
			document.frmproperty.agent_mobile.focus();
			return false;
		}
	}
	if(document.frmproperty.agent_terms.checked == false){
			//alert("inside");
			//return false;
			alert("Please tick to confirm that you have read our Terms and Conditions");
			document.frmproperty.agent_terms.focus();
			return false;
	}
	//alert("outisde");
	//return false;
	document.frmproperty.action="/advertise/?process=register";
	document.frmproperty.submit();
}


function RegisterPageUpdateValidate(){
	if(TextValidate(document.frmproperty.agent_firstname,"First name")==false) { return false;	}
	if(TextValidate(document.frmproperty.agent_lastname,"Last name")==false) { return false;	}
	if(TextValidate(document.frmproperty.agent_email,"Email address")==false) { return false;	}
	if(EmailValidate(document.frmproperty.agent_email,"Email address")==false) { return false;	}
	
	//Address
	if(TextValidate(document.frmproperty.agent_address1,"Address")==false) { return false;	}
	/*if(document.frmproperty.agent_address.value == "Owners personal address not the address of the holiday property"){
			alert("Please enter Address");
			document.frmproperty.agent_address.focus();
			
			document.frmproperty.agent_address.value = "";
			return false;
	}*/
	
	
	if(TextValidate(document.frmproperty.agent_town,"Town/City")==false) { return false;	}
	if(TextValidate(document.frmproperty.agent_postcode,"Post/Zip code")==false) { return false;	}
	if(SelectValidate(document.frmproperty.agent_country,"Country")==false) { return false;	}
	//if(TextValidate(document.frmproperty.agent_languagespoken,"Languages spoken")==false) { return false;	}
	//if(SelectValidate(document.frmproperty.agent_find,"How did you find us")==false) { return false;	}	
	
	///Passowrd	
	if(document.frmproperty.agent_new_password.value!=""){
		//if(MinumumLengthValidate(document.frmproperty.agent_new_password,6)==false) { return false;}
			if(document.frmproperty.agent_new_password.value.length < 6)
			{
				alert("The password should be a minimum of 6 characters");	
				document.frmproperty.agent_new_password.focus();
				return false;
			}
	}
	if(document.frmproperty.agent_new_password.value!="" && document.frmproperty.agent_new_confirm_password.value=="")
	{
		alert("Please confirm the password");
		document.frmproperty.agent_new_confirm_password.focus();
		return false;
	}
	if(document.frmproperty.agent_new_confirm_password.value!="" && document.frmproperty.agent_new_password.value!=""){
 		if(document.frmproperty.agent_new_confirm_password.value.length < 6)
		{
			alert("The Confirmation password should be a minimum of 6 characters");	
			document.frmproperty.agent_new_confirm_password.focus();
			return false;
		}
	}

	if(document.frmproperty.agent_new_password.value!="" && document.frmproperty.agent_new_confirm_password.value!=""){
		if(Comparetextboxes(document.frmproperty.agent_new_password,document.frmproperty.agent_new_confirm_password)==false) { return false;	}
	}	
	/*if(TextValidate(document.frmproperty.agent_phone,"Telephone")==false) { return false;	} // contact numbers
	if(document.frmproperty.agent_phone.value == "+"){
			alert("Please enter Telephone");
			document.frmproperty.agent_phone.focus();
			return false;
	}	
	
	
	if(TextValidate(document.frmproperty.agent_mobile,"Mobile phone")==false) { return false;	} // contact numbers
	if(document.frmproperty.agent_mobile.value == "+"){
			alert("Please enter Mobile phone");
			document.frmproperty.agent_mobile.focus();
			return false;
	}*/
	if(document.frmproperty.agent_alerts.checked == true)
	{
 		if(trim(document.frmproperty.agent_mobile.value) == "" || trim(document.frmproperty.agent_mobile.value) == "+")
		{
 			alert("Please enter a mobile number");
			document.frmproperty.agent_mobile.focus();
			return false;
		}
	}
	document.frmproperty.action="updateAccountDetails.php?agent_action=update";
	document.frmproperty.submit();
}



function RegisterClearDefaultValues(defaultvalue, controlname){
	if(document.getElementById(controlname).value == defaultvalue){
		document.getElementById(controlname).value = ""; // clear
	}
	if(controlname == "agent_new_password")
	{
		document.getElementById("agent_new_password").type = "password";	
	}
	if(controlname == "agent_password")
	{
		document.getElementById("agent_password").type = "password";	
	}
}

function DescriptionPageValidate(){
	var form_name = document.frmproperty;
	
	if(form_name.property_summary.value!="")
	{
		var length = document.getElementById("property_summary").value.length;	
		if(length > 200){
			alert("The maximum is 200 characters");
			//document.getElementById("property_summary").value = "";
			document.getElementById("property_summary").focus();
			return false;
		}
	}
	if(form_name.property_name.value!="")
	{
		if(QuoteValidate(document.getElementById("property_name"),"Property name field") == false){return false;}	
	}	
	if(form_name.property_postcode.value!="")
	{
		if(QuoteValidate(document.getElementById("property_postcode"),"Property postcode field") == false){return false;}	
	}	
	if(form_name.property_website.value!="")
	{
		if(QuoteValidate(document.getElementById("property_website"),"Property website field") == false){return false;}	
	}	
	//alert(form_name.property_type.value);
	//return false;
	if(form_name.property_name.value == "" || form_name.property_type_new.value == "" || form_name.property_bedrooms_new.value == "" || form_name.property_sleeps.value == "" || form_name.property_summary.value == "" || form_name.property_summary.value == "Max 200 characters" || form_name.property_description.value == ""){
		if(confirm("You have not completed all the necessary fields. Press OK to save anyway and return later or cancel to complete them now"))
		{
			document.frmproperty.action = "propertyDescription.php";
			document.frmproperty.submit();
		}	
	}else{
			document.frmproperty.action = "propertyDescription.php";
			document.frmproperty.submit();
	}
	
}

function FeaturesPageValidate(){
	var form_name = document.frmproperty;

if(form_name.property_doublebed.value == "" && form_name.property_singlebed.value == "" && form_name.property_highchairs.value == "" && form_name.property_sofabed.value == "" && form_name.property_cots.value == "" && form_name.property_bathroom.value == "" && form_name.property_ensuite.value == "" && form_name.property_shower.value == "" && form_name.property_wc.value == "" && form_name.property_diningseat.value == "" && form_name.property_loungeseat.value == "" && form_name.facility_hidden.value == "" && form_name.outdoorfacility_hidden.value == "" && form_name.property_notes.value == ""){
		if(confirm("You have not completed all the necessary fields. Press OK to save anyway and return later or cancel to complete them now"))
		{
			document.frmproperty.action = "propertyFeatures.php";
			document.frmproperty.submit();
		}	
	}else{
			document.frmproperty.action = "propertyFeatures.php";
			document.frmproperty.submit();
	}
}
function LocationPageValidate(){
	var country_list = document.frmproperty.property_country_new.value;
	var region_list  = document.frmproperty.property_region_new.value;
	var town_list    = document.frmproperty.property_town_new.value;
	var country_text = document.frmproperty.country_new.value;
	var region_text  = document.frmproperty.region_new.value;
	var town_text    = document.frmproperty.town_new.value;
	var nearest_beach = document.frmproperty.property_beach.value;
	var nearest_beach_distance = document.frmproperty.property_beachdistance_loc.selectedIndex;
	//var postcode = document.frmproperty.property_postcode.value;
	//alert(nearest_beach_distance);
	//return false;
	if(document.frmproperty.property_airportdistance.value!="")
	{
		if(AlphaValidate(document.getElementById("property_airportdistance"),"alphabets or special characters for Airport distance") == false){return false;}
		//if(DecimalValidate(document.getElementById("property_airportdistance"),"decimal points for Airport distance") == false){return false;}
	}
	
	if(document.frmproperty.property_stationdistance.value!="")
	{
		if(AlphaValidate(document.getElementById("property_stationdistance"),"alphabets or special characters for Station distance") == false){return false;}
		//if(DecimalValidate(document.getElementById("property_stationdistance"),"decimal points for Station distance") == false){return false;}
	}
	
	if(document.frmproperty.property_port_distance.value!="")
	{
		if(AlphaValidate(document.getElementById("property_port_distance"),"alphabets or special characters for Port distance") == false){return false;}
		//if(DecimalValidate(document.getElementById("property_port_distance"),"decimal points for Port distance") == false){return false;}
	}
	
	if(document.frmproperty.property_pubdistance.value!="")
	{
		if(AlphaValidate(document.getElementById("property_pubdistance"),"alphabets or special characters for Pub distance") == false){return false;}
		//if(DecimalValidate(document.getElementById("property_pubdistance"),"decimal points for Pub distance") == false){return false;}
	}
	
	if(document.frmproperty.property_restaurantdistance.value!="")
	{
		if(AlphaValidate(document.getElementById("property_restaurantdistance"),"alphabets or special characters for Restaurant distance") == false){return false;}
		//if(DecimalValidate(document.getElementById("property_restaurantdistance"),"decimal points for Restaurant distance") == false){return false;}
	}
	
	if(document.frmproperty.property_supermarketdistance.value!="")
	{
		if(AlphaValidate(document.getElementById("property_supermarketdistance"),"alphabets or special characters for Supermarket distance") == false){return false;}
		//if(DecimalValidate(document.getElementById("property_supermarketdistance"),"decimal points for Supermarket distance") == false){return false;}
	}	
	
	
	if(document.frmproperty.property_golfdistance.value!="")
	{
		if(AlphaValidate(document.getElementById("property_golfdistance"),"alphabets or special characters for Golf distance") == false){return false;}
		//if(DecimalValidate(document.getElementById("property_golfdistance"),"decimal points for Golf distance") == false){return false;}
	}	
	//alert(region_list);
	//alert(region_text);
	//return false;
	
	
	if(document.frmproperty.country_new.value!="")
	{
		if(QuoteValidate(document.getElementById("country_new"),"country field") == false){return false;}
	}
	
	if(document.frmproperty.region_new.value!="")
	{
		if(QuoteValidate(document.getElementById("region_new"),"region field") == false){return false;}
	}
	
	if(document.frmproperty.subregion_new.value!="")
	{
		if(QuoteValidate(document.getElementById("subregion_new"),"subregion field") == false){return false;}
	}
	
	if(document.frmproperty.town_new.value!="")
	{
		if(QuoteValidate(document.getElementById("town_new"),"town field") == false){return false;}
	}
	
	if(document.frmproperty.property_airport.value!="")
	{
		if(QuoteValidate(document.getElementById("property_airport"),"airport field") == false){return false;}
	}
	
	if(document.frmproperty.property_station.value!="")
	{
		if(QuoteValidate(document.getElementById("property_station"),"station field") == false){return false;}
	}
	
	if(document.frmproperty.property_port.value!="")
	{
		if(QuoteValidate(document.getElementById("property_port"),"port field") == false){return false;}
	}
	if(document.frmproperty.property_beach.value!="")
	{
		if(QuoteValidate(document.getElementById("property_beach"),"beach field") == false){return false;}
	}
	if(document.frmproperty.property_pub.value!="")
	{
		if(QuoteValidate(document.getElementById("property_pub"),"pub field") == false){return false;}
	}
	
	if(document.frmproperty.property_restaurant.value!="")
	{
		if(QuoteValidate(document.getElementById("property_restaurant"),"restaurant field") == false){return false;}
	}
	
	if(document.frmproperty.property_supermarket.value!="")
	{
		if(QuoteValidate(document.getElementById("property_supermarket"),"supermarket field") == false){return false;}
	}
	
	if(document.frmproperty.property_golf.value!="")
	{
		if(QuoteValidate(document.getElementById("property_golf"),"golf field") == false){return false;}
	}	
	
	
 	if((country_list == 0 && (country_text == "Enter Country" || country_text == "")) || (region_list == 0 && (region_text == "Enter Region" || region_text == "")) || (nearest_beach == "") || (nearest_beach_distance == 0) || (town_list == 0 && (town_text == "Enter Town" || town_text == "")) || document.getElementById("lat").value == "46.31658" || document.getElementById("lng").value == "2.28516"){
		if(confirm("You have not completed all the necessary fields. Press OK to save anyway and return later or cancel to complete them now"))
		{
			document.frmproperty.action = "propertyLocation.php";
			document.frmproperty.submit();
		}	
	}else{
			document.frmproperty.action = "propertyLocation.php";
			document.frmproperty.submit();
	}
}

function validatesmsalert()
{
	if(document.frmproperty.agent_alerts.checked == true)
	{		
		document.frmproperty.agent_alerts_hidden.value = 1;
	}else{
		document.frmproperty.agent_alerts_hidden.value = 0;
	}
}
function ValidateAgentLogin(url)
{

 	if(document.frmlogin.txtusername.value == "username" || document.frmlogin.txtusername.value == "")
	{
		alert("Please enter the Username");	
		document.frmlogin.txtusername.focus();
		return false;
	}
	if(document.getElementById("typetext").style.display == ""){
		if(document.frmlogin.txtpassword.value == "password")
		{
			alert("Please enter the Password");	
			document.frmlogin.txtpassword.focus();
			return false;
		}
	}else{
		if(document.frmlogin.txtpassword2.value == "")
		{
			alert("Please enter the Password");	
			document.frmlogin.txtpassword2.focus();
			return false;
		}
	}
 	document.frmlogin.action = url+"validateagentlogin.php";
	document.frmlogin.submit();
}
function changeyear(year,type) {
	//alert(year);
	var type = type;
	var year = trim(year);
 	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 year = ;	
		//alert(year);
		var property_id = document.getElementById("property_id").value;
		var url = 'changeyear2.php?property_id='+property_id+'&type='+type+'&year='+year+"&r="+ Math.random();		
		//alert(url);
		//return false;
 		//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() {
			//alert(xmlhttp.readyState);
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					//alert(xmlhttp.responseText);
					var response     = xmlhttp.responseText;	
					//alert(response);
					//alert(type);calender_content_new				
					document.getElementById("curyear_hidden").value = year;
					document.getElementById("calender_content").innerHTML = response;		
					if(type == "next")
					{
						document.getElementById("nextyear").innerHTML = Number(year)+1;
						document.getElementById("prevyear").innerHTML = Number(year)-1;
					}
					if(type == "prev")
					{
						document.getElementById("prevyear").innerHTML = Number(document.getElementById("prevyear").innerHTML)-1;
						document.getElementById("nextyear").innerHTML = Number(document.getElementById("nextyear").innerHTML)-1;
					}
								
 			}
		}
		xmlhttp.send(null);  
}
function datediff(from_date,to_date){
	//alert(from_date);
	//alert(to_date);
	var year1_temp = from_date.split("-");
	var year2_temp = to_date.split("-");
	var temp_from = "link"+from_date;
	var temp_to = "link"+to_date;
	var fromarray = from_date.split("-");
	var toarray = to_date.split("-");
	var montharr = fromarray[1]-1;
	var montharr2 = toarray[1]-1;
	var fromdate = new Date(fromarray[0],montharr,fromarray[2]);
	var todate  =  new Date(toarray[0],montharr2,toarray[2]);
	//alert(temp_from);
	//alert(temp_to);
	if (fromdate.getTime()>=todate.getTime()) {	
		if(year1_temp[0] == year2_temp[0]){
			document.getElementById(temp_from).style.border = "1px solid #D8D8D8";
			document.getElementById(temp_to).style.border = "1px solid #D8D8D8";
			document.getElementById("choosen_date").value = "";
		}else{
			//document.getElementById(temp_from).style.border = "1px solid #D8D8D8";
			document.getElementById(temp_to).style.border = "1px solid #D8D8D8";
			document.getElementById("choosen_date").value = "";
		}
		//alert("above");
		alert("wrong selection");	
		return false;
	}else {
		return true;	
	}
}
Date.prototype.getDayName = function() {
var d = ['Sun','Mon','Tues','Wed',
'Thur','Fri','Sat'];
return d[this.getDay()];
}
Date.prototype.getDayName2 = function() {
var d2 = ['Sun','Mon','Tues','Wed',
'Thur','Fri','Sat'];
return d2[this.getDay()];
}

function selectdate(date)
{
	//alert(date);
	var link_date = "link"+date;	
	var browserName = navigator.appName;
	document.getElementById(link_date).style.border = "1px solid #00B0F0";
	/*if (browserName=="Microsoft Internet Explorer")	{
	   document.getElementById(link_date).setAttribute('className', 'monthcalendarActive');
	} else {
		document.getElementById(link_date).setAttribute('class', 'monthcalendarActive');	
	}*/
	//document.getElementById(link_date).value
 	var final_date;
	if(document.getElementById("choosen_date").value!="")
	{
		var hidden_temp = document.getElementById("choosen_date").value.split(",");
		//alert(hidden_temp.length);
		if(hidden_temp.length > 1)
		{
			alert("You can select only two dates for a booking");
			//alert(document.getElementById("choosen_date").value);
			for (var i = 0; i < hidden_temp.length; i++)
 			{
				var link_name = "link"+hidden_temp[i];
				document.getElementById(link_name).style.border = "1px solid #D8D8D8";
			}
			var link_name2 = "link"+date;
			document.getElementById(link_name2).style.border = "1px solid #D8D8D8";
			document.getElementById("choosen_date").value = "";
			tt_HideInit();
			return false;
		}
	}
	//alert(document.getElementById("choosen_date").value);
	if(document.getElementById("choosen_date").value == "") {
		final_date = date;
		document.getElementById("choosen_date").value = final_date;		
		//alert("inside1");
	}else {
		var current_date = document.getElementById("choosen_date").value;
		var property_id = document.getElementById("property_id").value;
		final_date = current_date+","+date;
		//var fromdate_display = current_date.split("-");
  		//var fromdate_popup = dateFormat(current_date);
		//var todate_display = date.split("-");
  		//var todate_popup = dateFormat(date);
		if(datediff(current_date,date)) {
			//alert(current_date);
			var fromarrayNew = current_date.split("-");	
			//alert(fromarrayNew[0]);
			//alert(fromarrayNew[1]);
			//alert(fromarrayNew[2]);
			var montharr = fromarrayNew[1] - 1;
			var now = new Date(fromarrayNew[0],montharr,fromarrayNew[2]);
			//alert(now);
			if(now.getDate() < 10)
			{
				var fianl_date_temp = "0"+now.getDate();
			}else{
				var fianl_date_temp = now.getDate();
			}
			if(now.getMonth() < 9)
			{
				var fianl_month_new = Number(now.getMonth())+1;
				var fianl_month_temp = "0"+fianl_month_new;
			}else{
				var fianl_month_new = Number(now.getMonth())+1;
				var fianl_month_temp = fianl_month_new;
			}
			//var fianl_month_new = Number(fianl_month_temp) + 1;
			var dateStringNew = now.getDayName()+" "+fianl_date_temp+ "/" +fianl_month_temp + "/" + now.getFullYear();
			
			var fromarrayNew2 = date.split("-");
			var montharr2 = fromarrayNew2[1] - 1;
			var now2 = new Date(fromarrayNew2[0],montharr2,fromarrayNew2[2]);
			if(now2.getDate() < 10)
			{
				var fianl_date_temp2 = "0"+now2.getDate();
			}else{
				var fianl_date_temp2 = now2.getDate();
			}
			if(now2.getMonth() < 9)
			{
				var fianl_month_new2 = Number(now2.getMonth())+1;
				var fianl_month_temp2 = "0"+fianl_month_new2;
			}else{
				var fianl_month_new2 = Number(now2.getMonth())+1;
				var fianl_month_temp2 = fianl_month_new2;
			}
			var dateStringNew2 = now2.getDayName2()+" "+fianl_date_temp2+ "/" +fianl_month_temp2+ "/" + now2.getFullYear();
			//alert(dateString);
			//return false;
			var Div = "<div class='popupDate' id='popup-status'>"+dateStringNew+" to "+dateStringNew2+"<div class='popupDateInn'><a style='cursor:pointer;' onclick='javascript:availablecheck(1,"+property_id+");'><img src='../beachLetsImages/booked.jpg' alt='' border='0' /></a> <a style='cursor:pointer;' onclick='javascript:availablecheck(2,"+property_id+");'><img src='../beachLetsImages/available.jpg' alt='' width='74' height='23' border='0'  /></a><input type='text' name='availability_text' id='availability_text' maxlength='20'></div> </div>";
 			Tip(Div, FADEIN, 500, FADEOUT, 500,BORDERWIDTH,'0',FOLLOWMOUSE,true,ABOVE,true,STICKY, true);
			document.getElementById("choosen_date").value = final_date;
			/*if (browserName=="Microsoft Internet Explorer")	{
			   document.getElementById(date).setAttribute('className', '');
			} else {
				document.getElementById(date).setAttribute('class', '');	
			}*/
		}else {
			/*if (browserName=="Microsoft Internet Explorer")	{
			   document.getElementById(date).setAttribute('className', '');
			} else {
				document.getElementById(date).setAttribute('class', '');	
			}*/
			document.getElementById("choosen_date").value = "";
		}
		//document.getElementById(link_date).style.border = "";
		//alert(final_date);
		//alert(date);
	}
	
}
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
function defaultfocus()
{
	document.frmlogin.txtusername.focus();
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function availablecheck(type,id)
{
	//alert("insert");
	//return false;
	//alert(document.getElementById("booking_date").value);
	if(document.getElementById("availability_text").value!="")
	{
		if(SpecialValidate2(document.getElementById("availability_text"),"special characters") == false){return false;}	
 	}
	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 year = ;	
		//alert(year);
		var url = 'availablecheck.php?date='+document.getElementById("choosen_date").value+"&type="+type+"&property_id="+id+"&text="+document.getElementById("availability_text").value;
		//alert(url);
 		//return false;
 		//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() {
			//alert(xmlhttp.readyState);			
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					//alert(xmlhttp.responseText);
 					tt_HideInit();
 					var response     = xmlhttp.responseText;
					//alert(response);
					//return false;
					var response_temp = response.split("#");
					//alert(response_temp[2]);
					//alert(response_temp[1]);
					//alert(document.getElementById("choosen_date").value);
					//return false;
					var date_temp = document.getElementById("choosen_date").value.split(",");
					//alert(date_temp[0]);
					//alert(date_temp[1]);
					var link_date1 = "link"+date_temp[0];
					var link_date2 = "link"+date_temp[1];
					var year1_temp = date_temp[0].split("-");
					var year2_temp = date_temp[1].split("-");
					//alert(date_temp[0]);
					//alert(date_temp[1]);
					//return false;
					//var object1 = document.frmproperty.link_date1;
					//var object2 = document.frmproperty.link_date2;
					if(year1_temp[0] == year2_temp[0]){
						document.getElementById(link_date1).style.border = "1px solid #D8D8D8";	
						document.getElementById(link_date2).style.border = "1px solid #D8D8D8";
					}else{
						//document.getElementById(link_date1).style.border = "1px solid #D8D8D8";	
						document.getElementById(link_date2).style.border = "1px solid #D8D8D8";
					}
					document.getElementById("choosen_date").value = "";
					document.getElementById("availability_text").value = "";
					document.getElementById("curyear_hidden").value = response_temp[2];
					document.getElementById("prevyear_hidden").value = Number(response_temp[2]-1);
					document.getElementById("nextyear_hidden").value = Number(response_temp[2]+1);	
					document.getElementById("availability_count").value = Number(response_temp[4]);
					//alert(response_temp[3]);
					//return false;
					//alert("0");
					//alert(document.getElementById("curyear_hidden").value);
					//alert(document.getElementById("prevyear_hidden").value);
					//alert(document.getElementById("nextyear_hidden").value);
					//alert(document.getElementById("availability_count").value);
					//return false;
					if(trim(response_temp[0])=="0") {						
						alert(response_temp[3]);
					}else{
						//alert("inside else");
						//alert(response_temp[2]);
						//alert(response_temp[1]);
						changeyear2(response_temp[2],response_temp[1]);		
					}
					
					
			}
		}
		xmlhttp.send(null);  
}
function changeyear2(year,property_id) {
	//alert(year);
	//alert(property_id);
	var year = year;
 	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 url = 'changeyear2.php?year='+year+'&property_id='+property_id+"&r="+ Math.random();	
		//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;
					//alert(type);calender_content_new				
					document.getElementById("calender_content").innerHTML = response;		
					//if(type == "next")
					//{
						document.getElementById("nextyear").innerHTML = Number(year)+1;
						document.getElementById("prevyear").innerHTML = Number(year)-1;
					//}
					/*if(type == "prev")
					{
						document.getElementById("prevyear").innerHTML = Number(document.getElementById("prevyear").innerHTML)-1;
						document.getElementById("nextyear").innerHTML = Number(document.getElementById("nextyear").innerHTML)-1;
					}*/
								
 			}
		}
		//window.location.href = "updateAvailability.php?property_action=process&property_id="+property_id;
		xmlhttp.send(null);  
}
function availabilityPagevalidate()
{
	/*if(document.frmproperty.availability_count.value == 0)
	{
		if(confirm("You have not completed all the necessary fields. Press OK to save anyway and return later or cancel to complete them now"))
		{
			document.frmproperty.action = "updateAvailability.php";
			document.frmproperty.submit();
		}	
	}else{
		document.frmproperty.action = "updateAvailability.php";
		document.frmproperty.submit();
	}*/
	document.frmproperty.action = "updateAvailability.php";
	document.frmproperty.submit();
}
function ImagePageValidate(id)
{
 	if(document.frmproperty.image_count.value < 3 || document.frmproperty.summaryimage_count.value == 0)
	{
		if(confirm("You have not completed all the necessary fields. Press OK to save anyway and return later or cancel to complete them now"))
		{
			window.location.href = "editProperty.php?property_id="+id;
		}	
	}else{
		window.location.href = "editProperty.php?property_id="+id;
	}
}
function ImageValidate(field_name,order,property_id,loader)
{
		if(document.getElementById(field_name).value == "")
		{
			alert("Please browse an image");
			document.getElementById(field_name).focus();
			return false;
		}
		if(document.getElementById(field_name).value!=""){
			var file_type = document.getElementById(field_name).value.split(".");
			var final = file_type.length;
			if(file_type[final-1]!="jpg" && file_type[final-1]!="gif" && file_type[final-1]!="jpeg" && file_type[final-1]!="JPG" && file_type[final-1]!="GIF")
			{
				alert("Please upload JPEG or GIF images");
				return false;
			}
		}			
			document.frmproperty.action = "addUpdatePhotos.php?action_type=single&field_name="+field_name+"&order="+order+"&property_id="+property_id;
			document.frmproperty.submit();
			var loadername = "loader"+loader;
 			var nonloadername = "nonloader"+loader;
			document.getElementById(nonloadername).style.display = "none";
 			document.getElementById(loadername).style.display = "";			
}
function ImageDelete(id,loader,field_name)
{
	//alert(id);
	var id = id;
	var field_name = field_name;
	if(confirm("Are you sure you want to delete the image?")){
		document.frmproperty.action = "addUpdatePhotos.php?action_type=delete&image_id="+id+"&field_name="+field_name;
		//alert(document.frmproperty.action);
		//return false;
		document.frmproperty.submit();
		//var loadername = "loaderdelete"+loader;
		//var nonloadername = "nonloader"+loader;
		//document.getElementById(nonloadername).style.display = "none";
		//document.getElementById(loadername).style.display = "";
	}
}
function EditProperty(id)
{
	window.location.href = "editProperty.php?property_id="+id;
}
function AddRate(property_id,status,active)
{
	//alert(status);
	//return false;
	if(active == 0)
	{
		alert("You can add special offer only if your property is live");
		popup1 = new Epoch('popup1','popup',document.getElementById('period_firstnight'),false);
		popup2 = new Epoch('popup2','popup',document.getElementById('period_lastnight'),false);
		splofferpopup1 = new Epoch('splofferpopup1','popup',document.getElementById('offer_firstnight'),false);
		splofferpopup2 = new Epoch('splofferpopup2','popup',document.getElementById('offer_lastnight'),false);
		return false;
	}
	
	if(trim(document.frmproperty.property_currency.value) == "")
	{
		alert("Please select the currency");	
		document.frmproperty.property_currency.focus();
		return false;
	}
	if(trim(document.frmproperty.period_minstay.value) == "")
	{
		alert("Please select the Min stay");	
		document.frmproperty.period_minstay.focus();
		return false;
	}	
	if(trim(document.frmproperty.period_name.value) != "")
	{
		if(QuoteValidate(document.getElementById("period_name"),"period name field") == false){return false;}
	}
	/*if(trim(document.frmproperty.period_name.value) == "")
	{
		alert("Please enter the Period name");	
		document.frmproperty.period_name.focus();
		return false;
	}*/
	if(trim(document.frmproperty.period_firstnight.value) == "")
	{
		alert("Please select the First Night");	
		document.frmproperty.period_firstnight.focus();
		return false;
	}
	if(trim(document.frmproperty.period_lastnight.value) == "")
	{
		alert("Please select the Last Night");	
		document.frmproperty.period_lastnight.focus();
		return false;
	}
	if(document.frmproperty.period_firstnight.value!="" && document.frmproperty.period_lastnight.value!="")
	{
			
		
	if(ComparedatePrevoiusEnquiry(document.frmproperty.period_firstnight,document.frmproperty.period_lastnight)==false) { return false;	}
	}
	/*if(trim(document.frmproperty.period_weeklyrate.value) == "")
	{
		alert("Please enter the Week Rate");	
		document.frmproperty.period_weeklyrate.focus();
		return false;
	}
	if(trim(document.frmproperty.period_weeklyrate.value) == 0)
	{
		alert("Please enter the Week Rate");	
		document.frmproperty.period_weeklyrate.focus();
		return false;
	}
	if(AlphaValidate(document.getElementById("period_weeklyrate"),"alphabets or special characters") == false){return false;}
	if(DecimalValidate(document.getElementById("period_weeklyrate"),"decimal points for Week Rate") == false){return false;}
	if(trim(document.frmproperty.period_nightlyrate.value) == "")
	{
		alert("Please enter the Night Rate");	
		document.frmproperty.period_nightlyrate.focus();
		return false;
	}
	if(trim(document.frmproperty.period_nightlyrate.value) == 0)
	{
		alert("Please enter the Night Rate");	
		document.frmproperty.period_nightlyrate.focus();
		return false;
	}
	if(AlphaValidate(document.getElementById("period_nightlyrate"),"alphabets or special characters") == false){return false;}
	if(DecimalValidate(document.getElementById("period_nightlyrate"),"decimal points for Night Rate") == false){return false;}*/
	//alert(document.frmproperty.period_weeklyrate.value);
	if(document.frmproperty.period_minstay.value == "1 week" || document.frmproperty.period_minstay.value == "2 weeks" || document.frmproperty.period_minstay.value == "3 weeks"){
		if(trim(document.frmproperty.period_weeklyrate.value) == "")
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.period_weeklyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.period_weeklyrate.value) == 0)
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.period_weeklyrate.focus();
			return false;
		}
		//Please don’t enter decimal points for Week Rate
		if(AlphaValidate(document.getElementById("period_weeklyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("period_weeklyrate"),"decimal points for Week Rate") == false){return false;}
		if(trim(document.frmproperty.period_nightlyrate.value) != "")
		{
			if(trim(document.frmproperty.period_nightlyrate.value) == 0)
			{
				alert("Please enter the Night Rate");	
				document.frmproperty.period_nightlyrate.focus();
				return false;
			}
			if(AlphaValidate(document.getElementById("period_nightlyrate"),"alphabets or special characters") == false){return false;}
			if(DecimalValidate(document.getElementById("period_nightlyrate"),"decimal points for Night Rate") == false){return false;}
		}
	}
	if(document.frmproperty.period_minstay.value == "1 night" || document.frmproperty.period_minstay.value == "2 nights" || document.frmproperty.period_minstay.value == "3 nights" || document.frmproperty.period_minstay.value == "4 nights" || document.frmproperty.period_minstay.value == "5 nights" || document.frmproperty.period_minstay.value == "6 nights"){
		if(trim(document.frmproperty.period_nightlyrate.value) == "")
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.period_nightlyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.period_nightlyrate.value) == 0)
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.period_nightlyrate.focus();
			return false;
		}
		if(AlphaValidate(document.getElementById("period_nightlyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("period_nightlyrate"),"decimal points for Night Rate") == false){return false;}
		if(trim(document.frmproperty.period_weeklyrate.value) == "")
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.period_weeklyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.period_weeklyrate.value) == 0)
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.period_weeklyrate.focus();
			return false;
		}
		//Please don’t enter decimal points for Week Rate
		if(AlphaValidate(document.getElementById("period_weeklyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("period_weeklyrate"),"decimal points for Week Rate") == false){return false;}
	}
	if(document.frmproperty.period_minstay.value == "Flexible"){
		if(trim(document.frmproperty.period_weeklyrate.value) == "")
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.period_weeklyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.period_weeklyrate.value) == 0)
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.period_weeklyrate.focus();
			return false;
		}
		if(AlphaValidate(document.getElementById("period_weeklyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("period_weeklyrate"),"decimal points for Week Rate") == false){return false;}
		if(trim(document.frmproperty.period_nightlyrate.value) == "")
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.period_nightlyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.period_nightlyrate.value) == 0)
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.period_nightlyrate.focus();
			return false;
		}
		if(AlphaValidate(document.getElementById("period_nightlyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("period_nightlyrate"),"decimal points for Night Rate") == false){return false;}
	}
	var xmlhttp = false;
 	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
	}
	// 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 period_name = document.getElementById("period_name").value;
		var period_firstnight = document.getElementById("period_firstnight").value;
		if(period_firstnight!=""){
			var period_firstnight_temp = period_firstnight.split("/");
			//alert(period_firstnight_temp[2]);
			//alert(period_firstnight_temp[0]);
			//alert(period_firstnight_temp[1]);
			//return false;
			var period_firstnight_final = period_firstnight_temp[2]+"-"+period_firstnight_temp[1]+"-"+period_firstnight_temp[0];
		}else{
			var period_firstnight_final = "";
		}
		//alert(period_firstnight_final);
		//return false;
 		var period_lastnight = document.getElementById("period_lastnight").value;		
		if(period_lastnight!=""){
			var period_lastnight_temp = period_lastnight.split("/");
			var period_lastnight_final = period_lastnight_temp[2]+"-"+period_lastnight_temp[1]+"-"+period_lastnight_temp[0];
			var period_lastnight_next = new Date(period_lastnight_temp[2],period_lastnight_temp[1]-1,period_lastnight_temp[0]);			
			var period_nextnight = new Date(period_lastnight_next.getFullYear(),period_lastnight_next.getMonth(),period_lastnight_next.getDate()+1);
			var period_nextnight_final = period_nextnight.getDate()+"/"+(parseInt(period_nextnight.getMonth())+1)+"/"+period_nextnight.getFullYear();			
		}else{
			var period_lastnight_final = "";
		}
 		var period_weeklyrate = document.getElementById("period_weeklyrate").value;
		var period_nightlyrate = document.getElementById("period_nightlyrate").value;
		var property_currency = document.getElementById("property_currency").value;
		var period_minstay = document.getElementById("period_minstay").value;
 		var url = "rental-process.php?status="+status+"&property_id="+property_id+"&period_name="+period_name+"&period_firstnight="+period_firstnight_final+"&period_lastnight="+period_lastnight_final+"&period_weeklyrate="+period_weeklyrate+"&period_nightlyrate="+period_nightlyrate+"&period_minstay="+period_minstay+"&property_currency="+property_currency+"&period_id="+document.getElementById("period_hidden_id").value;	
  		//alert(url);
		//return false;
		//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_final = response.split("@");
				//alert(response_final[4]);
				//alert(response_final[0]);
				//alert(response_final[1]);
				if(response_final[4] == 0)
				{
					alert("You have already added rates for this date range");
					splofferpopup1 = new Epoch('splofferpopup1','popup',document.getElementById('offer_firstnight'),false);
					splofferpopup2 = new Epoch('splofferpopup2','popup',document.getElementById('offer_lastnight'),false);	
					date_duplicate_count++;
					if(last_period_lastnight !="" ){
						changefocus("newfunction",last_period_lastnight);						
					}else{
						popup1 = new Epoch('popup1','popup',document.getElementById('period_firstnight'),false);
						popup2 = new Epoch('popup2','popup',document.getElementById('period_lastnight'),false);					
					}
				}				
 				document.getElementById('rental_display').innerHTML = response_final[0];		
 				document.getElementById("rate_count").value = response_final[1];
				document.getElementById("affected_rows").value = response_final[2];
				document.getElementById("period_name").value = "";
				document.getElementById("period_firstnight").value = "";
				document.getElementById("period_lastnight").value = "";
				document.getElementById("period_weeklyrate").value = "";
				document.getElementById("period_nightlyrate").value = "";
				//document.getElementById("property_currency").value = "";offer_update_area
				document.getElementById("period_minstay").value = "";
				document.getElementById("period_hidden_id").value = "";
				document.getElementById("edit_option").style.display = "none";
				document.getElementById("add_option").style.display = "";
				//document.getElementById("offer_update_area").style.display = "none";
				//document.getElementById("offer_insert_area").style.display = "";
				splofferpopup1 = new Epoch('splofferpopup1','popup',document.getElementById('offer_firstnight'),false);
				splofferpopup2 = new Epoch('splofferpopup2','popup',document.getElementById('offer_lastnight'),false);
				
				if(response_final[4]!=0){
					//alert(period_lastnight);
					changefocus("newfunction",period_nextnight_final);
				}
				//alert(date_duplicate_count);
				if(date_duplicate_count == 0){
					last_period_lastnight = period_nextnight_final;
				}
				//popup1 = new Epoch('popup1','popup',document.getElementById('period_firstnight'),false);
				//popup2 = new Epoch('popup2','popup',document.getElementById('period_lastnight'),false);
  			}
		}
		xmlhttp.send(null);			
		popup1.tgt.dateObj = new Date();				
		popup2.tgt.dateObj = popup1.tgt.dateObj;					
	}
	
function dateswap(){
	popup2.tgt.dateObj = popup1.tgt.dateObj;
	popup2.setTarget(document.getElementById('period_lastnight'));	
}


function deleterental(id,property_id,offer)
{	
	
	var xmlHttp = false;
	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlHttp = new XMLHttpRequest();
	}
	// 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 
		document.getElementById("period_hidden_id").value = "";
		document.getElementById("edit_option").style.display = "none";
		document.getElementById("add_option").style.display = "";
		var url = "rental-processDelete.php?status=delete&period_id="+id+"&property_id="+property_id+"&offer="+offer;
	
 			//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);					
 					if(trim(response) == "success")
					{
						if(confirm("Are you sure you want to delete the period?"))
						{
								var xmlhttp = false;
								if (window.XMLHttpRequest) {
										//Intiate the object
										xmlhttp = new XMLHttpRequest();
								}
								// 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 
									document.getElementById("period_hidden_id").value = "";
									document.getElementById("edit_option").style.display = "none";
									document.getElementById("add_option").style.display = "";
									var url = "rental-process.php?status=delete&period_id="+id+"&property_id="+property_id+"&offer="+offer;	
									//alert(url);
									//return false;
									//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_final = response.split("@");
											//alert(response_final[0]);
											//alert(response_final[1]);
											//alert(trim(response_final[0]));
											//return false;
											if(trim(response_final[0]) == "error")
											{
												alert("You must have at least one 'rate period' active whilst your advert is live");
												return false;
											}
											document.getElementById('rental_display').innerHTML = response_final[0];		
											document.getElementById("rate_count").value = response_final[1];
											document.getElementById("affected_rows").value = response_final[2];
											//alert(response_final[3]);
											document.getElementById("offer_count").value = response_final[3];
											//document.getElementById("period_name").value = "";
											document.getElementById("period_firstnight").value = "";
											document.getElementById("period_lastnight").value = "";
											document.getElementById("period_weeklyrate").value = "";
											document.getElementById("period_nightlyrate").value = "";
											//document.getElementById("property_currency").value = "";
											document.getElementById("period_minstay").value = "";
											popup1 = new Epoch('popup1','popup',document.getElementById('period_firstnight'),false);
											popup2 = new Epoch('popup2','popup',document.getElementById('period_lastnight'),false);
											splofferpopup1 = new Epoch('splofferpopup1','popup',document.getElementById('offer_firstnight'),false);
											splofferpopup2 = new Epoch('splofferpopup2','popup',document.getElementById('offer_lastnight'),false);
										}
									}
								xmlhttp.send(null);  
						     }
					}else{
						//Else part comes here
						alert("You must have at least one 'rate period' active whilst your advert is live");
						return false;
 					}					
				}
			}
		xmlHttp.send(null);  
 }
function EditRate(period_id,special_offer,property_id)
{
	var period_id = period_id;
	var property_id = property_id;
	var special_offer = special_offer;
 	var xmlhttp = false;
	//alert(special_offer);
	// If the user is using Mozilla/Firefox/Safari/etc	
	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
	}
	// 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 
	if(special_offer == 1){
		document.getElementById("offer_update_area").style.display = "";
		document.getElementById("offer_insert_area").style.display = "none";
	}else{
		document.getElementById("edit_option").style.display = "";
		document.getElementById("add_option").style.display = "none";
	}
		//alert(period_id);
		document.getElementById("period_hidden_id").value = period_id;
		var url = 'rentaldisplay-process.php?period_id='+period_id+'&specialoffer='+special_offer;	
		//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;	
				var response_array = response.split("#");
				//alert(response);
				//return false;
				if(special_offer == 1){
					document.getElementById("offer_name").value = response_array[0];
					var first_night = response_array[1].split("-");
					var firstnight_final = first_night[2]+"/"+first_night[1]+"/"+first_night[0];
					document.getElementById("offer_firstnight").value = firstnight_final;
					var last_night = response_array[2].split("-");
					var lastnight_final = last_night[2]+"/"+last_night[1]+"/"+last_night[0];
					document.getElementById("offer_lastnight").value = lastnight_final;
 					document.getElementById("property_currency").value = response_array[3];
					document.getElementById("offer_weeklyrate").value = response_array[4];
					document.getElementById("offer_nightlyrate").value = response_array[5];
					document.getElementById("offer_minstay").value = response_array[6];
				}else{
					document.getElementById("period_name").value = response_array[0];
					var first_night = response_array[1].split("-");
					var firstnight_final = first_night[2]+"/"+first_night[1]+"/"+first_night[0];					
					document.getElementById("period_firstnight").value = firstnight_final;
					var last_night = response_array[2].split("-");
					var lastnight_final = last_night[2]+"/"+last_night[1]+"/"+last_night[0];
					document.getElementById("period_lastnight").value = lastnight_final;
					document.getElementById("property_currency").value = response_array[3];
					document.getElementById("period_weeklyrate").value = response_array[4];
					document.getElementById("period_nightlyrate").value = response_array[5];
					document.getElementById("period_minstay").value = response_array[6];
				}
   			}
		}
		xmlhttp.send(null);  
		
}
function ClearValue_email(field, strCheck)
{
	if(field.value == strCheck)
	field.value = "";
	//alert(field.value);
}
/*function CountLetter()
{
	var length = document.getElementById("property_summary").value.length;	
	if(length > 200){
		alert("The maximum is 200 characters");
		//document.getElementById("property_summary").value = "";
		document.getElementById("property_summary").focus();
		return false;
	}
}*/
function Repopulate_email(field, strCheck)
{
	//alert(document.getElementById("country_new").value);
	if(field.value == "")
	field.value = strCheck;
	//alert(field.value);
}
function GooglemapDisplay()
{
	var country_value = document.getElementById("country_new").value;
	var region_value = document.getElementById("region_new").value;
	var subregion_value = document.getElementById("subregion_new").value;
	var town_value = document.getElementById("town_new").value;
	if(country_value!="Enter Country" && country_value!="")
	{
		document.getElementById("address_country").value = country_value;
	}else{
		document.getElementById("address_country").value = "";
	}
	if(region_value!="Enter Region" && region_value!="")
	{
		document.getElementById("address_region").value = region_value;
	}else{
		document.getElementById("address_region").value = "";
	}
	if(subregion_value!="Enter Sub Region" && subregion_value!="")
	{
		document.getElementById("address_subregion").value = subregion_value;
	}else{
		document.getElementById("address_subregion").value = "";
	}
	if(town_value!="Enter Town" && town_value!="")
	{
		document.getElementById("address_town").value = town_value;
	}else{
		document.getElementById("address_town").value = "";
	}
	
	if(document.getElementById("address_country").value!="")
	{
			
	}
		showAddress(document.getElementById("address_country").value)
}
/*function MapRegion()
{
	var region_value = document.getElementById("region_new").value;
	if(region_value!="Enter Region")
	{
		if(document.getElementById("address").value == "")
		{
			document.getElementById("address").value = region_value;
		}else{
			document.getElementById("address").value = document.getElementById("address").value+","+region_value;
		}
		showAddress(document.getElementById("address").value)
	}
	//alert(document.getElementById("country_new").value);
	//showAddress(document.getElementById("country_new").value)
}
function MapSubregion()
{
	var subregion_value = document.getElementById("subregion_new").value;
	if(subregion_value!="Enter Sub Region")
	{
		if(document.getElementById("address").value == "")
		{
			document.getElementById("address").value = subregion_value;
		}else{
			document.getElementById("address").value = document.getElementById("address").value+","+subregion_value;
		}
		showAddress(document.getElementById("address").value)
	}
	//alert(document.getElementById("country_new").value);
	//showAddress(document.getElementById("country_new").value)
}
function MapTown()
{
	var town_value = document.getElementById("town_new").value;
	if(town_value!="Enter Town")
	{
		if(document.getElementById("address").value == "")
		{
			document.getElementById("address").value = town_value;
		}else{
			document.getElementById("address").value = document.getElementById("address").value+","+town_value;
		}
		showAddress(document.getElementById("address").value)
	}
	//alert(document.getElementById("country_new").value);
	//showAddress(document.getElementById("country_new").value)
}*/

function RatePageValidate(id)
{
	if(document.frmproperty.rate_count.value == 0)
	{
		if(confirm("You have not completed all the necessary fields. Press OK to save anyway and return later or cancel to complete them now"))
		{
			//window.location.href="editProperty.php?property_id="+id;		
			document.frmproperty.action = "rentalPeriodRates.php";
			document.frmproperty.submit();
		}
	}else{
			document.frmproperty.action = "rentalPeriodRates.php";
			document.frmproperty.submit();
	}
}
function AddBasket(property_id)
{
	document.frmproperty.action = "advertManager.php?status=addnew&property_id="+property_id;
	document.frmproperty.submit();
}
function Readvertise(property_id)
{
	document.frmproperty.action = "advertManager.php?status=readvertise&property_id="+property_id;
	document.frmproperty.submit();
}

function AddFeatured(property_id)
{
	document.frmproperty.action = "advertManager.php?status=featured&property_id="+property_id;
	document.frmproperty.submit();
}
function AddOffer(property_id)
{
	document.frmproperty.action = "rentalPeriodRates.php?property_action=process&property_id="+property_id;
	document.frmproperty.submit();
}

function RemoveBasket(basket_id,agent_id,code1,code2,code3)
{
	if(confirm("Are you sure you want to remove this item from your basket?"))
	{
		deletebasket(basket_id,agent_id,code1,code2,code3);
	}
}
function RemoveBasket2(property_id)
{
	if(confirm("Are you sure you want to remove this item from your basket?"))
	{
		deletebasket2(property_id,agent_id);
	}
}
function deletebasket(basket_id,agent_id,code1,code2,code3)
{
	
 	var basket_id = basket_id;
	var agent_id = agent_id;
 	var xmlhttp = false;
	//alert(id);
	// If the user is using Mozilla/Firefox/Safari/etc	
	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
	}
	// 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 url = 'checkoutprocess.php?basket_id='+basket_id+'&status=delete&agent_id='+agent_id+'&code1='+code1+'&code2='+code2+'&code3='+code3;	
		//alert(url);
	//	return false;
 		//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;	
				var response_final = response.split("@");
				//alert(response_final[0]);
				
				//alert(response_final[1]);
				//alert(response_final[2]);
				//alert(response_final[3]);
				//return false;
				document.getElementById("basket_display").innerHTML = response_final[0];
				document.getElementById("item_name").value = response_final[1];
				//alert(response_final[2]);
				//return false;
				document.getElementById("item_number").value = response_final[2];
				document.getElementById("amount").value = response_final[3];
				//document.getElementById("total_hidden").value = response_final[4];
				//alert(document.getElementById("amount").value);
	  		}
		}
		xmlhttp.send(null);  
}
function deletebasket2(property_id,agent_id)
{
	var property_id = property_id;
  	var xmlhttp = false;
	//alert(id);
	// If the user is using Mozilla/Firefox/Safari/etc	
	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
	}
	// 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 url = 'advertprocess.php?status=delete&property_id='+property_id+'&agent_id='+agent_id;
	//	alert(url);
		//return false;
 		//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("advert_display").innerHTML = response;
	  		}
		}
		xmlhttp.send(null);  
}

function Checkout()
{
    //alert(document.getElementById("amount").value);
	//return false;
	if(Number(document.getElementById("amount").value) > 0){
		//alert("paypal");
		//return false;
		document.frmproperty.action = "https://www.paypal.com/cgi-bin/webscr";
		document.frmproperty.submit();
	}else{
		//alert("normal");
		//return false;
  		document.frmproperty.action = "voucher-process.php?st=Completed";
		document.frmproperty.submit();
	}
}
function Checkoutbasket()
{
	window.location.href = "checkOut.php";	
}
function FinishAdvert(property_id)
{
	window.location.href="editProperty.php?property_id="+property_id;
}
function DeleteAdvert(property_id)
{
	if(confirm("Are you sure you want to delete the Property?")){
		window.location.href="advertManager.php?status=delete&property_id="+property_id;
	}
}
function Clearalldates(year,property_id)
{
	if(confirm("Are you sure you want to clear all the dates in this year?")){
			var year = year;
			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 year = ;	
				//alert(year);
				var property_id = document.getElementById("property_id").value;
				var url = 'cleardates.php?status=clear&property_id='+property_id+'&year='+year+"&r="+ Math.random();		
				//alert(url);
				//return false;
				//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() {
					//alert(xmlhttp.readyState);
					if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						//Replace the content of the "result" DIV with the result returned by the PHP script
							//alert(xmlhttp.responseText);
							var response     = xmlhttp.responseText;
							var response_final = response.split("@");
							//alert(response);
							//return false;
							//alert(type);calender_content_new				
							document.getElementById("curyear_hidden").value = year;
							document.getElementById("availability_count").value = response_final[1];
							document.getElementById("calender_content").innerHTML = response_final[0];							
							document.getElementById("nextyear").innerHTML = Number(year)+1;
							document.getElementById("prevyear").innerHTML = Number(year)-1;
										
					}
				}
				xmlhttp.send(null);  
	}	
}
function switchCheckbox( objChecked, objUnchecked )
{
	objChecked.checked = true;
	objUnchecked.checked = false;
	
	if ( objChecked.checked = true )
	{
		objUnchecked.checked = false;
		
	} else if ( objChecked.checked = false )
	{
		objUnchecked.checked = true;
	}
}
function Rentalchildren(flag)
{
	for(var i=1;i<=3;i++)
	{
		if(i == flag)
		{
			document.getElementById("rental_children_"+i).checked = true;
			document.getElementById("rental_children_hidden").value = document.getElementById("rental_children_"+i).value;
		}else{
			document.getElementById("rental_children_"+i).checked = false;
		}
	}
}
function Rentalelder(flag)
{
	for(var i=1;i<=3;i++)
	{
		if(i == flag)
		{
			document.getElementById("rental_elderly_"+i).checked = true;
			document.getElementById("rental_elderly_hidden").value = document.getElementById("rental_elderly_"+i).value;
		}else{
			document.getElementById("rental_elderly_"+i).checked = false;
		}
	}
}
function Rentalsmoking(flag)
{
	for(var i=1;i<=3;i++)
	{
		if(i == flag)
		{
			document.getElementById("rental_smoking_"+i).checked = true;
			document.getElementById("rental_smoking_hidden").value = document.getElementById("rental_smoking_"+i).value;
		}else{
			document.getElementById("rental_smoking_"+i).checked = false;
		}
	}
}
function Rentalpets(flag)
{
	for(var i=1;i<=3;i++)
	{
		if(i == flag)
		{
			document.getElementById("rental_pets_"+i).checked = true;
			document.getElementById("rental_pets_hidden").value = document.getElementById("rental_pets_"+i).value;
		}else{
			document.getElementById("rental_pets_"+i).checked = false;
		}
	}
}
function Rentalwheel(flag)
{
	for(var i=1;i<=2;i++)
	{
		if(i == flag)
		{
			document.getElementById("rental_wheelchair_"+i).checked = true;
			document.getElementById("rental_wheelchair_hidden").value = document.getElementById("rental_wheelchair_"+i).value;
		}else{
			document.getElementById("rental_wheelchair_"+i).checked = false;
		}
	}
}
function Rentalconsider()
{
	if(document.getElementById("rental_consider_longterm").checked == true)
	{
		document.getElementById("rental_consider_longterm_hidden").value = 1;
	}else{
		document.getElementById("rental_consider_longterm_hidden").value = 0;
	}
		if(document.getElementById("rental_consider_shortterm").checked == true)
	{
		document.getElementById("rental_consider_shortterm_hidden").value = 1;
	}else{
		document.getElementById("rental_consider_shortterm_hidden").value = 0;
	}

}
function Addoffer(property_id,status,active)
{
	//alert(status);
	//return false;
	//alert(count);
	count = document.getElementById("offer_count").value;
	if(active == 0)
	{
		alert("Sorry, you can only add a special offer once your advert is activated");
		popup1 = new Epoch('popup1','popup',document.getElementById('period_firstnight'),false);
		popup2 = new Epoch('popup2','popup',document.getElementById('period_lastnight'),false);
		splofferpopup1 = new Epoch('splofferpopup1','popup',document.getElementById('offer_firstnight'),false);
		splofferpopup2 = new Epoch('splofferpopup2','popup',document.getElementById('offer_lastnight'),false);
		document.getElementById("offer_firstnight").value = "";
		document.getElementById("offer_lastnight").value = "";
		document.getElementById("offer_weeklyrate").value = "";
		document.getElementById("offer_nightlyrate").value = "";
 		document.getElementById("offer_minstay").value = "";
 		return false;
	}
	if(count == 1 && status == "insert")
	{
		alert("You can add one special offer per property")	;
		popup1 = new Epoch('popup1','popup',document.getElementById('period_firstnight'),false);
		popup2 = new Epoch('popup2','popup',document.getElementById('period_lastnight'),false);
		splofferpopup1 = new Epoch('splofferpopup1','popup',document.getElementById('offer_firstnight'),false);
		splofferpopup2 = new Epoch('splofferpopup2','popup',document.getElementById('offer_lastnight'),false);
		document.getElementById("offer_firstnight").value = "";
		document.getElementById("offer_lastnight").value = "";
		document.getElementById("offer_weeklyrate").value = "";
		document.getElementById("offer_nightlyrate").value = "";
		//document.getElementById("property_currency").value = "";
		document.getElementById("offer_minstay").value = "";
		return false;
	}
	if(trim(document.frmproperty.property_currency.value) == "")
	{
		alert("Please select the currency");	
		document.frmproperty.property_currency.focus();
		return false;
	}
	if(trim(document.frmproperty.offer_minstay.value) == "")
	{
		alert("Please select the Min stay");	
		document.frmproperty.offer_minstay.focus();
		return false;
	}	
 	if(trim(document.frmproperty.offer_name.value) == "")
	{
		alert("Please enter the Period name");	
		document.frmproperty.offer_name.focus();
		return false;
	}
	if(trim(document.frmproperty.offer_firstnight.value) == "")
	{
		alert("Please select the First Night");	
		document.frmproperty.offer_firstnight.focus();
		return false;
	}
	if(trim(document.frmproperty.offer_lastnight.value) == "")
	{
		alert("Please select the Last Night");	
		document.frmproperty.offer_lastnight.focus();
		return false;
	}
	//var current_date = document.frmproperty.hidden_current_date.value;
	//alert(current_date);
	if(ComparedateSpecialofferdate(document.frmproperty.hidden_current_date,document.frmproperty.offer_firstnight)==false) { return false;}
	if(document.frmproperty.offer_firstnight.value!="" && document.frmproperty.offer_lastnight.value!="")
	{		
		if(ComparedatePrevoiusEnquiry(document.frmproperty.offer_firstnight,document.frmproperty.offer_lastnight)==false) { return false;}
	}
	if(document.frmproperty.offer_minstay.value == "1 week" || document.frmproperty.offer_minstay.value == "2 weeks" || document.frmproperty.offer_minstay.value == "3 weeks"){
		if(trim(document.frmproperty.offer_weeklyrate.value) == "")
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.offer_weeklyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.offer_weeklyrate.value) == 0)
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.offer_weeklyrate.focus();
			return false;
		}
		if(AlphaValidate(document.getElementById("offer_weeklyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("offer_weeklyrate"),"decimal points for Week Rate") == false){return false;}
		if(trim(document.frmproperty.offer_nightlyrate.value) != ""){
		if(trim(document.frmproperty.offer_nightlyrate.value) == 0)
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.offer_nightlyrate.focus();
			return false;
		}
			if(AlphaValidate(document.getElementById("offer_nightlyrate"),"alphabets or special characters") == false){return false;}
			if(DecimalValidate(document.getElementById("offer_nightlyrate"),"decimal points for Night Rate") == false){return false;}
		}
	}
	if(document.frmproperty.offer_minstay.value == "1 night" || document.frmproperty.offer_minstay.value == "2 nights" || document.frmproperty.offer_minstay.value == "3 nights" || document.frmproperty.offer_minstay.value == "4 nights" || document.frmproperty.offer_minstay.value == "5 nights" || document.frmproperty.offer_minstay.value == "6 nights"){
		if(trim(document.frmproperty.offer_nightlyrate.value) == "")
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.offer_nightlyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.offer_nightlyrate.value) == 0)
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.offer_nightlyrate.focus();
			return false;
		}
		//alert(document.frmproperty.offer_nightlyrate.value);
		//return false;
		if(AlphaValidate(document.getElementById("offer_nightlyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("offer_nightlyrate"),"decimal points for Night Rate") == false){return false;}
		if(trim(document.frmproperty.offer_weeklyrate.value) == "")
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.offer_weeklyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.offer_weeklyrate.value) == 0)
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.offer_weeklyrate.focus();
			return false;
		}
		if(AlphaValidate(document.getElementById("offer_weeklyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("offer_weeklyrate"),"decimal points for Week Rate") == false){return false;}
	}
	if(document.frmproperty.offer_minstay.value == "Flexible"){
		if(trim(document.frmproperty.offer_weeklyrate.value) == "")
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.offer_weeklyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.offer_weeklyrate.value) == 0)
		{
			alert("Please enter the Week Rate");	
			document.frmproperty.offer_weeklyrate.focus();
			return false;
		}
		if(AlphaValidate(document.getElementById("offer_weeklyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("offer_weeklyrate"),"decimal points for Week Rate") == false){return false;}
		if(trim(document.frmproperty.offer_nightlyrate.value) == "")
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.offer_nightlyrate.focus();
			return false;
		}
		if(trim(document.frmproperty.offer_nightlyrate.value) == 0)
		{
			alert("Please enter the Night Rate");	
			document.frmproperty.offer_nightlyrate.focus();
			return false;
		}
		if(AlphaValidate(document.getElementById("offer_nightlyrate"),"alphabets or special characters") == false){return false;}
		if(DecimalValidate(document.getElementById("offer_nightlyrate"),"decimal points for Night Rate") == false){return false;}
	}
	var xmlhttp = false;
 	if (window.XMLHttpRequest) {
			//Intiate the object
			xmlhttp = new XMLHttpRequest();
	}
	// 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 period_name = document.getElementById("offer_name").value;
		
		var period_firstnight = document.getElementById("offer_firstnight").value;
		if(period_firstnight!=""){
			var period_firstnight_temp = period_firstnight.split("/");
			var period_firstnight_final = period_firstnight_temp[2]+"-"+period_firstnight_temp[1]+"-"+period_firstnight_temp[0];
		}else{
			var period_firstnight_final = "";
		}
		
		var period_lastnight = document.getElementById("offer_lastnight").value;
		if(period_lastnight!=""){
			var period_lastnight_temp = period_lastnight.split("/");
			var period_lastnight_final = period_lastnight_temp[2]+"-"+period_lastnight_temp[1]+"-"+period_lastnight_temp[0];
		}else{
			var period_lastnight_final = "";
		}
		
		//alert(period_firstnight_final);
		//return false;
 		var period_weeklyrate = document.getElementById("offer_weeklyrate").value;
		var period_nightlyrate = document.getElementById("offer_nightlyrate").value;
		var property_currency = document.getElementById("property_currency").value;
		var period_minstay = document.getElementById("offer_minstay").value;
 		var url = "rental-process.php?offer=1&status="+status+"&property_id="+property_id+"&period_name="+period_name+"&period_firstnight="+period_firstnight_final+"&period_lastnight="+period_lastnight_final+"&period_weeklyrate="+period_weeklyrate+"&period_nightlyrate="+period_nightlyrate+"&period_minstay="+period_minstay+"&property_currency="+property_currency+"&period_id="+document.getElementById("period_hidden_id").value;	
  		//alert(url);
		//return false;
		//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_final = response.split("@");
				//alert(response_final[0]);
				//alert(response_final[1]);
				if(response_final[4] == 0)
				{
					alert("You have already added rates for this date range");
					popup1 = new Epoch('popup1','popup',document.getElementById('period_firstnight'),false);
					popup2 = new Epoch('popup2','popup',document.getElementById('period_lastnight'),false);
					splofferpopup1 = new Epoch('splofferpopup1','popup',document.getElementById('offer_firstnight'),false);
				}
 				document.getElementById('rental_display').innerHTML = response_final[0];		
 				document.getElementById("rate_count").value = response_final[1];
				document.getElementById("offer_count").value = response_final[3];
				//alert(response_final[3]);
				//document.getElementById("offer_name").value = "";
				document.getElementById("offer_firstnight").value = "";
				document.getElementById("offer_lastnight").value = "";
 				document.getElementById("offer_weeklyrate").value = "";
				document.getElementById("offer_nightlyrate").value = "";
				//document.getElementById("property_currency").value = "";
				document.getElementById("offer_minstay").value = "";
				document.getElementById("period_hidden_id").value = "";
				document.getElementById("offer_update_area").style.display = "none";
				document.getElementById("offer_insert_area").style.display = "";
				splofferpopup1 = new Epoch('splofferpopup1','popup',document.getElementById('offer_firstnight'),false);
				splofferpopup2 = new Epoch('splofferpopup2','popup',document.getElementById('offer_lastnight'),false);
  			}
		}
		xmlhttp.send(null); 		
}
function RemoveOffer(property_id)
{
	if(confirm("Are you sure you want to remove the offer for this property?"))
	{
		document.frmproperty.action = "advertManager.php?status=removeoffer&property_id="+property_id;
		document.frmproperty.submit();
	}
}
function validatePassword()
{
	if(trim(document.frmproperty.username.value) == "")
	{
		alert("Please enter your Username");
		document.frmproperty.username.focus();
		return false;		
	}
	document.frmproperty.action = "/forgot-password/?status=pass";
	document.frmproperty.submit();
}
function validatePasswordMember()
{
	if(trim(document.frmproperty.member_email.value) == "")
	{
		alert("Please enter your Email Address");
		document.frmproperty.member_email.focus();
		return false;		
	}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmproperty.member_email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");		
		document.frmproperty.member_email.focus();   	
		return false;		
	}	else if (!filter.test(document.frmproperty.member_email.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");
		document.frmproperty.member_email.focus();	   	
		document.frmproperty.member_email.select();
		return false;
	}
	document.frmproperty.action = "/forgot-password-member/?status=pass";
	document.frmproperty.submit();
}
function savemap()
{
	alert("The Current google map is saved");
	return false;
}
function validatemember(url)
{
	if(TextValidate(document.frmproperty.member_email,"the Email address")==false){ return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmproperty.member_email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");		
		document.frmproperty.member_email.focus();   	
		return false;		
	}	else if (!filter.test(document.frmproperty.member_email.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");
		document.frmproperty.member_email.focus();	   	
		document.frmproperty.member_email.select();
		return false;
	}
 	if(TextValidate(document.frmproperty.member_password,"the Password")==false){ return false;}
	document.frmproperty.action = url+"validatelogin_member.php";
	document.frmproperty.submit();
}
function ValidateRegisterMember(id)
{
	if(TextValidate(document.frmproperty.member_firstname,"the First Name")==false){ return false;}
	if(TextValidate(document.frmproperty.member_lastname,"the Last Name")==false){ return false;}
	if(TextValidate(document.frmproperty.member_email,"the Email address")==false){ return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmproperty.member_email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");		
		document.frmproperty.member_email.focus();   	
		return false;		
	}	else if (!filter.test(document.frmproperty.member_email.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");
		document.frmproperty.member_email.focus();	   	
		document.frmproperty.member_email.select();
		return false;
	}
 	if(TextValidate(document.frmproperty.member_password,"the Password")==false){ return false;}
	if(TextValidate(document.frmproperty.member_confirm_password,"the Confirm Password")==false){ return false;}
	if(document.frmproperty.member_password.value!="" && document.frmproperty.member_confirm_password.value!=""){
		if(document.frmproperty.member_password.value!=document.frmproperty.member_confirm_password.value)
		{
			alert("The Password and Confirmation password do not match");
			document.frmproperty.member_confirm_password.focus();
			return false;
		}
	}
	document.frmproperty.action = "/yourDetails.php?status=register&property_id="+id;
	document.frmproperty.submit();
}
function ShortlistNewsletter()
{
	if(document.frmproperty.member_newsletter.checked == true)
	{
		document.frmproperty.newsletter_hidden.value = 1;	
	}else{
		document.frmproperty.newsletter_hidden.value = 0;
	}
}
function ShortlistRememberme()
{
	if(document.frmproperty.member_rememberme.checked == true)
	{
		document.frmproperty.remember_hidden.value = 1;	
	}else{
		document.frmproperty.remember_hidden.value = 0;
	}
}
function LoginRemember()
{
	if(document.frmproperty.member_rememberme.checked == true)
	{
		document.frmproperty.remember_hidden.value = 1;	
	}else{
		document.frmproperty.remember_hidden.value = 0;
	}
}
function MailCopy()
{
	if(document.frmproperty.mail_copy.checked == true)
	{
		document.frmproperty.mailcopy_hidden.value = 1;	
	}else{
		document.frmproperty.mailcopy_hidden.value = 0;
	}
}
function Newslettersubscription()
{
	if(document.frmproperty.member_newsletter.checked == true)
	{
		document.frmproperty.member_newsletter_hidden.value = 1;	
	}else{
		document.frmproperty.member_newsletter_hidden.value = 0;
	}
}

function ShortlistRemoveTemp(id)
{
	//alert(id);
	//return false;
	if(confirm("Are you sure you want to remove the property?")){
		document.frmproperty.action = "?status=remove&property_id="+id;  // remove compare-villas.php for seo friendly url Abhishek Yadav 05-05-2010.
		document.frmproperty.submit();
	}
}
function RemoveShortlist(id)
{
	if(confirm("Are you sure you want to remove the property?")){
		document.frmproperty.action = "/yourShortlistLogged.php?status=delete&id="+id;
		document.frmproperty.submit();
	}
}
function SendEnquiry()
{
	if(TextValidate(document.frmproperty.member_name,"Your Name")==false){ return false;}
 	if(TextValidate(document.frmproperty.member_email2,"Your Email")==false){ return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmproperty.member_email2.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");		
		document.frmproperty.member_email2.focus();   	
		return false;		
	}	else if (!filter.test(document.frmproperty.member_email2.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");
		document.frmproperty.member_email2.focus();	   	
		document.frmproperty.member_email2.select();
		return false;
	}
	var count = document.getElementById("shortlist_count").value;
	var shortvalue= "";
	for(var i=1;i<=count;i++) {
		var id = "enquirybox"+i;
		if(document.getElementById(id).checked==true) {
			if(shortvalue=="") {
				shortvalue = document.getElementById(id).value;
			}else {
				shortvalue = shortvalue+","+document.getElementById(id).value;
			}	
			
		}
	}
	document.getElementById("enquiryselected_hidden").value = shortvalue;
	//alert(shortvalue);
	if(document.getElementById("enquiryselected_hidden").value == "")
	{
		alert("Your enquiry has not been sent. You need to select at least one property");
		return false;
	}
	if(document.frmproperty.mail_copy.checked == true)
	{
		document.frmproperty.mailcopy_hidden.value = 1;	
	}else{
		document.frmproperty.mailcopy_hidden.value = 0;
	}
 	if(document.frmproperty.member_newsletter.checked == true)
	{
		document.frmproperty.member_newsletter_hidden.value = 1;	
	}else{
		document.frmproperty.member_newsletter_hidden.value = 0;
	}
	document.frmproperty.action = "/compare-villas.php?status=email";
	document.frmproperty.submit();
}
function AdvertSendEnquiry(id)
{
	if(TextValidate(document.frmproperty.member_name,"Your Name")==false){ return false;}
 	if(TextValidate(document.frmproperty.member_email,"Your Email")==false){ return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmproperty.member_email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");		
		document.frmproperty.member_email.focus();   	
		return false;		
	}	else if (!filter.test(document.frmproperty.member_email.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");
		document.frmproperty.member_email.focus();	   	
		document.frmproperty.member_email.select();
		return false;
	}
	if(TextValidate(document.frmproperty.member_captcha,"the Code")==false){ return false;}
	if(document.frmproperty.mail_copy.checked == true)
	{
		document.frmproperty.mailcopy_hidden.value = 1;	
	}else{
		document.frmproperty.mailcopy_hidden.value = 0;
	}
 	if(document.frmproperty.member_newsletter.checked == true)
	{
		document.frmproperty.member_newsletter_hidden.value = 1;	
	}else{
		document.frmproperty.member_newsletter_hidden.value = 0;
	}
	document.frmproperty.action = "?status=email";
	document.frmproperty.submit();
}
function ValidateEnquiryShortlist()
{
	if(TextValidate(document.frmproperty.member_name,"Your Name")==false){ return false;}
 	if(TextValidate(document.frmproperty.member_email,"Your Email")==false){ return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmproperty.member_email.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");		
		document.frmproperty.member_email.focus();   	
		return false;		
	}	else if (!filter.test(document.frmproperty.member_email.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");
		document.frmproperty.member_email.focus();	   	
		document.frmproperty.member_email.select();
		return false;
	}
	var count = document.getElementById("shortlist_count").value;
	var shortvalue= "";
	for(var i=1;i<=count;i++) {
		var id = "enquirybox"+i;
		if(document.getElementById(id).checked==true) {
			if(shortvalue=="") {
				shortvalue = document.getElementById(id).value;
			}else {
				shortvalue = shortvalue+","+document.getElementById(id).value;
			}	
			
		}
	}
	document.getElementById("enquiryselected_hidden").value = shortvalue;
	//alert(shortvalue);
	if(document.getElementById("enquiryselected_hidden").value == "")
	{
		alert("Your enquiry has not been sent. You need to select at least one property");
		return false;
	}
	if(document.frmproperty.mail_copy.checked == true)
	{
		document.frmproperty.mailcopy_hidden.value = 1;	
	}else{
		document.frmproperty.mailcopy_hidden.value = 0;
	}
 	if(document.frmproperty.member_newsletter.checked == true)
	{
		document.frmproperty.member_newsletter_hidden.value = 1;	
	}else{
		document.frmproperty.member_newsletter_hidden.value = 0;
	}
	document.frmproperty.action = "/yourShortlistLogged.php?status=email";
	document.frmproperty.submit();
}
function changeyear_display(year,type,url_base) {
	//alert(year);

	var type = type;
	var year = year;
 	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 year = ;	
		//alert(year);
		var property_id = document.getElementById("property_id").value;
		var url = url_base+'advertDetails/changeyear-display.php?property_id='+property_id+'&type='+type+'&year='+year;		
	
 		//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() {
			//alert(xmlhttp.readyState);
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					//alert(xmlhttp.responseText);
					var response     = xmlhttp.responseText;	
					//alert(response);
					//return false;
					//alert(type);calender_content_new				
					document.getElementById("calender_display").innerHTML = response;		
					if(type == "next")
					{
						document.getElementById("nextyear").innerHTML = Number(year)+1;
						document.getElementById("prevyear").innerHTML = Number(year)-1;
					}
					if(type == "prev")
					{
						document.getElementById("prevyear").innerHTML = Number(document.getElementById("prevyear").innerHTML)-1;
						document.getElementById("nextyear").innerHTML = Number(document.getElementById("nextyear").innerHTML)-1;
					}
								
 			}
		}
		xmlhttp.send(null);  
}
function AdvertPaging(pagenumber)
{
 	document.frmproperty.method = "POST";
 	document.frmproperty.action = "advertStatics.php?&page="+pagenumber;
	document.frmproperty.submit();	
}
function ValidateVoucher()
{
	
	if(trim(document.frmproperty.voucher_code.value) == "")
	{
		alert("Please enter a Voucher code");
		document.frmproperty.voucher_code.focus();
		return false;
	}
 	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 code_amount = document.getElementById("property_id").value;
		var total_amount = document.getElementById("total_hidden").value;
		var textvalue = trim(document.frmproperty.voucher_code.value);
 		var url = 'validatevoucher.php?textvalue='+textvalue+'&total_amount='+total_amount;		
		//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() {
			//alert(xmlhttp.readyState);
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					//alert(xmlhttp.responseText);
					var response     = xmlhttp.responseText;	
					var response_final = response.split("@");
					//alert(response_final[0]);
					if(trim(response_final[0]) == "invalid")
					{
						alert("The Voucher code you have entered is not correct");
						document.frmproperty.voucher_code.focus();
						return false;
					}
					var total = response_final[3];
					document.getElementById("subtotal_display").innerHTML = "<p>&pound;"+trim(response_final[0])+"</p>";
					document.getElementById("total_display").innerHTML = "<p id='total_amount'>&pound;"+total+"</p>";
					document.getElementById("vat_amount_display").innerHTML = "<p>&pound;"+response_final[2]+"</p>";
					document.getElementById("discount_amountlabel").style.display = "";
					document.getElementById("discount_amount").style.display = "";
					document.getElementById("discount_amount").innerHTML = "<p> - &pound;"+response_final[1]+"</p>";			
					document.getElementById("amount").value = total;
					document.getElementById("total_hidden").value = total;
					document.getElementById("total_hidden_new").value = total_amount;
					document.getElementById("custom").value = response_final[4];
					document.getElementById("btn_reduce").style.display = "none";
 			}
		}
		xmlhttp.send(null);  	
}

function ValidateNormalEnquiry()
{
	if(trim(document.frmproperty.txtname.value) == "")	
	{
		alert("Please enter your Name");	
		document.frmproperty.txtname.focus();
		return false;
	}
	if(TextValidate(document.frmproperty.txtemail,"the Email address")==false){ return false;}
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(document.frmproperty.txtemail.value == "")
	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");		
		document.frmproperty.txtemail.focus();   	
		return false;		
	}	else if (!filter.test(document.frmproperty.txtemail.value)) 	{
		alert("Please enter a valid email address\ne.g. username@domainname.com");
		document.frmproperty.txtemail.focus();	   	
		document.frmproperty.txtemail.select();
		return false;
	}
	document.frmproperty.action = "/contact.php?status=email";
	document.frmproperty.submit();
}
function ShowAdvertimage(imagepath,imgid,url)
{
	//alert(imagepath+imgid);
	//Getting the Current Borwser name.
	var browserName = navigator.appName;
	if (browserName=="Microsoft Internet Explorer")	{
	    document.getElementById("img"+imgid).setAttribute('className', 'advertActiveImg');
	} else {
		document.getElementById("img"+imgid).setAttribute('class', 'advertActiveImg');	
	}	
	
	for(var i=1;i<=8;i++){
 			if(document.getElementById("img"+i)){
					if(i!=imgid){
							if (browserName=="Microsoft Internet Explorer")	{
								document.getElementById("img"+i).setAttribute('className', '');
							} else {
								document.getElementById("img"+i).setAttribute('class', '');	
							}
					}
			}
			
	}
	
 	document.getElementById("advert_mainimage").src = url+"property-images/large_"+imagepath;
}
function ValidateImagePage1(property_id,page,type,url_base)
{
	var type = type;
	var year = year;
 	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 code_amount = document.getElementById("property_id").value;
   		var url = url_base+'advertDetails/validateimagepage.php?property_id='+property_id+'&page='+page+'&type='+type;	
		
 		//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() {
			//alert(xmlhttp.readyState);
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					//alert(xmlhttp.responseText);
					var response     = xmlhttp.responseText;
					//alert(response);
				//	return false;
					document.getElementById("image_display").innerHTML = response;
  			}
		}
		xmlhttp.send(null);  	
}
function ValidateAdvertAlert(base,property_id)
{
	alert("Your latest changes to the advert are shown, but may not be approved yet");
	window.location.href = base+"advertDetails/advertdetails.php?property_id="+property_id+"&status=desc&type=preview";
}
function ValidateCurrencyChange(property_id,type,base_url)
{
	//alert(property_id);
	//alert(type);
	//alert(document.getElementById("property_currency").value);
	var property_id = property_id;
	var type = type;
	var currency = document.getElementById("property_currency").value;
	//alert(currency);
 	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 code_amount = document.getElementById("property_id").value;
   		var url = base_url+'advertDetails/currecny-calculation.php?property_id='+property_id+'&currency='+currency+'&type='+type;	
		//alert(url);
		//return false;
 		//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() {
			//alert(xmlhttp.readyState);
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					//alert(xmlhttp.responseText);
					var response     = xmlhttp.responseText;
					//var response_final = response.split("@@");
					//alert(response);
				//	return false;
					document.getElementById("currency_display").innerHTML = response;
					//document.getElementById("currency_text").innerHTML = response_final[1]+" "+response_final[2];
  			}
		}
		xmlhttp.send(null);  	
}

function ValidateCurrencyChangePreview(property_id,type,base_url)
{
	//alert(property_id);
	//alert(type);
	//alert(document.getElementById("property_currency").value);
	var property_id = property_id;
	var type = type;
	var currency = document.getElementById("property_currency").value;
	//alert(currency);
 	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 code_amount = document.getElementById("property_id").value;
   		var url = base_url+'advertDetails/currecny-calculation.php?property_id='+property_id+'&currency='+currency+'&type='+type;	
		//alert(url);
		//return false;
 		//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() {
			//alert(xmlhttp.readyState);
  			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 				//Replace the content of the "result" DIV with the result returned by the PHP script
					//alert(xmlhttp.responseText);
					var response     = xmlhttp.responseText;
					//var response_final = response.split("@@");
					//alert(response);
				//	return false;
					document.getElementById("currency_display").innerHTML = response;
					//document.getElementById("currency_text").innerHTML = response_final[1]+" "+response_final[2];
  			}
		}
		xmlhttp.send(null);  	
}



function PeriodTodate()
{
	var FirstNight = document.getElementById("period_firstnight").value;
	//alert(FirstNight);
	if(FirstNight!="")
	{
		document.getElementById("period_lastnight").value = FirstNight;
	}
}
function Updatelastnight()
{
	var firstnight = document.getElementById("offer_firstnight").value;
	if(firstnight!="")
	{
		document.getElementById("offer_lastnight").value = firstnight;
	}
	//alert(firstnight);
}
function Selectenquiry(id) {
	var count = document.getElementById("shortlist_count").value;
	var shortvalue= "";
	for(var i=1;i<=count;i++) {
		var id = "enquirybox"+i;
		if(document.getElementById(id).checked==true) {
			if(shortvalue=="") {
				shortvalue = document.getElementById(id).value;
			}else {
				shortvalue = shortvalue+","+document.getElementById(id).value;
			}	
			
		}
	}
	document.getElementById("enquiryselected_hidden").value = shortvalue;
	//alert(shortvalue);Selectenquiry_new
}
function Selectenquiry_new(id) {
	var count = document.getElementById("shortlist_count").value;
	var shortvalue= "";
	for(var i=1;i<=count;i++) {
		var id = "enquirybox"+i;
		if(document.getElementById(id).checked==true) {
			if(shortvalue=="") {
				shortvalue = document.getElementById(id).value;
			}else {
				shortvalue = shortvalue+","+document.getElementById(id).value;
			}	
			
		}
	}
	document.getElementById("enquiryselected_hidden").value = shortvalue;
	//alert(shortvalue);
}