﻿	//鏋勯€犲嚱鏁?
	function multipleSelect(mSelectId, data) {
		//鐩稿叧id鍜屾暟鎹?
		this.mSelectId = mSelectId;
		this.data = data;
		this.opened = false;
		this.check = this.data.split(",");		

		//鐩稿叧瀵硅薄
		this.obj = document.getElementById(mSelectId);
		this.objDisplay = document.getElementById(this.mSelectId + "_display");
		this.objDesc = document.getElementById(this.mSelectId + "_desc");
		this.children = this.objDisplay.getElementsByTagName("input");

		//鍑芥暟
		this.multipleClose = multipleClose;
		this.multipleOpen = multipleOpen;
		this.multipleClick = multipleClick;
		this.multipleInit = multipleInit;
		this.multipleClear = multipleClear;
		this.clearOnDeleteKeyDown = clearOnDeleteKeyDown;
		this.clearMultipleOption = clearMultipleOption;
		this.addMultipleOption = addMultipleOption;
		this.multipleLoaded = multipleLoaded;
		this.fetchMultipleSelectData = fetchMultipleSelectData;
		this.mSelectDependOnInit = mSelectDependOnInit;

		this.multipleInit();
	}
	
	//鍏抽棴灞?
	function multipleClose() {
		//鍏抽棴
		this.opened = false;		
		this.objDisplay.style.display = "none";
		
		//娓呯┖
		this.objDesc.value = "";
		this.obj.value = "";
		
		//閲嶆柊璧嫔€?
		for (i = 0;i < this.children.length;i ++) {
			if (this.children[i].checked) {
				this.objDesc.value = this.objDesc.value + " " + this.children[i].nextSibling.nodeValue;
				this.obj.value = this.obj.value + "," + this.children[i].value;
			}
		}
		this.obj.value = this.obj.value.substring(1);
		this.objDesc.value = this.objDesc.value.substring(1);
	}
	
	//镓揿紑灞?
	function multipleOpen() {		
		//缃墦寮€镄勬爣蹇?
		this.opened = true;
		
		
		//婊氩姩瀹氢綅xy
		var sLeft = 0;
		var sTop = 0;
		if (document.getElementsByName("body").length != 0) {
			var sLeft = document.body.scrollLeft;
			var sTop = document.body.scrollTop;
		}
		
		//瀹氢綅灞傜殑xy
		dTop = getBoundingClientBottom(this.objDesc) + sTop;
		dLeft = getBoundingClientLeft(this.objDesc) + sLeft;

		this.objDisplay.style.left = dLeft;
		this.objDisplay.style.top = dTop;
		this.objDisplay.style.display = "block";
	}
	
	//鎸夐挳
	function multipleClick() {
		if (!this.opened)
			this.multipleOpen();
		else
			this.multipleClose();
	}
	
	//鍒濆鍖栨带浠?
	function multipleInit() {
		if (this.data == "" || this.data == null) return false;		
		this.opened = false;
			
		this.objDisplay.style.display = "none";
		this.obj.value = "";
		this.objDesc.value = "";
						
		for (i = 0;i < this.check.length;i ++) {
			for (j = 0; j < this.children.length; j++) {
			    if (this.children[j].value == this.check[i]) {
			        this.children[j].checked = true;
					this.objDesc.value = this.objDesc.value + " " + this.children[j].nextSibling.nodeValue;
					this.obj.value = this.obj.value + "," + this.children[j].value;
					break;
			    }
			}
		}
		this.obj.value = this.obj.value.substring(1);
		this.objDesc.value = this.objDesc.value.substring(1);
		return true;
	}
	
	//娓呯┖宸茬粡阃夋嫨寰楀€?
	function multipleClear() {

		this.obj.value = "";
		this.objDesc.value = "";
		if (this.children) {
			for (i = 0; i < this.children.length; i++) {
				this.children[i].checked = false;
			}
		}
	}
	
	//褰撴寜delete镞跺缑娓呯┖
	function clearOnDeleteKeyDown(event) {
		event.returnValue = false;
		if (event.keyCode == 46) {			
			this.multipleClear();
		}
		return false;
	}

	//娓呯┖阃夐」
	function clearMultipleOption() {
		if (typeof this.onunload == "function") {
			this.onunload();
		}
				
		for (k = this.children.length - 1; k >= 0 ; k --) {
			//绉婚櫎<br>
			this.objDisplay.removeChild(this.children[k].nextSibling.nextSibling);
			//绉婚櫎阃夐」镄勬枃瀛?
			this.objDisplay.removeChild(this.children[k].nextSibling);
			//绉婚櫎input
			this.objDisplay.removeChild(this.children[k]);
		}
		//閲嶆柊缁檆hildren璧嫔€?
		this.children = this.objDisplay.getElementsByTagName("input");
		this.obj.value = "";
		this.objDesc.value = "";
	}
	
	//娣诲姞鏂扮殑阃夐」
	function addMultipleOption(value, text) {
		//checkbox
		var optionObj = document.createElement("INPUT");
		//br
		var brObj = document.createElement("BR");
		//鏂囨湰
		var textObj = document.createTextNode(text);
		optionObj.name = "a1";
		optionObj.type = "CHECKBOX";
		optionObj.value = value;
						
		//娣诲姞
		this.objDisplay.appendChild(optionObj);
		this.objDisplay.appendChild(textObj);
		this.objDisplay.appendChild(brObj);
		
		//鍒濆鍖栭€夌殑链?
		if (this.check) {
			for (i = 0;i < this.check.length;i ++) {
			    if (value == this.check[i]) {
			    	optionObj.checked = true;
			    	if (this.objDesc.value == "")
			    		this.objDesc.value = text;
			    	else
			    		this.objDesc.value = this.objDesc.value + " " + text;
			    	
			    	if (this.obj.value == "")
				    	this.obj.value = value;
			    	else
						this.obj.value = this.obj.value + "," + value;
						
					
			    	
			    	break;
			    }
			}
		}
						
		//鍒锋柊children
		this.children = this.objDisplay.getElementsByTagName("input");
	}

	
	function fetchMultipleSelectData(param) {
		frmObj = document.getElementsByName("iFrameMultipleSelect_" + this.mSelectId)[0];
		src = frmObj.getAttribute("url");
		if (param)
			src += "&" + param;
		frmObj.src = src;
	}
	
	function multipleLoaded() {			
		if (typeof this.onload == "function") {
			this.onload();
		}
	}
	
	function mSelectDependOnInit(dependOnId, weekDepend, dependParam) {
		var obj = this;
		eval("var " + obj.mSelectId + "PreChangeFun = function() {}");
		if (document.getElementById(dependOnId).onchange) {
			eval(obj.mSelectId + "PreChangeFun = document.getElementById(dependOnId).onchange;");
		}
		
		document.getElementById(dependOnId).onchange = function (dependObj) {
			if (!dependObj || dependObj == '[object Event]') dependObj = this;
			eval(obj.mSelectId + "PreChangeFun(dependObj);");

			if (dependObj.value && dependObj.value != "") {
				if (dependParam)
					obj.fetchMultipleSelectData(dependParam+"=" + dependObj.value);
				else
					obj.fetchMultipleSelectData(dependObj.name+"=" + dependObj.value);				
			} else {
				if (weekDepend)
					obj.fetchMultipleSelectData();
				else
					obj.clearMultipleOption();
			}
				
		}

		document.getElementById(dependOnId).onchange();
	}




