function showMySearchWord(obj) {
	if(document.all.my_search) {
		var top = event.clientY - event.offsetY + obj.offsetTop + document.body.scrollTop-3;
		var left = 585;
		document.all.my_search.style.top = top;
		document.all.my_search.style.left = left;
		document.all.my_search.style.visibility = "visible";
	}

}

function show_layer(top, left) {
	if(document.all.my_search) {
		document.all.my_search.style.top = top;
		document.all.my_search.style.left = left;
		document.all.my_search.style.visibility = "visible";
	}
}

function hid_layer() {
	if(document.all.my_search)
		document.all.my_search.style.visibility = "hidden";
}

function show_layer01(top, left) {
	if(document.all.search_poket) {
		document.all.search_poket.style.top = top;
		document.all.search_poket.style.left = left;
		document.all.search_poket.style.visibility = "visible";
	}
}

function hid_layer01() {
	if(document.all.search_poket)
		document.all.search_poket.style.visibility = "hidden";
}

function keyword(searchKeyword) {
	if(searchKeyword == "") {
		alert("검색어를 입력하세요");
		return;
	}
	frmSiteSearch.keyword.value = searchKeyword;
	frmSiteSearch.submit();
}

function LoginForm(login_url) {
	CenterWindow(login_url, "LoginWindow", 500, 400, 0,0);
}


function join(server_num) {
	CenterWindow("http://sso.kisti.re.kr/agreementForm.do?server_num=" + server_num + "&returnURL=http://www.yeskisti.net/yesKISTI/", "JoinWindow", 817, 500, 1,0);
}


//블로그 만들기
function makeblogWin(userid, name, email, isBlogExist) {
	if (userid == "") {
		alert("로그인이 필요합니다. 로그인 후 다시 시도해 주시기 바랍니다.");
		//LoginForm("/yesKISTI/common/LoginForm.jsp");
		return;
	} else if (isBlogExist != '') {
		alert("회원님의 블로그가 이미 존재합니다.");
		return;
	}
	
	CenterWindow('', 'makeBLOG', 800, 600, 0,0);
	makeblogForm(userid, name, email);
	document.frmMakeBlog.submit();
} 

function makeblogForm(userid, name, email) {
	var  frmValue="";
	if(document.frmMakeBlog==null){
    	frmValue+="<form name='frmMakeBlog' method='POST' action='http://blog.yeskisti.net/blog/bin/install/install_newblog.jsp' target='makeBLOG'>";
    	frmValue+="<input type='hidden' name='sUserID' value='"+userid+"'>";
    	frmValue+="<input type='hidden' name='sUserName' value='"+name+"'>";
		frmValue+="<input type='hidden' name='sEmail' value='"+email+"'>";
    	frmValue+="<input type='hidden' name='fromURL' value='"+encodeURI(document.location)+"'>";
    	frmValue+="</form>";
		document.body.innerHTML += frmValue;
	}
}

// aboutNDSL
function aboutNDSL() {
    //CenterWindow('/jsp/ndsl/html/introNDSL/index.html', 'aboutNDSL', 850, 450, 1, 0);
	window.open( '/jsp/ndsl/html/introNDSL/popup.htm','new','width=950, height=700, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=yes')
}

/** 로그인 폼 */
function valid(frm) {

	window.open("about:blank", "login_form" ,"status,width=10,height=10, scrollbars=0,resizable=0,left=0,top=0,screenX=0,screenY=0,status=no"); 
	frm.target = "login_form";

	frm.returnURL.value = window.location.href;
	if(frm.returnURL.value.indexOf("?")>-1){
		frm.returnURL.value += "&";
	}
	else{
		frm.returnURL.value += "?";
	}
	frm.returnURL.value += "fromURL=sso";

	if(!frm.userid.value){
		alert("[아이디 입력 항목] 잘못 지정된 접근입니다.\n\n관리자에게 문의 하시면 신속히 처리 될 것입니다");
		frm.userid.focus();
		return false; 
	}
	
	if(!frm.passwd.value){
		alert("[비밀번호 입력 항목] 잘못 지정된 접근입니다.\n\n관리자에게 문의 하시면 신속히 처리 될 것입니다");
		frm.passwd.focus();
		return false; 
	}
	
	if(!frm.passwd.value){
		alert("[비밀번호 입력 항목] 잘못 지정된 접근입니다.\n\n관리자에게 문의 하시면 신속히 처리 될 것입니다");
		frm.passwd.focus();
		return false; 
	}
	
	if( !frm.returnURL.value || frm.returnURL.value.indexOf("http://")<0 ){
		alert("[returnURL]이 잘못 지정 및 입력되지 않았거나 \n 'http://www.aaa.org/xxx.jsp'로 시작되는 [FULL URL]이 아닌 잘못된 접근입니다\n\n관리자에게 문의 하시면 신속히 처리 될 것입니다");
		return false; 
	}
	
	return true;
}



/** 회원정보 수정 및 비밀번호 찾기 */
function validUser(arg){
	var frm = document.all.frmUser;

	window.open("about:blank",arg,"status,width=817,height=500, scrollbars=1,resizable=0,left=0,top=0,screenX=0,screenY=0,status=no"); 
	frm.returnURL.value = window.location.href;
	frm.target = arg;

	if(arg == "Agreement"){ //회원가입
		frm.action = "http://sso.kisti.re.kr/agreementForm.do";
	}
	

	if(arg == "PassFind"){ //비밀번호 찾기
		frm.action = "http://sso.kisti.re.kr/idPasswdQueryForm.do";
	}

	if(arg == "Modify"){ //회원정보 변경
		frm.action = "http://sso.kisti.re.kr/userModificationForm.do";
	}
	if(arg == "withdraw"){ //회원탈퇴
		frm.returnURL.value = window.location.href.split("/yesKISTI/")[0] + "/yesKISTI/";	
		frm.action = "http://sso.kisti.re.kr/withdrawForm.do";
	}
	frm.submit();
}


/** 
* 메뉴 접기 
* param @menu_id : 메뉴 아이디
*/
function toggleMenu(menu_id) {
	var obj = eval("document.all.menu_layer_" + menu_id);
	if(obj.style.display == "inline"){
		obj.style.display = "none";
	}
	else{
		obj.style.display = "inline";
	}
}

//태그 제거 함수
function stripHTMLtag(string) { 
   var objStrip = new RegExp(); 
   objStrip = /[<][^>]*[>]/gi; 
   return string.replace(objStrip, ""); 
}

function ViewImage(img, w, h){

	CenterWindow("/KISTI/album/ViewImage.jsp?img=" + img + "&w=" + w + "&h=" + h ,"preview", w, h, 0,0);

}
function ViewImage2(img, w, h, path){	
	CenterWindow(path+"?img=" + img + "&w=" + w + "&h=" + h ,"preview", w, h, 0,0);

}
function CenterWindow(href,WinName,w,h,scroll,resize) { 
	var PosLeft; 
	var PosTop; 

	PosLeft = (window.screen.width/2) - (w/2 + 10); 
	PosTop = (window.screen.height/2) - (h/2 + 50);

//	scroll = 0;

	if(window.screen.width<w+10){
		PosLeft = 0;
		w = window.screen.width - 10;
		scroll = 1;
	}

	if(window.screen.height<h+60){
		PosTop = 0;
		if(window.screen.width>w+10){
			w +=15;
		}

		h = window.screen.height - 60;
		scroll = 1;
	}

	var objWin = window.open(href,WinName,"status,height=" + h + ",width=" + w + ", scrollbars=" + scroll + ",resizable=" + resize + ",left=" + PosLeft + ",top=" + PosTop + ",screenX=" + PosLeft + ",screenY=" + PosTop + ",status=no"); 
	if(objWin == null){
		alert("팝업창이 차단되었습니다.\n\n팝업창 차단 설정을 해제하여주십시요.\n\n팝업창 차단 설정은\n웹페이지 상단에 나타나는 [알림 표시줄]에서 설정이 가능합니다.\n\n또는 [도구 > 인터넷옵션 > 개인정보 > 팝업차단 > 설정]에서\n설정이 가능합니다.");
	}
}

//윈도우 창 리사이즈 
function resizeWin(maxX,maxY,speed,delay,win){
    this.obj = "resizeWin" + (resizeWin.count++);
    eval(this.obj + "=this");
    if (!win)     this.win = self;    else this.win = eval(win);
    if (!maxX)    this.maxX = 400;    else this.maxX = maxX;
    if (!maxY)    this.maxY = 300;    else this.maxY = maxY;
    if (!speed)   this.speed = 1/2;   else this.speed = 1/speed;
    if (!delay)   this.delay = 0;    else this.delay = delay;
    this.doResize = (document.all || document.getElementById);
    this.stayCentered = false;
    
    this.initWin =     function(){
        if (this.doResize){
            this.resizeMe();
        }
        else {
            this.win.resizeTo(this.maxX + 10, this.maxY - 20);
        }
    }

    this.resizeMe = function(){
        this.win.focus();
        this.updateMe();
    }
    
    this.resizeTo = function(x,y){
        this.maxX = x;
        this.maxY = y;
        this.resizeMe();
    }
        
    this.stayCentered = function(){
        this.stayCentered = true;
	}

    this.updateMe = function(){
        this.resizing = true;
        var x = Math.ceil((this.maxX - this.getX()) * this.speed);
        var y = Math.ceil((this.maxY - this.getY()) * this.speed);
        if (x == 0 && this.getX() != this.maxX) {
            if (this.getX() > this.maxX) x = -1;
            else  x = 1;
        }
        if (y == 0 && this.getY() != this.maxY){
            if (this.getY() > this.maxY) y = -1;
            else y = 1;
        }
        if (x == 0 && y == 0) {
            this.resizing = false;
        }
        else {
            this.win.top.resizeBy(parseInt(x),parseInt(y));
            if (this.stayCentered == true) this.win.moveTo((screen.width - this.getX()) / 2,(screen.height - this.getY()) / 2);
            setTimeout(this.obj + '.updateMe()',this.delay)
        }
    }
        
    this.write =  function(text){
        if (document.all && this.win.document.all["coords"]) this.win.document.all["coords"].innerHTML = text;
        else if (document.getElementById && this.win.document.getElementById("coords")) this.win.document.getElementById("coords").innerHTML = text;
    }
        
    this.getX =  function(){
        if (document.all) return (this.win.top.document.body.clientWidth + 10)
        else if (document.getElementById)
            return this.win.top.outerWidth;
        else return this.win.top.outerWidth - 12;
    }
    
    this.getY = function(){
        if (document.all) return (this.win.top.document.body.clientHeight + 29)
        else if (document.getElementById)
            return this.win.top.outerHeight;
        else return this.win.top.outerHeight - 31; 
    }
    
    this.onResize =  function(){
        if (this.doResize){
            if (!this.resizing) this.resizeMe();
        }
    }

    return this;
}
resizeWin.count = 0;
//윈도우 창 리사이즈 



/** 공백문자 없애기 */
String.prototype.trim = function(str) { 
        str = this != window ? this : str; 
        return str.replace(/^\s+/g,'').replace(/\s+$/g,''); 
}


/** 쿠키값을 가져오기 */
function getCookie(name) {
	var nameOfCookie = name + "="; 
	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 "";
} 

//설정한 날짜만큼 쿠키가 유지되게. expiredays가 1 이면 하루동안 유지
function setCookie(name, value, expiredays) {
	var expire_date = new Date();
	expire_date.setDate(expire_date.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; expires=" + expire_date.toGMTString() + "; path=/";
}


//쿠키 소멸 함수
function clearCookie(name) {
	var expire_date = new Date();
	//어제 날짜를 쿠키 소멸 날짜로 설정한다.
	expire_date.setDate(expire_date.getDate() - 1)
	document.cookie = name + "= " + "; expires=" + expire_date.toGMTString() + "; path=/"
}

function createPageForm(link, searchType, searchText) {
	document.write("<form name='frmPageMoveJS' method='POST' action='" + link + "'>");
	document.write("<input type='hidden' name='gotoPage' value=''>");
	document.write("<input type='hidden' name='sType' value='" + searchType + "'>");
	document.write("<input type='hidden' name='sText' value='" + searchText + "'>");
	document.write("</form>");
}

function movePageForm(gotoPage) {
	document.frmPageMoveJS.gotoPage.value = gotoPage;
	document.frmPageMoveJS.submit();
}

function insertPageFormValue(sElement, sValue) {
	if(document.frmPageMoveJS)
	{
		var newINPUT = document.createElement("<INPUT TYPE='hidden' NAME='" + sElement + "'>")
		newINPUT.value = sValue;
		document.frmPageMoveJS.insertBefore(newINPUT);
	}
}


function insertFormInputValue(sFrom, sElement, sValue) {
	if(sFrom)
	{
		var newINPUT = document.createElement("<INPUT TYPE='hidden' NAME='" + sElement + "'>")
		newINPUT.value = sValue;
		sFrom.insertBefore(newINPUT);
	}
}