
function SubSelectObj(id, pid, name) {
	this.id = id;
	this.pid = pid;
	this.name = name;
}
/* 构造一个子下拉菜单 
		*   用传入的下拉菜单选项元素 构造一个下拉菜单
		*/
function setSubSelect(subArray, subSelcet, pid) {
	subSelcet.length = 0;
	for (var i = 0; i < subArray.length; i++) {
		if (subArray[i].pid == pid) {
			subSelcet.length = subSelcet.length + 1;
			subSelcet.options[subSelcet.length - 1].value = subArray[i].id;
			subSelcet.options[subSelcet.length - 1].text = subArray[i].name;
		}
	}
}

/* 构造一个具有父子级关系的下拉菜单
*   传入父级元素数组 和 子集元素数组，根据pid 的关联 构造有层次的下拉菜单
*/
function setCascadSelect(parentArray, subArray, theSelect) {
	
	for (var i = 0; i < parentArray.length; i++) {
		theSelect.length = theSelect.length + 1;
		theSelect.options[theSelect.length - 1].value = parentArray[i].id;
		theSelect.options[theSelect.length - 1].pid = "";
		theSelect.options[theSelect.length - 1].text =  parentArray[i].name;
		for (var j = 0; j < subArray.length; j++) {
			if (subArray[j].pid == parentArray[i].id) {
				theSelect.length = theSelect.length + 1;
				theSelect.options[theSelect.length - 1].value = subArray[j].id;
				theSelect.options[theSelect.length - 1].pid = subArray[j].pid;
				theSelect.options[theSelect.length - 1].text = "  ┗" + subArray[j].name;
			}
		}
	}
}
function isParentCat(theSelect){
	for (var i = 0; i < theSelect.length; i++) {
		if (theSelect.options[i].selected == true 
			&& theSelect.options[i].pid =="") {
			return true;
		}
	}
	return false;
}

function checkCascadSelect(theSelect){
	for (var i = 0; i < theSelect.length; i++) {
		if (theSelect.options[i].selected == true 
			&& theSelect.options[i].pid =="") {
			alert("不能选择一级分类");
        	theSelect.value = "";;
		}
	}
}

function setSelectValue(theSelect,value){
	for (var i = 0; i < theSelect.length; i++) {
		if (theSelect.options[i].value == value ) {
        	theSelect.options[i].selected = true;
		}
	}
}
