﻿(function($) {

    $.sqlSecureKey = "";

    $.spJSON = function(sp, data, callback) {
        return jQuery.post("/_lib/agent/sp_D.ashx?__r_p_a_r_a_m=" + Math.random()
        + "&X_SP_AGENT_=" + escape(sp), data, callback, "json");
        $.ajaxSetup({ cache: false });
    };

    $.spXML = function(sp, data, callback) {
        return jQuery.post("/_lib/agent/sp_DX.aspx?__r_p_a_r_a_m=" + Math.random()
            + "&X_SP_AGENT_=" + escape(sp), data, callback, "json");
        $.ajaxSetup({ cache: false });
    };
    
    $.spXML_P = function(sp, data, callback) {
        
    };


    $.spIcore = function(sp, data, callback) {
        return jQuery.post("/_lib/agent/sp_I.ashx?__r_p_a_r_a_m=" + Math.random()
        + "&X_SP_AGENT_=" + escape(sp), data, callback, "text");
    };

    $.spI = function(sp, data, call_back) {
        $.spIcore(sp, data,
            function(data, status) {
                if (status == "success") {
                    if (jQuery.isFunction(call_back))
                        call_back(data);
                }
                else {
                    alert("요청하신 작업이 일시적인 중단되었습니다. 잠시후 다시 로그인 하시고 재 시도 해 주시기 바랍니다. 반복적으로 작업이 반송될 경우 관리자에게 문의 하여 주시기 바랍니다. 문의 코드:" + sp);
                }
            });
    };

    $.spS = function(sp, data, callback) {
        return jQuery.post("/_lib/agent/sp_S.aspx?__r_p_a_r_a_m=" + Math.random()
        + "&X_SP_AGENT_=" + escape(sp), data, callback, "text");
    };

    $.sqlJSON = function(sql, callback) {
        if ($.sqlSecureKey != "") {
            return jQuery.post("/_lib/agent/sql_D.aspx?__r_p_a_r_a_m=" + Math.random(),
            { X_SQL_AGENT_: escape($.sqlSecureKey + sql) }, callback, "json");
        }
    };

    $.sqlRUN = function(sql, callback) {
        if ($.sqlSecureKey != "") {
            return jQuery.post("/_lib/agent/sql_N.aspx?__r_p_a_r_a_m=" + Math.random(),
				{ X_SQL_AGENT_: escape($.sqlSecureKey + sql) }, callback, "text");
        }
    };

    $.dataPresentation = function(sp, data, presentation) {
        $.spJSON(sp, data,
         function(data, status) {
             if (status == "success") {
                 if (jQuery.isFunction(presentation))
                     presentation(data);
             }
         });
    };


})(jQuery);
