//Copyright © [Year(s)] Nokia Corporation and/or its subsidiary(-ies).
Fp.Modules.Recommendations={ajaxTimeOut:5,data:null,results:null,limit:11,elements:{template:null,list:null},init:function(){this.setElements();},load:function(){this.data=Fp.openData||null;if(null===this.elements.template||null===this.elements.list){this.setElements();}if(this.dataCheck()){this.clearContent();this.getData();}else{this.showError();}},setupEvents:function(){},setElements:function(){this.elements.template=Fp.byId("recommendationsElements").children[0];this.elements.list=Fp.byId("RecommendationsList");},getData:function(){var c=this,b=Fp.Settings.recommendationsURL.replace("{GEO_COORDS}",c.data.latitude+","+c.data.longitude),a=(Fp.POI.placeId)?("?pid="+encodeURIComponent(Fp.POI.placeId)):"";b+=a;setTimeout(function(){var d=new Fp.Ajax.Request({url:b,exresp:Fp.Ajax.ExResponse.JSON,method:"GET",timeout:this.ajaxTimeOut,lang:Fp.Lang.language,onSuccess:function(e,f){if(!f.recommendations||!f.recommendations.nearby||0==f.recommendations.nearby.length){c.showError();return;}c.fillData(f);},onFailure:function(e,f){c.showError();},onTimeout:function(e,f){c.showError();}});d.setHeader("X-User-Agent","S60-SR6");d.send();},1);},fillData:function(d){if(d.recommendations.nearby.constructor!=Array){this.results=[d.recommendations.nearby];}else{this.results=d.recommendations.nearby;}var c=(this.results.length>this.limit)?this.limit:this.results.length;Fp.Utils.addClass(this.elements.list,"hide");var a=1;for(var b=0;b<c;b++){if(this.results[b].place){this.addOneRecord(this.results[b],b,a);a++;}}Fp.Modules.toggleLoader();if(this.elements.list.innerHTML!=""&&a>1){Fp.Modules.Manager.setUpNav("Recommendations");Fp.Utils.removeClass(this.elements.list,"hide");Fp.Modules.Manager.toggleDefaultContent();}else{this.showError();}},addOneRecord:function(c,g,a){if(c&&c.place){var i=this.elements.template.cloneNode(true);if((a&1)===1){i.className="odd";}if(a===1){i.className+=" first";}new Fp.Utils.Events.addTapEvent({element:i,onEvent:this.openRecommendation});var b=Fp.Utils.convertKmMiles(c.distance),d=c.place,f=0,h=0;if(d.averageRatings&&d.averageRatings.averageRating){f=Fp.Ratings.calculateRating(d.averageRatings.averageRating.rating);}i.title=g;var e=this.formatAddress(d.location.address);if(i.children){i.children[0].innerHTML=Fp.Utils.getName(d);i.children[1].innerHTML=this.formatCategory(d.categories.category);i.children[2].children[0].innerHTML=e.street+" "+e.house_no;i.children[2].children[1].innerHTML=b;i.children[3].innerHTML='<span class="recommended-rating-count rating-'+f*10+'">'+Language["places.oviRating"].replace("%d",f||0)+"/5</span>";this.elements.list.appendChild(i);}}},formatCategory:function(a){a=a instanceof Array?a:[a];return a[0].displayName;},formatAddress:function(b){var e=b.street||"",d=b.houseNumber||"",a=b.zipCode||"",c=b.city||"";return{street:e,house_no:d,zip:a,city:c};},openRecommendation:function(d,a){var b=parseInt(a.title);var c=Fp.Modules.Recommendations.results[b];var f={isPlace:true,placeId:c.place.a_id,name:c.place.names.defaultName.name,desc:(c.place.categories.category instanceof Array)?c.place.categories.category[0].displayName:c.place.categories.category.displayName,phone:(c.place.contact&&c.place.contact.phone)?c.place.contact.phone:null,Url:(c.place.contact&&c.place.contact.website)?c.place.contact.website:null,street:c.place.location.address.street,houseno:c.place.location.address.houseNumber||null,Zip:c.place.location.address.zipCode||null,district:c.place.location.address.district||null,City:c.place.location.address.city||null,county:Fp.openData.country,countrycode:c.place.location.address.countryCode||null,distance:c.distance*1000,metric:Fp.openData.metric,latitude:c.place.location.geoCoordinates.latitude,longitude:c.place.location.geoCoordinates.longitude,online:Fp.openData.online,language:Fp.openData.language,uuid:Fp.openData.uuid,isNearby:true,fromHistory:true};Fp.History.setHistoryActivated(false);Fp.Tracking.track("nearbyPlace",{placeId:c.place.a_id,callback:function(){Fp.openDetailContainer(f);}});},dataCheck:function(){var a=false;if(this.data){if((this.data.latitude&&this.data.longitude)&&this.data.latitude>-90&&this.data.latitude<90&&this.data.longitude>-180&&this.data.longitude<180){a=true;}}return a;},clearContent:function(){this.elements.list.innerHTML="";},showError:function(){this.clearContent();Fp.Modules.Manager.deleteModule("Recommendations");if(this.data.isPlace){return;}else{Fp.Modules.toggleLoader();Fp.Modules.Manager.toggleDefaultContent(true);}},reset:function(){}};