var registerClientModel={firstname:"",lastname:"",email:"",phone:"",password:"",hearaboutus:"",state:""},additionalProducts=[{name:"tpd_insurance",amount:null},{name:"trauma_insurance",amount:null},{name:"health_insurance",amount:null},{name:"car_insurance",amount:null},{name:"home_insurance",amount:null},{name:"landlords_insurance",amount:null},],registerApp=angular.module("registerApp",["ngRoute","ngAnimate","ngSanitize","ysDirectives","ysAPI"]);registerApp.controller("registerController",["$scope","$http","$location",function(n,t,i){i.path("/quickcalculator")}]);registerApp.controller("quickcalcController",["$scope","$http","$location","ysapi",function(n,t,i,r){n.serviceFee=75;n.zieltwo=.9;n.cashbackTotal=0;n.trailTotal=0;n.ysproducts=[];n.cashback_chart={};n.calcProducts=quickCalculatorProducts;r.getYSProducts().success(function(t){n.ysproducts=t.ysproducts});n.updateCashback=function(){for(var t=0,r,u,i=0;i<n.calcProducts.length;i+=1)r=n.calcProducts[i],$.isNumeric(r.amount)&&(u=r.amount*r.rate*n.zieltwo,t=t+u);n.trailTotal=t;n.cashbackTotal=t>n.serviceFee?(t-n.serviceFee)/2:0;jQuery.isEmptyObject(n.cashback_chart)||n.updateChart()};n.setCashbackChart=function(t){var i=(new Date).getFullYear(),r={labels:[i+1,i+2,i+3,i+4,i+5],datasets:[{fillColor:"rgba(177, 219, 69, 0.65)",strokeColor:"rgba(148,147,147,0.6)",highlightFill:"rgba(177, 219, 69, 0.9)",highlightStroke:"rgba(148,147,147,1)",data:[parseFloat(n.cashbackTotal).toFixed(2),parseFloat(n.cashbackTotal*2).toFixed(2),parseFloat(n.cashbackTotal*3).toFixed(2),parseFloat(n.cashbackTotal*4).toFixed(2),parseFloat(n.cashbackTotal*5).toFixed(2)]},]};n.cashback_chart=new Chart(t).Bar(r,{responsive:!0,tooltipTemplate:"<%if (label){%>$<%}%><%= value %>",scaleLabel:"$<%=value%>",scaleFontSize:14,scaleFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",scaleFontStyle:"normal",barValueSpacing:2,barStrokeWidth:1})};n.updateChart=function(){i.path()=="/quickcalculator"&&(n.cashback_chart.datasets[0].bars[0].value=parseFloat(n.cashbackTotal).toFixed(2),n.cashback_chart.datasets[0].bars[1].value=parseFloat(n.cashbackTotal*2).toFixed(2),n.cashback_chart.datasets[0].bars[2].value=parseFloat(n.cashbackTotal*3).toFixed(2),n.cashback_chart.datasets[0].bars[3].value=parseFloat(n.cashbackTotal*4).toFixed(2),n.cashback_chart.datasets[0].bars[4].value=parseFloat(n.cashbackTotal*5).toFixed(2),n.cashback_chart.update())};n.setQuickCalculatorProducts=function(){var t=i.search();t!=undefined&&(n.calcProducts[0].amount=t.life_insurance!="null"?t.life_insurance:null,n.updateCashback())};n.setQuickCalculatorProducts()}]);registerApp.controller("estimateController",["$scope","$http","$location",function(n,t,i){var r=document.getElementById("calc-chart").getContext("2d");n.setCashbackChart(r);n.registerForm=function(){ga("send","event","Register","Next","Next Button",parseInt(n.cashbackTotal));mixpanel.track("Register Next",{cashback:n.cashbackTotal});i.path("/registerform")};ga("send","pageview","/account/register/quickcalculator")}]);registerApp.controller("signupController",["$scope","$http","$location","ysapi",function(n,t,i,r){n.hearAboutUsDropdown=[];n.register=registerClientModel;n.states=stateDropdown;n.acceptedTC=!1;n.error_message="";n.submitting=!1;n.additionalProducts=additionalProducts;r.getHearAboutUsValues().success(function(t){n.hearAboutUsDropdown=t.variables});n.submitForm=function(t){t.$valid&&(n.error_message="",n.submitting=!0,n.oldTracking(),n.registerTracking(),r.createMember(n.register).success(function(t){if(t.error.success){var i=n.getProductsToCreate();r.createMemberApplication(t.clientguid,i).success(function(t){t.error.success&&r.loginMember(n.register.email,n.register.password).success(function(n){n.error.success&&(document.location.href="/account/profile")})})}else n.submitting=!1,n.error_message="The email you have entered is invalid."}))};n.oldTracking=function(){var i,t;for(ga("send","event","Quick Calculator","Get trail fees","TrailFees",parseInt(n.trailTotal)),ga("send","event","Quick Calculator","Step 1","EstimatedCashback",parseInt(n.cashbackTotal)),ga("send","event","Calculator Submit","Your Profile",n.register.hearaboutus,parseInt(n.cashbackTotal)),mixpanel.track("Quick Calculator: Step 1",{EstimatedCashback:n.cashbackTotal,estimatedTrailFees:n.trailTotal}),mixpanel.track("Calculator Submit:Your Profile",{}),i=0;i<n.calcProducts.length;i++)t=n.calcProducts[i],$.isNumeric(t.amount)&&(ga("send","event","Quick Calculator","Add Product",t.name,parseInt(t.amount)),mixpanel.track("Quick Calculator: Add Product",{product_id:t.name,amount:t.amount}))};n.registerTracking=function(){var i,t;for(ga("send","event","Register","Register Submit","Submit Button",parseInt(n.cashbackTotal)),mixpanel.track("Register Submit",{cashback:n.cashbackTotal,trailfees:n.trailTotal}),i=0;i<n.calcProducts.length;i++)t=n.calcProducts[i],$.isNumeric(t.amount)&&(ga("send","event","Register","Add Product",t.name,parseInt(t.amount)),mixpanel.track("Register Add Product",{product:t.name,amount:t.amount}))};n.getProductsToCreate=function(){for(var i=[],t=0;t<n.calcProducts.length;t++)i.push({name:n.calcProducts[t].name,amount:n.calcProducts[t].amount});for(t=0;t<n.additionalProducts.length;t++)i.push({name:n.additionalProducts[t].name,amount:n.additionalProducts[t].amount});return i};ga("send","pageview","/account/register/registerform")}]);registerApp.config(["$routeProvider","$locationProvider",function(n){n.when("/quickcalculator",{templateUrl:"/umbraco/surface/RegisterSurface/quickcalculator",controller:"estimateController"}).when("/registerform",{templateUrl:"/umbraco/surface/RegisterSurface/registerform",controller:"signupController"})}])