/*Javascript设置要保留的小数位数，四舍五入。
*ForDight(Dight,How):数值格式化函数，Dight要格式化的 数字，How要保留的小数位数。
*这里的方法是先乘以10的倍数，然后去掉小数，最后再除以10的倍数。
*/
function ForDight(Dight, How) {
    Dight = Math.round(Dight * Math.pow(10, How)) / Math.pow(10, How);
    return Dight;
}
function CommonAjax(TimeOutminSecs, ApiFile, ParData, MsgClassName, DoingMsg, disOBJ, OkMsg, ErrMsg) {
    $("." + MsgClassName).html(DoingMsg);
    disOBJ.attr("disabled", "disabled");
    if (ApiFile.indexOf("?") >= 0) {
        ApiFile = ApiFile + "&Rnd=" + Math.random();
    } else {
        ApiFile = ApiFile + "?Rnd=" + Math.random();
    }
    $.ajax({
        type: "get",
        url: ApiFile,
        dataType: "text",
        data: ParData,
        timeout: TimeOutminSecs,
        success: function (data) {
            disOBJ.removeAttr("disabled");
            if (data == "True")
                $("." + MsgClassName).html(OkMsg);
            else
                $("." + MsgClassName).html(data);
        },
        error: function (err) {
            $("." + MsgClassName).html(ErrMsg);
            disOBJ.removeAttr("disabled");
        }
    });
}
function DeleteAjax(TimeOutminSecs, u, ParData) {
    if (u.indexOf("?") >= 0) {
        u = u + "&Rnd=" + Math.random();
    } else {
        u = u + "?Rnd=" + Math.random();
    }
    $.ajax({
        type: "get",
        url: u,
        dataType: "text",
        data: ParData,
        timeout: TimeOutminSecs,
        success: function (data) {
            if (data == "True") {
                $(this).dialog("close");
                document.location.reload();
            }
            else {
                $(".newui-icon-alert").html("");
                $(".msg").html("删除失败：" + data);
            }
        },
        error: function (err) {
            $(".newui-icon-alert").html("");
            $(".msg").html("删除错误，请刷新本页面再做尝试");
        }
    });
}
function CommonGetAjax(TimeOutminSecs, ApiFile, ParData, innerOBJ, errMsg) {
    if (ApiFile.indexOf("?") >= 0) {
        ApiFile = ApiFile + "&Rnd=" + Math.random();
    } else {
        ApiFile = ApiFile + "?Rnd=" + Math.random();
    }
    $.ajax({
        type: "get",
        url: ApiFile,
        dataType: "text",
        data: ParData,
        timeout: TimeOutminSecs,
        success: function (data) {

            innerOBJ.html(data);
        },
        error: function (err) {
            innerOBJ.html(errMsg);
        }
    });
}
function CommonEventAsyncAjax(ApiFile, ParData, DoEvent) {
    if (ApiFile.indexOf("?") >= 0) {
        ApiFile = ApiFile + "&Rnd=" + Math.random();
    } else {
        ApiFile = ApiFile + "?Rnd=" + Math.random();
    }
    $.ajax({
        type: "get",
        url: ApiFile,
        dataType: "text",
        data: ParData,
        async: false,
        success: function (data) {
            DoEvent(data);
        },
        error: function (err) {
            //alert("系统错误：" + err);
        }
    });
}
function CommonEventAjax(TimeOutminSecs, ApiFile, ParData, DoEvent) {
    if (ApiFile.indexOf("?") >= 0) {
        ApiFile = ApiFile + "&Rnd=" + Math.random();
    } else {
        ApiFile = ApiFile + "?Rnd=" + Math.random();
    }
    $.ajax({
        type: "get",
        url: ApiFile,
        dataType: "text",
        data: ParData,
        timeout: TimeOutminSecs,
        success: function (data) {
            DoEvent(data);
        },
        error: function (err) {
            //alert("系统错误：" + err);
        }
    });
}
function AjaxForDomainAppend(TimeOutminSecs, ApiFile, ParData, innerOBJ, errMsg, ClearMsg) {
    if (ApiFile.indexOf("?") >= 0) {
        ApiFile = ApiFile + "&Rnd=" + Math.random();
    } else {
        ApiFile = ApiFile + "?Rnd=" + Math.random();
    }
    $.ajax({
        type: "get",
        url: ApiFile,
        dataType: "text",
        data: ParData,
        timeout: TimeOutminSecs,
        //async:false,
        success: function (data) {
            innerOBJ.append(data);
            innerOBJ.html(innerOBJ.html().replace(ClearMsg, ""));
        },
        error: function (err) {
            innerOBJ.append(errMsg);
        }
    });
}
function AjaxForAppend(TimeOutminSecs, ApiFile, ParData, innerOBJ, errMsg) {
    if (ApiFile.indexOf("?") >= 0) {
        ApiFile = ApiFile + "&Rnd=" + Math.random();
    } else {
        ApiFile = ApiFile + "?Rnd=" + Math.random();
    }
    $.ajax({
        type: "get",
        url: ApiFile,
        dataType: "text",
        data: ParData,
        timeout: TimeOutminSecs,
        success: function (data) {
            innerOBJ.append(data);
        },
        error: function (err) {
            innerOBJ.append(errMsg);
        }
    });
}
function getUrlVars(url) {
    var vars = [], hash;
    var hashes = url.slice(url.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function getUrlVar(url, name) {
    return getUrlVars(url)[name];
}


function updateTips(t, tipsname) {
    tips = $("." + tipsname);
    tips.removeClass("ui-help-inline").addClass("ui-help-float").html("<img src=\"/Common/Images/false.png\" /> " + t);

}
function checkLength(o, n, min, max) {
    if (!o[0]) {
        return true;
    }
    if (o.val().length > max || o.val().length < min) {
        updateTips(n + "必须在" + min + "到" + max + "位之间", o.attr("id"));

        return false;
    } else {
        $("." + o.attr("id")).html("<img src=\"/Common/Images/true.png\" />");
        return true;

    }
}
function checkRegexp(o, regexp, n) {
    if (!o[0]) {
        return true;
    }
    if (!(regexp.test(o.val()))) {
        o.addClass("ui-state-error");
        updateTips(n, o.attr("id"));
        return false;
    } else {
        $("." + o.attr("id")).html("<img src=\"/Common/Images/true.png\" />");
        return true;
    }

}
function checkCheckBoxIsCheck(o, n) {
    if (!o[0]) {
        return true;
    }
    if (!o.attr("checked")) {
        o.addClass("ui-state-error");
        updateTips(n, o.attr("id"));
        return false;
    } else {
        $("." + o.attr("id")).html("<img src=\"/Common/Images/true.png\" />");
        return true;
    }

}
function checkNumlength(o, n, min, max) {
    if (!o[0]) {
        return true;
    }
    regexp = /^[0-9]+(\.?[0-9]{1,})?$/;
    if (!regexp.test(o.val())) {
        o.addClass("ui-state-error");
        updateTips(n + "必须为数值", o.attr("id"));
        return false;
    } else {
        var l = o.val() - 0;
        if (l < min || l > max) {
            o.addClass("ui-state-error");
            updateTips(n + "有效范围" + min + "到" + max + "之间", o.attr("id"));
            return false;
        }
        else {
            $("." + o.attr("id")).html("<img src=\"/Common/Images/true.png\" />");
            return true;
        }
    }

}
function checkEquals(n, o, o1) {
    if (!o[0]) {
        return true;
    }
    if (o.val() != o1.val()) {
        o1.addClass("ui-state-error");
        updateTips("两次" + n + "输入不一致", o1.attr("id"));
        return false;
    }
    else {
        $("." + o.attr("id")).html("<img src=\"/Common/Images/true.png\" />");
        $("." + o1.attr("id")).html("<img src=\"/Common/Images/true.png\" />");
        return true;
    }

}
function getUrlVaule(key) {
    var url = document.location.href;
    var urlarr = url.split('?');
    var returnstring = "";
    if (urlarr.length > 1) {
        urlarr = urlarr[1].split('&');
        for (var i = 0; i < urlarr.length; i++) {
            var marr = urlarr[i].split('=');
            if (marr[0].toLowerCase() == key.toLowerCase()) {
                returnstring = marr[1];
            }
        }
    }
    return returnstring;
}
function isChn(str) {
    var reg = /[\u4E00-\u9FA5]+/;
    if (!reg.test(str)) {
        return false;
    }
    return true;
}
$(function () {
    $(".cmbox").click(function () {
        if (confirm("您确定要执行此项操作吗？")) {
            return true;
        }
        else {
            return false;
        }
    });
});