 
   var cityArray = new Array();
   var xmlhttp=null;
   //
   //  Build xmlhttp object
   //
   if (window.XMLHttpRequest) 
   {
     // If IE7, Mozilla, Safari, and so on: Use native object.
     xmlhttp = new XMLHttpRequest();
   }
   else
   {
     if (window.ActiveXObject) 
     {
        // ...otherwise, use the ActiveX control for IE5.x and IE6.
        xmlhttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
     }
   }   
    
      
   /*   This is deprecated by the use of jQuery to check when DOM is ready  
            
          function InitAll()
          {
             document.getElementById("searchcity").onkeyup= ShowCity;
             document.getElementById('_ctl0_ContentPlaceHolder1_myzip').focus();
          }
          
       window.onload = InitAll ;
   */
   
   $(document).ready(function() 
   {
       $(".locmap").css("z-index","0"); 
       document.getElementById("searchcity").onkeyup= ShowCity;
        if(document.getElementById('_ctl0_ContentPlaceHolder1_capval').value=='99') 
        {
             document.getElementById('_ctl0_ContentPlaceHolder1_myzip').focus();
             document.getElementById('captchadiv').style.display='none';
        }
         else
         {
             document.getElementById('_ctl0_ContentPlaceHolder1_txtcaptcha').focus();
             
         }
       //alert(document.getElementById('_ctl0_ContentPlaceHolder1_capval').value);
       
    });    
      
   //
   //   Build list of search string city matches
   //
   function ShowCity()
   {
       var str = document.getElementById("searchcity").value;
       document.getElementById("searchcity").className="";
       if(str!="")
       {
          str= str.toLowerCase();
          document.getElementById("popups").innerHTML="";
          for(var i=0;i<cityArray.length;i++)
          {
            var thisCity = cityArray[i];
            if(thisCity.toLowerCase().indexOf(str)==0) 
            {            
               var tempDiv = document.createElement("div");
               tempDiv.innerHTML= thisCity;
               tempDiv.onclick= makeChoice;
               // These two are required for IE since div.hover does not work
               tempDiv.onmouseover = function() {this.className = "hover";};
               tempDiv.onmouseout = function() {this.className = "suggestions";};
               
               tempDiv.className ="suggestions";                
               document.getElementById("popups").appendChild(tempDiv);               
            }
          
          }
          var foundCt = document.getElementById("popups").childNodes.length;
          if(foundCt>18)   // Do not display if too many
          {
            document.getElementById("popups").innerHTML="";
          }
          else
          {
             if(foundCt==0)
             { 
               document.getElementById("searchcity").className="error";
             }
             if(foundCt==1) 
             {
               document.getElementById("searchcity").value= document.getElementById("popups").firstChild.innerHTML;
               document.getElementById("popups").innerHTML="";
             }
          }
       }   
   }
   
  
   
   function makeChoice(evt)
   {
       var thisDiv = (evt) ? evt.target:window.event.srcElement;
       document.getElementById("searchcity").value=thisDiv.innerHTML;
       document.getElementById("popups").innerHTML="";   
   }
   
   function popdealer(web)
   {
       webwin = window.open(web,null,"height=600,width=740,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
   }
   
   function fetchCities()
   {
         if(document.getElementById('mystate').value !='xx')
         {
            document.getElementById('loader').style.visibility="visible";
            document.getElementById("popups").innerHTML="";
            //if (typeof window.innerWidth != 'undefined')  
            document.getElementById('loader').style.visibility="visible";
            url="Buildcity.aspx?st="+document.getElementById('mystate').value;

            if(xmlhttp ) xmlhttp.abort();    // Required for IE 6 and below
            xmlhttp.onreadystatechange = showContents;
            xmlhttp.open('GET',url,true);    // true - asynchronous. required for IE to work well
            xmlhttp.send(null);
         }
   }
   
   function showContents()
   {
        
       if(xmlhttp.readyState==4)
       {
            LoadCityArray(xmlhttp.responseText);
            
           // Display dropdown list of all cities
           //    if(document.getElementById('clist'))
           //    {
           //      document.getElementById('clist').innerHTML = '<select name="mycity" id="mycity" width="120px" size="1" >'+xmlhttp.responseText+'</select>';
           //    }
            document.getElementById('_ctl0_ContentPlaceHolder1_myzip').value='';
            document.getElementById('loader').style.visibility="hidden";
            document.getElementById('searchcity').value="";
            document.getElementById('searchcity').focus();
        }          
        
   }
   
   //
   //  Create array of all cities. This list is in <option> format to also support
   //  select list (dropdown box).
   //
   function LoadCityArray( selList)
   {
      cityArray = [];
      var splitList =selList.split("</option>");
      for(var i=0;i<splitList.length;i++)
      {
         ndx = splitList[i].indexOf(">");         
         cityArray[i]=  splitList[i].substring(ndx+1);      
      }      
   }  
   
   
   //
   //    Fetch Locations based on zip code or city/state
   //
   function fetchLocations()
   {
     if(document.getElementById('_ctl0_ContentPlaceHolder1_capval').value=='99') 
     {
      zip= document.getElementById('_ctl0_ContentPlaceHolder1_myzip').value;
      document.getElementById("popups").innerHTML="";
      if(zip.length<5)
      {
         var st = document.getElementById('mystate').value;
         //var city = document.getElementById('_ctl0_ContentPlaceHolder1_mycity').value;
         var city = document.getElementById('searchcity').value;
         url="BuildLocations.aspx?st="+st+"&cty="+city;
      
      }
      else
      {
         url="BuildLocations.aspx?id="+zip;         
      }
      xmlhttp.open('GET',url,false);      // synchronous
      xmlhttp.send(null);
      if(document.getElementById('xmlLocs'))
      {
         document.getElementById('xmlLocs').innerHTML = xmlhttp.responseText;
         document.getElementById('mapheader').style.visibility='visible';
         if(document.getElementById('xmlLocsHolder'))
         {
            document.getElementById('locmap').style.width='440px';
            document.getElementById('locmap').style.height='340px';
            document.getElementById('locmap').style.visibility='visible';
            document.getElementById('locmap').innerHTML='<img src=./images/dealer_map.jpg style="position:relative;">';
            document.getElementById('title').style.visibility='hidden';
         }  
      }
     }
   }
   
   function ShowMap(lat,long, bn, addr)
   {
       if (GBrowserIsCompatible()) 
       {
            document.getElementById("popups").innerHTML="";
            var map = new GMap2(document.getElementById("locmap"));
            document.getElementById('locmap').style.width='500px';
            document.getElementById('locmap').style.height='400px';
            var geocoder = new GClientGeocoder();
            showAddress(addr, map, geocoder, lat, long);

            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            document.getElementById("title").innerHTML=bn;   

            if(document.getElementById('xmlLocsHolder'))
            {
                 document.getElementById('locmap').style.visibility='visible';
                 document.getElementById('title').style.visibility='visible';
            }  
       }
   }
   
   
  function showAddress(address, map, geocoder, lat, long ) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) 
      {
        // alert(address + " not found");
        map.setCenter(new GLatLng(lat, long), 13);    
        var pt = new GLatLng(lat,long);
        var mk = new GMarker(pt);
        map.addOverlay(mk);         
        
      } else 
      {
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        //
        GEvent.addListener(marker, "click", function() {
	    map.showMapBlowup(point,
                      {mapType:G_NORMAL_MAP});
	  });

        //
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);      
        map.showMapBlowup(point,
                      {mapType:G_NORMAL_MAP});
      }
    }
  );
} 
