function Include()
{
	for (var i = 0; i < arguments.length; i++)
	  document.write("<script src=\"" + arguments[i] + ".js\" type=\"text/javascript\"></script>");
}

function IncludeStr(jsScript)
{
	eval(jsScript);
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof(element)== 'string')
       element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}
function _tag$(o,p){
	if(p==null)
		return document.getElementsByTagName(o);
	else
		return p.getElementsByTagName(o);
}

function clear(o)
{
	$(o).parentNode.removeChild($(o));
}


var timer;
var timer_pool = [];
function display(o,sp,t)
{
    clearTimeout(timer_pool[4]);
	var obj = $(o)
	if(obj==null)return;
	var realHeight = parseInt(obj.scrollHeight);
	var nowHeight = obj.offsetHeight;
	if(realHeight==0)
	{
		return;
	}
		
	if(t==null)
	{
		if(nowHeight >= realHeight && nowHeight != 0)
		{
			//clearTimeout(timer);
			return;
		}
	}
	else
	{
		if(nowHeight<5)
		{
		 	obj.style.display = "none";
		 	//clearTimeout(timer);
		 	return;
		}
	}
	var newHeight;
	if(t==null)
	{
		newHeight = (nowHeight + (realHeight-nowHeight)/5+1);
		if(newHeight >= realHeight)
			newHeight = realHeight;
	}
	else
	{
		obj.style.overflow = "hidden";
		newHeight = (nowHeight - realHeight/5);
		if(newHeight < 0)
			newHeight =1;
	}
	obj.style.height = newHeight + "px";
	if(t!=null)
	{
		if(obj.offsetHeight == nowHeight)
		{
			obj.style.display = "none";
			return;
		}
	}
	if(sp==null)sp=20;
	timer_pool[4] = setTimeout("display('" + o + "'," + sp +"," + t + ")",sp);
}

function showHide(o)
{
	var obj = $(o);
	if(obj==null)
		return;
	if(obj.style.display=="none")
		obj.style.display = "";
	else
		obj.style.display = "none";
}

function cssSwitch(evt,cssName,tagName)
{
    if(oId==null)
    {
	   var obj = evt.target ? evt.target : event.srcElement;
	   var oId = obj.id;
	}
	else
	   var obj = $(oId);
	   
	var parent = obj.parentNode.parentNode;
	if(tagName==null)
		tagName = "A";
	var tabs = _tag$(tagName,parent);
	var theId = "";
	for(var i=0;i<tabs.length;i++)
	{
		if(tabs[i].className.indexOf(cssName)!=-1)
			tabs[i].className = tabs[i].className.replace(" " + cssName,"").replace(cssName,"");
	}
	if(obj.tagName.toLowerCase()!=tagName.toLowerCase())
		obj = obj.parentNode;
	obj.className += " "+cssName;
}

function tab(evt,key,oId,tagName)
{
    if(oId==null)
    {
	   var obj = evt.target ? evt.target : event.srcElement;
	   if(tagName!=null && obj.tagName!=tagName)
	   	obj = obj.parentNode;
	   oId = obj.id;
	}
	else
	   var obj = $(oId);
	var parent = obj.parentNode.parentNode;
	if(key=="menu")parent = parent.parentNode;
	if(tagName==null)
		tagName = "A";
	var tabs = _tag$(tagName,parent);
	var theId = "";
	for(var i=0;i<tabs.length;i++)
	{
		if(tabs[i].id.indexOf("_" + key)==-1)
			continue;
		theId = tabs[i].id;
		$(theId).className = $(theId).className.replace(/\s?active/,"");
		var objAreaId = theId.replace("_" + key,"");
		
		if(theId == oId)
		{
			if($(objAreaId).innerHTML == "" && obj.tagName == "A")
			{
			  $(objAreaId).innerHTML = "数据加载 ...";
			  loadData(objAreaId,obj.href,"","");
			}
			$(objAreaId).style.display = "";
			if(key=="menu")
				$(objAreaId).className = "active"; 
			$(theId).className += " active";
			$(theId).blur();
		}
		else
		{
			$(objAreaId).style.display = "none";
		}
	}
}

function showObj(oS,oH,v)
{
   clearTimeout(timer_pool[0]);
	if(v==null)v=1;
	if(oS!=null)setOpacity(oS,v);
	//if(oH!=null)setOpacity(oS,10-v);
	v += 1;
	if(v>10)return;
	timer_pool[0] = setTimeout("showObj('" + oS + "','" + oH + "'," + v + ")",100);
}
function setOpacity(o,value)
{
    var obj = $(o);
    if(obj==null)return;
    if(obj.style.display=="none")obj.style.display="block";
    obj.style.opacity = value/10;
    obj.style.MozOpacity = value/10;
    obj.style.filter="alpha(opacity="+value*10+")";
}

function getAbsTop(obj) {
var y = obj.offsetTop;
while (obj = obj.offsetParent) {
	y += obj.offsetTop
};
return y;
}

function getAbsLeft(obj) {
var x = obj.offsetLeft;
while (obj = obj.offsetParent) {
	x += obj.offsetLeft
};
return x;
}

function params(paraName,url){
	if(url==null)url = location.href;
	var str="(?:\\?|&){1}"+paraName+"=([^&]*)"
	var re=new RegExp(str,"gi");
	re.exec(url);
	return RegExp.$1;
}

function mail(mailer,title,server)
{
	if(server==null)
	{
		server = document.location.href.split("/")[2];
		if(server.split(".").length==3)
			server = server.split(".")[1]+"."+server.split(".")[2];
	}
	mailer = mailer + "@" + server;
	if(title!=null && title!="")
		title = "subject=" + title;
	else
		title = "";
	document.write('<a href="mailto:'+mailer+'?'+title+'" action="_blank">'+mailer+'</a>')	
}

function makesWin(wName)
{
	if(wName==null)
		wName = "swin" + parseInt(Math.random()*100);
	var sWin = document.createElement("DIV");
	sWin.style.width = "0px";
	sWin.style.height ="0px";
	sWin.style.overFlow ="hidden";
	if(document.location.href.indexOf("l.xiapy.com")==-1)
		sWin.innerHTML="<iframe frameborder=\"0\" width=\"0\" height=\"0\" id=\"" + wName + "\" name=\"" + wName + "\"></iframe>";
	else
		sWin.innerHTML="<iframe frameborder=\"0\" width=\"200\" height=\"200\" id=\"" + wName + "\" name=\"" + wName + "\"></iframe>"
	document.body.appendChild(sWin);
}

function openWin(evt,ask,is_loadding)
{
   if(ask!=null&&!confirm(ask))return;
   var element = evt.target ? evt.target : event.srcElement;
   if(element.tagName!="A")
		element = element.parentNode;
   getWin().src = element.href;
   if(is_loadding==null)
   	element.innerHTML = "处理中...";
   element.herf = "javascript:void(0)";
}

function getWin()
{ 
    var frames = _tag$("IFRAME");
    if(frames.length==0)
    {
        makesWin();
        return getWin();
    }
    
    for(var i=0;i<frames.length;i++)
    {
        if(frames[i].id!="" && frames[i].name!="" && frames[i].name.indexOf("swin")!=-1)return frames[i]; 
    }
    makesWin();
    return getWin();
}

function floatUp(oId,index)
{
    clearTimeout(timer_pool[6+oId]);
    var top = parseInt($(oId).style.top);
    var left = parseInt($(oId).style.left);
    //alert(top);
    if(top < -10)
    {
        $(oId).style.display = "none";
        return;
    }else
        $(oId).style.display = "";
    if(parseInt(top/100) % 2==1)
        left -= (1 + top/20);
    else
        left += (1 + top/20);
    index ++;

    if(index<9)
        setOpacity(oId,index)

    var sValue = parseInt($(oId).innerHTML);
    if(index<=Math.abs(sValue) && index % 10==0)
    {
        var sValue_id = oId.replace("_box","_value")
        if($(sValue_id))
        {
        if(sValue>0)
            $(sValue_id).innerHTML = $(sValue_id).innerHTML*1+1;
        else
            $(sValue_id).innerHTML = $(sValue_id).innerHTML*1-1;
        }
    }
    top -= 25;
    //alert(top);
    //$(oId).style.left = left + "px";
    $(oId).style.top = top + "px";
    timer_pool[6+oId] = setTimeout("floatUp('" + oId + "',"+index+")",100);
}

function showScore()
{
	if(!$("append_area"))
		return;
    var scoreName = ["积分","体力","名望","现金"];
    var scoreColor = ["0E91DC","AF00CE","AF00CE","FF0606"];

    var scoreX = [300,450,600,750];
    var scoreBox;
    var times = arguments[arguments.length-1];
    if(times == "")
        times = 0;
    if(times==0)
        return;
    var score_str = "";
	for(var i=0;i<arguments.length-1;i++)
	{
        scoreBox = $("score_box_" + i);
        arguments[i] = arguments[i]*times
        if(arguments[i]==0)
            continue;

        if(scoreBox == null)
        {
            scoreBox = document.createElement("DIV");
            scoreBox.id = "score_box_" + i;
            score_str = arguments[i] + scoreName[i];
            if(arguments[i]>0)
                score_str = "+" + score_str;
            scoreBox.innerHTML = score_str;
            scoreBox.className = "score_box_" + i;
            scoreBox.style.cssText = "display:none;font-size:16px;padding:30px 0 0 10px;font-weight:bold;z-index:10000;position:absolute;color:#" + scoreColor[i];
            scoreBox.style.left = scoreX[i] + "px";
            $("append_area").appendChild(scoreBox);
        }
        if($("score_value_" + i))
        $("score_value_" + i).innerHTML = $("score_value_" + i).innerHTML*1 + arguments[i];
        setOpacity("score_box_" + i,0)
        scoreBox.style.top = (document.documentElement.scrollTop + 700)+ "px";
        timer_pool[6+i] = setTimeout("floatUp('score_box_" + i + "',0)",i*500);
	}
}

function copy(oId, strTip){
    var t = $(oId);
	t.select();
    //IE           
    if (window.clipboardData) {
        window.clipboardData.clearData();
        window.clipboardData.setData("Text", t.value);        
    }
    //Opera浏览�?
    else 
        if (navigator.userAgent.indexOf("Opera") != -1) {        
            window.location = txt;            
        }        
        //FireFox        
        else 
            if (window.netscape) {           
                try {                
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");                    
                }                
                catch (e) {                
                    alert("您的firefox安全限制限制您进行剪贴板操作，请打开'about:config'�?signed.applets.codebase_principal_support'设置为true'之后重试");                    
                    return false;
                }
                var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
                if (!clip)
                    return;
                var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
                if (!trans)
                    return;
                trans.addDataFlavor('text/unicode');
                var str = new Object();
                var len = new Object();
                var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
                var copytext = t.value;
                str.data = copytext;
                trans.setTransferData("text/unicode", str, copytext.length * 2);
                var clipid = Components.interfaces.nsIClipboard;
                if (!clip) 
                    return false;
                clip.setData(trans, null, clipid.kGlobalClipboard);
            }
    if (strTip == "" || strTip == null) {
        alert("内容复制成功!");
    }
    else {
        alert(strTip);
    }
}

function levelIcon(level)
{
	var strIcon = "";
	if(level>16)
	{
		var sunNum = parseInt(level/16);
		for(var a=0;a<sunNum;a++)
			strIcon += "<img src=\"/skin/level_3.gif\" />";
		level = level % 16;
	}
	if(level>4)
	{
		var moonNum = parseInt(level/4)
		for(var b=0;b<moonNum;b++)
			strIcon += "<img src=\"/skin/level_2.gif\" />";
		level = level % 4;
	}
	for(var c=0;c<level;c++)
		strIcon += "<img src=\"/skin/level_1.gif\" />";
	return strIcon;
}


function doSearch(fId,sType)
{
	var theForm = $(fId);
	if(theForm.key.value == "")
	{
		alert("请输入关键词..");
		return;
	}
	theForm.action = "/" + sType + "/list";
	theForm.submit();
}

function fixPNG(myImage){
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		var cssText = myImage.style.cssText;
		if(cssText.indexOf("AlphaImageLoader")!=-1)
			return;
		cssText += ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + myImage.src + "\', sizingMethod='scale');";
		if(cssText.indexOf("height")!=-1)
			cssText += ";height:"+myImage.offsetHeight+"px;";
		if(cssText.indexOf("width")!=-1)
			cssText += ";width:" + myImage.offsetWidth+"px";
		myImage.style.cssText = cssText;
		myImage.src = "/skin/blank.gif";
    }
}

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,"");
}

window.onload = function() {
	var inputs = _tag$("INPUT");
	for(var ti=0;ti<inputs.length;ti++)
	{
		alert("type:" + inputs[ti].className);
		if(inputs[ti].type=="button" || inputs[ti].type=="submit" || inputs[ti].type=="text" || inputs[ti].type=="password")
		{
			if(inputs[ti].className!="")
				inputs[ti].className += " " + inputs[ti].type;
			else
				inputs[ti].className = inputs[ti].type;
			alert("class:" + inputs[ti].className);
		}
	}
}

if(window.HTMLElement) {
//为兼容FIREFOX，重写的outerHTML方法
var setOuterHtml = function(s){
	var range = this.ownerDocument.createRange();   range.setStartBefore(this);
	var fragment = range.createContextualFragment(s);
	  //alert(fragment.xml);
	this.parentNode.replaceChild(fragment, this);
};
	HTMLElement.prototype.__defineSetter__("outerHTML", setOuterHtml);

HTMLElement.prototype.__defineSetter__("innerText", function (sText) {this.innerHTML = sText.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");});
HTMLElement.prototype.__defineGetter__("innerText", function () {var r = this.ownerDocument.createRange();r.selectNodeContents(this);return r.toString();});
}

//为兼�?focus
window.onload = function() {
	var inputs = _tag$("INPUT");
	for(var ti=0;ti<inputs.length;ti++)
	{
		if(inputs[ti].type!="button" && inputs[ti].type!="reset" && inputs[ti].type!="submit" && inputs[ti].type!="text" && inputs[ti].type!="password")
			continue;
		if(inputs[ti].className!="")
			continue;
		inputs[ti].className = inputs[ti].type;
		if (document.all && !window.opera) //判断是否为IE
		{
			inputs[ti].onfocus = function() {
				this.className = this.className + " focus";
			}
			inputs[ti].onblur = function() {
				this.className = this.className.replace(" focus","");
			}
		}
	}
}
