var WWW_HOME = "http://www.melon.com"; //wwwFunc.getWWWHome();
var IMAGE_HOME = "http://image.melon.com";//imageFunc.getImageHome();

var search_promotion = true;

var RcmdServer = "http://www.melon.com/cds/search/web/searchkeyword_list.json";
var RcmdServer_ff = "http://www.melon.com/cds/search/web/searchkeyword_list.json";

var Td_;
var Ip_;
var top_position_;
var left_position_;
var wi_int_;
var bak_="", old_="";
var table_width_;
var ke;
var suggest_type_;	//ÀÚµ¿¿Ï¼º Å¸ÀÔ : ""=ÀüÃ¼, "AR"=Artist, "SO"=Song, "AL"=aLbum
function setDefaultAutoComplete_(objTextBox, valTopPosition, valLeftPosition, valTableWidth, valTimeout, valSuggestType) {
	Ip_ = objTextBox;
	top_position_ = valTopPosition;
	left_position_ = valLeftPosition;
	table_width_ = valTableWidth;
	wi_int_ = valTimeout;
	bak_ = old_ = Ip_.value;
	suggest_type_ = valSuggestType;
}

var g_ie5_ = 0;
function get_nav_() {
	var ver = navigator.appVersion;
	if (navigator.appName.indexOf("Microsoft Internet Explorer") != -1){
		return 1;
	}
	else if (navigator.appName.indexOf("Netscape") != -1) {
		return 2;
	}
	else if (navigator.appName.indexOf("Opera") != -1) {
		return 3;
	}
	else {
		return 0;
	}
}

function chk_rt_(t_) {
	try {
		Td_=document;
	} catch (e) {
		return 0;
	}

	return 1;
}

var t_ = get_nav_();
var c_ = chk_rt_(t_);
var m_on_=0, m_now_=0, s_now_=0, shl_=0, a_now_=0, a_on_=0, arr_on_=0, frm_on_=0;
var B_="block", I_="inline", N_="none", UD_="undefined";
var qs_ac_list_="", qs_ac_id_="", qs_q_="", qs_m_=0, qs_ac_len_=0, qs_ar_cnt="", qs_so_cnt="", qs_al_cnt="";
var acuse_ = 1;
var cc_ = new Object();
if ((t_ == 1 || t_ == 2) && c_ == 1) {

	function wd_() {
		var a = top_position_;
		var b = left_position_;

		document.getElementById("autoSuggestWrap").style.top = a + "px";
		document.getElementById("autoSuggestWrap").style.left = b + "px";

		if (acuse_ == 1) Ip_.autocomplete = "off";
		else if (acuse_ == 0) Ip_.autocomplete = "on";

		Ip_.onclick = req_ipc_;
		Ip_.onblur = dis_p_;
		document.getElementById("autoSuggestWrap").onclick = dis_p_;
	}

	var dnc_ = 0;
	function req_ipc_() {
		dnc_ = 1;
		frm_on_ = 0;
		req_ac2_(1);
	}

	function dis_p_() {
		if (dnc_) {
			dnc_ = 0;
			return;
		}
		if (arr_on_) {
			return;
		}
		if (frm_on_) {
			return;
		}
		alw = 0;
		ac_hide_();
	}

	function req_ac2_(me) {
		if (Ip_.value == "" || acuse_==0 ) return;
		if (a_on_ && dnc_) {
			ac_hide_();
			return;
		}
		var o = get_cc_(me);
		if (o && o[1][0] != ""){
			ac_show_(o[0], o[1], o[2], me);
		}else{
			reqAC_(me);
		}
	}

	var _req_ = null;
	function get_req_()	{
		if (window.ActiveXObject) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e2) {
					return null;
				}
			}
		} else if (window.XMLHttpRequest) {
			//Win Mac Linux m1,f1,o8 Mac s1 Linux k3
			return new XMLHttpRequest();
		} else {
			return null;
		}
	}

	function showResponse(oj){
		try {
			var qs_q_ = oj.qs_q_;
			var qs_m_ = oj.qs_m_;
			var qs_ac_id_ = oj.qs_ac_id_;
			var qs_ar_cnt = oj.qs_ar_cnt;
			var qs_so_cnt = oj.qs_so_cnt;
			var qs_al_cnt = oj.qs_al_cnt;
			var list = oj.qs_ac_list_;
			if (list == null || list  == "") list = "''";
			var qs_ac_list_ = eval("["+list+"]");

		} catch(e) {
			var qs_q_ = '';
			var qs_m_ = '1';
			var qs_ac_id_ = '1';
			var qs_ac_list_ = new Array('');
		}
		set_cc_(qs_q_, qs_ac_list_, qs_m_);
		ac_show_(qs_q_, qs_ac_list_, qs_ac_id_, qs_m_, qs_ar_cnt, qs_so_cnt, qs_al_cnt);
	}

	function sendRequest(callback, url, data, method) {

		url = url + "?" + data;
		$.ajaxSetup({
			cache: false,
			crossDomain: true,
			scriptCharset: "utf-8" ,
			contentType: "application/json; charset=utf-8"
		});

//		$.ajax({
//			url: url,
//			jsonpCallback: "showResponse",
//			dataType: "jsonp",
//			type: method,
//			contentType: "application/json; charset=UTF-8",
//			scriptCharset: "UTF-8",
//			cache: false,
//			jsonp: 'jscallback'
//		});

		$.getJSON (url+"&jscallback=?",function(data){showResponse(data); });

	}

	function reqAC_(me) {
		var sv;
		var stripped = "";

		ke = trim_space_(Ip_.value, me);
		ke = ke.replace(/ /g, " ");
		ke = ke.replace(/\\/g, "");
		//ke = ke.replace(/\'/g, "");	// 2009.08.13 KYPARK : '¸¦ ÀÚµ¿¿Ï¼º ¼­¹ö·Î ³Ñ±â±â À§ÇØ¼­ ¸·À½
		//ke = ke.replace(/&/g, "");//¾Æ·¡Ã³·³ º¯°æ QA¿äÃ»°Ç 2011.02.25
		ke = ke.replace(/&/g, "%26");
		ke = ke.replace(/|/g, "");
		ke = ke.replace(/ or /g, "");
		ke = ke.replace(/ and /g, "");
		ke = ke.replace(/ OR /g, "");
		ke = ke.replace(/ AND /g, "");
		//ke = ke.replace(/-/g, "");//º¯°æ QA¿äÃ»°Ç 2011.02.25 - µµ ÀÏÄ¡°Ë»ö¾î·Î ³ª¿Àµµ·Ï ¿äÃ»ÇÔ
		ke = ke.replace(/ not /g, "");
		//ke = ke.replace(/%/g, "%25");	// 2009.08.14 KYPARK : %¸¦ ÀÚµ¿¿Ï¼º ¼­¹ö·Î ³Ñ±â±â À§ÇØ¼­ Ãß°¡ //º¯°æ QA¿äÃ»°Ç 2011.02.25

		if ((ke == "") || (ke == "or") || (ke == "and") || (ke=="not")) {
			ac_hide_();
			return;
		}


		sv = RcmdServer + ke;
		ke = "suggestType=" + encodeURIComponent(suggest_type_) + "&query=" + encodeURIComponent(encodeURIComponent(ke)) + "&where=" + encodeURIComponent(document.searchMainFrm.menu_id.value);
		sendRequest(showResponse, RcmdServer, ke, "GET");
	}


	function ac_show_(aq, al, ai, am, ar_cnt, so_cnt, al_cnt) {
		if (aq && aq != "" && aq != trim_space_(Ip_.value, am))
			return;

		qs_q_ = aq;
		qs_m_ = am;
		qs_ac_list_ = al;
		qs_ac_id_ = ai;
		qs_ac_len_ = qs_ac_list_.length;

		qs_ar_cnt = ar_cnt;
		qs_so_cnt = so_cnt;
		qs_al_cnt = al_cnt;

		var h = (qs_ac_len_ > 9) ? 9 : qs_ac_len_;
		h = h * 20;

		print_ac_();

		if (qs_ac_list_[0] == "" && (qs_m_ == 1 || qs_m_ == 2)) {
			qs_ac_len_ = 1;
			h = 0;
			if (qs_ac_list_[0] == "") h = 0;
		}
		document.getElementById("autoSuggestWrap").style.height = h;

		if (qs_ac_len_) {
			h += 41;
			a_on_ = 1;
		} else {
			a_on_ = 0;
		}
		document.getElementById("autoSuggestWrap").width = table_width_+4;
		document.getElementById("autoSuggestWrap").height = h;
		document.getElementById("autoSuggestWrap").style.display = B_;

		if (a_on_) {
			set_acpos_(0);
			document.getElementById("autoSuggestWrap").scrollTop = 0;
			Ip_.onkeydown =  function (event){
				ackhl_(event);
			} ;
		}


		// °Ë»ö¾î ÀÔ·ÂÃ¢ ¿·ÀÇ È­»ìÇ¥¸¦ On »óÅÂ·Î º¯°æÇÑ´Ù.
		melonFunc.replace($("#btnSuggest img"), /Off./, "On.");
		$("#btnSuggest img").addClass("on");

	}

	function set_acpos_(v) {
		a_now_ = v;
		setTimeout('set_ahl_();', 10);
	}

	function set_ahl_() {
		var o1, o2;
		if (!a_on_) return;
		for (i=0;  i<qs_ac_len_; i++) {
			o1 = eval("document.getElementById('autoSuggestWrap_line_" + (i+1) + "_')");
			if ((i+1) == a_now_){
				o1.style.backgroundColor = "#F0F0F0";
			}else{
				try{ o1.style.backgroundColor = "";}catch (e) {}
			}
		}
	}

	var max_row_ = 4;
	function ackhl_(e) {
		//var e = window.event;
		if (!e) var e = window.event;

		var o1, o2, o3, o4;
		if (e.keyCode == 39) {
			req_ac2_(1);
		}
		if (e.keyCode == 40 || (e.keyCode == 9 && !e.shiftKey)) {

			if (m_on_) return;

			if (!a_on_) {
				req_ac2_(1);
				return;
			}
			if (a_now_ < qs_ac_len_) {
				if (a_now_ == 0) bak_ = Ip_.value;
				a_now_++;
				if (a_now_ > max_row_) document.getElementById("autoSuggestWrap").scrollTop = parseInt((a_now_-1)/max_row_)*max_row_*20;
				try{

					o1 = document.getElementById('autoSuggestWrap_line_' + a_now_ + '_');
					o2 = document.getElementById('acq' + a_now_ + '_');
					o3 = document.getElementById('secHidden_' + a_now_ + '_');//Ãß°¡
					o4 = document.getElementById('secIdHidden_' + a_now_ + '_');//Ãß°¡

					document.searchMainFrm.srchSec.value = o3.value;//Ãß°¡
					document.searchMainFrm.srchSecId.value = o4.value;//Ãß°¡

					//old_ = Ip_.value = o2.outerText;
					old_ = Ip_.value = o2.innerHTML;
					Ip_.focus();
					set_ahl_();
					e.returnValue = false;
				} catch (e) {	}
			}
		}
		if (a_on_ && (e.keyCode == 38 || (e.keyCode == 9 && e.shiftKey))) {
			if (!a_on_) return;
			if (a_now_ <= 1) {
				ac_hide_();
				old_ = Ip_.value = bak_;
			}
			else {
				a_now_--;
				if ((qs_ac_len_-a_now_)+1 > max_row_) document.getElementById("autoSuggestWrap").scrollTop = (qs_ac_len_-(parseInt((qs_ac_len_-a_now_)/max_row_)+1)*4)*20;
				try{
					o1 = document.getElementById('autoSuggestWrap_line_' + a_now_ + '_');
					o2 = document.getElementById('acq' + a_now_ + '_');
					o3 = document.getElementById('secHidden_' + a_now_ + '_');//Ãß°¡
					o4 = document.getElementById('secIdHidden_' + a_now_ + '_');//Ãß°¡

					document.searchMainFrm.srchSec.value = o3.value;//Ãß°¡
					document.searchMainFrm.srchSecId.value = o4.value;//Ãß°¡

					//old_ = Ip_.value = o2.outerText;
					old_ = Ip_.value = o2.innerHTML;
					Ip_.focus();
					set_ahl_();
					e.returnValue = false;
				} catch (e) {}
			}
		}
	}


	function print_ac_() {
		if (qs_ac_list_[0] == "" ) {
			document.getElementById("autoSuggestWrap").innerHTML = "<div class=\"downBody\">" + get_ac0_() + "</div><span class=\"downBgB\"></span>";
		} else if (document.searchMainFrm.menu_id.value == 'artist') {
			document.getElementById("autoSuggestWrap").innerHTML = "<div class=\"downBody\">" + get_aclist_artist() + "</div><span class=\"downBgB\"></span>";
		} else {
			document.getElementById("autoSuggestWrap").innerHTML = "<div class=\"downBody\">" + get_aclist_() + "</div><span class=\"downBgB\"></span>";
		}
		document.getElementById("autoSuggestWrap").style.display = B_;
		setTimeout('set_ahl_();', 20);//30
	}


	function get_aclist_artist() {
		var d="", ds="", l=0, s="";
		var aclist_table_width = table_width_;
		var srwd = document.searchMainFrm.q.value.replace(/\'/g, "`") ;
		if (qs_ac_list_[0] != "" &&	qs_ac_list_[0].indexOf("") > -1) {//ÄÁÅÙÃ÷Çü ÀÚµ¿¿Ï¼º ³ëÃâ
			s += "<dl class=\"albAutoDownBox\">";
			s += "<dt><a href=\"#\"><img src=\""+IMAGE_HOME+"/resource/image/cds/search/web/titDown_1.gif\" alt=\"¾ÆÆ¼½ºÆ®\"/></a></dt>";
			s += "<dd>";
			s += "<ul class=\"resultBox1\">";
			for (i=0; i < qs_ac_len_; i++) {
				ds = d = qs_ac_list_[i];
				infoList = ds.split("");
				anm_org = infoList[1];
				anm = infoList[1];
				l = js_strlen_(anm);

				if (l > 30) anm = js_substring_(anm, 0, 28) + "..";
				// &ÀÌ µé¾î¿ÔÀ»¶§ js_highlight ±â´ÉÀ» »ç¿ëÇÏÁö ¾Ê´Â´Ù.
				if (anm.indexOf("&") != 0) {
					anm = js_highlight(anm, qs_q_, qs_q_, 0);
				}

				if(infoList[4]=='M'){
					sexNm="³²¼º";
				}else if(infoList[4]=='F'){
					sexNm="¿©¼º";
				}else if(infoList[4]=='H'){
					sexNm="È¥¼º";
				}else{
					sexNm='';
				}
				if(infoList[3].length >0 && sexNm.length >0){
					na_sx = infoList[3] + " <span class=\"bar\">|</span> "+sexNm;
				}else if(infoList[3].length >0 && sexNm.length==0){
					na_sx = infoList[3] ;
				}else if(infoList[3].length==0 && sexNm.length >0){
					na_sx = sexNm ;
				}else{
					na_sx='';
				}
				if ( na_sx.length >0 && infoList[5].length >0) {
					na_sx_gnm = na_sx+" <span class=\"bar\">|</span> "+ infoList[5];
				} else if ( na_sx.length >0 && infoList[5].length==0) {
					na_sx_gnm = na_sx;
				} else if (na_sx.length==0 && infoList[5].length >0) {
					na_sx_gnm = infoList[5];
				}else{
					na_sx_gnm='';
				}

				//ÀÌ¹ÌÁö
				img_home = "http://image.melon.com";
				img_path = img_home+infoList[2];
				if(img_path != img_home){
					img_path_last = img_path.lastIndexOf('.');
					img_70 = img_path.substring(0, img_path_last)+ "_th."+img_path.substring(img_path_last+1, img_path.length);
				}else{
					img_70 = "http://image.melon.com";
				}
				s += " <li id='autoSuggestWrap_line_" + (i+1) + "_'  onmouseover=\"set_acpos_('" + (i+1) + "')\" onmouseout=\"set_acpos_(0); \">";
				//s += "	<a href='/cds/artist/web/artistdetailmain_list.htm?artistId="+infoList[0]+"' title='"+anm_org+"'>";
				s += "	<a href=\"javascript:goArDetail_('web_acartist','ARTIST','AR','"+srwd+"','"+infoList[0]+"');\" title='"+anm_org+"'>";
				s += "	<span class=\"im\"><img src='"+img_70+"' ONERROR=\"defaultImg_artist(this);\" alt=\"\"></span>";
				s += "	<span class=\"na\">"+anm+"</span>";
				s += "	<span class=\"ty\">"+na_sx_gnm+"</span>";
				s += "	</a>";
				s += " </li>";
				s += " <span id='acq" + (i+1) + "_' style='display:none; width:0px; height:0px;'>" + anm_org + "</span> ";
				s += " <input type='hidden' id='secIdHidden_" + (i+1) + "_' value='"+ infoList[0]+"' /> ";//Ãß°¡
				s += " <input type='hidden' id='secHidden_" + (i+1) + "_' value='ar' /> ";//Ãß°¡
			}
			s += "</ul>";
			s += "</dd>";
			s += "</dl>";

		} else if (qs_ac_list_[0] != "" && qs_ac_list_[0].indexOf("") < 0 ) {//±âÁ¸ ÀÚµ¿¿Ï¼º ³ëÃâ
			s += "<ul class=\"resultBox3\">";
			for (i=0; i < qs_ac_len_; i++) {
				ds = d = qs_ac_list_[i];
				l = js_strlen_(d);
				if (l > 30) ds = js_substring_(d, 0, 28) + "..";
				ds = js_highlight(ds, qs_q_, qs_q_, 0);
				//s += "<li id='autoSuggestWrap_line_" + (i+1) + "_'  onmouseover=\"set_acpos_('" + (i+1) + "')\" onmouseout=\"set_acpos_(0); \" onmousedown=\"set_acinput_('" + i + "')\" >";
				s += "<li id='autoSuggestWrap_line_" + (i+1) + "_'  onmouseover=\"set_acpos_('" + (i+1) + "')\" onmouseout=\"set_acpos_(0); \">";
				s += " <a href=\""+WWW_HOME+"/cds/search/web/searchtotalmain_list.htm?type=total&bg_type=headerTop&query="+d+"\" title=\""+d+"\">"+ ds +"</a>";
				s += "</li>";
				s += " <span id='acq" + (i+1) + "_' style='display:none; width:0px; height:0px;'>" + d + "</span>";
				s += " <input type='hidden' id='secIdHidden_" + (i+1) + "_' value='' /> ";//Ãß°¡
				s += " <input type='hidden' id='secHidden_" + (i+1) + "_' value='txt'/> ";//Ãß°¡
			}
			s += "</ul>";
		}
		return s;
	}

	function get_aclist_() {
		var d="", ds="", l=0, s="";
		var ar_=0, so_=0, al_=0;
		var aclist_table_width = table_width_;
		var endBgnone = "";
		var srwd = document.searchMainFrm.q.value.replace(/\'/g, "`") ;

		if (qs_ac_list_[0] != "" &&	qs_ac_list_[0].indexOf("") > -1) {//ÄÁÅÙÃ÷Çü ÀÚµ¿¿Ï¼º ³ëÃâ

			if(qs_ar_cnt > 0){
				endBgnone = "";
				if(qs_so_cnt <= 0 && qs_al_cnt <= 0) {
					endBgnone = "bgnone";
				}
				s += "<dl class=\"albAutoDownBox "+endBgnone+"\">";
				s += "<dt><a href=\"#\"><img src=\""+IMAGE_HOME+"/resource/image/cds/search/web/titDown_1.gif\" alt=\"¾ÆÆ¼½ºÆ®\"/></a></dt>";
				s += "<dd>";
				s += "<ul class=\"resultBox1\">";
				for (var arCnt=0; arCnt < qs_ar_cnt; arCnt++) {
					ds = d = qs_ac_list_[arCnt];
					infoList = ds.split("");
					//¾ÆÆ¼½ºÆ®¸í
					anm_org = infoList[1];
					anm = infoList[1];
					l = js_strlen_(anm);

					if (l > 30) anm = js_substring_(anm, 0, 28) + "..";

					// &ÀÌ µé¾î¿ÔÀ»¶§ js_highlight ±â´ÉÀ» »ç¿ëÇÏÁö ¾Ê´Â´Ù.
					if (anm.indexOf("&") != 0) {
						anm = js_highlight(anm, qs_q_, qs_q_, 0);
					}

					if(infoList[4]=='M'){
						sexNm="³²¼º";
					}else if(infoList[4]=='F'){
						sexNm="¿©¼º";
					}else if(infoList[4]=='H'){
						sexNm="È¥¼º";
					}else{
						sexNm='';
					}
					if(infoList[3].length >0 && sexNm.length >0){
						na_sx = infoList[3] + " | "+sexNm;
					}else if(infoList[3].length >0 && sexNm.length==0){
						na_sx = infoList[3] ;
					}else if(infoList[3].length==0 && sexNm.length >0){
						na_sx = sexNm ;
					}else{
						na_sx='';
					}
					if ( na_sx.length >0 && infoList[5].length >0) {
						na_sx_gnm = na_sx+" | "+ infoList[5];
					} else if ( na_sx.length >0 && infoList[5].length==0) {
						na_sx_gnm = na_sx;
					} else if (na_sx.length==0 && infoList[5].length >0) {
						na_sx_gnm = infoList[5];
					}else{
						na_sx_gnm='';
					}

					//ÀÌ¹ÌÁö
					img_home = "http://image.melon.com";
					img_path = img_home+infoList[2];
					if(img_path != img_home){
						img_path_last = img_path.lastIndexOf('.');
						img_70 = img_path.substring(0, img_path_last)+ "_th."+img_path.substring(img_path_last+1, img_path.length);
					}else{
						img_70 = "http://image.melon.com";
					}

					s += " <li id='autoSuggestWrap_line_" + (arCnt+1) + "_'  onmouseover=\"set_acpos_('" + (arCnt+1) + "')\" onmouseout=\"set_acpos_(0); \">";
					//s += "	<a href='/cds/artist/web/artistdetailmain_list.htm?artistId="+infoList[0]+"' title='"+anm_org+"'>";
					s += "	<a href=\"javascript:goArDetail_('web_acartist','ARTIST','AR','"+srwd+"','"+infoList[0]+"');\" title='"+anm_org+"'>";
					s += "	<span class=\"im\"><img src='"+img_70+"' ONERROR=\"defaultImg_artist(this);\" alt=\"\"></span>";
					s += "	<span class=\"na\">"+anm+"</span>";
					s += "	<span class=\"ty\">"+na_sx_gnm+"</span>";
					s += "	</a>";
					s += " </li>";
					s += " <span id='acq" + (arCnt+1) + "_' style='display:none; width:0px; height:0px;'>" + anm_org + "</span> ";
					s += " <input type='hidden' id='secIdHidden_" + (arCnt+1) + "_' value='"+ infoList[0]+"' /> ";//Ãß°¡
					s += " <input type='hidden' id='secHidden_" + (arCnt+1) + "_' value='ar' /> ";//Ãß°¡
				}
				s += "</ul>";
				s += "</dd>";
				s += "</dl>";
			}


			if(qs_so_cnt > 0){


				if( qs_ar_cnt  > 0){
					so_ =  qs_ar_cnt;
				}else{
					so_ = 0;
				}
				endBgnone = "";
				if(qs_so_cnt <= 0 ) {
					endBgnone = "bgnone";
				}
				s += "<dl class=\"albAutoDownBox "+endBgnone+"\">";
				s += "<dt><a href=\"#\"><img src=\""+IMAGE_HOME+"/resource/image/cds/search/web/titDown_3.gif\" alt=\"°î\"/></a></dt>";
				s += "<dd>";
				s += "<ul class=\"resultBox1\">";
				for (soCnt=so_; soCnt < parseInt(qs_so_cnt)+parseInt(qs_ar_cnt) ; soCnt++) {
					ds = d = qs_ac_list_[soCnt];
					infoList = ds.split("");

					//°î¸í
					snm_org = infoList[1];
					snm = infoList[1];
					l = js_strlen_(snm);
					if (l > 30) snm = js_substring_(snm, 0, 28) + "..";
					// &ÀÌ µé¾î¿ÔÀ»¶§ js_highlight ±â´ÉÀ» »ç¿ëÇÏÁö ¾Ê´Â´Ù.
					if (snm.indexOf("&") != 0) {
						snm = js_highlight(snm, qs_q_, qs_q_, 0);
					}

					//¾ÆÆ¼½ºÆ®¸í
					anm_org = infoList[3];
					anmList = anm_org.split("");
					var anm = '';
					var anm_= '';
					for(anSize = 0; anSize < anmList.length ; anSize++){
						anm_ = anmList[anSize].indexOf('=');
						if(anm.length > 0){anm += ", ";}
						anm += anmList[anSize].substring(anm_+1, anmList[anSize].length);
					}
					if (anm.length > 30) anm = js_substring_(anm, 0, 28) + "..";


					//ÀÌ¹ÌÁö
					img_home = "http://image.melon.com";
					img_path = img_home+infoList[2];
					if(img_path != img_home){
						img_path_last = img_path.lastIndexOf('.');
						img_38 = img_path.substring(0, img_path_last)+ "_hs.png";
					}else{
						img_38 = "http://image.melon.com";
					}

					s += " <li id='autoSuggestWrap_line_" + (parseInt(soCnt)+1) + "_'  onmouseover=\"set_acpos_('" + (parseInt(soCnt)+1) + "')\" onmouseout=\"set_acpos_(0); \">";
					//s += "	<a href='/cds/album/web/albumdetailmain_list.htm?albumId="+infoList[4]+"' title='"+snm_org+"'>";
					s += "	<a href=\"javascript:goAlDetail_S('web_acsong','SONG','SO','"+srwd+"','"+infoList[4]+"','"+infoList[0]+"');\" title='"+snm_org+"'>";
					s += "	<span class=\"im\"><img src='"+img_38+"' ONERROR=\"defaultImg_album(this);\" alt=\"\"></span>";
					s += "	<span class=\"na\">"+snm+"</span>";
					s += "	<span class=\"ty\">"+anm+"</span>";
					s += "	</a>";
					s += " </li>";
					s += " <span id='acq" + (parseInt(soCnt)+1) + "_' style='display:none; width:0px; height:0px;'>" + snm_org + "</span> ";
					s += " <input type='hidden' id='secIdHidden_" + (parseInt(soCnt)+1) + "_' value='"+ infoList[0] + "-" + infoList[4]+"' /> ";//Ãß°¡
					s += " <input type='hidden' id='secHidden_" + (parseInt(soCnt)+1) + "_' value='so' /> ";//Ãß°¡
				}
				s += "</ul>";
				s += "</dd>";
				s += "</dl>";
			}


			if(qs_al_cnt > 0){
				if(parseInt(qs_ar_cnt)+ parseInt(qs_so_cnt) > 0){
					al_ = parseInt(qs_ar_cnt)+ parseInt(qs_so_cnt);
				}else{
					al_ = 0;
				}

				s += "<dl class=\"albAutoDownBox bgnone\">";
				s += "<dt><a href=\"#\"><img src=\""+IMAGE_HOME+"/resource/image/cds/search/web/titDown_2.gif\" alt=\"¾Ù¹ü\"/></a></dt>";
				s += "<dd>";
				s += "<ul class=\"resultBox2\">";
				for (alCnt=al_; alCnt < parseInt(qs_ar_cnt)+parseInt(qs_so_cnt)+parseInt(qs_al_cnt); alCnt++) {
					ds = d = qs_ac_list_[alCnt];
					infoList = ds.split("");

					//¾Ù¹ü¸í
					ab_nm_org = infoList[1];
					ab_nm = infoList[1];
					l = js_strlen_(ab_nm);
					if (l > 30) ab_nm = js_substring_(ab_nm, 0, 28) + "..";
					// &ÀÌ µé¾î¿ÔÀ»¶§ js_highlight ±â´ÉÀ» »ç¿ëÇÏÁö ¾Ê´Â´Ù.
					if (ab_nm.indexOf("&") != 0) {
						ab_nm = js_highlight(ab_nm, qs_q_, qs_q_, 0);
					}

					//¾ÆÆ¼½ºÆ®¸í
					/*anm_org = infoList[3];
					anm_ = anm_org.indexOf('=');
					anm = anm_org.substring(anm_+1, anm_org.length);
					if(anm.indexOf('')>-1){
						anm = anm_org.substring(anm_+1, anm_org.indexOf('')+1);
					}*/
					anm_org = infoList[3];
					anmList = anm_org.split("");
					var anm = '';
					var anm_= '';
					for(anSize = 0; anSize < anmList.length ; anSize++){
						anm_ = anmList[anSize].indexOf('=');
						if(anm.length > 0){anm += ", ";}
						anm += anmList[anSize].substring(anm_+1, anmList[anSize].length);
					}
					if (anm.length > 30) anm = js_substring_(anm, 0, 28) + "..";

					//ÀÌ¹ÌÁö
					img_home = "http://image.melon.com";
					img_path = img_home+infoList[2];
					if(img_path != img_home){
						img_path_last = img_path.lastIndexOf('.');
						img_38 = img_path.substring(0, img_path_last)+ "_hs.png";
					}else{
						img_38 = "http://image.melon.com";
					}

					s += " <li id='autoSuggestWrap_line_" + (parseInt(alCnt)+1) + "_'  onmouseover=\"set_acpos_('" + (parseInt(alCnt)+1) + "')\" onmouseout=\"set_acpos_(0); \">";
					//s += "	<a href='/cds/album/web/albumdetailmain_list.htm?albumId="+infoList[0]+"' title='"+ab_nm_org+"'>";
					s += "	<a href=\"javascript:goAlDetail_A('web_acalbum','ALBUM','AL','"+srwd+"','"+infoList[0]+"');\" title='"+ab_nm_org+"'>";
					s += "	<span class=\"im\"><img src='"+img_38+"' ONERROR=\"defaultImg_album(this);\" alt=\"\"></span>";
					s += "	<span class=\"na\">"+ab_nm+"</span>";
					s += "	<span class=\"ty\">"+anm+"</span>";
					s += "	</a>";
					s += " </li>";
					s += " <span id='acq" + (parseInt(alCnt)+1) + "_' style='display:none; width:0px; height:0px;'>" + ab_nm_org + "</span> ";
					s += " <input type='hidden' id='secIdHidden_" + (parseInt(alCnt)+1) + "_' value='"+ infoList[0]+"' /> ";//Ãß°¡
					s += " <input type='hidden' id='secHidden_" + (parseInt(alCnt)+1) + "_' value='al' /> ";//Ãß°¡
				}
				s += "</ul>";
				s += "</dd>";
				s += "</dl>";
			}




		} else if (qs_ac_list_[0] != "" && qs_ac_list_[0].indexOf("") < 0 ) {//±âÁ¸ ÀÚµ¿¿Ï¼º ³ëÃâ

			s += "<ul class=\"resultBox3\">";
			for (i=0; i < qs_ac_len_; i++) {
				ds = d = qs_ac_list_[i];
				l = js_strlen_(d);
				if (l > 36) ds = js_substring_(d, 0, 36) + "..";
				// &ÀÌ µé¾î¿ÔÀ»¶§ js_highlight ±â´ÉÀ» »ç¿ëÇÏÁö ¾Ê´Â´Ù.
				if (ds.indexOf("&") != 0) {
					ds = js_highlight(ds, qs_q_, qs_q_, 0);
				}
				//s += "<li id='autoSuggestWrap_line_" + (i+1) + "_'  onmouseover=\"set_acpos_('" + (i+1) + "')\" onmouseout=\"set_acpos_(0); \" onmousedown=\"set_acinput_('" + i + "')\" >";
				s += "<li id='autoSuggestWrap_line_" + (i+1) + "_'  onmouseover=\"set_acpos_('" + (i+1) + "')\" onmouseout=\"set_acpos_(0); \" >";
				s += " <a href=\""+WWW_HOME+"/cds/search/web/searchtotalmain_list.htm?type=total&bg_type=headerTop&query="+d+"\" title=\""+d+"\">"+ ds +"</a>";
				s += "</li>";
				s += " <span id='acq" + (i+1) + "_' style='display:none; width:0px; height:0px;'>" + d + "</span>";
				s += " <input type='hidden' id='secIdHidden_" + (i+1) + "_' value='' /> ";//Ãß°¡
				s += " <input type='hidden' id='secHidden_" + (i+1) + "_' value='txt' /> ";//Ãß°¡
			}
			s += "</ul>";

			document.searchMainFrm.srchSec.value = "";//Ãß°¡
			document.searchMainFrm.srchSecId.value = "";//Ãß°¡
		}

		return s;
	}


	function js_highlight(s, d, eq, is_suf) {
		var ret = "";

		if (!is_suf) {
			ret = js_makehigh_pre(s, d);
			if (ret == "") ret = js_makehigh_pre(s, eq);
		} else {
			ret = js_makehigh_suf(s, d);
			if (ret == "") ret = js_makehigh_suf(s, eq);
		}

		if (ret == "") return s;
		else return ret;
	}

	function js_makehigh_pre(s, t) {
		var d = "";
		var s1 = s.replace(/ /g, "");
		var t1 = t.replace(/ /g, "");

		s1 = s1.toLowerCase(); 	// 2009.09.14 KYPARK : ´ë¼Ò¹®ÀÚ ¹«½Ã
		t1 = t1.toLowerCase();
		if (t1 == s1.substring(0, t1.length)) {
			d = "<font color='red'>";
			for (var i=0, j=0; j < t1.length; i++) {
				if (s.substring(i, i+1) != " ") j++;
				d += s.substring(i, i+1);
			}
			d += "</font>"+s.substring(i, s.length);
		}
		return d;
	}

	function js_makehigh_suf(s, t) {
		var d = "";
		var s1 = s.replace(/ /g, "");
		var t1 = t.replace(/ /g, "");

		s1 = s1.toLowerCase(); 	// 2009.08.14 KYPARK : ´ë¼Ò¹®ÀÚ ¹«½Ã
		t1 = t1.toLowerCase();
		if (t1 == s1.substring(s1.length-t1.length)) {
			for (var i=0, j=0; j < s1.length-t1.length; i++) {
				if (s.substring(i, i+1) != " ") j++;
				d += s.substring(i, i+1);
			}
			d+="<font color='red'>";
			for (var k=i, l=0; l < t1.length; k++) {
				if (s.substring(k, k+1) != " ") l++;
				d += s.substring(k, k+1);
			}
			d += "</font>";
		}
		return d;
	}

	function set_acinput_(v) {
		if (!a_on_) return;

		old_ = Ip_.value = qs_ac_list_[v];
		Ip_.focus();
		ac_hide_();
	}

	function get_ac0_() {
		var s="", ment="";
		var ac0_table_width = table_width_-7;
		if (qs_m_==1) ment = "ÇØ´ç ±ÛÀÚ·Î ½ÃÀÛÇÏ´Â ´Ü¾î°¡ ¾ø½À´Ï´Ù.";
		else if (qs_m_==2) ment = "ÇØ´ç ±ÛÀÚ·Î ³¡³ª´Â ´Ü¾î°¡ ¾ø½À´Ï´Ù.";
		s += "<table style='font-size: 12px; width:" + table_width_ + ";' border='0' cellspacing='0' cellpadding='0'>";
		s += " <tr id='autoSuggestWrap_line_1_' style=\"backgroundColor=''\">";
		s += "  <td height='18' style=\"padding: 5px 0; padding-left: 5px;\" align='left' ><font color='#797F7D'>" + ment + "</td></tr>";
		s += "	<span id=acq1_ style='display:none'>" + old_ + "</span>";
		s += "	<input type='hidden' id='secIdHidden_1_' value='' /> ";//Ãß°¡
		s += "	<input type='hidden' id='secHidden_1_' value='txt' /> ";//Ãß°¡
		s += "</table>";
		return s;
	}

	function js_strlen_(s) {
		var i, l=0;

		for (i=0; i < s.length; i++)
			if (s.charCodeAt(i) > 127) l+=2;
			else l++;
		return l;
	}

	function js_substring_(s, start, len) {
		var i, l=0, d="";

		for (i=start; i < s.length && l < len; i++) {
			if (s.charCodeAt(i) > 127) l += 2;
			else l++;
			d += s.substr(i, 1);
		}
		return d;
	}

	function trim_space_(ke, me) {
		if (me != 2) {
			ke = ke.replace(/^ +/g, "");
			ke = ke.replace(/ +$/g, " ");
		} else {
			ke = ke.replace(/^ +/g, " ");
			ke = ke.replace(/ +$/g, "");
		}
		ke = ke.replace(/ +$/g, " ");

		return ke;
	}

	function get_cc_(me) {
		var ke = trim_space_(Ip_.value, me) + me;

		return typeof(cc_[ke])==UD_ ? null : cc_[ke];
	}

	function set_cc_(aq, al, ai, me) {
		cc_[aq+me] = new Array(aq, al, ai);
	}

	function ac_hide_() {
		if (document.getElementById("autoSuggestWrap").style.display == N_) return;
		document.getElementById("autoSuggestWrap").style.display = N_;
		a_on_ = a_now_ = 0;
		document.searchMainFrm.srchSec.value = "";//Ãß°¡
		document.searchMainFrm.srchSecId.value = "";//Ãß°¡

		// °Ë»ö¾î ÀÔ·ÂÃ¢ ¿·ÀÇ È­»ìÇ¥¸¦ Off »óÅÂ·Î º¯°æÇÑ´Ù.
		melonFunc.replace($("#btnSuggest img"), /On./, "Off.");
		$("#btnSuggest img").removeClass("on");
	}

	function wi_() {
		if (acuse_ == 0) return;
		if (m_on_) {
			setTimeout("wi_()", wi_int_);
			return;
		}

		var now = Ip_.value;
		if (now == "" && now != old_) ac_hide_();
		if (now != "" && now != old_ && keystatus_!=1) {
			var o=null, me=1;
			o = get_cc_(me);
			if (o && o[1][0] != "") ac_show_(o[0], o[1], o[2], me);
			else reqAC_(me);
		}

		old_ = now;
		setTimeout("wi_()", wi_int_);
	}

	function set_mouseon_(f) {
		if (f == 1) arr_on_ = 1;
		else if (f == 2) frm_on_ = 1;
	}

	function set_mouseoff_(f) {
		if (f == 1) arr_on_ = 0;
		else if (f == 2) frm_on_ = 0;
	}

	function req_pf_() {
		frm_on_ = 1;
		req_ac2_(1);
		Ip_.focus();
		cursor_end_();
	}

	function req_sf_() {
		frm_on_ = 1;
		req_ac2_(2);
		Ip_.focus();
		cursor_end_();
	}

	function cursor_end_() {
		if (t_ == 1 && c_ == 1) {
			var rng = Ip_.createTextRange();

			if (rng != null) {
				rng.move("textedit");
				rng.select();
			}
		}
	}
}

var keystatus_ = 1;
function setTextBox_(evt) {

	var textbox = Ip_;
	var _event;

	switch (getNavigatorType_()) {
		case 1 : // IE
			_event = window.event;
			nodeName = _event.srcElement.nodeName;
			nodeId = _event.srcElement.id;
			break;
		case 2 : case 3 :// Netscape
			_event = evt;
			//nodeName = _event.target.nodeName;
			nodeName = _event.target.nodeName;
			nodeId = _event.target.id;
			break;
		default :
			nodeName = "None";
			nodeId = "None";
			break;
	}

	key = _event.keyCode;
	if (keystatus_ == 1 && key != 13) {
		//textbox.value = "";
		keystatus_ = 2;
	}

}

function getNavigatorType_() {
	if (navigator.appName == "Microsoft Internet Explorer")
		return 1;
	else if (navigator.appName == "Netscape")
		return 2;
	else if (navigator.appName == "Opera")
		return 3;
	else
		return 0;
}

function search_promo_off() {
	search_promotion = false;
}

function getBrws() {
	var ua = navigator.userAgent;
	var safari	= ua.indexOf("Safari") != -1;
	var konqueror	= ua.indexOf("Konqueror") != -1;
	var mozes	= ((a=navigator.userAgent.split("Gecko/")[1]) ?a.split(" ")[0]:0) >= 20011128;

	if (window.opera || safari || mozes)
		return "NI";
	else
		return "IE";
}

////////////////////////
////////////////////////

function trim(s){
	s = s.replace(/^\s*/,'').replace(/\s*$/, '');
	return s;
}


