$(document).ready(function() {
	date = new Date();									//create new date object
	//$("a.image_handle").lightBox();						//light box 
	$("a.image_handle").click(function(e) {
		e.preventDefault();
		var rel = $(this).attr("rel");
		$("a[rel="+rel+"]").lightBox();
		$(this).trigger("click");
	});
	$("a.image_handle_nagradna").lightBox();			//light box 
	//initialize date selector
	$('.oddaja_date_range_id').datepicker({rangeSelect: true, firstDay: 1, minDate: new Date(date.getFullYear() , 0, 1), maxDate: new Date(date.getFullYear()+1 , 11, 31) });
	
	rangeElementEvent();
	
	//	CYCLE IMAGE
	
	$('#oglas_slika_box').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 4000, 
		pager:  '#slika_nav' 
	});
	$('#novost_slika_box').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 4000, 
		pager:  '#slika_nav' 
	});
	$('.desno_slika_box').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 4000
		//pager:  '#slika_nav' 
	});
	for(i=1; i<=10; i++)
	{
		if($('#oddaja_slika_box_'+i).html != "")
		{
			$('#oddaja_slika_box_'+i).cycle({ 
				fx:     'fade', 
				speed:  'slow', 
				timeout: 4000, 
				pager:  '#slika_nav_'+i 
			});	
		}
		if($('#prodaja_slika_box_'+i).html != "")
		{
			$('#prodaja_slika_box_'+i).cycle({ 
				fx:     'fade', 
				speed:  'slow', 
				timeout: 4000, 
				pager:  '#slika_nav_'+i 
			});
		}
	}
	$('#servisi_slika_box').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 4000, 
		pager:  '#slika_nav' 
	});
	
	
	//	CLEARING FIELDS ON KEYUP
	
	$("#oglas_naslov_id").focus(function() {
		if($("#oglas_naslov_id").attr("value") == "Polje ne sme biti prazno!")
			$("#oglas_naslov_id").css("color", "black").attr("value", "");
	});
	$("#oglas_vsebina_id").focus(function() {
		if($("#oglas_vsebina_id").attr("value") == "Polje ne sme biti prazno!")
			$("#oglas_vsebina_id").css("color", "black").attr("value", "");
	});
	$("#oglas_kontakt_id").focus(function() {
		if($("#oglas_kontakt_id").attr("value") == "Polje ne sme biti prazno!")
			$("#oglas_kontakt_id").css("color", "black").attr("value", "");
	});
	$("#oglas_cena_id").focus(function() {
		if($("#oglas_cena_id").attr("value") == "Polje ne sme biti prazno!" || $("#oglas_cena_id").attr("value") == "To, kar ste vpisali, ni številka!")
			$("#oglas_cena_id").css("color", "black").attr("value", "");
	});
	
	$("#myprofile_geslo2").keyup(function() {
		$("#myprofile_geslo2_msg").html("");
	});
	
	$(".prodaja_naslov_class").focus(function() {
		if($(this).attr("value") == "Polje ne sme biti prazno!")
			$(this).css("color", "black").attr("value", "");
	});
	$(".prodaja_vsebina_class").focus(function() {
		if($(this).attr("value") == "Polje ne sme biti prazno!")
			$(this).css("color", "black").attr("value", "");
	});
	$(".prodaja_cena_class").focus(function() {
		if($(this).attr("value") == "Polje ne sme biti prazno!" || $(this).attr("value") == "To, kar ste vpisali, ni številka!")
			$(this).css("color", "black").attr("value", "");
	});
	
	$(".oddaja_naslov_class").focus(function() {
		if($(this).attr("value") == "Polje ne sme biti prazno!")
			$(this).css("color", "black").attr("value", "");
	});
	$(".oddaja_vsebina_class").focus(function() {
		if($(this).attr("value") == "Polje ne sme biti prazno!")
		$(this).css("color", "black").attr("value", "");
	});
	$(".oddaja_cena_class").focus(function() {
		if($(this).attr("value") == "Polje ne sme biti prazno!" || $(this).attr("value") == "To, kar ste vpisali, ni številka!")
			$(this).css("color", "black").attr("value", "");
	});
	$(".oddaja_date_range_id").focus(function() {
		$(this).css("color", "black").attr("value", "");
	});
	
	$("#servisi_naslov_id").focus(function() {
		if($("#servisi_naslov_id").attr("value") == "Polje ne sme biti prazno!")
			$("#servisi_naslov_id").css("color", "black").attr("value", "");
	});
	$("#servisi_opis_id").focus(function() {
		if($("#servisi_opis_id").attr("value") == "Polje ne sme biti prazno!")
			$("#servisi_opis_id").css("color", "black").attr("value", "");
	});
	$("#servisi_kontakt_id").focus(function() {
		if($("#servisi_kontakt_id").attr("value") == "Polje ne sme biti prazno!")
			$("#servisi_kontakt_id").css("color", "black").attr("value", "");
	});
	
	$("#geslo_username_id").focus(function() {
		if($("#geslo_username_id").attr("value") == "Polje ne sme biti prazno!")
			$("#geslo_username_id").css("color", "black").attr("value", "");
	});
	$("#geslo_email_id").focus(function() {
		if($("#geslo_email_id").attr("value") == "Polje ne sme biti prazno!")
			$("#geslo_email_id").css("color", "black").attr("value", "");
	});
	
	
	//	CUSTOM CODE
	
	
	//takrat ko klikneš dodaj obdobje
	$(".add_range").click(function() {
		id = $(this).attr("id");
		if(id != "")
		{
			id_array = id.split("_");
			id = "_"+id_array[1];
		}
		else
			id = "";
		
		range = $("#oddaja_range_input"+id).attr("value");
		if(range.indexOf("-") >= 0)
			isDate = true;
		else
			isDate = false;
		if(isDate)
		{
			var box = trim($("#oddaja_ranges_box"+id).html());
			box = box + "<div><b>" + range + "</b> <span class='range_element' title='Izbriši obdobje'>X</span></div>";
			while(box.indexOf("\n") != -1)
			{
				box = box.replace("\n", "");
			}
			while(box.indexOf("\r") != -1)
			{
				box = box.replace("\r", "");
			}
			box = box.toLowerCase();
			$("#oddaja_range_input"+id).attr("value", "Kliknite tu, za izbiro obdobja.");
			$("#oddaja_ranges_box"+id).html(box);
			$("#oddaja_obdobja_id"+id).attr("value", box);
			rangeElementEvent();	//listener za klik
		}
		else
		{	
			$("#oddaja_range_input"+id).attr("value", "Kliknite tu, za izbiro obdobja.");
		}
	});
	
	$(".clear_last_range").click(function() {
		id = $(this).attr("id");
		if(id != "")
		{
			id_array = id.split("_");
			id = "_"+id_array[1];
		}
		else
			id = "";								  
										  
		var box = $("#oddaja_ranges_box"+id).html();
		while(box.indexOf("\n") != -1)
		{
			box = box.replace("\n", "");
		}
		while(box.indexOf("\r") != -1)
		{
			box = box.replace("\r", "");
		}
		box = box.toLowerCase();
		
		box = box.substr(5);
		box = box.substr(0, box.length-6);
		box_array = box.split("</div><div>");
		var new_box = "";
		for(i=0; i<box_array.length-1; i++)
			new_box += "<div>" + box_array[i] + "</div>";
		$("#oddaja_date_range_id").attr("value", "Kliknite tu, za izbiro obdobja.");
		$("#oddaja_ranges_box"+id).html(new_box);
		$("#oddaja_obdobja_id"+id).attr("value", new_box);						 
	})
	
	//počisti ranges box
	$(".clear_range").click(function() {
		id = $(this).attr("id");
		if(id != "")
		{
			id_array = id.split("_");
			id = "_"+id_array[1];
		}
		else
			id = "";
		$("#oddaja_ranges_box"+id).html("");
		$("#oddaja_obdobja_id"+id).attr("value", "");
	});
	
	//neki pri registraciji
	$("#register_pogoji").click(function() {
		if($("#register_pogoji").attr("checked"))
			$("#register_pogoji_msg").html("");
	});
	$(".obvezen").keyup(function() {
		id = "#" + $(this).attr("name") + "_msg";
		$(id).html("");
	});
	
	//menja vsebino pri myprofile
	$(".myprofile_gumb").click(function() {
		id = $(this).attr("id");
		id_array = id.split("_");
		id_new = id_array[0]+"_"+id_array[1]+"_box";
		
		if(id_new == "myprofile_profil_box")
			window.location = "myprofile/?tab=1";
		else if(id_new == "myprofile_podjetje_box")
			window.location = "myprofile/?tab=2";
		else if(id_new == "myprofile_vsebine_box")
			window.location = "myprofile/?tab=3";
		
		/*if($("#myprofile_profil_box").is(":visible") && id != "myprofile_profil_gumb")
		{
			$("#myprofile_profil_gumb").removeClass("active");
			$("#myprofile_profil_box").fadeOut(400, function() {
				$("#"+id_new).fadeIn(400);	
				$("#"+id).addClass("active");
			});
		}
			
		if($("#myprofile_podjetje_box").is(":visible") && id != "myprofile_podjetje_gumb")
		{
			$("#myprofile_podjetje_gumb").removeClass("active");
			$("#myprofile_podjetje_box").fadeOut(400, function() {
				$("#"+id_new).fadeIn(400);
				$("#"+id).addClass("active");
			});
		}
			
		if($("#myprofile_vsebine_box").is(":visible") && id != "myprofile_vsebine_gumb")
		{
			$("#myprofile_vsebine_gumb").removeClass("active");
			$("#myprofile_vsebine_box").fadeOut(400, function() {
				$("#"+id_new).fadeIn(400);
				$("#"+id).addClass("active");
			});
		}*/
	});
	
	//menjanje vsebine za myprofile/moje vsebine
	$(".vsebine_meni").click(function() {
		id = $(this).attr("id");
		id_array = id.split("_");
		id_new = id_array[0]+"_"+id_array[1]+"_box";
		
		if($("#vsebine_prodaja_box").is(":visible") && id != "vsebine_prodaja_gumb")
		{
			$("#vsebine_prodaja_gumb").removeClass("active");
			$("#vsebine_prodaja_box").fadeOut(400, function() {
				$("#"+id_new).fadeIn(400);	
				$("#"+id).addClass("active");
			});
		}
			
		if($("#vsebine_oddaja_box").is(":visible") && id != "vsebine_oddaja_gumb")
		{
			$("#vsebine_oddaja_gumb").removeClass("active");
			$("#vsebine_oddaja_box").fadeOut(400, function() {
				$("#"+id_new).fadeIn(400);	
				$("#"+id).addClass("active");
			});
		}
			
		if($("#vsebine_storitve_box").is(":visible") && id != "vsebine_storitve_gumb")
		{
			$("#vsebine_storitve_gumb").removeClass("active");
			$("#vsebine_storitve_box").fadeOut(400, function() {
				$("#"+id_new).fadeIn(400);	
				$("#"+id).addClass("active");
			});
		}
			
		if($("#vsebine_oglasi_box").is(":visible") && id != "vsebine_oglasi_gumb")
		{
			$("#vsebine_oglasi_gumb").removeClass("active");
			$("#vsebine_oglasi_box").fadeOut(400, function() {
				$("#"+id_new).fadeIn(400);	
				$("#"+id).addClass("active");
			});
		}
	});
	
	//podčrtavanje submenija pri myprofile/moje vsebine
	$(".vsebine_meni").hover(function() {
		$(this).css("text-decoration", "underline");								 
	}, function() {
		$(this).css("text-decoration", "none");
	});
	
	//podčrtavanje menija pri myprofile
	$(".myprofile_gumb").hover(function() {
		$(this).css("text-decoration", "underline");								 
	}, function() {
		$(this).css("text-decoration", "none");
	});
	
	//dodajanje slike pri malih oglasih
	$(".oglas_dodaj_sliko").click(function() {
		id = $(this).attr("id");
		if(id != "")
			id = "_"+id;

		object = $(".oglas_slika"+id+":visible").next();
		object.show("slow");
		
		array = $(".oglas_slika"+id+":hidden").get();
		if(array.length == 0)
			$(this).hide("slow");
	});
	
	//če klikneš na link za kontakt pri podjetju - v kategoriji oddaja
	$(".oddaja_kontakt").click(function(e) {
		id = $(this).attr("id");
		id_array = id.split("_");
		id = id_array[2];
		
		if(!$("#oddaja_kontakt_box_"+id).is(":visible"))
			$("#oddaja_kontakt_box_"+id).slideDown("slow");
		else
			$("#oddaja_kontakt_box_"+id).slideUp("slow");
		
		return false;
	});
	//to pa če klikneš na zapri v boxu kontakt - pri oddaji
	$(".oddaja_kontakt_zapri").click(function() {
		id = $(this).attr("id");
		id_array = id.split("_");
		id = id_array[3];
		
		$("#oddaja_kontakt_box_"+id).slideUp("slow");
		return false;
	});
	
	//če klikneš na link za tehnične lastnosti pri podjetju - v kategoriji oddaja
	$(".tehnicne_last").click(function() {
		id = $(this).attr("id");
		id_array = id.split("_");
		id = id_array[2];
		
		if(!$("#tehnicne_last_box_"+id).is(":visible"))
			$("#tehnicne_last_box_"+id).slideDown("slow");
		else
			$("#tehnicne_last_box_"+id).slideUp("slow");
		
		return false;
	});
	//to pa če klikneš na zapri v boxu kontakt - pri oddaji
	$(".tehnicne_last_zapri").click(function() {
		id = $(this).attr("id");
		id_array = id.split("_");
		id = id_array[3];
		
		$("#tehnicne_last_box_"+id).slideUp("slow");
		return false;
	});
	
	arraydates = new Array(100);
	for(var i=1; i<=10; i++)
	{
		obdobja = $('#prikaz_obdobij_data_'+i).html();
		today = new Date();
		var today_text = today.getDate()+"."+(today.getMonth()+2)+"."+today.getFullYear();
		newDate = new Date();

		//day_count = 0;
		if(obdobja != null)
		{
			obdobja = trim(obdobja);
			var obdobja_array = obdobja.split("@");
			arraydates[i] = new Array(obdobja_array.length+10);
			for(j=0; j<obdobja_array.length; j++)
			{
				newDate.setTime(obdobja_array[j]);
				arraydates[i][j] = newDate.getTime();
			}
			
			$('#prikaz_obdobij_'+i).DatePicker({
				flat: true,
				date: today_text,
				current: today_text,
				format: 'd.m.Y',
				enumerate: i,
				calendars: 2,
				mode: 'multiple',
				onRender: function(date) {
					id = $(this).attr("id");
					id_array = id.split("_");
					id = id_array[1];
					return {
						disabled: true,
						className: arraydates[id]
					}
				},
				starts: 1
			});
		}
	}
	
	//hovering za vprašanja
	$(".vprasanje").hover(function() {
		$(this).css("text-decoration", "underline");						  
	}, function() {
		$(this).css("text-decoration", "none");
	});
	
	//ko klikneš na eno vprašanje
	$(".vprasanje").click(function() {
		if($(this).next("div").is(":visible"))
			$(this).next("div").slideUp("fast");
		else
		{
			$(".odgovor").slideUp("fast");
			$(this).next("div:hidden").slideDown("");
		}
	});
	
	//ko klikneš na naslov malega oglasa pri urejanju
	$(".vsebine_oglas_header").click(function() {
		if($(this).next("div").is(":visible"))
			$(this).next("div").slideUp("fast");
		else
		{
			$(".vsebine_oglas_box").slideUp("fast");
			$(this).next("div:hidden").slideDown("");
		}
	});
	//hovering za naslove malega oglasa pri urejanju
	$(".vsebine_oglas_header").hover(function() {
		$(this).css("text-decoration", "underline");						  
	}, function() {
		$(this).css("text-decoration", "none");
	});
	
	
	//menjava malih oglasov na začetni strani
	$(".index_mali_kat").click(function(e) {
		e.preventDefault();
		id = $(this).attr("id");
		id_array = id.split("_");
		id = id_array[id_array.length-1];
		
		$(".oglas-en:visible").hide();
		$(".index_oglas_"+id).show();									   
	});
	
	//menjavanje ostalih vsebin na začetni strani
	$(".index_ostalo_kat").click(function(e) {
		e.preventDefault();
		id = $(this).attr("id");
		id_array = id.split("_");
		id = id_array[id_array.length-1];
		
		$(".index_ostalo_kat").removeClass("active");
		$(this).addClass("active");
		
		$(".vsebina-en:visible").hide();
		$(".index_ostalo_vsebina_"+id).show();	
	});
});

//funkcija, ki jo kličeš takrat, ko dodaš neko obdobje - zato da zazna klik na križec
function rangeElementEvent()
{
	$(".range_element").click(function() {
		var object = $(this).parent().parent();
		var id = object.attr("id");
		var id_array = id.split("_");
		var id_nr = "";
		if(id_array.length == 4)
			id_nr = "_"+id_array[id_array.length-1];
		else 
			id_nr = "";

		$(this).parent().remove();
		var box = object.html();
		
		while(box.indexOf("\n") != -1)
		{
			box = box.replace("\n", "");
		}
		while(box.indexOf("\r") != -1)
		{
			box = box.replace("\r", "");
		}
		box = box.toLowerCase();
		
		$("#oddaja_obdobja_id"+id_nr).attr("value", box);
	});
}


//	FORM VALIDATION


//MALI OGLASI
function validateOglasForm(form)
{
	ok = true;
	if($("#oglas_naslov_id").attr("value") == "" || $("#oglas_naslov_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#oglas_naslov_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#oglas_vsebina_id").attr("value") == "" || $("#oglas_vsebina_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#oglas_vsebina_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#oglas_kontakt_id").attr("value") == "" || $("#oglas_kontakt_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#oglas_kontakt_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#oglas_cena_id").attr("value") == "" || $("#oglas_cena_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#oglas_cena_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	else
	{
		number = $("#oglas_cena_id").attr("value");
		result = formatNumber(number);
		
		if(result < 0)
		{
			ok = false;
			$("#oglas_cena_id").css("color", "red").attr("value", "To, kar ste vpisali, ni številka!");
		}
		else
		{
			$("#oglas_cena_id").attr("value", result);
		}
	}
	
	return ok;
}

function validateOglasDelete()
{
	return confirm("Resnično želite izbrisati ta oglas?");	
}

//MY PROFILE
function validateMyprofileForm()
{
	ok = true;
	
	if($("#myprofile_geslo").attr("value") != "" || $("#myprofile_geslo2").attr("value") != "")
		if($("#myprofile_geslo").attr("value") != $("#myprofile_geslo2").attr("value"))
		{
			$("#myprofile_geslo2_msg").html("* Gesli se morata ujemati!");
			ok = false;
		}
		
	if(ok)
		document.form_myprofile.submit();
}

//PRODAJA
function validateProdajaForm(id)
{
	if(id == -1)
		index = "";
	else
		index = "_"+id;
	
	ok = true;
	
	if($("#prodaja_naslov_id"+index).attr("value") == "" || $("#prodaja_naslov_id"+index).attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#prodaja_naslov_id"+index).css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#prodaja_vsebina_id"+index).attr("value") == "" || $("#prodaja_vsebina_id"+index).attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#prodaja_vsebina_id"+index).css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#prodaja_cena_id"+index).attr("value") == "" || $("#prodaja_cena_id"+index).attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#prodaja_cena_id"+index).css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	else
	{
		number = $("#prodaja_cena_id"+index).attr("value");
		result = formatNumber(number);
		
		if(result < 0)
		{
			ok = false;
			$("#prodaja_cena_id"+index).css("color", "red").attr("value", "To, kar ste vpisali, ni številka!");
		}
		else
		{
			$("#prodaja_cena_id"+index).attr("value", result);
		}
	}

	return ok;
}

function validateProdajaDelete()
{
	return confirm("Resnično želite izbrisati ta avtodom?");	
}

//ODDAJA
function validateOddajaForm(id)
{
	if(id == -1)
		index = "";
	else
		index = "_"+id;
	
	ok = true;
	
	if($("#oddaja_naslov_id"+index).attr("value") == "" || $("#oddaja_naslov_id"+index).attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#oddaja_naslov_id"+index).css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#oddaja_vsebina_id"+index).attr("value") == "" || $("#oddaja_vsebina_id"+index).attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#oddaja_vsebina_id"+index).css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#oddaja_obdobja_id"+index).attr("value") == "")
	{
		ok = false;
		$("#oddaja_range_input"+index).css("color", "red").attr("value", "Dodati morate obdobja!");
	}
	if($("#oddaja_cena_id"+index).attr("value") == "" || $("#oddaja_cena_id"+index).attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#oddaja_cena_id"+index).css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	else
	{
		number = $("#oddaja_cena_id"+index).attr("value");
		result = formatNumber(number);
		
		if(result < 0)
		{
			ok = false;
			$("#oddaja_cena_id"+index).css("color", "red").attr("value", "To, kar ste vpisali, ni številka!");
		}
		else
		{
			$("#oddaja_cena_id"+index).attr("value", result);
		}
	}

	return ok;
}

function validateOddajaDelete()
{
	return confirm("Resnično želite izbrisati ta avtodom?");	
}


//REGISTER
function validateRegisterForm()
{
	geslo1 = "";
	geslo2 = "";
	
	ok = true
	array = $(".obvezen").get();
	for(i=0; i<array.length; i++)
	{
		id = "#" + array[i].name + "_msg";
		if(array[i].value == "")
		{
			ok = false;
			$(id).html("* Vpišite podatek!");
		}
		else if(array[i].name == "register_geslo")
			geslo1 = array[i].value;
		else if(array[i].name == "register_geslo2")
			geslo2 = array[i].value;
	}
	
	if(geslo1 != "" && geslo2 != "")
		if(geslo1 != geslo2)
		{
			$("#register_geslo2_msg").html("* Gesli se morata ujemati!");
			ok = false;
		}
		
	if(!$("#register_pogoji").attr("checked"))
	{
		ok = false;
		$("#register_pogoji_msg").html("* Morate se strinjati!");
	}
	
	if(ok)
	{
		document.form_register.submit();
	}	
}

//SERVISI IN STORITVE
function validateServisiForm()
{
	ok = true;
	
	if($("#servisi_naslov_id").attr("value") == "" || $("#servisi_naslov_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#servisi_naslov_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#servisi_opis_id").attr("value") == "" || $("#servisi_opis_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#servisi_opis_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	if($("#servisi_kontakt_id").attr("value") == "" || $("#servisi_kontakt_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#servisi_kontakt_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}

	return ok;
}

function validateStoritevDelete()
{
	return confirm("Resnično želite izbrisati to vsebino?");	
}

function validatePozabljenoGesloForm()
{
	ok = true;
	
	/*if($("#geslo_username_id").attr("value") == "" || $("#geslo_username_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#geslo_username_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}*/
	if($("#geslo_email_id").attr("value") == "" || $("#geslo_email_id").attr("value") == "Polje ne sme biti prazno!")
	{
		ok = false;
		$("#geslo_email_id").css("color", "red").attr("value", "Polje ne sme biti prazno!");
	}
	
	return ok;
}


//	SPLOŠNE FUNKCIJE


//sproži event - isto kot če bi na eno sliko kliknu
function prikaziSliko(index)
{
	$('#image_handle'+index).trigger("click");
}

//formatira številko glede na to, kakšen format podamo
function formatNumber(number)
{
	imaVejico = number.indexOf(",");
	imaPiko = number.indexOf(".");
	
	if(imaVejico >=0 && imaPiko >= 0)	//ima obe
	{	
		error = false;
		
		array1 = number.split(".");
		rightmost = array1[array1.length-1];
		array2 = rightmost.split(",");
		if(array2.length > 1)	//potem je najbolj desni znak vejica
		{
			rightmost_char = ",";
			other_char = ".";
		}
		else
		{
			rightmost_char = ".";
			other_char = ",";
		}
			
		celidel = "";
		
		array = number.split(rightmost_char);
		for(i=0; i<array.length-1; i++)
		{
			array1 = array[i].split(other_char);
			for(j=0; j<array1.length; j++)
			{
				if(!isNaN(array1[j]))
					celidel += array1[j];
				else
					error = true;
			}
		}
		if(isNaN(array[array.length-1]))
			error = true;
		
		if(error)
			return -1;
		
		result = celidel + "." + array[array.length-1].toString();
		result = number_format(result, 2, ",", ".");
		if(result.charAt(0) == "-")
			result = "0,00";
		
		return result;
	}
	else if(imaVejico >= 0 && imaPiko < 0)	//ima vejico
	{
		error = false;
		
		array = number.split(",");
		celidel = "";
		for(i=0; i<array.length-1; i++)
		{
			if(!isNaN(array[i]))
				celidel += array[i];
			else
				error = true;
		}
		if(isNaN(array[array.length-1]))
			error = true;
			
		if(error)
			return -1;
			
		var result = celidel + "." + array[array.length-1].toString();
		result = number_format(result, 2, ",", ".");
		if(result.charAt(0) == "-")
			result = "0,00";
		
		return result;
	}
	else if(imaVejico < 0 && imaPiko >= 0)	//ima piko
	{
		error = false;
		
		array = number.split(".");
		celidel = "";
		for(i=0; i<array.length-1; i++)
		{
			if(!isNaN(array[i]))
				celidel += array[i];
			else
				error = true;
		}
		if(isNaN(array[array.length-1]))
			error = true;
			
		if(error)
			return -1;
			
		result = celidel + "." + array[array.length-1].toString();
		result = number_format(result, 2, ",", ".");
		if(result.charAt(0) == "-")
			result = "0,00";
		
		return result;
	}
	else if(imaVejico < 0 && imaPiko < 0)	//nima nič
	{
		error = false;
		
		if(isNaN(number))
			error = true;
			
		if(error)
			return -1;
			
		result = number_format(number, 2, ",", ".");
		if(result.charAt(0) == "-")
			result = "0,00";
		
		return result;
	}
}

//ekvivalent phpjevi number_format
function number_format( number, decimals, dec_point, thousands_sep ) {
    var n = number, prec = decimals, dec = dec_point, sep = thousands_sep;
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    sep = sep == undefined ? ',' : sep;
 
    var s = n.toFixed(prec),
        abs = Math.abs(n).toFixed(prec),
        _, i;
 
    if (abs > 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
 
        s = _.join(dec || '.');
    }
	else
	{
		s = s.replace(".", ",");	
	}
 
    return s;
}

//podati moraš 324.234.234,23 dobiš 324234234.23
function number_deformat( number ) 
{
    number_array = number.split(",");
	while((number_array[0]).indexOf(".") >= 0)
	{
		number_array[0] = number_array[0].replace(".", "");
	}
	
	s = number_array[0] + "." + number_array[1];
 
    return s;
}

//trimming string
function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

//contains
if (!Array.prototype.contains){
    Array.prototype.contains = function(obj){
    var len = this.length;
    for (var i = 0; i < len; i++){
      if(this[i]===obj){return true;}
    }
    return false;
  };
}


