//$.ajax({
//    type: "post",
//    url: "",
//    data: {  },
//    dataType: "json",
//    beforeSend: function (XMLHttpRequest) {
//        //console.log("beforeSend", XMLHttpRequest);
//        $("#loadImg").show();
//    },
//    success: function (data, textStatus) {
//        console.log("success", data, textStatus);
//    },
//    complete: function (XMLHttpRequest, textStatus) {
//        //console.log("complete", XMLHttpRequest, textStatus);
//        $("#loadImg").hide();
//    },
//    error: function (XMLHttpRequest, textStatus, errorThrown) {
//        if (console && console.log) {
//            console.log("error", XMLHttpRequest, textStatus, errorThrown);
//        }
//    }
//});

var doAjax = function (method, url, data, async, callBack) {
    $.ajax({
        type: method,
        url: url,
        data: data,
        dataType: "json",
        async: async,
        beforeSend: function (XMLHttpRequest) {
            //console.log("beforeSend", XMLHttpRequest);
            $("#loadImg").show();
        },
        success: function (data, textStatus) {
            //console.log("success", data, textStatus);
            if (callBack) callBack(data);
        },
        complete: function (XMLHttpRequest, textStatus) {
            //console.log("complete", XMLHttpRequest, textStatus);
            $("#loadImg").hide();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            if (console && console.log) {
                console.log("error", XMLHttpRequest, textStatus, errorThrown);
            }
        }
    });
}

var _debug = true;
var debug = function (log) {
    if (_debug)
        console.log(log);
}
//获取页面传值
var request = function (paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
}

var msgAlert = function (msg) {
    if (msg != null && msg != "") {
        $.messager.alert('提示', msg);
    }
}
var showEditDialog = function (id, url, title, width, height, func, fitFlag) {

    if (fitFlag == undefined) {
        fitFlag = false;
    }
    var content = '<iframe src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="no"></iframe>';
    var win = $("#" + id).dialog({
        id: id,
        content: content,
        width: width,
        height: height,
        modal: true,
        title: title,
        catch: false,
        onBeforeClose: func,
        fit: fitFlag
    });
    win.dialog('open');
}

//格式化字符串
String.prototype.format = function (args) {
    var result = this;
    if (arguments.length > 0) {
        if (arguments.length == 1 && typeof (args) == "object") {
            for (var key in args) {
                if (args[key] != undefined) {
                    var reg = new RegExp("({" + key + "})", "g");
                    result = result.replace(reg, args[key]);
                }
            }
        }
        else {
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] != undefined) {
                    var reg = new RegExp("({)" + i + "(})", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
    }
    return result;
}
//序列化
//JSON.stringify = JSON.stringify || function (obj) {
//    var t = typeof (obj);
//    if (t != "object" || obj === null) {
//        // simple data type
//        if (t == "string") obj = '"' + obj + '"';
//        return String(obj);
//    }
//    else {
//        // recurse array or object
//        var n, v, json = [], arr = (obj && obj.constructor == Array);
//        for (n in obj) {
//            v = obj[n]; t = typeof (v);
//            if (t == "string") v = '"' + v + '"';
//            else if (t == "object" && v !== null) v = JSON.stringify(v);
//            json.push((arr ? "" : '"' + n + '":') + String(v));
//        }
//        return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
//    }
//};
