<!--

function GetCenterPositionCode(width, height)
{
	isNetscape = navigator.appName.indexOf('Netscape')>=0;
	isExplorer = navigator.appName.indexOf('Explorer')>=0;

	sw  = screen.width;
	sh  = screen.height - 100;
	wbx = Math.round((sw-width)/2);
	wby = Math.round((sh-height)/2);
	
	if (isNetscape)
		return 'screenX='+wbx+',screenY='+wby;
	else
		return 'left='+wbx+',top='+wby;
}

function ActivateGame(gameId, buttonClientId, statClientId)
{
	var btnEnter = window.document.getElementById(buttonClientId);
	if (btnEnter != null)
		btnEnter.style.display = '';

	if (statClientId != '') {
		var lnkStat = window.document.getElementById(statClientId);
		if (lnkStat != null)
			lnkStat.style.display = '';
	}
	
	newWin = window.open('/GameEngine.aspx?gid=' + gameId, '_blank');
	newWin.focus();
}
function OpenSearchWindow()
{
	var w = 410;
	var h = 300;
	newWin = window.open('/PlayerSearch.aspx', 'EnPlayersSearch', 'height='+h+',width='+w+',resizable=yes,scrollbars=yes,' + GetCenterPositionCode(w,h));
	newWin.focus();
}
function OpenerReload()
{
	opener.document.location.href = opener.document.location.href;
}
function WindowClose()
{
	window.close();
}

function OpenScrollableWindow(link, winname, width, height)
{
	var w = width;
	var h = height;
	cal = window.open(link, winname, 'toolbar=no,menubar=no,status=no,scrollbars=yes,resizable=1,height='+h+',width='+w+',' + GetCenterPositionCode(w,h));
	if (!cal.opener)
		cal.opener = self;
	cal.focus();
}

function OpenFixedSizeWindow(link, winname, width, height)
{
	var w = width;
	var h = height;
	cal = window.open(link, winname, 'toolbar=no,menubar=no,status=no,scrollbars=no,resizable=0,height='+h+',width='+w+',' + GetCenterPositionCode(w,h));
	if (!cal.opener)
		cal.opener = self;
	cal.focus();
}

function OpenNewPhotoGalleryWindow( link, winname )
{
	var w = 820;
	var h = 500; 
	OpenFixedSizeWindow( link, winname, w, h );
}

function OpenUserRanksWindow()
{
	var w = 640;
	var h = 468;
	OpenFixedSizeWindow( '/UserRanks.aspx', 'UserRanks', w, h );
}

function confirmClick( message )
{
	confirmed = window.confirm ( message );
	if (!confirmed)
	{
		event.returnValue = false;
		return false;
	}
}

//takes UTC date and returns array of offset sign and GMT offset value
//the first index is sign, the second is value
function GetGMTOffsetInfo(strDate) 
{
	var date = new Date();
	if (strDate != null)
		date = new Date(strDate);
		
	var offTime = date.getTimezoneOffset();
	var DST = 2*date.getTimezoneOffset() - new Date(date.getFullYear() - 1, 0).getTimezoneOffset() - new Date(date.getFullYear() - 1, 6).getTimezoneOffset();
	var offset = DST >= 0 ? -1*parseFloat(offTime / 60) : parseFloat((DST - offTime) / 60);
	//var offset = DST >= 0 ? parseFloat((DST - offTime) / 60) : -1*parseFloat(offTime / 60);
	var sign = offset > 0 ? "+" : offset < 0 ? "-" : "";
	
	return [sign, Math.abs(offset)];
}

//takes UTC date and returns array of offset sign and UTC offset value
//the first index is sign, the second is value
function GetUTCOffsetInfo(strDate) 
{
	var date = new Date();
	if (strDate != null)
		date = new Date(strDate);
		
	var offTime = date.getTimezoneOffset();
	var offset = -1*parseFloat(offTime / 60);
	var sign = offset > 0 ? "+" : offset < 0 ? "-" : "";
	
	return [sign, Math.abs(offset)];
}

//takes UTC date and returns local date
function DateToLocalString(strDate) {
	var date = new Date(strDate);
	return date.toLocaleString();
}

function FormatToLocalDate(date)
{ 
	var ms = new Array('01','02','03','04','05','06','07','08','09','10','11','12'); 
	var dt = date.getDate(); 
	var m = date.getMonth(); 
	var y = date.getYear(); 
	var h = date.getHours(); 
	var mm = date.getMinutes(); 
	if (y < 1000)
		y += 1900;
	if (mm < 10)
		mm = '0' + mm;
	if (h < 10)
		h = '0' + h; 
	
	return dt + '.' + ms[m] + '.' + y + '\,&#160;' + h + ':' + mm; 
}

function DisplayGameLocalTimeInfo(dateTime, timeCtrlID, utcCtrlID, gmtCtrlID)
{
	var ctrl1 = document.getElementById(timeCtrlID);
	var ctrl2 = document.getElementById(utcCtrlID);	
	var ctrl3 = document.getElementById(gmtCtrlID);
	if (ctrl1 != null)
	{
		ctrl1.innerHTML = DateToLocalString(dateTime);
	}
	if (ctrl2 != null)
	{
		//info = GetUTCOffsetInfo(dateTime);
		info = GetUTCOffsetInfo();
		ctrl2.innerHTML = info[0] + info[1];
	}
	if (ctrl3 != null)
	{
		//info = GetGMTOffsetInfo(dateTime);
		info = GetGMTOffsetInfo();
		ctrl3.innerHTML = info[0] + info[1];
	}
}

function writeGMT()
{
	var info = GetGMTOffsetInfo();
	document.write(info[0] + info[1]);
}

function GetLastDigit(val)
{
	val = val + "";
	return val.charAt(val.length-1);
}

function tests(timer)
{
	//alert(timer + '');
	//clearTimeout(timer);
}

var global = this;
function OnTick(timerID, codeToEval)
{
	//debugger;
	//alert(timerID + '');
	if (codeToEval != null && codeToEval != "void(0)")
	{
		eval('clearTimeout(' + timerID + ')');
		//global.eval(codeToEval + '(' + timerID + ')')
	}
}

// Sets the ramained time text using total number of seconds before time will be ended
function SetRemainedTimeText(n, ctrlWhereSet, timerID, lang, twoFormat, codeToEval){
	if (n <= 0) return;
	
	var timeSeconds = n - 1;
	SetTimeText(timeSeconds, lang, ctrlWhereSet, twoFormat);
	
	OnTick(timerID, codeToEval);
	
	if (timeSeconds > 0)
	{
		if (codeToEval != null)
			timerID = setTimeout(
							function () 
							{
								//SetRemainedTimeText(timeSeconds, document.getElementById(ctrlWhereSet.id), timerID, lang, twoFormat, codeToEval.replace(/\'/g, "\\\'"));
								SetRemainedTimeText(timeSeconds, document.getElementById(ctrlWhereSet.id), timerID, lang, twoFormat, 'tests');
							}, 
							1000);
		else
			timerID = setTimeout(
							function () 
							{
								SetRemainedTimeText(timeSeconds, document.getElementById(ctrlWhereSet.id), timerID, lang, twoFormat, 'tests');
							}, 
							1000);
	}
	else
	{
		eval('clearTimeout(' + timerID + ')');
		if (timeSeconds == 0)
		{	
			if (codeToEval != null) {				
				setTimeout('eval(\'' + codeToEval.replace(/\'/g, '\\\'') + '\');', 1000);
			} else {				
				setTimeout("location.href = location.href;", 1000);
			}
		}
	}
}

function SetNextTimeText(n, ctrlWhereSet, timerID, lang, twoFormat){
	if (n < 0) return;
	
	var dd, ddlong;
	var hh, hhlong;
	var mm, mmlong;
	var ss, sslong;
	
	var timeSeconds = n+1;
	dd = Math.floor(timeSeconds/86400);
	hh = Math.floor((timeSeconds - 86400*dd)/3600);
	mm = Math.floor((timeSeconds - 86400*dd - 3600*hh)/60);
	ss = timeSeconds - 86400*dd - 3600*hh - mm*60;
	var bold_start = "<b>";
	var bold_end = "</b>";
	if (lang == 'ru')
	{
		var last = GetLastDigit(dd);
		if (dd >= 11 && dd <= 19) { ddlong = self.strDay1; }
		else if (last == 1) { ddlong = self.strDay2; }
		else if (last >= 2 && last <= 4) { ddlong = self.strDay3; }
		else if (last >= 5 && last <= 9) { ddlong = self.strDay1; }
		else if (dd != 0 && last == 0) { ddlong = self.strDay1; }
		else ddlong = "";
		
		last = GetLastDigit(hh);
		if (hh >= 11 && hh <= 19) { hhlong = self.strHour1; }
		else if (last == 1) { hhlong = self.strHour2; }
		else if (last >= 2 && last <= 4) { hhlong = self.strHour3; }
		else if (last >= 5 && last <= 9) { hhlong = self.strHour1; }
		else if ((hh != 0 && last == 0) || (hh == 0 && dd != 0)) { hhlong = self.strHour1; }
		else hhlong = "";
		
		if ((twoFormat && dd <= 0) || !twoFormat)
		{
			last = GetLastDigit(mm);
			if (mm >= 11 && mm <= 19) { mmlong = self.strMinute1; }
			else if (last == 1) { mmlong = self.strMinute2; }
			else if (last >= 2 && last <= 4) { mmlong = self.strMinute3; }
			else if (last >= 5 && last <= 9) { mmlong = self.strMinute1; }
			else if ((mm != 0 && last == 0) || ((dd != 0 || hh != 0) && mm == 0)) { mmlong = self.strMinute1; }
			else mmlong = "";
		}
		else
			mmlong = "";
		
		if ((twoFormat && hh <= 0) || !twoFormat)
		{
			last = GetLastDigit(ss);
			if (ss >= 11 && ss <= 19) { sslong = self.strSecond1; }
			else if (last == 1) { sslong = self.strSecond2; }
			else if (last >= 2 && last <= 4) { sslong = self.strSecond3; }
			else if (last >= 5 && last <= 9) { sslong = self.strSecond1; }
			else if (last == 0) { sslong = self.strSecond1; }
			else sslong = "";
		}
		else
			sslong = "";
	}
	else
	{
		if (dd == 1) { ddlong = self.strDay3; }
		else if (dd > 1) { ddlong = self.strDay1; }
		else { ddlong = ""; }
	
		if (hh == 1) { hhlong = self.strHour2; }
		else if (hh > 1) { hhlong = self.strHour1; }
		else if (hh == 0 && dd != 0) { hhlong = self.strHour1; }
		else hhlong = "";
		
		if ((twoFormat && dd <= 0) || !twoFormat)
		{
			if (mm == 1) { mmlong = self.strMinute2; }
			else if (mm > 1) { mmlong = self.strMinute1; }
			else if (mm == 0 && (hh != 0 || dd != 0)) { mmlong = self.strMinute1; }
			else mmlong = "";
		}
		else
			mmlong = "";
		
		if ((twoFormat && hh <= 0) || !twoFormat)
		{	
			if (ss == 1) { sslong = self.strSecond2; }
			else if (ss > 1 || ss == 0) { sslong = self.strSecond1; }
			else sslong = "";
		}
		else
			sslong = "";
	}
	
	if (ddlong != "")
			ddlong = bold_start + dd + bold_end + " " + ddlong + " ";
	if (hhlong != "")
			hhlong = bold_start + hh + bold_end + " " + hhlong + " ";
	if (mmlong != "")
			mmlong = bold_start + mm + bold_end + " " + mmlong + " ";
	if (sslong != "")
			sslong = bold_start + ss + bold_end + " " + sslong;
				
	ctrlWhereSet.innerHTML = ddlong + hhlong + mmlong + sslong;
	
			
	if (timeSeconds > 0)
	{
		timerID = setTimeout(
							function ()
							{
								SetNextTimeText(timeSeconds, document.getElementById(ctrlWhereSet.id), timerID, lang, twoFormat);
							}, 
							1000);
	}
	else
	{
		eval('clearTimeout(' + timerID + ')');
		//if (timeSeconds == 0)
		//	location.href = location.href;
	}
}

function SetTimeText(timeSeconds, lang, ctrlWhereSet, twoFormat)
{
	var dd, ddlong;
	var hh, hhlong;
	var mm, mmlong;
	var ss, sslong;
	
	dd = Math.floor(timeSeconds/86400);
	hh = Math.floor((timeSeconds - 86400*dd)/3600);
	mm = Math.floor((timeSeconds - 86400*dd - 3600*hh)/60);
	ss = timeSeconds - 86400*dd - 3600*hh - mm*60;
	var bold_start = "<b>";
	var bold_end = "</b>";
	if (lang == 'ru')
	{
		var last = GetLastDigit(dd);
		if (dd >= 11 && dd <= 19) { ddlong = self.strDay1; }
		else if (last == 1) { ddlong = self.strDay2; }
		else if (last >= 2 && last <= 4) { ddlong = self.strDay3; }
		else if (last >= 5 && last <= 9) { ddlong = self.strDay1; }
		else if (dd != 0 && last == 0) { ddlong = self.strDay1; }
		else ddlong = "";
		
		last = GetLastDigit(hh);
		if (hh >= 11 && hh <= 19) { hhlong = self.strHour1; }
		else if (last == 1) { hhlong = self.strHour2; }
		else if (last >= 2 && last <= 4) { hhlong = self.strHour3; }
		else if (last >= 5 && last <= 9) { hhlong = self.strHour1; }
		else if ((hh != 0 && last == 0) || (hh == 0 && dd != 0)) { hhlong = self.strHour1; }
		else hhlong = "";
		
		if ((twoFormat && dd <= 0) || !twoFormat)
		{
			last = GetLastDigit(mm);
			if (mm >= 11 && mm <= 19) { mmlong = self.strMinute1; }
			else if (last == 1) { mmlong = self.strMinute2; }
			else if (last >= 2 && last <= 4) { mmlong = self.strMinute3; }
			else if (last >= 5 && last <= 9) { mmlong = self.strMinute1; }
			else if ((mm != 0 && last == 0) || ((dd != 0 || hh != 0) && mm == 0)) { mmlong = self.strMinute1; }
			else mmlong = "";
		}
		else
			mmlong = "";
		
		if ((twoFormat && hh <= 0) || !twoFormat)
		{
			last = GetLastDigit(ss);
			if (ss >= 11 && ss <= 19) { sslong = self.strSecond1; }
			else if (last == 1) { sslong = self.strSecond2; }
			else if (last >= 2 && last <= 4) { sslong = self.strSecond3; }
			else if (last >= 5 && last <= 9) { sslong = self.strSecond1; }
			else if (last == 0) { sslong = self.strSecond1; }
			else sslong = "";
		}
		else
			sslong = "";
	}
	else
	{
		if (dd == 1) { ddlong = self.strDay3; }
		else if (dd > 1) { ddlong = self.strDay1; }
		else { ddlong = ""; }
	
		if (hh == 1) { hhlong = self.strHour2; }
		else if (hh > 1) { hhlong = self.strHour1; }
		else if (hh == 0 && dd != 0) { hhlong = self.strHour1; }
		else hhlong = "";
		
		if ((twoFormat && dd <= 0) || !twoFormat)
		{
			if (mm == 1) { mmlong = self.strMinute2; }
			else if (mm > 1) { mmlong = self.strMinute1; }
			else if (mm == 0 && (hh != 0 || dd != 0)) { mmlong = self.strMinute1; }
			else mmlong = "";
		}
		else
			mmlong = "";
		
		if ((twoFormat && hh <= 0) || !twoFormat)
		{	
			if (ss == 1) { sslong = self.strSecond2; }
			else if (ss > 1 || ss == 0) { sslong = self.strSecond1; }
			else sslong = "";
		}
		else
			sslong = "";
	}
	
	if (ddlong != "")
			ddlong = bold_start + dd + bold_end + " " + ddlong + " ";
	if (hhlong != "")
			hhlong = bold_start + hh + bold_end + " " + hhlong + " ";
	if (mmlong != "")
			mmlong = bold_start + mm + bold_end + " " + mmlong + " ";
	if (sslong != "")
			sslong = bold_start + ss + bold_end + " " + sslong;
				
	ctrlWhereSet.innerHTML = ddlong + hhlong + mmlong + sslong;
}

function Reload()
{
	location.href = location.href;
}

function Stub() {}
//-->