var mappingValueField, mappingTitleField;

//显示列表,values格式:标题1|值1\0标题2\0值2\0...\0标题n|值n
function showValueList(values, valueField, titleField, displayArea, barWidth, alignRight) {
	mappingValueField = valueField;
	mappingTitleField = titleField;
	
	var bar = document.getElementById("listBar");
	if(!bar) {
		var span = document.createElement("span");
		document.body.appendChild(span);
		span.innerHTML = '<div id="listBar" style="display:none" class="listbar" onblur="hideBar(this);">' +
						 '  <table onmousedown="clickItem()" onmouseover="mouseOverItem()" onmouseout="mouseOutItem()"  border="0" cellpadding="2" cellspacing="0" width="100%">' +
						 '    <tr><td id="itemId" class="menunormal">title</td></tr></table></div>';
		bar = document.getElementById("listBar");
	}
	var table = bar.getElementsByTagName("table")[0];
	for(var i=table.rows.length-1; i>=0; i--) {
		table.deleteRow(i);
	}
	if(values.substring(values.length - 1)=='\n') {
		values = values.substring(0, values.length - 1);
	}
	values = values.split("\n");
	for(var i=0; i<values.length && values[i]!=""; i++) { //创建列表
		var item = table.insertRow().insertCell();
		item.className = "listnormal";
		item.noWrap = true;
		var itemValues = values[i].split("|");
		item.id = itemValues[itemValues.length - 1]; //值
		item.innerHTML = itemValues[0]; //标题
		item.style.height = "18px";
	}
	if(!barWidth || barWidth<0 || barWidth==0) {
		barWidth = displayArea.offsetWidth;
	}
	var pos = getAbsolutePosition(displayArea);
	bar.style.left = alignRight ? pos.left + displayArea.offsetWidth - barWidth : pos.left;
	bar.style.top = pos.top + displayArea.offsetHeight;
	bar.style.width = barWidth;
	if(values.length>10) {
		bar.style.height = 190;
		bar.style.overflow = "auto";
	}
	else {
		bar.style.height = values.length==0 || values[0]=="" ? 0 : values.length * 20;
	}
	bar.style.display = "";
	currentAlignRight = alignRight;
	bar.focus();
}
function hideBar(src) {
	if(src && src.contains(document.activeElement)) {
		src.focus();
	}
	else {
		document.getElementById("listBar").style.display = "none";
	}
}
function mouseOverItem() {
	event.srcElement.className = "listover";
}
function mouseOutItem() {
	event.srcElement.className = "listnormal";
}
function clickItem() {
	hideBar();
	if(mappingValueField) {
		mappingValueField.value = event.srcElement.id;
	}
	if(mappingTitleField) {
		mappingTitleField.value = event.srcElement.innerText;
	}
	try {
		if(mappingValueField) {
			mappingValueField.onchange();
		}
	}
	catch(e) {
	}
	
	try {
		if(mappingTitleField) {
			mappingTitleField.onchange();
		}
	}
	catch(e) {
	}
}
function getAbsolutePosition(obj) { //获取对象的绝对位置
	var pos = new Object();
	pos.left = 0;
	pos.top = 0;
	while(obj.tagName!="BODY") {
		pos.left += obj.offsetLeft;
		pos.top += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return pos;
}