var EZTABLE={config:{}};EZTABLE.config.productionHosts=["eztable.com","www.eztable.com","staging.eztable.com","eztable.com.tw","www.eztable.com.tw","staging.eztable.com.tw","secure.eztable.com.tw","m.eztable.com","partner.eztable.com","partner-staging.eztable.com","partner.eztable.com.tw","partner-staging.eztable.com.tw"];EZTABLE.config.apiProductionURL="http://api.eztable.com/v2/";EZTABLE.API_STATUS={OK:"OK",EZ_PERMISSION_EXCEPTION:"EZPermissionException"};
EZTABLE.isProductionHost=function(){return $.inArray(location.hostname,EZTABLE.config.productionHosts)!=-1?!0:!1};EZTABLE.isDevHost=function(){return location.hostname=="zac.eztable.com"||location.hostname=="zac.eztable.com.tw"||location.hostname=="m-dev.eztable.com"||location.hostname=="partner-dev.eztable.com"||location.hostname=="partner-dev.eztable.com.tw"?!0:!1};
EZTABLE.debugMsg=function(b){EZTABLE.isProductionHost()?typeof window.console!="undefined"&&typeof window.console.log!="undefined"&&console.log(b):alert(b)};EZTABLE.getAPIHost=function(){return EZTABLE.isProductionHost()?EZTABLE.config.apiProductionURL:EZTABLE.isDevHost()?"http://api-dev.eztable.com/v2/":"http://"+location.host+"/v2/"};EZTABLE.addCommonParams=function(b){var a=$("#param_access_token");if(a.length>0)b.access_token=a.val();a=$("#param_lang");if(a.length>0)b.lang=a.val();return b};
EZTABLE.api=function(b){var a=$.extend(!0,{},{path:void 0,params:{},success:void 0,error:void 0,type:"POST"},b);$.ajax({url:EZTABLE.getAPIHost()+a.path+"?jsoncallback=?",dataType:"json",data:EZTABLE.addCommonParams(a.params),success:a.success,error:function(b,d,e){$.isFunction(a.error)?a.error(b,d,e):EZTABLE.debugMsg("error in: "+e.url+" \nerror:\n"+b.responseText)},type:a.type})};EZTABLE.htmlUtils={};
EZTABLE.htmlUtils.getXPath=function(b){for(var a="";b&&b.nodeType==1;b=b.parentNode){var c=$(b.parentNode).children(b.tagName).index(b)+1;c>1?c="["+c+"]":c="";a="/"+b.tagName.toLowerCase()+c+a}return a};EZTABLE.htmlUtils.getAllDataAttrs=function(b){var a={},c;for(c in b.attributes)if(!isNaN(c)){var d=b.attributes[c];if(d.name.length>5&&d.name.substr(0,5)=="data-")a[d.name.substr(5)]=d.value}return a};
EZTABLE.htmlUtils.getFormInputs=function(b){var a=$(b),c={};$.each(["input","select","textarea"],function(b,e){a.find(e).each(function(){var b=$(this).attr("name");b==null||b.length<=0||(c[b]=$(this).val())})});return c};EZTABLE.stringUtils={};EZTABLE.stringUtils.generateRandomAlphaNumericStr=function(b){for(var a="",c=0;c<b;c++)a+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random()*62));return a};EZTABLE.booking={};
EZTABLE.booking.modifyReservation=function(b){var a=b.form;if(a.find('select[name="time"]').length<=0)alert("\u8acb\u9078\u64c7\u4e00\u500b\u6642\u9593");else{var c={name:a.find('input[name="name"]').val(),gender:a.find('input[name="gender"]:checked').val(),tel:a.find('input[name="tel"]').val(),email:a.find('input[name="email"]').val(),subject:a.find('input[name="subject"]').val(),people:a.find('select[name="people"]').val(),datetime:a.find('input[name="date"]').val()+" "+a.find('select[name="time"]').val()+
":00",content:a.find('textarea[name="content"]').val()},d="reservation/modify/";d+=a.find('input[name="reservation_id"]').val()+"/";EZTABLE.api({path:d,params:c,success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})}};
EZTABLE.booking.cancelReservation=function(b){var a="reservation/cancel/";a+=b.form.find('input[name="reservation_id"]').val()+"/";EZTABLE.api({path:a,params:{},success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})};
EZTABLE.booking.modifyReservationByTempUser=function(b){var a=b.form;if(a.find('select[name="time"]').length<=0)alert("\u8acb\u9078\u64c7\u4e00\u500b\u6642\u9593");else{var c={name:a.find('input[name="name"]').val(),gender:a.find('input[name="gender"]:checked').val(),tel:a.find('input[name="tel"]').val(),email:a.find('input[name="email"]').val(),subject:a.find('input[name="subject"]').val(),people:a.find('select[name="people"]').val(),datetime:a.find('input[name="date"]').val()+" "+a.find('select[name="time"]').val()+
":00",content:a.find('textarea[name="content"]').val()},d="reservation/modify_by_temp_user/";d+=a.find('input[name="reservation_id"]').val()+"/";c.orig_email=a.find('input[name="orig_email"]').val();c.orig_tel=a.find('input[name="orig_tel"]').val();EZTABLE.api({path:d,params:c,success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})}};
EZTABLE.booking.cancelReservationByTempUser=function(b){var a=b.form,c={},d="reservation/cancel_by_temp_user/";d+=a.find('input[name="reservation_id"]').val()+"/";c.orig_email=a.find('input[name="orig_email"]').val();c.orig_tel=a.find('input[name="orig_tel"]').val();EZTABLE.api({path:d,params:c,success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})};
EZTABLE.booking.refreshModifyDialogQuotas=function(b){var a=b.form,c=a.find('input[name="date"]').val(),d=a.find('select[name="people"] option:selected').val(),e="restaurant/get_reservation_available_quotas_html_select_options/";e+=a.find('input[name="reservation_id"]').val()+"/";e+=a.find('input[name="restaurant_id"]').val()+"/";e+=c+"/";e+=d+"/";e+=a.find('select[name="time"]').length>0?a.find('select[name="time"]').val()+"/":a.find('input[name="default_time"]').val()+"/";b.quotaSpan.html("");EZTABLE.api({path:e,
params:{},success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.errorCallback(a):(a.data.length>0?b.quotaSpan.html('<select name="time">'+a.data+"</select>"):b.quotaSpan.html(b.fullMessage),b.successCallback(a.data))},error:b.errorCallback})};EZTABLE.booking.getReservationInfo=function(b){var a="reservation/get_info/";a+=b.reservationId+"/";EZTABLE.api({path:a,params:{},success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})};
EZTABLE.booking.getReservationInfoByTempUser=function(b){var a="reservation/get_info_by_temp_user/";a+=b.reservationId+"/";EZTABLE.api({path:a,params:{tel:b.tel},success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})};
EZTABLE.booking.inviteFriendsByEmail=function(b){var a=[],c=[];$.each(b.friends,function(b,d){a.push(b);c.push(d)});var d="reservation/invite_friends_by_email/";d+=b.reservationId+"/";d+=b.reservationChecksum+"/";EZTABLE.api({path:d,params:{emails:a,names:c},success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})};
EZTABLE.booking.inviteFriendsBySMS=function(b){var a=[],c=[];$.each(b.friends,function(b,d){a.push(b);c.push(d)});var d="reservation/invite_friends_by_sms/";d+=b.reservationId+"/";d+=b.reservationChecksum+"/";EZTABLE.api({path:d,params:{tels:a,names:c},success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})};
EZTABLE.booking.getReservationCircle=function(b){var a="reservation/get_reservation_circle/";a+=b.reservationId+"/";a+=b.reservationChecksum+"/";EZTABLE.api({path:a,params:{},success:function(a){a.status!=EZTABLE.API_STATUS.OK?b.failCallback(a):b.successCallback(a.data)},error:b.errorCallback})};EZTABLE.logger={};EZTABLE.logger.logArgs=function(b,a){var c="logger/log_args/";c+=b+"/";EZTABLE.api({path:c,params:a,success:function(){}})};
EZTABLE.logger.logByAccount=function(b,a,c){var d=$.extend(!0,{},{successCallback:void 0},c),c="logger/log_by_account/";c+=b+"/";EZTABLE.api({path:c,params:a,success:function(a){$.isFunction(d.successCallback)&&d.successCallback(a)}})};
EZTABLE.logger.logRefreshQuotasEvent=function(b){var a=[],c=[];$.each(b.quotas,function(b,d){d.availability?a.push(d.start_time):c.push(d.start_time)});var d={identifier:b.identifier,restaurant_id:b.restaurantId,date:b.date,people:b.people,available_times:a.join(","),unavailable_times:c.join(",")};EZTABLE.logger.logArgs(b.logCategory,d)};EZTABLE.login={FB_APP_ID:"126113257442223"};
EZTABLE.login.initFB=function(b){b=$.extend(!0,{},{callback:null,locale:"en_US"},b);if(location.hostname=="zac.eztable.com.tw"||location.hostname=="partner-dev.eztable.com.tw")EZTABLE.login.FB_APP_ID="123013947760541";else if(location.hostname=="localhost")EZTABLE.login.FB_APP_ID=location.host=="localhost:8888"?"164268793626492":location.host=="localhost:8889"?"208509142516135":"139500256120282";window.fbAsyncInit=function(){FB.init({appId:EZTABLE.login.FB_APP_ID,channelUrl:"//"+location.host+"/channel.html",
status:!0,cookie:!0,xfbml:!0});b&&b.hasOwnProperty("callback")&&$.isFunction(b.callback)&&b.callback()};(function(a){var c;if(!a.getElementById("facebook-jssdk"))c=a.createElement("script"),c.id="facebook-jssdk",c.async=!0,c.src="//connect.facebook.net/"+b.locale+"/all.js",a.getElementsByTagName("head")[0].appendChild(c)})(document)};
EZTABLE.login.loginFacebook=function(b){FB.login(function(a){if(a.authResponse){a="ajax/kernel/ezlogin_by_facebook.php";if(b.ajaxURL!==void 0)a=b.ajaxURL;$.ajax({type:"POST",url:a,dataType:"json",data:b.params,success:b.success})}else b.fail()},{scope:"user_birthday,email,offline_access,publish_stream"})};EZTABLE.autologger={};EZTABLE.autologger.options={};EZTABLE.autologger.options.category=void 0;EZTABLE.autologger.options.url=location.href;EZTABLE.autologger.options.identifer=void 0;
EZTABLE.autologger.log=function(b,a,c){c=$.extend(!0,{},{successCallback:void 0,logParams:{}},c);b=$(b);b.length<=0?$.isFunction(c.successCallback)&&c.successCallback({}):(b=b.get(0),b=EZTABLE.htmlUtils.getAllDataAttrs(b),b=$.extend(!0,{},b,c.logParams),b.log_id===void 0&&EZTABLE.debugMsg("log_id is undefined."),b.meta_event=a,b.meta_user_id=EZTABLE.autologger.options.identifer,b.meta_url=EZTABLE.autologger.options.url,EZTABLE.logger.logByAccount(EZTABLE.autologger.options.category,b,c))};
EZTABLE.autologger.replaceLinks=function(){var b=EZTABLE.getAPIHost()+"logger/eztable_autologger_link_redirect/";$(".eztable_autologger_link").each(function(){var a=$(this).attr("href");if(a!==null&&!(a.length<=4)&&!(a.length>b.length&&a.substr(0,b.length)==b)){var c=EZTABLE.htmlUtils.getAllDataAttrs(this);c.log_id===void 0&&EZTABLE.debugMsg("log_id is undefined.");c.meta_event="link";c.meta_user_id=EZTABLE.autologger.options.identifer;c.meta_url=EZTABLE.autologger.options.url;if(a.substr(0,4)!="http"){var d=
location.protocol+"//"+location.host;a.substr(0,1)!="/"&&(d+="/");d+=a;a=d}c.redirect_uri=a;a=b+EZTABLE.autologger.options.category+"/?"+$.param(c);$(this).attr("href",a)}})};
EZTABLE.autologger.init=function(b){EZTABLE.autologger.options.category=b;EZTABLE.autologger.options.identifer=$.cookie("eztable_autologger_identifier");if(null===EZTABLE.autologger.options.identifer)EZTABLE.autologger.options.identifer=EZTABLE.stringUtils.generateRandomAlphaNumericStr(32),$.cookie("eztable_autologger_identifier",EZTABLE.autologger.options.identifer);EZTABLE.autologger.replaceLinks();$.each(["click"],function(a,b){$("body").delegate(".eztable_autologger_"+b,b,function(){EZTABLE.autologger.log(this,
b)});$("body").delegate(".eztable_autologger_sync_"+b,b,function(a){var e=this;if($(this).data("eztable_autologger_sync_"+b+"_toggle")==1)return $(this).data("eztable_autologger_sync_"+b+"_toggle",0),!0;a.preventDefault();a.stopPropagation();EZTABLE.autologger.log(this,b,{successCallback:function(){$(e).data("eztable_autologger_sync_"+b+"_toggle",1);$(e).trigger(b)}});return!1})})};

