﻿
//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;
}
