
// avtomatsko pogledamo, če obstaja kaj kar moramo razbiti po rich text pravilih

function fetchRichText(){
	$(".jsRichText").each(function(i){
  	body = handleRichText($(this).html()); // spravi noter smeškote.... naredi presledke...
  	$(this).html(body)
	});
}


/* = handleRichText - funkcija, ki uredi forume, zasebna sporočila..../*
************************/

function handleRichText(body){
		body = body + " ";
		body = txt2html(body);
		
		// smajli
		body = body.replace(/\[veselje\]/gi, "<img src='/slike/cgp-forum-01.gif'>");
		body = body.replace(/\[kul\]/gi, "<img src='/slike/cgp-forum-02.gif'>");
		body = body.replace(/\[jeza\]/gi, "<img src='/slike/cgp-forum-03.gif'>");
		body = body.replace(/\[zloba\]/gi, "<img src='/slike/cgp-forum-04.gif'>");	
		body = body.replace(/\[jok\]/gi, "<img src='/slike/cgp-forum-05.gif'>");
		body = body.replace(/\[zalost\]/gi, "<img src='/slike/cgp-forum-06.gif'>");
		body = body.replace(/\[groza\]/gi, "<img src='/slike/cgp-forum-07.gif'>");
		body = body.replace(/\[rdecica\]/gi, "<img src='/slike/cgp-forum-08.gif'>");
		body = body.replace(/\[buska\]/gi, "<img src='/slike/cgp-forum-09.gif'>");
		body = body.replace(/\[pomezik\]/gi, "<img src='/slike/cgp-forum-10.gif'>");
		body = body.replace(/\[molk\]/gi, "<img src='/slike/cgp-forum-11.gif'>");
		body = body.replace(/\[koma\]/gi, "<img src='/slike/cgp-forum-12.gif'>");
		body = body.replace(/\[cudo\]/gi, "<img src='/slike/cgp-forum-13.gif'>");
		body = body.replace(/\[dvom\]/gi, "<img src='/slike/cgp-forum-14.gif'>");
		body = body.replace(/\[cmok\]/gi, "<img src='/slike/cgp-forum-15.gif'>");
		body = body.replace(/\[krohot\]/gi, "<img src='/slike/cgp-forum-16.gif'>")	;	
		body = body.replace(/\[srcek\]/gi, "<img src='/slike/cgp-forum-17.gif'>");
		body = body.replace(/\[vesoljc\]/gi, "<img src='/slike/cgp-forum-18.gif'>");
		body = body.replace(/\[vazno\]/gi, "<img src='/slike/cgp-forum-19.gif'>");
		body = body.replace(/\[kostko\]/gi, "<img src='/slike/cgp-forum-20.gif'>")	;	
		body = body.replace(/\[bruh\]/gi, "<img src='/slike/cgp-forum-21.gif'>");
		body = body.replace(/\[jezik\]/gi, "<img src='/slike/cgp-forum-22.gif'>");
		body = body.replace(/\[krajcar\]/gi, "<img src='/slike/cgp-forum-23.gif'>");
		body = body.replace(/\[goldinar\]/gi, "<img src='/slike/cgp-forum-24.gif'>")	;		
		
		// mini zapis
		if ( $("#dnevnik").length > 0 ) {
			body = body.replace(/(\[mini\]Mini zapis ob)(.+?)(\[\/mini\])/g, ' <span class=\'mini\'><img src=\'/slike/th_mini.gif\'> Mini zapis ob$2</span> ');
		}
		
		// url povezave
		
		body = body.replace(/(\[url=)([^"]+?)(\])(.+?)(\[\/url\])/gi, ' <a target="_blank" href="$2">$4</a> ');		
		
		
		//body = body.replace(/(\s)(http.+?)(\s)/g, '\n<a target="_blank" href="$2">$2</a>\n' );
		body = body.replace(/(http[^"]+?)(\s)/g, '\n<a target="_blank" href="$1">$1</a>\n' );
		
		//url maili in povezave - stare
		body = body.replace(/(\[url:mailto:)([^"]+?)(\])/g, ' <a target="_blank" href="mailto:$2">$2</a>');
		body = body.replace(/(\[url:)([^"]+?)(\])/g, ' <a target="_blank" href="$2"> $2 </a>');
		
		// slike groznyjev dnevnik
		//body = body.replace(/(&lt;img\ssrc=")(.+?)("&gt;)/g, ' <a target="_blank" href="$2">poglej sliko</a>');
		
		
		// dolge besede
		body = splitLine2(body,30);
		
		//splitLine(body,20);
		return body + " &nbsp; ";
		
}




/* split long words 
************************/  
// Line Splitter Function // copyright Stephen Chapman, 19th April 2006
function splitLine2(st,n) {
	

	st+=" " // dodamo presledek, da ne preseka tagov na koncu
	var b = ''; 
	var s = st;
	i = 0;
	while (s.length > n) {
		var d = 0;
		var e=0;
		var c = '';
		var f = s.indexOf('>');
		if (f < s.indexOf(" ") && (f != -1)) {
			d=f;
			c = s.substring(0,d);
			b+=c.substring(0,d)+'>';
			s=s.substring(d+1);
		} else {
			c = s.substring(0,n)
			d = c.lastIndexOf(' ');
			e = c.lastIndexOf('\n');
			if (e != -1) d = e;
			if (d == -1) d = n;
			
			b+=c.substring(0,d)+' ';
			s=s.substring(d+1);
		}
		i++;
		if (i > 30) {
		}
	}
	return (b+s);

}


/* txt -> html
************************/  
function txt2html(body){
	
		// preden začnemo čarati, vse <br> spremenimo v \n, ostale \n pa pobrišimo
		body = body.replace(/\n/g, "");
		body = body.replace(/<BR>|<br>/g, "\n");
		
		body = body.replace(/&gt;/gi, ">");
		body = body.replace(/&lt;/gi, "<");
		body = body.replace(/&amp;/gi, "&");
		body = body.replace(/&quot;/gi, "\"");
		
		
		//body = body.replace(/(&)(\w+?)(;\s)/g, '&amp;$2$3'); // tale navaden & spremeni dvakrat, zato v naslednji vrstici to počistimo
		body = body.replace(/&amp;amp;/g, " &amp; ");  
		body = body.replace(/</gi, "&lt;");
		body = body.replace(/>/gi, "&gt;");

		body = body.replace(/(\s{0,}\n{1,}\s{0,}){2,}/g, " <br><br>");
		body = body.replace(/(\s{0,}\n{1,}\s{0,}){1,}/g, " <br>");
		//body = body.replace(/(\[URL=)(.+?["])(.+?)(\])(.+?)(\[\/URL\])/gi, '$5');
		return body;
}

/* html -> txt
************************/  
function html2txt(body){
		body = body.replace(/&amp;/g, "&");
		body = body.replace(/&lt;/g, "<");
		body = body.replace(/&gt;/g, ">");
		body = body.replace(/<br>/g, "\n");
		return body;
}

/* = Adding to favorites / deleting from favorites
************************/

// za forume
var fav_0=new Image();
var fav_1=new Image();
var fav_temp=new Image();
var fav_temp2=new Image();

fav_0.src="/slike/th_favorites00.gif";
fav_1.src="/slike/th_favorites01.gif";
fav_temp.src="/slike/th_favorite_ajax.gif";
fav_temp2.src="/slike/th_favorite_ajax2.gif";

// za dnevnike - dodaj med priljubljene
favD_1=new Image();
favD_1.src="/slike/dh_fav01.gif";

	
/* samo zamenja sliko - forumi */
function ajax2favorites (id){
	document['fav'+id].src= (fav_temp.src);
	$.ajax({
		type: "GET",
		url: "/moja/ajax2favorites.php",
		data: "id=" + id + "&type=1",
		success: function(msg){
			ajax2favoritesResponse(id, msg);
		}
	});
}

function ajax2favoritesResponse(id, status) {
	// zamenjaj samo sliko - forumi
	document['fav'+id].src= eval("fav_"+ status +".src");
}
	
/* zamenja tudi besedilo ob sliki, sklicuje se na span  - forumi*/
function ajax2favoritesBig (id){
	document['favImg'].src = (fav_temp2.src);
	document.getElementById("favText").innerHTML = "Počakaj par trenutkov...";
	
	$.ajax({
			type: "GET",
			url: "/moja/ajax2favorites.php",
			data: "id=" + id + "&type=1",
			success: function(msg){
				ajax2favoritesResponseBig(id, msg);
			}
	});
}

function ajax2favoritesResponseBig(id, status) {
	// zamenjaj samo sliko - forumi
	document['favImg'].src = eval("fav_"+ status +".src");
	if (status == 1) {
		document.getElementById("favText").innerHTML= "To je tvoja priljubljena tema. &nbsp; | &nbsp; <a href=javascript:ajax2favoritesBig("+ id +")>odstrani</a> &nbsp; | &nbsp; <a href='/moja/priljubljeni.php'>obišči priljubljene</a> ";
	}
	else {
		document.getElementById("favText").innerHTML= "Tema je izbrisana iz seznama priljubljenih. &nbsp; | &nbsp; <a href='javascript:ajax2favoritesBig("+ id +")'>dodaj nazaj med priljubljene</a>";
	}
}

/* dodaj med priljubljene - dnevniki */
function ajaxD2favorites (id, type){
	document['favDImg'].src= (favD_temp.src);
	$("#dnevnikToFavoritestext").html("Počakaj trenutek...");
	$.ajax({
		type: "GET",
		url: "/moja/ajax2favorites.php",
		data: "id=" + id + "&type=" + type,
		success: function(msg){
			$("#dnevnikToFavoritestext").html("To je <a href='/moja/priljubljeni.php'>tvoj priljubljen dnevnik</a>.");
			document['favDImg'].src= (favD_1.src);
		}
	});
}

/* glasuj za dnevnike */

function ajaxVote(target,rate, id, action){
		if ($("#"+target+"Active").css("display") != "none"){
			if (action==1) {
				$("#"+target+"Bottom").removeClass("starBottomNull").addClass("starBottom");
				$("#"+target+"Active").css("display","none");
				$("#"+target+"Text").html("Tvoja ocena:");
				
				// pokličemo ajax
				//url = "/dnevnik/ajaxGradeDiary.php?id=" + id + "&grade=" + grade;
				$.getJSON("/dnevnik/ajaxGradeDiary.php", 
					{"id": id, "rate": rate},
					function(json){
						if (json.nogo == 1) {
							nogo();
						} else {
   				 		$("#yRateNewVote").show();
   				 		w = json.avgGrade*82/5;
   				 		$("#avRateTop").width(w+"px");
   				 		$("#avRateNo").html("(" + json.noGrades + ")");
   				 	}
  				}
				);
			}
			$("#"+target+"Top").width(16.5*rate+"px");
		}
}

function resetAjaxVote(target){
	$("#"+target+"Bottom").removeClass("starBottom").addClass("starBottomNull");
	$("#"+target+"Active").css("display","block");
	$("#"+target+"Text").html("Tvoja ocena:");
	$("#"+target+"NewVote").css("display","none");
	$("#"+target+"Top").width("0px");
}

/* brisanje blogov */
function confirmBlogDelete(id, n) {
	msg = "Ali res želiš izbrisati ta vpis?";
	if (n > 0) msg+= "\nIzbrisani bodo tudi vsi komentarji tega zapisa!";
	
	if (confirm(msg)) {
		document.location="/moja/dnevnik.php?id_delete=" + id;
	}
}

function confirmHiddenBlogDelete(id) {
	msg = "Ali res želiš zapisati ta skriti zapis?";
	if (confirm(msg)) {
		document.location="/moja/dnevnik.php?id_hidden_delete=" + id;
	}
}

function confirmBlogCommentDelete(id,id_delete,k) {
	if (confirm("Ali res želiš izbrisati ta komentar?")) {
		document.location="/moja/dnevnik-podrob.php?id=" + id + "&id_delete=" + id_delete + "&k="+k;
	}
}

function reportAbuse(id, type){
	
	if ($("#abuseLink"+id).attr("class")=="tab") {
		$("#abuseLink"+id).html("zapusti prijavo zapisa").addClass("open");
			if (!$("#abuseLink"+id).parent().children().is("div")) {
				$("#abuseLink"+id).parent().append("<div class='consoleAbuseFrame' id='abuse" + id + "'><div class='consoleAbuseBody'></div></div>");
				$("#abuse" + id).slideDown("fast", function(){
					// hack, zato da naredimo notranji div prozoren in mu dodamo bg barvo
					$("#abuse" + id + ">div").fadeTo("fast", 0.01, function(){
						$("#abuse"+id + ">div").css({"background": "#015C98"});
					});
					$.ajax({
  						type: "GET",
  						url: "/moja/ajaxReportAbuse.php",
  						data: "id=" + "abuse"+id + "&type=" + type,
  						success: function(msg){
        				$("#abuse" + id + ">div").fadeTo("normal", 0.9999999999, function(){
        					$("#abuse" + id + ">div").html(msg);	
        				});
        				
  						}
					});
				});
			} else {
			$("#abuse" + id).slideDown("fast", function(){
				$("#abuse" + id + ">div").fadeTo("normal", 0.9999999999)
			});
		}
	} else {
		$("#abuse" + id + ">div").fadeTo("normal", 0.01, function(){
			$("#abuse" + id).slideUp("fast", function(){
				$("#abuseLink" + id).removeClass("open").html("(prijavi neprimeren zapis)");
			});
		});
	}
}

function praiseInput(id, type) {
	if ($("#praiseLink"+id).attr("class")=="pohvali") {
		$("#praiseLink"+id).addClass("open");
		if (!$("#praiseLink"+id).parent().next().is("div")) {
			$("#praiseLink"+id).parent().after("<div class='consolePraiseFrame' id='praise" + id + "'><div class='consolePraiseBody'></div></div>");
			$("#praise" + id).slideDown("fast", function(){
				// hack, zato da naredimo notranji div prozoren in mu dodamo bg barvo
				$("#praise" + id + ">div").fadeTo("fast", 0.01, function(){
						$("#praise" + id + ">div").css({"background": "#015C98"});
				});
				$.ajax({
  				type: "GET",
  				url: "/moja/ajaxVoteFor.php",
  				data: "id=" + id + "&type=" + type,
  				success: function(msg){  
      			$("#praise" + id + ">div").fadeTo("normal", 0.9999999999, function(){
      					$("#praise" + id + ">div").html(msg);
      			});
  				}
				});
			});
		} else {
			$("#praise" + id).slideDown("fast", function(){
				$("#praise" + id + ">div").fadeTo("normal", 0.9999999999)
			});
		}
	} else {
		$("#praise" + id + ">div").fadeTo("normal", 0.01, function(){
			$("#praise" + id).slideUp("fast", function(){
				$("#praiseLink" + id).removeClass("open");
			});
		});
	}
}

// glasuj za prispevek dneva - ajax - jSon
function praise(id, type) {
	document.getElementById("voteButton" + id).innerHTML = "";
	$.getJSON("/moja/ajaxVoteForReply.php", 
		{"id": id, "type": type},
		function(json){
			if (json.nogo == 1) {
				nogo();
			} else if (json.error == 1) {
				document.getElementById("voteButton" + id).className = "voteFinishedFalse";
				document.getElementById("voteButton" + id).innerHTML = "Pri glasovanju je prišlo do težave. Osveži stran in poskusi ponovno!";
			} else {
				document.getElementById("voteButton" + id).className = "voteFinishedOK";
				document.getElementById("voteButton" + id).innerHTML = json.text;
  	 	}
  	}
	);
}


// zasebna sporočila - pošlji na svoj email (aajx + jSon)
function posta2mail(idTopic) {
	if ($(".load").css("display")=="none") {
		$(".load").slideDown("normal", function(){
			$.getJSON("/moja/ajaxPosta2email.php", 
				{"id": idTopic},
				function(json){
					if (json.nogo == 1) {
						nogo();
					} else {
						$(".load").addClass("sent");
						$(".load").html("Sporočila smo poslali na naslov <strong>"+ json.email +"</strong>. Preden jih izbrišeš preveri, če so res prispela v tvoj poštni predal.");
  	 		 	}
  			}
			);
		});
	}
}

// zasebna sporočila - shrani nastavitve
function submitPmSettings() {
	for (i=0; i<=2; i++) {
		if (document.getElementById("opt"+i).checked) {
			opt = i;
		}
	}
	if ((document.getElementById('PMstatus').value <= 10) && (opt > 0)) {
		$("#divRedAlert").slideDown("fast");
	} else {
		document.getElementById('formSettings').submit();
	}
}


// dnevnik - shrani nastavitve
function preveriVnosDnevnikSet() {
  err = 0;
  errorMsg = "";
	title=document.getElementById("dnevnikTitle").value;

	// preveri, če je vnesen naslov
	if (trimTrailingSpaces(title).length == 0)	{
		errorMsg+= "<li>Naslov dnevnika ni vnesen. Prosim, vnesi naslov!</li>"
		err = 1;
	}

	// preveri, če so samo velike črke
	if (err ==0)	{
		if (!checkCaps(title)) {
			errorMsg+= "<li>V naslovu je preveč velikih črk! Zamenjaj velike črke z malimi.</li>";
			err = 1;
		}
	}
	
	// preveri, kateri status je izbral:
	for (i=0; i<=2; i++) {
		if (document.getElementById("opt"+i).checked) {
			opt = i;
		}
	}
	if ((document.getElementById('blogStatus').value <= 10) && (opt > 0)) {
			errorMsg+= "<li>Izbrana omejitev komentiranja je na voljo samo pravim vajencem in vajenkam. <a href='/register/'>Preveri, kako lahko napreduješ!</a></li>";
			err = 1;
	}

	
	if (err == 1) {     
		//document.getElementById("dnevnikTitle").focus();
		document.getElementById("errorReport").innerHTML=errorMsg;
		$("#divRedAlert").slideDown();
	}
	else {
		document.getElementById("blogSettings").submit();
	}
		
}

// prijatelji - odstrani iz seznama
function removeFriend(id, spol){
	
	if (spol==1) {
		cMessage="Želiš res izbrisati člana iz seznama?"
	} else {
		cMessage="Želiš res izbrisati članico iz seznama?"
	}
	if (confirm(cMessage)) { 
		$("#confirmBlock").fadeOut();
		if (document.getElementById("friends").rows.length == 2) {
				$("#friends").fadeOut("fast", function(){
					$("#noFriends").fadeIn();
					});
			}
		else {
			//$("#fr"+id+"/td").fadeTo("slow", 0.2, function(){
				$("#fr"+id).remove();
			//});
		}
		$.getJSON("ajaxDeleteFriend.php", 
			{"id": id});
	}
}


// prijatelji - odpri zaznamek
function friendAddNote(id){
	remark = ($("#remarkNote"+id).html() == null) ? "" : $("#remarkNote"+id).html();
	$("#remarkNote"+id).hide();
	
	$("#note"+id).fadeTo("fast", 0.1, function() {
		remark = html2txt(remark);
		$(this).html("<strong>Urejanje zaznamka:</strong>").fadeTo("fast", 0.999999999)
			.after("<p class='friendNote' id='edit" + id + "'><textarea id='remark" + id + "'>"+remark+"</textarea><span><a href='javascript: friendCancelNote("+id+")' class='button'>prekliči</a> <a href='javascript: friendSaveNote("+id+")' class='button'>shrani zaznamek</a></span></p>");
			$("#edit"+id).slideDown();
	});	
}

function friendCancelNote(id){
	$("#edit"+id).slideUp(function(){
		$(this).remove();
	});
	$("#note"+id).fadeTo("fast", 0.1, function() {
		if ($("#remarkNote"+id).html() == null) {
			$(this).html("Pri tem članu še nimaš vpisanega zaznamka. <a href='javascript: friendAddNote("+id+")'>Dodaj zaznamek!<a/>").fadeTo("fast", 0.999999999)
		} else {
			$(this).html("<strong>Tvoj zaznamek:</strong> (<a href='javascript:friendAddNote("+id+")'>uredi zaznamek</a>)").fadeTo("fast", 0.999999999, function(){
     		remark = txt2html(remark);
     				if ($("#remarkNote"+id).html() == null) {
     					$("#note"+id).after("<p id='remarkNote" + id + "'>"+remark+"</p>");
     				} else {
     					$("#remarkNote"+id).html(remark).fadeIn();
     				}
     		
     	});
		}
	});
}


function friendSaveNote(id){
	$("#edit"+id+"/span").html("<img src='/slike/ajax_loader_small.gif' width='16' height='16' class='alignMiddle' alt='počakaj trenutek'> trenutek, shranjujem zaznamek...");
	remark = document.getElementById("remark" + id).value;
	remark = trimTrailingSpaces(remark);
	remark = splitLine2(remark, 30);
	$.post("/moja/ajaxFriendsRemark.php",
   	{ id: id, remark: remark },
  	 function(response){
     	if (response=="0"){
				$("#edit"+id).fadeOut(function(){$(this).remove();});
     			$("#note"+id).css("display","none").html("Pri tem članu še nimaš vpisanega zaznamka. <a href='javascript: friendAddNote("+id+")'>Dodaj zaznamek!</a>").fadeIn();
					$("#remarkNote"+id).remove();
     	} else {
				$("#edit"+id).fadeOut(function(){$(this).remove();}); 
          $("#note"+id).fadeTo("fast", 0.1, function() {
     			$("#note"+id).html("<strong>Tvoj zaznamek:</strong> (<a href='javascript:friendAddNote("+id+")'>uredi zaznamek</a>)").fadeTo("fast", 0.999999999, function(){
     			remark = txt2html(remark);
     				if ($("#remarkNote"+id).html() == null) {
     					$("#note"+id).after("<p id='remarkNote" + id + "'>"+remark+"</p>");
     				} else {
     					$("#remarkNote"+id).html(remark).fadeIn();
     				}
     			});
				});
     	}
		}
	);
}


// povabi na čvek konzola- spet nova funkcija
function inviteChat3(id, margin, myStatus, otherStatus) {
	
	if ($("#chat"+id).html() == null) {
		cText = "<br><ul class='chatConsole3' id='chat"+id+"'>";
		cText+= "<li><a href='" + ((myStatus==0) ? "/nogo.php" : "/metro/index.php?id="+id+"&where=1" ) + "' class='chatIco1'>Povabi na pločnik</a></li>";
		cText+= (otherStatus<10) ? "<li><span class='chatIco3p'>Povabi v kavarno</span></li>" :  "<li><a href='" + ((myStatus==0) ? "/nogo.php" : "/metro/index.php?id="+id+"&where=3" ) + "' class='chatIco3'>Povabi v kavarno</a></li>";
		cText+= (otherStatus<10) ? "<li><span class='chatIco2p'>Povabi na burek</span></li>" :  "<li><a href='" + ((myStatus==0) ? "/nogo.php" : "/metro/index.php?id="+id+"&where=2" ) + "' class='chatIco2'>Povabi na burek</a></li>";
		cText+= (otherStatus<10) ? "<li><span class='chatIco4p'>Izzovi na bitko</span></li>" :  "<li><a href='" + ((myStatus==0) ? "/nogo.php" : "/metro/index.php?id="+id+"&where=4" ) + "' class='chatIco4'>Izzovi na bitko!</a></li>";

		/*
		cText+= (otherStatus<10) ? "<li><span class='chatIco4'>Povabi na igrišče</span></li>" :  "<li><a href='" + ((myStatus==0) ? "/nogo.php" : "/metro/index.php" ) + "' class='chatIco2'>Povabi na igrišče</a></li>";
		cText+= (otherStatus<10) ? "<li><span class='chatIco5'>Povabi v nočni bar</span></li>" :  "<li><a href='" + ((myStatus==0) ? "/nogo.php" : "/index.php" ) + "' class='chatIco3'>Povabi v nočni bar</a></li>";
		*/
		cText+= "</ul>";
		$("#ahref"+id).after(cText);
	}
	if ($("#chat"+id).css("display")=="none") {
		$("#chat"+id).css("margin-left", margin+"em");
		$("#chat"+id).slideDown("fast");
	}
}
//$(document).ready(function(){
$.elementReady('fMojavajaContent', function() {
	$("body").click(function(){
		$(".chatConsole3:visible").slideUp("fast");
	})
});

/* nova poznanstva */
function set_counter() {
	max = 240;
	document.getElementById("counter").innerHTML = max - document.getElementById("oglas").value.length;
	if (document.getElementById("counter").innerHTML < 0)
   {
    document.getElementById("oglas").value = document.getElementById("oglas").value.substring(0,max);
    alert("Doseženo je maksimalno število znakov");
    document.getElementById("counter").innerHTML =  max - document.getElementById("oglas").value.length;
  } 
}

function preveriVnosOglas() {
	error = 0;
	if (!(checkCheckbox("c1") || checkCheckbox("c2") || checkCheckbox("c3") ||checkCheckbox("c4")   )) {
		alert ("Izberi vsaj eno možnost, ki jo želiš početi s prijatelji na vijavaji!");
		error = 1;
	}
	if (error == 0 && trimTrailingSpaces(document.getElementById("oglas").value).length == 0) {
		alert ("Prosim, vpiši oglas!");
		error = 1;
	}
	
	if (error == 0 && document.getElementById("omrSkup").value == 0) {
		alert ("Prosim, izberi kraj, iz katerega prihajaš!	");
		error = 1;
	}
	if (error == 0) {
		document.getElementById("mainForm").submit();
	}
}

function preveriEditGuestBook() {
	error = 0;
	if (error == 0 && trimTrailingSpaces(document.getElementById("oglas").value).length == 0) {
		alert ("Prosim, vpiši vsaj nekaj besed!!!");
		error = 1;
	}
	if (error == 0) {
		document.getElementById("mainForm").submit();
	}
}


 $(document).ready(function(){
   $("#sj2009").click(function(event){
    
   cc = $("#sj2009txt").val();
   if (cc == "") {
   	alert ("prosim, prepiši številko v bel okvirček!");	
   } else {
   	window.location=$("#sj2009").attr("href") + "&cc=" + cc;
   } 
   return false; 
   });
 });



function showFav(id) {
	$("#blog"+id).hide();
	$("#load"+id).addClass("loading").html("počakaj trenutek...");
			$.getJSON("/moja/ajaxShowNewDiary.php", 
				{"id": id},
				function(json){
					if (json.nogo == 1) {
						nogo();
					} else if (json.noNew == 1) {
						list = "<ul class='noDisplay'>";
							list+="<li>ni novih zapisov</li>";
							list+="</ul>"
							$("#load"+id).hide().after(list);
							$("#load"+id + " + ul").slideDown("fast");
					} else {
						list = "<ul class='noDisplay'>";
						// izpiši UL od seznama
						for (i=0; i<json.list.length; i++) {
							list+="<li><a href='/imenik/podrob_dnevnik_komentarji.php?id="+ json.list[i].id +"'>" + json.list[i].value + "</a></li>";
						}
						list+="</ul>";
						$("#load"+id).hide().after(list);
						$("#load"+id + " + ul").slideDown("fast");
  				}	
  			}
			);
}


/* knjiga gostov */
function confirmGuestBook (id) {
	$("#guest"+id).removeClass("bg03").addClass("bg01");
	
	$("#gostiAbuse_" +id+ "head").html("&nbsp;").removeClass("warning");
	
	
	$("#nepotrjen"+id).after("&nbsp;").remove();
	$("#aConfirm"+id).remove();
	if ($(".bg03").get().length==0) {
		$("#knjigaGostovUnconfirmed").slideUp();
	}
	$.getJSON("/moja/ajaxConfirmGuestBook.php", 
			{"id": id, "action": 1},
			function(json){
				if (json.response=="ok0") {
					$("#alertGuestBook").remove();
				}
			}
	);
}

function deleteGuestBook (id) {
	if (confirm ("Ali res želiš izbrisati ta vpis v knjigo gostov?")) {
		$("#guest"+id).remove();
		$.getJSON("/moja/ajaxConfirmGuestBook.php", 
			{"id": id, "action": 0},
			function(json){
				if (json.response=="ok0") {
					$("#alertGuestBook").remove();
				}
			}
		);
			
		if (document.getElementById("guestBook").rows.length == 0) {
			$("#knjigaGostovEmpty").fadeIn();
		}
		if ($(".bg03").get().length==0) {
			$("#knjigaGostovUnconfirmed:visible").slideUp();
		}
		
		
	}
}

/* dogajase */
function pofockajOut(id) {
	if (confirm("Želiš res preklicati svojo udeležbo na tem dogodku?")) {
		$("#pofockan"+id).slideUp("fast", function(){
			$(this).remove();
			
			$.getJSON("/moja/ajaxRemovePofockan.php", 
						{"idDogodek": id}
			);
			
			
			n=$("#pofList/li").get().length;
			if (n==0) {
				$("#pofFrame").slideUp();
			} else {
				switch(n){
					case 1:
  					$("#pofTitle/span").html("en dogodek");
  					break;
					case 2:
  					$("#pofTitle/span").html("dva dogodka");
  					break;
					case 3:
  					$("#pofTitle/span").html("tri dogodke");
  					break;
					case 4:
  					$("#pofTitle/span").html("štiri dogodke");
  					break;
					default:
  					$("#pofTitle/span").html(n + " dogodkov");
  					break;
				}
			}
			if (confirm("Do drugih članov bi bilo pošteno, da tudi na forumu dogodka objaviš, da te ne bo in zakaj odpoveduješ. \rŽeliš skočiti na forum?")) {
				window.location="/forum/forum_izpis_teme.php?id=32";
			}
			
			
		});
	}
}

/* /* racun */
function explainRacun(id){
		$("#racun"+id+":hidden").fadeIn("normal");
} 

/* odstrani iz seznama blokiranih */
function removeBlock(id, spol){
	if (spol==1) {
		cMessage="Želiš res izbrisati člana iz seznama blokiranih?"
	} else {
		cMessage="Želiš res izbrisati članico iz seznama blokiranih?"
	}
	if (confirm(cMessage)) {
		$("#fr"+id).remove();
		$.getJSON("ajaxDeleteBlock.php", 
					{"id": id});
	}
	if (document.getElementById("block").rows.length == 1) {
		$("#block").remove();
		$("#noBlock").fadeIn();
	}
}

/* kazen */
function explainKazen(id){
		$("#explain"+id+":hidden").fadeIn("normal");
}

/* podrob - prikaz forumov posameznega člana */
function showMemberForum(id) {
	
	if (document.getElementById(id+"more").style.display=="block") {
		hideMemberForum();
	}else {
		hideMemberForum();
		$("#"+id+"more").slideDown();
		$("#"+id).addClass("active");
	}

}
function hideMemberForum() {
	$(".memberPost:visible").slideUp();
	$(".active").removeClass("active")
}

// auto complete - 

function autoComplete(id, url) {
	if (($("#"+id).val()).length > 1) {   
		match = $("#"+id).val()
		$.getJSON(url, 
			{"match": match},
			function(json){
					$(".autofill:visible").remove();
					if (json.match.length > 0 ) {
						dDownMenu = "<div class='autofill' id='dDown"+ id +"'><ul>";
						for (i=0; i<json.match.length; i++) {
							
							hash = (json.match[i].val.replace(/ /g, "%20"));
							hash = (hash.replace(/'/g, "%*27"));
							hash = (hash.replace(/´/g, "%*27"));
							
							
							dDownMenu+="<li><a href=javascript:autoCompleteSel('" + hash +"','"+ id +"')>" + json.match[i].val + "</a></li>";
						}
						dDownMenu+="</ul></div>";
						$("#"+id).after(dDownMenu);
						if (json.match.length > 8) {
							$("#dDown"+id).height("13em");
						}
					}
					else {
						$(".autofill:visible").remove();
					}
  		}
		);
	} else {
		$(".autofill:visible").remove();
	}
}


function autoCompleteSel(match, id) {
	match = (match.replace(/\%\*27/g, "'"));
	hash = (hash.replace(/\%\*27/g, "'"));
	$("#"+id).val(match); 
	$(".autofill:visible").remove();
}

// funkcija za preverjanje ustreznosti referenduma (vnos novega referenduma):

function submitPoll() {
	error = 0;

	if (trimTrailingSpaces( $("#question").val()).length < 3)	{
		error = 1;
		alert ("Prosim, vnesi referendumsko vprašanje!");
	}
	if (error == 0) {
		optCount = 0;
		for (i=1; i<=6; i++) {
			if (trimTrailingSpaces($("#formOpt"+i).val()).length > 0) {
				optCount++;
			}
		}
		if (optCount < 3) {
			error = 1;
			alert ("Prosim, vnesi vsaj tri možne odgovore!");
		}
	}
	
	if (error == 0) {
		document.getElementById("pollForm").submit();
	}
}