/*
无级城市联动选择
*/
function ajaxCity(objs){
		/*
		假设设置了selected值，表示初始选择一个分类
		*/
		if (objs.selected > 0 && objs.id==0){
			$.get("/city/ajax/",
           { id: objs.selected, act:objs.action },
            function(data){
				array = data.split(',');
				//alert(array);
				for(i=0;i<array.length;i++){
					ajaxCity({id:array[i],pos:i,elms:objs.elms,lable:array})
				}
			}
			)
		}else{
			$.get("/city/ajax/",
           { id: objs.id, act: "showin" },
            function(data){
				var category = eval(data);
				var i;
				var content;
				var title = objs.pos ? '' : '';
				var elmsname = objs.elms ? objs.elms : 'parentid[]';	//判断是否设置input名称未设置则设置为默认
				var action = objs.action ? objs.action : 'add';
				var obj = document.getElementById('ajaxcity').getElementsByTagName('select');
				var selects = obj.length;
				objs.lable = objs.lable ? objs.lable : 0;
				objs.pos = objs.pos ? objs.pos : 0;
				while( objs.pos < selects ){
					selects = selects-1;
					document.getElementById('ajaxcity').removeChild(obj[selects]);
				}
				if ( (data.length>0 && objs.id>0 ) || obj.length==0){	//服务器有返回数据时
					content = '<select name="'+elmsname+'" onChange="ajaxCity({id:this.value,pos:'+(objs.pos+1)+'})">'
					content = content + '<option value="0">'+title+'</option>';
					if (typeof(category) != 'undefined'){

						for(i=0;i<category.length;i++){
							if (inArray(objs.lable, category[i].id)==true ){
								content = content + '<option value="'+category[i].id+'" selected="selected" >'+category[i].city+'</option>';
							}else{
								content = content + '<option value="'+category[i].id+'">'+category[i].city+'</option>';
							}
						}
					}
					content = content + '</select>';
					$("#ajaxcity").append(content);
				}
			}
        ) 
		}
}