function clearContents(field) {
	if (field.value == "Enter suburb, postcode or Property ID") {
		field.value = "";
	}
}

function resetContent(field) {
	if (field.value == "") {
		field.value = "Enter suburb, postcode or Property ID";
	}
}

function checkFavourites() {
	var favCookie = getCookie("fsfavourite");
	if (favCookie != "" && favCookie != undefined) {
		window.location = "property_listing.php?mode=fav";
	} else {
		alert("You have no properties in your favourites list.");
	}	
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) {
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	} else {
		return "";
	}
}

function addFavourite(pid) {
	var favCookie = getCookie("fsfavourite");
	var favArray = new Array();
	if (favCookie != "" && favCookie != undefined) {
		favArray = favCookie.split(":");
	} else {
		favCookie = "";
	}
	if (favArray.length >= 10) {
		alert("A maximum of 10 properties can be added to your Favourites list.");
	} else {
		var found = false;
		for (var i=0; i<favArray.length; i++) {
			if (favArray[i] == pid) {
				found = true;
				break;
			}
		}
		if (found) {
			alert("This property is already in your Favourites list.");
		} else {
			if (favCookie == "") {
				favCookie = pid;
			} else {
				favCookie += ":"+pid;
			}
			setCookie("fsfavourite", favCookie, 365);
			alert("This property has been added to your Favourites list.");
		}
	}
}