﻿// JScript File

//***********************************************************************************************
//  Local Variables
//***********************************************************************************************
//Id:                     Text:
//zd_h3Find               Find [Destination Value]
//zd_lDestinationName     Name of [Destination Value]
//zd_aFind                Find [Destination Value]
//zd_aReserve             
var destinationTypeToggleHandlerArray = null;
var vSelectAmenitiesTabIndex = null;
var vSelectSearchTabIndex = null;

destinationTypeToggleHandlerArray = new Array(4) 
destinationTypeToggleHandlerArray[0] = new Array("zd_h3Find", "Find [Destination Value]");
destinationTypeToggleHandlerArray[1] = new Array("zd_lDestinationName", "Name of [Destination Value]");
destinationTypeToggleHandlerArray[2] = new Array("zd_aFind", "Find [Destination Value]");
destinationTypeToggleHandlerArray[3] = new Array("zd_aReserve", "Reserve [Destination Value]");

var vConstAddressPrompt = "type address or landmark here";
var vConstDestinationNamePrompt = "type destination name here";

function GetDestinationTypes(vDestinationTypeId, vAliasNameType)
{            
    var vColumnIndex = -1;
    if (vAliasNameType == 'VCSC_SEARCH_TYPE_ALIAS')
    {
        vColumnIndex = 1;
    } else
    if (vAliasNameType == 'VCSC_TAB_BROWSE_ALIAS')
    {
        vColumnIndex = 2;
    } else
    if (vAliasNameType == 'VCSC_TAB_RESERVE_ALIAS')
    {
        vColumnIndex = 3;
    } else
    if (vAliasNameType == 'VCSC_URL_BROWSE_ALIAS')
    {
        vColumnIndex = 4;
    } else
    if (vAliasNameType == 'VCSC_URL_RESERVE_ALIAS')
    {
        vColumnIndex = 5;
    } else
    if (vAliasNameType == 'VCSC_HAVE_TAVE_RESERVE')
    {
        vColumnIndex = 6;
    }
    
    var vAliasName = null;
    if (vColumnIndex == -1) return vAliasName;
    $("#divDestinationTypes tr").each(function(idx)
    {
        var vObj = $("td:eq(0)", $(this));
        if (vObj.text() == vDestinationTypeId)
        {
            vAliasName = $("td:eq(" + vColumnIndex + ")", $(this)).text()               
            return false;                   
        }
    });
    return vAliasName;
}

//***********************************************************************************************
//  Method used to get index of tabs
//***********************************************************************************************
function GetSelectAmenitiesTabIndex()
{
    try {
        if (vSelectAmenitiesTabIndex != null && vSelectAmenitiesTabIndex > 0)
        {
            return "&optiontab=" + vSelectAmenitiesTabIndex;
        }
    } catch (ex) {
        alert('GetSelectAmenitiesTabIndex :' + ex.message);
    }
    return "";
}

//***********************************************************************************************
//  Method used to get index of menus
//***********************************************************************************************
function SelectSearchTabIndex()
{
    try {
        if (vSelectSearchTabIndex != null && vSelectSearchTabIndex > 0)
        {
            return "&searchtab=" + vSelectSearchTabIndex;
        }
    } catch (ex) {
        alert('SelectSearchTabIndex :' + ex.message);
    }
    return "";
}


//***********************************************************************************************
//  Method used to set default value of search page
//***********************************************************************************************
function SelectDefaultStatus()
{
    try {
        
        // Select the view type
        var vViewType  = zm_sDestinationsEnum.ViewType;
        $("input.SearchResultsDisplayType").filter("[value='" + vViewType + "']").attr("checked", "checked");
        
        var vAddress = $(":asp('zd_tbDestinationAddress')").val();
        var vParkName = $(":asp('zd_tbDestinationName')").val();        
        if(vAddress != '' && vAddress != vConstAddressPrompt)
        {
            SetPageLoadSearchBy('zd_rDestinationAddress');
        } else
        if(vParkName != '' && vParkName != vConstDestinationNamePrompt)
        {
            SetPageLoadSearchBy('zd_rDestinationName');
        } else {
            SetPageLoadSearchBy('zd_rState');
        }
        
        var amenities = $(":asp('txtAmenitiesMembersId')").val();
        var affiliations = $(":asp('txtAmenitiesAffiliationsId')").val();
        if (amenities != '' || affiliations != '')
        {
            var vObj = $("p.trigger"); 
            if (vObj != null) vObj.click();
             
            // Select the default tab
            SelectDefaultOptionTab();
                     
            //Step  -   If id="zd_SCContainerMain" is visible, then get the SCAmenities and SCAffiliations
            $("div#zd_SCContainerMain").filter(":visible").eq(0).each(function()
            {   
                    if (amenities != '')
                    {
                        var vAmenitiesArray = amenities.split(',');
                        var vLength = vAmenitiesArray.length;
		                for( var i = 0; i < vLength; i++ )
		                {
			                $("input.SCAmenities").filter("[vam_id='" + vAmenitiesArray[i] +"']").attr("checked", "checked");
		                }        		    
		            }		
            		
		            if (affiliations != '')
		            {
		                var vAffiliationsArray = affiliations.split(',');
                        vLength = vAffiliationsArray.length;
		                for( var i = 0; i < vLength; i++ )
		                {
			                $("input.SCAffiliations").filter("[vaf_id='" + vAffiliationsArray[i] +"']").attr("checked", "checked");
		                }	
            		    
		            }
            });
        }
        
        // Select the default tab object
        SelectDefaultMenuTab();
        
        // Set the search button status
        SetSearchButtonStatus(false);
    } catch (ex) {
        AlertMsg('Search.method.js', 'SelectDefaultStatus', ex.message);
    }
}

function SetSearchButtonStatus(vDisabled)
{
    var vSearch = $("button#zd_bSearch");
    if (vDisabled)
    {
        vSearch.attr("disabled","disabled");
    } else {
        vSearch.attr("disabled","");
    }
}

// Select default main menu tab
function SelectDefaultMenuTab()
{
    try {
        var vObj = $("li.MenuLinkHandler").filter("[value='" + zm_sDestinationsEnum.SearchTab + "']");
        if (vObj != null) 
        {
            ToggleSelectedMenuItem(vObj);
        } else {
            ToggleSelectedMenuItem($("li#zd_liFind"));
        }    
        return;
    } catch (ex) {
        alert('SelectDefaultMenuTab :' + ex.message);
    }
    ToggleSelectedMenuItem($("li#zd_liFind"));
}

//***********************************************************************************************
//  Method used to prevent early form submission via the enter key
//***********************************************************************************************
function SetPageLoadPreventEnterKey()
{
    var inputs = $('input.PreventEnterKeySubmit');   
    inputs.each(inputs, function(el,i) 
    {   
        el.addEvent('keypress', function(e) {   
            if(e.key == 'enter') 
            {
                e.stop()               
                if(inputs[i+1]) 
                { 
                    inputs[i+1].focus(); 
                }   
                
                //last one?   
                if(i == inputs.length-1) 
                { 
                    $('input.PreventEnterKeySubmit').focus(); 
                }   
            }   
        });   
    });
}

function GetSelectedAmenities()
{
    var vTempQueryString = null;
    var vAmenities = "";
    var vAffiliations = "";

    //Step  -   If id="zd_SCContainerMain" is visible, then get the SCAmenities and SCAffiliations
    $(":asp('zd_SCContainerMain')").filter(":visible").eq(0).each(function() 
    {
        $("input.SCAmenities").filter(':checked').each(function() {
            if(vAmenities == "")
            {
                vAmenities = vAmenities + $(this).attr("vam_id");
            } else {
                vAmenities = vAmenities + "," + $(this).attr("vam_id");
            }
        });
        
        $("input.SCAffiliations").filter(':checked').each(function() {
            if(vAffiliations == "")
            {
                vAffiliations = vAffiliations + $(this).attr("vaf_id");
            }
            else
            {
                vAffiliations = vAffiliations + "," + $(this).attr("vaf_id");
            }
        });
    });
    return {VAM:vAmenities,VAF:vAffiliations};
}

function SelectedAmenitiesParameters(vObj)
{
    var vTempQueryString = null;
    if (vObj.VAM == "" && vObj.VAF == "") {            
    } else {
        if(vObj.VAM  != "")
        {
            vTempQueryString = "VAM=" + vObj.VAM  + "/";
        } else {
            vTempQueryString = "VAM=empty/";
        }
        
        if(vObj.VAF != "")
        {
            vTempQueryString += "VAF=" + vObj.VAF + "/";
        } else {
             vTempQueryString += "VAF=empty/";
        }
    }
    return vTempQueryString;
}

//***********************************************************************************************
//  Method used to display error messages
//***********************************************************************************************
function DisplayErrorMessage(message, vWidth, vHeight)
{
    var vMessage = "<div style=\"text-align: left;width:100%; bolder:solid 1px red; pading-left:30px;\">"
    vMessage += "<br><br>"
    vMessage += "<font color=\"black\"><b>" + message + "<br></b></font>";
    vMessage += "</div>";
    
    vMessage += "<br><br><br>"
    vMessage += "<div style=\"float:left;text-align: center;display:inline; width:100%;\">";
    vMessage += "    <button type=\"button\" onclick=\"javascript:$.nyroModalRemove()\" style=\"width:90px;\">";
    vMessage += "        OK";
    vMessage += "    </button>";
    vMessage += "</div>";
    
    if (typeof(vWidth) == 'undefined')  vWidth = 400;
    if (typeof(vHeight) == 'height') vHeight = 300;
    
    $.nyroModalManual({
        content: vMessage,
        minWidth :vWidth,
        minHeight: vHeight
    });
    return;
}


//***********************************************************************************************
//  Method used by the jquery date pickers to restrict invalid dates from previous selection
//***********************************************************************************************
function SetAssociatedSearchDate(input) 
{ 
    //alert($(":asp('zd_tbSearchStartDate')").datepicker("getDate"));
    return {minDate: (input.id == $(":asp('zd_tbSearchEndDate')").attr("id") ? $(":asp('zd_tbSearchStartDate')").datepicker("getDate") : null), 
        maxDate: (input.id == $(":asp('zd_tbSearchStartDate')").attr("id") ? $(":asp('zd_tbSearchEndDate')").datepicker("getDate") : null)}; 
}

//***********************************************************************************************
//  Method to show divs that were hidden on load so that they don't show before sections are collapsed
//***********************************************************************************************
function SetPageLoadShowDivs()
{
    //maskWindow(true);
    $("div.form-group").show();
    $("div#zd_SCContainerMain").show();
    $("div#sw-wrapper").show();    
    //maskWindow(false);
}

//***********************************************************************************************
//  Set Default value of the Search by section to be set to State
//***********************************************************************************************
function SetPageLoadSearchBy(vRadioId)
{    
    $('div.left-form input[type=radio]').not(':selected').next().next().hide().find('input').attr('disabled', 'disabled');
    $("div.left-form input[id=" + vRadioId + "]").attr("checked", "checked");
    $("div.left-form input[id=" + vRadioId + "]").next().next(':hidden').css('opacity', 0.001).slideDown(175, function(){ $(this).fadeTo(0.9999, 175).find('input:eq(0)').removeAttr("disabled"); });
}

//***********************************************************************************************
//  Call WebMethod to get all of the regions for a the currently selected state
//***********************************************************************************************
function LoadSpaceType(vListObj) 
{
    try {

        var vVPO_ID = vListObj.getAttribute('VPO_ID');
        var vVCUT_ID = vListObj.value;
        // alert('VPO_ID :' + vVPO_ID + ' VCUT_ID :' + vVCUT_ID);
        
        var paramData = "{}";

        var vCurrentObject = this;
        var vURL = LinkPath("WebService.ashx");
        vURL += "?ActionType=1002";
        vURL += "&VPO_ID=" + vVPO_ID;
        vURL += "&VCUT_ID=" + vVCUT_ID;
        // alert(vURL);

        $.ajax({
            type: "POST",
            url: vURL,
            cache: false,
            data: paramData,
            contentType: "application/json; charset=utf-8",
            dataType: "json",

            success: function(listItems) {
                if (listItems != null) {
                    try {
                        //var JSONListItems = JSON.parse(listItems, null);
                        $(":asp('zd_ddlSiteTypes')").fillSelect(listItems);
                    } catch (ex) {
                        AlertMsg('Search.method.js', 'fillSelect', ex.message);
                    }
                } else {
                    $(":asp('zd_ddlSiteTypes')").fillSelect('[]');
                }
            },
            beforeSend: function() {
                maskWindow(true);
            },
            complete: function() {
                maskWindow(false);
            },
            error: function(msg) {
                maskWindow(false);
                alert("Exception : " + msg);
            }
        });
    } catch (ex) {
        AlertMsg('Search.method.js', 'LoadSpaceType', ex.message);
    }
}

//***********************************************************************************************
//  Call WebMethod to get all of the regions for a the currently selected state
//***********************************************************************************************
function LoadCustomerSubTypes(vSelectCustomerTypeId)
{
    try {
        if (vSelectCustomerTypeId == -1)
        {
            vSelectCustomerTypeId = $(":asp('zd_ddlDestinationTypes') :selected").val();
        }
        
        $(":asp('zd_ddlSubDestinationTypes')").clearSelect();
        var paramData = "'intDestinationId':'" + vSelectCustomerTypeId + "'";
        paramData += ",'isURLReWrite':'" + zm_sDestinationsEnum.IsURLReWrite + "'";
        paramData = "{" + paramData + "}";    
        var url = LinkPath("UtilityWebMethods/UtilityWebMethods.aspx/GetSubDestinationTypes"); 
        
        $.ajax({
            type: "POST",
            url: url,
            data: paramData,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            
            success: function(listItems) 
            {
                var JSONListItems = JSON.parse(listItems, null);
                $(":asp('zd_ddlSubDestinationTypes')").fillSelect(JSONListItems);
            },
            beforeSend: function()
            {
                maskWindow(true);
            },
            complete: function()
            {
                maskWindow(false);
            },
            error: function(msg)
            {
                maskWindow(false);
                alert("Error Message: " + msg);
            }
        });
    } catch (ex) {
        AlertMsg('Search.method.js', 'LoadCustomerSubTypes', ex.message);
    }
}

//***********************************************************************************************
//  Call WebMethod to get all of the regions for a the currently selected state
//***********************************************************************************************
function LoadRegions(selectedRegionId)
{
   $(":asp('zd_ddlRegions')").clearSelect();
   
    var selectedState = $(":asp('zd_ddlStates')").attr("value");
    var paramData = "'selectedState':'" + selectedState + "'";
    paramData = "{" + paramData + "}";
    
    var url = LinkPath("UtilityWebMethods/UtilityWebMethods.aspx/GetValidRegionsForState"); 
    
    $.ajax({
        type: "POST",
        url: url,
        data: paramData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        
        success: function(listItems) 
        {
            var JSONListItems = JSON.parse(listItems, null);
            $(":asp('zd_ddlRegions')").fillSelect(JSONListItems);
            if(selectedRegionId != null)
            {            
                $(":asp('zd_ddlRegions')").attr("value", selectedRegionId);
            }
        },
        beforeSend: function()
        {
            maskWindow(true);
        },
        complete: function()
        {
            maskWindow(false);
        },
        error: function(msg)
        {
            maskWindow(false);
            alert("Error Message: " + msg);
        }
    });
}

//***********************************************************************************************
//  Call WebMethod to get 
//***********************************************************************************************
function PerformDisplayUSMapForDiv(forceUSMap)
{
    //Step  -   See if State is already populated
    var selectedIndex = $(":asp('zd_ddlStates')").attr("selectedIndex")
    if((forceUSMap == true) || (selectedIndex == 0))
    {    
        var vcsc_id = $(":asp('zd_ddlDestinationTypes') :selected").attr("value");
        var paramData = "'VCSC_ID':'" + vcsc_id + "'";
        paramData = "{" + paramData + "}";
        
        var url = LinkPath("UtilityWebMethods/UtilityWebMethods.aspx/GetUSMapForDiv");
        
        if($.jqURL.qs() != null)
        {
            url += "?" + $.jqURL.qs();
        }
        
        $.ajax({
            type: "POST",
            url: url,
            data: paramData,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(content) 
            {
                $("div#zd_dSearchMap").html(content);
            },
            beforeSend: function()
            {
                maskWindow(true);
            },
            complete: function()
            {
                maskWindow(false);
            },
            error: function(msg)
            {
                maskWindow(false);
                alert("Error Message: " + msg);
            }
        });
    }
    else
    {
        PerformDisplayStateMapForDiv($(":asp('zd_ddlStates') :selected").attr("value"));
    }
}

//***********************************************************************************************
//  Call WebMethod to get 
//***********************************************************************************************
function PerformDisplayStateMapForDiv(selectedState)
{
    var vcsc_id = $(":asp('zd_ddlDestinationTypes') :selected").attr("value");
    var state = $(":asp('zd_ddlStates') :selected").attr("value");
    var paramData = "'VCSC_ID':'" + vcsc_id + "'";
    paramData += ", " + "'State':'" + state + "'";
    paramData = "{" + paramData + "}";

    var url = LinkPath("UtilityWebMethods/UtilityWebMethods.aspx/GetStateMapForDiv");
        
    if($.jqURL.qs() != null)
    {
        url += "?" + $.jqURL.qs();
    }    
    
    $.ajax({
        type: "POST",
        url: url,
        data: paramData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(content) 
        {
            $("div#zd_dSearchMap").html(content);
        },
        beforeSend: function()
        {
            maskWindow(true);
        },
        complete: function()
        {
            maskWindow(false);
        },
        error: function(msg)
        {
            maskWindow(false);
            alert("Error Message: " + msg);
        }
    });
}

//***********************************************************************************************
//  Method used 
//***********************************************************************************************
function PerformStateSelectedFromDiv(selectedState, displayStateMap) 
{
    SetState(selectedState);
    if((displayStateMap != null) && (displayStateMap == true))
    {
        PerformDisplayStateMapForDiv(selectedState);
    }
}

//***********************************************************************************************
//  Method used 
//***********************************************************************************************
function PerformRegionSelectedFromDiv(selectedRegionId) 
{
    SetRegion(selectedRegionId);
    PerformSearch();
}

//***********************************************************************************************
//  
//***********************************************************************************************
function PerformDisplayUSMapForModal(forceStateMap)
{   
    //Step  -   See if State is already populated
    var vcsc_id = $(":asp('zd_ddlDestinationTypes') :selected").attr("value");
    var selectedIndex = $(":asp('zd_ddlStates')").attr("selectedIndex");
    var selectedState = $(":asp('zd_ddlStates') :selected").attr("value");
    
    var vURL = LinkPath("Search/Maps/Modal/USMap.aspx?IsContainedInModal=true&VCSC_ID=" + vcsc_id);
    if($.jqURL.qs() != null)
    {
        //Note  -   The URL already contains a ?, so we are adding & to it.
        vURL += "&" + $.jqURL.qs();
    }
    
    if((forceStateMap == true) || (selectedIndex == 0))
    {     
        $.nyroModalManual({forceType: 'form', modal: true, url: vURL });
    }
    else
    {
        PerformDisplayStateMapForModal(selectedState);
    }
}

//***********************************************************************************************
//  
//***********************************************************************************************
function PerformDisplayStateMapForModal(selectedState)
{
    var vcsc_id = $(":asp('zd_ddlDestinationTypes') :selected").val();
    var vURL = LinkPath('Search/Maps/Modal/StateMap.aspx?IsContainedInModal=true&VCSC_ID=' + vcsc_id + '&State=' + selectedState);
    $.nyroModalManual({forceType: 'form', modal: true,url: vURL});
}

function PerformStateNotAvailable(isBackUSMap)
{
    if (isBackUSMap)
    {
        PerformDisplayUSMapForModal(true)   
    } else {
        PerformStateNotAvailableDiv(false);
    }
}

function PerformStateNotAvailableDiv(isMapSearch, vMapURL)
{
    var vSite = zm_sDestinationsEnum.PortalSite;
    var vMessage = "<div style=\"text-align: center;width:100%\">"
    vMessage += "<br><br><br><br>"
    vMessage += "<font color=\"black\"><b>This website does not list destinations for the region selected.<br>";
    vMessage += "Please visit <a href=http://" + vSite + " target=\"_blank\" >" + vSite + "</a> to search in that region.</b>";
    vMessage += "</font>"
     if (isMapSearch == false)
    {
        vMessage += "<br><br>"
        vMessage += "<div id=\"ModalAlertBackId\" style=\"float:left;text-align: center;display:inline; width:500px;\">";
        vMessage += "    <button id=\"zd_bBackUSMap\" class=\"PreventEnterKeySubmit\" type=\"button\" onclick=\"PerformStateNotAvailable(true)\" style=\"width:90px;\">";
        vMessage += "        Back USMap";
        vMessage += "    </button>";
        vMessage += "</div>";
    }
    vMessage += "</div>";
    $.nyroModalManual({content: vMessage,minWidth :500,minHeight: 200});
}

//***********************************************************************************************
//  Method used in nyroModal pop-up containing the Region Map
//***********************************************************************************************
function PerformStateSelectedFromModal(selectedState, displayStateMap) 
{
    SetState(selectedState);
    if((displayStateMap != null) && (displayStateMap == true))
    {
        PerformDisplayStateMapForModal(selectedState);
    }
}

//***********************************************************************************************
//  Method used in nyroModal pop-up containing the Region Map
//***********************************************************************************************
function PerformRegionSelectedFromModal(selectedRegionId) 
{
    SetRegion(selectedRegionId);
    $.nyroModalRemove();
}

//***********************************************************************************************
//  Method used in nyroModal pop-up containing the State Map
//***********************************************************************************************
function SetState(selectedState) 
{
    $(":asp('zd_ddlStates')").each(function() {  
        $("option", this).each(function() {
            if($(this).val() == selectedState)
            {
                //$(":asp('zd_ddlStates')").attr("value", $(this).attr("value"));
                $(":asp('zd_ddlStates')").attr("value", selectedState);
                //Step  -   Make sure Regions are reloaded
                LoadRegions(-1);
            }
        });
    });
}

//***********************************************************************************************
//  Method used in 
//***********************************************************************************************
function SetRegion(selectedRegionId) 
{
    $(":asp('zd_ddlRegions')").attr("value", selectedRegionId);
    //Note  -   If regions have NOT already been loaded then do this
    //LoadRegions(selectedRegionId);
} 

//***********************************************************************************************
//  Method used in
//***********************************************************************************************
//function SetStateAndRegion(selectedState, selectedRegionId) 
//{
//    $(":asp('zd_ddlStates')").attr("value", selectedState);
//    LoadRegions(selectedRegionId);
//} 

//***********************************************************************************************
//  
//***********************************************************************************************
function SetPageLoadMainMenuItem()
{
    // ToggleSelectedMenuItem($("li#zd_liFind"));
}

//***********************************************************************************************
//  
//***********************************************************************************************
function ToggleSelectedMenuItem(sender)
{
    $(sender).parent().children().filter(".active-menu").toggleClass("active-menu").toggleClass("nonactive-menu");
    $(sender).toggleClass("active-menu");
    ToggleSearchContainers(sender);
}

function ClickSelectedMenuItem(sender)
{
     var vSender = $(sender);
     
     var vReWriteURL = 'Find-Campgrounds-And-RV-Parks';
     
     if(vSender.attr("id") == $("li#zd_liReserve").attr("id"))
     {
        vReWriteURL = 'Reserve-A-Campsite';
     }
     else if(vSender.attr("id") == $("li#zd_liFindByMap").attr("id"))
     {
        vReWriteURL = 'Find-By-Map';
     }
     else if (vSender.attr("id") == $("li#zd_liViewRecentReviews").attr("id")) {
        vReWriteURL = 'view-recent-reviews';
     }
    
    //var vURL = LinkPath(vReWriteURL);
   // window.location = vURL;
    window.location.pathname =  "/" + vReWriteURL;
}

//***********************************************************************************************
//  
//***********************************************************************************************
function ToggleSearchContainers(sender)
{
    var vSender = $(sender);
    $("button#zd_bSearch").show();
//    $("input.SearchResultsDisplayType").filter("[value='2']").attr("checked", "checked");
    
    if(vSender.attr("id") == $("li#zd_liReserve").attr("id"))
    {
        $("div#zd_dSearchAvailability").show();
    }
    else
    {
        $("div#zd_dSearchAvailability").hide();
    }
    
    if(vSender.attr("id") == $("li#zd_liFindByMap").attr("id"))
    {
    
        $("div#zd_dMapSearchContainer").show();
        $("div#zd_dFindNonMapSearchContainer").hide();
        
        $("input#zd_rState").attr("checked","checked");        
	    SetPageLoadSearchBy('zd_rState');
        
        $("button#zd_bSearch").hide();
        PerformDisplayUSMapForDiv();
        $("input.SearchResultsDisplayType").filter("[value='3']").attr("checked", "checked");
    }
    else
    {
        $("div#zd_dMapSearchContainer").hide();
        $("div#zd_dFindNonMapSearchContainer").show();
    }
    
    vSelectSearchTabIndex = vSender.attr("value");
}                      

// Show or hide the reserve tab
function ViewReserveStatus(vDestinationTypeId)
{
    var vIsShow = GetDestinationTypes(vDestinationTypeId, 'VCSC_HAVE_TAVE_RESERVE');
    var vObj = $("li#zd_liReserve");
    if (vIsShow == 'True')
    {
        vObj.show();
    } else {
        vObj.hide();
    }
}
//***********************************************************************************************
//  VCSC_SEARCH_TYPE_ALIAS
//  VCSC_TAB_BROWSE_ALIAS 
//  VCSC_TAB_RESERVE_ALIAS 
//  VCSC_URL_BROWSE_ALIAS 
//  VCSC_URL_RESERVE_ALIAS  
//***********************************************************************************************
function SetDestinationTypeText(vDestinationTypeId) 
{    
    if (vDestinationTypeId == -1)
    {
        // var selectedDestinationType = $(":asp('zd_ddlDestinationTypes') :selected").text();
        vDestinationTypeId = $(":asp('zd_ddlDestinationTypes') :selected").val();
    }
    
    // Show or hide the reserve tab
    ViewReserveStatus(vDestinationTypeId);

    $(".DestinationTypeToggleHandler").each(function() 
    {
        for (i = 0; i < destinationTypeToggleHandlerArray.length; ++i) 
        {
            if (destinationTypeToggleHandlerArray[i][0] == $(this).attr("id")) 
            {
                selectedDestinationType = null;
                var valueText = destinationTypeToggleHandlerArray[i][1];
                if (destinationTypeToggleHandlerArray[i][0] == "zd_h3Find") 
                {
                    // Search Page Text Main Name
                    selectedDestinationType = GetDestinationTypes(vDestinationTypeId, 'VCSC_SEARCH_TYPE_ALIAS');
                } else
                if (destinationTypeToggleHandlerArray[i][0] == "zd_lDestinationName") 
                {
                    // Name of <Search_Type_Alias>
                    // Search the park name location
                    selectedDestinationType = GetDestinationTypes(vDestinationTypeId, 'VCSC_SEARCH_TYPE_ALIAS');

                } else
                if (destinationTypeToggleHandlerArray[i][0] == "zd_aFind") 
                {
                    // Search the first tab's text
                    selectedDestinationType = GetDestinationTypes(vDestinationTypeId, 'VCSC_TAB_BROWSE_ALIAS');
                } else
                if (destinationTypeToggleHandlerArray[i][0] == "zd_aReserve") 
                {
                    selectedDestinationType = GetDestinationTypes(vDestinationTypeId, 'VCSC_TAB_RESERVE_ALIAS');
                }

                valueText = valueText.replace(/\[Destination Value\]/, selectedDestinationType);
                if (destinationTypeToggleHandlerArray[i][0] == "zd_lDestinationName") {
                    var vHTMLText = $(this).html();
                    if (vHTMLText.indexOf('stickyName') > 0) 
                    {
                        valueText = vHTMLText.replace(/\[Destination Value\]/, selectedDestinationType);
                        $(this).html(valueText);

                        // 	Reload the Tooltip
                        $('.stickyName').cluetip(
                        {
                            sticky: true,
                            closePosition: 'title',
                            arrows: true,
                            width: '350px',
                            activation: 'click',
                            cluetipClass: 'jtip'
                        });
                    }
                } else {
                    $(this).text(valueText);
                }
                break
            }
        }
    });
}


// Select default main menu tab
function SelectDefaultOptionTab()
{
    try {
        var vObj = null;
        var vKeyWord = "ParkFacilities";
        if (zm_sDestinationsEnum.OptionTab == 1)
        {
            vKeyWord = "ParkFacilities"; 
        } else 
        if (zm_sDestinationsEnum.OptionTab == 2)
        {
            vKeyWord = "Activities";
        } else 
        if (zm_sDestinationsEnum.OptionTab == 3)
        {
            vKeyWord = "Atmosphere";
        } else 
        if (zm_sDestinationsEnum.OptionTab == 4)
        {
            vKeyWord = "Affiliations";
        } else 
        if (zm_sDestinationsEnum.OptionTab == 5)
        {
            vKeyWord = "ViewAll";
        }       

        // alert('Tab = '+zm_sDestinationsEnum.OptionTab + ' KeyWord =' + vKeyWord);
        SetPageLoadSearchCriteria(vKeyWord);
        return;
    } catch (ex) {
        alert('SelectDefaultMenuTab :' + ex.message);
    }
}

// Get the default option tab object
function GetDefaultOptionTabObj()
{
    var vKeyName = "ParkFacilities";
    var vObj = $("#zd_li" + vKeyName);
    if (vObj.html() == null)
    {
        vKeyName = "Activities";
         vObj = $("#zd_li" + vKeyName);
        if (vObj.html() == null)
        {
            vKeyName = "Atmosphere";
            vObj = $("#zd_li" + vKeyName);
            if (vObj.html() == null)
            {
                vKeyName = "Affiliations";
                vObj = $("#zd_li" + vKeyName);
                if (vObj.html() == null)
                {
                    vKeyName = "ViewAll";
                    vObj = $("#zd_li" + vKeyName);
                    if (vObj.html() == null)
                    {
                        vObj = null;
                    }  
                }  
            }
        }
    }
    return vObj;    
}
                  
//*******************************************************************************
//*******************************************************************************
function SetPageLoadSearchCriteria(vKeyName)
{
    try {
        if (typeof(vKeyName) == 'undefined') vKeyName = 'ParkFacilities';
        
        var vObj = $("#zd_li" + vKeyName);
        if (vObj.html() == null)
        {
            vObj = GetDefaultOptionTabObj()
            if (vObj == null) return;
            vKeyName = vObj.selector.substring(6);
        }     
           
        if (vObj.html() != null)
        {
            vObj.parent().children().filter(".active-menu").toggleClass("active-menu").toggleClass("nonactive-menu");
            vObj.toggleClass("active-menu"); 

            ToggleSCViewAllSep(false);
            ToggleAllSCContainer(false);
            
            ToggleSpecificSCContainer(vObj[0], vKeyName);
        }        
    } catch (ex) {
        AlertMsg('Search.method.js', 'SetPageLoadSearchCriteria', ex.message);
    } 
}

//***********************************************************************************************
//  
//***********************************************************************************************
function SetSearchCriteriaSelected(sender)
{

    // add by emile tu 02/25/2009
    // zd_liAffiliations
    $(sender).parent().children().filter(".active-menu").toggleClass("active-menu").toggleClass("nonactive-menu");
    $(sender).toggleClass("active-menu");
    
    ToggleSCViewAllSep(false);
    ToggleAllSCContainer(false);
    
    if(sender.id.endsWith("ParkFacilities"))
    {
        ToggleSpecificSCContainer(sender, "ParkFacilities");
    }
    
    else if(sender.id.endsWith("Activities"))
    {
        ToggleSpecificSCContainer(sender, "Activities");
    }
    
    else if(sender.id.endsWith("Atmosphere"))
    {
        ToggleSpecificSCContainer(sender, "Atmosphere");
    }
    
    else if(sender.id.endsWith("Affiliations"))
    {
        ToggleSpecificSCContainer(sender, "Affiliations");
    }
    
    else if(sender.id.endsWith("ViewAll"))
    {
        vSelectAmenitiesTabIndex = sender.value;
        ToggleSCViewAllSep(true);
        ToggleAllSCContainer(true);
    }
        
//    else if(sender.id.endsWith("Lifestyle"))
//    {
//        ToggleSpecificSCContainer(this, "Lifestyle");
//    }
//    
//    else if(sender.id.endsWith("RatesAndDiscounts"))
//    {
//        ToggleSpecificSCContainer(this, "RatesAndDiscounts");
//    }    
}

//***********************************************************************************************
//  
//***********************************************************************************************
function ToggleSpecificSCContainer(sender, name)
{
    vSelectAmenitiesTabIndex = sender.value;    
    var divTag = "zd_pSC" + name
    $(":asp('" + divTag + "')").show();
}

//***********************************************************************************************
//  
//***********************************************************************************************
function ToggleAllSCContainer(visible)
{
    if(visible == false)
    {
        $("div.SCContainerToggleHandler").hide();
    }
    else
    {
        $("div.SCContainerToggleHandler").show();
    }
}

//***********************************************************************************************
//  
//***********************************************************************************************
function ToggleSCViewAllSep(visible)
{
    if(visible == false)
    {
        $("div.SCSepToggleHandler").hide();
    }
    else
    {
        $("div.SCSepToggleHandler").show();
    }
}

var vFirstCall = true;
function onCollapse(vIsShow)
{
   if (vFirstCall) 
   {
        vFirstCall = false;
        UpdateAmenities()
   }
}

// Update the amenity
function UpdateAmenities()
{
    var paramData = '';
    paramData = "'intPortalId':'" + zm_sDestinationsEnum.PortalId + "',";
    paramData += "'isActivities':'" + zm_sDestinationsEnum.isActivities + "',";
    paramData += "'isAtmosphere':'" + zm_sDestinationsEnum.isAtmosphere + "',";
    paramData += "'isAmenities':'" + zm_sDestinationsEnum.isAmenities + "',";
    paramData += "'isMembership':'" + zm_sDestinationsEnum.isMembership + "'";
    paramData = "{" + paramData + "}";    
    var url = LinkPath("UtilityWebMethods/UtilityWebMethods.aspx/UpdateAmenities");
    maskWindow(true);
    
    $.ajax({
        type: "POST",
        url: url,
        data: paramData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",  
        cache: false,
        success: function(listItems) 
        {
            try {
                $("#AmenitiesContainerId").html(listItems);   
                
                var vActivities = '';         
                var vAtmosphere = '';
                var vParkAmenities = '';
                var vAffiliations = '';                
                $("#AmenitiesTableId tr").each(function(vIndex)
                {
                    var vType = $("td:eq(0)", $(this)).text();
                    var vId = $("td:eq(1)", $(this)).text();
                    var vName = $("td:eq(2)", $(this)).text();
                    switch (parseInt(vType,10))
                    {
                        case 1:
                            {
                                var vCategory = 'Activities_' + vId
                                vActivities += '<div id=\"zd_d' + vCategory + '\" class=\"SearchCriteriaContents\"><p><input id=\"zd_cb' + vCategory+ '\" name=\"zd_cb' + vCategory + '\" type=\"checkbox\" class=\"SCAmenities\" vam_id=\"' + vId + '\" /><label for=\"zd_cb' + vCategory + '\">&nbsp;' + vName + '</label></p></div>';
                            }
                            break;
                        case 2:
                            {
                                var vCategory = 'Atmosphere_' + vId
                                vAtmosphere += '<div id=\"zd_d' + vCategory + '\" class=\"SearchCriteriaContents\"><p><input id=\"zd_cb' + vCategory+ '\" name=\"zd_cb' + vCategory + '\" type=\"checkbox\" class=\"SCAmenities\" vam_id=\"' + vId + '\" /><label for=\"zd_cb' + vCategory + '\">&nbsp;' + vName + '</label></p></div>';
                            }
                            break;
                        case 3:
                            {
                                var vCategory = 'ParkFacilities_' + vId
                                vParkAmenities += '<div id=\"zd_d' + vCategory + '\" class=\"SearchCriteriaContents\"><p><input id=\"zd_cb' + vCategory+ '\" name=\"zd_cb' + vCategory + '\" type=\"checkbox\" class=\"SCAmenities\" vam_id=\"' + vId + '\" /><label for=\"zd_cb' + vCategory + '\">&nbsp;' + vName + '</label></p></div>';
                            }
                            break;
                        case 4:
                           {
                                var vCategory = 'Affiliations_' + vId
                                vAffiliations += '<div id=\"zd_d' + vCategory + '\" class=\"SearchCriteriaContents\"><p><input id=\"zd_cb' + vCategory+ '\" name=\"zd_cb' + vCategory + '\" type=\"checkbox\" class=\"SCAffiliations\" vaf_id=\"' + vId + '\" /><label for=\"zd_cb' + vCategory + '\">&nbsp;' + vName + '</label></p></div>';
                            }
                            break;
                    }                    
                });
                
                var vNoAvaiable = '<div style=\"width:100%; text-align:center\"><p>None available</p></div>';
                if (zm_sDestinationsEnum.isActivities) 
                {
                    if (vActivities == '') vActivities = vNoAvaiable;
                    $("div.SCActivities").html(vActivities);
                }
                if (zm_sDestinationsEnum.isAtmosphere) 
                {
                    if (vAtmosphere == '') vAtmosphere = vNoAvaiable;
                    $("div.SCAtmosphere").html(vAtmosphere);                
                }
                if (zm_sDestinationsEnum.isAmenities) 
                {
                    if (vParkAmenities == '') vParkAmenities = vNoAvaiable;
                    $("div.SCParkAmenities").html(vParkAmenities);
                }
                if (zm_sDestinationsEnum.isMembership) 
                {
                    if (vAffiliations == '') vAffiliations = vNoAvaiable;
                    $("div.SCAffiliations").html(vAffiliations);
                }
            } catch (ex) {
                alert('Success Exception :' + ex.message);
            }
        },
        beforeSend: function()
        {
            maskWindow(true);
        },
        complete: function()
        {
            maskWindow(false);
        },
        error: function(msg)
        {
            maskWindow(false);
            alert("Error Message: " + msg);
        }
    });
}
