/**
 * mplus_common
 */
var mplus_common = function(){
	
	mcare_mobile.call(this);
	var self = this;
	
	this.init = function(){
		addEvent();
	};
	var addEvent = function(){
		$('#btnSaveSetting').on('click', function(){
			changeSetting();
		});
		$('#logoutBtn').on('click', function(){
			logout();
		});
		$("#settingBtn").on('click', function(){
			initSetting();
		})
	};
	
	var initSetting = function(){
		if(indexPage!=null&&indexPage!=""){
			$(':input:radio[name=settingRadio][value="'+indexPage+'"]').prop("checked", "true");
		}else{
			$(':input:radio[name=settingRadio][value="I"]').prop("checked", "true");
		};
		$('#settingModal').modal('show');
	};
	
	var changeSetting = function(){
		/*외래: O 입원: I 응급: E 수술: P*/
		self.confirm("로그인 후 초기화면이 ["+$(":input:radio[name=settingRadio]:checked")[0].attributes.settingTab.value+"] 화면으로 설정됩니다.\n계속 진행하시겠습니까?", function(confirm){
			if(confirm){
				$.ajax ({
					 url : contextPath + '/mobile/user/userinfo/updateUserSetup.json',
					 type : 'POST', 
					 contentType: 'application/json', 
					 data: JSON.stringify({status: $(":input:radio[name=settingRadio]:checked").val()}),
					 success: function(result){
						 if(result.result.status==$("input:radio[name=settingRadio]:checked").val()){
							 indexPage = $("input:radio[name=settingRadio]:checked").val();
							 self.alert("저장되었습니다.");
						 }else{
							 self.alert("실패했습니다.");
						 }
					 }
				 })
				$('#settingModal').modal('hide');
			}
		})
	};
	
	var logout = function(){
		self.confirm("로그아웃 하시겠습니까?", function(callback){
			if(callback){
				self.changePage( contextPath + "/logout.page" );
			}
		});
	};
};