
 function Category(value, text) {
  this.value = value;
  this.text = text;
  this.length = 0;
 }

 function addCategory(category, value, text) {
  category[category.length] = new Category(value, text);
  category.length++;
 }

 var category = new Category();

 function initForm(form,val1,val2,val3,val4) {
	create_article_area1();
	var val1_exist = -1;
	if (val1!="")
	{
		for (i = 0; i < category.length; i++){
			if (val1==category[i].text)
			{
				setSel(1,i,val1);
				val1_exist = i;
				break;
			}
		}
	}

	var val2_exist = false;
	if (val2!="" && val1_exist>=0)
	{
		create_article_area2(val1_exist);

		for (i = 0; i < category[val1_exist].length; i++){
			if (val2==category[val1_exist][i].text)
			{
				setSel(2,i,val2);
				val2_exist = i;
				break;
			}
		}
	}

	var val3_exist = false;
	if (val3!="" && val1_exist>=0 && val2_exist>=0)
	{
		create_article_area3(val1_exist,val2_exist);

		for (i = 0; i < category[val1_exist][val2_exist].length; i++){
			if (val3==category[val1_exist][val2_exist][i].text)
			{
				setSel(3,i,val3);
				break;
			}
		}
	}

	document.tsForm.article_area4.value=val4;
 }
 
function change_article_area1(form) 
{
		var i = document.getElementById("article_area1_id").value;	//SelectBox index키

		// 하위 정리
		clearSel(3);
		clearSel(2);
		if (i>=0)
		{
			var aaa = oneSel_create("국가","국가",2,-1);
			for (j = 0; j < category[i].length; j++){
				aaa = aaa + oneSel_create(category[i][j].text,category[i][j].value,2,j);
			}
			createSel(2,aaa);
		}
		change_article_area2(form);
 }

 
function change_article_area2(form) 
{
	var i = document.getElementById("article_area1_id").value;
	var j = document.getElementById("article_area2_id").value;

	// 하위 정리
	clearSel(3);

	if (j>=0)
	{
		var aaa = oneSel_create("지역","지역",3,-1);
		for (k = 0; k < category[i][j].length; k++){
		aaa = aaa + oneSel_create(category[i][j][k].text,category[i][j][k].value,3,k);
		}
		createSel(3,aaa);
	}
 }
 
 function create_article_area1(form) {
	// 하위 정리
	clearSel(1);

	var aaa = oneSel_create("대륙선택","대륙선택",1,-1);
	for (i = 0; i < category.length; i++){
		aaa = aaa + oneSel_create(category[i].text,category[i].value,1,i);
	}
	createSel(1,aaa);
 }

 function create_article_area2(id) {
	// 하위 정리
	clearSel(2);

	var aaa = oneSel_create("국가선택","국가선택",2,-1);
	for (i = 0; i < category[id].length; i++){
		aaa = aaa + oneSel_create(category[id][i].text,category[id][i].value,2,i);
	}
	createSel(2,aaa);
 }

 function create_article_area3(id1,id2) {
	// 하위 정리
	clearSel(3);

	var aaa = oneSel_create("지역선택","지역선택",3,-1);
	if(id1!='' && id2!='')
	{
		for (i = 0; i < category[id1][id2].length; i++){
			aaa = aaa + oneSel_create(category[id1][id2][i].text,category[id1][id2][i].value,3,i);
		}
		createSel(3,aaa);
	}
 }

 function change_compo(){
  //var l = document.form.article_area3.selectedIndex;
  //alert("value >>"+document.form.article_area3[l].value);
  //alert("text >>"+document.form.article_area3[l].text);
 }




///////////////// div 제어 하기 /////////////////////
var _selectBox_id = 0;
function setSel(id,no,val)
{
	var selectedDic = document.getElementById("div_select_"+id);

	selectedDic.innerHTML = val;

	var obj = document.getElementById("article_area"+id);
	if (obj)
	{
		if(val=="대륙선택" || val=="국가선택" || val=="지역선택"){	
			obj.value = '';
		}else{
			obj.value = val;
		}
	}
	obj = document.getElementById("article_area"+id+"_id");
	if (obj)
	{
		obj.value = no;
	}
}

function oneSel_create(text,val,id,no){
	if(val=="대륙선택" || val=="국가선택" || val=="지역선택") val="";
	var firstSel_str= "<div id='div"+id+"' class='none_selected' style='width:70px;' onclick='selectDropDown(this,"+id+","+no+");' onmouseover='Background_on(this)' onmouseout='Background_off(this)'><a href='javascript:void(0);' class='stop' >"+text+"</a><input name='val' type='hidden' value='"+val+"' /><input name='text' type='hidden' value='"+text+"' /></div>\n";
	return firstSel_str;
}


function createSel(id,ss){
	var obj = document.getElementById("div_select_row_"+id);
	if (obj)
	{
		obj.innerHTML = ss;
	}
}

function clearSel(id)
{
	if(id==1) var tlt = "대륙선택";
	if(id==2) var tlt = "국가선택";
	if(id==3) var tlt = "지역선택";
	createSel(id,oneSel_create(tlt,"0",id));
	setSel(id,-1,tlt);
}

function showDropDown(id) {
	
	if (id)
	{
		var obj;
		for (i=1;i<=3 ;i++ )
		{
			obj = document.getElementById("div_select_row_"+i);
			if (obj && i!=id){
				obj.style.display = "none";
			}
		}
		_selectBox_id = id;
		var dicDropDown = document.getElementById("div_select_row_"+id);
		if (dicDropDown)
		{
			if (dicDropDown.style.display=="none")
			{
				dicDropDown.style.display = "block";
			} else {
				dicDropDown.style.display = "none";
			}
		}
	} else {
		var obj;
		for (i=1;i<=3 ;i++ )
		{
			obj = document.getElementById("div_select_row_"+i);
			if (obj )
			{
				obj.style.display = "none";
			}
		}
	}
}

function selectDropDown(list,id,no) {

	var selectedDic = document.getElementById("div_select_"+id);

	value		= list.getElementsByTagName("a")[0].innerHTML;	//		
	dicFidx		= list.getElementsByTagName("input")[0].value;  //value
	dicFtext	= list.getElementsByTagName("input")[1].value;	//text
	selectedDic.innerHTML = value;

	//지역 이름
	var obj = document.getElementById("article_area"+id);
	if (obj)
	{
		obj.value = dicFtext;
	}
	//지역 셀렉트박스 index
	obj = document.getElementById("article_area"+id+"_id");
	if (obj)
	{
		obj.value = no;
	}
	//지역 idx
	obj = document.getElementById("article_area"+id+"_idx");
	if (obj)
	{
		obj.value = dicFidx;
	}


	var lists = list.parentNode.childNodes;
	for(var i=0; i<lists.length; i++) {
		var temp = lists[i];
		temp.className = "none_selected";
	}
	list.className = "selected";
	selectedDic.innerHTML = value;
	showDropDown(id);

	if (id==1)
	{
		change_article_area1(document.tsForm);
	}
	if (id==2)
	{
		change_article_area2(document.tsForm);
	}
	///////////////////////////////////////////
	// Flash 호출함수
	onSel_flash(id,dicFidx);
	///////////////////////////////////////////

}

function onMouseDown(e) {
	if(!e) e = window.event;
	
	var target = e.target ? e.target : e.srcElement;
	
	if(target.className != "stop" && target.className != "over_selected") {
		_hideDropDown = false;
		showDropDown();	
	}
}

function Background_on(list){
	if (list.className != "selected")
	{
		list.className = "over_selected";
	}
}
function Background_off(list){
	if (list.className != "selected")
	{
		list.className = "none_selected";
	}
}


if(window.addEventListener)
	document.addEventListener("mousedown",onMouseDown, false);
else if(window.attachEvent)
	document.attachEvent("onmousedown", onMouseDown);






//////////////////////////////////////////////////////////////////////////
//Flash 
//////////////////////////////////////////////////////////////////////////
function onSel_flash(id,val)
{
	//플래쉬지역 확대
	if( id=='1' || id=='2' )
	{
		var flash_id1 = eval("document.getElementById('fid_"+val+"')");
		if( flash_id1.value!=null && flash_id1.value!="" && flash_id1.value!=",,"){	
			var param = flash_id1.value; 
			MyF_1(param);
		}
	}
	//지역컨텐츠정보
	get_Text( val );
}

var xmlhttps;
function createXMLHttpRequest() {
	var xmlhttps = false;
	if (window.XMLHttpRequest) {
		xmlhttps = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			xmlhttps = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try { xmlhttps = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				// Unable to create an XMLHttpRequest with ActiveX
			}
		}
	}
	return xmlhttps;
}
function get_Text(val)
{  
	//플래쉬지역 정보
	xmlhttps					= createXMLHttpRequest();	//xmlhttp 객체반환
	var handlerFunctionTree		= processFlashContentList;
	xmlhttps.onreadystatechange	= handlerFunctionTree;
	//alert('11');
	xmlhttps.open("POST", "/header_flash_proc.php", true);	// 도메인 이후 경로로 지정할것!!!
	xmlhttps.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//alert("idx="+val);
	xmlhttps.send("idx="+val);
}
function processFlashContentList() 
{
	if (xmlhttps.readyState == 4) {
		if (xmlhttps.status == 200) {
			//alert( xmlhttps.responseText );
			printFlashContentList();
		} else {
			alert("There was a problem retrieving the XML data:\n"+xmlhttps.statusText);
		}

	}

}
function printFlashContentList() 
{	
	document.getElementById("main_text").innerHTML = xmlhttps.responseText;
}



/*##############################################
## 웹사이트 --> 플래쉬 호출함수
################################################*/
//When select something in dropdown menu
function MyF_1(param) 
{	//플래쉬파일이 같은경로 위치
	window.document.locator_map.SetVariable("F_1", param);
}


/*##############################################
## 플래쉬 --> 웹사이트 호출함수
################################################*/
/* When click on country/state.  Show contact info for this country/state. Open name of country in dropdown menu  */
function set_world(div_name)
{	//플래쉬에서 호출 대륙선택
	if(div_name)
	{
		var idx1	= fmenu[ div_name ][0];	//value
		var val1	= fmenu[ div_name ][1];	//text
		//## clearSel(3); clearSel(2);
		//## var val4	= document.getElementById("article_area4").value;
		//SelectBox 선택
		//## initForm(document.tsForm,val1,"","",val4);
		//지역컨텐츠정보
		get_Text( idx1 );
	}
}

// fmenu => flash_id 로부터 지역idx,name 추출
function set_text(div_name)
{  
	//플래쉬에서 호출, 나라선택
	if(div_name){
		//## var val1 = document.getElementById("article_area1").value;
		var idx2 = fmenu[ div_name ][0];	//value
		var val2 = fmenu[ div_name ][1];	//text
		//## clearSel(3);	
		//## var val4 = document.getElementById("article_area4").value;
		//SelectBox 선택
		//## initForm(document.tsForm,val1,val2,"",val4);
		//지역컨텐츠정보
		get_Text( idx2 );	
	}

}
function set_level3(div_id)
{	
	//플래쉬에서 호출, 지역선택
	if(div_id)
	{
		//## var val1 = document.getElementById("article_area1").value;
		//## var val2 = document.getElementById("article_area2").value;
		//## var flash_id3 = eval("document.getElementById('fid_"+div_id+"')");
		//## if( flash_id3.value!=null ){	
		//## 	var val3 = flash_id3.value; 
		//## }
		//## var val4 = document.getElementById("article_area4").value;

		//SelectBox 선택
		//## initForm(document.tsForm,val1,val2,val3,val4);
		//지역컨텐츠정보
		get_Text( div_id );	
	}
}
/* When click on button 'back' on map. Hide contact infromation. Dropdown menus in default. */
function back()
{
	alert('back');
	//document.getElementById('main_text').innerHTML;=document.getElementById('main_back').innerHTML;
	//document.getElementById('opt_continent').selected='true';
	//document.getElementById('opt_country').selected='true';
}









/*
#########################################################################
## 플래쉬 오른쪽 국가정보 가져오기 2010-05-00
#########################################################################
*/
function openTema(seq,page,idx,table){
	//alert( 'seq:'+ seq +'|page:'+ page +'|idx:'+idx +'|table:'+ table );
	for(var i=0; i<6; i++){
		if(i==seq){
			if(document.getElementById("tema"+i)){
				document.getElementById("tema"+i).style.display			= 'block';
				FlashPageList(seq,page,idx,table);
			}
		}else{
			if(document.getElementById("tema"+i)){
				document.getElementById("tema"+i).style.display			= 'none';
			}
		}
	}
}
function FlashPageList(seq,page,idx,table)
{  
	xmlhttps					= createXMLHttpRequest();	//xmlhttp 객체반환
	var handlerFunction			= processList;
	xmlhttps.onreadystatechange	= handlerFunction;
	xmlhttps.open("POST", "/cron/create_arealistXml.php", true);	//도메인 이후 경로로 지정할것!!!
	xmlhttps.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttps.send("seq="+seq+"&idx="+idx+"&table="+table+"&page="+page);
	//alert("seq="+seq+"idx="+idx+"&table="+table+"&page="+page);
	
	document.getElementById("tema"+seq).style.textAlign = "center";
	document.getElementById("tema"+seq).innerHTML		= "<img src='/img/common/ajax-loader5.gif'>";
}
function processList() 
{
	if (xmlhttps.readyState == 4) {
		if (xmlhttps.status == 200) {
			Printout();
		} else {
			alert("There was a problem retrieving the XML data:\n"+xmlhttps.statusText);
		}
	}
}
function Printout()
{
	var lists					= xmlhttps.responseXML.getElementsByTagName("lists")[0]; 
	var items					= lists.getElementsByTagName("item");					
	var outhtml					= "";
	//outhtml						+= "<UL class='sso_thema'>";
	//outhtml						+= "<UI>";
	if(items.length > 0){
		for(var i=0; i<items.length; i++){
			var item			= items[i];
			var seq				= item.getElementsByTagName("seq")[0].firstChild.nodeValue;
			var article_id		= item.getElementsByTagName("article_id")[0].firstChild.nodeValue;
			var headline_id		= item.getElementsByTagName("headline_id")[0].firstChild.nodeValue;
			var	total_string	= item.getElementsByTagName("total_string")[0].firstChild.nodeValue;
			var	page_list		= item.getElementsByTagName("page_list")[0].firstChild.nodeValue;
			outhtml				+= "<LI>";
			outhtml				+= "- <a href='/content/news_view.html?m_id=0200&cat_id=&uid="+article_id+"&hid="+headline_id+"&page='>"+total_string+"</a>";
			outhtml				+= "</LI>";
		}
			outhtml				+= "<LI id='Paging' text:align:center;'>"+page_list+"</LI>";
	}else{
	}	
	//outhtml						+= "</UI>";
	//outhtml						+= "</UL>";
	var tema_ui = document.getElementById("tema"+seq);
	tema_ui.innerHTML = outhtml;
}
