var g_aLinks = new Array(
	new Array("", "game", "post", "comment", "gb", "news", "posofday", "user"),                               // 0
	new Array("404.php?id=", "/#", "forum.php?p=", "lastcomments.php?cid=", 
	          "guestbook.php?bid=", "newsarchive.php?nid=", "positionsofday.php?gid=", "profile.php?uid="),   // 1
	c_t35,                                                                                                    // 2
	c_t36                                                                                                     // 3
);

var g_aImg = new Array(new Image(), new Image(), new Image());
g_aImg[0].src = "/img/sgray.gif";
g_aImg[1].src = "/img/sgreenm.gif";
g_aImg[2].src = "/img/filter.gif";

function SB()
{
	var a, i, k;
	var o, oImg;
	var sClass;

	oImg = document.getElementById("iHlp");
	if( oImg ){
		oImg.className = "help";
		oImg.width = 24;
		oImg.height = 13;
		oImg.src = "img/HlpH.gif";
		oImg.align = "absmiddle";
		oImg.onmouseover = fa;
		oImg.onmouseout = fo;
		oImg.title = c_t34;
	}
						
	a = document.getElementsByTagName("TH");
	for(i=0; i<a.length; i++){
		o = a[i];
		if( o.id.length>2 ){
			s = o.id.substring(0, 2);
			if( s=="df"  ){
				o.className = "g";
				o.onclick = df;
				o.onmouseover = fa;
				o.onmouseout = fo;
			}
		}
	}

	a = document.getElementsByTagName("TD");
	for(i=0; i<a.length; i++){
		o = a[i];
		s = o.id.length < 3 ? "" : o.id.substring(0, 2);
		if( s=="vg" || s=="og" ){
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg ){
				oImg.width= 27;
				oImg.height = 13;
				oImg.src = "img/vg.gif";
			}
			if( !o.title )
				o.title = s=="vg" ? c_t01 : c_t02;
			if( !o.className )
				o.className = "gm";
			o.onclick = vg;
			o.onmouseover = fa;
			o.onmouseout = fo;
		}
		else if( s=="pi" || s=="pc" ){
			if( !o.title )
				o.title = c_t03+(1 + parseInt(o.id.substring(2, o.id.length)));
			o.className = s=="pi" ? "m" : "mC";
			o.style.paddingLeft = 3;
			o.style.paddingRight = 3;
			if( !o.onclick )
				o.onclick = gp;
			o.onmouseover = fa;
			o.onmouseout = fo;
		}
		else if( s=="eb" || s=="nb" ){
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg ){
				oImg.width= 17;
				oImg.height = 13;
				oImg.src = "img/voice.gif";
			}
			o.className = "gm";
			o.title = s=="eb" ? c_t04 : c_t05;
			o.onclick = sr;		
			o.onmouseover = fa;
			o.onmouseout = fo;
		}
		else if( s=="ac" || s=="vc" || s=="nc" ){
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg ){
				oImg.width= 11;
				oImg.height = 13;
				oImg.src = s=="nc" ? "img/ac.gif" : "img/cm.gif";
			}
			if( !o.className )
				o.className = "gm";
			o.title = (s=="ac" ? c_t06 : (s=="vc" ? c_t07 : c_t08));
			o.onclick = s=="nc" ? ac : cm;		
			o.onmouseover = fa;
			o.onmouseout = fo;
		}		
		else if( s=="sb" ){
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg ){
				oImg.width= 26;
				oImg.height = 16;
				oImg.src = o.id=="sb0" ? "img/UnsetBestgame.gif" : "img/SetBestgame.gif";
			}
			o.className = "gm";
			o.title = o.id=="sb0" ? c_t09 : c_t10;
			o.onclick = SetBestGame;
			o.onmouseover = fa;
			o.onmouseout = fo;		
		}
		else if( s=="ti" ){
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg ){
				oImg.width= 27;
				oImg.height = 24;
				oImg.src = "img/tg.gif";
			}
			o.className = "gm";
			o.title = c_t11+o.title+"'";
			o.onmouseover = fa;
			o.onmouseout = fo;				
		}
		else if( s=="pf" || s=="pn" || s=="ch" || s=="bg" ){
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg ){
				oImg.height = 13;
				oImg.src = "img/"+s+".gif";
			}
			o.title = (s=="pf" || s=="pn" ? c_t25 : (s=="ch" ? c_t27 : c_t28));
			o.className = "gm";
			o.onclick = (s=="pf" || s=="pn" ? vpf : (s=="ch" ? sch : vg));
			o.onmouseover = fa;
			o.onmouseout = fo;			
		}
		else{
			sClass = o.className;
			if( sClass=="m" || sClass=="mC" || sClass=="gm" || sClass=="btn" || sClass=="btnD" ){
				o.onmouseover = fa;
				o.onmouseout = fo;
			}
			else if( sClass=="ch" )
				o.title = c_t41;
			else if( sClass=="cg" )
				o.title = c_t42;
		}
	}
	
	a = document.getElementsByTagName("A");
	for(i=0; i<a.length; i++){
		o = a[i];
		if( o.id.length < 2 )
			continue;
		s = o.id.substring(0, 2);
		if( s=="sg" ){
			o.href = "/#";
			o.title = c_t12;
			o.className = "k";
			o.onclick = smg;
		}
		else if( s=="gp" || s=="gw" || s=="gl" || s=="gt" ){
			o.className = "k";
			o.title = s=="gp" ? c_t39 : (s=="gw" ? c_t51 : (s=="gl" ? c_t52 : c_t53));
			o.href = "findgames.php?uid="+o.parentNode.parentNode.id.substring(2, o.parentNode.parentNode.id.length)+"&s="+s;
		}
		else if( s=="sv" ){
			o.title = c_t13+o.title+")";
			o.href = "javascript:sv('"+o.id.substring(2, o.id.length)+"');";
		}
		else if( s=="ui" || s=="uk" || s=="z7" ){
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg ){
				oImg.width= 16;
				oImg.height = 13;
				oImg.src = "img/pf.gif";
			}
			if( !o.title )
				o.title = c_t32;
			if( s=="uk" )
				o.className = "k";
			o.href = "profile.php?uid="+o.id.substring(2, o.id.length);
		}
		else if( s=="ah" ){
			o.onmouseover = lma;
			o.onmouseout = lmo;
		}
		else if( s=="x1" || s=="x2" || s=="x3" || s=="x4" || s=="x5" || s=="x6" || s=="x7" ){
			k = parseInt(s.charAt(1));
			o.className = "k";
			o.title = g_aLinks[3][k];
			o.href = g_aLinks[1][k] + o.id.substring(2, o.id.length);
			o.onclick = CopyLink;
		}
		else if( s=="z1" ){
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg ){
				oImg.width= 27;
				oImg.height = 13;
				oImg.src = "img/vg.gif";
			}
			if( !o.title )
				o.title = c_t01;
			o.href = "/#";
			o.onclick = vg;
		}
		else if( s=="z2" || s=="z3" || s=="z4" || s=="z5" || s=="z6" ){
			k = parseInt(s.charAt(1));
			oImg = o.getElementsByTagName("IMG")[0];
			if( oImg && !oImg.src ){
				oImg.width= 10;
				oImg.height = 10;
				oImg.src = s=="z2" ? "img/qt.gif" : "img/ln.gif";
			}
			o.title = g_aLinks[2][k];
			o.href = g_aLinks[1][k] + o.id.substring(2, o.id.length);
			o.onclick = z;
		}
		else if( s=="hr" ){
			o.href = o.innerHTML;
			o.target = "_blank";
			o.title = c_t37;
		}
		else if( s=="ml" ){
			o.href = "mailto:"+o.innerHTML;
			o.title = c_t38+o.innerHTML;
		}
	}
	
	a = document.getElementsByTagName("IMG");
	for(i=0; i<a.length; i++){
		o = a[i];
		if( o.id.length < 3 )
			continue;
		s =  o.id.substring(0, 2);
		if( s=="sm" )
			o.src = "img/smiles/"+o.id+".gif";
	}	
}

function ST()
{
	var a, o, s, i, k;
	a = document.getElementsByTagName("IMG");
	for(i=0; i<a.length; i++){
		o = a[i];
		s = o.id;
		if( s.substring(0, 2)=="bs" ){
			k = parseInt(s.charAt(2));			
			o.width= 14;
			o.height = 14;
			o.src = "img/"+s+".gif";
			if( k < 8 ){
				o.align = (k & 4) ? "right" : "left";
				o.title = ((k & 1) ? c_t15 : c_t14) + ", " + ((k & 2) ? c_t24 : c_t23);
			}
			else{
				o.align = (k == 9) ? "right" : "left";
				o.title = (k == 9) ? c_t24 : c_t23;			
			}
		}
		else if( s=="er" || s=="el" ){
			o.width = 14;
			o.height = 14;
			o.src = "img/e.gif";
			o.align = s.charAt(1)=='r' ? "right" : "left";
		}
	}
}

// nUserStatus = 0 - onlooker
//             = 1 - gamer
//             = 2 - white gamer
function ogwP(nGameID, nUserStatus, sParams)
{
	var nW, nH, s, n, a;
	
	nH = 0;
	s = document.cookie;
	if( (n = s.indexOf("bs=")) != -1 ){
		if( (i = s.indexOf(";", n+3)) == -1 )
			i = s.length;
		a = s.substring(n+3, i).split(",");
		if( a.length > 9 ){
			nW = a[8];
			nH = a[9];
		}
	}

	if( !nH ){
		if( screen.height==600 ){
			nW = 690; nH = 474;
		}
		else if( screen.height==768 ){
			nW = 937; nH = 684;
		}
		else if( screen.height==1024 ){
			nW = 1108; nH = 798;
		}
		else{
			nW = Math.round(screen.height*1.19) + 4;
			nH = Math.round(screen.height*0.88) + 8;
		}
	}
	
	window.open("board.php?gid="+nGameID.toString()+"&us="+nUserStatus+sParams,"b"+nGameID.toString()+"_"+rnd()+"_Slon",
		"width="+nW.toString()+",height="+nH.toString()+
		",resizable");
}

function ogw(nGameID, nUserStatus)
{
	ogwP(nGameID, nUserStatus, "");
}

function df()
{
	document.forms.ft.so.value = this.id.substring(2, this.id.length);
	document.forms.ft.submit();
}

function gp()
{
	document.forms.ft.pi.value = this.id.substring(2, this.id.length);
	document.forms.ft.submit();	
}

function fme(sCellId, bOff)
{
	document.getElementById(sCellId).style.borderColor = bOff ? "#EFEFDE" : "#3169C6";
}

function ff(obj, sCellId)
{
	obj.select();
	fme(sCellId, 0);
}

function ChangeLogFilter()
{
	document.forms.ft.lf.value = document.forms.ft.lf.value!="" ? "" : "1";
	if( document.forms.ft.wf.value=="" && document.forms.ft.bf.value=="" )
		document.getElementById("LogFilter").innerHTML = document.forms.ft.lf.value!="" ? c_t16 : c_t17;
	else
		document.forms.ft.submit();
}

function SetBestGame()
{
	document.forms.setbg.action = g_sURL;
	document.forms.setbg.bgid.value = this.id.substring(2, this.id.length);
	document.forms.setbg.submit();
}

function ShowMyGames(nId)
{
	window.location.href = "/gamestopped.php" + (nId ? "?o=1" : "");
}

function gt(sPage)
{
	window.location.href = sPage;
}

function sf(sFile)
{
	var nW, nH;
	nW = screen.width>840 ? 840 : 690;
	nH = screen.height>640 ? 640 : 520;

	window.open("img/foto/"+sFile,"bFotoSlon",
		"width="+nW.toString()+",height="+nH.toString()+
		",resizable,scrollbars");
}

function cm()
{
	window.open("comments.php?gid="+this.id.substring(2, this.id.length), "CommentSlon",
		"width="+(Math.round(screen.height*4/5)).toString()+",height="+(Math.round(screen.height*2/3)).toString()+
		",resizable,scrollbars").focus();
}

function ac()
{
	window.open("newcomment.php?gid="+this.id.substring(2, this.id.length), "NewCommentSlon",
		"width="+(Math.round(screen.height*2/3)).toString()+",height="+(Math.round(screen.height*1/2)).toString()+
		",resizable").focus();
}

function vg()
{
	ogw(this.id.substring(2, this.id.length),0);
	return false;
}

function smg()
{
	document.forms.ft.uid.value = this.parentNode.id.substring(2, this.parentNode.id.length);
	document.forms.ft.pi.value = "0";
	if( document.forms.ft.wf )
		document.forms.ft.wf.value = "";
	if( document.forms.ft.bf ){		
		document.forms.ft.bf.value = "";
		document.forms.ft.lf.value = "1";
	}
	document.forms.ft.submit();

	return false;
}

function vpf()
{
	window.location.href = "profile.php?uid="+this.id.substring(2, this.id.length);
}

function sch()
{
	ocw(","+this.id.substring(2, this.id.length)+",");
}

function lma()
{
	return ma(document.getElementById("l"+this.id.substring(2, this.id.length)));
}

function lmo()
{
	return mo(document.getElementById("l"+this.id.substring(2, this.id.length)));
}

function mem(n)
{
	if( n ){
		n = document.forms.ft.pi.value;
		document.forms.ft.pi.value = (n=="-1" ? "0" : "-1");		
	}
	document.forms.ft.submit();
}

function CopyLink()
{
	var sLink = "["+g_aLinks[0][parseInt(this.id.charAt(1))]+this.id.substring(2, this.id.substring(2, this.id.length))+"]";

	if( window.clipboardData )
		window.clipboardData.setData("Text", sLink);
	else
		window.prompt(c_t40, sLink);
	
	return false;
}

function GotoShortcut(sName, nID)
{
	var obj, h, sURL;
	
	obj = document.getElementById(sName+nID.toString());
	if( obj ){
		h = obj.offsetTop;	
		do{
			obj = obj.offsetParent;
			h += obj.offsetTop;
		}while( obj != document.body );	
		window.scroll(0, h-8-(nID ? 0 : 24));
		return false;
	}
	else{
		sURL = g_aLinks[1][parseInt(sName.charAt(1))] + nID.toString();
		if( window.location.href.indexOf("/comments.php")==-1 && window.location.href.indexOf("/cht.php")==-1 ){
			window.location.href = sURL;
			return true;
		}
		else{
			window.open(sURL, "Level2Slon", "width=0,height=0,location,resizable,scrollbars,toolbar,status,menubar").focus();
			return false;
		}
	}
}
function z()
{
	return GotoShortcut("x"+this.id.substring(1, 2), this.id.substring(2, this.id.length));
}

function CrF(sWf, sBf, nSo, bLf, sWt, sBt)
{
	document.write("\
		<table class=g border=0 cellspacing=0 cellpadding=0 width=100% style=\"margin-top:0px;table-layout:fixed;\">\
		<tr>\
			<th id=WhiteFilter class=g\
			><input type=text class=ft name=wf maxlength=48 value=\""+sWf+"\"\
				title=\""+sWt+"\"\
				onfocus=\"javascript:ff(this, 'WhiteFilter');\"\
				onblur=\"javascript:fme('WhiteFilter', 1);\"\
				onmouseover=\"javascript:fme('WhiteFilter', 0);\"\
				onmouseout=\"javascript:fme('WhiteFilter', 1);\"\
			><input type=hidden name=so value=\""+nSo+"\"></th>\
			<th width=1></th>\
			<th class=g style=\"width:20pt;\" title=\""+c_t18+"\"\
				onmouseover=\"javascript:ma(this);\"\
				onmouseout=\"javascript:mo(this);\"\
				onclick=\"javascript:ChangeLogFilter();\"\
			><span id=LogFilter class=sl>"+(bLf!="" ? c_t16 : c_t17)+"</span></th>\
			<th width=1></th>\
			<th id=BlackFilter class=g\
			><input type=text class=ft name=bf maxlength=48 value=\""+sBf+"\"\
				title=\""+sBt+"\"\
				onfocus=\"javascript:ff(this, 'BlackFilter');\"\
				onblur=\"javascript:fme('BlackFilter', 1);\"\
				onmouseover=\"javascript:fme('BlackFilter', 0);\"\
				onmouseout=\"javascript:fme('BlackFilter', 1);\"\
			><input type=hidden name=lf value=\""+bLf+"\"></th>\
		</tr>\
		</table>"
	);
}

function CrS(pi, nMax, nPages)
{
	var i, nStart, nEnd;
	
	nStart = Math.floor(pi / nMax) * nMax;
	nEnd = Math.min(nStart+nMax, nPages);
	
	document.write("\
		<p></p>\
		<div align=right>\
		<table class=m border=0 cellspacing=4 cellpadding=0 style=\"border:0px none #FFFFFF;\">\
		<tr>"+(pi >= nMax ? "\
			<td id=pi0 title=\""+c_t26+"\">&lt;&lt;</td>\
			<td id=pi"+(nStart-1).toString()+">&lt;</td>" : "")
	);
	for(i=nStart; i<nEnd; i++)
		document.write("			<td id="+(i==pi ? "pc" : "pi")+i.toString()+">"+(i+1).toString()+"</td>");
	document.write((nEnd < nPages ? "\
			<td id=pi"+nEnd.toString()+">&gt;</td>\
			<td id=pi"+(nPages-1).toString()+" title=\""+c_t33+"\">&gt;&gt;</td>" : "") + "\
		</tr>\
		</table>\
		</div>"
	);
}
