$(document).ready(function(){
	for(var n=0;n<data.length/4;n++){
		$('<option freeleast="'+data[n*4][2]+'" hdfk="'+data[n*4][3]+'" ztd="'+data[n*4][4]+'" child="'+data[n*4][5]+'" value="'+data[n*4][1]+'">'+data[n*4][0].replace("->","")+'</option>').appendTo($('#ddlTopAreas'))
	}//end for
});
//arg_1:分类ID;arg_2:下一级的层级;arg_3:
function GetNextStep(arg_1,arg_2,arg_3){
var next_index =arg_2+1;
if(arg_2==2){
    $('#ddlSubAreas').remove();
    $('#ddlThirdAreas').remove();
    var subareaoptions = $('<select id="ddlSubAreas" onChange="GetNextStep(this.value,'+next_index+',true)" name="ddlSubAreas"></select>');
    $('#ddlTopAreas').after(subareaoptions);
}
if(arg_2==3){
    $('#ddlThirdAreas').remove();
    var thirdareaoptions = $('<select id="ddlThirdAreas" name="ddlThirdAreas"></select>');
    $('#ddlSubAreas').after(thirdareaoptions);
}

for(var i=0;i< data.length/4; i++){
	var cd = data[i*4+(arg_2-1)];
	if(arg_2 ==2){//获取第二级分类
		if(cd[0]==arg_1){
			for(var j=1;j< cd.length; j++)
			{
				//alert(j);
				if(cd[j][0] !="" && typeof cd[j][0]!="undefined"){
					if((cd[j][0]).indexOf("->") >0 ){
					    var valid =true;
					}else{
					    valid =false;
					}
					//alert(cd[j][0].replace("->",""));
					$('<option freeleast="'+cd[j][2]+'" hdfk="'+cd[j][3]+'" ztd="'+cd[j][4]+'" child="'+cd[j][5]+'" value="'+cd[j][1]+'">'+cd[j][0].replace("->","")+'</option>').appendTo($('#ddlSubAreas'));
				}
			}
		}
		else{
			continue;
		}
	}else{//第三级或第四级
		if(cd !=""){
			for(var j=0;j< cd.length/2; j++){
				if(cd[j*2]==arg_1){					    
					if(cd[j*2+1][0] !="" && cd[j*2+1][0]!="undefined" && typeof(cd[j*2+1][0])!="undefined"){
						if((cd[j*2+1][0]).indexOf("->") >0 ){
							var valid =true;         
						}else{
							valid =false;
						}
						$('<option freeleast="'+cd[j*2+1][2]+'" hdfk="'+cd[j*2+1][3]+'" ztd="'+cd[j*2+1][4]+'" child="'+cd[j*2+1][5]+'" value="'+cd[j*2+1][1]+'">'+cd[j*2+1][0].replace("->","")+'</option>').appendTo($('#ddlThirdAreas'));
					}
				}
				else{
					continue;
				}
			}//end for
		}//end if
	}//end if
}//end for
};