
function Dd(){
	this.did;
	this.dname;
	this.childs=false;
}

var doc;

function initialDoc(ulr){
	var _req  = new FancyReqClass();
	doc = _req.requestXML(ulr);
}

function setSelected(o,s){
	for( i=0;i<o.length;i++ ){
		if( o.options[i].value==s ){
			o.options[i].selected="true";
			return;
		}
	}
}

function sdetail(o,s,n,p){ 
	var ps = s.substring(0,2) + "000000";
	for(i = 0; i < o.length; i++){ 
		if(o[i].getAttribute('value')==ps){
			
			var tp = o[i].childNodes; 
			var pc='';
			if( tp.length >0 ){
				if(typeof(p)!='undefined' && p != '-1'){
					pc+='<option value="' + ps +'" selected>'+o[i].getAttribute('name') +'</option>'
				}
				for( k = 0; k<tp.length; k++ ){
					if(tp[k].getAttribute('value')==s){
						pc +='<option value="' + tp[k].getAttribute('value') +'" selected>'+tp[k].getAttribute('name') +'</option>';
					}else{
						pc +='<option value="' + tp[k].getAttribute('value') +'">'+tp[k].getAttribute('name') +'</option>';
					}
				} 
			}else{
				pc +='<option value="' + ps +'" selected>'+o[i].getAttribute('name') +'</option>';
			}
			
			pc+=''; 
			
			if(typeof (document.getElementById(n).outerHTML) == 'undefined'){ 
				document.getElementById(n).innerHTML=pc;
			}else{
				document.getElementById(n).outerHTML= '<select name="' + n + '" id="' + n +'">' + pc + '</select>' ;
			}
			
			return;
		}
	}
}


function tdetail(o,s,n1,n2){ 
	var ps = s.substring(0,2) + "000000";
	var ss = s.substring(0,4) + "0000";
	for(i = 0; i < o.length; i++){ 
		if(o[i].getAttribute('value')==ps){
			
			
			var tp = o[i].childNodes; 
			fsel =tp;
			var pc='';
			for( k = 0; k<tp.length; k++ ){
				if(tp[k].getAttribute('value')==ss){
					pc +='<option value="' + tp[k].getAttribute('value') +'" selected>'+tp[k].getAttribute('name') +'</option>';
					
					var tc = '';
					var tn = tp[k].childNodes; 
					for( j = 0; j<tn.length; j++ ){
						if( tn[j].getAttribute('value')==s ){
							tc +='<option value="' + tn[j].getAttribute('value') +'" selected>'+tn[j].getAttribute('name') +'</option>';
						}else{
							tc +='<option value="' + tn[j].getAttribute('value') +'">'+tn[j].getAttribute('name') +'</option>';
						}
					}
					if(typeof (document.getElementById(n2).outerHTML) == 'undefined'){ 
						document.getElementById(n2).innerHTML=tc;
					}else{
						document.getElementById(n2).outerHTML='<select id="' + n2 +'" name="' + n2 +'">' + tc + '</select>' ;
					}
					
				}else{
					pc +='<option value="' + tp[k].getAttribute('value') +'">'+tp[k].getAttribute('name') +'</option>';
				}
			} 
			pc+='';
			if(typeof (document.getElementById(n1).outerHTML) == 'undefined'){ 
				document.getElementById(n1).innerHTML=pc;
			}else{
				document.getElementById(n1).outerHTML='<select name="' + n1 + '" id="' + n1+'" onchange="spChange2(\'speciality1\',' + n1 + ',' + n2 + ')">' + pc + '</select>' ;
			}
			return;
		}
	}
}





//--------------------- guest nav

var s_area;
var s_industry;
var s_position;
var s_speciality;



var tempdiv="";
var tempobj="";
var isOpen=false;
var childOpen=false;

var fobj=document.createElement("iframe");
fobj.setAttribute("id","divIframe");
fobj.style.position="absolute";
fobj.setAttribute("frameborder",0);
fobj.setAttribute("scrolling","no");
fobj.style.left = "50%";
fobj.style.top = "150px";
fobj.style.marginLeft = "-300px";
fobj.style.display="none";
fobj.style.zIndex="10000";
fobj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=0,finishOpacity=0";
fobj.style.opacity="0";




function getOption(obj,data,title,ulr){
	if (isOpen)
	{
		document.body.removeChild(tempdiv);
	}
	createobj(obj.name,title);	//创建div

	isOpen=true;
	var objDiv=document.getElementById("div" + obj.name);
	childOpen=false;
	tempobj=obj;
	tempdiv=objDiv;
	objDiv.focus();
	obj.blur();
	
	var outStr="";
	switch(parseInt(data)){
		case 1://对应上边定义的数组
			pareseArea(ulr);
			outStr=getItemList(s_area,data);
			break;
		case 2:
			parseIndustry(ulr);
			outStr=getItemList(s_industry,data);
			break;
		case 3:
			parsePosition(ulr);
			outStr=getItemList(s_position,data);
			break;
		case 4:
			parseSpeciality(ulr);
			outStr=getItemList(s_speciality,data);
			break;
		}
	outStr="<ul>" + outStr + "</ul>";
	objDiv.innerHTML=objDiv.innerHTML + outStr;
	
//加iFrame解决select挡住div的问题
	if (document.getElementById("divIframe"))
	{
		document.getElementById("divIframe").style.display="block";
	}else{
		document.body.appendChild(fobj);
	}
	document.getElementById("divIframe").style.display="block";
	document.getElementById("divIframe").style.top=tempdiv.offsetTop + "px";
	document.getElementById("divIframe").style.height=tempdiv.offsetHeight + "px";
	document.getElementById("divIframe").style.width=tempdiv.offsetWidth + "px";

} 

function getItemList(ar,t){
	var ItemList=""
	for (var i=0;i<ar.length ;i++ )
	{
		var dd = ar[i];
		if (!dd.childs)
		{
			ItemList=ItemList + "<li><a id='" + dd.did + "' href='javascript:;' onclick='insertOption(this);' title='" + dd.dname + "'>"  + dd.dname + "</a></li>";
		}else{
			ItemList=ItemList + "<li><a id='" + dd.did + "' href='javascript:;' onclick='getChild(this," +t + " );' title='" + dd.dname + "'>" + dd.dname + "</a></li>";
		}
		
	}
	return ItemList;
}

function getChild(obj,t){
	
	if (!childOpen)
	{
		var cdiv=document.createElement("div");
		cdiv.setAttribute("id","childdiv");
		cdiv.innerHTML="<h3><span></span></h3><ul id='cdata'><li>正在读取数据...</li></ul>";
		tempdiv.appendChild(cdiv);
		childOpen=true;
	}else{
		var cdiv=document.getElementById("childdiv");
		cdiv.innerHTML="<h3><span></span></h3><ul id='cdata'><li>正在读取数据...</li></ul>";
	}

				var areaDoc = '';
				var attach = '';
					if(t=='1'){
						areaDoc = doc.firstChild.firstChild.childNodes;
					}else if ( t=='2' ){
						areaDoc = doc.firstChild.firstChild.nextSibling.childNodes;
					} else if (t=='3'){
						areaDoc = doc.firstChild.firstChild.nextSibling.nextSibling.childNodes;
						attach='(全部)';
					} else if (t=='4'){
						areaDoc = doc.firstChild.firstChild.nextSibling.nextSibling.nextSibling.childNodes;
					} 
				var childStr='';
				for(i = 0; i < areaDoc.length; i++){
					if(obj.id == areaDoc[i].getAttribute("value")){
						childStr += "<li><a id='" + areaDoc[i].getAttribute("value") + "' href='javascript:;' onclick='insertOption(this);' title='" + areaDoc[i].getAttribute("name") + attach + "'>" + areaDoc[i].getAttribute("name") + attach + "</a></li>";
						var citys = areaDoc[i].childNodes;
						for(j=0;j<citys.length;j++){
							childStr += "<li><a id='" + citys[j].getAttribute("value") + "' href='javascript:;' onclick='insertOption(this);' title='" + citys[j].getAttribute("name") + "'>" + citys[j].getAttribute("name") + "</a></li>";
						}
						break;
					}
				}
				if(typeof(childStr) == 'undefined' || childStr=='' ){
					childStr ='读取内容错误!';
				} 
				document.getElementById("cdata").innerHTML=childStr; 
				document.getElementById("divIframe").style.height=(tempdiv.offsetHeight+document.getElementById("childdiv").offsetHeight)+"px";
	
}


function createobj(name,title){
	var bordercolor,msgw,msgh;
	bordercolor="#ff6600";
	msgw="600px";
	var msgObj=document.createElement("div");
	msgObj.setAttribute("id","div" + name);
	msgObj.className="msgDiv";
	msgObj.style.position = "absolute";
	msgObj.style.left = "50%";
	msgObj.style.top = "150px";
	msgObj.style.marginLeft = "-300px" ;
	msgObj.style.width = msgw;
	msgObj.style.zIndex = "10001";
	msgObj.innerHTML="<h3><span>请选择" + title + "</span><a class='red' href='javascript:;' onclick='closediv();'>[关闭]</a></h3>";
	document.body.appendChild(msgObj);
}
function closediv(){
	document.body.removeChild(tempdiv);
	document.getElementById("divIframe").style.display="none";
	isOpen=false;
	childOpen=false; 
	//#shentu,20080314,e
	if( document.getElementById('globalDiv') != null ){
		document.getElementById('globalDiv').style.display="none";
	}
}

function insertOption(obj){
	var tit = obj.innerHTML;
	if( tit.length > 5 ){
		tit = (tit.substring(0,5) + "..");
	}
	tempobj.options[0]=new Option(tit,obj.id);
	document.body.removeChild(tempdiv);
	document.getElementById("divIframe").style.display="none";
	isOpen=false;
	childOpen=false;
	//#shentu,20080314,e
	//window.alert(document.getElementById('globalDiv'));
	if( document.getElementById('globalDiv') != null ){
		document.getElementById('globalDiv').style.display="none";
	}
}

//---------------------

function pareseArea(ulr){
	if(typeof(s_area) == 'undefined'){
		if( typeof(doc) == 'undefined' ){
			initialDoc(ulr);
		}
		if(typeof(doc) != 'undefined'){
				var areaDoc = doc.firstChild.firstChild.childNodes;
				s_area = new Array();
				var ft = new Dd();
				ft.did='-1';
				ft.dname='全国';
				s_area[0]=ft;
				for(i = 0; i < areaDoc.length; i++){
					var dd = new Dd();
					dd.did = areaDoc[i].getAttribute('value');
					dd.dname = areaDoc[i].getAttribute('name');
					if( areaDoc[i].childNodes.length > 0 ){
						dd.childs=true;
					}
					s_area[i+1]=dd;
				}
		}
	}
}

function parseIndustry(ulr){
	if(typeof(s_industry) == 'undefined'){
		if( typeof(doc) == 'undefined' ){
			initialDoc(ulr);
		}
		if(typeof(doc) != 'undefined'){
				var indDoc = doc.firstChild.firstChild.nextSibling.childNodes;
				s_industry = new Array();
				var ft = new Dd();
				ft.did='-1';
				ft.dname='全部';
				s_industry[0]=ft;
				for(i = 0; i < indDoc.length; i++){
					var dd = new Dd();
					dd.did = indDoc[i].getAttribute('value');
					dd.dname = indDoc[i].getAttribute('name');
					if( indDoc[i].childNodes.length > 0 ){
						dd.childs=true;
					}
					s_industry[i+1]=dd;
				}
		}
	}
}

function parsePosition(ulr){
	if(typeof(s_position) == 'undefined'){
		if( typeof(doc) == 'undefined' ){
			initialDoc(ulr);
		}
		if(typeof(doc) != 'undefined'){
				var positionDoc = doc.firstChild.firstChild.nextSibling.nextSibling.childNodes;
				s_position = new Array();
				var ft = new Dd();
				ft.did='-1';
				ft.dname='全部';
				s_position[0]=ft;
				for(i = 0; i < positionDoc.length; i++){
					var dd = new Dd();
					dd.did = positionDoc[i].getAttribute('value');
					dd.dname = positionDoc[i].getAttribute('name');
					if( positionDoc[i].childNodes.length > 0 ){
						dd.childs=true;
					}
					s_position[i+1]=dd;
				}
		}
	}
}


function parseSpeciality(ulr){
	if(typeof(s_speciality) == 'undefined'){
		if( typeof(doc) == 'undefined' ){
			initialDoc(ulr);
		}
		if(typeof(doc) != 'undefined'){
				var specialityDoc = doc.firstChild.firstChild.nextSibling.nextSibling.nextSibling.childNodes;
				s_speciality = new Array();
				var ft = new Dd();
				ft.did='-1';
				ft.dname='全部';
				s_speciality[0]=ft;
				for(i = 0; i < specialityDoc.length; i++){
					var dd = new Dd();
					dd.did = specialityDoc[i].getAttribute('value');
					dd.dname = specialityDoc[i].getAttribute('name');
					if( specialityDoc[i].childNodes.length > 0 ){
						dd.childs=true;
					}
					s_speciality[i+1]=dd;
				}
		}
	}
}

