

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();
    }
}

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';
    
    //lpe = document.getElementById("liczba_pytan");
    //pytan = lpe.options[lpe.selectedIndex].value;
    //alert('sss');
    
    
    switch(game_type)
    {
        case 1: 
        	//text1 = '<span class="opis_head">Wygrywaj turnieje i zdobądź tytuł Mistrza R1NGu. Wykaż się szeroką wiedzą z różnych tematów.</span>';
            //text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Pytania z różnych dziedzin tematycznych.'; 
//            text3 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych lub obrazkowych. ';
//            text4 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, wielokrotnego wyboru. ';
//            text5 = '<img src="/html/gfx/li.jpg" alt="-" /> Zaznaczamy wszystkie prawidłowe odpowiedzi (od 0 do 4). ';
//            text6 = '<img src="/html/gfx/li.jpg" alt="-" /> 30 sekund na odpowiedź na każde pytanie. ';
//            text7 = '';
//            czas = "10 min";
            //pytan = "20";
            break;
        case 2:
        	if(demo == 1){
//        		text1 = '<span class="opis_head">Turniej z testów na inteligencję. Sprawdź czy wypadniesz lepiej niż inni uczestnicy.</span>';
//            	text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Pytania z testów na inteligencję.'; 
//                text3 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych lub obrazkowych. ';
//                text4 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, zawsze prawidłowa tylko jedna odpowiedź.';
//                text5 = '<img src="/html/gfx/li.jpg" alt="-" /> 45 sekund na odpowiedź na każde pytanie. ';
//                text6 = '';
//                text7 = '';
//                czas = "15 min";
//                na_odpowiedz = 45;
        	}
        	break;
        case 22: 
//        	text1 = '<span class="opis_head">Turniej z testów na inteligencję. Sprawdź czy wypadniesz lepiej niż inni uczestnicy.</span>';
//        	text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Pytania z testów na inteligencję.'; 
//            text3 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych lub obrazkowych. ';
//            text4 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, zawsze prawidłowa tylko jedna odpowiedź.';
//            text5 = '<img src="/html/gfx/li.jpg" alt="-" /> 45 sekund na odpowiedź na każde pytanie. ';
//            text6 = '';
//            text7 = '';
//            czas = "15 min";
//            na_odpowiedz = 45;
           // pytan = "20";
            break;
        case 3: 
        	if(demo == 1){
//        		text1 = '<span class="opis_head">Turniej dla ciekawych świata. Najczęstsze pytania w tym turnieju to: „Gdzie to jest?”, „Jakie to miasto?”, itp.</span>';
//            	text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Pytania z wiedzy geograficznej.'; 
//            	text3 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych lub obrazkowych. ';
//            	text4 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, zawsze prawidłowa tylko jedna odpowiedź. ';
//            	text5 = '<img src="/html/gfx/li.jpg" alt="-" /> 30 sekund na odpowiedź na każde pytanie. ';
//            	text6 = '';
//            	text7 = '';
//            	czas = "10 min";
        	}
        	else{
//	        	text1 = '<span class="opis_head">Wygrywaj turnieje i zdobądź tytuł Szybkiego Billa. Wykaż się szeroką wiedzą z różnych tematów.</span>';
//	            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Pytania z różnych dziedzin tematycznych.'; 
//	            text3 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych lub obrazkowych. ';
//	            text4 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, wielokrotnego wyboru. ';
//	            text5 = '<img src="/html/gfx/li.jpg" alt="-" /> Zaznaczamy wszystkie prawidłowe odpowiedzi (od 0 do 4). ';
//	            text6 = '<img src="/html/gfx/li.jpg" alt="-" /> 15 sekund na odpowiedź na każde pytanie. ';
//	            text7 = '';
//	            czas = "2:30 min";
//	            na_odpowiedz = 15;
            //pytan = "20";
        	}
            break;
       case 21: 
//        	text1 = '<span class="opis_head">Turniej dla ciekawych świata. Najczęstsze pytania w tym turnieju to: „Gdzie to jest?”, „Jakie to miasto?”, itp.</span>';
//        	text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Pytania z wiedzy geograficznej.'; 
//        	text3 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych lub obrazkowych. ';
//        	text4 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, zawsze prawidłowa tylko jedna odpowiedź. ';
//        	text5 = '<img src="/html/gfx/li.jpg" alt="-" /> 30 sekund na odpowiedź na każde pytanie. ';
//        	text6 = '';
//        	text7 = '';
//        	czas = "10 min";
            //pytan = "20";
            break;
        case 4: 
        	$('licz_p').style.display = 'none';
//        	text1 = '<span class="opis_head">Zręcznie wyszukuj informacje w Internecie i wygrywaj turnieje. Uważaj na ujemne punkty!</span>';
//            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Pytania z różnych dziedzin tematycznych.'; 
//            text3 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, zawsze prawidłowa tylko jedna odpowiedź.  ';
//            text4 = '<img src="/html/gfx/li.jpg" alt="-" /> Można przeskakiwać do następnych / poprzednich pytań.';
//            text5 = '<img src="/html/gfx/li.jpg" alt="-" /> Za poprawną odpowiedź otrzymujesz 1 punkt, za błędną -1 punkt, za brak 0 punktów. ';
//            text6 = '';
//            text7 = '';
//            czas = "2 min";
//            na_odpowiedz = 12;
           // pytan = "20";
            break;
        case 5: 
//        	text1 = '<span class="opis_head">Poznaj opinię ludzi. Wytypuj jakie odpowiedzi najczęściej wybierali ankietowani.</span>';
//            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Wytypuj najczęstsze odpowiedzi ankietowanych osób.'; 
//            text3 = '<img src="/html/gfx/li.jpg" alt="-" /> Im więcej osób wybrało daną odpowiedź tym zdobywasz więcej punktów.';
//            text4 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych.';
//            text5 = '<img src="/html/gfx/li.jpg" alt="-" /> Wybierz 3 najpopularniejsze odpowiedzi.';
//            text6 = '<img src="/html/gfx/li.jpg" alt="-" /> Masz 30 sekund na odpowiedź na każde pytanie.';
//            //text6 = '';
//            text7 = '';
            //na_odpowiedz = 15;
            //pytan = "10";
            break;
        case 6: 
//        	text1 = '<span class="opis_head">Poczuj się jak Milioner. Masz '+pytan+' pytań z wiedzy ogólnej i 3 koła ratunkowe.</span>';
//            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Każdy uczestnik dostaje 3 „koła ratunkowe”.'; 
//            text3 = '<img src="/html/gfx/li.jpg" alt="-" /> Działanie koła: wygaszane są 2 błędne odpowiedzi.';
//            text4 = '<img src="/html/gfx/li.jpg" alt="-" /> Odpowiadasz na pytania do czasu pierwszej błędnej odpowiedzi.';
//            text5 = '<img src="/html/gfx/li.jpg" alt="-" /> Wygrywa ten, kto prawidłowo odpowie na najwięcej pytań.';
//            text6 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych z różnych dziedzin tematycznych.';
//            text7 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, prawidłowa jest zawsze tylko jedna.';
//            text7 = '<img src="/html/gfx/li.jpg" alt="-" /> W każdym pytaniu masz 30 sekund na odpowiedź. ';
//            czas = "10 min";
            //pytan = "20";
if (use_typ)
{
				//document.getElementById("typ").selectedIndex = 0;
			    //document.getElementById("typ_div").style.display='none';
}
            break;
        case 7: 
//        	text1 = '<span class="opis_head">Wybierz tematykę w której czujesz się najlepiej i wygrywaj. Muzyka, Piłka nożna, a może Polityka?</span>';
//            text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Turniej z wybranej dziedziny tematycznej.';
//            text3 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych lub obrazkowych. ';
//            text4 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, zawsze prawidłowa tylko jedna odpowiedź. ';
//            text5 = '<img src="/html/gfx/li.jpg" alt="-" /> 30 sekund na odpowiedź na każde pytanie.';
//            text6 = '';
//            text7 = '';
//            czas = "10 min";
            //pytan = "20";
            document.getElementById("turnieje_wiedzy").style.display='block';
            if(use_typ == false){
            turniejWiedzy('zaloz_turniej');
            }
            else if(rodzaj_t <= 7)
            	turniejWiedzy('zaloz_turniej');
            else
            	rodzaj_t = 0;
            break;
        case 19:
//        	text1 = '<span class="opis_head">Wybierz tematykę w której czujesz się najlepiej i wygrywaj. Muzyka, Piłka nożna, a może Polityka?</span>';
//        	text2 = '<img src="/html/gfx/li.jpg" alt="-" /> Turniej z wybranej dziedziny tematycznej.';
//            text3 = '<img src="/html/gfx/li.jpg" alt="-" /> '+pytan+' pytań tekstowych lub obrazkowych. ';
//            text4 = '<img src="/html/gfx/li.jpg" alt="-" /> 4 możliwe odpowiedzi, zawsze prawidłowa tylko jedna odpowiedź. ';
//            text5 = '<img src="/html/gfx/li.jpg" alt="-" /> 30 sekund na odpowiedź na każde pytanie.';
//            text6 = '';
//            text7 = '';
//            czas = "10 min";
            //pytan = "20"; 
            break;
        default:
        	//text1 = '';
        	text2 = '';
        	text3 = '';
        	text4 = '';
        	text5 = '';
        	text6 = ''; 
        	text7 = ''; 
        	break;
    }
    ustawRanking(game_type);
    
//    czas = Math.floor(pytan * na_odpowiedz / 60) ;
//
//    sek = pytan * na_odpowiedz % 60;
//    if (sek != 0)
//    {
//    	czas += ':'+sek;
//    }
//    
//    czas += ' min';
    
    if(demo == 1 && game_type == 2) game_type = 22;
    if(demo == 1 && game_type == 3) game_type = 21;
    	
    	
    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'];
    		//alert(result['naglowek']);
    		//alert(result['liczba_pytan']);
    		//alert(result['opisy']['opis_6']);
    		
    		var zdjecie = '<img src=&#34;/html/gfx/turnieje/'+result['photo_m']+'&#34; style=&#34; margin: 5px 15px 15px 15px; &#34; />';
    		
    		if(game_type != 4)
    		{
    		$('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>';
    			document.getElementById('photo_m').style.display = 'block'; //jak dojdzie miniaturka dla bitwy powitrznej usunac
    		}
    		else
    		{
    			document.getElementById('photo_m').style.display = 'none';//jak dojdzie miniaturka dla bitwy powitrznej usunac
    		}
    		
    		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="-" 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;" />' + result['opisy']['opis_4']; 
    			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;" />' + result['opisy']['opis_5']; 
    			$('opis6').style.margin = '0px';
    			
			if(facebook)
				{
    				$('opis6').style.padding = '10px 0px 0px 0px';
				}
				else
				{
					if(game_type == 4)
					{
						$('opis6').style.padding = '6px 120px 0px 0px';
					}
					else
					{
						$('opis6').style.padding = '10px 120px 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;" />' + result['opisy']['opis_6']; 
    			$('opis7').style.margin = '0px';
    			
			if(facebook)
				{	
    				$('opis7').style.padding = '10px 0px 0px 0px';
				}
				else
				{
					if(game_type == 4)
					{
						$('opis7').style.padding = '8px 100px 0px 0px';
					}
					else
					{
						$('opis7').style.padding = '10px 120px 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 ($('opis1')) 	$('opis1').innerHTML = text1;
   // if ($('opis2'))     $('opis2').innerHTML = text2;
    //if ($('opis3'))     $('opis3').innerHTML = text3;
   // if ($('opis4'))     $('opis4').innerHTML = text4;
//    if ($('opis5'))     $('opis5').innerHTML = text5;
//    if ($('opis6'))    $('opis6').innerHTML = text6;
//    if ($('opis7'))    $('opis7').innerHTML = text7;
    //if ($('ilosc_pytan_val')) $('ilosc_pytan_val').innerHTML = pytan;
    //if ($('czas_trwania_val')) $('czas_trwania_val').innerHTML = czas;
}

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(z1)
{    
    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)
			{ 
				document.getElementById("max_rank_select").innerHTML = '<select class="required" title="Proszę wybrać maksymalny ranking"  id="max_rank" onchange="pokazOpisRanking(this)" style="width: 150px;margin-left:0;" name="max_rank"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option SELECTED value="5">5</option></select>';
				
				switch(parseInt(obj.responseText))
				{
					case 1:
						if (navigator.appName=="Microsoft Internet Explorer"){
							document.getElementById("max_rank_select").innerHTML = '<select class="required" title="Proszę wybrać maksymalny ranking"  id="max_rank" onchange="pokazOpisRanking(this)" style="width: 150px;margin-left:0;" name="max_rank"><option value="1">1</option><option SELECTED value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>';
						}
						else{
						document.getElementById("max_rank").options[0].disabled = false;
						document.getElementById("max_rank").options[2].disabled = false;
						document.getElementById("max_rank").options[1].disabled = false;
						document.getElementById("max_rank").selectedIndex = 1;
						//document.getElementById("max_rank").disabled = false;
						}
						break;
					case 2:
						if (navigator.appName=="Microsoft Internet Explorer"){
							document.getElementById("max_rank_select").innerHTML = '<select class="required" title="Proszę wybrać maksymalny ranking"  id="max_rank" onchange="pokazOpisRanking(this)" style="width: 150px;margin-left:0;" name="max_rank"><option value="2">2</option><option SELECTED value="3">3</option><option value="4">4</option><option value="5">5</option></select>';
						}
						else{
							document.getElementById("max_rank").options[0].disabled = true;
							document.getElementById("max_rank").options[1].disabled = false;
							document.getElementById("max_rank").options[2].disabled = false;
							document.getElementById("max_rank").selectedIndex = 2;
							//document.getElementById("max_rank").disabled = false;
						}
						break;
					case 3:
						if (navigator.appName=="Microsoft Internet Explorer"){
							document.getElementById("max_rank_select").innerHTML = '<select class="required" title="Proszę wybrać maksymalny ranking"  id="max_rank" onchange="pokazOpisRanking(this)" style="width: 150px;margin-left:0;" name="max_rank"><option value="3">3</option><option SELECTED value="4">4</option><option value="5">5</option></select>';
						}
						else{
							document.getElementById("max_rank").options[0].disabled = true;
							document.getElementById("max_rank").options[1].disabled = true;
							document.getElementById("max_rank").options[2].disabled = false;
							//document.getElementById("max_rank").disabled = false;
							document.getElementById("max_rank").selectedIndex = 3;
						}
						break;
					case 4:
						if (navigator.appName=="Microsoft Internet Explorer"){
							document.getElementById("max_rank_select").innerHTML = '<select class="required" title="Proszę wybrać maksymalny ranking"  id="max_rank" onchange="pokazOpisRanking(this)" style="width: 150px;margin-left:0;" name="max_rank"><option value="4">4</option><option SELECTED value="5">5</option></select>';
						}
						else{
							document.getElementById("max_rank").options[0].disabled = true;
							document.getElementById("max_rank").options[1].disabled = true;
							document.getElementById("max_rank").options[2].disabled = true;
							//document.getElementById("max_rank").disabled = false;
							document.getElementById("max_rank").selectedIndex = 4;
						}
						break;
					case 5:
						//document.getElementById("max_rank").selectedIndex = 4;
						document.getElementById("max_rank_select").innerHTML = '<select class="required" title="Proszę wybrać maksymalny ranking"  id="max_rank" onchange="pokazOpisRanking(this)" style="width: 150px;margin-left:0;" name="max_rank"><option SELECTED value="5">5</option></select>';
						//document.getElementById("max_rank").disabled = false;
						break;
					default:
						document.getElementById("max_rank").selectedIndex = 1;
						//document.getElementById("max_rank").disabled = false;
						break;
				}
				if(max_rank){
					document.getElementById("max_rank").selectedIndex = max_rank-1;
				}
			}
		});
		
}

function poprzednia()
{
    $('strona').value = 1;
    $('game_form').submit();
}

function nastepna()
{
    $('strona').value = 2;
    $('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)
        {
            bxx.innerHTML = "-";
        }
        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
            {
                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)
    	{
    		
    	}
    	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();",1000);
}

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("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('login_form_top').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('login_form_top').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;
	}
}