/**
 * mcare_mobile_login
 */
var mcare_mobile_login = function(){
	//상속
	mcare_mobile.call(this);
	//super
	var self = this;
	
	//변수
	 var $userId = $("#txtUserId"),
	 	 $passwd = $("#txtPasswd"),
         /*$rememberMe = $("#rememberMe"),*/
         $loginBtn = $("#loginBtn");
	
	var parameterMap = null;
	
	/**
	 * 초기화
	 */
	this.init = function(){
		/*initDeviceToken();*/
		addEvent();
	};
	/**
	 * 이벤트 등록
	 */
	var addEvent = function(){
		//로그인 버튼 클릭 이벤트
		$loginBtn.on( "click", function(e){
			loginSubmit();
		});
		
	};
	
	function loginSubmit() {
		if( $userId.val() === "" ) {
			self.alert( self.getI18n( "login005" ));
			$('#mplusAlert').on('hidden.bs.modal', function () {
			    $("#txtUserId").focus();
			});
	        return;
		};
		if( $passwd.val() === "" ) {
			self.alert( self.getI18n( "login006" ));
			$('#mplusAlert').on('hidden.bs.modal', function () {
				$("#txtPasswd").focus();
			});
	        return;
		};
		/*var $isAuto = $rememberMe.is(':checked') ? true : false;*/
		var param = {userId: $userId.val(),
				password: $passwd.val(),
				rememberMe: true};
		
		var result;
		
		$.ajax ({
			  url : contextPath + '/loginSubmit.json',
			  type : 'POST',
			  dataType: "json",
			  async: false,
			  data: param,
			  success: function(response){
				  if(response.msg) {
					  // 현재 로그인 error는 모두 LoginException으로 처리되기 때문에
					  // type 체크는 하지 않았습니다.
					  self.alert(response.msg);
					  return;
				  } else {
					  if(response.indexPage=='I'){
						  self.changePage( contextPath + "/mobile/consent/consentInpatient.page?menuId=inpatient&first" );
					  }else if(response.indexPage=='O'){
						  self.changePage( contextPath + "/mobile/consent/consentOutpatient.page?menuId=outpatient&first" );
					  }else if(response.indexPage=='E'){
						  self.changePage( contextPath + "/mobile/consent/consentEmergency.page?menuId=emergency&first" );
					  }else if(response.indexPage=='P'){
						  self.changePage( contextPath + "/mobile/consent/consentOperation.page?menuId=operation&first" );
					  }else{
						  self.changePage( contextPath + "/mobile/consent/consentInpatient.page?menuId=inpatient&first" );
					  }
				  }
			  }
		});
		
	}
	
	/**
	 * device token 설정
	 */
	var initDeviceToken = function(){
		var msg = {
				type : "command", 
				functionType : "token", 
				value : {
					callbackFn : "window.activeObj.getDeviceTokenCallBack"
				}
		}; 
		self.toNative( msg );
	};
	/**
	 * 
	 */
	this.getDeviceTokenCallBack = function(token, type){
		deviceToken = token; 
		certiType = type;
//		self.alert("token : " + token); 
	};
};