
/*----------------------------------------------------------------------
  life.js
----------------------------------------------------------------------*/


function popup(url,width,height) {
	var properties = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + width + ",height=" + height;
	var myPopup = window.open(url, "myPopup", properties);
	myPopup.focus();
}

function scrollMeRed(speed) {
	frames.leftframe.scrollBy(0,speed);
	if (speed != 0) {
		redTime = setTimeout("scrollMeRed(" + speed + ")",25);
	}else{
		if (redTime) clearTimeout(redTime);
	}
}
function scrollMeBlue(speed) {
	frames.rightframe.scrollBy(0,speed);
	if (speed != 0) {
		blueTime = setTimeout("scrollMeBlue(" + speed + ")",25);
	}else{
		if (blueTime) clearTimeout(blueTime);
	}
}


function rYourS() {
	document.rYour.src="images/r_yourboardon.gif";
	document.rRank.src="images/r_rankedoff.gif";
	window.frames["leftframe"].src="yourlist.php?color=1";
}

function rYourSNoLog() {
	document.rYour.src="images/r_yourboardon.gif";
	document.rRank.src="images/r_rankedoff.gif";
	window.frames["leftframe"].src="yourlistNoLog.php?color=1";
}

function rRankS() {
	document.rYour.src="images/r_yourboardoff.gif";
	document.rRank.src="images/r_rankedon.gif";
	window.frames["leftframe"].src="rankedlist.php?color=1";
}


function bYourS() {
	document.bYour.src="images/b_yourboardson.gif";
	document.bRank.src="images/b_rankedoff.gif";
	window.frames["rightframe"].src="yourlist.php?color=2";
}

function bYourSNoLog() {
	document.bYour.src="images/b_yourboardson.gif";
	document.bRank.src="images/b_rankedoff.gif";
	window.frames["rightframe"].src="yourlistNoLog.php?color=2";
}

function bRankS() {
	document.bYour.src="images/b_yourboardsoff.gif";
	document.bRank.src="images/b_rankedon.gif";
	window.frames["rightframe"].src="rankedlist.php?color=2";
}



/*----------------------------------------------------------------------
  life.js (BAKSE)
----------------------------------------------------------------------*/
yourSelection = 0;
yourSelectionColor = "";

redSelection = 0;
redSelectionColor = "";
redName = "";

blueSelection = 0;
blueSelectionColor = "";
blueName = "";

function autoSetYourPreview(){
	window.frames["leftframe"].document.getElementById("row1").onclick();
}

function autoSetBattlePreview(){
	window.frames["leftframe"].document.getElementById("row1").onclick();
	window.frames["rightframe"].document.getElementById("row2").onclick();
}
function setYourPreview(row, name, wins, losses, draws)
{
	
	document.getElementById("boardName").innerHTML = name;
	document.getElementById("boardWins").innerHTML = wins;
	document.getElementById("boardLosses").innerHTML = losses;
	document.getElementById("boardDraws").innerHTML = draws;
	
	if (yourSelection > 0){
		window.frames["leftframe"].document.getElementById("row"+yourSelection).style.backgroundColor = yourSelection;
	}
	
	yourSelection = row;
	yourSelectionColor = window.frames["leftframe"].document.getElementById("row"+row).style.backgroundColor;	
	window.frames["leftframe"].document.getElementById("row"+row).style.backgroundColor = '#860000';
}

function setRedPreview(row, name)
{
	
	redName = name;
	document.getElementById("redName").innerHTML = name;
	
	
	if (redSelection > 0){
		window.frames["leftframe"].document.getElementById("row"+redSelection).style.backgroundColor = redSelectionColor;
	}
	
	redSelection = row;

	redSelectionColor = window.frames["leftframe"].document.getElementById("row"+row).style.backgroundColor;	
	window.frames["leftframe"].document.getElementById("row"+row).style.backgroundColor = '#860000';
}

function setBluePreview(row, name)
{
	blueName = name;
	document.getElementById("blueName").innerHTML = name;
	
	
	if (blueSelection > 0){
		window.frames["rightframe"].document.getElementById("row"+blueSelection).style.backgroundColor = blueSelectionColor;
		//window.frames["rightframe"].document.getElementById("row"+blueSelection).style['border'] = 'none';
	}
	
	blueSelection = row;

	blueSelectionColor = window.frames["rightframe"].document.getElementById("row"+row).style.backgroundColor;	
	window.frames["rightframe"].document.getElementById("row"+row).style.backgroundColor = '#0F385E';
	
	//window.frames["rightframe"].document.getElementById("row"+row).style['border-top'] = '1px solid #ffffff';
	//window.frames["rightframe"].document.getElementById("row"+row).style['border-bottom'] = '1px solid #ffffff';
}

function startBattle()
{
			window.location = "battle2.php?board1="+urlencode(redName)+"&board2="+urlencode(blueName);
			//	window.location = "battle2.php?board1="+redName+"&board2="+blueName;
	
}

function urlencode(strText) 
{
	var isObj; 
	var trimReg; 

	if (typeof (strText)  == "string" ) { 
		if( strText != null ) { 
	
			trimReg = /(^\s+)|(\s+$)/g; 
			strText = strText.replace( trimReg, ''); 
	
			for (i=32;i<256;i++)        {
				strText = strText.replace(String.fromCharCode(i),escape(String.fromCharCode(i)));
			} 
	
		} 	
	}
	return strText; 

}

