var selectBox;

function initCountryOption(req) {
	var xmlDoc = req.responseXML;
	var itemList = xmlDoc.getElementsByTagName("depth");
	var resultValue = "";
	var rowIndex = 1;
	if(selectBox == $('select_depth2')){
		$('select_depth2').options.length = 0;
		if($('select_depth3')) $('select_depth3').options.length = 0;
		if($('select_depth3')) $('select_depth3').options[0] = new Option('ÁßºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä.',0);
	} else {
		$(selectBox).options.length = 0;
	}
	for (var i=0; i<itemList.length; i++) {
		var idxNum = itemList[i].getElementsByTagName("idxNum")[0].firstChild.nodeValue;
		var depthName = itemList[i].getElementsByTagName("name")[0].firstChild.nodeValue;
		var cgroupNum = itemList[i].getElementsByTagName("cgroup")[0].firstChild.nodeValue;
		selectBox.options[i] = new Option(depthName,idxNum+'|'+cgroupNum);
	}
	if(i==0){
		selectBox.options[0] = (selectBox == $('select_depth2')) ? new Option('ÇØ´ç ÁßºÐ·ù°¡ ¾ø½À´Ï´Ù.',0) : new Option('ÇØ´ç ¼ÒºÐ·ù°¡ ¾ø½À´Ï´Ù.',0);
	}
}

function selectBoxChange(obj,val,tbl){
	selectBox = $(obj);
	new Ajax.Request("/_xml/getDepthValue.php?value="+val+"&tbl="+tbl, {asynchronous:false, onComplete: initCountryOption});
}

var selectBox2;

function initCountryOption2(req) {
	var xmlDoc = req.responseXML;
	var itemList = xmlDoc.getElementsByTagName("depth");
	var resultValue = "";
	var rowIndex = 1;
	if(selectBox2 == $('select_depth2')){
		$('select_depth2').options.length = 0;
		if($('select_depth3')) $('select_depth3').options.length = 0;
		if($('select_depth3')) $('select_depth3').options[0] = new Option('ÁßºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä.',0);
	} else {
		$(selectBox2).options.length = 0;
	}
	selectBox2.options[0] = new Option("¼±ÅÃ",0);
	for (var i=0; i<itemList.length; i++) {
		var idxNum = itemList[i].getElementsByTagName("idxNum")[0].firstChild.nodeValue;
		var depthName = itemList[i].getElementsByTagName("name")[0].firstChild.nodeValue;
		var cgroupNum = itemList[i].getElementsByTagName("cgroup")[0].firstChild.nodeValue;
		selectBox2.options[i+1] = new Option(depthName,idxNum+'|'+cgroupNum);
	}
	if(i==0){
		selectBox2.options[0] = (selectBox2 == $('select_depth2')) ? new Option('´ëºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä.',0) : new Option('ÁßºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä.',0);
	}
}

function selectBoxChange2(obj,val,tbl){
	selectBox2 = $(obj);
	new Ajax.Request("/_xml/getDepthValue.php?value="+val+"&tbl="+tbl, {asynchronous:false, onComplete: initCountryOption2});
}

var selectBox3;

function initCountryOption3(req) {
	var xmlDoc = req.responseXML;
	var itemList = xmlDoc.getElementsByTagName("depth");
	var resultValue = "";
	var rowIndex = 1;
	if(selectBox3 == $('select_depth2')){
		$('select_depth2').options.length = 0;
		if($('select_depth3')) $('select_depth3').options.length = 0;
		if($('select_depth3')) $('select_depth3').options[0] = new Option('ÁßºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä.',0);
	} else {
		$(selectBox3).options.length = 0;
	}
	selectBox3.options[0] = new Option("¼±ÅÃ",0);
	for (var i=0; i<itemList.length; i++) {
		var idxNum = itemList[i].getElementsByTagName("idxNum")[0].firstChild.nodeValue;
		var depthName = itemList[i].getElementsByTagName("name")[0].firstChild.nodeValue;
		var cgroupNum = itemList[i].getElementsByTagName("cgroup")[0].firstChild.nodeValue;
		selectBox3.options[i+1] = new Option(depthName,idxNum);
	}
	if(i==0){
		selectBox3.options[0] = (selectBox3 == $('select_depth2')) ? new Option('´ëºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä.',0) : new Option('ÁßºÐ·ù¸¦ ¼±ÅÃÇÏ¼¼¿ä.',0);
	}
}

function selectBoxChange3(obj,val,tbl){
	selectBox3 = $(obj);
	new Ajax.Request("/_xml/getDepthValue.php?value="+val+"&tbl="+tbl, {asynchronous:false, onComplete: initCountryOption3});
}