﻿/******************************************************************************
만든이     : 한현수
작성일     : 2008.09.22
최종수정일 : 2008.09.22
프로젝트명 : 웹전용 자바스크립트 라이브러리
모듈명     : 웹에서 사용되는 자바스크립트 함수 모음들 정리.
수정내용   : 
2008.09.30 print_cnts() 프린트
2008.09.30 zoom() 브라우져 확대/축소
2008.09.25 String.prototype.isDate(date) 날짜 유효성검사
2008.09.25 String.prototype.isHour(mode) 시간 유효성검사
2008.09.25 String.prototype.isMinute(mode) 분 유효성검사
2008.09.25 String.prototype.isSecond(mode) 초 유효성검사
2008.09.25 get_last_day(date) 이번달 말일
2008.09.22 help(id, mode) 추가
2008.09.22 count_byte() 추가
******************************************************************************/
// 브라우저 호환되는 여러가지 좌표값 구하기: 가져와서 이름들만 바꿈.
// 퍼온곳 : http://sir.co.kr/bbs/board.php?bo_table=tip_javascript&wr_id=125&page=0
var coord = {
	/* 
	Browser: MSIE7, Firefox3, Safari3, Opera9 
	DTD: Quirks, Strict XHTML 1.0, Strict HTML 4.01 
	Update: 2008-09-02 
	*/
	get_lft: function(idntty) { return parseInt(document.getElementById(idntty).style.left); }
    , get_top: function(idntty) { return parseInt(document.getElementById(idntty).style.top); }
    , get_wdth: function(idntty) { return parseInt(document.getElementById(idntty).style.width); }
    , get_hght: function(idntty) { return parseInt(document.getElementById(idntty).style.height); }
    , set_lft: function(idntty, nmbr) { document.getElementById(idntty).style.left = nmbr + "px"; }
    , set_top: function(idntty, nmbr) { document.getElementById(idntty).style.top = nmbr + "px"; }
    , set_wdth: function(idntty, nmbr) { document.getElementById(idntty).style.width = nmbr + "px"; }
    , set_hght: function(idntty, nmbr) { document.getElementById(idntty).style.height = nmbr + "px"; }

    , get_scrll_lft: function(idntty) {
    	if (document.body.scrollLeft) return document.body.scrollLeft;
    	else return document.documentElement.scrollLeft;
    }
    , get_scrll_top: function(idntty) {
    	if (document.body.scrollTop) return document.body.scrollTop;
    	else return document.documentElement.scrollTop;
    }
    , set_scrll_lft: function(nmbr) {
    	document.body.scrollLeft = nmbr;
    	document.documentElement.scrollLeft = nmbr;
    }
    , set_scrll_top: function(nmbr) {
    	document.body.scrollTop = nmbr;
    	document.documentElement.scrollTop = nmbr;
    }
    , clnt_wdth: function() {
    	if (typeof (document.compatMode) == 'undefined') return document.documentElement.clientWidth;
    	else if (document.compatMode == 'BackCompat') return document.body.clientWidth;
    	else if (document.compatMode == 'CSS1Compat') return document.documentElement.clientWidth;
    }
    , clnt_hght: function() {
    	if (typeof (document.compatMode) == 'undefined') return document.documentElement.clientHeight;
    	else if (document.compatMode == 'BackCompat') return document.body.clientHeight;
    	else if (document.compatMode == 'CSS1Compat') return document.documentElement.clientHeight;
    }
    , clnt_x: function(e) {
    	if (e) return e.clientX; else return event.clientX;
    }
    , clnt_y: function(e) {
    	if (e) return e.clientY; else return event.clientY;
    }
   };

// 브라우져 확대/축소
var iZoomPercent = 0;
function zoom(args) {
	if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
		if (document.body.style.zoom == null || document.body.style.zoom == "")
			iZoomPercent = 100;

		iZoomPercent = iZoomPercent + args;

		if (iZoomPercent > 200) iZoomPercent = 200;
		if (iZoomPercent < 50) iZoomPercent = 50;

		document.body.style.zoom = iZoomPercent + "%";
	}
}
// 프린트
function print_cnts() {
	window.print();
}
// 이번달 말일
function get_last_day(date) {
	var return_value;

	month_length = new Array(12);
	month_length[1] = 31
	month_length[2] = 28
	month_length[3] = 31
	month_length[4] = 30
	month_length[5] = 31
	month_length[6] = 30
	month_length[7] = 31
	month_length[8] = 31
	month_length[9] = 30
	month_length[10] = 31
	month_length[11] = 30
	month_length[12] = 31

	today = new Date()
	this_day = today.getDate()
	this_month = today.getMonth() + 1
	this_year = today.getYear();
	if (this_year < 2000)
		this_year = this_year + 1900;
	month_length[2] = (((this_year % 4 == 0) && (this_year % 100 != 0)) || (this_year % 400 == 0)) ? 29 : 28;

	var check_month;
	check_month = check_digit(this_month)

	return_value = this_year + '-' + check_month + '-' + month_length[this_month]

	//alert(return_value);
	return return_value;
}

function check_digit(args) {
	if (args < 10)
		return '0' + args
	return args;
	var aaa = new String();
}
//=====================================
// HTML 컨트롤 id의 display 스타일 설정
// 작성일 : 2008.09.22
// 인수   : id, display 값
//=====================================
function set_display(id, value) {
	if (document.getElementById(id) == null)
		return false;

	document.getElementById(id).style.display = value;
}

//=====================================
// 쿠키 저장
// 작성일 : 2008.09.22
// 인수   : 쿠키이름, 쿠키값, 유효일자
//=====================================
function cz_set_Cookie(name, value, days) {
	var today = new Date();
	var expire = new Date();

	expire.setTime(today.getTime() + 1000 * 60 * 60 * 24 * days);

	document.cookie = escape(name) + "=" + escape(value) + "; expires=" + expire.toGMTString();
}

//=====================================
// 쿠키값 가져오기
// 작성일 : 2008.09.22
// 인수   : 쿠키이름
//=====================================
function cz_get_Cookie(name) {
	var search = name + "=";

	if (document.cookie.length > 0) {                   // 쿠키가 있나?
		offset = document.cookie.indexOf(search);
		if (offset != -1) {								// name 쿠키가 있나?
			offset += search.length;                    // set index of beginning of value
			end = document.cookie.indexOf(";", offset); // set index of end of cookie value
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
}

//=====================================
// 풍선 도움말
// 작성일 : 2008.09.22
//=====================================
function help(id, mode) {
	var help_id = document.getElementById(id);

	help_id.style.backgroundColor = "ffff00";
	help_id.style.pixelLeft = event.x + 10;
	help_id.style.pixelTop = event.y + 10;

	if (mode == "show") {
		help_id.style.display = "";
	}
	else {
		help_id.style.display = "none";
	}
}

//=====================================
// 문자열의 바이트수 리턴
// 작성일 : 2008.09.22
// 기  타 : 한글: 2바이트, 영문 및 숫자: 1바이트
//=====================================
String.prototype.count_byte = function() {
	var return_value = 0;
	var tmpChar, i;

	for (i = 0; i < this.length; i++) {
		var tmpChar = this.charCodeAt(i);
		if (tmpChar > 256)
			return_value += 2;
		else
			return_value++;
	}

	return return_value;
}

// object(플래시) 뿌려주기
function writeflash(movie, argwidth, argheight, transparent) {
	var str;

	// 이걸로 하니까 크기가 안먹는다.
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='" + argwidth + "' height='" + argheight + "' align='middle'>");
	document.write("<param name='movie' value='" + movie + "' />");
	document.write("<param name='wmode' value='" + transparent + "' />");
	document.write("<embed src='/image/flash/RHRD.swf' quality='high' bgcolor='#ffffff' width='" + argwidth + "' height='" + argheight + "' name='RHRD' align='middle' allowscriptaccess='sameDomain' allowfullscreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}

// body의 onload 이벤트에 넣고, 가장 마지막에 보여줄 레이어를 보여주면 된다.
// div는 걍 호출이 가능하네? 바보냐...ㅡㅡ;
function loading() {
	a.style.display = "none";
	webbody.style.filter = "blendTrans(duration=0.5)";
	webbody.filters.blendTrans.apply();
	webbody.style.visibility = "visible";
	webbody.filters.blendTrans.play();
}

//-----------------------------------------------------------------------------
// 문자 앞 뒤 공백을 제거 한다.
//-----------------------------------------------------------------------------
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
//-----------------------------------------------------------------------------
// 내용이 있는지 없는지 확인하다.
// @return : true(내용 있음) | false(내용 없음)
//-----------------------------------------------------------------------------
String.prototype.notNull = function() {
	return (this == null || this.trim() == "") ? false : true;
}

//-----------------------------------------------------------------------------
// 아이디 체크 영어와 숫자만 체크 첫글자는 영어로 시작
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.mem_id = function(min, max) {
	if ((this.trim().match(/^[a-zA-z]{1}[0-9a-zA-Z]+$/)) && this.trim().length >= min && this.trim().length <= max)
		return true;
	else
		return false;
}

//-----------------------------------------------------------------------------
// 비밀번호 체크 영어/숫자/특수문자 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.mem_pwd = function(min, max) {
	if (this.trim().length >= min && this.trim().length <= max)
		return true;
	else
		return false;
}

//-----------------------------------------------------------------------------
// 주민번호 체크 XXXXXX-XXXXXXX 형태로 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.jumin = function() {
	var num = this.trim().onlyNum();
	if (num.length == 13) {
		num = num.substring(0, 6) + "-" + num.substring(6, 13);
	}
	else {
		return false;
	}
	num = num.match(/^([0-9]{6})-?([0-9]{7})$/);
	if (!num) return false;
	var num1 = RegExp.$1;
	var num2 = RegExp.$2;
	if (!num2.substring(0, 1).match(/^[1-4]{1}$/)) return false;
	num = num1 + num2;
	var sum = 0;
	var last = num.charCodeAt(12) - 0x30;
	var bases = "234567892345";
	for (i = 0; i < 12; i++) {
		sum += (num.charCodeAt(i) - 0x30) * (bases.charCodeAt(i) - 0x30);
	}
	var mod = sum % 11;
	return ((11 - mod) % 10 == last) ? true : false;
}

//-----------------------------------------------------------------------------
// 사업자번호 체크 XXX-XX-XXXXX 형태로 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.biznum = function() {
	var num = this.trim().onlyNum();
	if (num.length == 10) {
		num = num.substring(0, 3) + "-" + num.substring(3, 5) + "-" + num.substring(5, 10);
	}
	else {
		return false;
	}
	num = num.match(/([0-9]{3})-?([0-9]{2})-?([0-9]{5})/);
	if (!num) return false;
	num = RegExp.$1 + RegExp.$2 + RegExp.$3;
	var cVal = 0;
	for (var i = 0; i < 8; i++) {
		var cKeyNum = parseInt(((_tmp = i % 3) == 0) ? 1 : (_tmp == 1) ? 3 : 7);
		cVal += (parseFloat(num.substring(i, i + 1)) * cKeyNum) % 10;
	}
	var li_temp = parseFloat(num.substring(i, i + 1)) * 5 + '0';
	cVal += parseFloat(li_temp.substring(0, 1)) + parseFloat(li_temp.substring(1, 2));
	return (parseInt(num.substring(9, 10)) == 10 - (cVal % 10) % 10) ? true : false;
}

//-----------------------------------------------------------------------------
// 우편번호 체크 XXX-XXX 형태로 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.zipcode = function() {
	var num = this.trim().replace(/-/g, "");
	num = num.match(/^[0-9]{3}[0-9]{3}$/);
	return (num) ? true : false;
}

//-----------------------------------------------------------------------------
// 전화번호 체크 XXX-XXXX-XXXX 형태로 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.tel = function() {
	var num = this.trim().replace(/-/g, "");
	if (num.substring(1, 2) == "2") {
		num = num.substring(0, 2) + "-" + num.substring(2, num.length - 4) + "-" + num.substring(num.length - 4, num.length);
	}
	else {
		num = num.substring(0, 3) + "-" + num.substring(3, num.length - 4) + "-" + num.substring(num.length - 4, num.length);
	}
	num = num.match(/^0[0-9]{1,2}-[1-9]{1}[0-9]{2,3}-[0-9]{4}$/);
	return (num) ? true : false;
}

//-----------------------------------------------------------------------------
// 전화번호 체크 XXX-XXXX-XXXX 형태로 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.tel2 = function() {
	var num = this.trim().replace(/-/g, "");
	if (num.substring(1, 2) == "2") {
		num = num.substring(0, 2) + "-" + num.substring(2, num.length - 4) + "-" + num.substring(num.length - 4, num.length);
	}
	else {
		num = num.substring(0, 3) + "-" + num.substring(3, num.length - 4) + "-" + num.substring(num.length - 4, num.length);
	}
	num = num.match(/^02|031|032|033|041|042|043|051|052|053|054|055|061|062|063|064|0303|0502|0505|0506|070|080|1544|1566|1577|1588|1599|1600|1644|1688-[1-9]{1}[0-9]{2,3}-[0-9]{4}$/);
	return (num) ? true : false;
}

//-----------------------------------------------------------------------------
// 핸드폰 체크 XXX-XXXX-XXXX 형태로 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.mobile = function() {
	var num = this.trim().replace(/-/g, ""); // 20080418 : replace("-", "");은 한번만 작동해서 replace를 다시 만들었따.	// 20080417 : onlyNum()을 썼던거를 변형
	num = num.substring(0, 3) + "-" + num.substring(3, num.length - 4) + "-" + num.substring(num.length - 4, num.length);
	num = num.trim().match(/^01[016789]{1}-[1-9]{1}[0-9]{2,3}-[0-9]{4}$/);
	return (num) ? true : false;
}

//-----------------------------------------------------------------------------
// 팩스번호 체크 XXX-XXXX-XXXX 형태로 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.fax = function() {
	return this.tel();
}

//-----------------------------------------------------------------------------
// 메일의 유효성을 체크 한다.
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.email = function() {
	var em = this.trim().match(/^[_\-\.0-9a-zA-Z]{3,}@[-.0-9a-zA-z]{2,}\.[a-zA-Z]{2,4}$/);
	return (em) ? true : false;
}

//-----------------------------------------------------------------------------
// 날짜의 유효성을 체크 한다.
// 인수형식 : "2008-09-01"
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.date = function() {
	var er = 0; // 에러 변수
	var daa = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	var yyyy, mm, dd

	if (this.indexOf("-") >= 0) {

	}
	else if (this.length != 8) {
		return false;
	}
	else {
		return false;
	}

	var yyyy = parseInt(this.substring(0, 4), 10);
	var mm = parseInt(this.substring(4, 6), 10);
	var dd = parseInt(this.substring(6, 8), 10);

	if (yyyy % 1000 != 0 && yyyy % 4 == 0) daa[1] = 29; // 윤년
	if (dd > daa[mm - 1] || dd < 1) er = 1; // 날짜 체크
	if (mm < 1 || mm > 12) er = 1; // 월 체크
	if (mm % 1 != 0 || yyyy % 1 != 0 || dd % 1 != 0) er = 1; // 정수 체크

	if (er == 1)
		return false;
	else
		return true;

	//	--mm;

	//	var dateVar = new Date(yy, mm, dd);
	//인수로 받은 년월일과 생성한 Date객체의 년월일이 일치하면 true
	//	return (dateVar.getFullYear() == yy && dateVar.getMonth() == mm && dateVar.getDate() == dd) ? true : false;
}

//=====================================
// 시간 유효성 검사
// 반환값 : true | false
//=====================================
String.prototype.isLimitNumeric = function(arg1, arg2) {
	var tmp;

	// 인수 유효성 검사
	arg1 = parseInt(arg1);
	if (isNaN(arg1)) {	// 숫자인가?
		alert("Parameter Error!"); return false;
	}
	arg2 = parseInt(arg2);
	if (isNaN(arg2)) {	// 숫자인가?
		alert("Parameter Error!"); return false;
	}

	tmp = parseInt(this); // 형변환
	if (isNaN(tmp))		// 숫자인가?
		return false;

	if (tmp >= arg1 && tmp <= arg2)
		return true;
	else
		return false;
}

//=====================================
// 시간 유효성 검사
// 반환값 : true | false
//=====================================
String.prototype.isDate = function(arg1, arg2) {
	var tmp;
	return false;

}

//=====================================
// 시간 유효성 검사
// 반환값 : true | false
//=====================================
String.prototype.isTime = function(arg1, arg2) {

	var tmp;
	return false;
}

//-----------------------------------------------------------------------------
// 주민등록번호로 생년월일을 구한다.
// 인수 : -를 포함하지 않은 13자리 숫자
// @return : 날짜형식(9999-99-99) | false(잘못된 형식)
//-----------------------------------------------------------------------------
function get_jumin2birthdate(jumin) {
	if (!jumin.jumin()) {
		return false;
	}

	var return_value;

	if (jumin.substring(6, 7) == "1" || jumin.substring(6, 7) == "2") {
		return_value = "19" + jumin.substring(0, 2);
	}
	else if (jumin.substring(6, 7) == "3" || jumin.substring(6, 7) == "4") {

		return_value = "20" + jumin.substring(0, 2);
	}

	return_value = return_value + "-" + jumin.substring(2, 4);
	return_value = return_value + "-" + jumin.substring(4, 6);

	return return_value;
}

//-----------------------------------------------------------------------------
// 숫자만 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.num = function() {
	return (this.trim().match(/^[0-9]+$/)) ? true : false;
}

//-----------------------------------------------------------------------------
// 영어만 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.eng = function() {
	return (this.trim().match(/^[a-zA-Z]+$/)) ? true : false;
}

//-----------------------------------------------------------------------------
// 영어와 숫자만 체크
//
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.engnum = function() {
	return (this.trim().match(/^[0-9a-zA-Z]+$/)) ? true : false;
}

//-----------------------------------------------------------------------------
// 영어와 숫자만 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.numeng = function() {
	return this.engnum();
}

//-----------------------------------------------------------------------------
// 영어와 콤마(,)만 체크. 태그
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.tags = function() {
	return (this.trim().match(/^[a-zA-Z,]+$/)) ? true : false;
}

//-----------------------------------------------------------------------------
// 폴더체크(영어, 숫자, /, _, 첫글자는 영문자)
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.folder = function() {
	return (this.trim().match(/[a-zA-z]{1}[0-9a-zA-Z_]+$/)) ? true : false;
}

//-----------------------------------------------------------------------------
// 한글만 체크
// @return : true(맞는 형식) | false(잘못된 형식)
//-----------------------------------------------------------------------------
String.prototype.kor = function() {
	return (this.trim().match(/^[가-힣]+$/)) ? true : false;
}

//-----------------------------------------------------------------------------
// 숫자와 . - 이외의 문자는 다 뺀다. - 통화량을 숫자로 변환
// @return : 숫자
//-----------------------------------------------------------------------------
String.prototype.toNum = function() {
	var num = this.trim();
	return (this.trim().replace(/[^0-9\.-]/g, ""));
}

//-----------------------------------------------------------------------------
// 숫자 이외에는 다 뺀다.
// @return : 숫자
//-----------------------------------------------------------------------------
String.prototype.onlyNum = function() {
	var num = this.trim();
	return (this.trim().replace(/[^0-9]/g, ""));
}

//-----------------------------------------------------------------------------
// 숫자만 뺀 나머지 전부
// @return : 숫자 이외
//-----------------------------------------------------------------------------
String.prototype.noNum = function() {
	var num = this.trim();
	return (this.trim().replace(/[0-9]/g, ""));
}

//-----------------------------------------------------------------------------
// 숫자에 3자리마다 , 를 찍어서 반환
// @return : 통화량
//-----------------------------------------------------------------------------
String.prototype.toMoney = function() {
	var num = this.toNum();
	var pattern = /(-?[0-9]+)([0-9]{3})/;
	while (pattern.test(num)) {
		num = num.replace(pattern, "$1,$2");
	}
	return num;
}

//-----------------------------------------------------------------------------
// String length 반환
// @return : int
//-----------------------------------------------------------------------------
String.prototype.getLength = function() {
	return this.length;
}

//-----------------------------------------------------------------------------
// String length 반환 한글 2글자 영어 1글자
// @return : int
//-----------------------------------------------------------------------------
String.prototype.getByteLength = function() {
	var tmplen = 0;
	for (var i = 0; i < this.length; i++) {
		if (this.charCodeAt(i) > 127)
			tmplen += 2;
		else
			tmplen++;
	}
	return tmplen;
}

//-----------------------------------------------------------------------------
// 파일 확장자 반환
// @return : String
//-----------------------------------------------------------------------------
String.prototype.getExt = function() {
	var ext = this.substring(this.lastIndexOf(".") + 1, this.length);
	return ext;
}

//-----------------------------------------------------------------------------
// String에 따라서 받침이 있으면 은|이|을 을
// 받침이 없으면 는|가|를 등을 리턴 한다.
// str.josa("을/를") : 구분자는 항상 "/"로
// @return : 은/는, 이/가 ...
//-----------------------------------------------------------------------------
String.prototype.josa = function(nm) {
	var nm1 = nm.trim().substring(0, nm.trim().indexOf("/"));
	var nm2 = nm.trim().substring(nm.trim().indexOf("/") + 1, nm.trim().length);
	var a = this.substring(this.length - 1, this.length).charCodeAt();
	a = a - 44032;
	var jongsung = a % 28;
	return (jongsung) ? nm1 : nm2;
}


/******************************************************************************
* Form에 관련된 메서드
* 
* 1. text, textarea
* required : 값이 없으면 경고
* num : 값에 숫자만 가능
* eng : 값에 영어만 가능
* han : 값에 한글만 가능
* numeng : 값에 숫자와 영어만 가능
* min=value : 최소 value자 이상
* max=value : 최대 value자 이하
* len=value : 정확하게 value자만 가능
* len=start~end : start자에서 end자까지 가능
* userid : 영어 숫자만 가능하고 첫문자는 영어로
* phone=value : value가 ""면 이 필드만 아니면 value가 같은 phone에 관련된 모든 필드 조사
* mobile=value : value가 ""면 이 필드만 아니면 value가 같은 mobile에 관련된 모든 필드 조사
* email=value : value가 ""면 이 필드만 아니면 value가 같은 email에 관련된 모든 필드 조사
* jumin=value : value가 ""면 이 필드만 아니면 value가 같은 jumin에 관련된 모든 필드 조사
* biznum=value : value가 ""면 이 필드만 아니면 value가 같은 biznum에 관련된 모든 필드 조사
* 2. select
* required : 값이 없으면 경고
* 3. radio
* required : 아무것도 선택되지 않으면 경고
* 4. checkbox
* required : 아무것도 선택되지 않으면 경고
* min=value : 최소 value개 이상 가능
* max=value : 최대 value개 이하 가능
* len=value : 정확하게 value개 가능
* len=start~end : start개에서 end개 까지 가능
* 5. file
* required : 아무것도 선택되지 않으면 경고
* allow=value : 확장자가 value 인 파일만 업로드 가능 (allow="gif jpg jpeg png")
* deny=value : 확장자가 value 인 파일은 업로드 불가능
*****************************************************************************/
//-----------------------------------------------------------------------------
// FormUtil Class 생성
//-----------------------------------------------------------------------------
FormUtil = function(obj) {
	this.obj = obj;
}

//-----------------------------------------------------------------------------
// 폼 유효성 체크
//
// @return : true | false
//-----------------------------------------------------------------------------
FormUtil.prototype.success = function() {

	for (var i = 0; i < this.obj.elements.length; i++) {
		var f = this.obj[i];

		var fname = (f.getAttribute("FNAME") == null) ? f.name.toUpperCase() : fname = f.getAttribute("FNAME");

		// checkbox
		if (f.type == "checkbox") {
			if (!this.checkbox(f, fname)) {
				return false;
			}
		}
		// radio
		else if (f.type == "radio") {
			if (!this.radio(f, fname)) {
				return false;
			}
		}
		else { // text, textarea, password, select
			// <input required>
			if (f.getAttribute("REQUIRED") != null) {
				var ftype = f.type;
				var msg = " 입력 하세요";
				if (ftype.indexOf("select") >= 0 || ftype == "file") {
					msg = " 선택하세요";
				}

				if (!f.value.notNull()) {
					alert(fname + fname.josa("을/를") + msg);
					f.focus();
					return false;
				}
			}
			// <input num>
			if (f.getAttribute("NUM") != null && f.value != "") {
				if (!f.value.num()) {
					alert(fname + fname.josa("은/는") + " 숫자로만 구성되어야 합니다.");
					f.value = "";
					f.focus();
					return false;
				}
			}
			// <input eng>
			if (f.getAttribute("ENG") != null && f.value != "") {
				if (!f.value.eng()) {
					alert(fname + fname.josa("은/는") + " 영어로만 구성되어야 합니다.");
					f.value = "";
					f.focus();
					return false;
				}
			}
			// <input numeng>
			if (f.getAttribute("NUMENG") != null && f.value != "") {
				if (!f.value.numeng()) {
					alert(fname + fname.josa("은/는") + " 숫자와 영어로만 구성되어야 합니다.");
					f.value = "";
					f.focus();
					return false;
				}
			}
			// <input han>
			if (f.getAttribute("HAN") != null && f.value != "") {
				if (!f.value.kor()) {
					alert(fname + fname.josa("은/는") + " 한글로만 구성되어야 합니다.");
					f.value = "";
					f.focus();
					return false;
				}
			}
			// <input userid>
			if (f.getAttribute("USERID") != null && f.value != "") {
				if (!f.value.userid()) {
					alert(fname + fname.josa("은/는") + " 숫자와 영어로만 구성되어야 하며\n\n첫문자는 반드시 영어로 시작해야 합니다.");
					f.value = "";
					f.focus();
					return false;
				}
			}
			// <input type="file" deny="value">
			if (f.getAttribute("DENY") != null && f.type == "file" && f.value != "") {
				var ext = f.value.getExt().toLowerCase();
				var ext2 = f.getAttribute("DENY").toLowerCase();
				if (ext2.indexOf(ext) >= 0) {
					alert("확장자가 " + f.getAttribute("DENY").toUpperCase() + " 인 파일은 업로드 하실 수 없습니다.");
					return false;
				}
			}
			// <input type="file" deny="value">
			if (f.getAttribute("ALLOW") != null && f.type == "file" && f.value != "") {
				var ext = f.value.getExt().toLowerCase();
				var ext2 = f.getAttribute("ALLOW").toLowerCase();
				if (ext2.indexOf(ext) < 0) {
					alert("확장자가 " + f.getAttribute("ALLOW").toUpperCase() + " 인 파일만 업로드 가능 합니다.");
					return false;
				}
			}
			// <input max="10">
			if (f.getAttribute("MAX") != null) {
				var tmpLen = f.value.getLength();
				if (tmpLen > parseInt(f.getAttribute("MAX"))) {
					alert(fname + fname.josa("은/는") + " " + f.getAttribute("MAX") + "자 이하로 입력 하세요.");
					f.value = "";
					f.focus();
					return false;
				}
			}
			// <input min="10">
			if (f.getAttribute("MIN") != null) {
				var tmpLen = f.value.getLength();
				if (tmpLen < parseInt(f.getAttribute("MIN"))) {
					alert(fname + fname.josa("은/는") + " " + f.getAttribute("MIN") + "자 이상으로 입력 하세요.");
					f.focus();
					return false;
				}
			}
			// <input len="10">
			if (f.getAttribute("LEN") != null) {
				var tmpLen = f.value.getLength();
				var val = f.getAttribute("LEN");
				if (val.indexOf(val.noNum()) > 0) {
					var num1 = val.substring(0, val.indexOf(val.noNum()));
					var num2 = val.substring(val.lastIndexOf(val.noNum()) + 1, val.length);
					if (tmpLen < parseInt(num1) || tmpLen > parseInt(num2)) {
						alert(fname + fname.josa("은/는") + " " + num1 + "자 이상 " + num2 + "자 이하로 입력하세요");
						f.focus();
						return false;
					}
				}
				else {
					if (tmpLen != parseInt(val)) {
						alert(fname + fname.josa("은/는") + " " + val + "자리 입니다.");
						f.focus();
						return false;
					}
				}
			}
		}
	}

	for (var i = 0; i < this.obj.elements.length; i++) {
		var f = this.obj[i];
		// <input phone="name">
		if (f.getAttribute("PHONE") != null) {
			var val = "";
			if (f.getAttribute("PHONE") == "") {
				val = f.value
			}
			else {
				val = this.getValue("PHONE", f.getAttribute("PHONE"));
			}
			if (!val.tel()) {
				alert("올바른 전화번호가 아닙니다.\n\n다시 확인하여 주세요");
				f.focus();
				return false;
			}
		}
		// <input mobile="name">
		if (f.getAttribute("MOBILE") != null) {
			var val = "";
			if (f.getAttribute("MOBILE") == "") {
				val = f.value
			}
			else {
				val = this.getValue("MOBILE", f.getAttribute("MOBILE"));
			}
			if (!val.mobile()) {
				alert("올바른 핸드폰번호가 아닙니다.\n\n다시 확인하여 주세요");
				f.focus();
				return false;
			}
		}
		// <input jumin="name">
		if (f.getAttribute("JUMIN") != null) {
			var val = "";
			if (f.getAttribute("JUMIN") == "") {
				val = f.value
			}
			else {
				val = this.getValue("JUMIN", f.getAttribute("JUMIN"));
			}
			if (!val.jumin()) {
				alert("올바른 주민등록 번호가 아닙니다.\n\n다시 확인하여 주세요");
				f.focus();
				return false;
			}
		}
		// <input email="name">
		if (f.getAttribute("EMAIL") != null) {
			var val = "";
			if (f.getAttribute("EMAIL") == "") {
				val = f.value
			}
			else {
				val = this.getValue("EMAIL", f.getAttribute("EMAIL"));
			}
			if (!val.mail()) {
				alert("유효한 이메일이 아닙니다.\n\n다시 확인하여 주세요");
				f.focus();
				return false;
			}
		}
		// <input biznum="name">
		if (f.getAttribute("BIZNUM") != null) {
			var val = "";
			if (f.getAttribute("BIZNUM") == "") {
				val = f.value
			}
			else {
				val = this.getValue("BIZNUM", f.getAttribute("BIZNUM"));
			}
			if (!val.bizname()) {
				alert("유효한 사업자 등록 번호가 아닙니다.\n\n다시 확인하여 주세요");
				f.focus();
				return false;
			}
		}

	}

	return true;
}

//-----------------------------------------------------------------------------
// Checkbox 일때 유효성 체크
//
// @return : true | false
//-----------------------------------------------------------------------------
FormUtil.prototype.checkbox = function(f, fname) {
	var chkObj = eval("this.obj." + f.name);
	// 체크박스를 선택하여야 할 때
	var c = 0;
	var len = chkObj.length;
	if (len) {
		for (var j = 0; j < len; j++) {
			if (chkObj[j].checked) c++;
		}
	}
	else {
		if (chkObj.checked) c = 1;
	}

	if (f.getAttribute("REQUIRED") != null) {
		if (c == 0) {
			alert(fname + fname.josa("을/를") + " 선택하여 주세요");
			return false;
		}
	}
	if (f.getAttribute("MAX") != null) {
		var val = f.getAttribute("MAX");
		if (c > parseInt(val)) {
			alert(fname + fname.josa("은/는") + " 최대 " + val + "개 이하로 선택 하셔야 합니다.");
			return false;
		}
	}
	if (f.getAttribute("MIN") != null) {
		var val = f.getAttribute("MIN");
		if (c < parseInt(val)) {
			alert(fname + fname.josa("은/는") + " 최소 " + val + "개 이상 선택 하셔야 합니다.");
			return false;
		}
	}
	if (f.getAttribute("LEN") != null) {
		var val = f.getAttribute("LEN");
		if (val.indexOf(val.noNum()) > 0) {
			var num1 = val.substring(0, val.indexOf(val.noNum()));
			var num2 = val.substring(val.lastIndexOf(val.noNum()) + 1, val.length);
			if (c < parseInt(num1) || c > parseInt(num2)) {
				alert(fname + fname.josa("은/는") + " " + num1 + "개 이상 " + num2 + "개 이하로 선택 하셔야 합니다.");
				return false;
			}
		}
		else {
			if (c != parseInt(val)) {
				alert(fname + fname.josa("은/는") + " " + val + "개 선택 하셔야 합니다.");
				f.focus();
				return false;
			}
		}
	}
	return true;
}

//-----------------------------------------------------------------------------
// Radio 유효성 체크
//
// @return : true | false
//-----------------------------------------------------------------------------
FormUtil.prototype.radio = function(f, fname) {
	var chkObj = eval("this.obj." + f.name);
	if (f.getAttribute("REQUIRED") != null) {
		var c = 0;
		var len = chkObj.length;
		if (len) {
			for (var j = 0; j < len; j++) {
				if (chkObj[j].checked) c++;
			}
		}
		else {
			if (chkObj.checked) c = 1;
		}
		if (c == 0) {
			alert(fname + fname.josa("을/를") + " 선택하여 주세요");
			return false;
		}
	}
	return true;
}

//-----------------------------------------------------------------------------
// 체크되어 있는 갯수를 리턴해 준다.
//
// @return : int
//-----------------------------------------------------------------------------
FormUtil.prototype.checked = function(btn) {
	var len = btn.length;
	var c = 0;
	if (len) {
		for (var j = 0; j < len; j++) {
			if (btn[j].checked) c++;
		}
	}
	else {
		if (btn.checked) c = 1;
	}
	return c;
}

//-----------------------------------------------------------------------------
// 해당 name의 값이 같은 filed를 구한다.
//
// @return : String
//-----------------------------------------------------------------------------
FormUtil.prototype.getValue = function(name, value) {
	var val = "";
	for (var j = 0; j < this.obj.elements.length; j++) {
		if (eval("this.obj[j].getAttribute(\"" + name + "\")") != null && eval("this.obj[j].getAttribute(\"" + name + "\")") == value) {
			if (val == "") {
				val += this.obj[j].value;
			}
			else {
				val += "@" + this.obj[j].value;
			}
		}
	}
	return val;
}
/*
http://kin.naver.com/db/detail.php?d1id=1&dir_id=10105&eid=eawUnEH3bmLje0Vr3yrhZj2NZwZjng/M&qb=cmFkaW8gwK/Iv7y6sMu75w==

FNAME : 경고창에 뿌려줄때 폼 이름 값

REQUIRED : 필수 입력 항목. 값이 null 또는 "" 일때 경고창을 띠운다.

<input type="text" name="f1" value="" fname="필수 입력창" required>

NUM : 숫자 이외의 모든 문자가 value에 있을 경우 경고창

<input type="text" name="f2" value="" fname="숫자입력창" num>

ENG : 영문만 입력 받아야 할 때

<input type="text" name="f3" value="" fname="영문입력창" eng>

NUMENG : 영문과 숫자만 허용될 때

<input type="text" name="f4" value="" fname="영문 숫자 입력창" numeng>

HAN : 한글만 입력 받아야 할 때. (이모콘티 제외)

<input type="text" name="f5" value="" fname="한글 입력창" han>

USERID : 영문과 숫자로 이루어 지면 첫글자는 반드시 영어로 받을때.

<input type="text" name="f6" value="" fname="회원 아이디" userid>

DENY : <input type="file" deny="java php asp dll" > 에서 허용되지 않은 확장자 파일 - 이 확장자만 거부

<input type="file" name="f7" value="" fname="허용하지 않음" deny="gif jpg png bmp"> (이미지 파일을 올려 보세요)

ALLOW : <input type="file" allow="gif jpg png" > 에서 허용 하는 확장자 파일 - 이 확장자만 수락

<input type="file" name="f8" value="" fname="허용" deny="zzz">

MAX : <input type="text" max="5" > 최대 글자수 제한 최대 5자 이하

<input type="text" name="f9" value="" fname="MAX" max="5">

MIN : <input type="text" min="5" > 최소 글자수 제한 최소 5자 이상

<input type="text" name="f10" value="" fname="MIN" min="5">

LEN : <input type="text" len="5" > 글자수 5자로 고정

<input type="text" name="f11" value="" fname="LEN" len="5">

LEN : <input type="text" len="5~8" > 또는 <input type="text" len="5-8" > 글자수 5자이상 8자 이하

<input type="text" name="f12" value="" fname="LEN 범위" min="3-5">

PHONE : <input type="text" phone > 한 필드일때 전화번호 유효성 체크

<input type="text" name="f13" value="" fname="전화번호" phone>

PHONE : <input type="text" name="p" phone="p1" > - 
<input type="text" name="p" phone="p1" > - <input type="text" name="p" phone="p1" >

여러 필드로 나뉘어져 있을 경우 phone의 값을 같게 해야 한다.

<input type="text" name="f14" value="" fname="전화번호" phone="phone" size="4"> -
<input type="text" name="f15" value="" phone="phone" size="4"> - 
<input type="text" name="f16" value="" phone="phone" size="4">

MOBILE : 전화번호와 같음 단지 010 011 016 017 018 019 체크 루틴 추가

<input type="text" name="f17" value="" fname="핸드폰" mobile="phone" size="4"> -
<input type="text" name="f17" value="" mobile="phone" size="4"> - 
<input type="text" name="f17" value="" mobile="phone" size="4">

한필드일때 <input type="text" name="f18" value="" mobile>

JUMIN : 주민등록 검사

<input type="text" name="f19" value="" fname="주민번호" jumin="jumin" size="8"> -
<input type="text" name="f20" value="" jumin="jumin" size="8">

한필드일때 <input type="text" name="f21" jumin>

EMAIL : 메일 검사

<input type="text" name="f22" value="" fname="이메일" email="ttt" size="8"> @
<input type="text" name="f22" value="" email="ttt">

한필드일때 <input type="text" name="f22" email>

BIZNUM : 사업자 등록 번호 검사

select box 일 경우 - REQUIRED만 허용 (값이 있는지만 체크)

type=radio 일 경우 - REQUIRED 체크가 되었는지 아닌지 검사

type=checkbox 일 경우 - REQUIRED, MIN, MAX, LEN 허용


<input type="submit" value="확인하세요">
*/