/*
	Made By KTS - superkts.pe.kr/af.html
*/

// AF °ü·Ã °¢Á¾ ¼³Á¤°ª
var AF_vars = {
	key:'',
	names:'',
	autoForm:'',		// ÀÚµ¿¼­ºê¹Ô Æû ÀÌ¸§
	modifyFields:'',	// ¼öÁ¤µÈ ÇÊµå
	passFields:'',		// °Ë»çÇÏÁö ¾ÊÀ» ÇÊµå ÁöÁ¤, ¿¹) AF_vars.passFields = 'title,contents,userid'
	errMsg:''			// ¿¡·¯ ¸Þ¼¼Áö
};

var AF_util = {
	frm:null,
	field:null,
	types:null,
	msg:null,
	splitText:', ',
	chk:new Array(),
	showError:true,

	// ** ÃÊ±âÈ­
	init:function(val1, val2){ // init('ÆûÀÌ¸§'|Æû°´Ã¼[,'ÇÊµå¸í'|ÇÊµå°´Ã¼])
		this.frm = AF_util.getForm(val1);
		if(this.frm == null)return;
		if(val2 != null){
			this.setField(val2);
			if(this.field == null)return;
		}
	},

	// * ÇÊµå °ª ¾ò±â
	getValue:function(val){ // getValue('ÇÊµå¸í'|ÇÊµå°´Ã¼)
		var values = '';
		if(val != null)this.setField(val);
		if(this.field == null)return null;
		this.getType();
		if(this.field.length > 0 && this.types != 'select-one'){
			for(var i=0 ; i<this.field.length ;i++){
				if(this.types == 'radio' || this.types == 'checkbox'){
					if(this.field[i].checked){
						values += this.field[i].value + this.splitText;
					}
				}else{
					values += this.field[i].value + this.splitText;
				}
			}
			var reg = eval('/'+ this.splitText +'$/g');
			values = values.replace(reg, '');
		}else{
			if(this.types == 'radio' || this.types == 'checkbox'){
				if(this.field.checked)values = this.field.value;
			}else{
				if(this.types == 'select-one'){
					values = this.field.options[this.field.selectedIndex].getAttribute('value');
					if(values == null)values = ''; // option ¿¡ value °¡ ¾øÀ»¶§ null À» °ø¹éÀ¸·Î º¯È¯ ÈÄ ¹ÝÈ¯
				}else{
					values = this.field.value;
				}
			}
		}
		return values;
	},

	// * ´ÙÁß ÇÊµå °ª ¾ò±â
	getValues:function(val){ // getValues('ÇÊµå1,ÇÊµå2,ÇÊµå3, ...') - ¹è¿­·Î ¹ÝÈ¯
		var tmp = '';
		var aTmp = new Array();
		var aVal = val.replace(/( )*,( )*/g, ',').split(',');
		for(var i=0 ; i<aVal.length ; i++){
			tmp = this.getValue(aVal[i]);
			if(tmp != '')aTmp.push(tmp);
		}
		return aTmp;
	},

	// * ÇÊµå ¿ÀºêÁ§Æ® ¾ò±â
	getObject:function(sField){ // getObject('ÇÊµå¸í'|ÇÊµå°´Ã¼)
		if(sField != null)this.setField(sField);
		return this.field;
	},

	// * ÇÊµå Å¸ÀÔ ¾ò±â
	getType:function(sField){ // getType('ÇÊµå¸í'|ÇÊµå°´Ã¼)
		if(sField != null)this.setField(sField);
		if(this.field.length > 1 && this.field.type != 'select-one'){
			this.types = this.field[0].type;
			return this.types;
		}
		else{
			this.types = this.field.type;
			return this.types;
		}
	},

	// * ÇÊµå ÁöÁ¤
	setField:function(val){ // setField('ÇÊµå¸í'|ÇÊµå°´Ã¼)
		if(typeof val == 'string'){
			this.field = this.frm.elements[val];

			if(val.match(/.+\[[0-9]+\]$/gi)){ // ¹è¿­Çü ÇÊµåÀÌ¸§ Ã³¸® - ¿¹) formname[0]
				var names  = val.replace(/\[[0-9]+\]$/gi, '');
				var indexs = val.replace(/^.+\[|]$/gi, '');

				if(this.frm.elements[names].length > 0 && this.frm.elements[names].type != 'select-one'){
					this.field = this.frm.elements[names][indexs];
				}else{ // ÇÊµå°¡ ÇÏ³ª¶ó¸é ..[0]À» ÀÏ¹Ý ÇÊµå·Î Ã³¸®ÇÔ..
					this.field = this.frm.elements[names];
				}
			}
		}else if(typeof val == 'object'){
			this.field = val;
		}

		if(typeof this.field != 'object'){
			this.field = null;
			if(this.showError){
				alert('AF_util.setField : ÁöÁ¤ÇÑ [ ' + val + ' ] ÇÊµå°¡ ¾ø½À´Ï´Ù');
				this.field		= null;
				this.showError	= true;
			}
		}
	},

	// * ÇÊµå °¹¼ö ¾ò±â, f = field
	//	°°Àº ÀÌ¸§ÀÇ ÇÊµå°¡ ¸î°³ Á¸ÀçÇÏ´ÂÁö ÆÄ¾ÇÇÑ´Ù.
	getCount:function(f){ // getCount('ÇÊµå¸í'|ÇÊµå°´Ã¼)
		if(f != null)this.setField(f);
		if(this.field.length > 1 && this.field.type != 'select-one'){
			return this.field.length;
		}
		else{
			return 1;
		}
	},

	// * °°Àº ÀÌ¸§ÀÇ ÇÊµåÀÏ¶§ ¼ø¼­(index) ¾ò±â, 0 ºÎÅÍ ½ÃÀÛ
	//	¾ò°íÀÚ ÇÏ´Â ÇÊµå°´Ã¼¸¦ º¸³»¾ß ÇÑ´Ù.
	getIndex:function(f){ // getIndex(ÇÊµå°´Ã¼)
		var tmpObj = this.getObject(f);
		this.setField(f.name);
		var cnt = this.getCount();

		if(cnt == 1){
			return 0;
		}else{
			for(var i=0 ; i<cnt ; i++){
				if(this.field[i] == tmpObj){
					return i;
				}
			}
		}
	},


	// * ÄÞº¸¹Ú½º ¿É¼ÇÁö¿ì±â
	comboClear:function(n){ // comboClear([¼ýÀÚ]), comboClear([-1])
		var tmp = this.field.options.length;
		if(typeof n == 'number')tmp = tmp + n;
		for(var i=0 ; i<tmp ; i++)this.field.remove(this.field.options.length-1);
		this.field.selectedIndex = 0;
	},

	// * ÄÞº¸¹Ú½º ¿É¼ÇÃß°¡
	comboAdd:function(sVal, sText, sSelect){ // comboAdd('°ª','ÅØ½ºÆ®'[,'¼±ÅÃµÉ°ª'])
		var option   = new Option();
		option.value = sVal;
		option.text  = sText;

		if(sSelect != null){
			if(sVal == sSelect)option.selected = true;
		}
		this.field.options.add(option);
	},

	// * Ã¼Å© ÇÊµå ÀüÃ¼ ¼±ÅÃ
	checkAll:function(bool, val){ // checkAll(true|false[,'ÇÊµå¸í'|ÇÊµå°´Ã¼])
		try{
			if(val != null){
				this.setField(val);
			}
			var tmp = this.getLen();

			if(tmp == 0){
				this.field.checked = bool;
			}else{
				for(var i=0; i<tmp ; i++){
					this.field[i].checked = bool;
				}
			}
		}catch(e){}
	},

	// * ¼¿·ºÆ® ÇÊµå ÀüÃ¼ ¼±ÅÃ (¸ÖÆ¼¼¿·ºÆ®)
	selectAll:function(bool, val){ // selectAll(true|false[, 'ÇÊµå¸í'|ÇÊµå°´Ã¼])
		try{
			if(val != null){
				this.setField(val);
			}

			var tmp = this.getLen();
			for(var i=0; i<tmp ; i++){
				this.field[i].selected = bool;
			}
		}catch(e){}
	},

	// * Ã¼Å©¹Ú½º ¼±ÅÃ ¼ö ¼¼±â
	checkCnt:function(bool, val){ // checkCnt(true|false[,'ÇÊµå¸í'|ÇÊµå°´Ã¼])
		if(val != null){
			this.setField(val);
		}

		var cnt = 0;
		var tmp = this.getLen();

		if(tmp == 0){
			if(this.field.checked == bool)cnt++;
		}else{
			for(var i=0; i<tmp ; i++){
				if(this.field[i].checked == bool)cnt++;
			}
		}
		return cnt;
	},

	// * Æû °´Ã¼ ¾ò±â
	getForm:function(val){ // getForm('ÆûÀÌ¸§'|Æû°´Ã¼)
		var tmp;

		if(typeof val == 'string'){
			tmp = document.forms[val];
		}else if(typeof val == 'object'){
			tmp = val;
		}

		if(typeof tmp == 'object' && tmp.tagName == 'FORM'){
			return tmp;
		}else{
			alert('AF_util.getForm : ÁöÁ¤ÇÑ form ÀÌ ¾ø½À´Ï´Ù');
			return null;
		}
	},

	// * Æ¯Á¤ ¹®ÀÚ¿­À» AF Ã³¸®°¡ °¡´ÉÇÏ°Ô º¯È¯ ..
	getEval:function(val){
		var tmp = val;
		tmp = tmp.replace(/{{([a-z0-9_\[\]]+)}}\s*\=([^=])/gi, "AF_util.getObject('$1').value=$2");	// {{ÇÊµå¸í}}= : ÇØ´ç ÇÊµå¿¡ °ª ³Ö±â
		tmp = tmp.replace(/{{([a-z0-9_\[\]]+)}}/gi, "AF_util.getValue('$1')");						// {{ÇÊµå¸í}}  : ÇØ´ç ÇÊµåÀÇ °ª ¾ò±â
		tmp = tmp.replace(/{([a-z0-9_\[\]]+)}/gi, "AF_util.getObject('$1')");						// {ÇÊµå¸í}    : ÇØ´ç ÇÊµåÀÇ °´Ã¼ ¾ò±â
		tmp = tmp.replace(/this\./gi, 'obj.');														// this.       : this Ã³¸®
		return tmp;
	},

	getLen:function(){ // ÇÊµå ±æÀÌ ¾ò±â
		if(this.field.length > 0)return this.field.length;
		else return 0;
	},

	getCharLen:function(val, mode){ // ±ÛÀÚ¼ö È®ÀÎ
		var ch = '';
		var bytes = 0;

		for (var i=0; i<val.length; i++){
			ch = val.charAt(i);

			if(mode == 'han' && escape(ch).length > 4){
				bytes += 2;
			}else if (ch == '\n'){
				bytes += 1;
				if(val.charAt(i-1) != '\r'){
					bytes += 1;
				}
			}else{
				bytes += 1;
			}
		}
		return bytes;
	},

	haveBlank:function(sVal){ // °ø¹é Á¸Àç È®ÀÎ
		var tmp = sVal;
		if(tmp.match(/ |¡¡/g))return true;
		else return false;
	},

	removeHan:function(sVal){ // ÇÑ±Û Á¦°Å
		return sVal.replace(/[¤¡-ÆR]| /g, '');
	},
	removeEng:function(sVal){ // ¿µ¹® Á¦°Å
		return sVal.replace(/[a-z]| /gi, '');
	},
	removeBlank:function(sVal){ // °ø¹é, Æ¯¼ö¹®ÀÚ°ø¹é, ÁÙ¹Ù²ÞÁ¦°Å
		return sVal.replace(/\s|¡¡/gi, '');
	},

	isEmpty:function(sVal){ // °ªÀÌ ºñ¾îÀÖ³ª È®ÀÎ
		var tmp = this.removeBlank(sVal);
		if(tmp == '')return true;
		else return false;
	},
	isNum:function(sVal){ // ¼ýÀÚ ¿©ºÎ
		var tmp = sVal.replace(/[0-9]/g, '');
		if(tmp == '')return true;
		else return false;
	},
	isHan:function(sVal){ // ÇÑ±Û ¿©ºÎ
		var tmp = this.removeHan(sVal);
		if(tmp == '')return true;
		else return false;
	},
	isEng:function(sVal){ // ¿µ¹® ¿©ºÎ
		var tmp = this.removeEng(sVal);
		if(tmp == '')return true;
		else return false;
	}
};


function AF_srch_key(srch){
	var tmp = eval('/' + srch + '/gi');
	if(srch == '' && AF_util.chk[0] == ''){
		return true;
	}else if(srch != ''){
		for(var i=0 ; i<AF_util.chk.length; i++){
			if(AF_util.chk[i].replace(/ /g,'').match(tmp)){
				AF_vars.key = AF_util.chk[i];
				return true;
				break;
			}
		}
	}
	return false;
}


function AF_set_chkArr(vals){
	if(!vals.match(/\|/g)){
		vals += '|xx';
	}

	var tmp = vals.split('|');
	AF_util.msg = tmp[1];

	if(!tmp[0].match(/,/g)){
		tmp[0] += ',';
	}

	tmp[0] = tmp[0].replace(/,$/g, '');
	AF_util.chk = tmp[0].split(',');
}

// * Æû Ã¼Å©±â																																																															'

function AF_check(targetForm){ // AF_check(Æû°´Ã¼|'ÆûÀÌ¸§')

	var frm = AF_util.getForm(targetForm);

	if(frm == null)return false;

	AF_util.init(frm);
	AF_vars.errMsg		= ''; // ¿¡·¯¸Þ¼¼Áö ÃÊ±âÈ­

	var check			= true;
	var chk1			= 0;
	var chk2			= 0;
	var chkString		= '';
	var focusElements	= '';
	var isContinue		= true;
	var isOk			= 'Y';
	var names			= '';
	var passFields		= ',' + AF_vars.passFields.replace(/ /gi, '') + ',';
	var tmp1			= '';
	var tmp2			= '';
	var tmp3			= '';
	var tmpArr			= new Array();
	var types			= '';
	var values			= '';
	var obj;

	for(var i=0; i<frm.length ; i++){
		focusElements	= '';
		obj				= frm.elements[i];

		if(obj.getAttribute('chk') != null){
			types			= obj.type;
			names			= obj.name;
			values			= AF_util.getValue(obj);
			chkString		= obj.getAttribute('chk');
			AF_vars.names	= names;

			if(passFields != ''){
				if(passFields.indexOf(',' + names + ',') == -1){
					check = true;
				}else{
					check = false;
				}
			}

			// Æû Ã¼Å© ½ÃÀÛ (chk ¼Ó¼ºÀÌ Á¸ÀçÇÏ¿©¾ß ¾Æ·¡ ÄÚµåµéÀÌ ½ÇÇàµÈ´Ù)
			// exec, if µîÀÇ ¼Ó¼º¸¸ ÀÖ°í chk ¼Ó¼ºÀÌ ¾ø´Ù¸é ½ÇÇàµÇÁö ¾Ê´Â´Ù.
			if(check){

				// exec
				// Æû Ã¼Å©½Ã ÁöÁ¤ÇÑ ½ºÅ©¸³Æ® ½ÇÇà
				// Æû Ã¼Å©°¡ ½ÃÀÛµÇ¾úÀ»¶§ exec ¼Ó¼ºÀÇ ³»¿ëÀ» Á¦ÀÏ ¸ÕÀú ½ÇÇàÇÑ´Ù.
				// exec ¼Ó¼ºÀÇ °ªÀ¸·Î ÀÚ¹Ù½ºÅ©¸³Æ® ¸í·ÉÀ» ÀÔ·ÂÇÏ¸é ½ÇÇàÀÌ °¡´ÉÇÏ´Ù.
				// ÀûÀýÇÑ »ç¿ëÀ¸·Î Æ®¸®°Å È¿°ú¸¦ ±¸ÇöÇÒ ¼ö ÀÖ´Ù.
				// ¿¹) exec="{ÇÊµå¸í}.value='°ª'" µî È°¿ë °¡´É
				tmp1 = obj.getAttribute('exec');
				if(tmp1 != null){
					try{
						var execStr = AF_util.getEval(tmp1);
						eval(execStr);
						values = AF_util.getValue(obj); // exec ·Î ÇöÀç ÇÊµå°ªÀ» º¯°æÇÒ ¼ö ÀÖÀ¸¹Ç·Î °»½ÅÇÑ´Ù.
					}catch(e){alert('[AF_check °æ°í] - exec ±¸¹® ¿¡·¯\n\n\n¿øº» : ' +  tmp1 + '\n\nº¯È¯ : ' + execStr);return false}
				}

				// if
				// Á¦ÇÑ Á¶°Ç IF ºñ±³ (ÀÌ Á¶°Ç¿¡ °É¸®¸é ÇØ´ç ÇÊµå´Â 'ÇÊ¼ö' Ã¼Å© È¿°ú)
				// ¿¹) if="{ÇÊµå¸í}=='xx'" - if() ¾È¿¡ µé¾î°¥ ±¸¹®¸¸ ½áÁÜ
				tmp1 = obj.getAttribute('if');
				if(tmp1 != null){
					try{
						var ifStr = AF_util.getEval(tmp1);
						if(eval(ifStr)){
							chkString = 'ÇÊ¼ö,' + chkString;
						}
					}catch(e){alert('[AF_check °æ°í] - if ±¸¹® ¿¡·¯\n\n\n¿øº» : ' +  tmp1 + '\n\nº¯È¯ : ' + ifStr);return false}
				}

				// case
				// Á¦ÇÑ Á¶°Ç ºñ±³ - case (if »ç¿ë ±ÇÀå)
				// ÀÌ°ÍÀº »ç¿ëÇÏÁö ¾Ê±â¸¦ ¹Ù¶õ´Ù. -_-;
				if(obj.getAttribute('case') != null){
					try{
					tmp3 = obj.getAttribute('case');
						if(tmp3.match(/!=/gi) && !tmp3.match(/==/gi)){

							tmpArr = tmp3.split('!=');
							if(AF_util.getValue(tmpArr[0]) != tmpArr[1] + '')chkString = 'ÇÊ¼ö,' + chkString;
							else if(AF_util.getValue(obj) != ''){chkString = 'ÇÊ¼ö,' + chkString;focusElements=tmpArr[0];isContinue=false;chk2++}

						}else if(tmp3.match(/^.+==.+=.+$/gi) && !tmp3.match(/!=/gi)){

							tmpArr = tmp3.split('==');
							var tmpArr2 = tmpArr[1].split('=');
							if(eval('AF_util.getObject(tmpArr[0]).' + tmpArr2[0]) == eval(tmpArr2[1]))chkString = 'ÇÊ¼ö,' + chkString;
							else if(AF_util.getValue(obj) != ''){chkString = 'ÇÊ¼ö,' + chkString;focusElements=tmpArr[0];isContinue=false;chk2++}

						}else if(tmp3.match(/^.+==.+!=.+$/gi)){

							tmpArr = tmp3.split('==');
							var tmpArr2 = tmpArr[1].split('!=');
							if(eval('AF_util.getObject(tmpArr[0]).' + tmpArr2[0]) != eval(tmpArr2[1]))chkString = 'ÇÊ¼ö,' + chkString;
							else if(AF_util.getValue(obj) != ''){chkString = 'ÇÊ¼ö,' + chkString;focusElements=tmpArr[0];isContinue=false;chk2++}

						}else if(tmp3.match(/=/gi)){

							tmpArr = tmp3.split('=');
							if(AF_util.getValue(tmpArr[0]) == tmpArr[1])chkString = 'ÇÊ¼ö,' + chkString;
							else if(AF_util.getValue(obj) != ''){chkString = 'ÇÊ¼ö,' + chkString;focusElements=tmpArr[0];isContinue=false;chk2++}

						}
					}catch(e){alert(e + tmpArr[0] + ' ¾øÀ½');isContinue = false;chk2++}
				}

				// func
				// ÇÔ¼ö·Î °ª °ËÁõ
				// ¿¹) func="functionName(°ª)" - true, false ¸¦ ¹ÝÈ¯ÇÏ´Â ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© °ËÁõ
				// ¿¹2) func="functionName({{ÇÊµå¸í}})", func="functionName({ÇÊµå¸í}.value)"
				tmp1 = obj.getAttribute('func');
				if(tmp1 != null && (AF_srch_key('ÇÊ¼ö') || !AF_util.isEmpty(values))){
					try{
						chk1++;
						var funcStr = AF_util.getEval(tmp1);
						if(eval(funcStr)){
							chk2++;
						}else{
							isContinue = false;
						}
					}catch(e){alert('[AF_check °æ°í] - func ±¸¹® ¿¡·¯\n\n\n¿øº» : ' +  tmp1 + '\n\nº¯È¯ : ' + funcStr);return false}
				}

				AF_set_chkArr(chkString);

				if(isContinue && AF_srch_key('')){ // ¼±ÅÃÇü (°ø¹é ÀÔ·Â¸¸ ¹æÁö)
					if(types == 'text' || types == 'textarea' || types == 'file'){
						chk1++;
						if(values != '' && AF_util.removeBlank(values) == '')isContinue = false;
						else chk2++;
					}
				}

				// ÇÊ¼ö ÀÏ¶§ ºñ±³
				if(isContinue && AF_srch_key('ÇÊ¼ö')){ // ÇÊ¼ö
					chk1++;
					if(types == 'text' || types == 'textarea' || types == 'hidden' || types == 'password' || types == 'file'){
						if(!AF_util.isEmpty(values))chk2++;
						else isContinue = false;
					}
					else if(types == 'radio' || types == 'checkbox'){
						if(frm.elements[names].length > 0){
							for(var j=0 ; j<frm.elements[names].length ; j++){
								if(frm.elements[names][j].checked == true){chk2++;break}
							}
						}
						else{
							if(frm.elements[names].checked == true)chk2++;
						}
					}
					else if(types == 'select-one'){
						if(obj.selectedIndex > 0)chk2++;
						else isContinue = false;
					}
				}

				// Á¤±Ô½Ä ºñ±³
				if(isContinue && AF_srch_key('Á¤±Ô') && values != ''){
					chk1++;
					if(types == 'text' || types == 'textarea' || types == 'hidden' || types == 'password' || types == 'file'){
						if(obj.getAttribute('regexp') != null){
							try{
								tmp1 = eval(obj.getAttribute('regexp'));
							}catch(e){alert('[AF_check °æ°í]\n\nÁ¤±Ô½ÄÀÌ Àß¸øµÇ¾ú½À´Ï´Ù\n\n* NAME : ' + names + '\n* TYPE : '+ types +'\n\nÁ¤±Ô½Ä : ' + obj.getAttribute('regexp') + '\n\n¡æ /Á¤±Ô½Ä/gi');return false;}
							if(values.match(tmp1))chk2++;
							else isContinue = false;
						}
					}
				}
				// ¼ýÀÚ¸¸ Çã¿ë ÀÏ¶§
				if(isContinue && AF_srch_key('¼ýÀÚ')){ // ¼ýÀÚ
					chk1++;
					if(types == 'text' || types == 'textarea' || types == 'hidden' || types == 'password'){
						if(AF_util.isNum(values))chk2++;
						else isContinue = false;
					}
				}
				// ¿µ¹®¸¸ Çã¿ë ÀÏ¶§
				if(isContinue && AF_srch_key('¿µ¾î|¿µ¹®|¾ËÆÄºª')){ // ¿µ¾î, ¿µ¹®, ¾ËÆÄºª
					chk1++;
					if(types == 'text' || types == 'textarea' || types == 'hidden' || types == 'password'){
						if(AF_util.isEng(values))chk2++;
						else isContinue = false;
					}
				}
				// °ø¹é Æ÷ÇÔ ºÒ°¡ ÀÏ¶§
				if(isContinue && AF_srch_key('°ø¹é|¶ç¾î¾²±â')){ // °ø¹é
					chk1++;
					if(types == 'text' || types == 'textarea' || types == 'hidden'  || types == 'password'){
						if(!AF_util.haveBlank(values))chk2++;
						else isContinue = false;
					}
				}
				// n ÀÚ ÀÌ»óÀÏ¶§
				if(isContinue && AF_srch_key('[0-9]ÀÚÀÌ»ó') && values != ''){ // nÀÚ ÀÌ»ó
					chk1++;
					tmp2 = parseInt(AF_util.removeHan(AF_vars.key));
					if(AF_vars.key.match(/ÇÑ±Û/g)){
						tmp1 = 'han';
						tmp2 *= 2;
					}
					if(types == 'text' || types == 'textarea' || types == 'hidden' || types == 'password'){
						if(AF_util.getCharLen(values, tmp1) >= tmp2 )chk2++;
						else isContinue = false;
					}
				}
				// n ÀÚ ÀÌÇÏÀÏ¶§
				if(isContinue && AF_srch_key('[0-9]ÀÚÀÌÇÏ') && values != ''){ // nÀÚ ÀÌÇÏ
					chk1++;
					tmp2 = parseInt(AF_util.removeHan(AF_vars.key));
					if(AF_vars.key.match(/ÇÑ±Û/g)){
						tmp1 = 'han';
						tmp2 *= 2;
					}
					if(types == 'text' || types == 'textarea' || types == 'hidden' || types == 'password'){
						if(AF_util.getCharLen(values, tmp1) <= tmp2 )chk2++;
						else isContinue = false;
					}
				}
				// n ÀÚ ÀÔ·Â
				if(isContinue && AF_srch_key('[0-9]ÀÚÀÔ·Â') && values != ''){ // nÀÚ ÀÔ·Â
					chk1++;
					tmp2 = parseInt(AF_util.removeHan(AF_vars.key));
					if(AF_vars.key.match(/ÇÑ±Û/g)){
						tmp1 = 'han';
						tmp2 *= 2;
					}
					if(types == 'text' || types == 'textarea' || types == 'hidden' || types == 'password'){
						if(AF_util.getCharLen(values, tmp1) == tmp2 )chk2++;
						else isContinue = false;
					}
				}

				// Á¦ÇÑ Á¶°Ç¿¡ °É·ÈÀ» °æ¿ì Ã³¸®
				if(chk1 != chk2){
					if(AF_vars.errMsg == ''){
						AF_vars.errMsg = AF_util.msg.replace(/XX/gi,AF_vars.key);
						AF_vars.errMsg = AF_vars.errMsg.replace(/\\n/gi, '\n');
					}
					alert(AF_vars.errMsg);
					try{
						if(focusElements == '')obj.focus();
						else frm.elements[focusElements].focus();
					}catch(e){}
					isOk = 'N';
					break;
				}
			}
		}
	} // End For
	if(isOk == 'Y')return true;
	else if(isOk == 'N')return false;
}


// * ºñ±³Æû »ý¼º																																								'

function AF_formCreate(){
	var rnd = Math.round(Math.random()*100000);
	AF_vars.autoForm = 'autoSubmit_' + rnd;
	document.writeln('<form name="' + AF_vars.autoForm + '" method="get" action="" style="display:none">');
	document.writeln('</form>');
}

// * ºñ±³¿ë Æû º¹»ç
function AF_copyForm(val){ // AF_copyForm('ÆûÀÌ¸§'|Æû°´Ã¼)
	AF_formCreate();
	var frm		= AF_util.getForm(AF_vars.autoForm);
	var frm2	= AF_util.getForm(val);
	var names	= '';
	var values	= '';
	var types	= '';
	var newElement;

	if(frm2 == null){
		alert('[AF_copyForm °æ°í]\n\nº¹»ç ÇÒ formÀÌ ¾ø½À´Ï´Ù.');
		return;
	}

	for(var i = 0 ; i<frm2.length ; i++){
		names			= frm2.elements[i].name;
		values			= frm2.elements[i].value;
		types			= frm2.elements[i].type;
		newElement		= document.createElement('textarea');
		newElement.name	= names;

		if(types == 'radio' || types == 'checkbox'){
			if(frm2.elements[i].checked == true)newElement.value = 'true';
			else if(frm2.elements[i].checked == false)newElement.value = 'false';
		}else newElement.value = values;

		frm.appendChild(newElement);
	}
}

// * ¹Ù²ï ³»¿ë ºñ±³
function AF_formCompare(val){ // AF_formCompare('ÆûÀÌ¸§'|Æû°´Ã¼)
	var oriForm		= AF_util.getForm(val); // ¿øº» Æû
	var copyForm	= AF_util.getForm(AF_vars.autoForm); // º¹»çµÈ Æû
	var tmpArr;
	var tmp1		= '';
	var oriName		= '';
	var oriValue	= '';
	var oriType		= '';
	var copyName	= '';
	var copyValue	= '';
	var deleteFieldIdx		= '';
	var errMsg				= '[AF_copyForm °æ°í]\n\n';
	AF_vars.modifyFields	= '';

	if(oriForm == null){
		alert(errMsg + ' ÆûÀÌ ÀÖ´ÂÁö È®ÀÎÇØº¸¼¼¿ä');
		return false;
	}
	else if(copyForm == null){
		if(confirm(errMsg + ' ÆûÀ» º¹»çÇÒ ÆûÀÌ »ý¼ºµÇÁö ¾Ê¾Ò¾î¿ä\n\nAF_copyForm()À» ½ÇÇàÇß´ÂÁö È®ÀÎ!\n\n±×³É ÁøÇà ÇÒ±î¿ä?'))return true;
		return false;
	}


	try{
		for(var i=0 ; i<oriForm.length ; i++){
			oriName		= oriForm.elements[i].name;
			oriValue	= oriForm.elements[i].value;
			oriType		= oriForm.elements[i].type;
			copyName	= copyForm.elements[i].name;
			copyValue	= copyForm.elements[i].value;

			if(oriType == 'radio' || oriType == 'checkbox'){
				if(oriForm.elements[i].checked == true)oriValue = 'true';
				else if(oriForm.elements[i].checked == false)oriValue = 'false';
			}

			if(oriType == 'text' || oriType == 'textarea' || oriType == 'radio' || oriType == 'checkbox' || oriType == 'file' || oriType == 'select-one'){
				if(oriValue != copyValue && copyName != 'AF'){
					if(tmp1 != oriName)AF_vars.modifyFields += '|' + oriName;
					tmp1 = oriName;
				}else if(copyName != 'AF')deleteFieldIdx += '|' + i;
			}
		}

		AF_vars.modifyFields			= AF_vars.modifyFields.replace(/^\|/gi, '');
		deleteFieldIdx					= deleteFieldIdx.replace(/^\|/gi, '');
		oriForm.elements['AF'].value	= AF_vars.modifyFields;
		tmpArr = deleteFieldIdx.split('|');

	}catch(e){
		alert(errMsg + 'AF ¸¦ Æû¿¡ ³Ö¾îÁÖ¼¼¿ä');
		return false;
	}

	try{
		for(i=0 ; i<tmpArr.length ; i++){
			oriForm.elements[tmpArr[i]].removeAttribute('name');
		}
	}catch(e){}

	return true;
}

// * ÆûÀÇ °ª ¾ø´Â ÇÊµå 'ÀÌ¸§' ¾ø¾Ö±â																																			'

function AF_removeEmptyField(frm){ // AF_removeEmptyField('ÆûÀÌ¸§'|Æû°´Ã¼)
	AF_util.init(frm);

	for(var i=0 ; i<frm.length; i++){
		if(frm.elements[i].name != ''){
			if(AF_util.getValue(frm.elements[i]) == ''){
				frm.elements[i].removeAttribute('name');
			}
		}
	}
}
