function css(el, c) {
	for (var i in c) el.style[i] = c[i];
}
function combobox(el) {
	if (typeof el == "string") el = document.getElementById(el);
	if (!el) return;
	
	var container = document.createElement("div");		
	var cb = document.createElement("input");
	var ul = document.createElement("ul");
	cb.type = "text";
	cb.readOnly = "true";

	css(container, {
		width:el.offsetWidth + "px",
		display:'inline',
		position:'relative',
		height:el.offsetHeight
	});
	css(cb, {
		width:el.offsetWidth + "px",
		/*height:el.offsetHeight + "px",*/
		lineHeight:'18px',
		background:"url(/public/images/common/combobox.bmp) no-repeat top right"
	});
	css(ul, {
		width:el.offsetWidth + "px",
		display:'none', 
		background:'#fff', 
		position:'absolute', 
		top : el.offsetHeight+'px', 
		left:'0px', 
		padding:'0px', 
		margin:'0px', 
		border:'1px solid'
	});
	el.style.display = 'none';

	el.parentNode.insertBefore(container, el);
	container.appendChild(cb);
	container.appendChild(ul);
	
	buildCombobox(ul, el, cb);
	
	cb.onfocus = function(event) {ul.style.display = '';}
	cb.onclick = function(event) {
		if (event) {
			event.stopPropagation();
			event.preventDefault();
		} else {
			window.event.cancelBubble = true,
			window.event.returnValue = false;
		}
	}
	document.body.onclick = window.onclick = function() {
		for (var i=0, e; e=(window.dymCombox || [])[i]; i++) {
			e.style.display = 'none';
		}
	};
}


function buildCombobox(ul, select, cb) {
	(window.dymCombox = window.dymCombox || []).push(ul);
	var first = true;
	for (var i=0, o; o=select.options[i]; i++) {
		var li = document.createElement("li");
		li.innerHTML = o.text;
		li.title = o.title || o.text;
		li.selectedIndex = i;
		li.nowrap = true;
		css(li, {
			'listStyle':'none',
			'width':'100%',
			'fontSize':'12px',
			'height':'16px',
			'lineHeight':'16px'
		});
		li.onclick = function() {
			select.selectedIndex = this.selectedIndex;
			cb.value = this.innerHTML;
			cb.title = this.title;
			ul.style.display = 'none';
		}
		li.onmouseover = function() {css(this, {background:'#006', color:'white'})};
		li.onmouseout = function() {css(this, {background:'#fff', color:'black'})};
		ul.appendChild(li);
		if (first || o.selected) {
			first = false;
			cb.value = o.text;
			cb.title = o.title;
		}
	}
}