	function showHideBox(naziv){	
		if( $('.filter #'+naziv+' a.checked').length > 0 || ( $('.filter #'+naziv+' input').length > 0 && $('.filter #'+naziv+' input').val() != '' ) ){
			return false;
		}
		
		if(document.getElementById(naziv) && document.getElementById(naziv).style.display==''){
			document.getElementById(naziv).style.display='none';
			CookieTime = 1000 * 60 * 60 * 24 * 30;
			CookieName = "dp[" + naziv + "]";
			CookieVal = 1;			
		}else{
			document.getElementById(naziv).style.display='';
			CookieTime = 1000 * 60 * 60 * 24;
			CookieName = "dp[" + naziv + "]";
			CookieVal = 0;
		}
		UpdateUserCookie(CookieName, CookieVal, CookieTime);
		return false;
	}
	
	function UpdateUserCookie(name, val , time){
	    date = new Date();
    	date.setTime(date.getTime() + time); 		
	    document.cookie = name + "=" + val + "; expires=" + date.toGMTString();  
	}

	function processCheckBox(name, val){
		var oLnk = document.getElementById('lnk'+name);
		var oHid = document.getElementById(name);	
				
		if(oHid.value > 0){
			oHid.value = 0;
			oLnk.className = 'unchecked';
		}else{
			oHid.value = val;
			oLnk.className = 'checked';
		}
			
		return false;
	}
	
	$(document).ready(function(){
		
		var iCatID    = 0;
		var sCatNaziv = '';
		if( $('#js_fv').length > 0 && $('#js_fv').val() != '' )
			var aFV       = $('#js_fv').val().split(',');
				
		$('body').click(function(){
			$('.search_kategorije .search_lista_kategorija').hide();	
		});
				
		$('#container .search_kategorije').click(function(){
			$('#container .search_kategorije .search_lista_kategorija').toggle();
			return false;
		});
		
		
		$('.search_lista_kategorija li').click(function(){
			aCatID    = $(this).attr('id').split('cat_');
			sCatNaziv = $(this).html();
			iCatID    = aCatID[1];
									
			if( iCatID >= 0 ){
				if( $('.search_kategorije span#izabrana_'+iCatID).length < 1 ){
					$('.search_kategorije span[id^=izabrana_]').html(sCatNaziv);
					$('.search_kategorije span[id^=izabrana_]').attr('id', 'izabrana_' + iCatID);
					
					$('.search_lista_kategorija li').css('font-weight', 'normal');
					
					$(this).css('font-weight', 'bold');
					
					$('.search_lista_kategorija').css('display', 'none');
					
					if( iCatID == 0 )
						$('#pretragaKategorija').val("");
					else
						$('#pretragaKategorija').val( iCatID );
						
				}
			}
			return false;
		});
		
		
		var IDPoljeSema  = 0;
		var sTrenuntiIDs = '';
		if($('#linkBezFiltera').length > 0)
			var sLink        = $('#linkBezFiltera').val().replace(/&fv=/gi, "");
		
		$('a[id^=vise_]').click(function(el){
			
			if( $('input#fv').val() != '' )
				sTrenuntiIDs = $('input#fv').val();
						
			sTitle = $(this).parents('.filter_content').siblings('.filter_naziv').html();
						
			var aSlova = Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Š','Đ','Č','Ć','Ž');
			var sIspis = '';
			var aThisID = $(this).attr('id').split('_');
			IDPoljeSema = aThisID[1];
			
			
			$.each(aSlova, function(index, value){
				sIspis += '<a href="#" class="trazi_po_slovu" value="'+value+'" >'+value+'</a>&nbsp;';
			});			
			
			el.preventDefault();
			$.blockUI(
	    			{ 
	    				popupType:'Kupindo',
    				css: {width:'600px', height: '550px', left:'0', top:'0'},
    				message: '<div class="holder_content_separator_line">'+
    				'<div id="popup-content">'+
    				'<div class="holder_content_separator">'+
    				'<div class="holder_content" style="width:400px;">'+
    					'<label class="grupa">'+ sTitle +'</label>'+
    					'<div class="holder_content round_corners filter_lista" style="height:210px;overflow:hidden;width:360px;">'+    						
    						'<div class="holder_content_separator" style="background-color:#f4f4f4;padding:3px;margin-bottom:10px">' + sIspis + '</div>'+
    						'<ul style="overflow-y:scroll;height:180px;width:100%" id="ajx_brendovi_content"></ul>'+
    					'</div>'+
    				'</div>'+
    				'<div class="holder_content round_corners" style="width:165px;padding:15px;background-color:#f4f4f4;">'+
    				'<p>Izabrani za pretragu</p>'+
    					'<ul style="height:200px;overflow:auto" id="izabrani_za_pretragu" ></ul>'+
    				'</div>'+
    				'</div>'+
    				'</div>'+
    				'</div>',
    				popupButtons: {
    					'filtriraj': {
	    					type: 'link',
	    					cssClass: 'aktivirajPredmet',
	    					objID: 'btn_confirm',
							objName: 'btn_confirm'
		    			},
    					'otkaži': {
    						type: 'link',
							cssStyle: 'margin-left: 10px',
							cssClass: 'odustani_popup',
    						cancel: true
    	    			}
    				}
    			}
    		);
	    	$('.Kupindo_popup_holder').center();
	    	
	    	if( sTrenuntiIDs == undefined )
	    		sTrenuntiIDs = '';
	    			    	
				$.ajax({
		        	   type: "POST",
		        	   url: "/inc/ajx/Pretraga/ajxGetPopUpPretraga.php",
		        	   data: "IDPoljeSema=" + IDPoljeSema + "&TrazenoSlovo=A&TrenutnoIzabrani="+sTrenuntiIDs+"&PrikaziIzabrano=1",
		        	   success: function(objReturn){
							result = $.parseJSON(objReturn);    	 
							if( result.izabrano != '' ){
								$('#izabrani_za_pretragu').append(result.izabrano);
							}

							if( result.prikaz != '' ){
								$('#ajx_brendovi_content').html(result.prikaz);
								$('#popup-content').append('<div style="display: none;" id="cont_slovo_A">'+result.prikaz+'</div>');
							}else{
								$('#ajx_brendovi_content').html('<p>Nema rezultata za zadati kriterijum.</p>');
								$('#popup-content').append('<div style="display: none;" id="cont_slovo_A"><p>Nema rezultata za zadati kriterijum.</p></div>');
							}
		        	   }
				});	
			
	    	
	    	$('.aktivirajPredmet').attr('href', sLink+'&fv='+sTrenuntiIDs);
	    	
			return false;
		});
		
		$('a.trazi_po_slovu').live('click', function(){
			if( $('#cont_slovo_'+$(this).html()).length > 0 ){
				$('#ajx_brendovi_content').html( $('#cont_slovo_'+$(this).html()).html() );
				return false;
			}
			
			if( IDPoljeSema > 0 ){				
				var sBiranoSlovo = $(this).html();
				
				aTrenutnoIzabrani = new Array();
				$('#izabrani_za_pretragu a').each(function(){
					aPodaci  = $(this).attr('id').split('_');
					iID      = aPodaci[1];					
					aTrenutnoIzabrani.push(iID);
				});
				
				$.ajax({
		        	   type: "POST",
		        	   url: "/inc/ajx/Pretraga/ajxGetPopUpPretraga.php",
		        	   data: "IDPoljeSema=" + IDPoljeSema + "&TrazenoSlovo="+sBiranoSlovo+"&TrenutnoIzabrani="+eval(aTrenutnoIzabrani)+"&PrikaziIzabrano=0",
		        	   success: function(result){
							if( result != '' ){
								$('#ajx_brendovi_content').html(result);
								$('#popup-content').append('<div style="display: none;" id="cont_slovo_'+sBiranoSlovo+'">'+result+'</div>');
							}else{
								$('#ajx_brendovi_content').html('<p>Nema rezultata za zadati kriterijum.</p>');
								$('#popup-content').append('<div style="display: none;" id="cont_slovo_'+sBiranoSlovo+'"><p>Nema rezultata za zadati kriterijum.</p></div>');
							}
		        	   }
				});		
			}
			return false;
		});
		
		$('.brand_option').live('click',function(){
			
			sThisID  = $(this).attr('id');
			aPodaci  = sThisID.split('_');
			iID      = aPodaci[1];
			sName    = aPodaci[2];

			$('a[id^=podaci_'+iID+']').removeClass('unchecked');
			$('a[id^=podaci_'+iID+']').addClass('checked');
			
			if( $('a[id^=izabrano_'+iID+']').length < 1){
				$('#izabrani_za_pretragu').append('<li><a class="minus izbaci_iz_pretrage" href="#" id="izabrano_'+iID+'_'+sName+'"></a>'+sName+'</li>');
				postaviLink( sTrenuntiIDs );
			}			
			return false;
		});
		
		$('a.izbaci_iz_pretrage').live('click', function(){
			sThisID  = $(this).attr('id');
			aPodaci  = sThisID.split('_');
			iID      = aPodaci[1];
			sName    = aPodaci[2];
			
			$(this).parents('li').remove();
			
			$('a[id^=podaci_'+iID+']').removeClass('checked');
			$('a[id^=podaci_'+iID+']').addClass('unchecked');
			
			postaviLink( sTrenuntiIDs );
			
			return false;
		});
		
		function postaviLink(sTrenuntiIDs ){
			var sIDs  = '';
			var count = 0;
			$('#izabrani_za_pretragu a').each(function(){
				$aThisID = $(this).attr('id').split('_');
				if( count == 0 ){
					sIDs += $aThisID[1]; 
				}else{
					sIDs += ',' +$aThisID[1];
				}	
				count++;
			});
			count = 0;
			
		    $('.aktivirajPredmet').attr('href', sLink+'&fv='+sIDs);
		    
			return false;
		}
		
		//skrolovanje unutar combo boxova
		if( typeof aFV != 'undefined' ){		
			var oAChecked  = '';
			var oThisLista = '';
			
			$('.filter_lista').each(function(){		
				oAChecked  = '';
				oThisLista = this;
				
				$.each(aFV, function(key, value) { 
					if( $(oThisLista).find('a.checked.scrollTo_'+value).length > 0 ){
						oAChecked = $(oThisLista).find('a.checked.scrollTo_'+value);
					}
				});
				
				if(  typeof oAChecked != 'undefined' && oAChecked != '' ){
					$(oThisLista).animate({
						scrollTop: oAChecked.position().top - 80
					},1);
				}
				
			});
		}
		

		
	});
	
