/**
 * version: xyata1.0
 * author: sky
 * Date:2009-07-01
 * 功能：获取省和大学列表 以及根据选中大学获取该大学所有学院
 */
	var xmlhttpu = false;
	var docUniversity;
	var colleges;
	var returnUniversityParam = new Array(5);//记住返回页面的ids
//关闭窗口
	function closeWindow(){
		if(document.getElementById("back")!=null)
		{
			document.getElementById("back").parentNode.removeChild(document.getElementById("back"));
		}
		if(document.getElementById("iframe3head")!=null)
		{
			document.getElementById("iframe3head").parentNode.removeChild(document.getElementById("iframe3head"));
		}
	}
	function showUniversityDiv(div_id,div_width,param){/*--打开--*/
		var isIE = document.all ? true : false;
		closeWindow(); 
		var bWidth=parseInt(document.documentElement.scrollWidth);
		var bHeight=parseInt(document.documentElement.scrollHeight)<592?592:parseInt(document.documentElement.scrollHeight);
		var cX =  (bWidth - div_width)/2;
		var back=document.createElement("div");
		back.id="back";
		var iframe3 = document.createElement("iframe");
		iframe3.id="iframe3head";
		iframe3.style.cssText = "top:0px;left:0px;position:absolute;width:"+bWidth+"px;height:"+bHeight+"px;filter:alpha(opacity=0);opacity:0;";
		var styleStr="top:0px;left:0px;position:absolute;z-index:1;background:#666;width:"+bWidth+"px;height:"+bHeight+"px;";
		styleStr+=(isIE)?"filter:alpha(opacity=40);":"opacity:0.40;";
		back.style.cssText=styleStr;
		document.body.appendChild(iframe3);
		document.body.appendChild(back);
	    var o = document.getElementById(div_id);
	    o.style.display = "block";
	    var body = (document.documentElement || document.body);
		var top = (body.clientHeight - o.offsetHeight) / 2 + body.scrollTop;
		o.style.top = top + "px";
	    o.style.left = cX + "px";
		returnUniversityParam = param;
		if(docUniversity == null || docUniversity == undefined){
			 getAllPUniversity();
		}
	}   
	function getUniversityInfo() {
		if (xmlhttpu.readyState == 4) {
			if (xmlhttpu.status == 200) {
				var data = xmlhttpu.responseXML;//服务器返回查询数据
				callbackProvinceUniversity(data);
			} else {
				var mes = "<h3>读取数据失败，请重试！</h3>";
				document.getElementById("province_div").innerHTML = mes;
			}
		}else{
			document.getElementById("province_div").innerHTML = "<img src=\"images/loading_32x32.gif\" />";
		}
	}
	//取得所有的省和学校
	function getAllPUniversity() {
		xmlhttpu = createXMLHTTP();
		xmlhttpu.open("GET", "xyataxml/zyProvinceUniversity.xml", true);
		xmlhttpu.onreadystatechange = getUniversityInfo;
		xmlhttpu.send(null);
	}
	
	//回调函数，初始化省，并填充信息
	function callbackProvinceUniversity(data) {
		if (!data) {
		} else {
			docUniversity = data.getElementsByTagName("root")[0].childNodes;//获取返回数据中所有省元素
			buildProvinceUniversity();
		}
	}
	
	//构建省，并填充数据
	function buildProvinceUniversity() {
		//组装页面渲染
		var str = "<ul>";
		for (var i = 0; i < docUniversity.length; i++) {
			var provinceId = docUniversity[i].getAttribute("id");
			var provinceName = docUniversity[i].getAttribute("name");
			str = str + "<li><a id=\"pro_"+ i + "\" href=\"javascript:void(0)\" onclick=\"javascript:buildUniversity(" + i + ")\">" + provinceName + "</a></li>";
		}
		str = str + "</ul>";
		document.getElementById("province_div").innerHTML = str;
		buildUniversity(0);
	}
	
	//构建学校，并填充数据
	function buildUniversity(node) {
	if (typeof docUniversity != "undefined") {
		// 取到省name和id
		var provinceId = docUniversity[node].getAttribute("id");
		var provinceName = docUniversity[node].getAttribute("name");
		// 取到当前省的所有学校的doc
		var collegeDoc = docUniversity[node].childNodes;
		var returnvalue;
		// 组装页面渲染
		var ustr = "<ul>";
		var gstr = "<ul>";
		for (var i = 0; i < docUniversity.length; i++) {
			if (i == node) {
				document.getElementById("pro_" + i).className = "xz";
			} else {
				document.getElementById("pro_" + i).className = "";
			}
		}
		for (var i = 0; i < collegeDoc.length; i++) {
			var collegeId = collegeDoc[i].getAttribute("id");
			var collegeName = collegeDoc[i].getAttribute("name");
			var collegeType = collegeDoc[i].getAttribute("type");// 获取学校类型
			if (collegeType == "1") {// 1为大学
				returnvalue = "[" + provinceId + ", '" + provinceName + "', "
						+ collegeId + ", '" + collegeName + "', " + collegeType
						+ "]";
				ustr += "<li><a href=\"javascript:returnValueUniversity("
						+ returnvalue + ")\">" + collegeName + "</a></li>";
			} else {// 2研究所
				returnvalue = "[" + provinceId + ", '" + provinceName + "', "
						+ collegeId + ", '" + collegeName + "', " + collegeType
						+ "]";
				gstr += "<li><a href=\"javascript:returnValueUniversity("
						+ returnvalue + ")\">" + collegeName + "</a></li>";
			}
		}
		ustr += "</ul>";
		gstr += "</ul>";
		document.getElementById("university_div").innerHTML = ustr;
		document.getElementById("graduate_div").innerHTML = gstr;
	}
}
	//返回学校的名称和id
	function returnValueUniversity(returnvalue) {
		closeed("province_university_div");
		for (var i = 0; i < returnUniversityParam.length; ++i) {
			var obj = document.getElementById(returnUniversityParam[i]);
			if (null != obj) {
				obj.value = returnvalue[i];
			}
		}
		if(returnvalue[4] == 1){
			document.getElementById("ky_college_id1").style.display = "";
			set_ky_college_id1();
		}else{
			document.getElementById("ky_college_id1").style.display = "none";
		}
	}
  function set_ky_college_id1() {
		xmlhttp = createXMLHTTP();
		var sParams = "";
		sParams = addURLParamPost(sParams, "ky_university_id1", document.getElementById("ky_university_id1").value);
		xmlhttp.open("POST", "users/getCollegeByAjax_ky1.action", true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.onreadystatechange = proC1;
		xmlhttp.send(sParams);
	}
	function proC1() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				var returnXML = xmlhttp.responseXML;//xml格式解析返回信息
				colleges = returnXML.getElementsByTagName("college");
				var select = document.getElementById("ky_college_id1");
					//clear select
				for (var i = 0; i < select.options.length; i++) {
					for (var j = select.options.length; j > i; j--) {
						document.getElementById("ky_college_id1").remove(i);
					}
				}
					//add select
				var option = new Option("请选择学院/系", "-1");
				if (colleges.length > 0) {
					document.getElementById("ky_college_id1").options.add(option);
					for (var i = 0; i < colleges.length; i++) {
						var college = colleges[i];
						var collegesName = college.firstChild.nodeValue;
						var collegesId = college.getAttribute("id");
						var option = new Option(collegesName, collegesId);
						document.getElementById("ky_college_id1").options.add(option);
					}
				} else {
					document.getElementById("ky_college_id1").options.add(option);
				}
			}
		}
	}
	/*获取学院名称*/
	function getCollegeName(id){
			for (var i = 0; i < colleges.length; i++) {
						var collegesName = colleges[i].firstChild.nodeValue;
						var collegesId = colleges[i].getAttribute("id");
						if(collegesId == id){
							document.getElementById("collegeName").value = collegesName;
						}
				}
	}
  function closeed(id){/*--关闭--*/
  		closeWindow();
		document.getElementById(id).style.display = "none";
  }      
