function createXmlHttp() {

	var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp=false;
	  }
	 }
	@else
	 xmlhttp=false
	 @end @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && window.createRequest) {

		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}

	return xmlhttp;
}

function vyhledat()  {

	var vyraz = document.getElementById('Vyraz').value;

	if (vyraz.length < 3 || vyraz == null || vyraz == "") {
		document.getElementById('vyhledavaniChyba').innerHTML = 'Minimálně 3 znaky!';
		zobrazit('vyhledavaniChyba');
	} else {
		schovat('vyhledavaniChyba');
		window.location="http://www.hokejportal.cz/vyhledavani/"+vyraz+"/";
	}
}

function zobrazit(id)  {
	document.getElementById(id).style.display = 'block';
}

function schovat(id)  {
	document.getElementById(id).style.display = 'none';
}

function loadChat(id)  {

	var xmlHttp = createXmlHttp();

	xmlHttp.open("GET", 'http://www.hokejportal.cz/ajax/chat/'+id+'/', true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.status == 200) {
				setTimeout("loadChat("+id+")", 30000);
			}

			if (xmlHttp.responseText) {
				document.getElementById('chat').innerHTML = xmlHttp.responseText;
			}
		}
	}
}

function loadSkore(id)  {

	var xmlHttp = createXmlHttp();

	xmlHttp.open("GET", 'http://www.hokejportal.cz/ajax/skore/'+id+'/', true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.status == 200) {
				setTimeout("loadSkore("+id+")", 30000);
			}

			if (xmlHttp.responseText) {
				document.getElementById('skore').innerHTML = xmlHttp.responseText;
			}
		}
	}
}

function loadOnline(id)  {

	var xmlHttp = createXmlHttp();

	xmlHttp.open("GET", 'http://www.hokejportal.cz/ajax/online/'+id+'/', true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.status == 200) {
				setTimeout("loadOnline("+id+")", 30000);
				obnovCas();
			}

			if (xmlHttp.responseText) {
				document.getElementById('online').innerHTML = xmlHttp.responseText;
			}
		}
	}
}

function obnovCas()  {
	var cas_span = document.getElementById("cas");
	var cas_hodn = cas_span.innerHTML;
	var int_hodn = parseInt(cas_hodn);
	var nova_int_hodn = int_hodn - 1;

	if (nova_int_hodn > -1) {
		setTimeout("obnovCas()", 1000);
		cas_span.innerHTML = nova_int_hodn;
	} else {
		cas_span.innerHTML = 30;
	}
}

function chat(id)  {
	
	schovat('tlacitko2');
	zobrazit('loading');

	var xmlHttp = createXmlHttp();
	
	var text = document.getElementById('Text').value;

	document.getElementById('Text').value = '';
	
	var dotazovaciRetezec = 'id='+id+'&text='+text;
  var url = 'http://www.hokejportal.cz/ajax/chat/';

	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  xmlHttp.send(dotazovaciRetezec);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.responseText) {

				document.getElementById('chat').innerHTML = xmlHttp.responseText;
				
				schovat('loading');
				zobrazit('tlacitko2');

				delete xmlHttp;
			}
		}
	}
}

function tip(id, tip, uzivatel)  {

	var xmlHttp = createXmlHttp();

	xmlHttp.open("GET", 'http://www.hokejportal.cz/ajax/pridej-tip-zapas/'+id+'/'+tip+'/'+uzivatel+'/', true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.responseText) {

				document.getElementById('tipovacka').innerHTML = xmlHttp.responseText;

				delete xmlHttp;
			}
		}
	}
}

function tipovacka(id, tip, uzivatel)  {

	schovat('zapas'+id);

	var xmlHttp = createXmlHttp();

	xmlHttp.open("GET", 'http://www.hokejportal.cz/ajax/pridej-tip-zapasy/'+id+'/'+tip+'/'+uzivatel+'/', true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.responseText) {

				document.getElementById('vaseTipy').innerHTML = xmlHttp.responseText;

				delete xmlHttp;
			}
		}
	}
}

function smazTip(id, uzivatel)  {

	var xmlHttp = createXmlHttp();

	xmlHttp.open("GET", 'http://www.hokejportal.cz/ajax/smaz-tip/'+id+'/'+uzivatel+'/', true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			document.getElementById('bunka'+id).style.display = 'none';

			delete xmlHttp;
		}
	}
}

function vyhledavani()  {

	schovat('tlacitko');
	zobrazit('load');

	var xmlHttp = createXmlHttp();
	
	var podle = document.getElementById('Podle').value;

	var retezec = document.getElementById('Retezec').value;

	xmlHttp.open("GET", 'http://www.hokejportal.cz/ajax/vyhledavani-uzivatelu/'+podle+'/'+retezec+'/', true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.responseText) {

				document.getElementById('vysledek-vyhledavani').innerHTML = xmlHttp.responseText;
				
				zobrazit('tlacitko');
				schovat('load');

				delete xmlHttp;
			}
		}
	}
}

function anketa(sekce, anketaId, odpovedId)  {
	
	schovat('info');
	zobrazit('loading');

	var xmlHttp = createXmlHttp();

	xmlHttp.open("GET", 'http://www.hokejportal.cz/ajax/anketa/'+sekce+'/'+anketaId+'/'+odpovedId+'/', true);

	xmlHttp.send(null);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.responseText) {

				document.getElementById('anketa').innerHTML = xmlHttp.responseText;

				delete xmlHttp;
			}
		}
	}
}

function komentarePridat(sekce, id)  {

	schovat('pridatKomentar');
	zobrazit('loadingKomentar');

	var xmlHttp = createXmlHttp();

	var text = document.getElementById('Text').value;
	var odsazeni = document.getElementById('Odsazeni').value;
	var nadrazeny = document.getElementById('KomentarId').value;

	var dotazovaciRetezec = 'sekce='+sekce+'&id='+id+'&text='+text+'&odsazeni='+odsazeni+'&nadrazeny='+nadrazeny;
	var url = 'http://www.hokejportal.cz/komentare/pridat/';

	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlHttp.send(dotazovaciRetezec);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.responseText) {

				document.getElementById('Text').value = '';
				document.getElementById('Odsazeni').value = '';
				document.getElementById('KomentarId').value = '';
				document.getElementById('komentare').innerHTML = xmlHttp.responseText;

				schovat('loadingKomentar');
				zobrazit('pridatKomentar');

				delete xmlHttp;
			}
		}
	}
}

function komentareSmazat(sekce, id, komentar)  {

	var xmlHttp = createXmlHttp();

	var dotazovaciRetezec = 'sekce='+sekce+'&id='+id+'&komentar='+komentar;
	var url = 'http://www.hokejportal.cz/komentare/smazat/';

	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlHttp.send(dotazovaciRetezec);

	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {

			if (xmlHttp.responseText) {

				document.getElementById('komentare').innerHTML = xmlHttp.responseText;

				delete xmlHttp;
			}
		}
	}
}

function komentareValid(sekce, id)  {

	var text = document.getElementById('Text').value;
	var chyba = 'ne';

	if (text.length < 1 || text == null || text == "") {
		document.getElementById('chybaText').innerHTML = 'Nezadali jste text!';
		chyba = 'ano';
	}

	if (text.length > 1000) {
		document.getElementById('chybaText').innerHTML = 'Zadaný text je příliš dlouhý! Maximální povolená délka textu je 1000 znaků.';
		chyba = 'ano';
	}

	if (chyba == 'ne') {
		schovat('chyba');
		komentarePridat(sekce, id);
	} else {
		zobrazit('chyba');
	}
}

function komentareOdpovedet(komentarId, odsazeni) {

	document.getElementById('KomentarId').value = komentarId;
	document.getElementById('Odsazeni').value = odsazeni + 15;
	document.getElementById('Text').focus();

	return false;
}

function komentareSmajlik(cislo) {

	var elm = document.getElementById('Text');

	elm.focus();
	elm.value = elm.value + ' .:' + cislo + ':. ';

	return false;
}

function iframe() {

	var xmlHttp1 = createXmlHttp();
	var xmlHttp2 = createXmlHttp();

	var druh = document.getElementById('Druh').value;
	var liga = document.getElementById('Liga').value;
	var kodovani = document.getElementById('Kodovani').value;
	var sirka = document.getElementById('Sirka').value;

	xmlHttp2.open("GET", 'http://www.hokejportal.cz/iframe/html/'+druh+'/'+liga+'/'+kodovani+'/'+sirka+'/', true);
	xmlHttp1.open("GET", 'http://www.hokejportal.cz/iframe/'+druh+'/'+liga+'/'+kodovani+'/'+sirka+'/', true);

	xmlHttp2.send(null);
	xmlHttp1.send(null);

	xmlHttp1.onreadystatechange = function() {

		if (xmlHttp1.readyState == 4) {

			if (xmlHttp1.responseText) {

				document.getElementById('Nahled').innerHTML = xmlHttp1.responseText;
				document.getElementById('Html').innerHTML = xmlHttp2.responseText;

				delete xmlHttp1;
				delete xmlHttp2;
			}
		}
	}
}
function get(action, element, data)
{
	$.ajax({
		method: "get",url: '/ajax/'+action+'/'+data+'/',data: "", 
		success: function(html){
			$("#"+element).html(html);
		}
	});
}

function likeit(clanekId) {
	$.ajax({
		method: "get",url: '/ajax/likeit/'+clanekId+'/',data: "", 
		beforeSend: function() {
			$("#libiloseText").html('<img src="/www/images/ajax-loader.gif" alt="Ukládám" title="Ukládám" />');
		}, 
		success: function(html){
			if (html == 'error') {
				$("#libiloseText").html('Hlasoval!');
				setInterval('clearLikeIt()',1500);
			} else {
				$("#libilose > p").html(html);
				$("#libiloseText").html('Děkujeme');
				setInterval('clearLikeIt()',1500);
			}
		}, 
		error: function(html){
			$("#libiloseText").html('Chyba !');
			setInterval('clearLikeIt()',1500);
		}
	});
}

function clearLikeIt() {
	$("#libiloseText").html('Líbilo se');
}

function display(id) {
	$("#"+id).toggle();
}