// Various Cookie Control Methods
<!--
	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.toUTCString())+
		"; path=/";
		}

	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));
			}
		  }
		return "";
		}
	
	
	Array.prototype.indexAt = function()
		{
		  for(var i = 0; i < this.length; i++){
			if(this[i]===arguments[0])
			  return i;
		  };
		  return -1;
		}; 
		
			Array.prototype.add= function(wot)
		{
			if(this.indexAt(wot)!= -1) { // if already indexed in array
				alertBox("open","You have already added this home as a Favourite!");
			} else {
				this.push(wot); // not indexed, add favourite
				alertBox("open","This home has been added as a Favourite.");
				return this;
			}
		}
		
		Array.prototype.remove= function(wot)
		{
			if(this.indexAt(wot)!= -1) 
				{
					var indexNumber = this.indexAt(wot); // finds the array index no. of the item in question
					this.splice(indexNumber,1) // removes just the single item from the array
					alertBox("open","This home was removed from your Favourites.");
					return this;
				} else {
					alertBox("open","This home has already been removed from your Favourites.");
				}
			
		}

		
	function addToFavourites(favToAdd)
		{
		//alert ("addToFavourites method initiated");
		var currentfavs=getCookie('favourites');
		if (currentfavs!=null && currentfavs!="")
		  {
		  	var currentFavString = getCookie("favourites");
			
			var favsArray = new Array();
			favsArray = currentFavString.split(",");// explodes the current favourites string into an array for easy update.
			favsArray.add(favToAdd); // Checks to see if the current favourite name is already included, and if not, appends value to the array.
			
			var newFavString = new String;
			newFavString = favsArray.join(","); //implodes the recently updated array of favourites to a string, ready for storage inside the cookie.
			
			setCookie('favourites',newFavString,30); // set the cookie with the new/updated fav list.
			
		  }
		else
		  {
		  //currentfavs=prompt('No cookie.. wanna make one?',"");
		  currentfavs = favToAdd;
		  if (currentfavs!=null && currentfavs!="")
			{
			setCookie('favourites',currentfavs,30);
			alertBox("open","This home has been added as a Favourite.");
			}
		  }
		}
		
		
		function removeFromFavourites(favToRemove)
		{
		//alert ("removeFromFavourites method initiated");
		var currentfavs=getCookie('favourites');
		if (currentfavs!=null && currentfavs!="")
		  {
		  	var currentFavString = getCookie("favourites");
			
			var favsArray = new Array();
			favsArray = currentFavString.split(",");// explodes the current favourites string into an array for easy update.
			favsArray.remove(favToRemove); // Checks to see if the current favourite name is already included, and if so, removes it.
			
			var newFavString = new String;
			newFavString = favsArray.join(","); //implodes the recently updated array of favourites to a string, ready for storage inside the cookie.
			
			setCookie('favourites',newFavString,30); // set the cookie with the new/updated fav list.
			
		  }
		else
		  {
		  //currentfavs=prompt('No cookie wanna put one in?',"");
		  currentfavs = favToAdd;
		  if (currentfavs!=null && currentfavs!="")
			{
			setCookie('favourites',currentfavs,30);
			}
		  }
		}
//-->
