	var g_nKeyStatus;
	var g_isIE;
	var g_objTextSearch;
	var g_nCheckTime;
	var g_nResultIndex;
	var g_nResultIndexOn;
	var g_nMaxRow;
	var g_strTextSearchBak;
	var g_strTextSearchOld;
	var g_objList;
	var g_nListCount;
	var g_nFrmOn;
	var g_nTextSearchOn;
	var g_nTrHeight;
	var g_bReady;
	var g_isFireFox;
	var g_rPosMargin = [0,2];
	var g_iListItemStrWidth = 100;
	
	function InitializeAddTag(objTextSearch)
	{
		if(document.getElementById(objTextSearch))
		{
			g_objTextSearch = document.getElementById(objTextSearch);
			
			g_objTextSearch.autoComplete = "off";
		}
	}
	
	function fnDisplayTagList(arrResult,strQuery)
	{
		var strResult;
		if(arrResult[0] == "" || arrResult[1] == null || arrResult[1].data == null || arrResult[1].data.length == 0 )
		{
			HideFrame();
			
		}
		else
		{
			strResult = "";
			var strDisplay;
			var strValidDisplay;
			
			for(var nLoop = 0; nLoop < arrResult[1].data.length; nLoop++)
			{
				strResult = ""
				strDisplay = arrResult[1].data[nLoop].disp;
				if(strDisplay != "" )
				{					
					strValidDisplay = strDisplay.split("<").join("&lt;");
					strDisplay = GetPixelSizedText(strDisplay, g_iListItemStrWidth, false);					
					var nIndex = nLoop+1;
					
					var nStart = strDisplay.indexOf(strQuery.toUpperCase());
					if (nStart != -1)
					{
						nStart = nStart + strQuery.length ;
						var strDisplayHighlight = strDisplay.substring(0,nStart);
						strDisplayHighlight = "<span style=\"color:#826FED;\">" + strDisplayHighlight + "</span>";
						var strDisplayRemain = strDisplay.substring(nStart,strDisplay.length);						
						strDisplay = strDisplayHighlight + strDisplayRemain;						
					}
					document.getElementById('idDivTag' + nIndex).innerHTML = strDisplay;					
					document.getElementById('idTrTagText' + nIndex).innerHTML = strValidDisplay;
					document.getElementById('idDivTag' + nIndex).style.display = "block";											
				}
			}	
			for(var nLoopRemain = arrResult[1].data.length; nLoopRemain < 20; nLoopRemain ++)
			{
				var nIndex = nLoopRemain+1;					
				document.getElementById('idDivTag' + nIndex).style.display = "none";
			}
			
		}
		return strResult;
	}
	
	function InitializeFrame(sType)
	{
		g_bReady = false;
		g_nKeyStatus = 2;
		g_isIE = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
		g_isFireFox = ((navigator.userAgent.toLowerCase().indexOf("firefox"))!= -1);
		g_nCheckTime = 500;
		g_nResultIndex = 0;
		g_nResultIndexOn = 0;
		g_nMaxRow = 3;
		g_strTextSearchBak = "";
		g_strTextSearchOld = "";
		g_objList = new Object();
		g_nListCount = 0;	// ÇöÀç ¸®½ºÆ®ÀÇ °¹¼ö
		g_nFrmOn = 0;		// frameÀÌ º¸¿©Áö´ÂÁö ¿©ºÎ
		g_nTextSearchOn = 0;
		g_nTrHeight = 16;		
		document.write("<div style='display:none;' id='idTagSuggestion' class='auto_tag_layer'>");
		document.write("<div class='list' id='idTagList'>");
		var strTagListTemp = "";
		for(var nLoop=0; nLoop< 20; nLoop++)
		{
			strTagListTemp += "<div id='idDivTag" + (nLoop + 1) + "' onmouseover=\"fnSetTagPos('" + (nLoop + 1) + "')\" onmouseout=\"fnSetTagPos(0); \" onclick=\"fnSetSearchText('" + (nLoop + 1) + "')\" >";
			strTagListTemp += "</div>";
			strTagListTemp += "<span id='idTrTagText" + (nLoop + 1) + "' style='display:none'></span>";
			
		}

		document.write(strTagListTemp);		
		document.write("</div>");
		document.write("</div>");
		if(sType != null)
			document.write("<img id='imgTagInfoLayers' src='/images/guide/taglayer_" + sType + ".gif' style='position:absolute;display:none'");

	}
	
	function OnTextFocus(e,obj)
	{ 
		g_objTextSearch = obj;			
		g_objTextSearch.onkeyup = fnOnKeyUp;
		g_nTextSearchOn = 1;
		g_nFrmOn = 0;
		fnRequestData2();
		g_bReady = true;
		if(obj.value == "ÅÂ±×ÀÔ·Â")
			obj.value = "";	
		
	}

	function fnInitializeText()
	{
		var e = (g_isIE) ? window.event : event;
		if(e.keyCode != 13 && g_nKeyStatus == 1)
		{
			g_objTextSearch.value = "";
			g_nKeyStatus = 2;
		}
	}
		
	function fnShowTS(strQuery, arrResult)
	{	
		if (strQuery && strQuery != "" && strQuery != fnTrimSpace(g_objTextSearch.value))
			return;
			
		var nLeft 	= 	getPageLeft(g_objTextSearch) + g_rPosMargin[0];
		var nTop 	= 	getPageTop(g_objTextSearch) + g_objTextSearch.offsetHeight + g_rPosMargin[1]; 		

		nTop = nTop + document.body.scrollTop;
		if(document.getElementById('uploader_scroll'))
			nTop = nTop - document.getElementById('uploader_scroll').scrollTop;
			
		
		nTop = nTop - document.body.scrollTop;
		g_nListCount = arrResult[1].data.length;
		var nHeight = (arrResult[1].data.length > g_nMaxRow + 1) ? g_nMaxRow + 1 : g_nListCount;
		nHeight = nHeight * g_nTrHeight;

		//document.getElementById("idTagList").innerHTML = fnDisplayTagList(arrResult);
		fnDisplayTagList(arrResult,strQuery);
		document.getElementById("idTagSuggestion").style.display = "block";
		setTimeout('fnConvertColor();', 10);

		//¾øÀ» °æ¿ì ³ôÀÌ Á¶Á¤
		if (arrResult[1].data.length == 0)
		{
			document.getElementById("idTagList").style.display = "none";
			document.getElementById("idTagSuggestion").style.display = "none";
		}
		else
		{
			document.getElementById("idTagList").style.display = "block";
			document.getElementById("idTagList").style.height = nHeight;// + 4;
			g_nResultIndexOn = 1;
			document.getElementById("idTagSuggestion").style.height = nHeight;
			document.getElementById("idTagSuggestion").style.display = "block";
			if(g_nResultIndexOn)
			{ 
				fnSetTagPos(0);
				document.getElementById("idTagList").scrollTop = 0;
			}
		}
		document.getElementById("idTagSuggestion").style.left = nLeft + "px";
		document.getElementById("idTagSuggestion").style.top = nTop + "px";	

	} 


	function fnSetTagPos(nIndex)
	{ 
		g_nResultIndex = nIndex;
		setTimeout('fnConvertColor();', 10);
	}

	function fnConvertColor()
	{ 
		 if (!g_nResultIndexOn)
			return;
		 var objDiv;
		 for (var nLoop = 0;  nLoop < g_nListCount; nLoop++)
		 {
			objDiv = document.getElementById("idDivTag" + (nLoop + 1));
			if ((nLoop+1) == g_nResultIndex)
				objDiv.className = "on";
			else
				objDiv.className = "off";
		}
	}

	function fnSetSearchText(strData)
	{ 
		if (!g_nResultIndexOn)
			return;

		g_nResultIndex = strData;
		var objTag = document.getElementById("idTrTagText" + g_nResultIndex);
				
		if(g_isIE)			
			g_strTextSearchOld = g_objTextSearch.value = objTag.innerText;
		else
			g_strTextSearchOld = g_objTextSearch.value = objTag.textContent;		
	

		fnAddTag(g_objTextSearch,false);
		HideFrame();
	}

	

	function fnGetList()
	{ 
		var strData = fnTrimSpace(g_objTextSearch.value);
		return (typeof(g_objList[strData]) == "undefined") ? null : g_objList[strData];
	} 

	function HideFrame()
	{
		if(document.getElementById("idTagSuggestion"))
		{
			if(document.getElementById("idTagSuggestion").style.display == "none")
				return;
			document.getElementById("idTagSuggestion").style.display = "none";
		}
		g_nResultIndexOn = g_nResultIndex = 0;
	} 

	function DispFrame()
	{
		if(g_objTextSearch == undefined) 
			return;
		
		var strTextSearch = g_objTextSearch.value;

		if(strTextSearch == "" && strTextSearch != g_strTextSearchOld)
			HideFrame(); 

		if (strTextSearch != "" && strTextSearch != g_strTextSearchOld && g_nKeyStatus != 1 && strTextSearch != "ÅÂ±×ÀÔ·Â")
		{
			var arrResult = null;
			arrResult = fnGetList();
			if (arrResult != null && arrResult[1].data[0] != "")
				fnShowTS(arrResult[0], arrResult);
			else
				fnRequestTS();
		}
		g_strTextSearchOld = strTextSearch;
		if(g_isFireFox) setTimeout("DispFrame()", g_nCheckTime);
	}
	
	function fnOnDivMouse(nOp)
	{
		g_nFrmOn = nOp;
	}
	
	function fnRequestData2()
	{ 		
		if(g_objTextSearch.value == "")
		{
			HideFrame();
			return;
		}

		var arrResult = fnGetList();
		if(arrResult !=  null && arrResult[1].data[0] != "")
			fnShowTS(arrResult[0], arrResult);
		else
			fnRequestTS();
	}

	function fnRequestTS()
	{
		var strData = fnTrimSpace(g_objTextSearch.value);
		if(strData == "")
		{ 
			HideFrame();
			return;
		}
		Request.sendPOST("/index/dic.do?action=suggestMapWordsList","_word=" + TongEncodeURIComponent(strData) , IsSuccessSuggestWords, strData);
	}
		
		
	function IsSuccessSuggestWords(httpRequest,strQuery)
	{			
		try 
		{
			eval("var oResult=" + httpRequest.responseText);
			var code = oResult.code;
			var sTagsData = "";
			var strResult = "";
			for (var i = 0 ; i < oResult.tongtags.length ; i++) 
			{	
				if(strResult.length == 0)
				{
					strResult = oResult.tongtags[i].suggestWord + "\t";
				}
				else
				{
					strResult += "\n" + oResult.tongtags[i].suggestWord + "\t";
				}
			}			
			var objTList = new TList(strResult);
			g_objList[strQuery] = new Array(strQuery, objTList);
			fnShowTS(strQuery, g_objList[strQuery]);	

		}	
		catch (e) {
		}	
	}
		
	function fnOnKeyUp(e,objTarget)
	{
		var ev = (g_isIE) ? window.event : e;
		var objTr, objTag;
		if(ev.keyCode==39 || ev.keyCode == 13 || ev.keyCode == 40 || (ev.keyCode == 9 && !ev.shiftKey)|| g_nResultIndexOn && (ev.keyCode==38 || (ev.keyCode==9 && ev.shiftKey)))
		{
		}
		else
		{
			fnRequestData2();
		}
		
	}
	function fnOnKeyDown(e,objTarget)
	{		
		var ev = (g_isIE) ? window.event : e;
		var objTr, objTag;
		if(ev.keyCode==39)
		{
			// right arrow;
			fnRequestData2();
		}
		else if(ev.keyCode == 13)
		{

			g_bReady = false;
			if(!CheckValidateChar(g_objTextSearch))
			{
				alert("Æ¯¼ö¹®ÀÚ´Â ÀÔ·ÂÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
				return;
			}
			fnAddTag(objTarget,true);
			ev.returnValue = false;
		}
		else if(ev.keyCode == 40 || (ev.keyCode == 9 && !ev.shiftKey))
		{ 
			// down arrow
			if(g_nResultIndexOn == 0)
			{
				fnRequestData2();
				return;
			}
			if(g_nResultIndex < g_nListCount)
			{
				if(g_nResultIndex == 0)
					g_strTextSearchBak = g_objTextSearch.value;
				g_nResultIndex++;
				objTr = document.getElementById("idTrTag" + g_nResultIndex);
				objTag = document.getElementById("idTrTagText" + g_nResultIndex);
								
				if(g_nResultIndex > g_nMaxRow)
					document.getElementById("idTagList").scrollTop = parseInt((g_nResultIndex - 1) / g_nMaxRow) * g_nMaxRow * g_nTrHeight;				
				
				if(g_isIE)			
					g_strTextSearchOld = g_objTextSearch.value = objTag.innerText;
				else
					g_strTextSearchOld = g_objTextSearch.value = objTag.textContent;
			
			
				g_objTextSearch.focus();
				fnConvertColor();
				
				ev.returnValue = false;
			}
		}
		else if(g_nResultIndexOn && (ev.keyCode==38 || (ev.keyCode==9 && ev.shiftKey)))
		{
			// up arrow
			if(g_nResultIndexOn == 0)
				return;
			
			if (g_nResultIndex <= 1)
			{ 
				HideFrame();
				g_strTextSearchOld = g_objTextSearch.value = g_strTextSearchBak;
			} 
			else
			{
				g_nResultIndex--;
				if ((g_nListCount - g_nResultIndex) + 1 > g_nMaxRow)
					document.getElementById("idTagList").scrollTop = (g_nListCount - (parseInt((g_nListCount - g_nResultIndex) / g_nMaxRow) + 1) * g_nMaxRow) * g_nTrHeight;
				objTr = document.getElementById("idTrTag" + g_nResultIndex);
				objTag = document.getElementById("idTrTagText" + g_nResultIndex);
				
				if(g_isIE)			
					g_strTextSearchOld = g_objTextSearch.value = objTag.innerText;
				else
					g_strTextSearchOld = g_objTextSearch.value = objTag.textContent;
				g_objTextSearch.focus();
				fnConvertColor();
				ev.returnValue = false;
			}
		}
	}
	
	function OnTextBlur(e, objTarget, type)
	{
		if(!g_bReady) return;
		var ev = (g_isIE) ? window.event : e;

		if(g_isFireFox) return;
		if(document.getElementById("idTagSuggestion").style.display != "none")
		{
			var objElement = document.getElementById('idTagSuggestion');
			
			var nLeft 	= 	getPageLeft(objElement) ;
			var nRight 	= 	nLeft + objElement.offsetWidth ;
			var nTop 	= 	getPageTop(objElement) ;		
			var nBottom	= 	nTop + objElement.offsetHeight ;			
			if(((nLeft < ev.clientX) && (ev.clientX  < nRight )) && ((nTop < ev.clientY) && (ev.clientY  < nBottom)) )
			{
//				ev.returnValue = false;
			}			
			else
			{			
				if(!CheckValidateChar(g_objTextSearch))
				{
					alert("Æ¯¼ö¹®ÀÚ´Â ÀÔ·ÂÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
					return;
				}
				if (type == undefined) {
					fnAddTag(objTarget,false);
				} else if (type == "ThemeTongMain") {
					HideFrame();
				}	
			}
		}
		else
		{
			if(!CheckValidateChar(g_objTextSearch))
			{
				alert("Æ¯¼ö¹®ÀÚ´Â ÀÔ·ÂÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
				return;
			}
			fnAddTag(objTarget,false);	
		}
	}


	function fnTrimSpace(strData)
	{ 
		strData = strData.replace(/^ +/g, "");
		strData = strData.replace(/ +$/g, " ");
		strData = strData.replace(/^ +/g, " ") ;
		strData = strData.replace(/ +$/g, "") ;
		strData = strData.replace(/ +/g, " ");
		
		var ch;
		var chOld = "";
		var strReturn = "";
		for(var nLoop = 0; nLoop < strData.length; nLoop++)
		{
			ch = strData.charAt(nLoop)
			if(ch != " " || chOld != " ")
			{
				strReturn += ch;
			}
			chOld = ch;
		}		
		return strReturn;
	}
	
	function TList(strTagInfo)
	{
		this.data = new Array();
		this.addElement = AddElementTList;
		if(strTagInfo != "")
		{
			var arrTagInfo = strTagInfo.split("\n");
			for(var nLoop = 0; nLoop < arrTagInfo.length; nLoop++)
			{
				var objTagSuggestion = new TagSuggestion(arrTagInfo[nLoop]);
				this.data[this.data.length] = objTagSuggestion;
			}
		}
	}
	
	function AddElementTList(objTag)
	{
		this.data[this.data.length] = objTag;
	}	
	
	
	function TagSuggestion(strTagInfo)
	{
		var arrTagInfo  = strTagInfo.split("\t");
		this.disp = arrTagInfo[0];
		this.tid = (arrTagInfo.length == 2) ? arrTagInfo[1] : "";
	}
	
	
	function ValidateTagName(aryTagList, sTag)
	{	
		if(_CheckByteLength(sTag,128) == false)
		{
			alert("ÅÂ±×´ç 128byte ±îÁö¸¸ °¡´ÉÇÕ´Ï´Ù.");
			return false;
		}	
		if(_CheckByteLength(aryTagList.toString() + sTag ,340) == false)
		{
			alert("ÀüÃ¼ÅÂ±×´Â 340byte ±îÁö¸¸ °¡´ÉÇÕ´Ï´Ù.");
			return false;
		}
		for(var nLoop = 0; nLoop < aryTagList.length; nLoop++)
		{
			if(sTag.toLowerCase() == aryTagList[nLoop].toLowerCase())
			{
				alert("µ¿ÀÏÇÑ ÅÂ±×¸¦ Áßº¹ ÀÔ·ÂÇÒ ¼ö ¾ø½À´Ï´Ù.");
				return false;
			}
		}	
		return true;
	}
	
	
	function showHide_tagInfoLayers(sTargetElement, sType, bShow)
	{
		if(bShow ==1)
		{
			var nLeft 	= 	getPageLeft(sTargetElement) -10 ;
			var nTop 	= 	getPageTop(sTargetElement) - 100;	
			if(document.getElementById('imgTagInfoLayers'))
			{
				document.getElementById('imgTagInfoLayers').style.left = nLeft
				document.getElementById('imgTagInfoLayers').style.top = nTop
				document.getElementById('imgTagInfoLayers').style.zIndex = 15;
				document.getElementById('imgTagInfoLayers').style.display = "block";				
			}
		}
		
		else
		{
			if(document.getElementById('imgTagInfoLayers'))
				document.getElementById('imgTagInfoLayers').style.display = "none";
		}		
	}
	
	function Add_aryTagList(aryTagListData, sTag)
	{
		sTag = sTag.split("&quot;").join("\"").split("\\;").join(";").split("&gt;").join(">").split("&lt;").join("<").split("&#39;").join("'");
		aryTagListData[aryTagListData.length] = sTag;
	}
	