var namespaceReport={};$(function(){namespaceReport.ReportPage.init()});namespaceReport.ReportPage=function(){"use strict";var u="",p="",w="",b="",k="",r="",t="",d="",a="",i="",f="",e="",o="",s="",h="",c="",l="",tt=function(){it();ft();ct();ut();rt();ri()},it=function(){u=n("stationName");p=n("fuelType");w=n("price");b=n("serviceStationId");k=n("logoUrl");r=n("brand");t=n("address");d=n("complaintUrl");i=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-price").length>0&&($("#detail-brand").html(r),$("#detail-address").html(t),$("#detail-fueltype").html(p),$("#detail-fuelprice").html(w));$("#page-report-incorrect-address").length>0&&($("#detail-brand").html(r),$("#detail-address").html(t));$("#page-report-station-closed").length>0&&($("#detail-brand").html(r),$("#detail-address").html(t));$("#page-report-station").length>0&&($("#img-station-brand").attr("src",k),$("#detail-station-name").html(u),$("#detail-address").html(t))},ut=function(){i=="ios"&&($("#close-report").hide(),$("#page-report-thank-you").length>0&&$("#close-button").hide());i=="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])},u="",p="",w="",b="",k="",r="",t="",d="",a="",yt=function(){var a=y(),n;a==!0&&(n={issueType:"PriceMismatch",stationID:b,stationAddress:t,stationBrand:r,stationName:u,fuelType:p,fuelPrice:w,fuelActualPrice:$("#txt-actual-fuelprice").val(),comments:$("#txt-area-additional-comments").val(),image:$(".imgAttachment").attr("src")==undefined?"":$(".imgAttachment").attr("src"),contactName:$("#txt-name").val(),mobile:$("#txt-mobile").val(),email:$("#txt-email").val(),device:i,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:"IncorrectAddress",stationID:b,stationAddress:t,stationBrand:r,stationName:u,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:i,version:f,build:e,profile:o,fcm:s,deviceName:h,deviceSystem:c,model:l},v(n))},wt=function(){var a=y(),n;a==!0&&(n={issueType:"StationClosed",stationID:b,stationAddress:t,stationBrand:r,stationName:u,actualLocation:"",comments:$("#txt-area-additional-comments").val(),image:$(".imgAttachment").attr("src")==undefined?"":$(".imgAttachment").attr("src"),mobile:$("#txt-mobile").val(),email:$("#txt-email").val(),device:i,version:f,build:e,profile:o,fcm:s,deviceName:h,deviceSystem:c,model:l},v(n))},bt=function(){var t=y(),n;t==!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:i,version:f,build:e,profile:o,fcm:s,deviceName:h,deviceSystem:c,model:l},v(n))},kt=function(){var t=y(),n;t==!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:i,version:f,build:e,profile:o,fcm:s,deviceName:h,deviceSystem:c,model:l},v(n))},v=function(n){var t=window.fuelcheck.settings.reportIssue;$.post(t,n,function(){var n=window.fuelcheck.settings.baseUrl+"Report/thankyou?device="+i;window.location.href=n}).done(function(){}).fail(function(){alert("An error occured, please try again!")}).always(function(){})},dt=function(){var o=d+"?SS="+u+" "+encodeURIComponent(t)+"&FuelType="+p+"&Price="+w+"&Referrer=FuelCheckAppv1",i=new Date,e=i.getDate(),r;e<10&&(e="0"+e);r=i.getMonth()+1;r<10&&(r="0"+r);var s=i.getFullYear(),n=i.getHours(),f=i.getMinutes(),h=n>=12?"PM":"AM";n=n%12;n=n?n:12;f=f<10?"0"+f:f;o=o+"&Date="+e+"/"+r+"/"+s+"&Time="+n+":"+f+h;window.open(o,"_blank")},gt=function(){window.location.href=window.fuelcheck.settings.baseUrl+"Report/PriceMismatch?"+a},ni=function(){window.location.href=window.fuelcheck.settings.baseUrl+"Report/IncorrectAddress?"+a},ti=function(){window.location.href=window.fuelcheck.settings.baseUrl+"Report/StationPermanentlyClosed?"+a},ii=function(){var n=ui(),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},ri=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")})},ui=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},fi=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,submitIncorrectPrice:yt,submitIncorrectAddress:pt,submitStationClosed:wt,submitMissingStation:bt,submitBugOrOtherIssue:kt,reportToFairTraiding:dt,goToPriceMismatchPage:gt,goToIncorrectDetailsPage:ni,goToStationClosedPage:ti,goToLastPage:ii,goToHomePage:fi}}()