 
// 多极联合选择      
function outSelection(selectionMainName, values, arrayName, idName, level, allSelect)
{
	
    var value  ; 
    var selectName = selectionMainName ;
    var id = idName ;
    var array = arrayName ;
    var splitValue = "_"  ;
    
    var all ; //提示选择,或者忽略类别  ,忽略值为 all
    if (allSelect)
    {
        all = "<option value='all' > " + allSelect + "</option>" ;
    }
    if(values != "")
    {
        value = values.split(splitValue) ;
        
    }
    else
    {
       value = new Array(0, 0, 0, 0, 0, 0, 0) ;
    }  

    var select = "" ;  

    for (var i = 0 ; i < level  ; i ++)
    {
        
             
        var selectValue =  value[i] ;
        
        var selectValuePre = "" ;  //上一级 的值 用于找到 下一级 该打开的  数组
        if(i > 0)
        {
            selectName = selectionMainName + "_" + i ;  //   级联选择 的 onchange值
            id = idName + "_" + i ;  //  放置  select html的 div
            
            if(value.length >= i )
            {
                selectValuePre =  value[i-1] ;
            }
            else
            {
                selectValuePre = "null"
            }
            
            
            if(selectValuePre != 0  && selectValuePre != "null" && selectValuePre != "")
            {
                
                var arryId  = null;
                                            
                for(var s =0 ; s < value.length   ; s++)
                {
                    if (s == 0 && value.length > 1 && value.length < 3 )
                    {
                        
                        continue ;
                    }
                    
                    var arry = eval(array) ; 
                       
                    arryId  = null;
                    for (var k =0 ; k < arry.length ; k++ )
                    {
                        if(arry[k][0] == selectValuePre)
                        {
                            //alert(selectValue+"/"+ selectValuePre)
                            arryId = k ;  //找到  匹配值   得到 当前  arrray的 名字
                            break ;
                        }
                    } 
                    
                    array += "_" + arryId ; 
                    
                    if(arryId != null)
                    {
                        //alert(array) 
                        break;
                    }  
                    
                }
                
            }
            else
            {
               
               if(selectValuePre == "null")
                {
                    var aa = eval(array) ;
                    selectValuePre = aa[0][0];
                }               
                
                array += "_"  + 0 ;  
 
 
            }  
             
            
            select += selectValuePre +  splitValue ;   
            
            var tmp = "<select style='width:80px;'   name='" + selectName + 
                        "' onchange=\"outSelection('" 
                                + selectionMainName + "', '" + select + "'+this.value , '" 
                                + arrayName + "', '" + idName+ "', " 
                                +  level +  ", '"
                                + allSelect + "')\">\n" + all ;              
            
        }
        else
        {
            var tmp = "<select style='width:80px;'  name='" + selectName + 
                        "' onchange=\"outSelection('" 
                                + selectionMainName + "', this.value , '" 
                                + arrayName + "', '" + idName+ "', " 
                                +  level + ", '" 
                                + allSelect + "')\">\n" + all ;                
        }
        
        //超过ｌｅｖｅｌ 就终止
       ;     
        var ayy =   array.split(splitValue) ;   
        
        if(ayy.length > level)
        {   
            //alert(array + "out")
            break ;
        }
        //end 
        
        var ay = eval(array) ;
        
        //alert(ay) ; 
        
        for(var j = 0; j < ay.length; j++)
	    {
		    var selectStatus = "";
            //alert(selectValue);
		    if(selectValue === ay[j][0])
		    {
			    selectStatus = " selected ";
		    }
		    tmp += "<option value='" + ay[j][0] + "' "+selectStatus+">" + ay[j][1] + "</option>\n";
	    }
	    tmp += "</select>";
   
        document.getElementById(id).innerHTML = tmp ;
        
        //全选时候 放弃下一级
        if (selectValue == 'all')
        {
            document.getElementById(idName + "_" + 1).innerHTML = "" ;
            if (level > 2)
            {
                document.getElementById(idName + "_" + 2).innerHTML = "" ;  
            }
            break ; 
        }
        

        
        
             
	    //id.innerHTML = tmp;
    }
	
}

//outSelection("region", "22_8", "area", "region", 1)     