var droplistid = null;

function dropit(aevent, txtcmd, listid) {
	drawdrop();
	var list = document.getElementById(listid);
	if (list) {
		list.style.left = getAbsLeft(txtcmd) - 1;
		list.style.top = getAbsTop(txtcmd) + 30;
		list.style.display = 'block';
		droplistid = listid;
		var evt=aevent?aevent:event;
		evt.cancelBubble = true;
	}
}

function drawdrop() {
	if (droplistid) {
		drawit(droplistid);
		droplistid = null;
	}
}

function drawit(listid) {
	var list = document.getElementById(listid);
	if (list) {
		list.style.display = 'none';
	}
}

var fitem = null;
function itemfocus(nitem) {
	if (nitem) {
		nitem.bgColor = '#939393';
		if (fitem) {
			fitem.bgColor = '#EBEBEB';
		}
		fitem = nitem;
	}
}

function itemlost(nitem) {
	if (nitem) {
		nitem.bgColor = '#EBEBEB';
		
	}
	if (fitem) {
		fitem.bgColor = '#EBEBEB';
	}
	fitem = null;
}

var currentItem = null;
function itemselect(obj, listid, val) {
	//选择样式
	if (onitemchanged)
	{
		if (!onitemchanged(obj, listid, val)) 
		{
			return;
		}
	}
	

	var cmd = document.getElementById(listid + 'val');
	if (cmd) {
		cmd.value =  val;
		var txt = document.getElementById(listid + 'txt');
		if (txt) {
			txt.innerHTML = obj.innerHTML;
		}
		drawit(listid);
	}
	if (!currentItem) {
		currentItem = document.getElementById(listid + 'sel');
	}
	
	if (currentItem) {
		currentItem.bgColor = '#ebebeb';
		obj.bgColor = '#939393';
		currentItem = obj;
	}

	if (typeof(onitemready) != 'undefined')
	{
		onitemready(obj, listid, val);
	}
}

function onitemchanged() {}

function focusrect(listid) {
	var cmd = document.getElementById(listid + '_rect');
	if (cmd) {
		cmd.style.display = 'block';
	}
	if (listid == 'sleeve') {
		var cmd = document.getElementById('big' + listid + '_rect');
		if (cmd) {
			cmd.style.display = 'block';
		}
	}
}

function lostrect(listid) {
	var cmd = document.getElementById(listid + '_rect');
	if (cmd) {
		cmd.style.display = 'none';
		var cmd = document.getElementById('big' + listid + '_rect');
		if (cmd) {
			cmd.style.display = 'none';
		}
	}
}

var ImageIdx = 4;
function buildCombo(comboList, h, w, cmdname, cmdval, readonly) {
	var isread = false;var isfound=false;
	var cmdval0 = '';var cmdpic='';var cmdcap='';
	if (typeof(readonly) != 'undefined') {
		if (readonly == 'true') {
			isread = true;
		}
	}
	
	var cmdtxt = '&nbsp;';
	for (var i=0; i<comboList.length; i++) {
		if (nooptionids.indexOf(',' + comboList[i][0] + ',')<0) {
			if (cmdval0 == '') {
				cmdval0 = comboList[i][0];
				cmdpic = comboList[i][1];
				cmdcap = comboList[i][2];
			}
			if (cmdval == comboList[i][0]) {
				isfound = true;
				cmdpic = comboList[i][1];
				cmdcap = comboList[i][2];
				break;
			}
		}
	}
	if (isfound == false) {
		//如果没有找到，则取默认第一个。
		cmdval = cmdval0;
	}

	cmdtxt = '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	cmdtxt = cmdtxt + '<tr><td width=1>';
	if (cmdpic != '') {
		cmdtxt = cmdtxt + '<img src="' + cmdpic + '" border=0 width=26 height=26></td><td>' + cmdcap +
					   '</td></tr></table>';
	} else {
		cmdtxt = cmdtxt + '</td><td>' + cmdcap + '</td></tr></table>';
	}

	var wl = w + 2;
	if (isread == true) {
		io.write('<div style="width:' + w +'px;background-image:url(/images2/combo/droplistbg.gif); left:12px; position:relative;" ' +
		' onmouseover="javascript:void focusrect(\'' + cmdname + 
		'\');" onmouseout="javascript:void lostrect(\'' + cmdname + '\');">');
	}else{
		io.write('<div style="width:' + w +'px;background-image:url(/images2/combo/droplistbg.gif); left:12px; position:relative; cursor:pointer;" ' +
		' onClick="javascript:void dropit(event, this, \'' + cmdname + '\');" onmouseover="javascript:void focusrect(\'' + cmdname + 
		'\');" onmouseout="javascript:void lostrect(\'' + cmdname + '\');">');
	}
	
	io.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" height=34>');
	io.write('<tr>');
	io.write('<td width="1"><img src="/images2/combo/dropleft.gif" width="3" height="34" /></td>');
	io.write('<td id="' + cmdname + 'txt">' + cmdtxt + '</td>');
	if (isread == true) {
		io.write('<td width="1" valign="middle"><img src="/images2/combo/dropdivright.gif"></td>');
	}else{
		io.write('<td width="1" valign="middle" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image' + 
					ImageIdx + '\',\'\',\'/images2/combo/hdropbutton.gif\',1)"><img src="/images2/combo/dropbutton.gif" name="Image' + 
					ImageIdx + '" width="28" height="28" border="0"></td>');
	}
	io.write('<td width="1" valign="middle"><img src="/images2/combo/dropright.gif" width="2" height="34" /></td>');
	io.write('</tr>');
	io.write('</table>');
	io.write('</div>');
	io.write('<div style="position:absolute; display:none; width:' + wl + 'px; cursor:pointer; z-index:1000" id="' + cmdname + '">');
	io.write('<input type=hidden name="' + cmdname + 'val" id="' + cmdname + 'val" value="' + cmdval +'" />');
	io.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
	io.write('<tr>');
	io.write('<td width="3" background="/images2/combo/dropleftbg.gif"></td>');
	io.write('<td align="left" valign="top" bgcolor="EBEBEB" style="border:1px #939393 solid">');
	io.write('<span style="overflow-y:auto; height:' + h + 'px; width:100%">');
	io.write('<table width="100%" border="0" cellspacing="0" cellpadding="3">');
	for (var i=0; i<comboList.length; i++) {
		if (nooptionids.indexOf(',' + comboList[i][0] + ',')<0) {
			io.write('<tr onMouseOver="javascript:void itemfocus(this);" onMouseOut="javascript:void itemlost(this);">');
			if (cmdval == comboList[i][0]) {
				io.write('<td bgcolor="#939393" id="' + cmdname + 'sel" onClick="javascript:void itemselect(this, \'' + cmdname + '\', \'' + comboList[i][0] + '\');">');
			}else {
				io.write('<td onClick="javascript:void itemselect(this, \'' + cmdname + '\', \'' + comboList[i][0] + '\');">');
			}
			io.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
			io.write('<tr><td width=1>');
			if (comboList[i][1] != '') {
				io.write('<img src="' + comboList[i][1] + '" border=0 width=26 height=26></td><td>' + comboList[i][2] +
							   '</td></tr></table>');
			} else {
				io.write('</td><td>' + comboList[i][2] + '</td></tr></table>');
			}
			io.write('</td></tr>');
		}
    }

	io.write('</table>');
	io.write('</span>');
	io.write('</td>');
	io.write('<td width="3" background="/images2/combo/droprightbg.gif"></td>');
	io.write('</tr>');
	io.write('<tr height="3">');
	io.write('<td background="/images2/combo/dropleftbg.gif"></td>');
	io.write('<td height="3" background="/images2/combo/dropbottombg.gif"></td>');
	io.write('<td background="/images2/combo/droprightbg.gif"></td>');
	io.write('</tr>');
	io.write('</table>');
	io.write('</div>');
	if (window.document.readyState == 'complete') {
		var s = io.read();
		io.close();
		return s;
	}else{
		document.write(io.read());
		io.close();
	}
	
	ImageIdx = ImageIdx + 1;
}

function requestAjax(url, jsid) {
	var jselm = document.getElementById(jsid);
	var loadjs;
	var jsparent;
	
	if(jselm) {
		jsparent = jselm.parentNode;
		jsparent.removeChild(jselm);
	}
	loadjs = document.createElement('script');
	loadjs.language = 'javascript';
	loadjs.id= jsid;
	loadjs.src = url;
	document.body.appendChild(loadjs);
}