addLoadEvent(initSearchAdvanced);

function initSearchAdvanced() 
{
    var selects = document.getElementsByTagName('select');
	for (var i = 0; i < selects.length; i++) {
		if (selects[i].className.indexOf('fancySelect') != -1) {
			new SelectAdvanced(selects[i]);
		}
	}
}

function SelectAdvanced(select)
{
	var container = select.parentNode;
	var div = document.createElement('div');
	div.className = 'selectBox';
	if (select.getAttribute('size')) {
		div.style.height = parseInt(select.getAttribute('size')) + 2.3 + 'em';
	}
	var ol = document.createElement('ol');
	for (var i = 0; i < select.options.length; i++) {
		var li = document.createElement('li');
		var a = document.createElement('a');
		a.setAttribute('rel',select.options[i].value);
		a.setAttribute('rev',select.id);
		a.setAttribute('href','#');
		if (select.options[i].defaultSelected == true) {
			a.setAttribute('class','current');
		}
		var txt = document.createTextNode(select.options[i].text);
		a.appendChild(txt);
		li.appendChild(a);
		ol.appendChild(li);
		a.onclick = function() {
			var select = document.getElementById(this.rev);
			var doit = true;
			for (var i = 0; i < select.options.length && doit; i++) {
				if(select.options[i].value == this.rel) {
					select.options[i].selected = true;
					doit = false;
				}
			}
			select.form.submit();
			return false;
		}
	}
	div.appendChild(ol);
	container.appendChild(div);
	select.style.display = 'none';
}

