﻿+/*
    This file is the common code for the base masterpage's RadWindowManager and related
*/
function UseWindowManager(url, windowName, width, height, ismodal) {
    var oManager = GetRadWindowManager();
    var oWnd = oManager.open(url, windowName);
    if (oWnd) {
        if (width != 0)
            oWnd.set_width(width);

        if (height != 0)
            oWnd.set_height(height);

        oWnd.set_modal(ismodal);
    }
}

function ShowUpsellWindow() {
    UseWindowManager("/Loading.aspx?redirectURL=Upsells.aspx", "RadWindowUpsells", 600, 200, true);
    //prevent event from triggering twice
    Sys.Application.remove_load(ShowUpsellWindow);
}

function ShowCheckoutPromoWindow() {
    UseWindowManager("/Loading.aspx?redirectURL=CheckoutPromo.aspx", "RadWindowCheckoutPromo", 600, 200, true);
    //prevent event from triggering twice
    Sys.Application.remove_load(ShowCheckoutPromoWindow);
}

function ShowMutliSessionCheckoutWindow() {
    UseWindowManager("/Loading.aspx?redirectURL=MultiSessionCheckout.aspx", "RadWindowMultiSessionCheckout", 600, 100, true);
    //prevent event from triggering twice
    Sys.Application.remove_load(ShowMutliSessionCheckoutWindow);
}


function OnClientClose_SourceCode(oWnd, args) {
    //get the transferred arguments
    var arg = args.get_argument();

    if (arg) {
        var gotoSourceCode = arg.gotoSourceCode;
        var reloadCurrentPage = arg.reloadCurrentPage;
        var tmpSourceCode = arg.SourceCode;
        
        //not sure what's the page to redirect to........
        if (gotoSourceCode == "true") {
            $("body").css("cursor", "progress");
            window.location.href = "/campaign/?sourcecode=" + tmpSourceCode;
        }
        else if (reloadCurrentPage == "true") {
            $("body").css("cursor", "progress");
            window.location = window.location;
        }
    }
}

function OnClientClose_ShipToMultiB(oWnd, args) {
    $("body").css("cursor", "progress");
    window.location.href = "/Basket/";
}

function OnClientClose_ShipToMultiC(oWnd, args) {
    $("body").css("cursor", "progress");
    window.location.href = "/Checkout/";
}

function OnClientClose_PayInvoice(oWnd, args) {
    //get the transferred arguments
    var arg = args.get_argument();

    if (arg) {
        var reloadCurrentPage = arg.reloadCurrentPage;

        if (reloadCurrentPage == "true") {
            $("body").css("cursor", "progress");
            window.location = window.location;
        }
    }
}

function OnClientClose_Checkout(oWnd, args) {
    var arg = args.get_argument();
    $("body").css("cursor", "progress");
    if (arg) {
        if (arg == "checkout")
            window.location = "/Checkout/";
        else
            window.location = "/Product/" + arg + "/";
    }
    else
        window.location = window.location;
}

function OnClientClose_CheckoutPromo(oWnd, args) {

    var arg = args.get_argument();
    if (arg) {
        $("body").css("cursor", "progress");        
        if (arg == "checkout")
            window.location = "/Checkout/";
        else
            window.location = "/Product/" + arg + "/";
    }
    //else
    //    window.location = window.location;
}       