//-------------------------------------------------------------------------------------------------------------------
// inc_newsview : <div onMouseUp="selectMouseBlock();"></div>
// inc_newsview : <div id="NewsviewBanner" style="position:absolute; visibility:hidden;"></div>
// right        : <div id="RightBanner" style="position:absolute; visibility:hidden;"></div>
//-------------------------------------------------------------------------------------------------------------------

var oldEasySearchWordValue = '';
var selectedphrase = '';
var esAutoHidOnOff;
// ÀÌÁö¼­Ä¡ È£Ãâ ÀÌº¥Æ®
var wrd ;			// ¼±ÅÃÇÑ °´Ã¼
function selectMouseBlock(srcObj, srcTxt){
	var agNoiseWords;	// Á¦°ÅÇÒ Æ¯¼ö¹®ÀÚ


	if (event.button == 1){
		// Á¦°ÅÇÒ Æ¯¼ö¹®ÀÚ
		agNoiseWords = "~ ! # $ % ^ * ( ) - _ = + ` ' , . < \ ? \" ";
		// ¼±ÅÃÇÑ ºÎºÐÀÇ °´Ã¼ È¹µæ
		wrd = document.selection.createRange();

		// ¼±ÅÃÇÑ °´Ã¼¾ÈÀÇ ¹®ÀÚ¿­ È¹µæ
		selectedphrase = wrd.text;

		// ¹«°á¼ºÃ¼Å©-¼±ÅÃÀÇ Á¤È®¼º ¹«È¿Ã³¸®
		if( oldEasySearchWordValue == selectedphrase && selectedphrase != "" ){
			esMenuLayerDisplay('N');
			oldEasySearchWordValue = '';
			document.selection.empty();
			return;
		}

		// ¹«°á¼ºÃ¼Å©-¹®ÀÚ¿­ ±æÀÌÃ¼Å© ¹«È¿Ã³¸®
		if(selectedphrase == "" || agNoiseWords.indexOf(selectedphrase) != -1) {
			esMenuLayerDisplay('N');
			return;
		}

		// °ø¹éÀ» Á¦¿ÜÇÑ ¹®ÀÚ¿­ÀÇ ½ÃÀÛÀ§Ä¡¿Í Á¤È®ÇÑ ±æÀÌ °è»ê
		var selWordCount = wrd.text.split(" ").length - 1;		// °ø¹éÀ¸·Î ³ª´µ´Â ¹®ÀÚ¿­±×·ìÀÇ °³¼ö
		var selWordLength = returnGetLength(selectedphrase) ;

		// ±æÀÌ Á¦ÇÑÇÏ¿© ·¹ÀÌ¾îº¸ÀÌ±â
		//if (wrd != null && selWordLength <= 30 && selWordCount <= 3  ){	// ´Ü¾îÁ¦ÇÑ ÀÓ½Ã·Î ¸·½À´Ï´Ù.
		if (wrd != null && selWordLength <= 30){
			esAutoHidOnOff = 'on';
			setTimeout("esMenuLayerDisplay('autoN')",4000);
			esMenuLayerDisplay('Y');
			esMenuLayerPosition();
			oldEasySearchWordValue = selectedphrase ;
		}else {
			esMenuLayerDisplay('N');
		}
	}
}

// ¸Þ´ºÃ³¸® ÇÔ¼ö
function esMenu(key){
	// keyÀÇ Á¾·ù
	// search:ÅëÇÕ°Ë»ö,pdic:»çÀü°Ë»ö,pimg:ÀÌ¹ÌÁö°Ë»ö,pnews:´º½º°Ë»ö,pshop:¼îÇÎ°Ë»ö,copy:º¹»ç

	if (key == '') return;

	switch (key)
	{
		case 'copy':
			setClipboard(selectedphrase);
			break;
		default:
			// var url = "http://www.i815.or.kr/Search/Total?p_eye=news^atc^sch^new^fromNews&rurl=http://search.paran.com/"+key+"/index.php?Query=" + selectedphrase + "%26fromNews%3D1";

			// var url = "http://www.i815.or.kr/KO/Search/TotalSearch/appl/Total.php?v_dblist=249108364596&data_type=all&v_db=&v_rtype=0&v_pnum=5&v_expmode=1&sgh=1&v_kw_query=&t_kw_query="+wrd.text;
// alert( wrd.text );			
			// esOpenUrl(url);
			SearchKeywordHistory( wrd.text );
	}
	esMenuLayerDisplay('N');
}

// »õÃ¢¶ç¿ì±â
function esOpenUrl(url) {
	var pWidth = 800;
	var pHeight = 600;

	var pLeft = screen.width - pWidth - 5 ;
	var pTop = 0  ;

	window.open( url ,'totalSearch' , 'directories =yes, menubar =yes,  location =yes, resizable =yes, status =yes, titlebar =yes, toolbar =yes, scrollbars=yes, top='+ pTop + ' ,left= ' +  pLeft + ', width =' +pWidth + ", height=" + pHeight  );
}

// ¸Þ´º·¹ÀÌ¾î º¸ÀÌ±â/°¨Ãß±â
function esMenuLayerDisplay(YN) {
	if (YN == 'autoN' && esAutoHidOnOff == 'off'){
		return;
	}
	if (YN == 'N') {
		oldEasySearchWordValue = "";
	}
	objDisplay('esMenuLayer', YN);
	return;
}

// ¸Þ´º·¹ÀÌ¾î À§Ä¡Á¤ÇÏ±â
function esMenuLayerPosition() {
	var id ='esMenuLayer';
	var esTop, esLeft;

	if(document.all || document.getElementById) {
		if(document.all) {
			obj = document.all[id];
			esTop = event.clientY + document.body.scrollTop;
			esLeft = event.clientX + document.body.scrollLeft;

			var LeftMove = false;
			var TopMove = false;

			var MenuWidth = 102;
			var MenuHeight = 128;
			var bannerWidth = 230;
			var bannerHeight = 208;

			// 100x126 - À©µµ¿ì ¾È³ª°¡°Ô
			if (esTop > (document.body.clientHeight + document.body.scrollTop - MenuHeight)) {
				TopMove = true;
			}
			if (esLeft > (document.body.clientWidth + document.body.scrollLeft - MenuWidth)) {
				LeftMove = true;
			}

			// 230x208 - ¹è³Ê ¾È°¡¸®°Ô
			if (document.all.NewsviewBanner)
			{

				/*
				*¿µ¿ª¼³Á¤ÀÔ´Ï´Ù.±×¸²ÀÌ ±úÁ® º¸ÀÌ¸é ¸Þ¸ðÀå¿¡¼­ º¸½Ã¿À*
				¦£¦¡¦¡¦¡¦¨¦¡¦¡¦¡¦¡¦¡¦¡¦¡¦¡¦¤
				¦¢      ¦¢                ¦¢
				¦¢  C   ¦¢       B        ¦¢
				¦¢      ¦¢                ¦¢
				¦¢      ¦¢                ¦¢
				¦§¦¡¦¡¦¡¦«¦¡¦¡¦¡¦¡¦¡¦¡¦¡¦¡¦©
				¦¢      ¦¢                ¦¢
				¦¢      ¦¢                ¦¢
				¦¢  A   ¦¢     banner     ¦¢
				¦¢      ¦¢                ¦¢
				¦¢      ¦¢                ¦¢
				¦¢      ¦¢                ¦¢
				¦§¦¡¦¡¦¡¦«¦¡¦¡¦¡¦¡¦¡¦¡¦¡¦¡¦©
				¦¢      ¦¢                ¦¢
				¦¢  E   ¦¢       D        ¦¢
				¦¢      ¦¢                ¦¢
				¦¢      ¦¢                ¦¢
				¦¦¦¡¦¡¦¡¦ª¦¡¦¡¦¡¦¡¦¡¦¡¦¡¦¡¦¥
				*/
				var bannerLeft = document.all.NewsviewBanner.offsetLeft + 340;	// °¡·Î 340¿ÀÂ÷ ¹ÌÇØ°á
				var bannerTop = document.all.NewsviewBanner.offsetTop + 10;		// ¼¼·Î 10¿ÀÂ÷ ¹ÌÇØ°á
				var bannerRight = bannerLeft + bannerWidth;
				var bannerBottom = bannerTop + bannerHeight;

				var bannerALeft = bannerLeft - MenuWidth;
				var bannerATop = bannerTop;
				var bannerARight = bannerLeft;
				var bannerABottom = bannerBottom;

				var bannerBLeft = bannerLeft;
				var bannerBTop = bannerTop - MenuHeight;
				var bannerBRight = bannerRight;
				var bannerBBottom = bannerTop;

				var bannerCLeft = bannerLeft - MenuWidth;
				var bannerCTop = bannerTop - MenuHeight;
				var bannerCRight = bannerLeft;
				var bannerCBottom = bannerTop;

				var bannerDLeft = bannerLeft;
				var bannerDTop = bannerBottom;
				var bannerDRight = bannerRight;
				var bannerDBottom = bannerBottom + MenuHeight;

				var bannerELeft = bannerLeft - MenuWidth;
				var bannerETop = bannerBottom;
				var bannerERight = bannerLeft;
				var bannerEBottom = bannerBottom + MenuHeight;

				// A¿µ¿ªÀÏ¶§ ¼öÆòÀüÈ¯
				if (esTop > bannerATop && esTop < bannerABottom && esLeft > bannerALeft && esLeft < bannerARight)
				{
					LeftMove = true;
				}

				// B¿µ¿ªÀÏ¶§ ¼öÁ÷ÀüÈ¯
				if (esTop > bannerBTop && esTop < bannerBBottom && esLeft > bannerBLeft && esLeft < bannerBRight)
				{
					TopMove = true;
				}

				// C¿µ¿ªÀÏ¶§ ¼öÁ÷ÀüÈ¯
				if (esTop > bannerCTop && esTop < bannerCBottom && esLeft > bannerCLeft && esLeft < bannerCRight)
				{
					LeftMove = true;
				}

				// D¿µ¿ªÀÏ¶§ ¼öÁ÷ÀüÈ¯ ÇØÁ¦
				if (esTop > bannerDTop && esTop < bannerDBottom && esLeft > bannerDLeft && esLeft < bannerDRight)
				{
					TopMove = false;
				}

				// E¿µ¿ªÀÌ¸é¼­ ¼öÁ÷ÀüÈ¯ÀÏ¶§ ¼öÆòÀüÈ¯ ¼¼ÆÃ
				if (esTop > bannerETop && esTop < bannerEBottom && esLeft > bannerELeft && esLeft < bannerERight && TopMove)
				{
					LeftMove = true;
				}

			}else if (document.all.RightBanner){
				//var bannerTop = 120;
				//var bannerLeft = 730 + document.all.esStartLayer.offsetLeft;

				var bannerTop = document.all.RightBanner.offsetTop;
				var bannerLeft = document.all.RightBanner.offsetLeft - 134;

				var bannerALeft = bannerLeft - MenuWidth;
				var bannerABottom = bannerTop + bannerWidth;

				if (esLeft > bannerALeft && esTop < bannerABottom)
				{
					LeftMove = true;
				}

			}

			// ÇØ´ç»çÇ× À§Ä¡ ÀÌµ¿ ½ÃÅ°±â
			if (TopMove){
				esTop = esTop - MenuHeight;
			}

			if (LeftMove){
				esLeft = esLeft - MenuWidth;
			}


		}else {
			obj = document.getElementById(id);
			esTop = event.clientY + window.scrollY;
			esLeft = event.clientX + window.scrollX;

			// 100x126 - À©µµ¿ì ¾È³ª°¡°Ô
			if (esTop > (document.body.clientHeight + window.scrollY - 126)) {
				esTop = esTop - 126;
			}
			if (esLeft > (document.body.clientWidth + window.scrollX - 100)) {
				esLeft = esLeft - 100;
			}
		}

		obj.style.top = esTop;
		obj.style.left = esLeft;
	}

	return;
}

function setAutoHidOff() {
	esAutoHidOnOff = 'off';
}

//----------------------------------------------------------------------------------------------------------------------------
// ¾Æ·¡ÀÇ ÇÔ¼ö´Â À§¿¡¼­ »ç¿ëÇÏ´Â °øÅë ¶óÀÌºê·¯¸®ÀÔ´Ï´Ù. 
//----------------------------------------------------------------------------------------------------------------------------

// ¹®ÀÚ¿­ ±æÀÌ È¹µæ
function returnGetLength(str)
{
	return(str.length+(escape(str)+"%u").match(/%u/g).length-1);
}

// °´Ã¼¸¦ º¸ÀÌ±â/°¨Ãß±â
function objDisplay(id, YN) {
	if(document.all || document.getElementById) {
		if(document.all) {
			obj = document.all[id];
		}else {
			obj = document.getElementById(id);
		}
	}

	if (YN == 'Y'){
		obj.style.visibility = "visible";
	}else {
		obj.style.visibility = "hidden";
	}
	return;
}

// Å¬¸³º¸µå¿¡ ÀúÀå
function setClipboard(text) {
	if( window.clipboardData && window.clipboardData.setData ){
		if (navigator.appVersion.indexOf("MSIE 5") != -1 || navigator.appVersion.indexOf("MSIE 4") != -1) {
			document.esClipBoardForm.esClipBoardText.select();
			document.execCommand('Copy');
		}else {
			window.clipboardData.setData('Text', text);
		}

	} else if (window.netscape) {
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 

		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); 
		if (!clip) return; 

		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); 
		if (!trans) return; 

		trans.addDataFlavor('text/unicode'); 

		var str = new Object(); 
		var len = new Object(); 

		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); 

		var copytext = str;  
		str.data = copytext; 

		trans.setTransferData("text/unicode",str,copytext.length*2); 
		var clipid = Components.interfaces.nsIClipboard; 
		if (!clipid) return false; 

		clip.setData(trans,null,clipid.kGlobalClipboard); 
	}
}

// Å¬¸³º¸µå³»¿ë È¹µæ
function getClipboard() {
	if (window.clipboardData) {
		return(window.clipboardData.getData('Text'));
	} else if (window.netscape) {
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		trans.addDataFlavor('text/unicode');

		clip.getData(trans,clip.kGlobalClipboard);

		var str = new Object();
		var len = new Object();

		try { trans.getTransferData('text/unicode',str,len); }
		catch(error) { return; }

		if (str) {
			if (Components.interfaces.nsISupportsWString) str=str.value.QueryInterface(Components.interfaces.nsISupportsWString);
			else if (Components.interfaces.nsISupportsString) str=str.value.QueryInterface(Components.interfaces.nsISupportsString);
			else str = null;
		}

		if (str) return(str.data.substring(0,len.value / 2));
	}
	return;
}

	document.write("<!--//ÀÌÁö¼­Ä¡ ·¹ÀÌ¾î-->");
	document.write("<form name=\"esClipBoardForm\"><input type=\"hidden\" name=\"esClipBoardText\" value=\"\"></form>");
	document.write("<div id=\"esMenuLayer\" style=\"position:absolute; left:707px; top:323px; width:193px; height:163px; z-index:11; visibility:hidden\" onMouseOver=\"setAutoHidOff();esMenuLayerDisplay('Y')\" onMouseOut=\"esMenuLayerDisplay('N')\">");
	document.write("<table width=\"100\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	document.write("    <tr>");
	document.write("        <td style=\"border:1 solid #9CB4DA; padding: 5;\" bgcolor=\"#F7F8FF\">");
	document.write("        <table width=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	document.write("            <tr>");
	document.write("                <td height=\"17\" class=\"down\" onmouseover=\"this.className='over'\" onmouseout=\"this.className='down'\" onclick=\"esMenu('search')\" style=\"padding:2 0 0 0;cursor:hand;\">ÅëÇÕ°Ë»ö</td>");
	document.write("            </tr>");

	document.write("            <tr>");
if(navigator.appVersion.substring(navigator.appVersion.indexOf('MSIE')+5,navigator.appVersion.indexOf('MSIE')+8)<=5.5){
	document.write("                <td height=\"15\" class=\"down\" onmouseover=\"this.className='over'\" onmouseout=\"this.className='down'\" onclick=\"esMenu('copy')\" style=\"padding:2 0 0 0;cursor:hand;\">");
	document.write("                <img src=\"http://photonews.paran.com/images/easysearch/icon_copy.gif\" width=\"13\" height=\"12\" align=\"absmiddle\" style=\"margin:0 0 2 2;\">");
	document.write("                <a href=\"javascript:esMenu('copy')\" onfocus='javascript:this.blur();'> º¹»ç&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>");
	document.write("                </td>");
}else{
	//document.write("                <a onblur=\"javascript:esMenu('copy')\" onfocus='javascript:this.blur();'> º¹»ç&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td>");
	document.write("                <td height=\"15\" class=\"down\" onmouseover=\"this.className='over'\" onmouseout=\"this.className='down'\" onclick=\"esMenu('copy')\" style=\"padding:2 0 0 0;cursor:hand;\">");
	document.write("                <img src=\"http://photonews.paran.com/images/easysearch/icon_copy.gif\" width=\"13\" height=\"12\" align=\"absmiddle\" style=\"margin:0 0 2 2;\">");
	document.write("                º¹»ç");
	document.write("                </td>");
}
	document.write("        </tr>");
	document.write("        </table>");
	document.write("        </td>");
	document.write("    </tr>");
	document.write("</table>");
	document.write("</div>");
	document.write("<!--ÀÌÁö¼­Ä¡ ·¹ÀÌ¾î//-->");
