  //<![CDATA[
   var zipar = [ ] ;					// Zips Found
   var chkar = [ ] ;					// Places Found
   var plcar = [ ] ;					// Places Found
   var marar = [ ] ;					// Marker Array
   var lastclick = "" ;					// Last Clicked Point
   var map ;

   function LoadMap()
   {
    if (GBrowserIsCompatible()) 			// Do Map if Compatible Browser only
    {
     map = new GMap2(document.getElementById("map_canvas"));
     map.addControl(new GLargeMapControl());
     map.addControl(new GMapTypeControl());
     map.addControl(new GScaleControl()) ;
     map.addControl(new GOverviewMapControl()) ;
     var latlng = new GLatLng(35.036040,-89.977512) ; // Memphis Airport
     map.setCenter(latlng,4);
     GEvent.addListener(map, 'click', function(overlay, point)
     {
      if (overlay)
      {
      } else if (point) 
      {
       checkclick( point ) ;
      }
     });
     if ( location.search.length > 1 )
     {
      zippoly( 0, location.search.substring(3,location.search.length) ) ;
     }   
    } else
    {
     document.getElementById("map").innerHTML = "<h1>Browser not compatible with Google Maps. Sorry...</h1>" ;
    }
  }

// Find a zip code and cause it to be drawn on the map...

// Clear overlays, Div area and restore map...

   function clearmap( place )
   {
    place.zip.value = "" ;
    document.getElementById("message").innerHTML = "" ;
    map.clearOverlays() ;
    lastclick = "" ;
    zipar = [ ] ;
    chkar = [ ] ;
    plcar = [ ] ;
    marar = [ ] ;
   }

// Check for a double click...

   function checkclick ( point )
   {
    if ( lastclick != point )
    {
     lastclick = point ;
     zippoly( point, '' ) ;
    }
   }

// Open an Infowindow when the zip link is clicked in the message div...
        
   function placeLink(place)
   {
    for (var i = 0; i < plcar.length; i++)
    {
     if ( plcar[i] == place )
     {
      break ;
     } 
    }
    GEvent.trigger(marar[i], "click");
   }

// Check to see if a Place has already been selected...
        
   function CheckPlace(place)
   {
    for (var i = 0; i < chkar.length; i++)
    {
     if ( chkar[i] == place )
     {
      return(i) ;
     } 
    }
    return(-1) ;
   }

// Check to see if a Zip has already been selected...
        
   function CheckZip(zip)
   {
    for (var i = 0; i < zipar.length; i++)
    {
     if ( zipar[i] == zip )
     {
      return(i) ;
     } 
    }
    return(-1) ;
   }

// Find a zip code and return the polygon coordinates along with other information...

   function zippoly()
   {
    var request = GXmlHttp.create();
    var parms = "";
    request.open("GET", "js/ajax.xml", true);
    request.setRequestHeader('Content-Type','application/x-www-form-urlencoded') ;	// Thanks to Darkstar 3D!
    request.onreadystatechange = function() 
    {
     document.getElementById("loading").innerHTML = "Loading, please wait..." ;

     if (request.readyState == 4)
     {
      var xmlDoc = request.responseXML ;
      try
      {
       var info = xmlDoc.documentElement.getElementsByTagName("info") ;
       var place = info[0].getAttribute("place") ;
       var hitrem = parseInt(info[0].getAttribute("hitrem")) ;
       if ( hitrem <= 1 )
       {
        alert("You have exausted your requests for this time period. Please come back in 2 hours. If this is not enough for your purposes, please use the contact form, or see the sales information page for details on increasing your access.") ;
       } else if ( place == "-" )
       {
        alert("Area clicked not defined by a US Town or City") ;
       } else
       {
        var placeindex = CheckPlace( place ) ;
        if ( placeindex > -1 )
        {
         GEvent.trigger(marar[placeindex], "click")
        } else
        {
         var lastpoint	= map.getCenter() ;
         var point	= lastpoint ;
         var placename	= info[0].getAttribute("placename") ;
         var fipscsa	= info[0].getAttribute("fipscsa") ;
         var csaname	= info[0].getAttribute("csaname") ;
         var uspsst	= info[0].getAttribute("uspsst") ;
         var stname	= info[0].getAttribute("stname") ;
         var areas	= parseInt(info[0].getAttribute("areas")) ;
         var count	= parseInt(info[0].getAttribute("count")) ;
         chkar.push(place) ;
         for (var j = 1; j <= count; j++)
         {
          var polylines = xmlDoc.documentElement.getElementsByTagName("polyline" + j) ;
          var points = [] ;
          for (var i = 0; i < polylines.length; i++)
          {
           points.push( new GLatLng(parseFloat(polylines[i].getAttribute("lat")),parseFloat(polylines[i].getAttribute("lng"))) ) ;
          }
          map.addOverlay( new GPolyline(points,"#336600", 2, 1) ) ;
          var markers = xmlDoc.documentElement.getElementsByTagName("marker" + j);
          for (var i = 0; i < markers.length; i++)
          {
           point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng"))) ;
           html	= "<div style='width:200px; text-align:left;'><b>Town/City Code:</b> " + place + 
                   "<br>" + placename + 
                   "<br>" + uspsst + " - " + stname +
                   "<br>FIPS CSA: " + fipscsa + 
                   "<br>" + csaname ;
           if ( areas > 1 )
           {
            html += "<br>Number of Areas: " + j + "/" + areas ;
           }
           html	+= "</div>" ;
           marar.push( createMarker( point, html ) ) ;
           map.addOverlay(marar[marar.length-1]);
           plcar.push(place + "A" + j) ;
           var html	= "<a href=\"javascript:placeLink('" + place + "A" + j + "')\">" + place ;
           if ( areas > 1 )
           {
            html += " (" + j + ")" ;
           }
           html += "</a><br>&nbsp;" + placename + ", " + uspsst + "<br>" ; 
           document.getElementById("message").innerHTML =  html + document.getElementById("message").innerHTML ;
          }
         }
         if ( point != lastpoint )
         {
          if( chkar.length > 1 )
          {
           map.setCenter( point, map.getZoom() ) ;
          } else
          {
           map.setCenter( point, 12 ) ;
          }
         }
        }
       }
      } catch(e)
      {
       alert("Some error occured during program processing:" + e) ;
      }       
      document.getElementById("loading").innerHTML = "" ;
     }
    }
    request.send();
   }

// Create a marker at a point with an infowindow...

   function createMarker(point, html) 
   {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function()
    {
     marker.openInfoWindowHtml(html);
    });
    return marker;
   }

  //]]>
