<!--

	//removes a property from the compareListings cookie
	function removeCompareListing( listID, expiryDate )
	{
	
		var totalListings;		
		var value = "";
		
		//read compareListings cookie
		var compareListings = readCookie( "compareListings" );
		
		if ( compareListings != null )
		{
		
			//load array with properties
			totalListings = unescape(compareListings).split( "|" );
			
			//loop through all properties added to comparison		
			for( var i = 0; i <= totalListings.length - 1; i++ )
			{
			
				//build list of properties excluding the one requested for removal
				if ( totalListings[i].indexOf( listID ) != 0 )
				{
				
					value += totalListings[i] + "|";	
				
				}	
											
			}
			
			//remove ending seperator
			if ( value.charAt(value.length - 1) == "|" )
			{
			
				value = value.substring( 0, value.length - 1 );
			
			}			
			
			//if all properties are removed delete cookie by setting expiry date to yesterday
			if ( value.length == 0 )
			{
			
				expiryDate = new Date();
				expiryDate.setDate( expiryDate.getDate() - 1 );				
			
			}
			
			//set cookie with properties
			setCookie( "compareListings", value, expiryDate, "/" );
									
			//update screen
			updateUser();
		
		}
			
	}
	
	//removes a listing from the viewedListings cookie
	function removeViewedListing( listID, expiryDate )
	{
	
		var totalListings;		
		var value = "";
		
		//read viewedListings cookie
		var viewedListings = readCookie( "viewedListings" );
		
		if ( viewedListings != null )
		{		
		
			//load array with properties
			totalListings = unescape(viewedListings).split( "|" );
			
			//loop through all properties viewed	
			for( var i = 0; i <= totalListings.length - 1; i++ )
			{
			
				//build list of properties excluding the one requested for removal
				if ( totalListings[i].indexOf( listID ) != 0 )
				{
				
					value += totalListings[i] + "|";	
				
				}	
											
			}
			
			//remove ending seperator
			if ( value.charAt(value.length - 1) == "|" )
			{
			
				value = value.substring( 0, value.length - 1 );
			
			}
			
			//if all properties are removed delete cookie by setting expiry date to yesterday
			if ( value.length == 0 )
			{
			
				expiryDate = new Date();
				expiryDate.setDate( expiryDate.getDate() - 1 );				
			
			}						
			
			//set cookie with properties
			setCookie( "viewedListings", value, expiryDate, "/" );						
			
			//update screen
			updateUser();
		
		}
	
	}	
	
	//adds a property to the compareListings cookie
	function compareProperty( listID, address, expiryDate )
	{
			
		address = new String(address);		
		var escapeSeq = /\'\'/gi;
		address = address.replace(escapeSeq, address);
				
		//add property to compareListings cookie
		setCompareCookie( "compareListings", listID + "," + address, expiryDate, "/" );
		
		//update screen
		updateUser();					
				
	}
	
	//adds a property to the viewedListings cookie
	function viewedListings( listID, address, expiryDate )
	{	
		
		address = new String(address);		
		var escapeSeq = /\'\'/gi;
		address = address.replace(escapeSeq, address);		
		
		//add property to viewedListings cookie
		setListingCookie( "viewedListings", listID + "," + address, expiryDate, "/" );				
	
	}		
	

		
	//udpates screen with information stored in cookies
	function updateUser()
	{
	
		var totalListings, propertyList, listingDetail;
		var compareListings = readCookie( "compareListings" );				
		
		if ( compareListings != null )
		{
		
			totalListings = unescape(compareListings).split( '|' );					
			
			propertyList = "<br><ul class=\"quick_links\">"
			
			for( var i = 0; i <= totalListings.length - 1; i++ )
			{		
				
				listingDetail = unescape(totalListings[i]).split( ',' );				
				if ( listingDetail.length == 2 )
				{
				
					propertyList += "<li><a class=\"quick_links\" href=\"?listid=" + listingDetail[0] + "\">" + listingDetail[1] + "</a>&nbsp;&nbsp;<img src=\"images/remove.gif\" width=\"10px\" height=\"10px\" onclick=\"javascript:removeCompareListing( '" + listingDetail[0] + "', '" + document.getElementById( "expiryDate" ).value + "' );\"></li>";
					
				}
						
			}
			
			propertyList += "</ul>";					
			
			document.getElementById( "propertyComparison" ).innerHTML = propertyList;						
					
		}
		else
		{		
		
			document.getElementById( "propertyComparison" ).innerHTML = "<br>Click the compare listing button to add properties.";
					
		}
		
		var viewedListings = readCookie( "viewedListings" );
		
		if ( viewedListings != null )
		{			
			
			totalListings = unescape(viewedListings).split( '|' );			
						
			propertyList = "<br><ul class=\"quick_links\">"
			
			for( var i = 0; i <= totalListings.length - 1; i++ )
			{
		
				listingDetail = totalListings[i].split( ',' );
				if ( listingDetail.length == 2 )
				{
				
					propertyList += "<li><a class=\"quick_links\" href=\"?listid=" + listingDetail[0] + "\">" + listingDetail[1] + "</a>&nbsp;&nbsp;<img src=\"images/remove.gif\" width=\"10px\" height=\"10px\" onclick=\"javascript:removeViewedListing( '" + listingDetail[0] + "', '" + document.getElementById( "expiryDate" ).value + "' );\"></li>";
					
				}
						
		
			}
			
			propertyList += "</ul>";			

			document.getElementById( "viewedListings" ).innerHTML = propertyList;	
					
					
		}
		else
		{
		
			document.getElementById( "viewedListings" ).innerHTML = "<br>Click the more information button to add properties.";
		
		}	
	
	}
	
	//create basic cookie
	function setCookie( name, value, expires, path )
	{
	
		var expiryDate = new Date(expires);
		document.cookie = name + "=" + escape(value) + "; expires=" + expiryDate.toUTCString() + "; path=" + path;					
	
	}
	
	//create comparison cookie saving properties already in compareListings cookie
	function setCompareCookie( name, value, expires, path ) 
	{
	
		var expiryDate = new Date(expires);
		var currentListings = readCookie( "compareListings" );
				
		if ( currentListings == null )
		{
				
			document.cookie = name + "=" + escape(value) + "; expires=" + expiryDate.toUTCString() + "; path=" + path;				
					
		}
		else
		{
		
			if ( currentListings.indexOf( escape( value ) ) == -1 )
			{				
				
				document.cookie = name + "=" + escape(value) + "|" + currentListings + "; expires=" + expiryDate.toUTCString() + "; path=" + path;					
				
			}		
		
		}		
		
	}
	
	//create listing cookie saving properties already in viewedListings cookie
	function setListingCookie( name, value, expires, path ) 
	{
	
		var expiryDate = new Date(expires);
		var currentListings = readCookie( "viewedListings" );	
		
		if ( currentListings == null )
		{
				
			document.cookie = name + "=" + escape(value) + "; expires=" + expiryDate.toUTCString() + "; path=" + path;	
			
			
		}
		else
		{
		
			if ( currentListings.indexOf( escape( value ) ) == -1 )
			{				
				
				document.cookie = name + "=" + escape(value) + "|" + currentListings + "; expires=" + expiryDate.toUTCString() + "; path=" + path;	
				
			}		
		
		}
		
	}
	
	//reads requested value from cookie
	function readCookie(name)
	{
	
		name += "=";
		var c = document.cookie.split( ';' );
		var ca;
		
		for( var i=0; i < c.length; i++ )
		{
			
			
			if ( c[i].indexOf( name ) == 0 || c[i].indexOf( name ) == 1 )
			{
				
				ca = c[i].split( '=' );
				return ca[1];
			
			}

		}
		
		return null;
		
	}
	
	//opens listingComparison page
	function viewComparison()
	{
	
		window.open( "listingComparison.aspx?compare=" + getComparisonListings(), "comparisonWindow", "width=" + ( screen.width - 20 ) + ",height=540px,resizable=no,scrollbars=yes,toolbar=no,left=0" );
		
	}
	
	//returns all listIDs stored in compareListings cookie
	function getComparisonListings()
	{
	
		var totalListings, listingDetail, propertyList;
		var compareListings = readCookie( "compareListings" );
		if ( compareListings != null )
		{
		
			totalListings = unescape(compareListings).split( '|' );
			propertyList = "";
			
			for( var i = 0; i <= totalListings.length - 1; i++ )
			{	
		
				listingDetail = unescape(totalListings[i]).split( ',' );
				
				if ( listingDetail.length == 2 )				
				{
				
					propertyList += listingDetail[0] + "|";
				
				}
				
			}
							
		}
		
		return propertyList;	
	
	}		
	
	//save house hunt for user
	function save( emailAddress )
	{
	
		alert( emailAddress );		
	
	}	
	
-->
