var fontDefaultSize = 9;
function font_zoom_it(n) {
	fontDefaultSize += n;
	objs = document.getElementsByTagName("body").item(0);
	objs.style.fontSize = fontDefaultSize + "pt";
}
document.getElementById("fontSizeUp").onclick = function () {
	font_zoom_it(1);
	return false;
}
/*
document.getElementById("fontSizeDefault").onclick = function () {
	window.location.reload();
	return false;
}
*/
document.getElementById("fontSizeDown").onclick = function () {
	font_zoom_it(-1);
	return false;
}

var bodyDefaultfSize = 100;

function body_zoom_it(n) {
	bodyDefaultfSize += n;
	objs = document.getElementsByTagName("body").item(0);
	objs.style.zoom = bodyDefaultfSize + "%";
}
document.getElementById("bodySizeUp").onclick = function () {
	body_zoom_it(5);
	return false;
}
document.getElementById("bodySizeDown").onclick = function () {
	body_zoom_it(-5);
	return false;
}

var STATICMENU;
var stmnScrollSpeed = 10;
var stmnTimer;

var check = 0;

function RefreshStaticMenu()
{
	var stmnStartPoint = parseInt(STATICMENU.style.top + 10, 10);
	var stmnEndPoint = parseInt(document.documentElement.scrollTop + 150, 10);
	
	if( check < 10 )
	{
		check++;
	}

	var stmnRefreshTimer = 1;
	
	if ( stmnStartPoint != stmnEndPoint ) {
			stmnScrollAmount = Math.ceil( Math.abs( stmnEndPoint - stmnStartPoint ) / 17 );
			STATICMENU.style.top = parseInt(STATICMENU.style.top, 10) + ( ( stmnEndPoint<stmnStartPoint ) ? -stmnScrollAmount : stmnScrollAmount ) + "px";
			stmnRefreshTimer = stmnScrollSpeed;
	}

	stmnTimer = setTimeout ("RefreshStaticMenu();", stmnRefreshTimer);
}

var check = false;
function InitializeStaticMenu()
{
	STATICMENU = document.getElementById("dvQuickButton");
	STATICMENU.style.top = ( document.documentElement.scrollTop + 50 ) + "px";
	RefreshStaticMenu();
	DivPostSet();
	return;
}

function getObjId(name)
{
	return document.getElementById(name);
}


function DivPostSet()
{
	var bodyObj = document.getElementsByTagName("body").item(0);
	var startpox = bodyObj.offsetWidth/2 + 470;
	
	if( bodyObj.offsetWidth > 920 )
		STATICMENU.style.left = startpox + "px";
	else	
		STATICMENU.style.left = 930 + "px";;
	
	return;
}


if (window.addEventListener) { // W3C
	window.addEventListener("load", InitializeStaticMenu, false);
	window.addEventListener("resize", DivPostSet, false);
} 
else if (window.attachEvent) { // IE
	window.attachEvent("onload", InitializeStaticMenu);
	window.attachEvent("onresize", DivPostSet);
} else {
	window.resize = DivPostSet();
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
}

function isAlNum(ch) {
    return ("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(ch) == -1) ? false : true;
}
removeTags = function(str, myTags) {
    var tags = ['!--','!doctype','isindex','script','blockquote','style','input','plaintext','body','colgroup','fieldset','frameset','multicol','noframes','noscript','optgroup','textarea','basefont','acronym','address','caption','comment','listing','marquee','noembed','nolayer','bgsound','applet','button','center','iframe','ilayer','legend','nextid','object','option','select','server','spacer','strike','strong','keygen','blink','embed','label','layer','small','table','tbody','tfoot','thead','title','param','frame','abbr','area','cite','code','font','form','head','html','menu','nobr','ruby','samp','span','base','link','meta','bdo','big','del','dfn','dir','div','ins','kbd','map','pre','sub','sup','var','xmp','img','col','wbr','br','dd','dl','dt','em','h1','h2','h3','h4','h5','h6','li','ol','rb','rp','rt','td','th','tr','tt','ul','hr','a','b','i','p','q','s','u'];

    if (myTags) {
        for (var i = 0; i < myTags.length; i++) {
            for (var j = 0; j < tags.length; j++) {
                if (myTags[i] == tags[j]) {
                    tags.splice(j, 1);
                    break;
                }
            }
        }
    }

    for (var i = 0; i < tags.length; i++) {
        str = removeTags.remove(str, tags[i]);
    }
    return str.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&#8260;/g, "\/");
};

removeTags.remove = function(str, tag) {
    var op,tp,cp,lt,gt,copy;
    op = 0,lt = "&lt;",gt = "&gt;";
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/\//g, "&#8260;");
    copy = str;
    str = str.toLowerCase();
    while ((op = str.indexOf(lt + tag, op)) != -1) {
        tp = str.substring(op + lt.length + tag.length, op + lt.length + tag.length + 1)
        if (isAlNum(tp)) {
            op = op + lt.length + tag.length + 1;
            continue;
        }
        if ((cp = str.indexOf(lt + "&#8260;" + tag + gt, op)) == -1) {
            tp = str.indexOf(gt, op);
            str = str.substring(0, op) + str.substring(tp + 4, str.length);
            copy = copy.substring(0, op) + copy.substring(tp + 4, copy.length);
        } else {
            if ((tag == "script") || (tag == "style") || (tag == "object")) {
                tp = str.indexOf(gt, op);
                str = str.substring(0, op) + str.substring(cp + tag.length + 9 + 6, str.length);
                copy = copy.substring(0, op) + copy.substring(cp + tag.length + 9 + 6, copy.length);
            } else {
                tp = str.indexOf(gt, op);
                str = str.substring(0, op) +
                      str.substring(tp + 4, cp) +
                      str.substring(cp + tag.length + 9 + 6, str.length);
                copy = copy.substring(0, op) +
                       copy.substring(tp + 4, cp) +
                       copy.substring(cp + tag.length + 9 + 6, copy.length);
            }
        }
    }
    return copy;
};

/**
*   통합 검색 실시
*   신규 수정 2008.2.13
*/
function searchSubmit(){
	var fm = document.searchForm;
	if ( fm.searchText.value == "" ){
		alert("검색어를 입력하세요!");
	}else{
		for(i=0;i<fm.m_type.length;i++){
			if(fm.m_type[i].checked){
				fm.mType.value = fm.m_type[i].value;
			}
		}
		fm.mc_collection.value = "all";
		var col = fm.collection.options[fm.collection.selectedIndex].value;
		if(col == 'dic' || col == 'webdoc'){
			fm.resultcount.value = 10;
			fm.page.value = 1;
		}

		if(col == 'kc'){
			fm.tType.value = "all";
			fm.action = "/SearchSF1/search_result_subject.jsp";
		}else if(col == 'rc'){
			fm.resultcount.value = 3;
			fm.action = "/SearchSF1/search_result_resources.jsp";
		}else{
			fm.action = "/SearchSF1/search_result.jsp";
		}
		//viewDetail('none','block');
		fm.submit();
	}
}

/**
* 상세검색보이기 
* 신규 수정 2008.2.13
*/
function viewDetailGo(){
	var fm = document.searchForm;

	fm.collection.value = "all";
	fm.detail.value = "block";
	fm.inSearch.value = "none";
	fm.searchText.value = "";

	fm.action = "/SearchSF1/search_result.jsp";
	fm.submit();
}

/**
* 매체유형 선택 
* 신규 수정 2008.2.13
*/
function checkMediaType(type){
	document.searchForm.mType.value = type;
}

function onKeyPress(e) {
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (e.keyCode == 13) {
        searchSubmit();
    }
}

function go_dir() {
    var fm = document.searchForm;
    fm.mode.value = "dir";
    fm.ColName.value = "colA";
    fm.ColNameKo.value = "총류";
    fm.action = "/SearchSF1/search_result_dir.jsp";
    fm.submit();
}

function go_nl() {
    var fm = document.searchForm;
    fm.mode.value = "dir";
    fm.ColName.value = "colNL";
    fm.ColNameKo.value = "고서";
    fm.nlKcd.value = "NCL_DB_7"
    fm.action = "/SearchSF1/search_nl_dir.jsp";
    fm.submit();
}

function go_patent() {
    var fm = document.searchForm;
    fm.mode.value = "dir";
    fm.ColName.value = "colPAT";
    fm.ColNameKo.value = "한국특허";
    fm.patKcd.value = "IT201"
    fm.action = "/SearchSF1/search_patent_dir.jsp";
    fm.submit();
}

function advSearch() {
    document.searchForm.action = "/SearchSF1/search_adv.jsp";
    document.searchForm.submit();
}

function goWeekP() {
    document.searchForm.action = "/SearchSF1/famous_search_date.jsp";
    document.searchForm.submit();
}

function getByteLength(str) {
    var byteLength = 0;
    for (inx = 0; inx < str.length; inx++) {
        var oneChar = escape(str.charAt(inx));
        if (oneChar.length == 1) {
            byteLength ++;
        } else if (oneChar.indexOf("%u") != -1) {
            byteLength += 2;
        } else if (oneChar.indexOf("%") != -1) {
            byteLength += oneChar.length / 3;
        }
    }
    return byteLength;
}

//포럼 바로가기
function goto_forum(cafeid) {
    if (cafeid != "") {
        location.href = "/html/forum/club/main.jsp?cafeid=" + cafeid;
    }
}

function goPopular(popular){
	var fm = document.searchForm;
	fm.searchText.value = "";
	fm.searchText.value = popular;
//	document.detailForm.detailSearchText.value = "";
//	document.detailForm.detailSearchText.value = popular;
//	document.detailForm.searchText.value = popular;
//	if(fm.detail.value == "block"){
//		var col = fm.collection.options[fm.collection.selectedIndex].value;
//		if(col == 'webdoc' || col == 'dic'){
//			if( fm.searchText.value == "" ){
//				alert("검색어를 입력하세요!");
//				fm.searchText.focus();
//			}else{
//				searchSubmit();
//			}
//		}else{
//			document.detailForm.mc_collection.value = "all";
//			document.detailForm.collection.value = col;
//			if(col == 'kc'){
//				document.detailForm.tType.value = "all";
//			}
//			detailSearch();
//		}
//	}else{

		for(i=0;i<fm.m_type.length;i++){
			if(fm.m_type[i].checked){
				fm.mType.value = fm.m_type[i].value;
			}
		}
		var col = fm.collection.options[fm.collection.selectedIndex].value;
		if(col == 'kc'){
			fm.action = "/SearchSF1/search_result_subject.jsp";
		}else{
			fm.action = "/SearchSF1/search_result.jsp";
		}
		fm.submit();
	//}
}

function setCookie(value ){
	var nowCookieArray;
	var nowCookieValue = getCookie();
	if(nowCookieValue != ''){
		nowCookieArray = nowCookieValue.split(',');
	}
	

	if(nowCookieArray == null){		
		document.cookie = 'knowid=' + escape( value ) + '; path=/; '
	}else{
		if(nowCookieValue.indexOf(value) == -1){
			if(nowCookieArray.length > 0 && nowCookieArray.length <5){
				document.cookie = 'knowid='+nowCookieValue+',' + escape( value ) + '; path=/; '
			}else if(nowCookieArray.length == 5){
				document.cookie = 'knowid='+nowCookieArray[1]+','+nowCookieArray[2]+','+nowCookieArray[3]+','+nowCookieArray[4]+',' + escape( value ) + '; path=/; '
			}
		}
	}
}

 
function getCookie(){
	var nameOfCookie = "knowid=";
	var x = 0;
	while ( x <= document.cookie.length ){
		var y = (x+nameOfCookie.length);
		
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 )
			break;
	}
	return "";
}

//유료,무료
function viewpage(page,pk) {
	if(page=='document'){
				objWin=window.open('/listing/catalogue/document.jsp?catalogue_num='+pk,'popup','top=0,left=620,width=800,height=650,resizable=1,status=1,menubar=0, scrollbars=yes');
		}
		if(page=='image') {					objWin=window.open('/listing/catalogue/image.jsp?catalogue_num='+pk,'popup','top=0,left=620,width=800,height=650,resizable=1,status=1,menubar=0, scrollbars=yes');
		}
		if(page=='audio') {					objWin=window.open('/listing/catalogue/audio.jsp?catalogue_num='+pk,'popup','top=0,left=620,width=800,height=650,resizable=1,status=1,menubar=0, scrollbars=yes');
		}
		if(page=='video') {					objWin=window.open('/listing/catalogue/video.jsp?catalogue_num='+pk,'popup','top=0,left=620,width=800,height=650,resizable=1,status=1,menubar=0, scrollbars=yes');
		}
		if(page=='application_file') {				objWin=window.open('/listing/catalogue/applicationfile.jsp?catalogue_num='+pk,'popup','top=0,left=620,width=800,height=650,resizable=1,status=1,menubar=0, scrollbars=yes');
		}
		if(page=='application_sw') {				objWin=window.open('/listing/catalogue/applicationsw.jsp?catalogue_num='+pk,'popup','top=0,left=620,width=800,height=650,resizable=1,status=1,menubar=0, scrollbars=yes');
		}
		if(page=='data_db') {					objWin=window.open('/listing/catalogue/datadb.jsp?catalogue_num='+pk,'popup','top=0,left=620,width=800,height=650,resizable=1,status=1,menubar=0, scrollbars=yes');
		}
		if(page=='package') {				objWin=window.open('/listing/catalogue/package.jsp?catalogue_num='+pk,'popup','top=0,left=620,width=800,height=650,resizable=1,status=1,menubar=0, scrollbars=yes');
		}
	objWin.focus(); 
 }