var index = -1;
var XML_Content;
var XML_Channel;
var queryStr; 			// »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ Å°¿öµå
var selectedQueryStr; 	// ¸¶¿ì½º·Î Å¬¸¯ÇÑ Å°¿öµå
var	searchMode=0;		// 0 : Àü¹æÀÏÄ¡, 1 : ÈÄ¹æÀÏÄ¡, 2 : Áß¾ÓÀÏÄ¡
var	searchPos=-1;		// °Ë»ö°á°ú°¡ ÀÖ´Â °Ë»ö¾î À§Ä¡ 
var	autoSearch;			// ÀÚµ¿¿Ï¼º »ç¿ë¿©ºÎ : ÄíÅ°¿¡ ÀúÀå
var	historySearch;		// °Ë»ö¾î È÷½ºÅä¸® »ç¿ë¿©ºÎ : ÄíÅ°¿¡ ÀúÀå
var	helpSearch=0;		// È÷½ºÅä¸® ¹öÆ° Åä±Û(È­¸éÃâ·Â, È­¸é»èÁ¦)
var	historyCount=15;	// °Ë»ö¾î È÷½ºÅä¸® ÀúÀå °³¼ö
var	searchTry;
var	history_array;
var q_xmlhttp;
var transCheck;

var en_h = "rRseEfaqQtTdwWczxvg"; 
var reg_h = "[" + en_h + "]";
var en_b = {
	k : 0,
	o : 1,
	i : 2,
	O : 3,
	j : 4,
	p : 5,
	u : 6,
	P : 7,
	h : 8,
	hk : 9,
	ho : 10,
	hl : 11,
	y : 12,
	n : 13,
	nj : 14,
	np : 15,
	nl : 16,
	b : 17,
	m : 18,
	ml : 19,
	l : 20
}
var reg_b = "hk|ho|hl|nj|np|nl|ml|k|o|i|O|j|p|u|P|h|y|n|b|m|l";
var en_f = {
	"" : 0,
	r : 1,
	R : 2,
	rt : 3,
	s : 4,
	sw : 5,
	sg : 6,
	e : 7,
	f : 8,
	fr : 9,
	fa : 10,
	fq : 11,
	ft : 12,
	fx : 13,
	fv : 14,
	fg : 15,
	a : 16,
	q : 17,
	qt : 18,
	t : 19,
	T : 20,
	d : 21,
	w : 22,
	c : 23,
	z : 24,
	x : 25,
	v : 26,
	g : 27
}
var reg_f = "rt|sw|sg|fr|fa|fq|ft|fx|fv|fg|qt|r|R|s|e|f|a|q|t|T|d|w|c|z|x|v|g|";
var reg_exp = new RegExp("("+reg_h+")("+reg_b+")((?:"+reg_f+")(?=(?:"+reg_h+")(?:"+reg_b+"))|(?:"+reg_f+"))","g");

function autoSearchInit()
{
	envSearchInit();

	autoSearch=GetCookie('g_auto');
	if( autoSearch == null )
		autoSearch = 'on';			// °Ë»ö¾î ÀÚµ¿¿Ï¼º : Ã³À½ »ç¿ëÀÚÀÌ¸é ±â´É È°¼ºÈ­
	historySearch=GetCookie('g_history');
	if( historySearch == null )		// °Ë»ö¾î È÷½ºÅä¸® : Ã³À½ »ç¿ëÀÚÀÌ¸é ±â´É ºñÈ°¼ºÈ­
		historySearch = 'off';
}

function envSearchInit()
{
	q_xmlhttp = new xmlHttp_Auto();

	searchMode = 0;
	searchPos = -1;
	searchTry = 0;
	index = -1;
	queryStr = null;
	XML_Content = null;
	XML_Channel = null;
}

function getCookieVal( offset )
{
	var endstr = document.cookie.indexOf (";", offset);
	if(endstr == -1)
		endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie( name )
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break; 
	}

	return null;
}

function SetCookie( name, value, expires )
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : "/";
	var domain = (4 < argc) ? argv[4] : ".gomtv.com";
	var secure = (5 < argc) ? argv[5] : false;

	document.cookie = name + "=" + escape (value) +
	  ((expires == null) ? "" : ("; expires=Wed, 09-Nov-2020 12:11:31 GMT;")) +
	  ((path == null) ? "" : ("; path=" + path)) +
	  ((domain == null) ? "" : ("; domain=" + domain)) +
	  ((secure == true) ? "; secure" : "");
}

function ReplaceStr( inputStr, oldStr, newStr )
{
	return inputStr.split(oldStr).join(newStr);
}

function autoSearchOn()
{
	SetCookie( 'g_auto', 'on', 'noexpire' );
	document.topSearchForm.key.autocomplete='off';
	removeHelpBox();
	document.topSearchForm.key.focus();
	autoSearch = 'on';
}

function autoSearchOff()
{
	SetCookie( 'g_auto', 'off', 'noexpire' );
	document.topSearchForm.key.autocomplete='on';
	removeListBox();
	document.topSearchForm.key.focus();
	autoSearch = 'off';
}

function historySearchOn()
{
	SetCookie( 'g_history', 'on', 'noexpire' );
	historySearch = 'on';
	helpMessage(0);
}

function historySearchOff()
{
	SetCookie( 'g_history', 'off', 'noexpire' );
	historySearch = 'off';
	historyDestroy();
	helpMessage(0);
}

function historyGet()
{
	var	str_list;
	str_list = GetCookie( 'g_history_list' );
	if( str_list != null )
		history_array = str_list.split('^');
	else
		history_array = null;
}

function historyAdd( str )
{
	var	item_len;
	var	str_list;
	var	str_list2;
	var	save_array;
	var	dup_flag=0;
	
	if( str.length == 0 )
		return;

	historySearch=GetCookie('g_history');
	if( historySearch == 'on' )
	{
		str =  ReplaceStr( str, "^", "%5E" );
		str = HtmlSpecialChars(str);

		str_list = GetCookie( 'g_history_list' );
		if( str_list == null )
		{
			str_list = str;
			item_len = 1;
		}
		else
		{
			save_array = str_list.split('^');
			item_len = save_array.length;
			str_list2 = null;
			for( i=item_len-1; i>=0; i-- )
			{
				if( str != save_array[i] )
				{
					str_list2 == null ? str_list2 = save_array[i] : str_list2 = save_array[i] + "^" + str_list2;
				}
			}

			if( str_list2 != null )
			{
				str_list = str + "^" + str_list2;
			}
		}
		item_len = str_list.split('^').length;

		// ÄíÅ° ÀúÀå ÇÑ°è°ªÀ» ³Ñ¾úÀ» °æ¿ì °¡Àå ¸ÕÀú ÀúÀåµÈ °Ë»ö¾î »èÁ¦
		if( item_len > historyCount )
		{
			str_list = str_list.substring(0, str_list.lastIndexOf("^"));
		}

		SetCookie( 'g_history_list', str_list, 'noexpire' );
	}
}

function historyDelete( pos )
{
	var str_list=null;

	if( history_array && history_array.length > 0 )
	{
		for( i=0; i<history_array.length; i++ )
		{
			if( i != pos )
			{
				if( str_list == null )
					str_list = history_array[i];
				else
					str_list += "^" + history_array[i];
			}
		}
		if( str_list == null )	str_list = '';

		SetCookie( 'g_history_list', str_list, 'noexpire' );
	}
	helpMessage(0);
}

function historyDestroy()
{
	SetCookie( 'g_history_list', '', 'noexpire' );
	helpMessage(0);
}

function helpMessage( mode )
{
	if( mode == 1 )
	{
		if( helpSearch == 1 )
		{
			document.all['helpimg'].src='http://img.gomtv.com/images/common/icon/search_layer_open.gif';
		}
		else
		{
			document.all['helpimg'].src='http://img.gomtv.com/images/common/icon/search_layer_close.gif';
		}
	}
	else
	{
		document.all['helpimg'].src='http://img.gomtv.com/images/common/icon/search_layer_close.gif';
	}

	box = document.getElementById("help_zone");
	help_body = box.contentWindow.document.getElementById("help_body");

	html = new String;
	if( historySearch == 'on' )
	{
		html += "<div class='search_layer' id='sl_2'>";
	}else{
		html += "<div class='search_layer' id='sl_1'>";	
	}

	html +="<span class='t'>³»°¡ Ã£Àº °Ë»ö¾î</span><div class='r'>";

	if( historySearch == 'on' )
	{
		html += "<a href=javascript:parent.historySearchOff();>±â´É²ô±â</a> | <a href=javascript:parent.historyDestroy();>ÀüÃ¼»èÁ¦</a>";
	}
	else
	{
		html += "<a href=javascript:parent.historySearchOn();>±â´ÉÄÑ±â</a>";
	}
	html +="</div>";


	if( historySearch == 'on' )
	{
		// È÷½ºÅä¸®¿¡ ÀúÀåµÈ °Ë»ö¾î ¸®½ºÆ® Ãâ·Â
		historyGet();
		if( history_array  == null )
		{
			html += "<div class='box'>ÃÖ±Ù¿¡ °Ë»öÇÑ °Ë»ö¾î¸¦ ÀúÀåÇÏÁö ¾ÊÀ¸½Ã·Á¸é <br /><em>'±â´É²ô±â'</em>¸¦ Å¬¸¯ÇÏ¼¼¿ä.</div>";
		}
		else
		{
			html += "<div class='box'><ul>";
			for( i=0; history_array && i<history_array.length; i++ )
			{
				//2008-11-03 START
				var	str="", viewStr="", linkStr="";
				
				str = ReplaceStr( history_array[i], "%5E", "^" );
				
				viewStr = HtmlSpecialChars_decode( str ) ;
				viewStr = HtmlRemove(viewStr);	
				
				linkStr = str; //no cut

				html += "\
					<li onmouseover=\"this.style.backgroundColor='#FDF9E9';\" onmouseout=\"this.style.backgroundColor='';\">\
					";
				if(str.bytes() > 32)
				{
					str = str.cut(32);
					html += "\
							<a href=\"javascript:parent.goTWordSearch_auto('" + linkStr + "')\" title='" + history_array[i] + "' class='gray4'>"+viewStr+"</a>\
							";
				}else
				{
					html += "\
							<a href=\"javascript:parent.goTWordSearch_auto('" + linkStr + "')\" class='gray4'>"+viewStr+"</a>\
							";				
				}
				html += "\
					<a href=javascript:parent.historyDelete("+i+");><img class='right' src='http://img.gomtv.com/images/common/icon/icon_delete.gif' width='10' height='9 alt='»èÁ¦' /></a>\
					</li>\
					";
			}
			html += "</ul></div>";
		}
	}
	else
	{
		html += "<div class='box'>ÃÖ±Ù¿¡ °Ë»öÇÑ °Ë»ö¾î¸¦ ÀúÀåÇÏ¿© ³ªÁß¿¡ <br />ÀçÀÔ·Â ¾øÀÌ ´Ù½Ã °Ë»ö ÇÏ½Ã·Á¸é <em>'±â´ÉÄÑ±â'</em>¸¦ <br />Å¬¸¯ÇÏ¼¼¿ä.</div>";

	}


	if( autoSearch == 'on' )
	{
		html += "<div class='bt'>°Ë»ö¾î ÀÚµ¿¿Ï¼º ±â´ÉÀ» »ç¿ëÇÏ°í °è½Ê´Ï´Ù.</div>";
	}
	else
	{
		html += "<div class='bt'>°Ë»ö¾î ÀÚµ¿¿Ï¼º ±â´ÉÀ» »ç¿ëÇØ º¸¼¼¿ä. </div><div class='r'><a href=javascript:parent.autoSearchOn()>±â´ÉÄÑ±â</a></div>";
	}

	html += "<div>";

	if( historySearch != 'on' || !history_array )
	{
//		document.all.help_zone.height= 141 ;
		document.all.help_zone.height= 202;
	}
	else
	{
//		document.all.help_zone.height= 69 + history_array.length*20;
		height = 69 + history_array.length*20;
		if(height < 202) height = 202;
//		document.all.help_zone.height= 69 + history_array.length*20;	
		document.all.help_zone.height= height;	

	}

	if( mode == 1 )
	{
		if( helpSearch == 1 )
		{
			helpSearch = 0;
			document.all['helpimg'].src='http://img.gomtv.com/images/common/icon/search_layer_open.gif';
			removeHelpBox();
		}
		else
		{
			help_body.innerHTML = html;
			box.style.display = "inline";
			helpSearch = 1;
			document.all['helpimg'].src='http://img.gomtv.com/images/common/icon/search_layer_close.gif';
		}
	}
	else
	{
		help_body.innerHTML = html;
		box.style.display = "inline";
		document.all['helpimg'].src='http://img.gomtv.com/images/common/icon/search_layer_close.gif';
	}
}	
/*
function setSearchMode(mode, action)
{
	var	key_count;

	searchMode = mode;
	box = document.getElementById("list");
	text = document.topSearchForm.key;
	queryStr = text.value;

	if( action == 1 )
	{	
		xmlHttp_Auto_Request( queryStr );
		dispListBox( queryStr, mode );
	}
}
*/
function setSearchMode(mode, action)
{
	var	key_count;

	searchMode = mode;
	box = document.getElementById("list");
	text = document.topSearchForm.key;
	
	queryStr = text.value;
	jasoStr =  text.value;
//	alert("t:"+jasoStr);
	jasoStr = jasoStr.trim();
//	alert("t:"+jasoStr);	

	if( action == 1 )
	{			
	//	if(mode == 1)	 {
			jasoStr = split_jaso(jasoStr);
		//	jasoStr = jasoStr.revjaso();

	//	alert("mode:"+mode+",queryStr:"+queryStr+ ",jasoStr:"+jasoStr + "jasolen:"+jasoStr.length);

		if(jasoStr.length == 0)
			return ;

		xmlHttp_Auto_Request( jasoStr , queryStr );
		dispListBox( queryStr, mode );
	//	alert("queryStr:"+queryStr);
	}
}

function ArrowListBox()
{
	var channel_count;
	try{
		if(XML_Channel.length){
			channel_count = XML_Channel.length;
			if(channel_count > 10) channel_count = 10;
			totalLength = parseInt(channel_count+XML_Content.length);
		}else
			totalLength = XML_Content.length;
	}
	catch(e)
	{}
	if( event.type == "keyup" )
	{
		return;
	}

	if( event.keyCode == 8 )
	{
		//alert("Å°: 8");
		index = -1;
		setListBox( document.topSearchForm.key.value );
		return;
	}

	if( event.keyCode != 40 && event.keyCode != 38 )		// 40 : ¡é, 38 : ¡è
		return;

	if( document.topSearchForm.key.value != "" && XML_Content != null && XML_Channel != null )
	{
		if( XML_Content.length <= 0 && channel_count <= 0 )
			return;
	}
	else
	{
		return;
	}

	setSearchMode( searchMode, 0 );
	if(event.keyCode == 40 && index <= totalLength)
	{
		with(box.contentWindow.document)
		{
			event.returnValue=false;
			if( index == totalLength-1 )
			{
				box.style.display = "inline";

				getElementById("no_" + index).style.backgroundColor = "#FFFFFF";
				getElementById("no_" + 0).style.backgroundColor = "#FDF9E9";

				index = -1;
			}

			if(index > -1) getElementById("no_" + index).style.backgroundColor = "#FFFFFF";
			var tmpno = ++index;
			getElementById("no_" + tmpno).style.backgroundColor = "#FDF9E9";
				try
				{
					if(channel_count)
						if(index < channel_count)
							text.value = XML_Channel.item(index).getAttribute("STRTITLE");
						else
							text.value = XML_Content.item(index-channel_count).getAttribute("WORD");
					else
						text.value = XML_Content.item(index).getAttribute("WORD");
				}
				catch(e)
				{
				}
		}
		box.style.display = "inline";
	}
	else if( event.keyCode == 38 )
	{
		if( index > 0 )
		{
			event.returnValue=false;
			with( box.contentWindow.document )
			{
				getElementById("no_" + index).style.backgroundColor = "#FFFFFF";
				getElementById("no_" + --index).style.backgroundColor = "#FDF9E9";
				try
				{
					if(channel_count)
						if(index < channel_count)
							text.value = XML_Channel.item(index).getAttribute("STRTITLE");
						else
							text.value = XML_Content.item(index-channel_count).getAttribute("WORD");
					else
						text.value = XML_Content.item(index).getAttribute("WORD");
				}
				catch(e)
				{
				}
			}
		}
		else
		{
			box.style.display = "none";
			text.value = "";
			parent.removeListBox();
		}
	}
	else if( event.keyCode == 13 )			// ENTER
	{
		goTSearch_auto();
	}
}

function setListBox()
{//alert("setListBox");
	removeHelpBox();

	str = document.topSearchForm.key.value;
	str =  ReplaceStr( str, "\\", "" );
	str =  ReplaceStr( str, "'", "" );

	if( str.length <= 0 )
	{
		envSearchInit();
		removeListBox();
		return;
	}

	keycode = event.keyCode;
	if( str && autoSearch == 'on' )
	{
		if( str.charAt(0) == ' ' )
		{
			XML_Content = null;

			removeListBox();
			return;
		}

		// °Ë»ö¾î·Î »ç¿ëµÇ´Â Å°º¸µå ÀÔ·ÂÀÏ °æ¿ì¸¸ °Ë»ö ¿äÃ»
		//if(!(event.keyCode == 38 || event.keyCode == 40))
		if( keycode == 8  || keycode == 32  || ( keycode >= 48  &&  keycode <= 90 ) ||  
			( keycode >= 96  &&  keycode <= 111) )
		{
			index = -1;
			setSearchMode( 0, 0 );
			if( searchPos < 0 || ( str.length < searchPos ) )
			{
				setTimeout( "xmlHttp_Auto_Request('" + str +"' ,'" + str +"')", 10);
			}

			if( XML_Content && XML_Content.length == 0 && XML_Channel && XML_Channel.length==0)
			{
				searchTry++;
				if( searchPos < 0 && searchTry > 3 )
					searchPos = str.length;
			}
			else
			{
				searchPos = -1;
				searchTry = 0;
			}
		}
	}
	else 
	{
		removeListBox();
	}
}

function dispListBox( str , mode)
{
	var	key_count, channel_count, channel_tot_count;
	box = document.getElementById("list");
	list_body = box.contentWindow.document.getElementById("list_body");

	if( XML_Content != null )//°Ë»ö¾î
		key_count = XML_Content.length;	
	else
		key_count = 0;

	if( XML_Channel != null )//Ã¤³Î
		channel_count = XML_Channel.length;	
	else
		channel_count = 0;

//alert("Ã¤³Î°¹¼ö:"+channel_count);

	if( ( key_count <= 0 && channel_count <= 0  ) || str.length <= 0 )
	{
		///2008-06-17 Ãß°¡ START
		if(str.length > 0) 
		{	
			transStr = str.trim();
			if( isEnglish(transStr) )	//
			{
				transStr = toKorean(transStr);

				if( isKorean( transStr) )
					xmlHttp_Auto_Request( transStr , transStr );
				else
					removeListBox();

				return;
			}
		//2008-06-17 Ãß°¡ END
		}

		removeListBox();
		return;
	}

///////////////////////////////
	searchMode = mode;
	text = document.topSearchForm.key;
	queryStr = text.value;

	html = new String;

	html += "\
			<span class='t'>°Ë»ö¾î ÀÚµ¿¿Ï¼º</span>\
			<div class='r'><a href=javascript:parent.autoSearchOff()>±â´É²ô±â</a></div>\
			<div class='box'>\
			<div class='func'>\
			";

	if( searchMode == 0 )
		html += "<a class='on' href=javascript:parent.setSearchMode(0,1)>Ã³À½~</a>";
	else
		html += "<a href=javascript:parent.setSearchMode(0,1)>Ã³À½~</a>";
	
	html += "<span class='bar'>|</span>";

	if( searchMode != 2 && searchMode != 0)
		html += "<a class='on' href=javascript:parent.setSearchMode(1,1)>³¡~</a>";
	else
		html += "<a href=javascript:parent.setSearchMode(1,1)>³¡~</a>";
		
	html += "</div>";

//	list_head.innerHTML = html;
//////////////////////////// Ã¤³Î Á¤º¸ °¡Á®¿À±â /////////////////////////////////////

//	html = new String;
	if( XML_Channel != null && XML_Channel.length > 0 )
	{
		html += "\
					<ul id='channel'>\
					<li class='title'>Ã¤³ÎÀÌ¸§<span class='right'>Ã¤³Î¹øÈ£</span>\
					</li>\
					";

		channel_count= XML_Channel.length;
		if(channel_count > 10) channel_count = 10;

		for( i=0; i<channel_count; i++ )
		{
			var intseq = XML_Channel.item(i).getAttribute("INTSEQ");
			var intchnumber = XML_Channel.item(i).getAttribute("STRCHNUMBER");
			var strtitle = XML_Channel.item(i).getAttribute("STRTITLE");
		//	var link="<a href=http://ch.gomtv.com/"+intchnumber+" class=gray4 target=_top>"; 
			var link;
			var strSubject;

			if( strtitle.bytes() > 32)
			{	
				strtitle = strtitle.cut(32);

				link="<a href=http://ch.gomtv.com/"+intchnumber+" class=gray4 target=_top  title='" + XML_Channel.item(i).getAttribute("STRTITLE") + "'>"; 
			}
			else
				link="<a href=http://ch.gomtv.com/"+intchnumber+" class=gray4 target=_top>"; 

	//		strtitle = strtitle.replace(str, "<font color=orange>" + str + "</font>");
			var myStr, myReg;
			myReg= new RegExp(str,'gi'); 
			myStr = strtitle.match( myReg );
			strtitle = strtitle.replace( myStr, "<font color=orange>" + myStr + "</font>");

			html += "\
			<li  id='no_" + i + "' onmouseover=\"this.style.backgroundColor='#FDF9E9'\" onmouseout=\"this.style.backgroundColor='';\" onmousedown=\"parent.goTWordSearch_auto('" + XML_Channel.item(i).getAttribute("STRTITLE") + "')\";>\
				"+link+strtitle+"</a>"+"<span class='right'>"+link+intchnumber+"</a></span>\
			</li>\
			";
		}
		html += "</ul>";
	}

	////////////////////////////////////////////////////////////////////////////////
	/// ÀÎ±â °Ë»ö¾î
	if( key_count > 0 )
	{
		html += "\
			<ul id='popword'>\
			<li class='title'>\
				´Ü¾î<span class='right'>ÀÎ±âµµ</span>\
			</li>\
				";
	}

	str = str.toLowerCase();

	for( i=0,w=channel_count; i<key_count; i++,w++ )
	{

		if( XML_Content.item(i).getAttribute("WORD") == str )
		{
	
			html += "\
				<li id='no_" + w + "' onmouseover=\"this.style.backgroundColor='#FDF9E9';\" onmouseout=\"this.style.backgroundColor='';\" onClick=\"parent.goTWordSearch_auto('" + XML_Content.item(i).getAttribute("WORD") + "')\";>\
				" + XML_Content.item(i).getAttribute("WORD").replace(str, "<font color=orange>" + str.bold() + "</font>") + "<img class='right' src=http://img.gomtv.com/gomtv/img/auto_star_" + popLevel(XML_Content.item(i).getAttribute("RESULT"))  +".gif width='39' height='6' alt='' />\
				</li>\
				";
		}
		else
		{
			if( searchMode == 0 )
			{
				if( XML_Content.item(i).getAttribute("WORD").indexOf(str) == 0 )
				{			
					html += "\
						<li id='no_" + w + "' onmouseover=\"this.style.backgroundColor='#FDF9E9';\" onmouseout=\"this.style.backgroundColor='';\" onClick=\"parent.goTWordSearch_auto('" + XML_Content.item(i).getAttribute("WORD") + "')\";>\
						" + XML_Content.item(i).getAttribute("WORD").replace(str, "<font color=orange>" + str + "</font>") + "<img class='right' src=http://img.gomtv.com/gomtv/img/auto_star_" + popLevel(XML_Content.item(i).getAttribute("RESULT") ) +".gif width='39' height='6' alt='' />\
						</li>\
						";				
				}
				else
				{
					html += "\
						<li id='no_" + w + "' onmouseover=\"this.style.backgroundColor='#FDF9E9';\" onmouseout=\"this.style.backgroundColor='';\" onClick=\"parent.goTWordSearch_auto('" + XML_Content.item(i).getAttribute("WORD") + "')\";>\
						" + XML_Content.item(i).getAttribute('WORD') + "<img class='right' src=http://img.gomtv.com/gomtv/img/auto_star_" + popLevel( XML_Content.item(i).getAttribute("RESULT"))  +".gif width='39' height='6' alt='' />\
						</li>\
						";		
				}
			}
			else
			{
					html += "\
						<li id='no_" + w + "' onmouseover=\"this.style.backgroundColor='#FDF9E9';\" onmouseout=\"this.style.backgroundColor='';\" onClick=\"parent.goTWordSearch_auto('" + XML_Content.item(i).getAttribute("WORD") + "')\";>\
						" + XML_Content.item(i).getAttribute("WORD").replace(str, "<font color=orange>" + str + "</font>") +  "<img class='right' src=http://img.gomtv.com/gomtv/img/auto_star_" + popLevel(XML_Content.item(i).getAttribute("RESULT"))  +".gif width='39' height='6' alt='' />\
						</li>\
						";					
			}
		}
	}

	html += "</ul></div>";
	
	list_body.innerHTML = html;	

	height = 85 + key_count*20;

	if( channel_count > 0 )
		height += 35+channel_count*20;

	if(height < 202)	height = 202;
	parent.document.all.list.height=height;

	if(index == -1) box.style.display = "inline";
//	parent.document.topSearchForm.key.focus();
}

function removeListBox() {
	box = document.getElementById("list");
	if( box.style.display == "inline" )
	{
		box.style.display = "none";
//		parent.document.topSearchForm.key.focus();
	}
}

function removeHelpBox()
{
	box = document.getElementById("help_zone");
	if( box.style.display == "inline" )
	{
		box.style.display = "none";
		parent.document.topSearchForm.key.focus();
	}
}


function xmlHttp_Auto()
{
	if( window.XMLHttpRequest )
	{
		return new XMLHttpRequest();
	}
	else if( window.ActiveXObject )	
	{
		try
		{
			return new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (e)
		{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
	}

	return null;
}

function xmlHttp_Auto_Request( str , original_str)
{
	var	url;

	if( q_xmlhttp.readyState !=0 )
    {       
        q_xmlhttp.abort();
        q_xmlhttp = new xmlHttp_Auto();
    }

	if( q_xmlhttp != null && str.length > 0 )
	{
		url = "/autosearch/searchword.gom?opt=" + searchMode + "&query=" + original_str; 
	//	alert("url:"+url);
	//	url = "/test.xml"; 
	
		q_xmlhttp.open("GET", url, true);
		q_xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
		q_xmlhttp.onreadystatechange=function()
		{
			if( q_xmlhttp.readyState == 4 )
			{
				if( q_xmlhttp.status == 200 )
				{
					XML_Content = q_xmlhttp.responseXML.getElementsByTagName("SEARCH");
					XML_Channel = q_xmlhttp.responseXML.getElementsByTagName("CHANNEL");
				//	alert(q_xmlhttp.responseText);
				//	alert("Ã¤³Î len:"+XML_Channel.length + ",mode:" +searchMode);

				//	alert("dispListBoxÈ£Ãâ:"+str+", ¿øº»:"+original_str);
					dispListBox( original_str , searchMode);
				}
				else
				{
					return;
				}
			}
		}
		q_xmlhttp.send(null);
	}
}

function check_auto(e)
{
	if( e ) // IFRAME³ª ´Ù¸¥°÷¿¡¼­ ÀÌº¥Æ®°¡ ¿ÔÀ»¶§.
	{
		if( e.srcElement.tagName != "INPUT" )
		{
			removeListBox();
			removeHelpBox();
			envSearchInit();
			
		}
	}
	else if( event ) // ÀÚ±â ÀÚ½ÅÀÇ ÀÌº¥Æ®
	{
		if( event.srcElement.tagName != "INPUT" )
		{
			removeListBox();
			removeHelpBox();
			envSearchInit();
		}
	}
}

document.onclick=check_auto;
autoSearchInit();

function checkAction_auto(whr)
{
    var action='http://search.gomtv.com/search.gom';
	return action;

}
function goTSearch_auto()
{
    Submit_auto(document.topSearchForm.key.value);
}
function goTWordSearch_auto(word)
{
    Submit_auto(word);
}
function Submit_auto(key)
{
    var tf = parent.document.topSearchForm;
    tf.action=checkAction_auto(tf.whr.value);
    tf.target='GOMTV';
    tf.key.value=key;
    tf.submit();
}

/** 
* string String::cut(int len)
* ±ÛÀÚ¸¦ ¾Õ¿¡¼­ºÎÅÍ ¿øÇÏ´Â ¹ÙÀÌÆ®¸¸Å­ Àß¶ó ¸®ÅÏÇÕ´Ï´Ù.
* ÇÑ±ÛÀÇ °æ¿ì 2¹ÙÀÌÆ®·Î °è»êÇÏ¸ç, ±ÛÀÚ Áß°£¿¡¼­ Àß¸®Áö ¾Ê½À´Ï´Ù.
*/
String.prototype.cut = function(len) {
	var str = this;
	var l = 0;
	for (var i=0; i<str.length; i++) {
		l += (str.charCodeAt(i) > 128) ? 2 : 1;
		if (l > len) return str.substring(0,i) + "...";
	}
	return str;
}

/** 
* bool String::bytes(void)
* ÇØ´ç½ºÆ®¸µÀÇ ¹ÙÀÌÆ®´ÜÀ§ ±æÀÌ¸¦ ¸®ÅÏÇÕ´Ï´Ù. (±âÁ¸ÀÇ length ¼Ó¼ºÀº 2¹ÙÀÌÆ® ¹®ÀÚ¸¦ ÇÑ±ÛÀÚ·Î °£ÁÖÇÕ´Ï´Ù)
*/
String.prototype.bytes = function() {
	var str = this;
	var l = 0;
	for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
	return l;
}

function HtmlSpecialChars (str) {
	var ret_str = str;
	var search = new Array (/'/g , /"/g , /&/g , /</g , />/g);
	var replace = new Array ("&#039;" , "&quot;" , "&amp;" , "&lt;" , "&gt;");
	var cnt = search.length;

	for(var i=0; i<cnt; i++) {
			  ret_str = ret_str.replace (search[i],replace[i]);
	}

	return ret_str;
}

function HtmlSpecialChars_decode (str) {
	var ret_str = str;
	var search = new Array (/&#039;/g , /&quot;/g , /&amp;/g , /&lt;/g , /&gt;/g);
	var replace = new Array ("\'" , "\"" , "\&" , "\<" , "\>");

	var cnt = search.length;

	for(var i=0; i<cnt; i++) {
		ret_str = ret_str.replace (search[i],replace[i]);
	}
	return ret_str;
}

//ÅÂ±×Á¦°Å 
function HtmlRemove( ohtml ) 
{
 
	var objStrip = new RegExp(); 
	objStrip = /[<][^>]*[>]/gi; 
	var ret_html = ohtml.replace(objStrip, ""); 

	return ret_html;
}

String.prototype.revjaso = function(){
	var str = this;
	var ret_str="";
	var len = str.length;
//	alert("revjaso() len: "+len);

	for(i=len-1; i>0; i--)
	{
		ret_str += str.substring(i-1,i);	
	}
//	alert("revjaso() len: "+ret_str.length + ", str:" +ret_str);
return ret_str;

}

String.prototype.trim = function(){

	var str = this;
	var ret_str="";
	var chkstr="";

	var len = str.length;

	for(i=0; i<len; i++)
	{
		chkstr = str.substring(i,i+1);

		if(chkstr != " ")
			ret_str += chkstr;	
	}
return ret_str;

}

function split_jaso( keyword ){

	hanTable=new Array();
	hanTable[0]='¤¡¤¢¤¤¤§¤¨¤©¤±¤²¤³¤µ¤¶¤·¤¸¤¹¤º¤»¤¼¤½¤¾'; // 19 ÃÊ¼º
	hanTable[1]='¤¿¤À¤Á¤Â¤Ã¤Ä¤Å¤Æ¤Ç¤È¤É¤Ê¤Ë¤Ì¤Í¤Î¤Ï¤Ð¤Ñ¤Ò¤Ó'; //21 Áß¼º
	hanTable[2]=' ¤¡¤¢¤£¤¤¤¥¤¦¤§¤©¤ª¤«¤¬¤­¤®¤¯¤°¤±¤²¤´¤µ¤¶¤·¤¸¤º¤»¤¼¤½¤¾'; //28 Á¾¼º

	str="";
	wordLen = keyword.length;
	
//	alert("split_jaso():"  +  keyword + ", len:"+wordLen);

	for(i=0;i<wordLen;i++){
		b=keyword.charCodeAt(i);
		
		if(b >= 0xAC00 && b <= 0xD7A3)
		{
			hcode=b-0xAC00;
			//hanTable='¤¡¤¢¤£¤¤¤¥¤¦¤§¤¨¤©¤ª¤«¤¬¤­¤®¤¯¤°¤±¤²¤³¤´¤µ¤¶¤·¤¸¤¹¤º¤»¤¼¤½¤¾¤¿¤À¤Á¤Â¤Ã¤Ä¤Å¤Æ¤Ç¤È¤É¤Ê¤Ë¤Ì¤Í¤Î¤Ï¤Ð¤Ñ¤Ò¤Ó ';

			cho=new Array();
			cho[0]=parseInt(hcode / 588); //ÃÊ¼º
			hcode2=hcode % 588;

			cho[1]=parseInt(hcode2 / 28); //Áß¼º
			cho[2]=hcode2 % 28; //Á¾¼º ¤¡,,,¤¤ 

			m=new Array();

			//ÃÊ¼º 
			m[0]=Math.floor((b-0xAC00)/(21*28)); 
			//Áß¼º
			m[1]=Math.floor(((b-0xAC00)%(21*28))/28); 
			//Á¾¼º
			m[2]=(b-0xAC00)%28


			mun=new Array();
			mun[0]=hanTable[0].charAt(cho[0]);
			mun[1]=hanTable[1].charAt(cho[1]); //ÀÚÀ½
			mun[2]=hanTable[2].charAt(cho[2]); //0¹øÀº Á¾¼ºÀ¯¹«

			//0xAC00 + ÃÊ¼º¼ø¼­¹øÈ£(0¹øºÎÅÍ)*Áß¼º°¹¼ö*Á¾¼º°¹¼ö + Áß¼º¼ø¼­¹øÈ£*Á¾¼º°¹¼ö + Á¾¼º¼ø¼­¹øÈ£

			hap=String.fromCharCode(0xAC00+(cho[0]*21*28)+(cho[1]*28)+cho[2]);

			//str+=mun+"\n";
			str+=mun[0]+mun[1]+mun[2];
		
		}
		else
			str+=keyword.charAt(i);
		
	}
	
	return str; 
	
}

function popLevel( count ) 
{
    if( count < 10 )
    {
        return 0;
    }
    else if( count >=10 && count < 100 ) 
    {
        return 1;
    }
    else if( count >= 100 && count < 1000 )
    {
        return 2;
    }
    else if( count >= 1000 && count < 5000 )
    {
        return 3;
    }
    else if( count >= 5000 && count < 10000 ) 
    {
        return 4;
    }
    else    
    {
        return 5;
    }

}

/////////////////////////////////////////////////////////////////////////////////
function isKorean(p) 
{
	chk = /[^¤¡-¤¾¤¿-¤Ó°¡-ÆR]/;
	return !(chk.test(p));
	} 

function isEnglish(p) 
{
	chk = /[^-a-zA-Z0-9]/;  
	return !(chk.test(p)) ;
} 

function toKorean(str) 
{ 
    return str.replace(reg_exp,replace_han); 
} 

//ÃÊ¼º Áß¼º Á¾¼º º°·Î ¿µ¾î ¿ÀÅ¸°ªÀ» ¸¸µé°í, Á¶ÇÕÀ» °í·ÁÇØ¼­ ÇÑ±Û º¯È­½ÃÀÇ ÇÑ±Û¹®ÀÚ·Î º¯È¯
//Caps Lock´Â offµÈ »óÅÂ, Áï ½ÖÀÚÀ½ÀÌ³ª ¿¬¸ðÀ½ÀÌ ¿µ´ë¹®ÀÚ
function replace_han(str,h,b,f) {
	var h = en_h.indexOf(h);
	var b = en_b[b];
	var f = en_f[f];
	var code = h*21*28 + b*28 + f + 44032;
	return String.fromCharCode(code);
}

