<!-- 
////////////////////////////////////////////////////////////////////////////
// js/net/highbase/FormUtil.js
////////////////////////////////////////////////////////////////////////////
//	author	highbase
//	generate:	2004.07.27
//	modified:	2004.07.27
//	            2004.07.28
//	            2004.08.07
//	            2005.04.02
//	v1.03		2005.04.30	µ¥ÀÌÅÍ °´Ã¼ÀÇ °ªÀ» ÇÊµå¿¡ ¹Ý¿µ Ã³¸®
////////////////////////////////////////////////////////////////////////////
//	v 1.0.0
//	. ³ÎÃ¼Å©/»çÀÌÁîÃ¼Å©/µ¿ÀÏ°ªÃ¼Å©/¶óµð¿À,Ã¼Å©¹Ú½º ¼±ÅÃÃ¼Å©/¼¿·ºÆ® ¼±ÅÃÃ¼Å©
//	. ¸Þ¼¼Áö Ãâ·Â ÅÂ±× Á¸Àç½Ã ÅÂ±×¿¡ ¸Þ¼¼Áö Ãâ·Â
//	. ÅÂ±×°¡ ¾øÀ»½Ã, alertÀ¸·Î ¸Þ¼¼Áö Ãâ·Â
////////////////////////////////////////////////////////////////////////////
//ie6+
if (typeof(FormUtil) == "undefined") FormUtil = function(){}
//Æ÷Ä¿½º¸¦ °­Á¦·Î ¸ÂÃß´Â Ã³¸®¸¦ ÇÏÁö ¾ÊÀ½.
FormUtil.prototype.jitCheckNull = function(o, msg){
	return this.cmmCheckNull(o, msg, true);
}

FormUtil.prototype.checkNull = function(o, msg){
	return this.cmmCheckNull(o, msg, false);
}
// o: object
// msg: message
// jit: ¿À·ù¹ß°ß½Ã focus¸¦ À¯Áö±ÝÁö ¿©ºÎ
// 2005.04.19 °ø¹é¹®ÀÚµµ Á¦°ÅÇÑ »óÅÂ¿¡¼­ °Ë»ç.
FormUtil.prototype.cmmCheckNull = function(o, msg, jit){
	try{
		o.value = o.value.trim();
		if (o.value == null || o.value == "" 
				// °ø¹é Á¦°Å ·çÆ¾ÀÌ ³»¿ëÀÌ ±æ °æ¿ì ½ºÅÃ ¿À¹öÇÃ·Î¸¦ À¯¹ßÇÏ¿©
				// ±æÀÌ¸¦ 20ÀÚ ÀÌ³» ÁÖ·Î ¾ÆÀÌµð, ºñ¹øÀ» ¼ö¿ëÇÏ´Â ±æÀÌ·Î Á¦ÇÑÀ» µÒ. 
				// 2005-12-30 highbase
				|| (o.value.length < 20 && o.value.deleteWhiteSpace() == "")){
			this.cmmAlertFocus(o, msg, jit);
			return true;
		}
		return this._msgClear_returnFalse(o);
	} catch(e){
		return this._alertError_returnTrue(e, msg);
	}
}

FormUtil.prototype.checkPattern = function(o, p, msg) {
	return this.cmmCheckPattern(o, p, msg, false);
}	

FormUtil.prototype.jitCheckPattern = function(o, p, msg) {
	return this.cmmCheckPattern(o, p, msg, true);
}	

FormUtil.prototype.cmmCheckPattern = function(o, p, msg, jit) {
	try {
		if (!eval(o.pattern).test(o.value)) {
			this.cmmAlertFocus(o, msg, jit);
			return true;
		}
		return this._msgClear_returnFalse(o);
	} catch(e) {
		return this._alertError_returnTrue(e, msg);
	}
}	

FormUtil.prototype.jitCheckSize = function(){
	if (arguments.length == 3)
		return this.cmmCheckSize(arguments[0], arguments[1], arguments[2], true);
	else if (arguments.length == 4)
		return this.cmmCheckSize(arguments[0], arguments[1], arguments[2], arguments[3], true);
}

FormUtil.prototype.checkSize = function(){
	if (arguments.length == 3)
		return this.cmmCheckSize(arguments[0], arguments[1], arguments[2], false);
	else if (arguments.length == 4)
		return this.cmmCheckSize(arguments[0], arguments[1], arguments[2], arguments[3], false);
}

FormUtil.prototype.cmmCheckSize = function(){
	maxlen = 0;
	minlen = 0;
	o = arguments[0];
	jit = arguments[arguments.length - 1];
	msg = arguments[arguments.length - 2];
	if(arguments.length == 4){
		maxlen = arguments[1];
	}
	else if(arguments.length == 5){
		minlen = arguments[1];
		maxlen = arguments[2];
	}
	if (o.value.length < minlen || o.value.length > maxlen){
		this.cmmAlertFocus(o, msg, jit);
		return true;
	}
	return this._msgClear_returnFalse(o);
}

FormUtil.prototype.jitCheckSame = function(o1, o2, msg){
	return this.cmmCheckSame(o1, o2, msg, true);
}

FormUtil.prototype.checkSame = function(o1, o2, msg){
	return this.cmmCheckSame(o1, o2, msg, false);
}

FormUtil.prototype.cmmCheckSame = function(o1, o2, msg, jit){
	if (o1.value != o2.value){
		this.cmmAlertFocus(o2, msg, jit);
		return true;
	}
	return this._msgClear_returnFalse(o1);
}

FormUtil.prototype.checkCheckbox = function(o, msg){
	return this.checkRadio(o, msg);
}

FormUtil.prototype.checkRadio = function(o, msg){
	try{
		if (! this.isChecked(o)){
			this.alertFocus(o, msg);
			return true;
		}
		return this._msgClear_returnFalse(o);
	} catch(e){
		return this._alertError_returnTrue(e, msg);
	}
}

FormUtil.prototype.checkSelect = function(o, msg){
	try{
		if (! this.isSelected(o)){
			this.alertFocus(o, msg);
			return true;
		}
		return this._msgClear_returnFalse(o);
	} catch(e){
		return this._alertError_returnTrue(e, msg);
	}
}

FormUtil.prototype.jitCheckWhiteSpace = function(o, msg){
	return this.cmmCheckWhiteSpace(o, msg, true);
}

FormUtil.prototype.checkWhiteSpace = function(o, msg){
	return this.cmmCheckWhiteSpace(o, msg, false);
}

FormUtil.prototype.cmmCheckWhiteSpace = function(o, msg, jit){
	try{
		if (this.hasWhiteSpace(o)){
			this.cmmAlertFocus(o, msg, jit);
			return true;
		}
		return this._msgClear_returnFalse(o);
	} catch(e){
		return this._alertError_returnTrue(e, msg);
	}
}
////////////////////////////////////////////////////////////////////////////
//extract method.
FormUtil.prototype.hasWhiteSpace = function(o){
	rexp = /\s/;
	if(rexp.test(o.value)){
		return true;
	}
	else{
		return false;
	}
}

FormUtil.prototype.isWhiteSpace = function(o){
	rexp = /^\s+$/;
	if(rexp.test(o.value)){
		return true;
	}
	else{
		return false;
	}
}

FormUtil.prototype.isChecked = function(o){
	for (i = 0; i < o.length; i++){
		if (o[i].checked) return true;
	}
	return false;
}

FormUtil.prototype.isSelected = function(o){
	for (i = 0; i < o.options.length; i++){
		if (o.options[i].selected && o.options[i].value != "") return true;
	}
	return false;
}

FormUtil.prototype.msgClear = function(o){
	try{
		document.all[o.disp].innerHTML = "";
	} catch(e){
	}
}

// modify 2004.08.07 highbase
FormUtil.prototype.alert = function(o, msg){
	if (this.prevObj != null){
		this.prevObj.innerHTML = "";
	}
	try{
		document.all[o.disp].innerHTML = msg;
		this.prevObj = document.all[o.disp];
	} catch(e){
		alert(msg);
	}
}
//	modified.	2004.07.28	highbase
//		checkbox, radioÀÏ °æ¿ìµµ Ã³¸®ÇÏµµ·Ï ¼öÁ¤ÇÔ.
FormUtil.prototype.alertFocus = function(o, msg){
	this.cmmAlertFocus(o, msg, false);
}

FormUtil.prototype.cmmAlertFocus = function(o, msg, jit){
	this.alert(o, msg);
	if (jit){
		//return;
	}
	else{
		if (".SELECT.INPUT.TEXTAREA".indexOf(o.tagName) > -1){
			o.focus();
		}
		// checkbox, radio°¡ ÇØ´çµÊ.
		else if (".object".indexOf(typeof(o)) > -1){
			o[0].focus();
		}
	}
}

FormUtil.prototype.alertError = function(e, msg){
	alert(e.name + ": " + e.message + "\n" + 
		  //e.number + ": " + e.description + "\n" +
		  msg + "¸¦ Ã³¸®ÇÏ´Â Áß ¿À·ù¹ß»ý");
}
//
FormUtil.prototype._msgClear_returnFalse = function(o){
	this.msgClear(o);
	return false;
}

FormUtil.prototype._alertError_returnTrue = function(e, msg){
	this.alertError(e, msg);
	return true;
}

/*
 * 2005.04.02	highbase
 *
 * @param f Ã¼Å©¹Ú½º¸¦ °¡Áø Æû °´Ã¼
 * @param sName Ã¼Å©¹Ú½ºÀÇ ÀÌ¸§
 */
FormUtil.prototype.checkedAll = function(f, sName) {
//	logger.log("### checkedAll(f, sName) entered.")
	try {
		var o = f.elements[sName];
		for (var i = 1; i < o.length; i++) {
			o[i].checked = o[0].checked;
//			logger.log(o[i].checked);
		}
	}
	catch (e) {
		this.log(269, e.message);
	}
}

/*
 * 2005.04.09	highbase
 */
FormUtil.prototype.getForm = function(n) {
	this.log(277, "typeof(n)=[" + typeof(n) + "]");
	if (typeof(n) == "undefined")
		return document.forms[document.forms.length - 1];
	else
		return document.forms[n];
}

FormUtil.prototype.focus = function(f) {
//	this.log(281, "focus()");
	try {
		for (var i = 0; i < f.elements.length; i++){
			this.log(284, "typeof(f.elements[i].FOCUSIT)=[" + typeof(f.elements[i].FOCUSIT) + "]");
			if (typeof(f.elements[i].FOCUSIT) != "undefined") {
				f.elements[i].focus();
				return;
			}
		}
	}
	catch(e) {
		this.log(291, "e.number=[" + e.number + "]");
	}
}

FormUtil.prototype.log = function(nNum, msg) {
	if (typeof(logger) == "object")
		logger.log("FormUtil#" + nNum + " " + msg);
}

/*
 * 2005.04.29
 */
FormUtil.prototype.checkForm = function(f) {
	var els = f.elements;
	var el;
	
	for (var i = 0; i < els.length; i++) {
		el = els[i];
		try {
			if (typeof(el.checkNull) == "string") {
                if (typeof(el.whenNN) == "string") {
                    if (els[el.whenNN].value != '' && this.checkNull(el, el.checkNull)) return false;
                }
                else if (typeof(el.whenNull) == "string") {	// Æ¯Á¤ÇÊµå°¡ ³ÎÀÏ °æ¿ì¿¡ ³ÎÃ¼Å©.2005.12.16
                    if (els[el.whenNull].value == '' && this.checkNull(el, el.checkNull)) return false;
                }
				else {
                    if (this.checkNull(el, el.checkNull)) return false;
                }
			}
			if (typeof(el.checkSize) == "string") {
                var msg = el.checkSize.replace("#MIN", el.minLength).replace("#MAX", el.maxLength);
				if (typeof(el.whenNN) == "string") {
                    if (els[el.whenNN].value != '' 
                        && this.checkSize(el, el.minLength, el.maxLength, msg)) return false;
                }
				else {
                    if (this.checkSize(el, el.minLength, el.maxLength, msg)) return false;
                }
			}
			if (typeof(el.checkPattern) == "string") {
				if (this.checkPattern(el, el.pattern, el.checkPattern)) return false;
			}
			if (typeof(el.checkCustom) == "string") {
				if (eval(el.checkCustom + "(el)")) return false;
			}
			if (typeof(el.checkSame) == "string" && els[el.sameWith].value != '') {
				if (this.checkSame(els[el.sameWith], el, el.checkSame)) return false;
			}
		}
		catch(e) {
			this.log(297, e.message);
			return false;
		}
	}
	
	return true;
}

FormUtil.prototype.nextFocus = function(o, o2) {
	if (o.value.length >= o.maxLength) {
		o2.focus();
	}
}

FormUtil.prototype.initForm = function(f) {
	var els = f.elements;
	var el;
	
	for (var i = 0; i < els.length; i++) {
		el = els[i];
		this.log(346, "el.tagName=[" + el.tagName + "], el.name=[" + el.name + "]");
		if (el.type == "radio" && el.DB != "undefined") {	// ¶óµð¿À ¹öÆ° Ã³¸®
			this.log(347, "el.DB=[" + el.DB + "]");
			this.log(348, "el.DB.toLowerCase()=[" + el.DB.toLowerCase() + "]");
			
			if (el.DB.toLowerCase() == 'true') {
				el.DB = '1';
			}
			else if (el.DB.toLowerCase() == 'false') {
				el.DB = '0';
			}
			el.checked = (el.DB == el.value);
		}
		else if (el.tagName == "INPUT") {
			if (typeof(el.tran) == "string") {
				eval(el.tran + "(el)");
			}
		}
		else if (el.tagName == "SELECT") {
			if (typeof(el.DB) == "string") {
				this.log(366, "el.options.length=[" + el.options.length + "]");
				for (var i = 0; i < el.options.length; i++) {
					this.log(368, "i=[" + i + "]");
					if (el.options[i].value == el.DB) {
						el.options[i].selected = true;
						break;
					}
				}
			}
		}
	}
}

FormUtil.prototype.initForm2 = function() {
	switch (arguments.length) {
	case 4:
		this.cmmInitForm2(arguments[0], arguments[1], arguments[2], arguments[3]);
		break;
	case 2:
		this.cmmInitForm2(arguments[0], arguments[1], null, null);
		break;
	case 1:
		this.initForm(arguments[0]);
		break;
	}
}

/*
 * @param form object °ªÀÌ µé¾î°¥ Æû °´Ã¼
 * @param Data object Æû¿¡ Àû¿ëÇÒ °ªÀ» °¡Áø °´Ã¼
 * @param DIV object °ª ¹Ý¿µ½Ã º¸¿©Áú Æû
 * @param DIV object °ª ¹Ì ¹Ý¿µ½Ã º¸¿©Áú Æû
 */
FormUtil.prototype.cmmInitForm2 = function(f, data, RECORD, NO_RECORD) {
	var isNoRecords = true;
	var el = null;
	var j = 0;	// ArrayÀÇ ÀÎµ¦½º °ª
	var pname = null;	// ÀÌÀü ÀÌ¸§
	
	with(f) {
		with(elements){
			for (var i = 0; i < length; i++){
				el = elements[i];
				if(typeof(el.name) == "string"){
					if (pname != el.name) {
						j = 0;
					}
					switch(el.type) {
					case 'radio':
						if (typeof(data[el.name]) != "undefined")
							el.checked = (data[el.name] == el.value);
						break;
					default:
						if (data[el.name] instanceof Array){
							//alert(el.name + ":" + j + ":" + data[el.name][j]);
							el.value = data[el.name][j++];
						}
						else if (typeof(data[el.name]) != "undefined")
							el.value = data[el.name];
					}
					isNoRecords = false;
					pname = el.name;
				};
			}
		}
	}
	if (RECORD != null)
		RECORD.style.display = (isNoRecords)?'none':'';
	if (NO_RECORD != null)
		NO_RECORD.style.display = (isNoRecords)?'':'none';
}

FormUtil.prototype.autoFocus = function(o1, o2) {
    if (o1.value.length == o1.maxLength) {
		o2.focus();
	}
}

/*
 * ¸®½ºÆ®¿¡¼­ ¼±ÅÃµÈ ´ë»óÀ» À§·Î ÀÌµ¿½ÃÅ²´Ù.
 * @param oselect ¸®½ºÆ®°´Ã¼
 * @rel swapOption(o1, o2)
 * @dependency 1
 */
FormUtil.prototype.up = function(oselect) {
	if (oselect.selectedIndex < 0) {
		alert("ÀÌµ¿ÇÒ ´ë»óÀ» ¼±ÅÃÇÏ¼¼¿ä.");
	}
	else if (oselect.selectedIndex == 0) {
		alert("ÀÌµ¿ ÇÒ ¼ö ¾ø½À´Ï´Ù.");
	}
	else {
		for (var i = 1; i < oselect.options.length; i++) {
			if (oselect.options[i].selected) {
				this.swapOption(oselect.options[i], oselect.options[i - 1]);	// depend
				oselect.options[i - 1].selected = true;
				oselect.options[i].selected = false;
			}
		}
	}
}

/*
 * ¸®½ºÆ®¿¡¼­ ¼±ÅÃµÈ ´ë»óÀ» ¾Æ·¡·Î ÀÌµ¿½ÃÅ²´Ù.
 * @param oselect ¸®½ºÆ®°´Ã¼
 * @rel swapOption(o1, o2)
 * @dependency 1
 */
FormUtil.prototype.down = function(oselect) {
	if (oselect.selectedIndex < 0) {
		alert("ÀÌµ¿ÇÒ ´ë»óÀ» ¼±ÅÃÇÏ¼¼¿ä.");
	}
	else if (oselect.selectedIndex == oselect.options.length - 1) {
		alert("ÀÌµ¿ ÇÒ ¼ö ¾ø½À´Ï´Ù.");
	}
	else {
		for (var i = oselect.options.length - 1; i >= 0; i--) {
			if (oselect.options[i].selected) {
				this.swapOption(oselect.options[i], oselect.options[i + 1]); // depend
				oselect.options[i + 1].selected = true;
				oselect.options[i].selected = false;
			}
		}
	}
}

/*
 * ¸®½ºÆ®¿¡¼­ µÎ ¿É¼ÇÀÇ À§Ä¡¸¦ ¹Ù²Û´Ù.
 * @param o1
 * @param o2
 * @dependency 0
 */
FormUtil.prototype.swapOption = function(o1, o2) {
	var text = o1.text;
	var value = o1.value;
	o1.text = o2.text;
	o1.value = o2.value;
	o2.text = text;
	o2.value = value;
}

// -->
