﻿// 쿠키 받기 함수
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 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;
}

//연락처검사
function checkcontactddd(strvalue)
{
	var str = /02$|031|032|033|041|042|043|051|052|053|054|055|061|062|063|064|070|010|011|012|015|016|017|018|019/;
	if(!str.test(strvalue))
		return true;
	return false;
}

//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 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);
}

//IE6 PNG 이미지 투명처리 함수
function setPng24(obj)
{ 
    obj.width=obj.height=1; 
    obj.className=obj.className.replace(/\bpng24\b/i,''); 
    obj.style.filter = 
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');" 
    obj.src='';  
    return ''; 
}

//자바스크립트 UTF-8 인코딩 - 한글깨짐 방지 
function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (0xf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    } 
    return s0;
} 

//다음칸으로 이동
function move_next(obj, nextobjname, len)
{ 
    if(obj.value.length == len) 
    { 
        var nextobj = document.getElementById(nextobjname);
        nextobj.focus();
    } 
}

// 부평 둘러보기
function sendlookaround()
{
    sendopen("http://bpl.go.kr:9000/bupyeong/bp_info8.php?floor=1&img1=info8_pic1-1.gif&menu=A","lookaround",720,452,"no","no",false);
}

// 영문홈페이지
function sendenglish()
{
    sendopen("/english/about/greeting.asp","chinese",1221,800,"no","yes",false);
}

// 중문홈페이지
function sendchinese()
{
    sendopen("/chinese.html","chinese",655,600,"no","yes",false);
}

// 디지털자료실 좌석 관리 보기
function senddigitalroom()
{
    sendopen("http://211.251.221.75:7700/","digitalroom",1024,768,"yes","yes",false);
}

// 열람실 좌석현황 보기
function sendreadingroom()
{
    sendopen("http://www.bpl.go.kr:8080/index.asp","readingroom",1024,768,"yes","yes",false);
}

//인천지역정보 보기
function sendincheonarea()
{
    window.open("http://incheon.go.kr/inpia/servlet/html?pgm_id=INPIA000221","incheonarea");
}

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);
}
