font_cho = Array('¤¡', '¤¢', '¤¤', '¤§', '¤¨','¤©', '¤±', '¤²', '¤³', '¤µ', '¤¶', '¤·', '¤¸', '¤¹', '¤º', '¤»', '¤¼', '¤½', '¤¾' ); 
font_jung = Array('¤¿', '¤À', '¤Á', '¤Â', '¤Ã', '¤Ä', '¤Å', '¤Æ', '¤Ç', '¤È', '¤É', '¤Ê', '¤Ë', '¤Ì', '¤Í', '¤Î', '¤Ï', '¤Ð', '¤Ñ', '¤Ò', '¤Ó' ); 
font_jong = Array('', '¤¡', '¤¢', '¤£', '¤¤', '¤¥', '¤¦', '¤§', '¤©', '¤ª', '¤«', '¤¬', '¤­', '¤®', '¤¯', '¤°', '¤±', '¤²', '¤´', '¤µ', '¤¶', '¤·', '¤¸', '¤º', '¤»', '¤¼', '¤½', '¤¾' );
var SearchDouble="";
var nFocus="";
var OldKeyWord="";

function ChoSung(aaa){
	stringtest = aaa;
	CompleteCode = stringtest.charCodeAt(0);
	UniValue = CompleteCode - 0xAC00;
	
	Jong = UniValue % 28;
	Jung = ( ( UniValue - Jong ) / 28 ) % 21;
	Cho = parseInt (( ( UniValue - Jong ) / 28 ) / 21);
	 
	//alert(font_cho[Cho])
	//return font_cho[Cho];
	 
}

var xmlHttp;
var results;
var rowNum=-1;	//ÇöÀç¼±ÅÃµÈ ¿­¹øÈ£
var IsWork;		//Á¶È¸µÈ ¸®½ºÆ®°¡ Á¸ÀçÇÏ´ÂÁö ¿©ºÎ
var IsUse=1;	//ÀÚµ¿¿Ï¼º±â´É »ç¿ë,¹Ì»ç¿ë
var FocusWhere=1;	//Æ÷Ä¿½º°¡ ¾îµðÀÖ´ÂÁö
var y=-1;
var ymax = 0;

//XMLHttpRequest °´Ã¼»ý¼º
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}

//Å° ÀÌº¥Æ® Ã³¸®(¹æÇâÅ°)
function KeyChk(){
	if(event.keyCode==13){SearchKeyWord();}
	//--------------------------------------------------------------------------------------------
	// ¾Æ·¡ ¹æÇâÅ°,ÅÇ ´­·¶À»¶§
	//--------------------------------------------------------------------------------------------
	if(event.keyCode==40 || event.keyCode==9){			
		// ·¹ÀÌ¾î°¡ ¾Èº¸ÀÌ´Â »óÈ²ÀÌ¶ó¸é º¸ÀÌ°Ô Ã³¸®
		if(document.all['search_layer'].style.visibility == "hidden"){		
			document.all['search_layer'].style.visibility = "visible";
		}
			// ½ÇÁ¦ Ã³¸®ºÎºÐ				
			if(IsWork==1){
				if(ymax>0 && y<ymax-2){
					if(y>-1) eval('word'+y).style.backgroundColor = '#ffffff';
					y++;
					eval('word'+y).style.backgroundColor = '#ECECEC';
					document.SearchFrm.KeyWord.value=results[y];				//ÅØ½ºÆ®¹Ú½º¿¡ ¹Ý¿µ
					if(y>4){													//½ºÅ©·ÑÀÌµ¿
						document.all.tblshow.scrollTop = (y-4)*20; 
					} 
				}
			}
		
	}

	//--------------------------------------------------------------------------------------------
	//À§ÂÊ ¹æÇâÅ° ´­·¶À»¶§
	//--------------------------------------------------------------------------------------------
	if(event.keyCode==38){			
		// ·¹ÀÌ¾î°¡ ¾Èº¸ÀÌ´Â »óÈ²ÀÌ¶ó¸é º¸ÀÌ°Ô Ã³¸®
		if(y>-1 && ymax>0){							
			if(IsWork==1){
				eval('word'+y).style.backgroundColor = '#ffffff';
				y--;
				if(y==-1) {
					document.SearchFrm.KeyWord.value=OldKeyWord;						//ÅØ½ºÆ®¹Ú½º¿¡ ¹Ý¿µ
					document.all['search_layer'].style.visibility = "hidden";
				}
				else {
					eval('word'+y).style.backgroundColor = '#ECECEC';
					document.SearchFrm.KeyWord.value = results[y];						//ÅØ½ºÆ®¹Ú½º¿¡ ¹Ý¿µ
				}
				if(document.all.tblshow.scrollTop>y*20){								//½ºÅ©·ÑÀÌµ¿
					document.all.tblshow.scrollTop = y*20; 
				}
			}
		}else {	
			y=0;
			document.all['search_layer'].style.visibility = "hidden";
		}
	}
}

//ÀÔ·Â°ª AJAXÀü¼ÛÃ³¸®ÇÏ´Â ºÎºÐ
function startRequest(wValue) {
	//--------------------------------------------------------------------------------------------
	// ÀÔ·Â½Ã AJAX Ã³¸®ÇÏ´Â ºÎºÐ(¹æÇâÅ° Á¦¿Ü)
	//--------------------------------------------------------------------------------------------
	if(wValue=="") {
		if(tblshow.hasChildNodes()) {
				tblshow.removeChild(eval('word0'));
				if(ymax>1) {
					for(i=1;i<ymax-1;i++) {
						tblshow.removeChild(eval('word'+i));
					}
				}
			}
		document.all['search_layer'].style.visibility="hidden";
	}
	else if(event.keyCode!=13 && event.keyCode!=37 && event.keyCode!=38 && event.keyCode!=39 && event.keyCode!=40 && IsUse==1 && OldKeyWord!=wValue){
		OldKeyWord=wValue;
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = handleStateChange; 
		xmlHttp.open("GET", "/public/Search_Sub2.asp?word="+ escape(wValue), true);
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=euc-kr');
		xmlHttp.send(null);
		//IsWork=0;
	}
}

//AJAX¿¡¼­ µ¥ÀÌÅÍ ¹Þ¾Æ¿À´Â ºÎºÐ
function handleStateChange() {
    var AutoListHeight=20;
    
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			
			//ÇÏÀ§³ëµå »èÁ¦
			if(tblshow.hasChildNodes()) {
				tblshow.removeChild(eval('word0'));
				if(ymax>1) {
					for(i=1;i<ymax-1;i++) {
						tblshow.removeChild(eval('word'+i));
					}
				}
			}
			document.all['search_layer'].style.visibility = "hidden"
			
			y=-1;
			results = xmlHttp.responseText.split('#*#');
            if(results.length > 0){
				IsWork=1;
				ymax=results.length;
				for(i=0;i < results.length;i++) {
					if(results[i] != '') {
						wordLI = document.createElement('li');
						wordLI.id = 'word' + i;
						elmData = document.createTextNode(results[i]);
						wordLI.appendChild(elmData);
						tblshow.appendChild(wordLI);
						wordLI.attachEvent('onmouseup',upLI);
						wordLI.attachEvent('onmouseover',overLI);
						wordLI.attachEvent('onmouseout',outLI);
					}
				}
				
				//·¹ÀÌ¾î °Ë»ö±æÀÌ¿¡ ¸Â°Ô µ¿ÀûÀ¸·Î º¯È¯
				if(ymax==2){ 
					document.all['tblshow'].style.height=AutoListHeight; 
				}else if(ymax==3){ 
					document.all['tblshow'].style.height=AutoListHeight*2; 
				}else if(ymax==4){ 
					document.all['tblshow'].style.height=AutoListHeight*3;
				}else if(ymax==5){ 
					document.all['tblshow'].style.height=AutoListHeight*4;
				}else{ 	
					document.all['tblshow'].style.height=AutoListHeight*5-2; 
				}

				document.all['search_layer'].style.visibility = "visible";
            }
			if(ymax==1){
				IsWork=0;
				ymax=0;
				wordLI = document.createElement('li');
				wordLI.id = 'word0';
				elmData = document.createTextNode("ÇØ´ç °Ë»ö¾î °ü·Ã ÃßÃµ¾î°¡ ¾ø½À´Ï´Ù.");
				wordLI.appendChild(elmData);
				tblshow.appendChild(wordLI);
				document.all['tblshow'].style.height=AutoListHeight;
			}

        }
    }
}

//¸¶¿ì½º ¿À¹ö½Ã ¹è°æ»ö
function overLI(evt){
	var obj;
	obj = getevtObjName(evt)
	obj.style.backgroundColor = '#ECECEC';
	obj.style.color = '#ff0000';
}

//¸¶¿ì½º ¾Æ¿ô½Ã ¹è°æ»ö º¹±Í
function outLI(evt){
	var obj;
	obj = getevtObjName(evt)
	obj.style.backgroundColor = '#fff';
	obj.style.color = '#656565';
}

//¸¶¿ì½º Å¬¸¯½Ã
function upLI(evt){
	document.SearchFrm.KeyWord.value = results[getevtObjName(evt).id.substring(4)];
	SearchKeyWord();
}

//¿ÀºêÁ§Æ®¸í ¹Þ¾Æ¿À±â
function getevtObjName(evt){
	if(evt.srcElement)
		return evt.srcElement;
	else
		return evt.target;
}

//°Ë»öÀÔ·ÂÃ¢¿¡ Æ÷Ä¿½º°¡ °¥¶§, ÀÚµ¿¿Ï¼ºÈ­¸é º¸ÀÌ±â
function KeyFocus() {
	if(ymax>0 && IsUse==1){	
		document.all['search_layer'].style.visibility = "visible";
	}
}

// ÀÚµ¿¿Ï¼º È­¸é º¸ÀÌ±â,¼û±â±â
function search_layerView(cValue){
	//º¸ÀÌ±â
	if(cValue==1){
		if(IsUse==0){
			search_layerOn(1);
		}
		if(document.all['search_layer'].style.visibility=="visible") {
			SearchDouble="OK";
			document.all['search_layer'].style.visibility="hidden";
		}
	}
	//¼û±â±â
	else{
		if(SearchDouble=="OK") {
			document.all['search_layer'].style.visibility="visible";
		}
	}
}

function TopValueChk() {
	if(document.SearchFrm.KeyWord.value=="") {
		document.all['search_layer'].style.visibility="hidden";
	}
}

function FocusChk(cValue){
	if(cValue==1){
		if(FocusWhere==0){
			FocusWhere=1;
			tblshow.focus();
		}
	}
	else{
		if(FocusWhere==1){
			FocusWhere=0;
			document.SearchFrm.KeyWord.focus();
		}
	}
}
