// vc_id = "$Id: lib.js 12531 2009-04-20 17:41:10Z jgiven $"
/**************************************************************************************
 * Global Variables
**************************************************************************************/
var origScrollLeft = 0;
var layerScrollTo = 0;
var currentTab = 'tabSearch';
var LISTING_DETAIL_FRAME_LOADER = null;
var SUMMARY_CURRENT_THUMB = null;
var SUMMARY_SCROLL_TO = 0;
var CURRENT_PID = null;
var FIX_ARRAY = null;
var LAST_MIN_PRICE = null;
var LAST_MAX_PRICE = null;
var P_START = 1;
var basepath = APPIMAGES ? APPIMAGES + "/" : "images/";
var maxDisplayableListings = 5000;

var maxRentalArray = new Array();
var minRentalArray = new Array();
minRentalArray[0] = new Array(
		'No Min Price',
		new Option('$500', 500),
		new Option('$1,000', 1000),
		new Option('$2,000', 2000),
		new Option('$3,000', 3000));
maxRentalArray[0] = new Array(
		'No Max Price',
		new Option('$500', 500),
		new Option('$1,000', 1000),
		new Option('$2,000', 2000),
		new Option('$3,000', 3000));
var maxForSaleArray = new Array();
var minForSaleArray = new Array();
maxForSaleArray[0] = new Array(
		'No Max Price',
		new Option('$10,000', 10000),
		new Option('$20,000', 20000),
		new Option('$30,000', 30000),
		new Option('$40,000', 40000),
		new Option('$50,000', 50000),
		new Option('$60,000', 60000),
		new Option('$70,000', 70000),
		new Option('$80,000', 80000),
		new Option('$90,000', 90000),
		new Option('$100,000', 100000),
		new Option('$125,000', 125000),
		new Option('$150,000', 150000),
		new Option('$175,000', 175000),
		new Option('$200,000', 200000),
		new Option('$225,000', 225000),
		new Option('$250,000', 250000),
		new Option('$275,000', 275000),
		new Option('$300,000', 300000),
		new Option('$325,000', 325000),
		new Option('$350,000', 350000),
		new Option('$375,000', 375000),
		new Option('$400,000', 400000),
		new Option('$425,000', 425000),
		new Option('$450,000', 450000),
		new Option('$475,000', 475000),
		new Option('$500,000', 500000),
		new Option('$550,000', 550000),
		new Option('$600,000', 600000),
		new Option('$650,000', 650000),
		new Option('$700,000', 700000),
		new Option('$750,000', 750000),
		new Option('$800,000', 800000),
		new Option('$850,000', 850000),
		new Option('$900,000', 900000),
		new Option('$950,000', 950000),
		new Option('$1,000,000', 1000000),
		new Option('$1,100,000', 1100000),
		new Option('$1,200,000', 1200000),
		new Option('$1,300,000', 1300000),
		new Option('$1,400,000', 1400000),
		new Option('$1,500,000', 1500000),
		new Option('$1,600,000', 1600000),
		new Option('$1,700,000', 1700000),
		new Option('$1,800,000', 1800000),
		new Option('$1,900,000', 1900000),
		new Option('$2,000,000', 2000000),
		new Option('$3,000,000', 3000000),
		new Option('$4,000,000', 4000000),
		new Option('$5,000,000', 5000000),
		new Option('$6,000,000', 6000000),
		new Option('$7,000,000', 7000000),
		new Option('$8,000,000', 8000000),
		new Option('$9,000,000', 9000000),
		new Option('$10,000,000', 10000000));
minForSaleArray[0] = new Array(
		'No Min Price',
		new Option('$10,000', 10000),
		new Option('$20,000', 20000),
		new Option('$30,000', 30000),
		new Option('$40,000', 40000),
		new Option('$50,000', 50000),
		new Option('$60,000', 60000),
		new Option('$70,000', 70000),
		new Option('$80,000', 80000),
		new Option('$90,000', 90000),
		new Option('$100,000', 100000),
		new Option('$125,000', 125000),
		new Option('$150,000', 150000),
		new Option('$175,000', 175000),
		new Option('$200,000', 200000),
		new Option('$225,000', 225000),
		new Option('$250,000', 250000),
		new Option('$275,000', 275000),
		new Option('$300,000', 300000),
		new Option('$325,000', 325000),
		new Option('$350,000', 350000),
		new Option('$375,000', 375000),
		new Option('$400,000', 400000),
		new Option('$425,000', 425000),
		new Option('$450,000', 450000),
		new Option('$475,000', 475000),
		new Option('$500,000', 500000),
		new Option('$550,000', 550000),
		new Option('$600,000', 600000),
		new Option('$650,000', 650000),
		new Option('$700,000', 700000),
		new Option('$750,000', 750000),
		new Option('$800,000', 800000),
		new Option('$850,000', 850000),
		new Option('$900,000', 900000),
		new Option('$950,000', 950000),
		new Option('$1,000,000', 1000000),
		new Option('$1,100,000', 1100000),
		new Option('$1,200,000', 1200000),
		new Option('$1,300,000', 1300000),
		new Option('$1,400,000', 1400000),
		new Option('$1,500,000', 1500000),
		new Option('$1,600,000', 1600000),
		new Option('$1,700,000', 1700000),
		new Option('$1,800,000', 1800000),
		new Option('$1,900,000', 1900000),
		new Option('$2,000,000', 2000000),
		new Option('$3,000,000', 3000000),
		new Option('$4,000,000', 4000000),
		new Option('$5,000,000', 5000000),
		new Option('$6,000,000', 6000000),
		new Option('$7,000,000', 7000000),
		new Option('$8,000,000', 8000000),
		new Option('$9,000,000', 9000000),
		new Option('$10,000,000', 10000000));
/**************************************************************************************
 * End Blobal Variables
**************************************************************************************/

/**************************************************************************************
 * Map interaction including thumbnails, overlays, layout etc...
**************************************************************************************/

/**
 * initialize the layout
 */
function initializePP3MapLayout( ) {
	
	var IE = (document.all) ? 1 : 0;
	
	
    
    var headerDiv = document.getElementById('header');
    var leftToolBarDiv = document.getElementById('leftToolBar');
    var footerDiv = document.getElementById('footer');
    var rightContainerDiv = document.getElementById('rightContainer');
    var rightScrollDiv = document.getElementById('rightScrollContainer');
    var rightTabNavDiv = document.getElementById('rightToolBar');
    var mapDiv = document.getElementById('map');
	
    /* Calc Height of the map */
    var headerHeight = headerDiv.offsetHeight + document.getElementById('navigation').offsetHeight + document.getElementById('navigation_secondary_line').offsetHeight;
    var footerHeight = footerDiv.offsetHeight;
    var totalHeaderFooterHeight = headerHeight + footerHeight;
    var idealMapHeight = getWindowHeight() - totalHeaderFooterHeight;
    var rightTabNavDivHeight = rightTabNavDiv.offsetHeight;
    mapDiv.style.height = idealMapHeight + 'px';
	
    /* Just for fun and continuity set the searchForm div height eq to map div height */
    rightScrollDiv.style.height = (idealMapHeight - 27) + 'px';

	if (IE == 1) {
		rightScrollDiv.style.width = rightScrollDiv.offsetWidth + 'px';
	}
    
    //document.getElementById('messages').innerHTML = showObjInfo(document.body);
    
    /* Calc Width of the map - go off of the header since it will always be 100% and accurate with the scrollbar */
    var idealMapWidth = headerDiv.offsetWidth - rightContainerDiv.offsetWidth;
    mapDiv.style.width = idealMapWidth + 'px';
    
	
	if (currentTab != 'tabProperty') {
		showMapMessage("Properties will appear when your search returns between <br>1 and " + maxDisplayableListings + " matches. Zoom in on the map or refine the search criteria above.", 5000);
	}
	
}

function initializeJumpTo () {
	// Jump To Table width
	var headerDiv = document.getElementById('header');
	var rightContainerDiv = document.getElementById('rightContainer');
	var idealMapWidth = headerDiv.offsetWidth - rightContainerDiv.offsetWidth;
	//var VEtoolBarWidth = document.getElementById('MSVE_navAction_topBackground').offsetWidth + document.getElementById('MSVE_navAction_ObliqueMapView_Custom').offsetWidth;
	
	//alert(document.getElementById('MSVE_navAction_container').offsetWidth);
	
	var VEtoolBarWidth = 282; //377
	
    var leftToolBarWidth = idealMapWidth - VEtoolBarWidth; // Minus VEtoolBarWidth to account for VE toolbar;
	
    document.getElementById('jumpToTable').style.width = leftToolBarWidth + 'px';
    document.getElementById('leftToolBar').style.width = leftToolBarWidth + 'px';
	document.getElementById('integratedToolBarBackground').style.width = leftToolBarWidth + 'px';
	document.getElementById('jumpToTable').style.left = VEtoolBarWidth + 'px';
	document.getElementById('leftToolBar').style.left = VEtoolBarWidth + 'px';
    document.getElementById('integratedToolBarBackground').style.left = VEtoolBarWidth + 'px';

	// Integrated toolbar (VE) width
	document.getElementById('integratedToolBarBackground').style.width = (idealMapWidth - VEtoolBarWidth) + 'px';
}

/**
 * Listing drop down reporter construction
 * handles both position change events
 * and xhr state change
 * @param mechanism for loading detail.  if true,
 *   utilizes frame, otherwise uses ajax ( default )
 */
function ListingDropDownReporter( frame )  {
	this.positionChange = listingDropDown;
	this.XHRStateChange = loadPropertyDetailsXHR;
        this.frame = frame ? true : false;
        if ( this.frame ) {
	    LISTING_DETAIL_FRAME_LOADER = 
		new FrameLoaderSCS( "property", "contentPropertyFrame" );
        }
}

function addListingDetailFrameLoaderStateChangeListener( listener ) {
    LISTING_DETAIL_FRAME_LOADER.addListener( listener );
}

function removeListingDetailFrameLoaderStateChangeListener( listener ) {
    LISTING_DETAIL_FRAME_LOADER.removeListener( listener );
}

/**
 * load the property details. 
 * this method chooses the correct conduit, either ajax or frame.
 * @param url to load
 * @param mechanism for loading detail.  if true,
 *   utilizes frame, otherwise uses ajax ( default )
 * @param pid of this detail, sets the current pid to this.
 */
function triggerPropertyDetails( url, frame, pid ) {
    currentTab = 'tabProperty';
    if ( frame ) {
	LISTING_DETAIL_FRAME_LOADER.load( url );
	toggleTabs('Property');
    } else {
	updateListingDetailXHR( url );
    }
    CURRENT_PID = pid;
}

/**
 * load the property details after xhr response
 * @param xhr object
 */
function loadPropertyDetailsXHR( xhr ) {
    if ( xhr.success( ) ) {
        document.getElementById("contentProperty").innerHTML = xhr.responseText( );
        toggleTabs('Property');
    }
}

// copied from ppListingDropDown.js
// modified slightly to get it working ( sortof )
// renamed existing method to temp
//
// this method is now polymorphic.  it can accept either a specific location fix 
//   or a position change event
// @param location fix or position change event, 
//   if LocationFix, defines location of popup and a specific match
//   if PositionChangeEvent, defines location of popup and search for nearby matches
function listingDropDown( fixOrPosition ) {
    var positionevent;
    var matches;

    if ( fixOrPosition.id ) {
	// LocationFix
	positionevent = new PositionChangeEvent( fixOrPosition.position, 
						 fixOrPosition.earth, 
						 new GeoPoint( fixOrPosition.screen.x, fixOrPosition.screen.y - 20 ) );
	matches = [fixOrPosition.id];
    } else {
	// PositionChangeEvent
        positionevent = fixOrPosition;
	matches = getNearbyLocationFixIDs(positionevent);
    }

	var divLayer = document.getElementById("popUpContainer");
	var loopCount = 0;
	var matchesLoopCount = 1;
	var objInnerHTML = '';
	
	document.getElementById("pp3poMeta").scrollLeft = 0;
	origScrollLeft = 0;
	layerScrollTo = 0;
	
	// Check to see if user is drawing box.
	if (areListingMapBoundsInitialized() != false) {
		return;
	}
	
	if (matches.length > 0) {
		objInnerHTML += "<table cellpadding=0 cellspacing=0 border=0><tr>";
		
	    for ( var i = 0; i < matches.length; i++ ) {
		if (matches[i]) {
		    var pointLocation = retrieveLocationFix(matches[i]);
		    var detail = "javascript:triggerPropertyDetails('" + pointLocation.url + "'," + this.frame + ",'" + pointLocation.pid + "');"
		    var clipThis = "javascript:thsListingQueue.appendValue(" + pointLocation.pid + ",'" + pointLocation.address + "');";
			
			//objInnerHTML += "<td onclick=" + detail + ">";
			//objInnerHTML += '<td align="center" class="pp3poMetaTd"><img src="images/spacer.gif" border="0" width="105" height="1"><br>';
		    
			
		   	if (pointLocation.attributes.hasOpenHouse()) {
				objInnerHTML += '<td class="pp3poMetaTd" align="center" style="background-image:url(' + pointLocation.thumb +'); background-repeat: no-repeat; background-position: center top"><img src="images/spacer.gif" border="0" width="105" height="1"><br>';
				objInnerHTML += '<a href="' + detail + '"><img id="ohpng" src="images/map/pp3-oh-popup.gif" border="0" width="75" height="55"></a><br>';
			} else if (pointLocation.attributes.hasOpenHouse() == false) {
				//objInnerHTML += '<a href="' + detail + '"><img src="' + pointLocation.thumb + '" border="0"></a><br>';
				objInnerHTML += '<td class="pp3poMetaTd" align="center" style="background-image:url(' + pointLocation.thumb +'); background-repeat: no-repeat; background-position: center top"><img src="images/spacer.gif" border="0" width="105" height="1"><br>';
				objInnerHTML += '<a href="' + detail + '"><img src="images/spacer.gif" border="0" width="75" height="55"></a><br>';
			}

			if (matches.length > 1) {
				//javascript:scrollit(x+350)
				objInnerHTML += '<div style="padding: 3px; background-color: #e7e7e7; margin-bottom: 3px;">';
				if (i == 0) {
					objInnerHTML += "<span style='color:#fff'>&lt;&lt;</span> ";
				} else {
					objInnerHTML += "<a href='#' onclick='javascript:layerScrollTo = layerScrollTo - 105;scrollListing(0);'>&lt;&lt;</a> ";
				}
				
				objInnerHTML += matchesLoopCount + " of " + matches.length;
				
				if (i == (matches.length - 1)) {
					objInnerHTML += " <span style='color:#fff'>&gt;&gt;</span>";
				} else {
					objInnerHTML += " <a href='#' onclick='layerScrollTo = layerScrollTo + 105;scrollListing(1);'>&gt;&gt;</a>";
				}
				objInnerHTML += '</div>';
			}

			objInnerHTML += pointLocation.address + "<br>";
			objInnerHTML += pointLocation.price + ", " + pointLocation.bedbath + "<br>";
			//objInnerHTML += "<div style='float:left; padding-left: 4px;'><a href='index.cfm?fuseaction=listing.largePhotos&listingID='\"" + pointLocation.id + "\" + ' onclick='window.open(this.href, 'Listing_#attributes.listingID#_Images', 'width=1000,height=700,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1'); return false;'><img src='images/refresh/photoJumpSmallText.png' border=0 style='margin-top:5px;margin-right:2px'></a></div><div style='float:right;padding-right: 4px;'><b><a href=\"" + detail + "\">View Details</a></span><br>";
			objInnerHTML += '<div style="float: left; padding-left: 4px;"><a href="index.cfm?fuseaction=listing.largePhotos&listingID=' + pointLocation.pid + '" onclick="window.open(this.href, \'Listing_Images\', \'width=1000,height=700,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1\'); return false;"><img src="images/refresh/photoJumpSmallText.png" border="0"></a></div>';
			objInnerHTML += '<div style="float: right; padding-right: 4px;"><b><a href="' + detail +'">View Details</a></b></div>';
			objInnerHTML += "<b><a href=\"" + clipThis + "\">Clip It!</a></b></div><div style='clear:both;'></div>";
			
			objInnerHTML += "</td>";
		}
		if (loopCount == 1) {
		    var loopCount = 0;
		}
		var loopCount = loopCount + 1;
		matchesLoopCount = matchesLoopCount + 1;
	    }
	    
	    objInnerHTML += "</tr></table>";
	    
	    if (objInnerHTML != '') {
			document.getElementById("pp3poMeta").innerHTML = objInnerHTML;
			displayLayer(positionevent.screen.x, positionevent.screen.y, 1);
		}
		
		//alert(showObjInfo(pointLocation));
	} else if (matches.length == 0) {
	    displayLayer(positionevent.screen.x, positionevent.screen.y, 0);
		matchesLoopCount = 0;
	}
}


// If it is on the map show the thumbnail for orientation.
// @param pid, optional, will lookup current
// @param terse, if terse only show thumbnail, otherwise include summary
function displayThumbNail( pid, terse ) {
    var pid = pid ? pid : CURRENT_PID;
    var fix = retrieveLocationFixByPID( pid );
    if ( fix != null ) {
	if ( terse ) {
	    displayLayer(fix.screen.x,fix.screen.y,1,fix.thumb);
	} else {
	    listingDropDown.positionChange( fix );
	}
    }
}

// copied from ppListingDropDown.js
// modified slightly to get it working ( sortof )
function displayLayer(tempX,tempY,showHide,thumb) {
	var divLayer = document.getElementById("popUpContainer");
	var mapWidth = document.getElementById('map').offsetWidth;
	//var pointerHolder = document.getElementById("listingPointer");
	var offSetRight = -1;
	var mouseMapX = tempX; // Account for the 50px discrepancy on the position change event page x
	
	//pointerHolder.style.position = 'absolute';
	//pointerHolder.style.top = 90 + 'px';
	
	//Where in relation to the map
	//Should I place the Div Layer
	//If left side, then the right & viceversa
	if ((showHide == 1) && (mouseMapX < mapWidth / 2)) {
		document.getElementById('pp3pointerRight').style.visibility = 'hidden';
		document.getElementById('pp3pointerLeft').style.visibility = 'visible';
	} else if ((showHide == 1) && (mouseMapX > mapWidth / 2)) {
		document.getElementById('pp3pointerLeft').style.visibility = 'hidden';
		document.getElementById('pp3pointerRight').style.visibility = 'visible';
		tempX = tempX - 132;
	}
	
	tempY = tempY + 25;
	
	// if summary mouseover, set innerHTML to the thumbnail
	if (thumb) {
		document.getElementById("pp3poMeta").innerHTML = '<br><img src=' + thumb + ' border=0 height=55><br><br>';
	}
	
	//SUMMARY_CURRENT_THUMB = thumb;
	
	if (showHide == 1) {
	//document.getElementById('city1').value = tempX;
	//divLayer.style.position = 'relative';
		if (SUMMARY_CURRENT_THUMB == null) { // if not summary mouseover...
			divLayer.style.top = (tempY + 40) + 'px';
		} else {
			divLayer.style.top = tempY + 'px';
		}
		divLayer.style.left = tempX + 'px';
		divLayer.style.zIndex = 5000;
		if (offSetRight != 0) { divLayer.style.display = 'block'; }
	} else if (showHide == 0) {
		divLayer.style.display = 'none';
	}
}

function scrollListing (way) {
	var scrollLayer = document.getElementById("pp3poMeta");
	
	if (way == 0) {
		scrollLayer.scrollLeft = (origScrollLeft - 10); // pseudo-property code: Move right by 10p
	} else {
		scrollLayer.scrollLeft = (origScrollLeft + 10);
	}
	
	if (origScrollLeft >= 0) {
		origScrollLeft = scrollLayer.scrollLeft;
	}
	
	//logMessage(origScrollLeft + '|' + layerScrollTo);
	
	if (way == 0) {
		if (origScrollLeft > layerScrollTo) { setTimeout("scrollListing(0)",10); } // call doMove() in 20 msec
	} else {
		if (origScrollLeft < layerScrollTo) { setTimeout("scrollListing(1)",10); } // call doMove() in 20 msec
	}
}

/**
 * accepts a StateChangeSupport object
 */
function setMapMessages( scs ) {
	var mapDiv = document.getElementById('map');
	var mapMessages = document.getElementById('mapMessages');	
    var delay = 700;
    var delay_error = 2000;
	
	// Map Messaging will now be centered and in the middle of the map!
	var msgWidth = (document.getElementById('leftContainer').offsetWidth * .75);
	var msgLeft = (document.getElementById('leftContainer').offsetWidth - msgWidth) / 2;
	
	var msgTop = 300;
	
	mapMessages.style.width = msgWidth + 'px';
	mapMessages.style.left = msgLeft + 'px';
	mapMessages.style.top = msgTop + 'px';
            
	if ( !scs.complete( ) ) {
	    mapMessages.className = "mapMessages";
        mapMessages.innerHTML = scs.name + " " + scs.stateText( ) + " ...";
	    mapMessages.style.display = 'block';
            //setFullOpac('mapMessages');
	} else {
	    if ( scs.success( ) ) {
                mapMessages.className = "mapMessages";
                mapMessages.innerHTML = scs.name + " " + scs.stateText( );
		//setOpacity('mapMessages', 100, 0, delay);
		document.getElementById( 'mapMessages' ).style.display = 'none';
	    } else {
                mapMessages.className = "mapMessagesError";
		mapMessages.innerHTML = scs.name + " " + scs.statusText( );
 		//setOpacity('mapMessages', 100, 0, delay_error);
		document.getElementById( 'mapMessages' ).style.display = 'none';
	    }
	}
}

/*****
@ fade() and fadeStep() use the new colorFade.js file.
*****/
function fade(el) {
	var colEnd = new Color("white");
	var steps = parseInt(50);
	var delay = parseInt(10);
	var element = document.getElementById(el);
	var colStart = new Color("red");

	var pallet = colStart.blend(colEnd, steps);
	
	setTimeout(fadeStep(element, pallet, 0, delay), delay);
}

function fadeStep(element, pallet, step, delay) {
	return function() {
		if (step < pallet.length) {
			element.style.backgroundColor = pallet[step++].hex();
			setTimeout(fadeStep(element, pallet, step, delay),delay);
		}
	}
}

function showMapMessage (msg,msgTime,fadeOut) {
	var msgBox = document.getElementById('pp3Messages');
	msgBox.style.display = "none";
	setFullOpac('pp3Messages');
	msgBox.innerHTML = msg;
	if (fadeOut) { setTimeout("fadeMapMessage()", msgTime); }
}

function fadeMapMessage (hideMessage) {
	var msgBox = document.getElementById('pp3Messages');
	setOpacity('pp3Messages', 100, 0, 700);
	if (!hideMessage) { setTimeout("hideMapMessage()", 700); }
}

function hideMapMessage () {
	var msgBox = document.getElementById('pp3Messages');
	msgBox.style.display = 'none';
}

/** 
 * update the count and fade in
 * @param count
 */
function updateCount( count ) {
   	 document.getElementById('countHolder').innerHTML = '<span style="font-size: 20px;">' + dollarFormat( count, false ) + '</span> Matches';
     setOpacity( 'countHolder', 0, 100, 750 );
}

/**************************************************************************************
 * End Map / Overlay Interaction
**************************************************************************************/

/**************************************************************************************
 * Summary tab logic
**************************************************************************************/

function initSummary( bypass ) { 
	var key = null;
	var fixes = retrieveLocationFix( );
	
	var fix_array_loopcount = 0;
	
	FIX_ARRAY = new Array();
	
	for ( key in fixes ) {
		var pointLocation = retrieveLocationFix(key);
		FIX_ARRAY[fix_array_loopcount] = pointLocation;
		fix_array_loopcount = fix_array_loopcount + 1;
	}
	
	//alert(bypass);
	
	if (bypass == 1) {
		buildSummary();
	} else {
		checkSort();
	}
	//logMessage(pointLocation);
}

function buildSummary () {
	var openHouseTestMode = true;
	var summary = document.getElementById("summary-container");

	while( summary.hasChildNodes( ) ) {
	    summary.removeChild( summary.childNodes[0] );
	}
	
	for ( var i = 0; i < FIX_ARRAY.length; i++ ) {
	    // listingHolder <div style="width:98%; height:55px; margin-bottom:5px; font-size:9pt; color:#333333; padding:5px; clear:both; background-color: #fff" onmouseover="displayThumbNail( " + FIX_ARRAY[i].pid + " ); return true;">;
	    var listingHolder = document.createElement( 'div' );
	    listingHolder.style.width = '98%';
	    listingHolder.style.height = '55px';
	    listingHolder.style.marginBottom = '5px';
	    listingHolder.style.fontSize = '9pt';
	    listingHolder.style.color = '#333333';
	    listingHolder.style.padding = '5px';
	    listingHolder.style.clear = 'both';
	    listingHolder.style.backgroundColor = '#ffffff';
	    listingHolder.pid = FIX_ARRAY[i].pid;
	    listingHolder.onmouseover = function( ) { displayThumbNail( this.pid ); return true; };

	    // listingImage <div style="float:left; clear:left; width:85px;">
	    var listingImage = document.createElement( 'div' );
	    listingImage.style.cssFloat = 'left';
	    listingImage.style.styleFloat = 'left';
	    listingImage.style.clear = 'left';
	    listingImage.style.width = '85px';
	    listingImage.innerHTML = "<a style=\"font-size:16px; font-weight:bold;\" href=\"javascript:CURRENT_PID=" + FIX_ARRAY[i].pid + ";" + "triggerPropertyDetails('" + FIX_ARRAY[i].url + "',true,'" + FIX_ARRAY[i].pid + "');\"><img src=\"" + FIX_ARRAY[i].thumb + "\" width=\"75\" height=\"55\" border=\"0\"><\/a>";

	    // listingInfo <div style="float:right; width:268px; padding-left:5px; padding-right:5px;">
	    var listingInfo = document.createElement( 'div' );
	    listingInfo.style.cssFloat = 'right';
	    listingInfo.style.styleFloat = 'right';
	    listingInfo.style.width = '268px';
	    listingInfo.style.paddingLeft = '5px';
	    listingInfo.style.paddingRight = '5px';
	    if( FIX_ARRAY[i].attributes && FIX_ARRAY[i].attributes.hasOpenHouse() ) {
		listingInfo.innerHTML += "<img style=\"float:right; display:block; clear:right;\" width=\"36\" height=\"32\" alt=\"Open House\" title=\"Open House\" src=\"" + basepath + "OpenHouseIcon.png\" \/>";
	    }
	    listingInfo.innerHTML += "<a style=\"font-size:16px; font-weight:bold;\" href=\"javascript:CURRENT_PID=" + FIX_ARRAY[i].pid + ";" + "triggerPropertyDetails('" + FIX_ARRAY[i].url + "',true,'" + FIX_ARRAY[i].pid + "');\">" + FIX_ARRAY[i].address + "<\/a>";
	    listingInfo.innerHTML += "<br><strong>Price:<\/strong> " + FIX_ARRAY[i].price;
	    listingInfo.innerHTML += "<strong>Bed\/Bath:<\/strong> " + FIX_ARRAY[i].bedbath;
	    if ( FIX_ARRAY[i].credit() && FIX_ARRAY[i].credit() != "" ) {
		// listingInfo.innerHTML += "<br><div style=\"font-size: 9px; line-height:100%; \">" + FIX_ARRAY[i].credit() + "<\/div>";
		listingInfo.innerHTML += "<br>";
		// listingCredit = <div style="font-size: 9px; line-height:100%;">
		var listingCredit = document.createElement( 'div' );
		listingCredit.style.fontSize = '9px';
		listingCredit.style.lineHeight = '100%';
		listingCredit.innerHTML = FIX_ARRAY[i].credit();
		listingCredit.id = "mlsCredit_" + FIX_ARRAY[i].pid;
		listingInfo.appendChild( listingCredit );
	    }

	    // <div style="clear:both;">
	    var listingClear = document.createElement( 'div' );
	    listingClear.style.clear = 'both';

	    listingHolder.appendChild( listingImage );
	    listingHolder.appendChild( listingInfo );
	    listingHolder.appendChild( listingClear );	    
	    summary.appendChild( listingHolder );
	}
	
	// setSummaryScroll();
}

function setSummaryScroll () {
	document.getElementById('rightScrollContainer').scrollTop = SUMMARY_SCROLL_TO;
}

function updateSummaryMlsCredit( ) {
    var fixes = retrieveLocationFix( );
    for ( key in fixes ) {
	var fix = retrieveLocationFix( key );
	if ( fix.credit( ) && fix.credit( ) != "" ) {
	    var listingCredit = document.getElementById( "mlsCredit_" + fix.pid );
	    if ( listingCredit ) {
		listingCredit.innerHTML = fix.credit( );
	    }
	}
    }
}

// Sorts the array of fixes within the summary
function sortFixObj (val) {

	setCookie('summarySort',val);
	
	if (val == 1) { // High to Lo
		FIX_ARRAY = FIX_ARRAY.sort(function(a,b) { return currencyToNum(b.price) - currencyToNum(a.price) });
		buildSummary();
	} else if (val == 2) { // Lo to Hi
		FIX_ARRAY = FIX_ARRAY.sort(function(a,b) { return currencyToNum(a.price) - currencyToNum(b.price) });
		buildSummary();
	} else {
		initSummary(1);
	}
}

function checkSort () {
	if ((getCookie('summarySort') == 1) || (getCookie('summarySort') == 2)) {
		sortFixObj (getCookie('summarySort'));
	} else {
		initSummary(1);
	}
	
	//document.searchListingForm.summarySort.value = getCookie('summarySort');
}

/**************************************************************************************
 * END: Summary tab logic
**************************************************************************************/

/**************************************************************************************
 * Tab / Toggle Div Logic
**************************************************************************************/

function toggleTabs (tabname) {
	
	var  tabSearch = document.getElementById('tabSearch');
	var  tabProperty = document.getElementById('tabProperty');
	//var  tabClippings = document.getElementById('tabClippings');
	var contentSearch = document.getElementById('contentSearch');
	var contentProperty = document.getElementById('contentProperty');
	//var contentClippings = document.getElementById('contentClippings');
	var tabOn = basepath + 'map/pp3TabOn.gif';
	var tabOff = basepath + 'map/pp3TabOff.gif';
	var clippingsOn = basepath + 'map/pp3TabClippingsOn.gif';
	
	if (tabname != 'Clippings') {
		contentSearch.style.display = 'none';
		contentProperty.style.display = 'none';
	}
	
	
	if (tabname == 'Property') {
		//document.getElementById('countHolder').style.display = 'none';
		document.getElementById('pp3Messages').style.display = 'none';
		document.getElementById('rightScrollContainer').style.overflow = 'hidden';
        if ( document.getElementById('contentPropertyControl').style.display == 'none' ) {
		    document.getElementById('rightScrollContainer').style.height = ( document.getElementById( 'map' ).offsetHeight - 27  ) + 'px';
		    document.getElementById('contentPropertyControl').style.display = 'block';
		}
	} else if (tabname == 'Search') {
		document.getElementById('rightScrollContainer').style.overflow = 'auto';
		//document.getElementById('countHolder').style.display = 'block';
		if (getListingCollectionXHRCount( ) > maxDisplayableListings) {
		  document.getElementById('pp3Messages').style.display = 'block'; 
		  showMapMessage ( "Properties will appear when your search returns between <br>1 and " + maxDisplayableListings + " matches. Zoom in on the map or refine the search criteria above.", 700 ); 
		}
		if ( document.getElementById('contentPropertyControl').style.display == 'block' ) {
		    document.getElementById('contentPropertyControl').style.display = 'none';
		    //document.getElementById('rightScrollContainer').style.height = document.getElementById('map').offsetHeight + 'px';
		}
	}
	
	if (tabname == 'Search') {
		document.getElementById('tabSearch').style.borderBottom = '1px solid #97b1d8';
		document.getElementById('tabProperty').style.borderBottom = '1px solid #000';
		document.getElementById('tabClippings').style.borderBottom = '1px solid #000';
		document.getElementById('tabSearch').style.color = '#000';
		document.getElementById('tabProperty').style.color = '#fff';
		document.getElementById('tabClippings').style.color = '#fff';
		document.getElementById('tabSearch').style.backgroundImage = "url('" + tabOn + "')";
		document.getElementById('tabProperty').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('tabClippings').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('rightScrollContainer').style.height = (document.getElementById('leftContainer').offsetHeight - 27) + 'px';
	} else if (tabname == 'Property') {
		document.getElementById('tabSearch').style.borderBottom = '1px solid #000';
		document.getElementById('tabProperty').style.borderBottom = '1px solid #97b1d8';
		document.getElementById('tabClippings').style.borderBottom = '1px solid #000';
		document.getElementById('tabSearch').style.color = '#fff';
		document.getElementById('tabProperty').style.color = '#000';
		document.getElementById('tabClippings').style.color = '#fff';
		document.getElementById('tabSearch').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('tabProperty').style.backgroundImage = "url('" + tabOn + "')";
		document.getElementById('tabClippings').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('rightScrollContainer').style.height = (document.getElementById('leftContainer').offsetHeight - 54) + 'px';
	} else {
		if (currentTab == 'tabSearch') {
			document.getElementById('rightScrollContainer').style.height = (document.getElementById('leftContainer').offsetHeight - 27) + 'px';
		} else if (currentTab == 'tabProperty') {
			document.getElementById('rightScrollContainer').style.height = (document.getElementById('leftContainer').offsetHeight - 54) + 'px';
		}
		document.getElementById('tabClippings').style.backgroundImage = "url('" + clippingsOn + "')";
		document.getElementById('tabClippings').style.borderBottom = '1px solid #fff';
		document.getElementById('tabClippings').style.color = '#000';
	}
	
	// Set appropriate style and display for what is passed.
	//document.getElementById('tab' + tabname).className = 'ppSelectedTab';
	if (tabname != 'Clippings') { document.getElementById('content' + tabname).style.display = 'block'; }
}

function toggleDiv (divID) {
	var thsDiv = document.getElementById(divID);
	
	if ((thsDiv.style.display == 'block') || (thsDiv.style.display == '')) {
		thsDiv.style.display = 'none';
	} else {
		thsDiv.style.display = 'block';
	}
}

/**************************************************************************************
 * END: Tab / Toggle Div Logic
**************************************************************************************/
function showClippings(divID){
	if (divID == 'LQholder'){
		document.getElementById('LQholder').style.display = 'block';
		//document.getElementById('tabClippings').className = 'ppSelectedTab';
		document.getElementById('LQholder').style.left = (findPosX(tabClippings) - 67) + 'px';
		document.getElementById('LQholder').style.top = (findPosY(tabClippings) + 27) + 'px';
		document.getElementById('LQholder').style.backgroundColor = '#FFFFFF';
		document.getElementById('LQholder').style.padding = 10 +'px';
		document.getElementById('LQholder').style.borderTop = 'none';
		document.getElementById('LQholder').style.borderRight = '1px solid black';
		document.getElementById('LQholder').style.borderBottom = '1px solid black';
		document.getElementById('LQholder').style.borderLeft = '1px solid black';	
	}
}
function resizeClippings(){ 
	if ((document.getElementById('LQholder')) && (document.getElementById('LQholder').style.display == 'block')) {
			showClippings('LQholder')
		}
}
function hideClippings(){
		var tabOff = basepath + 'map/pp3TabOff.gif';
		document.getElementById('LQholder').style.display = 'none';
		document.getElementById('tabClippings').style.backgroundImage = "url('" + tabOff + "')";
		document.getElementById('tabClippings').style.borderBottom = '1px solid #000';
		document.getElementById('tabClippings').style.color = '#fff';
		

}
 
/**************************************************************************************
 * Search Form Validation
**************************************************************************************/

function getQueryString()
{

	var result = new Array();

	var query = window.location.href.substring( window.location.href.indexOf('?') + 1, window.location.href.length ).split("&");

	for( var i = 0; i < query.length; i++ )
	{

		var index = query[i].indexOf('=');
		var key = query[i].substring(0,index);
		var value = query[i].substring( index + 1, query[i].length );

		if( value.indexOf('#') > -1 ) value = value.substring(0,value.indexOf('#'));

		result[key] = value;

	}
	
	return result;
	
}

function querySearchCriteria()
{

	var query = getQueryString();

	if( query["searchString"] )
	{

		var pairs = query["searchString"].split("|");

		for( var i = 0; i < pairs.length; i++ )
		{

			var pair = pairs[i].split("=");
			var k = pair[0];
			var v = pair[1];

			switch( k )
			{
				case "minPrice": { LAST_MIN_PRICE = v; break; }
				case "MaxPrice": { LAST_MAX_PRICE = v; break; }
			}

		}

	}

}

function valThis () {

	var thisForm = document.forms['searchListingForm'];

	if( !thisForm ) return;

	var daysBack = thisForm.daysBack;
	if ( daysBack != null && (!isNumeric(daysBack.value)) && (daysBack.value != '')) {
		alert('Days Back must be numeric');
		daysBack.value = '';
		fade('daysBack');
	}

	var ybtmin = thisForm.ybtmin;
	if ( ybtmin != null && (!isNumeric(ybtmin.value)) && (ybtmin.value != '')) {
		alert('Year Built Min must be numeric');
		ybtmin.value = '';
		fade('ybtmin');
	}

	var ybtmax = thisForm.ybtmax;
	if ( ybtmax != null && (!isNumeric(ybtmax.value)) && (ybtmax.value != ''))
	{
		alert('Year Built Max must be numeric');
		ybtmax.value = '';
		fade('ybtmax');
	}

	if ( ybtmax != null && ybtmin != null && (ybtmax.value != '') && (ybtmin.value != ''))
	{
		if (ybtmax.value <= ybtmin.value)
		{
			alert('Year Built Max must be greater than Year Built Min');
			ybtmin.value = '';
			ybtmax.value = '';
			fade('ybtmax');
			fade('ybtmin');
		}
	}

	var maxsqft = thisForm.maxsqft;
	var minsqft = thisForm.minsqft;
	if ( maxsqft != null && minsqft != null && (maxsqft.value != '') && (minsqft.value != ''))
	{

		// By dividing values it forces the form value to be a proper number for the <> evaluation.
		var minSQ = minsqft.value / 2;
		var maxSQ = maxsqft.value / 2;

		if (maxSQ < minSQ)
		{
			alert('SQFT Max must be greater than SQFT Min');
			minsqft.value = '';
			maxsqft.value = '';
			fade('maxsqft');
			fade('minsqft');
		}

	}

	var minPrice = thisForm.minPrice;
	var MaxPrice = thisForm.MaxPrice;
	if ( minPrice != null && MaxPrice != null && (minPrice.value != '') && (MaxPrice.value != ''))
	{

		// By dividing values it forces the form value to be a proper number for the <> evaluation.
		var minP = minPrice.value / 2;
		var maxP = MaxPrice.value / 2;

		if (minP > maxP)
		{
			alert('Max Price must be greater than Min Price');
			//minPrice.value = '';
			//MaxPrice.value = '';
			fade('minPrice');
			fade('maxPrice');
			LAST_MIN_PRICE = null;
			LAST_MAX_PRICE = null;
		}

	}

}

/***
 * Uses above price arrays to populate min/max price objects based off of selection.
**/
function checkRentals (curVal) {

	var thisForm = document.forms['searchListingForm'];
	
	querySearchCriteria();
	
	with (thisForm) {
		
		MaxPrice.options.length = 0;
		minPrice.options.length = 0;
		
		// if Rentals is checked
		if ((ptyp[5].checked) && (curVal == 6)) {
			// Set checked to false for all
			for (var i = 0; i < ptyp.length; i++) {
				ptyp[i].checked = false;
			}
			// Set Checked for rentals true
			ptyp[5].checked = true;
			
			// Change the font colors for the labels accordingly
			for (var p = 0; p < 5; p++) {
				document.getElementById('ptypFS' + p).style.color = '#666666';
			}
			document.getElementById('ptypRT0').style.color = '#000000';
			
			// Populate the price options with appropriate values based off of array
			for (var j = 0; j < maxRentalArray[0].length; j++) {
				
				if (isNumeric(maxRentalArray[0][j])) {
					MaxPrice.options[j] = maxRentalArray[0][j];
					minPrice.options[j] = minRentalArray[0][j];
				} else {
					MaxPrice.options[j] = new Option('No Max Price', '');
					minPrice.options[j] = new Option('No Min Price', '');
				}
			}
			
			MaxPrice.options[0].selected = true;
			minPrice.options[0].selected = true;
		} else {
			// Rentals checked = false
			ptyp[5].checked = false;
			
			// Check to see if any are checked (incase user unchecks rentals without checking something else)
			var oneChecked = 0;
			for (var i = 0; i < ptyp.length; i++) {
				if (ptyp[i].checked) {
					oneChecked = 1;
				}
			}
			
			// If user has simply unchecked rentals then default Residential
			if (oneChecked == 0) {
				ptyp[0].checked = true;
			}
			
			// Set label font colors appropriately
			for (var p = 0; p < 5; p++) {
				document.getElementById('ptypFS' + p).style.color = '#000000';
			}
			document.getElementById('ptypRT0').style.color = '#666666';
			
			// Populate Price options appropriately from array
			var thsCount = 0;
			var minPriceArrayKey = 0;
			var maxPriceArrayKey = 0;
			for (var j = 0; j < maxForSaleArray[0].length; j++) {
				if (isNumeric(maxForSaleArray[0][j])) {
					MaxPrice.options[j] = maxForSaleArray[0][j];
					minPrice.options[j] = minForSaleArray[0][j];
					
					// Because of how Safari handles the dynamic JS form option, I hold the values of the last selected price values.
					if (minForSaleArray[0][j].value == LAST_MIN_PRICE) {
						//alert(minForSaleArray[0][j].value + ' | ' + LAST_MIN_PRICE);
						minPriceArrayKey = j;
					}
					if (maxForSaleArray[0][j].value == LAST_MAX_PRICE) {
						//alert(minForSaleArray[0][j].value + ' | ' + LAST_MAX_PRICE);
						maxPriceArrayKey = j;
					}
				} else {
					MaxPrice.options[j] = new Option('No Max Price', '');
					minPrice.options[j] = new Option('No Min Price', '');
				}
			}
			// Because of how Safari handles the dynamic JS form option, I hold the values of the last selected price values.
			if ((LAST_MIN_PRICE != null) && (LAST_MIN_PRICE > 3000)) {
				minPrice.options[minPriceArrayKey].selected = true;
			} else {
				minPrice.options[0].selected = true;	
			}
			if ((LAST_MAX_PRICE != null) && (LAST_MAX_PRICE > 3000)) {
				MaxPrice.options[maxPriceArrayKey].selected = true;
			} else {
				MaxPrice.options[0].selected = true;
			}
		}
	}
	
}

function saveSearch () {
	var msgBox = document.getElementById('pp3Messages');
	
	if (getListingCollectionXHRCount( ) <= 500) {
		window.location = 'index.cfm?fuseaction=account.savePropertySearch&searchString=' + queryStringFromForm(document.forms['searchListingForm'], PIPE_DELIM) + '&saveSearchPP3=1';
	} else {
		// Since The message about listings showing with a count of 100 or under is now persisted the below logic is important in the case of saving a search.
		if (document.getElementById('pp3Messages').style.display == 'block') {
			fadeMapMessage ();
			setTimeout("showMapMessage ('Please limit your listing count to 500 listings or under to save a search.  Thank you.',700)" ,700);
			setTimeout("fadeMapMessage (1)" ,8000);
			setTimeout("showMapMessage ('Properties will appear when your search returns between <br>1 and " + maxDisplayableListings + " matches. Zoom in on the map or refine the search criteria above.',700)" ,8720);
		} else {
			showMapMessage("Please limit your listing count to 500 listings or under to save a search.  Thank you.", 2500,1);
		}
	} 
}

/**************************************************************************************
 * END: Search Form Validation
**************************************************************************************/

/**************************************************************************************
 * Helper Functions
**************************************************************************************/
function showObjInfo(obj) {
	var names = '';
	for (var i in obj) {
		names += i + '\n';
	}
	return names;
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

function setHandStyle (onOff) {
	if (onOff) { document.body.style.cursor  = 'pointer'; } else { document.body.style.cursor  = 'default'; }
}

// Functions to return any object screen XY
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
function isNumeric(strString) {
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
 }
 
/***
 * Helper function to format a numeric string as a dollar amount.
**/
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num);
}

function currencyToNum (num) {
	num = num.toString().replace(/\$|\,/g,'');
	return num;
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}

/**************************************************************************************
 * END: Helper Functions
**************************************************************************************/

function growDiv ( objName, finish ) { 
	var thsObj = document.getElementById( objName );
	var thsObjHeight = document.getElementById( objName ).offsetHeight;
	
	if (!finish) {
		var finish = thsObj.scrollHeight;
	}
	
	if (thsObjHeight < finish) {
		thsObj.style.height = (thsObjHeight + 2) + 'px';
		setTimeout("growDiv(" + "'" + objName + "'" + "," + finish + ")",1);
	}
}

function shrinkDiv ( objName, finish ) {
	var thsObj = document.getElementById( objName );
	var thsObjHeight = document.getElementById( objName ).offsetHeight;

	//alert(thsObjHeight + '|' + finish);
	
	if (thsObjHeight > finish) {
		thsObj.style.height = (thsObjHeight - 2) + 'px';
		setTimeout("shrinkDiv(" + "'" + objName + "'" + "," + finish + ")",5);
	}
}

function displayAdvancedOptions() {
	shEl("advSearchCriteriaCol1");
	shEl("advSearchCriteriaCol2");
	shEl("advSearchCriteriaCol3");
}

function shEl(el) {
	var thisDivElement = document.getElementById(el);
	
	if (thisDivElement.style.display == 'block') {
		thisDivElement.style.display = 'none';
		document.getElementById('advancedSearchButton').innerHTML = '<a href="javascript: displayAdvancedOptions();">More Options</a>';
		document.getElementById('advancedSearchButton').className = 'advancedSearchArrowDown';
	} else {
		thisDivElement.style.display = 'block';
		document.getElementById('advancedSearchButton').innerHTML = '<a href="javascript: displayAdvancedOptions();">Fewer Options</a>';
		document.getElementById('advancedSearchButton').className = 'advancedSearchArrowUp';
	}
	
}

function listingPagination ( paginate,way ) {
	var maxCount = 5000;
	var pCount = eval(P_START + 99);
	var lCount = getListingCollectionXHRCount();
	var pp3Prev = document.getElementById("pp3Prev");
	var pp3Next = document.getElementById("pp3Next");
	var nowShowing = document.getElementById("nowShowing");
	var summarySort = document.getElementById("summarySortContainer");
	
	if (pCount < lCount) {
		var ofCOunt = pCount;
	} else {
		var ofCOunt = lCount;
	}
	
	if (!paginate) {
		if (getListingCollectionXHRCount() > 5000) {
			showEmsg();
			document.getElementById("eMsg").innerHTML = 'The map currently has <span style="font-size: 20px;">' + dollarFormat(lCount,false) + '</span> matches.  Properties will appear on the map when your search returns less than <span style="font-size: 20px;">' + dollarFormat(maxCount,false) + '</span> matches. Zoom in on the map or refine the search criteria to your right.';
			document.getElementById("eMsg").style.display = 'block';
			pp3Prev.style.display = 'none';
			pp3Next.style.display = 'none';
			nowShowing.style.display = 'none';
			summarySort.style.display = 'none';
		} else {
			pp3Prev.style.display = 'block';
			pp3Next.style.display = 'block';
			nowShowing.style.display = 'block';
			summarySort.style.display = 'block';
			//document.searchListingForm.summarySort.selectedIndex = 1; // For IE because IE creates the need for hacks.
			//document.searchListingForm.summarySort.selectedIndex = 0; // For IE because IE creates the need for hacks.
			document.getElementById("eMsg").style.display = 'none';
			document.getElementById("eMsg").innerHTML = '';
			document.searchListingForm.pStart.value = P_START;
			document.getElementById("nowShowing").innerHTML = 'Now showing <span style="font-size: 20px;">' + P_START + '</span> through <span style="font-size: 20px;">' + ofCOunt + '</span> of&nbsp;';
		}
	} else {
		if ((way == 'next') && (pCount < lCount)) {
			P_START = P_START + 100;
			document.searchListingForm.pStart.value = parseInt(document.searchListingForm.pStart.value) + 100;
			updateListingCollectionXHR( );
		} else if ((way == 'prev') && (P_START > 100)) {
			P_START = P_START - 100;
			document.searchListingForm.pStart.value = parseInt(document.searchListingForm.pStart.value) - 100;
			updateListingCollectionXHR( );
		}
	}
}

function resetPagination () {
	document.searchListingForm.pStart.value = 1;
	P_START = 1;
}

function showEmsg () {
	var eMsg = document.getElementById("eMsg");
	var pp3MessagesContainer = document.getElementById("pp3MessagesContainer");
	var map = document.getElementById("map");
	
	
	eMsg.style.top = (findPosY(map) + 50) + 'px';
	eMsg.style.width = (map.offsetWidth - 150) + 'px';
	eMsg.style.marginLeft = '80px';
	eMsg.style.display = 'block';
	
}


