

function $(id) {
     return document.getElementById(id);
}

function show_hide(msg_id)
{
    $(msg_id).style.display = $(msg_id).style.display == 'none' ? '' : 'none'
}

function show_gamers(msg_id)
{
    var msg = "lista" + msg_id;
    
    $(msg).style.display = $(msg).style.display == 'none' ? '' : 'none'
    $("lista_graczy" + msg_id).innerHTML = $(msg).style.display == 'none' ? "Wyświetl listę graczy" : "Zwiń listę graczy";
}

function show_blocked(msg_id)
{
    var msg = "lista" + msg_id;
    
    $(msg).style.display = $(msg).style.display == 'none' ? '' : 'none'
    $("lista_blokowanych" + msg_id).innerHTML = $(msg).style.display == 'none' ? "Wyświetl listę blokowanych" : "Zwiń listę blokowanych";
}

function show_wingamers(msg_id)
{
    var msg = "lista" + msg_id;
    
    $(msg).style.display = $(msg).style.display == 'none' ? '' : 'none'
    $("lista_graczy" + msg_id).innerHTML = $(msg).style.display == 'none' ? "Wyświetl listę zwycięzców" : "Zwiń listę zwycięzców";
}

function show_losegamers(msg_id)
{
    var msg = "lista2_" + msg_id;
    
    $(msg).style.display = $(msg).style.display == 'none' ? '' : 'none'
    $("lista_przegranych" + msg_id).innerHTML = $(msg).style.display == 'none' ? "Wyświetl listę przegranych" : "Zwiń listę przegranych";
}

function pokazWszystkie ( )
{
    $('subkategorie').style.display = $('subkategorie').style.display == 'none' ? '' : 'none'
    $("lista_wszystkich").innerHTML = $('subkategorie').style.display == 'none' ? "Pokaż szczegóły »" : "Ukryj szczegóły »";
}


function popUpWH(URL, width, height)
{
	var day = new Date();
	var id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + ",left = 100,top = 107');");
}

function popUp(URL)
{
	var day = new Date();
	var id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=582,height=330,left = 100,top = 107');");
}

function isNumeric(sText)
{
	var ValidChars = "0123456789.";
	var numeric = true;
	var Char;
 
	for (i = 0; i < sText.length && numeric == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			numeric = false;
		}
	}
	
	return numeric;
}

function checkTime(id)
{
    var string = $(id).value
    
    if(string == 24)
    {
        $(id).value = '00';
        next_day();
    }
	if(string == -1)
    {
        $(id).value = '23';
        prev_day();
    }
}

function next_minute()
{
	var time_st = parseInt(document.form.time_st.value);
	if(time_st == -1)
	{
		time_st = 3
	}
	else
	{
		time_st = time_st + 1;
	}
	
	document.form.time_st.value = time_st;
	
	var zm = '';
	$('time_d').style.color = 'black';
	if(time_st == 0)
	{
		zm = '(za 15 sek)';
	}
	else if(time_st > 0 && time_st < 20)
	{
		zm = '(za '+time_st + ' min)';
	}
	else
	{
		zm = '(za > 20 min)';
	}
	
	$('time_d').innerHTML = zm;
	
	var minuta = (document.form.minuta.value);
	
	if(document.form.minuta.value != '' && minuta < 59)
	{
		var next_minuta = minuta -1 + 2; //dodanie minuty zeby nie traktowało jako string
		if(next_minuta < 10)
		{
			next_minuta = '0'+next_minuta;
		}
		document.form.minuta.value = next_minuta;
	}
	if(document.form.minuta.value != '' && minuta >= 59)
	{
		document.form.minuta.value = '00';
		next_godz();
	}
}

function next_godz()
{
	var godzina = parseInt(document.form.godzina.value);
	var next_godz = godzina + 1;
	document.form.godzina.value = next_godz;
	checkTime('godzina');
}

function prev_minute()
{
	var time_st = parseInt(document.form.time_st.value);
	if(time_st == -1)
	{
		time_st = 1;
	}
	else if((time_st == 1 && (document.form.rodzaj.value == 24 || document.form.rodzaj.value == 25)) || time_st > 1)
	{
		time_st = time_st - 1;
		
		var minuta = (document.form.minuta.value);
		if(document.form.minuta.value != '' && minuta > 0)
		{
			var prev_minuta = minuta - 1;
			if(prev_minuta < 10)
			{
				prev_minuta = '0'+prev_minuta;
			}
			document.form.minuta.value = prev_minuta;
		}
		if(document.form.minuta.value != '' && minuta == 00)
		{
			document.form.minuta.value = '59';
			prev_godz();
		}
	}
	
	document.form.time_st.value = time_st;
	
	var zm = '';
	$('time_d').style.color = 'black';
	if(time_st == 0)
	{
		zm = '(za 15 sek)';
		$('time_d').style.color = 'red';
	}
	else if(time_st > 0 && time_st < 20)
	{
		zm = '(za '+time_st + ' min)';
	}
	else
	{
		zm = '(za > 20 min)';
	}
	
	$('time_d').innerHTML = zm;
	
}

function prev_godz()
{
	var godzina = parseInt(document.form.godzina.value);
	var prev_godz = godzina - 1;
	document.form.godzina.value = prev_godz;
	checkTime('godzina');
}

function setValue(id)
{
    var string = $(id).value
    
    if(string == 'RRRR' || string == 'DD' || string == 'MM' || string == '**1**' || string == '**2**')
    {
        $(id).value='';
    }
}

function sprawdzPoprawnoscKwoty( id )
{
	var str = $( id ).value;
	if( str.search(/,\d{2}/) > 0 )
	{
		return 1;
	}
	else if( str.search(/,\d{1}/) > 0 )
	{
		$( id ).value += "0";
		return 1;
	}
	else if( str.search(/,/) > 0 )
	{
		$( id ).value += "00";
		return 1;
	}
	
	if ( str.search(/\.\d{2}/) > 0 )
	{
		$( id ).value = str.replace(/\./, ",");
	}
	else if ( str.search(/\.\d{1}/) > 0 )
	{
		$( id ).value = str.replace(/\./, ",");
		$( id ).value += "0";
	}
	else if ( str.search(/\./) > 0 )
	{
		$( id ).value = str.replace(/\./, ",00");
	}
	else
	{
		$( id ).value += ",00";
	}
}

function pokazHistorie()
{
	document.location.replace("#div52");
}

function demo_start()
{
	var game_type = parseInt(document.getElementById('rodzaj').options[document.getElementById('rodzaj').selectedIndex].value);
	if (game_type == 0)
	{
		$('rodz_t').innerHTML = "Wybierz rodzaj turnieju.";
		document.getElementById("rodz_t").style.display='block';
	}
	else
	{
		if (game_type == 7)
		{
			game_type = parseInt(document.getElementById('rodzaj2').options[document.getElementById('rodzaj2').selectedIndex].value);
		}
		
		self.location = baseHr + "turniej/gra/demo/"+game_type+"/0";
//		window.location = baseHr + "turniej/gra/demo/"+game_type+"/0";
	}
}

var ToArray = {
		  version: '1.0',
		 
		  str2array: function (string, separator) {/*...*/},
		  
		  isOnlyWhiteString: function (value) {/*...*/},
		 
		  xml2array: function (xml, byId) {
		    if (xml.hasChildNodes() == true) {
		      var nrChildren = xml.childNodes.length;
		      var result = new Array();
		      for(var i=0; i<nrChildren; i++) {
		        var node = xml.childNodes[i];
		        if(node.nodeName != '#text') {
		          var key = node.nodeName;
		          if(key!='xml') { // in view of IE
		            if (byId == true && node.getAttribute('id')) {
		              key = node.getAttribute('id');
		            }
		            result[key] = this.xml2array(node, byId);
		          }
		        } else {
		          if (nrChildren > 1) {
		            if(this.isOnlyWhiteString(node.nodeValue) == false) {
		              result.push(node.nodeValue);
		            }
		          } else {
		            var result = node.nodeValue;
		          }
		        }
		      }
		    }
		    return result;
		  }
		}

function wybierzTurniej(z1, use_typ)
{
if (use_typ == null) use_typ = true;
    var text1 = "";
    var text2 = "";
    //var pytan = "10";
    if(document.getElementById('liczba_pytan') != null)
    	var pytan = document.getElementById('liczba_pytan').value;
    else
    	var pytan = 10;
    
    var na_odpowiedz = 30;
    var czas = "10 min";
    var game_type = parseInt(z1.options[z1.selectedIndex].value);
    
    document.getElementById("typ_div").style.display='block';
    document.getElementById("turnieje_wiedzy").style.display='none';
    $('licz_p').style.display = 'block';
	//$('stawka_zaloz').style.display = 'table-row';
    $('stawka_input').style.display = 'block';
	$('stawka_label').style.display = 'none';
	//$('licz_input').style.display = 'block';
	//$('licz_input2').style.display = 'block';
	$('licz_label').style.display = 'none';
	$('pytan_zaloz').style.display = 'table-row';
	$('rank_zaloz').style.display = 'table-row';
    
    
    switch(game_type)
    {
        case 1: 
            break;
        case 2:
        	break;
        case 22: 
            break;
        case 3: 
            break;
       case 21: 
            break;
        case 4: 
        	$('licz_p').style.display = 'none';
            break;
        case 5: 
            break;
        case 6: 
            break;
        case 7: 
            document.getElementById("turnieje_wiedzy").style.display='block';
            if(use_typ == false){
            	turniejWiedzy('zaloz_turniej',7);
            }
            else if(rodzaj_t <= 7)
            	turniejWiedzy('zaloz_turniej',7);
            else
            	rodzaj_t = 0;
            break;
        case 19:
            break;
		case 24:
			//$('stawka_zaloz').style.display = 'none';
			$('stawka_input').style.display = 'none';
			$('stawka_label').style.display = 'block';
			$('stawka_label').innerHTML = '1';
			//$('pytan_zaloz').style.display = 'none';
			$('licz_p').style.display = 'none';
			//$('licz_input').style.display = 'none';
			//$('licz_input2').style.display = 'none';
			$('licz_label').style.display = 'block';
			//$('licz_label').innerHTML = '1';
			$('rank_zaloz').style.display = 'none';
            break;
		case 25:
			//$('stawka_zaloz').style.display = 'none';
			$('stawka_input').style.display = 'none';
			$('stawka_label').style.display = 'block';
			$('stawka_label').innerHTML = '1';
			//$('pytan_zaloz').style.display = 'none';
			$('licz_p').style.display = 'none';
			//$('licz_input').style.display = 'none';
			//$('licz_input2').style.display = 'none';
			$('licz_label').style.display = 'block';
			//$('licz_label').innerHTML = '1';
			$('rank_zaloz').style.display = 'none';
            break;
        default:
        	//text1 = '';
        	text2 = '';
        	text3 = '';
        	text4 = '';
        	text5 = '';
        	text6 = ''; 
        	text7 = ''; 
        	break;
    }
    
    
    ustawRanking(game_type);
    
    if(demo == 1 && game_type == 2) game_type = 22;
    if(demo == 1 && game_type == 3) game_type = 21;
    if(demo == 1 && game_type == 4) game_type = 23;
    if(demo == 1 && game_type == 19) game_type = 7;
    	
    advAJAX.get({
	    url: baseHr+"ajax.php?action=get_opisy&var=" + game_type+"&var2="+pytan ,
	    onSuccess : function(obj) {  
    		var result = ToArray.xml2array(obj.responseXML, true);
    		result = result['doc'];
    		
    		var zdjecie = '<img src=&#34;/html/gfx/turnieje/'+result['photo_m']+'&#34; style=&#34; margin: 5px 15px 15px 15px; &#34; />';
    		
			if(game_type == 24 || game_type == 25)
			{
				$('photo_m').innerHTML = '<a style="" onclick="layerMessageOpen1(&#39; ' + zdjecie + '&#39;);return false;" href="#"><img src="/html/gfx/turnieje/'+result['photo_m']+'" style="width:95px;" /></a><br /><a style="color: #222;" onclick="layerMessageOpen1(&#39; ' + zdjecie + '&#39;);return false;" href="#">Kliknij aby powiększyć</a>';
			}
			else
			{
				$('photo_m').innerHTML = '<a style="" onclick="layerMessageOpen1(&#39; ' + zdjecie + '&#39;);return false;" href="#"><img src="/html/gfx/turnieje/'+result['photo_m']+'" style="width:138px;" /></a><br /><a style="color: #222;" onclick="layerMessageOpen1(&#39; ' + zdjecie + '&#39;);return false;" href="#">Kliknij aby powiększyć</a>';
			}
    		$('photo_m').style.display = 'block'; //jak dojdzie miniaturka dla bitwy powitrznej usunac
    		
    			/*if(result['automat_przech_pytan']=='no')
        	    {
        	    	$("przech_pytan").options[0].disabled = true;
        	    	$("przech_pytan").selectedIndex = 1;
        	    }
        	    else
        	    {
        	    	$("przech_pytan").options[0].disabled = false;
        	    	$("przech_pytan").selectedIndex = 0;
        	    }
        	    
        	    if(result['reczne_przech_pytan']=='no')
        	    {
        	    	$("przech_pytan").options[1].disabled = true;
        	    }
        	    else
        	    {
        	    	$("przech_pytan").options[1].disabled = false;
        	    }*/
        	    
    		if ($('opis1')) 	$('opis1').innerHTML = '<span class=""> '+result['naglowek']+'</span>';
    		/*if ($('opis1a') && (result['reczne_przech_pytan']=='yes'))     
    		{
    			$('opis1a').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" style="float: left;" /> Przechodzenie Pytań: Ręczne.'; 
    		}
    		else
    		{
    			$('opis1a').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" style="float: left;" /> Przechodzenie Pytań: Automatyczne.';
    		}*/
    		if ($('opis2') && (result['opisy']['opis_1'] != 'brak'))     $('opis2').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" style="float: left;" />' + result['opisy']['opis_1']; 
    		if ($('opis3') && (result['opisy']['opis_2'] != 'brak'))     $('opis3').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" style="float: left;" />' + result['opisy']['opis_2']; 
    		if ($('opis4') && (result['opisy']['opis_3'] != 'brak'))
    		{	
    			$('opis4').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" style="float: left;" />' + result['opisy']['opis_3']; 
    			if(game_type == 4)
				{
					$('opis4').style.padding = '6px 80px 0px 0px';
				}
    		}
    		if ($('opis5') && (result['opisy']['opis_4'] != 'brak'))
    		{     
    			$('opis5').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" style="float: left;" /><div>' + result['opisy']['opis_4'] + '</div>'; 
    			if(game_type == 4)
				{
					$('opis5').style.padding = '8px 105px 0px 0px';
				}
    		}
    		else{
				$('opis5').innerHTML = '';
			}
    		
    		if ($('opis6') && (result['opisy']['opis_5'] != 'brak'))
    		{    
    			$('opis6').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" style="float: left;" /><div style="float: left; width:250px;">' + result['opisy']['opis_5'] + '</div>'; 
    			$('opis6').style.margin = '0px';
    			
			if(facebook)
				{
    				$('opis6').style.padding = '10px 0px 0px 0px';
				}
				else
				{
					if(game_type == 4)
					{
						$('opis6').style.padding = '6px 60px 0px 0px';
					}
					else
					{
						$('opis6').style.padding = '10px 60px 0px 0px';
					}
				}
    		}
			else{
				$('opis6').innerHTML = '';
			}
    		
    		if ($('opis7') && (result['opisy']['opis_6'] != 'brak'))
    		{
    			$('opis7').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" style="float: left;" /><div style="float: left; width:240px;">' + result['opisy']['opis_6'] + '</div>'; 
    			$('opis7').style.margin = '0px';
    			
			if(facebook)
				{	
    				$('opis7').style.padding = '10px 0px 0px 0px';
				}
				else
				{
					if(game_type == 4)
					{
						$('opis7').style.padding = '8px 60px 0px 0px';
					}
					else
					{
						$('opis7').style.padding = '10px 60px 0px 0px';
					}
				}
    		}
    		else{
    			$('opis7').innerHTML = '';
    		}
    		
    		if ($('ilosc_pytan_val')) $('ilosc_pytan_val').innerHTML = result['liczba_pytan'];
    	    if ($('czas_trwania_val')) $('czas_trwania_val').innerHTML = result['czas_trwania'];
    	    
    	    if(result['wybor_stawki']=='no')
    	    {
    	    	$("stawka").value = result['stawka'];
    	    	$("stawka").setAttribute('readonly',true); 
    	    }
    	    else
    	    {
    	    	if(!$("stawka").value)
				{
					$("stawka").value = 3;
				}
    	    	$("stawka").removeAttribute('readonly'); 
    	    }
    	    
    	    if(result['wybor_liczby_pytan']=='no')
    	    {
				if(result['liczba_pytan'] == 15)
				{
					$("liczba_pytan").innerHTML = "15";
					$("licz_label").innerHTML = "15";
				}
				else if(result['liczba_pytan'] == 10)
				{
					$("liczba_pytan").innerHTML = "10";
					$("licz_label").innerHTML = "10";
				}
				else
				{
					$("liczba_pytan").innerHTML = "5";
					$("licz_label").innerHTML = "5";
				}
    	    }
    	    else
    	    {
    	    	$('licz_label').style.display = 'none';
    	    	$("liczba_pytan").innerHTML = "5";
    	    }
    	}
	});
    
}

function wybierzSubTurniej(z1)
{
    var text1 = "";
    var text2 = "";
    var game_type = parseInt(z1.options[z1.selectedIndex].value);
    
    switch(game_type)
    {
        case 0: 
            text1 = ''; 
            text2 = ''; 
            break;
        case 8: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Filmy i Seriale'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Filmy i Seriale'; 
            break;
        case 9: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Finanse i Ekonomia'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Finanse i Ekonomia'; 
            break;
        case 10: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Geografia i Turystyka'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Geografia i Turystyka'; 
            break;
        case 11: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Historia'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Historia'; 
            break;
        case 12: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Informatyka'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Informatyka'; 
            break;
        case 13: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Język Polski i Literatura'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Język Polski i Literatura'; 
            break;
        case 14: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Matematyka i Fizyka'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Matematyka i Fizyka'; 
            break;
        case 15: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Motoryzacja'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Motoryzacja'; 
            break;
        case 16: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Muzyka'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Muzyka'; 
            break;
        case 17: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Piłka Nożna'; 
            text2 = '<img src="gfx/li.jpg" alt="-" /> OPIS KATEGORI: Piłka Nożna'; 
            break;
        case 18: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Polityka'; 
            text2 = '<img src="gfx/li.jpg" alt="-" /> OPIS KATEGORI: Polityka'; 
            break;
        case 19: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Rośliny i Zwierzęta'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Rośliny i Zwierzęta'; 
            break;
        case 20: 
            text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Sport'; 
            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Sport'; 
            break;
        case 21: 
        	text1 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Gdzie to jest'; 
        	text2 = '<img src="/html/gfx/li.jpg" alt="-" /> OPIS KATEGORI: Gdzie to jest'; 
        	break;
    }
    
    ustawRanking(game_type);
    
/*    text3 = '';
	text4 = '';
	text5 = '';
	text6 = ''; 
	text7 = ''; 

    $('opis3').innerHTML = text3;
    $('opis4').innerHTML = text4;
    $('opis5').innerHTML = text5;
    $('opis6').innerHTML = text6;
    $('opis7').innerHTML = text7;
    $('opis1').innerHTML = text1;
    $('opis2').innerHTML = text2;*/
}

function wybierzTyp(z1)
{
    var text = "";
    var text2 = "";
    var game_type = parseInt(z1.options[z1.selectedIndex].value);
    
    switch(game_type)
    {
        case 1: 
        	text = '<span class="">R1NG</span>';
        	text2 = '<img src="/html/gfx/new/star_ico.png" alt="-" /> Wygrywa najlepszy wynik';
        	break;
        case 2: 
        	text = '<span class="">1vs1</span>';
        	text2 = '<img src="/html/gfx/new/star_ico.png" alt="-" /> W turnieju może wziąc udział tylko 2 graczy, wygrywa 1: lepszy';
        	break;
        case 3: 
        	text = '<span class="">10%</span>';
        	text2 = '<img src="/html/gfx/new/star_ico.png" alt="-" /> Wygrywa 10% najlepszych wyników';
        	break;
        case 4: 
        	text = '<span class="">30%</span>';
        	text2 = '<img src="/html/gfx/new/star_ico.png" alt="-" /> Wygrywa 30% najlepszych wyników';
        	break;
    }
    text3 = '';
	text4 = '';
	text5 = '';
	text6 = ''; 
	text7 = ''; 
    $('opis1').innerHTML = text;
    $('opis2').innerHTML = text2;
    $('opis3').innerHTML = text3;
    $('opis4').innerHTML = text4;
    $('opis5').innerHTML = text5;
    $('opis6').innerHTML = text6;
    $('opis7').innerHTML = text7;
}

function pokazOpisRanking()
{    
    text2 = '';
    text3 = '';
	text4 = '';
	text5 = '';
	text6 = ''; 
	text7 = ''; 
    $('opis1').innerHTML = '<span class="">Maksymalny ranking</span>';
    $('opis2').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" /> Pozwala określić maksymalny poziom zaawansowania uczestników turnieju. ';
    $('opis3').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" /> Czym wyższy poziom tym mogą grać lepsi gracze. ';
    $('opis4').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" /> Nie można wybrać niższego poziomu niż ma się samemu.';
    $('opis5').innerHTML = text5;
    $('opis6').innerHTML = text6;
    $('opis7').innerHTML = text7;
}

function ustawRanking(rodzaj){
	 var zapytanie = baseHr+"ajax.php?action=pobierzRanking&var=" + rodzaj;
		advAJAX.get({
			url : zapytanie,
			onSuccess : function(obj)
			{ 
				switch(parseInt(obj.responseText))
				{
					case 1:
						$('max_rank').value = 4;
						$('min_rank').value = 1;
						break;
					case 2:
						$('max_rank').value = 4;
						$('min_rank').value = 2;
						break;
					case 3:
						$('max_rank').value = 4;
						$('min_rank').value = 3;
						break;
					case 4:
						$('max_rank').value = 4;
						$('min_rank').value = 4;
						break;
					case 5:
						$('max_rank').value = 5;
						$('min_rank').value = 5;
						break;
					default:
						$('max_rank').value = 4;
						$('min_rank').value = 1;
						break;
				}
			}
		});
		return;
}

function poprzednia()
{
    $('strona').value = 1;
    document.getElementById("game_form").action = baseHr+"ajax.php?action=turniej2&id=" + gameId+"&strona=1";
    advAJAX.submit(document.getElementById("game_form"), {
    	onSuccess : function(obj) { self.location = baseHr+ "turniej/gra/"+gameId; }
    });
    //$('game_form').submit();
}

function nastepna(type)
{
    $('strona').value = 2;
    document.getElementById("game_form").action = baseHr+"ajax.php?action=turniej2&id=" + gameId+"&strona=2";
    advAJAX.submit(document.getElementById("game_form"), {
    	onSuccess : function(obj) {
	    	if(type == 2)
	    	{
	    		self.location = baseHr+ "turniej/gra/"+gameId+"/zakoncz_czas";
	    	}
	    	else if(type == 3)
	    	{
	    		
	    	}
			else
	    	{
	    		self.location = baseHr+ "turniej/gra/"+gameId; 
	    	}
    	}
    });
    
   // $('game_form').submit();
}

function zakoncz_demo()
{
	document.getElementById('demo_koniec').value = 1;
	document.game_form.submit();
}

function konto_prev()
{
    $('strona').value--;
    $('formh').submit();
}

function konto_next()
{
    $('strona').value++;
    $('formh').submit();
}

function konto_send()
{
    $('strona').value = 1;
    $('formh').submit();
}

function t(z1){
    v = new Date();
    n = new Date();
    o = new Date();
    for (cn = 1; cn <= count; cn++)
    {
        bxx = document.getElementById('tm' + cn);
        
        if (bxx == null)
        {
        	break;
        }
        
        ss = bxx.title;
        
        s = ss - Math.round((n.getTime() - v.getTime()) / 1000.);
        m = 0;
        h = 0;
        d = 0;
        tyg = 0;
        mc = 0;

        if (s < 0)
        {
        	if(zakonczony_czas)
        	{
        		bxx.innerHTML = "<span style='font-size: 24px;'>(Obliczanie wyników)</span>";
        	}
        	else
        	{
        		bxx.innerHTML = "-";
        	}
        }
        else if (s < 600)
		{
			if (s > 59)
            {
                m = Math.floor(s/60);
                s = s - m * 60;
				if(s < 10)
				{
					s = '0'+s;
				}
				m = '0'+m;
            }
			else
			{
				m = '00';
				if(s < 10)
				{
					s = '0'+s;
				}
			}
			bxx.innerHTML = m + ":"+s;
		}
		else
        {
            if (s > 59)
            {
                m = Math.floor(s/60);
                s = s - m * 60;
            }
            if (m > 59)
            {
                h = Math.floor(m / 60);
                m = m - h * 60;
            }
            if (h > 23)
            {
                d = Math.floor(h / 24);
                h = h - d * 24;
            }
            
            if (d > 6)
            {
                tyg = Math.floor(d / 7);
            }
            
            if (tyg > 4)
            {
                mc = Math.floor(tyg / 4);
            }
            
            if( mc > 0 )
            {
                switch( mc )
                {
                    case 1:
                        bxx.innerHTML = mc + " miesiąc";
                        break;
                    default:
                        bxx.innerHTML = mc + " miesięcy";
                        break;
                }
            }
           /* else if( tyg > 0 )
            {
                switch( tyg )
                {
                    case 1:
                        bxx.innerHTML = tyg + " tydzień";
                        break;
                    default:
                        bxx.innerHTML = tyg + " tygodni";
                        break;
                }
            }*/
            else if( d > 0 )
            {
                switch( d )
                {
                    case 1:
                        bxx.innerHTML = d + " dzień";
                        break;
                    default:
                        bxx.innerHTML = d + " dni";
                        break;
                }
            }
            else if( h > 0 )
            {
                switch( h )
                {
                    case 1:
                        bxx.innerHTML = h + " godzina";
                        break;
                    case 2:
                    case 3:
                    case 4:
                        bxx.innerHTML = h + " godziny";
                        break;
                    default:
                        bxx.innerHTML = h + " godzin";
                        break;
                }
            }
            else if( m > 0 )
            {
                switch( m )
                {
                    case 1:
                        bxx.innerHTML = m + " minuta";
                        break;
                    case 2:
                    case 3:
                    case 4:
                        bxx.innerHTML = m + " minuty";
                        break;
                    default:
                        bxx.innerHTML = m + " minut";
                        break;
                }
                if (m == 9 && (s == 59 || s == 58))
                {
                	location.reload(true);
                }
            }
            else if( s > 0 )
            {
                switch( s )
                {
                    case 1:
                        bxx.innerHTML = s + " sek";
                        break;
                    case 2:
                    case 3:
                    case 4:
                        bxx.innerHTML = s + " sek";
                        break;
                    default:
                        bxx.innerHTML = s + " sek";
                        break;
                }
            }
            else
            {
            	if(zakonczony_czas)
            	{
            		bxx.innerHTML = "<span style='font-size: 24px;'>(Obliczanie wyników)</span>";
            	}
            	else
            	{
            		bxx.innerHTML = "-";
            	}
            }
            
        }
        
        bxx.title = bxx.title - 1;
        
        if(z1 > 0)
        {
            bx2 = document.getElementById('tm' + cn + 'b');
            bx2.title = bxx.title;
            bx2.innerHTML = bxx.innerHTML;
        }
    }
    if(z1 > 0)
    {
    	if (glowna)
    	{
    		
    	}
    	else
    	{
    		window.setTimeout("t(1);", 1000);
    	}
    }
    else
    {
    	if (glowna)
    	{
    		window.setTimeout("t();", 1000);
    	}
    	else
    	{
    		window.setTimeout("t();", 1000);
    	}
    }
}

function getElementHeight(Elem) {
	if(document.getElementById)
	{
		var elem = document.getElementById(Elem);
	}
	else if (document.all)
	{
		var elem = document.all[Elem];
	}

	return elem.offsetHeight + 84;
}

function loadPic(z1)
{
    var game_type = z1.options[z1.selectedIndex].value;
    if( game_type == "5a" || game_type == "5b" || game_type == 6 )
    {
		$('loadPic').style.display = 'none';
    }
    else
    {
		$('loadPic').style.display = '';
    }
}

function checkSelection()
{
    var count = 0;
    var max = 3;
    
    for (var i = 0 ; i < document.game_form.elements.length; i++ )
    {
        var e = document.game_form.elements[i];
        if( e.type == 'checkbox' )
        {
            e.disabled = false;
            
            if ( e.checked )
            {
                count++;
            }
        }
    }
    
    if( count >= max )
    {
        for (var i = 0 ; i < document.game_form.elements.length; i++ )
        {
            var e = document.game_form.elements[i];
            if( e.type == 'checkbox' )
            {
                if ( !e.checked )
                {
                    e.disabled = true;
                }
            }
        }
    }
}

function checkSelectionSzperacz()
{
//	alert("aaa");
	for (var i = 0 ; i < document.game_form.elements.length; i++ )
    {
//		alert("bbb");
        var e = document.game_form.elements[i];
        if( e.type == 'radio' )
        {
            //e.disabled = false;
            
            if ( e.checked )
            {
            	//alert("ccc "+e.value);
            	if (demo == false)
            	eszperacz(e.value);
            }
        }
    }
}

function sendMessage(){
	var message = document.getElementById("message").value;

	if(message != ''){
		advAJAX.get({
	        url: baseHr+"ajax.php?action=send_message&var=" + message + "&var1=" + gameId + "&var2=" +color_id ,
	        onSuccess : function(obj) { 
				if(obj.responseText == 'ALERT'){
					document.getElementById('message').disabled = true;
				}
			}
	   
	    });
	}

	document.getElementById("message").value = '';
	document.getElementById("message").focus();
	return false;
}

function leaveChat(){
	chat = 0;
	advAJAX.get({
        url: baseHr+"ajax.php?action=leave_chat&var=" + gameId ,
        onSuccess : function(obj) {   }
   
    });

	//window.location = baseHr;
}

function refreshChat( )
{
    advAJAX.get({
        url: baseHr+"ajax.php?action=get_chat_message&var=" + gameId,
        onSuccess : function(obj) 
        { 
    		$(chat_id).innerHTML = obj.responseText;
    		$(chat_id).scrollTop = $(chat_id).scrollHeight;
    		//alert(obj.responseText);
    		
    	}
    });
    
    window.setTimeout("refreshChat();",2000);
}

function dodaj_czarna_lista()
{
	var login = document.getElementById("czarna_lista_login").value;
	//alert(document.getElementById("czarna_lista_login").value);
	
	advAJAX.get({
        url: baseHr+"ajax.php?action=dodaj_czarna_lista&var=" + login,
        onSuccess : function(obj) 
        { 
    		if(obj.responseText == 'OK')
    		{
    			//window.location = baseHr + "profil/edycja";
    			document.getElementById("error1_czarna_lista").style.display = "none";
    			document.getElementById("msg1_czarna_lista").style.display = "block";
    			document.getElementById("msg2_czarna_lista").innerHTML = "Użytkownik został dodany do czarnej listy.";
    			document.getElementById("error1_czarna_lista").style.display = "none";
    			
    			advAJAX.get({
    		        url: baseHr+"ajax.php?action=get_czarna_lista",
    		        onSuccess : function(obj) 
    		        { 
    					document.getElementById("czarna_l").innerHTML = obj.responseText;
    		        }
    			});
    		}
    		else
    		{
    			document.getElementById("msg1_czarna_lista").style.display = "none";
    			document.getElementById("error1_czarna_lista").style.display = "block";
    			document.getElementById("error2_czarna_lista").innerHTML = obj.responseText;
    		}
    	}
    });
}

function usun_czarna_lista(id)
{
	//alert(id);
	
	advAJAX.get({
        url: baseHr+"ajax.php?action=usun_czarna_lista&var=" + id,
        onSuccess : function(obj) 
        { 
			if(obj.responseText == 'OK')
			{
				//window.location = baseHr + "profil/edycja";
				document.getElementById("msg1_czarna_lista").style.display = "block";
    			document.getElementById("msg2_czarna_lista").innerHTML = "Użytkownik został usunięty z czarnej listy.";
    			document.getElementById("error1_czarna_lista").style.display = "none";
    			
				advAJAX.get({
    		        url: baseHr+"ajax.php?action=get_czarna_lista",
    		        onSuccess : function(obj) 
    		        { 
    					document.getElementById("czarna_l").innerHTML = obj.responseText;
    		        }
    			});
	        }
			else
			{
				document.getElementById("msg1_czarna_lista").style.display = "none";
				document.getElementById("error1_czarna_lista").style.display = "block";
				document.getElementById("error2_czarna_lista").innerHTML = obj.responseText;
			}
    	}
    });
}

function sciezka2_opisy(rodzaj)
{
	advAJAX.get({
	    url: baseHr+"ajax.php?action=get_opisy&var="+rodzaj ,
	    onSuccess : function(obj) {  
			var result = ToArray.xml2array(obj.responseXML, true);
			result = result['doc'];
			//alert(result['naglowek']);
			//alert(result['liczba_pytan']);
			//alert(result['opisy']['opis_6']);
			
			if ($('opis1')) 	$('opis1').innerHTML = '<span class=""> '+result['naglowek']+'</span>';
			if ($('opis2') && (result['opisy']['opis_1'] != 'brak'))     $('opis2').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" />' + result['opisy']['opis_1']; 
			if ($('opis3') && (result['opisy']['opis_2'] != 'brak'))     $('opis3').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" />' + result['opisy']['opis_2']; 
			if ($('opis4') && (result['opisy']['opis_3'] != 'brak'))     $('opis4').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" />' + result['opisy']['opis_3']; 
    		if ($('opis5') && (result['opisy']['opis_4'] != 'brak')){     
				$('opis5').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" />' + result['opisy']['opis_4']; 
    		}
    		else{
				$('opis5').innerHTML = '';
			}
    		
    		if ($('opis6') && (result['opisy']['opis_5'] != 'brak')){    
				$('opis6').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" />' + result['opisy']['opis_5']; 
    		}
			else{
				$('opis6').innerHTML = '';
			}
    		
    		if ($('opis7') && (result['opisy']['opis_6'] != 'brak')){
				$('opis7').innerHTML = '<img src="/html/gfx/new/star_ico.png" alt="-" />' + result['opisy']['opis_6']; 
    		}
    		else{
    			$('opis7').innerHTML = '';
    		}
    		
    		if ($('ilosc_pytan_val')) $('ilosc_pytan_val').innerHTML = result['liczba_pytan'];
    	    if ($('czas_trwania_val')) $('czas_trwania_val').innerHTML = result['czas_trwania'];
		}
	});
}

function wybierzLPyt()
{
	var kind = document.getElementById('rodzaj').value;
	var liczba_pytan = document.getElementById('liczba_pytan').value;
	
    advAJAX.get({
        url: baseHr+"ajax.php?action=get_czas_odp&var=" + kind + "&var2="+liczba_pytan,
        onSuccess : function(obj) 
        { 
    		document.getElementById('czas_trwania_val').innerHTML = obj.responseText;
    	}
    });
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function zmien_logowanie(kind)
{
	if(header_form == 'register')
	{
		header_form = 'login';
		document.getElementById('register_form_top').style.display = 'none';
		document.getElementById('logowanie-form').style.display = 'block';
		//document.getElementById('btn_zaloguj').style.background = 'url(/html/gfx/new/btn_zaloguj_hover.png)';
		//document.getElementById('btn_zarejestruj').style.background = 'url(/html/gfx/new/btn_zarejestruj.png)';
		var login = document.getElementById('nick').value;
		var mail = document.getElementById('mail').value;
		if(login != '')
			document.getElementById('nick2').value = login;
		else if(mail != '')
			document.getElementById('nick2').value = mail;
		document.getElementById('pass2').value = document.getElementById('pass1').value;
		
		if(kind == 1)
		{
			document.getElementById('przyp_haslo').style.display = 'block';
		}
	}
}

function zmien_rejestracja()
{
	if(header_form == 'login')
	{
		header_form = 'register';
		document.getElementById('logowanie-form').style.display = 'none';
		document.getElementById('register_form_top').style.display = 'block';
		//document.getElementById('btn_zaloguj').style.background = 'url(/html/gfx/new/btn_zaloguj.png)';
		//document.getElementById('btn_zarejestruj').style.background = 'url(/html/gfx/new/btn_zarejestruj_hover.png)';
		document.getElementById('nick').value = document.getElementById('nick2').value;
		document.getElementById('pass1').value = document.getElementById('pass2').value;
		document.getElementById('form-btns').style.background = 'url(/html/gfx/v2/tlo-buttons-odwrocone.png) no-repeat scroll center top #E6E6E6';
	}
}

function sprawdzZakonczenie(id_turnieju, kind)
{
	advAJAX.get({
        url: baseHr+"ajax.php?action=sprawdz_zakonczenie&var="+id_turnieju+"&var2="+kind,
        onSuccess : function(obj) { 
			if( obj.responseText == "ZAKONCZ" )
			{
				self.location = baseHr+ "turniej/gra/"+id_turnieju;
			}
			else{
				$('gracze_zakoncz').innerHTML = obj.responseText;
			} 
		}
    });
	window.setTimeout("sprawdzZakonczenie("+id_turnieju+","+ kind+");",5000);
}

function sprawdzLiczbeOdp(odp, pyt, id_turnieju)
{
	if(odp >= pyt)
	{
		nastepna(2);
	}
	else
	{
		advAJAX.get({
	        url: baseHr+"ajax.php?action=sprawdz_liczbe_odp&id_turnieju="+id_turnieju,
	        onSuccess : function(obj) { 
				var licz = pyt - obj.responseText;
				if(licz == 0)
				{
					nastepna(2);
				}
				else
				{
		var answer = confirm("Nie udzieliłeś odpowiedzi na "+licz +" pytań. Na pewno chcesz zakończyć turniej?");
		if (answer)
		{
			nastepna(2);
		}
	}
}
	    });
	}
	return;
}

function share_wall()
{
	advAJAX.get({
        url: baseHr+"ajax.php?action=share_wall&promocje=0",
        onSuccess : function(obj) { 
			
		}
    });
	return;
}

function share_wall_csi()
{
	advAJAX.get({
		url: baseHr+"ajax.php?action=share_wall_csi&promocje=0",
		onSuccess : function(obj) { 
		
	}
	});
	return;
}

function like_turniej_typ(id_typ)
{
	advAJAX.get({
        url: baseHr+"ajax.php?action=like_wall&promocje="+id_typ,
        onSuccess : function(obj) { 
			
		}
    });
	return;
}

function share_wall_promocje()
{
	advAJAX.get({
		url: baseHr+"ajax.php?action=share_wall&promocje=1",
        onSuccess : function(obj) { 
			
		}
    });
	return;
}

/**
 * Funkcja sterująca checkboksem typu zaznacz/odznacz wszystkie
 * 
 * Podpinamy ją:
 * <input type="checkbox" onclick="checkAll(this)" ...
 * 
 * @param allbox
 */
function checkAll(allbox) {
	for (var i=0; i < allbox.form.elements.length; i++)	{
		var e = allbox.form.elements[i];
		if (e != allbox && e.type=='checkbox') {
			e.checked = allbox.checked;
		}
	}
}

