//***************THE FOLLOWING FUNCTIONS ARE USED THROUGHOUT************
function openWin(url,windowName,options){
	var WindowHandle=window.open(url,windowName,options);
	WindowHandle.focus();
}

var ns6=document.getElementById&&!document.all
var ie=document.all

function showSpan(spanID,thetext){
	if (ie) eval("document.all."+spanID).innerHTML=thetext
	else if (ns6) document.getElementById(spanID).innerHTML=thetext
}
function hideSpan(spanID){
	if (ie) eval("document.all."+spanID).innerHTML=' '
	else if (ns6) document.getElementById(spanID).innerHTML=' '
}

function getElementBy(elemTag){
	var elem = document.getElementById (elemTag);
	if (elem)
		return elem;
	var elems = document.getElementsByName (elemTag);
	if (elems.length > 0)
		return elems[0];
	return null;
}

function toggleOpenCloseElem(elemName){
	var elem = getElementBy (elemName);
	if (!elem)
		return;
	if (elem.style.display == "")
		elem.style.display = "none";
	else
		elem.style.display = "";
}

function testForObject(Id){
	var o = document.getElementById(Id);
	if (o){return true;}return false;
}
//***************THE ABOVE FUNCTION IS USED THROUGHOUT************



//***************THE FOLLOWING FUNCTION IS USED FOR FORM VALIDATION************
function confirmPrompt(msg,url){
	if(confirm(msg)) 
		document.location = url;
}

function validateLength(objTB,maxChar){
	if (objTB.value.length > maxChar){return false;}
	return true;
}

function validateEmailByValue(email) {
    var regExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    return regExp.test(email);
}

function validateEmail(objTB){
	var invalidChars = "*|,\":<> []{}`\';()&$#%";
	if (objTB.value.indexOf('@') < 0 || objTB.value.indexOf('.') < 0 || objTB.value.length < 5){return false;}
	for (var i = 0; i < objTB.value.length; i++){
	   if (invalidChars.indexOf(objTB.value.charAt(i)) != -1){return false;}
	}
	return true;
} 

function validateEmailNonReq(objTB){
	var invalidChars = "*|,\":<> []{}`\';()&$#%";
	if (objTB.value.length > 0){
		if (objTB.value.indexOf('@') < 0 || objTB.value.indexOf('.') < 0 || objTB.value.length < 5){return false;}
		for (var i = 0; i < objTB.value.length; i++){
		   if (invalidChars.indexOf(objTB.value.charAt(i)) != -1){return false;}
		}
		return true;
	}
	return true;
} 

function validateTextBox(objTB){
	if (objTB.value==''){return false;}
	return true;
}

function validateSelectList(objTB){
	if (objTB.selectedIndex==''){return false;}
	return true;
}

function validateNumberTextBoxNonReq(objTB){
	if (isNaN(objTB.value)){return false;}
	return true;
}

function validateNumberTextBox(objTB){
	if (objTB.value=='' || isNaN(objTB.value)){return false;}
	return true;
}

function restrictNumberKeys(e){
		/*
		Description: This function restricts an input box to only accept numerics, dashes,
					 parentheses and spaces.
		  
		Usage:
			<input onKeyPress="return restrictNumberKeys(event);">
			
		Known Browser Support: MSIE 6.0, FireFox 1.0.4, Safari 2.0
		Written By: Chris Pietschmann, MCSD, MCAD
		*/
		var keyCode;
		
		if(window.event) //MSIE
			keyCode = e.keyCode;
		else //FireFox
			keyCode = e.which;

		if(keyCode >= 48 && keyCode <= 57 //Numeric Digits 0-9
			|| (keyCode == 8) //Backspace
			|| (keyCode == 0) //keys like Enter and Delete will return zero
			|| (keyCode == 99 && e.ctrlKey) // Ctrl-C
			|| (keyCode == 118 && e.ctrlKey) // Ctrl-V
			)
			return true;
		else
			return false;
	}
	
	function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var dtCh="/";
	var minYear=1900;
	var maxYear=2100;

	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

//***************THE ABOVE FUNCTION IS USED FOR FORM VALIDATION************



//***************THE FOLLOWING FUNCTIONS ARE USED BY THE PROPERTY COMPARE FEATURE************
var thecookie = document.cookie;
var Max_Number_Properties = 4;

function setCookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}				
	
// this deletes the cookie when called
function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function commitCompareList(){		

	setCookie('VAR_CompareList',GLOBAL_CompareList,30, '/', '', '' );
	setCookie('CompareCount',GLOBAL_CompareCount,30, '/', '', '' );	
	
	//
}		


function compareClear(){
    var compareClassName;
	GLOBAL_CompareList = "";
	GLOBAL_CompareCount = 0;		
	setCookie('VAR_CompareList','',30, '/', '', '' );
	setCookie('CompareCount','',30, '/', '', '' );
	var clearImages = document.getElementsByTagName("a");
	for (var i = 0; i < clearImages.length; i++) {
	    compareClassName = clearImages[i].className;
	    if (clearImages[i].className == compareClassName.replace("propComp-off", "propComp-on")){
    	     clearImages[i].className = compareClassName.replace("propComp-on", "propComp-off");
	    }
	
	}
}


function Right(str, n)
/***
        IN: str - the string we are RIGHTing
            n - the number of characters we want to return

        RETVAL: n characters from the right side of the string
***/
{
        if (n <= 0)     // Invalid bound, return blank string
           return "";
        else if (n > String(str).length)   // Invalid bound, return
           return str;                     // entire string
        else { // Valid bound, return appropriate substring
           var iLen = String(str).length;
           return String(str).substring(iLen, iLen - n);
        }
}

function addCompare(strAdd,strID){

	//the maximum number of listings a user can check to compare
    var myString = GLOBAL_CompareList;

    //Get the new Class Name
    if (testForObject(strID)){
		var compareClassName = document.getElementById(strID).className;
		if (compareClassName == compareClassName.replace("propComp-on", "propComp-off")){
		    compareClassName = compareClassName.replace("propComp-off", "propComp-on");
		}else{
		    compareClassName = compareClassName.replace("propComp-on", "propComp-off");
		}
	}

	if(GLOBAL_CompareCount == undefined || isNaN(GLOBAL_CompareCount) == true){
		GLOBAL_CompareCount = 0;
	}

    if (myString.indexOf(strAdd) == -1 )
	{
		if (GLOBAL_CompareCount == Max_Number_Properties) {			
			alert('You have already chosen ' + Max_Number_Properties + ' properties!');
		}
		else {
			GLOBAL_CompareList = GLOBAL_CompareList + strAdd;
			GLOBAL_CompareCount = parseInt(GLOBAL_CompareCount) + 1;
	        setCookie('VAR_CompareList',GLOBAL_CompareList,'', '/', '', '' );
	        setCookie('CompareCount',GLOBAL_CompareCount,'', '/', '', '' );
	        if (strID){
	            if (document.getElementById(strID)){
                    document.getElementById(strID).className=compareClassName
                    
                    if (document.getElementById(strID.replace("imgeNav","img")) != null){
                        document.getElementById(strID.replace("imgeNav","img")).className=compareClassName
                    }
                    if (document.getElementById(strID.replace("img","imgeNav")) != null){
                        document.getElementById(strID.replace("img","imgeNav")).className=compareClassName
                    }
                }
            }
		}
	}	
	else 
	{
		GLOBAL_CompareCount = parseInt(GLOBAL_CompareCount) - 1
		GLOBAL_CompareList = GLOBAL_CompareList.replace(strAdd,"");

	    setCookie('VAR_CompareList',GLOBAL_CompareList,'', '/', '', '' );
	    setCookie('CompareCount',GLOBAL_CompareCount,'', '/', '', '' );
	    if (strID){
	        if (document.getElementById(strID)){
                document.getElementById(strID).className=compareClassName
                
                if (document.getElementById(strID.replace("imgeNav","img")) != null){
                    document.getElementById(strID.replace("imgeNav","img")).className=compareClassName
                }
                if (document.getElementById(strID.replace("img","imgeNav")) != null){
                    document.getElementById(strID.replace("img","imgeNav")).className=compareClassName
                }
            }
        }
	}
}

function propertyCompareOnload() {
    var compareArray;
    var compareClassName;
	var GLOBAL_CompareList;
	
    if (GLOBAL_CompareList) {

        compareArray = GLOBAL_CompareList.split(';');

        for (var i = 0; i < compareArray.length; i++) {
            if (document.getElementById('img' + compareArray[i])) {
                compareClassName = document.getElementById('img' + compareArray[i]).className;
                document.getElementById('img' + compareArray[i]).className = compareClassName.replace("propComp-off", "propComp-on");
            }
        }
    }
}


var enableCache = true;
var jsCache = new Array();

var dynamicContent_ajaxObjects = new Array();

function ajax_showContent(divId,ajaxIndex,url)
{
	document.getElementById(divId).innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
	if(enableCache){
		jsCache[url] = 	dynamicContent_ajaxObjects[ajaxIndex].response;
	}
	dynamicContent_ajaxObjects[ajaxIndex] = false;
}

function ajax_loadContent(divId,url)
{
    /*
	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		return;
	}
    */

	var ajaxIndex = dynamicContent_ajaxObjects.length;
	document.getElementById(divId).innerHTML = 'Loading content - please wait';
	dynamicContent_ajaxObjects[ajaxIndex] = new sack();

	if(url.indexOf('?')>=0){
		dynamicContent_ajaxObjects[ajaxIndex].method='GET';
		var string = url.substring(url.indexOf('?'));
		url = url.replace(string,'');
		string = string.replace('?','');
		var items = string.split(/&/g);
		for(var no=0;no<items.length;no++){
			var tokens = items[no].split('=');
			if(tokens.length==2){
				dynamicContent_ajaxObjects[ajaxIndex].setVar(tokens[0],tokens[1]);
			}	
		}	
		url = url.replace(string,'');

	}
		url = url + '?VAR_Compare=' + getCookie('VAR_CompareList');
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
	
	
}



/* Simple AJAX Code-Kit (SACK) */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence, see documentation or authors website for more details */

function sack(file){
	this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
	this.requestFile = file;
	this.method = "POST";
	this.URLString = "";
	this.encodeURIString = true;
	this.execute = false;

	this.onLoading = function() { };
	this.onLoaded = function() { };
	this.onInteractive = function() { };
	this.onCompletion = function() { };

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err) {
				this.xmlhttp = null;
			}
		}
		if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
			this.xmlhttp = new XMLHttpRequest();
		if (!this.xmlhttp){
			this.failed = true; 
		}
	};
	
	this.setVar = function(name, value){
		if (this.URLString.length < 3){
			this.URLString = name + "=" + value;
		} else {
			this.URLString += "&" + name + "=" + value;
		}
	}
	
	this.encVar = function(name, value){
		var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
	return varString;
	}
	
	this.encodeURLString = function(string){
		varArray = string.split('&');
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split('=');
			if (urlVars[0].indexOf('amp;') != -1){
				urlVars[0] = urlVars[0].substring(4);
			}
			varArray[i] = this.encVar(urlVars[0],urlVars[1]);
		}
	return varArray.join('&');
	}
	
	this.runResponse = function(){
		eval(this.response);
	}
	
	this.runAJAX = function(urlstring){
		this.responseStatus = new Array(2);
		if(this.failed && this.AjaxFailedAlert){ 
			alert(this.AjaxFailedAlert); 
		} else {
			if (urlstring){ 
				if (this.URLString.length){
					this.URLString = this.URLString + "&" + urlstring; 
				} else {
					this.URLString = urlstring; 
				}
			}
			if (this.encodeURIString){
				var timeval = new Date().getTime(); 
				this.URLString = this.encodeURLString(this.URLString);
				this.setVar("rndval", timeval);
			}
			if (this.element) { this.elementObj = document.getElementById(this.element); }
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					var totalurlstring = this.requestFile + "?" + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
				}
				if (this.method == "POST"){
  					try {
						this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')  
					} catch (e) {}
				}

				this.xmlhttp.send(this.URLString);
				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState){
						case 1:
							self.onLoading();
						break;
						case 2:
							self.onLoaded();
						break;
						case 3:
							self.onInteractive();
						break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
							self.onCompletion();
							if(self.execute){ self.runResponse(); }
							if (self.elementObj) {
								var elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							self.URLString = "";
						break;
					}
				};
			}
		}
	};
this.createAJAX();
}

//***************THE ABOVE FUNCTIONS ARE USED BY THE COMPARE TOOL************

/*
Note that this tries several methods of creating the XmlHttpRequest object,
depending on the browser in use. Also note that as of this writing, the
Opera browser does not support the XmlHttpRequest.
*/

function XMLHTTPRequest_createRequester()
{
    var myRequest;
    try{
        myRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            myRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(oc){
            myRequest = null;
        }
    }
 
    if(!myRequest && typeof XMLHttpRequest != "undefined"){
        myRequest = new XMLHttpRequest();
    }
    return myRequest;
}

//***************THE ABOVE FUNCTION IS USED WITH AJAX************



/****************** Below Functions are used to Maintain Consistency when navigating back and forward without reloading the page ****************************/

function updateSignIn() {
    var elem = document.getElementById('listmailersignin');
    if (elem) {
        var req = XMLHTTPRequest_createRequester();
        if (req != null) {
            req.open('GET', '/_include/modules/quickSignIn/content.asp', true);
            req.onreadystatechange = function() {
                if (req.readyState == 4 && req.status == 200) {
                    elem.innerHTML = req.responseText;
                }
            }
            req.send(null);
        }
    }
}

function executeOnloadFunctions(){
    propertyCompareOnload();
    updateSignIn();
}
/****************** Above Functions are used to Maintain Consistency when navigating back and forward without reloading the page ****************************/

/********************************************************** Below - Save Property and Search Functions **********************************************************/

function saveSearch(qryStr) {
    var status;
    var req = XMLHTTPRequest_createRequester();

    if (req != null) {
        req.open('GET', '/listmailer/saveSearch.asp?' + qryStr + '&doNotCacheIE=' + Math.random(), true);
        req.onreadystatechange = function() {
            if (req.readyState == 4 && req.status == 200) {
                status = req.responseText;
                if (status == 'searchSaved') {   /* Saved Search Added to Database */
                    document.getElementById('saveSearchImage').src = '/images/saved.gif';
                    document.getElementById('saveSearchText').innerHTML = 'Search Saved';
                }
                else if (status == 'signInUp') {
                    document.getElementById('signUpDialog').style.display = '';     /* signUpDialog div is set to display="none" to prevent pages from flickering on load */
                    setCookie('saveSearch', qryStr, '', '/', '', '');               /* Set Temporary Cookie to save search after listmailer login */
                    YAHOO.container.signUpDialog.show();                            /* Sign up or sign in to listmailer */
                }
            }
            updateSignIn();
        }
        req.send(null);
    }
}

function saveProperty(MlsNumber, MlsName, page) {   /* typical usage: called from  {'list', 'detail', 'map'} */
    var propertyID = MlsNumber + '|' + MlsName;
    var currentURL = location.pathname.toLowerCase();
    var addProperty;
    var status;
    var url;

    GLOBAL_savedPropertyPage = page;
    setCookie('savedPropertyPage', page, '', '/', '', '');
    addProperty = (GLOBAL_savedPropertyList.indexOf(propertyID) == -1 ? 1 : 0);     /* Save Property : Delete Property */

    if (GLOBAL_savedPropertyList == '' && getCookie('savedPropertyList')) {   /* This needs to follow the code setting the variable addProperty */
        GLOBAL_savedPropertyList = getCookie('savedPropertyList');
    }

    url = '/listmailer/saveProperty.asp?PRM_MlsNumber=' + MlsNumber + '&PRM_MlsName=' + MlsName + '&addProperty=' + addProperty + '&doNotCacheIE=' + Math.random();
    var req = XMLHTTPRequest_createRequester();

    if (req != null) {
        req.open("GET", url, true);
        req.onreadystatechange = function() {
            if (req.readyState == 4 && req.status == 200) {
                status = req.responseText;

                if (status == 'propertySaved') {                                     /* Saved Property Record Added to Database*/
                    savePropertyUpdateClientBrowser('saved', propertyID, page);
                }
                else if (status == 'propertyDeleted') {                              /* Saved Property Record Deleted from Database */
                    savePropertyUpdateClientBrowser('removed', propertyID, page);
                }
                else if (status == 'signInUp') {
                    setCookie('saveProperty', propertyID, '', '/', '', '');         /* Set Temporary Cookie to save property after listmailer login */
                    document.getElementById('signUpDialog').style.display = '';     /* signUpDialog div is set to display="none" to prevent pages from flickering on load */
                    YAHOO.container.signUpDialog.show();                            /* Sign up or sign in to listmailer */
                }
            }
            updateSignIn();
        }
        req.send(null);
    }
}

function savePropertyUpdateClientBrowser(savedOrRemoved, propertyID, page) {
    var propertyId = document.getElementById('save' + propertyID);
    var mapId = document.getElementById('mapSave' + propertyID);
    var propertyTextId = document.getElementById('savePropertyText' + propertyID);

    if (savedOrRemoved == 'saved') {
        GLOBAL_savedPropertyList += propertyID + ';';
        GLOBAL_savedPropertyListRemoved = GLOBAL_savedPropertyListRemoved.replace(propertyID + ';', "");
    }
    else {
        GLOBAL_savedPropertyList = GLOBAL_savedPropertyList.replace(propertyID + ';', "");
        GLOBAL_savedPropertyListRemoved += propertyID + ';';
    }

    setCookie('savedPropertyList', GLOBAL_savedPropertyList, '', '/', '', '');
    setCookie('savedPropertyListRemoved', GLOBAL_savedPropertyListRemoved, '', '/', '', '');

    if (propertyId) {       /* used on the property list and detail pages */
        propertyId.src = savePropertyImage(savedOrRemoved, page);
    }
    if (mapId) {            /* used on the property list and interactive map search pages*/
        mapId.src = savePropertyImage(savedOrRemoved, page);
    }
    if (propertyTextId) {
        propertyTextId.innerHTML = savePropertyText(savedOrRemoved, page);
    }
}

function savePropertyImage(savedOrRemoved, page) {
    if (page == 'detail') {
        return (savedOrRemoved == 'saved' ? '/images/ico_savedProperty.gif' : '/images/ico_saveProperty.gif');
    }
    else {  /* page = 'list' or page = 'map' */
        return (savedOrRemoved == 'saved' ? '/images/saved.gif' : '/images/save.gif');
    }
}

function savePropertyText(savedOrRemoved, page) {return (savedOrRemoved == 'saved' ? 'Property Saved' : 'Save Property');}
