		var category_id=0;
		var time_id=0;
		var search_id=1;
		var search_timeout=15;

		function search_progress(auctions){
		    $('#progress_val').html(auctions);
		}
		
		function search_incomplete(sid,code){
		    if (search_id!=sid)
			return;			
		    
		    if (code==0)
			msg='Twoje wyszukiwanie zajmuje za duzo czasu. Wciaz je przetwarzamy. Sprobuj za jakis czas ponownie - bedziemy mieli juz rezultat'
			
		    if (code==1)
		    {
			msg='Musisz wpisac fraze';
			$('#searchButtonContainer').show();
    			$('#searchButton').show();
			$('#search_box1').addClass('redBorder');
			document.getElementById("query").focus();
		    }
		
		    if (code==2)
		    {
			msg='Musisz wybrac kategorie';
			$('#searchButtonContainer').show();
			$('#searchButton').show();
			$('#search_box2').show('normal');
			expandTree('category');
			$('#search_box2').addClass('redBorder');
		    }
			
		    $('#progress_waiting').hide();
		    $('#progress_message').html(msg).fadeIn();
		    
		}
		
		function search_complete(sid,url){
		
		    //search_incomplete(sid);
		    //return;
		
		    if (search_id!=sid)
			return;
			
//		    window.dhtmlHistory.create();
//		    dhtmlHistory.initialize();
		    //dhtmlHistory.add(document.location);
//		    dhtmlHistory.add(url,"");
		    window.location='/redirect.php?l='+url;
		}
		
		function formSubmit(){
		    doSearch();  		    
		    
		    return false;
		}
		
		
		function onSearchTimer()
		{
		    search_timeout--;
		    var num = search_timeout/17;
		    
		    if (num < 0)
			num = 0;
			
		    $("#progress_counter").html(""+num.toFixed(2));
		    if (search_timeout > 0)
	    	        setTimeout("onSearchTimer();", 1000/17);
		}
		
		function setSearchTimeout(tout)
		{
		    search_timeout = tout*17;
		    $("#progress_counter").html(""+tout.toFixed(2));
		    setTimeout("onSearchTimer();", 1000/17);
		}
		
		function abortSearch(){
		
		    if (!$('#searchButton').is(':visible')){
			if (!confirm('Czy chcesz porzucic poprzednie wyszukiwanie i rozpoczac nowe??'))
			    return false;
		    } else {
			return true;
		    }

		
		    search_id++;
		    $('#progress').hide();
		    $('#searchButtonContainer').show();
		    return true;
		}				
		
		function wyszukiwanie()
		{
		    $('#search_box1').show('normal');
		    $('#search_box1c').show();
/*		    if (!$('#query').val())
			$('#search_box2').hide();
		    else {
			if (!category_id)
			    $('#search_box3').hide();
		    }
*/


		    setImg(2,2);
		    setImg(3,3);
		    $(document).pngFix();


/*		    $('#search_img1').attr("src", "/static/glass_numbers_1.png");
		    $('#search_img2').attr("src", "/static/glass_numbers_2.png");
		    $('#search_img3').attr("src", "/static/glass_numbers_3.png");*/
		    $('#search_name').html("WYSZUKIWANIE");
		    $('#query_mode').val('0')
		    $('#bigtab_search').addClass('bigtabchosen').blur();
		    $('#bigtab_browse').removeClass('bigtabchosen');
		    $('#searchButton').removeClass('searchBrowse');

		}
		
		function setImg(id,img_id){
		    $('#search_img'+id).parent().html(
			'<img id="search_img'+id+'" src="http://static.paa.pl/glass_numbers_'+img_id+'.png">'
		    );
		}
		
		function przegladanie()
		{
		    abortSearch();
		    $('#search_box1').hide('normal');
//		    $('#search_box1c').hide();
		    $('#search_box2').show('normal');
		    $('#search_box2c').show();
		    
		    setImg(2,1);
		    setImg(3,2);
		    $(document).pngFix();
		    $('#search_name').html("PRZEGLADANIE");
		    
		    $('#query_mode').val('1');
		    $('#bigtab_search').removeClass('bigtabchosen');
		    $('#bigtab_browse').addClass('bigtabchosen').blur();
		    
		    $('#searchButton').addClass('searchBrowse');
		}
		
		tipshown=Array();
		var tooltip_pos=false;
		function showHelp(id){
		
		
		    if (undefined!=tipshown[id])
			if (tipshown[id])
			    return;
		
		    tipshown[id]=1;		    		    
		    pos=tooltip_pos;		    
		    //alert(pos.left);
		    $('#tip_'+id).css('left',(pos.left+500)+'px').css('top',(pos.top-25)+'px').show();
		}
		function hideHelp(id){
		    
		
		    tipshown[id]=0;		    
		    
		    $('#tip_'+id).hide();
		}


// ************************************ CATEGORY SELECT   *********************************************
    
    
    
    function expandTree(name){
	$('#'+name+'_choice').show('normal');
	switchButton(name,'erase');
    }
    
    function eraseTree(name){
	eval(name+'_id = 0;');
	applyTree(name);
    }
    
    function switchButton(name,mode){
	button=$('#'+name+'_expand');
	button.attr('href',"javascript:"+mode+"Tree('"+name+"');");
	button.html('<img height="23" width="'+((mode=='erase') ? 24 : 73)+'"src="/static/icon_'+mode+'.png"/>');
	$(document).pngFix();
	button.attr('title',((mode=='erase') ? 'Usun ten wybor' : 'Kliknij aby pokazac drzewo wyboru'));
    }
    
    function applyTree(name,noanim)
    {
	var treevar=eval(name+'_id');
	if (treevar==undefined)
	    return;
	    
	qry_span='#current_'+name;
	
	anim_type=(noanim==null) ? 'normal':null;
	
	    
	if (treevar==0){
	    $('#'+name+'_choice').hide(anim_type);
	    switchButton(name,'expand');
	    $(qry_span).html('(Dowolna)');
	} else {
	//    switchButton(name,'erase');
	    //$('#'+name+'_choice').show();//'normal');
	}
	    
    }
		
var catselect_opts ={
    menuclass : 'horiz',
    divid: 'browsing',
    children : function(id){
	     return category_children[id];
	},
    itemname : function(id){
	    return category_name[id];
	},
    scripturl : function(id){
    	    if (id==0)
		return '/monitor/ajax_cat_tree2.php?nobox=1&id='+id;
	    
    	    for (i = 0; i < category_children[0].length; i++){
		if (category_children[0][i] == id)
		    return  '/monitor/ajax_cat_tree2.php?nobox=1&id='+id;
	    }
	    return 0;
	},
    itemclick : function (catarray){
	    abortSearch();
	    ret='';
	    for (i in catarray){
		if (!catarray[i])
		    break;
		category_id=catarray[i];
		ret += ((ret!='') ? ' &#187; ' : '') + category_name[catarray[i]];
	    }
	    $('#current_category').html(ret);
	    applyTree('category');
	},
    anchor: function(id){ return 'search3'; }
    
}

/************************************ TIME SELECT *******************************************/


function timeId2str(id){
	    if (id<3000)
		return ''+id;
	    if (id<300000){
		arr=("sty lut mar kwi maj cze lip sie wrz paz lis gru").split(" ");
		return arr[ (id%100)-1];
	    }
	    return id%100;
}

function onTimeSelected(){
    abortSearch();
}


		
timeselect_opts={
    menuclass : 'horiz',
    divid: 'time_choice',
    children : function(id){
    
    	    str=''+id;
	    ret=Array();
	    x=0;
	    
	    currdate=new Date();
	    
	    if (id==0){
		for (i = 2006; i<=currdate.getFullYear(); i++)
		    ret[x++] = i;
	    } else  if (str.length==4){

		for (var i=((id==2006)? 6 : 1);i<=12;i++)
		    ret[x++] = id*100 + i;
		    
	    } else if (str.length==6){
		year=parseInt(str.substring(0,4));
		//alert(year);
		mon=parseInt(str.substring(4));
		if (mon==2)
		    daycnt=(((year-2004)%4)==0) ? 29 :28
		else
		    daycnt=(0==mon%2)? 30 :31;
		    
		for (var i=1;i<=daycnt;i++)
		    ret[x++]=id*100 + i;
	    } else
		return 0;
	    
	    return ret;
	},
    itemname : function(id){
	    return timeId2str(id);
	},
    scripturl : function(id){
	    return 0;
	},
    itemclick : function (catarray){
	    ret='';
	    for (i in catarray){
		if (!catarray[i])
		    break;
		time_id=catarray[i];
		ret += ((ret!='') ? ' - ' : '') + timeId2str(catarray[i]);
	    }
	    if (i<3)
		return;
	    $('#current_time').html(ret);
	    onTimeSelected();
	},
    anchor: function(id){ return '#'; }
    
}		

