﻿// JavaScript Document
var url = "";
var destination = "";
function loadData(url){
	var xmlHttp = XmlHttp.create();
	xmlHttp.open("GET", url, true);	
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4){
			parseData(xmlHttp.responseXML);			
			document.getElementById('showMsg').style.display="none";	
			
		}
	}		
	window.setTimeout(function () {xmlHttp.send(null);}, 1);
}
function parseData(oXmlDoc){
	//如果用xmlhttp加载失败，则用document进行加载
	if(oXmlDoc == null||oXmlDoc.documentElement == null){
		try{
			oXmlDoc = XmlDocument.create();
			oXmlDoc.load(url);
		}catch(ex){
			window.status=(ex.message);
			oXmlDoc = null;	
		}
	}
	if( oXmlDoc == null || oXmlDoc.documentElement == null) {
		window.status=("加载\""+url+"\"进出错!");							
	}else {
		var root = oXmlDoc.documentElement;
		showData(root);		
	}
}
function showData(node){
	//alert(node.getAttribute("name"));
	//clearSelect();
	var dest  = document.getElementById(destination);
	//dest.options.length = 0;
	var rows = node.childNodes;
	var size = rows.length;
	for(var i = 0;i<size;i++){
		var child = rows[i];
		//alert(child.getAttribute("name"));
		var op = document.createElement("option");
		op.text = child.getAttribute("name");
		op.value = child.getAttribute("value");
		dest.options.add(op);
		//dest.options[i] = new Option(child.getAttribute("name"),child.getAttribute("value"));
	}
	//alert(destination);
}
function appendSubOption(souId,destId,showId){

	destination = destId;
	var source  = document.getElementById(souId);
	var parentId = source.options[source.selectedIndex].value;
	//alert("");
	var showit  = document.getElementById(destId);	
	url = "/commons/jsp/getDataByXMLHTTP.jsp?majorId="+parentId;
	//alert("3:"+showit);
	//showit.appendChild(t);
	//showit.options.add(t);
	document.getElementById(showId).style.visibility="visible";
	document.getElementById('showMsg').style.display="block";
	document.getElementById('showMsg').style.left=document.body.clientWidth/2;
	document.getElementById('showMsg').style.top=document.body.clientHeight/2;
	if (souId=='zero')
	{
	while(lengthOne=document.getElementById('one').length)
	{
	document.getElementById('one').remove(0);
	}
	while(lengthOne=document.getElementById('two').length)
	{
	document.getElementById('two').remove(0);
	}
	while(lengthOne=document.getElementById('three').length)
	{
	document.getElementById('three').remove(0);
	}
document.getElementById('twoMajorDiv').style.visibility="hidden";
document.getElementById('threeMajorDiv').style.visibility="hidden";
	}
	else if (souId=='one')
	{
		while(lengthOne=document.getElementById('two').length)
	{
	document.getElementById('two').remove(0);
	}
	while(lengthOne=document.getElementById('three').length)
	{
	document.getElementById('three').remove(0);
	}
	document.getElementById('threeMajorDiv').style.visibility="hidden";
	}
	else if (souId=='two')
	{
	while(lengthOne=document.getElementById('three').length)
	{
	document.getElementById('three').remove(0);
	}
	}
	loadData(url); 
	
}
function getKeyWord(souId)
{
var source  = document.getElementById(souId);
document.getElementById('specialtyForSearch').value=document.getElementById(souId).options[source.selectedIndex].text;
document.getElementById('specialtyid').value=document.getElementById(souId).value;
}

