﻿// ================================
// DHTML mini library
// Gerard Ferrandez - January 2007
// http://www.dhteumeuleu.com
// ================================
var notip = "javascript:alert('敬请期待');";
var currentUrl = location.href;

function bzalert()
{
    var d=null;
    var s=null;
    var i=null;
    
    if(arguments.length ==1)
    {
        var s = arguments[0];
        var d = $("divBZTip");
    }
    else
    {
        var s = arguments[0];
        var i = arguments[1];
        var d = $(i);
    }
    
    if(d!=null)
    {
        d.style.display = "";
        d.innerHTML = "<div style='width:750px; height:65px; background:url(/images/8zsq_45.jpg) no-repeat 58px 8px; float:left;'><div class='hongse' style='padding-left:80px; padding-top:26px;'>"+s+"</div></div>";
    }
    else
    {
        alert(s);
    }
}

function hideAllTip()
{
    if($("divBZTip")!= null)
    {
        $("divBZTip").style.display = "none";
    }
}

function officialTip()
{
    alert("暂未开放，敬请期待！");
}

function notActiveServerTip()
{
    if($("divServer").childNodes[0].options.length == 1)
    {
        bzalert("您还未登录过该游戏的任何一个服务器，无法对其进行充值操作","divNoServerTip");
    }
}

function $(id)
{
    if(document.getElementById(id) != null)
    {
        return document.getElementById(id);
    }
    else if(id.indexOf("mainContent") > -1)
    {
        var ar = id.split("_");
        if(document.getElementById(ar[ar.length-1]) != null)
        {
            return document.getElementById(ar[ar.length-1]);
        }
        else
        {
            return null;
        }
    }
    else
    {
        if(document.getElementById("ctl00_mainContent_"+id) != null)
        {
            return document.getElementById("ctl00_mainContent_"+id);
        }
        else if(document.getElementById("ctl01_mainContent_"+id) != null)
        {
            return document.getElementById("ctl01_mainContent_"+id);
        }
        else 
        {
            return null;
        }
    }
}

function $p(o)
{
   if(typeof(o) == "object")
    {
        return o.parentNode;
    }
    else
    {
        return $(o).parentNode;
    }
}

function singleShow(o)
{
    var p = $p(o);
    
    if(p!= null)
    {
        for(var i=0;i<p.childNodes.length;i++)
        {
            hide(p.childNodes[i]);
        }
    }
    show(o);
}

function show(o)
{
    if(typeof(o) == "object")
    {
        o.style.display="";
    }
    else
    {
        $(o).style.display="";
    }
}

function hide(o)
{
    if(typeof(o) == "object")
    {
        o.style.display="none";
    }
    else
    {
        $(o).style.display="none";
    }
}

px = function (x) {
	return ''.concat(Math.round(x), 'px');
}

randompx = function(x){
    return ''.concat(Math.round(Math.random()*x),'px')
}

pxLeft = function(o) {
	for (var x = 0; o != null; o = o.offsetParent) x += o.offsetLeft;
	return x;
}

pxTop = function(o) {
	for (var x = 0; o != null; o = o.offsetParent) x += o.offsetTop;
	return x;
}

/* ==== DOM 2 add event ==== */
addEvent = function (o, e, f) {
	var r = false;
	if (window.addEventListener) {
		o.addEventListener(e, f, false);
		r = true;
	} else if (window.attachEvent) {
		r = o.attachEvent('on' + e, f);
	}
	return r;
}

/* find browser window size */
function browserWindow () {
	width = 0
	height = 0;
	if (document.documentElement) {
		width = document.documentElement.offsetWidth;
		height = document.documentElement.offsetHeight;
	} else if (window.innerWidth && window.innerHeight) {
		width = window.innerWidth;
		height = window.innerHeight;
	}
	return [width, height];
}
/* find total page height */
function getScrollXY() {
	scrOfX = 0; 
	scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	totalY = (window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null);

	totalX = (window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null);
	
	return [ scrOfX, scrOfY, totalY, totalX ];
}

/******************************************* 通用Ajax函数 ******************************************/
function Ajax() {
	
	var xmlHttpReq = null;
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) {
			xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	var handler = null;
	
	this.invoke = function (url, mode, synchro, _handler) {
		handler = _handler;
		xmlHttpReq.open(mode, url, synchro);
		xmlHttpReq.onreadystatechange = this.callback;
		xmlHttpReq.send(null);
	};
	
	this.callback = function () {
		if (xmlHttpReq.readyState == 4) {
			if (xmlHttpReq.status == 200) {
				handler(xmlHttpReq.responseText);
			} else {
				//alert("There was a problem retrieving the XML data:\n" + xmlHttpReq.statusText);
				alert("请刷新页面！");
			}
		}
	};
}

function getScroll() {     
var t, l, w, h;          
if (document.documentElement && document.documentElement.scrollTop) {           

t = document.documentElement.scrollTop; 
l = document.documentElement.scrollLeft;        
w = document.documentElement.scrollWidth;         
   h = document.documentElement.scrollHeight;     
} else if (document.body) {         
   t = document.body.scrollTop;       
   l = document.body.scrollLeft;         
   w = document.body.scrollWidth;         
   h = document.body.scrollHeight;     
}
     
return { t: t, l: l, w: w, h: h }; 
}


function getByteLen( sTargetStr ) 
{
    var sTmpStr, sTmpChar;
    var nOriginLen = 0;
    var nStrLength = 0;
    
    sTmpStr = new String(sTargetStr);
    nOriginLen = sTmpStr.length;

    for ( var i=0 ; i < nOriginLen ; i++ ) 
    {
        sTmpChar = sTmpStr.charAt(i);

        if (escape(sTmpChar).length > 4) 
        {
                nStrLength += 2;
        } 
        else if (sTmpChar!='\r')
        {
                nStrLength ++;
        }
    }
    return nStrLength; 
}

function subByteString(str,len)
{
    if( getByteLen(str) > len )
    {
        while( getByteLen(str) > len )
        {
           var OriginStr = new String(str);
           str = str.substring(0,str.length-1);
        }
        return str+".";
    }
    else
    {
        return str;
    }
}

String.prototype.toSafeString = function()
{
    return this.replace(/<\/?[^>]+>?/gi, '');
}

String.prototype.format = function()
{
    var p = arguments;
	return this.replace(/(\{\d+\})/g,function(){
		return p[arguments[0].replace(/\D/g,"")];
	});
}

String.prototype.trim = function()
{
    var _argument = arguments[0]==undefined ? " ":arguments[0];
	if(typeof(_argument)=="string"){
		return this.replace(_argument == " "?/(^\s*)|(\s*$)/g : new RegExp("(^"+_argument+"*)|("+_argument+"*$)","g"),"");
	}else if(typeof(_argument)=="object"){
		return this.replace(_argument,"")
	}else if(typeof(_argument)=="number" && arguments.length>=1){
		return arguments.length==1? this.substring(arguments[0]) : this.substring(arguments[0],this.length-arguments[1]);
	}
}

