
	//### load() instanciates Google Map object
	//##
	//#
	var map;
	var geocoder = new GClientGeocoder();
	
	function gMapLoad() {
		try{
			//map = new GMap2(document.getElementById("map"));
			//map.setCenter(new GLatLng(40.8, -96.666667), 3);
			//map.addControl(new GLargeMapControl());
		
		
			if( document.getElementById('address_list').innerHTML != "" ){
				processRepLocations( document.getElementById('address_list').innerHTML );
				
				var coords = new Array();
				coords = getCoordsFromURL();
				map.setCenter(new GLatLng(coords[0], coords[1]), 9);
				
			}
		}catch(e){ return; }

	}
	
	
	function getCoordsFromURL(){
		
		var coords = new Array();
		var loc = ''+window.location+'';
		
		var query_string = loc.substring( loc.indexOf( '?' )+1 );
		var query_split = query_string.split( '&' );
		
		for( i = 0; i < query_split.length; i++  ){
			
			var get_split = query_split[i].split( "=" );
			
			if( get_split[0] == 'lat' ){
				coords[0] = get_split[1];
			}else if( get_split[0] == 'lng' ){
				coords[1] = get_split[1];
			}
			
		}

		return coords;
		
	}
	
			
	//### processAddress( oForm )
	//##
	//#   formats form address data for getAddressCoords()
	var geocoder = new GClientGeocoder();
	
	var user_address = "";
	function processAddress( oForm ){
	
		var zip = getObject('user_zip').value  //document.getElementById( 'Locator_form1_user_zip' ).value;
		
		user_address = zip;
		
		//document.getElementById('rep_list').innerHTML = user_address;
		
		geocoder.getLocations(zip, getAddressCoords);
	
	}
	

	//### getAddressCoords(response)
	//##
	//#   asks geocoder for coordinates of the address requested
	var place;
	var user_lat = 0;
	var user_lng = 0;
	var distance = 0;
	var doesExist = "";
	function getAddressCoords(response) {

		var oForm = document.forms[0];
		var list = "";
		
		
		
		//#check the response of the request. A no-go means we post an error message
		if (!response || response.Status.code != 200) {
		
			doesExist = "Sorry, <i>'" + user_address + "'</i> cannot be found!!<br />.";
			
		}else{ //#but is all's good, add lat and long to the form
		
			place = response.Placemark[0];
			
			user_lat = place.Point.coordinates[1];
			user_lng = place.Point.coordinates[0];
			//gotoLoc();
										
		}	
		
		if( place == null ){ 
			document.getElementById('locator_feedback').innerHTML = doesExist;
		}else{
			
			var radios = getObject('radio_td').getElementsByTagName('INPUT');
			
			for( i = 0; i < radios.length; i++ ){
				if( radios[i].checked ){ distance = radios[i].value; break; }
			}
			
			var address = 'zip_locator_app.aspx?lat='+user_lat+'&lng='+user_lng+'&distance='+distance+'&zip='+user_address ;
			
			//alert( address );
			//window.location = address;
			//document.getElementById('locator_feedback').innerHTML = address;
			
			xmlRequest( address, 'locations_list' );
		
		}
		
		//#now we process the form
		//validateForm( oForm );			
		
	}
	
	
	
	//### processRepLocations( source )
	//##
	//#	  processes rep addresses returned in locator app
	function processRepLocations( source ){
		
		try{
			//#clear any existing markers from the map
			map.clearOverlays();
			
			//#break apart the list rep details (lat,long,name&address)
			locationsArray = source.split(':');
			//alert( source );
			
			for (var i = 0; i < locationsArray.length; i++) {
				var coords = locationsArray[i].split(',');
			
				var lat = parseFloat(coords[0]);
				var lng = parseFloat(coords[1]);
				var point = new GLatLng(lat,lng);
				var html = trim( "<span><b>" + coords[2] + "</b><br />" + coords[3] + "<br />" + coords[4] + ", " + coords[5] + "</span>" );
				var marker = createMarker(point,html);
				map.addOverlay(marker);
				
			}
		}catch(e){}
		
	}
	
	
	
	// A function to create the marker and set up the event window
	// Dont try to unroll this function. It has to be here for the function closure
	// Each instance of the function preserves the contends of a different instance
	// of the "marker" and "html" variables which will be needed later when the event triggers.    
	function createMarker(point,html) {
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		});
		return marker;
	}