$.fn.extend({
	/**
	 * ÀÚµ¿ ÅÇ ÀÌµ¿
	 * $("input[name='mgr_tel2']").autoTab("input[name='mgr_tel3']"); 
	 */
	autoTab: function(destination) {
		$(this).keyup(function(event) {
			var maxLen = $(this).attr("maxlength");
			if ($(this).val().length >= maxLen) {
				$(destination).val("");
				$(destination).focus();
			}
		});
		return false;
	},
	/**
	 * ¼ýÀÚ¸¸ ÀÔ·Â
	 * $("input[name='mgr_tel2']").onlyNum();
	 */
	onlyNum: function() {
		$(this).css("ime-mode", "disabled");
		$(this).keypress(function(event) {
			var numPattern = /^[0-9]$/;
			var keyChar = String.fromCharCode(event.which);
			if (event.which != 13) {
				if (!numPattern.test(keyChar)) {
					return false;
				}
			}
		});
		return false;
	},
	/**
	 * ¿µ¹®¸¸ ÀÔ·Â
	 * $("input[name='mgr_engNm']").onlyEng();
	 */
	onlyEng: function() {
		$(this).css("ime-mode", "disabled");
		$(this).keypress(function(event) {
			var engPattern = /^[a-zA-Z]$/;
			var keyChar = String.fromCharCode(event.which);
			if (event.which != 13) {
				if (!engPattern.test(keyChar)) {
					return false;
				}
			}
		});
		return false;
	},
	/**
	 * ¿µ¹®, ¼ýÀÚ¸¸ ÀÔ·Â
	 * $("input[name='mgr_id']").onlyEngNum();
	 */
	onlyEngNum: function() {
		$(this).css("ime-mode", "disabled");
		$(this).keypress(function(event) {
			var engNumPattern = /^[a-zA-Z0-9]$/;
			var keyChar = String.fromCharCode(event.which);
			if (event.which != 13) {
				if (!engNumPattern.test(keyChar)) {
					return false;
				}
			}
		});
		return false;
	},
	/**
	 * checkbox¿¡ ´ëÇÑ ÀüÃ¼ Ã¼Å©/ÇØÁ¦
	 *
	 * @param destination  : Ã¼Å©/ÇØÁ¦ÀÇ ´ë»óÀÌ µÇ´Â selector
	 */
	checkedAll: function(destination) {
		$(this).click(function(event) {
			if ($(this).attr("checked") == true) {
				$(destination).attr("checked", "checked");
			} else {
				$(destination).attr("checked", "");
			}
		});
		return false;
	},
	/**
	 * °Ë»ö¾î Å¬¸¯ ½Ã ÀÚµ¿ »èÁ¦
	 * $("input[name='mgr_id']").delVal();
	 */
	delVal: function() {
		$(this).click(function(event) {
			$(this).val("");
		});
		return false;
	}
});

/**
 * Ã¹¹øÂ° ÅØ½ºÆ® ¹Ú½º¿¡ ÀÚµ¿ Æ÷Ä¿½º
 */
function initFocus() {
	$("input").each(function(i) {
		var val = $(this).val();
		if (val == null || val == "") {
			$(this).focus();
			return false;
		}
	});
}

/**
 * ¸ðµç ÅØ½ºÆ® ¹Ú½º¸¦ ÀÚµ¿ ÅÇ ÀÌµ¿
 */
function autoTabAll() {
	var maxLen;
	$("input[type='text']").each(function(i) {
		if ($(this).attr("maxlength") != undefined && $(this).attr("maxlength") != "") {
			$(this).keyup(function(event) {
				maxLen = $(this).attr('maxlength');
				if ($(this).val().length >= maxLen) {
					$("input[type='text']").eq((i + 1)).val("");
					$("input[type='text']").eq((i + 1)).focus();
				}
			});
		}
	});
}

/**
 * ÀÚµ¿ ¿µ¹®, ¼ýÀÚ¸¸ ÀÔ·Â 
 * 
 *  html ¼Ó¼º °ª : textType="num" ¼ýÀÚ¸¸
 *  html ¼Ó¼º °ª : textType="eng" ¿µ¹®¸¸
 *  html ¼Ó¼º °ª : textType="engNum" ¿µ¹® ¼ýÀÚ¸¸
 *  html ¼Ó¼º °ª : textType="numDot ¼ýÀÚ¿Í .¸¸(ÁÖ°Å¸éÀû¿ë)
 */
function textTypeAll() {
	$("input[type='text']").each(function(i) {
		var textType = $(this).attr("textType");
		var pattern;

		if (textType != undefined && textType != "") {
			if ($(this).attr("textType") == "eng") {
				pattern = /^[a-zA-Z]$/;
			} else if ($(this).attr("textType") == "engNum") {
				pattern = /^[a-zA-Z0-9]$/;
			} else if ($(this).attr("textType") == "email") {
				pattern = /^[a-zA-Z0-9._-]$/;
			} else if ($(this).attr("textType") == "numDot") {
				pattern = /^\d{0,5}(\.\d{0,2})?$/;
			} else {
				pattern = /^[0-9]$/;
			}

			$(this).css("ime-mode", "disabled");
			$(this).keypress(function(event) {
				var keyChar = String.fromCharCode(event.which);
				if (event.which != 13) {
					if (!pattern.test(keyChar)) {
						return false;
					}
				}
			});
		}
	});
}

/**
 * POST ¹æ½ÄÀ¸·Î ¸µÅ© °É±â
 * @param url : ¸µÅ© ÁÖ¼Ò
 * @param params : ÆÄ¶ó¹ÌÅÍ
 * @param target : Å¸°Ù(ÇÊ¼ö ¾Æ´Ô)
 *
 * postLink("http://naver.com", { aa: "aa", bb: "bb" }, "_blank");
 *
 */
function postLink(url, params, target) {
	var formHtml = "<form id='postLinkForm' name='postLinkForm' method='POST' action='"+url+"'>";
	if ( params.constructor == Array || params.jquery ) {
		jQuery.each(params, function() {
			formHtml += "<input type='hidden' name='"+this.name+"' value='"+this.value+"'>";
		});
	} else {
		for (var i in params) {
			if (params[i] && params[i].constructor == Array) {
				jQuery.each( params[i], function(){
					formHtml += "<input type='hidden' name='"+i+"' value='"+this+"'>";
				});
			} else {
				formHtml += "<input type='hidden' name='"+i+"' value='"+params[i]+"'>";
			}
		}
	}
	
	formHtml += "</form>";
	jQuery("body").append(formHtml);
	if (target != null && target != "") {
		document.postLinkForm.target = target;
	}
	$("#postLinkForm").submit();
}
