var SearchUnion_SelectedCallback=null;
function SearchUnion_SetLocation(header, tobjID, tcon, tcty, tloc, selidx, locidx)
{
	
	var inHTML="";
	if(tloc!="")
		inHTML+=tloc;
	if(inHTML!="")
		inHTML+=" / ";
	if(tcty!="")
		inHTML+=tcty;
	if(inHTML!="")
		inHTML+=" / ";
	if(tcon!="")
		inHTML+=tcon;
	
	document.getElementById(tobjID+"_selection").title=inHTML;
	//inHTML="<span style='color:#848484' nowrap >"+inHTML+"</span>";	
	document.getElementById(tobjID).value="";
	document.getElementById(tobjID+"_selection").innerHTML=inHTML;
	document.getElementById(tobjID+"_value").value=selidx;
	document.getElementById(tobjID+"_loc_value").value=locidx;
	document.getElementById(tobjID+"_type").value=header;
	document.getElementById(tobjID+"_input").style.display="none";
	document.getElementById(tobjID+"_selection").style.display="inline";
	if(SearchUnion_SelectedCallback!=null)
		SearchUnion_SelectedCallback(header);
	
			
}
function SearchUnion_ShowInput(tobjID)
{
	document.getElementById(tobjID+"_type").value="";
	document.getElementById(tobjID+"_loc_value").value="";
	document.getElementById(tobjID+"_value").value="";
	document.getElementById(tobjID+"_input").style.display="inline";
	document.getElementById(tobjID+"_selection").style.display="none";
	document.getElementById(tobjID).focus();
}
function SearchUnion_MakeInput(tobjID, twidth, theight, selectedCallback)
{
	SearchUnion_MakeInput_Core(tobjID, twidth, theight, selectedCallback, "");
}
function SearchUnion_MakeInput_Core(tobjID, twidth, theight, selectedCallback, styleEx)
{
	SearchUnion_SelectedCallback=selectedCallback;
	var inHTML="<table onblur=\"SearchUnion_ShowCloseLayer('"+tobjID+"', true);\" width=\""+twidth+"\" cellpadding=0 cellspacing=0 border=0 style=\"cursor:default;\">"
	inHTML+="	<tr><td valign=\"top\">";
	inHTML+="	<table cellpadding=0 cellspacing=0 border=0 style=\"width:100%;height:20px;border:1px solid #C0C0C0;background:#FFFFFF;"+styleEx+"\">";
	inHTML+="	<tr>";
	inHTML+="	<td width=100% height=\"20\" style=\"color:#444444;" + styleEx + "\">";
	inHTML+="	<div style=\"width:"+twidth+";display:none;\" id=\""+tobjID+"_input\"><input type=\"text\" style=\"color:red;width:100%;height:17px;border:0px solid #ffffff;background-color:Transparent;\" id=\""+tobjID+"\" name=\""+tobjID+"\" onkeyup=\"return SearchUnion_OnKeyUpEvent(this);\"/></div>";
	//inHTML+="	<div style=\"width:100%;display:inline;\" id=\""+tobjID+"_input\"><input type=\"text\" style=\"color:red;width:100%;height:17px;border:0px solid #ffffff;background-color:Transparent;\" id=\""+tobjID+"\" name=\""+tobjID+"\" /></div>";
	inHTML+="	<div style=\"width:"+twidth+"px;height:20px;line-height:20px;display:inline;text-align:left;overflow:hidden;text-overflow:ellipsis;color:#848484\" nowrap title=\"\" id=\""+tobjID+"_selection\" onclick=\"SearchUnion_ShowInput('"+tobjID+"')\">도시 또는 랜드마크(예>에펠탑, 신주쿠, 인천공항, 코엑스)를 입력하세요!</div>";
	inHTML+="	<input type=\"hidden\" id=\""+tobjID+"_value\" name=\""+tobjID+"_value\"/>";
	inHTML+="	<input type=\"hidden\" id=\""+tobjID+"_loc_value\" name=\""+tobjID+"_loc_value\" value=\"0\"/>";
	inHTML+="	<input type=\"hidden\" id=\""+tobjID+"_type\" name=\""+tobjID+"_type\" value=\"0\"/>";
	//alert(inHTML);
	inHTML+="	</td>";
	inHTML+="	</tr>";
	inHTML+="</table></td></tr></table>";
	inHTML+="<div  id=\""+tobjID+"_Layer\" style=\"width:"+(twidth)+";position:absolute;display:none;z-index:23;\">"
	inHTML+="<TABLE onblur=\"SearchUnion_ShowCloseLayer('"+tobjID+"', false);\" WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" id=\""+tobjID+"_rtable\" >";
	inHTML+="    <TR>";
	inHTML+="        <TD STYLE=\"border: 3px solid #55cedc;\">";
/*	inHTML+="            <table WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">";
	inHTML+="                <tr>";
	inHTML+="                    <td HEIGHT=\"20\" BGCOLOR=\"#f2f2f2\">";
	inHTML+="<table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	inHTML+="	<tr>";
	inHTML+="		<td><img src='/images/pop_btm_title001.gif'></td><td align=\"right\"><img src=\"/images/pop_btm_close01.gif\" onclick=\"javascript:SearchUnion_ShowCloseLayer('"+tobjID+"', false);\" style=\"cursor:pointer\"></td>";
	inHTML+="	</tr>";
	inHTML+="</table>";
	inHTML+="                </tr>";
	inHTML+="                <tr>";
	inHTML+="                    <td>";
	inHTML+="<div id=\""+tobjID+"_Results\" style=\"height:"+theight+";overflow-y:scroll;width:"+(twidth)+";\"></div>"
	inHTML+="<div id=\""+tobjID+"_CurSel\" style=\"display:none;\">-1</div>"
	inHTML+="<div id=\""+tobjID+"_CurCol\" style=\"display:none;\">ct</div>"
	inHTML+="                    </td>";
	inHTML+="                </tr>";
	inHTML+="            </table>";*/
	
	inHTML+="<table onblur=\"SearchUnion_ShowCloseLayer('"+tobjID+"', false);\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" id=\""+tobjID+"_rtable\">";
inHTML+='  <tr>';
inHTML+="    <td><img src=\"/images/search_top_title.gif\" alt=\"여행지\" width=\"205\" height=\"25\"><img src=\"/images/search_top_title01.gif\" alt=\"랜드마크/지명/공항/전시장...\" width=\"177\" height=\"25\"><img src=\"/images/search_top_title01_1.gif\" alt=\"닫기\" width=\"43\" height=\"25\" onclick=\"javascript:SearchUnion_ShowCloseLayer('"+tobjID+"', false);\" style=\"cursor:pointer\"></td>";
inHTML+='  </tr>';
inHTML+='  <tr>';
inHTML+='    <td background="/images/search_content_BG.gif">';
inHTML+="<div id=\""+tobjID+"_Results\" style=\"height:"+theight+";overflow-y:scroll;width:"+(twidth)+";\"></div>"
inHTML+="<div id=\""+tobjID+"_CurSel\" style=\"display:none;\">-1</div>"
inHTML+="<div id=\""+tobjID+"_CurCol\" style=\"display:none;\">ct</div>"
inHTML+='	</td>';
inHTML+='  </tr>';
inHTML+='  <tr>';
inHTML+='    <td><img src="/images/search_btm_title.gif" alt="이동,선택, 유명관광지 선택시, 반경 2.5km 이내 검색" width="425" height="20"></td>';
inHTML+='  </tr>';
inHTML+='</table>';


	inHTML+="        </TD>";
	inHTML+="    </TR>";
	inHTML+="</TABLE>";
	


	
	inHTML+="</div>";

	
	document.write(inHTML);
}

function SearchUnion_SelItem(header, tobjID, selindex, locidx)
{
	
	document.getElementById(tobjID+"_Layer").style.display="none";
	eval(document.getElementById(header+"_"+tobjID+"selfunc"+selindex+"_"+locidx).innerHTML.toString().replace(/\"\\\&quot;/g, "\\\"").replace(/\\\&quot;\"/g, "\\\""));
}
function SearchUnion_MouseOver(tobj)
{
	tobj.style.background="#F5D8BA";
	tobj.style.cursor="hand";
}
function SearchUnion_MouseOut(tobj)
{
	tobj.style.background="#FFFFFF";
}

function SearchUnion_ReadyState(tsuccess, retval, terrorcode, tobjID)
{
	if(terrorcode==200)
	{
		try{
			
			var oLayer=document.getElementById(tobjID+"_Layer");
			var oCurSel=document.getElementById(tobjID+"_CurSel");
			var oCurCol=document.getElementById(tobjID+"_CurCol");
			var rResults=document.getElementById(tobjID+"_Results");
			oCurSel.innerHTML="0";
			oCurCol.innerHTML="ct";
			rResults.innerHTML=retval;
			
			var oResults=document.getElementById(oCurCol.innerHTML+"_"+tobjID+"_Results");
			{
				
				if(oResults)
				{
					oResults.scrollTop="0";
					if(oResults.childNodes[0].childNodes.length>0)
					{
						var tdiv=oResults.childNodes[0].childNodes[0].childNodes[0].childNodes[0];
						SearchUnion_MouseOver(tdiv);
					}
				}
				bLastReqUnionSearchKeyResponse=true;
				oLayer.style.display="inline";
			}
				
			
		}catch(e)
		{
		}
		
	}
}

var LastReqUnionSearchKey="";
var bLastReqUnionSearchKeyResponse=false;
var SearchUnionAJAXCore=new nineAJAX("SearchUnionAJAXCore");
function SearchUnion_ShowResultLayer(tobjID)
{
	//if(document.getElementById(tobjID).value
	var tval=document.getElementById(tobjID).value;
	var tlayer=document.getElementById(tobjID+"_Layer");
	var fheader="";
	if(tval.charCodeAt(0)<=255)
	{
		fheader=tval.substr(0, 2);
	}
	else
	{
		fheader=tval.substr(0, 1);
	}
	if(LastReqUnionSearchKey!=Trim(tval.toLowerCase()))
	{
		bLastReqUnionSearchKeyResponse=false;
		turl="/common/AJAXLib/AJAX_Client_GetSynonymList_ForUnion.asp?ObjID="+tobjID+"&FindWord="+escape(tval)+"&width="+400;//parseInt(tlayer.style.width,10);
		try{
			LastReqUnionSearchKey=Trim(tval.toLowerCase());
			//window.open(turl);
			SearchUnionAJAXCore.ModuleReset();
			SearchUnionAJAXCore.SendXmlhttp(turl, 1, "SearchUnion_ReadyState", tobjID);
			
			
			
			
		}catch(e)
		{
		}
	}
	else
	{
		if(bLastReqUnionSearchKeyResponse)
		{
			SearchUnion_ShowCloseLayer(tobjID, true);
		   
		}
	}
	
	
}
function SearchUnion_ShowCloseLayer(tobjID, bshow)
{
   if(bshow)
   {
	 
	 gLayerManager.OpenLayer(tobjID+"_Layer");
	 document.getElementById(tobjID+"_Layer").style.display="inline";
	 //document.getElementById(tobjID+"_rtable").focus();
   }
   else
   {
	
	 gLayerManager.CloseLayer(tobjID+"_Layer");
	 document.getElementById(tobjID+"_Layer").style.display="none";
	 //document.body.onclick = null;
   }
}
function SearchUnion_OnKeyUpEvent(tobj)
{
	var tval=tobj.value;
	if(tval.length==0)
	{
		document.getElementById(tobj.id+"_Layer").style.display="none";
		return;
	}
	if(tval.length==1)
	{
		if(tval.charCodeAt(0)<=255)
		{
			document.getElementById(tobj.id+"_Layer").style.display="none";
			return;
		}
		
	}
	SearchUnion_ShowResultLayer(tobj.id);
	//document.body.onclick = CloseSearchLayer;
	return false;
}

function SearchUnion_LayerKeyControl(objID, keyCode)
{
	objID=objID.replace("_Layer", "");
	var oCurSel=document.getElementById(objID+"_CurSel");
	var oCurCol=document.getElementById(objID+"_CurCol");
	var oResultLayer=document.getElementById(oCurCol.innerHTML+"_"+objID+"_Results");
	var rResults=document.getElementById(objID+"_Results");
	if(keyCode==13 || keyCode==38 || keyCode==40 || keyCode==39 || keyCode==37)
	{
		//alert(oResultLayer.childNodes[0].childNodes[0].childNodes[0].outerHTML);
		var tbody=oResultLayer.childNodes[0];
		
		var oldIdx=parseInt(oCurSel.innerHTML, 10);
		
			
		switch(keyCode)
		{
		case 39://->
			if(oCurCol.innerHTML!="lm")
			{
				if(document.getElementById("lm_"+objID+"_Results").childNodes[0].childNodes.length==0)
				{
					break;	
				}
				if(oldIdx!=-1)
				{
					
					var tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
					SearchUnion_MouseOut(tdiv);
				}
				
				
				oCurCol.innerHTML="lm";
				oResultLayer=document.getElementById(oCurCol.innerHTML+"_"+objID+"_Results");
				tbody=oResultLayer.childNodes[0];
				if(tbody.childNodes.length<=0 || tbody.childNodes.length<=oldIdx)
				{
					oldIdx=0;
				}
				if(tbody.childNodes.length>0)
				{
					tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
					SearchUnion_MouseOver(tdiv);
					if(rResults.scrollTop>(oldIdx*20))
						rResults.scrollTop=(oldIdx*20);	
				}
				else
				{
					oldIdx=-1;
				}
				oCurSel.innerHTML=oldIdx;
				
						
			}
			
					
			break;
		case 37://<-
			if(oCurCol.innerHTML!="ct")
			{
				if(document.getElementById("ct_"+objID+"_Results").childNodes[0].childNodes.length==0)
				{
					break;	
				}
				if(oldIdx!=-1)
				{
					var tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
					SearchUnion_MouseOut(tdiv);
				}
				
				
				
				oCurCol.innerHTML="ct";
				oResultLayer=document.getElementById(oCurCol.innerHTML+"_"+objID+"_Results");
				tbody=oResultLayer.childNodes[0];
				if(tbody.childNodes.length<=0 || tbody.childNodes.length<=oldIdx)
				{
					oldIdx=0;
				}
				if(tbody.childNodes.length>0)
				{
					tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
					SearchUnion_MouseOver(tdiv);
					if(rResults.scrollTop>(oldIdx*20))
						rResults.scrollTop=(oldIdx*20);	
				}
				else
				{
					oldIdx=-1;
				}
				oCurSel.innerHTML=oldIdx;
				
						
			}
			
					
			break;
		case 13:
			var tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
			tdiv.onclick();
			break;
		case 38:
			if(tbody.childNodes.length<1)
			{
				
				if(oCurCol.innerHTML=="lm")
				{
					if(document.getElementById("ct_"+objID+"_Results").childNodes[0].childNodes.length<1)
					{
						break;
					}
					oCurCol.innerHTML="ct";
					oResultLayer=document.getElementById("ct_"+objID+"_Results");
					tbody=oResultLayer.childNodes[0];
				}
			}
			if(oldIdx>=1)
			{
				var tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
				SearchUnion_MouseOut(tdiv);
				oldIdx--;
				tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
				SearchUnion_MouseOver(tdiv);
				oCurSel.innerHTML=oldIdx;
				if(rResults.scrollTop>(oldIdx*20))
					rResults.scrollTop=(oldIdx*20);
			}
			
			break;
		case 40:
			
			if(tbody.childNodes.length<1)
			{
				if(oCurCol.innerHTML=="ct")
				{
					if(document.getElementById("lm_"+objID+"_Results").childNodes[0].childNodes.length<1)
					{
						break;
					}
					oCurCol.innerHTML="lm";
					oResultLayer=document.getElementById("lm_"+objID+"_Results");
					tbody=oResultLayer.childNodes[0];
				}
				
			}
			if(oldIdx<(tbody.childNodes.length-1))
			{
				
				var tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
				SearchUnion_MouseOut(tdiv);
				
				
			}
			oldIdx++;
			if(oldIdx>=(tbody.childNodes.length))
				oldIdx=tbody.childNodes.length-1;
			tdiv=tbody.childNodes[oldIdx].childNodes[0].childNodes[0];
			SearchUnion_MouseOver(tdiv);
			oCurSel.innerHTML=oldIdx;
			if(rResults.scrollTop+parseInt((rResults.style.height), 10)<=(oldIdx*20))
				rResults.scrollTop+=20;
			
			
			break;
		case 27:
			document.getElementById(objID+"_value").value=selidx;
			document.getElementById(objID+"_input").style.display="none";
			document.getElementById(objID+"_selection").style.display="inline";
			break;
		}
		
		return true;
	}
	return false;
}
//document.onkeyup = new Function("SearchUnion_OnKeyUpEvent(document.all.sDestination);");


