function oKorisniku(ulime, th) {
	var zu = th.parentNode.parentNode.lastChild; // za upis
	if( http && !uPogonuSam ) {
		http.open("GET", "korisnik.php?action=DajZaForum&ulime="+ulime);
		http.onreadystatechange = function() {
			if( http.readyState == 4 ) {
				uPogonuSam = false;
				zu.innerHTML = http.responseText;
				th.src = "stilovi/zatvori.gif";
				th.title = "Zatvori";
				th.alt = "Zatvori";
				th.onclick = function() {
					zu.innerHTML = "";
					th.src = "stilovi/otvori.gif";
					th.title = "O korisniku";
					th.alt = "O korisniku";
					th.onclick = function() {
						oKorisniku(ulime, th);
					}
				}
			}
		}
		uPogonuSam = true;
		http.send( null );
	}
}

function PreimenujTemu( tid, stari ) {
	var naslov = prompt ( "Unesite novi naslov teme ili kliknite [Cancel]", stari.innerHTML );
	if( naslov != null && naslov != "" ) {
		if( http && !uPogonuSam ) {
			http.open("POST", "forumi.php?action=t_PreimenujTemu");
			http.onreadystatechange = function() {
				if( http.readyState == 4 ) {
					uPogonuSam = false;
					if( http.responseText.indexOf("Greška") == -1 ) {
						stari.innerHTML = http.responseText;
					} else {
						alert( http.responseText );
					}
				}
			}
			uPogonuSam = true;
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			http.send( "tid="+tid+"&naslov="+naslov );
		}
	}
}

function Odgovori( tid, th ) { // Odgovor na temu tid
	cF = document.getElementById("cForm");
	cF.style.display = "block";
	cF.action = "forumi.php?action=t_DodajClanak&tid="+tid;
	thn = th.parentNode.parentNode;
	thn.appendChild( cF );
//	enableDesignMode('tekst', '', false);
}

function PokreniTemu( fid, th ) {
	cF = document.getElementById("cForm2");
	cF.style.display = "block";
	cF.action = "forumi.php?action=f_DodajTemu&fid="+fid;
	thn = th.parentNode.parentNode;
	thn.appendChild( cF );
// enableDesignMode('tekst', '', false);
}

function ObrisiOznaceneTeme( fid ) {
	var fT = document.getElementById("fTeme");
	if( confirm( "Doista želite obrisati označene teme?" ) ) {
		fT.action = "forumi.php?action=f_ObrisiOznaceneTeme&fid="+fid;
		fT.submit();
	}
}

function SrediOznaceneTeme( fid ) {
	var fT = document.getElementById("fTeme");
	fT.action = "forumi.php?action=f_SrediOznaceneTeme&fid="+fid;
	fT.submit();
}

function PremjestiOznaceneTeme( fid ) {
	var sF = document.getElementById("sPForumi");
	if( sF.style.display == "none" ) {
		sF.style.display = "";
	} else {
		var fid2 = sF.options[sF.options.selectedIndex].value;
		var fT = document.getElementById("fTeme");
		fT.action = "forumi.php?action=f_PremjestiOznaceneTeme&fid="+fid+"&fid2="+fid2;
		fT.submit();
	}
}

function ObrisiTemu( tid ) {
	if( confirm( "Doista ćelite obrisati čitavu temu?" ) ) {
		location = "forumi.php?action=t_ObrisiTemu&tid="+tid;
	}
}

function PremjestiTemu( tid ) {
	var sF = document.getElementById("sPForumi");
	if( sF.style.display == "none" ) {
		sF.style.display = "";
	} else {
		var fid2 = sF.options[sF.options.selectedIndex].value;
		location = "forumi.php?action=t_PremjestiTemu&tid="+tid+"&fid2="+fid2;
	}
}

function ZakljucajTemu( tid ) {
	location = "forumi.php?action=t_ZakljucajTemu&tid="+tid;
}

function OtkljucajTemu( tid ) {
	location = "forumi.php?action=t_OtkljucajTemu&tid="+tid;
}

function VaznaTema( tid ) {
	location = "forumi.php?action=t_VaznaTema&tid="+tid;
}

function ObrisiOznaceneClanke( tid ) {
	var fC = document.getElementById("fClanci");
	if( confirm( "Doista želite obrisati označene članke?" ) ) {
		fC.action = "forumi.php?action=t_ObrisiOznaceneClanke&tid="+tid;
		fC.submit();
	}
}

function RazdvojiOznaceneClanke( tid ) {
	var fC = document.getElementById("fClanci");
	var naslov = prompt ( "Unesite naslov nove teme ili kliknite [Cancel]" );
	if( naslov != null && naslov != "" ) {
		fC.action = "forumi.php?action=t_RazdvojiOznaceneClanke&tid="+tid+"&naslov="+naslov;
		fC.submit();
	}
}

function IzmjeniClanak( tid, cid, th, aret ) {
	var cF = document.getElementById("cForm");
	bret = aret.cloneNode( true );
	aret.style.display="none";
	cF.aret = aret;
	cF.style.display = "block";
	cF.action = "forumi.php?action=t_SpremiClanak&tid="+tid+"&cid="+cid;
	cF.tekst.value = bret.innerHTML;
	thn = th.parentNode.parentNode;
	thn.appendChild( cF );
	document.getElementById('hdntekst').value = bret.innerHTML;
//	enableDesignMode('tekst', bret.innerHTML, false);
	alert( "Ako se nije pojavio ispravan tekst članka\n\rprobajte opet kliknuti na [Izmjenite]" );
}

function ObrisiClanak( tid, cid ) {
	if( confirm( "Doista ćelite obrisati ovaj članak?" ) ) {
		location = "forumi.php?action=t_ObrisiClanak&tid="+tid+"&cid="+cid;
	}
}

function SpojiTeme( tid ) {
	nova = prompt( "Upišite naslov novo kreirane teme!" );
	if( nova != null && nova != "" ) {
		alert( "Sada trebate pronaći temu koju želite spojiti sa "+tid );
		location = "forumi.php?action=t_SpojiTeme&tid="+tid+"&nova="+nova;
	}
}

function PrekiniSpajanje( tid ) {
	location = "forumi.php?action=PrekiniSpajanje&location="+location;
}

var IE, cUpis, zc, zcs, zcp, is;

function PokreniChat() {
	zc = document.getElementById("zChat");
	zcs = document.getElementById("zcSalje");
	zcp = document.getElementById("zcPrima");
	is = document.getElementById("iSalje");

	IE = ( navigator.userAgent.toLowerCase().indexOf("msie") != -1 ); 
	if ( IE ) {
		var sr = document.getElementById("sredina");
		sr.style.paddingLeft = 0;
		sr.style.paddingRight = 0;
		sr.style.width= document.getElementById("h1").clientWidth-460;
		sr.style.paddingTop = 0;

		zc.style.height = 400;
		zc.style.position = "absolute";
		zcs.style.position = "absolute";
		zcs.style.top = 380;
		zcp.style.height = 366;
	}
	is.focus();
	is.onkeyup = StoPise;
	setTimeout( "DohvatiChat()", 1000 );
}

function DohvatiChat() {
//	document.getElementById("sredina").style.width= document.getElementById("h1").clientWidth-460;
	if( http && !uPogonuSam ) {
		http.open("GET", "chat5.php");
		http.onreadystatechange = function() {
			if( http.readyState == 4 ) {
				uPogonuSam = false;
				zcp.innerHTML += http.responseText;
				zcp.scrollTop = zcp.scrollHeight;
			}
		}
		uPogonuSam = true;
		http.send( null );
	} else {
//		zcp.innerHTML += "<b>Nisam dohvatio</b><br />";
		zcp.scrollTop = zcp.scrollHeight;
	}
	setTimeout("DohvatiChat()", 3000);
}

function StoPise(e) {
	if( IE ) e=event;
	if( e.keyCode == 13 ) {
		cUpis = is.value;
		PosaljiChatu();
		is.value = "";
		is.focus();
	}
}

var uPogonu2 = false;

function PosaljiChatu() {
	if( hp && !uPogonu2 ) {
		hp.open("POST", "chat5.php", true);
		hp.onreadystatechange = function() {
			if( hp.readyState == 4 ) {
				uPogonu2 = false;
				cUpis = "";
			}
		}
//		uPogonu2 = true;
		hp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		hp.send( "action=posalji&str="+cUpis );
	} else {
		zcp.innerHTML += "<b>Nisam upisao.</b><br />";
	}
}

function PokaziKorisnika( ulime ) {
	zcp.innerHTML += "<div class='head'>Trazim podatke o korisniku [<a href='korisnici.php?action=Vidi&ulime="+ulime+"'>"+ulime+"</a>]<\/div>";
	if( http && !uPogonuSam ) {
		http.open( "GET", "korisnici.php?action=Vidi2&ulime="+ulime, true );
		http.onreadystatechange = function() {
			if( http.readyState == 4 ) {
				uPogonuSam = false;
				zcp.innerHTML += http.responseText;
				zcp.scrollTop = zcp.scrollHeight;
			}
		}
		uPogonuSam = true;
		http.send( null );		
	}
}

function Blokiraj( ulime, forum ) {
	var razlog = prompt ( "Upišite zašto želite blokirati korisnika ["+ulime+"]\nili kliknite[Cancel]", "" );
	if( razlog != null && razlog != "" ) {
		if( hp && !uPogonu2 ) {
			hp.open("POST", "forumi.php?action=f_blokiraj", true);
			hp.onreadystatechange = function() {
				if( hp.readyState == 4 ) {
					uPogonu2 = false;
					alert( hp.responseText );
				}
			}
			uPogonu2 = true;
			hp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			hp.send( "razlog="+razlog+"&ulime="+ulime+"&fid="+forum );
		} else {
			alert( "Nisam poslao :(" );
		}
	}
}
