// DHTML version of building select (much faster than DOM)
function select_div( id )
{
	//var stoper = new Stoper(); stoper.start();
	
	// get place in DIV where to insert SELECT:
	var div = document.getElementById("div_"+id);

	// Change UL list into SELECT & OPTIONS

	var ul = document.getElementById("ul_"+id);
	var list = ul.getElementsByTagName("a");
	var len = list.length;
	var options_str = '';
	
	for(var i=0; ( a = ul.getElementsByTagName("a")[i] ); i++)
	{
		selected = (a.className == 'selected') ? ' selected':'';		
		options_str += '<option value="'+a.href+'"'+selected+'>'+a.innerHTML+'</option>';
	}
	
	div.innerHTML = '<select name="'+ id +'" onchange="do_url(this);">'+options_str+'</select>';
	
	ul.style.display = 'none';
	
	//stoper.stop();
	//window.status=window.status+'[JS.'+id+':'+stoper.get()+']'
}

// DOM version of building select (in IE 10x slower than DHTML version)
function select_div_DOM( id )
{
	var stoper = new Stoper(); stoper.start();
	
	// Insert brand new SELECT as a content of DIV:
	var div = document.getElementById("div_"+id);
	div.innerHTML = '<select name="'+ id +'" onchange="do_url(this);"></select>';

	// Change UL list into SELECT & OPTIONS
	var form_name = "wyszukiwarka";	
	
	var select = document.forms[form_name].elements[id];
	var options = select.options; var q = 0;
	// clear options list
	options.length = 0;
	
	var ul = document.getElementById("ul_"+id);
	var list = ul.getElementsByTagName("a");
	var len = list.length;
	for(var i=0; i<len; i++)
	{
		/*
		options[q] = new Option( list[i].innerHTML, list[i].href );  // (text, value)
		if(list[i].className=='selected')
		{
			options[q].selected = true;
			window.status=window.status + '/'+list[i].innerHTML+'/';
		}
		*/
		options[q] = new Option( list[i].innerHTML, list[i].href );  // (text, value)
		options[q].selected = (list[i].className == 'selected');
		q++;
	}
	ul.style.display = 'none';
	
	stoper.stop();	
	window.status=window.status+'[JS.'+id+':'+stoper.get()+']'
}
function do_url(select)
{
	var option = select.options[select.selectedIndex];
	if( option.value )
	{
		window.location = option.value;
	}
}

function Stoper()
{
	var _Tstart=false;
	var _Tstop=false;
		
	this.start = function()
	{
		var _datetime = new Date();
		this._Tstart = _datetime.getTime();
	}
	this.stop = function()
	{
		var _datetime = new Date();
		this._Tstop = _datetime.getTime();
	}
	this.get = function()
	{
		if(!this._Tstop)
			this.stop();
			
		if(this._Tstop && this._Tstart)
			return (this._Tstop-this._Tstart)/1000;
		else
			return false;
	}
}

