
  var ok_top = new Vue({ // ok_top.member_info
  	name: 'OkTop',
    el: '#ok_member_top',
    delimiters: ['${', '}'],
    data: {
      try: 'tkchan',
      info: [],
      member_info:{
        id: readCookie("okibook_user_id"),
        firstname: readCookie("okibook_user_name"),
        lastname: '',
        token: readCookie("okibook_token"),
        status: readCookie("okibook_status"),
      },
      input:{
      },
      modelConfig: {
        type: '',
        mask: '', // Uses 'iso' if missing email', 'password
      }
    },
     methods:{
       checkHandler(){
        // console.log('mounted'+ this.member_info.id);
       },
        onResize() {
          this.windowHeight = window.innerHeight
          this.windowWidth = window.innerWidth
        },
       checkLoginHandler(){
       }
     },
      mounted () {
//        this.checkHandler(),
      },
      watch:{
        member_info : function(){
          if(this.member_info.status == 'in'){
//             ok_hiddenpopup();
          }
            // console.log('member_info' + this.member_info.firstname + ' ' + this.member_info.status);
        }
      }
  })

  
  var ok_mobile = new Vue({
    name: 'OkMobile',
    el: '#ok_member_mobile',
    delimiters: ['${', '}'],
    methods:{},
    data: {
      member_info:{
        id: readCookie("okibook_user_id"),
        firstname: readCookie("okibook_user_name"),
        lastname: '',
        token: readCookie("okibook_token"),
        status: readCookie("okibook_status"),
      },
    },
  })
  
var ok_popup = new Vue({
  name: 'OkPopup',
   el: '#ok_popup',
  delimiters: ['${', '}'],
   methods:{
     loginHandler(){
       ok_popup.login.message = "";
       ok_popup.login.message_tw = "";
       
       if(!this.login.password){ //join.message password_c
         ok_popup.login.message = "Please input your password.";
         ok_popup.login.message_tw = "請輸入你的密碼";
       }
       if(this.login.email){
         var validRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
          if (!this.login.email.match(validRegex)) {
            ok_popup.login.message = "Please input a valid Email Address.";
            ok_popup.login.message_tw = "請輸入有效電郵";
          }
       }
       if(!this.login.email){ //join.message
         ok_popup.login.message = "Please input your Email Address.";
         ok_popup.login.message_tw = "請輸入你的電郵";
       }
       if(this.login.password && this.login.email && !this.login.message){
       axios.post(this.url + this.language + '/shopapi/login',
                  this.login
                 )
       .then(function (response) { // 请求失败处理
         ok_popup.login_info = response.data;
         if(response.data.confirmed == 1 && response.data.status == 'in'){
            ok_top.member_info = response.data;
            ok_mobile.member_info = response.data;
           	ok_popup.login.message = "";
             ok_popup.login.password = "";
             ok_popup.login.email = "";
            ok_popup.edit = response.data;
            set_cookies('okibook_token', response.data.token);
            set_cookies('okibook_user_id', response.data.id);
            set_cookies('okibook_user_name', response.data.firstname + ' ' + response.data.lastname);
            set_cookies('okibook_status', response.data.status);
           	ok_hiddenpopup();
           ok_login();
           ok_showpopup('#ok_popup');
           ok_popup.pointHandler();
           ok_popup.pointHistoryHandler();
           ok_page_change('ok_bonus_content', 'sub_account');
           if(response.data.storeadmin && response.data.link){
            // console.log('Store Admin:' + response.data.storeadmin +' '+ response.data.link);
            window.location.href = response.data.link;
           }
          }
         if(response.data.confirmed != 1 && response.data.status == 'in'){
           ok_popup.login.message = "Please confirm your email.";
           ok_popup.login.message_tw = "請先確認你的電郵地址";
         }
         if(response.data.status == 'out'){
           // ok_hiddenpopup();
           ok_hidden('#menu_open');
           ok_popup.login.message = "Login failed. Email and/or password incorrect.";
           ok_popup.login.message_tw = "登入失敗，電郵或密碼錯誤。";
           ok_top.member_info = response.data;
           ok_mobile.member_info = response.data;
           set_cookies('okibook_status', this.login_info.status);
         }
       }
//              response => (
//          ok_popup.login_info = response.data
//        )
            )
       .catch(function (error) { // 请求失败处理
         ok_popup.login_info = error ;
         // console.log('Login api 请求失败处理:' + error);
         // console.log('Login api data:' + response.data);
       });
       // console.log('login info:' + this.login.email + this.login.password + this.login_info.id + this.login_info.email);
        }
     },
     forgetHandler(){
       ok_popup.forget.message = "";
       ok_popup.forget.message_tw = "";
       if(this.forget.email){
         var validRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
          if (!this.forget.email.match(validRegex)) {
            ok_popup.forget.message = "Please input a valid Email Address.";
            ok_popup.forget.message_tw = "請輸入有效電郵";
          }
       }
       if(!this.forget.email){ //join.message
         ok_popup.forget.message = "Please input your Email Address.";
         ok_popup.forget.message_tw = "請輸入你的電郵";
       }
       if(this.forget.email && !this.forget.message){
         axios.post(this.url + this.language +'/shopapi/forget',
                    this.forget
                   )
       .then(function (response) {
         // console.log('Forget password:' + response.data);
           if(response.data == 'Email not find.'){
             ok_popup.forget.message = "Email not find.";
             ok_popup.forget.message_tw = "此電郵並沒有會員登記";
           }
           if(response.data == 'Email is empty.'){
             ok_popup.forget.message = "Please input your Email Address.";
             ok_popup.forget.message_tw = "請輸入你的電郵";
           }
           if(response.data == 'Done'){
             ok_popup.forget.email = "";
//              ok_popup.forget.message = "<h3>We sent a email to your email box, you may reset your password follow this email.</h3>";
//              ok_popup.forget.message_tw = "<h3>我們已寄出電郵至你至的信箱，你可以從這電郵重設你的密碼。</h3>";
//              ok_hiddenpopup();
             ok_page_change('ok_forgot_done_content', 'sub_profile');
             
           }
           
       })
         .catch(function (error) { // 请求失败处理
           // console.log('Forget api 请求失败处理:' + error);
         });
       }
//      forget.email
     },
     chBirthdayHandler(){ //edit.message edit.message edit.bdYear edit.bdMonth
     },
     editHandler(){
       axios.post(this.url + this.language + '/shopapi/updated',
                  this.edit
                 )
       .then(function (response) {
         // console.log('Member update: ' + response.data);
         set_cookies('okibook_user_name', ok_popup.edit.firstname + ' ' + ok_popup.edit.lastname);
         // ok_hiddenpopup();
         ok_page_change('ok_edit_done_content');
//          ok_popup.login_info = response.data
       })
       .catch(function (error) { // 请求失败处理
//          ok_popup.login_info = error ;
         // console.log('CH Birthday api 请求失败处理:' + error);
       });
     },
     inputHandler(){
       // console.log('login email:' + this.login.email);
       // console.log('login password:' + this.login.password);
       //this.input.email = this.login_email
       //this.input.password = this.login_password

     },
     logoutHandler(){
       axios.post(this.url + this.language +'/shopapi/logout',
                  this.login_info
                 )
       .then(response => (
         ok_popup.login_info = response.data
       ))
       .catch(function (error) { // 请求失败处理
         ok_popup.login_info = error ;
         //ok_hidden('#menu_open');
         // console.log('Logout api 请求失败处理:' + error);
       });
       set_cookies('okibook_token', '');
       set_cookies('okibook_user_id', '');
       set_cookies('okibook_user_name', '');
       set_cookies('okibook_status', 'out');
       ok_top.member_info.status = 'out';
       ok_top.member_info.firstname = '';
       ok_top.member_info.lastname = '';
       ok_mobile.member_info.status = 'out';
       ok_mobile.member_info.firstname = '';
       ok_mobile.member_info.lastname = '';
       // console.log('Logout '+this.login_info.id+' '+this.login_info.token);
       ok_hiddenpopup();
     },
     passwordHandler(){
         ok_popup.ch_password.message = "";
         ok_popup.ch_password.message_tw = "";
       if (this.ch_password.new_password && this.ch_password.new_password != this.ch_password.new_password_c){
         ok_popup.ch_password.message = "Password confirmation does not match.";
         ok_popup.ch_password.message_tw = "確認密碼不相符";
       }
       if(!this.ch_password.new_password_c){ //join.message password_c
           this.ch_password.message = "Please confirm your password.";
           this.ch_password.message_tw = "請確認你的密碼";
       }
       if (this.ch_password.new_password && this.ch_password.new_password.length < 6){
         ok_popup.ch_password.message = "Your new password needs to contain at least 6 characters.";
         ok_popup.ch_password.message_tw = "新密碼需長6個字元";
       } // if (isNaN(x)) {} Your password needs to contain at least 6 characters
       if(!this.ch_password.new_password){ //join.message password_c
         ok_popup.ch_password.message = "Please input your new password.";
         ok_popup.ch_password.message_tw = "請輸入你的新密碼";
       }
       if(!this.ch_password.old_password){ //join.message password_c
         ok_popup.ch_password.message = "Please input your old password.";
         ok_popup.ch_password.message_tw = "請輸入你的舊密碼";
       }
       if(this.ch_password.old_password && this.ch_password.new_password && this.ch_password.new_password_c && !this.ch_password.message){
         // console.log('password: '+this.ch_password.user_id +' '+ this.ch_password.new_password +' '+ this.ch_password.new_password_c);
//          if(this.ch_password.new_password != this.ch_password.new_password_c){
//            this.ch_password.message = "Please confirmate your new password.";
//            this.ch_password.message_tw = "請確認你的新密碼";
//          }else{
//          }
           axios.post(this.url + this.language + '/shopapi/password',
                      this.ch_password
                     )
           .then(function(response){
             // console.log('ch_password.return:' + response.data);
             if(response.data == "Password not correct."){
             	ok_popup.ch_password.message = "Old password incorrect." ;
             	ok_popup.ch_password.message_tw = "舊密碼錯誤" ;
             }else if(response.data == "User not exist."){
             	ok_popup.ch_password.message = response.data ;
             	ok_popup.ch_password.message_tw = "請先登入" ;
               ok_hiddenpopup();
             }else if(response.data == "Update done."){
//                ok_popup.ch_password.message = "Update done." ;
//              	ok_popup.ch_password.message_tw = "成功更新" ;
               ok_popup.ch_password.return = response.data;
               ok_page_change('ok_password_done_content');
               ok_popup.ch_password.old_password = "";
               ok_popup.ch_password.new_password = "";
               ok_popup.ch_password.new_password_c = "";
               // ok_hiddenpopup();
             }
           })
           .catch(function (error) { // 请求失败处理
             ok_popup.ch_password.return = error ;
             // console.log('Change password api 请求失败处理:' + error);
           });
       }
          
     },
     	checkTokenHandler(){// 'token' 'user_id'
          // console.log('Old info: ' + this.old.token + this.old.user_id );
          axios.post(this.url + this.language + '/shopapi',
          // axios.post('https://www.okibook.com/shopapi/login',
            this.old
          )
          .then(response => (
            ok_popup.login_info = response.data
          ))
          .catch(function (error) { // 请求失败处理
//             ok_popup.login_info = error ;
         ok_hidden('#menu_open');
            // console.log('Check Token api 请求失败处理:' + error);
          });
        },
     checkJoinHandler(){
//        console.log(ok_popup.join);
       ok_popup.join.message = "";
       ok_popup.join.message_tw = "";
       if(this.join.bdMonth > 12 || this.join.bdMonth < 1){ //join.message password_c  join.bdYear join.bdMonth
         ok_popup.join.message = "Please input a valid birth month.";
         ok_popup.join.message_tw = "請輸入有效的月份";
       }
       if(!this.join.bdMonth){ //join.message password_c  join.bdYear join.bdMonth
         ok_popup.join.message = "Please input your birth month.";
         ok_popup.join.message_tw = "請輸入你的出生月份";
       }
       if(this.join.bdYear > new Date().getFullYear() || this.join.bdYear < 1900){ //join.message password_c  join.bdYear join.bdMonth
         ok_popup.join.message = "Please input a valid birth year.";
         ok_popup.join.message_tw = "請輸入有效的年份";
       }
       if(!this.join.bdYear){ //join.message password_c 
         ok_popup.join.message = "Please input your birth year.";
         ok_popup.join.message_tw = "請輸入你的出生年份";
       }
       if (this.join.password && this.join.password != this.join.password_c){
         ok_popup.join.message = "Password confirmation does not match.";
         ok_popup.join.message_tw = "確認密碼不相符";
       }
       if(!this.join.password_c){ //join.message password_c
         ok_popup.join.message = "Please confirm your password.";
         ok_popup.join.message_tw = "請確認你的密碼";
       }
       if (this.join.password && this.join.password.length < 6){
         ok_popup.join.message = "Your password needs to contain at least 6 characters.";
         ok_popup.join.message_tw = "密碼需長6個字元";
       } // if (isNaN(x)) {}
       if(!this.join.password){ //join.message password_c
         ok_popup.join.message = "Please input your password.";
         ok_popup.join.message_tw = "請輸入你的密碼";
       }
       if(this.join.phone && isNaN(this.join.phone)){
         ok_popup.join.message = "Please enter a correct phone number.";
         ok_popup.join.message_tw = "只能以數字輸入正確電話號碼";
       }
       if(!this.join.phone){ //join.message phonecode
         ok_popup.join.message = "Please input your phone number.";
         ok_popup.join.message_tw = "請輸入你的電話號碼";
       }
       if(!this.join.phonecode){ //join.message
         ok_popup.join.message = "Please input your phone Country Code.";
         ok_popup.join.message_tw = "請輸入你的電話地區碼";
       }
       if(!this.join.lastname){ //join.message
         ok_popup.join.message = "Please input your last name.";
         ok_popup.join.message_tw = "請輸入你的姓氏";
       }
       if(!this.join.firstname){ //join.message
         ok_popup.join.message = "Please input your first name.";
         ok_popup.join.message_tw = "請輸入你的名字";
       }
       if(this.join.email){
         var validRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
          if (!this.join.email.match(validRegex)) {
            ok_popup.join.message = "Please input a valid Email Address.";
            ok_popup.join.message_tw = "請輸入有效電郵";
          }
       }
       if(!this.join.email){ //join.message
         ok_popup.join.message = "Please input your Email Address.";
         ok_popup.join.message_tw = "請輸入你的電郵";
       }
     },
        joinHandler(){
//           checkJoinHandler();
          if(!this.join.message && this.join.firstname && this.join.lastname && this.join.password && this.join.password_c && this.join.email && this.join.password == this.join.password_c){
            axios.post(
              this.url + this.language +'/shopapi/join',
               this.join
            )
            .then(function (response) {
              // console.log('Join in: ' + response.data);
              if(response.data == 'done'){
                ok_popup.join.message = "";
                ok_popup.join.password = "";
                ok_popup.join.email = "";
                ok_popup.join.status = "";
                ok_popup.join.firstname = "";
                ok_popup.join.lastname = "";
                ok_popup.join.token = "";
                ok_popup.join.message = "";
                ok_popup.join.message_tw  = "";
                ok_popup.join.phone  = "";
                ok_popup.join.bdYear = "";
                ok_popup.join.bdMonth = "";
                ok_page_change('ok_join_done_content');
              }else if(response.data == 'Email is already used.'){
                ok_popup.join.message = "This Email Address is already taken.";
                ok_popup.join.message_tw = "此電郵已被登記";
              }else{
                ok_popup.join.message = "Join in fail, please try later.";
                ok_popup.join.message_tw = "登記失敗，請稍後再試。";
              }
            })
            .catch(function (error) { // 请求失败处理
//                 ok_popup.login_info = error ;
                // console.log('join 请求失败处理:' + error);
            });
        	}
        },
       allBookingHandler(){
         ok_popup.Booking.data = "";
         axios.post(this.url + this.language +'/shopapi/booking/all',
                    this.Booking
                   )
         .then(function (response) {
           console.log(response.data);
           // ok_hiddenpopup();
           ok_popup.Booking.data = response.data;
         })
         .catch(function (error) { // 请求失败处理
//            ok_popup.login_info = error ;
           //console.log('all booking 请求失败处理:' + error);
         });
       },
       bookingHandler(){
         ok_popup.Booking.data = "";
         axios.post(this.url + this.language +'/shopapi/booking',
                    this.Booking
                   )
         .then(function (response) {
           console.log(response.data);
           // ok_hiddenpopup();
           ok_popup.Booking.data = response.data;
         })
         .catch(function (error) { // 请求失败处理
//            ok_popup.login_info = error ;
           //console.log('booking 请求失败处理:' + error);
         });
       },
       allVouchersHandler(){
         ok_popup.Vouchers.data = "";
         axios.post(this.url + this.language +'/shopapi/vouchers/all',
                    this.Vouchers
                   )
         .then(function (response) {
           console.log(response.data);
           // ok_hiddenpopup();
           ok_popup.Vouchers.data = response.data;
         })
         .catch(function (error) { // 请求失败处理
//            ok_popup.login_info = error ;
           //console.log('vouchers 请求失败处理:' + error);
         });
       },
       vouchersHandler(){
         ok_popup.Vouchers.data = "";
         axios.post(this.url + this.language +'/shopapi/vouchers',
                    this.Vouchers
                   )
         .then(function (response) {
           console.log(response.data);
           // ok_hiddenpopup();
           ok_popup.Vouchers.data = response.data;
         })
         .catch(function (error) { // 请求失败处理
//            ok_popup.login_info = error ;
           //console.log('vouchers 请求失败处理:' + error);
         });
       },
       pointHandler(){
         ok_popup.Points.data = "";
         axios.post(this.url + this.language +'/shopapi/points',
                    this.Points
                   )
         .then(function (response) {
           console.log( response.data);
           // ok_hiddenpopup();
           ok_popup.Points.data = response.data;
         })
         .catch(function (error) { // 请求失败处理
            // ok_popup.login_info = error ;
           //console.log('vouchers 请求失败处理:' + error);
         });
       }, //
       pointHistoryHandler(){
         ok_popup.Points_history.data = "";
         axios.post(this.url + this.language +'/shopapi/points_history',
                    this.Points_history
                   )
         .then(function (response) {
           // console.log(response.data);
           // ok_hiddenpopup();
           ok_popup.Points_history.data = response.data;
         })
         .catch(function (error) { // 请求失败处理
//            ok_popup.login_info = error ;
           //console.log('vouchers 请求失败处理:' + error);
         });
       },
       allCodeHandler(){
         ok_popup.AllCodes.data = "";
         axios.post(this.url + this.language +'/shopapi/allcodes',
                    this.AllCodes
                   )
         .then(function (response) {
           // console.log(response.data);
           // ok_hiddenpopup();
           ok_popup.AllCodes.data = response.data;
         })
         .catch(function (error) { // 请求失败处理
//            ok_popup.login_info = error ;
           //console.log('vouchers 请求失败处理:' + error);
         });
       },
       redeemHandler(id){
         ok_popup.Redeem.price_id = id;
         ok_popup.Redeem.data = "";
         ok_popup.MyCodes.data = '';
         // console.log('Redeem: ' + this.Redeem.price_id);
         axios.post(this.url + this.language +'/shopapi/redeem',
                    this.Redeem
                   )
         .then(function (response) {
           // console.log(response.data);
           // ok_hiddenpopup();
           ok_popup.Redeem.data = response.data;
           ok_popup.pointHandler();
           ok_page_change('ok_code_bonus_content', 'sub_rewards');
           ok_popup.allCodeHandler();
         })
         .catch(function (error) { // 请求失败处理
//            ok_popup.login_info = error ;
           //console.log('vouchers 请求失败处理:' + error);
         });
       },
       myCodeHandler(){
         ok_popup.MyCodes.data = "";
         axios.post(this.url + this.language +'/shopapi/mycodes',
                    this.MyCodes
                   )
         .then(function (response) {
           // console.log(response.data.total_point);
           // ok_hiddenpopup();
           ok_popup.MyCodes.data = response.data;
           ok_popup.Points.data.total_point = response.data.total_point;
         })
         .catch(function (error) { // 请求失败处理
//            ok_popup.login_info = error ;
           //console.log('vouchers 请求失败处理:' + error);
         });
       },
       getAlertHandler(){
         ok_popup.alert.message = "";
         if(this.alert.alert){
          axios.post(this.url + this.language +'/shopapi/alert',
                      this.alert
                    )
          .then(function (response) {
            // console.log( response.data.total_point);
            // ok_hiddenpopup();
            ok_popup.alert.message = response.data;
            ok_popup.Points.data.total_point = response.data.total_point;
          })
          .catch(function (error) { // 请求失败处理
  //            ok_popup.login_info = error ;
            //console.log('vouchers 请求失败处理:' + error);
          });
          }
       },
        autoLoginHandler(logintoken = null, status = null){
          // this.autotoken = getURLParam("atk"); //okibook_token
          this.autotoken = readCookie("okibook_token");
          if(logintoken){
            this.autotoken = logintoken ;
          }
          // console.log('atk: '+ this.autotoken +' '+ status);
          if(this.autotoken){
          /* */
          axios.post(this.url + this.language + '/shopapi/autoin',
                  { atk: this.autotoken }
                 )
           .then(function (response) {
            // console.log('atk response: '+ response.data + response.data.status + response.data.token);
             ok_popup.login_info = response.data; //
             if(response.data.confirmed == 1 && response.data.status == 'in'){
                ok_top.member_info = response.data;
                ok_mobile.member_info = response.data;
                ok_popup.login.message = "";
                ok_popup.login.password = "";
                ok_popup.login.email = "";
                ok_popup.edit = response.data;
                if(readCookie("okibook_token") && readCookie("okibook_status") != 'in'){
                set_cookies('okibook_token', response.data.token);
                set_cookies('okibook_user_id', response.data.id);
                set_cookies('okibook_user_name', response.data.firstname + ' ' + response.data.lastname);
                set_cookies('okibook_status', response.data.status);}
                ok_hiddenpopup();
                ok_login();
//                 window.location.replace(this.shop_url);
               // window.location.href = this.shop_url;
              //  window.location.href = '/'; // reload later
              // if(status == 'facebook'){ window.location.href = '/'; }
              if(status == 'facebook'){ 
                // var date = new Date();
                // var dateTimeNow = date.getTime();
                // var lasttime = readCookie('okibook_time');
                var lastPageUrl = document.referrer
                // console.log('ok time: '+dateTimeNow +' - '+ lasttime +' = '+ (dateTimeNow - lasttime) +' '+ lastPageUrl);
                if(lastPageUrl == 'https://shop.okibook.com/'){
                  // console.log('form shop, ' + lastPageUrl+'?fblogin=fb&atk='+response.data.token);
                  window.location.href = lastPageUrl+'?fblogin=fb&atk='+response.data.token; //https://okibook-test-store-opened-1-jul-2021.myshopify.com/?fblogin=fb&atk={{$current_user->token}}
                }else{
                  // console.log('not form shop, ' + lastPageUrl);
                  history.back();
                }
              }
              }
             }
            )
           .catch(function (error) { // 请求失败处理
             ok_popup.login_info = error ;
             //ok_hidden('#menu_open');
            //  console.log('Auto Login api 请求失败处理:' + error);
           });
          }else{
          // console.log('No atk '+ this.autotoken);
          // console.log('language '+ this.language);
          }
        },
        getTokenHandler(){
          /* */
          axios.post(this.url + this.language + '/shopapi/token',
                  { atk: this.autotoken }
                 )
           .then(function (response) {
            // console.log('get_token response: '+ response);
             ok_popup.login_info = response.data;
             if(response.data.token){
               // console.log('get_token: '+ response.data.token);
                set_cookies('okibook_token', response.data.token);
              }
             }
            )
           .catch(function (error) { // 请求失败处理
             // ok_popup.login_info = error ;
             //ok_hidden('#menu_open');
             // console.log('get_token api 请求失败处理:' + error);
           });
        },
      },
      data: {
        // {% if request.locale.iso_code == 'en' %}
        // language : "en",
        // {% else %}
        // language : "tc",
        // {% endif %}
        language : $(location).attr('pathname').slice(1,3)?$(location).attr('pathname').slice(1,3):'tc',
        url_A: "https://okibook.mpsecure.com/",
        url: "https://www.okibook.com/",
        shop_url: "https://shop.okibook.com/",
        shop_url_A: "https://okibook-test-store-opened-1-jul-2021.myshopify.com/",
        autotoken: getURLParam("atk"),
        ok_alert: {
          alert: getURLParam("alert"),
          message: '',
        },
        info: [], // Login: 'email' 'password' 'token',
        status_en: {'activate': 'Activate', 'used': 'Used', 'planning':'Pending', 'cancel': 'Cancelled', 'delete': 'Deleted', 'expiry': 'Expired', 'no show': 'No Show'} ,
        status_ch: {'activate': '有效', 'used': '已使用', 'planning': '未入帳', 'cancel': '已取消', 'delete': '已刪除', 'expiry': '已過期', 'no show': '沒有出席'},
        windowHeight: window.innerHeight,
        windowWidth: window.innerWidth,
        edit:{
          token: readCookie("okibook_token"),
          user_id: readCookie("okibook_user_id"), 
          bdYear: "",
          bdMonth: "",
          phone: "",
          phone_ccode: "",
          firstname: "",
          lastname: "",
          email: "",
        },
        login_info: {
          token:"",
          id:"",
         user_id:"",
          email:"",
        },
        login:{
          visitor_token : readCookie("okibook_token"),
          token : "",
          password : "",
          email: "",
          message: "",
          message_tw: "",
        },
        join:{  // join.message
          password : "",
          email: "",
          status: "",
          firstname : "",
          lastname : "",
          token : "",
          message : "",
          message_tw : "",
          phone : "",
          bdYear : "",
          bdMonth : "",
          phonecode : 852,
          preference_lang : $(location).attr('pathname').slice(1,3),
          reservation_id : "",
          voucher_id : "",
          // {% if request.locale.iso_code == 'en' %}
          // preference_lang : "en"
          // {% else %}
          // preference_lang : "zh-TW"
          // {% endif %}
        },
        input:{ 
          password : "",
          email: "",
          status: "",
          first_name : "",
          last_name : "",
          token : ""
        },
        ch_password: {
          old_password: "",
          new_password: "",
          new_password_c: "",
          message: "",
          message_tw: "",
          return: "",
          token: "",
          user_id: "",
        },
        forget:{ 
          email: "",
          message : "",
          message_tw : "",
        },
        old:{ // 'token' 'user_id'
          token: readCookie("okibook_token"),
          user_id: readCookie("okibook_user_id"),
          status: readCookie("okibook_status"),
        }, 
        modelConfig: {
            type: 'string',
            mask: 'YYYY-MM-DD', // Uses 'iso' if missing email', 'password
        },
        lan_select: [
          {"value": "zh-TW",
           "text": "Traditional Chinese"},
          {"value": "en",
           "text": "English"}
        ],
        Booking:{
          data:"",
          token: "",
          user_id: "",
		},
        Vouchers:{
          data:"",
          token: "",
          user_id: "",
        }, 
        Points:{
          data:"",
          token: "",
          user_id: "",
        },
        Points_history:{
          data:"",
          token: "",
          user_id: "",
        },
        AllCodes:{
          data:"",
          token: "",
          user_id: "",
        },
        MyCodes:{
          data:"",
          token: "",
          user_id: "",
        },
        Redeem:{
          data:"",
          token: "",
          user_id: "",
          price_id: "",
        },
      },
      mounted () {
        //this.submitHandler()
      },
      watch:{
        login_info : function(){
          ok_info(this.login_info.status, this.login_info.email);
          /**  console.log('watch info:' + this.login_info.status + ' - '+ 
                      this.login_info.token + ' - '+ 
                      this.login_info.firstname + ' - '+ 
                      this.login_info.lastname + ' - '+  
                      this.login_info.confirmed + ' - '+ 
                      this.login_info.id + ' - '+ 
                      this.login_info.email); */
          if(this.login_info.confirmed == 1 && this.login_info.status == 'in'){
            var dt = new Date( this.login_info.birthday );
//          document.write(" getFullYear() : " + dt.getFullYear() ); 
//          document.write(" getMonth() : " + ( dt.getMonth()+1 ) );
            ok_top.member_info = this.login_info;
            ok_mobile.member_info = this.login_info;
            this.edit = this.login_info;
            this.edit.bdedit = this.login_info.birthday;
            this.ch_password.user_id = this.login_info.id;
            this.ch_password.token = this.login_info.token;
            this.old.user_id = this.login_info.id;
            this.old.token = this.login_info.token;
            this.Booking.user_id = this.login_info.id;
            this.Booking.token = this.login_info.token;
            this.Vouchers.user_id = this.login_info.id;
            this.Vouchers.token = this.login_info.token;
            this.Points.user_id = this.login_info.id;
            this.Points.token = this.login_info.token;
            this.Points_history.user_id = this.login_info.id;
            this.Points_history.token = this.login_info.token;
            this.AllCodes.user_id = this.login_info.id;
            this.AllCodes.token = this.login_info.token;
            this.MyCodes.user_id = this.login_info.id;
            this.MyCodes.token = this.login_info.token;
            this.Redeem.user_id = this.login_info.id;
            this.Redeem.token = this.login_info.token;
            if(this.login_info.birthday){
              this.edit.bdYear = dt.getFullYear();
              this.edit.bdMonth = ( dt.getMonth()+1 );
            }else{
              this.edit.bdYear = "";
              this.edit.bdMonth = "";
            }
            // set_cookies('okibook_token', this.login_info.token);
            // set_cookies('okibook_user_id', this.login_info.id);
            // set_cookies('okibook_user_name', this.login_info.firstname + ' ' + this.login_info.lastname);
            // set_cookies('okibook_status', this.login_info.status);
          }else{
//             set_cookies('okibook_token', this.login_info.token);
//             set_cookies('okibook_user_id', this.login_info.id);
//             set_cookies('okibook_user_name', this.login_info.firstname + ' ' + this.login_info.lastname);
            // set_cookies('okibook_status', this.login_info.status);
            ok_top.member_info = this.login_info;
            ok_mobile.member_info = this.login_info;
          }
          
//           if(this.login_info.status == 'out'){
//             ok_hiddenpopup();
//             ok_top.member_info = this.login_info;
//             ok_mobile.member_info = this.login_info;
//             set_cookies('okibook_status', this.login_info.status);
//           }
        },
        range : function() {
            this.submitHandler()
            // console.log('start: '+this.range.start);
            // console.log('end: '+this.range.end);
        },
        ch_password : function(){
           if(this.ch_password.return != "Update done."){
             this.ch_password.message = this.ch_password.return ;
           }else{
             this.ch_password.message = "" ;
             ok_hiddenpopup();
           }
          if(this.ch_password.message){
            // console.log('password message: '+this.ch_password.message);
          }
        },
        autotoken : function(){
//         	console.log('atk: '+ this.autotoken);
        }
      }
})
  let fbtoken = getURLParam('oklogintoken');
  if(fbtoken){
    // console.log('fbtoken: '+ fbtoken);
    set_cookies('okibook_token', fbtoken);
    ok_popup.autoLoginHandler(fbtoken, 'facebook');
  }
  // if(readCookie("okibook_status") != 'in' && !fbtoken){
  // }
  //   let oldtoken = readCookie("okibook_token");
    ok_popup.autoLoginHandler('', 'auto try ' + readCookie("okibook_status"));
  ok_popup.checkTokenHandler();
  if(getURLParam("fb_log") && readCookie("okibook_status") == 'in'){
    ok_showpopup('#ok_popup');
    ok_popup.pointHandler();
    ok_page_change('ok_bonus_content', 'sub_account');
  }else{
     //ok_hidden('#menu_open');
  }

  $(document).ready(function() {
    let mempage = getURLParam('okmember');
    let logtatus = readCookie("okibook_status");
    let old_token = readCookie("okibook_token");
    // console.log('mem page '+ mempage +' - '+ logtatus);
    if(!old_token){
      ok_popup.getTokenHandler();
    }
    if(logtatus == 'in'){
      if(mempage == 'profile' || mempage == 'dashboard' || mempage == 'login'){
        ok_showpopup('#ok_popup'); 
        ok_page_change('ok_member_content', 'sub_profile'); 
        ok_show('#menu_open'); 
        // ok_hidden('#menu_close');
      }
    }else{
      if(mempage == 'profile' || mempage == 'dashboard' || mempage == 'login'){
        ok_logout(); 
        ok_showpopup('#ok_popup'); 
        ok_page_change('ok_login_content');
      }
      if(mempage == 'forget'){
        ok_logout(); 
        ok_showpopup('#ok_popup'); 
        ok_page_change('ok_forgot_content');
      }
    }
  });
