// JavaScript Document

			var mouselat;
			var mouselng;
			var map; 
			var mapLat =null;
			var mapLon = null;
			var setZoom = null;
			
			var numresults = 0;
			var i = 0;
			var htmls = [];
			var addresses = [];
			var gmarkers = [];
			var previousclick = -1;
			var a=0;
			var resultLat=0;
			var resultLon=0;
			var resultZoom=0;
			var geocoder = new GClientGeocoder();
			
			

			

			function mapload(stateId) {
				
				i=0;
				if (GBrowserIsCompatible()) {
					if (stateId == "none") {
						mapLat = 39.833333; mapLon = -95.883333; setZoom = 4;
					} else {
						switchState = dojo.byId(stateId).value;
						switch(switchState) {
	
							case "IL": mapLat = 40.1333 ; mapLon = -89.3667 ; setZoom= 6; break;
	
							case "IN": mapLat = 40.0000; mapLon = -86.2667; setZoom = 7;break;
	
							case "TX": mapLat = 31.3333; mapLon = -99.5333; setZoom = 5; break;
	
							case "NY": mapLat = 42.7; mapLon = -76.0167; setZoom = 6; break;
	
							case "CA": mapLat = 37.1; mapLon = -120.2167; setZoom = 6; break;
	
							case "NJ": mapLat = 40.1; mapLon = -74.6333; setZoom = 8; break;
	
							case "AL": mapLat = 32.9167; mapLon = -86.6333; setZoom = 6; break;
	
							case "AK": mapLat = 64.8667; mapLon = -152.5; setZoom = 4; break;
	
							case "AZ": mapLat = 34.3833; mapLon = -111.8833; setZoom = 6; break;
	
							case "AR": mapLat = 34.95; mapLon = -92.3167; setZoom = 7; break; 
	
							case "CO": mapLat = 39.1333; mapLon = -105.7167; setZoom = 7; break;
	
							case "CT": mapLat = 41.7; mapLon = -72.7667; setZoom = 8; break;
	
							case "DE": mapLat = 39.1; mapLon = -75.6167; setZoom = 8; break;
	
							case "FL": mapLat = 28.1333; mapLon = -81.7667; setZoom = 6; break;
	
							case "GA": mapLat = 32.8333; mapLon = -83.6; setZoom = 7; break;
	
							case "HI": mapLat = 20.9667; mapLon =-157.3667 ; setZoom = 7; break;
	
							case "ID": mapLat = 45.3167; mapLon =-115.0167 ; setZoom = 6; break;
	
							case "IA": mapLat = 42.0667; mapLon =-93.4 ; setZoom = 7; break;
	
							case "KS": mapLat = 38.6333; mapLon =-98.8333 ; setZoom = 6; break;
	
							case "KY": mapLat = 37.43333; mapLon =-85.5667 ; setZoom = 7; break;
	
							case "LA": mapLat = 30.9833; mapLon =-92.5667 ; setZoom = 7; break;
	
							case "ME": mapLat = 45.2833; mapLon =-69.2333 ; setZoom = 7; break;
	
							case "MD": mapLat = 39.5167; mapLon =-77.4167 ; setZoom = 7; break;
	
							case "MA": mapLat = 42.4; mapLon =-72.1667 ; setZoom = 7; break;
	
							case "MI": mapLat = 45.1667; mapLon =-84.9833 ; setZoom = 6; break;
	
							case "MN": mapLat = 46.1; mapLon =-95.4167 ; setZoom = 7; break;
	
							case "MS": mapLat = 32.95; mapLon =-89.7167 ; setZoom = 6; break; 
	
							case "MO": mapLat = 38.6; mapLon =-92.7667 ; setZoom = 7; break;
	
							case "MT": mapLat = 47.1667; mapLon =-109.6833 ; setZoom = 6; break;
	
							case "NE": mapLat = 41.6; mapLon =-99.9667 ; setZoom = 6; break;
	
							case "NV": mapLat = 39.55; mapLon =-117.0667 ; setZoom = 6; break;
	
							case "NH": mapLat = 43.7167; mapLon =-71.6167 ; setZoom = 7; break;
	
							case "NM": mapLat = 34.1567; mapLon =-106.2167 ; setZoom = 6; break;
	
							case "NC": mapLat = 35.6333; mapLon =-79.5 ; setZoom = 7; break;
	
							case "ND": mapLat = 47.5167; mapLon =-100.5833 ; setZoom = 7; break;
	
							case "OH": mapLat = 40.4667; mapLon =-82.8167 ; setZoom = 7; break; 
	
							case "OK": mapLat = 35.5667; mapLon =-97.75 ; setZoom = 7; break;
	
							case "OR": mapLat = 43.8833; mapLon =-121.0833 ; setZoom = 7; break;
	
							case "PA": mapLat = 41.0167; mapLon =-77.8667 ; setZoom = 7; break;
	
							case "RI": mapLat = 41.7167; mapLon =-71.6667 ; setZoom = 7; break;
	
							case "SC": mapLat = 33.95; mapLon =-80.9333 ; setZoom = 7; break;
	
							case "SD": mapLat = 44.4167; mapLon =-100.5833 ; setZoom = 7; break;
	
							case "TN": mapLat = 35.9; mapLon =-86.6667 ; setZoom = 7; break;
	
							case "UT": mapLat = 39.4167; mapLon =-111.7 ; setZoom = 7; break;
	
							case "VT": mapLat = 44.0167; mapLon =-72.7167 ; setZoom = 7; break;
	
							case "VA": mapLat = 37.5333; mapLon =-78.6833 ; setZoom = 7; break;
	
							case "WA": mapLat = 47.3333; mapLon =-120.2833 ; setZoom = 7; break;
	
							case "WI": mapLat = 44.4333; mapLon =-89.8833 ; setZoom = 7; break;
	
							case "WV": mapLat = 38.7333; mapLon =-80.7333 ; setZoom = 7; break;
	
							case "WY": mapLat =43.0167 ; mapLon =-107.7167 ; setZoom = 7; break;
	
							default: mapLat = 39.833333; mapLon = -95.883333; setZoom = 4; break;		
	
						}
	
						if(stateId == "state") {
						
							switch(dojo.byId('region').value) {
		
								case "Chicago Area": mapLat = 41.759020 ; mapLon = -87.599487 ; setZoom= 10; break;
		
								case "New York Harbor": mapLat = 40.759741 ; mapLon = -73.995667; setZoom= 10; break;
		
								case "Houston Ship Channel": mapLat = 29.744109 ; mapLon = -95.179367 ; setZoom= 10; break;
		
							}
						} else if (stateId == "stateRef") {
							switch(dojo.byId('PAD').value) {
								case "District 1": mapLat = 37.926868 ; mapLon = -77.958984 ; setZoom= 4; break;
								case "District 1A": mapLat = 43.977005 ; mapLon = -71.059570; setZoom= 6; break;
								case "District 1B": mapLat = 41.722131 ; mapLon = -76.069336 ; setZoom= 6; break;
								case "District 1C": mapLat = 34.016242 ; mapLon = -81.254883 ; setZoom= 5; break;
								case "District 2": mapLat = 41 ; mapLon = -92.724609 ; setZoom= 5; break;
								case "District 3": mapLat = 33.100745 ; mapLon = -95.449219 ; setZoom= 5; break;
								case "District 4": mapLat = 42.293564 ; mapLon = -110.654297 ; setZoom= 5; break;
								case "District 5": mapLat = 37.996163 ; mapLon = -121.728516 ; setZoom= 4; break;
							}
						}
						
						switch(stateId) {
							case "state": 
								if(dojo.byId('City5').value != "") {	
									geocoder.getLatLng(dojo.byId('City5').value, function(point) {
										if (!point) {
											alert(address + " not found");
										} else {
										
											mapLat = point.lat();
											mapLon = point.lng();
											setZoom = 9;
											resultLat = mapLat;
											resultLon = mapLon;
											resultZoom = setZoom;

											map.setCenter(new GLatLng(mapLat,mapLon), setZoom,G_NORMAL_MAP);
										}
									});	
								
									
								}
								break;
							case "stateRef": 
								if(dojo.byId('CityRef').value!= "") {	
									geocoder.getLatLng(dojo.byId('CityRef').value, function(point) {
										if (!point) {
											alert(address + " not found");
										} else {
										
											mapLat = point.lat();
											mapLon = point.lng();
											setZoom = 9;
											resultLat = mapLat;
											resultLon = mapLon;
											resultZoom = setZoom;

											map.setCenter(new GLatLng(mapLat,mapLon), setZoom,G_NORMAL_MAP);
										}
									});	
								}
								break;
							case "stateBio": 
								if(dojo.byId('CityBio').value!= "") {	
									geocoder.getLatLng(dojo.byId('CityBio').value, function(point) {
										if (!point) {
											alert(address + " not found");
										} else {
										
											mapLat = point.lat();
											mapLon = point.lng();
											setZoom = 9;
											resultLat = mapLat;
											resultLon = mapLon;
											resultZoom = setZoom;

											map.setCenter(new GLatLng(mapLat,mapLon), setZoom,G_NORMAL_MAP);
										}
									});	
								}
								break;
							
						}
					}
					
					resultLat = mapLat;
					resultLon = mapLon;
					resultZoom = setZoom;
					if(!map){
						setTimeout('initMap()',200);
					} else {
						resultLocation = new GLatLng(mapLat, mapLon);
						resultZoom = setZoom;
						map.checkResize();
						map.setCenter(resultLocation, setZoom,G_NORMAL_MAP);
					}
				}
			}

			function initMap() {	
					
					
					map = new GMap2(dojo.byId('map'));
					map.checkResize();
					map.setCenter(new GLatLng(mapLat, mapLon), setZoom);


					map.setUIToDefault();
					
					var interval = setInterval("count()",500);
					
					
					
			}
		
			function createMarker(point,name,html,address, citystatezip,x) {
						var marker = new GMarker(point, {title: name});
						GEvent.addListener(marker, "click", function() {
						  var infodbcall = "<script type='dojo/method' event='onClick'>	dojo.xhrPost({url: 'details.php',form: 'frm" + x +"', load: function(htmlOutput) {formatDetails(htmlOutput); },error: function(error){ console.error ('Error: ',error); }});</script>";
						  infoHTML = "<div id='divInfo" + i + "'><form method='submit' id='frmInfo" + i + "'><table><td><strong>" + name + "</strong><br>" + address + "<br>" + citystatezip + "<input type='hidden' id='hiddenAddress' name='hiddenAddress' value='" + address + "'/><input type='hidden' id='hiddenName' name='hiddenName' value='" + name + "'/><br></td><td align='right'><button type='button' dojoType='dijit.form.Button' >Details" + infodbcall + " </button></table></form></div>";
						  infoHTML += "<script type=text/javascript>dojo.parser.parse(dojo.byId('divInfo" + i + "'));</script>";
						 
						  marker.openInfoWindow(infoHTML);
						  
						  	if (previousclick >= 0) {
								dojo.byId("mapData" + previousclick).style.background = "#FFF";
							}
							
							dojo.byId("mapData" + x).style.background = "#A0B4B4";
						
						
							previousclick = x;
						    dojo.parser.parse(dojo.byId('divInfo'+ i));
						});
						
						
						gmarkers[i] = marker;
						htmls[i] = name;
						addresses[i] = address;
						i++;
						
						return marker;
						
			}
					
					

				  // This function picks up the click and opens the corresponding info window
			function myclick(a) {
						if (previousclick >= 0) {
							dojo.byId("mapData" + previousclick).style.background = "#FFF";
						}
						gmarkers[a].openInfoWindowHtml(htmls[a]);
						dojo.byId("mapData" + a).style.background = "#A0B4B4";
						
						
						previousclick = a;
						
					  }
					  
			
				
			function count() {
						paragraphs = map.getContainer().getElementsByTagName('p').length;
						if(paragraphs > 4) {
							map.zoomOut(false,true);
						}
						
			}
			
			function setMapParams(newLat, newLon, aerial, zoom) {
					map.checkResize();
					newCenter = new GLatLng(newLat,newLon);
					if (aerial) {
						map.setCenter(newCenter, zoom, G_HYBRID_MAP);
					} else {
						map.setCenter(newCenter, zoom, G_NORMAL_MAP);
					}
					
					
					var interval = setInterval("count()",500);
					
			}
			

