	/**
	 * MULTISELECT CONTROL conponent
	 */
	/** constant **/
	MultiSelect.SELECTMODE_SINGLE = 1;
	MultiSelect.SELECTMODE_MULTIPLE = 2;
	MultiSelect.SELECTMODE_SINGLEPAGE_SINGLESELECT = 3;
	MultiSelect.MS_PREFIX = "ms_";
	MultiSelect.width = 180;
	
	/* manager */
	function MultiSelectManager(){
		this.multiSelects = new Array();
		
		this.registerMultiSelect = function(newMS){
			if(newMS == null)
				return;
				
			newMS.id = this.multiSelects.length;
			
			this.multiSelects[this.multiSelects.length] = newMS;
		}
		
		/*  */
		this.getMultiSelectById = function(id){
			if(id == null) return;
		
			for(var n=0;n<this.multiSelects.length;n++){
				if(this.multiSelects[n].id == id)
					return this.multiSelects[n];
			}
			
			return null;
		}
	}
	
	var msManager = new MultiSelectManager();
	
	function MultiSelect(name, data){
		if(data == null)
			alert("data can not be null");
		
		this.id = null;
		
		this.data = data;
		
		this.mandatoryId = null;
		
		this.selectedIds = new Array();
		this.tmpSelectedIds = new Array();
		
		/** 1=checkbox, 2=radio, 3=singlePageSingleSelectCheckbox **/
		this.selectMode = null;
		
		this.name = name;
		
		this.canAdd = false;
		
		this.maxSelectedNumber = 5;
		
		this.currentSubType = 0;
		
		this.disabled = false;
		
		this.popupWin = new PopupWindow();
		
		this.associateSubtypeMultiSelectId = null;
		
		this.searchCriteria = null;
		
		this.setMaxHeight = function(height){
			if(height){
				this.popupWin.setMaxHeight(height);
			}
		};
		
		this.getMultiSelectId = function(){
			return this.getInstancePrefix() + this.name;
		}
		
		this.setSelectedIdStr = function(idStr){
			if(idStr == null || trim(idStr) == "" || this.data == null || this.data.length <= 2) return;
			
			this.selectedIds = new Array();
			
			var ids = idStr.split(",");
			
			for(var idCounter=0;idCounter<ids.length;idCounter++){
				if(this.data != null && this.data.length > 2 && this.data[2] != null && hasType(this.data)){
					
					for(var n=2;n<this.data.length;n++){
						for(var i=2;i<this.data[n].length;i++){
							if(this.data[n][i][0] == ids[idCounter]){
								this.selectedIds[this.selectedIds.length] = ids[idCounter];
								break;
							}
						}
					}
					
				}
				else{
					for(var n=2;n<this.data.length;n++){
						if(this.data[n][0] == ids[idCounter]){
							this.selectedIds[this.selectedIds.length] = ids[idCounter];
							break;
						}
					}
				}
			}
			
		}
		
		this.addSelectedId = function(newId){
			if(newId == null) return;
			
			for(var n=0;n<this.selectedIds.length;n++){
				if(this.selectedIds[n] == newId)
					return;
			}
			
			this.selectedIds[this.selectedIds.length] = newId;
		}
		
		this.removeSelectedId = function(idToRemove){
			if(idToRemove == null) return;
			
			var result = new Array();
			
			for(var n=0;n<this.selectedIds.length;n++){
				if(this.selectedIds[n] == idToRemove)
					continue;
				
				result[result.length] = this.selectedIds[n];
			}
			
			this.selectedIds = result;
			
			this.fireEvent("onSubmit");
		}
		
		this.getSelectedIdStr = function(){
			if(this.data == null || this.selectedIds.length <= 0)
				return "";
			
			var result = "";
			
			for(var n=0;n<this.selectedIds.length;n++){
				if(n == 0)
					result += this.selectedIds[n];
				else
					result += ("," + this.selectedIds[n]);
			}
			
			return result;
		}
		
		this.getAllSelectedInfo = function(){
			if(this.data == null || this.selectedIds.length <= 0)
				return new Array();
			
			var result = new Array();
			
			for(var n=0;n<this.selectedIds.length;n++){
				var singleSelectedInfo = this.getSelectedItemInfoById(this.selectedIds[n]);
				result[result.length] = singleSelectedInfo;
			}
			//singleSelectedInfo.parentName + "&gt;" + singleSelectedInfo.selectedName
			return result;
		}
		
		this.getAllTmpSelectedInfo = function(){
			if(this.data == null || this.tmpSelectedIds.length <= 0)
				return new Array();
			
			var result = new Array();
			//alert(this.tmpSelectedIds);
			for(var n=0;n<this.tmpSelectedIds.length;n++){
				var singleSelectedInfo = this.getSelectedItemInfoById(this.tmpSelectedIds[n]);
				result[result.length] = singleSelectedInfo;
			}
			//singleSelectedInfo.parentName + "&gt;" + singleSelectedInfo.selectedName
			return result;
		}
		
		/* get single selected id full info */
		this.getSelectedItemInfoById = function(curId){
			if(curId == null || this.data == null || this.selectedIds.length <= 0)
				return null;
			
			var parentName = null;
			var selectedName = null;
			var selectedId = null;
			
			//no type
			if(!hasType(this.data)){
				for(var n=2;n<this.data.length;n++){
					if(this.data[n][0] == curId){
						selectedName = this.data[n][1];
						selectedId = this.data[n][0];
						break;
					}
				}
			}
			//has type
			else if(hasType(this.data)){
				for(var n=2;n<this.data.length;n++){
					for(var i=2;i<this.data[n].length;i++){
					
						if(this.data[n][i][0] == curId){
							parentName = this.data[n][1];
							selectedId = this.data[n][i][0];
							selectedName = this.data[n][i][1];
							break;
						}
					}
				}
			}
			
			return {parentName:parentName, selectedName:selectedName, selectedId:selectedId};
		}
		
		this.getInstancePrefix = function(){
			return MultiSelect.MS_PREFIX + this.id + "_";
		}
		
		this.generateHtml = function(){
			//register
			if(this.id == null){
				msManager.registerMultiSelect(this);
				
				this.popupWin.attachEvent("onSubmit", "msManager.getMultiSelectById(" + this.id + ").submitPopup()");
				this.popupWin.attachEvent("onClose", "msManager.getMultiSelectById(" + this.id + ").setDropdownButtonFocus()");
			}
			//init currentSubType
			if(this.data != null && this.data.length > 2 && this.data[2] != null && hasType(this.data))
				this.currentSubType = this.data[2][0];
			
			var popupScript = 'msManager.getMultiSelectById(' + this.id + ').popup()';
			
			var html = '<div id="' + this.getInstancePrefix() + 'container" onclick="' + (this.disabled?"":popupScript) + '" style="cursor:pointer;font-size:12px;width:' + (MultiSelect.width - 2) + 'px;border:1px solid;border-color:#808080;background-color:white;float:left">';
			html += this.generateBaseInternalHtml();
			html += '</div>';
			
			return html;
		}
		
		this.create = function(){
			document.write(this.generateHtml());
		}
		
		this.refresh = function(){
			document.getElementById(this.getMultiSelectId()).value = this.getSelectedIdStr();
			
			var containerObj = document.getElementById(this.getInstancePrefix() + "container");
			
			containerObj.innerHTML = this.generateBaseInternalHtml();
		}
		
		//--------------
		
		this.popup = function(){
			if(this.data == null) return;
			
			//设置默认打开页
			if(this.associateSubtypeMultiSelectId != null && msManager.getMultiSelectById(this.associateSubtypeMultiSelectId).selectedIds != null
				&& msManager.getMultiSelectById(this.associateSubtypeMultiSelectId).selectedIds.length > 0){
				this.currentSubType = msManager.getMultiSelectById(this.associateSubtypeMultiSelectId).selectedIds;
			}

			//不管是不是新开窗口，都重新设置parent
			this.popupWin.parentObj = document.getElementById(this.getInstancePrefix() + "container");
						
			//设置临时选择缓冲
			this.tmpSelectedIds = new Array();
			for(var n=0;n<this.selectedIds.length;n++){
				this.tmpSelectedIds[this.tmpSelectedIds.length] = this.selectedIds[n];
			}

			this.popupWin.title = this.data[1]; 

			this.popupWin.content = this.generatePopupInternalHtml();
			this.popupWin.toolbar = this.generateButtonDiv();
			
			this.popupWin.popup();
			
			if(this.popupWin.isShown()){
				if(this.data != null && this.data.length > 2){
					if(this.data[2] != null && hasType(this.data)){
						try{
							document.getElementById(this.getInstancePrefix() + 'select').focus();
						}catch(E){}
					}
					else{
						var firstOption = document.getElementById(this.getInstancePrefix() + this.getSubTypeDataById(this.currentSubType)[0][0] + '_value');
						if(firstOption != null && !firstOption.disabled){
							try{
								firstOption.focus();
							}catch(E){}
						}
						else{
							//无法置第一个选项焦点就置第二个，如果没有第二个就置在确定按钮上
							if(this.getSubTypeDataById(this.currentSubType).length > 1){
								var secondOption = document.getElementById(this.getInstancePrefix() + this.getSubTypeDataById(this.currentSubType)[1][0] + '_value');
								if(secondOption != null && !secondOption.disabled)
									secondOption.focus();
								else{
									var okButton = document.getElementById(this.getInstancePrefix() + "ok");
									
									if(okButton != null)
										okButton.focus();
								}
							}
						}
					}
				}
				else{
					var okButton = document.getElementById(this.getInstancePrefix() + "ok");
					if(okButton != null)
						okButton.focus();
				}
			}
		}
		
		this.changeTmpSelectId = function(optionObj){
			if(optionObj == null) return;
			
			if(this.selectMode == MultiSelect.SELECTMODE_SINGLE){
				this.tmpSelectedIds = [optionObj.value];
			}
			else if(this.selectMode == MultiSelect.SELECTMODE_SINGLEPAGE_SINGLESELECT){
				var allOptions = document.getElementsByName(optionObj.name);
				
				if(allOptions != null && allOptions.length > 0){
					for(var n=0;n<allOptions.length;n++){
						this.removeTmpSelectedId(allOptions[n].value);
					}
				}
				if(this.checkMaxSelect(optionObj))
					this.addTmpSelectedId(optionObj.value);
			}
			else if(this.selectMode == MultiSelect.SELECTMODE_MULTIPLE){
				if(optionObj.checked){
					if(this.checkMaxSelect(optionObj))
						this.addTmpSelectedId(optionObj.value);
				}
				else
					this.removeTmpSelectedId(optionObj.value);
			}
		}
		
		this.checkMaxSelect = function(optionObj){
			if((this.maxSelectedNumber > 0) && this.tmpSelectedIds.length >= this.maxSelectedNumber){
				alert("最多可以选择[" + this.maxSelectedNumber + "]个选项");
				optionObj.checked = false;
				
				return false;
			}
			
			return true;
		}
		
		this.addTmpSelectedId = function(newId){
			if(newId == null) return;
			
			for(var n=0;n<this.tmpSelectedIds.length;n++){
				if(this.tmpSelectedIds[n] == newId)
					return;
			}
			
			this.tmpSelectedIds[this.tmpSelectedIds.length] = newId;
		}
		
		this.removeTmpSelectedId = function(idToRemove){
			if(idToRemove == null) return;
			
			var result = new Array();
			
			for(var n=0;n<this.tmpSelectedIds.length;n++){
				if(this.tmpSelectedIds[n] == idToRemove)
					continue;
				
				result[result.length] = this.tmpSelectedIds[n];
			}
			
			this.tmpSelectedIds = result;
			
		}
		
		/** submit popup window */
		this.submitPopup = function(){
			this.selectedIds = this.tmpSelectedIds;
			
			closeCurrentPopup();
			
			this.setDropdownButtonFocus()
			
			this.refresh();
			
			/*if(this.associateSubtypeMultiSelectId != null){
				msManager.getMultiSelectById(this.associateSubtypeMultiSelectId).setSelectedIdStr(""+this.currentSubType);
				
				msManager.getMultiSelectById(this.associateSubtypeMultiSelectId).refresh();
			}*/
			
			this.fireEvent("onSubmit");
		}
		
		this.getSubTypeDataById = function(subTypeId){
			if(this.data == null || this.data.length <=0) return null;
			
			var result = new Array();
			
			if(this.data != null && this.data.length > 2 && this.data[2] != null && hasType(this.data)){
				if(subTypeId == null) return null;
				for(var n=0;n<this.data.length;n++){
					if(subTypeId == this.data[n][0]){
						for(var i=2;i<this.data[n].length;i++){
							result[result.length] = this.data[n][i];
						}
						
						return result;
					}
				}
				
				return null;
			}
			else{
				for(var n=2;n<this.data.length;n++){
					result[result.length] = this.data[n];
				}
				
				return result;
			}
		}
		
		this.addNewValue = function(newId, newValue){
			if(newId==null || trim(newId) == "" || newValue==null || trim(newValue) == "")
				return;
			
			if(this.data != null && this.data.length > 2 && this.data[2] != null && hasType(this.data)){
				for(var n=0;n<this.data.length;n++){
					if(this.currentSubType == this.data[n][0]){
						//alert(this.data[n]);
						if(this.data[n][2] != null && this.data[n][2] != "")
							this.data[n][this.data[n].length] = [newId, newValue];
						else
							this.data[n][2] = [newId, newValue];
						
						break;
					}
				}
				
			}
			else{
				this.data[this.data.length] = [newId, newValue];
			}
		}
		
		//--------------
		
		this.setDropdownButtonFocus = function(){
			var dropdownButton = document.getElementById(this.getInstancePrefix() + 'dropdownButton');

			if(dropdownButton != null){
				try{
					setTimeout("document.getElementById('" + this.getInstancePrefix() + "dropdownButton').focus()", 10);
				}catch(e){}
			}
		}
		
		this.generateBaseInternalHtml = function(){
			var html = '<input ' + (this.disabled?'disabled':'') + ' type="hidden" id="' +this.getMultiSelectId()+ '" name="' + this.name + '" value="' + this.getSelectedIdStr() + '">';
			
			html += '<table cellpadding="1" cellspacing="1" style="width:' + (MultiSelect.width-2) + 'px;font-size:12px;background-color:#EFEFEF" id="table1">';
			
			var selectedInfo = this.getAllSelectedInfo();
			
			if(selectedInfo.length <= 0){
				selectedInfo[0] = '';
			}
			
			var popupScript = 'msManager.getMultiSelectById(' + this.id + ').popup()';
			
			for(var n=0;n<selectedInfo.length;n++){
				html += '	<tr>';
				html += '		<td width="' + (MultiSelect.width-38) + '" style="' + ((n == 0 && selectedInfo == '')?'':'background-color:white;') + '">';
				html += (n == 0 && selectedInfo == '')?'<div style="width:' + (MultiSelect.width-40) + 'px;height:15px;overflow:hidden">&nbsp;</div>':'			<div style="width:' + (this.disabled?(MultiSelect.width-6):(MultiSelect.width-40)) + 'px;font-size:12px;color:blue;border:0px;height:15px;overflow:hidden" nowrap title="' + (selectedInfo[n].parentName != null?selectedInfo[n].parentName + '-&gt;':'') + (selectedInfo[n].selectedName != null?selectedInfo[n].selectedName:'') + '">' + (selectedInfo[n].parentName != null?selectedInfo[n].parentName + '-&gt;':'') + (selectedInfo[n].selectedName != null?selectedInfo[n].selectedName:'') + '</div>';
				html += '		</td>';
				if(!this.disabled){
					html += '		<td width="14" style="width:14px">';
					if(selectedInfo[n].selectedId != this.mandatoryId){
						html += (n == 0 && selectedInfo == '')?'<div style="width:14px;height:15px">&nbsp;</div>':'			<img onclick="msManager.getMultiSelectById(' + this.id + ').removeSelectedId(' + selectedInfo[n].selectedId + ');msManager.getMultiSelectById(' + this.id + ').refresh()" src="../../imgs/icon_delete.gif" style="margin-left:1px;margin-top:2px;cursor:pointer" alt="删除当前选项" border="0">';
					}
					else{
						html += '<div style="width:12px;height:14px">&nbsp;</div>';
					}
					html += '		</td>';
				}
				//first row, add dropdown icon
				if(!this.disabled && n == 0){
					html += '		<td rowspan="1000" height="100%" width="100%" style="background-color:white;" align="center">';
					html += '			<table onclick="' + popupScript + '" style="cursor:pointer;width:12px;border:1px solid;border-color:#EFEFEF;" cellpadding="0" cellspacing="0" width="100%" height="100%" border="0" onmouseover="hightlightBorder(this)" onmouseout="dehightlightBorder(this)">';
					html += '				<tr><td align="center"><img style="margin:3px" src="../../imgs/down.gif" border="0"></td></tr>';
					html += '			</table>';
					html += '		</td>';
				}
				html += '	</tr>';
			}
			html += '</table>';
			
			return html;
		}
		
		this.generatePopupInternalHtml = function(){
			var html = "";
			
				html += "<div style='margin-left:4px'>Search:<input id='" + this.getInstancePrefix() + "searchCriteria' type='text' value='" + (this.searchCriteria != null?this.searchCriteria:"") + "' onkeypress='if(event.keyCode == 13){msManager.getMultiSelectById(" + this.id + ").searchCriteria = this.value;msManager.getMultiSelectById(" + this.id + ").refreshSearchResultDiv(this.value)}' class='thin_border_ele' style='width:120px'></div>";
				
				html += "<hr>";
				
				html += "<div style='display:" + ((this.searchCriteria != null && this.searchCriteria.length > 0)?"none":"block") + "' id='" + this.getInstancePrefix() + "subTypeOptionsDiv'>";
				if(this.data != null && this.data.length > 2 && this.data[2] != null && hasType(this.data)){
					html += this.generateSubTypeDiv();
				}
				html += "<div style='font-size:12px' id='" + this.getInstancePrefix() + "subtypeValueDiv' style='margin:2px'>";
				html += this.generateValueDiv(this.currentSubType);
				html += "</div>";
				
				html += "<div style='font-size:12px' align='right' style='margin:2px;margin-top:4px;padding-top:4px;border-top:1px dashed;'>";
				//html += this.generateButtonDiv();
				html += "</div>";
				html += "</div>";
				
				html += "<div style='display:" + ((this.searchCriteria != null && this.searchCriteria.length > 0)?"block":"none") + "' id='" + this.getInstancePrefix() + "searchResultDiv'>";

				html += this.generateSearchResultValueDiv(this.searchCriteria);
			
				html += "</div>";
			
			return html;
		}
		
		this.refreshValueDiv = function(addNew){
			document.getElementById(this.getInstancePrefix() + "subtypeValueDiv").innerHTML = this.generateValueDiv(this.currentSubType, addNew);
			if(addNew){
				setTimeout('document.getElementById("' + this.getInstancePrefix() + 'newValue").focus()', 10);
			}
			
			this.popupWin.reinit();
		}
		
		this.refreshSearchResultDiv = function(criteria){
			
			if(criteria != null && criteria.length > 0){
				document.getElementById(this.getInstancePrefix() + "subTypeOptionsDiv").style.display = "none";
				document.getElementById(this.getInstancePrefix() + "searchResultDiv").style.display = "";
				
				if(document.getElementById(this.getInstancePrefix()+ "newValueButton") != null)
					document.getElementById(this.getInstancePrefix()+ "newValueButton").disabled = true;
					
				if(document.getElementById(this.getInstancePrefix() + "selectAll") != null)
					document.getElementById(this.getInstancePrefix() + "selectAll").disabled = true;
				
				document.getElementById(this.getInstancePrefix() + "searchResultDiv").innerHTML = this.generateSearchResultValueDiv(this.searchCriteria);
			}else{
				document.getElementById(this.getInstancePrefix() + "subTypeOptionsDiv").style.display = "";
				document.getElementById(this.getInstancePrefix() + "searchResultDiv").style.display = "none";
				
				if(document.getElementById(this.getInstancePrefix()+ "newValueButton") != null)
					document.getElementById(this.getInstancePrefix()+ "newValueButton").disabled = false;
					
				if(document.getElementById(this.getInstancePrefix() + "selectAll") != null)
					document.getElementById(this.getInstancePrefix() + "selectAll").disabled = false;
			}
			
			this.popupWin.reinit();
		}
		
		this.generateSearchResultValueDiv = function(criteria){
			var searchResult = this.getSearchResult(criteria);
			
			var valueType = "radio";
			
			if(this.selectMode == MultiSelect.SELECTMODE_MULTIPLE)
				valueType = "checkbox";
			
			var html = "";
			
			html += "<table width='100%' border='0' cellpadding='0' cellspacing='2'>";
			
			var searchResultLength = searchResult != null && searchResult != ""?searchResult.length:0;
			
			for(var n=0;n<searchResultLength;n++){
				
				if(n % 2 == 0)
					html += "	<tr>";
				html += "		<td nowrap='nowrap'><input onclick='msManager.getMultiSelectById(" +this.id+ ").changeTmpSelectId(this)'" + (this.mandatoryId==searchResult[n][0]?"disabled":"") + " " + (this.isSelected(searchResult[n][0])?"checked":"") + " name='" + this.getInstancePrefix() + "value' id='" + this.getInstancePrefix() +  searchResult[n][0] + "_value' type='" + valueType + "' value='" + searchResult[n][0] + "'><label style='font-size:12px' for='" + this.getInstancePrefix() + searchResult[n][0] + "_value'>" + searchResult[n][1] + "</label></td>";
				
				if(n % 2 == 1)
					html += "	</tr>";
			}
			
			html += "</table>";
			
			return html;
		}
		
		this.getSearchResult = function(criteria){
			criteria = criteria!=null?criteria.toLowerCase():null;
			
			var searchResult = new Array();
			if(this.data != null && this.data.length > 2 && this.data[2] != null && hasType(this.data)){
				for(var n=2;n<this.data.length;n++){
					for(var i=2;i<this.data[n].length;i++){
						if(this.data[n][i][1] != null && this.data[n][i][1].toLowerCase().indexOf(criteria)>=0){
							var nextResult = searchResult.length;
							searchResult[nextResult] = new Array();
							searchResult[nextResult][0] = this.data[n][i][0];
							searchResult[nextResult][1] = this.data[n][1] + "->" + this.data[n][i][1];
						}
					}
				}
			}
			else{
				for(var n=2;n<this.data.length;n++){
					if(this.data[n][1].toLowerCase().indexOf(criteria)>=0){
						var nextResult = searchResult.length;
						searchResult[nextResult] = new Array();
						searchResult[nextResult][0] = this.data[n][0];
						searchResult[nextResult][1] = this.data[n][1];
						
					}
				}
			}
			
			return searchResult;
		}
		
		this.events = new Array();
		
		/**
		 * event handling, supported events: onNewValueSave, onPopup
		 */ 
		this.attachEvent = function(eventType, eventFunc){
			if(eventType != null && eventFunc != null){
				if(eventType == "onNewValueSave")
					this.canAdd = true;
				
				this.events[this.events.length] = [eventType, eventFunc];
			}
		}
		
		/* fire event */
		this.fireEvent = function(eventType){
			if(eventType == null)
				return;
				
			for(var n=0;n<this.events.length;n++){
				if(this.events[n][0] == eventType){
					if(typeof(this.events[n][1]) == "string")
						eval(this.events[n][1]);
					else
						this.events[n][1](this);
				}
			}
		}
		
		this.confirmSaveNewValue = function(){
			if(trim(document.getElementById(this.getInstancePrefix() + "newValue").value) == ""){
				this.refreshValueDiv();
			}
			else{
				if(confirm("是否保存您新增添的选项?")){
					this.fireEvent("onNewValueSave");
				}
				else{
					this.refreshValueDiv();
				}
			}
			document.getElementById(this.getInstancePrefix()+ "newValueButton").focus();
		}
		
		this.changeCurrentSubType = function(subTypeId){
			if(subTypeId != null){
				this.currentSubType = subTypeId;
				
				if(document.getElementById(this.getInstancePrefix() + "selectAll") != null){
					document.getElementById(this.getInstancePrefix() + "selectAll").checked = false;
				}
			}
		}
		
		this.generateSubTypeDiv = function(){
			if(this.data == null) return "";
			
			var html = "<select style='color:#C39595;margin-left:4px' id='" + this.getInstancePrefix() + "select' onchange='msManager.getMultiSelectById(" + this.id + ").changeCurrentSubType(this.options[this.selectedIndex].value);msManager.getMultiSelectById(" + this.id + ").refreshValueDiv();'>";
			for(var n=2;n<this.data.length;n++){
				html += "<option " + (this.data[n][0] == this.currentSubType?"selected":"") + " value='" + this.data[n][0] + "'>" + this.data[n][1] + "</option>";
			}
			html += "</select>";
			
			return html;
		}
		
		this.handleNewValueKeypress = function(e){
			var evt = window.event?window.event:e;
			
			if(evt.keyCode == 13){
				document.getElementById(this.getInstancePrefix() + "newValue").blur();
			}
		}
		
		this.generateValueDiv = function(subTypeId, addNew){
			if((this.data == null || this.data.length<=2 || (this.data.length==3 && this.data[2] == "")) && !addNew) 
				return "无";
			
			var subTypeData = this.getSubTypeDataById(subTypeId);
			
			if((subTypeData == null || subTypeData.length <= 0 || subTypeData == "") && !addNew) return "无";
			
			//is multiple pages
			var multiPages = this.data != null && this.data.length>=2 && this.data[2] != null && hasType(this.data);
			
			var valueType = "radio";
			
			if(this.selectMode == MultiSelect.SELECTMODE_MULTIPLE)
				valueType = "checkbox";
			
			var html = "";
			
			html += "<table width='100%' border='0' cellpadding='0' cellspacing='2'>";
			
			var subTypeDataLength = subTypeData != null && subTypeData != ""?subTypeData.length:0;
			
			for(var n=0;n<subTypeDataLength;n++){
				
				if(n % 2 == 0)
					html += "	<tr>";
				html += "		<td nowrap='nowrap'><input onclick='msManager.getMultiSelectById(" +this.id+ ").changeTmpSelectId(this)'" + (this.mandatoryId==subTypeData[n][0]?"disabled":"") + " " + (this.isSelected(subTypeData[n][0])?"checked":"") + " name='" + this.getInstancePrefix() + "value' id='" + this.getInstancePrefix() +  subTypeData[n][0] + "_value' type='" + valueType + "' value='" + subTypeData[n][0] + "'><label style='font-size:12px' for='" + this.getInstancePrefix() + subTypeData[n][0] + "_value'>" + subTypeData[n][1] + "</label></td>";
				
				if(n % 2 == 1)
					html += "	</tr>";
			}
			
			if(addNew){
				if(subTypeDataLength %2 == 0){
					html += "	<tr>";
				}
				html+="<td>";
				
				html += "		<input onkeypress='msManager.getMultiSelectById(" +this.id+ ").handleNewValueKeypress(event)' onblur='msManager.getMultiSelectById(" +this.id+ ").confirmSaveNewValue()' id='" + this.getInstancePrefix() + "newValue' class='thin_border_ele' style='font-size:12px;width:120px'>";
				
				html += "	</td></tr>";
			}
			else{
				if(subTypeDataLength %2 == 1)
					html += "	</tr>";
			}
			
			html += "</table>";
			
			return html;
		}
		
		this.selectAll = function(checked){
			if(this.data != null && this.data.length > 2 && this.data[2] != null && hasType(this.data)){
				for(var n=2;n<this.data.length;n++){
					if(this.data[n][0] == this.currentSubType){
						for(var i=2;i<this.data[n].length;i++){
							if(this.data[n][i][0] != this.mandatoryId){
								if(checked)
									this.addTmpSelectedId(this.data[n][i][0]);
								else
									this.removeTmpSelectedId(this.data[n][i][0]);
							}
						}
					}
				}
			}
			else{
				for(var n=2;n<this.data.length;n++){
					if(this.data[n][0] != this.mandatoryId){
						if(checked)
							this.addTmpSelectedId(this.data[n][0]);
						else
							this.removeTmpSelectedId(this.data[n][0]);
					}
				}
			}
			this.refreshValueDiv();
		}
		
		this.generateButtonDiv = function(){
			var html = "";
			
			html += "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
			html += "	<tr>";
			if(this.data != null && this.data.length > 2 && this.selectMode != MultiSelect.SELECTMODE_SINGLE && this.maxSelectedNumber <= 0){
				html += "<td align='left'>";
				html += "<input type='checkbox' onclick='msManager.getMultiSelectById(" +this.id+ ").selectAll(this.checked);' id='" + this.getInstancePrefix() + "selectAll'><label style='font-size:12px;color:blue;' for='" +this.getInstancePrefix()+ "selectAll'>全选</label>";
				html += "</td>";
			}
			
			html += "<td align='right'>";
			html += "<input type='button' style='font-size:12px;margin-left:2px;margin-right:2px' value='OK' id='" +this.getInstancePrefix()+ "ok' onclick='msManager.getMultiSelectById(" +this.id+ ").submitPopup()'>";
			
			if(this.canAdd)
				html += "<input id='" +this.getInstancePrefix()+ "newValueButton' type='button' style='font-size:12px;margin-left:2px;margin-right:2px' value='Add' onclick='msManager.getMultiSelectById(" +this.id+ ").refreshValueDiv(true)'>";
			
			html += "<input type='button' style='font-size:12px;margin-left:2px;margin-right:20px' value='Close' onclick='closeCurrentPopup();msManager.getMultiSelectById(" + this.id + ").setDropdownButtonFocus()'>";
			html += "</td>"
			html += "</tr>"
			html += "</table>"
			return html;
		}
		
		this.isSelected = function(curId){
			if(this.tmpSelectedIds == null || curId == null) return false;
			for(var n=0;n<this.tmpSelectedIds.length;n++){
				if(curId == this.tmpSelectedIds[n])
					return true;
			}
			
			return false;
		}
	}
	
	function hightlightBorder(obj){
		if(obj == null)
			return;
		
		obj.style.borderColor='#808080';
	}
	
	function dehightlightBorder(obj){
		if(obj == null)
			return;
		
		obj.style.borderColor='#EFEFEF';
	}

	/**
	 * 2010-08-04 15:05
	 * @author wavesun
	 * 将该方法替换掉原来的 this.data[2].length > 2 和 this.data[2].length == 2
	 * 修正
	 * 		当第一个类型没有子项时使两级multiselect退化成一级
	 * 的bug
	 */
	function hasType(data){
		for(var i = 2; i < data.length; i ++){
			if(data[i].length > 2){
				return true;
			}
		}
		return false;
	}