var ie = (navigator.userAgent.indexOf("MSIE")!=-1);//IE
var ie7 = (navigator.userAgent.indexOf("MSIE 7.0")>-1);//IE7
var ff = (navigator.userAgent.indexOf("Firefox")!=-1);//Firefox
var ope = (navigator.userAgent.indexOf("Opera")!=-1);//Opera
var op950 = (navigator.userAgent.indexOf("Opera/9.50")!=-1);//Opera9.50
var op = ope&&!op950;

var isFoundMsXml = false;
function GetXmlObject()
{
	var ArrXmlObj=["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"];
	var obj = null;
	for(var i=0; i<ArrXmlObj.length; i++)
	{
		try
		{
			obj = new ActiveXObject(ArrXmlObj[i]);
			isFoundMsXml = true;
			break;
		} 
		catch(e){}
	}
	return obj;
}

var isIEex = false;
function GetXmlHttpObject()
{
	var ArrXmlObj=['Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
	var obj = null;
	if(window.ActiveXObject){
		for(var i=0; i<ArrXmlObj.length; i++)
		{
			try
			{
				obj = new ActiveXObject(ArrXmlObj[i]);
				isIEex = true;
				break;
			} 
			catch(e){}
		}
	}
	else if(window.XMLHttpRequest){
		obj = new XMLHttpRequest();
		isIEex = false;
	}
	return obj;
}

String.prototype.Trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function()
{
return this.replace(/(\s*$)/g, "");
}

Date.prototype.format = function(format) //author: meizz
{
  var o = {
    "M+" : this.getMonth()+1, //month
    "d+" : this.getDate(),    //day
    "h+" : this.getHours(),   //hour
    "m+" : this.getMinutes(), //minute
    "s+" : this.getSeconds(), //second
    "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
    "S" : this.getMilliseconds() //millisecond
  }
  if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
    (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  for(var k in o)if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,
      RegExp.$1.length==1 ? o[k] : 
        ("00"+ o[k]).substr((""+ o[k]).length));
  return format;
}
Date.prototype.dateDiff = function(interval,objDate)
{
var d=this, t=d.getTime(), t2=objDate.getTime(), i={};
i["y"]=objDate.getFullYear()-d.getFullYear();
i["q"]=i["y"]*4+Math.floor(objDate.getMonth()/4)-Math.floor(d.getMonth()/4);
i["m"]=i["y"]*12+objDate.getMonth()-d.getMonth();
i["ms"]=objDate.getTime()-d.getTime();
i["w"]=Math.floor((t2+345600000)/(604800000))-Math.floor((t+345600000)/(604800000));
i["d"]=Math.floor(t2/86400000)-Math.floor(t/86400000);
i["h"]=Math.floor(t2/3600000)-Math.floor(t/3600000);
i["n"]=Math.floor(t2/60000)-Math.floor(t/60000);
i["s"]=Math.floor(t2/1000)-Math.floor(t/1000);
return i[interval];
};

var GetNodeValue = function(obj)
{
    var str = "";
    if(ie)    //IE
    {
        str = obj.text;
    }
    else //Mozilla
    {
        try
        {
            str = obj.childNodes[0].nodeValue;
        }
        catch(ex)
        {
            str = "";
        }
    }
    return str;
}

var SetInnerText = function(obj, str){
    if(ie)    //IE
    {
        obj.innerText = str;
    }
    else //Mozilla
    {
        try
        {
            obj.textContent = str;
        }
        catch(ex)
        {
        }
    }
}

if(document.implementation && document.implementation.createDocument)
{
    XMLDocument.prototype.loadXML = function(xmlString)
    {
        var childNodes = this.childNodes;
        for (var i = childNodes.length - 1; i >= 0; i--)
            this.removeChild(childNodes[i]);

        var dp = new DOMParser();
        var newDOM = dp.parseFromString(xmlString, "text/xml");
        var newElt = this.importNode(newDOM.documentElement, true);
        this.appendChild(newElt);
    };

    // check for XPath implementation
    if( document.implementation.hasFeature("XPath", "3.0") )
    {
       // prototying the XMLDocument
       XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
       {
          if( !xNode ) { xNode = this; } 
          var oNSResolver = this.createNSResolver(this.documentElement)
          var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
                       XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
          var aResult = [];
          for( var i = 0; i < aItems.snapshotLength; i++)
          {
             aResult[i] =  aItems.snapshotItem(i);
          }
          return aResult;
       }

       // prototying the Element
       Element.prototype.selectNodes = function(cXPathString)
       {
          if(this.ownerDocument.selectNodes)
          {
             return this.ownerDocument.selectNodes(cXPathString, this);
          }
          else{throw "For XML Elements Only";}
       }
    }

    // check for XPath implementation
    if( document.implementation.hasFeature("XPath", "3.0") )
    {
       // prototying the XMLDocument
       XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
       {
          if( !xNode ) { xNode = this; } 
          var xItems = this.selectNodes(cXPathString, xNode);
          if( xItems.length > 0 )
          {
             return xItems[0];
          }
          else
          {
             return null;
          }
       }
       
       // prototying the Element
       Element.prototype.selectSingleNode = function(cXPathString)
       {    
          if(this.ownerDocument.selectSingleNode)
          {
             return this.ownerDocument.selectSingleNode(cXPathString, this);
          }
          else{throw "For XML Elements Only";}
       }
    }

	HTMLElement.prototype.insertAdjacentHTML=function(where, html) 
	{ 
		var e=this.ownerDocument.createRange(); 
		e.setStartBefore(this); 
		e=e.createContextualFragment(html); 
		switch (where) 
		{ 
			case 'beforeBegin': this.parentNode.insertBefore(e, this);break; 
			case 'afterBegin': this.insertBefore(e, this.firstChild); break; 
			case 'beforeEnd': this.appendChild(e); break; 
			case 'afterEnd': 
			if(!this.nextSibling) this.parentNode.appendChild(e); 
			else this.parentNode.insertBefore(e, this.nextSibling); break; 
		} 
	}
}
  if(typeof(HTMLElement)!="undefined" && !window.opera)
  {   
      HTMLElement.prototype.__defineGetter__("outerHTML",function()
      {   
          var a=this.attributes, str="<"+this.tagName,   i=0;for(;i<a.length;i++)
          if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';
          if(!this.canHaveChildren)   return   str+" />";
          return str+">"+this.innerHTML+"</"+this.tagName+">";
      });   
      HTMLElement.prototype.__defineSetter__("outerHTML",function(s)
      {   
          var d = document.createElement("DIV"); d.innerHTML = s;
          for(var i=0; i<d.childNodes.length; i++)
                this.parentNode.insertBefore(d.childNodes[i], this);
          this.parentNode.removeChild(this);
      });
      HTMLElement.prototype.__defineGetter__("canHaveChildren",function()
      {
          return   !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
      });
  }

function FormatPercent(s,t,l){
	if(parseInt(s)==0 || parseInt(t)==0) return "0%";
	var tmp;
	tmp = parseFloat(s) * 100 / parseFloat(t);
	if(l<1){
		return Math.round(tmp) + "%";
	}
	else{
		if(tmp<1)
		{
			return tmp.toPrecision(l) + "%";
		}
		else
		{
		   return tmp.toPrecision(l+1) + "%";
		}
	}	
}

function FormatNumberPercent(s,l){
	if(parseFloat(s)==0) return "0%";
	tmp = parseFloat(s) * 100;
	if(l<1){
		return Math.round(s) + "%";
	}
	else{
		if(tmp<1)
		{
			return tmp.toPrecision(l) + "%";
		}
		else
		{
		   return tmp.toPrecision(l+1) + "%";
		}
	}
}

	 
function FormatDecimal(s,l){
	if(l<1) return s;
	var t = parseFloat(s);
	if(t<1){
		return t.toPrecision(l);
	}
	else{
		return t.toPrecision(l+1);
	}
	if(s.indexOf(".")==-1){
		return s;
	}
	else{
		var int,decimal;
		var tarr = s.split(".");
		int = tarr[0];
		decimal = tarr[1];
		if(l>0){

			if(decimal.length>l)
			{
				if(parseInt(decimal.charAt(l))>=5){
					decimal = parseInt(decimal.substring(0,l)) + 1;
				}
				else{
					decimal = decimal.substring(0,l);
				}
				return int + "." + decimal;
			}
			else
			{
				return s;
			}
		}
		else{
			if(parseInt(decimal.charAt(0))>=5){
				int = parseInt(int) + 1;
			}
			return int;
		}
	}
}

function getObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
}

function SetHtml(objID, html){
	if(document.getElementById(objID)){
		document.getElementById(objID).innerHTML = html;
	}
	else if(document.all(objID)){
		document.all(objID).innerHTML = html;
	}
}

function get_cookie(Name) { 
	var search = Name + "=" 
	var returnvalue = ""; 
	if (document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search); 
		if (offset != -1) { 
			offset += search.length 
			end = document.cookie.indexOf(";", offset); 
			if (end == -1) end = document.cookie.length; 
			returnvalue=unescape(document.cookie.substring(offset, end))
		} 
	} 
	return returnvalue; 
}

function set_cookie(Name,value){ 
	document.cookie=Name+"="+value;
}

function setCookie(name,value)
{
    var Days = 30;
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg)) return unescape(arr[2]);
    else return "";
}
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

var PassPortApi = {
	domain:"spb8.com",
	getDomain:function(){
		var hostname = document.domain.split('.');
		var l = hostname.length;
		if(l<=2) return document.domain;
		return hostname[l-2] + '.' + hostname[l-1];
	},
	addCookie:function(name,value,expireHours){
		if(this.domain=="")this.domain = this.getDomain();
		var cookieString = name + "=" + escape(value) + "; path=/; domain=." + this.domain + ";";
		if(expireHours>0){
			var date=new Date();
			date.setTime(date.getTime() + expireHours*3600*1000);
			cookieString = cookieString + "expires=" + date.toGMTString() + ";";
		}
		document.cookie = cookieString;
	},
	getCookie:function(name){
		try{
			var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
			if(arr=document.cookie.match(reg)) return unescape(arr[2]);
			else return "";
		}
		catch(e){return "";}
	},
	deleteCookie:function(name){
		if(this.domain=="") this.domain=this.getDomain();
		var exp = new Date();
		exp.setTime(exp.getTime()-100000);
		var cval = this.getCookie(name);
		document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString() + "; path=/; domain=." + this.domain + ";";
	}
};

function noData(){
	var tmp = "";
	tmp += "<table width='100%' height='100%' border='0' cellspacing='1' cellpadding='0' bgcolor='#696969'><tr><td align='center' bgcolor='#ffffff' style='padding-top:10px; padding-bottom:10px;'><span style='font-size:16px; color:#f00; font-weight:bold;'>www.spb8.com</span></td></tr></table>"
	return tmp;
}

function no(str){
	var tmp = "";
	tmp += "<table width='100%' height='100%' border='0' cellspacing='1' cellpadding='0' bgcolor='#696969'><tr><td align='center' bgcolor='#ffffff' style='padding-top:5px; padding-bottom:5px;'><span style='font-size:16px; color:#f00; font-weight:bold;'>" + str + "</span></td></tr></table>"
	return tmp;
}

function loadData(){
	var tmp = "";
	tmp += '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#696969"><tr><td align="center" bgcolor="#ffffff" style="padding-top:10px; padding-bottom:10px;"><span style="font-size:12px; color:#000;"><img src="http://img.8bo8.org/live/loading.gif" width="16" height="16" border="0" align="absmiddle">数据加载中，请稍候。。。<br>score loading, please wait!!!</span></td></tr></table>';
	return tmp;
}

function htmldecode(str){
	var tmp = str;
	tmp = tmp.replace("&amp;", "&").replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"");
	return tmp;
}

function htmlencode(str){
	var tmp = str;
	tmp = tmp.replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;").replace("&", "&amp;");
	return tmp;
}

function getExplore(){
	var ie = (navigator.appVersion.indexOf("MSIE")!=-1);
	var ff = (navigator.userAgent.indexOf("Firefox")!=-1);
	if(ie){
		return "ie";
	}
	if(ff){
		return "ff";
	}
	return "";
}

function getScrollTop(){
	var obj_top = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	return obj_top;
}

function getScrollLeft(){
	var obj_left = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
	return obj_left;
}

function getClientWidth(){
	var obj_width = (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
	return obj_width;
}

function getClientHeight(){
	var obj_height = (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;	
	return obj_height;
}

function $(id){
	return document.getElementById(id);
}

function chkdate(datestr)
{
var lthdatestr ;
if (datestr != "")
{
	lthdatestr= datestr.length ;
}
else
{
	lthdatestr=0;
}
var tmpy="";
var tmpm="";
var tmpd="";
var status;
status=0;
if ( lthdatestr== 0) return false;
for (i=0;i<lthdatestr;i++)
{ 
	if (datestr.charAt(i)== '-')
	{
		status++;
	}
	if (status>2)
	{
		alert("无效日期!");
		return false;
	}
	if ((status==0) && (datestr.charAt(i)!='-'))
	{
		tmpy=tmpy+datestr.charAt(i);
	}
	if ((status==1) && (datestr.charAt(i)!='-'))
	{
		tmpm=tmpm+datestr.charAt(i);
	}
	if ((status==2) && (datestr.charAt(i)!='-'))
	{
		tmpd=tmpd+datestr.charAt(i);
	}
}
year=new String (tmpy);
month=new String (tmpm);
day=new String (tmpd);
if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
{
	alert("无效日期!");
	return false;
}
if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
{
	alert ("无效日期!");
	return false;
}
if (!((year % 4)==0) && (month==2) && (day==29))
{
	alert ("无效日期!");
	return false;
}
if ((month<=7) && ((month % 2)==0) && (day>=31))
{
	alert ("无效日期!");
	return false;
}
if ((month>=8) && ((month % 2)==1) && (day>=31))
{
	alert ("无效日期!");
	return false;
}
if ((month==2) && (day==30))
{
	alert("无效日期!");
	return false;
}
return true;
}

function StringToDate(sDate){
	var tmp = sDate.split(/[-]/);
	return new Date(parseInt(tmp[0]), parseInt(tmp[1])-1, parseInt(tmp[2]), 0, 0, 0);
}

function DateToString(){
	var d=new Date();
	return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
}

function ParseDateTime(dtstr){
	var dt = dtstr.replace(/\d+(?=-[^-]+$)/, function (a) { return parseInt(a, 10) - 1; }).match(/\d+/g);
	var d = eval('new Date(' + dt + ')'); 
	return d;
}