
function  ClearLocationByArrowKeys(evt)
   {
      //Left up right down arrows
       if(evt.keyCode ==37 || evt.keyCode ==38 || evt.keyCode ==39 || evt.keyCode ==40)
       {
                document.getElementById("locationid").value="";
                document.getElementsByName("location").value="" ;
       }
   }
  ///////////////////////////////////////////////////////////////////////////////

   ////////////////////////////////////////////////

     function toggle_popup(){
	var link_pos = $('lnk_learn_more').cumulativeOffset();
	$('popup_discounts').style.top = (link_pos[1] + 16) + 'px';
	$('popup_discounts').style.left = (link_pos[0] + 3) + 'px';
	$('popup_discounts').style.display = ($('popup_discounts').getStyle('display')=='block')?'none':'block';
}

/////////////////////////////////////////////

 function ShowMultipleAddress()
    {

        if (document.getElementById("nosearchresultsmessage") != null)
        {
            document.getElementById("nosearchresultsmessage").style.display="none";
        }

        //set to none to hide them
        document.getElementById("noresults").style.display="none";
        var hidetable=document.getElementById("table_results") ;

        if (hidetable != null)
        {
            hidetable.style.display = "none";
        }

    }

//////////////////////////////////
function chkEligibleforPostback(value)
{
  var dropdown= document.getElementById("storage_unit_size_selector");

  var blnReturn = false ;
  //debugger;
   if(dropdown != null)
   {
   var currenttextdisplayed= dropdown.options[0].innerHTML ;

            var displaytext = "select" ;
               if (value == "FiveByFive")
              {
              displaytext = "5'x 5'" ;
              }
               if (value == "FiveByTen")
              {
              displaytext = "5'x 10'" ;
              }
               if (value == "FiveByFifteen")
              {
              displaytext = "5'x 15'" ;
              }
               if (value == "TenByTen")
              {
              displaytext = "10'x 10'" ;
              }
               if (value == "TenByFifteen")
              {
              displaytext = "10'x 15'" ;
              }
               if (value == "TenByTwenty")
              {
              displaytext = "10'x 20'" ;
              }
              if (value == "TenByTwentyFive")
              {
              displaytext = "10'x 25'" ;
              }
              if (value == "TenByThirty")
              {
              displaytext = "10'x 30'" ;
              }
              if (value == "Parking")
              {
              displaytext = "Parking" ;
              }
        if (currenttextdisplayed == displaytext )
        {
         blnReturn = false ;
        }
        else
        {
         blnReturn = true ;
        }
   }
 return blnReturn ;
}

//TO CHECK  IE8 VERSION
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
     var ua = navigator.userAgent;
     var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
     if (re.exec(ua) != null)
        rv = parseFloat(RegExp.$1);
    }
 return rv;
}
//TO CHECK  IE8 VERSION
function checkVersion() {

  var boolchk=false;
  var ver = getInternetExplorerVersion();
  if (ver > -1)
  {
    if (ver >= 8.0)
	    {
	      boolchk=true; // msg = "You're using a recent copy of Windows Internet Explorer."
	    }
    else
	    {
              boolchk=false; // msg = "You should upgrade your copy of Windows Internet Explorer.";
	    }
  }
 return boolchk;
}




////////////////////////////////////

var gmarkers = new Array();
    var Addresses = [];
    var AddressesWithNoCoupons = [];
    var map;
    var PointsArray;
    var PointsArrayWithNoCoupons;
    var ImageArray = [];
    var ImageArrayWithNoCoupons = [];
    var zoomFactor = 12;
    var markersinBoundary = "";
    var gCenter;
    var MonthlyRateArray = new Array();
    var initialArray = new Array();
    var infowindowmove = "false";
    var backgroundColor = '#fff6cd'; //in case purple use '#C0C0C0'
    var isInfoWindowOn = false;
    var clickOnHyperlink  = "false";
    var currentDivIndex = -1;
    var gDistanceMoved;
    var gZoomEnd ="";
    //Variables declared for Balloon Highlighting/Unhighlighting
    var LastBalloonID="";
    var LastFlagIDIndex="x";
    var CurrentFlagIndex="x" ;


function fitMap( map, PointsArray, nInitialNumProperties)
    {
        if (gmarkers.length >= 0)
        {
            var bounds = new GLatLngBounds();
            var pointsLen = 0;
            if (gmarkers.length < nInitialNumProperties)
            {
                pointsLen = gmarkers.length;
            }
            else
            {
                pointsLen = nInitialNumProperties;
            }
            for (var i=0; i< pointsLen; i++)
            {
                var latlon = gmarkers[i].getLatLng();;//new GLatLng(PointsArray[i][0],PointsArray[i][1])
                bounds.extend(latlon);
            }
            //if we set scale as 9 we get more properties
            //if we set scale as 12 we get less properties
            map.setCenter(bounds.getCenter());
            var mapscale = map.getBoundsZoomLevel(bounds);
            map.setZoom(mapscale);
        }
    }
//create array of markups
function CreateMarkersList(map, refresh)
    {
        //debugger;
        if (PointsArray.length != 0)
        {
            for (nIndex = 0; nIndex< PointsArray.length; nIndex++)
            {
                pointObj = PointsArray[nIndex];

                if (refresh == "FALSE")
                {
                    var point = new GLatLng(pointObj[0], pointObj[1]);
                    var icon = new GIcon(G_DEFAULT_ICON,"../images/balloons"+"/"+ ImageArray[nIndex]);
                    var opts = new Object();
                    opts.clickable = true;

                    if (nIndex != null)
                    {
                        opts.title = nIndex + 1;
                    }
                    if(icon!=null)
                    {
                        opts.icon = icon;
                    }
                    CreateMarker(map, point, icon,"<b>Test</b>", opts, nIndex, refresh);
                }
                //in case of refresh no need to recreate the pushpins. Just change the icons
                //based on global ImageArray
                if (refresh == "TRUE")
                {
                    for (i=0; i< gmarkers.length; i++ )
                    {
                        if (i < ImageArray.length)
                        {
                            var marker1 = gmarkers[i];
 	                        marker1.setImage("../images/balloons"+"/"+ ImageArray[i]);
 	                    }
 	                    else
 	                    {
 	                         var marker1 = gmarkers[i];
 	                         var pointsLength = PointsArray.length;
 	                         var inIndex = i - pointsLength;
 	                        marker1.setImage("../images/balloons"+"/"+ ImageArrayWithNoCoupons[inIndex]);
 	                    }
                    }

                }
            }
        }
    }

    //create array of markups

    function CreateMarkersListWithNoCoupons(map, refresh)
    {
        if (PointsArrayWithNoCoupons != undefined)
        {
            if (PointsArrayWithNoCoupons.length != 0)
            {
                for (nIndex = 0; nIndex< PointsArrayWithNoCoupons.length; nIndex++)
                {
                    pointObj = PointsArrayWithNoCoupons[nIndex];
                    var StartIndex = ImageArray.length;
                    var imageIndex = StartIndex+nIndex;

                    if (refresh == "FALSE")
                    {
                        var point = new GLatLng(pointObj[0], pointObj[1]);
                        var icon = new GIcon(G_DEFAULT_ICON,"../images/balloons"+"/"+ ImageArrayWithNoCoupons[nIndex]);
                        var opts = new Object();
                        opts.clickable = true;

                        if (nIndex != null)
                        {
                            opts.title = imageIndex + 1;
                        }
                        if(icon!=null)
                        {
                            opts.icon = icon;
                        }
                        CreateMarkerWithNoCoupons(map, point, icon,"<b>Test</b>", opts, nIndex, refresh);
                    }
                    //in case of refresh no need to recreate the pushpins. Just change the icons
                    //based on global ImageArray
                    if (refresh == "TRUE")
                    {
                        var StartIndex = ImageArray.length;
                        var imageIndex = StartIndex+nIndex;

                        for (i=0; i< gmarkers.length; i++ )
                        {
                            if (i < ImageArray.length)
                            {
                                var marker1 = gmarkers[i];
 	                            marker1.setImage("../images/balloons"+"/"+ ImageArray[i]);
 	                        }
 	                        else
 	                        {
 	                             var marker1 = gmarkers[i];
 	                             var pointsLength = PointsArray.length;
 	                             var inIndex = i - pointsLength;
 	                            marker1.setImage("../images/balloons"+"/"+ ImageArrayWithNoCoupons[inIndex]);
 	                        }
                        }
                    }
                }
            }
        }
    }



     function CreateMarkerWithNoCoupons(map, point,icon,InfoHTML, opts, nIndex, refresh)
    {
        var marker = new GMarker(point, opts);
        marker.value = nIndex;
        var val = marker.clickable;
        map.addOverlay(marker);
        if(InfoHTML!='')
        {
                GEvent.addListener(marker, "click", function()
                {
                     currentDivIndex =  nIndex + 1;
                     infowindowmove = "true";
                    if (clickOnHyperlink == "false")
                    {
                        //this is when user clicks on the actual marker in map window.
                        isInfoWindowOn = true;
                        map.openInfoWindowHtml(point,AddressesWithNoCoupons[nIndex]);
                       // debugger;
                        ClearAllCouponsHighlight();
                        UnHighLightLastBalloon();
                        LoadOnHyperlinkClickWithNoCoupons("","",PointsArrayWithNoCoupons[nIndex][0], PointsArrayWithNoCoupons[nIndex][1], nIndex, false , "TRUE");
                        infowindowmove = "true";
                    }
                    if (clickOnHyperlink == "true")
                    {
                        //this is when user clicks on Hyperlink click on the coupons
                        isInfoWindowOn = true;
                        map.openInfoWindowHtml(point,AddressesWithNoCoupons[nIndex]);
                        infowindowmove = "true";
                        //reset flag
                        clickOnHyperlink ="false";
                    }
                    else
                    {
                        clickOnHyperlink = "false";
                    }
                }
            );
        }
        if (refresh == "FALSE")
        {
            gmarkers.push(marker);
        }
        return marker;
    }

    function CreateMarker(map, point,icon,InfoHTML, opts, nIndex, refresh)
    {
        var marker = new GMarker(point, opts);
        marker.value = nIndex;
        var val = marker.clickable;
        map.addOverlay(marker);
        if(InfoHTML!='')
        {
                GEvent.addListener(marker, "click", function()
                {
                    //debugger;
                     currentDivIndex =  nIndex + 1;
                    infowindowmove = "true";
                    if (clickOnHyperlink == "false")
                    {
                        //this is when user clicks on the actual marker in map window.
                        isInfoWindowOn = true;
                       // Code for High lighting Coupons from Google MAP
                        UnHighLightLastBalloon();
                        LastBalloonID="";
                        LastFlagIDIndex="x";
                        HighLighMultiSelectBalloon(nIndex);
                       // End
                        map.openInfoWindowHtml(point,Addresses[nIndex]);
                        highlightMultiSelected (document.getElementById(nIndex+1));
                        LoadOnHyperlinkClick("","",PointsArray[nIndex][0], PointsArray[nIndex][1], nIndex, false , "TRUE");
                        infowindowmove = "true";
                    }
                    if (clickOnHyperlink == "true")
                    {
                        //this is when user clicks on Hyperlink click on the coupons
                        isInfoWindowOn = true;
                        map.openInfoWindowHtml(point,Addresses[nIndex]);
                        infowindowmove = "true";
                        //reset flag
                        clickOnHyperlink ="false";
                    }
                    else
                    {
                        clickOnHyperlink = "false";
                    }
                }
            );
        }
        if (refresh == "FALSE")
        {
            gmarkers.push(marker);
        }
        return marker;
    }

    function initializeWithNoCoupons(refresh)
    {
        LoadDefaultImagesForNoCoupons();
        if (GBrowserIsCompatible())
        {
            CreateMarkersListWithNoCoupons(map, refresh);
        }
    }


    var initLoad = "false";
    function initialize(refresh)
    {
        //debugger;
        LoadDefaultImages();
        if (GBrowserIsCompatible())
        {
            map = new GMap2(document.getElementById("map"));
        	map.addControl(new GMapTypeControl());
        	map.addControl(new GSmallMapControl ());
        	_mPreferMetric = true;
            map.addControl(new GScaleControl("125"));
            if (PointsArray.length != 0)
            {
                //for now zoom to first point
                //TODO :Check with team where to center when initial map is loaded ?
                SetCenterPoint();
            }
            CreateMarkersList(map, refresh);
            fitMap(map, PointsArray, nInitialNumProperties);
            GEvent.trigger(map, "moveend");

            initLoad = "true";
            gZoomEnd = "false";
            GEvent.addListener(this.map,"zoomend",function()
            {
                gZoomEnd = "true";
            }
            );
            //following event will be tiggered whenever map window is zoomed(in/out), pan or moved
            GEvent.addListener(map,'moveend',function()
            {
                if (initLoad == "true")
                {
                    gZoomEnd = "false";
                }
                else
                {
                    if (gZoomEnd == "false")
                    {
                        if ( infowindowmove == "false")
                        {
	                        //geocoding();
                        }
                    }
                }
                var bounds = map.getBounds();
                markersinBoundary = "";
                var nIndex =0;
                var pointObj;
                for (nIndex = 0; nIndex< gmarkers.length; nIndex++)
                {
                    var id = nIndex + 1;
                    pointObj = gmarkers[nIndex].getLatLng();
                    if (bounds.containsLatLng(pointObj ))
                    {
                        if (markersinBoundary != "")
                        {
                            markersinBoundary = markersinBoundary + id +"|";
                        }
                        else
                        {
                            markersinBoundary = markersinBoundary + id + "|";
                        }
                    }
                }
               ReloadPropertiesOnMapZoomOrPan(markersinBoundary);
            }
            );
            //GEvent.trigger(map, "moveend");
            //Since we are not calling  above moveend, we need to call MarkersInBoundaryOnInitLoad
            //so we know what are the properties which are in current map boundary
            //This changes is needed when we moved from 30 to 8 properties which is dynamic-show
            MarkersInBoundaryOnInitLoad();
            if (initLoad == "true")
            {
                //This is to sync map balloon with map coupons on initial load
                ReloadPropertiesOnMapZoomOrPan(markersinBoundary);
                initLoad = false;
            }
        }
    }



    //Since we are not calling  above moveend, we need to call MarkersInBoundaryOnInitLoad
    //so we have the list of properties which are in current map boundary
    //This change is needed when we had moved from 30 to 8 properties which is dynamic-display
    //i.e as map location changes, we are getting properpties dynamically
    //Issue : 155
    function MarkersInBoundaryOnInitLoad()
    {
        //debugger;
        var bounds = map.getBounds();
        markersinBoundary = "";
        var nIndex =0;
        var pointObj;

        for (nIndex = 0; nIndex< gmarkers.length; nIndex++)
        {
            var id = nIndex + 1;
            pointObj = gmarkers[nIndex].getLatLng();
            if (bounds.containsLatLng(pointObj ))
            {
                if (markersinBoundary != "")
                {
                    markersinBoundary = markersinBoundary + id +"|";
                }
                else
                {
                    markersinBoundary = markersinBoundary + id + "|";
                }
            }
        }
    }


    //in case address entered by user is not valid
    //display no results div and hide all remaining divs
    function DisplayNoResults()
    {
        //set null as below to display message
        if (document.getElementById("nosearchresultsmessage") != null)
        {
            document.getElementById("nosearchresultsmessage").style.display="";
        }
        //set to none to hide them
        document.getElementById("noresults").style.display="none";
        document.getElementById('Locator1-belowList').style.display='none';
        setDropdownTextforUnitSize();

        var hidetable=document.getElementById("table_results") ;

        if (hidetable != null)
        {
            hidetable.style.display = "none";
        }
    }


    function ReloadPropertiesOnMapZoomOrPan(markersinBoundary)
    {
        if (infowindowmove == "true")
        {
            infowindowmove = "false";
            return false;
        }
        FindDistance();
        document.getElementById("noresults").style.display="none";
        //Addresses for Coupons to be displayed based on Div Id
        var Addresses =  markersinBoundary.split ( '|' );
         var chkboolNoCoupon = true ;
       // alert(Addresses);
        //Total number of rows inside Datalist Table
      if(document.getElementById("ctl00_PublicStoragePageContent_dlLocations") != null)
      {
        var itemRowLength=  document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows.length ;

        //Iterating through loop of Datalist Table i= "Row Number" starting from zero index of Datalist Table
        for (i=0 ; i < itemRowLength ; i++)
        {
                // This loop is for comapring current Row of Datalist Table with Coupons to be displayed
              for (nLoopIndex = 0; nLoopIndex < Addresses.length-1; nLoopIndex++)
              {
                   // get the Div number  to be displayed [Coupon]
                    var id = Addresses[nLoopIndex];
                    // Check id
                    if ( id != null || id!="")
                    {
                        // Key is div id  like div5
                        var key = "id=div"+id;
                        var strinnerHTML = document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows[i].cells[0].innerHTML;
                        //for firefox id=/"div5/" was comimg removing '/"'
                        strinnerHTML=strinnerHTML.replace("\"","");
                        strinnerHTML=strinnerHTML.replace("\"","");
                        var value = strinnerHTML.indexOf(key);
                        if(value == -1)
                        {
                            //HIDE
                            document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows[i].style.display = "none";
                        }
                        else
                        {
                        // when div is present find next character after Div Id i.e. div5 look for blank spaceS
                        var startpos = value + key.length ;
                        //for IE 7
                       // var newchk= document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows[i].cells[0].innerHTML.charAt(startpos);
                        var newchk=strinnerHTML.charAt(startpos);
                        // for FF & Chrome
                      //  var chkff= document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows[i].cells[0].innerHTML.charAt(startpos + 1 );

                        if (newchk == " "  )
                        {
                        document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows[i].style.display = "";
                        break ;
                        }
                        else
                        { //check IE8 and chk value here
                            if(checkVersion && newchk == ">")
                            {
                                 //show
                                document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows[i].style.display = "";
                                break ;
                            }
                            else
                            {
                            //HIDE
                            document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows[i].style.display = "none";
                            }
                        }
                        }
                    }
              }
            //when no Coupon is to be displayed
                if (Addresses.length == 1 &&  Addresses[0]== "" )
                {
                 //HIDE all the rows
                 document.getElementById("ctl00_PublicStoragePageContent_dlLocations").rows[i].style.display = "none";
                 // for showing message no results
                 document.getElementById("noresults").style.display="";
                 document.getElementById('Locator1-belowList').style.display='none';
                }
        }
            //if there are no properties in selected zoom window,display following message:
            if (Addresses != null)
            {
                if (Addresses.length == 1)
                {
                    //debugger;
                    if (gDistanceMoved > MaxDistanceForDynamicLoad)
                    {
                        geocoding();
                    }
                }
            }
     } //if condition closed
            //reset the flag
             if (gZoomEnd == "true")
             {
                gZoomEnd = "false";
             }
    }

    function geocoding()
    {
        var request = GXmlHttp.create();
        var gCenter = map.getCenter();
         request.open("POST", "reverse.pl", true);
         request.setRequestHeader('Content-Type','application/x-www-form-urlencoded') ;

        var latlng = new GLatLng(gCenter.lat(),gCenter.lng());
            var geocoder = new GClientGeocoder();
            geocoder.getLocations(latlng, showAddress);

        if (request.readyState == 4)
        {
            var xmlDoc = request.responseXML ;
            try
            {
                var info = xmlDoc.documentElement.getElementsByTagName("info") ;
                var hitrem = parseInt(info[0].getAttribute("hitrem")) ;
                var address = xmlDoc.documentElement.getElementsByTagName("address")[0].firstChild.nodeValue ;
            }
            catch (e)
            {
            }
        }
    }

    function showAddress(response)
    {
      if (!response || response.Status.code != 200)
      {
        //alert("Status Code:" + response.Status.code);
      }
      else
      {
           place = response.Placemark[0];
           point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);

            var cityname ="";
            try
            {
                if (place.AddressDetails.Country.AdministrativeArea)// != 'undefined')
                {
                    if (place.AddressDetails.Country.AdministrativeArea.PostalCode)
                    {
                        cityname = place.AddressDetails.Country.AdministrativeArea.PostalCode.PostalCodeNumber;
                    }
                    if (cityname == "")
                    {
                        if (place.AddressDetails.Country.AdministrativeArea.Locality)
                        {
                            if(place.AddressDetails.Country.AdministrativeArea.Locality.PostalCode)
                            {
                                cityname = place.AddressDetails.Country.AdministrativeArea.Locality.PostalCode.PostalCodeNumber;
                            }
                        }
                        if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea)
                        {
                            if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality)
                            {

                                if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode)
                                {
                                    cityname = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;
                                 }
                            }
                            if (place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea)
                            {
                                if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.PostalCode)
                                {
                                    if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.PostalCode.PostalCodeNumber)
                                    {
                                        cityname = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.PostalCode.PostalCodeNumber;
                                    }
                                }
                            }
                            if (cityname == "")
                            {
                                if(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName)
                                {
                                    if (place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName)
                                    {
	                                    cityname = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName +" " +place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (e)
            {
            }
            //debugger;
            var path = document.location.pathname;
            x = path.length;

            while((path.substring(x,x-1))!= "/"){ x--; } clipstart = x;
            var file = path.substring(path.length,clipstart);
            var url;

            if(file == "storage-search-landing.aspx")
            {
                url = 'storage-search-landing.aspx?location=' + cityname;
            }
            else if (file == "storage-search-landing1.aspx")
            {
                url = 'storage-search-landing1.aspx?location=' + cityname;
            }
            else if (file == "storage-search-landing2.aspx")
            {
                url = 'storage-search-landing2.aspx?location=' + cityname;
            }
            else if (file == "storage-search-landing3.aspx")
            {
                url = 'storage-search-landing3.aspx?location=' + cityname;
            }
            else
            {
                url = 'storage-search-landing.aspx?location=' + cityname;
            }
            window.location.href=(url);
        }
    }

    function DocfilenameExtract()
{
wholeurl = document.location.href;
x = wholeurl.length;
while((wholeurl.substring(x,x-1))!= "/"){ x--; } clipstart = x;
return wholeurl.substring(wholeurl.length,clipstart);
}



  //This how we can enable the infowindow when user clicks on any coupon

   function LoadDefaultImages()
   {
        var nIndex;
        var nIndex1;
        if (PointsArray.length != 0)
        {
            for( nIndex=0; nIndex< PointsArray.length; nIndex++)
            {
                ImageArray[nIndex]= "flag_"+nIndex+".gif";
            }
        }
   }

   function LoadDefaultImagesForNoCoupons()
   {
        var nIndex;
        var nIndex1;
        if (PointsArrayWithNoCoupons != undefined)
        {
            if (PointsArrayWithNoCoupons.length != 0)
            {
                var StartIndex = ImageArray.length;
                for( nIndex1=0; nIndex1< PointsArrayWithNoCoupons.length; nIndex1++)
                {
                    var imageIndex = StartIndex+nIndex1;
                    ImageArrayWithNoCoupons[nIndex1]= "flag_"+imageIndex+".gif";
                }
            }
        }
   }
      //The main difference is that the RegisterStartupScript method places the JavaScript at the
    //bottom of the ASP.NET page right before the closing </form> element. The RegisterClientScriptBlock
    //method places the JavaScript directly after the opening <form> element in the page.
    function LoadOnHyperlinkClick(Address, SiteID, PointX, PointY, imageIndex, flag, refresh)
    {
        customsLinks();
        LoadDefaultImages();
        LoadDefaultImagesForNoCoupons();
        ImageArray[imageIndex] = "flag_highlight_"+imageIndex +".gif";
        if (GBrowserIsCompatible())
        {
            CreateMarkersList(map , refresh);
        }
        if (flag == "true")
        {
            clickOnHyperlink = "true";
            GEvent.trigger(gmarkers[imageIndex], "click");
            return false;
        }
      }

      function customsLinks()
      {
        var linkname = "Search Results Pushpin Click";
        var s = s_gi(s_account)
        s.linkTrackVars = "events"
        s.linkTrackEvents = "event22"
        s.events="event22";
        s.tl(true, 'o', linkname);
      }

     function LoadOnHyperlinkClickWithNoCoupons(Address, SiteID, PointX, PointY, imageIndex, flag, refresh)
    {
        LoadDefaultImagesForNoCoupons();
        LoadDefaultImages();
        var innerimageIndex = PointsArray.length +imageIndex;
        ImageArrayWithNoCoupons[imageIndex] = "flag_highlight_"+innerimageIndex +".gif";
        if (GBrowserIsCompatible())
        {
            CreateMarkersListWithNoCoupons(map , refresh);
        }
        if (flag == "true")
        {
            return false;
        }
      }

    function TableCellClick(PointX, PointY, imageIndex)
    {
        LoadDefaultImages();
        LoadDefaultImagesForNoCoupons();
        ImageArray[imageIndex] = "flag_highlight_"+imageIndex +".gif";

        if (GBrowserIsCompatible())
        {
            CreateMarkersList(map , "TRUE");
            CreateMarkersListWithNoCoupons(map, "TRUE");
        }
      }

      function ClearAllCouponsHighlight()
      {
        var items = document.getElementsByTagName('table');

            for(i=0;i<items.length;i++)
            {
                //For FireFox, the color compare has to be "rgb(255, 250, 115)"
                if (items[i].style.backgroundColor=="rgb(255, 250, 115)" || items[i].style.backgroundColor == backgroundColor)
                {
                    items[i].style.backgroundColor='white';
                    items[i].style.color='Black';
                }
            }
      }
      function highlightMultiSelected(spanChk)
      {
            var items = document.getElementsByTagName('table');
            for(i=0;i<items.length;i++)
            {
                if (items[i].id !="")
                {
                    if(items[i].id != spanChk.id )
                    {
                        items[i].style.backgroundColor='white';
                        //items[i].style.color='Black';
                    }
                    else
                    {
                        items[i].style.display="";
                        items[i].style.backgroundColor=backgroundColor;
                        //items[i].style.color=backgroundColor;
                    }
                }
            }
      }

    function ResetAllBaloonImages1(divid)
    {
        //debugger;
        var images = document.getElementsByTagName("img");
        for (imageIndex = 0; imageIndex < images.legth; imageIndex++)
        {
            document.write(images[imageIndex].src);
        }
    }

      function ResetAllBaloonImages(divid)
      {
        //debugger;
        var images = document.getElementsByTagName("img");
        var items = document.getElementsByTagName('table');
        if (markersinBoundary != null)
        {
            var Addresses =  markersinBoundary.split ( '|' );
            for(j =1;j< gmarkers.length+1 ; j++)
            {
                for(i=0;i<items.length;i++)
                {
                    if (items[i].id == j)
                    {
                        var imageId;
                        var imageIndex= divid-1;

                        if (j <= 9)
                        {
                            var imageId = "ctl00_PublicStoragePageContent_dlLocations_ctl0"+imageIndex+"_baloonImage";
                        }
                        else
                        {
                            var imageId = "ctl00_PublicStoragePageContent_dlLocations_ctl0"+imageIndex+"_baloonImage";
                        }
                        var image = document.getElementById(imageId);
                        if (image != null)
                        {
                            var imageSrc = image.src;
                            var match = imageSrc.match("flag_highlight_");
                            if (match != null)
                            {
                                image.src= "../images/balloons/flag_"+imageIndex+".gif";
                            }
                        }
                        if (divid == j )
                        {
                            var imageIndex = divid -1;
                            image.src= "../images/balloons/flag_highlight_"+imageIndex+".gif";
                            break;
                        }
                    }
                }
            }
        }
      }

      function highlightSelected(spanChk) {
      //debugger;
            var items = document.getElementsByTagName('table');
            for(i=0;i<items.length;i++)
            {
                items[i].style.backgroundColor='white';
            }
            spanChk.style.backgroundColor = backgroundColor;
            // For High lighting Balloons in Coupons first Unhighlighting all Balloons
            UnHighLightLastBalloon();
            LastBalloonID="";
            LastFlagIDIndex="x";
            //End
            if (isInfoWindowOn == true)
            {
                if (currentDivIndex != spanChk.id)
                {
                    map.closeInfoWindow();
                    isInfoWindowOn = false;
                }
            }

            var CurrentRdbID = spanChk.id;
            if (CurrentRdbID != null)
            {
                  var nIndex = parseInt(CurrentRdbID);
                  if (nIndex > 0)
                  {
                      nIndex = nIndex - 1;
                      if (PointsArray != undefined)
                      {
                          if (PointsArray.length != 0)
                          {
                           ////Highlighting Single Coupon
                           var str = spanChk.innerHTML;
                           var str2=str.split("ctl00_PublicStoragePageContent_dlLocations_ctl");
                              if (str2.length > 1 )
                              {
                                   var str3=str2[1].split("_baloonImage");
                                   var nImageIndex = str3[0];
                                    var imageId = "ctl00_PublicStoragePageContent_dlLocations_ctl"+ nImageIndex +"_baloonImage";
                                    LastBalloonID=imageId;
                                    var image = document.getElementById(imageId);
                                    if (image != null)
                                        {
                                            var nIndex= spanChk.id-1 ;
                                             image.src= "../images/balloons/flag_highlight_"+ nIndex+".gif";
                                             LastFlagIDIndex=nIndex;
                                        }
                               }
                             TableCellClick(PointsArray[nIndex][0], PointsArray[0][1], nIndex);
                          }
                      }
                  }
            }
      }

       /// For  UnHighlighting Balloons in the Coupon
     function UnHighLightLastBalloon()
      {
        if(LastBalloonID != '' && LastFlagIDIndex !='x')
        {
         var strSplitBallonID = LastBalloonID.split('|');
         for(i=0;i<strSplitBallonID.length;i++)
          {
                 var image = document.getElementById(strSplitBallonID[i]);
                 if (image != null)
                  {
                   image.src= "../images/balloons/flag_"+ LastFlagIDIndex+".gif";
                  }
           }
        }

      }
      // For High Lighting Balloons in Coupon Multi-Coupons Scenario
    function HighLighMultiSelectBalloon(BalloonIndex)
    {
        var images = document.getElementsByTagName("img");
        var chkImgSrc="../images/balloons/flag_"+ BalloonIndex +".gif";
         for(i=0;i<images.length;i++)
        {
                  if (i <= 9)
                  {
                    var imageId = "ctl00_PublicStoragePageContent_dlLocations_ctl0"+i+"_baloonImage";
                  }
                  else
                  {
                   var imageId = "ctl00_PublicStoragePageContent_dlLocations_ctl"+i+"_baloonImage";
                  }
                  var image = document.getElementById(imageId);
                   if (image != null)
                    {
                        var imageSrc = image.src;
                        var substrimageSrc=imageSrc.indexOf(chkImgSrc);
                        if(substrimageSrc != -1)
                        {
                           imageSrc=imageSrc.replace("flag_","flag_highlight_");
                           image.src =imageSrc;
                          // debugger;
                          //For Multi Highlighting Check
                           if (LastBalloonID != '')
                           {
                                   if((LastBalloonID) != (imageId))
                                   {
                                      LastBalloonID= LastBalloonID + "|" +  imageId ;
                                   }
                             }
                             else
                             {
                                     LastBalloonID= imageId ;
                             }
                           LastFlagIDIndex = BalloonIndex ;
                        }
                    }
         }
    }

