



	var mySales = new Array();

	var mySalesIDs = new Array();

	var myRouteList = new Array();

	var nextRouteNum = 1;

	var goDirections = false;

	var pmWin = false;

	var pmMap = false;

	var isInSearch = false;

	var days = new Array();

	setDays('ALL',true);

	

	var MAIN_TITLE = 'Garage Sale Map from GarageSaleFinder.com';



	function LoadMap() {

		if (GBrowserIsCompatible()) {

			MapDisableLocatorControls();

			MapUpdateStatusMessage( "Loading data...", 1 );

			

			goMap = new MapData();

			

			goMap.map.addControl( new GLargeMapControl() );

			goMap.map.addControl( new GMapTypeControl() );

			goMap.map.setCenter( goMap.center, goMap.zoom );

			goMap.map.hideControls();

			goMap.map.enableScrollWheelZoom();

			

			GEvent.addListener(goMap.map, "mouseover", goMap.map.showControls);

			GEvent.addListener(goMap.map, "mouseout", goMap.map.hideControls);

			

			MapEnableLocatorControls();

			MapUpdateStatusMessage( "Ready!", 0 );

			DisplaySelectedArea();

		}

	}

	

	

	function MapData() {

		this.map = new GMap2(document.getElementById("map"));

		this.geocoder = new GClientGeocoder();

		this.center = new GLatLng(38, -94);

		this.zoom = 4;

		this.icons = new MapIcons();

		this.status = new MapStatus();

		this.tools = new MapTools();

		this.constants = new MapConstants();

		this.sales = new Array();

		this.states = new Array();

		this.zips = new Array();

		

		return this;

	}

	

	

	function MapIcons() {

		var loSaleIcon = new GIcon();

		loSaleIcon.image = "images/map/icon_lpink.png";

		loSaleIcon.shadow = "images/map/icon_shadow.png";

		loSaleIcon.iconSize = new GSize(12, 20);

		loSaleIcon.shadowSize = new GSize(22, 20);

		loSaleIcon.iconAnchor = new GPoint(6, 20);

		loSaleIcon.infoWindowAnchor = new GPoint(5, 1);

		

		var loSaleMyIcon = new GIcon();

		loSaleMyIcon.image = "images/map/icon_pink.png";

		loSaleMyIcon.shadow = "images/map/icon_shadow.png";

		loSaleMyIcon.iconSize = new GSize(12, 20);

		loSaleMyIcon.shadowSize = new GSize(22, 20);

		loSaleMyIcon.iconAnchor = new GPoint(6, 20);

		loSaleMyIcon.infoWindowAnchor = new GPoint(5, 1);

		

		var loHereIcon = new GIcon();

		loHereIcon.image = "images/map/icon_point.png";

		loHereIcon.shadow = "images/map/icon_point_shadow.png";

		loHereIcon.iconSize = new GSize(15, 14);

		loHereIcon.shadowSize = new GSize(24, 14);

		loHereIcon.iconAnchor = new GPoint(8, 14);

		loHereIcon.infoWindowAnchor = new GPoint(5, 1);

		

		this.sale = loSaleIcon;

		this.salemine = loSaleMyIcon;

		this.here = loHereIcon;

		

		return this;

	}

	

	

	function MapStatus() {

		this.zip = null;

		this.state = null;

		this.city = null;

		this.center = null;

		this.zoom = null;

		this.marker = null;

		this.markerInterval = null;

		

		return this;

	}

	

	

	function MapState( pName, pCode, pLat, pLng, pZoom ) {

		this.name = pName;

		this.code = pCode;

		this.center = new GLatLng( pLat, pLng );

		this.zoom = pZoom;

		this.cities = new Array();

		this.sales = new Array();

		

		this.loadCityStatus = goMap.constants.loadStatus.isReady;

		this.loadSaleStatus = goMap.constants.loadStatus.isReady;

		

		this.isLoadedMarkers = false;

		this.isLoadedTabs = false;

		

		return this;

	}

	

	

	function MapCity( pName ) {

		this.name = pName;

		this.zoom = null;

		this.center = null;

		this.sales = new Array();

		

		this.loadSaleStatus = goMap.constants.loadStatus.isReady;

		

		this.isLoadedMarkers = false;

		this.isLoadedTabs = false;

		

		return this;

	}

	

	

	function MapZip( pCode, pState, pLat, pLng, pZoom ) {

		this.code = pCode;

		this.state = pState;

		this.center = new GLatLng( pLat, pLng );

		this.zoom = pZoom;

		this.sales = new Array();

		

		this.loadSaleStatus = goMap.constants.loadStatus.isReady;

		

		this.isLoadedMarkers = false;

		this.isLoadedTabs = false;

		

		return this;

	}

	



	function MapSale( pID, pName, pShortDescription, pLongDescription, pAddress, pSubdivision, pCity, pState, pZip, pPhone, pType, pLatitude, pLongitude, pStart, pEnd, pSday, pEday, pCoded, isMine ) {

		this.id = pID;

		this.name = pName;

		this.shortdescription = pShortDescription;

		this.description = pLongDescription;

		this.address = pAddress;

		this.subdivision = pSubdivision;

		this.city = pCity;

		this.state = pState;

		this.zip = pZip;

		this.phone = pPhone;

		this.type = pType;

		this.latitude = pLatitude;

		this.longitude = pLongitude;

		this.date_start = pStart;

		this.date_end = pEnd;

		this.center = new GLatLng( pLatitude, pLongitude );

		this.sday = pSday;

		this.eday = pEday;

		this.coded = pCoded;

		this.ismine = isMine;

		this.marker = null;

		this.isCurrentLocation = true;

		this.matchSearch = false;



		this.listdiv = false;

		this.wtext = null;

		this.watext = null;

		this.wrtext = null;

		this.image = null;

		this.dnum = null; // Display Number (on marker)

		this.rnum = null; // Route Position



		this.loadMarkerStatus = goMap.constants.loadStatus.isReady;

		this.isActiveMarker = false;

		

		return this;

	}

	

	

	function MapConstants() {

		this.loadStatus = new MapLoadStatus();

		

		return this;

	}

	

	function MapLoadStatus() {

		this.isReady = 0;

		this.isDone = 1;

		this.isLoading = 2;

		this.isProcessing = 3;

		

		return this;

	}

	

	

	function MapTools() {

		this.Convert2Boolean = function( psValue ) {

									return (psValue.toLowerCase() == "true") ? true : false;

								}

		

		this.SetHere = function( point, txt ) {

							goMap.status.center = point;

							goMap.status.marker = goMap.tools.CreateHereMarker( point, txt );

							goMap.map.addOverlay( goMap.status.marker );

						}

		

		this.ClearLocation = function( psWhere ) {

							if (goMap.status.marker != null) goMap.map.removeOverlay( goMap.status.marker );

							

							goMap.status.center = null;

							goMap.status.marker = null;

							

							if (psWhere != "zip") {

								var loZip = document.getElementById( "zip" );

								if (loZip) loZip.value = "";

								

								goMap.status.zip = null;

							}

							

							if (psWhere != "city") {

								var loCity = document.getElementById( "city" );

								if (loCity) loCity.selectedIndex = 0;

								

								goMap.status.city = null;

								

								var loPanel = document.getElementById( "city_panel" );

								if (loPanel) loPanel.style.visibility = "hidden";

							}

								

							if (psWhere != "state" && psWhere != "city") {

								var loState = document.getElementById( "state" );

								if (loState) loState.selectedIndex = 0;

								

								goMap.status.state = null;

							}

							// Clear Current Search

							goMap.tools.ClearCurrentLocation();

							goMap.tools.ClearSaleMarkers();

						}

		

		this.CreateSaleWindow = function( pSales ) {

									var mSale = '';



									for (var i = 0; i < pSales.length; i++) {

										mSale += 	'<div id="mapwindow"><table><tr><td valign="top"><span class="number">' + pSales[i].dnum + '</span><br /></td>' +

													'<td valign="top"><span class="mainline">' + pSales[i].address + ', ' + pSales[i].city + '</span><br/>' +

													'<span class="subs">Neighborhood: </span>'+ pSales[i].subdivision + '<br/>' +

													'<span class="subs">Dates: </span>' + pSales[i].date_start + ' &#8211; ' +

													pSales[i].date_end + '<br /></td></tr></table></div>' +

													'<div id="saledescription">' + pSales[i].description + '</div>' +

													'<div id="spacer"></div>';

									}

									

									return mSale;

								}

		

		this.CreateSaleWindowA = function( pSales ) {

									var mSale = '';



									for (var i = 0; i < pSales.length; i++) {

										mSale += '<div class="routebtn" align="right"><a href="#" onclick="AddToRoute(' + pSales[i].id + ', true)" class="btn">Add to Route</a></div>';

									}

									

									return mSale;

								}

		this.CreateSaleWindowR = function( pSales ) {

									var mSale = '';



									for (var i = 0; i < pSales.length; i++) {

										mSale += '<div class="routebtn" align="right"><a href="#" onclick="RemoveFromRoute(' + pSales[i].id + ')" class="btn">Remove from Route</a></div>';

									}

									

									return mSale;

								}



		this.listings = new Array();

		this.route = new Array();

		this.currentTab = 'location';

		

		this.SwitchTabs = function (tab){

			switch(tab){

				case 'location':

				case 'sales':

					if (this.currentTab == 'route'){

						this.ClearSaleMarkers(true);

						this.BuildSalesTab(true);

					}

					this.currentTab = tab;

				break;

				case 'route':

					/*

					if (this.currentTab != 'route'){

						this.listings = new Array();

						var i;

						for (i = 0; i < goMap.sales.length; i++) {

							if (goMap.sales[i].isActiveMarker) {

								this.listings[this.listings.length] = i;

							}

						}

					}

					*/

					if (this.currentTab != 'route'){

						this.ClearSaleMarkers(true);

						var routeIdList = getMyRouteList();

					

						for (i = 1; i < routeIdList.length; i++){

							goMap.map.addOverlay( myRouteList[routeIdList[i]].marker );

							myRouteList[routeIdList[i]].isActiveMarker = true;								

						}

					}

					this.currentTab = tab;

				break;

			}

		}

		

		this.ClearCurrentLocation = function ( ) {

			for (i = 0; i < goMap.sales.length; i++) {

				if (goMap.sales[i].isCurrentLocation) {

					goMap.sales[i].isCurrentLocation = false;

				}

			}

		}

		

		this.BuildSalesTab = function ( markersOnly ) {

			//this.ClearSaleList(true);

			var points = new Array();

			var shown = false;

			var listingsField = document.getElementById('sales_listings');

			var firstLF = false;

			if (listingsField){

				listingsField.value = '';

				firstLF = true;

			}

			for(i in goMap.sales){

				show = false;

				shown = false;

				if (goMap.sales[i].isCurrentLocation){

					if (!isInSearch || goMap.sales[i].matchSearch){

						if (this.CheckSaleDate(i)){

							if (!goMap.sales[i].isActiveMarker){

								goMap.map.addOverlay( goMap.sales[i].marker );

								goMap.sales[i].isActiveMarker = true;

							}

							if (!markersOnly){

								if (!goMap.sales[i].listdiv){

									this.ListSale(goMap.sales[i]);

								}else{

									goMap.sales[i].listdiv.style.display = 'block';

								}

							}

							points[points.length] = goMap.sales[i].center;



							if (listingsField){

								if (firstLF){

									listingsField.value = goMap.sales[i].id;

									firstLF = false;

								}else{

									listingsField.value += ',' + goMap.sales[i].id;

								}

							}



							shown = true;

						}

					}

				}

				if (!shown && !markersOnly){

					// Hide It

					if (goMap.sales[i].isActiveMarker) {

						goMap.map.removeOverlay( goMap.sales[i].marker );

						goMap.sales[i].isActiveMarker = false;

					}

					goMap.sales[i].listdiv.style.display = 'none';					

				}

			}

			if (goMap.status.center){

				points[points.length] = goMap.status.center;	

			}

			this.UpdateCurrentBounds(points);

			/* Not working at this time

			cursors = new Array();

			objects = document.getElementsByTagName('*');

			for (var i in objects){

				if (objects[i] && objects[i].style){

					cursors[i] = objects[i].style.cursor;

					objects[i].style.cursor = 'wait';

				}

			}

			document.body.style.cursor = 'wait';

			for (var i in objects){

				if (objects[i] && objects[i].style){

					if(cursors[i] && cursors[i] !== '')

						objects[i].style.cursor = cursors[i];

					else

						objects[i].style.cursor = 'default';

				}

			}

			document.body.style.cursor = 'default';

			*/

		}

		

		this.CheckSaleDate = function ( saleNum ) {

			var day;

			var show = false;

			if (!days[7]){

				for (day = goMap.sales[saleNum].sday; day <= goMap.sales[saleNum].eday; day++){

					if (days[day]){

						show = true;

						break;

					}

				}

			}else{

				show = true;

			}

			return show;

		}

		

		this.CreateSaleMarker = function( pSale ) {

										//SET SALE MARKERS HERE

										

										pSale.image = 'marker.php?t=' + pSale.type + '&n=' + pSale.dnum;



										var loSaleIcon = new GIcon();

										loSaleIcon.image = pSale.image;

										loSaleIcon.shadow = "/images/mapiconshadow.png";

										loSaleIcon.iconSize = new GSize(24, 26);

										loSaleIcon.shadowSize = new GSize(37, 34);

										loSaleIcon.iconAnchor = new GPoint(14, 24);

										loSaleIcon.infoWindowAnchor = new GPoint(12, 5);

								

								

										var marker = new GMarker( pSale.center, loSaleIcon );

										

										GEvent.addListener(marker, "click", function() {

												marker.openInfoWindowHtml( pSale.wtext + pSale.watext );

											});

										

										return marker;

									}

		

		this.UpdateSaleMarker = function( pSale ) {

										GEvent.clearListeners(pSale.marker, "click");

										if (pSale.rnum !== null){

											GEvent.addListener(pSale.marker, "click", function() {

													pSale.marker.openInfoWindowHtml( pSale.wtext + pSale.wrtext );

												});

										}else{

											GEvent.addListener(pSale.marker, "click", function() {

													pSale.marker.openInfoWindowHtml( pSale.wtext + pSale.watext );

												});

										}

										return true;

									}

		

		this.CreateHereMarker = function( point, txt ) {

									var marker = new GMarker( point, goMap.icons.here );

									

									GEvent.addListener(marker, "click", function() {

											marker.openInfoWindowHtml(txt);

										});

									

									return marker;

								}

		

		this.ClearSaleMarkers = function(keepList) {

										if (!keepList){

											goMap.tools.ClearSaleList();

										}

										for (var i = 0; i < goMap.sales.length; i++) {

											if (goMap.sales[i].isActiveMarker) {

												goMap.map.removeOverlay( goMap.sales[i].marker );

												goMap.sales[i].isActiveMarker = false;

											}

										}

									}

		

		this.GetMarkerListBounds = function( pList ) {

									var bounds = new GLatLngBounds();

									

									for (var i = 0; i < pList.length; i++) {

										bounds.extend( pList[i].center );

									}

									

									return bounds;

								}

		

		this.UpdateCurrentBounds = function ( points ) {

									

									// Functionality Removed 2009-05-05

									return true;

									

									var currentBounds = goMap.map.getBounds();

									var newBounds = new GLatLngBounds();

									var i;

									for (i=0;i<points.length;i++){

										newBounds.extend(points[i]);	

									}

									if (points && points.length > 0){

										goMap.map.panTo( newBounds.getCenter() );

										var newZoom = goMap.map.getBoundsZoomLevel(newBounds);

										if (newZoom > 12){

											newZoom = 12;

										}else if (newZoom > 10){

											newZoom--;

										}

										goMap.map.setCenter(newBounds.getCenter(),newZoom);

									}else{

										goMap.map.setCenter(goMap.center,goMap.zoom);

									}

								}

		

		this.GetState = function( pState ) {

							var ord = null;

							

							for (var i = 0; i < goMap.states.length; i++) {

								if (goMap.states[i].code == pState) {

									ord = i;

									break;

								}

							}

							

							return ord;

						}

		

		this.GetCity = function( psCity, piState ) {

							var ord = null;

							

							for (var i = 0; i < goMap.states[piState].cities.length; i++) {

								if (goMap.states[piState].cities[i].name == psCity) {

									ord = i;

									break;

								}

							}

							

							return ord;

						}

		

		this.GetZip = function( pZip ) {

							var ord = null;

							

							for (var i = 0; i < goMap.zips.length; i++) {

								if (goMap.zips[i].code == pZip) {

									ord = i;

									break;

								}

							}

							

							return ord;

						}

		

		this.GetSale = function( pSale ) {

							var ord = null;

							

							for (var i = 0; i < goMap.sales.length; i++) {

								if (goMap.sales[i].id == pSale) {

									ord = i;

									break;

								}

							}

							

							return ord;

						}

		

		this.UpdateSaleCollections = function( pSale, pState, pCity, pZip ) {

											if (pState != null) {

												var lbIsStateSale = false;

												 

												for (var i = 0; i < goMap.states[pState].sales.length; i++) {

													if (goMap.states[pState].sales[i] == pSale) {

														lbIsStateSale = true;

														break;

													}

												}

												

												if (!lbIsStateSale) goMap.states[pState].sales.push( pSale );

												

												if (pCity != null) {

													var lbIsCitySale = false;

													 

													for (var i = 0; i < goMap.states[pState].cities[pCity].sales.length; i++) {

														if (goMap.states[pState].cities[pCity].sales[i] == pSale) {

															lbIsCitySale = true;

															break;

														}

													}

													

													if (!lbIsCitySale) goMap.states[pState].cities[pCity].sales.push( pSale );

												}

											}

											

											if (pZip != null) {

												var lbIsZipSale = false;

												 

												for (var i = 0; i < goMap.zips[pZip].sales.length; i++) {

													if (goMap.zips[pZip].sales[i] == pSale) {

														lbIsZipSale = true;

														break;

													}

												}

												

												if (!lbIsZipSale) goMap.zips[pZip].sales.push( pSale );

											}

										}

		

		this.UpdateGeocode = function( poSale ) {

									var path = "http://" + gsURL + "/data_update.php?sale=" + poSale.id + "&lat=" + poSale.center.y + "&lng=" + poSale.center.x;

									var request = GXmlHttp.create();

									

									request.open("GET", path, true);

									request.onreadystatechange = function() {

																	if (request.readyState == 4) {

																		// nothing to do...

																	}

																}

									request.send(null);

								}

		

		this.CheckMarkerStatus = function( poObj ) {

										if (!poObj.isLoadedMarkers) {

											var lbIsLoaded = true;

											

											for (var i = poObj.sales.length - 1; i >= 0; i--) {

												if (goMap.sales[poObj.sales[i]].loadMarkerStatus != goMap.constants.loadStatus.isDone) {

													lbIsLoaded = false;

													break;

												}

											}

											

											poObj.isLoadedMarkers = lbIsLoaded;

										}

										

										if (lbIsLoaded && goMap.status.markerInterval != null) {

											clearInterval( goMap.status.markerInterval );

											goMap.status.markerInterval = null;

										}

										

										return poObj.isLoadedMarkers;

									}

		

		this.GroupEqualPointSales = function( pObj ) {

										

										if (!pObj.isLoadedTabs) {

											//function disabled

											/*

											for (var i = 0; i < pObj.sales.length; i++) {

												var dupes = new Array();

												dupes.push( goMap.sales[pObj.sales[i]] );

												

												for (var j = 0; j < pObj.sales.length; j++) {

													if (j != i && goMap.sales[pObj.sales[j]].center.equals( goMap.sales[pObj.sales[i]].center )) {

														dupes.push( goMap.sales[pObj.sales[j]] );

													}

												}

												

												if (dupes.length > 1) {

													goMap.sales[pObj.sales[i]].wtext = goMap.tools.CreateSaleWindow( dupes );

													goMap.sales[pObj.sales[i]].marker = goMap.tools.CreateSaleMarker( goMap.sales[pObj.sales[i]] );

												}

											}

											*/

											pObj.isLoadedTabs = true;

										}

										

										return pObj.isLoadedTabs;

									}

		

		this.ClearSaleList = function() {

								//var obj = document.getElementById( "listings" );

								//if (obj) obj.innerHTML = "";

								for (var i in goMap.sales){

									if (goMap.sales[i] && goMap.sales[i].listdiv){

										goMap.sales[i].listdiv.style.display = 'none';

									}

								}

							}

		

		this.ListSale = function( pSale ) {

								var obj = document.getElementById( "listings" );

								if (obj) {

									if (!pSale.listdiv){

										var lsSaleInfo = '<div id="record"><table cellspacing="0" cellpadding="0" border="0" width="100%"><tbody><tr>' +

											'<td width="30" valign="top"><img src="' + pSale.image + '" /></td>' +

											'<td valign="top"><span class="listing_text">' + 

											'<a href="#" onclick="return goMap.tools.RevealSale(' + pSale.id + ');">'+ pSale.address + '</a> - ' +

											pSale.shortdescription + '</span></td>' +

											'<td align="center" valign="top" width="50"><span class="listing_type" onclick="return goMap.tools.RevealSale(' + pSale.id + ');">'+

											pSale.city +'</span></td></tr></tbody></table></div>';

										// Should be icon marker instead of type.

										

										//obj.innerHTML += '<li>' + lsSaleInfo + '</li>';

										pSale.listdiv = document.createElement("DIV");

										pSale.listdiv.innerHTML = lsSaleInfo;

										obj.appendChild(pSale.listdiv);

									}else{

										pSale.listdiv.style.display = 'block';

									}

								}

							}



		this.RevealSale = function( piSale ) {

								var liSaleOrd = goMap.tools.GetSale( piSale );

								var liSaleRoute = (goMap.sales[liSaleOrd].rnum === null) ? goMap.sales[liSaleOrd].watext : goMap.sales[liSaleOrd].wrtext;

								goMap.sales[liSaleOrd].marker.openInfoWindowHtml( goMap.sales[liSaleOrd].wtext + liSaleRoute);

								

								return false;

							}

		

		this.DisplayState = function() {

								if (goMap.status.state != null) {

									if (goMap.states[goMap.status.state].loadSaleStatus == goMap.constants.loadStatus.isDone) {

										if (goMap.tools.CheckMarkerStatus( goMap.states[goMap.status.state] )) {

											goMap.tools.GroupEqualPointSales( goMap.states[goMap.status.state] );

											

											var listingsField = document.getElementById('sales_listings');

											var firstLF = false;

											if (listingsField){

												listingsField.value = '';

												firstLF = true;

											}

											// display sale markers...

											for (var i = 0; i < goMap.states[goMap.status.state].sales.length; i++) {

												if (goMap.tools.CheckSaleDate(goMap.states[goMap.status.state].sales[i])){

													goMap.map.addOverlay( goMap.sales[goMap.states[goMap.status.state].sales[i]].marker );

													goMap.sales[goMap.states[goMap.status.state].sales[i]].isActiveMarker = true;

													goMap.tools.ListSale( goMap.sales[goMap.states[goMap.status.state].sales[i]] );

												}

												goMap.sales[goMap.states[goMap.status.state].sales[i]].isCurrentLocation = true;

												if (listingsField){

													if (firstLF){

														listingsField.value = goMap.sales[goMap.states[goMap.status.state].sales[i]].id;

														firstLF = false;

													}else{

														listingsField.value += ',' + goMap.sales[goMap.states[goMap.status.state].sales[i]].id;

													}

												}

											}

											

											// move to new location...

											if (goMap.states[goMap.status.state].zoom == goMap.map.getZoom()) {

												goMap.map.panTo( goMap.states[goMap.status.state].center );

											} else {

												goMap.map.setCenter( goMap.states[goMap.status.state].center, goMap.states[goMap.status.state].zoom );

											}



											// update message...

											var count = goMap.states[goMap.status.state].sales.length;

											var msg = (goMap.status.state == null) ? null : ('Sorry, no sales were found in your area.');

											if (count >= 1){

												msg = 'There ' + ((count == 1) ? 'is' : 'are') + ' ' + ((count == 0) ? 'no' : count) + ' sale' + ((count == 1) ? '' : 's') + ' in the state of ' + goMap.states[goMap.status.state].name + '.';

											}

											MapUpdateStatusMessage( msg, ((count == 0) ? 2 : 0) );

											

											var loPanel = document.getElementById("city_panel");

											if (loPanel) loPanel.style.visibility = "visible";

											

											goMap.tools.PopulateCityOptions();

											if (goMap.states[goMap.status.state].name){

												document.title = goMap.states[goMap.status.state].name + ' ' + MAIN_TITLE;

											}else{

												document.title = MAIN_TITLE;

											}

										}

									}

								}

							}

		

		this.DisplayCity = function() {

								if (goMap.status.city != null && goMap.status.state != null) {

									if (goMap.states[goMap.status.state].cities[goMap.status.city].loadSaleStatus == goMap.constants.loadStatus.isDone) {

										if (goMap.tools.CheckMarkerStatus( goMap.states[goMap.status.state].cities[goMap.status.city] )) {

											goMap.tools.GroupEqualPointSales( goMap.states[goMap.status.state].cities[goMap.status.city] );

											

											var listingsField = document.getElementById('sales_listings');

											var firstLF = false;

											if (listingsField){

												listingsField.value = '';

												firstLF = true;

											}

											// display sale markers...

											var points = new Array();

											for (var i = 0; i < goMap.states[goMap.status.state].cities[goMap.status.city].sales.length; i++) {

												if (goMap.tools.CheckSaleDate(goMap.states[goMap.status.state].cities[goMap.status.city].sales[i])){

													goMap.map.addOverlay( goMap.sales[goMap.states[goMap.status.state].cities[goMap.status.city].sales[i]].marker );

													goMap.sales[goMap.states[goMap.status.state].cities[goMap.status.city].sales[i]].isActiveMarker = true;

													goMap.tools.ListSale( goMap.sales[goMap.states[goMap.status.state].cities[goMap.status.city].sales[i]] );

													points[points.length] = goMap.sales[goMap.states[goMap.status.state].cities[goMap.status.city].sales[i]].center;

												}

												goMap.sales[goMap.states[goMap.status.state].cities[goMap.status.city].sales[i]].isCurrentLocation = true;

												if (listingsField){

													if (firstLF){

														listingsField.value = goMap.sales[goMap.states[goMap.status.state].cities[goMap.status.city].sales[i]].id;

														firstLF = false;

													}else{

														listingsField.value += ',' + goMap.sales[goMap.states[goMap.status.state].cities[goMap.status.city].sales[i]].id;

													}

												}

											}

											

											goMap.tools.SetHere( goMap.states[goMap.status.state].cities[goMap.status.city].center, ("The city of " + goMap.states[goMap.status.state].cities[goMap.status.city].name + ", " + goMap.states[goMap.status.state].code + " is located here.") );

											points[points.length] = goMap.states[goMap.status.state].cities[goMap.status.city].center;

											

											// move to new location...

											if (goMap.states[goMap.status.state].cities[goMap.status.city].zoom == goMap.map.getZoom()) {

												goMap.map.panTo( goMap.states[goMap.status.state].cities[goMap.status.city].center );

											} else {

												goMap.map.setCenter( goMap.states[goMap.status.state].cities[goMap.status.city].center, goMap.states[goMap.status.state].cities[goMap.status.city].zoom );

											}

											goMap.tools.UpdateCurrentBounds(points);

											

//											if (goMap.states[goMap.status.state].cities[goMap.status.city].sales.length > 0) {

//												var bounds = new GLatLngBounds();

//												for (var i = 0; i < goMap.states[goMap.status.state].cities[goMap.status.city].sales.length; i++) {

//													bounds.extend( goMap.sales[goMap.states[goMap.status.state].cities[goMap.status.city].sales[i]].center );

//												}

//												var zoom = goMap.map.getBoundsZoomLevel( bounds );

//												

//												goMap.map.setZoom( zoom );

//											}

											

											// update message...

											var count = goMap.states[goMap.status.state].cities[goMap.status.city].sales.length;

											var msg = 'There ' + ((count == 1) ? 'is' : 'are') + ' ' + ((count == 0) ? 'no' : count) + ' sale' + ((count == 1) ? '' : 's') + ' in or near ' + goMap.states[goMap.status.state].cities[goMap.status.city].name + ', ' + goMap.states[goMap.status.state].code + '.';

											MapUpdateStatusMessage( msg, ((count == 0) ? 2 : 0) );

											if (count > 0){

												TabbedPanels1.showPanel(1);	

											}

											

											if (goMap.states[goMap.status.state].cities[goMap.status.city].name){

												document.title = goMap.states[goMap.status.state].cities[goMap.status.city].name + ', ' + goMap.states[goMap.status.state].name + ' ' + MAIN_TITLE;

											}else{

												document.title = goMap.states[goMap.status.state].name + ' ' + MAIN_TITLE;

											}

											

										}

									}

								}

							}

		

		this.DisplayZip = function() {

								if (goMap.status.zip != null) {

									if (goMap.zips[goMap.status.zip].loadSaleStatus == goMap.constants.loadStatus.isDone) {

										if (goMap.tools.CheckMarkerStatus( goMap.zips[goMap.status.zip] )) {

											goMap.tools.GroupEqualPointSales( goMap.zips[goMap.status.zip] );

											

											var listingsField = document.getElementById('sales_listings');

											var firstLF = false;

											if (listingsField){

												listingsField.value = '';

												firstLF = true;

											}

											// display sale markers...

											var points = new Array();

											for (var i = 0; i < goMap.zips[goMap.status.zip].sales.length; i++) {

												if (goMap.tools.CheckSaleDate(goMap.zips[goMap.status.zip].sales[i])){

													goMap.map.addOverlay( goMap.sales[goMap.zips[goMap.status.zip].sales[i]].marker );

													goMap.sales[goMap.zips[goMap.status.zip].sales[i]].isActiveMarker = true;

													goMap.tools.ListSale( goMap.sales[goMap.zips[goMap.status.zip].sales[i]] );

													points[points.length] = goMap.sales[goMap.zips[goMap.status.zip].sales[i]].center;

												}

												goMap.sales[goMap.zips[goMap.status.zip].sales[i]].isCurrentLocation = true;

												if (listingsField){

													if (firstLF){

														listingsField.value = goMap.sales[goMap.zips[goMap.status.zip].sales[i]].id;

														firstLF = false;

													}else{

														listingsField.value += ',' + goMap.sales[goMap.zips[goMap.status.zip].sales[i]].id;

													}

												}

											}

											

											if (goMap.zips[goMap.status.zip].sales.length == 0) {

												goMap.map.setCenter( goMap.center, goMap.zoom );

												MapUpdateStatusMessage( 'No sales found for the requested zip code!', 3 );

											} else {

												goMap.tools.SetHere( goMap.zips[goMap.status.zip].center, ("The zipcode of " + goMap.zips[goMap.status.zip].code + " is located here.") );

												points[points.length] = goMap.zips[goMap.status.zip].center;

												

												// move to new location...

												if (goMap.zips[goMap.status.zip].zoom == goMap.map.getZoom()) {

													goMap.map.panTo( goMap.zips[goMap.status.zip].center );

												} else {

													goMap.map.setCenter( goMap.zips[goMap.status.zip].center, goMap.zips[goMap.status.zip].zoom );

												}

												goMap.tools.UpdateCurrentBounds(points);

												

												// update message...

												var count = goMap.zips[goMap.status.zip].sales.length;

												var msg = 'There ' + ((count == 1) ? 'is' : 'are') + ' ' + ((count == 0) ? 'no' : count) + ' sale' + ((count == 1) ? '' : 's') + ' in or near the zipcode ' + goMap.zips[goMap.status.zip].code + '.';

												MapUpdateStatusMessage( msg, ((count == 0) ? 2 : 0) );

												if (count > 0){

													TabbedPanels1.showPanel(1);	

												}

											}

										}

									}

								}

							}

		

		this.PopulateCityOptions = function() {

										var loCity = document.getElementById("city");

										loCity.options.length = 0;

										

										if (goMap.status.state != null) {

											if (goMap.states[goMap.status.state].loadCityStatus == goMap.constants.loadStatus.isDone) {

												loCity.options[loCity.options.length] = new Option(((goMap.states[goMap.status.state].cities.length == 0) ? 'No Sales Found' : 'Select a City'), '');

												

												for (var i = 0; i < goMap.states[goMap.status.state].cities.length; i++) {

													loCity.options[loCity.options.length] = new Option(goMap.states[goMap.status.state].cities[i].name, i);

												}

												//setTimeout('DisplaySelectedArea()',1500);

												DisplaySelectedArea();

											} else {

												loCity.options[loCity.options.length] = new Option('Loading cities...', '');

												

												goMap.tools.LoadStateCities();

											}

										}

									}

		

		this.LoadStateCities = function() {

									if (goMap.status.state != null) {

										goMap.states[goMap.status.state].loadCityStatus = goMap.constants.loadStatus.isLoading;

										

										var path = "http://" + gsURL + "/data_cities.php?state=" + goMap.states[goMap.status.state].code;

										var request = GXmlHttp.create();

										

										request.open("GET", path, true);

										request.onreadystatechange = function() {

																		if (request.readyState == 4) {

																			var xmlDoc = request.responseXML;

																			var cities = xmlDoc.documentElement.getElementsByTagName("city");

																			

																			var liStateOrd = goMap.status.state;

																			goMap.states[liStateOrd].loadCityStatus = goMap.constants.loadStatus.isLoading;

																			

																			for (var i = 0; i < cities.length; i++) {

																				var lName = cities[i].getAttribute("name");

																				

																				goMap.states[liStateOrd].cities.push( new MapCity(lName) );

																			}

																			

																			goMap.states[liStateOrd].loadCityStatus = goMap.constants.loadStatus.isDone;

																			

																			if (goMap.status.state != null) goMap.tools.PopulateCityOptions();

																		}

																	}

										

										request.send(null);

									}

								}

		

		this.LoadSale = function( pMapSale ) {

							goMap.sales.push( pMapSale );

							

							var liSale = goMap.sales.length - 1;

							var sale = goMap.sales[liSale];

							

							sale.loadMarkerStatus = goMap.constants.loadStatus.isLoading;

							

							if (sale.coded) {

								sale.wtext = goMap.tools.CreateSaleWindow( [sale] );

								sale.watext = goMap.tools.CreateSaleWindowA( [sale] );

								sale.wrtext = goMap.tools.CreateSaleWindowR( [sale] );

								sale.marker = goMap.tools.CreateSaleMarker( sale );

								sale.loadMarkerStatus = goMap.constants.loadStatus.isDone;

							} else {

								var address = (sale.address + ', ' + sale.city + ', ' + sale.state);

								var point = goMap.geocoder.getLatLng( address, function(point) {

										if (point) {

											sale.center = point;

											goMap.tools.UpdateGeocode( sale );

										}

										

										sale.wtext = goMap.tools.CreateSaleWindow( [sale] );

										sale.watext = goMap.tools.CreateSaleWindowA( [sale] );

										sale.wrtext = goMap.tools.CreateSaleWindowR( [sale] );

										sale.marker = goMap.tools.CreateSaleMarker( sale );

										sale.loadMarkerStatus = goMap.constants.loadStatus.isDone;

									} );

							}

						}

		

		this.ParseSaleData = function( pSales, piState, piCity, piZip ) {

			

									for (var i = 0; i < pSales.length; i++) {

										var lsID = pSales[i].getAttribute("id");

										var liSaleOrd = goMap.tools.GetSale( parseInt(lsID) );

										

										if (liSaleOrd == null) {

											var lsName = pSales[i].getAttribute("name");

											var lsShortDescription = pSales[i].getAttribute("description_short");

											var lsLongDescription = pSales[i].getAttribute("description_long");

											var lsAddress = pSales[i].getAttribute("address");

											var lsSubdivision = pSales[i].getAttribute("subdivision");

											var lsCity = pSales[i].getAttribute("city");

											var lsState = pSales[i].getAttribute("state");

											var lsZip = pSales[i].getAttribute("zip");

											var lsPhone = pSales[i].getAttribute("phone");

											var lsType = pSales[i].getAttribute("type");

											var lsLat = pSales[i].getAttribute("latitude");

											var lsLng = pSales[i].getAttribute("longitude");

											var lsStart = pSales[i].getAttribute("start");

											var lsEnd = pSales[i].getAttribute("end");

											var lsSday = pSales[i].getAttribute("start_day");

											var lsEday = pSales[i].getAttribute("end_day");

											var lsIsCoded = pSales[i].getAttribute("iscoded");

											var lsIsMine = pSales[i].getAttribute("ismine");

											if (lsIsMine === null){

												lsIsMine = 'no';

											}



											var loSale = new MapSale( parseInt(lsID), lsName, lsShortDescription, lsLongDescription, lsAddress, lsSubdivision, lsCity, lsState, lsZip, lsPhone, lsType, parseFloat(lsLat), parseFloat(lsLng), lsStart, lsEnd, lsSday, lsEday, goMap.tools.Convert2Boolean(lsIsCoded), lsIsMine ); 

											if (piState == null) piState = goMap.tools.GetState( lsState );

											

											//  add to my sales and generate the number for the marker

											//	var mySales = new Array();

											//	var mySalesIDs = new Array();



											if (mySalesIDs[loSale.id] === undefined){

												if (mySales.length == 0){

													var myNum = 1;

												}else{

													var myNum = mySales.length;

												}

												mySales[myNum] = loSale;

												mySalesIDs[loSale.id] = myNum;

												loSale.dnum = myNum;

											}else{

												loSale.dnum = mySalesIDs[loSale.id];												

											}

											

											goMap.tools.LoadSale( loSale );

										}else{

											liSaleOrd.isCurrentLocation = true;

										}

										

										if (liSaleOrd == null) liSaleOrd = goMap.tools.GetSale( parseInt(lsID) );

										clearSearch();

										goMap.tools.UpdateSaleCollections( liSaleOrd, piState, piCity, piZip );

									}

								}

		

		this.LoadStateSaleData = function( psState ) {

										if (psState != null) {

											var path = "http://" + gsURL + "/data_sales.php?state=" + psState;

											var request = GXmlHttp.create();

											

											request.open("GET", path, true);

											request.onreadystatechange = function() {

																			if (request.readyState == 4) {

																				var xmlDoc = request.responseXML;

																				var lsStateName = xmlDoc.documentElement.getAttribute("name");

																				var lsStateCode = xmlDoc.documentElement.getAttribute("code");

																				var lsStateLat = xmlDoc.documentElement.getAttribute("lat");

																				var lsStateLng = xmlDoc.documentElement.getAttribute("lng");

																				var lsStateZoom = xmlDoc.documentElement.getAttribute("zoom");

																				

																				var liStateOrd = goMap.tools.GetState( psState );

																				if (liStateOrd == null) {

																					goMap.states.push( new MapState( lsStateName, lsStateCode, parseFloat(lsStateLat), parseFloat(lsStateLng), parseInt(lsStateZoom) ) );

																					liStateOrd = goMap.states.length - 1;

																				}

																				

																				goMap.status.state = liStateOrd;

																				

																				if (goMap.states[liStateOrd].loadSaleStatus == goMap.constants.loadStatus.isReady) {

																					goMap.states[liStateOrd].loadSaleStatus = goMap.constants.loadStatus.isLoading;

																					goMap.tools.ParseSaleData( xmlDoc.documentElement.getElementsByTagName("sale"), liStateOrd, null, null );

																					goMap.states[liStateOrd].loadSaleStatus = goMap.constants.loadStatus.isDone;

																				}

																				

																				if (liStateOrd == goMap.status.state) {

																					if (goMap.status.markerInterval != null) {

																						clearInterval( goMap.status.markerInterval );

																						goMap.status.markerInterval = null;

																					}

																					

																					goMap.status.markerInterval = setInterval(goMap.tools.DisplayState, 500);

																				}

																			}

																		}

											

											request.send(null);

										}

									}

		

		this.LoadCitySaleData = function() {

										if (goMap.status.city != null && goMap.status.state != null) {

											var liStateOrd = goMap.status.state;

											var liCityOrd = goMap.status.city;

											

											var path = "http://" + gsURL + "/data_sales.php?city=" + goMap.states[liStateOrd].cities[liCityOrd].name + "&state=" + goMap.states[liStateOrd].code;

											var request = GXmlHttp.create();

											

											request.open("GET", path, true);

											request.onreadystatechange = function() {

																			if (request.readyState == 4) {

																				if (liStateOrd != null && liCityOrd != null) {

																					var xmlDoc = request.responseXML;

																					var lsCityName = xmlDoc.documentElement.getAttribute("state");

																					var lsCityLat = xmlDoc.documentElement.getAttribute("lat");

																					var lsCityLng = xmlDoc.documentElement.getAttribute("lng");

																					var lsCityZoom = xmlDoc.documentElement.getAttribute("zoom");

																					

																					goMap.states[liStateOrd].cities[liCityOrd].center = new GLatLng( parseFloat(lsCityLat), parseFloat(lsCityLng) );

																					goMap.states[liStateOrd].cities[liCityOrd].zoom = parseInt(lsCityZoom);

																					

																					if (goMap.states[liStateOrd].cities[liCityOrd].loadSaleStatus == goMap.constants.loadStatus.isReady) {

																						goMap.states[liStateOrd].cities[liCityOrd].loadSaleStatus = goMap.constants.loadStatus.isLoading;

																						goMap.tools.ParseSaleData( xmlDoc.documentElement.getElementsByTagName("sale"), liStateOrd, liCityOrd, null );

																						goMap.states[liStateOrd].cities[liCityOrd].loadSaleStatus = goMap.constants.loadStatus.isDone;

																					}

																				}

																				

																				if (liStateOrd == goMap.status.state && liCityOrd == goMap.status.city) {

																					if (goMap.status.markerInterval != null) {

																						clearInterval( goMap.status.markerInterval );

																						goMap.status.markerInterval = null;

																					}

																					

																					goMap.status.markerInterval = setInterval(goMap.tools.DisplayCity, 500);

																				}

																			}

																		}

											

											request.send(null);

										}

									}

		

		this.LoadZipSaleData = function( psZip ) {

									if (psZip != null) {

										var path = "http://" + gsURL + "/data_sales.php?zip=" + psZip;

										var request = GXmlHttp.create();

										

										request.open("GET", path, true);

										request.onreadystatechange = function() {

																		if (request.readyState == 4) {

																			var xmlDoc = request.responseXML;

																			var lsZipState = xmlDoc.documentElement.getAttribute("state");

																			var lsZipLat = xmlDoc.documentElement.getAttribute("lat");

																			var lsZipLng = xmlDoc.documentElement.getAttribute("lng");

																			var lsZipZoom = xmlDoc.documentElement.getAttribute("zoom");

																			

																			var liZipOrd = goMap.tools.GetZip( psZip );

																			if (liZipOrd == null) {

																				goMap.zips.push( new MapZip( psZip, lsZipState, parseFloat(lsZipLat), parseFloat(lsZipLng), parseInt(lsZipZoom) ) );

																				liZipOrd = goMap.zips.length - 1;

																			}

																			

																			goMap.status.zip = liZipOrd;

																			

																			if (goMap.zips[liZipOrd].loadSaleStatus == goMap.constants.loadStatus.isReady) {

																				goMap.zips[liZipOrd].loadSaleStatus = goMap.constants.loadStatus.isLoading;

																				goMap.tools.ParseSaleData( xmlDoc.documentElement.getElementsByTagName("sale"), null, null, liZipOrd );

																				goMap.zips[liZipOrd].loadSaleStatus = goMap.constants.loadStatus.isDone;

																			}

																			

																			if (liZipOrd == goMap.status.zip) {

																				if (goMap.status.markerInterval != null) {

																					clearInterval( goMap.status.markerInterval );

																					goMap.status.markerInterval = null;

																				}

																				

																				goMap.status.markerInterval = setInterval(goMap.tools.DisplayZip, 500);

																			}

																		}

																	}

										

										request.send(null);

									}

								}

		

		return this;

	}

	

	

	function MapChangeState(state) {

		MapUpdateStatusMessage( "Loading state data...", 1 );

		goMap.tools.ClearLocation( "state" );

		

		var loState = document.getElementById( "state" );

		var lsState = (loState) ? loState.value : "";

		if (state){

			lsState = state;

		}

		

		if (lsState.length == 0) {

			goMap.status.state = null;

			goMap.map.setCenter( goMap.center, goMap.zoom );

			

			var loPanel = document.getElementById("city_panel");

			if (loPanel) loPanel.style.visibility = "hidden";

			

			MapUpdateStatusMessage( null, 0 );

		} else {

			goMap.status.state = goMap.tools.GetState( lsState );

			

			var liLoadStatus = (goMap.status.state == null) ? goMap.constants.loadStatus.isReady : goMap.states[goMap.status.state].loadSaleStatus;

			if (liLoadStatus == goMap.constants.loadStatus.isReady) {

				goMap.tools.LoadStateSaleData( lsState );

			} else {

				goMap.tools.DisplayState();

			}

		}

	}

	

	

	function MapChangeCity(city) {

		MapUpdateStatusMessage( "Loading city data...", 1 );

		goMap.tools.ClearLocation( "city" );

				

		var loCity = document.getElementById( "city" );

		var lsCity = (loCity) ? loCity.value : "";

		if (city){

			lsCity = city;

		}

		

		if (lsCity.length == 0) {

			goMap.status.city = null;

			goMap.map.setCenter( goMap.states[goMap.status.state].center, goMap.states[goMap.status.state].zoom );

			

			MapUpdateStatusMessage( null, 0 );

			MapChangeState();

		} else {

			goMap.status.city = parseInt(lsCity);

			

			if (goMap.states[goMap.status.state].cities[goMap.status.city].loadSaleStatus == goMap.constants.loadStatus.isReady) {

				goMap.tools.LoadCitySaleData();

			} else {

				goMap.tools.DisplayCity();

			}

		}

	}

	

	

	function MapChangeZip( obj ) {

		MapUpdateStatusMessage( 'Loading zipcode data...', 1 );

		goMap.tools.ClearLocation( "zip" );

				

		var loZip = document.getElementById( "zip" );

		var lsZip = (loZip) ? loZip.value : "";

		

		if (lsZip.length == 5) {

			goMap.status.zip = goMap.tools.GetZip( lsZip );

			

			var liLoadStatus = (goMap.status.zip == null) ? goMap.constants.loadStatus.isReady : goMap.zips[goMap.status.zip].loadSaleStatus;

			if (liLoadStatus == goMap.constants.loadStatus.isReady) {

				goMap.tools.LoadZipSaleData( lsZip );

			} else {

				goMap.tools.DisplayZip();

			}

		} else {

			MapUpdateStatusMessage( 'You must enter a valid zip code!', 3 );

			alert('You must enter a valid 5-digit zip code!');

		}

		

	}

	

	

	function MapUpdateStatusMessage( msg, icon ) {

		var obj = document.getElementById( "statusmsg" );

		if (obj) obj.innerHTML = (msg == null) ? "" : msg;

		

		var obj = document.getElementById( "statusimg" );

		if (obj) {

			var file;

			

			switch(icon) {

				case 1:

					file = 'rotate.gif';

					break;

				case 2:

					file = 'error.gif';

					break;

				case 3:

					file = 'exclamation.gif';

					break;

				default:

					file = 'comment.gif';

					break;

			}

			

			obj.src = "images/map/" + file;

		}

	}

	

	// Create Loading Div to match this

	function MapDisableLocatorControls() {

		var loLoading = document.getElementById( "sidebar_select_location_loading" );

		if (loLoading) loLoading.style.display = "block";

		

		var loFormBox = document.getElementById( "sidebar_select_location" );

		if (loFormBox) loFormBox.style.visibility = "hidden";

	}

	

	

	function MapEnableLocatorControls() {

		var loLoading = document.getElementById( "sidebar_select_location_loading" );

		if (loLoading) loLoading.style.display = "none";

		

		var loFormBox = document.getElementById( "sidebar_select_location" );

		if (loFormBox) loFormBox.style.visibility = "visible";

	}



	// Direction Functions

	function AddToRoute(id, revealSale){

		var error = false;

		if (id !== undefined){

			if (typeof(id) == "number"){

				if (id > 0){

					if (mySalesIDs[id]){

						if (typeof(mySales[mySalesIDs[id]]) == "object"){

							if (!myRouteList[id]){

								myRouteList[id] = mySales[mySalesIDs[id]];

								myRouteList[id].rnum = nextRouteNum++;

								goMap.tools.UpdateSaleMarker(mySales[mySalesIDs[id]]);

								BuildRouteList();

								if (revealSale){

									goMap.tools.RevealSale(id);

								}

							}

							return true;

						}else{

							error = id + ' not in mySales list at position ' + mySalesIDs[id];

						}

					}else{

						error = id + ' not in mySalesIDs list';

					}

				}else{

						error = '! id > 0';

				}

			}else{

					error = 'id != number';

			}

		}else{

				error = 'id is undefined';

		}

		return error;

	}



	function MoveInRoute(id, how, skipBuild){

		//How: + is down, - is up number is how far

		if (myRouteList[id] !== undefined){

			if (myRouteList[id].rnum !== null){

				if ( how !== Number.NaN ){

					how = Math.round(how); // No decimals

					var newRnum = false;

					var current = myRouteList[id].rnum;

					if (how > 0){

						if (current + how >= nextRouteNum){

							newRnum = nextRouteNum-1;

						}else{

							newRnum = current + how;

						}

					}else if (how < 0){

						if (current + how < 1){

							newRnum = 1;

						}else{

							newRnum = current + how;

						}						

					}

					if (newRnum){

						for (var i = 1; i < myRouteList.length; i++){

							if (typeof(myRouteList[i]) == "object" && myRouteList[i] !== null){

								if (myRouteList[i].rnum !== null){

									if (how > 0){

										if (myRouteList[i].rnum > current && myRouteList[i].rnum <= newRnum){

											myRouteList[i].rnum = myRouteList[i].rnum - 1;

										}

									}else if (how < 0){

										if (myRouteList[i].rnum < current && myRouteList[i].rnum >= newRnum){

											myRouteList[i].rnum = myRouteList[i].rnum + 1;

										}

									}

								}

							}

						}

						myRouteList[id].rnum = newRnum;

						if (!skipBuild){

							BuildRouteList();

						}

						return true;

					}

				}

			}

		}

		return false;		

	}

	

	function RemoveFromRoute(id){

		if (myRouteList[id] !== undefined){

			if (myRouteList[id].rnum !== null){

				MoveInRoute(id,nextRouteNum,true); // Could compute the new value, but the Move function will fix it for me anyway.

				myRouteList[id].rnum = null;

				goMap.tools.UpdateSaleMarker(myRouteList[id]);

				myRouteList[id] = null;

				nextRouteNum--;

				BuildRouteList();

				if (goMap.tools.currentTab == 'route'){

					setTab('route');

				}else{

					goMap.tools.RevealSale(id);	

				}

				return true;

			}

		}

		return false;

	}

	

	function ClearRoute(){

		var routeIdList = getMyRouteList();

		var i;

		for (i = 1; i < myRouteList.length; i++){

			if (typeof(myRouteList[i]) == "object" && myRouteList[i] !== null){

				myRouteList[i] = null;

				nextRouteNum--;

			}

		}

		BuildRouteList();

		if (goMap.tools.currentTab == 'route'){

			setTab('route');

		}

	}

	

	function BuildRouteList(){

		var routeHTML = '';

		var routeIdList = getMyRouteList();

		var i;

		

		var salesRoute = document.getElementById('sales_route');

		

		salesRoute.value = '';

		

		for (i = 1; i < routeIdList.length; i++){

			if (routeIdList[i]){

				routeHTML += 	'<div id="record">' +

								'<table cellspacing="0" cellpadding="0" border="0" width="100%">' +

								'<tbody><tr><td width="30" valign="top">' +

								'<img src="'+ myRouteList[routeIdList[i]].image+'"/></td>' +

								'<td valign="top"><span class="listing_text">' +

								'<a href="#" onclick="javascript:goMap.tools.RevealSale(' + myRouteList[routeIdList[i]].id + ')"> '+ myRouteList[routeIdList[i]].address + '</a> - ' + myRouteList[routeIdList[i]].shortdescription + '</span></td>' +

								'<td width="28" valign="top"><div id="remove" onclick="RemoveFromRoute('+myRouteList[routeIdList[i]].id+')"><img src="http://garagesalefinder.com/images/remove.gif" alt="Remove From Route" name="remove" width="16" height="16" border="0" id="remove"</div></td>' +

								'<td width="10"><div class="handle"><div style="height:15px;" ' +

								'onclick="MoveInRoute('+myRouteList[routeIdList[i]].id+","+-1+')"></div>' +

								'<div style="height:15px;" onclick="MoveInRoute('+myRouteList[routeIdList[i]].id+","+1+')"></div>' +

								'</div></td>' +

								'</tr></tbody></table></div>'+"\n";

				if (salesRoute.value == ''){

						salesRoute.value = myRouteList[routeIdList[i]].id;

				}else{

						salesRoute.value += ',' + myRouteList[routeIdList[i]].id;

				}

			}

		}

		

		var routeDiv = document.getElementById('route_listings');

		routeDiv.innerHTML = routeHTML;

		

		// NEED TO UPDATE MARKERS

	}

	

	function getRouteDirections(){



		var routeIDlist = getMyRouteList();

		if (routeIDlist.length >= 1 && routeIDlist.length <= 23){



			var frmRoute = document.getElementById('frmRoute');

			

			frmRoute.submit();

			return true;

		}else{

			if (routeIDlist.length < 1){

				alert ('Please add at least 1 sale to the route list.');

			}else{

				alert ('There are too many sales in your route list.  Please reduce the number of sales to 23 or less to get directions.');

			}

		}

	}

	

	function getSalesDetails(type){

		var salesList = document.getElementById('sales_listings');

		if (salesList && salesList.value != ''){



			var frmSalesListings = document.getElementById('frmSalesListings');



			if (type){

				var output = document.getElementById('sales_listings_output');

				output.value = type;

				if (type == 'xml'){

					frmSalesListings.action = 'listing_details.xml';	

				}else if (type == 'kml'){

					frmSalesListings.action = 'listing_details.kml';	

				}else if (type == 'csv'){

					frmSalesListings.action = 'listing_details.csv';	

				}else{

					frmSalesListings.action = 'listing_details.php';	

				}

			}

				

			frmSalesListings.submit();

			return true;

		}else{

			alert('There must be results showing in the sales list in order to preform this function.');	

		}

	}



function getMyRouteList(){

		var routeIdList = new Array();

		var i;

		for (i = 1; i < myRouteList.length; i++){

			if (typeof(myRouteList[i]) == "object" && myRouteList[i] !== null){

				if (myRouteList[i].rnum !== null){

					routeIdList[myRouteList[i].rnum] = i;

				}

			}

		}

		return routeIdList;

	}

	

	function setTab(which){

		//setTab('location')

		//setTab('sales')

		//setTab('route')

		

		goMap.tools.SwitchTabs(which);

		

	}



	function setDays(which, on){

		if (which === 'ALL'){

			for (i = 0; i <= 6; i++){

				days[i] = on;

			}

			days[7] = on;

		}else if(IsNumeric(which) && which >= 0 && which <= 6){

			if (days[7]){

				setDays('ALL',false);

			}

			days[Math.floor(which)] = on;

		}

	}



	function clickDay(which){

		if (which !== 'ALL'){

			// Switch Day on/off

			if(IsNumeric(which) && which >= 0 && which <= 6){

				setDays(which,!days[Math.floor(which)] || days[7]);

			}

		}else{

			// or Set All on/off

			setDays(which,!days[7]);

		}

		// Update images

		var imgSrc = 'images/';

		var imgOn = '-on.jpg';

		var imgOff = '-off.jpg';

		var imgID = 'imgDate';

		var imgNameID = 'imgDateName';

		var imgName = false;

		if (days[7]){

				document.getElementById(imgID+'ALL').src = imgSrc+'all'+imgOn;

		}else{

				document.getElementById(imgID+'ALL').src = imgSrc+'all'+imgOff;

		}

		for (i = 0; i <= 6; i++){

			imgName = document.getElementById(imgNameID+i).value;

			if (days[i] && !days[7]){

				document.getElementById(imgID+i).src = imgSrc+imgName+imgOn;

			}else{

				document.getElementById(imgID+i).src = imgSrc+imgName+imgOff;

			}

		}

		// Update Listing and Icons

		goMap.tools.BuildSalesTab();

	}



	function searchInCurrentItems(){

		

		var i;

		var query = document.getElementById('search_field');

		query = query.value;

		clearSearch();

		if (query !== ''){

			var pattern = RegExp(query,'i');

			

			isInSearch = true;		

			

			for (i = 0; i < goMap.sales.length; i++){

			

				if (goMap.sales[i] && goMap.sales[i].isCurrentLocation){

					if (goMap.sales[i].description.search(pattern) !== -1){

						goMap.sales[i].matchSearch = true;

					}

				}

	

			}

			

			goMap.tools.BuildSalesTab();

		}

	}

	

	function clearSearchAll(){

		var query = document.getElementById('search_field');

		query.value = '';

		clearSearch();

		goMap.tools.BuildSalesTab();

	}



	function clearSearch(){

		for (i = 0; i < goMap.sales.length; i++){

			goMap.sales[i].matchSearch = false;

		}

		isInSearch = false;		

	}

	

	var SELECTED_DISPLAY_STATUS = 0;

	function DisplaySelectedArea(){

		// SELECTED_STATE = '<?=$_REQUEST['state']?>';

		// SELECTED_CITY = '<?=str_replace('+',' ',str_replace("'","\\'",$_REQUEST['city']))?>';

		if (SELECTED_AREA){

			if (SELECTED_DISPLAY_STATUS == 0){

				var elem = document.getElementById('state');

				var i = 0;

				for (i = 0; i < elem.options.length; i++){

					if (elem.options[i].value == SELECTED_STATE){

						elem.options[i].selected = true;	

					}

				}

				MapChangeState(SELECTED_STATE);

			}else if (SELECTED_DISPLAY_STATUS == 1){

				var elem = document.getElementById('city');

				var i = 0;

				var found = false;

				for (i = 0; i < elem.options.length; i++){

					if (elem.options[i].text == SELECTED_CITY){

						elem.options[i].selected = true;	

						found = true;

					}

				}

				if (found){

					MapChangeCity();

				}else{

					alert('Sorry, there are no sales in or near ' + SELECTED_CITY + ' at this time.');

				}

			}

			SELECTED_DISPLAY_STATUS++;

		}

		

	}

	

	// Support 

	

function IsNumeric(strString)

   //  check for valid numeric strings	

   {

   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;

   }

