﻿function ResumeError() {
    return true;
}
window.onerror = ResumeError;
function GoBoard(no) {
    if (no == "1") {
        document.getElementById('BoardContainer01').style.display = "none";
        document.getElementById('BoardContainer02').style.display = "block";
        document.getElementById('BoardContainer03').style.display = "none";
        document.getElementById('BoardContainer04').style.display = "none";
    } else if (no == "2") {
        document.getElementById('BoardContainer01').style.display = "none";
        document.getElementById('BoardContainer02').style.display = "none";
        document.getElementById('BoardContainer03').style.display = "block";
        document.getElementById('BoardContainer04').style.display = "none";
    } else if (no == "3") {
        document.getElementById('BoardContainer01').style.display = "none";
        document.getElementById('BoardContainer02').style.display = "none";
        document.getElementById('BoardContainer03').style.display = "none";
        document.getElementById('BoardContainer04').style.display = "block";
    } else {
        document.getElementById('BoardContainer01').style.display = "block";
        document.getElementById('BoardContainer02').style.display = "none";
        document.getElementById('BoardContainer03').style.display = "none";
        document.getElementById('BoardContainer04').style.display = "none";
    }
}
function MM_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && document.getElementById) x = document.getElementById(n); return x;
}
function MM_showHideLayers() {
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v = 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}
function MM_preloadImages() {
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}
function MM_swapImgRestore() {
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_swapImage() {
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function goMenu(Val, Sel) {
    Sel.value = '';
    if (Val) location = Val;

}
function ResizeFrame() {
    var obj;
    if (parent != null) {
        obj = parent.document.all[self.name];
        if (obj != null) {
            obj.style.pixelWidth = self.document.body.scrollWidth; obj.style.pixelHeight = self.document.body.scrollHeight;
        }
    }
}
function CheckLoginValue(obj) {
    var username = document.getElementById('username');
    var password = document.getElementById('password');
    var code = document.getElementById('code');
    var expiress = document.getElementById('expiress').value;

    if (username.value == '') {
        alert("请输入您的用户名！");
        username.focus();
        return false;
    }

    if (password.value == '') {
        alert("请输入您的帐号密码！");
        password.focus();
        return false;
    }
    if (code.value.length != 4) {

        alert("请输入验证码！");
        code.focus();
        return false;
    }
    document.getElementById('LoginArea').innerHTML = "<div style='margin:15px'><img src='/images/progressbar.gif'></div>";
    AjaxHelper.Updater('/usercontrols/' + obj + '.ascx', 'LoginArea', 'act=check&username=' + encodeURIComponent(username.value) + '&password=' + encodeURIComponent(password.value) + '&code=' + code.value + '&expiress=' + expiress);
}

if (!Array.prototype.push) {
    Array.prototype.push = function() {
        var startLength = this.length;
        for (var i = 0; i < arguments.length; i++)
            this[startLength + i] = arguments[i];
        return this.length;
    }
}
if (!Function.prototype.apply) {
    // Based on code from http://www.youngpup.net/
    Function.prototype.apply = function(object, parameters) {
        var parameterStrings = new Array();
        if (!object) object = window;
        if (!parameters) parameters = new Array();

        for (var i = 0; i < parameters.length; i++)
            parameterStrings[i] = 'x[' + i + ']';

        object.__apply__ = this;
        var result = eval('obj.__apply__(' +
parameterStrings[i].join(', ') + ')');
        object.__apply__ = null;

        return result;
    }
}
var Prototype = {
    Version: '@@VERSION@@'
}

var Class = {
    create: function() {
        return function() {
            this.initialize.apply(this, arguments);
        }
    }
}
var Abstract = new Object();
Object.prototype.extendss = function(object) {
    for (property in object) {
        this[property] = object[property];
    }
    return this;
}

Function.prototype.bind = function(object) {
    var method = this;
    return function() {
        method.apply(object, arguments);
    }
}

Function.prototype.bindAsEventListener = function(object) {
    var method = this;
    return function(event) {
        method.call(object, event || window.event);
    }
}

Number.prototype.toColorPart = function() {
    var digits = this.toString(16);
    if (this < 16) return '0' + digits;
    return digits;
}

var Try = {
    these: function() {
        var returnValue;

        for (var i = 0; i < arguments.length; i++) {
            var lambda = arguments[i];
            try {
                returnValue = lambda();
                break;
            } catch (e) { }
        }

        return returnValue;
    }
}
var PeriodicalExecuter = Class.create();
PeriodicalExecuter.prototype = {
    initialize: function(callback, frequency) {
        this.callback = callback;
        this.frequency = frequency;
        this.currentlyExecuting = false;

        this.registerCallback();
    },

    registerCallback: function() {
        setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
    },

    onTimerEvent: function() {
        if (!this.currentlyExecuting) {
            try {
                this.currentlyExecuting = true;
                this.callback();
            } finally {
                this.currentlyExecuting = false;
            }
        }

        this.registerCallback();
    }
}
function $Get() {
    var elements = new Array();

    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        try {
            if (typeof element == 'string')
                element = document.getElementById(element) || document.all(element) || document.forms(0).all(element);
        }
        catch (ex) {
            element = null;
        }

        if (arguments.length == 1)
            return element;

        elements.push(element);
    }

    return elements;
}
var Ajax = {
    getTransport: function() {
        return Try.these(
function() { return new ActiveXObject('Msxml2.XMLHTTP') },
function() { return new ActiveXObject('Microsoft.XMLHTTP') },
function() { return new XMLHttpRequest() }
) || false;
    },

    emptyFunction: function() { }
}

Ajax.Base = function() { };
Ajax.Base.prototype = {
    setOptions: function(options) {
        this.options = {
            method: 'post',
            asynchronous: true,
            parameters: ''
}.extendss(options || {});
        }
    }

    Ajax.Request = Class.create();
    Ajax.Request.Events =
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];

    Ajax.Request.prototype = (new Ajax.Base()).extendss({
        initialize: function(url, options) {
            this.transport = Ajax.getTransport();
            this.setOptions(options);

            try {
                if (this.options.method == 'get')
                    url += '?' + this.options.parameters + '&_=';

                this.transport.open(this.options.method, url, true);

                if (this.options.asynchronous) {
                    this.transport.onreadystatechange = this.onStateChange.bind(this);
                    setTimeout((function() { this.respondToReadyState(1) }).bind(this), 10);
                }

                this.transport.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
                this.transport.setRequestHeader('X-Prototype-Version', Prototype.Version);

                if (this.options.method == 'post') {
                    this.transport.setRequestHeader('Connection', 'close');
                    this.transport.setRequestHeader('Content-type',
'application/x-www-form-urlencoded');
                }

                this.transport.send(this.options.method == 'post' ?
this.options.parameters + '&_=' : null);

            } catch (e) {
            }
        },

        onStateChange: function() {
            var readyState = this.transport.readyState;
            if (readyState != 1)
                this.respondToReadyState(this.transport.readyState);
        },

        respondToReadyState: function(readyState) {
            var event = Ajax.Request.Events[readyState];
            (this.options['on' + event] || Ajax.emptyFunction)(this.transport);
        }
    });

    Ajax.Updater = Class.create();
    Ajax.Updater.prototype = (new Ajax.Base()).extendss({
        initialize: function(container, url, options) {
            this.container = $Get(container);
            this.setOptions(options);

            if (this.options.asynchronous) {
                this.onComplete = this.options.onComplete;
                this.options.onComplete = this.updateContent.bind(this);
            }

            this.request = new Ajax.Request(url, this.options);

            if (!this.options.asynchronous)
                this.updateContent();
        },

        updateContent: function() {
            if (this.options.insertion) {
                new this.options.insertion(this.container,
this.request.transport.responseText);
            } else {
                this.container.innerHTML = this.request.transport.responseText;
            }

            if (this.onComplete) {
                setTimeout((function() { this.onComplete(this.request) }).bind(this), 10);
            }
        }
    });
    var Field = {
        clear: function() {
            for (var i = 0; i < arguments.length; i++)
                $Get(arguments[i]).value = '';
        },

        focus: function(element) {
            $Get(element).focus();
        },

        present: function() {
            for (var i = 0; i < arguments.length; i++)
                if ($Get(arguments[i]).value == '') return false;
            return true;
        },

        select: function(element) {
            $Get(element).select();
        },

        activate: function(element) {
            $Get(element).focus();
            $Get(element).select();
        }
    }
    var Form = {
        serialize: function(form) {
            var elements = Form.getElements($Get(form));
            var queryComponents = new Array();

            for (var i = 0; i < elements.length; i++) {
                var queryComponent = Form.Element.serialize(elements[i]);
                if (queryComponent)
                    queryComponents.push(queryComponent);
            }

            return queryComponents.join('&');
        },

        getElements: function(form) {
            form = $Get(form);
            var elements = new Array();

            for (tagName in Form.Element.Serializers) {
                var tagElements = form.getElementsByTagName(tagName);
                for (var j = 0; j < tagElements.length; j++)
                    elements.push(tagElements[j]);
            }
            return elements;
        },

        disable: function(form) {
            var elements = Form.getElements(form);
            for (var i = 0; i < elements.length; i++) {
                var element = elements[i];
                element.blur();
                element.disable = 'true';
            }
        },

        focusFirstElement: function(form) {
            form = $Get(form);
            var elements = Form.getElements(form);
            for (var i = 0; i < elements.length; i++) {
                var element = elements[i];
                if (element.type != 'hidden' && !element.disabled) {
                    Field.activate(element);
                    break;
                }
            }
        },

        reset: function(form) {
            $Get(form).reset();
        }
    }

    Form.Element = {
        serialize: function(element) {
            element = $Get(element);
            var method = element.tagName.toLowerCase();
            var parameter = Form.Element.Serializers[method](element);

            if (parameter)
                return encodeURIComponent(parameter[0]) + '=' +
encodeURIComponent(parameter[1]);
        },

        getValue: function(element) {
            element = $Get(element);
            var method = element.tagName.toLowerCase();
            var parameter = Form.Element.Serializers[method](element);

            if (parameter)
                return parameter[1];
        }
    }

    Form.Element.Serializers = {
        input: function(element) {
            switch (element.type.toLowerCase()) {
                case 'hidden':
                case 'password':
                case 'text':
                    return Form.Element.Serializers.textarea(element);
                case 'checkbox':
                case 'radio':
                    return Form.Element.Serializers.inputSelector(element);
            }
            return false;
        },

        inputSelector: function(element) {
            if (element.checked)
                return [element.name, element.value];
        },

        textarea: function(element) {
            return [element.name, element.value];
        },

        select: function(element) {
            var index = element.selectedIndex;
            var value = element.options[index].value || element.options[index].text;
            return [element.name, (index >= 0) ? value : ''];
        }
    }
    var $F = Form.Element.getValue;
    Abstract.TimedObserver = function() { }
    Abstract.TimedObserver.prototype = {
        initialize: function(element, frequency, callback) {
            this.frequency = frequency;
            this.element = $Get(element);
            this.callback = callback;

            this.lastValue = this.getValue();
            this.registerCallback();
        },

        registerCallback: function() {
            setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
        },

        onTimerEvent: function() {
            var value = this.getValue();
            if (this.lastValue != value) {
                this.callback(this.element, value);
                this.lastValue = value;
            }

            this.registerCallback();
        }
    }

    Form.Element.Observer = Class.create();
    Form.Element.Observer.prototype = (new Abstract.TimedObserver()).extendss({
        getValue: function() {
            return Form.Element.getValue(this.element);
        }
    });

    Form.Observer = Class.create();
    Form.Observer.prototype = (new Abstract.TimedObserver()).extendss({
        getValue: function() {
            return Form.serialize(this.element);
        }
    });
    var AjaxProxyUrl = new String("/Common/ajax.aspx");

    var AjaxHelper =
{

    Updater: function(ajaxTemplate, output, params, onComplete) {
        if (typeof output == 'string') {
            output = $Get(output);
        }

        var FormatContent = function(str) {
            var content = new String(str);
            var prefix = new String("<!--AjaxContent-->");
            content = content.substring(content.indexOf(prefix, 0) + prefix.length, content.length - 9);
            return content;
        }

        this.result = "1";
        new Ajax.Request(AjaxProxyUrl,
{ onComplete: function(transport) {
    if (output != null)
    { output.innerHTML = FormatContent(transport.responseText); }
    if (onComplete != null)
    { onComplete(FormatContent(transport.responseText)) }
}, parameters: params + '&AjaxTemplate=' + ajaxTemplate
});

        return this.result;
    },


    SerializeForm: function(form) {
        return Form.serialize(form);
    }

}

    function DOKEE_SITE(category1, category2) {
        switch (category1) {
            case 0:
                if (category2 == 1) document.location.href = "/";
                else if (category2 == 2) {
                    thisCookie = document.cookie.split("; ");
                    playerCookie = false;
                    for (i = 0; i < thisCookie.length; i++) {
                        cookieName = thisCookie[i].split("=")[0]
                        if ((cookieName == "expiredt") && (thisCookie[i].split("=")[1] == "Y")) {
                            playerCookie = true;
                        }
                    }

                    var winObj = null;
                    var w = 300;
                    var h = 305;
                    var url = "/";
                    var winl = screen.width - 300;
                    var wint = 0;
                    winprops = 'width=' + w + ',height=' + h + ',top=' + wint + ',left=' + winl + ',resizable=no,scrollbars=no,status=no,menu=no';

                    function aloneOpenWin() {

                        if (winObj == null || winObj.closed) {
                            //alert(winObj);
                            winObj = window.open(url, "player", winprops);
                        }
                        else {
                            winObj.focus();
                        }
                    }

                    if (!playerCookie) {
                        aloneOpenWin();
                    }
                }
                break;
            case 1: //兵团
                if (category2 == 1) document.location.href = "/team/"; 		  //兵团分布
                else if (category2 == 2) document.location.href = "/team/teamrank.aspx"; //兵团排行
                else if (category2 == 3) document.location.href = "/team/teamrec.aspx"; //兵团招募
                else if (category2 == 4) document.location.href = "/team/teamlevel.aspx"; //兵团级别
                else if (category2 == 5) document.location.href = "/team/teamsearch.aspx"; //兵团列表
                else if (category2 == 6) document.location.href = "/team/teamspace.aspx"; //兵团空间
                break;
            case 2: //游戏
                if (category2 == 1) document.location.href = "/game/"; 		  //服务器
                else if (category2 == 2) document.location.href = "/game/Battle.aspx";  //约战
                else if (category2 == 3) document.location.href = "/game/prison.aspx";  //监狱
                else if (category2 == 4) document.location.href = "/game/down.aspx";  //下载
                else if (category2 == 5) document.location.href = "/game/GameOP.aspx";  //豆官
                else if (category2 == 6) document.location.href = "/game/newmap.aspx";  //地图
                else if (category2 == 7) document.location.href = "/game/Demo.aspx";  //DEOM上传
                break;
            case 3: //赛事
                if (category2 == 1) document.location.href = "/match/";
                break;
            case 4: //排行
                if (category2 == 1) document.location.href = "/rank/";
                else if (category2 == 2) document.location.href = "/stats/classtop.aspx";
                else if (category2 == 3) document.location.href = "/rank/location/";
                break;
            case 5: //道具
                if (category2 == 1) document.location.href = "/shop/";
                break;
            case 6: //充值
                if (category2 == 1) document.location.href = "/pay/";
                break;
            case 7: //客服
                if (category2 == 1) document.location.href = "/service/"; 			//FAQ列表
                else if (category2 == 2) document.location.href = "/service/userask.aspx"; //问题提问
                else if (category2 == 3) document.location.href = "/service/ServiceInfo.aspx"; //客服团队
                else if (category2 == 4) document.location.href = "/service/instance.aspx"; //对豆客的建议
                else if (category2 == 5) document.location.href = "/service/MyQuestion.aspx"; //我的问题[建议]
                break;
            case 8: //博客
                if (category2 == 1) document.location.href = "http://dokeebar.ux2008.com";
                break;
//            case 9: //论坛
//                if (category2 == 1) document.location.href = "/bbs/";
//                break;
        }
    }


    function go() {
        var rad = document.getElementsByName("radio");
        var name = document.getElementById("myusername").value;
        var obj = document.getElementById("search_result");
        var html = "<h1>温馨提示</h1><p>系统正在查询相匹配的用户，请稍候....</p>";
        var type;
        var len = rad.length;
        for (var i = 0; i < len; i++) {
            if (rad[i].checked) {
                type = rad[i].value;
            }
        }
        //非空验证
        if (name == "") { alert("请输入精确的玩家信息！"); return false; }
        //验证 数字id为 数字
        if (rad[0].checked) {
            if (!IsNum(name)) {
                alert("数字ID必须为整数！");
                return false;
            }
        }
        obj.innerHTML = html;
        document.getElementById("searchImage").src = "images/main/pro2.gif";
        document.getElementById("searchA").onclick = function() { return false };
        $.ajax({ url: '/ajaxpage/temp/SearchUser.aspx', type: 'POST', dataType: 'html', data: "type=" + type + "&name=" + name + "",
            error: function(e) { return; }, success: callback
        });

    }
    // 根据条件 返回 uid ，跳转到指定的页面
    function callback(uid) {
        document.getElementById("searchA").onclick = go;
        document.getElementById("searchImage").src = "images/main/u_s_btn.gif";
        var obj = document.getElementById("search_result");
        var html = "<h1 style=\"color:#FAC432\">搜索结果</h1>";
        if (uid != null && uid != 0) {
            html += "<p><a href=\"/stats/personal-" + uid + ".html\" target = \"_blank\"> 恭喜您，系统为您找到了的匹配用户，点击查看详情！</a></p>";
        } else {
            html += "<p>对不起，系统仅提供精确搜索，没有找到匹配用户！</p>";
        }
        obj.innerHTML = html;
    }
    function IsNum(num) {
        var reNum = /^\d*$/;
        return (reNum.test(num));
    }