﻿/// <reference path="jquery-1.3.2-vsdoc.js" />
/// <reference path="jquery-ui-1.7.2.custom.min.js" />
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", { imgDown: "/Content/SpryAssets/SpryMenuBarDownHover.gif", imgRight: 
"/Content/SpryAssets/SpryMenuBarRightHover.gif" });

$(document).ready(function () {

    $.get("/Cart/CartCount", function (d) {
        if (d.toString() == "-1") {
            window.location = "/Account/Logon";
        } else {
            $(".cartcontents").text(d.toString() + " ITEMS");
        }
    }, "json");

    $('.watermark').each(
		function (i) {
		    $(this).focus(function () {
		        $(this).val("");
		    })
		})

    $("#LongDesc").dialog({ autoOpen: false });
    $("#LargeProductImg").dialog({ autoOpen: false, modal: true, width: 800 });

    $("#MoreDesc").click(function () {
        $("#LongDesc").dialog('open');
    });

    $("#ProductImg").click(function () {
        $("#LargeProductImg").dialog('open');
    });

    $(".AltProductImage").click(function () {
        var newImg = "/Stock/medium/" + $(this).attr("name");
        var newLargeImg = "/Stock/large/" + $(this).attr("name");
        $("#ProductImg IMG").attr("src", newImg);
        $("#LargeProductImg IMG").attr("src", newLargeImg);
    });

    $("#CopyAddress").click(CopyAddress);

    $("#gcLookup").dialog({ autoOpen: false, modal: true, title: 'Gift Card Validation' });

    $("#gc").click(function () {
        $("#gcLookup").dialog('open');
    });

    $("#codeOverlay").dialog({ autoOpen: false, modal: false, title: 'Credit Card Code', width: 400 });

    $("#ccMore").click(function (e) {
        $("#codeOverlay").dialog('open');
        e.preventDefault();
    });

    if (typeof (valueURL) != "undefined") {

        $("#dGC").dialog({ autoOpen: false, modal: true, title: 'Check Gift Card Balance', width: 400 });
        $("#checkGC").click(function (e) {
            $("#dGC").dialog("open");
            e.preventDefault();
        });

        $("#bGcCheck").click(function () {
            $.post(valueURL, { paymentid: $("#paymentid").val(), captcha: $("#captcha").val() }, function (d) {

                if (d.Value > 0) {
                    $("#gcValue").text("Gift card value: $" + d.Value);
                } else {
                    $("#gcValue").text(d.Msg);
                }
            }, "json");
        });

    }

    // Configure any last minute scripts
    if (typeof (Body_OnLoad) != "undefined") Body_OnLoad();

    // Configure estimate shipping link
    $("#mEstimate").dialog({ autoOpen: false, modal: true, title: 'Estimate Shipping Costs', width: 400 });

    $("#hlEstimateShipping").click(function () {
	$("#dEstimateResults").html("");
	$("#mEstimate").dialog("open");
    });

    $("#bEstimate").click(function () {
        $("#dEstimateResults").load("/Cart/EstimateShipping", { postalCode: $("#tPostal").val() });
    });

    // Configure any Add To Cart buttons
    $(".AddToCart").click(function (e) {

        e.preventDefault();

        var button = $(this);
        var qtyID = button.attr("qCtl")
        var q = $("#" + qtyID).val();

        $.post(
            "/Cart/AddToCart",
            { stockId: button.attr("prodId"), quantity: q },
            function (d) {

                $(".cartcontents").text(d.toString() + " ITEMS");
                alert("Your item has been added to the cart");
            },
            "json");

    });

});


function CopyAddress() {

    $("#ShipTo_FirstName").val($("#BillTo_FirstName").val());
    $("#ShipTo_LastName").val($("#BillTo_LastName").val());
    $("#ShipTo_Address").val($("#BillTo_Address").val());
    $("#ShipTo_Address2").val($("#BillTo_Address2").val());
    $("#ShipTo_City").val($("#BillTo_City").val());
    $("#ShipTo_State").val($("#BillTo_State").val());
    $("#ShipTo_PostalCode").val($("#BillTo_PostalCode").val());
    $("#ShipTo_Country").val($("#BillTo_Country").val());
    $("#ShipTo_Phone").val($("#BillTo_Phone").val());
    $("#ShipTo_Email").val($("#BillTo_Email").val());

}

function swp4(s,t,u,v,w,x,y,z){
a=document.getElementById(t).style
b=document.getElementById(v).style
c=document.getElementById(x).style
d=document.getElementById(z).style
a.display=(s=='on')?'block':'none'
b.display=(u=='on')?'block':'none'
c.display=(w=='on')?'block':'none'
d.display=(y=='on')?'block':'none'
}

function swp5(q,r,s,t,u,v,w,x,y,z){
a=document.getElementById(r).style
b=document.getElementById(t).style
c=document.getElementById(v).style
d=document.getElementById(x).style
e=document.getElementById(z).style
a.display=(q=='on')?'block':'none'
b.display=(s=='on')?'block':'none'
c.display=(u=='on')?'block':'none'
d.display=(w=='on')?'block':'none'
e.display=(y=='on')?'block':'none'
}

function swpd(q,r,s,t,w,x,y,z){
a=document.getElementById(r).style
b=document.getElementById(s).style
c=document.getElementById(t).style
d=document.getElementById(x).style
e=document.getElementById(y).style
f=document.getElementById(z).style
a.display=(q=='on')?'block':'none'
b.display=(q=='on')?'block':'none'
c.display=(q=='on')?'block':'none'
d.display=(w=='on')?'block':'none'
e.display=(w=='on')?'block':'none'
f.display=(w=='on')?'block':'none'
}

function popMenu(menu, PForm, PParams){
ref=menu.choice.options[menu.choice.selectedIndex].value;
if (ref != "") 
{popWin = open(ref, PForm, PParams);
popWin.focus();} // brings the new window to the front
}