function zavrit(el)
{
  el.style.display = 'none';
}

// CHAT
// -----------------------------------------------------------------------------
function ajaxChat($ref)
{
	if (window.ActiveXObject)
	{
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} else
	{
		httpRequest = new XMLHttpRequest();
	}
	httpRequest.open("GET", "http://cis3mu.cisgames.cz/complement/chat.php", true);
	httpRequest.onreadystatechange= function () { ajaxChatProcessRequest(); };
	httpRequest.send(null);
	if ($ref) window.setTimeout("ajaxChat(true)", 10000);
}
function ajaxChatProcessRequest()
{
	if (httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			var vypis = document.getElementById("ajaxChat");
			var soubor = httpRequest.responseText;
			vypis.innerHTML = soubor;
		}
	}
}

function vloz_visible(nick)
{
	var text = document.comment.chat_zprava;
	text.value = nick + ': ' + text.value;
	var delka = text.value.length;
	text.focus();
	if(text.setSelectionRange)
	{
		text.setSelectionRange(delka, delka);
	}
}

function chat_odeslat()
{
	var text = document.comment.chat_zprava;
	if (window.ActiveXObject)
	{
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	} else
	{
		httpRequest = new XMLHttpRequest();
	}
	httpRequest.open("POST", "http://cis3mu.cisgames.cz/complement/chat_zapis.php", true);
	httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	httpRequest.send("zprava=" + text.value.replace("&", "HEX[26]")); 
	//httpRequest.send(null);

	var delka = text.value.length;
	text.value = '';
	text.focus();
	if(text.setSelectionRange)
	{
		text.setSelectionRange(delka, delka);
	}
	ajaxChat(false);
}

// -----------------------------------------------------------------------------

// CS
// -----------------------------------------------------------------------------
function castlesiege()
{
	if ( document.getElementById( "cs_zbyva" ) )
	{
		var params = document.getElementById( "cs_zbyva" ).value.split( "_" );
		var time = parseInt( params[1] );
		var type = params[3];
		castlesiege_timer( "cs_cas", time );
	}
}

function castlesiege_timer( timer, time )
{
	var t = time;
	if ( t > 0 )
	{
		var d = Math.floor( t / ( 24 * 3600) );
		var h = Math.floor( ( t - d * 24 * 3600 ) / 3600 );
		var m = Math.floor( ( t - ( d * 24 * 3600 + h * 3600) ) / 60);
		var s = t - (d * 24 * 3600 + h * 3600 + m * 60);

		if ( d == 0 ) d = "";
		else if( d > 4 ) d = d + " dní ";
		else if( d > 1 ) d = d + " dny ";
		else d = d + " den ";

		if ( d == 0 && h == 0 ) h = "";
		else if( h > 4 ) h = h + " hodin ";
		else if( h > 1 ) h = h + " hodiny ";
		else if( h == 1 ) h = h + " hodina ";
		else h = h + " hodin ";
//		else h = h + " hod ";

		if ( d == 0 && m == 0 && h == 0 ) m = "";
		else if( m > 4 ) m = m + " minut ";
		else if( m > 1 ) m = m + " mituty ";
		else if( m == 1 ) m = m + " minuta ";
		else m = m + " minut ";
//		else m = m + " min ";

		if ( d == 0 && s == 0 && m == 0 && h == 0 ) s = "";
		else if( s > 4 ) s = s + " sekund ";
		else if( s > 1 ) s = s + " sekundy ";
		else if( s == 1 ) s = s + " sekunda ";
		else s = s + " sekund ";
//		else s = s + " sek ";
		document.getElementById( timer ).firstChild.nodeValue = d + h + m + s;

		var time = t - 1;
		window.setTimeout( 'castlesiege_timer( "'+timer+'", "'+time+'" )', 1000 );

	} else {
		document.getElementById( timer ).firstChild.nodeValue= "Právě probíhá boj";
	}
}
