
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
	var xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		var XmlHttpVersions = new Array('Msxml2.XMLHTTP.7.0',
										'MSXML2.XMLHTTP.6.0',
										'MSXML2.XMLHTTP.5.0',
										'MSXML2.XMLHTTP.4.0',
										'MSXML2.XMLHTTP.3.0',
										'MSXML2.XMLHTTP',
										'Microsoft.XMLHTTP');		
		for(var i = 0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{	
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e){}
		}
	}
	if(!xmlHttp)
	{
		alert("Error!");
	}
	else
	{
		return xmlHttp;
	}
}	
function poziv_meni(link)
{
	clear();
	if(xmlHttp)
	{
		try
		{
			switch(link)
			{
				case 3: xmlHttp.open("GET","Tecajevi.html", true);
				break;
				case 5: xmlHttp.open("GET","u_izradi.html",true);
				break;
			}
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
				{
					var tekst = xmlHttp.responseText;
					var divPrvi = document.getElementById("divPrvi");
					divPrvi.innerHTML = tekst;
				}
			}
			
			xmlHttp.send(null);
		}
		catch(e)
		{
		}
	}
}
//Odjava korisnika iz sustava

//Odjavljuje korisnika iz sustava, briše CMS navigaciju, te vraća login formu.

function izlaz()
{
	brisanje_elementa("popDiv");
	brisanje_elementa("divPodloga");
}
function izlaz2()
{
	brisanje_elementa("popSlika");
	brisanje_elementa("divPodloga");
}
function brisanje_elementa(id)
{
	try
	{
		var element = document.getElementById(id);
		element.parentNode.removeChild(element);
	}
	catch(e)
	{
	}
}

function clear()
{
	document.getElementById("divPrvi").innerHTML="";
	document.getElementById("divDrugi").innerHTML="";
	document.getElementById("divTreci").innerHTML="";
}

function stil_za_table(element)
{
	try
	{
		var tablica = document.getElementById("tblTecajevi");
		var redovi = tablica.getElementsByTagName("tr");
		for(i=0;i<redovi.length;i++)
		{
			if(redovi[i]==element)
			{
				redovi[i].style.background="#cae4ff";
			}
			else
			{
				redovi[i].style.background="";
			}
		}
	}
	catch(e)
	{}
}
function prikaz_popDiv()
{
	var popDiv = document.createElement("div");
	popDiv.setAttribute("id","popDiv");
}
function prikaz_podloga()
{
	var divPodloga = document.createElement("div");
	divPodloga.setAttribute("id", "divPodloga");
	document.body.appendChild(divPodloga);
	document.getElementById("divPodloga").style.left= document.body.offsetLeft+"px";
	document.getElementById("divPodloga").style.top = document.body.offsetTop+"px";
	document.getElementById("divPodloga").style.width=document.body.offsetWidth+"px";
	document.getElementById("divPodloga").style.height =document.body.offsetHeight+"px";
}
function check_checkbox()
{
	document.getElementById("chkbox").checked = true;
}
function uncheck_checkbox()
{
	document.getElementById("chkbox").checked = false;
}
//Funkcija za validaciju polja
function validacija_polja(polje, upozorenje)
{
	if(polje.value==null || polje.value=="")
	{
		alert(upozorenje);
		polje.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function pub_tecaj_zupanije()
{
	document.getElementById("divDrugi").innerHTML="";
	document.getElementById("divTreci").innerHTML="";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("POST","pub_tecaj_zupanije.php",true);
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divDrugi").innerHTML = tekst;
				}
			}
			xmlHttp.send(null);
		}
		catch(e)
		{
		}
	}
}


function pub_tecaj_zupanija_grad(id_zupanije)
{
	document.getElementById("divDrugi").innerHTML="";
	document.getElementById("divTreci").innerHTML="";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("POST","pub_tecaj_zupanija_grad.php",true);
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divDrugi").innerHTML = tekst;
				}
			}
			xmlHttp.send("zupanija="+id_zupanije);
		}
		catch(e)
		{
		}
	}
}
function pub_tecaj_grad(id_grada, stranica)
{
	document.getElementById("divDrugi").innerHTML="";
	document.getElementById("divTreci").innerHTML="";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("POST","pub_grad_tecaj.php",true);
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divDrugi").innerHTML = tekst;
				}
			}
			xmlHttp.send("grad="+id_grada+"&stranica="+stranica);
		}
		catch(e)
		{
		}
	}
}
function pub_prethodna_str_tecaj(stranica, grad)
{
	if(stranica>1)
	{
		stranica--;
		pub_tecaj_grad(grad, stranica);
	}
}
function pub_sljedeca_str_tecaj(stranica, ukupno_stranica, grad)
{
	if(stranica<ukupno_stranica)
	{
		stranica++;
		pub_tecaj_grad(grad, stranica);
	}
}
function cms_upload_slike_sucelje()
{
	var popDiv = document.createElement("div");
	popDiv.setAttribute("id","popDiv");
	var divPodloga = document.createElement("div");
	divPodloga.setAttribute("id", "divPodloga");
	id_tecaj = document.getElementById("hidTecaj").innerHTML;
	if(id_tecaj!="")
	{
		id_tecaj = parseInt(id_tecaj);
		if(xmlHttp)
		{
			try
			{
				xmlHttp.open("GET","cms_sucelje_upload_slike.php?id_tecaj="+id_tecaj,true);
				xmlHttp.onreadystatechange = function ()
				{
					if(xmlHttp.readyState==4 && xmlHttp.status==200)
					{
						var tekst = xmlHttp.responseText;
						popDiv.innerHTML = tekst;
					}	
				}
				xmlHttp.send(null);
			}
			catch(e)
			{
			}
			document.body.appendChild(divPodloga);
			
			document.getElementById("divPodloga").style.left= document.body.offsetLeft+"px";
			document.getElementById("divPodloga").style.top = document.body.offsetTop+"px";
			document.getElementById("divPodloga").style.width=document.body.offsetWidth+"px";
			document.getElementById("divPodloga").style.height =document.body.offsetHeight+"px";
			
			document.getElementById("page").appendChild(popDiv);
		}
	}
	else
	{
		alert("Morate selektirati tečaj!");
	}

}
function cms_upload_slike()
{
	var iframe = document.createElement("iframe");
	iframe.setAttribute("id", "iframe_upload");
	iframe.setAttribute("name", "iframe_upload");
	iframe.style.width="0px";
	iframe.style.height="0px";
	iframe.style.border="0px";
	iframe.src="#";
	document.getElementById("popDiv").appendChild(iframe);
	document.frmUpload.submit();
}
function pub_tecaj_prikaz(id_tecaj)
{
	document.getElementById("divDrugi").innerHTML="";
	document.getElementById("divTreci").innerHTML="";
	if(xmlHttp)
		{
			try
			{
				xmlHttp.open("GET","pub_tecaj_prikaz.php?id_tecaj="+id_tecaj,true);
				xmlHttp.onreadystatechange = function ()
				{
					if(xmlHttp.readyState==4 && xmlHttp.status==200)
					{
						var tekst = xmlHttp.responseText;
						document.getElementById("divDrugi").innerHTML = tekst;
					}	
				}
				xmlHttp.send(null);
			}
			catch(e)
			{
			}
		}	
}
function pub_tecaj_gradovi(stranica)
{
	document.getElementById("divDrugi").innerHTML="";
	document.getElementById("divTreci").innerHTML="";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("GET","pub_tecaj_gradovi.php?stranica="+stranica ,true);
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divDrugi").innerHTML = tekst;
				}	
			}
			xmlHttp.send(null);
		}
		catch(e)
		{
		
		}
	}	
}
function pub_prethodna_str_grad(stranica)
{
	if(stranica>1)
	{
		stranica--;
		pub_tecaj_gradovi(stranica);
	}
}
function pub_sljedeca_str_grad(stranica, ukupno_stranica)
{
	if(stranica<ukupno_stranica)
	{
		stranica++;
		pub_tecaj_gradovi(stranica);
	}
}
function pub_tecaj_popis(stranica)
{
	document.getElementById("divDrugi").innerHTML="";
	document.getElementById("divTreci").innerHTML="";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("GET","pub_tecaj_popis.php?stranica="+stranica ,true);
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divDrugi").innerHTML = tekst;
				}	
			}
			xmlHttp.send(null);
		}
		catch(e)
		{
		
		}
	}	
}
function pub_tecaj_grad_prikaz(id_tecaj)
{
	document.getElementById("divDrugi").innerHTML="";
	document.getElementById("divTreci").innerHTML="";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("GET","pub_tecaj_grad_prikaz.php?id_tecaj="+id_tecaj,true);
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divDrugi").innerHTML = tekst;
				}	
			}
			xmlHttp.send(null);
		}
		catch(e)
		{
		}
	}	
}
function pub_prethodna_stranica(stranica, sifra)
{
	if(stranica>1)
	{
		stranica--;
		switch(sifra)
		{
			case 1: pub_tecaj_popis(stranica);
			break;
			case 2: pub_tecaj_popis_mladi(stranica);
			break;
		}
	}
}
function pub_sljedeca_stranica(stranica, ukupno_stranica, sifra)
{
	if(stranica<ukupno_stranica)
	{
		stranica++;
		switch(sifra)
		{
			case 1: pub_tecaj_popis(stranica);
			break;
			case 2: pub_tecaj_popis_mladi(stranica);
			break;
		}
	}
}
function pub_prikaz_slike(ID_slika)
{
	var popDiv = document.createElement("div");
	popDiv.setAttribute("id","popSlika");
	if(xmlHttp)
		{
			try
			{
				xmlHttp.open("GET","pub_prikaz_slike.php?ID_slika="+ID_slika,true);
				xmlHttp.onreadystatechange = function ()
				{
					if(xmlHttp.readyState==4 && xmlHttp.status==200)
					{
						var tekst = xmlHttp.responseText;
						popDiv.innerHTML = tekst;
					}	
				}
				xmlHttp.send(null);
			}
			catch(e)
			{
			}
		}	
	prikaz_podloga();
	document.getElementById("page").appendChild(popDiv);	
}
function pub_obicni_prikaz_slike(slika)
{
	var visina;
	var popDiv = document.createElement("div");
	popDiv.setAttribute("id","popSlika");
	if(xmlHttp)
		{
			try
			{
				xmlHttp.open("GET","pub_obicni_prikaz_slike.php?slika="+slika,true);
				xmlHttp.onreadystatechange = function ()
				{
					if(xmlHttp.readyState==4 && xmlHttp.status==200)
					{
						var tekst = xmlHttp.responseText;
						popDiv.innerHTML = tekst;
					}	
				}
				xmlHttp.send(null);
			}
			catch(e)
			{
			}
		}	
	prikaz_podloga();
	//document.getElementById("page").appendChild(popDiv);
	document.body.appendChild(popDiv);
	visina = document.body.offsetHeight
	document.getElementById("popSlika").style.top = 50 + "px";
	document.getElementById("popSlika").style.left = 50+"%";
	document.getElementById("popSlika").style.marginLeft = -300 + "px";
	
}

function pub_tecaj_mladi_prikaz(id_tecaj)
{
	clear();
	//document.getElementById("divDrugi").innerHTML="";
	//document.getElementById("divTreci").innerHTML="";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("GET","pub_tecaj_mladi_prikaz.php?id_tecaj="+id_tecaj,true);
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divPrvi").innerHTML = tekst;
				}	
			}
			xmlHttp.send(null);
		}
		catch(e)
		{
		}
	}	
}
function pub_dojam_mladi_prikaz(id_dojam)
{
	document.getElementById("divDrugi").innerHTML = "";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("GET","pub_dojam_mladi_prikaz.php?id_dojam="+id_dojam,true);
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divDrugi").innerHTML = tekst;
				}	
			}
			xmlHttp.send(null);
		}
		catch(e)
		{
		}
	}
}
function pub_novosti_male()
{
	document.getElementById("novosti").innerHTML = "";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("GET","pub_novosti_male.php",true);
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("novosti").innerHTML = tekst;
				}	
			}
			xmlHttp.send(null);
		}
		catch(e)
		{
		}
	}
}
function pub_dojam_prikaz(id_dojam)
{
	document.getElementById("divTreci").innerHTML = "";
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("GET","pub_dojam_mladi_prikaz.php?id_dojam="+id_dojam,true);
			xmlHttp.onreadystatechange = function ()
			{
				if(xmlHttp.readyState==4 && xmlHttp.status==200)
				{
					var tekst = xmlHttp.responseText;
					document.getElementById("divTreci").innerHTML = tekst;
				}	
			}
			xmlHttp.send(null);
		}
		catch(e)
		{
		}
	}
}
function PotvrdaBrisanja(skripta, tip)
{
	if(confirm("Da li ste sigurni da želite obrisati "+tip+"?"))
	{
		window.location.href=skripta;
	}
}

