﻿$(document).ready(function () {

    // Sign In and Register Dashboard toggle
    $("#signin_dd").click(function () {
        $("#dashboard").toggle();
    });

    // Sign In and Register Close Dashboard button
    $("#clsbtn").click(function () {
        $("#dashboard").hide();
    });

    // Contact Us Dashboard toggle
    $("#contactus_dd").click(function () {
        $("#contactus-dashboard").toggle();
    });

    // Contact Us Close Dashboard button
    $("#contactus-clsbtn").click(function () {
        $("#contactus-dashboard").hide();
    });

    // Tabs 
    $(function () {
        $("#tabs").tabs();
    });

    // Gift Products toggle
    $("#gift-prods-list").hide();
    $("#gift-prods .toggle").click(function () {
        $("#gift-prods-list").toggle();
    });

    // Pure Spa - Link
    $('#modal-pure-spa-link').click(function () {
        var modal = $('#modal-pure-spa');
        modal.dialog('open');
        modal.find('input:first').focus();
        return false;
    });

    // Pure Spa - Modal
    $('#modal-pure-spa').dialog({
        autoOpen: false,
        width: 550,
        height: 400,
        modal: true,
        open: function () { { $(this).parent().appendTo($("form:first")); } }
    });



    // Weekend Stay - Link
    $('#modal-weekend-link').click(function () {
        var modal = $('#modal-weekend');
        modal.dialog('open');
        modal.find('input:first').focus();
        return false;
    });

    // Weekend Stay - Modal
    $('#modal-weekend').dialog({
        autoOpen: false,
        width: 550,
        height: 550,
        modal: true,
        open: function () { { $(this).parent().appendTo($("form:first")); } }
    });

    // Overnight Stay - Link
    $('#modal-overnight-link').click(function () {
        var modal = $('#modal-overnight');
        modal.dialog('open');
        modal.find('input:first').focus();
        return false;
    });

    // Overnight Stay - Modal
    $('#modal-overnight').dialog({
        autoOpen: false,
        width: 550,
        height: 460,
        modal: true,
        open: function () { { $(this).parent().appendTo($("form:first")); } }
    });

    // Cards and Checks - Link
    $('#modal-cards-checks-link').click(function () {
        var modal = $('#modal-cards-checks');
        modal.dialog('open');
        modal.find('input:first').focus();
        return false;
    });

    // Cards and Checks - Modal
    $('#modal-cards-checks').dialog({
        autoOpen: false,
        width: 650,
        height: 480,
        modal: true,
        open: function () { { $(this).parent().appendTo($("form:first")); } }
    });

    // Accordion
    $(function () {
        $("#accordion").accordion({
            autoHeight: false,
            navigation: true
        });
    });

    // Change Password - Link
    $('#modal-change-password-link').click(function () {
        $('#modal-change-password').dialog('open');
        return false;
    });

    // Change Password - Modal
    $('#modal-change-password').dialog({
        autoOpen: false,
        width: 550,
        height: 400,
        modal: true,
        open: function () { { $(this).parent().appendTo($("form:first")); } }
    });

    // Change Address - Link
    $('#modal-change-address-link').click(function () {
        var modal = $('#modal-change-address');
        modal.dialog('open');
        modal.find('input:first').focus();
        return false;
    });


    // Change Address - Modal
    $('#modal-change-billing-address').dialog({
        autoOpen: false,
        width: 550,
        height: 650,
        modal: true,
        open: function () { { $(this).parent().appendTo($("form:first")); } }
    });

    // Dialog			
    $('#dialog').dialog({
        autoOpen: false,
        width: 400,
        modal: true,
        buttons: {
            "Confirm": function () {
                $(this).dialog("close");
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });

    // Datepicker
    $(function () {
        $("#date-picker").datepicker();

    });

    // Message - Link
    $('#modal-message-link').click(function () {
        var modal = $('#modal-message');
        modal.dialog('open');
        modal.find('input:first').focus();
        return false;
    });

    // Message - Modal
    $('#modal-message').dialog({
        autoOpen: false,
        width: 300,
        height: 200,
        modal: true,
        buttons: {
            "OK": function () {
                $(this).dialog("close");
            }
        }
    });
	
	// image hover for footer logos
	$('.logosWrapper li a img').imghover({
		suffix: '_hover',
		fade: true,
		fadeSpeed: 200
	});

});

function showDialog(id) {
    $('#' + id).dialog("open");
}

function closeDialog(id) {
    $('#' + id).dialog("close");
}

function openMessageDialog(confirmMessage) {
    $("#lblGenericMessage").val(confirmMessage);
    $('#modal-message').dialog('open');
}

function saveCloseDialog(id, confirmMessage) {
    $('#' + id).dialog("close");
    window.location.reload();
}

function setCursorPositionToEnd(elementId) {

    var control = document.getElementById(elementId);
    if (null != control) {
        var pos = control.value.length;
        if (control.setSelectionRange) {
            control.setSelectionRange(pos, pos);
        }
        else if (control.createTextRange) {
            var textRange = control.createTextRange();
            textRange.collapse(true);
            textRange.moveEnd("character", pos);
            textRange.moveStart("character", pos);
            textRange.select();
        }
        control.focus();
    }
}
