﻿/*
    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", 630, 700, 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;

        //campaign redirect
        if (gotoSourceCode == "true") {
            $("body").css("cursor", "progress");
            window.location.href = "/campaign/?sourcecode=" + tmpSourceCode;
        }
        //cyop redirect
        else if (gotoSourceCode == "cyop") {
            $("body").css("cursor", "progress");
            window.location.href = "/Campaign/CreateYourOwnPackage/?sourcecode=" + tmpSourceCode;
        }
        else if (gotoSourceCode == "removesc") {
            $("body").css("cursor", "progress");
            window.location.href = "/";
        }
        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");
    
    var url = location.href;
    var baseURL = "/";
    if (url.indexOf("http://www.shopingenix.com", 0) > -1 )
        baseURL = url.substring(0, url.indexOf("/", 8)+1).replace('http','https');
    
    window.location.href = baseURL + "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"){
            var url = location.href;
            var baseURL = "/";
            if (url.indexOf("http://www.shopingenix.com", 0) > -1)
                baseURL = url.substring(0, url.indexOf("/", 8)+1).replace('http','https');
    
            window.location = baseURL + "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"){
            var url = location.href;
            var baseURL = "/";
            if (url.indexOf("http://www.shopingenix.com", 0) > -1)
                baseURL = url.substring(0, url.indexOf("/", 8)+1).replace('http','https');
            
            window.location = baseURL + "Checkout/";
            }
        else
            window.location = "/Product/" + arg + "/";
    }
    else
        window.location = window.location;
}       
