document.getElementById('dealerLocator').className = 'hidden';
locArray = new Array;
locArray = window.location.href.split("?");
locArray = locArray[0].split("/");
switch(locArray[locArray.length-1]){
	case "results.php":
		displayMapResults();
		break;
	case "map.php":
		displayMapLarge();
		break;
	case "directions.php":
		displayMapDirections();
		break;
}

//function for index of dealer locator
if(document.getElementById('dealerForm')){
	document.getElementById('dealerForm').onsubmit = function(){
		geocoder = new GClientGeocoder();
		var address = document.getElementById('searchZip').value;
		if(document.getElementById('UMProducts').value == ""){
			alert("Please select a product from the drop down box");
			return false;
		}else if(address == ""){
			alert("Please input a zip/postal code");
			return false;
		}else{
			if(geocoder){			
				geocoder.getLatLng(address,
					function(point) {
						if (!point) {
							alert(address + " not found. Please try a different postal code.");
							return false;
						}else{
							document.getElementById('LongLat').value = point;
							document.getElementById('dealerForm').submit();
						}
					}
				);
			}
		}
		return false;
	}
}

//function for results page
function mapResults(a,dlrLat,dlrLong){
	//<![CDATA[
	map = new Array;
	geocoder = new Array;
	mapVar = 'map' + a;
	map[a] = null;
	geocoder[a] = null;
	if (GBrowserIsCompatible()) {
		map[a] = new GMap2(document.getElementById(mapVar));
		map[a].disableDragging();
		var address = new GLatLng(dlrLat, dlrLong);
		map[a].setCenter(address, 9);
		var marker = new GMarker(address);
		map[a].addOverlay(marker);
	};
	//]]>
}
function displayMapResults(){
}
//function for map page
//<![CDATA[
function displayMapLarge(){
	map = null;
	geocoder = null;
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("cDealerLrgMap"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl(true));
		GEvent.addListener(map,"moveend", function(){
			var center = map.getCenter();
		});
		var address = new GLatLng(0, 0);
		map.setCenter(address, 13);
		var marker = new GMarker(address);
		map.addOverlay(marker);
		GEvent.addListener(marker, "click", function(){
			marker.openInfoWindow("<br /><br />,  ");
			map.setCenter(address,13);
		});
	}
}
//]]>
function displayMapDirections(){
	//<![CDATA[
    map = null;
	geocoder = null;
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("cDealerDirMap"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl(true));
		GEvent.addListener(map,"moveend", function(){
			var center = map.getCenter();
		});
		geocoder = new GClientGeocoder();
		var dirDiv = document.getElementById('cDirections');
		var directions = new GDirections(map, dirDiv);
		directions.load("@,  to  - , ,   @, ");
		geocoder = new GClientGeocoder();
		var address = ', ';
		if(geocoder){			
			geocoder.getLatLng(address,
				function(point) {
					if (!point) {
						alert(address + " Not Found");
					}
				}
			);
		}
	}
	//]]>
}
window.onunload = function(){
	GUnload();	
}