function addCookie() {
    if (document.all) {
        window.external.addFavorite("http://www.969w.com/index.html", "百家乐棋牌娱乐中心");
    }
    else if (window.sidebar) {
        window.sidebar.addPanel("百家乐棋牌娱乐中心", "http://www.969w.com/index.html", "");
    }
}

function setHomepage() {
    if (document.all) {
        document.body.style.behavior="url(#default#homepage)";
        document.body.setHomePage("http://www.969w.com/index.html");
    }
    else if (window.sidebar) {
        if(window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            catch (e) {
                alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
                return;
            }
        }
        var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref("browser.startup.homepage", "http://www.969w.com/index.html");
    }
}

try {
    jQuery.fn.extend({
        pressEnter: function(fun) {
            this.keypress(function(e) {
                if (e.which == "13") {
                    fun();
                }
            });
        }
    });
}
catch (e) { }

function QueryString(qs) {
    var s = location.href;
    s = s.replace("?", "?&").split("&");
    var re = "";
    for(i = 1; i < s.length; i++) {
        if (s[i].indexOf(qs + "=") != -1) { re = s[i].replace(qs + "=", ""); break;}
    }
    return re;
}

function getNumCode() {
    $("#numcode").attr("src", "NumCode.asp?rnd=" + Math.random());
}

function getNumCode1() {
    $("#numcode1").attr("src", "NumCode.asp?rnd=" + Math.random());
}

function getRegNumCode() {
    $("#numcode").attr("src", "RegNumCode.asp?rnd=" + Math.random());
}

function getMBNumCode() {
    $("#mbnumcode").attr("src", $("#mbnumcode").attr("src") + "&rnd=" + Math.random());
}

function Ajax(url, bcallback, scallback, ecallback, ajid, tar, pars) {
    var options = {
        data: pars,
        url: url,
        type: "post",
        beforeSend: function(data) { if (!ajid) { bcallback() } },
        beforeSubmit: function(formData, jqForm) { return bcallback(jqForm) },
        //var queryString = $.param(formData);
        success: function(data) { scallback(data) },
        error: function(data, status) { ecallback(data.responseText) },
        target: tar ? "#" + tar : null,
        clearForm: false,
        resetForm: false
        //timeout: 3000
    };
    if (ajid) { $("#" + ajid).ajaxSubmit(options) }
    else { $.ajax(options) }
}

function AjaxSuccess(data, obj) {
    if (data.substr(0, sp.length) == sp) {
        //window.location = data.substr(sp.length);
        var f = document.createElement("form");
        f.method = "get";
        var url = data.substr(sp.length);
        var postUrl = url;
        if (url.indexOf("?") != -1) {
            var urlArr = url.split("?");
            postUrl = urlArr[0];
            var postData = urlArr[1];
            if (postData.indexOf("&") != -1) {
                var poData = postData.split("&");
                for (var i = 0; i < poData.length; i++) {
                    var pData = poData[i].split("=");
                    var input = document.createElement("input");
                    input.name = pData[0];
                    input.value = pData[1];
                    f.appendChild(input);
                }
            }
            else {
                var pData = postData.split("=");
                var input = document.createElement("input");
                input.name = pData[0];
                input.value = pData[1];
                f.appendChild(input);
            }
        }
        f.action = postUrl;
        f.target = "_self";
        document.body.appendChild(f);
        f.submit();
    }
    else if (data == "mb") {
        ShowMB(3);
    }
    else if (data == "sj") {
        ShowPhoneMB(3);
    }
    else if (data == "hm") {
        ShowHardMB();
    }
    else if (data != "") {
        $(obj).removeAttr("disabled");
        alert(data);
        try {
            if (location.href.indexOf("reg.shtml") == -1) {
                getNumCode();
                getNumCode1();
            }
            else {
                getRegNumCode();
            }
        }
        catch (e) { }
        //if (data.indexOf("验证码") != -1) {
            //if (location.href.indexOf("reg.shtml") == -1) {
                //getNumCode();
            //}
            //else {
                //getRegNumCode();
            //}
        //}
    }
}

var sp = "^|^";
var page = 1;
var onepagetol = 18;

function GetPage(pagetol, scallback) {
    if (Number(pagetol) > 0) {
        var iPages = Math.ceil(Number(pagetol / onepagetol));
        var html = [];
        html.push("共" + pagetol + "条记录　");
        html.push("页次<b>" + page + "</b>/" + iPages + "　");
        html.push("每页" + onepagetol + "条　");
        if (page == 1 || iPages == 1){ html.push("首页　上页　") }
        else { html.push("<a href='javascript:void(0)' onclick='page=1;" + scallback + "'>首页</a>　<a href='javascript:void(0)' onclick='page-=1;if(page<1){page=1};" + scallback + "'>上页</a>　") }
        if (page == iPages || iPages == 1){ html.push("下页　末页　") }
        else { html.push("<a href='javascript:void(0)' onclick='page+=1;if(page>" + iPages + "){page=" + iPages + "};" + scallback + "'>下页</a>　<a href='javascript:void(0)' onclick='page=" + iPages + ";" + scallback + "'>末页</a>　") }
        html.push("<input id='pagetxt' size='4' maxlength='4' onkeyup='value=value.replace(/[^0-9]/g,\"\");if(value>" + iPages + "){value=" + iPages + "}'> <input type='button' value=' 转到 ' class='btn' onclick='if(page!=$(\"#pagetxt\")[0].value){page=$(\"#pagetxt\")[0].value;" + scallback + "}'>");
        $("#pagehtml").html(html.join(""));
        $("#pagetxt").val(page);
    }
    else{
        $("#pagehtml").html("");
    }
}

function LoadIndexNewMarquee() {
    Ajax("Function.asp", function() { }, function(obj) { $("#newmarquee").html(obj) }, function(obj) { }, null, null, "action=getindexnewmarquee");
}

function LoadIndexNewList() {
    Ajax("Function.asp", function() { }, function(obj) { $("#newlist").html(obj) }, function(obj) { }, null, null, "action=getindexnewlist");
}

function LoadClientNewList(did, id) {
    Ajax("../Function.asp", function() { }, function(obj) { $("#" + did).html(obj) }, function(obj) { }, null, null, "action=getclientnewlist&id=" + id);
}

function LoadHotNewList(ishotnew, divid) {
    Ajax("Function.asp", function() { }, function(obj) { $("#" + divid).html(obj) }, function(obj) { }, null, null, ishotnew == 1 ? "action=gethotgamelist" : "action=getnewgamelist");
}

function LoadIndexLogin() {
    Ajax("Function.asp", function() { }, function(obj) { $("#logindiv").html(obj); $("#uname,#upwd,#ucode").pressEnter(function() { UserLogin(); }); }, function(obj) { }, null, null, "action=getindexlogin");
}

function LoadIndexFaqList() {
    Ajax("Function.asp", function() { }, function(obj) { $("#faqlist").html(obj) }, function(obj) { }, null, null, "action=getindexfaqlist");
}

function LoadNew(lb, pn){
    var id = QueryString("id");
    if (Number(id)) {
        $("#list1").css({display: "none"});
        $("#list2").css({display: ""});
        LoadNewContent(id);
    }
    else {
        $("#list1").css({display: ""});
        $("#list2").css({ display: "none" });
        if (pn == "rank") {
            onepagetol = 20;
        }
        else {
            onepagetol = 13;
        }
        LoadNewList(lb, pn);
    }
}

var newlb;
var newpn;

function LoadNewList(lb, pn) {
    newlb = lb;
    newpn = pn;
    Ajax("Function.asp", function() { }, function(obj) { LoadNewSuccess(obj) }, function(obj) { }, null, null, "action=getnewlist&lb=" + newlb + "&pn=" + newpn + "&pagetol=" + onepagetol + "&page=" + page);
}

function LoadNewSuccess(data) {
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        $("#newlist").html(str[1]);
        if (newpn == "rank") {
            $("#rankpm").html("（" + BuWei((page - 1) * onepagetol + 1, 1000) + "-" + BuWei(page * onepagetol, 1000) + "）名");
        }
        GetPage(str[0], "LoadNewList(" + newlb + ",\"" + newpn + "\")");
    }
}

function BuWei(nowint, maxint) {
    return Array(3).join("0").concat(nowint).slice(-3);
}

function LoadNewContent(id) {
    Ajax("Function.asp", function() { }, function(obj) { LoadNewSuccess1(obj) }, function(obj) { }, null, null, "action=getnewcontent&id=" + id);
}

function LoadNewSuccess1(data) {
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        $("#newtitle").html(str[0] + " <span style='font-size:12px'>[" + str[1] + "]</span>");
        $("#newcontent").html(str[2]);
    }
}

function UserLogin() {
    Ajax("Function.asp", function(obj) { return UserLoginBefore(obj) }, function(obj) { UserLoginSuccess(obj) }, function(obj) { }, "login", null, null);
}

function UserLoginBefore(jqForm) {
    var form = jqForm[0];
    if (!form.uname.value) {
        alert("请输入用户名");
        form.uname.focus();
        return false;
    }
    else if (!form.upwd.value) {
        alert("请输入用户密码");
        form.upwd.focus();
        return false;
    }
    else if (!form.ucode.value) {
        alert("请输入验证码");
        form.ucode.focus();
        return false;
    }
    $("#login input,img").attr("disabled", true);
    return true;
}

function UserLoginSuccess(data) {
    if (data == sp) {
        LoadIndexLogin()
    }
    else {
        AjaxSuccess(data, "#login input,img");
    }
}

function UserLoginOut(o) {
    if (o) {
        Ajax("Function.asp", function() { }, function(obj) { AjaxSuccess(obj, "") }, function(obj) { }, null, null, "action=loginout");
    }
    else {
        Ajax("Function.asp", function() { }, function(obj) { LoadIndexLogin() }, function(obj) { }, null, null, "action=loginout");
    }
}

function LoadClientIndexUserPhoto() {
    Ajax("../Function.asp", function() { }, function(obj) { MarPhoto1(obj) }, function(obj) { }, null, null, "action=getindexuserphoto");
}

function MarPhoto1(data) {
    $("#wanjiapic").html(data);
    new Marquee("wanjiapic", 2, 1, 641, 90, 20, 0, 0);
}

function LoadIndexUserPhoto() {
    Ajax("Function.asp", function() { }, function(obj) { MarPhoto(obj) }, function(obj) { }, null, null, "action=getindexuserphoto");
}

function MarPhoto(data) {
    $("#wanjiapic").html(data);
    new Marquee("wanjiapic", 2, 1, 454, 102, 20, 0, 0);
}

function LoadPhoto(uid, pn) {
    var id = QueryString("id");
    if (Number(id)) {
        $("#list1").css({display: "none"});
        $("#list2").css({display: ""});
        LoadPhotoContent(id);
    }
    else {
        $("#list1").css({display: ""});
        $("#list2").css({display: "none"});
        LoadPhotoList(uid, pn);
    }
}

var newuid = 0;

function LoadPhotoList(uid, pn) {
    onepagetol = 30;
    newuid = uid;
    newpn = pn;
    Ajax("Function.asp", function() { }, function(obj) { LoadPhotoSuccess(obj) }, function(obj) { }, null, null, "action=getphotolist&uid=" + newuid + "&pn=" + newpn + "&pagetol=" + onepagetol + "&page=" + page);
}

function LoadPhotoSuccess(data) {
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        $("#photolist").html(str[1]);
        GetPage(str[0], "LoadPhotoList(" + newuid + ", \"" + newpn + "\")");
    }
}

function LoadPhotoContent(id) {
    Ajax("Function.asp", function() { }, function(obj) { LoadPhotoSuccess1(obj) }, function(obj) { }, null, null, "action=getphotocontent&id=" + id);
}

function LoadPhotoSuccess1(data) {
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        $("#newtitle").html("昵称：" + str[0]);
        $("#photocontent").html(str[1]);
    }
}

function LoadGameDesContent(id) {
    Ajax("Function.asp", function() { }, function(obj) { LoadGameDesSuccess(obj) }, function(obj) { }, null, null, "action=getnewcontent&id=" + id);
}

function LoadGameDesContent1(id) {
    Ajax("Function.asp", function() { }, function(obj) { LoadGameDesSuccess(obj) }, function(obj) { }, null, null, "action=getnewcontent1&id=" + id);
}

function LoadGameDesSuccess(data) {
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        $("#gamedestitle").html(str[0]);
        $("#gamedescontent").html(str[2]);
    }
    else {
        $("#gamedestitle").html("");
        $("#gamedescontent").html("");
    }
}

function CheckUserName() {
    if ($("#regform").validate().element("#uname")){
        Ajax("Function.asp", function() { }, function(obj) { AjaxSuccess(obj) }, function(obj) { }, null, null, "action=checkusername&uname=" + $("#uname").val() + "&srcname=" + escape($("#srcname").val()));
    }
}

function CheckUserSrcName() {
    if ($("#regform").validate().element("#srcname")){
        Ajax("Function.asp", function() { }, function(obj) { AjaxSuccess(obj) }, function(obj) { }, null, null, "action=checkusersrcname&uname=" + $("#uname").val() + "&srcname=" + escape($("#srcname").val()));
    }
}

function LoadRegName(spread) {
    Ajax("Function.asp", function() { }, function(obj) { LoadRegNameSuccess(obj) }, function(obj) { }, null, null, "action=getregname&id=" + spread);
}

function LoadRegNameSuccess(data) {
    if (data != "") {
        $("#spread").val(data);
        $("#spread").attr("readonly", "readonly");
    }
}

function UserReg() {
    if ($("#protocol").attr("checked") == "") {
        alert("请确认您已阅读并同意服务协议");
    }
    else if ($("#regform").valid()) {
        Ajax("Function.asp", function() { $("#regform input,img").attr("disabled", true); return true }, function(obj) { UserRegSuccess(obj) }, function(obj) { }, "regform", null, null);
    }
}

function UserRegSuccess(data) {
    if (data.substr(0, sp.length) == sp) { alert("恭喜您已经注册成功！") }
    AjaxSuccess(data, "#regform input,img");
}

function UserGetPwd() {
    Ajax("Function.asp", function() { $("#getpwdform input,img").attr("disabled", true); return true }, function(obj) { UserGetPwdSuccess(obj) }, function(obj) { }, "getpwdform", null, null);
}

function UserGetPwdSuccess(data) {
    if (data.substr(0, sp.length) == sp) {
        alert("密码修改确认信已经发送到您的Email，请注意查收！");
        window.location = "user.asp";
    }
    else {
        AjaxSuccess(data, "#getpwdform input,img");
    }
}

function LoadGetPwdName(id) {
    Ajax("Function.asp", function() { }, function(obj) { LoadGetPwdNameSuccess(obj) }, function(obj) { }, null, null, "action=getpwdname&id=" + id);
}

function LoadGetPwdNameSuccess(data) {
    if (data == "") {
        $("#f1").css({ display: "none" });
        $("#f2").css({ display: "" });
    }
    else {
        $("#uname").html(data);
        $("#f1").css({ display: "" });
        $("#f2").css({ display: "none" });
    }
}

function UserEditGetPwd() {
    Ajax("Function.asp", function() { $("#getpwdform input,img").attr("disabled", true); return true }, function(obj) { AjaxSuccess(obj, "#getpwdform input,img") }, function(obj) { }, "getpwdform", null, null);
}

function LoadPayUName() {
    Ajax("Function.asp", function() { }, function(obj) { LoadPayUNameSuccess(obj) }, function(obj) { }, null, null, "action=getuserinfo");
}

function LoadPayUNameSuccess(data) {
    if (data.indexOf(sp) != -1) {
        var uname = data.split(sp)[0];
        $("#uname,#confirm_uname").val(uname);
        payrate = data.split(sp)[1];
    }
    else {
        payrate = data;
    }
    $("#prate").html("1 元人民币 = " + payrate + " 乐币");
}

function UserPay() {
    if ($("#payform").valid()) {
        Ajax("Function.asp", function() { $("#payform input,img").attr("disabled", true); return true }, function(obj) { PaySuccess(obj) }, function(obj) { }, "payform", null, null);
    }
}

function PaySuccess(data) {
    if (data.substr(0, sp.length) == sp) {
        if (data.indexOf("pay3") != -1) {
            AjaxSuccess(data, "#payform input,img");
        }
        else {
            tb_show("", "#TB_inline?height=70&width=200&inlineId=hiddendiv&modal=true", "");
            //window.open(data.substr(sp.length));
            window.location = data.substr(sp.length);
        }
    }
    else {
        AjaxSuccess(data, "#payform input,img");
    }
}

function UserKeepPay(payid) {
    Ajax("Function.asp", function() { }, function(obj) { PaySuccess(obj) }, function(obj) { }, null, null, "action=keepbankpay&payid=" + payid);
}

function UserEditInfo(o) {
    if (o || $("#editinfo").valid()) {
        Ajax("Function.asp", function() { $("#editinfo input,img").attr("disabled", true); return true }, function(obj) { AjaxSuccess(obj, "#editinfo input,img"); window.location.reload() }, function(obj) { }, "editinfo", null, null);
    }
}

function UserHardMBSet() {
    if ($("#hardmbset").valid()) {
        Ajax("Function.asp", function() { $("#hardmbset input,img").attr("disabled", true); return true }, function(obj) { AjaxSuccess(obj, "#hardmbset input,img"); window.location.reload() }, function(obj) { }, "hardmbset", null, null);
    }
}

function LoadBankTradeList() {
    onepagetol = 10;
    Ajax("Function.asp", function() { }, function(obj) { LoadBankTradeListSuccess(obj) }, function(obj) { }, null, null, "action=getbanktradelist&pagetol=" + onepagetol + "&page=" + page);
}

function LoadBankTradeListSuccess(data) {
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        if (str == "") {
            window.location = str[1];
        }
        else {
            $("#list").html(str[1]);
            GetPage(str[0], "LoadBankTradeList()");
        }
    }
}

function LoadPayList() {
    onepagetol = 10;
    $("#timesearch").attr("disabled", true);
    Ajax("Function.asp", function() { }, function(obj) { LoadPayListSuccess(obj) }, function(obj) { }, null, null, "action=getpaylist&timestart=" + $("#timestart").val() + "&timeend=" + $("#timeend").val() + "&pagetol=" + onepagetol + "&page=" + page);
}

function LoadPayListSuccess(data) {
    $("#timesearch").attr("disabled", false);
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        if (str == "") {
            window.location = str[1];
        }
        else {
            $("#list").html(str[1]);
            GetPage(str[0], "LoadPayList()");
        }
    }
}

function UserUpFace() {
    Ajax("Function.asp", function() { $("#upface input,img").attr("disabled", true); return true }, function(obj) { AjaxSuccess(obj, "#upface input,img"); }, function(obj) { }, "upface", null, null);
}

function GetRefUrl() {
    if (document.referrer.indexOf("dajiale365.com") == -1) {
        Ajax("Function.asp", function() { }, function(obj) { }, function(obj) { }, null, null, "action=getrefurl&refurl=" + document.referrer);
    }
}

function GetDownHits() {
    Ajax("Function.asp", function() { }, function(obj) { }, function(obj) { }, null, null, "action=getdownhits");
}

function LoadClientRank(id) {
    Ajax("../Function.asp", function() { }, function(obj) { $("#" + id).html(obj) }, function(obj) { }, null, null, "action=loadclientank&id=" + id);
}

function LoadItemsList() {
    onepagetol = 4;
    Ajax("Function.asp", function() { }, function(obj) { LoadItemsListSuccess(obj) }, function(obj) { }, null, null, "action=getitemslist&pagetol=" + onepagetol + "&page=" + page);
}

function LoadItemsListSuccess(data) {
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        $("#itemslist").html(str[1]);
        GetPage(str[0], "LoadItemsList()");
    }
}

function ShowMB(sid) {
    tb_show("密保验证", "showmb.asp?sid=" + sid + "&KeepThis=true&TB_iframe=true&height=150&width=270", "");
}

function ShowPhoneMB(sid) {
    tb_show("手机密保验证", "showphonemb.asp?sid=" + sid + "&KeepThis=true&TB_iframe=true&height=100&width=270", "");
}

function ShowHardMB() {
    tb_show("大家乐贴身保验证", "showhardmb.asp?KeepThis=true&TB_iframe=true&height=100&width=270", "");
}

function GoldIDSearch() {
    var goldvalue = "";
    var goldtype = "";
    $("input[name='goldvalue']").each(function() {
        if ($(this).attr("checked")) {
            goldvalue += $(this).attr("value") + ",";
        }
    });
    $("input[name='goldtype']").each(function() {
        if ($(this).attr("checked")) {
            goldtype += $(this).attr("value") + ",";
        }
    });
    Ajax("Function.asp", function() { $("input[type='checkbox']").attr("disabled", true); }, function(obj) { GoldIDSearchSuccess(obj) }, function(obj) { }, null, null, "action=goldidsearch&goldvalue=" + goldvalue + "&goldtype=" + goldtype);
}

function GoldIDSearchSuccess(data) {
    $("input[type='checkbox']").attr("disabled", false);
    if (data.indexOf(sp) != -1) {
        var str = data.split(sp);
        $("#goldidcontent").html(str[1]);
    }
}

function GoldIDPay() {
    Ajax("Function.asp", function() { $("#uname").attr("disabled", true); }, function(obj) { GoldIDPaySuccess(obj) }, function(obj) { }, null, null, "action=goldidpay&uname=" + escape($("#uname").val()));
}

function GoldIDPaySuccess(data) {
    $("#uname").attr("disabled", false);
    if (data.indexOf("成功") != -1) {
        window.location = "GoldIDOK.shtml";
    }
    else {
        alert(data);
    }
}

function HardMB(fid) {
    Ajax("Function.asp", function() { $("#hardmb" + fid + " input,img").attr("disabled", true); }, function(obj) { AjaxSuccess(obj, "#hardmb" + fid + " input,img"); if (obj.indexOf("成功") != -1) { window.location.reload() } }, function(obj) { }, "hardmb" + fid, null, null);
}
