﻿var map;
var geocoder;
var baseIcon;
var ImageArray;
var ImageArrayIndex;
var BusinessNameArray;//for VN
//var BusinessNameArrayIndex; //for VN
var fromAddress;
var toAddress;
var mapZoom;
var treeview;
var scrollMapPosition;
var businessName;
var VImageName;
var DisplayInfoWindowFlag;
var DicBusAddress;
var DicAdressToBus;
var VNnodeExpanded = false;

function FindBabyName()
{
   window.location.assign('BabyNames.aspx?father=' + document.getElementById('TextFatherName').value + '&mother=' + document.getElementById('TextMotherName').value);
}

function FindMovieTrailer()
{
   window.location.assign('MovieTrailersbyActor.aspx?actor=' + document.getElementById('TextMovieName').value);
}

   function clearnodes() {
        var selectedNode = treeview.getNodes();
       for (var i = 0; i < selectedNode.length; i++) {          
            var childNodes = selectedNode[i].getChildNodes();               
               for (var j = 0; j < childNodes.length; j++)                  
               {
                 childNodes[j].setChecked(false);                               
               }                
           selectedNode[i].setChecked(false);
       }
    
   }
//flytreeview help   http://www.9rays.net/asp.net_2/treeview/miscpages/doc/ClientEvents.aspx
       function flyTreeView_onInitialized(treeviewObject) {           
           treeview = treeviewObject;           
       }
 
  function flyTreeView_onNodeEvent(sender,node,eventType) {           
     if(eventType == 'expanded' && VNnodeExpanded == false)//move footer only once for expand
       {
          document.getElementById('DivFooter').style.top = '2880px';
         VNnodeExpanded = true;
       }
    }     

function onKeyDownofBusinessText(event)
{
if(event.which || event.keyCode)
{
   if ((event.which == 13) || (event.keyCode == 13))
    {// alert(document.getElementById('textBoxSearch').value.length);
     if(document.getElementById('textBoxSearch').value.length == 0)
         {
         document.getElementById('textBoxSearch').value = "Enter Location";
         document.forms['form1'].elements['textBoxSearch'].focus();          
         }
      else         
        {   
        document.getElementById('butGo').click();
        document.forms['form1'].elements['butGo'].focus();
          return false;
        }
    //  return false;
    }
    clearnodes();
}
   else 
    { 
    return true;
    }
}
function scrollMap() { //not used ..issues
   // alert(scrollMapPosition);
    var ScrollTop = document.body.scrollTop; //documentElement.scrollTop; //document.body.scrollTop;
   // alert(ScrollTop);
    if (ScrollTop == 0) {
        if (window.pageYOffset)
            ScrollTop = window.pageYOffset;
        else
            ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
    }
  if (ScrollTop > scrollMapPosition)
        document.getElementById("googleMap").style.top = ScrollTop + 'px';
}
function SetFocusTo(control) {
 // if(document.getElementById('textBoxSearch').value.length == 0)   
    document.forms['form1'].elements[control].focus();
   
//    else
//    {   
//    document.getElementById('butGo').click();
//    document.forms['form1'].elements['butGo'].focus();
//    return false;
//    }
  //  document.forms['form1'].elements['butgo'].focus();
}
function DisplayInfoMessageForVirtual() {//For Virtual    
    document.getElementById('DivMessage').style.display = "";
}
function ReduceCensusHeight() {//For Virtual    
    document.getElementById('DivtableCensus').style.height = "352px";
}
function test1()
{
alert('hi');
}
function test(tt,tt1)
{
  alert(tt + tt1);
}
function DisplayInfoMessage(mesg) {
    
    if (mesg.length > 0 && mesg.substr(0, 7) != 'Did you' &&  mesg != "Search any location to enable this feature.") {//if there is only 1 result in the city search        
        window.location.assign(mesg);
    }
    else {
        document.getElementById('DivMessage').innerHTML = mesg;
        document.getElementById('DivMessage').style.display = "";
        document.getElementById("DivMessage").style.zIndex = 3;//in mozilla to bring them front
        document.getElementById('DivAccordianNews').style.display = "none"; 
    }
}
 
function UpdateMap(sender, args) {    
    // alert('updatemap');
    if (document.getElementById('textBoxBusinessName').value.length == 0) {
        initializeAjaxGMap(9);
        //alert('updatemap');
        EndRequestHandler(sender, args);
    }
    else {     
        ShowAndHideYahooNewsButton();
    }
}
function ClearBusinessName() {   
    document.getElementById('textBoxBusinessName').value = "";
   // document.getElementById('CustomSearchBox').style.visibility = "hidden";
}
function MoveBusinessResultsForMozilla() {   
 
    if(navigator.appName != "Microsoft Internet Explorer")
    {  
      document.getElementById("BusinessSearchResults").style.top = '-7px';
      document.getElementById("BusinessSearchResults").style.left = '0px';
      document.getElementById("DivTableBusinessResults").style.top = '-334px';
    
      document.getElementById("midTotal").style.top = '130px'; 
       document.getElementById("mainCon").style.top = '95px';       
       document.getElementById("DivNearbyPlaces").style.left = '1px';    
       document.getElementById("DivNearbyPlaces").style.top = '700px';
       document.getElementById("DivNearbyCaption").style.left = '1px';
       document.getElementById("DivNearbyTabSec").style.top = '1px'; 
       document.getElementById("DivAccordianNews").style.top = '-10px'; 
       document.getElementById("DailyUpdates").style.top = '328px';   
       document.getElementById("DivCoolStuffHead").style.top = '1050px';                           
       document.getElementById("weatherbox").style.top = '83px';  
    }
    var nodeSelected = false;
    if(treeview != null)
    {
      var selectedNode = treeview.getNodes();
       for (var i = 0; i < selectedNode.length; i++) 
       {          
          if(selectedNode[i].getChecked())
          {
            nodeSelected = true;
            break;            
          }
          else
          {
             var childNodes = selectedNode[i].getChildNodes()
               for (var j = 0; j < childNodes.length; j++)
                {  
                      if(childNodes[j].getChecked())
                      {
                        nodeSelected = true;
                        break;            
                      }
               }
               if(nodeSelected)
                  break;
          }          
       }
    }
       
     HideBusinessResultsDuringBackButton();
     
    if (document.getElementById('textBoxBusinessName').value.length > 0 || nodeSelected) 
    {
     document.getElementById('DivAccordianNews').style.display = "none";  
    // document.getElementById('DivTableBusinessResults').style.display = "";   //first time visitors when they search busines..it goes up and then displays down..inorder to avoid that...we display once its positioned.    
    if(document.getElementById('hfNotavalidCityMessage').value.length > 1)//== "No Results found.")//modified so that divtablebusiness no results found //goes down.and used for //(no business found + invalid city) and (business found + valid city.)
            {
            document.getElementById("DivTableBusinessResults").style.top = '18px';
            //document.getElementById('DivTableBusinessResults').style.display = "";  
            document.getElementById('hfNotavalidCityMessage').value = '';
            }  
    }
    else
    {
      var msg = document.getElementById('DivMessage').innerHTML;//dont display accordian  if did you mean appears
      if(msg.length < 1 && document.getElementById('hfNotavalidCityMessage').value.length < 1)      
         document.getElementById('DivAccordianNews').style.display = "";  
         else
         {
            document.getElementById("DivTableBusinessResults").style.top = '18px';
            // document.getElementById('DivTableBusinessResults').style.display = "";  
            document.getElementById('hfNotavalidCityMessage').value = '';
         }
     }
     
      
  //  MoveLocalSearchFooter();//move footer for localsearch after navigating from other subpags
}

function HideBusinessResultsDuringBackButton()
{
  var busResultsHide = readCookie('BusResultsHide');
         if(busResultsHide == null) {
       document.getElementById('textBoxBusinessName').value = "";
       }
        else {
        if(busResultsHide == "Y") {
            document.getElementById('textBoxBusinessName').value = "";
             }
        }        
}

function MoveVNElementsForMozilla() {   
    if(navigator.appName != "Microsoft Internet Explorer")
    {          
      document.getElementById("DivSearchBox").style.top = '0px'; 
      document.getElementById("mainCon").style.top = '60px'; 
      document.getElementById("DivMidRight").style.top = '279px';
      document.getElementById("DivTopCities").style.top = '279px';     
      document.getElementById("DivNearbyPlaces").style.top = '340px'; 
      document.getElementById("DivEmbedTag").style.top = '690px'; 
      document.getElementById("DivTourisitsResults").style.top = '615px'; 
      document.getElementById("DivTableBusinessResults").style.top = '280px';       
      document.getElementById("DivCensus").style.top = '695px';   
      document.getElementById("DivCensus").style.left = '-10px';//addednew    
      document.getElementById("DivTableCensus").style.top = '249px';      
      document.getElementById("DivTableCensus").style.left = '251px';//addednew     
      document.getElementById("weatherbox").style.top = '97px';//addednew
      document.getElementById("GetDirections").style.top = '535px';              
    }
}

function DisplayNews()
{ 
  clearnodes();
  document.getElementById("textBoxBusinessName").value = "";
  document.getElementById("GetDirections").style.display = 'none';   
  document.getElementById('butGo').click();   
}
 
function ShowHideCustomSearchBox() {
    document.getElementById('CustomSearchBox').style.visibility = "visible";
}
function ShowAndHideYahooNewsButton() { 
    //document.getElementById('Button1').value="New Name"    alert(document.getElementById('textBoxZipCodeafterSearch').value);
    var splitZipCity = document.getElementById('textBoxZipCodeafterSearch').value.split(";");
    //alert(splitZipCity);
    if (splitZipCity.length >= 2) //show button
    {  //alert(document.getElementById('textBoxZipCodeafterSearch').value);//    alert(splitZipCity.length);
         document.getElementById('DivMessage').style.display = "none";  
//        document.getElementById("ButtonTrafficNews").style.textAlign = document.getElementById("ButtonIndeedJobs").style.textAlign = document.getElementById("ButtonFlight").style.textAlign = "center";
        // document.getElementById('ButtonYahooNews').value = 'Local News for ' + splitZipCity[1];        
        //document.getElementById("ButtonSchools").disabled = false;
       // document.getElementById('ButtonAparments').value = 'Apartments in ' + splitZipCity[1];                 
//        document.getElementById('ButtonRealEstate').value = 'Real Estate for ' + splitZipCity[1];
//        document.getElementById('ButtonFlight').value = 'Flight Deals for ' + splitZipCity[1]; 
//        document.getElementById('ButtonIndeedJobs').value = 'Jobs in ' + splitZipCity[1];
//        document.getElementById('ButtonSchools').value = 'Schools/University in ' + splitZipCity[1];   
//        document.getElementById('ButtonTrafficNews').value = 'Live Traffic for ' + splitZipCity[1];
//        document.getElementById('ButtonPhysicians').value = 'Physicians in ' + splitZipCity[1];
//        document.getElementById('ButtonBanksATM').value = 'Banks/ATM in ' + splitZipCity[1];

        document.getElementById('weatherbox').style.visibility = document.getElementById('uc_weather_ImageWeather').style.visibility = "visible";
     
         document.getElementById('DivNearbyPlaces').style.display = "";
         //   alert(document.getElementById('tableTouristsResults').getAttribute('ShowDivTourisitsResults'));
        if (document.getElementById('tableTouristsResults').getAttribute('ShowDivTourisitsResults') == "true") {
            document.getElementById('DivTourisitsResults').style.display = "";
        }
        document.getElementById('DivTopCities').style.display = "none";
        document.getElementById('DivSponsorAds').style.display = ""; 
    }
    else //move down n hide button
    {
        DisplayInfoMessage(document.getElementById('hfDidyouMeanCity').value);
        document.getElementById('uc_weather_ImageWeather').style.visibility = "hidden";
    }
   
}
function OnMouseoverColor(imageName,add, busname) {
    //alert(add + "::" + busname);
    BusinessNameArray = null;
    // style.backgroundColor = '#D4D0C8';   // DisplayInfoWindowFlag = true;
    VImageName = imageName;
    DisplayAddress(add, busname);
    //document.getElementById(but).style.border = "3px none #663300";
    //document.getElementById(but).style.border = "2px double #663300";
}
function OnMouseOutColor() {
    style.backgroundColor = '#F2F9FF';
   // document.getElementById(but).style.border = "3px double #663300";
}
function UpdateMapAddress() {
     map.clearOverlays();     
    ImageArray = new Array();
    ImageArrayIndex = 0;

    BusinessNameArray = new Array();
   // BusinessNameArrayIndex = 0;
    // document.getElementById('DivSearchContents').innerHTML = document.getElementById('textBoxmapResultsAddress').value;
    //var allAddress = "316 Inman Ave Colonia NJ:Images/kfc.jpg;1256 Saint Georges Ave Avenel NJ:Images/kfc.jpg;"//407 forest view Dr Avenel NJ:Images/kfc.jpg;";
    var allAddress = document.getElementById('textBoxmapResultsAddress').value;
   // alert(allAddress);
    //  var ind = allAddress.indexOf(";", 0)
    var splitAddress = allAddress.split(";");

   // document.getElementById('linkButMoreSearchResults').style.visibility = "hidden";
    
    if (splitAddress.length > 1) {   
        document.getElementById('GetDirections').style.display = "";    
        document.getElementById('BusinessSearchResults').style.display = "";
        var startStr = allAddress.substr(0, 5);
       // alert(startStr);  
        if (startStr == '#END#') {
            allAddress = allAddress.replace('#END#', '');
            splitAddress = allAddress.split(";"); //alert('hi');
           // document.getElementById('linkButPreviousSearchResults').style.display  = document.//getElementById('linkButMoreSearchResults').style.display = "none";             
            document.getElementById('DivLinkButMore').style.display = "none";         
         }
        else { // alert(startStr);
           /* document.getElementById('linkButMoreSearchResults').style.left = "640px";
            document.getElementById('linkButPreviousSearchResults').style.left = "110px";
            document.getElementById('linkButPreviousSearchResults').style.top = document.getElementById('linkButMoreSearchResults').style.top = "1050px";
            document.getElementById('linkButPreviousSearchResults').style.display = document.getElementById('linkButMoreSearchResults').style.display = ""; */
            document.getElementById('DivLinkButMore').style.display = "";
        }
    }
    else
        document.getElementById('BusinessSearchResults').style.display = "none";

    for (i = 0; i < splitAddress.length; i++)//first store all images and then call display function due to delay
    {
        var splitImages = splitAddress[i].split(":Images/");
        if (splitImages[0].length > 1) {                    
            // ImageArray[i] = splitImages[1];
            var BusNameAddrr = splitImages[0].split("@$");
            // alert(splitImages[1]);
            ImageArray[BusNameAddrr[0]] = splitImages[1];
        }
    }
    //alert(ImageArray.length);
    DisplayInfoWindowFlag = false;
    DicBusAddress = new Object();
    DicAdressToBus = new Object();
   // var arrayIndex = 0;
    for (i = 0; i < splitAddress.length; i++) {
        var splitImages1 = splitAddress[i].split(":Images/");
        if (splitImages1[0].length > 1) {               // imageName = splitImages[1];
            var BusNameAddress = splitImages1[0].split("@$");
            //    alert(BusNameAddress[0] + " -- " + BusNameAddress[1]);
            DicBusAddress[BusNameAddress[0]] = BusNameAddress[1];

            if (BusNameAddress[1] != null && BusNameAddress[1].length > 3) {
                var incrInd = 3;
                while (1) {
                    if (DicAdressToBus[BusNameAddress[1].substring(0, incrInd)] == null) {
                        DicAdressToBus[BusNameAddress[1].substring(0, incrInd)] = BusNameAddress[0];
                        break;
                    }
                    else
                        incrInd = incrInd + 2;

                    if (incrInd == 7) break; //to prevent from infinite loop
                }
            } 
            BusinessNameArray[i] = BusNameAddress[0];  // BusinessNameArray[arrayIndex++] = BusNameAddress[0];        
           //DisplayAddress(BusNameAddress[1], BusNameAddress[0]);   //DisplayAddress(splitImages1[0],'');  add , name
            // DisplayAddress(splitImages1[0],''); //address 
        }
    }
     for (i = 0; i < BusinessNameArray.length; i++) {
     var name = BusinessNameArray[i];
     var address = DicBusAddress[BusinessNameArray[i]];          //    alert(name + " " + address);
        DisplayAddress(address, name); 
     }
   // alert(DicBusAddress[tmp]);
    document.getElementById('textBoxmapResultsAddress').value = ''; //reset the text so that linkbutton doesnt appear on next search
}

function OnMouseoverColorLocalSearch(add, busname) {
    BusinessNameArray = null;  
    DisplayAddress(add, busname);
}
function DisplayAddress(add, bName) {     // alert('hi');
    // document.getElementById('DivNode1').style.background = '#F00';
   // BusinessNameArray = null;   
    if (BusinessNameArray == null) //DisplayInfoWindowFlag make true only for local search.
        DisplayInfoWindowFlag = true;
       
    businessName = bName;//    alert(businessName);
    findLocation(add, 15);
    fromAddress = document.getElementById('textBoxSearch').value;
    toAddress = add;
    document.getElementById('GetDirections').style.display = "";
}
   
// findLocation() is used to enter the sample addresses into the form.
function findLocation(address, zoom) {    
  //  alert(geocoder);
    showLocation(address, zoom);
}
// showLocation() is called when you click on the Search button
// in the form.  It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation(address, zoom) {
    //map.setCenter(new google.maps.LatLng(34, 0), zoom); //map.setCenter(new GLatLng(34, 0), zoom);
    if(address != null && geocoder != null)
    {
       CenterMapbyLatLong(zoom);   
       geocoder.getLocations(address, addAddressToMap);
    }
}


// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
    //   map.clearOverlays();
    if (!response || response.Status.code != 200) {
        //alert("Sorry, we were unable to geocode that address");
    } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);

      //  if (BusinessNameArray != null) { //this is for during the icons mapping on the map during the load for VN.
        //    businessName = BusinessNameArray[BusinessNameArrayIndex++];
           // DicBusAddress[point] = businessName;
       // }
        //alert(businessName);
        marker = createMarker(point, place.address); //new GMarker(point);
        map.addOverlay(marker);

        if (businessName != null && businessName.length > 0 && DisplayInfoWindowFlag == true) {
            marker.openInfoWindowHtml('<font style="color: blue;font-size: 13px;">' + businessName + '</font><br><font style="color: black;font-weight: normal;font-size: 12px;">' 
            + place.address + '</font>');
          //  businessName = '';
        }
//        else
//            marker.openInfoWindowHtml(place.address + '<br>' +
//                '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
    }
}

// Creates a marker whose info window displays the letter corresponding
// to the given index.
function createMarker(point, popuptext) {      
    var letteredIcon = new GIcon(baseIcon);     
    //ImageArrayIndex++;
    // Set up our GMarkerOptions object
    markerOptions = { icon: letteredIcon} //, title: businessName };
    var marker = new GMarker(point, markerOptions);
    if (popuptext.length > 3) {
    
        var busTit = null;
        if (BusinessNameArray != null) {
            if (DicAdressToBus[popuptext.substring(0, 7)] != null)
                busTit = DicAdressToBus[popuptext.substring(0, 7)];
            else if (DicAdressToBus[popuptext.substring(0, 5)] != null)
                busTit = DicAdressToBus[popuptext.substring(0, 5)];
            else if (DicAdressToBus[popuptext.substring(0, 3)] != null)
                busTit = DicAdressToBus[popuptext.substring(0, 3)];

            if (busTit == null)
                busTit = "";
            else {
                if (ImageArray != null)
                    letteredIcon.image = "Images/" + ImageArray[busTit]; //imageName;//"http://www.google.com/mapfiles/marker" + letter + ".png";
                else
                    letteredIcon.image = "Images/NoImage.png";
                //  alert(ImageArray.length);
            }
        }
        else {
            busTit = businessName;
        }
        GEvent.addListener(marker, "click", function() {
            //alert(marker.getTitle());        //marker.openInfoWindowHtml("<b>" + popuptext + "</b>");
            marker.openInfoWindowHtml('<font style="color: blue;font-size: 13px;">' + busTit + '</font><br><font style="color: black;font-weight: normal;font-size: 12px;">'
            + popuptext + '</font>');

        });
    }
    if (VImageName != null)
        letteredIcon.image = "Images/" + VImageName;
  
    return marker;
}

function CenterMapbyLatLong(zoom) {   
    var latLongCookie = readCookie('LatLong'); 
    //alert(latLongCookie);
    if (latLongCookie != null)
         {
             var latLong = latLongCookie.split(",");  
             if (map != null && latLong.length > 0) {               
                 var lat = latLong[0];
                //alert(lat + " " + latLong[1]);                  
                 var longg = latLong[1];                  
                 map.setCenter(new google.maps.LatLng(lat, longg), zoom);//8
        
              }
        }
 
}
function localSearchOnload()
{
    //google.load("maps", "2");   
    window.onunload = function(){  //when users leave the site..we hide the business results next time when they come using back.
            createCookie('BusResultsHide','Y',30);
                 }  
    initializeAjaxGMap(2);
   // Lat49.initAds(677);  //  Lat49eventFired();
}

 function initializeAjaxGMap(zoom) {
    try 
        {
      if(zoom != 9) //9 to avoid registering endrequest again..during updatemap call.
         {   
            zoom = 2;        
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        }
 
      var mapAddressCookieValue = readCookie('MapAddressCookie');
      if (mapAddressCookieValue != null)
                zoom = 9;

            map = new google.maps.Map2(document.getElementById("map_canvas"));
          
          try { 
                if(Lat49 != null)  {
                  Lat49.initAds(677);//uncomment later          
                }
          }  catch(e) { }
         
        map.setCenter(new google.maps.LatLng(40, -83), zoom);
       // map.addControl(new GLargeMapControl);      //  map.addControl(new GMapTypeControl());
      
        var mapTypeControl = new GMapTypeControl();
        var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
        var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
        map.addControl(mapTypeControl, topRight);
        GEvent.addListener(map, "dblclick", function() {
          map.removeControl(mapTypeControl);
          map.addControl(new GMapTypeControl(), bottomRight);
        });
        map.addControl(new GSmallMapControl());

        GEvent.addListener(this.map, "moveend", function() { //for Lat49 Ads
            Lat49eventFired();
        });
        
        geocoder = new GClientGeocoder();
        baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "Images/shadow50.png"; //"http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
   
       
        if (mapAddressCookieValue != null && mapAddressCookieValue.length > 0) {             
            if (document.getElementById('textBoxBusinessName').value.length == 0) { //some how cookie gets trimmed for checkbox search
              //  if(document.getElementById('textBoxmapResultsAddress').value != null)                {
                   document.getElementById('textBoxmapResultsAddress').value = mapAddressCookieValue + ";";
                //}
            }                    
           // alert('initajax');
            UpdateMapAddress();            
        }
        CenterMapbyLatLong(8);
       } 
       catch(e) { }
    }

    function OpenDirections() {
        var Args = new Array(fromAddress, toAddress);
        var WinSettings = "center:yes;resizable:no;dialogHeight:600px;dialogWidth:1000px"
        var Args = window.showModalDialog("HTML/Directions.htm", Args, WinSettings);
        if (Args == null) {
            //window.alert("Nothing returned from child. No changes made to input boxes");
        }

    } 

    
    function SetCookie() {
        // set time, it's in milliseconds        
       //document.cookie = "MapAddressCookie= ;";
    }
    function UpdateMapAddressForVirtual() {
        map.clearOverlays();
        ImageArray = new Array();
       // ImageArrayIndex = 0;
        
        BusinessNameArray = new Array();
       // BusinessNameArrayIndex = 0;
        // document.getElementById('DivSearchContents').innerHTML = document.getElementById('textBoxmapResultsAddress').value;
        //var allAddress = "316 Inman Ave Colonia NJ:Images/kfc.jpg;1256 Saint Georges Ave Avenel NJ:Images/kfc.jpg;"//407 forest view Dr Avenel NJ:Images/kfc.jpg;";
        var allAddress = document.getElementById('textBoxmapResultsAddress').value;
        // alert(allAddress);
        //  var ind = allAddress.indexOf(";", 0)
        var splitAddress = allAddress.split(";");

        // document.getElementById('linkButMoreSearchResults').style.visibility = "hidden";

        if (splitAddress.length > 1) {
            document.getElementById('DivSponsorAds').style.display =
            document.getElementById('GetDirections').style.display =
            document.getElementById('DivTableBusinessResults').style.display =
            document.getElementById('DivCensusData').style.display =
            document.getElementById('DivNearbyPlaces').style.display =
            document.getElementById('DivEmbedTag').style.display =
            document.getElementById('weatherbox').style.display = 
            document.getElementById('DivTourisitsResults').style.display = "";
            document.getElementById('DivTopCities').style.display = "none";
          
            var startStr = allAddress.substr(0, 5);

            if (startStr == '#END#') {
                allAddress = allAddress.replace('#END#', '');
                splitAddress = allAddress.split(";"); //alert('hi');
            }
           
        }
       
        for (i = 0; i < splitAddress.length; i++)//first store all images and then call display function due to delay
        {
            var splitImages = splitAddress[i].split(":Images/");
            if (splitImages[0].length > 1) {
               var BusNameAddrr= splitImages[0].split("@$");
                // alert(splitImages[1]);
               ImageArray[BusNameAddrr[0]] = splitImages[1];
            }
        }
        //alert(ImageArray.length);
        DisplayInfoWindowFlag = false;
        DicBusAddress = new Object();
        DicAdressToBus = new Object();
       // var arrayIndex = 0;
        for (i = 0; i < splitAddress.length; i++) {
            var splitImages1 = splitAddress[i].split(":Images/");
            if (splitImages1[0].length > 1) {               // imageName = splitImages[1];

                var BusNameAddress = splitImages1[0].split("@$");
                //    alert(BusNameAddress[0] + " -- " + BusNameAddress[1]);
                DicBusAddress[BusNameAddress[0]] = BusNameAddress[1];

                if (BusNameAddress.length > 1 && BusNameAddress[1].length > 3) {

                    var incrInd = 3;
                    while (1) {
                        if (DicAdressToBus[BusNameAddress[1].substring(0, incrInd)] == null) {
                            DicAdressToBus[BusNameAddress[1].substring(0, incrInd)] = BusNameAddress[0];
                            break;
                        }
                        else
                            incrInd = incrInd + 2;

                        if (incrInd == 7) break;//to prevent from infinite loop
                    }
                }
                
              BusinessNameArray[i] = BusNameAddress[0];//  BusinessNameArray[arrayIndex++] = BusNameAddress[0];
                //DisplayAddress(BusNameAddress[1], BusNameAddress[0]);   //DisplayAddress(splitImages1[0],'');  
            }
        }
         for (i = 0; i < BusinessNameArray.length; i++) {
         var name = BusinessNameArray[i];
          var address = DicBusAddress[BusinessNameArray[i]];          //    alert(name + " " + address);
           DisplayAddress(address, name); 
     }
     //CenterMapbyLatLong(14);
     //CenterMapbyLatLong(19);//to zoom so that lat49 displays ad
//     var lat = '+40.75';
//     var longg = '-73.99';
//     if(map != null)
//     { 
//     map.setCenter(new google.maps.LatLng(lat, longg), 14);
//      lat = '+45.75';
//     map.setCenter(new google.maps.LatLng(lat, longg), 17);
//     }
        document.getElementById('textBoxmapResultsAddress').value = ''; //reset the text so that linkbutton doesnt appear on next search
    }

    function VirtualSearchOnLoad()
    {
        InitializeVirtualNAjaxGMap();   
    }
    
    function InitializeVirtualNAjaxGMap() {
    try
    {
        var zoom = 4;
        map = new google.maps.Map2(document.getElementById("map_canvas"));
        
        try  {
                if(Lat49 != null)  {
                Lat49.initAds(677); //uncomment later
                }
         }  catch(e) { }
        //   alert(zoom);
        map.setCenter(new google.maps.LatLng(37, -93), zoom);
        // map.addControl(new GLargeMapControl);
        //  map.addControl(new GMapTypeControl());

        var mapTypeControl = new GMapTypeControl();
        var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 10));
        var topRight1 = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(30, 30));
        var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 10));
        map.addControl(mapTypeControl, topRight);
        GEvent.addListener(map, "dblclick", function() {
            map.removeControl(mapTypeControl);
            map.addControl(new GMapTypeControl(), bottomRight);
        });
        map.addControl(new GSmallMapControl(),topRight1);

         GEvent.addListener(this.map, "moveend", function() { //for Lat49 Ads
            Lat49eventFired();
        });

        geocoder = new GClientGeocoder();
        baseIcon = new GIcon(G_DEFAULT_ICON);
        baseIcon.shadow = "Images/shadow50.png"; //"http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);

        UpdateMapAddressForVirtual();
      //  alert(document.getElementById('textBoxmapResultsAddress').value);
        }      catch(e) { }
       
    }
    
    function Lat49eventFired()     
    { 
    // alert('hi');  
      if(this.map != null)
         {
           var bnds = this.map.getBounds();
           var center = bnds.getCenter();
           var lat = center.lat();
           var lon = center.lng();
           try {
                  if(Lat49 != null)  {
               var zoomlevel = Lat49.Tile.convertGMap2Zoom(this.map.getZoom());
               Lat49.updateAdByLatLon("adcontainer", lat, lon, zoomlevel);
               }
           } catch (e) { }
       }
   }

    function EndRequestHandler(sender, args) {
         //alert(window.onbeforeunload);
        //findLocation('Austin TX','9'); return;       
        UpdateMapAddress();
        ShowAndHideYahooNewsButton();
        // RefreshLocalSearch(); disabled for right now...to refresh ads for google 
        MoveBusinessResultsForMozilla();
       // MoveLocalSearchFooter();
        CenterMapbyLatLong(8);
    }

   

    function RefreshLocalSearch() {
        if (document.getElementById('textBoxBusinessName').value.length > 0) {
            // window.location.assign('LocalSearch.aspx?q=' + document.getElementById('textBoxBusinessName').value);
        }
        else {
            var elocalFinderCookieValue = readCookie('elocalFinderTextCookie');
            if (elocalFinderCookieValue != null) {
                var businesNameFromCheckbox = elocalFinderCookieValue.split(" ");
                // window.location.assign('LocalSearch.aspx?q=' + businesNameFromCheckbox[0]);
            }
        }
    }

    function DisplayResultsHeader(businessText) {    //called from localsearch.cs file      
        document.getElementById('BusinessSearchResults').style.display = "";
        document.getElementById('textBoxBusinessName').value = businessText;
        document.getElementById('DivAccordianNews').style.display = "none";  
    }
/**
*
*  Crossbrowser Drag Handler
*  http://www.webtoolkit.info/
*
**/
 
var DragHandler = {
 
 
	// private property.
	_oElem : null,
 
 
	// public method. Attach drag handler to an element.
	attach : function(oElem) {
		oElem.onmousedown = DragHandler._dragBegin;
 
		// callbacks
		oElem.dragBegin = new Function();
		oElem.drag = new Function();
		oElem.dragEnd = new Function();
 
		return oElem;
	},
 
 
	// private method. Begin drag process.
	_dragBegin : function(e) {
		var oElem = DragHandler._oElem = this;
 
		if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
		if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }
 
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
 
		e = e ? e : window.event;
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
 
		oElem.dragBegin(oElem, x, y);
 
		document.onmousemove = DragHandler._drag;
		document.onmouseup = DragHandler._dragEnd;
		return false;
	},
 
 
	// private method. Drag (move) element.
	_drag : function(e) {
		var oElem = DragHandler._oElem;
 
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
 
		e = e ? e : window.event;
		oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
		oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';
 
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
 
		oElem.drag(oElem, x, y);
 
		return false;
	},
 
 
	// private method. Stop drag process.
	_dragEnd : function() {
		var oElem = DragHandler._oElem;
 
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
 
		oElem.dragEnd(oElem, x, y);
 
		document.onmousemove = null;
		document.onmouseup = null;
		DragHandler._oElem = null;
	}
 
}

//function MoveLocalSearchFooter() {
//   var divFooterValue = readCookie('DivFooterValue');
//   //  alert(divFooterValue);
//     if (divFooterValue != null) {          
//     document.getElementById("DivFooter").style.top = divFooterValue;
//   }    
//}

//function initialize(zoom) {    
//   
//    if(zoom != 9) //9 to avoid registering endrequest again..during updatemap call.
//      Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
//    //alert('2');
//  
//    map = new GMap2(document.getElementById("map_canvas"));
//    map.setCenter(new GLatLng(34, 0), zoom);
//    map.addControl(new GLargeMapControl);
//    map.addControl(new GMapTypeControl());
//    geocoder = new GClientGeocoder();
//    baseIcon = new GIcon(G_DEFAULT_ICON);
//    baseIcon.shadow = "Images/shadow50.png"; //"http://www.google.com/mapfiles/shadow50.png";
//    baseIcon.iconSize = new GSize(20, 34);
//    baseIcon.shadowSize = new GSize(37, 34);
//    baseIcon.iconAnchor = new GPoint(9, 34);
//    baseIcon.infoWindowAnchor = new GPoint(9, 2);
//}
 
 

//function eraseCookie(name) {
//    createCookie(name, "", -1);
//}

//        while(ind != -1) 
//        {
//            var address = allAddress.substr(0,ind);   
//            allAddress.split( 
//            if(address.length  > 1)
//            {
//               ind = address.indexOf(":Images/",0)
//               imageName = address.substr(ind+":Images/".length,address.length-ind);  
//                
//        //       alert(imageName);
//                DisplayAddress(address);
//                allAddress = allAddress.substring(ind+1,allAddress.length);//    alert(str);
//                ind = allAddress.indexOf(";",0)
//            }
//        //ind = -1;
//        }
//        // if(allAddress.length  > 1)
// DisplayAddress(allAddress);

//inside ShowAndHideYahooNewsButton
//        document.getElementById("ButtonPhysicians").style.top = document.getElementById("ButtonSchools").style.top = 
//        document.getElementById("ButtonBanksATM").style.top = '25px';
//        
//        document.getElementById("ButtonAparments").style.top =  document.getElementById("ButtonYahooNews").style.top = 
//        document.getElementById("ButtonIndeedJobs").style.top = '-5px';        
//       document.getElementById("ButtonTrafficNews").style.top = document.getElementById("ButtonFlight").style.top = 
//       document.getElementById("ButtonRealEstate").style.top = '-35px';

//         document.getElementById("ButtonSchools").style.height = document.getElementById("ButtonTrafficNews").style.height = 
//        document.getElementById("ButtonIndeedJobs").style.height = document.getElementById("ButtonFlight").style.height = 
//        document.getElementById("ButtonAparments").style.height = document.getElementById("ButtonRealEstate").style.height = 
//        document.getElementById("ButtonYahooNews").style.height = document.getElementById("ButtonPhysicians").style.height = 
//        document.getElementById("ButtonBanksATM").style.height ='26px';

//        document.getElementById("ButtonSchools").style.width = document.getElementById("ButtonYahooNews").style.width = 
//        document.getElementById("ButtonAparments").style.width = document.getElementById("ButtonRealEstate").style.width = 
//        document.getElementById("ButtonFlight").style.width = document.getElementById("ButtonIndeedJobs").style.width = 
//        document.getElementById("ButtonTrafficNews").style.width = document.getElementById("ButtonPhysicians").style.width = 
//        document.getElementById("ButtonBanksATM").style.width = '310px'; //(7 * document.getElementById('ButtonYahooNews').value.length) + 4;
//        document.getElementById('textBoxZipCodeafterSearch').value = "";

//       document.getElementById("ButtonPhysicians").style.left = document.getElementById("ButtonIndeedJobs").style.left = 
//       document.getElementById("ButtonFlight").style.left = '345px';       
//       document.getElementById("ButtonSchools").style.left =document.getElementById("ButtonAparments").style.left = 
//       document.getElementById("ButtonRealEstate").style.left = '10px';
//       document.getElementById("ButtonYahooNews").style.left = document.getElementById("ButtonTrafficNews").style.left = 
//       document.getElementById("ButtonBanksATM").style.left ='680px';

/*


function initializeAjaxGMapOLD(zoom) 
{
    zoom = 2;     
    
    map = new google.maps.Map2(document.getElementById("map_canvas"));
    map.setCenter(new google.maps.LatLng(40, -83), zoom);
    // map.addControl(new GLargeMapControl);
    //  map.addControl(new GMapTypeControl());

    var mapTypeControl = new GMapTypeControl();
    var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 10));
    var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 10));
    map.addControl(mapTypeControl, topRight);
//    GEvent.addListener(map, "dblclick", function() {
//        map.removeControl(mapTypeControl);
//        map.addControl(new GMapTypeControl(), bottomRight);
//    });
    map.addControl(new GSmallMapControl());
    
//    GEvent.addListener(map, "click", function(overlay, latlng) {
//        var lat = latlng.lat();
//        var lng = latlon.lng();
//        var zoom = Lat49.Tile.convertGMap2Zoom(map.getZoom());
//        Lat49.updateAdByLatLon("adcontainer", lat, lng, zoom);
//        });
    GEvent.addListener(this.map, "moveend", function() {
            var bnds = map.getBounds();
            var center = bnds.getCenter();
            var lat = center.lat();
            var lon = center.lng();          
            try {
                var zoomlevel = Lat49.Tile.convertGMap2Zoom(map.getZoom());              
                Lat49.updateAdByLatLon("adcontainer", lat, lon, zoomlevel);
            } catch (e) {   }
        });
        
    geocoder = new GClientGeocoder();
    baseIcon = new GIcon(G_DEFAULT_ICON);
    baseIcon.shadow = "Images/shadow50.png"; //"http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);

   // CallLat();
}
function FillSnagZipCode(zip)
{
    //document.forms['formSnagJob'].elements['zipCode'].value = zip;
}
 function FillPricelineData(depCity , depDate)
 {
 // document.forms['pclnbanner_rc'].elements['DepCity'].value = depCity; 
 // document.forms['pclnbanner_rc'].elements['DepartureDate'].value = depDate; 
 }
*/
