/* AJAX pro roletku s uzivatelema */
function odeslat_kamaradovi_fce(id){
	 komu = document.getElementById("otevrena-hra-nadpis").value;
	 komentar = document.getElementById("otevrena-hra-obsah").value;
		var url =  '/ajax.php?akce=odeslat_kamaradovi&email='+komu+'&komentar='+komentar+'&id='+id;
     if (url != 0)
     {
        if (window.ActiveXObject)
        {
          odeslat_kamaradovi = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          odeslat_kamaradovi = new XMLHttpRequest();
        }
        odeslat_kamaradovi.open("GET", url, true);
        odeslat_kamaradovi.onreadystatechange= function () {odeslat_kamaradovi_reakce()} ;
        odeslat_kamaradovi.send(null);
      }
}

function odeslat_kamaradovi_reakce()
{
  if (odeslat_kamaradovi.readyState == 4)
  {
    if(odeslat_kamaradovi.status == 200)
    {
    	 document.getElementById("odeslat-kamaradovi-odpoved").innerHTML = odeslat_kamaradovi.responseText; 	
		 	
    }
    else
    {
        alert("Chyba pri nacitani stanky"+ odeslat_kamaradovi.status +":"+ odeslat_kamaradovi.statusText);
    }
  }else{
	document.getElementById("odeslat-kamaradovi-odpoved").innerHTML = "<div style='width: 260px; margin-left: auto; margin-right: auto;'><img src='/obr/loading.gif' alt='Nahrávám' style='float:left;'><div style='float:left;¨margin-left: 10px;margin-top: 2px;'>Odesílám</div></div>";
}
}




function hlavni_strana_ajax(akce,strana,pocet)
{
     var url =  '/ajax.php?akce='+akce+'&strana='+strana+'&pocet='+pocet;
     if (url != 0)
     {
        if (window.ActiveXObject)
        {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange= function () {processRequest(akce,strana,pocet); } ;
        httpRequest.send(null);
      }
}

function processRequest(akce,strana,pocet)
{
  if (httpRequest.readyState == 4)
  {
    if(httpRequest.status == 200)
    {
    	document.getElementById(akce+"-text").innerHTML = httpRequest.responseText; 	
    }
    else
    {
        alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }else{
	document.getElementById(akce+"-text").innerHTML = "<div id='loading'><img src='obr/loading.gif' alt='Nahrávám' id='loading-obrazek'><div id='loading-text'>Nahrávám</div></div>" + document.getElementById(akce+"-text").innerHTML
}
}



function spustena_hra(id,poprve){
	 var url =  '/ajax.php?akce=spustena_hra&id='+id+'&poprve='+poprve;
     if (url != 0)
     {
        if (window.ActiveXObject)
        {
          spusteno = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          spusteno = new XMLHttpRequest();
        }
        spusteno.open("GET", url, true);
        spusteno.send(null);
    }
      setTimeout("spustena_hra("+id+",0)", 61*1000);
}

function oblibene_fce(id,typ){
	if (typ == "pridat"){
		var url =  '/ajax.php?akce=oblibene&typ=pridat&id='+id;	
	}else{
		if (typ == "smazat"){
			var url =  '/ajax.php?akce=oblibene&typ=smazat&id='+id;
		}
	}
     
     if (url != 0)
     {
        if (window.ActiveXObject)
        {
          oblibene = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          oblibene = new XMLHttpRequest();
        }
        oblibene.open("GET", url, true);
        oblibene.onreadystatechange= function () {oblibene_reakce(id)} ;
        oblibene.send(null);
      }
}

function oblibene_reakce(id)
{
  if (oblibene.readyState == 4)
  {
    if(oblibene.status == 200)
    {
    	var vstup = oblibene.responseText; 	
    	var kde = vstup.indexOf("/||/");
    	document.getElementById("tlacitko-oblibene").innerHTML = vstup.substr(kde + 4);
      	document.getElementById("oblibene_hry").innerHTML =  vstup.substr(0,kde);
      	
		 	
    }
    else
    {
        alert("Chyba pri nacitani stanky"+ oblibene.status +":"+ oblibene.statusText);
    }
  }else{
	//document.getElementById(akce+"-text").innerHTML = "<div id='loading'><img src='obr/loading.gif' alt='Nahrávám' id='loading-obrazek'><div id='loading-text'>Nahrávám</div></div>" + document.getElementById(akce+"-text").innerHTML
}
}


function hvezdicky_aktualni(id){
			for (i=1; i < 6; i++){
				if (id == i){
					document.getElementById('hvezdicka_' + i).src = 'obr/hvezdicky/h_zlata.gif';}else {if (id > i){document.getElementById('hvezdicka' + i).src = 'obr/hvezdicky/h_zlata50per.gif';}
				else{							
					document.getElementById('hvezdicka' + i).src = 'obr/hvezdicky/h_seda.gif';}}								
			}						
}


function skryjZobraz(co,co_dalsi){

	if (document.getElementById(co).style.display == 'none'){
		//$("div#"+co_dalsi).hide("blind", { direction: "vertical" }, 1000);
		//$("div#"+co).show("blind", {}, 1000);		
		document.getElementById(co).style.display = '';
		document.getElementById(co_dalsi).style.display = 'none';
	}else{
		//$("div#"+co).hide("blind", { direction: "vertical" }, 1000);
		//$("div#"+co_dalsi).show("blind", {}, 1000);
		document.getElementById(co).style.display = 'none';
		document.getElementById(co_dalsi).style.display = '';
	}
	
}



function hvezdicky_najeti(kam){
	for (i = 1; i<6;i++){
		if (i <= kam){
			document.getElementById("hvezdicka-"+i).src = '/layout/hvezdicka-najeta.png';
		}else{
			document.getElementById("hvezdicka-"+i).src = '/layout/hvezdicka.png';
		}
	}
}

function hvezdicky_odjeti(kam){
	for (i = 1; i<6;i++){
		if (i <= kam){
			document.getElementById("hvezdicka-"+i).src = '/layout/hvezdicka-najeta.png';
		}else{
			if(i+0.5 <= i){
				document.getElementById("hvezdicka-"+i).src = '/layout/hvezdicka-pul.jpg';
			}else{
				document.getElementById("hvezdicka-"+i).src = '/layout/hvezdicka.png';
			}
		}		
	}
}	

function hodnot_fce(id,kolik,hash){
     var url =  '/ajax.php?akce=hodnotit&id='+id+'&kolik='+kolik+'&hash='+hash;
     if (url != 0)
     {
        if (window.ActiveXObject)
        {
          hodnot = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          hodnot = new XMLHttpRequest();
        }
        hodnot.open("GET", url, true);
        hodnot.onreadystatechange= function () {hodnot_reakce(id,kolik); } ;
        hodnot.send(null);
      }
}

function hodnot_reakce(id,kolik)
{
  if (hodnot.readyState == 4)
  {
    if(hodnot.status == 200)
    {
    	document.getElementById("hodnoceni").innerHTML = hodnot.responseText; 	
    }
    else
    {
        alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }else{
}
}


function pridatkomentarZobraz(){
	$("div#pridat-komentar-box").show("blind", {}, 1000,document.getElementById('pridatkomentar').onclick = '');
}




function zobrazitKomentare(id,typ)
{
     var url =  '/ajax.php?akce=komentare&id='+id+'&typ='+typ;
     if (url != 0)
     {
        if (window.ActiveXObject)
        {
          komentare = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          komentare = new XMLHttpRequest();
        }
        komentare.open("GET", url, true);
        komentare.onreadystatechange= function () {komentare_reakce(id,typ); } ;
        komentare.send(null);
      }
}

function komentare_reakce(id,typ)
{
  if (komentare.readyState == 4)
  {
    if(komentare.status == 200)
    {
    	document.getElementById("diskuze-obsah").innerHTML = komentare.responseText;
		if (typ == true){
			document.getElementById("diskuze-zavrit-vse").style.display= '';
			document.getElementById("diskuze-zobrazit-vse").style.display= 'none';
			
		}else{
			document.getElementById("diskuze-zobrazit-vse").style.display= '';
			document.getElementById("diskuze-zavrit-vse").style.display= 'none';			
		} 	
    }
    else
    {
        alert("Chyba pri nacitani stanky"+ komentare.status +":"+ komentare.statusText);
    }
  }else{
}
}

/* Přesouvání  
$("#prava-strana").sortable({
	placeholder: "ui-selected";
	revert: true;
});*/



