String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};
function enterSubmit(form){
    if( event.keyCode == "13" ) {
        if(detailValCheck(form)){
            form.submit();
        }else{
            return false;
        }
    }
}
var myStartEffect = function(element) {
    element._opacity = Element.getOpacity(element);
    new Effect.Opacity(element, {duration:1, from:element._opacity, to:1});
    //new Effect.Highlight(element, {});
}
// Run the script on DOM ready:
function selectBoxInit(){
    try{
        //rss portlet
        changejQueryTags('rssKeyword','selectbox203_01','selectbox-wrapper203_01');
        //google portlet
        changejQueryTags('lr','selectbox70_02','selectbox-wrapper70_02',true);
        //wiki portlet
        changejQueryTags('language','selectbox70_01','selectbox-wrapper70_01');
        //selectbox 하단검색들 203_02
        //검색
        //field1
        changejQueryTags('field1','selectbox70_001','selectbox-wrapper70_001',true);
        changejQueryTags('field2','selectbox70_002','selectbox-wrapper70_002',true);
        changejQueryTags('field3','selectbox70_003','selectbox-wrapper70_003',true);
        //op
        changejQueryTags('op1','selectbox89_001','selectbox-wrapper89_001',true);
        changejQueryTags('op2','selectbox89_002','selectbox-wrapper89_002',true);
        /*
        jQuery('#myselectbox203_02').selectbox({
            inputClass:"selectbox203_02",
            containerClass: "selectbox-wrapper203_02"
        });
        */
        //selectbox 하단검색들 70_01
        /*
        jQuery('#myselectbox70_01').selectbox({
            inputClass:"selectbox70_01",
            containerClass: "selectbox-wrapper70_01"
        });
        */
    }catch(ex){alert(ex.message)}
}
function sboxOpen(){
    var forienDBLayer=document.getElementById('forienDBLayer');
    var arrow=document.getElementById("arrow");
    var arrowBtn=document.getElementById("arrowBtn");
    try{
	    if(forienDBLayer.className=="smDBlayeroff clearfix"){
	    	document.getElementById('forienDBLayer').className="smDBlayer clearfix";
	        arrow.setAttribute("src","/search/images/btn_5page_layerbtn06_0705.gif");
	        arrow.src="/search/images/btn_5page_layerbtn06_0705.gif";
	        arrow.setAttribute("alt","닫힘");
	        arrowBtn.setAttribute("src",arrowBtn.getAttribute("src").replace('05','07'));
	        arrowBtn.setAttribute("alt","닫힘");
	        setCookie( 'forienDBLayer', 'on', 1 ) ;
	    }else{
	        document.getElementById('forienDBLayer').className="smDBlayeroff clearfix";
	        arrow.setAttribute("src","/search/images/btn_5page_layerbtn08_0705.gif");
	        arrow.src="/search/images/btn_5page_layerbtn08_0705.gif";
	        arrow.setAttribute("alt","펼침");
	        arrowBtn.setAttribute("src",arrowBtn.getAttribute("src").replace('07','05'));
	        arrowBtn.setAttribute("alt","펼침");
	        setCookie( 'forienDBLayer', 'off', 1 ) ;
	    }
    }catch(e){
    	alert(e.message);
    }
}
function searchTogle(_open,_close){
    var o=document.getElementById(_open);
    var c=document.getElementById(_close);
    o.style.display="block";
    c.style.display="none";
    // 다국어 포커스
    if (_open == "nomal") {
        document.getElementById("lastFocusName").value = "basicQuery";
    } else if (_open == "detail") {
        document.getElementById("lastFocusName").value = "keyword1";
    }
    // 상세검색 검색연산자 css 재조정
    jQuery('#opDiv1').removeClass('sc2');
    jQuery('#opDiv1').addClass('sc2');
    jQuery('#opDiv2').removeClass('sc2');
    jQuery('#opDiv2').addClass('sc2');
}
var submitFlag="Y";
function mainValCheck(form){
	if(submitFlag=='Y'){
		if(trim(form.query.value)==''){
	        alert('키워드를 입력하세요');
	        return false;
	    }
	    form.query.value=CharacterCheck(form.query.value);
	    if(trim(form.query.value)=='') {
	        alert("검색어에 특수문자( ? * , )는 입력할 수 없습니다.");
	        return false;
	    }
	    if(trim(CharacterCheck2(form.query.value))=='') {
	    	alert("검색어가 알파벳(a~z an at and by for from in is it its on or the with)만으로 이루어져 있습니다. \n다른 검색어를 입력하십시오. ");
	    	form.query.focus();
	        return false;
	    }
	    try{
	        document.getElementById("autoDiv").style.display = "none";
	    } catch(errorObj){}
	    submitFlag='N';
	    return true;
	}else{
		return false;
	}
}
function detailValCheck(form){
	if(submitFlag=='Y'){
	    if(form.keyword1.value=='' &&
	            form.keyword2.value=='' &&
	            form.keyword3.value==''){
	        alert('검색어를 입력해 주세요.');
	        return false;
	    }
	    if(form.keyword1.value !=""){
	    	form.keyword1.value=CharacterCheck(form.keyword1.value);
	        if(trim(form.keyword1.value)=='') {
	            alert("검색어에 특수문자( ? * , )는 입력할 수 없습니다.");
	            return false;
	        }
	        if(trim(CharacterCheck2(form.keyword1.value)) == "") {
	            alert("검색어가 알파벳(a~z an at and by for from in is it its on or the with)만으로 이루어져 있습니다. \n다른 검색어를 입력하십시오. ");
	            form.keyword1.focus();
	            return false;
	        }
	    }
	    if(form.keyword2.value !=""){
	    	form.keyword2.value=CharacterCheck(form.keyword2.value);
	        if(trim(form.keyword2.value)=='') {
	            alert("검색어에 특수문자( ? * , )는 입력할 수 없습니다.");
	            return false;
	        }
	        if(trim(CharacterCheck2(form.keyword2.value)) == "") {
	            alert("검색어가 알파벳(a~z an at and by for from in is it its on or the with)만으로 이루어져 있습니다. \n다른 검색어를 입력하십시오. ");
	            form.keyword2.focus();
	            return false;
	        }
	    }
	    if(form.keyword3.value !=""){
	    	form.keyword3.value=CharacterCheck(form.keyword3.value);
	        if(trim(form.keyword3.value)=='') {
	            alert("검색어에 특수문자( ? * , )는 입력할 수 없습니다.");
	            return false;
	        }
	        if(trim(CharacterCheck2(form.keyword3.value)) == "") {
	            alert("검색어가 알파벳(a~z an at and by for from in is it its on or the with)만으로 이루어져 있습니다. \n다른 검색어를 입력하십시오. ");
	            form.keyword3.focus();
	            return false;
	        }
	    }
	    return true;
	}else{
		return false;
	}
}
function inFocus(obj){
    var o=document.getElementById(obj);
    jQuery(o).css({
        borderBottom : '#616161 3px solid',
        borderLeft : '#616161 3px solid',
        borderTop : '#616161 3px solid',
        borderRight : '#616161 3px solid'
    });
}
function outFocus(obj){
    var o=document.getElementById(obj);
    jQuery(o).css({
        borderBottom : '#d8d8d8 3px solid',
        borderLeft : '#d8d8d8 3px solid',
        borderTop : '#d8d8d8 3px solid',
        borderRight : '#d8d8d8 3px solid'
    });
    // 다국어 팝업 포커스
    if (obj == "sc1") {
        document.getElementById("lastFocusName").value = "keyword1";
    } else if (obj == "sc2") {
        document.getElementById("lastFocusName").value = "keyword2";
    } else if (obj == "sc3") {
        document.getElementById("lastFocusName").value = "keyword3";
    }
}
//키워드 전방일치 전환
function changeSeachOption(val){
    if(val=='0'){
        document.getElementById('sch1').style.display="block";
        document.getElementById('sch2').style.display="block";
        document.getElementById('kemChecbox').style.display="block";
        var options=jQuery('#myselectbox70_003 > option');
        for(var i=0;i<options.length;i++)
            jQuery(options[i]).remove();
        var option1=document.createElement("option");//전체(znAll)
        var option2=document.createElement("option");//제목(znTitle)
        var option3=document.createElement("option");//저자명(znCreator)
        var option4=document.createElement("option");//발행처(znPublisher)
        var option5=document.createElement("option");//초록(znAbstract)
        var option6=document.createElement("option");//목차(znKtoc)
        option1.setAttribute("value","znAll");
        option2.setAttribute("value","znTitle");
        option3.setAttribute("value","znCreator");
        option4.setAttribute("value","znPublisher");
        option5.setAttribute("value","znAbstract");
        option6.setAttribute("value","znKtoc");
        option1.appendChild(document.createTextNode("전체"));
        option2.appendChild(document.createTextNode("제목"));
        option3.appendChild(document.createTextNode("저자명"));
        option4.appendChild(document.createTextNode("발행처"));
        option5.appendChild(document.createTextNode("초록"));
        option6.appendChild(document.createTextNode("목차"));
        var select=document.getElementById('myselectbox70_003');
        select.appendChild(option1);
        select.appendChild(option2);
        select.appendChild(option3);
        select.appendChild(option4);
        select.appendChild(option5);
        select.appendChild(option6);
        jQuery('#myselectbox70_003_container').remove();
        jQuery('#myselectbox70_003_input').remove();
        changejQueryTags('field3','selectbox70_003','selectbox-wrapper70_003',true);
    }else if(val=='2'){
    	document.getElementById('sch1').style.display="none";
        document.getElementById('sch2').style.display="none";
        document.getElementById('kemChecbox').style.display="block";
        var options=jQuery('#myselectbox70_003 > option');
        for(var i=0;i<options.length;i++)
            jQuery(options[i]).remove();
        var option1=document.createElement("option");//전체(znAll)
        var option2=document.createElement("option");//제목(znTitle)
        var option3=document.createElement("option");//저자명(znCreator)
        var option4=document.createElement("option");//발행처(znPublisher)
        var option5=document.createElement("option");//초록(znAbstract)
        var option6=document.createElement("option");//목차(znKtoc)
        option1.setAttribute("value","znAll");
        option2.setAttribute("value","znTitle");
        option3.setAttribute("value","znCreator");
        option4.setAttribute("value","znPublisher");
        option5.setAttribute("value","znAbstract");
        option6.setAttribute("value","znKtoc");
        option1.appendChild(document.createTextNode("전체"));
        option2.appendChild(document.createTextNode("제목"));
        option3.appendChild(document.createTextNode("저자명"));
        option4.appendChild(document.createTextNode("발행처"));
        option5.appendChild(document.createTextNode("초록"));
        option6.appendChild(document.createTextNode("목차"));
        var select=document.getElementById('myselectbox70_003');
        select.appendChild(option1);
        select.appendChild(option2);
        select.appendChild(option3);
        select.appendChild(option4);
        select.appendChild(option5);
        select.appendChild(option6);
        jQuery('#myselectbox70_003_container').remove();
        jQuery('#myselectbox70_003_input').remove();
        changejQueryTags('field3','selectbox70_003','selectbox-wrapper70_003',true);
    }else if(val=='1'){
        document.getElementById('sch1').style.display="none";
        document.getElementById('sch2').style.display="none";
        document.getElementById('kemChecbox').style.display="none";
        var options=jQuery('#myselectbox70_003 > option');
        for(var i=0;i<options.length;i++)
            jQuery(options[i]).remove();
        var option1=document.createElement("option");//논문명
        var option2=document.createElement("option");//저자
        var option3=document.createElement("option");//수여대학
        var option4=document.createElement("option");//발행처
        var option5=document.createElement("option");//ISBN
        option1.setAttribute("value","title_sort");
        option2.setAttribute("value","creator_sort");
        option3.setAttribute("value","publisher_sort");
        option4.setAttribute("value","publisher_sort");
        option5.setAttribute("value","srch_isbn");
        option1.appendChild(document.createTextNode("논문명"));
        option2.appendChild(document.createTextNode("저자"));
        option3.appendChild(document.createTextNode("수여대학"));
        option4.appendChild(document.createTextNode("발행처"));
        option5.appendChild(document.createTextNode("ISBN"));
        var select=document.getElementById('myselectbox70_003');
        select.appendChild(option1);
        select.appendChild(option2);
        select.appendChild(option3);
        select.appendChild(option4);
        select.appendChild(option5);
        jQuery('#myselectbox70_003_container').remove();
        jQuery('#myselectbox70_003_input').remove();
        changejQueryTags('field3','selectbox70_003','selectbox-wrapper70_003',true);
    }
}
function notice_setCookie( name, value, expiredays ) {
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";";
}
function notice_closeWin(){
    if ( document.f1.notice.checked )
            notice_setCookie( "pop_alert", "done" , 1); // 1=하룻동안 공지창 열지 않음
    ModalPopup.close();
}
function notice_open(name,url,popupName,width,height,left,top){
    if (getCookie(name) != "done" ) {
    	//팝업사이즈 : 612*654 + foot_height 27px -->
    	var opt="";
    	if(typeof left=='undefined' && typeof top=='undefined')
    		opt=setCenterReport(width,height);
    	else
    		opt="left="+left+",top="+top+",width="+width+",height="+height;
    	window.open(url, popupName, opt+",status=no,menubar=no,resizable=yes,scrollbars=yes");
    }
}
function openLayer(){
    jQuery.ajax({
        type: "POST",
        url: "/AlertNote.do",
        success : function(html){
                    ModalPopup.open(html, true, {backGround: '#777777'});
                },
        error: function(result){
                    alert("조회시 일시적인 문제가 발생하였습니다.\n다시 시도해 주세요.");
                }
    });
}
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 "";
}
