var combodropimage='../../img/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="Selecione uma opção" />';

function atualizaValorCombo(selectid, valor) {
	var selectbox		= document.getElementById(selectid);
	var dhtmlselectbox	= document.getElementById("dhtml_"+selectid);

	for (var i=0; i<selectbox.options.length; i++) {
		if (selectbox.options[i].value == valor) {
			selectbox.options[i].selected = true;
			dhtmlselectbox.getElementsByTagName("div")[0].style.display = "none";
			document.getElementById('titulo_'+ selectid).innerHTML = selectbox.options[i].text;
		}
	}
}

function dhtmlselect(selectid, selectwidth, optionwidth, acao) {
	var selectbox=document.getElementById(selectid);

	var titulo = selectbox.title;
	if (selectbox.options[0].value != '') {
		titulo = selectbox.options[0].text;
	}

	document.write('<div id="dhtml_'+selectid+'" class="dhtmlselect"><span id="titulo_'+ selectid +'">'+ titulo +'</span>'+combodropimage+'<div class="dropdown">');

	for (var i=0; i<selectbox.options.length; i++) {
		if (selectbox.options[i].value != '') {
			if (acao == "padrao") {
				document.write('<a href="javascript:void(0)" onclick="atualizaValorCombo(\''+ selectid +'\', \''+ selectbox.options[i].value +'\')">'+selectbox.options[i].text+'</a>');
			} else if (acao == "url") {
				document.write('<a href="'+selectbox.options[i].value+'">'+selectbox.options[i].text+'</a>');
			}
		}
	}
	document.write('</div></div>');

	selectbox.options[0].selected = true;

	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.onmouseover = function() {
		this.getElementsByTagName("div")[0].style.display="block";
	}

	dhtmlselectbox.onmouseout = function() {
		this.getElementsByTagName("div")[0].style.display="none";
	}
}
