var index = -1;
var XML_Content;
var XML_Recom;
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;

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_Recom = 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_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++ )
			{
				var	str;
				str = ReplaceStr( history_array[i], "%5E", "^" );
				html += "\
					<li onmouseover=\"this.style.backgroundColor='#FDF9E9';\" onmouseout=\"this.style.backgroundColor='';\">\
						<a href=\"javascript:parent.goTWordSearch_auto('" + history_array[i] + "')\" class='gray4'>"+str+"</a>\
						<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= 202;
	}
	else
	{
		height = 69 + history_array.length*20;

		if(height < 202) height = 202;
		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 ArrowListBox()
{
	try{
		if(XML_Channel.length)
			totalLength = parseInt(XML_Channel.length+XML_Content.length);
		else
			totalLength = XML_Content.length;
	}
	catch(e)
	{}
	if( event.type == "keyup" )
	{
		return;
	}

	if( event.keyCode == 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 && XML_Channel.length <= 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";
			getElementById("no_" + ++index).style.backgroundColor = "#FDF9E9";
				try
				{
					if(XML_Channel.length)
						if(index < XML_Channel.length)
							text.value = XML_Channel.item(index).getAttribute("STRTITLE");
						else
							text.value = XML_Content.item(index-XML_Channel.length).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(XML_Channel.length)
						if(index < XML_Channel.length)
							text.value = XML_Channel.item(index).getAttribute("STRTITLE");
						else
							text.value = XML_Content.item(index-XML_Channel.length).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()
{
	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 +"')", 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, recom_tot_count, recom_count, channel_count, channel_tot_count;
	var	recom_str;
	box = document.getElementById("list");
	list_body = box.contentWindow.document.getElementById("list_body");
//	list_recom_body = box.contentWindow.document.getElementById("list_recom_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;

	if( ( key_count <= 0 && channel_count <= 0  ) || str.length <= 0 )
	{
		removeListBox();
		return;
	}

///////////////////////////////
//	var	key_count;

	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 )
		html += "<a class='on' href=javascript:parent.setSearchMode(2,1)>~Áß°£~</a>";
	else
		html += "<a href=javascript:parent.setSearchMode(2,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;
		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>"; 


			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 += "\
			<li  id='no_" + i + "' onmouseover=\"if(parent.index>-1&&parent.index!=" + i + "){document.getElementById('no_' + parent.index).style.backgroundColor='';} parent.index=" + i + ";this.style.backgroundColor='#FDF9E9';parent.selectedQueryStr='" + XML_Channel.item(i).getAttribute("STRTITLE") + "';\" onmouseout=\"this.style.backgroundColor='';\" onmousedown=\"parent.goTWordSearch_auto('" + XML_Channel.item(i).getAttribute("STRTITLE") + "')\";>\
				"+link+""+strtitle+"<span class='right'>"+link+""+intchnumber+"</span>\
			</li>\
			";

//////////////// obst Ãß°¡
html += "<div id='no_" + i + "' style='width:100%; height:15px; cursor:pointer'";
html += "onmouseover=\"if(parent.index>-1&&parent.index!=" + i + "){document.getElementById('no_' + parent.index).style.backgroundColor='';} parent.index=" + i + ";this.style.backgroundColor='#ECECEC';parent.selectedQueryStr='" + XML_Channel.item(i).getAttribute("STRTITLE") + "';\" ";
html += "onmouseout=\"parent.index=-1;this.style.backgroundColor='#FFFFFF'\" "; 
html += "onmousedown=\"parent.goTWordSearch_auto('" + XML_Channel.item(i).getAttribute("STRTITLE") + "')\"; >";
html += "<table width=100% border=0 cellspacing=0 cellpadding=0>\
		<tr height=22 onmouseover=this.style.backgroundColor='#ECECEC' onmouseout=this.style.backgroundColor='#FFFFFF'>\
			<td style='padding:0 0 0 5' class='none'>"+link+""+strtitle+"</a></td>\
			<td width=60 align=right style='padding:0 8 0 0' class='none'>"+link+""+intchnumber+"</a></td>\
		</tr>\
		</table>";
html += "</div>";
*/
////////////////////////////
		}
		html += "</ul>";
	}
	
	///////////////////////////////////////////////////////////////////////////////
	/// ÃßÃµ ÄÁÅÙÃ÷ 
	recom_str = "";
	recom_tot_count = recom_count = 0;

	if( XML_Recom != null )
	{
		recom_tot_count = XML_Recom.length;
		for( i=0; i<recom_tot_count; i++ )
		{
			if( XML_Recom.item(i).getAttribute("TYPE") == "eng2kor" )
			{
				str = XML_Recom.item(i).getAttribute("TITLE");	// ÇÑ¿µ º¯È¯µÈ ´Ü¾îµéÀÇ ÇÏÀÏ¶óÀÌÆ® Ã³¸®¸¦ À§ÇØ
			}
			else if( XML_Recom.item(i).getAttribute("TYPE") == "event" )
			{
				recom_str = XML_Recom.item(i).getAttribute("TITLE");
				recom_count++;
			}
		}
	}
	////////////////////////////////////////////////////////////////////////////////
	/// ÀÎ±â °Ë»ö¾î
	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_" + 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 class=oragne>" + str + "</font>") + "<img class='right' src=http://img.gomtv.com/gomtv/img/auto_star_" + 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_" + 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_" + XML_Content.item(i).getAttribute("RESULT")  +".gif width='39' height='6' alt='' />\
						</li>\
						";					
			}
		}


/*
html += "\
				<li id='no_" + w + "' onmouseover=\"if(parent.index>-1&&parent.index!=" + w + "){document.getElementById('no_' + parent.index).style.backgroundColor='';} parent.index=" + w + ";this.style.backgroundColor='#FDF9E9';parent.selectedQueryStr='" + XML_Content.item(i).getAttribute('WORD') + "';\" 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_" + XML_Content.item(i).getAttribute("RESULT")  +".gif width='39' height='6' alt='' />\
				</li>\
				";


		html += "<div id='no_" + w + "' style='width:100%; height:15px; cursor:pointer'";
		html += "onmouseover=\"if(parent.index>-1&&parent.index!=" + w + "){document.getElementById('no_' + parent.index).style.backgroundColor='';} parent.index=" + w + ";this.style.backgroundColor='#ECECEC';parent.selectedQueryStr='" + XML_Content.item(i).getAttribute('WORD') + "';\" ";
		html += "onmouseout=\"parent.index=-1;this.style.backgroundColor='#FFFFFF'\" "; 
		html += "onmousedown=\"parent.goTWordSearch_auto('" + XML_Content.item(i).getAttribute("WORD") + "')\"; >";
		if( XML_Content.item(i).getAttribute("WORD") == str )
		{
			html += "<table width=100% cellspacing=0 cellpadding=0 border=0><tr height=21 onmouseover=this.style.backgroundColor='#ECECEC' onmouseout=this.style.backgroundColor='#FFFFFF'><td class='gray4' style='padding-left:5'>" + XML_Content.item(i).getAttribute("WORD").replace(str, "<font class=orange>" + str.bold() + "</font>") + "</td><td width=60 align=right style='padding-right:8'><img src=http://img.gomtv.com/gomtv/img/auto_star_" + XML_Content.item(i).getAttribute("RESULT")  +".gif width=39 heigth=6></td></tr></table>";
		}
		else
		{
			if( searchMode == 0 )
			{
				if( XML_Content.item(i).getAttribute("WORD").indexOf(str) == 0 )
				{
					html += "<table width=100% cellspacing=0 cellpadding=0 border=0><tr height=21 onmouseover=this.style.backgroundColor='#ECECEC' onmouseout=this.style.backgroundColor='#FFFFFF'><td class='gray4' style='padding-left:5'>" + XML_Content.item(i).getAttribute("WORD").replace(str, "<font class=oragne>" + str + "</font>") + "</td><td width=60 align=right style='padding-right:8'><img src=http://img.gomtv.com/gomtv/img/auto_star_" + XML_Content.item(i).getAttribute("RESULT")  +".gif width=39 heigth=6></td></tr></table>";
				}
				else
				{
					html += "<table width=100% cellspacing=0 cellpadding=0 border=0><tr height=21 onmouseover=this.style.backgroundColor='#ECECEC' onmouseout=this.style.backgroundColor='#FFFFFF'><td class='srch' style='padding-left:5'>" + XML_Content.item(i).getAttribute("WORD") + "</td><td width=60 align=right style='padding-right:8'><img src=http://img.gomtv.com/gomtv/img/auto_star_" + XML_Content.item(i).getAttribute("RESULT")  +".gif width=39 heigth=6></td></tr></table>";
				}
			}
			else
			{
					html += "<table width=100% cellspacing=0 cellpadding=0 border=0><tr height=21 onmouseover=this.style.backgroundColor='#ECECEC' onmouseout=this.style.backgroundColor='#FFFFFF'><td class='gray4' style='padding-left:5'>" + XML_Content.item(i).getAttribute("WORD").replace(str, "<font class=orange>" + str + "</font>") + "</td><td width=60 align=right style='padding-right:8'><img src=http://img.gomtv.com/gomtv/img/auto_star_" + XML_Content.item(i).getAttribute("RESULT")  +".gif width=39 heigth=6></td></tr></table>";
			}
		}
		html += "</div>";

*/
	}

	var recom_html="";
/*	if( recom_str != "" )
	{
		recom_html += "\
				<table width=100% border=0 cellspacing=0 cellpadding=0>\
				<tr height=5>\
					<td></td>\
				</tr>\
				<tr height=25>\
					<td style='padding:0 0 0 2'><b>ÃßÃµ ÄÁÅÙÃ÷</b></td>\
				</tr>\
				</table>\
				<table width=100% border=0 cellspacing=0 cellpadding=0>\
				<tr>\
					<td background=http://img.gomtv.com/gomtv/img/auto_border2_top.gif><img src=http://img.gomtv.com/gomtv/img/auto_border2_lt.gif></td>\
					<td background=http://img.gomtv.com/gomtv/img/auto_border2_top.gif align=right><img src=http://img.gomtv.com/gomtv/img/auto_border2_rt.gif></td>\
				</tr>\
				<tr>\
					<td colspan=2 style='border-left:1px #999999 solid; border-right:1px #999999 solid; padding:2 2 1 4' bgcolor=#FFFFFF>\
						<table width=100% border=0 cellspacing=0 cellpadding=0>\
						<tr>\
							<td style='padding:2 0 0 0' class='none'>"+recom_str+"</td>\
						</tr>\
						</table>\
					</td>\
				</tr>\
				<tr>\
					<td background=http://img.gomtv.com/gomtv/img/auto_border2_bot.gif><img src=http://img.gomtv.com/gomtv/img/auto_border2_lb.gif></td>\
					<td background=http://img.gomtv.com/gomtv/img/auto_border2_bot.gif align=right><img src=http://img.gomtv.com/gomtv/img/auto_border2_rb.gif></td>\
				</tr>\
				</table>\
				";
	}
*/

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

	height = 85 + key_count*20;

	if( recom_count > 0 )
	{
//		height += 50;	
	}
	else
	{

	}
	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 )
{
	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.php?opt=" + searchMode + "&query=" + str; 
		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_Recom = q_xmlhttp.responseXML.getElementsByTagName("RECOM");
					XML_Channel = q_xmlhttp.responseXML.getElementsByTagName("CHANNEL");
					dispListBox( 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();
}
