/**
 * Copyright (c) 2008, 新浪网支付中心
 * All rights reserved.
 *
 * 文件名称：sinapay.js
 * 摘    要：webgame登录用
 * 作    者：常川
 * 版    本：1.0
 * 修改日期:2008.4.10
 */
/*--E X I T W E B--*/
function unipro_clearCookie(name){
    document.cookie = name + "=; " + "domain=sina.com.cn; path=/; ";
}

function pay_clearCookie(name){
    document.cookie = name + "=; " + "domain=pay.sina.com.cn; path=/; ";
}

function UniProLogout(){
    unipro_clearCookie("SINAPRO");
    unipro_clearCookie("SINA-AVATAR");
    unipro_clearCookie("SINAPROC");
    unipro_clearCookie("nick");
    unipro_clearCookie("SINA_NU");
    unipro_clearCookie("SINA_OU");
    unipro_clearCookie("appmask");
    unipro_clearCookie("gender");
    unipro_clearCookie("UNIPROTM");
    unipro_clearCookie("UNIPROU");
    unipro_clearCookie("SINA_USER");
    unipro_clearCookie("SMS_COOKIE");
    unipro_clearCookie("SID");
    //unipro_clearCookie("PAYSID");
    unipro_clearCookie("UNIPROM");
    return true;
}

function SinaPayLogout(){
    pay_clearCookie("PAYSID");
    pay_clearCookie("PayBalance");
    pay_clearCookie("PayPresent");
    pay_clearCookie("PayPoint");
    pay_clearCookie("datetime");
    pay_clearCookie("PPOINT");
    return true;
}

/***example:
 UniProLogout();
 SinaPayLogout();
 location.replace("http://pay.sina.com.cn");
 **/
/*=================*/
(function(){
    if (typeof SINAPAY == 'undefined') {
        window.SINAPAY = SINAPAY = {};
    };
    if (typeof SINAPAY.Dom == "undefined") 
        SINAPAY.Dom = {};
    
    SINAPAY.Debug = true;
    
    Array.prototype.include = function(s){
        for (var i = 0, len = this.length; i < len; i++) {
            if (this[i] == s) 
                return true;
        }
        return false;
    }
    SINAPAY.Dom.setOpactity = function(elem, val){
        if (document.all) {
            elem.style.filter = "alpha(opacity=" + val * 100 + ")";
        }
        else {
            elem.style.opacity = val;
        }
    };
    SINAPAY.Dom.getStyle = function(element, style){
        var elem = typeof element == "string" ? document.getElementById(element) : element;
        if (['float', 'cssFloat'].include(style.toLowerCase())) {
            style = (typeof elem.style.styleFloat != 'undefined' ? 'styleFloat' : 'cssFloat');
        }
        var value = elem.style[style];
        if (!value) {
            if (document.defaultView && document.defaultView.getComputedStyle) {
                var css = document.defaultView.getComputedStyle(elem, null);
                value = css ? css[style] : null;
            }
            else 
                if (elem.currentStyle) {
                    value = elem.currentStyle[style];
                }
        }
        if ((value == 'auto') && (['width', 'height'].include(style.toLowerCase())) && (SINAPAY.Dom.getStyle(elem, 'display') != 'none')) {
            value = elem['offset' + style.charAt(0).toUpperCase() + style.substring(1, style.length)] + 'px';
        }
        if (window.opera && (['left', 'top', 'right', 'bottom'].include(style.toLowerCase()))) {
            if (SINAPAY.Dom.getStyle(elem, 'position') == 'static') 
                value = 'auto';
        }
        if (style == 'opacity') {
            if (value) 
                return parseFloat(value);
            if (value = (SINAPAY.Dom.getStyle(elem, 'filter') || '').match(/alpha\(opacity=(.*)\)/)) 
                if (value[1]) 
                    return parseFloat(value[1]) / 100;
            return 1.0;
        }
        return value == 'auto' ? null : value;
    };
    
    SINAPAY.Fx = {};
    /**
     * <pre>Timer 类</pre>
     *
     * @param {Object} fnHandle					要间隔运行的函数
     * @param {Number} oTime					间隔时间
     * @param {Function|Number} mCondition		条件（function），或运行次数（number）
     */
    SINAPAY.Fx.Timer = function(fnHandle, oTime, mCondition){
        var _c = function(){
            return true;
        }
        var sum = 0;
        if (typeof mCondition == "function") {
            _c = mCondition;
        }
        if (typeof mCondition == "number") {
            sum = mCondition;
        }
        var tmpTime = window.setInterval(function(){
            if (sum != 0) {
                sum--;
            }
            if (sum > 0 || !_c()) {
                fnHandle();
            }
            else {
                window.clearInterval(tmpTime);
            }
        }, oTime);
    };
    /**
     * <pre>渐变显示对象</pre>
     * @param {Object} oEl			要show的对象
     * @param {Object} itime		动画时间
     */
    SINAPAY.Fx.show = function(oEl, itime){
        var _i = SINAPAY.Dom.getStyle(oEl, "opacity");
        var t = 0;
        var _step = _i / (itime || 1) / 25;
        SINAPAY.Dom.setOpactity(oEl, 0)
        SINAPAY.Fx.Timer(function(){
            t = (t + _step) <= _i ? (t + _step) : _i;
            SINAPAY.Dom.setOpactity(oEl, t);
        }, 40, function(){
            return t == _i;
        })
    };
    //-------------------------------------
    (function(){
        SINAPAY.HTTPp = HTTPp = {};
        HTTPp._factories = [function(){
            return new XMLHttpRequest();
        }, function(){
            return new ActiveXObject("Msxml2.XMLHTTP");
        }, function(){
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
];
        HTTPp._factory = null;
        HTTPp.newRequest = function(){
            if (HTTPp._factory != null) 
                return HTTPp._factory();
            
            for (var i = 0; i < HTTPp._factories.length; i++) {
                try {
                    var factory = HTTPp._factories[i];
                    var request = factory();
                    if (request != null) {
                        HTTPp._factory = factory;
                        return request;
                    }
                } 
                catch (e) {
                    continue;
                }
            }
            HTTPp._factory = function(){
                throw new Error("XMLHTTPRequest not supported");
            };
            HTTPp._factory();
        };
        HTTPp._getResponse = function(request){
            switch (request.getResponseHeader("Content-Type")) {
                case "text/xml":
                    return request.responseXML;
                    
                case "text/json":
                case "text/javascript":
                case "application/javascript":
                case "application/x-javascript":
                    var r = null;
                    try {
                        r = eval(request.responseText);
                    } 
                    catch (e) {
                    }
                    finally {
                        return r;
                    }
                default:
                    return request.responseText;
            }
        };
        
        HTTPp.encodeFormData = function(data){
            var pairs = [];
            var regexp = /%20/g;
            
            for (var name in data) {
                var value = data[name].toString();
                var pair = encodeURIComponent(name).replace(regexp, "+") + '=' +
                encodeURIComponent(value).replace(regexp, "+");
                pairs.push(pair);
            };
            return pairs.join('&');
        };
        HTTPp.send = function(method, url, callback, object, options){
            var request = HTTPp.newRequest();
            var n = 0;
            var timer;
            options = options ? options : {};
            if (options.timeout) {
                timer = setInterval(function(){
                    request.abort();
                    if (options.timeoutHandler) {
                        options.timeoutHandler();
                    }
                }, options.timeout);
            }
            request.onreadystatechange = function(){
                if (request.readyState == 4) {
                    if (timer) {
                        clearTimeout(timer);
                    }
                    if (request.status == 200) {
                        callback(HTTPp._getResponse(request));
                    }
                    else {
                        if (options.errHandler) {
                            options.errHandler(request.status, request.statusText);
                        }
                        else {
                            //callback(null);
                        }
                    }
                }
                else 
                    if (options.progressHandler) {
                        options.progressHandler(++n);
                    }
            };
            
            var target = url;
            var enCodeData = HTTPp.encodeFormData(object);
            var m_method = method.toUpperCase();
            var Syn = ((typeof options.syn) == "boolean") ? options.syn : true; //是不是异步的
            var userName = options.username || ""; //用户名
            var passWord = options.password || ""; //密码
            if (m_method == "GET") {
                if (options.parameters) {
                    target += "?" + enCodeData;
                }
                request.open("GET", target, Syn, userName, passWord);
                request.send(null);
            }
            else 
                if (m_method == "POST") {
                    request.open("POST", target, Syn, userName, passWord);
                    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    request.send(enCodeData);
                }
            return request;
        };
        HTTPp.get = function(sUrl, fnCallBack, oObject, oOptions){
            return HTTPp.send("GET", sUrl, fnCallBack, oObject, oOptions);
        };
        HTTPp.post = function(sUrl, fnCallBack, oObject, oOptions){
            return HTTPp.send("POST", sUrl, fnCallBack, oObject, oOptions);
        }
    })();
    //-----------------------------------------------------
    
    
    SINAPAY.toArray = function(obj){
        var a = [];
        for (var i = 0; i < obj.length; i++) {
            a.push(obj[i]);
        }
        return a;
    }
    SINAPAY.setCookie = function(sName, sValue, oExpires, sPath, sDomain, bSecure){
        sName = sName.replace(/\s+/, "");
        if (!sValue) {
            document.cookie = sName + "=";
            return;
        }
        
        
        
        var sCookie = sName + "=" + escape(sValue);
        if (oExpires) {
            sCookie += "; expires=" + oExpires.toGMTString()
        };
        if (sPath) {
            sCookie += "; path=" + sPath
        };
        if (sDomain) {
            sCookie += "; domain=" + sDomain
        };
        if (bSecure) {
            sCookie += "; secure"
        };
        document.cookie = sCookie;
    };
    SINAPAY.getCookie = function(sName){
        var sRE = "(?:; )?" + sName + "=([^;]*);?";
        var oRE = new RegExp(sRE);
        if (oRE.test(document.cookie)) {
            return unescape(RegExp["$1"]);			
			//decodeURIComponent(RegExp["$1"]);
        }
        else {
            return null;
        }
    };
    (function(){
        var sUserAgent = window.navigator.userAgent;
        var isOpera = sUserAgent.indexOf("Opera") > -1;
        var isKHTML = sUserAgent.indexOf("KHTML") > -1 ||
        sUserAgent.indexOf("Konqueror") > -1 ||
        sUserAgent.indexOf("AppleWebKit") < -1;
        var isIE = sUserAgent.indexOf("compatible") > -1 &&
        sUserAgent.indexOf("MSIE") > -1 &&
        !isOpera;
        var isMoz = isFF = sUserAgent.indexOf("Gecko") > -1 &&
        !isKHTML;
        SINAPAY.isOpera = isOpera;
        SINAPAY.isKHTML = isKHTML;
        SINAPAY.isIE = isIE;
        SINAPAY.isFF = SINAPAY.isMoz = isMoz;
    })();
    var getViewPortHeight = function(){
        var height = self.innerHeight; // Safari, Opera
        var mode = document.compatMode;
        
        if ((mode || SINAPAY.isIE)) { // IE, Gecko
            height = (mode == 'CSS1Compat') ? document.documentElement.clientHeight : // Standards
 document.body.clientHeight; // Quirks
        }
        
        return height;
    }
    var getViewPortWidth = function(){
        var width = self.innerWidth; // Safari
        var mode = document.compatMode;
        
        if (mode || SINAPAY.isIE) { // IE, Gecko, Opera
            width = (mode == 'CSS1Compat') ? document.documentElement.clientWidth : // Standards
 document.body.clientWidth; // Quirks
        }
        return width;
    }
    /**
     * <pre>得到视口的左起点和宽高</pre>
     */
    SINAPAY.getViewPortBox = function(){
        var l, t, w, h;//左起点位置，和宽高
        h = getViewPortHeight();
        w = getViewPortWidth();
        l = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
        t = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
        return {
            l: l,
            t: t,
            h: h,
            w: w
        };
    };
    /**
     * <pre>滚动条是否可用</pre>
     * @param {Boolean} bPropety //滚动条是否可用
     */
    SINAPAY.ableSroll = function(bPropety){
        var p = arguments[0] ? "" : "hidden";        
		if(document.documentElement)
		{
			document.documentElement.style.overflowY = p;
			document.documentElement.style.overflowX = p;
		}else{
			document.body.style.overflowY = p;
        	document.body.style.overflowX = p;
		}		
    };
    
    SINAPAY.aSelects = []; //保存覆盖不了的select
    /**
     * <pre>覆盖所有有效的select</pre>
     */
    SINAPAY.disableSelects = function(){
        aSele = SINAPAY.aSelects.length > 0 ? SINAPAY.aSelects : document.getElementsByTagName("select");
        SINAPAY.aSelects = [];
        for (var i = 0; i < aSele.length; i++) {
            if (!aSele[i].disabled) {
                aSele[i].disabled = true;
                SINAPAY.aSelects.push(aSele[i]);
            }
        }
    };
    /**
     * <pre>显示所有有效的select</pre>
     */
    SINAPAY.enableSelects = function(){
        for (var i = 0; i < SINAPAY.aSelects.length; i++) {
            SINAPAY.aSelects[i].disabled = false;
        }
    };
    SINAPAY.enableTab = function(_o, b){
        _o = _o || document.body;
        b = b || false;
        
        var aEle = SINAPAY.toArray(_o.getElementsByTagName("input"));
        aEle = aEle.concat(SINAPAY.toArray(_o.getElementsByTagName("a")));
        
        for (var i = 0, l = aEle.length; i < l; i++) {
            aEle[i].tabIndex = b ? 0 : -1;
        }
    };
	 SINAPAY.enableIframe=function(b)
	 {
	 	var b=b?"":"hidden";
		var a=document.getElementsByTagName("iframe");
	
		for(var i=0 ;i<a.length;i++)
		{
		    if(a[i].src=="http://games.sina.com.cn/iframe/2008-04-30/1030.shtml"
			||a[i].src=="http://games.sina.com.cn/iframe/2008-03-31/962.shtml"
			||a[i].src=="http://games.sina.com.cn/o/skywar/kb/7037.shtml"
			||a[i].id=="woocall_50sg")
			{			
				a[i].style.visibility=b;
			}			
		}
	 };
    
    /**
     * <pre>把指定元素显示在屏幕中间</pre>
     * @param {Object} oDom	要显示的dom元素
     */
    SINAPAY.showCenter = function(oDom, b){
    
        oDom = oDom;
        if (!b && oDom.style.display !== "none") 
            return;
		var dbody=document.getElementById("sinapaypopposition")||document.body;
        dbody.appendChild(oDom);
        //document.body.insertBefore(oDom, document.body.childNodes[0])
        oDom.style.position = "absolute";
        oDom.style.zIndex = "1000";
        oDom.style.display = "";
        var iH = oDom.offsetHeight || parseInt(oDom.style.height);
        var iW = oDom.offsetWidth || parseInt(oDom.style.width);
        var oView = SINAPAY.getViewPortBox();
        var iL = (oView.w - iW) / 2 + oView.l;
        var iT = (oView.h - iH) / 2 + oView.t;
        oDom.style.left = iL + "px";
        oDom.style.top = iT + "px";
        
        oDom.style.display = "";
        /*window.setTimeout(function (){
         oDom.style.display="";
         SINAPAY.Fx.show(oDom,0.1);
         },200);	*/
    };
    /**
     * <pre>遮盖整个视口的浮层</pre>
     */
    SINAPAY.floatDiv = {};
    /**
     * <pre>显示遮盖整个视口的浮层</pre>
     */
    SINAPAY.floatDiv.show = function(b){
    
        if (!SINAPAY.floatDiv.oDiv) {
            var oDiv = document.getElementById("sinapayFloatDiv") || document.createElement("div");
            oDiv.style.display = "none";
            SINAPAY.floatDiv.oDiv = oDiv;
        }
        SINAPAY.ableSroll(false);
        var oDiv = SINAPAY.floatDiv.oDiv;
        if (!b && oDiv.style.display === "") 
            return;
		var dbody=document.getElementById("sinapaypopposition")||document.body;
        dbody.appendChild(oDiv);
       //document.body.appendChild(oDiv);
        oDiv.id = "sinapayFloatDiv";
        oDiv.style.position = "absolute";
        oDiv.style.zIndex = "999";
        var box = SINAPAY.getViewPortBox();
        oDiv.style.top = box.t + "px";
        oDiv.style.left = box.l + "px";
        oDiv.style.height = box.h + "px";
        oDiv.style.width = box.w + "px";
        oDiv.style.display = "";
        SINAPAY.disableSelects();
		SINAPAY.enableIframe(false);
		
        if (!b) 
            SINAPAY.Fx.show(oDiv, 0.1);
    };
    /**
     * <pre>隐藏遮盖整个视口的浮层</pre>
     */
    SINAPAY.floatDiv.hide = function(){
        var oDiv = SINAPAY.floatDiv.oDiv;
        if (oDiv.style.display === "none") 
            return;
        oDiv.style.display = "none";
        SINAPAY.ableSroll(true);
        SINAPAY.enableSelects();
		SINAPAY.enableIframe(true);
    };
    /**
     * <pre>自定义模式对话框alert</pre>
     * @param {Object} sMsg			要显示的消息
     * @param {Object} fnHandl		点击确定后要执行的函数句柄
     * @param {Object} sButtonTip	确定按钮的文字显示（默认为 确定）
     */
    SINAPAY.Alert = function(sMsg, fnHandl, sButtonTip){
        var oDom = document.getElementById("sinapayAlert");
        if (!oDom) {
            oDom = document.createElement("div");
            oDom.id = "sinapayAlert";
            oDom.className = "sinapayLoginPop";
            oDom.style.display = "none";
            oDom.innerHTML = '<DIV class=sinapayLogin_header id=sinapayLogin_header>\
                <SPAN class=title style="FILTER: none;" id=sinapayAlert_title>提示</SPAN>\
                <SPAN class=close id=sinapayAlert_close><img src="http://login.games.sina.com.cn/webgamelogin/img/wclose.gif" style="float:right;padding-right:2px;"/></SPAN>\
            </DIV>\
            <DIV id=sinapayLogin_body>\
                <DIV class=msg id=sinapayAlert_msg style="height:50px;">\
                    游戏正在维护中\
                </DIV>\
				<br/>\
                <DIV style="";>\
                    <SPAN class=sinapayLogin_sub_1></SPAN>\
                    <SPAN class="sinapayLogin_sub_1 button"><INPUT style="margin-left:30px;" id=sinapayAlert_ok type=button value=确定></SPAN>\
                </DIV>\
            </DIV>';
			var dbody=document.getElementById("sinapaypopposition")||document.body;
        	dbody.appendChild(oDom);
            //document.body.appendChild(oDom);
        }
        sMsg = sMsg ? sMsg : "";
        fnHandl = fnHandl ? fnHandl : function(){
        };
        sButtonTip = sButtonTip ? sButtonTip : "确定";
        document.getElementById("sinapayAlert_msg").innerHTML = sMsg;
        document.getElementById("sinapayAlert_ok").value = sButtonTip;
        document.getElementById("sinapayAlert_close").style.cursor = "default";
        document.getElementById("sinapayAlert_ok").onclick = function(){
            SINAPAY.Alert.hide();
            fnHandl();
        }
        document.getElementById("sinapayAlert_close").onclick = function(){
            SINAPAY.Alert.hide();
            fnHandl();
        }
        
        SINAPAY.showCenter(oDom);
        
        SINAPAY.floatDiv.show();
		
		document.getElementById("sinapayAlert_ok").focus();
    };
    /**
     * <pre>关闭自定义模式对话框alert</pre>
     */
    SINAPAY.Alert.hide = function(){
        var oDom = document.getElementById("sinapayAlert");
        oDom.style.display = "none";
        //SINAPAY.floatDiv.hide();
    };
    
    /**
     *<pre>自定义模式对话框Confirm</pre>
     * @param {Object} sMsg			要显示的消息
     * @param {Object} fnHandl_1	点击确定按钮后要执行的函数句柄
     * @param {Object} fnHandl_2	点击取消按钮后要执行的函数句柄
     * @param {Object} sButtonTip_1	确定按钮的文字显示（默认为 确定）
     * @param {Object} sButtonTip_2	取消按钮的文字显示（默认为 确定）
     */
    SINAPAY.Confirm = function(sMsg, fnHandl_1, fnHandl_2, sButtonTip_1, sButtonTip_2){
        var oDom = document.getElementById("sinapayConfirm");
        if (!oDom) {
            oDom = document.createElement("div");
            oDom.id = "sinapayConfirm";
            oDom.className = "sinapayLoginPop";
            oDom.style.display = "none";
            oDom.innerHTML = '<DIV class=sinapayLogin_header id=sinapayLogin_header>\
                <SPAN class=title style="FILTER: none;">提示</SPAN>\
                <SPAN class=close id=sinapayConfirm_close><img src="http://login.games.sina.com.cn/webgamelogin/img/wclose.gif" style="float:right;padding-right:2px;"/></SPAN>\
            </DIV>\
            <DIV id=sinapayLogin_body>\
                <DIV class=msg id=sinapayConfirm_msg>\
                    登录失败!请重试。\
                </DIV>\
                <DIV>\
                    <SPAN class=sinapayLogin_sub_1></SPAN>\
                    <SPAN class=button><INPUT id=sinapayConfirm_ok type=button value=确定></SPAN><SPAN class=button id=sinapayConfirm_cancel><INPUT style="margin-left:20px;" type=button value=取消></SPAN>\
                </DIV>\
            </DIV>';
			var dbody=document.getElementById("sinapaypopposition")||document.body;
        	dbody.appendChild(oDom);
			
            //document.body.appendChild(oDom);
        }
        sMsg = sMsg ? sMsg : "";
        fnHandl_1 = fnHandl_1 ? fnHandl_1 : function(){
        };
        fnHandl_2 = fnHandl_2 ? fnHandl_2 : function(){
        };
        sButtonTip_1 = sButtonTip_1 ? sButtonTip_1 : "确定";
        sButtonTip_2 = sButtonTip_2 ? sButtonTip_2 : "取消";
        document.getElementById("sinapayConfirm_msg").innerHTML = sMsg;
        document.getElementById("sinapayConfirm_ok").value = sButtonTip_1;
        document.getElementById("sinapayConfirm_cancel").value = sButtonTip_2;
        document.getElementById("sinapayConfirm_close").style.cursor = "default";
        document.getElementById("sinapayConfirm_ok").onclick = function(){
            SINAPAY.Confirm.hide();
            fnHandl_1();
        }
        document.getElementById("sinapayConfirm_cancel").onclick = function(){
            SINAPAY.Confirm.hide();
            fnHandl_2();
        }
        document.getElementById("sinapayConfirm_close").onclick = function(){
            SINAPAY.Confirm.hide();
            fnHandl_2();
        }
        //oDom.style.display="";
        SINAPAY.showCenter(oDom);
        SINAPAY.floatDiv.show();
    };
    /**
     * <pre>隐藏自定义模式对话框Confirm</pre>
     */
    SINAPAY.Confirm.hide = function(){
        var oDom = document.getElementById("sinapayConfirm");
        oDom.style.display = "none";
        //SINAPAY.floatDiv.hide();
    };
    /**
     * <pre>显示登录框</pre>
     */
    SINAPAY.LoginPop = function(){
        var oDom = document.getElementById("sinapayLoginPop");
        if (!oDom) {
            oDom = document.createElement("div");
            oDom.id = "sinapayLoginPop";
            oDom.className = "sinapayLoginPop";
            oDom.style.display = "none";
            oDom.innerHTML = '<div class="sinapayLogin_header" id="sinapayLogin_header">\
                <span class="title" style="FILTER: none;">通行证登录</span>\
                <span class="close" id="sinapayLoginPop_close" style="CURSOR:pointer"><img src="http://login.games.sina.com.cn/webgamelogin/img/wclose.gif" style="float:right;padding-right:2px;"/></span>\
            </div>\
            <div id="sinapayLogin_body"><form onsubmit="SINAPAY.LoginPop.fnLogin();return false;">\
                <div>\
                    <span class="sinapayLogin_sub_1">登录名:</span>\
                    <span class="sinapayLogin_sub_2"><input id="sinapayLoginPop_user" value="" /></span>\
                </div>\
                <DIV>\
                    <SPAN class="sinapayLogin_sub_1">密码:</SPAN>\
                    <SPAN class="sinapayLogin_sub_2"><INPUT id="sinapayLoginPop_pass" type="password" value="" /></SPAN>\
                </DIV>\
                <DIV>\
                    <SPAN class="sinapayLogin_sub_1"></SPAN>\
                    <SPAN style="FLOAT: left;vertical-align:middle;"><INPUT id="sinapayLoginPop_remember" type="checkbox" value="on" />记住登录名</SPAN>\
                </DIV>\
                <DIV>\
                    <SPAN class="sinapayLogin_sub_1"></SPAN>\
                    <SPAN class="sinapayLogin_sub_2"><INPUT type="submit" style="border:none;background:none;;background-image:url(\'http://login.games.sina.com.cn/webgamelogin/img/login.gif\');width:71px;height:27px;" id="sinapayLoginPop_login" value="" />&nbsp;<A href="https://login.sina.com.cn/getpass.html">找回密码</A></SPAN>\
               <form></DIV>\
            </div>';
			var dbody=document.getElementById("sinapaypopposition")||document.body;
        	dbody.appendChild(oDom);
            //document.body.appendChild(oDom);
        }
        var oLogin = document.getElementById("sinapayLoginPop_login");
        var oClose = document.getElementById("sinapayLoginPop_close");
        oClose.style.cursor = "default";
        oLogin.onclick = function(){
            // SINAPAY.LoginPop.fnLogin();
        }
        oClose.onclick = function(){
            SINAPAY.LoginPop.hide();
            SINAPAY.floatDiv.hide()
        }
        SINAPAY.floatDiv.show();
        SINAPAY.showCenter(oDom);
        
        SINAPAY.enableTab(null, false);
        SINAPAY.enableTab(oDom, true);
        
        
        window.onresize = function(){
            SINAPAY.showCenter(oDom, true);
            SINAPAY.floatDiv.show(true);
        }
        
        
        SINAPAY.autoComp();
        
        setTimeout('\
		document.getElementById("sinapayLoginPop_user").focus();\
		', 50);
        
    };
    /**
     * <pre>隐藏登录框</pre>
     */
    SINAPAY.LoginPop.hide = function(){
        var oDom = document.getElementById("sinapayLoginPop");
        oDom.style.display = "none";
        //SINAPAY.floatDiv.hide();
        
        var sUser = document.getElementById("sinapayLoginPop_user").value = "";
        var sUser = document.getElementById("sinapayLoginPop_pass").value = "";
        // var sPass = document.getElementById("sinapayLoginPop_remember").checked = "checked";
        
        SINAPAY.enableTab(null, true);
        
        window.onresize = function(){
        };
    };
    SINAPAY.LoginPop.fnLogin = function(){
        var sUser = document.getElementById("sinapayLoginPop_user").value;
        var sPass = document.getElementById("sinapayLoginPop_pass").value;
        var bRemember = document.getElementById("sinapayLoginPop_remember").checked;
        //var bRemember = document.getElementById("sinapayLoginPop_remember");
        SINAPAY.LoginPop.hide();
        if (sUser && sPass) {
        
            SINAPAY.Alert("正在登录中,请稍候...", function(){
                if (SINAPAY.Global.request) {
                    SINAPAY.Global.request.abort();
                    SINAPAY.Global.request = null;
                }
                SINAPAY.Alert.hide();
                SINAPAY.floatDiv.hide();
            }, "取消");
            SINAPAY.sendToServer({
                user: sUser,
                pass: sPass
            });
            if (bRemember) {
                SINAPAY.setCookie("spName", sUser);
            }
            else {
                SINAPAY.setCookie("spName", "");
            }
        }else if(!sUser&&!sPass){
			SINAPAY.Alert("请输入用户名和密码", function(){
                SINAPAY.LoginPop();
            });
		}
        else if(!sUser){
            SINAPAY.Alert("请输入您的用户名", function(){
                SINAPAY.LoginPop();
            });
        }else{
			SINAPAY.Alert("请输入您的密码", function(){
                SINAPAY.LoginPop();
            });
		}
    }
    //-------------------------------------------------------------------------------------
    SINAPAY.Global = {};
    SINAPAY.Global.targetUrl = "http://login.games.sina.com.cn/webgame/validateSinaUser.php";//"?genid="+SINAPAY.genid;	//默认跳转到的页面
    SINAPAY.Global.ajaxUrl = "http://login.games.sina.com.cn/webgame/loginSinaUser.php"; //ajax接口       
    SINAPAY.Global.msg = {};
    //--------------------------------------------------------------
	
    //挂到网页上的钩子
    SINAPAY.EnterHook = function(){
		
        if (SINAPAY.hasSinpro()) {
            window.location = SINAPAY.Global.targetUrl;
            return;
        }
        else {
            SINAPAY.LoginPop();
        }

    };
    //检查sinapro是否存在
    SINAPAY.hasSinpro = function(){
       return SINAPAY.getCookie("SUP");
    };
    SINAPAY.remoteSinapro = function(){
        var sCookie = SINAPAY.hasSinpro();
        
        SINAPAY.Alert("正在登录中,请稍候...", function(){
            if (SINAPAY.Global.request) {
                SINAPAY.Global.request.abort();
                SINAPAY.Global.request = null;
            }
            SINAPAY.Alert.hide();
			SINAPAY.floatDiv.hide();
        }, "取消");
        var r = SINAPAY.Global.targetUrl;//"";
        SINAPAY.sendToServer("", r);
    };
    //远程校验
    SINAPAY.sendToServer = function(obj, _url){
        var sUrl = (_url ? _url : SINAPAY.Global.ajaxUrl) + "?" + SINAPAY.getGenid();
        sUrl+=sUrl.substring(sUrl.length-1)=="?"?SINAPAY.getOtype():"&"+SINAPAY.getOtype();		
		var fnCallBack = SINAPAY.responseServer;
        var oObject = obj;
        var oOptions = {
            errorHandler: function(){
                SINAPAY.Alert.hide();
                SINAPAY.Alert("登录失败请重试", function(){
                    SINAPAY.LoginPop();
                }, "确定");
            }
        };
        if (SINAPAY.Global.request) {
            SINAPAY.Global.request.abort();
            SINAPAY.Global.request = null;
        }
        SINAPAY.Global.request = HTTPp.post(sUrl, fnCallBack, oObject, oOptions);
    };
    //相应服务器结果
    SINAPAY.responseServer = function(obj){
        SINAPAY.Global.request = null;
        SINAPAY.Alert.hide();
        if (!obj) 
            return; //报错
        try {
            obj = eval('(' + obj + ')');
        } 
        catch (e) {
            if (SINAPAY.Debug) {
                SINAPAY.Alert("服务器返回有误", function(){
                    SINAPAY.Alert.hide()
                });
            }
            
            return;
        }
        if (!obj.error) {
            //登录成功 要做处理        		
			if(obj.nick)
			{
				SINAPAY.nick=obj.nick;
			}
            if (obj.data && obj.data.url) {
				var pwindow=self;
				while(pwindow!=pwindow.top)
				{
					pwindow=pwindow.top;
				}
                pwindow.location = obj.data.url;
                return;
            }
            SINAPAY.floatDiv.hide();
            SINAPAY.loginSucced();
        }
        else {
            var notice = obj.data.notice || SINAPAY.Global.msg[obj.error] || "异常";
            SINAPAY.Alert(notice, function(){
                if (obj.error == "201") 
                    SINAPAY.LoginPop();
                else {
                    SINAPAY.floatDiv.hide();
                }
                //
            }, "确定");
        }
    };
    //自动填写用户名
    SINAPAY.autoComp = function(){
        var sN = SINAPAY.getCookie("spName");
        if (sN && document.getElementById("sinapayLoginPop_user")) {
            document.getElementById("sinapayLoginPop_user").value = sN;
            document.getElementById("sinapayLoginPop_remember").checked = "checked";
        }
    }
    
})();


//-------------------------2008-05-08-------------------------------------	
/*********************ie only 编码转换*****************************/
(function(){

if(typeof execScript=="undefined"){
			window.getBytes=window.reBytes=function(e)
			{
				return e;
			}
			return;
	}
window.getBytes=function(chrList)
{
    var bytes = [];
    for(var i = 0;i<chrList.length;i++)
    {
        c = "";
        ch = chrList.charAt(i);
        execScript("c = Hex(Asc(ch))","vbscript");
        bytes.push(c);
    }
    return bytes;
}
window.reBytes=function(arr) 
{ 
   c = ""; 
   for(var i=0;i <arr.length;i++)  
   { 
        byt = arr[i]; 
        execScript("c = c+Chr(CInt('&H'+byt))","vbscript"); 
    } 
   return c; 
} 
/** example
var chrList = "汉字";
alert(getBytes(chrList));  
alert(reBytes(['cba7 ', 'D7D6'])); 
*/
})();
function getNick(){
		var d ={};
		var c = SINAPAY.getCookie("SUP")
		c = c.split("&");
		var rg = /([^=]+)=([^=]+)/;
		for(var i = 0 ; i<c.length ; i++)
		{
			  if(rg.test(c[i]))
				{
				    var k = RegExp.$1,v = decodeURIComponent(RegExp.$2);
				    d[k] = v;
				}
		}
		return d['nick'] || d['user'];			
    };
//设置右上角的文字
SINAPAY.setLoginFlagR = function(){
   
    var o = document.getElementById("sinapayLoginFlagR");
    var a = document.getElementById("sinapayLoginFlagL");
    
    
    if (SINAPAY.hasSinpro()) {
        if (o) {
            o.innerHTML = "退出";
        }
        if (a) {
            a.innerHTML = getNick()+"/退出";
            a.onclick = function(){
				SINAPAY.Hook();
            };
        }
        
    }
    else {
        if (a) {
            a.innerHTML = "我要登录";
            a.onclick = function(){
                SINAPAY.Hook()
            };//SINAPAY.clickHandle;
        }
        if (o) {
            o.innerHTML = "登录";
            o.onclick = function(){
                SINAPAY.Hook()
            };//SINAPAY.clickHandle;
        }
    }
};

//退出新浪通行证
function logoutsinaer(url)
{
	url = url || window.location;
	var baseurl = "http://login.sina.com.cn/cgi/login/logout.php";
	window.location = baseurl + "?r="+encodeURIComponent(url);	
}
//退出
SINAPAY.loginOut = logoutsinaer;
//登录
SINAPAY.loginIn = function(){
    SINAPAY.LoginPop();
};
//
SINAPAY.loginSucced = function(){
    SINAPAY.setLoginFlagR();
    if (!SINAPAY.activeButton) {
        return;
    };
    if (SINAPAY.activeButton.gameid) {
        SINAPAY.remoteSinapro();
    }
    else {
        return;
    }
};

SINAPAY.clickHandle = function(){
    var e = arguments[0] || window.event;
    var el = e.target || e.srcElement;
    
    for (var i = 0, _o, len = SINAPAY.buttonIds.length; i < len; i++) {
        if (SINAPAY.buttonIds[i] == el.id) {
            break;
        }
        else 
            if (i == len - 1) {
                alert("el.id error");
                return;
            }
    }
    
    SINAPAY.activeButton = el.id;
    if (el.id != SINAPAY.buttonIds[0] && el.id != SINAPAY.buttonIds[1]) {
        if (SINAPAY.hasSinpro()) {
            SINAPAY.loginSucced();
        }
        else {
            SINAPAY.loginIn();
        }
    }
    else {
        if (SINAPAY.hasSinpro()) {
            SINAPAY.loginOut();
        }
        else {
            SINAPAY.loginIn();
        }
    }
}

//记录当前是那个按钮或链接被点了	
SINAPAY.activeButton = null;

SINAPAY.getGenid = function(){
    if (SINAPAY.activeButton && SINAPAY.activeButton.gameid) {
    
        var gid = SINAPAY.activeButton.gameid;
        gid = "genid=" + gid;
        var ser = SINAPAY.activeButton.serverid;
        
        if (ser || ser === 0) {
            return gid + "_" + ser;
        }
        else {
            return gid;
        }
    }
    else {
        return "";
    }
}
SINAPAY.getOtype=function()
{
	if (SINAPAY.activeButton && SINAPAY.activeButton.otype) 
	{
		return "otype="+SINAPAY.activeButton.otype;
	}else{
		return "";
	}
}
//设置初始状态
SINAPAY.initPage = function(){

    if (!document.getElementById("sinapayLoginFlagR") && !document.getElementById("sinapayLoginFlagL")) {
        SINAPAY.tempTimer = window.setTimeout(SINAPAY.initPage, 500);
        return;
    }
    SINAPAY.setLoginFlagR();
    
    document.domain = "sina.com.cn";
};
if (!SINAPAY) {
    window.SINAPAY = {};
}
//______________________________________________________
//游戏是否在维护
	SINAPAY.gameModify=false;
	
SINAPAY.Hook = function(gameid, serverid,otype){
	if(SINAPAY.gameModify)
	{
		SINAPAY.Alert("游戏正在维护中...",function(){
			SINAPAY.Alert.hide();
            SINAPAY.floatDiv.hide();
		},"确定");
		return;
	}
	
	
	if (location.host !== "login.games.sina.com.cn") {
		var tttt = document.getElementById("sinapaytemp_iframe");
		if(tttt){
			if(!tttt.contentWindow||!tttt.contentWindow.flag)
			{
				alert("页面尚未加载完成,请稍后点击");
				window.location=window.location;
				return;
			}
		}		
	}
	
	
    var _a = arguments;
    serverid = serverid ? serverid : "";
    
    if (_a.length > 0) { //游戏链接登录
        SINAPAY.activeButton = {
            "gameid": gameid,
            "serverid": serverid,
			"otype":otype
        };
        
        if (SINAPAY.hasSinpro()) {
            SINAPAY.loginSucced();
        }
        else {
            SINAPAY.loginIn();
        }
    }
    else {
        //单纯登录
        SINAPAY.activeButton = {
            "gameid": "",
            "serverid": ""
        };
        if (SINAPAY.hasSinpro()) {
            SINAPAY.loginOut();
        }
        else {
            SINAPAY.loginIn();
        }
    }
    
};


SINAPAY.initPage();
//--------------------
//   sinapayLoginFlagR    sinapayLoginFlagL

//----------------------------------------------------------


//HTTPp._factory      返回xmlhttprequest对象的方法
//在跨域时工作

(function(){
    if (location.host !== "login.games.sina.com.cn") {
        var __i = 0;
        
        window.onload = function(){
			            try {
			                window.document.domain = "sina.com.cn";
			                __i++;
							
							var tttt=document.getElementById("sinapaytemp_iframe");
							if(tttt)return;
								
			                SINAPAY.myifram = document.createElement("iframe");
			                SINAPAY.myifram.style.display = "none";
			                SINAPAY.myifram.src = "http://login.games.sina.com.cn/webgame/proxy2.html";
							
							var dbody=document.getElementById("sinapaypopposition")||document.body;
        					dbody.appendChild(SINAPAY.myifram);
			                //document.body.appendChild(SINAPAY.myifram);
			                
			                SINAPAY.Fx.Timer(function(){
			                    SINAPAY.newRequest = SINAPAY.myifram.contentWindow.getXHR();
			                    HTTPp._factory = function(){
			                        return SINAPAY.newRequest;
			                    }
			                }, 500, function(){
			                    return !SINAPAY.myifram.contentWindow;
			                });
			            } 
			            catch (e) {
			            };
                    }
        
    }
})();
window.onerror=function(){};

/*
 侠义道：		0010101			xiayidao
 天空左岸：	0020101			sky
 纵横天下：	0030101			zongheng
 帝国崛起：	0040101			diguo  1
 			0040201			diguo  2
 新帝国崛起  新的0040301		旧的  0070101
 			
武林三国：	0050101			武林三国  1
七龙纪： 		0060101
 
 */



