﻿var lastCommand = "noCommand"

function koalaInitializeRequest(sender, args) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (prm.get_isInAsyncPostBack()) {
        args.set_cancel(true);
        // se in asyncpostback cancella ulteriori richieste ajax
        // per annullare la richesta in corso si usa prm.abortPostBack();
    } else {
        if (args.get_postBackElement().alt == "ShowUpload") {
            $("#upload-ajaxcontent").hide();
            $("#upload-ajaxloading").show();
            lastCommand = args.get_postBackElement().alt;
        } else if (args.get_postBackElement().alt == "UploadAjaxContent") {
            $("#upload-ajaxcontent").hide();
            $("#upload-ajaxloading").show();
            lastCommand = args.get_postBackElement().alt;
        } else if (args.get_postBackElement().title == "SubscribeNS") {
            $("#subscribe-ajaxcontent").hide();
            $("#subscribe-ajaxloading").show();
            lastCommand = args.get_postBackElement().title;
            //AGGIUNGERE GLI ELSE IF SE CI SONO ALTRI PULSANTI CON EFFETTI DIVERSI
        } else if (args.get_postBackElement().title == "SubmitLogin") {
            showmodal("progress-ctr", "to-overlay", "obscure_generic");
            lastCommand = "noCommand";
        } else if (args.get_postBackElement().title == "CartUpdate") {
            $("#box_cart_update .updating").show();
            $("#box_cart_update .updated").hide();
            //$("#box_cart_added").show();
            show_generic("box_cart_update", "all", "show");
            $("#box_cart_update").shadow({
                offset: 3,
                opacity: 0.2,
                color: "#333",
                monitor: false
            });
            //showmodal("#box_cart_added", "all", "obscure_generic");
            lastCommand = args.get_postBackElement().title;
            //AGGIUNGERE GLI ELSE IF SE CI SONO ALTRI PULSANTI CON EFFETTI DIVERSI
        } else if (args.get_postBackElement().title == "InvoiceProvinceCheck") {
            $("#i_invoiceprovincecheck").show();
            lastCommand = args.get_postBackElement().title;
        } else if (args.get_postBackElement().title == "noCommand") {
            lastCommand = args.get_postBackElement().title;
        } else {
            showmodal("progress-ctr", "all", "obscure_generic");
            lastCommand = "generic command";
        }

    }

}


function koalaEndRequest(sender, args) {
    if (lastCommand != "noCommand") {
        if (lastCommand == "ShowUpload") {
            $("#upload-ajaxloading").hide();
            $("#upload-ajaxcontent").show();
        } else if (lastCommand == "UploadAjaxContent") {
            $("#upload-ajaxloading").hide();
            $("#upload-ajaxcontent").show();
        } else if (lastCommand == "SubscribeNS") {
            $("#subscribe-ajaxloading").hide();
            $("#subscribe-ajaxcontent").show();
        } else if (lastCommand == "CartUpdate") {
            $("#box_cart_update .updating").hide();
            $("#box_cart_update .updated").show();
            setTimeout(hideCartUpdate, 1500);
            //AGGIUNGERE GLI ELSE IF SE CI SONO ALTRI PULSANTI CON EFFETTI DIVERSI
        } else if (lastCommand == "ProvinceCheck") {
            $("#i_provincecheck_loading").hide();
        } else {
            hidemodal("progress-ctr", "obscure_generic");
        }
    }
}

function hideCartUpdate() {
    $("#box_cart_update").shadowDestroy();
    $("#box_cart_update").fadeOut("slow"); 
}

function showUpload(arg) {
    switch (arg) {
        case "image":
            {
                $("#upload-divfile").hide();
                $("#upload-divimage").show();
                break
            }
        case "file":
            {
                $("#upload-divimage").hide();
                $("#upload-divfile").show();
                break
            }

    }
    showmodal("upload-ctr", "all", "obscure_upload");
}

function hideUpload() { hidemodal("upload-ctr", "obscure_upload"); }

function showSubscribe() {
    //$("html, body").animate({ scrollTop: 0 }, "slow", function() {
        showmodal("subscribe-ctr", "all", "obscure_subscribe", "fadeIn");
    //}); 

 }

function hideSubscribe() { hidemodal("subscribe-ctr", "obscure_subscribe", "fadeOut"); }

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
