/*
01/21/2010	CB	Added fadeout to sendListingMessage, pulled from ASP processing.
01/27/2010	CB	Added sorting function
01/29/2010	CB	Added currency funtions

resultsData
resultsData.clearMarkers()
resultsData.showMarkers()
resultsData.hideMarkers()

function validateFirm()
function validateRealtor()
function loadSearchMap()
function loadSmallSearchMap(longitude, latitude, location, listingID)
function searchPreSubmit()
function updateResultsCount(propertyClass, totalListings)
function changeAdvancedSearch(propertyClass)
function updateSearchData(oldPropertyClass, newPropertyClass)
function clearListings(propertyClass)
function updateListings(propertyClass, latitude, longitude)
function searchListings()
function resetListingSearch()
function photoShiftRight(totalPhotos)
function slidePhotoRight(endLocation)
function photoShiftLeft()
function slidePhotoLeft(endLocation)
function plotSinglePoint(latitude, longitude, location)
function swapThumbnail(imageID)
function swapThumbnailFade()
function preLoadImages(imageList)
function searchSchool()
function searchMembers()
function updateSearchAreaCoordinates()
function enableCoordinateUpdates()
function disableCoordinateUpdates()
function mapSearch()
function emailListing(overlayStyle, listingID)
function sendListingMessage()
function watchListing(listingID)
function storeWatchListing()
function contactAgent(overlayStyle, listingID)
function contactAgents(overlayStyle)
function sendContactAgent()
function plotPoints(searchID)
function plotPointsKML(propertyClass, searchID, maxListings)
function plotPointsKMLStatic(pointSet)
function plotPointsKMLSavedSearch(propertyClass, savedSearchID, maxListings)
function adjustKMLViewPort(propertyClass)
function saveSearch()
function saveSearchProcess()
function openhouseDisplayTimes(MLNum)
function updateSort()
function updateCurrency(currency)
function formatCurrency(Price)
*/

/* -------------------===================== RESULTS DATA OBJECT =====================------------------- */
resultsData = function(resultsCount, resultSetID)
{
	this.resultsCount	= resultsCount || "";
	this.resultsMarkers	= null;
	this.advancedSearch	= true;
	this.resultSetID	= resultSetID || 0;
};

resultsData.prototype.clearMarkers=function()
{
	this.hideMarkers();

	this.resultsMarkers	= null;
};

resultsData.prototype.showMarkers=function()
{
	if(this.resultsMarkers)
		_googleMap.addOverlay(this.resultsMarkers);
};

resultsData.prototype.hideMarkers=function()
{
	if(this.resultsMarkers)
		_googleMap.removeOverlay(this.resultsMarkers);
};
/* -------------------===================== RESULTS DATA OBJECT =====================------------------- */

//var
var _resultsInformation			= new Array;
var _currentlySlidingThumbnail	= false;
var _slideSpeed					= 10; //1000 = 1 sec
var _slideDistance				= 10; //pixels
var _preLoadedImages			= new Array;
var _mapMoveDelayID				= null;
var _mapSearchedCenter			= null;
var _mapBounds;
var _markerSchool;
var _markerGolf;
var _markerHouse;
var _googleMap;
var _mapDragEvent;
var _mapZoomEvent;
var _mapSearchedCenter;
//var

try
{
	_mapBounds			= new GLatLngBounds();
	_markerSchool		= new GIcon();
	_markerGolf			= new GIcon();
	_markerHouse		= new GIcon();

	//Create new school icon
	_markerSchool.image		= "/images/mapMarker_school.png";
	_markerSchool.shadow		= "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	_markerSchool.iconSize		= new GSize(24, 38);
	_markerSchool.shadowSize	= new GSize(42, 38);
	_markerSchool.iconAnchor	= new GPoint(12, 38);
	//Create new golf icon
	_markerGolf.image		= "/images/mapMarker_golf.png";
	_markerGolf.shadow		= "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	_markerGolf.iconSize		= new GSize(24, 38);
	_markerGolf.shadowSize		= new GSize(42, 38);
	_markerGolf.iconAnchor		= new GPoint(12, 38);
	//Create new house icon
	_markerHouse.image		= "/images/mapMarker_house.png";
	_markerHouse.shadow		= "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	_markerHouse.iconSize		= new GSize(24, 38);
	_markerHouse.shadowSize		= new GSize(42, 38);
	_markerHouse.iconAnchor		= new GPoint(12, 38);
}catch(e){};

function validateFirm()
{
	if(document.getElementById("f_firmName").value == '')
	{
		alert("Please enter part of the Firm Name to find a Firm.");
		document.getElementById("f_firmName").focus();
	}else
		document.getElementById("firm_search").submit();
};

function validateRealtor()
{
	if(document.getElementById("f_realtorName").value == ''
		&& document.getElementById("f_realtorFirmName").selectedIndex == 0
		&& document.getElementById("f_designations").selectedIndex == -1
		&& document.getElementById("f_languages").selectedIndex == 0
		)
		alert("Please select at fill out at least one field to find a REALTOR.");
	else
		document.getElementById("realtor_search").submit();
};

function loadSearchMap()
{
	if (GBrowserIsCompatible())
	{
		_googleMap = new GMap2(document.getElementById("listingMap"),{mapTypes:[G_NORMAL_MAP,G_HYBRID_MAP]});
		_googleMap.addControl(new GLargeMapControl());
		_googleMap.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
		_googleMap.setCenter(new GLatLng(26.212878, -81.718964), 11);
		_googleMap.enableScrollWheelZoom();
		GEvent.addListener(_googleMap, "infowindowopen", function() {
			//Replace the "target=_blank" that KML forces
			this.getInfoWindow().getContentContainers()[0].innerHTML = this.getInfoWindow().getContentContainers()[0].innerHTML.replace(/target=_blank/g,'');
		});
		GEvent.addListener(_googleMap, "infowindowclose", function() {
			if(_mapSearchedCenter)
				_googleMap.panTo(_mapSearchedCenter);
		});
	};
};

function loadSmallSearchMap(longitude, latitude, location, listingID)
{
	if (GBrowserIsCompatible() && document.getElementById("listing" + listingID + "Map"))
	{
		_googleMap = new GMap2(document.getElementById("listing" + listingID + "Map"),{mapTypes:[G_NORMAL_MAP,G_HYBRID_MAP]});
		_mapBounds = new GLatLngBounds();
		_googleMap.addControl(new GSmallZoomControl());
		_googleMap.addControl(new GMapTypeControl());
		_googleMap.enableScrollWheelZoom();
		geocoder = new GClientGeocoder();
			
		if(longitude != '' && longitude != undefined && latitude != '' && latitude != undefined)
			plotSinglePoint(latitude, longitude, location)
		else
			_googleMap.setCenter(new GLatLng(26.212878, -81.718964), 11);
	};
};

function searchPreSubmit()
{
	//var
	var currentPropertyClass = "";
	//var
	
	document.getElementById("searchResultsCount").innerHTML = "Searching..."
	
	for(Runner=0; Runner<document.getElementsByTagName('div').length; Runner++)
	{
		if(document.getElementsByTagName('div')[Runner].id.match('divSearch') && (document.getElementsByTagName('div')[Runner].style.display == 'block' || document.getElementsByTagName('div')[Runner].style.display == ''))
		{
			currentPropertyClass = document.getElementsByTagName('div')[Runner].id.replace('divSearch','');
			break;
		};
	};
	
	document.getElementById("f_currentSearch").value = currentPropertyClass;
	document.getElementById("homeSearchForm").target = 'hiddenSubmitFrame';
	document.getElementById("homeSearchForm").action = '/includesASP/searchPreSubmit.asp';
	document.getElementById("homeSearchForm").submit();
	//Get the current center, to recenter on bubble close.
	_mapSearchedCenter = _googleMap.getCenter();
};

function updateResultsCount(propertyClass, totalListings, resultSetID)
{
	if(_resultsInformation[propertyClass] == undefined)
		_resultsInformation[propertyClass] = new resultsData(totalListings, resultSetID);
	else{
		_resultsInformation[propertyClass].resultsCount = totalListings;
		_resultsInformation[propertyClass].resultSetID = resultSetID;
	};
	
	document.getElementById("f_resultSetID").value = resultSetID;
	document.getElementById("searchResultsCount").innerHTML = totalListings;
};

function changeAdvancedSearch(propertyClass)
{
	if(_resultsInformation[propertyClass] == undefined)
		_resultsInformation[propertyClass] = new resultsData('--');

	if(document.getElementById('divAdvancedSearch' + propertyClass).style.display == 'block')
	{
		document.getElementById('divAdvancedSearch' + propertyClass).style.display = 'none';
		_resultsInformation[propertyClass].advancedSearch = false;
	}else{
		document.getElementById('divAdvancedSearch' + propertyClass).style.display = 'block';
		_resultsInformation[propertyClass].advancedSearch = true;
	};
};

function updateSearchData(oldPropertyClass, newPropertyClass)
{
	if(_resultsInformation[oldPropertyClass] != undefined)
		_resultsInformation[oldPropertyClass].hideMarkers();
		
	if(document.getElementById('divAdvancedSearch' + oldPropertyClass))
		document.getElementById('divAdvancedSearch' + oldPropertyClass).style.display = 'none';
	
	if(_resultsInformation[newPropertyClass] != undefined)
	{
		_resultsInformation[newPropertyClass].showMarkers();
		document.getElementById("f_resultSetID").value = _resultsInformation[newPropertyClass].resultSetID;
		document.getElementById("searchResultsCount").innerHTML = _resultsInformation[newPropertyClass].resultsCount;
		if(_resultsInformation[newPropertyClass].advancedSearch)
			document.getElementById('divAdvancedSearch' + newPropertyClass).style.display = 'block';
	}else{
		document.getElementById("f_resultSetID").value = 0;
		document.getElementById("searchResultsCount").innerHTML = '--';
		document.getElementById('divAdvancedSearch' + newPropertyClass).style.display = 'block';
	};
};

function clearListings(propertyClass)
{
	setTimeout("_resultsInformation['" + propertyClass + "'].clearMarkers()",1);
};

function updateListings(propertyClass, latitude, longitude)
{
	//var
	var singlePoint = new GLatLng(longitude, latitude);
	var singleMarker = new GMarker(singlePoint, {icon:_markerHouse});
	//var
	
	if(_resultsInformation[propertyClass] == undefined)
		_resultsInformation[propertyClass] = new resultsData(0, singleMarker);
	else
		_resultsInformation[propertyClass].addMarker(singleMarker);

	_mapBounds.extend(singlePoint);
	_googleMap.addOverlay(singleMarker);
	_googleMap.setCenter(_mapBounds.getCenter(), _googleMap.getBoundsZoomLevel(_mapBounds));
};

function searchListings()
{
	//var
	var currentPropertyClass = "";
	var currentResultCount = document.getElementById("searchResultsCount").innerHTML;
	var searchID = document.getElementById("f_resultSetID").value;
	//var
	
	if(currentResultCount != '--' && currentResultCount != 0)
	{
		for(Runner=0; Runner<document.getElementsByTagName('div').length; Runner++)
		{
			if(document.getElementsByTagName('div')[Runner].id.match('divSearch') && (document.getElementsByTagName('div')[Runner].style.display == 'block' || document.getElementsByTagName('div')[Runner].style.display == ''))
			{
				currentPropertyClass = document.getElementsByTagName('div')[Runner].id.replace('divSearch','');
				break;
			};
		};
		
		document.getElementById("f_currentSearch").value = currentPropertyClass;
		document.getElementById("homeSearchForm").target = '';
		document.getElementById("homeSearchForm").action = 'home-search-results.asp?rsid=' + searchID;
		document.getElementById("homeSearchForm").submit();
	}else
		alert("There were no results found for this search.\nPlease modify your search criteria.");
};

function resetListingSearch()
{
	//var
	var currentPropertyClass = "";
	//var
		
	for (currentPropertyClass in _resultsInformation)
		_resultsInformation[currentPropertyClass].clearMarkers();
	
	_resultsInformation = new Array;
	
	document.getElementById("homeSearchForm").reset();
	
	document.getElementById("searchResultsCount").innerHTML = "--";
};

function photoShiftRight(totalPhotos)
{
	//var
	var currentPos = parseInt(document.getElementById('photo_slider').style.left.replace('px',''));
	//var
	
	//92 = 80 (img) + 2 (border) + 10 (spacing)
	
	if(currentPos > -((totalPhotos-5)*80) && !_currentlySlidingThumbnail)
		slidePhotoRight((currentPos - (92*3)))
	else if(currentPos > -((totalPhotos-4)*80) && !_currentlySlidingThumbnail)
		slidePhotoRight((currentPos - (92*2)))
	else if(currentPos > -((totalPhotos-3)*80) && !_currentlySlidingThumbnail)
		slidePhotoRight((currentPos - 92))
};

function slidePhotoRight(endLocation)
{
	//var
	var currentPos = parseInt(document.getElementById('photo_slider').style.left.replace('px',''));
	//var
	
	if(currentPos != endLocation)
	{
		if( (currentPos - _slideDistance) < endLocation)
		{
			document.getElementById('photo_slider').style.left = endLocation;
			_currentlySlidingThumbnail = false;
		}else{
			_currentlySlidingThumbnail = true;

			document.getElementById('photo_slider').style.left = (currentPos - _slideDistance) + 'px';
			setTimeout("slidePhotoRight(" + endLocation + ")", _slideSpeed);
		};
	}else
		_currentlySlidingThumbnail = false;
};

function photoShiftLeft()
{
	//var
	var currentPos = parseInt(document.getElementById('photo_slider').style.left.replace('px',''));
	//var
	
	//92 = 80 (img) + 2 (border) + 10 (spacing)
	
	if(currentPos < -240 && !_currentlySlidingThumbnail)
		slidePhotoLeft((currentPos + (92*3)))
	else if(currentPos < -160 && !_currentlySlidingThumbnail)
		slidePhotoLeft((currentPos + (92*2)))
	else if(currentPos < 0 && !_currentlySlidingThumbnail)
		slidePhotoLeft((currentPos + 92))
};

function slidePhotoLeft(endLocation)
{
	//var
	var currentPos = parseInt(document.getElementById('photo_slider').style.left.replace('px',''));
	//var
	
	if(currentPos != endLocation)
	{
		if( (currentPos + _slideDistance) > endLocation)
		{
			document.getElementById('photo_slider').style.left = endLocation;
			_currentlySlidingThumbnail = false;
		}else{
			_currentlySlidingThumbnail = true;
			document.getElementById('photo_slider').style.left = (currentPos + _slideDistance) + 'px';
			setTimeout("slidePhotoLeft(" + endLocation + ")", _slideSpeed);
		};
	}else
		_currentlySlidingThumbnail = false;
};

function plotSinglePoint(latitude, longitude, location)
{
	//var
	var mapPoint = new GLatLng(longitude, latitude)
	var zoomLevel = 10;
	//var
	
	_mapBounds.extend(mapPoint);
	switch(location)
	{
		case 'school'	: _googleMap.addOverlay(new GMarker(mapPoint, {icon:_markerSchool})); break;
		case 'golf'		: _googleMap.addOverlay(new GMarker(mapPoint, {icon:_markerGolf})); break;
		case 'house'	: _googleMap.addOverlay(new GMarker(mapPoint, {icon:_markerHouse})); break;
		case 'poi'		: _googleMap.addOverlay(new GMarker(mapPoint)); break;
		case 'community': _googleMap.addOverlay(new GMarker(mapPoint)); break;
		default			: _googleMap.addOverlay(new GMarker(mapPoint)); break;
	};
	if(_googleMap.getBoundsZoomLevel(_mapBounds) > 15)
		zoomLevel = 15;
	else
		zoomLevel = _googleMap.getBoundsZoomLevel(_mapBounds);
	
	_googleMap.setCenter(_mapBounds.getCenter(), zoomLevel);
};

function swapThumbnail(imageID)
{
	document.getElementById("lisingPhotoFade").src = _preLoadedImages[imageID-1].src
	document.getElementById("listingPhotoFadeContainer").style.display = "block";
	document.getElementById("lisingPhotoFade").style.opacity = "0.0";
	document.getElementById("lisingPhotoFade").style.filter = "alpha(opacity=0)";
	
	swapThumbnailFade();
};

function swapThumbnailFade()
{
	//var
	var currentMozOpacity = parseFloat(document.getElementById("lisingPhotoFade").style.opacity);
	var currentIEOpacity = parseInt(document.getElementById("lisingPhotoFade").style.filter.replace("alpha(opacity=","").replace(")",""));
	var currentListingMatch = "";
	var currentListingID = "";
	//var
	
	if(currentMozOpacity < 1 || currentIEOpacity < 90)
	{
		document.getElementById("lisingPhotoFade").style.opacity = (currentMozOpacity + 0.1);
		document.getElementById("lisingPhotoFade").style.filter = "alpha(opacity=" + (currentIEOpacity + 10) + ")";
		setTimeout("swapThumbnailFade()",1);
	}else{
		for(Runner=0; Runner<document.getElementsByTagName('img').length; Runner++)
		{
			if(document.getElementsByTagName('img')[Runner].id.match('PhotoMain'))
			{
				currentListingMatch = document.getElementsByTagName('img')[Runner].id.match(/lising(\d+)PhotoMain/);
				break;
			};
		};
		if(currentListingMatch)
			currentListingID = currentListingMatch[1];
		
		document.getElementById("lising" + currentListingID + "PhotoMain").src = document.getElementById("lisingPhotoFade").src;
		document.getElementById("listingPhotoFadeContainer").style.display = "none";
	};
};

function preLoadImages(imageList)
{
	//var
	var fileNames = imageList.split(",");
	var runner = 0;
	var tempImage;
	var mlImageRegex = /\d\d(\d\d)\./;
	//var
	
	if(imageList != "")
	{
		for(runner = 0; runner < fileNames.length; runner++)
		{
			tempImage = new Image();
			if(fileNames[runner].match(mlImageRegex))
				tempImage.src = "http://www.sunshinemls.com:8081/pphotos/" + fileNames[runner].match(mlImageRegex)[1] + "/" + fileNames[runner];
			else if(window.location.toString().match(/\/POI\//) || window.location.toString().match(/poi-/))
				tempImage.src = "/images/poi_photos/" + fileNames[runner];
			else
				tempImage.src = "/images/community_photos/" + fileNames[runner];
			
			_preLoadedImages.push(tempImage);
		};
	};
};

function searchSchool()
{
	if(document.getElementById("f_address").value != '')
	{
		document.searchSchools.action = "school-address-results.asp"
		document.searchSchools.submit();
	}else if(document.getElementById("f_schoolName").value != ''){
		document.searchSchools.action = "school-name-results.asp"
		document.searchSchools.submit();
	}else
		alert("Please enter a street or school name.");
};

function searchMembers()
{
	//var
	var currentPropertyClass = "";
	//var
	
	for(Runner=0; Runner<document.getElementsByTagName('div').length; Runner++)
	{
		if(document.getElementsByTagName('div')[Runner].id.match('divSearch') && (document.getElementsByTagName('div')[Runner].style.display == 'block' || document.getElementsByTagName('div')[Runner].style.display == ''))
		{
			currentPropertyClass = document.getElementsByTagName('div')[Runner].id.replace('divSearch','');
			break;
		};
	};
	
	document.getElementById("f_currentSearch").value = currentPropertyClass;
	document.getElementById("memberSearchForm").submit();
};

function updateSearchAreaCoordinates()
{
	if(_googleMap.isLoaded())
	{
		document.getElementById("f_minLat").value	= _googleMap.getBounds().getSouthWest().lat();
		document.getElementById("f_minLong").value	= _googleMap.getBounds().getSouthWest().lng();
		document.getElementById("f_maxLat").value	= _googleMap.getBounds().getNorthEast().lat();
		document.getElementById("f_maxLong").value	= _googleMap.getBounds().getNorthEast().lng();
	}else
		setTimeout("updateSearchAreaCoordinates()", 500);
};

function enableCoordinateUpdates()
{
	_mapDragEvent = GEvent.addListener(_googleMap, "dragend", function() {
		if(_mapMoveDelayID)
			clearTimeout (_mapMoveDelayID);
		_mapMoveDelayID = setTimeout ("mapSearch()", 3000); //3 seconds
	});
	_mapZoomEvent = GEvent.addListener(_googleMap, "zoomend", function() {
		if(_mapMoveDelayID)
			clearTimeout (_mapMoveDelayID);
		_mapMoveDelayID = setTimeout ("mapSearch()", 3000); //3 seconds
	});
};

function disableCoordinateUpdates()
{
	GEvent.removeListener(_mapDragEvent);
	GEvent.removeListener(_mapZoomEvent);
};

function mapSearch()
{
	if(!document.getElementById("f_mapIgnore").checked)
	{
		if(_mapMoveDelayID)
			clearTimeout (_mapMoveDelayID);
		updateSearchAreaCoordinates();
		searchPreSubmit();
	};
};

function emailListing(overlayStyle, listingID)
{
	//var
	var listingAddress = document.getElementById("listingAddress" + listingID).innerHTML.replace("<BR>"," ");
	var currentDoamin = window.location.toString().match(/http:\/\/\w+\.\w+\.com\//)
	//var
	
	overlayFadeIn(overlayStyle);
	
	document.getElementById("f_listingLinks").value = "<a href='" + currentDoamin + listingID + "-" + listingAddress.replace(/,/g,"").replace(/ /g,"-") + "' >" + listingID + " -- " + listingAddress + "</a>";

	document.getElementById("emailListings").innerHTML = listingID + " -- " + listingAddress;
};

function sendListingMessage()
{
	//var
	var enteredRecptEmail = document.getElementById('f_recptEmailAddress');
	var enteredSenderEmail = document.getElementById('f_sendEmailAddress');
	var okayToSend = true;
	//var
	
	if(enteredRecptEmail || enteredSenderEmail)
	{
		if(enteredSenderEmail && (enteredSenderEmail.value == "" || !_regexEmail.test(enteredSenderEmail.value)))
		{
			alert("Please enter your valid Email Address.");
			okayToSend = false;
		};
		if(okayToSend && enteredRecptEmail && (enteredRecptEmail.value == "" || !_regexEmail.test(enteredRecptEmail.value)))
		{
			alert("Please enter a valid Email Address to send this listing to.");
			okayToSend = false;
		};
		if(okayToSend)
		{
			document.getElementById('process_message_area').style.display = 'none';
			document.getElementById("formEmailListings").submit();
			overlayFadeOut();
		};
	}else{
		document.getElementById('process_message_area').style.display = 'none';
		document.getElementById("formEmailListings").submit();
		overlayFadeOut();
	};
};

function watchListing(listingID)
{
	overlayFadeIn("addToWatchlist");
	
	document.getElementById("lid").value = listingID;
};

function storeWatchListing()
{
	document.getElementById("formWatchListings").submit();
	overlayFadeOut();
};

function contactAgent(overlayStyle, listingID)
{
	//var
	var listingAddress = document.getElementById("listingAddress" + listingID).innerHTML.replace("<BR>"," ");
	var currentDoamin = window.location.toString().match(/http:\/\/\w+\.\w+\.com\//)
	//var
	
	overlayFadeIn(overlayStyle);
	
	document.getElementById("f_listingIDs").value = listingID;
	document.getElementById("f_listingLinks").value = "<a href='" + currentDoamin + listingID + "-" + listingAddress.replace(/,/g,"").replace(/ /g,"-") + "' >" + listingID + " -- " + listingAddress + "</a>";

	document.getElementById("emailListings").innerHTML = listingID + " -- " + listingAddress;
};

function contactAgents(overlayStyle)
{
	//var
	var cartContainer	= document.getElementById('cartContainer');
	//var

	if((cartContainer.childNodes.length-2)>0)
	{
		overlayFadeIn(overlayStyle);
		
		document.getElementById("f_listingIDs").value = "cart"
		
		document.getElementById("emailListings").innerHTML = "All listings in your cart wil be sent.";
	}else
		alert("Please add listings to the cart before contact agents.");
};

function sendContactAgent()
{
	//var
	var enteredEmail = document.getElementById('f_sendEmailAddress');
	//var
	
	if(enteredEmail)
	{
		if(enteredEmail.value == "" || !_regexEmail.test(enteredEmail.value))
			alert("Please enter a valid Email Address.");
		else{
			document.getElementById('process_message_area').style.display = 'none';
			document.getElementById("formContactAgent").submit();
		};
	}else{
		document.getElementById('process_message_area').style.display = 'none';
		document.getElementById("formContactAgent").submit();
	};
};

function plotPoints(propertyClass, searchID)
{
	setTimeout("plotPointsKML('" + propertyClass + "'," + searchID + ",2000)", 1);
};

function plotPointsKML(propertyClass, searchID, maxListings, currentPage)
{
	//var
	var currentDoamin = window.location.toString().match(/http:\/\/\w+\.\w+\.com\//)
	var geoXml = new GGeoXml(currentDoamin + "includesASP/plotPointsKML.asp?uid=" + searchID + '&maxlistings=' + maxListings + '&page=' + currentPage);
	//var
	
	if(_resultsInformation[propertyClass])
		_resultsInformation[propertyClass].resultsMarkers = geoXml;
	else{
		_resultsInformation[propertyClass] = new resultsData();
		_resultsInformation[propertyClass].resultsMarkers = geoXml;
		adjustKMLViewPort(propertyClass);
	};
	
	_googleMap.addOverlay(geoXml);
};

function plotPointsKMLStatic(pointSet)
{
	//var
	var currentDoamin = window.location.toString().match(/http:\/\/\w+\.\w+\.com\//)
	var geoXml = null;
	//var
	
	switch(pointSet)
	{
		case 'SchoolsAllCollier' :	geoXml = new GGeoXml(currentDoamin + "includesASP/plotPointsKMLSchoolsAllCollier.kml"); break;
	};
	
	if(geoXml)
	{
		_resultsInformation['static'] = new resultsData();
		_resultsInformation['static'].resultsMarkers = geoXml;
		adjustKMLViewPort('static');
		_googleMap.addOverlay(geoXml);
	};
};

function plotPointsKMLSavedSearch(propertyClass, savedSearchID, maxListings, currentPage)
{
	//var
	var currentDoamin = window.location.toString().match(/http:\/\/\w+\.\w+\.com\//)
	var geoXml = new GGeoXml(currentDoamin + "includesASP/plotPointsKMLSavedSearch.asp?sid=" + savedSearchID + '&maxlistings=' + maxListings + '&pclass=' + propertyClass + '&page=' + currentPage);
	//var
	
	if(_resultsInformation[propertyClass])
		_resultsInformation[propertyClass].resultsMarkers = geoXml;
	else{
		_resultsInformation[propertyClass] = new resultsData();
		_resultsInformation[propertyClass].resultsMarkers = geoXml;
		adjustKMLViewPort(propertyClass);
	};
	
	_googleMap.addOverlay(geoXml);
};

function adjustKMLViewPort(propertyClass)
{
	if(_resultsInformation[propertyClass].resultsMarkers.hasLoaded())
		_googleMap.setCenter(_resultsInformation[propertyClass].resultsMarkers.getDefaultCenter(), _googleMap.getBoundsZoomLevel(_resultsInformation[propertyClass].resultsMarkers.getDefaultBounds()));
	else
		setTimeout("adjustKMLViewPort('" + propertyClass + "');",10);
};

function saveSearch()
{
	//var
	var currentResultCount = parseInt(document.getElementById("searchResultsCount").innerHTML);
	//var
	
	if(currentResultCount && currentResultCount <= 100)
		overlayFadeIn("saveSearch");
	else
		alert("To save a search, it must have less than 100 results.");
};

function saveSearchProcess()
{
	//var
	var currentPropertyClass = "";
	//var
	
	for(Runner=0; Runner<document.getElementsByTagName('div').length; Runner++)
	{
		if(document.getElementsByTagName('div')[Runner].id.match('divSearch') && (document.getElementsByTagName('div')[Runner].style.display == 'block' || document.getElementsByTagName('div')[Runner].style.display == ''))
		{
			currentPropertyClass = document.getElementsByTagName('div')[Runner].id.replace('divSearch','');
			break;
		};
	};
	
	document.getElementById("f_currentSearch").value = currentPropertyClass;
	document.getElementById("homeSearchForm").target = 'hiddenSubmitFrame';
	document.getElementById("homeSearchForm").action = '/includesASP/searchSave.asp?searchName=' + document.getElementById("f_searchName").value;
	document.getElementById("homeSearchForm").submit();
	
	overlayFadeOut();
};

function openhouseDisplayTimes(MLNum)
{
	//var
	var Js_post=new postback("/includesASP/openhouseLoadData.asp");
	//var
	
	Js_post.Parameters = "mlnum=" + MLNum;
	
	Js_post.Retrieve();
};

function updateSort(field)
{
	//var
	var currentURL = window.location.href;
	//var
	
	currentURL = currentURL.replace(/&?page=\d+/,'');
	currentURL = currentURL.replace(/&?sort=\w+/,'');
	
//	alert(field[field.selectedIndex].value + '\n\n' + window.location.href + '\n\n' + currentURL + '\n\n' + currentURL.match(/\?$/) + '\n\n' + currentURL.match(/\?\w/));
	if(currentURL.match(/\?$/))
		window.location.href = currentURL + 'sort=' +  field[field.selectedIndex].value
	else if(currentURL.match(/\?\w/))
		window.location.href = currentURL + '&sort=' +  field[field.selectedIndex].value
	else
		window.location.href = currentURL + '?sort=' +  field[field.selectedIndex].value
};

function updateCurrency(currency)
{
	//var
	var listingCurrency				= document.getElementById('listingCurrency');
	var listingCurrencyAnnual		= document.getElementById('listingCurrencyAnnual');
	var listingCurrencySeason		= document.getElementById('listingCurrencySeason');
	var listingCurrencyOffSeason	= document.getElementById('listingCurrencyOffSeason');
	var priceNumeric				= document.getElementById('f_priceNumeric');
	var priceNumericAnnual			= document.getElementById('f_priceNumericAnnual');
	var priceNumericSeason			= document.getElementById('f_priceNumericSeason');
	var priceNumericOffSeason		= document.getElementById('f_priceNumericOffSeason');
	var currencyRate				= 0;
	//var

	try{
		currencyRate = currencyRates[currency.value];

		if(listingCurrency && priceNumeric && currencyRate)
		{
			if(currency.value == 'USD')
				listingCurrency.innerHTML = '$' + formatCurrency(currencyRate * priceNumeric.value) + ' ' + currency.value;
			else
				listingCurrency.innerHTML = formatCurrency(currencyRate * priceNumeric.value) + ' ' + currency.value;
		}else if(currencyRate){
			if(listingCurrencyAnnual && priceNumericAnnual){
				if(currency.value == 'USD')
					listingCurrencyAnnual.innerHTML = '$' + formatCurrency(currencyRate * priceNumericAnnual.value) + ' ' + currency.value;
				else
					listingCurrencyAnnual.innerHTML = formatCurrency(currencyRate * priceNumericAnnual.value) + ' ' + currency.value;
			};
			if(listingCurrencySeason && priceNumericSeason){
				if(currency.value == 'USD')
					listingCurrencySeason.innerHTML = '$' + formatCurrency(currencyRate * priceNumericSeason.value) + ' ' + currency.value;
				else
					listingCurrencySeason.innerHTML = formatCurrency(currencyRate * priceNumericSeason.value) + ' ' + currency.value;
			};
			if(listingCurrencyOffSeason && priceNumericOffSeason){
				if(currency.value == 'USD')
					listingCurrencyOffSeason.innerHTML = '$' + formatCurrency(currencyRate * priceNumericOffSeason.value) + ' ' + currency.value;
				else
					listingCurrencyOffSeason.innerHTML = formatCurrency(currencyRate * priceNumericOffSeason.value) + ' ' + currency.value;
			};
		};
	}catch(e){};
	
	overlayFadeOut();
};

function formatCurrency(Price)
{
	//var
	var Mod=0;
	var New_price=Price;
	var Runner=0;
	var Sign_Offset=false;
	//var
	
	//Quick comma replace
	if(isNaN(Price))
	{
		Price=Price.replace(/[,$]/g,"");
	};
	if(Price.toString().match(/^0/))
	{
		Price=Price.toString().replace(/^0+/,"");
	};
	if(!isNaN(Price))
	{
		if(Price!="")
		{
			if(Price.toString().indexOf(".")==0)
			{
				Price=0;
			}else if(Price.toString().indexOf(".")>0){
				Price=Price.toString().substr(0,Price.indexOf("."));
			};
			Price=parseInt(Price);
			Price=Price+'';
			if(Price<0)
			{
				Sign_Offset=true;
				Price=Math.abs(Price).toString();
			};
			if((Price.length) > 3)
			{
				New_price=0;
				Mod = Price.length%3;
				New_price = (Mod > 0 ? (Price.substring(0,Mod)) : '');
				for(Runner=0;Runner<Math.floor(Price.length/3);Runner++)
				{
					if((Mod==0) && (Runner==0))
						New_price+= Price.substring(Mod+3*Runner,Mod+3*Runner+3);
					else
						New_price+= ',' + Price.substring(Mod+3*Runner,Mod+3*Runner+3);
				};
			}else{
				New_price=Price;
			};
		}else{
			New_price=0;
		};
	};
	if(Sign_Offset)
		New_price='-' + New_price;
		
	return New_price;
};
