/*

	If you would like a site built like this one, please contact Thomas Forrester at Thomas@ThomasForrester.info
	or by phone (919) 349 - 3669 .  I will be happy to create your site next!
	
	Website Programming by an all around computer specialist: Thomas Forrester -- Your Computer Solutions Expert!

*/

	var goMap;
	var gsURL = document.domain;
	
	if (window.navigator.userAgent.indexOf("MSIE") <= 0) {
		HTMLElement.prototype.__defineGetter__( "innerText", function () { return(this.textContent); } );
		HTMLElement.prototype.__defineSetter__( "innerText", function (txt) { this.textContent = txt; } );
	}

	var myEvents = new Array();
	var myEventsIDs = 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 map_div = false;
	var map_loading_div = false;
	
	var debug;
	
	function MapSearchStart(){
		if (!map_div || !map_loading_div){
			map_div = document.getElementById('map');
			map_loading_div = document.getElementById('map_loading');
		}
		map_div.style.display = 'none';
		map_loading_div.style.display = 'block';
	}
	function MapSearchComplete(){
		if (!map_div || !map_loading_div){
			map_div = document.getElementById('map');
			map_loading_div = document.getElementById('map_loading');
		}
		map_loading_div.style.display = 'none';
		map_div.style.display = 'block';
	}

	function LoadMap() {
		MapUpdateStatusMessage( "Loading map...", 1 );
		var mapDIV = document.getElementById('map');
		if (mapDIV){
			mapDIV.style.backgroundImage = '';
		}
		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.showControls();
			//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 );
			mapLoaded = true;
			goMap.ListingSorter = new MapListingSorter();
			doLoad();
			/*
			for (var el in document.all){
				document.all[el].keydown = function (e) {  
												if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
													doSearch();
													return false;  
												} else {  
													return true;  
												} 
											};
			}
			*/
			document.onkeyup = function (e) {
									if ( typeof e == "undefined" ) e = window.event;
									wkey = e.keyCode;
									if ( document.layers ) wkey = e.which;
									if (wkey == 13) doSearch();

									/*
									if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
										doSearch();
										return false;  
									} else {  
										return true;  
									}
									*/
								};
		}else{
			var mapDiv = document.getElementById('map');
			mapDiv.innerHTML = 'Sorry, your browser isn\'t compatible with Google Maps.';
		}
	}
	
	
	function MapListingSorter(){
		this.dateList = new Array();
		this.dateArray = new Array();
		this.resultslist = document.getElementById( "tab_results_body" );
		
		this.splitDate = function (date){
			var dateArray = new Array();
			dateArray = date.split('-');
			var retArray = new Array();
			retArray[0] = dateArray[2];
			retArray[1] = dateArray[0];
			retArray[2] = dateArray[1];
			return retArray;
		}
		
		this.dateCompare = function (datea, dateb){
			var first = true;
			if (datea.year > dateb.year){
				first = true;
			}else if (datea.year < dateb.year){
				first = false;
			}else{
				if (datea.month > dateb.month){
					first = true;
				}else if (datea.month < dateb.month){
					first = false;
				}else{
					if (datea.day > dateb.day){
						first = true;
					}else{
						first = false;
					}
				}
			}
			return first;
		}
		
		this.getDateDiv = function (date){
			
			var datedetails = this.splitDate(date);
			var dates = new Object;
			dates.year = datedetails[0];
			dates.month = datedetails[1];
			dates.day = datedetails[2];
			var set = true;
			if (!this.dateArray[dates.year]){
				set = false;
			}
			if (set && !this.dateArray[dates.year][dates.month]){
				set = false;
			}
			if (set && this.dateArray[dates.year][dates.month][dates.day]){
				return this.dateArray[dates.year][dates.month][dates.day];
			}else{
				return this.insertDate(date);
			}
		}
		
		this.insertDate = function (date){
			dated = document.createElement('DIV');
			datep = document.createElement("P");
			//<p align="center" class="results_date">11/01/2009</p>
			datep.innerHTML = date;
			datep.align = 'center';
			datep.className = 'results_date';
			dated.appendChild(datep);
			var datedetails = this.splitDate(date);
			dated.year = datedetails[0];
			dated.month = datedetails[1];
			dated.day = datedetails[2];
			dated.date = date;
			dated.datep = datep;
			this.dateList.push(dated);
			if (this.dateList.length == 1){
				dated.PREV = null;
				dated.NEXT = null;
				this.resultslist.appendChild(dated);
			}else{
				if (this.dateList.length == 2){
					dated.PREV = this.dateList[0];
					dated.NEXT = this.dateList[0];
					this.dateList[0].PREV = dated;
					this.dateList[0].NEXT = dated;
					var first = this.dateCompare(this.dateList[0], dated.year);
					if (first){
						this.resultslist.insertBefore(dated,this.dateList[0]);
					}else{
						this.resultslist.appendChild(dated);
					}
				}else{
					// find date after this one
					var searchDate = this.dateList[this.dateList.length - 2];
					//var lastDate = searchDate;
					var before = null;
					var after = null;
					var first = null;
					var firstTry = true;
					while (before == null || after == null){
						first = this.dateCompare(searchDate,dated);
						if (first){
							if (firstTry == true){
								firstTry = searchDate;
							}else{
								if (firstTry == searchDate){
									after = '';
								}
							}
							if (!before){
								before = searchDate;
							}else{
								if (this.dateCompare(before,searchDate)){
									before = searchDate;
								}
							}
							searchDate = searchDate.PREV;
						}else{
							if (firstTry == true){
								firstTry = searchDate;
							}else{
								if (firstTry == searchDate){
									before = '';
								}
							}
							if (!after){
								after = searchDate;
							}else{
								if (this.dateCompare(searchDate,after)){
									after = searchDate;
								}
							}
							searchDate = searchDate.NEXT;
						}
					}
					var append = false;
					if (before == ''){
						before = after.NEXT;
						append = true;
					}
					if (after == ''){
						after = before.PREV;
					}
					
					dated.PREV = after;
					dated.NEXT = before;
					before.PREV = dated;
					after.NEXT = dated;
					if (!append){
						this.resultslist.insertBefore(dated,before);
					}else{
						this.resultslist.appendChild(dated);
					}
				}
			}
			if (!this.dateArray[dated.year]){
				this.dateArray[dated.year] = new Array();
			}
			if (!this.dateArray[dated.year][dated.month]){
				this.dateArray[dated.year][dated.month] = new Array();
			}
			this.dateArray[dated.year][dated.month][dated.day] = dated;
			debug += 'Added: '+date+' ';
			return dated;
		}
		
		
		this.addEvent = function (date, eventp){
			var dated = this.getDateDiv(date);
			dated.appendChild(eventp);
		}
		
		this.showDates = function (dates){
			this.hideDates();
			// Array of dates
			var dateDiv = null;
			for (var i = 0; i < dates.length; i++){
				dateDiv = this.getDateDiv(dates[i]);
				if (dateDiv){
					dateDiv.style.display = 'block';
				}
			}
		}
		
		this.hideDates = function (date){
			for (var i = 0; i < this.dateList.length; i ++){
				this.dateList[i].style.display = 'none';
			}
		}
		
	}
	
	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.eVents = new Array();
		this.states = new Array();
		this.zips = new Array();
		
		return this;
	}
	
	
	function MapIcons() {


		// Initialize all of the racing icons
		adventure = new GIcon(G_DEFAULT_ICON);
		adventure.image = 'icons/adventure.png';
		adventure.shadow = 'icons/adventure_s.png';
		adventure.iconSize = new GSize(39,43);
		adventure.shadowSize = new GSize(61,43);
		adventure.iconAnchor = new GPoint(20,43);
		adventure.infoWindowAnchor = new GPoint(20,0);
		adventure.printImage = 'icons/adventure_printImage.gif';
		adventure.mozPrintImage = 'markers/mozPrintImage.gif';
		adventure.printShadow = 'icons/adventure_print_s.gif';
		adventure.transparent = 'icons/adventure_transparent.png';
		adventure.imageMap = [22,0,25,1,28,2,29,3,30,4,31,5,32,6,33,7,33,8,33,9,33,10,34,11,34,12,34,13,34,14,34,15,33,16,33,17,33,18,33,19,32,20,32,21,32,22,31,23,31,24,32,25,33,26,33,27,34,28,38,29,38,30,37,31,31,32,25,33,25,34,24,35,23,36,23,37,22,38,21,39,20,40,19,41,19,42,14,42,13,41,12,40,11,39,11,38,10,37,9,36,8,35,8,34,7,33,6,32,6,31,5,30,4,29,4,28,3,27,3,26,2,25,2,24,1,23,1,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,1,5,2,4,3,3,4,2,7,1,11,0];
		this.adventure = adventure;
		
		cycling = new GIcon(G_DEFAULT_ICON);
		cycling.image = 'icons/cycling.png';
		cycling.shadow = 'icons/cycling_s.png';
		cycling.iconSize = new GSize(47,43);
		cycling.shadowSize = new GSize(69,43);
		cycling.iconAnchor = new GPoint(24,43);
		cycling.infoWindowAnchor = new GPoint(24,0);
		cycling.printImage = 'icons/cycling_printImage.gif';
		cycling.mozPrintImage = 'icons/cycling_mozPrintImage.gif';
		cycling.printShadow = 'icons/cycling_print_s.gif';
		cycling.transparent = 'icons/cycling_transparent.png';
		cycling.imageMap = [28,0,32,1,34,2,36,3,37,4,38,5,40,6,42,7,42,8,42,9,41,10,40,11,40,12,40,13,40,14,40,15,40,16,40,17,40,18,43,19,44,20,45,21,45,22,45,23,45,24,45,25,44,26,43,27,40,28,35,29,34,30,33,31,33,32,32,33,31,34,31,35,30,36,29,37,29,38,28,39,27,40,26,41,25,42,21,42,20,41,19,40,18,39,17,38,17,37,16,36,15,35,14,34,14,33,13,32,12,31,12,30,11,29,6,28,3,27,2,26,1,25,1,24,1,23,1,22,1,21,2,20,3,19,6,18,6,17,6,16,5,15,5,14,5,13,5,12,5,11,5,10,6,9,6,8,6,7,7,6,8,5,9,4,10,3,11,2,14,1,18,0];
		this.cycling = cycling;
		
		kayak = new GIcon(G_DEFAULT_ICON);
		kayak.image = 'icons/kayak.png';
		kayak.shadow = 'icons/kayak_s.png';
		kayak.iconSize = new GSize(71,43);
		kayak.shadowSize = new GSize(93,43);
		kayak.iconAnchor = new GPoint(36,43);
		kayak.infoWindowAnchor = new GPoint(36,0);
		kayak.printImage = 'icons/kayak_printImage.gif';
		kayak.mozPrintImage = 'icons/kayak_mozPrintImage.gif';
		kayak.printShadow = 'icons/kayak_print_s.gif';
		kayak.transparent = 'icons/kayak_transparent.png';
		kayak.imageMap = [38,0,42,1,45,2,46,3,47,4,48,5,49,6,50,7,50,8,50,9,51,10,51,11,51,12,51,13,51,14,51,15,50,16,50,17,50,18,68,19,69,20,70,21,70,22,70,23,70,24,47,25,47,26,46,27,46,28,45,29,44,30,44,31,43,32,43,33,42,34,41,35,40,36,40,37,39,38,38,39,37,40,37,41,36,42,31,42,30,41,30,40,29,39,28,38,27,37,26,36,26,35,25,34,24,33,24,32,23,31,22,30,22,29,21,28,21,27,20,26,19,25,0,24,0,23,4,22,8,21,8,20,17,19,17,18,16,17,16,16,16,15,16,14,16,13,16,12,16,11,16,10,16,9,17,8,17,7,17,6,18,5,19,4,20,3,22,2,24,1,28,0];
		this.kayak = kayak;
		
		mtBike = new GIcon(G_DEFAULT_ICON);
		mtBike.image = 'icons/mtBike.png';
		mtBike.shadow = 'icons/mtBike_s.png';
		mtBike.iconSize = new GSize(49,43);
		mtBike.shadowSize = new GSize(71,43);
		mtBike.iconAnchor = new GPoint(25,43);
		mtBike.infoWindowAnchor = new GPoint(25,0);
		mtBike.printImage = 'icons/mtBike_printImage.gif';
		mtBike.mozPrintImage = 'icons/mtBike_mozPrintImage.gif';
		mtBike.printShadow = 'icons/mtBike_print_s.gif';
		mtBike.transparent = 'icons/mtBike_transparent.png';
		mtBike.imageMap = [28,0,32,1,35,2,36,3,37,4,38,5,39,6,39,7,40,8,40,9,40,10,40,11,41,12,41,13,40,14,40,15,40,16,40,17,40,18,40,19,39,20,39,21,42,22,45,23,46,24,47,25,47,26,47,27,47,28,47,29,46,30,45,31,44,32,41,33,32,34,31,35,30,36,30,37,29,38,28,39,27,40,26,41,26,42,21,42,20,41,19,40,19,39,18,38,17,37,16,36,15,35,15,34,8,33,4,32,3,31,2,30,1,29,1,28,1,27,1,26,1,25,2,24,3,23,5,22,7,21,7,20,7,19,6,18,6,17,6,16,6,15,6,14,5,13,5,12,6,11,6,10,6,9,6,8,7,7,7,6,8,5,9,4,10,3,12,2,14,1,18,0];
		this.mtBike = mtBike;
		
		other = new GIcon(G_DEFAULT_ICON);
		other.image = 'icons/other.png';
		other.shadow = 'icons/other_s.png';
		other.iconSize = new GSize(43,43);
		other.shadowSize = new GSize(65,43);
		other.iconAnchor = new GPoint(22,43);
		other.infoWindowAnchor = new GPoint(22,0);
		other.printImage = 'icons/other_printImage.gif';
		other.mozPrintImage = 'icons/other_mozPrintImage.gif';
		other.printShadow = 'icons/other_print_s.gif';
		other.transparent = 'icons/other_transparent.png';
		other.imageMap = [29,0,33,1,35,2,37,3,38,4,39,5,40,6,40,7,41,8,41,9,41,10,41,11,41,12,41,13,41,14,41,15,41,16,41,17,41,18,40,19,40,20,40,21,39,22,39,23,38,24,38,25,37,26,37,27,36,28,36,29,36,30,39,31,38,32,33,33,32,34,32,35,31,36,30,37,30,38,29,39,28,40,27,41,26,42,22,42,21,41,20,40,19,39,19,38,18,37,17,36,16,35,16,34,15,33,14,32,13,31,13,30,12,29,12,28,11,27,10,26,0,25,0,24,1,23,3,22,4,21,8,20,7,19,7,18,7,17,7,16,6,15,6,14,6,13,6,12,6,11,6,10,7,9,7,8,7,7,8,6,9,5,10,4,11,3,12,2,15,1,19,0];
		this.other = other;
		
		run = new GIcon(G_DEFAULT_ICON);
		run.image = 'icons/run.png';
		run.shadow = 'icons/run_s.png';
		run.iconSize = new GSize(36,43);
		run.shadowSize = new GSize(58,43);
		run.iconAnchor = new GPoint(18,43);
		run.infoWindowAnchor = new GPoint(18,0);
		run.printImage = 'icons/run_printImage.gif';
		run.mozPrintImage = 'icons/run_mozPrintImage.gif';
		run.printShadow = 'icons/run_print_s.gif';
		run.transparent = 'icons/run_transparent.png';
		run.imageMap = [22,0,26,1,28,2,30,3,31,4,32,5,33,6,33,7,34,8,34,9,34,10,34,11,34,12,34,13,34,14,34,15,34,16,34,17,34,18,33,19,33,20,33,21,32,22,32,23,31,24,31,25,30,26,30,27,29,28,29,29,28,30,28,31,27,32,26,33,26,34,25,35,24,36,23,37,23,38,22,39,21,40,20,41,19,42,15,42,14,41,13,40,12,39,12,38,11,37,10,36,9,35,9,34,8,33,1,32,0,31,0,30,0,29,1,28,1,27,4,26,3,25,3,24,2,23,2,22,1,21,1,20,1,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,1,7,1,6,2,5,3,4,4,3,5,2,8,1,12,0];
		this.run = run;
		
		ski = new GIcon(G_DEFAULT_ICON);
		ski.image = 'icons/ski.png';
		ski.shadow = 'icons/ski_s.png';
		ski.iconSize = new GSize(56,43);
		ski.shadowSize = new GSize(78,43);
		ski.iconAnchor = new GPoint(28,43);
		ski.infoWindowAnchor = new GPoint(28,0);
		ski.printImage = 'icons/ski_printImage.gif';
		ski.mozPrintImage = 'icons/ski_mozPrintImage.gif';
		ski.printShadow = 'icons/ski_print_s.gif';
		ski.transparent = 'icons/ski_transparent.png';
		ski.imageMap = [33,0,38,1,40,2,42,3,43,4,46,5,48,6,49,7,49,8,49,9,48,10,47,11,46,12,46,13,46,14,46,15,46,16,46,17,46,18,45,19,45,20,45,21,44,22,44,23,43,24,46,25,55,26,54,27,41,28,41,29,40,30,39,31,39,32,38,33,37,34,37,35,36,36,35,37,35,38,34,39,33,40,32,41,31,42,26,42,25,41,24,40,24,39,23,38,22,37,21,36,21,35,20,34,19,33,18,32,18,31,17,30,17,29,16,28,15,27,13,26,5,25,1,24,13,23,13,22,12,21,12,20,12,19,0,18,0,17,3,16,10,15,11,14,11,13,11,12,11,11,11,10,11,9,11,8,12,7,12,6,13,5,14,4,15,3,17,2,19,1,24,0];
		this.ski = ski;
		
		tri = new GIcon(G_DEFAULT_ICON);
		tri.image = 'icons/tri.png';
		tri.shadow = 'icons/tri_s.png';
		tri.iconSize = new GSize(48,43);
		tri.shadowSize = new GSize(70,43);
		tri.iconAnchor = new GPoint(24,43);
		tri.infoWindowAnchor = new GPoint(24,0);
		tri.printImage = 'icons/tri_printImage.gif';
		tri.mozPrintImage = 'icons/tri_mozPrintImage.gif';
		tri.printShadow = 'icons/tri_print_s.gif';
		tri.transparent = 'icons/tri_transparent.png';
		tri.imageMap = [29,0,33,1,35,2,36,3,39,4,41,5,42,6,42,7,42,8,41,9,40,10,41,11,41,12,41,13,44,14,44,15,40,16,42,17,45,18,46,19,47,20,47,21,47,22,47,23,47,24,46,25,45,26,43,27,35,28,35,29,34,30,33,31,33,32,32,33,31,34,31,35,30,36,29,37,28,38,28,39,27,40,26,41,25,42,21,42,20,41,19,40,19,39,18,38,17,37,16,36,15,35,15,34,14,33,13,32,13,31,12,30,11,29,11,28,4,27,2,26,1,25,0,24,0,23,0,22,0,21,1,20,1,19,3,18,5,17,6,16,5,15,5,14,5,13,5,12,5,11,5,10,6,9,6,8,6,7,7,6,7,5,8,4,10,3,11,2,13,1,17,0];		
		this.tri = tri;

		multiple = new GIcon();
		multiple.image = 'icons/multiple.png';
		multiple.shadow = 'icons/multiple_s.png';
		multiple.iconSize = new GSize(36,43);
		multiple.shadowSize = new GSize(58,43);
		multiple.iconAnchor = new GPoint(18,43);
		multiple.infoWindowAnchor = new GPoint(18,0);
		multiple.printImage = 'icons/multiple_printImage.gif';
		multiple.mozPrintImage = 'icons/multiple_mozPrintImage.gif';
		multiple.printShadow = 'icons/multiple_print_s.gif';
		multiple.transparent = 'icons/multiple_transparent.png';
		multiple.imageMap = [23,0,27,1,29,2,30,3,32,4,32,5,33,6,34,7,34,8,34,9,35,10,35,11,35,12,35,13,35,14,35,15,34,16,34,17,34,18,34,19,33,20,33,21,32,22,32,23,32,24,31,25,31,26,30,27,29,28,29,29,28,30,28,31,27,32,26,33,26,34,25,35,24,36,23,37,23,38,22,39,21,40,20,41,19,42,15,42,14,41,13,40,12,39,11,38,11,37,10,36,9,35,8,34,8,33,7,32,6,31,6,30,5,29,4,28,4,27,3,26,3,25,2,24,2,23,1,22,1,21,1,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,1,6,1,5,2,4,3,3,5,2,7,1,11,0];
		this.multiple = multiple;

		var loEventIcon = new GIcon();
		loEventIcon.image = "images/map/icon_lpink.png";
		loEventIcon.shadow = "images/map/icon_shadow.png";
		loEventIcon.iconSize = new GSize(12, 20);
		loEventIcon.shadowSize = new GSize(22, 20);
		loEventIcon.iconAnchor = new GPoint(6, 20);
		loEventIcon.infoWindowAnchor = new GPoint(5, 1);

		var loEventMyIcon = new GIcon();
		loEventMyIcon.image = "images/map/icon_pink.png";
		loEventMyIcon.shadow = "images/map/icon_shadow.png";
		loEventMyIcon.iconSize = new GSize(12, 20);
		loEventMyIcon.shadowSize = new GSize(22, 20);
		loEventMyIcon.iconAnchor = new GPoint(6, 20);
		loEventMyIcon.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.eVent = loEventIcon;
		this.eVentmine = loEventMyIcon;
		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.eVents = new Array();
		
		this.loadCityStatus = goMap.constants.loadStatus.isReady;
		this.loadEventStatus = 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.eVents = new Array();
		
		this.loadEventStatus = 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.eVents = new Array();
		
		this.loadEventStatus = goMap.constants.loadStatus.isReady;
		
		this.isLoadedMarkers = false;
		this.isLoadedTabs = false;
		
		//this.eVentDistances = new Array();
		
		return this;
	}
	
	
	function MapEvent( pID, pName, pTitle, pSource, pAddress, pCity, pState, pZip, pWebsite, pType, pDistances, pLatitude, pLongitude, pStart, pSday, pDate, pTime, pDistance, pCoded, isMine ) {
		this.id = pID;
		this.name = pName;
		this.title = pTitle;
		this.source = pSource;
		this.address = pAddress;
		//this.subdivision = pSubdivision;
		this.city = pCity;
		this.state = pState;
		this.zip = pZip;
		this.website = pWebsite;
		this.type = pType;
		this.distances = pDistances;
		this.latitude = pLatitude;
		this.longitude = pLongitude;
		this.center = new GLatLng( pLatitude, pLongitude );
		this.date_start = pStart;
		//this.date_end = pEnd;
		this.sday = pSday;
		//this.eday = pEday;
		this.date = pDate;
		this.time = pTime;
		this.distance = pDistance;
		this.coded = pCoded;
		this.ismine = isMine;
		this.marker = null;
		this.isCurrentLocation = true;
		this.matchSearch = false;
		this.matchAddtlSearch = true;

		this.listp = false;
		this.wtext = null;
		this.tabs = false;
		//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 = "Zip Code";
								
								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.ClearEventMarkers();
						}
		
		this.CreateEventWindow = function( pEvents ) {
									var mEvent = '';
									if (pEvents.length == 1){
										var i = 0;
										mEvent += 	'<b>'+pEvents[i].title+'</b><br/><b>Distance:</b> '+pEvents[i].distances+'<br/><b> Date:</b> '+pEvents[i].date+'<br/>'+((pEvents[i].time == '12:00 AM')?'':'<b>Start Time:</b> '+pEvents[i].time+'<br/>')+'<b>Location:</b><br/> '+pEvents[i].address+((pEvents[i].address != '')?'<br/> ':'')+pEvents[i].city+', '+pEvents[i].state;
										if (pEvents[i].website != ''){
											mEvent += 	'<br/> <i><a href="'+pEvents[i].website+'" target="_blank">Race Website</a></i>';
										}
									}else{
										mEvent = new Array();
										for (var i = 1; i < pEvents.length; i++) {
											tabText = pEvents[i].wtext;
											//pEvents[i].title+' on '+pEvents[i].date
											mEvent.push(new GInfoWindowTab(i, tabText));
										}
										tabText = pEvents[0].wtext;
										//pEvents[i].title+' on '+pEvents[i].date
										mEvent.push(new GInfoWindowTab(i, tabText));
										
									}
									
									return mEvent;
								}
/*		
		this.CreateEventWindowA = function( pEvents ) {
									var mEvent = '';

									for (var i = 0; i < pEvents.length; i++) {
										mEvent += '<div class="routebtn" align="right"><a href="#" onclick="AddToRoute(' + pEvents[i].id + ', true)" class="btn">Add to Route</a></div>';
									}
									
									return mEvent;
								}
		this.CreateEventWindowR = function( pEvents ) {
									var mEvent = '';

									for (var i = 0; i < pEvents.length; i++) {
										mEvent += '<div class="routebtn" align="right"><a href="#" onclick="RemoveFromRoute(' + pEvents[i].id + ')" class="btn">Remove from Route</a></div>';
									}
									return mEvent;
								}
*/									

		this.listings = new Array();
		this.route = new Array();
		this.currentTab = 'location';
		
		this.SwitchTabs = function (tab){
			switch(tab){
				case 'search':
					TF_TabsShow(tab);
					this.currentTab = tab;
				break;
				case 'results':
					/*
					if (this.currentTab == 'search'){
						this.ClearEventMarkers(true);
						this.BuildEventsTab(true);
					}
					*/
					TF_TabsShow(tab);
					this.currentTab = tab;
				break;
			}
		}
		
		this.ClearCurrentLocation = function ( ) {
			for (i = 0; i < goMap.eVents.length; i++) {
				if (goMap.eVents[i].isCurrentLocation) {
					goMap.eVents[i].isCurrentLocation = false;
				}
			}
		}
		
		this.BuildEventsTab = function ( markersOnly ) {
			//this.ClearEventList(true);
			var points = new Array();
			var shown = false;
			var listingsField = document.getElementById(TF_TabsLookup('results'));
			var firstLF = false;
			if (listingsField){
				listingsField.value = '';
				firstLF = true;
			}
			for(i in goMap.eVents){
				show = false;
				shown = false;
				if (goMap.eVents[i].isCurrentLocation){
					if (!isInSearch || goMap.eVents[i].matchSearch){
						if (this.CheckEventDate(i)){
							if (!goMap.eVents[i].isActiveMarker){
								goMap.map.addOverlay( goMap.eVents[i].marker );
								goMap.eVents[i].isActiveMarker = true;
							}
							if (!markersOnly){
								if (!goMap.eVents[i].listp){
									this.ListEvent(goMap.eVents[i]);
								}else{
									goMap.eVents[i].listp.style.display = 'block';
								}
							}
							points[points.length] = goMap.eVents[i].center;

							if (listingsField){
								if (firstLF){
									listingsField.value = goMap.eVents[i].id;
									firstLF = false;
								}else{
									listingsField.value += ',' + goMap.eVents[i].id;
								}
							}

							shown = true;
						}
					}
				}
				if (!shown && !markersOnly){
					// Hide It
					if (goMap.eVents[i].isActiveMarker) {
						goMap.map.removeOverlay( goMap.eVents[i].marker );
						goMap.eVents[i].isActiveMarker = false;
					}
					goMap.eVents[i].listp.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.CheckEventDate = function ( eVentNum ) {
			var day;
			var show = false;
			if (!days[7]){
				for (day = goMap.eVents[eVentNum].sday; day <= goMap.eVents[eVentNum].eday; day++){
					if (days[day]){
						show = true;
						break;
					}
				}
			}else{
				show = true;
			}
			return show;
		}
		
		this.CreateEventMarker = function( pEvent ) {
										//SET EVENT MARKERS HERE
										
										//pEvent.image = 'marker.php?t=' + pEvent.type + '&n=' + pEvent.dnum;

										var loEventIcon;
										if (!pEvent.tabs){
											switch (pEvent.type){
												case 'R':
												case 'M':
													loEventIcon = goMap.icons.run;
												break;
												case 'T':
													loEventIcon = goMap.icons.tri;
												break;
												case 'C':
													loEventIcon = goMap.icons.cycling;
												break;
												case 'S':
													loEventIcon = goMap.icons.ski;
												break;
												case 'B':
													loEventIcon = goMap.icons.mtBike;
												break;
												case 'A':
													loEventIcon = goMap.icons.adventure;
												break;
												case 'K':
													loEventIcon = goMap.icons.kayak;
												break;
												case 'O':
												default:
													loEventIcon = goMap.icons.other;
												break;
											}
											var marker = new GMarker( pEvent.center, loEventIcon );
											
											GEvent.addListener(marker, "click", function() {
													marker.openInfoWindowHtml( pEvent.wtext );
												});
										}else{
											loEventIcon = goMap.icons.multiple;
											var marker = new GMarker( pEvent.center, loEventIcon );
											
											GEvent.addListener(marker, "click", function() {
													marker.openInfoWindowTabs( pEvent.tabs );
												});
										}
								
										return marker;
									}
									
	
		
		this.UpdateEventMarker = function( pEvent ) {
										/*
										GEvent.clearListeners(pEvent.marker, "click");
										if (pEvent.rnum !== null){
											GEvent.addListener(pEvent.marker, "click", function() {
													pEvent.marker.openInfoWindowHtml( pEvent.wtext + pEvent.wrtext );
												});
										}else{
											GEvent.addListener(pEvent.marker, "click", function() {
													pEvent.marker.openInfoWindowHtml( pEvent.wtext + pEvent.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.ClearEventMarkers = function(keepList) {
										if (!keepList){
											goMap.tools.ClearEventList();
										}
										for (var i = 0; i < goMap.eVents.length; i++) {
											if (goMap.eVents[i].isActiveMarker) {
												goMap.map.removeOverlay( goMap.eVents[i].marker );
												goMap.eVents[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
									//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--;
										}
										if ((SearchType == 'zip') && (points.length == 1)){
											newZoom = 8;
										}
										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.GetEvent = function( pEvent ) {
							var ord = null;
							
							for (var i = 0; i < goMap.eVents.length; i++) {
								if (goMap.eVents[i].id == pEvent) {
									ord = i;
									break;
								}
							}
							
							return ord;
						}
		
		this.UpdateEventCollections = function( pEvent, pState, pCity, pZip ) {
											if (pState != null) {
												var lbIsStateEvent = false;
												 
												for (var i = 0; i < goMap.states[pState].eVents.length; i++) {
													if (goMap.states[pState].eVents[i] == pEvent) {
														lbIsStateEvent = true;
														break;
													}
												}
												
												if (!lbIsStateEvent) goMap.states[pState].eVents.push( pEvent );
												
												if (pCity != null) {
													var lbIsCityEvent = false;
													 
													for (var i = 0; i < goMap.states[pState].cities[pCity].eVents.length; i++) {
														if (goMap.states[pState].cities[pCity].eVents[i] == pEvent) {
															lbIsCityEvent = true;
															break;
														}
													}
													
													if (!lbIsCityEvent) goMap.states[pState].cities[pCity].eVents.push( pEvent );
												}
											}
											
											if (pZip != null) {
												var lbIsZipEvent = false;
												 
												for (var i = 0; i < goMap.zips[pZip].eVents.length; i++) {
													if (goMap.zips[pZip].eVents[i] == pEvent) {
														lbIsZipEvent = true;
														break;
													}
												}
												
												if (!lbIsZipEvent) goMap.zips[pZip].eVents.push( pEvent );
											}
										}
		
		this.UpdateGeocode = function( poEvent ) {
									var path = "http://" + gsURL + "/data_update.php?eVent=" + poEvent.id + "&lat=" + poEvent.center.y + "&lng=" + poEvent.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.eVents.length - 1; i >= 0; i--) {
												if (goMap.eVents[poObj.eVents[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.GroupEqualPointEvents = function( pObj, removeOld ) {
										
										if (!pObj.isLoadedTabs) {
											for (var i = 0; i < pObj.eVents.length; i++) {
												var dupes = new Array();
												dupes.push( goMap.eVents[pObj.eVents[i]] );
												
												for (var j = 0; j < pObj.eVents.length; j++) {
													if (j != i && goMap.eVents[pObj.eVents[j]].center.equals( goMap.eVents[pObj.eVents[i]].center )) {
														dupes.push( goMap.eVents[pObj.eVents[j]] );
													}
												}
												
												var title = '';
												if (dupes.length > 1) {
													if (removeOld){
														goMap.map.removeOverlay(goMap.eVents[pObj.eVents[i]].marker);
													}
													
													//goMap.eVents[pObj.eVents[i]].wtext = false;
													goMap.eVents[pObj.eVents[i]].tabs = goMap.tools.CreateEventWindow( dupes );
													goMap.eVents[pObj.eVents[i]].marker = goMap.tools.CreateEventMarker( goMap.eVents[pObj.eVents[i]] );
													if (removeOld){
														goMap.map.addOverlay(goMap.eVents[pObj.eVents[i]].marker);
													}
												}
											}
											pObj.isLoadedTabs = true;
										}
										
										return pObj.isLoadedTabs;
									}
		
		this.ClearEventList = function() {
								//var obj = document.getElementById( "listings" );
								//if (obj) obj.innerHTML = "";
								for (var i in goMap.eVents){
									if (goMap.eVents[i] && goMap.eVents[i].listp){
										goMap.eVents[i].listp.style.display = 'none';
									}
								}
							}
		
		this.ListEvent = function( pEvent ) {
								//var obj = document.getElementById( "tab_results_body" );
								//if (obj) {
									if (!pEvent.listp){
										var lsEventInfo = '<span class="event_result_title">' + 
											'<a href="#" onclick="return goMap.tools.RevealEvent(' + pEvent.id + ');">'+ pEvent.title + '</a></span>';
										
										//obj.innerHTML += '<li>' + lsEventInfo + '</li>';
										pEvent.listp = document.createElement("P");
										pEvent.listp.innerHTML = lsEventInfo;
										goMap.ListingSorter.addEvent(pEvent.date,pEvent.listp);
									}else{
										pEvent.listp.style.display = 'block';
									}
								//}
							}

		this.RevealEvent = function( piEvent ) {
								var liEventOrd = goMap.tools.GetEvent( piEvent );
								var liEventRoute = (goMap.eVents[liEventOrd].rnum === null) ? goMap.eVents[liEventOrd].watext : goMap.eVents[liEventOrd].wrtext;
								goMap.eVents[liEventOrd].marker.openInfoWindowHtml( goMap.eVents[liEventOrd].wtext);
								
								return false;
							}
		
		this.DisplayState = function() {
								if (goMap.status.state != null) {
									if (goMap.states[goMap.status.state].loadEventStatus == goMap.constants.loadStatus.isDone) {
										if (goMap.tools.CheckMarkerStatus( goMap.states[goMap.status.state] )) {
											//goMap.tools.GroupEqualPointEvents( goMap.states[goMap.status.state] );
											
											var listingsField = document.getElementById('events_listings');
											var firstLF = false;
											if (listingsField){
												listingsField.value = '';
												firstLF = true;
											}
											// display eVent markers...
											for (var i = 0; i < goMap.states[goMap.status.state].eVents.length; i++) {
												//if (goMap.tools.CheckEventDate(goMap.states[goMap.status.state].eVents[i])){
													goMap.map.addOverlay( goMap.eVents[goMap.states[goMap.status.state].eVents[i]].marker );
													goMap.eVents[goMap.states[goMap.status.state].eVents[i]].isActiveMarker = true;
													goMap.tools.ListEvent( goMap.eVents[goMap.states[goMap.status.state].eVents[i]] );
												//}
												goMap.eVents[goMap.states[goMap.status.state].eVents[i]].isCurrentLocation = true;
												if (listingsField){
													if (firstLF){
														listingsField.value = goMap.eVents[goMap.states[goMap.status.state].eVents[i]].id;
														firstLF = false;
													}else{
														listingsField.value += ',' + goMap.eVents[goMap.states[goMap.status.state].eVents[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].eVents.length;
											var msg = (goMap.status.state == null) ? null : ('Sorry, no events were found in your area.');
											if (count >= 1){
												count = goMap.tools.HideExtraResults(goMap.states[goMap.status.state].eVents,goMap.states[goMap.status.state].center);
												if (count >= 1) goMap.tools.SwitchTabs('results');	
												msg = 'There ' + ((count == 1) ? 'is' : 'are') + ' ' + ((count == 0) ? 'no' : count) + ' event' + ((count == 1) ? '' : 's') + ' matching the search criteria 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();
										}
									}
								}
								MapSearchComplete();
							}
		
		this.DisplayCity = function() {
								if (goMap.status.city != null && goMap.status.state != null) {
									if (goMap.states[goMap.status.state].cities[goMap.status.city].loadEventStatus == goMap.constants.loadStatus.isDone) {
										if (goMap.tools.CheckMarkerStatus( goMap.states[goMap.status.state].cities[goMap.status.city] )) {
											//goMap.tools.GroupEqualPointEvents( goMap.states[goMap.status.state].cities[goMap.status.city] );
											
											var listingsField = document.getElementById('eVents_listings');
											var firstLF = false;
											if (listingsField){
												listingsField.value = '';
												firstLF = true;
											}
											// display eVent markers...
											var points = new Array();
											for (var i = 0; i < goMap.states[goMap.status.state].cities[goMap.status.city].eVents.length; i++) {
												if (goMap.tools.CheckEventDate(goMap.states[goMap.status.state].cities[goMap.status.city].eVents[i])){
													goMap.map.addOverlay( goMap.eVents[goMap.states[goMap.status.state].cities[goMap.status.city].eVents[i]].marker );
													goMap.eVents[goMap.states[goMap.status.state].cities[goMap.status.city].eVents[i]].isActiveMarker = true;
													goMap.tools.ListEvent( goMap.eVents[goMap.states[goMap.status.state].cities[goMap.status.city].eVents[i]] );
													points[points.length] = goMap.eVents[goMap.states[goMap.status.state].cities[goMap.status.city].eVents[i]].center;
												}
												goMap.eVents[goMap.states[goMap.status.state].cities[goMap.status.city].eVents[i]].isCurrentLocation = true;
												if (listingsField){
													if (firstLF){
														listingsField.value = goMap.eVents[goMap.states[goMap.status.state].cities[goMap.status.city].eVents[i]].id;
														firstLF = false;
													}else{
														listingsField.value += ',' + goMap.eVents[goMap.states[goMap.status.state].cities[goMap.status.city].eVents[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].eVents.length > 0) {
//												var bounds = new GLatLngBounds();
//												for (var i = 0; i < goMap.states[goMap.status.state].cities[goMap.status.city].eVents.length; i++) {
//													bounds.extend( goMap.eVents[goMap.states[goMap.status.state].cities[goMap.status.city].eVents[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].eVents.length;
											var msg = 'There ' + ((count == 1) ? 'is' : 'are') + ' ' + ((count == 0) ? 'no' : count) + ' event' + ((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){
												goMap.tools.SwitchTabs('results');	
											}
										}
									}
								}
								MapSearchComplete();
							}
		
		this.DisplayZip = function() {
								if (goMap.status.zip != null) {
									if (goMap.zips[goMap.status.zip].loadEventStatus == goMap.constants.loadStatus.isDone) {
										if (goMap.tools.CheckMarkerStatus( goMap.zips[goMap.status.zip] )) {
											goMap.tools.GroupEqualPointEvents( goMap.zips[goMap.status.zip] );
											
											var listingsField = document.getElementById('eVents_listings');
											var firstLF = false;
											if (listingsField){
												listingsField.value = '';
												firstLF = true;
											}
											// display eVent markers...
											var points = new Array();
											var datesToShow = new Array();
											var lastdate = false;
											for (var i = 0; i < goMap.zips[goMap.status.zip].eVents.length; i++) {
												//if (goMap.tools.CheckEventDate(goMap.zips[goMap.status.zip].eVents[i])){
													goMap.map.addOverlay( goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]].marker );
													goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]].isActiveMarker = true;
													goMap.tools.ListEvent( goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]] );
													points[points.length] = goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]].center;
												//}
												goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]].isCurrentLocation = true;
												if (listingsField){
													if (firstLF){
														listingsField.value = goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]].id;
														firstLF = false;
													}else{
														listingsField.value += ',' + goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]].id;
													}
												}
												if (!lastdate || lastdate != goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]].date){
													lastdate = goMap.eVents[goMap.zips[goMap.status.zip].eVents[i]].date;
													datesToShow.push(lastdate);
												}
											}
											
											if (goMap.zips[goMap.status.zip].eVents.length == 0) {
												goMap.map.setCenter( goMap.center, goMap.zoom );
												MapUpdateStatusMessage( 'No events 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].eVents.length;
												//count = goMap.tools.HideExtraResults(goMap.zips[goMap.status.zip].eVents,goMap.zips[goMap.status.zip].center,goMap.zips[goMap.status.zip].eVentDistances);
												if (count >= 1){
													goMap.tools.UpdateCurrentBounds(points);
													goMap.tools.SwitchTabs('results');
												}

												var msg = 'There ' + ((count == 1) ? 'is' : 'are') + ' ' + ((count == 0) ? 'no' : count) + ' event' + ((count == 1) ? '' : 's') + ' matching the search criteria in or near the zipcode ' + goMap.zips[goMap.status.zip].code + '.';
												MapUpdateStatusMessage( msg, ((count == 0) ? 2 : 0) );
												SwitchAdBanners(goMap.zips[goMap.status.zip].state);
												goMap.ListingSorter.showDates(datesToShow);
											}
										}
									}
								}
								MapSearchComplete();
							}
		
		this.PopulateCityOptions = function() {
			
										return true; // City Option Removed Currently
										
										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 Events 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);
												}
											} 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.LoadEvent = function( pMapEvent ) {
							goMap.eVents.push( pMapEvent );
							
							var liEvent = goMap.eVents.length - 1;
							var eVent = goMap.eVents[liEvent];
							
							eVent.loadMarkerStatus = goMap.constants.loadStatus.isLoading;
							
							if (!eVent.coded) {
								var address = (eVent.address + ', ' + eVent.city + ', ' + eVent.state);
								var point = goMap.geocoder.getLatLng( address, function(point) {
										if (point) {
											eVent.center = point;
											goMap.tools.UpdateGeocode( eVent );
										}
									} );
							}
							
							eVent.wtext = goMap.tools.CreateEventWindow( [eVent] );
							//eVent.watext = goMap.tools.CreateEventWindowA( [eVent] );
							//eVent.wrtext = goMap.tools.CreateEventWindowR( [eVent] );
							eVent.marker = goMap.tools.CreateEventMarker( eVent );
							eVent.loadMarkerStatus = goMap.constants.loadStatus.isDone;
						}
		
		this.ParseEventData = function( pEvents, piState, piCity, piZip ) {
			
									for (var i = 0; i < pEvents.length; i++) {
										var lsID = pEvents[i].getAttribute("id");
										var liEventOrd = goMap.tools.GetEvent( parseInt(lsID) );



										if (liEventOrd == null) {
											var lsName = pEvents[i].getAttribute("name");
											var lsTitle = pEvents[i].getAttribute("title");
											var lsSource = pEvents[i].getAttribute("source");
											var lsAddress = pEvents[i].getAttribute("address");
											//var lsSubdivision = pEvents[i].getAttribute("subdivision");
											var lsCity = pEvents[i].getAttribute("city");
											var lsState = pEvents[i].getAttribute("state");
											var lsZip = pEvents[i].getAttribute("zip");
											var lsWebsite = pEvents[i].getAttribute("website");
											var lsType = pEvents[i].getAttribute("type");
											var lsDistances = pEvents[i].getAttribute("distances");
											var lsLat = pEvents[i].getAttribute("latitude");
											var lsLng = pEvents[i].getAttribute("longitude");
											var lsStart = pEvents[i].getAttribute("start");
											//var lsEnd = pEvents[i].getAttribute("end");
											var lsSday = pEvents[i].getAttribute("start_day");
											//var lsEday = pEvents[i].getAttribute("end_day");
											var lsDate = pEvents[i].getAttribute("date");
											var lsTime = pEvents[i].getAttribute("time");
											var lsDistance = pEvents[i].getAttribute("distance");
											var lsIsCoded = pEvents[i].getAttribute("iscoded");
											var lsIsMine = pEvents[i].getAttribute("ismine");
											if (lsIsMine === null){
												lsIsMine = 'no';
											}

											var loEvent = new MapEvent( parseInt(lsID), lsName, lsTitle, lsSource, lsAddress, lsCity, lsState, lsZip, lsWebsite, lsType, lsDistances, parseFloat(lsLat), parseFloat(lsLng), lsStart, lsSday, lsDate, lsTime, lsDistance, goMap.tools.Convert2Boolean(lsIsCoded), lsIsMine ); 
											if (piState == null) piState = goMap.tools.GetState( lsState );
											
											//  add to my eVents and generate the number for the marker
											//	var myEvents = new Array();
											//	var myEventsIDs = new Array();

											if (myEventsIDs[loEvent.id] === undefined){
												if (myEvents.length == 0){
													var myNum = 1;
												}else{
													var myNum = myEvents.length;
												}
												myEvents[myNum] = loEvent;
												myEventsIDs[loEvent.id] = myNum;
												loEvent.dnum = myNum;
											}else{
												loEvent.dnum = myEventsIDs[loEvent.id];												
											}
											
											goMap.tools.LoadEvent( loEvent );
										}else{
											liEventOrd.isCurrentLocation = true;
											var lsDistance = pEvents[i].getAttribute("distance");
											goMap.eVents[liEventOrd].distance = lsDistance;
										}
										
										if (liEventOrd == null) liEventOrd = goMap.tools.GetEvent( parseInt(lsID) );
										//clearSearch();
										goMap.tools.UpdateEventCollections( liEventOrd, piState, piCity, piZip );
									}
								}
		
		this.LoadStateEventData = function( psState ) {
										if (psState != null) {
											var path = "http://" + gsURL + "/data_events.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].loadEventStatus == goMap.constants.loadStatus.isReady) {
																					goMap.states[liStateOrd].loadEventStatus = goMap.constants.loadStatus.isLoading;
																					goMap.tools.ParseEventData( xmlDoc.documentElement.getElementsByTagName("event"), liStateOrd, null, null );
																					goMap.states[liStateOrd].loadEventStatus = 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.LoadCityEventData = 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_events.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].loadEventStatus == goMap.constants.loadStatus.isReady) {
																						goMap.states[liStateOrd].cities[liCityOrd].loadEventStatus = goMap.constants.loadStatus.isLoading;
																						goMap.tools.ParseEventData( xmlDoc.documentElement.getElementsByTagName("event"), liStateOrd, liCityOrd, null );
																						goMap.states[liStateOrd].cities[liCityOrd].loadEventStatus = 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.LoadZipEventData = function( psZip ) {
									if (psZip != null) {
										var otherOptions = getOtherOptions();
										
										var path = "http://" + gsURL + "/data_events.php?zip=" + psZip + otherOptions;
										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[liZipOrd] = new MapZip( psZip, lsZipState, parseFloat(lsZipLat), parseFloat(lsZipLng), parseInt(lsZipZoom) );
																				//liZipOrd = goMap.zips.length - 1;
																			}
																			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].loadEventStatus == goMap.constants.loadStatus.isReady) {
																				goMap.zips[liZipOrd].loadEventStatus = goMap.constants.loadStatus.isLoading;
																				goMap.tools.ParseEventData( xmlDoc.documentElement.getElementsByTagName("event"), null, null, liZipOrd );
																				/*
																				for (var i in goMap.zips[liZipOrd].eVents){
																					goMap.zips[liZipOrd].eVentDistances[i] = goMap.eVents[goMap.zips[liZipOrd].eVents[i]].distance;
																				}
																				*/
																				
																				goMap.zips[liZipOrd].loadEventStatus = 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);
									}
								}
		
		this.HideExtraResults = function(items,center,distances){
			/*
									if (typeof(items) !== "array"){
										return 0;
									}
			*/
									var count = 0;
									var points = new Array();
									var distance;
									var datesToShow = new Array();
									var lastdate = false;
									var visible = new Object();
									visible.eVents = new Array();
									// Hide all text listings 
									for (var c in goMap.eVents){
										if (goMap.eVents[c].listp){
											goMap.eVents[c].listp.style.display = 'none';
										}
									}
									for (var i in items){
										if (SearchType == 'zip'){
											distance = distances[i];
										}else{
											distance = 0;
										}
										if (goMap.tools.TestEventForAddtlSearchMatch(goMap.eVents[items[i]],distance)){
											count++;
											goMap.eVents[items[i]].matchAddtlSearch = true;
											points.push(goMap.eVents[items[i]].center);
											visible.eVents.push(items[i]);
											if (goMap.eVents[items[i]].listp){
												goMap.eVents[items[i]].listp.style.display = 'block';
											}
											if (!lastdate || lastdate != goMap.eVents[items[i]].date){
												lastdate = goMap.eVents[items[i]].date;
												datesToShow.push(lastdate);
											}
										}else{
											goMap.eVents[items[i]].marker.hide();
											goMap.eVents[items[i]].matchAddtlSearch = false;
											if (goMap.eVents[items[i]].listp){
												goMap.eVents[items[i]].listp.style.display = 'none';
											}
										}
									}
									if (SearchType == 'zip') points.push(center);
									goMap.tools.UpdateCurrentBounds(points);
									goMap.ListingSorter.showDates(datesToShow);
									goMap.tools.GroupEqualPointEvents( visible, true );
									return count;
								}
		
		this.TestEventForAddtlSearchMatch = function(eVent,edistance){
			
											// Check Type (races  type)
											var type = document.getElementById('races');
											type = type.options[type.selectedIndex].value;
											if (type !== '*'){
												if (type == 'R'){
													if (eVent.type != 'M' && eVent.type != 'R'){
														return false;
													}
												}else{
													if (eVent.type != type){
														return false;
													}
												}
											}
											
											// Check Date (when  sday or date)
											var when = document.getElementById('when');
											when = when.options[when.selectedIndex].value;
											if (when != '*'){
												var days = parseInt(when,10);
												if (days){
													if (days < eVent.sday){
														return false;
													}
												}else{
													var mon = false;
													switch (when){
														case 'J':
															mon = 1;
														break;
														case 'F':
															mon = 2;
														break;
														case 'M':
															mon = 3;
														break;
														case 'A':
															mon = 4;
														break;
														case 'Ma':
															mon = 5;
														break;
														case 'Ju':
															mon = 6;
														break;
														case 'Jul':
															mon = 7;
														break;
														case 'Au':
															mon = 8;
														break;
														case 'S':
															mon = 9;
														break;
														case 'O':
															mon = 10;
														break;
														case 'N':
															mon = 11;
														break;
														case 'D':
															mon = 12;
														break;
													}
													if (mon){
														if (mon !== parseInt(eVent.date.substring(0,2),10)){
															return false;
														}
													}
												}
											}
												
											// Check Distance (distance  distance)
											// Only if searching by zip code
											if (SearchType == 'zip'){
												var distance = document.getElementById('distance');
												distance = parseInt(distance.options[distance.selectedIndex].value);
												if ( (distance) && (distance !== '*') ){
													if (distance < edistance){
														return false;
													}
												}
											}
											
											return true;
										}
		
		return this;
	}
	
	
	function MapChangeState() {
		
		MapSearchStart();
		
		MapUpdateStatusMessage( "Loading state data...", 1 );
		goMap.tools.ClearLocation( "state" );
		
		var loState = document.getElementById( "state" );
		var lsState = (loState) ? loState.value : "";
		
		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].loadEventStatus;
			if (liLoadStatus == goMap.constants.loadStatus.isReady) {
				goMap.tools.LoadStateEventData( lsState );
			} else {
				goMap.tools.DisplayState();
			}
		}
	}
	
	
	function MapChangeCity() {
		
		MapSearchStart();

		MapUpdateStatusMessage( "Loading city data...", 1 );
		goMap.tools.ClearLocation( "city" );
				
		var loCity = document.getElementById( "city" );
		var lsCity = (loCity) ? loCity.value : "";
		
		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].loadEventStatus == goMap.constants.loadStatus.isReady) {
				goMap.tools.LoadCityEventData();
			} 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) {
			MapSearchStart();
			goMap.status.zip = goMap.tools.GetZip( lsZip );
			
			//var liLoadStatus = (goMap.status.zip == null) ? goMap.constants.loadStatus.isReady : goMap.zips[goMap.status.zip].loadEventStatus;
			//if (liLoadStatus == goMap.constants.loadStatus.isReady) {
				goMap.tools.LoadZipEventData( 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, revealEvent){
	}

	function MoveInRoute(id, how, skipBuild){
		return false;		
	}
	
	function RemoveFromRoute(id){
		return false;
	}
	
	function ClearRoute(){
	}
	
	function BuildRouteList(){
		return false;
	}
		
	
	function getRouteDirections(){

		return false;
	}
	*/
	function getEventsDetails(type){
		var eVentsList = document.getElementById('eVents_listings');
		if (eVentsList && eVentsList.value != ''){

			var frmEventsListings = document.getElementById('frmEventsListings');

			if (type){
				var output = document.getElementById('eVents_listings_output');
				output.value = type;
				if (type == 'xml'){
					frmEventsListings.action = 'listing_details.xml';	
				}else if (type == 'kml'){
					frmEventsListings.action = 'listing_details.kml';	
				}else{
					frmEventsListings.action = 'listing_details.php';	
				}
			}
				
			frmEventsListings.submit();
			return true;
		}else{
			alert('There must be results showing in the eVents list in order to preform this function.');	
		}
	}

function getMyRouteList(){
	return false;
	}
	
	function setTab(which){
		//setTab('location')
		//setTab('eVents')
		//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.BuildEventsTab();
	}

	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.eVents.length; i++){
			
				if (goMap.eVents[i] && goMap.eVents[i].isCurrentLocation){
					if (goMap.eVents[i].description.search(pattern) !== -1){
						goMap.eVents[i].matchSearch = true;
					}
				}
	
			}
			
			goMap.tools.BuildEventsTab();
		}
	}
	
	function clearSearchAll(){
		var query = document.getElementById('search_field');
		query.value = '';
		clearSearch();
		goMap.tools.BuildEventsTab();
	}

function clearSearch(){
		for (i = 0; i < goMap.eVents.length; i++){
			goMap.eVents[i].matchSearch = false;
		}
		isInSearch = false;		
	}
	
	*/
	
	function getOtherOptions(){
		var ret = '';
		
		var elem = document.getElementById('races');
		if (elem){
			ret += '&type=' + elem.options[elem.selectedIndex].value;
		}
		
		elem = document.getElementById('when');
		if (elem){
			ret += '&when=' + elem.options[elem.selectedIndex].value;
		}
		
		elem = document.getElementById('distance');
		if (elem){
			ret += '&distance=' + elem.options[elem.selectedIndex].value;
		}
	
		return ret;

}
	
	// 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;
   }



