/* ---------------------------------------------------------------------------------------------------------------------------------------------
Common Function
--------------------------------------------------------------------------------------------------------------------------------------------- */
function LTrim(s) {
	return s.replace(/^\s+/g,"");
}

function RTrim(s) {
	return s.replace(/\s+$/g,"");
}

function Trim(s) {
	return LTrim(RTrim(s));
}

function Len(s) {
	var s1 = Trim(s);
	return s1.length;
}

function num_only()
{
	if(((event.keyCode<48) || (event.keyCode>57)) && (event.keyCode != 46)) {
	event.returnValue=false;
	}
}

function CheckNum(s) {
    if (Len(s) == 0) return false;

    for (i=0; i < s.length; i++) {
        if (!(s.charAt(i) >= "0" && s.charAt(i) <= "9")) 
            return false;
	}

    return true;
}

function CheckStrNum(s) {
    if (Len(s) == 0) return false;

    for (i=0; i < s.length; i++) {
        if (!((s.charAt(i) >= "a" && s.charAt(i) <= "z") ||
	      (s.charAt(i) >= "A" && s.charAt(i) <= "Z") ||
	      (s.charAt(i) >= "0" && s.charAt(i) <= "9")))
            return false;
	}

    return true;
}

function CheckExceptStrNum(s) {
    if (Len(s) == 0) return false;

    for (i=0; i < s.length; i++) {
        if (!((s.charAt(i) >= "a" && s.charAt(i) <= "z") ||
	      (s.charAt(i) >= "A" && s.charAt(i) <= "Z") ||
	      (s.charAt(i) >= "0" && s.charAt(i) <= "9") ||
	      (s.charAt(i) == "_"))) 
            return false;
	}

    return true;
}

function CheckSpace(s) {
    if (Len(s) == 0) return false;

    for (i=0; i < s.length; i++) {
        if (s.charAt(i) == " ") 
            return false;
	}

    return true;
}

function namosw_exchange_src() { 
	str = namosw_exchange_src.arguments[0];
	str = (navigator.appName == 'Netscape') ? 'document.' + str : 'document.all.' + str;
	img = eval(str);
	if (img) {
		if (img.ori_src == null) {
			img.ori_src = img.src;
			img.src     = namosw_exchange_src.arguments[1];
		} else {
			var temp    = img.src;
			img.src     = img.ori_src;
			img.ori_src = temp;
		}
	} 
}

function namosw_preload_img() { 
	var img_list = namosw_preload_img.arguments;
	
	if (document.preloadlist == null) document.preloadlist = new Array();

	var top = document.preloadlist.length;

	for (var i=0; i < img_list.length; i++) {
		document.preloadlist[top+i]     = new Image;
		document.preloadlist[top+i].src = img_list[i];
	} 
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
Style Switer
--------------------------------------------------------------------------------------------------------------------------------------------- */
function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		a.disabled = true;
		if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
			&& a.getAttribute("rel").indexOf("alt") == -1
			&& a.getAttribute("title")
		) return a.getAttribute("title");
	}
		return null;
	}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

window.onload = function(e) {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);

	switch (document.body.id) {
		case "default" : 
			var i;
			i = document.getElementById("split_image_no").value;
			
			namosw_preload_img('/images/split/' + i + '/1.gif', '/images/split/' + i + '/2.gif', '/images/split/' + i + '/3.gif', '/images/split/' + i + '/4.gif', '/images/split/' + i + '/5.gif', '/images/split/' + i + '/6.gif', '/images/split/' + i + '/7.gif', '/images/split/' + i + '/8.gif', '/images/split/' + i + '/9.gif', '/images/split/' + i + '/10.gif', '/images/split/' + i + '/11.gif', '/images/split/' + i + '/12.gif', '/images/split/' + i + '/13.gif', '/images/split/' + i + '/14.gif', '/images/split/' + i + '/15.gif', '/images/split/' + i + '/16.gif');
			break;
		case "hwadu_2th" :
			namosw_preload_img('/images/hwadu/split_image_1_2th.gif', '/images/hwadu/split_image_2_2th.gif', '/images/hwadu/split_image_3_2th.gif', '/images/hwadu/split_image_4_2th.gif', '/images/hwadu/split_image_5_2th.gif', '/images/hwadu/split_image_6_2th.gif');
			break;
		case "hwadu_3th" :
			namosw_preload_img('/images/hwadu/split_image_1_3th.gif', '/images/hwadu/split_image_2_3th.gif', '/images/hwadu/split_image_3_3th.gif', '/images/hwadu/split_image_4_3th.gif', '/images/hwadu/split_image_5_3th.gif', '/images/hwadu/split_image_6_3th.gif');
			break;
		case "master_2th" :
			namosw_preload_img('/images/master/split_image_1_2th.gif', '/images/master/split_image_2_2th.gif', '/images/master/split_image_3_2th.gif', '/images/master/split_image_4_2th.gif', '/images/master/split_image_5_2th.gif', '/images/master/split_image_6_2th.gif');
			break;
		case "master_3th" :
			namosw_preload_img('/images/master/split_image_1_3th.gif', '/images/master/split_image_2_3th.gif', '/images/master/split_image_3_3th.gif', '/images/master/split_image_4_3th.gif', '/images/master/split_image_5_3th.gif', '/images/master/split_image_6_3th.gif');
			break;
		case "life_2th" :
			namosw_preload_img('/images/life/split_image_1_2th.gif', '/images/life/split_image_2_2th.gif', '/images/life/split_image_3_2th.gif', '/images/life/split_image_4_2th.gif', '/images/life/split_image_5_2th.gif', '/images/life/split_image_6_2th.gif');
			break;
		case "life_3th" :
			namosw_preload_img('/images/life/split_image_1_3th.gif', '/images/life/split_image_2_3th.gif', '/images/life/split_image_3_3th.gif', '/images/life/split_image_4_3th.gif', '/images/life/split_image_5_3th.gif', '/images/life/split_image_6_3th.gif');
			break;
		case "jokb_2th" :
			namosw_preload_img('/images/jokb/split_image_1_2th.gif', '/images/jokb/split_image_2_2th.gif', '/images/jokb/split_image_3_2th.gif', '/images/jokb/split_image_4_2th.gif', '/images/jokb/split_image_5_2th.gif', '/images/jokb/split_image_6_2th.gif');
			break;
		case "jokb_3th" :
			namosw_preload_img('/images/jokb/split_image_1_3th.gif', '/images/jokb/split_image_2_3th.gif', '/images/jokb/split_image_3_3th.gif', '/images/jokb/split_image_4_3th.gif', '/images/jokb/split_image_5_3th.gif', '/images/jokb/split_image_6_3th.gif');
			break;
		case "library_2th" :
			namosw_preload_img('/images/library/split_image_1_2th.gif', '/images/library/split_image_2_2th.gif', '/images/library/split_image_3_2th.gif', '/images/library/split_image_4_2th.gif', '/images/library/split_image_5_2th.gif', '/images/library/split_image_6_2th.gif');
			break;
		case "library_3th" :
			namosw_preload_img('/images/library/split_image_1_3th.gif', '/images/library/split_image_2_3th.gif', '/images/library/split_image_3_3th.gif', '/images/library/split_image_4_3th.gif', '/images/library/split_image_5_3th.gif', '/images/library/split_image_6_3th.gif');
			break;
		default :
			break;
	}
	if(!NiftyCheck()) return;
	if (document.getElementById("frm_search")) {
		Rounded("form#frm_search","#fff","#ccc");
	}

	if (readCookie("font_size") != null) {
		if (document.getElementById("content")) {
			switch (readCookie("font_size")) {
				case "m" :
					document.getElementById("content").style.fontSize = '12px';
					break;
				case "l" :
					document.getElementById("content").style.fontSize = '14px';
					break;
				case "xl" :
					document.getElementById("content").style.fontSize = '16px';
					break;
				case "xxl" :
					document.getElementById("content").style.fontSize = '18px';
					break;
			}
		}
	}

	if (document.getElementById("footer")) {
		//alert(document.getElementById("footer").style.position);
		//document.getElementById("footer").style.position='absolute';
	}
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

/* ---------------------------------------------------------------------------------------------------------------------------------------------
Round
--------------------------------------------------------------------------------------------------------------------------------------------- */
function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
var b=navigator.userAgent.toLowerCase();
if(b.indexOf("msie 5")>0 && b.indexOf("opera")==-1)
    return(false);
return(true);
}

function Rounded(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
	AddTop(v[i],bk,color,size);
    AddBottom(v[i],bk,color,size);
    }
}

function RoundedTop(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddTop(v[i],bk,color,size);
}

function RoundedBottom(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddBottom(v[i],bk,color,size);
}

function AddTop(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rbottom";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.appendChild(d,el.firstChild);
}

function getElementsBySelector(selector){
var i;
var s=[];
var selid="";
var selclass="";
var tag=selector;
var objlist=[];
if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    objlist.push(document.getElementById(selid));
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className==selclass){
        objlist.push(v[i]);
        }
    }
return(objlist);
}


/* ---------------------------------------------------------------------------------------------------------------------------------------------
Etc
--------------------------------------------------------------------------------------------------------------------------------------------- */

function CheckSearch() {
	if (Len(document.getElementById("unity_search_value").value) == 0) {
		alert('Fill in the search word.');
		document.getElementById("unity_search_value").focus();
		return false;
	}
}

function ViewEvent() {
	document.getElementById("event").style.display = 'none';
	document.getElementById("news").style.display = 'block';
}

function ViewNews() {
	document.getElementById("event").style.display = 'block';
	document.getElementById("news").style.display = 'none';
}

function SetFontSize(type) {
	if (document.getElementById("content")) {
		switch (type) {
			case "m" :
				document.getElementById("content").style.fontSize = '12px';
				createCookie("font_size", "m", 30)
				break;
			case "l" :
				document.getElementById("content").style.fontSize = '14px';
				createCookie("font_size", "l", 30)
				break;
			case "xl" :
				document.getElementById("content").style.fontSize = '16px';
				createCookie("font_size", "xl", 30)
				break;
			case "xxl" :
				document.getElementById("content").style.fontSize = '18px';
				createCookie("font_size", "xxl", 30)
				break;
		}
		location.reload();
	}
}

function SendEmail(topic, page_url) {
	send_email = window.open('/common/lib/send_email.asp?topic=' + escape(topic) + '&page_url=' + escape(page_url), 'send_email', 'scrollbars=0,left=' + (screen.availWidth - 640) / 2 + ',top=' + (screen.availHeight - 430) / 2 + ',width=640,height=430');
	send_email.focus();
	return;
}

function PrintPage(content_type, unique_seq) {
	print_page = window.open('/common/lib/print_page.asp?content_type=' + content_type + '&unique_seq=' + unique_seq, 'print_page', 'scrollbars=1,left=' + (screen.availWidth - 800) / 2 + ',top=' + (screen.availHeight - 600) / 2 + ',width=800,height=600');
	print_page.focus();
	return;
}

function ChgNews(type) {
	if (readCookie("style") != 'text') {
		document.getElementById("news_jokb").getElementsByTagName("dt")[0].style.backgroundImage = "url('/images/title_news_jokb_off.gif')";
		document.getElementById("news_center").getElementsByTagName("dt")[0].style.backgroundImage = "url('/images/title_news_center_off.gif')";
		document.getElementById("news_clipping").getElementsByTagName("dt")[0].style.backgroundImage = "url('/images/title_news_clipping_off.gif')";
		document.getElementById(type).getElementsByTagName("dt")[0].style.backgroundImage = "url('/images/title_" + type + "_on.gif')";

		document.getElementById("news_jokb").getElementsByTagName("dd")[0].style.display = 'none';
		document.getElementById("news_center").getElementsByTagName("dd")[0].style.display = 'none';
		document.getElementById("news_clipping").getElementsByTagName("dd")[0].style.display = 'none';
		document.getElementById(type).getElementsByTagName("dd")[0].style.display = 'block';
	}
}
function OpenMusic() {
	open_music = window.open('http://www.llf.or.kr/music.asp', 'open_music', 'scrollbars=0, left=' + (screen.availWidth - 400) / 2 + ',top=' + (screen.availHeight - 412) / 2 + ',width=400,height=412');
	open_music.focus();
	return;
}