function area_remove(sel) {
	while(sel.options.length > 0) {
		sel.options.remove(0);	
	}
}

function area_init(sel, json, p) {
	var level = sel.getAttribute('level');
	var dvs = eval('i_' + p);
	for(var i = 0; i < json.length; i++) {
		var si = document.createElement('option');
		si.value = json[i].code;
		si.text = json[i].title;
		si.setAttribute('di', json[i]);
		sel.options.add(si);

		if(si.value == dvs[level - 1]) {
			sel.selectedIndex = i;
		}
	}
	
	if(sel.options.length == 0) return ;
	if(sel.selectedIndex == -1) sel.selectedIndex = 0;
	
	
	//if(level != '4') {
		
		area_change(sel, parseInt(level), p);
	//}
}

function area_init2(sel, json) {
	for(var i = 0; i < json.length; i++) {
		var si = document.createElement('option');
		si.value = json[i].code;
		si.text = json[i].title;
		si.setAttribute('di', json[i]);
		sel.options.add(si);
	}
}

function area_change(sel, level, p) {
	if(level >= 4) return ;
	
	var si = sel.options[sel.selectedIndex];
	var di = si.getAttribute('di');
	
	var selID = p + (level + 1);
	var cID = 'c_' + selID;
	
	if(di.children && di.children.length > 0) {
		area_remove(document.getElementById(selID));
		area_init(document.getElementById(selID), di.children, p);
		document.getElementById(cID).style.display = 'block';
	} else {
		document.getElementById(cID).style.display = 'none';
	}
}
