function bookmark(url, title)
{
	if(window.sidebar)
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if(window.external)
	{ // IE Favorite
		window.external.AddFavorite(url, title);
	}
}
function homepage(me)
{
	var url = 'http://mygamespocket.com/';
	if(window.sidebar)
	{ // Mozilla Firefox Bookmark
		alert("您的瀏覽器不支援自動設定首頁的功能，請您自己手動設定，謝謝！\n\n   http://mygamespocket.com/");
	}
	else if(window.external)
	{ // IE Favorite
		me.style.behavior='url(#default#homepage)';
		me.setHomePage(url)
	}
}
function check_english(input)
{
	for(var i=0;i<input.value.length;++i)
	{
		var c = input.value.charAt(i);
		if(	(c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') )
			continue;
		if( c=='_' )
			continue;
		return false;
	}
	return true;
}
function checkEmail(input)
{
	var ret = false;
	if(input.value.indexOf(" ")<=0)
	{
		var at_index = input.value.indexOf("@");
		var c_index = input.value.lastIndexOf(".");
		ret = (at_index>0 && c_index>2 && (at_index+1)<c_index && c_index<input.value.length-1);
	}
	return ret;
}
function copy_to_clipborad(id)
{
	var obj = document.getElementById(id);
	obj.select();
	if (window.clipboardData) 
	{
		window.clipboardData.setData("Text", obj.value);
	}
	else if (window.netscape) 
	{
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		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=obj.value;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
}

function report_bad_link(gameIndex)
{
	if(confirm("您要回報這個遊戲的網址已經失效\n或是這個遊戲已經不在這個網頁上？"))
		top.location.href="report_bad_link.php?game_index="+gameIndex;
}
function back_site(gameIndex)
{
	var url = "game_detail.php?game_index="+gameIndex;
	if(top.opener!=null && !top.opener.closed)
	{
		top.opener.location.href = url;
		top.opener.focus();
		top.close();
	}
	else
	{
		top.location.href=url;
	}
	
	return false;
}
function back_sitetag(gameIndex, tag)
{
	var url = "game_detail.php?game_index="+gameIndex+"#"+tag;
	if(top.opener!=null && !top.opener.closed)
	{
		top.opener.location.href = url;
		top.opener.focus();
		top.close();
	}
	else
	{
		top.location.href=url;
	}
	
	return false;
}

function on_rate(theform, gameIndex)
{
	var rate = parseInt(theform.score[theform.score.selectedIndex].value);
	if(rate >= 1 && rate <= 5)
	{
		var win = open("rate_game.php?game_index="+gameIndex+"&rate="+rate,"gpsrategame","width=325,height=120,scrollbars=0,toolbar=0,resizable=1");
		win.focus();
	}
	else
	{
		alert("請選擇評分");
	}
}
function goplay(gameIndex, ageconfirm)
{
	if(ageconfirm && !confirm("這個遊戲可能含有血腥或色情的畫面\n您要年滿18歲才能玩這個遊戲喔!"))
		return false;
	var win = open("game_play.php?game_index="+gameIndex,"playgame", "width=860,height=720,scrollbars=1,toolbar=0,resizable=1");
	if(win && !win.closed)
	{
		win.focus();
		return false;
	}
	return true;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function email_user(uid)
{
	var win = open("email_user.php?uid="+uid,"email_user","width=325,height=160,scrollbars=0,toolbar=0,resizable=1");
	win.focus();
	return false;
}
function contact_us()
{
	var win = open("contact_us.php","contactus","width=325,height=350,scrollbars=0,toolbar=0,resizable=1");
	win.focus();
	return false;
}
function del_msg(index, board)
{
	if(confirm("請問您確定要刪除這篇留言嗎？"))
	{
		var win = open("update_message.php?op=del&index="+index+"&board="+board,"update_comment","width=325,height=120,scrollbars=0,toolbar=0,resizable=1");
	}
	return false;
}
function edit_msg(index, board)
{
	var win = open("update_message.php?op=edit&index="+index+"&board="+board,"update_comment","width=325,height=120,scrollbars=0,toolbar=0,resizable=1");
	win.focus();
	return false;
}
function del_cmt(index)
{
	if(confirm("請問您確定要刪除這篇文章嗎？"))
	{
		var win = open("update_comment.php?op=del&index="+index,"update_comment","width=325,height=120,scrollbars=0,toolbar=0,resizable=1");
	}
	return false;
}
function edit_cmt(index)
{
	var win = open("update_comment.php?op=edit&index="+index,"update_comment","width=325,height=120,scrollbars=0,toolbar=0,resizable=1");
	win.focus();
	return false;
}
function reply_cmt(index)
{
	var win = open("read_comment.php?index="+index+"#reply","read_comment","width=500,height=400,scrollbars=1,toolbar=0,resizable=1");
	win.focus();
	return false;
}
function read_cmt(index)
{
	var win = open("read_comment.php?index="+index,"read_comment","width=500,height=400,scrollbars=1,toolbar=0,resizable=1");
	win.focus();
	return false;
}
function on_accuse(game_index)
{
	if(game_index > 0)
	{
		var win = open("accuse.php?game_index="+game_index,"gpsaccuse","width=380,height=300,scrollbars=0,toolbar=0,resizable=1");
		win.focus();
	}
}
function chooseMessage()
{
	var index = Math.floor(Math.random()*gMessages.length);
	var msg = gMessages[index];
	if(msg == gMessage)
		msg = gMessages[(index+1)%gMessages.length];
	gMessage = msg;
	gMsgIndex = 0;
}
function anim_led()
{
	var led = document.getElementById("led");
	var width = parseInt(led.style.width);
	var fontsize = 12;
	var maxChars = Math.floor(width/fontsize);
	var msg = "";
	var num_spaces = maxChars-gMsgIndex;
	for(var i=0;i<num_spaces;++i)
	{
		msg += "  ";
	}
	var startIndex = 0;
	var wait = gMessage.length*2 + 10;
	if(num_spaces < -wait)
	{
		startIndex -= (num_spaces+wait);
	}
	msg += gMessage.substr(startIndex, ++gMsgIndex);
	led.value = msg;
	
	if(startIndex > gMessage.length)
	{
		chooseMessage();
	}
	setTimeout("anim_led()", 100);
}
function bk_hemi()
{
	desc='';
	via='';
	if(document.referrer)via=document.referrer;
	if(typeof(_ref)!='undefined')via=_ref;
	if(window.getSelection)desc=window.getSelection();
	if(document.getSelection)desc=document.getSelection();
	if(document.selection)desc=document.selection.createRange().text;
	return 'http://www.hemidemi.com/user_bookmark/new?title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&description='+encodeURIComponent(desc)+'&via='+encodeURIComponent(via);
}
function bk_digg()
{
	desc='';
	if(window.getSelection)desc=window.getSelection();
	if(document.getSelection)desc=document.getSelection();
	if(document.selection)desc=document.selection.createRange().text;
	return 'http://digg.com/submit?phase=2&title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href)+'&bodytext='+encodeURIComponent(desc)+'&topic=playable_web_games';
}
function bk_myshare()
{
	d=document;
	w=window;t='';
	if(d.selection){t=d.selection.createRange().text;}
	else if(d.getSelection){t=d.getSelection();}
	else if(w.getSelection){t=w.getSelection();}
	return 'http://myshare.url.com.tw/index.php?func=newurl&from=mysharepop&NewsMaster=1&url='+encodeURIComponent(location.href)+'&desc='+escape(document.title)+'&contents='+escape(t);
}
function bk_delicious()
{
	return 'http://del.icio.us/post?v=4&title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(location.href);
}
function bk_furl()
{
	return 'http://www.furl.net/storeIt.jsp?t='+encodeURIComponent(document.title)+'&u='+encodeURIComponent(location.href);
}
function bk_yahoo()
{
	return 'http://tw.myweb2.search.yahoo.com/myresults/bookmarklet?u='+encodeURIComponent(location.href)+'&ei=UTF-8&t='+encodeURIComponent(document.title);
}
function bk_youpush()
{
	q=(document.location.href);
	return 'http://www.youpush.net/submit.php?url='+escape(q);
}
function bk_search20()
{
	t=document.title;
	n=(window.getSelection? window.getSelection(): (document.getSelection? document.getSelection(): (document.selection? document.selection.createRange().text: '')));
	return 'http://search20.portal20.com.tw/x.jsp?f=1&t='+encodeURIComponent(t)+'&u='+encodeURIComponent(location.href)+'&n='+encodeURIComponent(n);
}
