
if ("undefined" == typeof bugs) bugs = {};
	
bugs.login = {
	initGnb : function() {
		bugs.login.init("frmLoginGnb", 
			jQuery("#frmLoginGnb button.btnLogin"), jQuery("p input"), 
			"inputID", "inputPW", "focus", "focus", "endInput");
		bugs.login.initLogged();
	},
	initPopup : function() {
		bugs.login.init("frmLoginPopup", 
			jQuery("#frmLoginPopup button.btnLogin"), jQuery(".enterIDPW input"), 
			"default", "default", "focus", "focus", "focus");
	},
	initCp : function() {
		bugs.login.init("frmLoginCp", 
			jQuery("#frmLoginCp button.btnLogin"), jQuery("p input"), 
			"inputID", "inputPW", "focus", "focus", "endInput");
	},
	initLogged : function() {
		$(".myInfo .layerMyInfo .infoB .cash .btn").click(buyCash);
	}, 
	init : function(formId, submitButton, inputs, 
			defaultInputClass, defaultPasswdClass, focusInputClass, focusPasswdClass, endInputClass) {
		var _form  = jQuery("#" + formId);
		var userId = jQuery("input[name=user_id]", _form);
		if(!bugs.login.empty(userId.val())) userId.addClass(endInputClass);
	
		var passWd = jQuery("input[name=passwd]", _form);;
		if(!bugs.login.empty(passWd.val())) passWd.addClass(endInputClass);

		passWd.keypress(function(event) {
			if(event.keyCode == 13) {
				bugs.login.submit(_form, userId, passWd);
			}
		});
		
		inputs.each(function(idx) {
			jQuery(this).bind("focus", function(event) {
				var className;
				if(idx == 0) {
					jQuery(event.target).removeClass(endInputClass);
					jQuery(event.target).addClass(focusInputClass);
				} else if(idx == 1) {
					jQuery(event.target).removeClass(endInputClass);
					jQuery(event.target).addClass(focusPasswdClass);
				}
			}).bind("blur", function(event) {
				if(!bugs.login.empty(this.value)) {
					jQuery(event.target).addClass(endInputClass);
				} else {
					if(idx == 0) {
						jQuery(event.target).removeClass(focusInputClass);							
						jQuery(event.target).addClass(defaultInputClass);
					} else if(idx == 1) {
						jQuery(event.target).removeClass(focusPasswdClass);
						jQuery(event.target).addClass(defaultPasswdClass);
					}
				}
			});
		});
		
		if(jQuery("#keepUid", _form).length > 0) {
			jQuery("#keepUid", _form).click(function() {
				if (jQuery(this).is(":checked")) {
					bugs.login.alert("<p><strong>현재 사용하시는 PC에<br />아이디를 저장하시겠습니까?</strong></p>" +
							"<p>PC방 등 공공장소에서는 개인정보가<br />유출될 수있으니 주의해 주시기 바랍니다.</p>", 
							{css : "layerLoginMsg"});
				}
			});
		}
		submitButton.click(function(event) {
			bugs.login.submit(_form, userId, passWd);
		});
		//
		//jQuery("#frmLoginGnb button.btnLogin").click(function(event) {
		//	gnbLoginSubmit(_for, userId, passWd);
		//});
	}, 
	alert : function(text, option) {
		if(typeof bugs.ui.showAlert == "undefined") alert(text);
		else bugs.ui.showAlert(text, option);
	},
	empty : function(str) {
		if(typeof str == "string" && bugs.utils.trim(str).length > 0) 
			return false;
		return true;
	},
	submit : function(_form, userId, passWd) {
		if(bugs.login.empty(userId.val())) {
			bugs.login.alert("아이디를 입력해주세요!", {css : "layerLoginMsg", onOk : function() {
				userId.get(0).focus();
			}, onCancel : function() {
				userId.get(0).focus();
			}});
			return false;
		}
		if(bugs.login.empty(passWd.val())) {
			bugs.login.alert("비밀번호를 입력해주세요!", {css : "layerLoginMsg", onOk : function() {
				passWd.get(0).focus();
			}, onCancel : function() {
				passWd.get(0).focus();
			}});
			return false;
		}
		
		if(jQuery("#keepUid", _form).length > 0) {
			var oDate = new Date();
			if (jQuery("#keepUid", _form).is(":checked")) {
				oDate.setDate(oDate.getDate() + 30);	
				bugs.cookie.set("saveId", userId.val(), oDate, "/");
			} else {
				oDate.setDate(oDate.getDate() - 1);
				bugs.cookie.set("saveId", "", oDate, "/");
			}
		}
		var rUrl = jQuery("input[name=rUrl]", _form);
		if(bugs.login.empty(rUrl.val())) {
			//rUrl.val(g_urlBase);
			rUrl.val(document.location.href);
		}
		
		_form.submit();
	}
		
}