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 copyToClipboard (textit) {
	if (window.clipboardData) {
		window.clipboardData.setData("Text",textit);
	} else {
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="/common/_clipboard.swf" FlashVars="clipboard='+textit+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
	alert('This page address has been copied, you can paste to sent ^_^')
}

var copyURL={}
copyURL.url= String(self.location)
copyURL.init=function(){
	var s=""
	s+="<table cellspacing=0 cellpadding=0 border=0><tr><td>"
	s+="Recommend this game to your friends:"
	s+=this.url+"<br>"
	s+="<INPUT onclick=copyURL.copy(1) type=button value='copy URL address' />"
	s+="<INPUT onclick=copyURL.copy(2) type=button value='copy HTML code' />"
	s+="<INPUT onclick=copyURL.copy(3) type=button value='copy UBB code' />"
	s+="</td></tr></table>"
	document.write(s)
}
copyURL.copy=function(type){
	var u = this.url;
	var t = document.title;
	var s = "";
	if		(type==1){s = ""+t+". Oh this game is good fun! Games address is:"+u;
	}else if(type==2){s = '<a href="'+u+'" target="_blank">'+t+'</a> Oh this game is good fun! Games address is:<a href="'+u+'" target="_blank">'+u+"</a>";
	}else if(type==3){s = "[url="+u+"]"+t+"[/url] Oh this game is good fun! Games address is:[url="+u+"]"+u+"[/url]";
	}
	copyToClipboard(s)
}

function trim(s){
	return s.replace(/(^[ 　\t\r\n]*)|([ 　\t\r\n]*$)/g, "");
}

function strGetUrlArg(s,sv,sd){
	var a=s.match(new RegExp("(^|&|\\?)"+sv+"=[^&]*"))
	return a==null||sv==""?(sd||""):a[0].slice(sv.length+2)
}
function strReverse(s) {
	return s.split("").reverse().join("");
}


function limitText(t,n){
	if(t.value.length>n) t.value=t.value.substring(0,n);
}
function addFavorite (title,url) {if (window.sidebar) { window.sidebar.addPanel(title, url,""); } else if( document.all ) {window.external.AddFavorite( url, title);} else if( window.opera && window.print ) {return true;}}

function checkSearch(f){
	var s=trim(f.s.value)
	f.s.value=s
	if(s!="") window.location="/s-"+encodeURIComponent(s)+"-1.html"
	return false
}

function selectMenuItem(){
	var a=$("h-menu").getElementsByTagName("a")
	var b=String(window.location).match(/([^\/-]+)-[0-9]+.html$/)
	if(b){
		for(var i=0;i<a.length;i++){
			if(a[i].href.indexOf(b[1])!=-1){a[i].className="st";return;}
		}
	}
	a[0].className="st"
}

//B popTip
var popTip={}
popTip.show=function(id,str){
	try{
		var p = document.createElement("div");
		document.body.appendChild(p);
		p.id = "popTip";
		p.style.position="absolute"
		p.style.zIndex=8
		var s=''
		s+='<table border="0" cellspacing="0" cellpadding="0"><tr>'
		s+='<td width="35"><img src="/images/tt_01.png" width="35" height="26" /></td>'
		s+='<td valign="bottom" background="/images/tt_02.png">'+str+' </td>'
		s+='<td width="28"><a href="javascript:popTip.hide()"><img src="/images/tt_04.png" width="28" height="26" border="0" /></a></td>'
		s+='</tr><tr>'
		s+='<td width="35"><img src="/images/tt_12.png" width="35" height="24" /></td>'
		s+='<td background="/images/tt_13.png">&nbsp;</td>'
		s+='<td width="28"><img src="/images/tt_14.png" width="28" height="24" /></td>'
		s+='</tr></table>'
		p.innerHTML=s

		var t=$(id);
		var ol=t.offsetLeft
		var ot=t.offsetTop
		var ow=t.clientWidth

		while(t=t.offsetParent){
			ot+=t.offsetTop;
			ol+=t.offsetLeft;
		}
		p.style.top = ot-44+"px";
		p.style.left = ol+ow-22+"px";
	}catch(e){
		alert(str)
	}
}
popTip.hide=function(){
	var p=$("popTip")
	if(p)p.parentNode.removeChild(p)
}
//E popTip

//getcookie('goodness')
function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

//setcookie("goodness","yes",24*3600*1000);
function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

window.defaultStatus="Press Ctrl + D, see what happens?";

var doc={}
doc.nav=function(){
	var s="<a href=/ >home</a>"
	var a={
		"Action":"action",
		"Sports":"sports",
		"Puzzle":"puzzle",
		"Shooting":"shooting",
		"Funny":"funny",
		"Adventure":"adventure",
		"Fighting":"fighting",
		"Strategy":"strategy",
		"Agile":"agile",
		"DressUp":"dress-up",
		"Layout":"layout",
		"Business":"business"
	}
	for(var i in a){
		s+="<a href=/"+a[i]+"-1.html>"+i+"</a>"
	}
	document.write(s)
}
doc.qq=function() {
	var s="email: #@qq.com"
	s=s.replace(/#/g,strReverse("968422365"))
    document.write(s)
}
doc.setGameInfo=function(){
	$("game-info-text").innerHTML=$("c-info-text").innerHTML
}
doc.cryear=function(){
	var s="2000-"+(new Date().getYear())
	document.write(s)
}

skipForm = function(cn,tn,p){
	p=p.split("#")
	var s="<select onchange='window.location=\""+p[0]+"\"+this.value+\""+p[1]
	s+="\"'>"
	for(var i=1;i<=tn;i++){
		s+="<option value="+i
		if(i==cn) s+=" selected"
		s+=">"+i+"</option>"
	}
	s+="</select>"
	document.write(s)
}
