﻿var AJAXController = {
    url: "/AJAXController/AJAXResponseBuilder.aspx",
    ajax_calling: "",
    hasFirebug: function () { return ("console" in window && "firebug" in window.console) || (console != null && typeof console != 'undefined') },
    AR: function (callto, params, updateElementId) {
       
        AJAXController.ARC(callto, params, updateElementId, null);

    },

    ARC: function (callto, params, updateElementId, callback) {
        if (callto != "") {
            $("#divSystemWorking").show();
            AJAXController.ajax_calling = callto;
          
            var call = { callname: callto };
            if (!params) params = {};
            if (params && params == "") params = {};
            $.extend(params, call);
            $.ajax({
                url: this.url,
                type: "POST",
                data: (params),
                dataType: "json",
                success: function (response) {
                    if (response.Success) {
                        if (updateElementId != null && updateElementId.length > 0 && $(updateElementId))
                            $(updateElementId).html(response.Data);
                        if (callback && (typeof callback === "function"))
                            callback(response.Data);
                    }
                    else if (AJAXController.hasFirebug()) {
                        console.log("[error]AJAXController: callname:" + callto + " failed --> [Runtime error:" + response.RuntimeError + "], [Json error: " + response.JSONError + "]");
                    }

                    $("#divSystemWorking").hide();
                },
                error: function (response) {
                    $("#divSystemWorking").hide();
                    if (AJAXController.hasFirebug())
                        console.log("[error]AJAXController: callname:" + callto + " --> " + response.responseText);

                }
            });
        } else {
            $("#divSystemWorking").hide();
            if (AJAXController.hasFirebug())
                console.log("[error]AJAXController: no callname");
        }
    }
}

