﻿var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_beginRequest(panelLoading);
prm.add_endRequest(panelLoaded);
prm.add_endRequest(EndRequest);

function panelLoading(b, a) {
    setTimeout("document.body.style.cursor = \"wait\";", 10);
    $get("hidShowAddToCartProgress").value = "y";
    setTimeout("ShowAddToCartProgress();", 1000)
}

function panelLoaded(b, a) {
    $get("hidShowAddToCartProgress").value = "n";
    $find("mpeModal").hide();
    $find("mbProgress").stop();
    setTimeout("document.body.style.cursor = \"auto\";", 10);

    // Light box
    $('a.lightbox').lightBox();
}

function ShowAddToCartProgress() {
    if ($get("hidShowAddToCartProgress").value == "y") {
        $find("mpeModal").show(); $find("mbProgress").play()
    }
}

function EndRequest(sender, args) {
    // Check to see if there's an error on this request.
    if (args.get_error() != undefined) {

        var msg = args.get_error().message.replace("Sys.WebForms.PageRequestManagerServerErrorException: ", "");

        // Show the custom error. 
        // Here you can be creative and do whatever you want
        // with the exception (i.e. call a modalpopup and show 
        // a nicer error window). I will simply use 'alert'
        alert(msg);

        // Let the framework know that the error is handled, 
        //  so it doesn't throw the JavaScript alert.
        args.set_errorHandled(true);
    }
}

