﻿// *** Service Calling Proxy Class - Minified version of Rick Strahl's Proxy Class. (http://www.west-wind.com/weblog/posts/324917.aspx) 
eval(function (p, a, c, k, e, d) { e = function (c) { return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36)) }; if (!''.replace(/^/, String)) { while (c--) { d[e(c)] = k[c] || e(c) } k = [function (e) { return d[e] } ]; e = function () { return '\\w+' }; c = 1 }; while (c--) { if (k[c]) { p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]) } } return p } ('3 r(5){1 f=b;b.5=5;b.t=3(g,c,6,0,h){1 9=8.u(c);1 a=f.5+g;$.n({a:a,c:9,o:"v",w:D,E:"F/9",C:B,x:"y",z:3(i){2(!6)4;1 7=8.l(i);2(h){6(7);4}H(1 k A 7){6(7[k]);G}},0:3(e){2(!0)4;2(e.j){1 d=8.l(e.j);2(d)0(d);m 0({p:"q s 0."})}4}})}}', 44, 44, 'error|var|if|function|return|serviceUrl|callback|result|JSON|json|url|this|data|err|xhr|_I|method|bare|res|responseText|property|parse|else|ajax|type|Message|Unknown|serviceProxy|server|invoke|stringify|POST|processData|dataType|text|success|in|10000|timeout|false|contentType|application|break|for'.split('|'), 0, {}))
//Modal Display Formating
var modalOptions = { overlay: 100
                     , opacity: 80
                     , overlayCss: { backgroundColor: '#c4daf0', 'padding-bottom': '20px' }
                     , containerCss: { fontFamily: 'Lucida Grande, Lucida Sans Unicode, sans-serif' }
                     , zIndex: 3001
                     , position: ['10%', '']
                     , closeClass: 'close'
                     , appendTo: 'FORM'
                     , escClose: true
                     , onOpen: function (dialog) {
                         dialog.overlay.fadeIn('fast', function () {
                             dialog.data.hide();
                             dialog.container.fadeIn('fast', function () {
                                 dialog.data.slideDown('fast');
                             });
                         });
                     }
                    }

function popupCallForAvailability(obj, skuID) {
    // *** Create a static instance
    var Proxy = new serviceProxy("/service/PopupService.svc/");
    var XslName = "popup-call-for-availability.xsl";

    Proxy.invoke("TransformSku", { xslName: XslName, skuID: skuID },
    function (result) {
        $.modal(result, modalOptions);
    }); //Suppress Errors
}

function popupCallForPricing(obj, skuID) {
    // *** Create a static instance
    var Proxy = new serviceProxy("/service/PopupService.svc/");
    var XslName = "popup-call-for-pricing.xsl";

    Proxy.invoke("TransformSku", { xslName: XslName, skuID: skuID },
    function (result) {
        $.modal(result, modalOptions);
    }); //Suppress Errors
}

function popupUmapPricing(obj, skuID) {
    // *** Create a static instance
    var Proxy = new serviceProxy("/service/PopupService.svc/");
    var XslName = "popup-umap-pricing.xsl";

    Proxy.invoke("TransformSku", { xslName: XslName, skuID: skuID },
    function (result) {
        $.modal(result, { overlay: 100
                     , opacity: 80
                     , overlayCss: { backgroundColor: '#c4daf0', 'padding-bottom': '20px' }
                     , containerCss: { 'font-family': 'Lucida Grande", "Lucida Sans Unicode", sans-serif' }
                     , zIndex: 3001
                     , position: ['10%', '']
                     , closeClass: 'close'
                     , appendTo: 'FORM'
                     , persist: true
                     , escClose: true
                     , onOpen: function (dialog) {
                         dialog.overlay.fadeIn('fast', function () {
                             dialog.data.hide();
                             dialog.container.fadeIn('fast', function () {
                                 dialog.data.slideDown('fast', function () {
                                     $(".popup-wrapper .jquery-add-to-basket").addToBasket({ RedirectToBasket: false });
                                 });
                             });
                         });
                     }
        });

    });   //Suppress Errors
}











//UMAP CONTROL
function popupUMAP(obj, skuID) {
    var _umapWrapper = $(".POPUP_UMAP_WRAPPER");
    if (_umapWrapper.length > 0) {
        //Cleanup
        $(".POPUP_UMAP_PriceWrapper").hide();
        $(".POPUP_UMAP_BuyWrapper").hide();
        $(".POPUP_UMAP_Progress").show();

        openModal(_umapWrapper.attr("id"));
        
        //Make JSON Call
        UMAPWebService.GetUMAP(skuID, function(umap) {
            $(".POPUP_UMAP_Quantity").val(1);
            $(".POPUP_UMAP_RetailPrice").html(umap.RetailPrice);
            $(".POPUP_UMAP_RetailSquareFootagePrice").html(umap.RetailSquareFootagePrice);
            $(".POPUP_UMAP_CustomerPrice").html(umap.CustomerPrice);
            $(".POPUP_UMAP_CustomerSquareFootagePrice").html(umap.CustomerSquareFootagePrice);
            $(".POPUP_UMAP_Savings").html(umap.SavingsAmount);
            $(".POPUP_UMAP_SavingsPercentage").html(umap.SavingsPercentage);

            if (umap.QuantityOnHand <= 0) {
                $(".POPUP_UMAP_QuantityWrapper").hide();
                $(".POPUP_UMAP_ButtonWrapper").hide();
                $(".POPUP_UMAP_OutOfStock").show();
            } else {
                $(".POPUP_UMAP_QuantityWrapper").show();
                $(".POPUP_UMAP_ButtonWrapper").show();
                $(".POPUP_UMAP_OutOfStock").hide();
            }

            $(".POPUP_UMAP_AddToCart").attr("skuid", umap.SKUID).unbind("click").click(function() {
                var arr = new Array();
                var o = new Object();
                o.DOMObjectReferenceID = "";
                o.SKUID = $(this).attr("skuid");
                o.QuantityRequested = $(".POPUP_UMAP_Quantity").val();
                arr.push(o);
                return AddBasketItems($(this), arr);
            });

            //Show 
            $(".POPUP_UMAP_Progress").hide();
            $(".POPUP_UMAP_PriceWrapper").show();
            $(".POPUP_UMAP_BuyWrapper").show();
        }, function() {
            alert(GENERICERROR);
        });
    }
    return false; //Prevent Default action 
}


//OutOfStock Popup
function popupOutOfStock(obj, skuid) {
    $(".POPUP_OOS_Iframe").attr("src", "_blank").attr("src", "OutOfStockFrame.aspx?itemid=" + skuid);

    //Clone the Progress Bar and display it until the Iframe finishes loading. 
    $(".POPUP_OOS_Wrapper").html($(".POPUP_OOS_Progress").clone().css("display", "block")); 
    
    
    openModal($(".POPUP_OOS_WRAPPER").attr("id"));
    return false;
}

//MyList Popup
function popupMyList(obj, skuid) {

    $(parent.document).find(".POPUP_MYLIST_Progress").show();
    $(parent.document).find(".POPUP_MYLIST_Iframe").hide();

    $(".POPUP_MYLIST_Iframe").attr("src", "_blank").attr("src", "MyListFrame.aspx?itemid=" + skuid);
    openModal($(".POPUP_MYLIST_WRAPPER").attr("id"));
    return false;
}

//Shipping Information Popup
function popupShippingInformation(obj, skuid, postalcode, quantity, shippingservicecodeid) {
    $(".POPUP_SHIPPING_INFORMATION_Iframe").attr("src", "_blank").attr("src", "ShippingInformationFrame.aspx?itemid=" + skuid + "&postalcode=" + postalcode + "&quantity=" + quantity + "&shippingservicecodeid=" + shippingservicecodeid);

    //Clone the Progress Bar and display it until the Iframe finishes loading.
    $(".POPUP_SHIPPING_INFORMATION_WRAPPER").html($(".POPUP_SHIPPING_INFORMATION_Progress").clone().css("display", "block"));

    openModal($(".POPUP_SHIPPING_INFORMATION_MAIN_WRAPPER").attr("id"));
    return false;
}

//PostalCode Popup
function popupPostalCode(obj, skuid, quantity, shippingservicecodeid) {
    var _postalCodeWrapper = $(".POPUP_POSTALCODE_WRAPPER");
    $("input[id$='hidSKUID']").val(skuid);
    $("input[id$='hidQuantity']").val(quantity);
    $("input[id$='hidShippingServiceCodeID']").val(shippingservicecodeid);
    if (_postalCodeWrapper.length > 0) {
        openModal(_postalCodeWrapper.attr("id"));
    }
    return false;
}

//Coupon Code Information Popup
function popupCouponCodeInformation(couponcode, description) {
    var _couponCodeInformationWrapper = $(".POPUP_COUPONCODEINFORMATION_WRAPPER");
    $("span[id$='lblCouponCode']").html(couponcode);
    $("span[id$='lblDescription']").html(description);
    if (_couponCodeInformationWrapper.length > 0) {
        openModal(_couponCodeInformationWrapper.attr("id"));
    }
    return false;
}
