var namespaceReport={};$(function(){namespaceReport.ReportPage.init()});namespaceReport.ReportPage=function(){"use strict";var r="",w="",b="",p="",k="",u="",i="",d="",a="",t="",f="",e="",o="",s="",h="",c="",l="",tt=function(){it();ft();ct();ut();rt();ti()},it=function(){r=n("stationName");w=n("fuelType");b=n("price");p=n("serviceStationId");k=n("logoUrl");u=n("brand");i=n("address");d=n("complaintUrl");t=n("device")==undefined?"Web":n("device");f=n("version")==undefined?"":n("version");e=n("build")==undefined?"":n("build");o=n("profile")==undefined?"":n("profile");s=n("fcm")==undefined?"":n("fcm");h=n("deviceName")==undefined?"":n("deviceName");c=n("deviceSystem")==undefined?"":n("deviceSystem");l=n("model")==undefined?"":n("model");var v=window.location.href.split("?");v.length>1&&(a=v[1])},rt=function(){$("#page-report-incorrect-address").length>0&&($("#detail-brand").html(u),$("#detail-address").html(i));$("#page-report-station-closed").length>0&&($("#detail-brand").html(u),$("#detail-address").html(i));$("#page-report-station").length>0&&($("#img-station-brand").attr("src",k),$("#detail-station-name").html(r),$("#detail-address").html(i))},ut=function(){t=="ios"&&($("#close-report").hide(),$("#page-report-thank-you").length>0&&$("#close-button").hide());t=="android"&&($("#sticky-navigation").hide(),$("#header-report").hide(),$(".page-report").addClass("device-mode"),$("#page-report-thank-you").length>0&&$("#close-button").hide())},ft=function(){if(window.File&&window.FileReader&&window.FormData){var n=$(".fileImage");n.on("change",function(n){var t=n.target.files[0];t?/^image\//i.test(t.type)?et(t):(alert("Not a valid image!"),$(this).val("")):g()})}else alert("File upload is not supported!")},et=function(n){var t=new FileReader;t.onloadend=function(){ot(t.result,n.type)};t.onerror=function(){alert("There was an error reading the file!")};t.readAsDataURL(n)},ot=function(n,t){var r=800,u=800,i=new Image;i.src=n;i.onload=function(){var e=i.width,o=i.height,l=e>r||o>u,s,h,f,c;!l;e>o?(h=o*(r/e),s=r):(s=e*(u/o),h=u);f=document.createElement("canvas");f.width=s;f.height=h;c=f.getContext("2d");c.drawImage(this,0,0,s,h);n=f.toDataURL(t);st(n)};i.onerror=function(){alert("There was an error processing your file!")}},st=function(n){var r=$("#select-image"),t=r.find(".imgAttachment"),i,u;t.length<=0&&(i=$('<div class="imgAttachment-container">'),i.appendTo(r),t=$('<img class="imgAttachment" style="max-width:150px;">'),t.appendTo(i),u=$('<span class="delete-image-attachment icon-close">'),u.appendTo(i),ht());t.attr("src",n)},ht=function(){$(".delete-image-attachment").click(function(){g()})},g=function(){var t=$(".imgAttachment-container"),n;t.remove();n=$(".fileImage");n.val("")},ct=function(){navigator.geolocation?($("#a-current-location").show(),$("#a-current-location").click(function(){lt()}),$("#clear-textbox").click(function(){var n=$("#a-current-location").attr("data-connected-textbox");n!=undefined&&($("#"+n).val("").removeAttr("disabled").focus(),$("#clear-textbox").hide())})):$("#a-current-location").hide()},lt=function(){if(navigator.geolocation)navigator.geolocation.getCurrentPosition(vt,at,{enableHighAccuracy:!0,timeout:1e4})},at=function(n){console.warn("ERROR("+n.code+"): "+n.message)},vt=function(n){console.log(n);var i=n.coords.latitude,r=n.coords.longitude,t=$("#a-current-location").attr("data-connected-textbox");t!=undefined&&($("#"+t).val(i+","+r).attr("disabled","disabled"),$("#clear-textbox").show())},n=function(n){for(var u=window.location.search.substring(1),r=u.split("&"),t,i=0;i<r.length;i++)if(t=r[i].split("="),t[0]===n)return t[1]===undefined?!0:decodeURIComponent(t[1])},r="",w="",b="",p="",k="",u="",i="",d="",a="",yt=function(){var a=y(),n;a==!0&&(n={issueType:"IncorrectAddress",stationID:p,stationAddress:i,stationBrand:u,stationName:r,actualLocation:$("#txt-actual-location").val(),comments:$("#txt-area-additional-comments").val(),image:$(".imgAttachment").attr("src")==undefined?"":$(".imgAttachment").attr("src"),mobile:$("#txt-mobile").val(),email:$("#txt-email").val(),device:t,version:f,build:e,profile:o,fcm:s,deviceName:h,deviceSystem:c,model:l},v(n))},pt=function(){var a=y(),n;a==!0&&(n={issueType:"StationClosed",stationID:p,stationAddress:i,stationBrand:u,stationName:r,actualLocation:"",comments:$("#txt-area-additional-comments").val(),image:$(".imgAttachment").attr("src")==undefined?"":$(".imgAttachment").attr("src"),mobile:$("#txt-mobile").val(),email:$("#txt-email").val(),device:t,version:f,build:e,profile:o,fcm:s,deviceName:h,deviceSystem:c,model:l},v(n))},wt=function(){var i=y(),n;i==!0&&(n={issueType:"MissingStation",stationID:"",stationAddress:"",stationBrand:$("#txt-brand").val(),stationName:"",actualLocation:$("#txt-actual-location").val(),comments:$("#txt-area-additional-comments").val(),image:$(".imgAttachment").attr("src")==undefined?"":$(".imgAttachment").attr("src"),mobile:$("#txt-mobile").val(),email:$("#txt-email").val(),device:t,version:f,build:e,profile:o,fcm:s,deviceName:h,deviceSystem:c,model:l},v(n))},bt=function(){var i=y(),n;i==!0&&(n={issueType:"Bug",stationID:"",stationAddress:"",stationBrand:"",stationName:"",actualLocation:"",comments:$("#txt-area-additional-comments").val(),image:$(".imgAttachment").attr("src")==undefined?"":$(".imgAttachment").attr("src"),mobile:$("#txt-mobile").val(),email:$("#txt-email").val(),device:t,version:f,build:e,profile:o,fcm:s,deviceName:h,deviceSystem:c,model:l},v(n))},v=function(n){var i=window.fuelcheck.settings.reportIssue;$.post(i,n,function(){var n=window.fuelcheck.settings.baseUrl+"Report/thankyou?device="+t;window.location.href=n}).done(function(){}).fail(function(){alert("An error occured, please try again!")}).always(function(){})},kt=function(){var o=d+"?SS="+r+" "+encodeURIComponent(i)+"&FuelType="+w+"&Price="+b+"&Referrer=FuelCheckAppv1",t=new Date,e=t.getDate(),u;e<10&&(e="0"+e);u=t.getMonth()+1;u<10&&(u="0"+u);var s=t.getFullYear(),n=t.getHours(),f=t.getMinutes(),h=n>=12?"PM":"AM";n=n%12;n=n?n:12;f=f<10?"0"+f:f;o=o+"&Date="+e+"/"+u+"/"+s+"&Time="+n+":"+f+h;window.open(o,"_blank")},dt=function(){window.location.href=window.fuelcheck.settings.baseUrl+"Report/IncorrectAddress?"+a},gt=function(){window.location.href=window.fuelcheck.settings.baseUrl+"Report/StationPermanentlyClosed?"+a},ni=function(){var n=ii(),t=$("#popup-confirmation-outer");n==!0?nt():t.removeClass("hide-popup")},nt=function(){var n="";($("#page-report-incorrect-address").length>0||$("#page-report-station-closed").length>0)&&(n=window.fuelcheck.settings.baseUrl+"Report/ReportThisStation?"+a);($("#page-report-missing-station").length>0||$("#page-report-bug").length>0)&&(n=window.fuelcheck.settings.baseUrl+"Report/ReportAnIssue");window.location.href=n},ti=function(){var n=$("#popup-confirmation-outer");$("#button-proceed-confirmation").bind("click",function(){nt()});$("#button-cancel-confirmation").bind("click",function(){n.addClass("hide-popup")});$("#close-confirmation-popup").bind("click",function(){n.addClass("hide-popup")})},ii=function(){var n=!0;return $("input[type=text]").each(function(){$(this).val().trim()!=""&&(n=!1)}),$("input[type=file]").each(function(){$(this).val().trim()!=""&&(n=!1)}),$("textarea").each(function(){$(this).val().trim()!=""&&(n=!1)}),n},ri=function(){window.location.href=window.fuelcheck.settings.baseUrl},y=function(){var n=!0,t=null;return $("*[data-required]").each(function(){var i=$(this);i.val().trim()==""?(t==null&&(t=i),i.addClass("error-validation-required"),n=!1):(i.removeClass("error-validation-required"),n=n==!1?!1:!0)}),t!=null&&t.focus(),n};return{init:tt,submitIncorrectAddress:yt,submitStationClosed:pt,submitMissingStation:wt,submitBugOrOtherIssue:bt,reportToFairTraiding:kt,goToIncorrectDetailsPage:dt,goToStationClosedPage:gt,goToLastPage:ni,goToHomePage:ri}}()