﻿	function xmlRemoteList(objNodeList)
	{
		this.m_objList=objNodeList;
		this.GetListCount=GetListCount;
		this.GetListItemText=GetListItemText;
		this.GetListItemValue=GetListItemValue;
	}
	function GetListCount()
	{
		return this.m_objList.length;
	}
	function GetListItemText(intIndex)
	{
		var obj=this.m_objList.item(intIndex);
		return obj.getAttribute("IT");
	}
	function GetListItemValue(intIndex)
	{
		var obj=this.m_objList.item(intIndex);
		return obj.getAttribute("IV");
	}

	
	function xmlRemoteObject(strURL)
	{
		this.m_strURL=strURL;	
		this.m_objHTTP=new ActiveXObject("Msxml2.XMLHTTP");
		this.m_objReturned=null;
		this.m_objRootE=null;
		this.GetData=GetData;
		this.GetStringAtt=GetStringAtt;
		this.GetIntAtt=GetIntAtt;
		this.GetFloatAtt=GetFloatAtt;
		this.GetList=GetList;

	}
	
	
	function GetList(strName)
	{
		if (this.m_objRootE==null ) return null;
		var currNodeList = this.m_objRootE.selectSingleNode(strName);
		if (currNodeList==null) return null;
		var objNodes=currNodeList.selectNodes("ITEM");
		return objNodes;
	}
	
	function GetIntAtt(strName)
	{
		var strV=this.GetStringAtt(strName);
		if (strV==null) return 0;
		return parseInt(strV);
	}	

	function GetFloatAtt(strName)
	{
		var strV=this.GetStringAtt(strName);
		if (strV==null) return 0;
		return parseFloat(strV);
	}	
	
	function GetStringAtt(strName)
	{
		if (this.m_objRootE==null ) return null;
		var currNode = this.m_objRootE.selectSingleNode(strName);
		if (currNode==null) return null;
		return currNode.text;
	}
	
	function GetData_old(strURL)
	{
		if (strURL!=null)
		{
			this.m_strURL=strURL;				
		}
		
		var strTempURL=this.m_strURL;
		
		/*
		disable the refreshing function
		if (strTempURL.indexOf("?")>0)
		{
			strTempURL=strTempURL+"&r"+Math.random();
		}
		else
		{
			strTempURL=strTempURL+"?r"+Math.random();
		}*/
	
		this.m_objHTTP.Open("GET", strTempURL, false);
		this.m_objHTTP.send();

		//window.alert(strTempURL);
		//window.alert(this.m_objHTTP.responseText);

		if (this.m_objHTTP.responseXML!=null)
		{
			this.m_objReturned=this.m_objHTTP.responseXML;
			this.m_objRootE=this.m_objReturned.documentElement;
			return (true);
		}
		else
		{
			return (false);
		}
	}
	
	//zhaobg Modify
	function ChangeToCacheURL_old(strURL,strID)
	{
		strURL=strURL.toLowerCase();
		strURL=strURL.replace("searchcenter","searchcenter/xmlcache");
		strURL=strURL+"."+strID+".xml";
		return strURL;
	}
	
	function BindDataforSelectControl_old(objSelect, strDataURL,strID)
	{
		if(objSelect.options.length>0){
			objSelect.length=0;
		}
		
		var oOption;
		var intCounts=0;		
		if (strID=="")
		{
			objSelect.options[objSelect.length] = new Option("","");
		}
		else
		{
			alert("LoadXML")
			//alert(strDataURL+"?catid="+strID);
			//alert(strDataURL);
			strDataURL=ChangeToCacheURL(strDataURL,strID);
			//alert(strDataURL);
			var obj=new xmlRemoteObject(strDataURL);
			alert(obj)
			obj.GetData(null);
			
			var objList = new xmlRemoteList(obj.GetList("cat"));
			var intcount= objList.GetListCount();
			intCounts=intcount
			for(var i=0;i<intcount;i++)
			{
				objSelect.options[objSelect.length] = new Option(objList.GetListItemText(i),objList.GetListItemValue(i));
			}
		}
		objSelect.selectIndex=0;
		if(intCounts>1)
		{
			objSelect.style.display="inline";
		}
		else
		{
			objSelect.style.display="none";
		}
	}



	function CheckJSCache(strID)
	{
		
		
		if (strID=="") return undefined;
		var chrF=strID.charAt(0);
		
		var ret=undefined;		
		
		if (chrF=='A' || chrF=='a')
		{
			if (typeof(arrtype)!=undefined)	    ret=arrtype;
		}
		if (chrF=='G' || chrF=='g')
		{
			if (typeof(arrarea)!=undefined) 	ret=arrarea;
		}

		if (chrF=='U' || chrF=='u')
		{
			if (typeof(arruni)!=undefined) 	ret=arruni;
		}
			
		return ret;
			
		
	}
	function IsLeaveID(strID)
	{
		//判断是否是叶子类别	
		var objlist=CheckJSCache(strID);
		
		if (objlist==undefined)
		{
			return false;
		}

		var intIndex=objlist[strID];
		if (strID=="" || intIndex==undefined)
		{
			return true;
		}
		else
		{
			var objcat=objlist[intIndex];
			var intSubIndex	=objcat[2]; //the start index of subcat list
			var intcount=objcat[3]; //the size of sub-cat list
			if (intcount<=0 && intSubIndex < 0)
			  return true;
			else
			  return false;
		}
	}
	
	function BindDataforSelectControl(objSelect,strID)
	{
		
		var objlist=CheckJSCache(strID);
		//alert(objlist==undefined)
		if (objlist==undefined)
		{
			//BindDataforSelectControl_old(objSelect, strDataURL,strID);
			
			if(objSelect.options.length>0){
				objSelect.length=0;
			}
			
			var oOption;
			var intCounts=0;		
			if (strID=="")
			{
				objSelect.options[objSelect.length] = new Option("","");
			}
			
			return;
		}
		
		if(objSelect.options.length>0){
			objSelect.length=0;
		}
		
		var oOption;
		var intCounts=0;
		
		objSelect.options[objSelect.length] = new Option("请选择...","");
		
		var intIndex=objlist[strID];
		if (strID=="" || intIndex==undefined)
		{
			return;
		}
		else
		{
			var objcat=objlist[intIndex];
			var intSubIndex	=objcat[2]; //the start index of subcat list
			var intcount=objcat[3]; //the size of sub-cat list
			intCounts=intcount;
			for(var i=0;i<intcount;i++)
			{
				intIndex=intSubIndex+i;
				objcat=objlist[intIndex];
				//alert(objlist[intIndex]);

				objSelect.options[objSelect.length] = new Option(objcat[1],objcat[0]);
				
			}
		}
		objSelect.selectIndex=0;
		if(intCounts>=1){
			objSelect.style.display="inline";
			objSelect.disabled=false;
		}else{
			objSelect.disabled=true;
			objSelect.style.display="none";
		}
	}
	
