
	function copyObj(obj, stype){
		var retVal=new Array();
		for(var i=0; i<13; i++){
			retVal[i]=obj[i];
		}
		var sjAr=new Array();
		for(var i=0; i<obj[13].length; i++){
			sjAr[i]=obj[13][i];
		}
		retVal[13]=sjAr;
		return retVal;
	}

	function doFilter(){
//		alert("filtering");
		frezultati=new Array();
		var podrucje="*";
		var grad="*";
		var drzava="*";
		var tip="*";
		var ptip="*";
		var star="*";
		if(document.getElementById("filt_region")){
			podrucje=document.getElementById("filt_region").options[document.getElementById("filt_region").selectedIndex].value;
		}
		if(document.getElementById("filt_city")){
			grad=document.getElementById("filt_city").options[document.getElementById("filt_city").selectedIndex].value;
		}
		if(document.getElementById("filt_gis")){
			grad=document.getElementById("filt_gis").options[document.getElementById("filt_gis").selectedIndex].value;
			if(grad=="*"){
				podrucje="*";
			}else if(grad.substring(0,1)=="P"){
				podrucje=grad.substring(1);
				grad="*";
			}
		}
		if(document.getElementById("filt_gis_international")){
			grad=document.getElementById("filt_gis_international").options[document.getElementById("filt_gis_international").selectedIndex].value;
			if(grad=="*"){
				podrucje="*";
				drzava="*";
			}else if(grad.substring(0,1)=="P"){
				podrucje=grad.substring(1);
				grad="*";
				drzava="*";
			}else if(grad.substring(0,1)=="D"){
				drzava=grad.substring(1);
				podrucje="*";
				grad="*";
			}
		}
		if(document.getElementById("filt_type")){
			tip=document.getElementById("filt_type").options[document.getElementById("filt_type").selectedIndex].value;
			if(tip.substring(0,1)=="P"){
				ptip=tip.substring(1);
				tip="*";
			}
		}
		if(document.getElementById("filt_star")){
			star=document.getElementById("filt_star").options[document.getElementById("filt_star").selectedIndex].value;
			if(star!="*")
				star*1;
		}
//		alert("grad="+grad+",podrucje="+podrucje+",ptip="+ptip+",tip="+tip+",star="+star);
		for(var i=0; i<rezultati.length; i++){
			if(
				(drzava=="*" || rezultati[i][7]==drzava) &&
				(podrucje=="*" || rezultati[i][6]==podrucje) &&
				(grad=="*" || rezultati[i][5]==grad) &&
				(ptip=="*" || rezultati[i][8]==ptip) &&
				(star=="*" || rezultati[i][11]==star)
			){
				if(tip=="*")
					frezultati[frezultati.length]=copyObj(rezultati[i],tip);
				else{
					var passed=false;
					for(var j=0; j<(rezultati[i][13].length/7) && !passed; j++){
						if(rezultati[i][13][(j*7)+4]==tip)
							passed=true;
					}
					if(passed)
						frezultati[frezultati.length]=copyObj(rezultati[i],tip);
				}
			}
		}
//		alert("Original: "+rezultati.length+", Filtered: "+frezultati.length);
		doSort();
	}
	
	
	
	var compareInd=9;
	var ascending=true;
	
	function compareElem(a,b){
		if(
			(a[compareInd]<b[compareInd] && !ascending) ||
			(a[compareInd]>b[compareInd] && ascending)
		){
			return 1;
		}else if(a[compareInd]==b[compareInd]){
			return 0;
		}else{
			return -1;
		}
	}
	
	function doSort(){
//		alert("sorting v3");
		if(document.getElementById("auto_sort_t") && document.getElementById("auto_sort_t").selectedIndex>0){
			srezultati=new Array();
			compareInd=9;
			var compareT=document.getElementById("auto_sort_t").options[document.getElementById("auto_sort_t").selectedIndex].value;
			if(compareT.substring(0,1)=="p")
				compareInd=10;
			ascending=true;
			if(compareT.substring(1,2)=="d")
				ascending=false;
//			alert("compareInd="+compareInd+", ascending="+ascending+" was "+compareT+"["+compareT.substring(0,1)+","+compareT.substring(1,2)+"]");
			for(var i=0; i<frezultati.length; i++){
				srezultati[i]=copyObj(frezultati[i],"*");
			}
			srezultati.sort(compareElem);
		}else{
			srezultati=frezultati;
		}
		pages=(perPage>-1)?srezultati.length/perPage:1;
		if (Math.floor(pages)<pages) 
			pages=Math.floor(pages)+1;
		else
			pages=Math.floor(pages);
		showPage(0,1);
	}

