﻿
var slide = true;
var sub = true;
var checkNow = true;
var searchNow = true;
$(document).ready(function () {
    $('#btnSearch').click(function () {
        if (searchNow) {
            $('#popupSearch').slideDown('slow'); searchNow = false
            $('#popupCheckNow').slideUp('slow'); checkNow = true
            $('#popupContact').slideUp('slow'); slide = true
            $('#popupsub').slideUp('slow'); sub = true
        }
        else {
            $('#popupSearch').slideUp('slow'); searchNow = true
        }
    });
    $('#btnCheckNow').click(function () {
        if (checkNow) {
            $('#popupCheckNow').slideDown('slow'); checkNow = false
            $('#popupSearch').slideUp('slow'); searchNow = true
            $('#popupContact').slideUp('slow'); slide = true
            $('#popupsub').slideUp('slow'); sub = true
        }
        else {
            $('#popupCheckNow').slideUp('slow'); checkNow = true
        }
    });
    $('#button').click(function () {
        if (slide) {
            $('#popupContact').slideDown('slow'); slide = false;
            $('#popupSearch').slideUp('slow'); searchNow = true;
            $('#popupCheckNow').slideUp('slow'); checkNow = true;
            $('#popupsub').slideUp('slow'); sub = true;
        }

        else {
            $('#popupContact').slideUp('slow'); slide = true;
        }
    });

    $('.popupContactClose').click(function () {
        $('#popupContact').slideUp('slow'); slide = true;
        $('#popupCheckNow').slideUp('slow'); checkNow = true;
        $('#popupsub').slideUp('slow'); sub = true;
    });

    $('#sub').click(function () {
        if (sub) {
            $('#popupsub').slideDown('slow'); sub = false;
            $('#popupSearch').slideUp('slow'); searchNow = true;
            $('#popupContact').slideUp('slow'); slide = true;
            $('#popupCheckNow').slideUp('slow'); checkNow = true;
        }
        else {
            $('#popupsub').slideUp('slow'); sub = true
        }
    });
    $('.popupContactClose').click(function () {
        $('#popupContact').slideUp('slow'); slide = true;
        $('#popupCheckNow').slideUp('slow'); checkNow = true;
        $('#popupsub').slideUp('slow'); sub = true;
    });

    $('#txtStartDate, #txtEndDate').datepicker({
        showOn: "button",
        buttonImage: imgpath,
        buttonImageOnly: true,
        onSelect: addDays,
        beforeShow: customRange,

        changeFirstDay: false
    });
    $('#txtArrivalDate, #txtDepartureDate').datepicker({
        showOn: "button",
        buttonImage: imgpath,
        buttonImageOnly: true,
        onSelect: addDays1,
        beforeShow: customRange1,

        changeFirstDay: false
    });


    $('#SignIn').click(function () {

        if ($('#edittxtloginemail').val() == '') {
            $('#edittxtloginemail').focus();
            alert('Please Enter Email.');
            return false;
        }
        if ($('#edittxtloginpassword').val() == '') {
            $('#edittxtloginpassword').focus();
            alert('Please Enter Password.');
            return false;
        }
        $('#Form').attr('action', 'https://book.hiddenbeachresort.com/res/STWMain.aspx');
        $('#footerbooknow').remove();
        $('#popupContact').remove();
        $('#__VIEWSTATE').remove();
        $('#__dnnVariable').remove();
        $('#Form').submit();
    });
    $('#buttonBig').click(function () {
        if ($('#txtStartDate').val() == '') {
            $('#txtStartDate').focus();
            alert('Please Enter Arrival Date.');
            return false;
        }
        if ($('#txtEndDate').val() == '') {
            $('#txtEndDate').focus();
            alert('Please Enter Departure Date.');
            return false;
        }
        $('#Form').attr('action', 'https://book.hiddenbeachresort.com/res/STWMain.aspx?Theme=HBEACH&Action=SeqList&newsearch=1&airisoptional=Y&producttype=L&airtocity=CUN&airretfromcity=CUN&productcode=MX-HBR');


        if (typeof ($('#txtStartDate').val()) != 'undefined') {
            $('#edit-airdateout').val($('#txtStartDate').val());
        }
        if (typeof ($('#txtEndDate').val()) != 'undefined') {
            $('#edit-airdateret').val($('#txtEndDate').val());
        }
        $('#popupContact').hide();
        $('#footerbooknow').remove();
        $('#__VIEWSTATE').remove();
        $('#__dnnVariable').remove();
        $('#popupCheckNow').remove();
        $('#Form').submit();
    });
    $('#footerbtnbook').click(function () {
        if ($('#txtArrivalDate').val() == '') {
            $('#txtArrivalDate').focus();
            alert('Please Enter Arrival Date.');
            return false;
        }
        if ($('#txtDepartureDate').val() == '') {
            $('#txtDepartureDate').focus();
            alert('Please Enter Departure Date.');
            return false;
        }
        $('#Form').attr('action', 'https://book.hiddenbeachresort.com/res/STWMain.aspx?Theme=HBEACH&Action=SeqList&newsearch=1&airisoptional=Y&producttype=L&airtocity=CUN&airretfromcity=CUN&productcode=MX-HBR');
        $('#popupContact').remove();
        $('#popupCheckNow').remove();
        $('#__VIEWSTATE').remove();
        $('#__dnnVariable').remove();
        $('#Form').submit();
    });


    $("#edit-airfromcity-wrapper").hide();
    $('#edit-airfromcity').val('');
    $("#edit-chkAir-Y").click(function () {
        $('#edit-airfromcity-wrapper').show();
        $('#edit-airfromcity').val('');
    });
    $("#edit-chkAir-N").click(function () {
        $('#edit-airfromcity-wrapper').hide();
    });

    //            $("#edit-airfromcity").autocomplete({
    //                source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
    //            }); 
    $('#edit-airfromcity').autocomplete(citypath, {
        minChars: 2, scroll: false, selectFirst: false, formatItem: formatItem, formatResult: formatResult
    });
});
function formatItem(row) {
    return row[0].replace(/\(.*\)/, "");
}
function formatResult(row) {
    return row[1];
}
function addDays(dateStr, input) {
    if (input.id === "txtStartDate") {
        if ($("#txtEndDate").datepicker("getDate") == null) {
            var d = $.datepicker.parseDate('mm/dd/yy', dateStr);
            d.setDate(d.getDate() + 3); // Add three days
            $('#txtEndDate').datepicker('setDate', d);
        }
    }
}
function customRange(input) {
    $('#ui-datepicker-div').css({ 'bottom': '' });
    var min = new Date(), //Set this to your absolute minimum date
        dateMin = min,
        dateMax = null,
        mindayRange = 1,
        dayRange = 900; // Set this to the range of days you want to restrict to
    if (input.id === "txtStartDate") {
        if ($("#txtEndDate").datepicker("getDate") != null) {
            dateMax = $("#txtEndDate").datepicker("getDate");
            dateMax.setDate(dateMax.getDate() - mindayRange);
            dateMin = $("#txtEndDate").datepicker("getDate");
            dateMin.setDate(dateMin.getDate() - dayRange);
            if (dateMin < min) {
                dateMin = min;
            }
        }
        else {
            var rangeMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + dayRange - mindayRange);
            dateMax = rangeMax;
        }
    }
    else if (input.id === "txtEndDate") {
        if ($("#txtStartDate").datepicker("getDate") != null) {
            dateMin = $("#txtStartDate").datepicker("getDate");
            dateMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + dayRange);
            dateMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + mindayRange);
        }
    }
    return {
        minDate: dateMin,
        maxDate: dateMax
    };
}
function addDays1(dateStr, input) {
    if (input.id === "txtArrivalDate") {
        if ($("#txtDepartureDate").datepicker("getDate") == null) {
            var d = $.datepicker.parseDate('mm/dd/yy', dateStr);
            d.setDate(d.getDate() + 3); // Add three days
            $('#txtDepartureDate').datepicker('setDate', d);
        }
    }
}
function customRange1(input) {
    field = $(input);
    left = field.position().left; //add offset
    bottom = 30;
    setTimeout(function () {
        $('#ui-datepicker-div').css({ 'top': '', 'bottom': bottom + 'px', 'left': left + 'px' });
    }, 1);
    var min = new Date(), //Set this to your absolute minimum date
        dateMin = min,
        dateMax = null,
        mindayRange = 1,
        dayRange = 900; // Set this to the range of days you want to restrict to
    if (input.id === "txtArrivalDate") {
        if ($("#txtDepartureDate").datepicker("getDate") != null) {
            dateMax = $("#txtDepartureDate").datepicker("getDate");
            dateMax.setDate(dateMax.getDate() - mindayRange);

            dateMin = $("#txtDepartureDate").datepicker("getDate");
            dateMin.setDate(dateMin.getDate() - dayRange);
            if (dateMin < min) {
                dateMin = min;
            }
        }
        else {
            var rangeMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + dayRange - mindayRange);
            dateMax = rangeMax;
        }
    }
    else if (input.id === "txtDepartureDate") {
        if ($("#txtArrivalDate").datepicker("getDate") != null) {
            dateMin = $("#txtArrivalDate").datepicker("getDate");
            dateMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + dayRange);
            dateMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + mindayRange);
        }
    }
    return {
        minDate: dateMin,
        maxDate: dateMax
    };
}
function hideLabel() {
    $('#dnn_ddnSubscription_lblMessage').hide();
}
