// Hide And Show Toggle
var cc=0
function hideShow(id) {
	if (cc==0) {
		cc=1
		document.getElementById(id).style.display="none";
	} else {
		cc=0
		document.getElementById(id).style.display="block";
	}
}

// Show And Hide Toggle
var cc=0
function showHide(id) {
	if (cc==0) {
		cc=1
		document.getElementById(id).style.display="block";
	} else {
		cc=0
		document.getElementById(id).style.display="none";
	}
}

// Local Navigation Toggle
function lnbToggle(id) {
	for(num=1; num<=3; num++) document.getElementById('D3MG'+num).style.display='none'; //D4MG1~D4MG3 까지 숨긴 다음
	document.getElementById(id).style.display='block'; //해당 ID만 보임
}

// IS
function chkIsKind(key, value) {
	showHide('selectOrder');
	xGetElementById('search_target'+key).checked = true;
	xInnerHtml('search_target_label', value);
}



/* IE Flicker Bug Fix */
try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}



/* 포탈서치폼 영역에 포커스 */
function doFocusX(fo_id) {
	if(xScrollTop()) return;
	var fo_obj = xGetElementById(fo_id);
	if(fo_obj) {
		try{
			fo_obj.focus();
		} catch(e) {};
	}
}


// ### 키워드 인코딩
// Escape the '+' character as well as those escaped by Javascript escape.
// This matches up unescaping that is done by CSP.
function enEscape (str) {
	return escape(str).replace('+','%2B');
}

var enHexChars = "0123456789ABCDEF";
function enEncodeChar (ch) {
	return '%' + enHexChars.charAt(ch >> 4) + enHexChars.charAt(ch & 0x0F);
}

function enEncodeUTF8 (s) {
	var sbuf = '';
	var len;
	var i;
	var ch;

	if (s==null) return "";

	s=s+"";
	len = s.length;

	for (i = 0; i < len; i++) {
		ch = s.charCodeAt(i);
		if ( (65 <= ch && ch <= 90) || // 'A'..'Z'
			(97 <= ch && ch <= 122) || // 'a'..'z'
			(46 <= ch && ch <= 57) ) { // '.', '/', '0'..'9'
			sbuf += s.charAt(i);

		} else if (ch == 32) { // space
			sbuf += '+';

		} else if (ch <= 0x007f) { // other ASCII
			sbuf += enEncodeChar(ch);

		} else if (ch <= 0x07FF) { // non-ASCII <= 0x7FF
			sbuf += enEncodeChar(0xc0 | (ch >> 6));
			sbuf += enEncodeChar(0x80 | (ch & 0x3F));

		} else { // 0x7FF < ch <= 0xFFFF
			sbuf += enEncodeChar(0xe0 | (ch >> 12));
			sbuf += enEncodeChar(0x80 | ((ch >> 6) & 0x3F));
			sbuf += enEncodeChar(0x80 | (ch & 0x3F));
		}
	}
	return sbuf;
}




// ### 포탈검색 안내 내용 보이기 여부 쿠키설정
/*  if (xGetCookie('editor_mode') == 'html')

	if(mode == 'html' || mode ==''){
		var expire = new Date();
		expire.setTime(expire.getTime()+ (7000 * 24 * 3600000));
		xSetCookie('editor_mode', mode, expire);
	}
*/

//특정부분을 가렸다가 보였다가 하는 함수 <== FF 지원안함.
function ctlDisply(id, doit) {
	obj = xGetElementById(id);
	if(!doit) {
		if (obj.style.display == "none")	{	obj.style.display = 'block';	doit='show'; }
		else								{	obj.style.display = 'none';		doit='hide'; }
	} else {
		if (doit=='show')		obj.style.display = "block";
		if (doit=='hide')		obj.style.display = "none";
	}

	if(id == 'searchHelp'){
		var expire = new Date();
		expire.setTime(expire.getTime()+ (365 * 24 * 3600000)); // 24 * 3600000 = 1일
		xSetCookie('main_search_help', doit, expire);
	}

} 
//document.all[''].style.display = "none"; // document.all[]   <== FF 지원안함.

//검색관련
search1 = new Array;
search1[0] = ["http://www.naver.com",		"http://search.naver.com/search.naver?query="];
search1[1] = ["http://www.daum.net",		"http://search.daum.net/cgi-bin/nsp/search.cgi?action=query&pg=express&which=web&qt=&q="];
search1[2] = ["http://www.empas.com",		"http://search.empas.com/search/all.html?z=A&q="];
search1[3] = ["http://www.nate.com",		"http://nate.search.empas.com/search/all.html?s=&z=A&q="];
search1[4] = ["http://www.paran.com",		"http://search.paran.com/search/index.php?fn=top&Query="];
search1[5] = ["http://kr.yahoo.com",		"http://kr.search.yahoo.com/bin/search?&p="];
search1[6] = ["http://www.google.co.kr",	"http://www.google.co.kr/search?complete=1&hl=ko&aq=f&q="];
search1[7] = ["http://www.dreamwiz.com",	"http://search.dreamwiz.com/cgi-bin/irs.cgi?so=2&x=21&y=12&q="];
search1[8] = ["http://cyworld.com",			"http://cyworld.search.empas.com/search/all.html?q="];
search2 = new Array;
search2[0] = ["http://dic.naver.com/",		"http://search.naver.com/search.naver?where=dic&query="];
search2[1] = ["http://cglink.kr/terms",		"http://cglink.kr/?mid=terms&category=&search_target=title_content&search_keyword="];
search2[2] = ["http://www.encyber.com/",	"http://www.encyber.com/search_w/wsearch.php?q="];

var PotalSearchKind = 1;
function ChangeSearch(m) {
	if(m==1) {	ctlDisply('DivSearch1','show');	ctlDisply('DivSearch2','hide');	PotalSearchKind = 1;	}
	if(m==2) {	ctlDisply('DivSearch1','hide');	ctlDisply('DivSearch2','show');	PotalSearchKind = 2;	}
}

function PotalSearch(re2,t) {
	if(re2==0) {		keyword = enEscape(xGetElementById('PSF_word').value);	}	//encodeURI, encodeURIComponent, escape
	else {				keyword = enEncodeUTF8(xGetElementById('PSF_word').value); }

	if(t==null)	target = '_top';
	else			target = t;

	if(PotalSearchKind==1) {
		if(keyword) {
			if(t==null)	{	location.href = '/l.php?url=' + escape(search1[0][1] + keyword);		return false;	}
			else			{	window.open(search1[re2][1] + keyword, target);	}
		} else {
								location.href = '/l.php?url=' + escape(search1[re2][0]);
		}
	} else if(PotalSearchKind==2) {
		if(keyword) {
			if(t==null)	{	location.href = '/l.php?url=' + escape(search2[0][1] + keyword); 	return false;	}
			else			{	window.open(search2[re2][1] + keyword, target); }
		} else {
								location.href = '/l.php?url=' + escape(search2[re2][0]);
		}
	}

}

function OnEnter( field ) { if( field.value == field.defaultValue ) { field.value = ""; } }
function OnExit( field ) { if( field.value == "" ) { field.value = field.defaultValue; } }


//toolbar=0,Uncopyhistory=no,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=610,height=470
function openWin(rUrl,rName,rContent) {
	remote = window.open(rUrl,rName,rContent);
}

/* 외부링크 */
function linkOut(url) {
	if(url) {
		url = encodeURIComponent(url);
		location.href = '/l.php?url=' + url; 
	}
	//location.replace('/linkOut.php?url=http://www.naver.com');
}

