//Copyright © [Year(s)] Nokia Corporation and/or its subsidiary(-ies).
Fp.CheckIn={isEnabled:false,data:null,init:function(){this.elements={main:Fp.byId("checkin"),question:Fp.byId("checkin-question"),stats:Fp.byId("checkin-stats")};this.isEnabled=false;new Fp.Utils.Events.addTapEvent({element:this.elements.main,onEvent:Fp.Utils.bind(this.onCheckIn,this)});},onCheckIn:function(){if(true===Fp.Utils.hasClass(this.elements.question,"possible")){Fp.Api.fireC2A({hook:Fp.Api.C2Aid.CHECKIN});}},afterCheckIn:function(){Fp.openData.checkinAllowed=0;Fp.openData.checkedIn=1;this.fillCheckIn();this.getStats();},getStats:function(){if(0==Fp.openData.checkinAllowed&&0==Fp.openData.checkedIn){return false;}this.clearStats();var a=+new Date();setTimeout(function(){var b=new Fp.Ajax.Request({url:Fp.Settings.checkinStatsURL.replace("{PLACE_ID}",Fp.openData.placeId)+"?"+a,exresp:Fp.Ajax.ExResponse.JSON,method:"GET",timeout:5,lang:Fp.Lang.language,onSuccess:function(c,d){Fp.CheckIn.fillStats(d);},onFailure:function(c,d){Fp.CheckIn.clearStats(c,"failure");},onTimeout:function(c,d){Fp.CheckIn.clearStats(c,"timeout");}});b.send();},1);},clearStats:function(a,b){this.data=null;if(b&&1==Fp.openData.checkedIn){this.elements.stats.innerHTML=Language["places.checkin.youAreHere"];return false;}if(a||b){}this.elements.stats.innerHTML="";return false;},fillStats:function(b){if(!this.elements.stats){return false;}if(!b){this.clearStats("error");return false;}this.data=b;var a;if(1==Fp.openData.checkinAllowed){if(b.usersCheckinHereLastHour>0){a=Language["places.checkin.numOthershere"].replace("%d",b.usersCheckinHereLastHour);}else{if(b.totalCheckinCount>0){a=Language["places.checkin.numOthersBeenHere"].replace("%d",b.totalCheckinCount);}else{a=Language["places.checkin.bethefirstOneHere"];}}}else{if(0==Fp.openData.checkinAllowed&&1==Fp.openData.checkedIn){var c=b.usersCheckinHereLastHour-1;if(c>0&&Fp.isPortrait()){a=Language["places.checkin.youAndOthersHere"].replace("%d",c);}else{a=Language["places.checkin.youAreHere"];}Fp.Tracking.track("usersCheckedIn",c);}else{a="";}}this.elements.stats.innerHTML=a;},fillCheckIn:function(){if(!this.elements.main){return false;}if(!Fp.openData.checkinAllowed&&!Fp.openData.checkedIn){this.isEnabled=false;return true;}this.isEnabled=true;if(1==Fp.openData.checkinAllowed){Fp.Utils.addClass(this.elements.question,"possible");Fp.Utils.removeClass(this.elements.main,"checked-in");}else{Fp.Utils.addClass(this.elements.main,"checked-in");Fp.Utils.removeClass(this.elements.question,"possible");}},setContent:function(a){if(Fp.openData){this.fillStats(this.data);}}};