var combodropimage='downbox.gif'; //path to "drop down" image
var combodropoffsetY=2; //offset of drop down menu vertically from default location (in px)
var combozindex=100;

if (combodropimage!="")
	combodropimage='<img class="downimage" src="'+combodropimage+'" title="Select an option" />'

function dhtmlselect(selectid, hiddenid, selectwidth, optionwidth){
	var selectbox=document.getElementById(selectid)
	
	document.write('<div id="dhtml_'+selectid+'" class="dhtmlselect"><span id="' + selectid + '_selected_item">'+selectbox.title+'</span>'+" "+combodropimage+'<div id="dropdown_'+selectid+'" class="dropdown">')
	for (var i=0; i<selectbox.options.length; i++){
		document.write('<span id="' + selectid + '_item?' + selectbox.options[i].value +'" class="item">'+selectbox.options[i].text+'</span>');
		if (selectbox.options[i].selected){
			jQuery('#'+hiddenid).val(selectbox.options[i].value);
			jQuery('#dhtml_'+ selectid)[0].firstChild.innerHTML=selectbox.options[i].text;
		}
			
		var element=document.getElementById(selectid + '_item?' + selectbox.options[i].value);
		
		element.onclick=function(){
			var parent = this.parentNode.parentNode;
			id_item = parent.firstChild.getAttribute("id");
			jQuery('#'+id_item).html(this.innerHTML);
			jQuery('#'+hiddenid).val(this.id.substring(this.id.indexOf('?')+1));
		}
		
	}
		
	document.write('</div></div>')
	
	selectbox.style.display="none"
	
	var dhtmlselectbox=document.getElementById("dhtml_"+selectid)
	
	dhtmlselectbox.style.zIndex=combozindex
	combozindex--
	
	if (typeof selectwidth!="undefined")
		dhtmlselectbox.style.width=selectwidth
	if (typeof optionwidth!="undefined")
		dhtmlselectbox.getElementsByTagName("div")[0].style.width=optionwidth
		
	dhtmlselectbox.getElementsByTagName("div")[0].style.top=dhtmlselectbox.offsetHeight-combodropoffsetY+"px"
	
	if (combodropimage!="")
		dhtmlselectbox.getElementsByTagName("img")[0].style.left=dhtmlselectbox.offsetWidth+3+"px"

		
	dhtmlselectbox.onclick=function(){
		if (this.getElementsByTagName("div")[0].style.display == "block")
			this.getElementsByTagName("div")[0].style.display="none";
		else
			this.getElementsByTagName("div")[0].style.display="block";
	}
}
