function handlerNum(obj) {
 //숫자만 입력 받게끔 하는 함수.
  e = window.event; //윈도우의 event를 잡는것입니다.
  //입력 허용 키
  if( ( e.keyCode >=  48 && e.keyCode <=  57 ) ||   //숫자열 0 ~ 9 : 48 ~ 57
      ( e.keyCode >=  96 && e.keyCode <= 105 ) ||   //키패드 0 ~ 9 : 96 ~ 105
        e.keyCode ==   8 ||    //BackSpace
        e.keyCode ==  46 ||    //Delete
        //e.keyCode == 110 ||    //소수점(.) : 문자키배열
        //e.keyCode == 190 ||    //소수점(.) : 키패드
        e.keyCode ==  37 ||    //좌 화살표
        e.keyCode ==  39 ||    //우 화살표
        e.keyCode ==  35 ||    //End 키
        e.keyCode ==  36 ||    //Home 키
        e.keyCode ==   9       //Tab 키
    ) {
  
    if(e.keyCode == 48 || e.keyCode == 96) { //0을 눌렀을경우
//      if ( obj.value == "" || obj.value == '0' ) //아무것도 없거나 현재 값이 0일 경우에서 0을 눌렀을경우
//        e.returnValue=false; //-->입력되지않는다.
//      else //다른숫자뒤에오는 0은
        return; //-->입력시킨다.
	} 
	else //0이 아닌숫자
      return; //-->입력시킨다.
    }
    else //숫자가 아니면 넣을수 없다.
 {
  //alert('숫자만 입력가능합니다');
  e.returnValue=false;
 }
}


/*========================================================================================
	주민등록번호 체크함수

	jumin1 : input object
	jumin2 : input object
==========================================================================================*/

function confirmJumin(jumin1, jumin2) {				// 주민등록번호 check
	var tmp = 0
	var yy = jumin1.value.substring(0,2)
	var mm = jumin1.value.substring(2,4)
	var dd = jumin1.value.substring(4,6)
	var sex = jumin2.value.substring(0,1)
	var j1 = jumin1
	var j2 = jumin2

	if ((j1.value.length != 6 ) || ( mm < 1 || mm > 12 || dd < 1) ) return false;
	if ((sex != 1 && sex !=2 && sex !=3 && sex !=4)|| (j2.value.length != 7 )) return false;

	for (var i = 0; i <=5 ; i++) {
		tmp = tmp + ((i%8+2) * parseInt(j1.value.substring(i,i+1)))
	}

	for (var i = 6; i <=11 ; i++) {
		tmp = tmp + ((i%8+2) * parseInt(j2.value.substring(i-6,i-5)))
	}

	tmp = 11 - (tmp %11);
	tmp = tmp % 10;

	if (tmp != j2.value.substring(6,7)) return false;
	return true;
}

// 숫자 3자리 콤마
function currency(obj) {
	var str = obj.value.replace(/,/g, "");
	len = str.length;
	str1 = "";

	for( i=1; i <= len; i++ ) {
		str1 = str.charAt(len-i) + str1;
		if( ( i%3 == 0 ) && ( len-i != 0 ) ) str1 = "," + str1;
	}
	obj.value = str1;
}

function currency0(val) {
	var str = val.toString();
	len = str.length;
	str1 = "";

	for( i=1; i <= len; i++ ) {
		str1 = str.charAt(len-i) + str1;
		if( ( i%3 == 0 ) && ( len-i != 0 ) ) str1 = "," + str1;
	}
	return str1;
}

function currencyj(obj) {
	var str = obj.val().replace(/,/g, "");
	len = str.length;
	str1 = "";

	for( i=1; i <= len; i++ ) {
		str1 = str.charAt(len-i) + str1;
		if( ( i%3 == 0 ) && ( len-i != 0 ) ) str1 = "," + str1;
	}
	obj.val(str1);
}

// 빈칸 제거
function btrim(str) {
	var str1 = str.replace(/ /g, "");
	return str1;
}

// 전화번호(핸드폰) 하이픈
function hpHypen(obj) {
    var str = checkDigit(obj.value);
    var retValue = "";
    var len = str.length;

    if (len == 10 || len == 11) {
        if (len == 10) {
            retValue = retValue + str.substring(0, 3) + "-" + str.substring(3, 6) + "-" + str.substring(6, 10);
        } else {
            retValue = retValue + str.substring(0, 3) + "-" + str.substring(3, 7) + "-" + str.substring(7, 11);
        }
    } else {
        return false;
    }
	obj.value = retValue;
}

// 입력값중에 공백 및 기타 문자를 날려버리는 함수
function checkDigit(num) {
    var Digit = "1234567890";
    var string = num;
    var len = string.length
    var retVal = "";

    for (i = 0; i < len; i++) {
        if (Digit.indexOf(string.substring(i, i+1)) >= 0) {
            retVal = retVal + string.substring(i, i+1);
        }
    }
    return retVal;
}

// 레이어 위치 지정
function getBounds(tag) {
	var ret = new Object(); 
	var rect = tag.getBoundingClientRect();
	ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft); 
	ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop); 
	ret.width = rect.right - rect.left; 
	ret.height = rect.bottom - rect.top;
/*
	if(document.all) { 
		var rect = tag.getBoundingClientRect();
		ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft); 
		ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop); 
		ret.width = rect.right - rect.left; 
		ret.height = rect.bottom - rect.top;
	} else {
		var box = document.getBoxObjectFor(tag);
		ret.left = box.x;
		ret.top = box.y;
		ret.width = box.width; 
		ret.height = box.height; 
	}
*/
	return ret;
}

// 썩여있는 날짜 순서대로 재배열
function sortDate(a,b){
	var arr0 = a.split("-");
	var arr1 = b.split("-");
	var date_a = new Date(arr0[0],arr0[1]-1,arr0[2]);
	var date_b = new Date(arr1[0],arr1[1]-1,arr1[2]);
	if (date_a < date_b) return -1;
	if (date_a > date_b) return 1;
	return 0;
}

// 브라우저 버전 알아내기
var uAgent = navigator.userAgent.toLowerCase();
function getBrowserVer() {
	var retVar;
	var browser = getBrowser();

	switch(browser) {
		case 'msie':
			var arr = uAgent.split(';');
			retVar = arr[1].replace(/msie /,'');
			break;
		case 'safari':
			var token = 'version/';
			var arr = uAgent.split(token);
			token = ' ';
			arr = arr[1].split(token);
			retVar = arr[0];
			break;
		default:
			var token = browser + '/';
			var arr = uAgent.split(token);
			var arr0 = arr[1].split(' ');
			retVar = arr0[0];
	}

	return retVar;
}

// 브라우저 알아내기
function getBrowser() {
	var retVar;
	var bs = new Array('msie', 'chrome', 'firefox', 'safari');
	for(var i=0 ; i < bs.length ; i++) {
		if( uAgent.indexOf(bs[i]) != -1 ) {
			retVar = bs[i];
			i = bs.length;
		}
	}
	return retVar;
}

// 쿠키 저장
function setCookie( name, value, expiredays ) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// 쿠키 가져오기
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 "";
}

function getCookie2(name) {
    cookie  = document.cookie;
    name    = name + "=";
    idx     = cookie.indexOf(name);
    if(cookie && idx >= 0) {
        tmp     = cookie.substring(idx, cookie.length);
        deli    = tmp.indexOf(";");
        if(deli > 0) {
            return tmp.substring(name.length, deli);
        } else {
            return tmp.substring(name.length);
        }
    }
}

// 쿠키 지우기
function clearCookie(name) {
    today   = new Date();
    today.setDate(today.getDate() - 1);
    document.cookie = name + "=; path=/; expires=" + today.toGMTString() + ";";
}

// 쿠키 모두 지우기
function clearAllCookie() {
    cookie  = document.cookie.split(";");
    total   = cookie.length;
    for(i=0; i<total; i++) {
        name = cookie[i].substring(0, cookie[i].indexOf("="));
        clearCookie(name);
    }
}

// 팝업 가운데
function fn_popup(w,h,url,winName) {
	var t = (window.screen.height - h) / 3;
	var l = (window.screen.width - w) / 2;
	var status = "toolbar=no,location=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l;
	window.open(url, winName, status);
}

function fn_popup0(w,h,url,winName) {
	var t = (window.screen.height - h) / 3;
	var l = (window.screen.width - w) / 2;
	var status = "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l;
	window.open(url, winName, status);
}

// 글자수 바이트수로 변환하여 반환
function cal_byte(aquery) 
{
	var tmpStr;
	var temp=0;
	var onechar;
	var tcount;
	tcount = 0;

	tmpStr = new String(aquery);
	temp = tmpStr.length;

	for (k=0;k<temp;k++)
	{
		onechar = tmpStr.charAt(k);
		if (escape(onechar) =='%0D'){ 
		} 
		else if (escape(onechar).length > 4)
			tcount += 2; 
		else 
			tcount++; 
	}
	
	return tcount;
}

// 스트링 날짜를 Date로 변환
function strToDate(str) {
	var newDate;
	var arr = str.split('-');
	if ( arr.length < 3 ) {
		return;
	} else {
		 newDate = new Date(parseInt(arr[0],10),parseInt(arr[1],10)-1,parseInt(arr[2],10));
	}
	return newDate;
}

// 스트링 날짜를 Date로 변환 ( 두자리년월일 )
function strToDate0(str0,str1) {
	var newDate;
	var idx = str1.substr(0,1);
	var hy;
	switch(idx) {
		case '1':
			hy = '19';
			break;
		case '2':
			hy = '19';
			break;
		case '3':
			hy = '20';
			break;
		case '4':
			hy = '20';
			break;
	}
	newDate = new Date(parseInt(hy+str0.substr(0,2),10),parseInt(str0.substr(2,2),10)-1,parseInt(str0.substr(4,2),10));
	return newDate;
}

// 날짜 차이 계산 ( 년y, 월m, 일d, 시간h )
function dateDiff(token,d1,d2) {
	var days = 0;
	var date1 = new Date(d1);
	var date2 = new Date(d2);
	switch(token) {
		case 'h':
			days = Math.ceil((date2 - date1) / ( 1000 * 60 * 60 ));
			break;
		case 'd':
			days = Math.ceil((date2 - date1) / ( 1000 * 24 * 60 * 60 ));
			break;
		case 'm':
			days = Math.ceil((date2 - date1) / ( 1000 * 24 * 60 ));
			break;
		case 'y':
			days = date2.getYear() - date1.getYear();
			break;
	}
	return days;
}

//ajaxSetup
var ajaxSetup = function() {
	$.ajaxSetup({
		type : 'get',
		dataType : 'json',
		timeout : 10000,
		error : function(info, xhr) {
			if(info.readyState == '4') {
				alert('문제가 발생했습니다.\n상태코드 : ' + info.status+ '\n\n' + info.responseText);
				//$('div#divErr').append('<br>'+info.responseText)
			} else {
				alert('문제가 발생했습니다.\n잠시후 다시 시도해 주세요.');
			}
		}
	});
}

//jquery UI 달력
var datepicker = function(){
	$(".date").datepicker({
		dateFormat: "yy-mm-dd",
		//showAnim: "blind",
		changeMonth: true,
		changeYear: true,
		monthNamesShort: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
	});
}


//top 로그인 버튼 클릭
var layerLog = function(){
	$('#LayLoginForm').show();
}

//회원로그인 레이터 닫기
var layerClo = function(){
	$('#LayLoginForm').hide();
}

/*** 재무교육원 팝업 로그인 스크립트 수정 시 주의사항 top.document.body.clientWidth-w : 값 지정??! ***/
function view_cover(id, formid, nurl, divtype, cover)
{
	if(!id) id = "LayLoginForm";
	if(!divtype) divtype = true;
	if(!cover) cover = true;

	if(cover == true) {
		if(!top.document.getElementById('div_cover')){
			create_cover();
		}else{
			top.document.getElementById('div_cover').style.width = '100%';

			if(top.document.body.clientHeight > top.document.body.scrollHeight) top.document.getElementById('div_cover').style.height = '300';
			else top.document.getElementById('div_cover').style.height = top.document.body.scrollHeight;
			top.document.getElementById('div_cover').style.display = 'block';
		}
	}

	var w = parseInt(top.document.getElementById(id).style.width);
	var h = parseInt(top.document.getElementById(id).style.height);
	var window_left = (top.document.body.clientWidth-w)/2;
	var window_top = (top.document.body.clientHeight-h)/2+300;
	this.Lw = h/2;

	if(id) {
		this.Lid = id;
		top.document.getElementById(id).style.display = '';
		top.document.getElementById(id).style.top = window_top;
		top.document.getElementById(id).style.left = window_left;
		if(divtype == true) CheckUIElements();
	}

//	if(formid) top.document.getElementById('formid').value = formid;
//	if(nurl) top.document.getElementById('nurl').value = nurl;
//	return true;

}

function CheckUIElements() 
{
    var yMenuFrom, yMenuTo, yButtonFrom, yButtonTo, yOffset, timeoutNextCheck;

    yMenuFrom   = parseInt (top.document.getElementById(this.Lid).style.top, 10);
    if ( window.document.layers ) 
        yMenuTo = top.pageYOffset + 0;
    else if ( window.document.getElementById ) 
        yMenuTo = top.document.body.scrollTop + parseInt('0');

    timeoutNextCheck = 500;

    if ( Math.abs (yButtonFrom - (yMenuTo + 300)) < 6 && yButtonTo < yButtonFrom )
     {
        setTimeout ("CheckUIElements()", timeoutNextCheck);
        return;
    }

    if ( yMenuFrom != yMenuTo )
    {
        yOffset = Math.ceil( Math.abs( yMenuTo - yMenuFrom ) / 3 );
        if ( yMenuTo < yMenuFrom )
            yOffset = -yOffset;

        top.document.getElementById(this.Lid).style.top = (parseInt(top.document.getElementById(this.Lid).style.top) + yOffset) + 5;

        timeoutNextCheck = 10;
    }

    setTimeout ("CheckUIElements()", timeoutNextCheck);
}

function cover_off(id){
	if(top.document.getElementById('div_cover')) top.document.getElementById('div_cover').style.display = 'none';
	$('#LayLoginForm').hide();
}

function create_cover(){

	var color = '#000000';
	var opacity = '70';

	var cover_div = top.document.createElement('div');
	cover_div.style.position = 'absolute';
	cover_div.style.top = '0px';
	cover_div.style.left = '0px';
	cover_div.style.width = '100%';
	cover_div.style.zIndex = 1;
	if(top.document.body.offsetHeight > top.document.body.scrollHeight) cover_div.style.height = '100%';
	else cover_div.style.height = top.document.body.scrollHeight;
	cover_div.style.backgroundColor = color;
	cover_div.style.filter = 'alpha(opacity='+opacity+')';
	cover_div.id = 'div_cover';
	top.document.body.appendChild(cover_div);
}

