	function CatHolder(){
		this.cats = new Array(); //niz kategorija
		
		//HTML polja
		this.fCats;
		this.fSubCats;
		
		// funny alerts and comments
		this.Funny = false;
		
		//initialization
		this.init = init;
		
		//inicijalno selektirane vrijednosti
		this.sSelCat = new String();
		this.sSelSubCat = new String();
		
		// ako ne postoje vrijednosti koje treba selektirati, 
		// da li ih unijeti u listu?
		this.bInsCat = false;
		this.bInsSubCat = false;
		
		//dodavanje
		this.addCat = addCat;
		this.addSubCat = addSubCat;
		
		//azuriranje prikaza na web strani
		this.updateCats = updateCats;
		this.updateSubCats = updateSubCats;
		
		this.catTitle = new String();
		this.subCatTitle = new String();
		
		//label for first item which has value of 0
		this.sZeroCatLabel = new String("");
		this.sZeroSubCatLabel = new String("");
	}
		
	/*----------------------| dont mess up with this |------------------------------*/
	function init(fCat, fSubCat, catTitle, subCatTitle, selCat, selSubCat, insCat, insSubCat, zeroCatLabel, zeroSubCatLabel){
		if(!selSubCat){
			selSubCat = null;
			insSubCat = false;
		}
		
		if(!selCat){
			selCat = null;
			insCat = false;
			
			// ako nema selektirane kategorije, 
			// ne mozemo selektirati niti unijeti podkategoriju!
			selSubCat = null;
			insSubCat = false;
		}
		
		if(!insCat) insCat = false;
		if(!insSubCat) insSubCat = false;
		
		if(zeroCatLabel) this.sZeroCatLabel = zeroCatLabel;
		if(zeroSubCatLabel) this.sZeroSubCatLabel = zeroSubCatLabel;
		
		
		this.fCats = fCat;
		this.fSubCats = fSubCat;
		
		this.sSelCat = selCat;
		this.sSelSubCat = selSubCat;
		
		this.catTitle = catTitle;
		this.subCatTitle = subCatTitle;
		
		this.bInsCat = insCat;
		this.bInsSubCat = insSubCat;
		
		
		var self = this;
		this.fCats.onchange = function(){
			self.updateSubCats();
		};
			
		this.updateCats(true);
	}
	
	//azuriranje prikaza kategorija na stranici
	//ukoliko je bInit == true radi se o inicijalnom prikazu i bice selektirana aktivna kategorija (npr: prilikom izmjene podataka)
	function updateCats(bInit){
		if(bInit == undefined) bInit = false;
		
		//brisemo listu
		while(this.fCats.options.length){
			this.fCats.remove(0);
		}
		this.fCats.options[0] = new Option(this.sZeroCatLabel, "");
		
		var bSelected;
		var nSelectedIndex = 0;
		var bDoSelect = (this.sSelCat && bInit);
		
		// ukoliko ne postoji kategorija koju smo zelimo selektirati
		// a bInsCat je true, onda cemo je dodati i selektirati
		if(bDoSelect && this.bInsCat){
			var index = InArray(this.sCatName, this.cats);
			if(index == -1){
				this.cats.push(this.sCatName);
				//alert("inserting cat");
			}
		}
		
		for(var i=0; i<this.cats.length; i++){
			if(bDoSelect && this.cats[i].title == this.sSelCat) nSelectedIndex = i+1;
			this.fCats.options[i+1] = new Option(this.cats[i].title, this.cats[i].title);
		}
		
		this.fCats.options[nSelectedIndex].selected = true;	
		this.updateSubCats(bInit);
	}
	
	//azuriranje prikaza podkategorija - isto kao i za kategorije
	function updateSubCats(bInit){
		
		if(bInit == undefined) bInit = false;
		
		while(this.fSubCats.options.length){
			this.fSubCats.remove(0);
		}
		
		this.fSubCats.options[0] = new Option(this.sZeroSubCatLabel, ""); // -> 1
	
		if(this.fCats.options[this.fCats.selectedIndex].value){
			var nSelected = this.fCats.selectedIndex -1; //jer je prvi element prazan -> 1
			if(nSelected >= 0){
				var bSelected;
				var nSelectedIndex = 0;
				var bDoSelect = (this.sSelSubCat && bInit);
				
				// ukoliko ne postoji podkategorija koju smo zelimo selektirati
				// a bInsCat je true, onda cemo je dodati i selektirati
				if(bDoSelect && this.bInsSubCat){
					var index = InArray(this.sSelSubCat, this.cats[nSelected].subCats);
					if(index == -1){
						this.cats[nSelected].subCats.push(this.sSelSubCat);
						//alert("inserting sub cat");
					}
				}
				
				for(var i=0; i<this.cats[nSelected].subCats.length; i++){
					if(bDoSelect && this.cats[nSelected].subCats[i] == this.sSelSubCat)	nSelectedIndex = i+1;
					this.fSubCats.options[i+1] = new Option(this.cats[nSelected].subCats[i], this.cats[nSelected].subCats[i]);
				}
						
				this.fSubCats.options[nSelectedIndex].selected = true;
			}	
		}
	}
	
	// ako se navede niz argumenata, prvi je naziv kategorije, a ostali su nazivi njegovih podkategorija
	// ukoliko nema argumenata, onda se od korisnika trazi naziv nove kategorije
	function addCat(){
		var nIndex = this.cats.length;
		this.cats[nIndex] = new Object();
		this.cats[nIndex].title = new String();
		this.cats[nIndex].subCats = new Array();
		
		if(arguments.length > 0){
			this.cats[nIndex].title = arguments[0];
			for(var i=1; i<arguments.length; i++){
				this.cats[nIndex].subCats.push(arguments[i]);
			}
		}else{
			var catName = prompt(this.catTitle + ": ", "");
			if(catName == null) return;
			
			this.cats[nIndex].title = catName;
			
			var nSelectedIndex = this.fCats.options.length;
			this.fCats.options[nSelectedIndex] = new Option(catName, catName);
			this.fCats.options[nSelectedIndex].selected = true;
			
			this.updateSubCats();
		}
	}
	
	//isto kao i za kategorije
	function addSubCat(){
		if(this.fCats.options[this.fCats.selectedIndex].value){
			var subCatName = (arguments.length > 0) 
				? arguments[0]
				: prompt(this.subCatTitle + ": ", "");
				
			if(subCatName == null) return;
			
			var nSelected = this.fCats.selectedIndex - 1;
			
			// provjeravamo da vidimo da li vec postoji
			var index = InArray(subCatName, this.cats[nSelected].subCats);
			if(index > -1){
				if(this.Funny) alert(this.subCatTitle + " '" + subCatName + "' is already on the list. \nI'll be kind enough to select it for you ;-)");
				this.fSubCats.options[index+1].selected = true;
				return;
			}
			
			this.cats[nSelected].subCats.push(subCatName);
			var nSelectedIndex = this.fSubCats.options.length;
			this.fSubCats.options[nSelectedIndex] = new Option(subCatName, subCatName);
			this.fSubCats.options[nSelectedIndex].selected = true;
		}else{
			alert("Please choose a category first.");
		}
	}
	
	function InArray(sItem, aArray){
		for(var i=0; i<aArray.length; i++){
			if(aArray[i] == sItem) return i;	
		}
		return -1;
	}
