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 createLoginReturnForm(rturl) {
	var setrturl = "";
	if(rturl==null || rturl=='') {
		setrturl = location.href;
	} else {
		setrturl = rturl;
	}

	document.write("<form name='frmMoveLogin' method='POST' action='/yesKISTI/common/LoginPage.jsp'>");
	document.write("<input type='hidden' name='setrturl' value='" + setrturl + "'>");
	document.write("<input type='hidden' name='runScript' value=''>");
	document.write("<table border='0' style='display:none' id='loginValueTable'><tr><td></td></tr></table>");
	document.write("</form>");
}

function addLoginFormObject(ofrm) {
	if(ofrm) {
		if(!document.frmMoveLogin) {
			createLoginReturnForm(location.href);
		}
		if(loginValueTable) {
			for(var i=0; i<ofrm.length; i++) {
				if(ofrm.elements[i]) {
					addLoginFormValue(ofrm.elements[i].name, ofrm.elements[i].value);
				}
			}
		}
	}
}

function addLoginFormValue(elemName, elemValue) {
	if(loginValueTable && elemName && elemName!="") {
		var oInput = eval('document.frmMoveLogin.' +  elemName);
		if(!oInput) {
			var oRow = loginValueTable.insertRow();
			var oCell= oRow.insertCell();
			oCell.innerHTML = "<input type='hidden' name='" + elemName + "'>";
			oInput = eval('document.frmMoveLogin.' +  elemName);
		}
		if(oInput) {
			oInput.value = elemValue;
		}
	}
}

function goLoginPage(rturl) {
	if(frmMoveLogin) {
		if(rturl!='undefined' && rturl!=null) {
			frmMoveLogin.setrturl.value = rturl;
		}
		frmMoveLogin.submit();
	} else {
		document.href = '/yesKISTI/common/LoginPage.jsp';
	}
}

function goLoginPageAndRun(runScript, rturl) {
	if(frmMoveLogin) {
		frmMoveLogin.setrturl.value = rturl;
		frmMoveLogin.runScript.value = runScript;
		frmMoveLogin.submit();
	} else {
		document.href = '/yesKISTI/common/LoginPage.jsp';
	}
}

function LoginForm(login_url) {
	var runScript = "";

	var args = LoginForm.arguments;
	if(args[1]) {	// run script가 넘어올경우
		runScript = args[1];
	}

	if(runScript!="") {
		goLoginPageAndRun(runScript,'');
	} else {
		goLoginPage();
	}
}


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, 700, 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;
	}
}


//블로그가 없을 때..팝업
function BlogPopup(userid, name, email) {
	if(confirm("회원님의 블로그가 존재하지 않습니다.\n 지금 새로운 블로그를 만드시겠습니까?")){
		makeblogWin(userid, name, email, '');
	}	//CenterWindow('/yesKISTI/common/Blog.jsp', 'BlogWindow', 480, 280, 0, 0);
} 

//개별 블로그 방문
function openblogWin(postBlogID) {
    window.open('http://blog.yeskisti.net/blog/bin/blog/index.jsp?postBlogID='+postBlogID, 'blogWin', 'scrollbars=yes, status=yes,toolbar=yes,resizable=yes,location=yes,menu=yes, width=1024,height=768,left=50,top=50');

}


/*
   - sBlogID : 블로그 아이디, 현재는 사용자 아이디와 동일하다고 가정합니다.
   - sUserID : 사용자 아이디 ( 기타 sUserNIC, sUserName - 현재 사용하지 않습니다. )
   - sTitle : 포스트 제목
   - sContent : 포스트 내용 ( 현재 TEXT만 전달받는 것으로 가정합니다. HTML 사용은 추후 협의 )
   - sSourceURI : 원본 출처 URI ( http://로 시작하도록 지정 )
*/ 	
function getBlog(){
	var right= "\r\n\r\n\r\nCopyright⒞2006 KISTI All right reserved. 모든 저작권은 한국과학기술정보연구원에 있습니다.";

	if (document.all.div_textual) {
		document.all.sContent.value = document.all.div_textual.innerText+right;
	} else if (document.all.blogContent) {
		document.all.sContent.value = document.all.blogContent.innerText+right;
	} else if (document.all.span_abstract) {
		document.all.sContent.value = document.all.span_abstract.innerText+right;
	}

	blogFrm.target = "my_blog_scrap";
	blogFrm.action = "http://blog.yeskisti.net/blog/bin/post/post/popup_scrap_community.jsp";
	CenterWindow('', 'my_blog_scrap', 449,356,0,0);
	blogFrm.submit();
}


//포스트 보기
function viewpostWin(nPostIndex, postBlogID) {
	window.open('http://blog.yeskisti.net/blog/bin/blog/index.jsp?sCmd=post_view&postIndex='+nPostIndex+'&nPage=1', 'blogWin', "scrollbars=yes, status=yes,toolbar=yes,resizable=yes,location=yes,menu=yes, width=1024,height=768,left=50,top=50");
} 

//커뮤니티 만들기
function makecomWin(contextURL) {
    CenterWindow(contextURL+'/make', 'community_make', 800, 617, 1, 0);

} 

//커뮤니티 방문
function opencomWin(href) {
    var comwin = window.open(href, "comWin", "scrollbars=yes,status=yes,toolbar=yes,resizable=yes,location=yes,menu=yes, width=1024, height=768,left=50,top=50");
}

function goCommunity(contextURL, domain){
	if (domain) {
		window.open(contextURL + '/index.jsp?domain='+domain, 'new', 'scrollbars=yes,status=yes,toolbar=yes,resizable=yes,location=yes,menu=yes, width=1150, height=790,left=50,top=50');
	} 
	//if (document.all.my_community.value =='0')
	document.all.my_community.options[0].selected=true;
	
}
											 
//커뮤니티 게시글 보기
function viewbbsWin(href) {
    var comwin = window.open(href, "comWin", "scrollbars=yes,status=yes,toolbar=yes,resizable=yes,location=yes,menu=yes, width=1150, height=790,left=50,top=50" );
} 

/** 로그인 폼 */
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, meid) {
	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("<input type='hidden' name='meid' value=''>");
	document.write("</form>");
}

function movePageForm(gotoPage,meid) {
	document.frmPageMoveJS.gotoPage.value = gotoPage;
	document.frmPageMoveJS.meid.value = meid;
	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 moveMore(sClass, sSeq){

	opener.location.href ="/View.do?type=1&class="+sClass+"&seq="+sSeq;
	self.close();
}