
<script language="javascript">
    // 行业类别处理
  	function Category(id,title) 
	{
		this.id = id;
		this.title=title;
		this.boardlist=new Array();
		this.addBoard=addBoard;
		this.getOptions = getOptions;
	}        

	function addBoard(board)
	{
		this.boardlist = this.boardlist.concat(board);
	}
		
	function getOptions() 
	{
		var tmp = new Array();
		for(var i=0; i < this.boardlist.length;i++) 
		{
			var b = this.boardlist[i];
			tmp[i]= b.getOption();
		}
		return tmp;
	}

 	function Board(catid,id,title,total)
	{                
		this.catid=catid;
		this.id=id;
		this.title=title;
		this.getOption=getOption;
	}

   function getOption() 
   {
	 return new Option(this.title,this.id);                
   }
	
   function changeCategory(list)
   {
    	if (list.selectedIndex<=0)
	    {
		    catForm.options[0].selected=true;
			var len = boardForm.options.length;
			for (var i=len-1;i>0;i--)
			{
			    boardForm.options[i]=null;
		    }                                        
		}
		else
		{
		    var boards = catArr[list.selectedIndex-1].getOptions();
			var len = boardForm.options.length;
			for (var i=len-1;i>0;i--)
			{
				boardForm.options[i]=null;
			}                
			for (var i=0;i<boards.length;i++)
			{
			    boardForm.options[i+1]=boards[i];
			}
	     }
		boardForm.options[0].selected=true;
	}

	function selectBoard(catid,bid,list)
    {
		var isExist = false; //是否是叶子类目
		for(var i=0;i<catForm.length;i++) 
		{
	    	 if (catForm.options[i].value==catid) 
		     {
 			    catForm.options[i].selected=true;
			    changeCategory(catForm);
			    break;                        
		     }                        
		}                                
		for(var i=0;i<boardForm.length;i++)
		{
			if (boardForm.options[i].value==bid)
	    	{
 		        boardForm.options[i].selected=true;  
		        isExist = true;                              
		        break;
            }                        
	   }   
	
	if (!isExist) 
	{//如果是二级类目，则下拉框只显示该二级类目下所有类目                   
	    var boards = catArr[catForm.selectedIndex-1].getOptions();
	    var len = boardForm.options.length;
	    for (var i=len-1;i>0;i--)
	    {
	        boardForm.options[i]=null;
	    }     
	    var locate = 1;           
	    for (var i=0;i<boards.length;i++)
	    {                                                              
	        if(boards[i].text.indexOf(bid) == 0)
	        {
		        boardForm.options[locate]=boards[i];
		        locate++;
		    }                                                
	    }
	    boardForm.options[0].selected=true;   
	}            
}        
 	var catArr = new Array();
	var cur;   
 	var catForm = document.form.p_z_Z_RootCategory;
	var boardForm = document.form.p_z_Z_CategoryId1;
    function showCategorys()
	{
		var catId = catForm.value
		if(boardForm.value)
		{
	    	catId = boardForm.value
		}
		else if(catForm.value)
		{
		    catId = catForm.value
		}
 	 }
		
    for (var i=0;i<catArr.length;i++)
    {
		  catForm.options[i+1]=new Option(catArr[i].title,catArr[i].id);
    }
		
   function initRootCategorys()
   {
	  for (var i=0;i<catArr.length;i++) 
	  {
    	   catForm.options[i+1]=new Option(catArr[i].title,catArr[i].id);
	  }
   }  
</script>

<script src="../js/allCategorys.js"></script>

<script>
  initRootCategorys(); 
</script>

<script>
  selectBoard("<%=Replace_Text(request("p_z_Z_RootCategory"))%>","<%=Replace_Text(request("p_z_Z_CategoryId1"))%>");
</script>

<!-----------------------------------行业分类js处理  end ----------------------------------------->
<%
conn.close
%>
