﻿// 쿠키 받기 함수
function getCookie(strname)
{
	var nameOfCookie = strname + "=";
	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 setCookie(name, value, expire)
{
	var tDate = new Date();
	tDate.setDate(tDate.getDate() + expire);
	document.cookie = name + "=" + escape(value) + ";path=/;expires="+tDate.toGMTString()+";"
}

// 포커스된 입력박스 색표시
function sendfocuscolor(objname)
{
	objname.style.backgroundColor = "#F5F5F5";
}

// 블러된 입력박스 색표시
function sendblurcolor(objname)
{
	objname.style.backgroundColor = "#FFFFFF";
}

//목록 포커스 색표시
function sendlistfocuscolor(objname)
{
	objname.style.background = "#F5F5F5";
}

//목록 블러 색 표시
function sendlistblurcolor(objname)
{
	objname.style.background = "#FFFFFF";
}

//한글입력검사
function checkkorean(strvalue)
{
	var i = 0;
	var str = /[가-히]/;
	while(i < strvalue.length)
	{
		if(!str.test(strvalue.charAt(i)))
			return true;
		i++;
	}
	return false;
}

//아이디검사
function checkid(strvalue)
{
	var str = /[A-Za-z0-9_]/;
	var i = 0
	while(i < strvalue.length)
	{
		if(!str.test(strvalue.charAt(i)))
		{
			return true;
			break;
		}
		i++;
	}
	if(strvalue.length < 6)
		return true;
	return false;
}

//로그인 아이디 및 비밀번호 검사
function checklogin(strvalue)
{
	var str = /[\S]/;
	var i = 0
	while(i < strvalue.length)
	{
		if(!str.test(strvalue.charAt(i)))
		{
			return true;
			break;
		}
		i++;
	}
	return false;
}

//영문이름검사
function checkenglish(strvalue)
{
	var str = /[A-Za-z]/;
	var i = 0
	while(i < strvalue.length)
	{
		if(!str.test(strvalue.charAt(i)))
		{
			return true;
			break;
		}
		i++;
	}
	return false;
}

// 비밀번호 검사 (영문대소문자, 숫자 혼합)
function checkpwd(strvalue)
{
	var alphacnt = 0;
	var digitcnt = 0;
	var i = 0;
	var str = /[A-Za-z]/;
	var str1 = /[0-9]/;
	while(i < strvalue.length)
	{
		if(str.test(strvalue.charAt(i)))
			alphacnt++;
		if(str1.test(strvalue.charAt(i)))
			digitcnt++;
		i++;
	}
	if(alphacnt > 0 && digitcnt > 0 && (alphacnt + digitcnt == strvalue.length))
		return false;
	else
		return true;
	if(strvalue.length < 6)
		return true;
	return false;
}

// 비회원 비밀번호 검사 (영문대소문자, 숫자 혼합)
function checknonpwd(strvalue)
{
	var alphacnt = 0;
	var digitcnt = 0;
	var i = 0;
	var str = /[A-Za-z]/;
	var str1 = /[0-9]/;
	while(i < strvalue.length)
	{
		if(str.test(strvalue.charAt(i)))
			alphacnt++;
		if(str1.test(strvalue.charAt(i)))
			digitcnt++;
		i++;
	}
	if(alphacnt > 0 && digitcnt > 0 && (alphacnt + digitcnt == strvalue.length))
		return false;
	else
		return true;
	if(strvalue.length < 6)
		return true;
	return false;
}

//주민등록번호검사
function checkresidentno(strvalue)
{
	var str = /\d{6}[1-4]\d{6}/;
	if(str.test(strvalue))
	{
		var check = new Array(13);
		var key = new Array(2,3,4,5,6,7,8,9,2,3,4,5);
		var sum = 0;
		for(var i=0; i<13; i++)
			check[i] = parseInt(strvalue.charAt(i),10);
		for(var i=0; i<12; i++)
			sum += check[i] * key[i];
		var rs = (11-(sum%11)) % 10
		if(rs != check[12])
			return true;
		return false;
	}
	return true;
}

//공백입력검사
function checkspace(strvalue)
{
	var str = /[ \n\r]/;
	var i = 0;
	var count = 0;
	while(i < strvalue.length)
	{
		if(str.test(strvalue.charAt(i)))
			count++;
		i++;
	}
	if(count == strvalue.length)
		return true;
	else
		return false;
}

//숫자입력검사
function checkdigit(strvalue, size)
{
	var str = /[0-9]/;
	for(var i=0; i<strvalue.length; i++)
	{
		if(!str.test(strvalue.charAt(i)))
			return true;
	}
	if(strvalue.length < size)
		return true;
	return false;
}

//숫자입력검사
function checkdigit1(strvalue)
{
	var str = /[0-9]/;
	for(var i=0; i<strvalue.length; i++)
	{
		if(!str.test(strvalue.charAt(i)))
			return true;
	}
	return false;
}

//메일주소검사
function checkmail(strvalue)
{
	var str = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if(!str.test(strvalue))
		return true;
	return false;
}

//전화번호검사
function checkphoneddd(strvalue)
{
	var str = /02|031|032|033|041|042|043|051|052|053|054|055|061|062|063|064/;
	if(str.test(strvalue))
		return false;
	else
		return true;
}

//핸드폰검사
function checkmobileddd(strvalue)
{
	var str = /010|011|012|015|016|017|018|019/;
	if(str.test(strvalue))
		return false;
	else
		return true;
}

//URL 검사
function checkurl(strvalue)
{
	var str = /http:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/;
	if(str.test(strvalue))
		return false;
	else
		return true;
}

//이미지 파일 검사
function checkimage(strvalue)
{
	var str = /gif|jpg|jpeg|png/;
	if(strvalue.lastIndexOf(".") > -1)
	{
		strvalue = strvalue.substr(strvalue.lastIndexOf(".") + 1,strvalue.length - strvalue.lastIndexOf(".") - 1).toLowerCase();
		if(str.test(strvalue))
			return false;
		else
			return true;
	}
	else
		return true;
}

//통화자리수표시 함수
function checkcurrency(intvalue)
{
	var strvalue = intvalue.toString();
	var commalocation = strvalue.length % 3;
	if(commalocation > 0)
	{
		var returnvalue = strvalue.substring(0,commalocation);
		if(strvalue.length > 3)
			returnvalue += ",";
	}
	else
		returnvalue = "";
	for(var i=commalocation; i < strvalue.length; i+=3)
	{
		returnvalue += strvalue.substring(i, i+3);
		if(i < strvalue.length - 3)
			returnvalue += ",";
	}
	return returnvalue;
}

//글자 길이 검사 함수
function checklength(value, length)
{
    var i=0;
    var cnt = 0;
    while(i < value.length)
    {
	    if (escape(value.charAt(i)).length > 4)
		    cnt += 2;
	    else if (value.charAt(i) != '\r')
		    cnt++;
	    if(cnt > length)
		    return true;
	    i++;
    }
    return false;
}

//팝업창 닫기 함수
function sendclose()
{
	window.close(this);
}

//인수 있는 팝업창 닫기 함수
function sendpopupclose(strname,strdays)
{ 
    setCookie( strname, "done" , strdays); // 1=하룻동안 공지창 열지 않음
    window.close();
}

//뒤로 이동 함수
function sendback()
{
	window.history.back();
}

//취소 함수
function sendcancel(strmsg, strlocation)
{
	if(confirm(strmsg))
		window.location.href = strlocation;
}

// 엔터키를 받아 실행하는 함수
function sendkeypress(value)
{
    if(window.event.keyCode == 13)
    {
        var objbtn = document.getElementById(value);
        objbtn.click();
    }
}

//팝업창 오픈 함수 - 가운데 정렬
function sendopen(strurl, strid, intwidth, intheight, strresizable, strscrollbars, boolreplace)
{
	var top = window.screen.availHeight / 2 - intheight / 2;
	var left = window.screen.availWidth / 2 - intwidth / 2;
	var objwin = window.open(strurl,strid,"top=" + top + ",left=" + left + ",width=" + intwidth + ",height=" + intheight + ",location=no,menubar=no,resizable=" + strresizable + ",scrollbars=" + strscrollbars + ",status=no,titlebar=no,toolbar=no",boolreplace);
	objwin.focus();
}

//팝업창 오픈 함수 - 왼쪽 정렬
function sendpopupopen(strurl, strid, intleft, inttop, intwidth, intheight, strresizable, strscrollbars, boolreplace)
{
	var objwin = window.open(strurl,strid,"top=" + inttop + ",left=" + intleft + ",width=" + intwidth + ",height=" + intheight + ",location=no,menubar=no,resizable=" + strresizable + ",scrollbars=" + strscrollbars + ",status=no,titlebar=no,toolbar=no",boolreplace);
}

//팝업창 값전달 오픈 함수 - 왼쪽 정렬
function sendreturnpopupopen(strurl, strid, intleft, inttop, intwidth, intheight, strresizable, strscrollbars, boolreplace)
{
	var objwin = window.open(strurl,strid,"top=" + inttop + ",left=" + intleft + ",width=" + intwidth + ",height=" + intheight + ",location=no,menubar=no,resizable=" + strresizable + ",scrollbars=" + strscrollbars + ",status=no,titlebar=no,toolbar=no",boolreplace);
	return objwin
}

//팝업창 오픈 함수 - 전체화면 가운데 정렬
function sendopenfull(strurl, strid, strresizable, strscrollbars, boolreplace)
{
	var intheight = window.screen.availHeight - 30;
	var intwidth = window.screen.availWidth - 10;
	var objwin = window.open(strurl,strid,"top=0,left=0,width=" + intwidth + ",height=" + intheight + ",location=no,menubar=no,resizable=" + strresizable + ",scrollbars=" + strscrollbars + ",status=no,titlebar=no,toolbar=no",boolreplace);
	objwin.focus();
}

//드림위버 자동 생성 스크립트
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//메뉴 링크 스크립트
function goPage(value)
{
    switch(value)
    {
        case 0:
            window.open("/index.aspx");
            break;
        //도서관안내
        case 1:
        case 11:
            window.location.href = "/about/index.aspx";
            break;
        case 12:
            window.location.href = "/about/usetime.aspx";
            break;
        case 13:
            window.location.href = "/about/room_humansocietyscience.aspx";
            break;
        case 14:
            window.location.href = "/about/map.aspx";
            break;
        //자료검색
        case 2:
        case 21:
            window.location.href = "/search/index.aspx";
            break;
        case 22:
            window.location.href = "/search/topic_browsing.aspx";
            break;
        case 23:
            window.location.href = "/search/new_data.aspx";
            break;
        case 24:
            window.location.href = "/search/web_data.aspx";
            break;
        case 25:
            window.location.href = "/search/publication.aspx";
            break;
        case 26:
            window.location.href = "/search/nonbook.aspx";
            break;
        case 27:
            window.location.href = "/search/oldbook.aspx";
            break;
        case 28:
            window.location.href = "/search/lend_best.aspx";
            break;
        //도서관서비스
        case 3:
        case 31:
            window.location.href = "/library/index.aspx";
            break;
        case 32:
            window.location.href = "/library/hope_data.aspx";
            break;
        case 33:
            window.location.href = "/library/night_lend.aspx";
            break;
        case 34:
            window.location.href = "/library/delivery.aspx";
            break;
        case 35:
            window.location.href = "/library/interlibraryloan.aspx";
            break;
        case 36:
            window.location.href = "/library/classic_music.aspx";
            break;
        //독서.문화정보
        case 4:
        case 41:
            window.location.href = "/culture/index.aspx";
            break;
        case 42:
            window.location.href = "/culture/good_book.aspx";
            break;
        case 43:
            window.location.href = "/culture/recommand_book.aspx";
            break;
        case 44:
            window.location.href = "/culture/this_month.aspx";
            break;
        case 45:
            window.location.href = "/culture/namsan_culture.aspx";
            break;
        case 46:
            window.location.href = "/culture/online_information.aspx";
            break;
        //평생교육
        case 5:
        case 51:
            window.location.href = "/lifelong/index.aspx";
            break;
        case 52:
            window.location.href = "/lifelong/schedule_event.aspx";
            break;
        case 53:
            window.location.href = "/lifelong/education.aspx";
            break;
        case 54:
            window.location.href = "/lifelong/audio_visual.aspx";
            break;
        case 55:
            window.location.href = "/lifelong/schedule_exhibit.aspx";
            break;
        case 56:
            window.location.href = "/lifelong/readingschool_vacation.aspx";
            break;
        //학교도서관지원
        case 6:
        case 61:
            window.location.href = "/school/index.aspx";
            break;
        case 62:
            window.location.href = "/school/support_application.aspx";
            break;
        case 63:
            window.location.href = "/school/visit_reading_education.aspx";
            break;
        case 64:
            window.location.href = "/school/refer_infomation.aspx";
            break;
        //이용자마당
        case 7:
        case 71:
            window.location.href = "/user/index.aspx";
            break;
        case 72:
            window.location.href = "/user/newdata.aspx";
            break;
        case 73:
            window.location.href = "/user/free.aspx";
            break;
        case 74:
            window.location.href = "/user/serve.aspx";
            break;
        case 75:
            window.location.href = "/user/knowledge.aspx";
            break;
        case 76:
            window.location.href = "/user/offcialactionprinciple.aspx";
            break;
        case 77:
            window.location.href = "/user/volunteer_schedule.aspx";
            break;
        case 78:
            window.location.href = "/user/club.aspx";
            break;
        case 79:
            window.location.href = "/user/onebook_impression.aspx";
            break;
        case "7A":
            window.location.href = "/user/survey.aspx";
            break;
        case "7B":
            window.location.href = "/user/faq.aspx";
            break;
    }
}

function sendbanner(value)
{
    switch(value)
    {
        case 1:
            window.open("http://www.knowledge.go.kr/main.jsp");
            break;
        case 2:
            window.open("http://210.117.214.245/libmeta/index.html");
            break;
        case 3:
            window.open("http://kiss.kstudy.com/");
            break;
        case 4:
            window.open("http://namsan.naxosmusiclibrary.com/homepage.asp");
            break;
        case 5:
            window.location.href = "/lifelong/audio_visual.aspx";
            break;
        case 6:
            sendopen("/about/userguide.aspx","userguide",775,650,"no","no",false);
            break;
    }
}


function sendblind()
{ 
    var objwin = window.open("/blind/index.aspx");
    objwin.focus();
}

function sendenglish()
{
    var objwin = window.open("/english/index.aspx");
    objwin.focus();
}

function sendchinese()
{
    var objwin = window.open("/chinese/index.aspx");
    objwin.focus();
}

function sendjapanese()
{
    var objwin = window.open("/japanese/index.aspx");
    objwin.focus();
}

function sendroominfo()
{
    sendopen("/about/roominfo.aspx","roominfo",870,580,"no","no",false);
}

function sendiframe(value)
{
    var innerBody = value.contentWindow.document.body;
    oldEvent = innerBody.onclick;
    innerBody.onclick = function(){ sendiframe(value, 1);oldEvent; };
    var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
    value.style.height = innerHeight;
    var innerWidth = innerBody.scrollWidth + (innerBody.offsetWidth - innerBody.clientWidth);
    value.style.width = innerWidth;
    if(!arguments[1])
        this.scrollTo(1,1);
}


function fc_view2(obj)
{
    var temp;
    temp = document.getElementById("view_div").value;
    
    document.getElementById("div_" + temp).style.display = "none";
    document.getElementById("div_" + obj).style.display = "";
    document.getElementById("view_div").value = obj;

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//우클릭 차단
//document.oncontextmenu=function() {return false};   

