﻿// JScript File
// JScript File

google.load('maps' , '2');
google.load('search' , '1');
google.load("elements", "1", {
  packages : ["localsearch"]
});
var map;
var center
var directions;
var geocoder ;
var searcher;
var fromaddress 
var toaddress 
var vPoint = 0;
var checkDirection
var t;
var blnComplete="false";
var dstMiles;
var j = 0;
var myArray; 
var srtArray; 
fromaddress=""
toaddress=""
var imgCounter = 0;
var arrayCounter = 0;
var blnProgress = false;
var blnSearchOne = false;
var logoIdx = 0;
var geocoder, location1, location2, gDir;
var blnsearchdb ;
var searchDining;
var searchSeating;
var searchReservation;
var pref_counter;
var pref_inprogress;
var pref_found_counter;
var pref_found_lat;
var pref_found_lng;
var bln_search_distance;
var search_distance;
var bln_season_tgc;
var searchtext;
var selectedResName;
var tableName = "";
var default_distance = 0
var IsSuggestedResult;
IsSuggestedResult=false;
var SugestedFromAddress;
SugestedFromAddress="";
var reasons=[];
var lCounter;
var isMeanAddress;
var isRevDirection;
var revFromAddress ;
var state_code;

function googleplace(addr){

$("input#txtsearch").val(addr);
$("input#btnSearch").click();

}



function getPath(vFrom,vTo,checkDirection,dvTarget)
{


    if(map!=null){

    document.getElementById(dvTarget).innerHTML=""
    directionsPanel = document.getElementById(dvTarget);
    directions = new GDirections(map, directionsPanel);
    directions.clear();
    fromaddress= vFrom;
    toaddress = vTo;



 
    if(checkDirection=="0")
    {

    directions.load("from: "+fromaddress+" to: "+toaddress);
    }
    else if(checkDirection=="1")
    {

    directions.load("from: "+fromaddress+" to: "+toaddress ,{travelMode:G_TRAVEL_MODE_WALKING});}
    else if(checkDirection=="2")
    {

    }
  
 
 
    GEvent.addListener(directions, "error", function() {
showSuggestedAddress();
   // alert("Error code "+directions.getStatus().code + ": Not able to find direction")
   // alert("Location from " + fromaddress + " to " + toaddress + "  cannot be found.");

    });


}


$("body").bind("mousemove", function(){

$(this).find("div.group > div#locator_div > div#map > div#content > div > div > div > div > svg:not(:last)").attr("style", "display:none;").remove(); //FF
$(this).find("div.group > div#locator_div > div#map > div#content > div > div > div > div[dir='ltr'] > *[unselectable='on']:not(:last)").attr("style", "display:none;").remove(); //IE

});


}



function showSuggestedAddress() {
        var search; 
        search=toaddress;

        geocoder.getLocations(search, function(result) {
            // map.clearOverlays();
            if (result.Status.code == G_GEO_SUCCESS) {
                var strhtm;
                strhtm = "";
                if (result.Placemark.length > 0) {
                isMeanAddress=true;
                    strhtm+= "<div style='font-size:14px;margin-top:15px;'>Did you mean:</div>";
                    for (var i = 0; i < result.Placemark.length; i++) {
                        var p = result.Placemark[i].Point.coordinates;
                        if(isRevDirection)
                        {
                        strhtm += "<br><div style='font-size:12px;' class='num left'>" + (i + 1) + ":&nbsp;&nbsp;</div> <a  style='cursor:pointer'  onclick=\"getRevDirection(" + lCounter + ",'" + result.Placemark[i].address  + "');\" >" + result.Placemark[i].address + "</a>";
                        }else
                        {
                        strhtm += "<br><div style='font-size:12px;' class='num left'>" + (i + 1) + ":&nbsp;&nbsp;</div> <a  style='cursor:pointer'  onclick=\"getDirection(" + lCounter + ",'" + result.Placemark[i].address  + "');\" >" + result.Placemark[i].address + "</a>";
                        }
                      //  strhtm += "<br><div style='font-size:12px;' class='num left'>" + (i + 1) + ":&nbsp;&nbsp;</div> <a  style='cursor:pointer'  onclick=\"place('"+result.Placemark[i].address+"' );\" >" + result.Placemark[i].address + "</a>";
                  
                    //getDirection(" + imgName + ",'" + nToAddress + "')
                    }
                     if(document.getElementById("route"+lCounter) != null)
                    {
                    document.getElementById("route"+lCounter).innerHTML = strhtm;
                    }else
                    {
                    alert("Unable to find direction , please try \"To here\" direction and then try \"From here\" direction");
                     return;

                    }
                   
                }
                else {
                 alert("Location from " + fromaddress + " to " + toaddress + "  cannot be found.");
                }
            }
            // ====== Decode the error status ======
            else {
             
                var reason = "Code " + result.Status.code;
                if (reasons[result.Status.code]) {
                    reason = reasons[result.Status.code]
                }
                alert("Location from " + fromaddress + " to " + toaddress + "  cannot be found.");
              
            }
        }
        );
      }


function place(add) {

      var suggDiv=document.getElementById("route"+lCounter);
        if(suggDiv!=null)
        {
        suggDiv.innerHTML = "";
        document.getElementById("txtSearchToName"+lCounter).value=add;
        }
      }





function MyKeepHandler(result,imgName,distance,logoName , orgTitle, addressline1 , addressline2 , country ,  telnumber , lat ,lng, RestId , commingsoon)
{ 
          
    var rest_addr = lat+"_"+lng;  

    var nToAddress = addressline1 + " " + addressline2 + " " + country ;
    var dvLocations = document.getElementById("locations");

    var node = document.createElement('div');
    var newdiv = document.createElement('div');
    var menudiv = document.createElement('div');
    var routediv = document.createElement('div');
    var dvlocation = document.createElement('div');
    var dvAddress = document.createElement('div');
    var sendto_div = document.createElement('div');
    var direction_div = document.createElement('div');
    var detail_div = document.createElement('div');
    var txtSendToName = "txtSendTo" + imgName;
    var sendToSelectId = "select"+imgName;
    var ddName = "ddName" + imgName;
    var ddSend = "ddSend" + imgName;
    var txtSearchToName = "txtSearchToName" + imgName;
    var dvloc = "location" + + imgName;
    var sendto_div = "sendto"+imgName;
    var direction_div = "dir"+imgName;
    var detail_div = "detail"+imgName;
    var routediv = "route"+imgName;
    var addrstring = result;
    var tohere = "tohere"+imgName;
    var fromhere = "fromhere"+imgName;
    var norgTitle = orgTitle.replace("&amp;","");
    norgTitle = norgTitle.replace("&#39;","");
    var vTitle = norgTitle;
    var vLogoName;
    var vMarker;
    var menuLink;
    var vCommingSoon;
          
          ///////////// set logo on the base of title 
           if(vTitle.search("Red Lobster") >= 0)
                {
                    vLogoName = "Red_Lobster_menu.gif";
                    vCommingSoon = "rl_coming-soon.jpg";
					vMarker = "redlob";
					orgTitle = "Red Lobster";
					
					menuLink = "http://www.redlobster.com/locator/redir/menu.asp?busid="+RestId;
                }else if(vTitle.search("Bahama Breeze") >= 0)
                {
                  vLogoName = "Bahama_Breeze_menu.gif";
                  vCommingSoon="bb_coming_soon.gif";
				  vMarker = "bahamabreeze";
				  orgTitle = "Bahama Breeze";
				 
				  menuLink = "http://www.bahamabreeze.com/pdf/locator/togo/TG"+RestId+".pdf";
                }else if(vTitle.search("Olive Garden") >= 0)
                {
                    vLogoName = "Olive_Garden_menu.gif";
					vMarker = "olive";
					vCommingSoon="og_coming-soon.jpg";
					menuLink = "http://www.olivegarden.com/locator/redir/menu.asp?busid="+RestId;
                }else if(vTitle.search("Capital Grille") >= 0)
                {
                  vLogoName = "Capital_Grille_menu.gif";
                  vCommingSoon="tcg_coming-soon.jpg";
				  vMarker = "tcg";
				  menuLink = "http://www.thecapitalgrille.com/menu/main.asp";
				 
                }else if(vTitle.search("Seasons 52") >= 0)
                {
                 vLogoName = "Seasosns52_menu.gif";
                 vCommingSoon="season_coming-soon.jpg";
				 vMarker = "season";
				 menuLink = "http://www.seasons52.com/menu/default.asp";
				 
                }else if(vTitle.search("LongHorn") >= 0)
                {
                  vLogoName = "Longhorn_menu.gif";
                  vCommingSoon="lh_coming-soon.jpg";
				  vMarker = "longhorn";
				  orgTitle = "LongHorn Steakhouse";
				 
				  menuLink = "http://www.longhornsteakhouse.com/MyLongHorn.asp?show=menu&RestaurantID="+RestId;
                }
          
          orgTitle = orgTitle + " - " + RestId; //Added 11/11/2010 and AGAIN 12/02/2010 By BC

          ////////////////////////////////
     
     
    var dst = 0;
    dvlocation.id = dvloc;

    newdiv.className = "info";
    menudiv.className = "panels";
    dvAddress.className = "vcard address";
    dvlocation.className = "location";
    var lstData =  "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td id=\"marginbtn\" colspan=\"3\">Get Directions : <a id='"+ tohere +"' style=\"cursor:pointer;\" class=\"direction_selected\" onclick=\"getDirection("+ imgName + ",'"+ nToAddress + "'); return false;\">To here</a> | <a id='"+ fromhere +"' style=\"cursor:pointer;\" class=\"direction_unselected\" onclick=\"getRevDirection("+ imgName +",'"+ nToAddress + "'); return false;\">From here</a> </td></tr>"
    lstData  += "<tr><td colspan=\"2\" ><input class=\"go_input\" type=\"text\" onfocus=\"clearFld(this.id)\" value=\"Enter Location Here\" id="+ txtSearchToName  +" name="+ txtSearchToName  +"></td><td><input type=\"button\" class=\"go_btn\"   value=\"GO\" onclick=\"getDirection("+ imgName + ",'"+ nToAddress + "')\"></td></tr>";
    lstData  += "<tr><td colspan=\"2\"><select style=\"margin-top:3px;\" name="+ ddName +" id="+ ddName +">";
    lstData += "<option  selected=\"selected\" value=\"1\">By Car</option>";
    lstData += "<option value=\"2\">Walking</option>";
    lstData += "</select></td><td></td></tr></table>";

            //////// updated by tahir 27 March 2010 == call function getMenuLink to get the id of the resturatn
			
    var strHTML = "";
    strHTML = "<DIV class=\"info\"><SPAN> <IMG src=\"images/icon/" +vMarker+"/"+ imgName +".png\"><SPAN style=\"color:#333333; display: block; width: 100%; height: 30px; margin: 0; padding: 0; text-align: center; overflow: hidden;\" class=\"toLoc miles\">"+ distance +" Miles</SPAN></SPAN></DIV>";
   
    if(commingsoon == 'True')
    {
    strHTML += "<DIV class=\"vcard address\"><IMG  src=\"images/icon/" + vCommingSoon + "\">";
    }else
    {
    strHTML += "<DIV class=\"vcard address\"><A class=\"menu\" target=\"_blank\"  href="+menuLink+"><IMG class=\"photo\" src=\"images/icon/" + vLogoName + "\"></A>";
    }
    
    strHTML += "<DIV class=\"org\"><A name=\"result"+imgName+"\" style=\"color:#000000;cursor:pointer;\" onclick=\"getCenter("+ lat +","+lng +")\"><B>"+ orgTitle +"</B></A></DIV>";
    strHTML += "<DIV class=\"adr\">";
    strHTML += "<DIV class=\"street-address\">"+ addressline1 +"</DIV>";
    strHTML += "<DIV class=\"adr\">";
    strHTML += "<DIV class=\"street-address\">"+ addressline2 +"</DIV></DIV>";
    strHTML += "<DIV class=\"tel\">"+ telnumber +"</DIV></DIV></DIV>";
    strHTML += "<DIV class=\"panels\"> <input type=\"hidden\" id=\"hdnMeanAdd"+imgName+"\" />";
    strHTML += "<UL class=\"three_buttons\">";

        if( vTitle.search("Capital Grille") >= 0)
        {
        strHTML += "<LI class=\"directions\"><A href=\"#\" onclick=\"showDiv('"+ direction_div + "',"+ imgName + " );return false;\">Directions</A></LI>";
        strHTML += "<LI class=\"sendto\"><A href=\"#\" onclick=\"showDiv('"+ sendto_div + "' ,"+ imgName + ");return false;\">Send to</A></LI>";
        }else
        {
        strHTML += "<LI class=\"directions\"><A href=\"#\" onclick=\"showDiv('"+ direction_div + "',"+ imgName + " );return false;\">Directions</A></LI>";
        strHTML += "<LI class=\"sendto\"><A href=\"#\" onclick=\"showDiv('"+ sendto_div + "' ,"+ imgName + ");return false;\">Send to</A></LI>";
        strHTML += "<LI class=\"details\"><A href=\"#\" onclick=\"getDetail('"+ RestId+ "',"+ imgName + ",'"+ norgTitle +"');return false;\">Details</A></LI>";
        }
    strHTML += "</UL>"
    strHTML += "<DIV class=\"drop_down_container\"><!--contains dropdown divs -->";
    strHTML += "<DIV style=\"display:none;\" id="+ direction_div +" class=\"drop_down directions\">"+ lstData +" ";
    strHTML += "<div id="+ routediv +"></div></DIV><!--end 'directions' div -->";
    strHTML += "<DIV style=\"display:none\" id="+sendto_div+" class=\"drop_down sendto\">";
    strHTML += "<SELECT id="+sendToSelectId+" onchange=\"changeSendToValue(this.id,'"+ txtSendToName  +"')\"><OPTION value=\"0\">Send To Email</OPTION><OPTION value=\"1\">Send To Phone</OPTION><OPTION value=\"Send To Printer\">Send To Printer</OPTION></SELECT>"; 
    strHTML += "<DIV class=\"send_bar\">";
    strHTML += "<DIV class=\"send_input\"><input style=\"border-color:#acacac;\" type=\"text\" onfocus=\"clearFld(this.id)\" value=\"Enter recipient's email address\" id="+ txtSendToName  +" /> </DIV>";
    strHTML += "<DIV class=\"send_btn\"><INPUT value=\"SEND\" onclick=\"sendEmail(" + imgName + ",'" + nToAddress + "','" + RestId + "','" + vTitle + "')\" type=\"button\"> </DIV></DIV></DIV>";
    strHTML +="<DIV style=\"display:none\" id="+ detail_div +" class=\"drop_down details\">";
    strHTML += "</DIV></DIV>";
    strHTML +="</DIV>";
    dvlocation.innerHTML = strHTML;
    dvLocations.appendChild(dvlocation);
/*
     $("div#"+sendto_div+" select").bind("change", function(){
     try{
	
	var selectedVal = $(this).val();
	
	if(selectedVal == "Send To Printer"){
	$(this).parents("div.drop_down").find(".send_bar .send_input input").attr("disabled", "disabled").val("Click \"SEND\" For Printable Directions");
	$(this).parents("div.drop_down").find(".send_bar .send_btn input").removeAttr("onclick").bind("click", function{
								
    var inputAddress = $(this).parents(".drop_down_container").find(".directions div.googledir").find("td[jscontent='address']:first").html();
    
    var restAddress = $(this).parents(".drop_down_container").find(".directions div.googledir").find("td[jscontent='address']:last").html();
    
    var directionsLink = "http://maps.google.com/maps?hl=en&saddr="+inputAddress+"&daddr="+restAddress+"&dirflg=&ie=UTF8&z=11&layer=c&pw=2";
    var walkingLink = "http://maps.google.com/maps?f=d&source=s_d&saddr="+inputAddress+"&daddr="+restAddress+"&hl=en&mra=ls&dirflg=w&ie=UTF8&z=12&layer=c&pw=2";
    if($(this).parents(".drop_down_container").find(".directions div.googledir").length == 0){alert("Please search for Directions on the \"Directions\" Tab.");}
    else{
    if($(this).parents(".drop_down_container").find(".directions div.googledir div[jsdisplay='walking']").css("display") != "none"){
    window.open(walkingLink);
    }
    else{
    window.open(directionsLink);
    }
    } ); 
	} else if (selectedVal == "0") {

            $(this).parents("div.drop_down").find(".send_bar .send_input input").removeAttr("disabled").val("Enter recipient's email address");
            $(this).parents("div.drop_down").find(".send_bar .send_btn").html("<INPUT value=\"SEND\" onclick=\"sendEmail(" + imgName + ",'" + nToAddress + "','" + RestId + "','" + vTitle + "')\" type=\"button\">");

        }else
        {
             $(this).parents("div.drop_down").find(".send_bar .send_input input").removeAttr("disabled").val("Enter recipient's phone number");
            $(this).parents("div.drop_down").find(".send_bar .send_btn").html("<INPUT value=\"SEND\" onclick=\"sendEmail(" + imgName + ",'" + nToAddress + "','" + RestId + "','" + vTitle + "')\" type=\"button\">");
        }
        }catch(err){}
        });
     

    }
 */ 
		}
 
       
function sPreference()
{
	
//sets scroller to top position on every update
    var api = $("div.locations_holder").scrollable({vertical:true, size: 1, clickable: false, keyboard: true, api:true});
    api.seekTo(0);


    blnsearchdb = false;
    searchDining = false;
    searchSeating = false;
    searchReservation = false;
    bln_search_distance = false;
    bln_season_tgc = false;
    search_distance = 0;
    var objDistance = document.getElementById("ddDistance");
    if(objDistance.selectedIndex > 0)
    {
        search_distance =  objDistance.options[objDistance.selectedIndex].value;
        bln_search_distance = true;
        blnsearchdb = true;
    }
    
    if(document.getElementById("dining").checked)
    {
        blnsearchdb = true;
        searchDining = true;
        bln_season_tgc = true;
        
    }
        
    if(document.getElementById("seating").checked)
    {
        blnsearchdb = true;
        searchSeating = true;
        bln_season_tgc = true;
    }
    if(document.getElementById("reservations").checked)
    {
        blnsearchdb = true;
        searchReservation = true;
        bln_season_tgc = true;
    }
    if(document.getElementById("ddResturant").selectedIndex > 0 && bln_season_tgc == true)
    {
   
    }

    OnLoad(null);
}

function OnLoad(act) {

//sets scroller to top position on every search
    var api = $("div.locations_holder").scrollable({vertical:true, size: 1, clickable: false, keyboard: true, api:true});
    api.seekTo(0);
     geocoder = new GClientGeocoder();
              reasons[G_GEO_SUCCESS] = "Success";
              reasons[G_GEO_MISSING_ADDRESS]= "Missing Address: The address was either missing or had no value.";
              reasons[G_GEO_UNKNOWN_ADDRESS]= "Unknown Address:  No corresponding geographic location could be found for the specified address.";
              reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
              reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
              reasons[G_GEO_TOO_MANY_QUERIES]= "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
              reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed.";
            
   // debugger
    vPoint = 0;
    blnComplete="false";
    j = 0;
    imgCounter = 0;
    blnProgress = false;
    blnSearchOne = false;

    pref_counter = 0;
    pref_inprogress = false;
    logoIdx = 0;
    arrayCounter = 0;
    pref_found_counter = 0;
    pref_found_lat=0;
    pref_found_lng=0;
    myArray = new Array();
    srtArray = new Array();
    selectedResName = "";
     if(act!=null)
     {
        blnsearchdb = false;
        bln_season_tgc = false;
        search_distance = 0;
        searchDining = false;
        searchSeating = false;
        searchReservation = false;
     }
 
 
////////
    var objDistance = document.getElementById("ddDistance");
     if(objDistance.selectedIndex > 0)
     {
       search_distance =  objDistance.options[objDistance.selectedIndex].value;
       bln_search_distance = true;
       blnsearchdb = true;
     }
   
    if(document.getElementById("dining").checked)
     {
        blnsearchdb = true;
        searchDining = true;
        bln_season_tgc = true;
        
     }
        
     if(document.getElementById("seating").checked)
     {
        blnsearchdb = true;
        searchSeating = true;
        bln_season_tgc = true;
     }
     if(document.getElementById("reservations").checked)
     {
        blnsearchdb = true;
        searchReservation = true;
        bln_season_tgc = true;
      }

////////////
    geocoder = new GClientGeocoder();
    var address= document.getElementById("txtsearch").value;
    var selectedResturant = document.getElementById("ddResturant")
    var dvResult = document.getElementById("locations");
    var spload =  document.getElementById("spLoading");
    var contentDiv = document.getElementById('content');
    var idx = selectedResturant.selectedIndex;
    searchtext = address;
    dvResult.innerHTML='';
    contentDiv.innerHTML = '';
    spload.style.display = 'block';
    tableName="";

    if(idx > 0)
    {
     switch(idx)
     {
          case 1:
          tableName="bahamabreeze";
          break;
          case 2:
          tableName="tcg";
          break;
          case 3:
          tableName="longhorn";
          break;
          case 4:
          tableName="olive";
          break;
          case 5:
          tableName="redlob";
          break;
          case 6:
          tableName="season";
          break;
         
          
     }
   }else if(bln_season_tgc)
    {
       tableName="season_tgc";
    }
///////////////
/////////////////

///// update 11 Nov ,2010 by Tahir
if(address == "" ){
  var query_value = getQueryVariable("q");

        if (query_value != 'undefined') {
            if (query_value != null) {
                if (query_value != "") {
                    document.getElementById("txtsearch").value = '';
                    document.getElementById("txtsearch").value = decodeURI(query_value);                    
                    address = decodeURI(query_value);
                    searchtext = address;
                    
                   
                }
            }
        }
}
//////////////////

if (document.getElementById("txtsearch").value.length > 0) {
    $("label").attr({ htmlFor: "txtsearch" }).hide();

}

          if(address == "")
          {
            var param = "id=ip"; 
            $.ajaxSetup ({   
            cache: false  
            });  
            $.ajax({ 
            type: "GET", 
            url: "getDefaultAddress.aspx", 
            data: param , 
            success: function(d) { 
           
            searchtext = d;
            if(parseInt(search_distance) < 1)
            search_distance =  0;
            bln_search_distance = true;
          //  blnsearchdb = true;
            geocoder.getLatLng(d,    function(point)
            {   
            
            if (!point) {  
            				 
			 var nfHTML = "";
			 nfHTML = "<div id='notfound' style='width:240px; margin:150px auto 0; text-align:center;'>";
			 nfHTML += "<h1 style='font:bold 30px Arial, Helvetica, sans-serif; color:#8b1106; margin-bottom: 5px;'>IP NOT FOUND</h1>";
			 nfHTML += "<p style='font: bold 16px Arial, Helvetica, sans-serif; color:#000; line-height: 1.5em; margin-top: 0;'>Sorry, we could not locate your IP Address. Please enter your city, state, or zip code.</p>";
			 nfHTML += "<input type='button' id='tryagain' style='font: bold 14px Arial, Helvetica, sans-serif; color:#fff; background: #8b1106 url(common/images/try-again-btn.gif) no-repeat center top; border:none; width: 104px; height: 30px; overflow: hidden; cursor:pointer;' value='SEARCH' /></div>";
			 
				if($("div#locations").html()==""){
				$("div#locations").html(nfHTML);							 
				}
							 
							 

                spload.style.display='none';
                } // end of first if (!point)
                else {  
                vPoint = point;
                 geocoder.getLocations(point, function(addresses) {
                                if(addresses.Status.code != 200) {
                                 state_code = "";
                                  init();
                                //alert("reverse geocoder failed to find an address for " + latlng.toUrlValue());
                                // errorMessage();
                                     }
                                else {
                                   for(var m=0 ; m <addresses.Placemark.length;m++ )
                                   {
                                        if(addresses.Placemark[m].AddressDetails.Country.AdministrativeArea != null)
                                            {
                                                state_code = addresses.Placemark[m].AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
                                                break;
                                            }
                                    
                                        
                                     }// end for
                                     init();
                                }      
                               
                          });
                }    }  );

                } 

                });  
           }else
           {
               geocoder.getLatLng(address, function (point) {

                   if (!point) {

                       var nfHTML = "";
                       nfHTML = "<div id='notfound' style='width:240px; margin:150px auto 0; text-align:center;'>";
                       nfHTML += "<h1 style='font:bold 30px Arial, Helvetica, sans-serif; color:#8b1106; margin-bottom: 5px;'>NOT FOUND</h1>";
                       //nfHTML += "<p style='font: bold 16px Arial, Helvetica, sans-serif; color:#000; line-height: 1.5em; margin-top: 0;'>Sorry, but your search yielded no results. Please try again.</p>";
                       nfHTML += "<p style='font: bold 16px Arial, Helvetica, sans-serif; color:#000; line-height: 1.5em; margin-top: 0;'>We were unable to auto-detect your address.  Please enter a valid address, city, state or zip code.</p>";

                       nfHTML += "<input type='button' id='tryagain' style='font: bold 14px Arial, Helvetica, sans-serif; color:#fff; background: #8b1106 url(common/images/try-again-btn.gif) no-repeat center top; border:none; width: 104px; height: 30px; overflow: hidden; cursor:pointer;' value='TRY AGAIN' /></div>";
                       $("div#locations").html(nfHTML);
                       spload.style.display = 'none';
                   } // end of first if (!point)
                   else {

                       //alert(point) 
                       vPoint = point;
                       geocoder.getLocations(point, function (addresses) {

                           if (addresses.Status.code != 200) {
                               state_code = "";
                               init();
                               //alert("reverse geocoder failed to find an address for " + latlng.toUrlValue());
                               // errorMessage();
                           }
                           else {
                               for (var m = 0; m < addresses.Placemark.length; m++) {
                                   try {
                                       if (addresses.Placemark[m].AddressDetails.Country.AdministrativeArea != null) {
                                           state_code = addresses.Placemark[m].AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
                                           break;
                                       }
                                   }
                                   catch (Error) {
                                       //fail silently
                                   }

                               } // end for
                               init();
                           }
                       });


                   } 
               });
                         
    }
      
   }

   
   ///////////
   ///////////
function init() {

    
                            $.ajaxSetup({
                                cache: false
                            });
                          //  debugger
                            var param = "lat="+vPoint.y+"&lon="+vPoint.x+"&table="+tableName+"&search=" + searchtext+"&preference="+bln_season_tgc+"&D="+searchDining+"&S="+searchSeating+"&O="+searchReservation+"&distance="+search_distance+"&state_code="+state_code;;
                           // alert(param)
                            $.ajax({
                                type: "GET",
                                url: "getdata.aspx",
                                data: param,
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                error: function() {
                                   // errorMessage();
                                   errorMessage();
                                   document.getElementById("spLoading").style.display = 'none';
                                },
                                success: function(d) {
                                /////
                               
                              //  alert(d.results.length)
                                for (var i = 0; i < d.results.length  ; i++) {
                                
            // debugger
            var result = d.results[i]; // Get the specific result
            
            var markerLatLng = new google.maps.LatLng(parseFloat(result.lat),
                                                    parseFloat(result.lng));


            imgCounter++
            var imgName = imgCounter;
            var strIno = "";
                //alert(result.phone_number)        
                strIno +="<div class=\"gs-localResult gs-result\">";
                    strIno +="<div class=\"gs-title\">";
                        strIno +="<a href=\"#\" class=\"gs-title\" target=\"_blank\"><b>"+ result.title +"</b></a></div>";
                    strIno +="<div class=\"gs-address\">";
                        strIno +="<div class=\"gs-street gs-addressLine\">";
                            strIno += result.Address1  +"</div>";
                        strIno += "<div class=\"gs-city gs-addressLine\">";
                           strIno += result.city + ", " + result.state + " " + result.zip +"</div>";
                       strIno += "</div>";
                    strIno +="<div class=\"gs-phone\">";
                     strIno += result.phone_number  + "</div></div>";
                    
             
         //   var vFromLatlan = new google.maps.LatLng(vPoint.y, vPoint.x);
         //   var mileDistance = vFromLatlan.distanceFrom(markerLatLng, 3959).toFixed(2);
         var mileDistance = result.rest_distance;
            
            // alert(mileDistance)

            /////// store result into array /////////////
            var vTitle = result.title;
            
           // alert(result.phone_number)
           // return;
            
            
            var dvInfoWindow = document.createElement("div");
            dvInfoWindow.innerHTML = strIno;
           // dvInfoWindow.innerHTML = "hello";
          //  if(mileDistance <= default_distance)
          //    {
                srtArray[arrayCounter] = new Array(13)

                for (k = 0; k < 14; k++) {
                    switch (k) {
                        case 0:
                            srtArray[arrayCounter][k] = mileDistance;
                            break;
                        case 1:
                            if (result.phone_number == null) {
                                srtArray[arrayCounter][k] = "<strong>" + result.title + "</strong><br>" + result.Address1 + " <br> " + result.city + ", " + result.state ;
                            } else
                                srtArray[arrayCounter][k] = "<strong>" + result.title + "</strong><br>" + result.Address1 + " <br> " + result.city + ", " + result.state  + "<br>" + result.phone_number;
                            break;
                        case 2:
                            srtArray[arrayCounter][k] = result.lat;
                            break;
                        case 3:
                            srtArray[arrayCounter][k] = result.lng
                            break;
                        case 4:
                            srtArray[arrayCounter][k] = j
                            break;
                        case 5:
                            srtArray[arrayCounter][k] = result.title ; //result.addressLines[0] + " " + result.addressLines[1] + " " + result.country;
                            break;
                        case 6:
                            srtArray[arrayCounter][k] = result.Address1;
                            break;
                        case 7:
                            srtArray[arrayCounter][k] = result.city + ", " + result.state+" " + result.zip;
                            break;
                        case 8:
                            srtArray[arrayCounter][k] = "";
                            break;
                        case 9:
                            if (result.phone_number == null) {
                                srtArray[arrayCounter][k] = "";
                            } else
                                srtArray[arrayCounter][k] = result.phone_number;
                            break;
                        case 10:
                            srtArray[arrayCounter][k] = dvInfoWindow; //"<div>hello</div>";//result.html.cloneNode(true);
                            break;
                            case 11:
                            srtArray[arrayCounter][k] = result.fax ; //"<div>hello</div>";//result.html.cloneNode(true);
                            break;
                            case 12:
                                                    
                            srtArray[arrayCounter][k] = result.RestId;
                            break;
                        case 13:
                            srtArray[arrayCounter][k] = result.commingsoon;
                            break;
                           



                    }
                }

                arrayCounter++;
           // }
          }
            ////////////////sort array ends here///////////////////                 
      


        
            if (srtArray.length > 0) {
                 getSortedValues();           
            } else  // end if(srtArray.length > 0)
            {
                
                function showAddress() {
                    var search = document.getElementById("txtsearch").value;
                    // ====== Perform the Geocoding ======        
                    geocoder.getLocations(search, function(gresult) {
                        if (map != null) {
                            map.clearOverlays();
                        }
                        if (gresult.Status.code == G_GEO_SUCCESS) {
                            // ===== If there was more than one result, "ask did you mean" on them all =====
                            if (gresult.Placemark.length > 1) {
                                 var didHTML = "";
        didHTML = "<div style='width:300px; height:185px; border: 2px solid #373737; margin:0 auto; background-color:#fff; color:#000; margin-top: 100px;'>";
        didHTML += "<a id='x_noneofthese' href='#' onclick='return false;'><img src='common/images/x_btn.png' border='0' style='float:right; margin: -14px -14px 0 0; cursor:pointer;' /></a>";
        didHTML += "<div style='width: 90%; margin: 10px auto 0 auto;'>";
        didHTML += "<strong>Did you mean:</strong>";
        didHTML += "<div id='dymresults' style='width: 100%; height: 111px; overflow: auto; margin-top: 5px;'>";
        didHTML += "</div></div><a id='noneofthese' href='#' onclick='return false;' style='text-align:center; display:block; font-size: 11px; padding-top:8px; color:#000;'>None of these, refine search.</a></div>"

                                document.getElementById("content").innerHTML = didHTML;


                                // Loop through the results
                                for (var i = 0; i < gresult.Placemark.length; i++) {
                                    var praw = gresult.Placemark[i].address;
                                    var p = "";
                                    if (praw.indexOf(", USA") != -1) {
                                        p = praw.replace(", USA", "");
                                    } else { p = praw; }
                                    document.getElementById("dymresults").innerHTML += (i + 1) + ": <a href='#' onclick='googleplace(\"" + p + "\"); return false;'>" + p + "<\/a><br>";
                             

                                }

                                // ========= adds the "not found" message to the side ===========				
                                var nfHTML = "";
        nfHTML = "<div id='notfound' style='width:240px; margin:150px auto 0; text-align:center;'>";
        nfHTML += "<h1 style='font:bold 30px Arial, Helvetica, sans-serif; color:#8b1106; margin-bottom: 5px;'>NOT FOUND</h1>";
        nfHTML += "<p style='font: bold 16px Arial, Helvetica, sans-serif; color:#000; line-height: 1.5em; margin-top: 0;'>Your search yielded multiple results. Choose your location from the list or try again.</p>";
        nfHTML += "<input type='button' id='tryagain' style='font: bold 14px Arial, Helvetica, sans-serif; color:#fff; background: #8b1106 url(common/images/try-again-btn.gif) no-repeat center top; border:none; width: 104px; height: 30px; overflow: hidden; cursor:pointer;' value='TRY AGAIN' /></div>";

        $("div#locations").html(nfHTML);






                            }
                            // ===== If there was a single marker =====
                            else {
                                //document.getElementById("content").innerHTML = "";
                                //var p = gresult.Placemark[0].address;
                                //googleplace(p);

                                if ($("div#content").html() == "" && $("div#locations").html() == "") {
                                    var searchtext = document.getElementById("txtsearch").value;
                                    //alert(" No result Found in " + searchtext );

                                    // ========= adds the "not found" message to the side ===========				
                                   var nfHTML = "";
//debugger
        nfHTML = "<div id='notfound' style='width:240px; margin:120px auto 0; text-align:center;'>";
        nfHTML += "<h1 style='font:bold 30px Arial, Helvetica, sans-serif; color:#8b1106; margin-bottom: 5px;'>NOT FOUND</h1>";
	nfHTML += "<p style='font: bold 16px Arial, Helvetica, sans-serif; color:#000; line-height: 1.5em; margin-top: 0;'>Sorry, there are no Darden<sub style='font-size:11px;'>SM</sub> Restaurants in the <span style='color:#8b1106; font-style: italic;'>"+decodeURI(searchtext)+"</span> area. Would you like to try a different location?</p>";
        nfHTML += "<input type='button' id='tryagain' style='font: bold 14px Arial, Helvetica, sans-serif; color:#fff; background: #8b1106 url(common/images/try-again-btn.gif) no-repeat center top; border:none; width: 104px; height: 30px; overflow: hidden; cursor:pointer;' value='TRY AGAIN' /></div>";

        $("div#locations").html(nfHTML);

                                }

                            }
                        }
                        // ====== Decode the error status ======
                        else {
                            var reason = "Code " + gresult.Status.code;
                            //if (reasons[gresult.Status.code]) {
                            // reason = reasons[gresult.Status.code]
                            //} 
                            alert('Could not find "' + search + '" ' + reason);
                        }
                    }
        );
                }

                showAddress();








                document.getElementById("spLoading").style.display = 'none';

        
                                
                             ///////
                              }
                             }
                             });
    
    

            }
       





///////// show default map if no record found

    ///////// show default map if no record found
    function defaultMap()
    {
        var contentDiv = document.getElementById('content');
        contentDiv.innerHTML = '';
        var mapContainer = document.createElement('div'); // build the map div
        mapContainer.style.height = '420px'; // set the map height
        mapContainer.style.width = '460px'; // set the map width
        contentDiv.appendChild(mapContainer);
        // We're ready to build our map...
        map = new google.maps.Map2(mapContainer);
        //Scroll wheel zoom...
        map.enableScrollWheelZoom();
        // ...and add a couple of controls.
        map.addControl(new google.maps.SmallMapControl()); // Add a small map control
        var defaultIcon = new GIcon();
        defaultIcon.image = "images/icon/darden/star.png"; //--------------Willie 11/3/09 fixed icon for default location---------------//
        defaultIcon.iconSize = new GSize(24, 37);
        defaultIcon.shadow = "images/icon/shadow2.png";
        defaultIcon.shadowSize = new GSize(43, 37);
        defaultIcon.iconAnchor = new GPoint(12, 37);
        var default_markerLatLng = new google.maps.LatLng(vPoint.y,vPoint.x);
        markerOptions = { icon: defaultIcon };
        var default_marker = new google.maps.Marker(default_markerLatLng,markerOptions)
        map.addOverlay(default_marker);
        var vDistance = 0
        if(srtArray.length > 0)
        {             
            vDistance =  parseInt(srtArray[srtArray.length-1][0]);
           
        }
        var zoomLevel = getMapZoomLevel(vDistance);
        map.setCenter(new google.maps.LatLng(vPoint.y,vPoint.x),zoomLevel );

        ////////// end of default value /////////////////
        document.getElementById("spLoading").style.display='none';   
    }
    
   
////////////////////////////


function getSortedValues()
{

    var contentDiv = document.getElementById('content');
    contentDiv.innerHTML = '';
    var mapContainer = document.createElement('div'); // build the map div
    mapContainer.style.height = '420px'; // set the map height
    mapContainer.style.width = '460px'; // set the map width
    contentDiv.appendChild(mapContainer);
    // We're ready to build our map...
    map = new google.maps.Map2(mapContainer);
    //Scroll wheel zoom...
    map.enableScrollWheelZoom();
    map.addMapType(G_PHYSICAL_MAP);
 
      var mapControl = new GMapTypeControl();
      map.addControl(mapControl);
    // ...and add a couple of controls.
   map.addControl(new google.maps.SmallMapControl()); // Add a small map control
    srtArray.sort(compare);
   
 
    for(var m=0; m<arrayCounter;m++)
    {
    var markerLatLng = new google.maps.LatLng(vPoint.y,vPoint.x)
    if(srtArray.length > 0)
    {
    markerLatLng = new google.maps.LatLng(parseFloat(srtArray[m][2]),
    parseFloat(srtArray[m][3]));
    }   
    var imgName = m + 1;
    if(blnSearchOne)
    {

    MyKeepHandler(srtArray[m][1],imgName,srtArray[m][0],logoIdx,srtArray[m][5],srtArray[m][6],srtArray[m][7],srtArray[m][8],srtArray[m][9],srtArray[m][2],srtArray[m][3],srtArray[m][12],srtArray[m][13])
    }else
    {            
    MyKeepHandler(srtArray[m][1],imgName,srtArray[m][0],srtArray[m][4],srtArray[m][5],srtArray[m][6],srtArray[m][7],srtArray[m][8],srtArray[m][9],srtArray[m][2],srtArray[m][3],srtArray[m][12],srtArray[m][13])
    }
    //-------------Set restaurant specific markerOption - Willie 10/30/2009----------//	
    ////// updated by tahir set infoWindowAnchor , remove default icon - 11/05/09 ////////////
    var blueIcon = new GIcon();
    blueIcon.image = "images/icon/darden/"+imgName+".png";
    blueIcon.iconSize = new GSize(24, 37);
    blueIcon.shadow = "images/icon/shadow2.png";
    blueIcon.shadowSize = new GSize(43, 37);
    blueIcon.iconAnchor = new GPoint(12, 37);
    blueIcon.infoWindowAnchor = new GPoint(18, 6); 

    var longIcon = new GIcon();
    longIcon.image = "images/icon/longhorn/"+imgName+".png";
    longIcon.iconSize = new GSize(24, 37);
    longIcon.shadow = "images/icon/shadow2.png";
    longIcon.shadowSize = new GSize(43, 37);
    longIcon.iconAnchor = new GPoint(12, 37);
    longIcon.infoWindowAnchor = new GPoint(18, 6);

    var oliveIcon = new GIcon();
    oliveIcon.image = "images/icon/olive/"+imgName+".png";
    oliveIcon.iconSize = new GSize(24, 37);
    oliveIcon.shadow = "images/icon/shadow2.png";
    oliveIcon.shadowSize = new GSize(43, 37);
    oliveIcon.iconAnchor = new GPoint(12, 37);
    oliveIcon.infoWindowAnchor = new GPoint(18, 6);

    var redIcon = new GIcon();
    redIcon.image = "images/icon/redlob/"+imgName+".png";
    redIcon.iconSize = new GSize(24, 37);
    redIcon.shadow = "images/icon/shadow2.png";
    redIcon.shadowSize = new GSize(43, 37);
    redIcon.iconAnchor = new GPoint(12, 37);
    redIcon.infoWindowAnchor = new GPoint(18, 6);

    var tcgIcon = new GIcon();
    tcgIcon.image = "images/icon/tcg/"+imgName+".png";
    tcgIcon.iconSize = new GSize(24, 37);
    tcgIcon.shadow = "images/icon/shadow2.png";
    tcgIcon.shadowSize = new GSize(43, 37);
    tcgIcon.iconAnchor = new GPoint(12, 37);
    tcgIcon.infoWindowAnchor = new GPoint(18, 6);

    var seasonIcon = new GIcon();
    seasonIcon.image = "images/icon/season/"+imgName+".png";
    seasonIcon.iconSize = new GSize(24, 37);
    seasonIcon.shadow = "images/icon/shadow2.png";
    seasonIcon.shadowSize = new GSize(43, 37);
    seasonIcon.iconAnchor = new GPoint(12, 37);
    seasonIcon.infoWindowAnchor = new GPoint(18, 6);

    var bahamaIcon = new GIcon();
    bahamaIcon.image = "images/icon/bahamabreeze/"+imgName+".png";
    bahamaIcon.iconSize = new GSize(24, 37);
    bahamaIcon.shadow = "images/icon/shadow2.png";
    bahamaIcon.shadowSize = new GSize(43, 37);
    bahamaIcon.iconAnchor = new GPoint(12, 37);
    bahamaIcon.infoWindowAnchor = new GPoint(18, 6);

    var iconType 
    if(srtArray.length > 0)
    iconType = srtArray[m][5];
    if(iconType.search("LongHorn") >= 0)
    {markerOptions = {icon: longIcon}}
    else if(iconType.search("Olive Garden") >= 0)
    {markerOptions = {icon: oliveIcon}}
    else if(iconType.search("Bahama Breeze") >= 0)
    {markerOptions = {icon: bahamaIcon}}
    else if(iconType.search("Red Lobster") >= 0)
    {markerOptions = {icon: redIcon}}
    else if(iconType.search("Seasons 52") >= 0)
    {markerOptions = {icon: seasonIcon}}
    else if(iconType.search("Capital Grille") >= 0)
    {markerOptions = {icon: tcgIcon}}
    else {markerOptions = {icon: blueIcon}};


   
		
//----------------------------End - Willie 10/30/2009--------------------------//

         
         
 
		 ///////// updated on 03 Nov 09 /////////
		 /////////// add info window on marker ///////
    var marker = new google.maps.Marker(markerLatLng,markerOptions); // Create the marker




    var dvStrMenu =  document.createElement('div');

    var dvDirName = "dir"+imgName;
    var dvDetail = "detail"+imgName;
    var dvSendTo = "sendto"+imgName;
    
    var strAddress = srtArray[m][2]+"_"+srtArray[m][3]; 
    var strTitle = srtArray[m][5];

		            //-------------Willie 11/4/09-------------/////////// set logo on the info window 
        if(strTitle.search("Red Lobster") >= 0)
        {
            LogoName = "Red_Lobster.gif";
        }else if(strTitle.search("Bahama Breeze") >= 0)
        {
          LogoName = "Bahama_Breeze.gif";
        }else if(strTitle.search("Olive Garden") >= 0)
        {
            LogoName = "Olive_Garden.gif";
        }else if(strTitle.search("Capital Grille") >= 0)
        {
          LogoName = "Capital_Grille.gif";
        }else if(strTitle.search("Seasons 52") >= 0)
        {
         LogoName = "Seasosns52.gif";
        }else if(strTitle.search("LongHorn") >= 0)
        {
          LogoName = "Longhorn.gif";
        }
          
          
          ////////////////////////////////
		  
		  
		 if(strTitle.search("Capital Grille") >= 0)
		 {
		 dvStrMenu.innerHTML =  "<div class='gs-localResult gs-result navigators'><span><a class='scrollTo"+imgName+"' onmousedown=\"showDiv('"+ dvDirName + "',"+ imgName + " ); return false;\">Directions</a></span><span> | <a class='scrollTo"+imgName+"' onmousedown=\"showDiv('"+ dvSendTo + "' ,"+ imgName + "); return false;\">Send To</a> </span><img style=\"margin-top:-70px; z-index:0; display:inline-block;\" src=\"images/icon/"+LogoName+"\"></div>";
		 }else 
		 {
         dvStrMenu.innerHTML =  "<div class='gs-localResult gs-result navigators'><span><a class='scrollTo"+imgName+"' onmousedown=\"showDiv('"+ dvDirName + "',"+ imgName + " ); return false;\">Directions</a></span><span> | <a class='scrollTo"+imgName+"' onmousedown=\"showDiv('"+ dvSendTo + "' ,"+ imgName + "); return false;\">Send To</a> </span><span> | <a class='scrollTo"+imgName+"' onmousedown=\"getDetail('"+ srtArray[m][12] + "',"+ imgName + ",'"+ strTitle +"'); return false;\"> Details</a></span><img style=\"margin-top:-70px; z-index:0; display:inline-block;\" src=\"images/icon/"+LogoName+"\"></div>";
         }
		 
    var dvMarkerInfo = srtArray[m][10];

    dvMarkerInfo.appendChild(dvStrMenu)

    marker.bindInfoWindow(dvMarkerInfo);

    ////////////////// Scroll to result on marker click ////////////////////

    GEvent.addListener(marker, "infowindowopen", function(){
    										   
    var num = $(".navigators span:first a").attr("class").replace("scrollTo", "");
    
    var api = $("div.locations_holder").scrollable({vertical:true, size: 1, clickable: false, keyboard: true, api:true});
    api.seekTo(num-1);

    // Rename the Incorrect gs-titles
    var titles = $("a.gs-title b").html();
    
    if (titles == "LongHorn"){$("a.gs-title b").html("LongHorn Steakhouse");}
    if (titles == "Red Lobster"){$("a.gs-title b").html("Red Lobster");}
    if (titles == "Bahama Breeze"){$("a.gs-title b").html("Bahama Breeze");}

    });	
			 
////////////////// end Scroll to result on marker click ////////////////////
		 ////////////// end add info window on marker
           // bind the marker to the result
    map.addOverlay(marker);


        if(m == 0)
        {
        var objAdd1 = document.getElementById("hdnAddress1");
        objAdd1.appendChild(srtArray[m][10])
        }                                         
 
		
       
       } /// end of for
     
         ///////// updated on 03 Nov 09 ///////// 
         ////// add default marker for txtsearch value -- set center the default location ////////
    var defaultIcon = new GIcon();
    defaultIcon.image = "images/icon/darden/star.png"; //--------------Willie 11/3/09 fixed icon for default location---------------//
    defaultIcon.iconSize = new GSize(24, 37);
    defaultIcon.shadow = "images/icon/shadow2.png";
    defaultIcon.shadowSize = new GSize(43, 37);
    defaultIcon.iconAnchor = new GPoint(12, 37);
    var default_markerLatLng = new google.maps.LatLng(vPoint.y,vPoint.x);
    markerOptions = { icon: defaultIcon };
    var default_marker = new google.maps.Marker(default_markerLatLng,markerOptions)
   
    map.addOverlay(default_marker);
    var vDistance = 0
   
    if(srtArray.length > 0)
    {
        vDistance =  parseInt(srtArray[srtArray.length-1][0]);
       
    }
    var zoomLevel = getMapZoomLevel(vDistance);
    map.setCenter(new google.maps.LatLng(vPoint.y,vPoint.x),zoomLevel );

    ////////// end of default value /////////////////
    document.getElementById("spLoading").style.display='none';                                     
 
}


//////////////


function loopDelay(numberMillis) { 
    var now = new Date(); 
    var exitTime = now.getTime() + numberMillis; 
    while (true) { 
    now = new Date(); 
    if (now.getTime() > exitTime) 
    return; 
    } 
} 

function showd()
{
alert("hi")
}

    var flag;
    flag=0;

  function showDiv(obj,vCounter)
  {

	
	$(".navigators a").livequery("click", function(){
	var api = $("div.locations_holder").scrollable({vertical:true, size: 1, clickable: false, keyboard: true, api:true});
	var tclass = $(this).attr("class");
	var num = tclass.replace("scrollTo", "");
		api.seekTo(num-1);
	});

 
    var sendto = document.getElementById("sendto"+vCounter);
    var dir = document.getElementById("dir"+vCounter);
    var detail = document.getElementById("detail"+vCounter);
    var obj1  = document.getElementById(obj)
 
    if(obj1!=null)   {
    
        if(obj1.style.display == 'none' || obj1.style.display == '')
        {

        if(obj.indexOf("sendto")!=-1)
        {


        $(dir).slideUp();
        $(obj1).parents(".location").find("li.directions").removeClass("selected");
        $(detail).slideUp();
        $(obj1).parents(".location").find("li.details").removeClass("selected");
        $(obj1).slideDown();
        $(obj1).parents(".location").find("li.sendto").addClass("selected"); //.css("background-color", "#faf5ee").css("border", "1px solid black").css("border-bottom", "0");
        }
        else if(obj.indexOf("dir")!=-1)
        {
        $(sendto).slideUp();
        $(obj1).parents(".location").find("li.sendto").removeClass("selected");
        $(detail).slideUp();
        $(obj1).parents(".location").find("li.details").removeClass("selected");
        $(obj1).slideDown();
        $(obj1).parents(".location").find("li.directions").addClass("selected");
		}
       else if(obj.indexOf("detail")!=-1)
       {

        $(dir).slideUp();
        $(obj1).parents(".location").find("li.directions").removeClass("selected");
        $(sendto).slideUp();
        $(obj1).parents(".location").find("li.sendto").removeClass("selected");
        $(obj1).slideDown();
        $(obj1).parents(".location").find("li.details").addClass("selected");
        
        }
         }
         else
         {
          
		  $(obj1).slideUp();
		  $(obj1).parents(".location").find("li.directions, li.sendto, li.details").removeClass("selected");
		  
         
         }
    }
    else
    {
   
        if(obj.style.display == 'none' || obj.style.display == '')
        {

        $(dir).slideUp();
        $(obj).parents(".location").find("li.directions").removeClass("selected");
       
        $(sendto).slideUp();
        $(obj).parents(".location").find("li.sendto").removeClass("selected");
       
        $(obj).slideDown();
        $(obj).parents(".location").find("li.details").addClass("selected");
       
     }
     else
         {
		$(obj).slideUp();
        $(dir).slideUp();
		$(sendto).slideUp();
		$(obj).parents(".location").find("li.details, li.directions, li.sendto").removeClass("selected");
		 
         }
    }
    
    
  }


function getDirection(vCounter,toAddress)
{
	if(isMeanAddress==true)
    {
        var mAdd=document.getElementById("hdnMeanAdd"+vCounter);
        if(mAdd!=null)
        {
            mAdd.value=toAddress;
        }
    }
    isMeanAddress=false;
    isRevDirection=false;
     lCounter=vCounter;
    var ddName = document.getElementById("ddName"+vCounter);
    var txtSearchTo = document.getElementById("txtSearchToName"+vCounter);
    var objToHere = document.getElementById("tohere"+vCounter);
    var objFromHere = document.getElementById("fromhere"+vCounter);
    objToHere.className = "direction_selected";
    objFromHere.className = "direction_unselected";
    var opt = ddName.selectedIndex;
    var vFrom = txtSearchTo.value;
    vTo = toAddress
    var dVtarget = "route"+vCounter;
    if (vFrom == "Enter Location Here" || vFrom == ""){
	   alert("Please enter a location.");}
    else{
						 
    getPath(vFrom,toAddress,opt,dVtarget);
   }
}



function getRevDirection(vCounter,toAddress)
{
    
    var ddName = document.getElementById("ddName"+vCounter);
    var txtSearchTo = document.getElementById("txtSearchToName"+vCounter);
    var opt = ddName.selectedIndex;
    var vFrom =""; //txtSearchTo.value;
    var vTo = "";
    isRevDirection = true;
    if(isMeanAddress==true)
    {
        vFrom = revFromAddress;
         var mAdd=document.getElementById("hdnMeanAdd"+vCounter);
        if(mAdd!=null)
        {
          if(mAdd.value != "")
          {
          vFrom = mAdd.value;
          }else
          {
          alert("Unable to find direction , please try \"To here\" direction and then try \"From here\" direction");
          return;   
          }
        }
     vTo = toAddress; 
    }else
    {
     vFrom = toAddress; //txtSearchTo.value;
     vTo = txtSearchTo.value;
     revFromAddress = toAddress;
    }
    var dVtarget = "route"+vCounter;

     var objToHere = document.getElementById("tohere"+vCounter);
    var objFromHere = document.getElementById("fromhere"+vCounter);
    objToHere.className = "direction_unselected";
    
    objFromHere.className = "direction_selected";

    if (vTo == "Enter Location Here" || vTo == ""){
    alert("Please enter a location.");}
    else{   


    getPath(vFrom,vTo,opt,dVtarget);
   }
}
//////////// function get detail////////
function getDetail(Rest_id,vCounter,vTitle)
{
	
	
        $(".navigators a").livequery("click", function(){
        var api = $("div.locations_holder").scrollable({vertical:true, size: 1, clickable: false, keyboard: true, api:true});
        var tclass = $(this).attr("class");
        var num = tclass.replace("scrollTo", "");
        api.seekTo(num-1);
      
        });	

        var rstName = "";
        var colName = "";
        var target = document.getElementById("detail"+vCounter)

        if(vTitle.search("Red Lobster") >= 0)
        {
        rstName = "redlob";
        colName = "Latitude_Longitude";
        }else if(vTitle.search("Bahama Breeze") >= 0)
        {
        rstName = "bahamabreeze";
        colName = "Latitude_Longitude";
        }else if(vTitle.search("Olive Garden") >= 0)
        {
        rstName = "Olive";
        colName = "Latitude_Longitude";
        }else if(vTitle.search("Capital Grille") >= 0)
        {
        rstName = "TCG";
        colName = "Lat_Long";
        }else if(vTitle.search("Seasons 52") >= 0)
        {
        rstName = "season"; 
        colName = "Latitude_Longitude";
        }else if(vTitle.search("LongHorn") >= 0)
        {
        colName = "Latitude_Longitude";
        rstName = "LongHorn";  
        colName = "Address1";
        }
        
        $.ajaxSetup ({   
        cache: false  
        });   
        var ajax_load = "<img src=\"Images/loading.gif\" alt=\"loading...\" />";   
        var dvname = "detail"+vCounter;
        
       
         var param = "search="+Rest_id+"&dvname="+dvname+"&rest_name="+rstName;

    var loadUrl = "updatecode.aspx?";


    $(target).html(ajax_load).load(loadUrl, param,
                function(responseText) {
                    target.innerHTML = responseText;
                    showDiv(target, vCounter);
                    //alert(responseText);   
                });

    

}

////////////////////////send email
function sendEmail(vCounter, vAddress, vRestId, vTitle)
{
// updated on 06 july ,2010

     var objEmailAddress = document.getElementById("txtSendTo" + vCounter)
     var objDir = document.getElementById("route"+vCounter);
     var option = document.getElementById("select" + vCounter)
    
     var tableName = "";
    var colName = "";
    
     /////////// get table name of restaurant //////////
    if (vTitle.search("Red Lobster") >= 0) {
        tableName = "redlob";
        colName = "Latitude_Longitude";
    } else if (vTitle.search("Bahama Breeze") >= 0) {
    tableName = "bahamabreeze";
        colName = "Latitude_Longitude";
    } else if (vTitle.search("Olive Garden") >= 0) {
    tableName = "Olive";
        colName = "Latitude_Longitude";
    } else if (vTitle.search("Capital Grille") >= 0) {
    tableName = "TCG";
        colName = "Lat_Long";
    } else if (vTitle.search("Seasons 52") >= 0) {
    tableName = "season";
        colName = "Latitude_Longitude";
    } else if (vTitle.search("LongHorn") >= 0) {
        
        tableName = "LongHorn";
        colName = "Address1";
    }
    //////////////////////////
    var searchFrom = "";   
 if(option.value == "0")
    {
/*   
             if(objDir.innerHTML.length < 1)
               {
                alert("Please search for Directions on the \"Directions\" Tab.");
                return false;
               }else
               {*/
               var objDirectionFrom = document.getElementById("txtSearchToName" + vCounter);
               searchFrom = objDirectionFrom.value;
     //          }  
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = objEmailAddress.value;
    if (reg.test(address) == false) {
        alert('Invalid Email Address');
        return false;
    }
//    if(searchFrom =="")
//                {
//                alert("Direction text box is empty");
//                var objDir = "dir"+vCounter
//                showDiv(objDir,1 )
//                return;
//                }
                
                
   var toAdd;
   var maddvalue;
   toAdd=document.getElementById("hdnMeanAdd"+vCounter)
   if(toAdd!=null)
   {
       if(toAdd.value!="")
       {
       maddvalue=toAdd.value;
       }
   }
  //  var param = "sendEmail=" + objEmailAddress.value + "&LatLng=" + vLatLng + "&tableName=" + tableName + "&SearchText=" + searchtext //+ "&direction=" + directionsLink;
  var param = "sendEmail=" + objEmailAddress.value + "&RestId=" + vRestId  + "&tableName=" + tableName + "&SearchText="+searchFrom+"&meanadd="+maddvalue //+ "&direction=" + directionsLink;
 // alert(param)
    $.ajaxSetup({
        cache: false
    });


    $.ajax({
        type: "GET",
        url: "updatecode.aspx",
        data: param,
        error: function() {
            alert('Unable to send email , please try again later');
        },
        success: function(d) {

            alert(d)

        }

    });
   }if(option.value == "1")
   {
       var regexObj = /^[\+]?([0-9]?)[\(|\s|\-|\.]?([0-9]{3})[\)|\s|\-|\.]*([0-9]{3})[\s|\-|\.]*([0-9]{4})$/;

       var objDirectionFrom = document.getElementById("txtSearchToName" + vCounter);
       searchFrom = objDirectionFrom.value;
       if (isNaN(objEmailAddress.value) || (objEmailAddress.value == "")) {
           if (!regexObj.test(objEmailAddress.value)) {           
               alert('Please enter a valid phone number');
               return;

           }
           else {
           }
       }

     // var param = "sms=" + objEmailAddress.value + "&LatLng=" + vLatLng + "&tableName=" + tableName + "&SearchText="+searchtext //+ "&direction=" + directionsLink;
      var param = "sms=" + objEmailAddress.value + "&RestId=" +  vRestId  + "&tableName=" + tableName + "&SearchText="+searchtext //+ "&direction=" + directionsLink;
    
      $.ajaxSetup({
          cache: false
      }); 
    
    
          $.ajax({ 
        type: "GET", 
        url: "updatecode.aspx", 
        data: param , 
        success: function(d) { 
           
        alert(d)
                      
        } 
                      
        });  
   
     }
    
}



function stripHtml(s) {
    return s.replace(/\\&/g, '&amp;').replace(/\\</g, '&lt;').replace(/\\>/g, '&gt;').replace(/\\t/g, '&nbsp;&nbsp;&nbsp;').replace(/\\n/g, '<br />');
	}

function compare(a, b)
{

  return a[0] - b[0];
}



//////// close div
function closeDiv(obj)
{
 obj.style.display = 'none';
}

/////// check enter press
function checkEnter(e)
{

    if(e.keyCode == 13)
    {
        alert(e.keyCode)
        OnLoad();
    }
}


 function clearFld(obj)
 {
 var objText = document.getElementById(obj) 
 objText.value="";
 }
	
function getCenter(lat,lng)
{
  
    map.setCenter(new google.maps.LatLng(lat,lng), 11);
}


/////////// print //////
function print(intCounter)
{

        var printContent = document.getElementById("content").innerHTML
       // var locationContent = document.getElementById("locations").innerHTML
       var ActiveDiv = document.getElementById("location"+intCounter);
        var locationContent = ActiveDiv.innerHTML;
        var windowUrl = 'about:blank';
        var uniqueName = new Date();
        var windowName = 'Print' + uniqueName.getTime();

        var strHeadingText = "<br><b><i><p style=\"padding-left:30px \">Search Result in " + searchtext + "<br>";
        if(selectedResName.length > 0)
        {
        strHeadingText += " ,For Restaurant <u>" + selectedResName + "</u>"; 
        }
        if(parseInt(search_distance) > 0)
        {
        strHeadingText += " ,Distance within  <u>" + search_distance + " Miles</u>"; 
        }
        if(searchDining)
        {
        strHeadingText += " ,with <u>Group Dining</u> "; 
        }
        if(searchSeating)
        {
        strHeadingText += " ,with <u>Call-Ahead Seating</u> "; 
        }
        if(searchReservation)
        {
        strHeadingText += " ,with <u>Online Reservations</u> "; 
        }


        strHeadingText += "</i></b><br><br><br>";

        var printWindow = window.open(windowUrl, windowName);// 'left=50,top=50,width=800,height=800,scrollbar=yes;');
        var strheading = "<img src=\"wrapper/images/core/logo_darden.gif\">";
        var strHTML = "<html><head><title>Restaurant Locator : Print Preview</title><script src=\"common/js/darden_print.js\" type=\"text/javascript\"></script>";

        strHTML += "<link href=\"common/css/locator1.css\" rel=\"stylesheet\" type=\"text/css\" />";
        strHTML += "</head><body onload=\"hideForPrint();\"> ";
        strHTML += strheading + strHeadingText

        strHTML += "";
        strHTML += "<div id=\"scroll_block\"  style='float:none;'> <div class=\"locations_holder_print\" style='min-height:0px;'>";
        strHTML += "<div id=\"locations\" class=\"locations\">";
        //strHTML += strheading +  "<div id=\"content\" class=\"google_map c1\">" + printContent + "<div>" + locationContent  ;
        strHTML += locationContent;
        strHTML += "</div></div></div>";
        strHTML += " <div id=\"map\" style='float:none;'>";
        strHTML += "<div id=\"content\" class=\"google_map c1\">" + printContent + "</div>"
        strHTML += "</div>"
        strHTML += ""
        strHTML += " </body></html>";

        printWindow.document.write(strHTML);
        printWindow.document.close();
        printWindow.focus();
       
}

function show()
{
    var objDiv = document.getElementsByTagName('div');

    for(var h=0; h < objDiv.length; h++)
    {
    if(objDiv[h].className == "info" || objDiv[h].className == "panels")
    {

    objDiv[h].style.display="none";
    }

    }

    var objDiv = document.getElementsByTagName('img');

    for(var h=0; h < objDiv.length; h++)
    {
    if(objDiv[h].className == "photo" )
    {

    objDiv[h].style.display="none";
    }

    }
}

/// set scroll bar height
function setScrollBarHeight()
{
    var dvScroll = document.getElementById("location1");
    dvScroll.focus();

}

function sendEmailMap()
{
    
}
function openEmailForm()
{
    var objDiv = document.getElementsByTagName('A');

    for(var h=0; h < objDiv.length; h++)
    {
    if(objDiv[h].className == "gs-directions")
    {
    var aurl = objDiv[h];
    var url = "sendEmailForm.aspx?url="+ aurl;
    window.open(url,"mywindow","top=200,left=200,width=600,height=350,resizable=no,scrollbars=no,toolbar=no,location=mo,status=no,menubar=no");
    break;
    }
    }

}

function showMailForm(objHide,objShow)
{

     var objH = document.getElementById(objHide);
     var objS = document.getElementById(objShow);
     objH.className = "hiddiv";
     objS.className="showdiv";
     
}


function requiredEmail(source, arguments)
{

        var status = true;
        var i = 0;
        var emails = document.getElementById("txtto").value.split(",");
        for(i=0; i<emails.length; i++){
        if(!validate(trim(emails[i]))){	

        status = false;
        break;
        }
        }
        if(document.getElementById("txtto").value.length<1)
        {

        source.innerHTML="Required field";
        }
        else
        {
        source.innerHTML="Invalid email address";
        }

        if(status == true){
        arguments.IsValid = true;}

        if(status == false){
        arguments.IsValid = false;}
}
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email);
}

function trim(str){
    var	str = str.replace(/^\s\s*/,''),
    ws = /\s/,
    i = str.length;
    while (ws.test(str.charAt(--i)));
    return str.slice(0, i + 1);
}

//////////// function get map zoom level

function getMapZoomLevel(vDistance)
{
        var zoomLevel = 0;
         if(vDistance >= 0 && vDistance <= 10)
         {
          zoomLevel = 12;
         }
        else if(vDistance >= 10 && vDistance <= 20)
        {
        zoomLevel = 11;
        }else if(vDistance >= 20 && vDistance <= 30)
        {

        zoomLevel = 10;
        }else if(vDistance >= 30 && vDistance <= 40)
        {
        zoomLevel = 9;
        }else if(vDistance >= 40 && vDistance <= 50)
        {
        zoomLevel = 8
        }else if(vDistance >= 50 && vDistance <= 60)
        {
        zoomLevel = 7;
        }else
        zoomLevel = 6;

        return zoomLevel;
}


///// function to clear search preference
 function sPreferenceClear()
 {
        $("#dining").attr("checked", false);
        $("#seating").attr("checked", false);
        $("#reservations").attr("checked", false);
        $("#ddDistance").attr("selectedIndex",0);
        blnsearchdb = false;
        searchSeating = false;
        bln_season_tgc = false;
        sPreference();
}


//////////// funcion getMenuLink
////// by tahir 27 March 2010

function getMenuLink(link, vAddress, vTitle)
 {
 
     if (vTitle.search("Red Lobster") >= 0) {
         rstName = "redlob";
         colName = "Latitude_Longitude";
     } else if (vTitle.search("Bahama Breeze") >= 0) {
         rstName = "bahamabreeze";
         colName = "Latitude_Longitude";
     } else if (vTitle.search("Olive Garden") >= 0) {
         rstName = "Olive";
         colName = "Latitude_Longitude";
     } else if (vTitle.search("Capital Grille") >= 0) {
         rstName = "TCG";
         colName = "Lat_Long";
     } else if (vTitle.search("Seasons 52") >= 0) {
         rstName = "season";
         colName = "Latitude_Longitude";
     } else if (vTitle.search("LongHorn") >= 0) {
         colName = "Latitude_Longitude";
         rstName = "LongHorn";
         colName = "Address1";
     }
     
     $.ajaxSetup({
         cache: false
     });
     var ajax_load = "<img src=\"Images/loading.gif\" alt=\"loading...\" />";
 
     var param = "rest_id=true&search=" + vAddress + "&rest_name=" + rstName;
   

     $.ajax({
         type: "GET",
         url: "updatecode.aspx",
         data: param,
         success: function(responseText) {
            
            if (vTitle.search("Bahama Breeze") >= 0) {
             var newURL = link + responseText + ".pdf"
            } else {
             var newURL = link + responseText;
            }
            
            window.open(newURL);
           
         }
     });


 
}

function replaceAll(text, strA, strB) {
    while (text.indexOf(strA) != -1) {
        text = text.replace(strA, strB);
    }
    return text;
}

////// updated by tahir - july 06,2010
/// change value of text box -- if send to phone or sent to mail option selected
function changeSendToValue(objSelect,objTextBox)
{
//alert(objTextBox)
objTextBox = document.getElementById(objTextBox);
var objSelect = document.getElementById(objSelect);
if(objSelect.value == "1")
{
objTextBox.value = "Enter recipient's phone number";
}else if(objSelect.value == "Send To Printer")
{
ddPrint(objSelect);
}else
{
objTextBox.value = "Enter recipient's email address";
}

//alert(objTextBox.value + ":" + objSelect.value);
}

function errorMessage()
{

    var nfHTML = "";
        nfHTML = "<div id='notfound' style='width:240px; margin:120px auto 0; text-align:center;'>";
        nfHTML += "<h1 style='font:bold 30px Arial, Helvetica, sans-serif; color:#8b1106; margin-bottom: 5px;'>NOT FOUND</h1>";
        nfHTML += "<p style='font: bold 16px Arial, Helvetica, sans-serif; color:#000; line-height: 1.5em; margin-top: 0;'>Sorry, there are no Darden<sub style='font-size:11px;'>SM</sub> Restaurants in the <span style='color:#8b1106; font-style: italic;'>"+decodeURI(searchtext)+"</span> area. Would you like to try a different location?</p>";
        nfHTML += "<input type='button' id='tryagain' style='font: bold 14px Arial, Helvetica, sans-serif; color:#fff; background: #8b1106 url(common/images/try-again-btn.gif) no-repeat center top; border:none; width: 104px; height: 30px; overflow: hidden; cursor:pointer;' value='TRY AGAIN' /></div>";

        $("div#locations").html(nfHTML);
}
function ddPrint(objdd)
{

var intCounter = $(objdd).attr("id").match(/\d+$/);
var selectedVal = $(objdd).val();
	
	if(selectedVal == "Send To Printer"){
	$(objdd).parents("div.drop_down").find(".send_bar .send_input input").attr("disabled", "disabled").val("Click \"SEND\" For Printable Directions");
	$(objdd).parents("div.drop_down").find(".send_bar .send_btn input").removeAttr("onclick").bind("click", function(){
								
    var inputAddress = $(objdd).parents(".drop_down_container").find(".directions div.googledir").find("td[jscontent='address']:first").html();
    
    var restAddress = $(objdd).parents(".drop_down_container").find(".directions div.googledir").find("td[jscontent='address']:last").html();
    
    var directionsLink = "http://maps.google.com/maps?hl=en&saddr="+inputAddress+"&daddr="+restAddress+"&dirflg=&ie=UTF8&z=11&layer=c&pw=2";
    var walkingLink = "http://maps.google.com/maps?f=d&source=s_d&saddr="+inputAddress+"&daddr="+restAddress+"&hl=en&mra=ls&dirflg=w&ie=UTF8&z=12&layer=c&pw=2";
    if($(objdd).parents(".drop_down_container").find(".directions div.googledir").length == 0){
    //alert("Please search for directions on the \"Directions\" tab.");
    print(intCounter);
    }
    else{
    if($(objdd).parents(".drop_down_container").find(".directions div.googledir div[jsdisplay='walking']").css("display") != "none"){
    window.open(walkingLink);
    }
    else{
    window.open(directionsLink);
    }
    }
		}); 
	} else if (selectedVal == "Send To Email"){
		
	$(objdd).parents("div.drop_down").find(".send_bar .send_input input").removeAttr("disabled").val("Enter recipient's email address");
	$(objdd).parents("div.drop_down").find(".send_bar .send_btn").html("<INPUT value=\"SEND\" onclick=\"sendEmail("+ imgName +",'"+ nToAddress +"')\" type=\"button\">");
		
		}
		

}


/// get query string value //// updated on 28 july ,2010

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
}
