/* recentlyViewed.js
********************
Recently Viewed buildings are tracked and listed.

Author:	Brenton Bartel
Date:	August 19, 2004

Copyright Acro Media Inc. 1998-2004, www.acromediainc.com
*/

var cookiePrefix = "mr_";
var cookieDomain = "mountainrealty.ca";
var cookiePath = "/";

/* outMRRecentlyViewedProperties
********************************
This loops & parses through all the mountain realty cookies, and outputs a buildling list of those that have been recently viewed (based on cookies)

# linkURL *SHOULD* be passed as URL_SEARCH?action=propRedirect (which would most likely be "http://www.mountainrealty.ca/wwwapps/search.ami?action=propRedirect")
**NOTE: we *ASSUME* there should be a valid linkURL, so if there isn't ... *KABOOM*
*/
function outMRRecentlyViewedProperties(linkURL){
	var rvCookies = document.cookie;
	var begin = 0;
	var end = 0;
	var propertyID = "";
	var propertyTitle = "";

	// do we have any?
	if(rvCookies.indexOf(cookiePrefix) != -1){

		document.writeln("\t\t\t<div class=\"searchDetailHeader\" style=\"margin-top:20px;\">Recently Viewed Properties</div>");

		document.writeln("\t\t\t<table cellpadding=0 cellspacing=0 border=0 id=\"detailTable\" style=\"width:100%\">");

		// start us off for the first loop around
		begin = rvCookies.indexOf(cookiePrefix,end);

		// loop through the available cookies
		while(begin != -1){

			// update to end of the prefix
			begin += cookiePrefix.length;

			// get the id
			end = rvCookies.indexOf("=", begin);
			propertyID = rvCookies.substring(begin,end);

			// update begin to start at end (+1 for "=" symbol)
			begin = end+1;

			// now get the name
			end = rvCookies.indexOf(";", begin);
			if(end == -1){
				end = rvCookies.length;
			}
			propertyTitle = unescape(rvCookies.substr(begin,(end-begin)));

			// get ready for the next loop starting from where we ended off
			begin = rvCookies.indexOf(cookiePrefix,end);

			// output the row, if applicable
			if(propertyID.length > 0){
				document.writeln("\t\t\t\t<tr>");
				document.writeln("\t\t\t\t\t<td width=19 height=19 style=\"padding:0px; background-color:006699;\"><a href=\"" + linkURL + "&workingBuildingID=" + propertyID + "\" onMouseOver=\"window.status='" + propertyTitle + "';return true;\" onMouseOut=\"window.status='';return true;\"><img src=\"/graphics/bullet.gif\" width=19 height=19 border=0></a></td>");

				document.writeln("\t\t\t\t\t<td style=\"width:100%;padding-left:6px;\"><a href=\"" + linkURL + "&workingPropertyID=" + propertyID + "\" onMouseOver=\"window.status='" + propertyTitle + "';return true;\" onMouseOut=\"window.status='';return true;\">" + propertyTitle +"</a>");
				document.write("</td>");
				document.writeln("\t\t\t\t</tr>");
			}
		}

		document.writeln("\t\t\t</table>");
	}
}

/* setMRRecentlyViewedCookie
****************************
Sets a cookie for the recently viewed building feature
*/
function setMRRecentlyViewedCookie(propertyID, propertyTitle){
	var expires = 0;
	var secure = 0;
	var name = cookiePrefix + propertyID;
	var value = propertyTitle;

	var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((cookiePath) ? "; path=" + cookiePath : "") +
			((cookieDomain) ? "; domain=" + cookieDomain : "") +
			((secure) ? "; secure" : "");
	document.cookie = curCookie;
}
