﻿$(document).ready(function() {
    $(".addtocart").click(function(event) {
        event.preventDefault();

        var productId = $(this).attr("rel");

        var sizeList = $("#Size");


        if (sizeList.val() !== undefined) {
            if (sizeList.val() === "--select size--") {
                alert("Please Select a Size");
                return;
            } else {
                productId = sizeList.val();
            }
        }

        $(this).attr("src", "/content/images/btns/btnAddingToToolKit.gif");
        var buttonImage = $(this);
        $.ajax({
            type: "POST",
            url: "/trolley/AjaxAdd",
            data: { "productID": productId },
            success: function(msg) {
                $("#cart").empty();
                $("#cart").html(msg);
                //buttonImage.attr("src", "/content/images/btns/btnAddToToolKit.gif");
                setTimeout(function() { buttonImage.attr("src", "/content/images/btns/btnAddToToolKit.gif") }, 1000);
            }
        });

    });

    $(".date-picker").datepicker();

    hijackStoreSearch();

});


$(function() {

    // Setup terms link click events
    $('#terms_link').click(function(e) {
        e.preventDefault();
        $('#terms_dialog').dialog('open');
        if ($.browser.msie && $.browser.version == "6.0") {
            $("select").css("display", "none");
        }
        return false;
    });

    // Setup dialog and download content
    $("#terms_link").each(
        function(link) {

            var content = $('<div />').attr("id", "terms_content").text("Loading..")
            var container = $('<div />').attr("id", "terms_dialog").attr("title", "Terms and Conditions").css("display", "none");

            $('body').append(container.append(content));

            $('#terms_dialog').dialog({
                autoOpen: false,
                width: 960,
                height: 600,
                buttons: {
                    "": function() {
                        $(this).dialog("close");
                    }
                },
                close: function() {
                    $("select").css("display", "block");
                },
                modal: true
            });

            $.ajax({
                type: "GET",
                url: $("#terms_link").attr('href'),
                success: function(data) {
                    $('#terms_content').html($(data).find("#disclaimer-text").html());
                },
                error: function() {
                    $('#terms_content').html("Error Loading Terms and Condititions");
                }
            });
        });
});




$().ready(function() {
    swapValues = [];
    $(".watermark").each(function(i) {
        swapValues[i] = $(this).attr("rel");
        if ($.trim($(this).val()) == "") { $(this).val(swapValues[i]).addClass("watermark") };
        $(this).focus(function() {
            if ($(this).val() == swapValues[i]) {
                $(this).val("").removeClass("watermark")
            }
        }).blur(function() {
            if ($.trim($(this).val()) == "") { $(this).val(swapValues[i]).addClass("watermark") }
        })
    })
}); 

function hijackStoreSearch() {
    $("form#storesearchform").submit(function(event) {
        event.preventDefault();
        searchLocations();
    });
}


