    // A function to create the marker and set up the event window
    function createMarker(point,html) {
    	var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html,{maxWidth:150});
        });

        return marker;
    }

      // This function picks up the click and opens the corresponding info window
    function getMarker(m) {
    	gmarkers[m].openInfoWindowHtml(htmls[m],{maxWidth:150});
    }
	  	
    function load() {
      if (GBrowserIsCompatible()) {
	  	  	
        var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			map.addControl(new GScaleControl());	
				
		for (i = 0; i < locales.length; i++){
			site = explodeArray(locales[i], ',');
			if (site[1] != '  '){
				//add address to map
				//alert(site[1]);
				showAddress(site, map, i);			
			} //if (site[1] != ' ')
		} // for (i=0; i < locales.length; i++)		
	  } //if (GBrowserIsCompatible())
    } //function load()
	
	function showAddress(site, map, index){
	//alert('here' + site[1]);
		var point = new GLatLng(site[1], site[2]);
		var Zippoint = new GLatLng(zipLong, zipLat);
		//determine zoom level based on tolerance
		if (tolerance == 25) {
			map.setCenter(Zippoint, 9);
		} else if (tolerance == 50) {
			map.setCenter(Zippoint, 7);
		} else if (tolerance == 100) {
			map.setCenter(Zippoint, 6);
		}
			
		var mHTML = '<div class="infoWindow"><b>' + trim(site[0]) + '</b><br>' + trim(site[3]) + '<br>' + trim(site[5]) + ', ' + 
					trim(site[6]) + ' ' + trim(site[7]) + '<br>' + trim(site[8]) + ' mile' + ((site[8] > 1 || site[8] == 0) ? 's' : '') + 
					' &bull; <a href="http://maps.google.com/maps?saddr=' + zip + '&daddr=' + trim(site[3].replace(/\s/g,"+")) + 
					trim(site[5].replace(/\s/g,"+")) + trim(site[6].replace(/\s/g,"+")) + trim(site[7].replace(/\s/g,"+")) + 
					'" target="_blank">Get Directions</a></div>';
		
		var marker = createMarker(point,mHTML);					
		map.addOverlay(marker);

   	    // save the info we need to use later for our location list links	
		gmarkers[g] = marker;
		htmls[g] = mHTML;
				
		//increment our counter variable g
		g++; 
	}
	
	//this function validates our search required fields
	function validateSearch(theForm) {
		
		var allValid = true;
		//the possible combinations are as follow
		//1. Zip code only
		//2. City & State
		if ((theForm.zip.value.length < 5 || trim(theForm.zip.value) == '' || !IsNumeric(trim(theForm.zip.value))) && (theForm.city.value.length == 0 && theForm.state.selectedIndex == 0)) {
			alert("Please enter a valid zip code OR a valid city and state.");
			allValid = false;
		} else {
			if (theForm.zip.value.length == 0) {
				if (theForm.city.value.length == 0 && theForm.state.selectedIndex == 0
					|| theForm.city.value.length > 0 && theForm.state.selectedIndex == 0
					|| theForm.state.selectedIndex > 0 && theForm.city.value.length == 0) {
					alert("Please enter the City and State or search by Zip code.");
					allValid = false;
				} //if (theForm.city.value.length == 0 && theForm.state.selectedIndex == 0 || theForm.city.value.length > 0 && theForm.state.selectedIndex == 0 || theForm.state.selectedIndex > 0 && theForm.city.value.length == 0)
			} //if (theForm.zip.value.length == 0)
		} //if ((theForm.zip.value.length == 0 || theForm.zip.value == '') && (theForm.city.value.length == 0 && theForm.state.selectedIndex == 0))
		
		return allValid;
	}
