﻿$(window).load(function() {
    $(window).keydown(function(event) {
        if ((event.which == 13) || (event.keyCode == 13)) {
            PerformSearch();
        }
    });
    
    $("button#zd_bSearch").click(function() {
        PerformSearch();
    });

    $("select.States").change(function() {
        LoadRegions(-1);
    });

    $("#zd_iLoadMap").mouseover(function() {
        $(this).css("cursor", "pointer");
    });

    $("#zd_iLoadMap").click(function() {
        PerformDisplayUSMapForModal();
    });

    $("li.MenuLinkHandler").click(function() {
        //ToggleSelectedMenuItem(this);
        if (this.id != 'zd_liViewAll') { // Occur when click the view all, relink the page
            ClickSelectedMenuItem(this);
        }
    });

    $("li.SCLinkHandler").click(function() {
        SetSearchCriteriaSelected(this);
    });

    $("select.DestinationTypes").change(function() {
        SetDestinationTypeText(this.value);


        LoadSpaceType(this);
        //LoadCustomerSubTypes(this.value);
    });

    // 	Tooltip
    $('.sticky').cluetip(
    {
        sticky: true,
        closePosition: 'title',
        arrows: true,
        width: '350px',
        activation: 'click',
        cluetipClass: 'jtip'
    });

    $("input.SearchStartDate,input.SearchEndDate").datepicker(
    {
        beforeShow: SetAssociatedSearchDate,
        showOn: "both",
        duration: "fast",
        //duration: "",
        buttonImage: LinkPath("/images/general/calendar.gif"),
        buttonImageOnly: true
    }).attr("readonly", "readonly");

    $("div.collapse").collapse(
    {
        header: "p.trigger",
        content: "div.show_set",
        expandIcon: LinkPath("/images/general/closed1.gif"),
        collapseIcon: LinkPath("/images/general/open1.gif"),
        expandText: "&nbsp;&nbsp;Add Amenities and Lifestyle Options",
        collapseText: " Close Amenities and Lifestyle Options",
        callBack: onCollapse
    });

    $("input.DestinationAddress").example(function() {
        return $(this).attr("title");
    }, { className: "sample-text" });

    $("input.DestinationName").example(function() {
        return $(this).attr("title");
    }, { className: "sample-text" });

    $('div.left-form input[type=radio]').click(function() {
        if ($(this).not(':selected')) {
            $('div.left-form input[type=radio]').not(this).next().next(':visible').fadeTo(0.001, 175, function() { $(this).slideUp(175).find('input:eq(0)').attr("disabled", "disabled"); });
            $(this).next().next(':hidden').css('opacity', 0.001).slideDown(175, function() { $(this).fadeTo(0.9999, 175).find('input:eq(0)').removeAttr("disabled"); });
        }
    });

    // Step  -   Page Load Calls
    SetPageLoadPreventEnterKey();

    // Set Default value
    SetDestinationTypeText(-1);

    // Set State as the default selection
    SetPageLoadSearchCriteria();

    SetPageLoadShowDivs();

    SelectDefaultStatus();

    onLoadMap();
    LoadIFrameAD();

    // Show the Active Dialog
    CallActiveAcountDialog();
});

