  
  var talleyaddress = "9183 Old Number Six Hwy<br>Santee, SC, 29142";
	var map;
	var directionsPanel;
	var directions;
	var nonajaxToAddr;
	var nonajaxDealerName;
	var nonajaxDealerPhone;

  addEvent(window, 'load', init, false);
	
	function load(fromaddr,toaddr,dealername,dealerphone) 
	{
		if (GBrowserIsCompatible()) 
		{		
			map = new GMap2(document.getElementById("map"));
			defMap();
			loadMarkers();			
			
			if(fromaddr == ", , US" ||
				 fromaddr == "" ||
				 fromaddr == "(Ex. 123 Main St), , US")
			{

			}
			else
			{

				getDirections(fromaddr, toaddr, dealername,dealerphone);
			}
		}
	}
	
	function defMap()
	{
		map.setCenter(new GLatLng(39.50, -98.35), 4);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());

		nonajaxToAddr = "";
		nonajaxDealerName = "";
		nonajaxDealerPhone = "";
	}
	
	function getDirections(fromaddr, toaddr, dealername,dealerphone)
	{
	  directionsPanel = document.getElementById("directions");
  	map.setCenter(new GLatLng(49.496675,-102.65625), 3);
	  directions = new GDirections(map, directionsPanel);
	  GEvent.addListener(directions, "error", handleErrors);
  	directions.load("from: " + fromaddr + " to: " + toaddr);
  
  	$('searchtoolbar').setStyles({'display' : 'block'});
  	$('search').setStyles({'display' : 'none'});
  	document.getElementById('dealername').innerHTML=dealername;
  	document.getElementById('dealeraddr').innerHTML=toaddr;
  	document.getElementById('dealerphone').innerHTML=dealerphone;
	}
	
	function handleErrors()
	{		
		if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + directions.getStatus().code);
	  else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + directions.getStatus().code);
	   
	  else if (directions.getStatus().code == G_GEO_MISSING_QUERY)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + directions.getStatus().code);

	//   else if (directions.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + directions.getStatus().code);
	     
	  else if (directions.getStatus().code == G_GEO_BAD_KEY)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: The given key is either invalid or does not match the domain for which it was given. \n Error code: " + directions.getStatus().code);

	  else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: A directions request could not be successfully parsed.\n Error code: " + directions.getStatus().code);
	    
	  else alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: An unknown error occurred.");
	  	
	 	resetSearch();
	  
	}

	
	function resetSearch()
	{
		defMap();
		
		if(directions) {directions.clear();}
		$('searchtoolbar').setStyles({'display' : 'none'});
		$('searchtitle').setStyles({'display' : 'block'});
		$('searchdesc').setStyles({'display' : 'block'});
		$('search').setStyles({'display' : 'block'});
		
		document.getElementById('directions').innerHTML='';
		document.getElementById('dealername').innerHTML='';
		document.getElementById('dealeraddr').innerHTML='';
		document.getElementById('dealerphone').innerHTML='';
		nonajaxToAddr = "";
		nonajaxDealerName = "";
		nonajaxDealerPhone = "";
	}
	
	function setNonAjaxSearch(naAddr, naDealerName, naDealerPhone)
	{
		resetSearch();
		
		nonajaxToAddr = naAddr;
		nonajaxDealerName = naDealerName;
		nonajaxDealerPhone = naDealerPhone;
		
		$('searchtitle').setStyles({'display' : 'none'});
		$('searchdesc').setStyles({'display' : 'none'});
		
		$('searchtoolbar').setStyles({'display' : 'block'});
	
  	document.getElementById('dealername').innerHTML=naDealerName;
  	document.getElementById('dealeraddr').innerHTML=naAddr;
  	document.getElementById('dealerphone').innerHTML=naDealerPhone;
 	}

  function init() {
      if (!Sarissa || !document.getElementById) return;
      
      var formElements = document.getElementsByTagName('form');
      for (var i = 0; i < formElements.length; i++) {
          if (formElements[i].className.match(/\bajaxify\b/)) {
              addEvent(formElements[i], 'submit', getClosestDealer, false);
          }
      }
  }
  
  function getClosestDealer(e) {
  	
	      /* Cancel the submit event, and find out which form was submitted */
      knackerEvent(e);
      var target = window.event ? window.event.srcElement : e ? e.target : null;
      if (!target) return;
      
      /* Check if this form is already in the process of being submitted. 
       * If so, don't allow it to be submitted again. */
      if (target.ajaxInProgress) return;
      
     	if(nonajaxToAddr != "") 
  		{
  			getDirections(
  				target.elements['address'].value + "," + target.elements['zip'].value + "," + target.elements['country'].value, 
  				nonajaxToAddr, nonajaxDealerName, nonajaxDealerPhone);
  			return;
  		}
      
      /* Set up the request */
      var xmlhttp =  new XMLHttpRequest();
      xmlhttp.open('POST', 'http://www.talleymanufacturing.com/cgi-bin/public_controller.cgi', true);
      
      /* The callback function */
      xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4) {
              if (xmlhttp.status == 200)
                  showDirections(xmlhttp.responseXML, target);
              else
                  target.submit();
          }
      }

      /* Send the POST request */
      xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      //xmlhttp.send('rating=' + target.elements['rating'].value);
			xmlhttp.send("view=ajax_map&address=" + target.elements['address'].value + 
				"&zip=" + target.elements['zip'].value + 
				"&country=" + target.elements['country'].value);   
			
      /* Add temporary feedback that the request has been sent */   
      var loadingImg = document.createElement('img');
      loadingImg.src = '../img/sub/working.gif';
      //target.getElementsByTagName('search')[0].appendChild(loadingImg);
      target.ajaxInProgress = true;
  }
  
  function showDirections(responseXML, target) {

			getDirections(responseXML.getElementsByTagName('useraddr')[0].firstChild.data,
										responseXML.getElementsByTagName('dealeraddr')[0].firstChild.data,
										responseXML.getElementsByTagName('dealername')[0].firstChild.data,
										responseXML.getElementsByTagName('dealerphone')[0].firstChild.data);
										
      // Free up the form to go again
      target.ajaxInProgress = false;
  }
    
  var talleyaddress = "9183 Old Number Six Hwy<br>Santee, SC, 29142";
	var map;
	var directionsPanel;
	var directions;
	var nonajaxToAddr;
	var nonajaxDealerName;
	var nonajaxDealerPhone;

  addEvent(window, 'load', init, false);
	
	function load(fromaddr,toaddr,dealername,dealerphone) 
	{
		if (GBrowserIsCompatible()) 
		{		
			map = new GMap2(document.getElementById("map"));
			defMap();
			loadMarkers();			
			
			if(fromaddr == ", , US" ||
				 fromaddr == "" ||
				 fromaddr == "(Ex. 123 Main St), , US")
			{

			}
			else
			{

				getDirections(fromaddr, toaddr, dealername,dealerphone);
			}
		}
	}
	
	function defMap()
	{
		map.setCenter(new GLatLng(39.50, -98.35), 4);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());

		nonajaxToAddr = "";
		nonajaxDealerName = "";
		nonajaxDealerPhone = "";
	}
	
	function getDirections(fromaddr, toaddr, dealername,dealerphone)
	{
	  directionsPanel = document.getElementById("directions");
  	map.setCenter(new GLatLng(49.496675,-102.65625), 3);
	  directions = new GDirections(map, directionsPanel);
	  GEvent.addListener(directions, "error", handleErrors);
  	directions.load("from: " + fromaddr + " to: " + toaddr);
  
  	$('searchtoolbar').setStyles({'display' : 'block'});
  	$('search').setStyles({'display' : 'none'});
  	document.getElementById('dealername').innerHTML=dealername;
  	document.getElementById('dealeraddr').innerHTML=toaddr;
  	document.getElementById('dealerphone').innerHTML=dealerphone;
	}
	
	function handleErrors()
	{		
		if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + directions.getStatus().code);
	  else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + directions.getStatus().code);
	   
	  else if (directions.getStatus().code == G_GEO_MISSING_QUERY)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + directions.getStatus().code);

	//   else if (directions.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + directions.getStatus().code);
	     
	  else if (directions.getStatus().code == G_GEO_BAD_KEY)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: The given key is either invalid or does not match the domain for which it was given. \n Error code: " + directions.getStatus().code);

	  else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: A directions request could not be successfully parsed.\n Error code: " + directions.getStatus().code);
	    
	  else alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: An unknown error occurred.");
	  	
	 	resetSearch();
	  
	}

	
	function resetSearch()
	{
		defMap();
		
		if(directions) {directions.clear();}
		$('searchtoolbar').setStyles({'display' : 'none'});
		$('searchtitle').setStyles({'display' : 'block'});
		$('searchdesc').setStyles({'display' : 'block'});
		$('search').setStyles({'display' : 'block'});
		
		document.getElementById('directions').innerHTML='';
		document.getElementById('dealername').innerHTML='';
		document.getElementById('dealeraddr').innerHTML='';
		document.getElementById('dealerphone').innerHTML='';
		nonajaxToAddr = "";
		nonajaxDealerName = "";
		nonajaxDealerPhone = "";
	}
	
	function setNonAjaxSearch(naAddr, naDealerName, naDealerPhone)
	{
		resetSearch();
		
		nonajaxToAddr = naAddr;
		nonajaxDealerName = naDealerName;
		nonajaxDealerPhone = naDealerPhone;
		
		$('searchtitle').setStyles({'display' : 'none'});
		$('searchdesc').setStyles({'display' : 'none'});
		
		$('searchtoolbar').setStyles({'display' : 'block'});
	
  	document.getElementById('dealername').innerHTML=naDealerName;
  	document.getElementById('dealeraddr').innerHTML=naAddr;
  	document.getElementById('dealerphone').innerHTML=naDealerPhone;
  	scrollTo(0,0);

 	}

  function init() {
      if (!Sarissa || !document.getElementById) return;
      
      var formElements = document.getElementsByTagName('form');
      for (var i = 0; i < formElements.length; i++) {
          if (formElements[i].className.match(/\bajaxify\b/)) {
              addEvent(formElements[i], 'submit', getClosestDealer, false);
          }
      }
  }
  
  function getClosestDealer(e) {
  	
	      /* Cancel the submit event, and find out which form was submitted */
      knackerEvent(e);
      var target = window.event ? window.event.srcElement : e ? e.target : null;
      if (!target) return;
      
      /* Check if this form is already in the process of being submitted. 
       * If so, don't allow it to be submitted again. */
      if (target.ajaxInProgress) return;
      
     	if(nonajaxToAddr != "") 
  		{
  			getDirections(
  				target.elements['address'].value + "," + target.elements['zip'].value + "," + target.elements['country'].value, 
  				nonajaxToAddr, nonajaxDealerName, nonajaxDealerPhone);
  			return;
  		}
      
      /* Set up the request */
      var xmlhttp =  new XMLHttpRequest();
      xmlhttp.open('POST', 'http://www.talleymanufacturing.com/cgi-bin/public_controller.cgi', true);
      
      /* The callback function */
      xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4) {
              if (xmlhttp.status == 200)
                  showDirections(xmlhttp.responseXML, target);
              else
                  target.submit();
          }
      }

      /* Send the POST request */
      xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      //xmlhttp.send('rating=' + target.elements['rating'].value);
			xmlhttp.send("view=ajax_map&address=" + target.elements['address'].value + 
				"&zip=" + target.elements['zip'].value + 
				"&country=" + target.elements['country'].value);   
			
      /* Add temporary feedback that the request has been sent */   
      var loadingImg = document.createElement('img');
      loadingImg.src = '../img/sub/working.gif';
      //target.getElementsByTagName('search')[0].appendChild(loadingImg);
      target.ajaxInProgress = true;
  }
  
  function showDirections(responseXML, target) {

			getDirections(responseXML.getElementsByTagName('useraddr')[0].firstChild.data,
										responseXML.getElementsByTagName('dealeraddr')[0].firstChild.data,
										responseXML.getElementsByTagName('dealername')[0].firstChild.data,
										responseXML.getElementsByTagName('dealerphone')[0].firstChild.data);
										
      // Free up the form to go again
      target.ajaxInProgress = false;
  }
    
  var talleyaddress = "9183 Old Number Six Hwy<br>Santee, SC, 29142";
	var map;
	var directionsPanel;
	var directions;
	var nonajaxToAddr;
	var nonajaxDealerName;
	var nonajaxDealerPhone;

  addEvent(window, 'load', init, false);
	
	function load(fromaddr,toaddr,dealername,dealerphone) 
	{
		if (GBrowserIsCompatible()) 
		{		
			map = new GMap2(document.getElementById("map"));
			defMap();
			loadMarkers();			
			
			if(fromaddr == ", , US" ||
				 fromaddr == "" ||
				 fromaddr == "(Ex. 123 Main St), , US")
			{

			}
			else
			{

				getDirections(fromaddr, toaddr, dealername,dealerphone);
			}
		}
	}
	
	function defMap()
	{
		map.setCenter(new GLatLng(39.50, -98.35), 4);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());

		nonajaxToAddr = "";
		nonajaxDealerName = "";
		nonajaxDealerPhone = "";
	}
	
	function getDirections(fromaddr, toaddr, dealername,dealerphone)
	{
	  directionsPanel = document.getElementById("directions");
  	map.setCenter(new GLatLng(49.496675,-102.65625), 3);
	  directions = new GDirections(map, directionsPanel);
	  GEvent.addListener(directions, "error", handleErrors);
  	directions.load("from: " + fromaddr + " to: " + toaddr);
  
  	$('searchtoolbar').setStyles({'display' : 'block'});
  	$('search').setStyles({'display' : 'none'});
  	document.getElementById('dealername').innerHTML=dealername;
  	document.getElementById('dealeraddr').innerHTML=toaddr;
  	document.getElementById('dealerphone').innerHTML=dealerphone;
	}
	
	function handleErrors()
	{		
		if (directions.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + directions.getStatus().code);
	  else if (directions.getStatus().code == G_GEO_SERVER_ERROR)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + directions.getStatus().code);
	   
	  else if (directions.getStatus().code == G_GEO_MISSING_QUERY)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + directions.getStatus().code);

	//   else if (directions.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + directions.getStatus().code);
	     
	  else if (directions.getStatus().code == G_GEO_BAD_KEY)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: The given key is either invalid or does not match the domain for which it was given. \n Error code: " + directions.getStatus().code);

	  else if (directions.getStatus().code == G_GEO_BAD_REQUEST)
	    alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: A directions request could not be successfully parsed.\n Error code: " + directions.getStatus().code);
	    
	  else alert("We're Sorry, but there was a problem with the address you entered.  Please enter again.\n\nError: An unknown error occurred.");
	  	
	 	resetSearch();
	  
	}

	
	function resetSearch()
	{
		defMap();
		
		if(directions) {directions.clear();}
		$('searchtoolbar').setStyles({'display' : 'none'});
		$('searchtitle').setStyles({'display' : 'block'});
		$('searchdesc').setStyles({'display' : 'block'});
		$('search').setStyles({'display' : 'block'});
		
		document.getElementById('directions').innerHTML='';
		document.getElementById('dealername').innerHTML='';
		document.getElementById('dealeraddr').innerHTML='';
		document.getElementById('dealerphone').innerHTML='';
		nonajaxToAddr = "";
		nonajaxDealerName = "";
		nonajaxDealerPhone = "";
	}
	
	function setNonAjaxSearch(naAddr, naDealerName, naDealerPhone)
	{
		resetSearch();
		
		nonajaxToAddr = naAddr;
		nonajaxDealerName = naDealerName;
		nonajaxDealerPhone = naDealerPhone;
		
		$('searchtitle').setStyles({'display' : 'none'});
		$('searchdesc').setStyles({'display' : 'none'});
		
		$('searchtoolbar').setStyles({'display' : 'block'});
	
  	document.getElementById('dealername').innerHTML=naDealerName;
  	document.getElementById('dealeraddr').innerHTML=naAddr;
  	document.getElementById('dealerphone').innerHTML=naDealerPhone;
  	scrollTo(0,0);

 	}

  function init() {
      if (!Sarissa || !document.getElementById) return;
      
      var formElements = document.getElementsByTagName('form');
      for (var i = 0; i < formElements.length; i++) {
          if (formElements[i].className.match(/\bajaxify\b/)) {
              addEvent(formElements[i], 'submit', getClosestDealer, false);
          }
      }
  }
  
  function getClosestDealer(e) {
  	
	      /* Cancel the submit event, and find out which form was submitted */
      knackerEvent(e);
      var target = window.event ? window.event.srcElement : e ? e.target : null;
      if (!target) return;
      
      /* Check if this form is already in the process of being submitted. 
       * If so, don't allow it to be submitted again. */
      if (target.ajaxInProgress) return;
      
     	if(nonajaxToAddr != "") 
  		{
  			getDirections(
  				target.elements['address'].value + "," + target.elements['zip'].value + "," + target.elements['country'].value, 
  				nonajaxToAddr, nonajaxDealerName, nonajaxDealerPhone);
  			return;
  		}
      
      /* Set up the request */
      var xmlhttp =  new XMLHttpRequest();
      xmlhttp.open('POST', 'http://www.talleymanufacturing.com/cgi-bin/public_controller.cgi', true);
      
      /* The callback function */
      xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4) {
              if (xmlhttp.status == 200)
                  showDirections(xmlhttp.responseXML, target);
              else
                  target.submit();
          }
      }

      /* Send the POST request */
      xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      //xmlhttp.send('rating=' + target.elements['rating'].value);
			xmlhttp.send("view=ajax_map&address=" + target.elements['address'].value + 
				"&zip=" + target.elements['zip'].value + 
				"&country=" + target.elements['country'].value);   
			
      /* Add temporary feedback that the request has been sent */   
      var loadingImg = document.createElement('img');
      loadingImg.src = '../img/sub/working.gif';
      //target.getElementsByTagName('search')[0].appendChild(loadingImg);
      target.ajaxInProgress = true;
  }
  
  function showDirections(responseXML, target) {

			getDirections(responseXML.getElementsByTagName('useraddr')[0].firstChild.data,
										responseXML.getElementsByTagName('dealeraddr')[0].firstChild.data,
										responseXML.getElementsByTagName('dealername')[0].firstChild.data,
										responseXML.getElementsByTagName('dealerphone')[0].firstChild.data);
										
      // Free up the form to go again
      target.ajaxInProgress = false;
  }
  
