/**
 * version: xyata1.0
 * author: fgm
 * Date:2010-08-21
 * 功能：辅导班首页选择城市
 */
var xmlhttpc = false;
var docCity;
/*--打开层--*/
function showCityDiv(div_id,div_width){
	var isIE = document.all ? true : false;
	closeCityWindow(); 
	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="back1";
	var iframe7 = document.createElement("iframe");
	iframe7.id="iframe7head";
	iframe7.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(iframe7);
	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";
	if(docCity == null || docCity == undefined){getAllPCity();}
}   
function getCityInfo() {
	if (xmlhttpc.readyState == 4) {
		if (xmlhttpc.status == 200) {
			var data = xmlhttpc.responseXML;//服务器返回查询数据
			callbackProvinceCity(data);
		} else {
			var mes = "<h3>读取数据失败，请重试！</h3>";
			document.getElementById("province_cdiv").innerHTML = mes;
		}
	}else{
		document.getElementById("province_cdiv").innerHTML = "<img src=\"images/loading_32x32.gif\" />";
	}
}
// 获取所有省和城市
function getAllPCity() {
	xmlhttpc = createXMLHTTP();
	xmlhttpc.open("GET", "xyataxml/provinceCity.xml", true);
	xmlhttpc.onreadystatechange = getCityInfo;
	xmlhttpc.send(null);
}
// 回调函数，初始化省，并填充信息
function callbackProvinceCity(data){if(!data){}else{docCity = data.getElementsByTagName("root")[0].childNodes;buildProvinceCity();}}
// 构建省，并填充数据
function buildProvinceCity() {
	var str = "<ul>";
	for (var i = 0; i < docCity.length; i++) {
		var provinceId = docCity[i].getAttribute("id");
		var provinceName = docCity[i].getAttribute("name");
		str = str + "<li><a target=\"_self\" id=\"pro_"+ i + "\" href=\"javascript:;\" onclick=\"javascript:buildCity(" + i + ")\">" + provinceName + "</a></li>";
	}
	str = str + "</ul>";
	document.getElementById("province_cdiv").innerHTML = str;
	buildCity(0);
}
// 构建每个省对应的城市
function buildCity(node) {
	if (typeof docCity != "undefined") {
		// 取得当前城市节点
		var cityDoc = docCity[node].childNodes;
		// 组装页面渲染
		for (var i = 0; i < docCity.length; i++) {
			if (i == node) {
				document.getElementById("pro_" + i).className = "xz";
			} else {
				document.getElementById("pro_" + i).className = "";
			}
		}
		var str = "<ul>";
		for(var i=0;i<cityDoc.length;i++){
			var cityId = cityDoc[i].getAttribute("id");
			var cityName = cityDoc[i].getAttribute("name");
			str = str + "<li><a target=\"_self\" href=\"classinfo/toTutorClass.action?cId=" + cityId + "\">"+ cityName +"</a></li>";
		}
		str = str + "</ul>";
		document.getElementById("city_div").innerHTML = str;
	}
}
//关闭窗口
function closeCityWindow(){if(document.getElementById("back1")!=null){document.getElementById("back1").parentNode.removeChild(document.getElementById("back1"));}if(document.getElementById("iframe7head")!=null){document.getElementById("iframe7head").parentNode.removeChild(document.getElementById("iframe7head"));}}
/*--关闭--*/
function closeedCity(id){closeCityWindow();document.getElementById(id).style.display = "none";}
