function Permit() {
    $.ajax({
        type: "get",
        dataType: "html",
        url: "?type=permit&r=" + Math.random(),
        async: false,
        beforeSend: function (XMLHttpRequest) { },
        success: function (data) {
            if (data != "")
                $("#install").html(data);
            else
                Check();
        },
        error: function () { }
    });
}

function Check() {
    $.ajax({
        type: "get",
        dataType: "html",
        url: "?type=agreement&r=" + Math.random(),
        async: false,
        beforeSend: function (XMLHttpRequest) { },
        success: function (data) {
            $("#install").html(data);
        },
        error: function () { }
    });
}

function Install() {
    $.ajax({
        type: "get",
        dataType: "html",
        url: "?type=install" + SqlParm() + "&r=" + Math.random(),
        async: false,
        beforeSend: function (XMLHttpRequest) { },
        success: function (data) {
            $("#install").html(data);
            $("#install dl dt input[type=checkbox]").click(function () { CheckboxAll(this); });
        },
        error: function () { }
    });
}

function Submit(type) {
    $.ajax({
        type: "post",
        dataType: "html",
        data: $('#myformadu').serialize(),
        url: "?type=" + type + SqlParm() + "&r=" + Math.random(),
        beforeSend: function (XMLHttpRequest) {
            BtnDisabled(true);
        },
        success: function (data) {
            SubmitResult(data);
            BtnDisabled(false);
        },
        error: function () {
            BtnDisabled(false);
        }
    });
}

function SubmitConfirm(type, text) {
    if (confirm(text))
        Submit(type);
}

function SubmitResult(data) {
    var result = eval("(" + data + ")");
    if (result != null) {
        if (result.result == "success") {
            if (result.msg != "")
                alert(result.msg);
            if (result.href != "")
                location.href = result.href;
        } else {
            if (result.msg != "")
                alert(result.msg);
            if (result.href != "")
                location.href = result.href;
        }
    } else { alert(data); }
}

function SqlParm() {
    var str = "";

    if (QueryString("cdkey") != "")
        str += "&cdkey=" + QueryString("cdkey");

    return str;
}

function QueryString(name) { //获取url请求地址
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return "";
}

function CheckboxAll(obj) {
    var ck = $(obj).is(':checked');
    $(obj).parent().parent().nextUntil('dt').each(function () {
        $(this).find("input[type=checkbox]").attr("checked", ck);
    });
}

function BtnDisabled(bit) { //禁用或启用页面按钮
    if (bit)
        $(".installbtn").attr("disabled", "disabled");
    else
        $(".installbtn").removeAttr("disabled");
}