var autoUpdate={gettingExchangeRate:!1,skipNextAutoUpdate:0,initialize:function(){if(!useSignalR){console.log("Not using SignalR so skipping");return}var n=$.connection.exchangeRatesHub;$.connection.hub.stateChanged(function(t){if(t.newState===$.signalR.connectionState.connecting,t.newState===$.signalR.connectionState.connected){var i=exchangeRates.C1Currency+exchangeRates.C2Currency;n.server.watch(i)}t.newState===$.signalR.connectionState.reconnecting&&self.connectMessage("SignalR Reconnecting...");t.newState===$.signalR.connectionState.disconnected&&console.log("SignalR Disconnected.")});n.client.updateRates=function(n){autoUpdate.showUpdatedRates(n);newChart.addPoint(n)};$(window).bind("unload",function(){var t=exchangeRates.C1Currency+exchangeRates.C2Currency;n.server.stopWatching(t);console.log("Un-subscribed from currency: "+t)});console.log("Using www.Dollars2Pounds.com for SignalR");$.connection.hub.url="https://www.Dollars2Pounds.com/signalr";$.connection.hub.logging=!1;$.connection.hub.start()},getLatestExchangeRate:function(){if(autoUpdate.gettingExchangeRate){useSignalR||autoUpdate.setTimer();return}if(autoUpdate.skipNextAutoUpdate>0){autoUpdate.skipNextAutoUpdate--;console.log("Skipping this update because of previous errors. "+autoUpdate.skipNextAutoUpdate+" left.");autoUpdate.setTimer();return}autoUpdate.gettingExchangeRate=!0;console.log("Using REST api");$.ajax({type:"GET",url:"/WebApi/ExchangeRate/"+exchangeRates.C1Currency+"/"+exchangeRates.C2Currency+"/F6A76A3B-CBA7-46FC-BF7C-1C6DCB280ECF",contentType:"application/json; charset=utf-8",processData:!1,dataType:"json",timeout:5e3,async:!0,cache:!1,success:function(n){console.log("Got new exchange rate");autoUpdate.showUpdatedRates(n);autoUpdate.setTimer()},error:function(n,t,i){console.log("Skipping next 5 updated because of server errors");autoUpdate.skipNextAutoUpdate=5;autoUpdate.gettingExchangeRate=!1;ajaxFailed(n,t,i);autoUpdate.setTimer()}})},setTimer:function(){useSignalR||(console.log("Setting fx update for : "+exchangeRates.refreshInterval+" seconds"),window.setTimeout(autoUpdate.getLatestExchangeRate,1e3*exchangeRates.refreshInterval))},showUpdatedRates:function(n){autoUpdate.gettingExchangeRate=!1;autoUpdate.updateRateValues(n);autoUpdate.chartRefreshCounter++;autoUpdate.refreshRates()},getFormattedDelta:function(n){return n=Math.round(n*1e4)/1e4,(n===0||n=="0")&&(n=""),n>0&&(n="+"+n),n},updateRateValues:function(n){if(n==null){console.log("Returned result was null for autoUpdate");return}exchangeRates.invExchangeRateDelta=n.C1Value-exchangeRates.invExchangeRate;exchangeRates.exchangeRateDelta=n.C2Value-exchangeRates.exchangeRate;exchangeRates.Id=n.Id;exchangeRates.invExchangeRate=n.C1Value;exchangeRates.exchangeRate=n.C2Value;exchangeRates.lastUpdated=n.LastUpdated;exchangeRates.lastUpdatedDateTime=n.LastUpdatedDateTime;exchangeRates.lastUpdatedLink=n.LastUpdatedLink},refreshRates:function(){$("#ratesC1Value").html(exchangeRates.invExchangeRate);$("#ratesC1Delta").html(autoUpdate.getFormattedDelta(exchangeRates.invExchangeRateDelta));$("#ratesC2Value").html(exchangeRates.exchangeRate);$("#ratesC2Delta").html(autoUpdate.getFormattedDelta(exchangeRates.exchangeRateDelta));autoUpdate.refreshRatesUpdatedTime();autoUpdate.hightlightChange(exchangeRates.invExchangeRateDelta,$("#ratesC1Value"));autoUpdate.hightlightChange(exchangeRates.exchangeRateDelta,$("#ratesC2Value"));$("#ratesUpdatedLink").effect("highlight",{},"slow")},refreshRatesUpdatedTime:function(){var t=moment(exchangeRates.lastUpdatedDateTime),n=t.format("LL");n+=" ";n+=t.format("HH:mm:ss");n+=" ";n+="("+t.twitter()+")";$("#ratesUpdatedLink").html(n);$("#ratesUpdatedLink").attr("href",exchangeRates.lastUpdatedLink)},hightlightChange:function(n,t){if(n>-5e-5&&n<5e-5){t.removeClass("deltaDown");t.removeClass("deltaUp");t.effect("highlight",{color:"#ffd800"},"slow");return}n>0?(t.removeClass("deltaDown"),t.addClass("deltaUp")):(t.addClass("deltaDown"),t.removeClass("deltaUp"))}},updating,lastId;D2P.CalculatorsPage=D2P.CalculatorsPage||{};D2P.CalculatorsPage.ViewModel=function(n){var t=this;return t.calculator=new CalculatorViewModel(n),t.feeCalculator=new FeeCalculatorViewModel(n),t.initialize=function(){useSignalR&&(console.log("initialize auto-update"),autoUpdate.initialize())},t};D2P.CalculatorsPage.WireEvents=function(){$(".tabs").tabs()};var CalculatorViewModel=function(n){var t=this;return t.exchangeRate=n,t.showConversions=ko.observable(!1),t.c1Amount=ko.observable("1.00"),t.c2Amount=ko.observable(),t.salesTax=ko.observable(0),t.includeFee=ko.observable(!1),t.fee=ko.observable(3),t.showAdvancedOptions=ko.observable(!1),t.conversions=ko.observableArray([]),t.latestConversion=ko.observable(),t.fromCurrency=ko.observable(),t.fromCurrencySymbol=ko.observable(),t.toCurrency=ko.observable(),t.toCurrencySymbol=ko.observable(),t.errorMessage=ko.observable(),t.isValid=ko.observable(!0),t.isInvalid=ko.computed(function(){return!t.isValid()}),t.c1Amount.subscribe(function(n){isNaN(n)?(t.errorMessage("The value entered is not a number, please enter only numeric values. e.g. 1234.56"),t.isValid(!1)):t.isValid(!0)}),t.hasMidpointRates=ko.computed(function(){return t.latestConversion()==null?!1:t.latestConversion().hasMidpointRates()}),t.midpointLink=ko.computed(function(){return t.latestConversion()==null?"/Out/midpoint.com":"/Out/midpoint.com?currency="+t.latestConversion().fromCurrency()+"&amount="+t.latestConversion().effectiveAmount()}),t.showAdvancedOptionsOptions=ko.computed(function(){return!t.showAdvancedOptions()}),t.includingTaxAndFees=ko.computed(function(){var n,i,r;try{return n=parseFloat(t.c1Amount()),i=n/100*parseFloat(t.salesTax()),n+=i,console.log("Sales Tax: "+i),t.includeFee()&&(r=t.fee()*n/100,n+=r,console.log("Fee: "+r)),n}catch(u){return console.log(u),""}}),t.setFocus=function(){$("#amount").focus();$("#amount").select()},t.DoShowAdvancedOptions=function(){t.showAdvancedOptions(!0)},t.startInputKeyUp=function(n){console.log("key up");n.keyCode==13&&t.convertC1toC2()},t.inputSelected=function(){$("#start").select()},t.getStartAmount=function(){return t.includingTaxAndFees()},t.convertC1toC2=function(){var n=t.getStartAmount(),i;isNaN(n)?(t.errorMessage("The value entered is not a number, please enter only numeric values. e.g. 34.53"),t.isValid(!1)):(i=calculatorCommon.convertFrom(n),t.c2Amount(i),t.fromCurrency(exchangeRates.C1Currency),t.fromCurrencySymbol(exchangeRates.C1Symbol),t.toCurrency(exchangeRates.C2Currency),t.toCurrencySymbol(exchangeRates.C2Symbol),t.addConversion())},t.convertC2toC1=function(){var n=t.getStartAmount(),i;isNaN(n)?(t.errorMessage("The value entered is not a number, please enter only numeric values. e.g. 34.53"),t.isValid(!1)):(i=calculatorCommon.convertTo(n),t.c2Amount(i),t.fromCurrency(exchangeRates.C2Currency),t.fromCurrencySymbol(exchangeRates.C2Symbol),t.toCurrency(exchangeRates.C1Currency),t.toCurrencySymbol(exchangeRates.C1Symbol),t.addConversion())},t.addConversion=function(){var n=new CalculatorConvertedAmount,i;n.startAmount(t.c1Amount());n.effectiveAmount(t.includingTaxAndFees());n.resultAmount(t.c2Amount());i=t.getPermaLink(t.fromCurrency(),t.toCurrency(),t.includingTaxAndFees());n.permaLink(i);n.fromCurrencySymbol(t.fromCurrencySymbol());n.fromCurrency(t.fromCurrency());n.toCurrencySymbol(t.toCurrencySymbol());n.toCurrency(t.toCurrency());n.salesTax(t.salesTax());t.includeFee()&&n.fee(t.fee());n.setNotes();t.latestConversion(n);t.conversions.push(n);t.showConversions(!0)},t.getPermaLink=function(n,t,i){return"/Convert/"+n+"/"+t+"/"+i},t},CalculatorConvertedAmount=function(){var n=this;return n.defaultNotesText="Click to add notes.",n.startAmount=ko.observable(),n.effectiveAmount=ko.observable(),n.resultAmount=ko.observable(),n.permaLink=ko.observable(),n.fromCurrency=ko.observable(),n.fromCurrencySymbol=ko.observable(),n.toCurrency=ko.observable(),n.toCurrencySymbol=ko.observable(),n.salesTax=ko.observable(0),n.fee=ko.observable(0),n.notes=ko.observable(n.defaultNotesText),n.midpointBuy=ko.observable(new MidpointRate),n.midpointSell=ko.observable(new MidpointRate),n.hasMidpointRates=ko.observable(!1),n.from=ko.computed(function(){return n.fromCurrencySymbol()+n.startAmount()}),n.via=ko.computed(function(){return n.salesTax()>0||n.fee>0?"-> "+n.effectiveAmount()+" = ":"="}),n.to=ko.computed(function(){return n.toCurrencySymbol()+n.resultAmount()}),n.setNotes=function(){if(n.salesTax()>0||n.fee()>0){var t="";n.salesTax()>0&&(t+="Includes "+n.salesTax()+"% tax");n.fee()>0?t+=n.salesTax()>0?" and "+n.fee()+"% fee. ":"Includes "+n.fee()+"% fee. ":n.salesTax()>0&&(t+=".");n.notes(t)}},n.addNotes=function(){n.notes()==n.defaultNotesText&&n.notes("")},n.getConversionRates=function(){},n},MidpointRate=function(){var n=this;return n.fromAmount=ko.observable(""),n.fromCurrencySymbol=ko.observable(""),n.midpointCost=ko.observable(0),n.load=function(t,i,r){n.fromAmount(t);n.fromCurrencySymbol(i);n.midpointCost(r)},n.buyTitle=ko.computed(function(){return"Funding required to purchase "+n.fromCurrencySymbol()+" "+n.fromAmount()+" though Midpoint.com."}),n.sellTitle=ko.computed(function(){return"Amount resulting from the sale of "+n.fromCurrencySymbol()+" "+n.fromAmount()+" though Midpoint.com."}),n},chartPage={baseUrl:"",currencies:null,initialize:function(){var n,t,i;$("#loading").fadeIn("fast");$("#sidebar").hide();$("#content").addClass("fullContent");$("#content").removeClass("content");newChart.selectedHistoryOption=5;newChart.chartDateRange="all";newChart.flipped=!1;n=new CurrencyPairViewModel(exchangeRates.C1Currency,exchangeRates.C2Currency);n.showAddButton(!1);n.showUpdateButton(!0);n.isFirstSeries=!0;t=[n];newChart.buildChart(!0,null,t[0].seriesAdded);i=new ChartsViewModel(chartPage.currencies,t,exchangeRates.C1Currency,exchangeRates.C2Currency);i.addPlaceholderSeries();ko.applyBindings(i)},updateChartLink:function(n,t){$("#linkToPage").html(chartPage.baseUrl+"/Charts/"+n+"/"+t)}},ChartsViewModel=function(n,t,i,r){var u=this;return u.Currency1=i,u.Currency2=r,u.currencyList=n,u.currencyPairs=ko.observableArray(t),u.nextCurrencyPair=null,u.chartSeries=null,u.showCompare=ko.observable(!1),u.compare=ko.observable(null),u.compareOptions=ko.observableArray(["None","Value","Percent"]),u.selectedYAxis=ko.observable("Primary"),u.selectedYAxisOptions=ko.observableArray(["Primary","Secondary"]),u.compare.subscribe(function(n){console.log("Compare mode changed to "+n);u.updateCompare()}),u.updateCompare=function(){var n=u.compare();switch(n){case"None":newChart.chart.yAxis[0].setCompare(null,!0);break;case"Value":newChart.chart.yAxis[0].setCompare("value",!0);break;case"Percent":newChart.chart.yAxis[0].setCompare("percent",!0);break;default:newChart.chart.yAxis[0].setCompare(null,!0)}},u.add=function(){console.log("Adding new series");var n=u.nextCurrencyPair;u.currencyPairs().length===2?(u.compare("Value"),u.showCompare(!0)):u.currencyPairs().length===1&&u.showCompare(!1);n.addSeriesToChart(u.compare(),function(){u.updateCompare()});u.addPlaceholderSeries()},u.addPlaceholderSeries=function(){console.log("Adding next currency pair option");u.nextCurrencyPair=new CurrencyPairViewModel(u.Currency1,"");u.currencyPairs.push(u.nextCurrencyPair)},u.remove=function(n){console.log("Removing series");n.removeChartSeries();u.currencyPairs.remove(n);u.currencyPairs.length<2&&u.compare("null")},u},cheatSheetWidget={initialize:function(){$("#tabs").tabs();$(".cheatSheet tr:even").addClass("oddRow")}},CurrencyPairViewModel=function(n,t){var i=this;return i.fromCurrency=ko.observable(n),i.toCurrency=ko.observable(t),i.showAddButton=ko.observable(!0),i.showUpdateButton=ko.observable(!1),i.chartSeries=null,i.color=ko.observable(""),i.isFirstSeries=!1,i.currencyPair=ko.computed(function(){return i.toCurrency()?i.fromCurrency()+i.toCurrency():i.fromCurrency()+"---"}),i.flip=function(){var n=i.fromCurrency();i.fromCurrency(i.toCurrency());i.toCurrency(n)},i.callback=null,i.addSeriesToChart=function(n,t){console.log("Adding series.");i.callback=t;i.compareMode=n;newChart.addSeries(i.fromCurrency(),i.toCurrency(),n,!0,i.seriesAdded)},i.update=function(){console.log("Add/Updating series.");i.chartSeries!=null&&i.removeChartSeries();newChart.addSeries(i.fromCurrency(),i.toCurrency(),i.compareMode,!0,i.seriesAdded)},i.seriesAdded=function(n){console.log("*** Series added: "+n);i.chartSeries=n;try{n.color!==undefined&&i.color(n.color)}catch(t){}i.isFirstSeries||newChart.updateSeriesDataForZoomedArea(n);console.log("Hiding add");i.showAddButton(!1);i.showUpdateButton(!0);i.callback&&(i.callback(),i.callback=null)},i.removeChartSeries=function(){try{newChart.removeSeries(i.chartSeries)}catch(n){console.error("Failed to remove chart series: "+n)}newChart.redraw()},i.setCompare=function(n){chartSeries.setCompare(n)},i},ExchangeRateViewModel=function(){var n=this;return n.baseCurrency=ko.observable(),n.baseCurrencySymbol=ko.observable(),n.toCurrency=ko.observable(),n.toCurrencySymbol=ko.observable(),n.exchangeRate=ko.observable(),n.inverseExchangeRate=ko.observable(),n.exchangeRateDelta=ko.observable(),n.invExchangeRateDelta=ko.observable(),n.lastUpdated=ko.observable(),n.lastUpdatedDateTime=ko.observable(null),n.lastUpdatedLink=ko.observable(""),n.load=function(t){console.log("Last daily rate: "+t.Date);n.lastUpdated(t.Date);n.lastUpdatedDateTime(moment(t.Date));console.log("Currency Pair: "+t.CurrencyPair);n.baseCurrency(t.CurrencyPair);n.toCurrency(t.CurrencyPair);n.exchangeRate(t.Rate);n.inverseExchangeRate(t.InverseRate);n.exchangeRateDelta(t.RateDelta);n.invExchangeRateDelta(t.InverseRateDelta)},n},FeeCalculatorViewModel=function(n){var t=this;return t.exchangeRate=n,t.receivedCurrency=ko.observable(n.C2Currency),t.receivedAmount=ko.observable(""),t.paidCurrency=ko.observable(n.C1Currency),t.paidAmount=ko.observable(),t.feePaid=ko.observable(),t.feePaidInOriginalCurrency=ko.observable(),t.feePercentage=ko.observable(),t.idealExchangeRate=ko.observable(t.exchangeRate.invExchangeRate),t.receivedExchangeRate=ko.observable("?????"),t.showResults=ko.observable(!1),t.flipped=ko.observable(!1),t.flipCurrencies=function(){var n=t.receivedCurrency();t.receivedCurrency(t.paidCurrency());t.paidCurrency(n);t.flipped(!t.flipped())},t.compute=function(){if(t.receivedAmount()&&t.paidAmount()){var s={receivedCurrency:t.receivedCurrency(),receivedAmount:t.receivedAmount(),paidCurrency:t.paidCurrency(),paidAmount:t.paidAmount()},i=t.idealExchangeRate(),r=parseFloat(t.paidAmount()),u=r*i,n=parseFloat(t.receivedAmount()),f=u-n,e=accounting.toFixed(u/n*100-100,2),o=accounting.toFixed(n/r,4);t.feePaid(accounting.formatNumber(f,2,","));t.feePaidInOriginalCurrency(accounting.formatNumber(f/i,2,","));t.feePercentage(e);t.receivedExchangeRate(o);t.showResults(!0)}},t.receivedAmount.subscribe(function(){t.compute()}),t.paidAmount.subscribe(function(){t.compute()}),t.flipped.subscribe(function(n){var i=n?t.exchangeRate.exchangeRate:t.exchangeRate.invExchangeRate;t.idealExchangeRate(i);t.compute()}),t};useSignalR=!0;updating=!1;lastId=0;$(document).ready(function(){$.ajaxSetup({async:!0});$(".ajaxSpinner").hide();$(".ajaxSpinner").ajaxStart(function(){$(this).show()}).ajaxStop(function(){$(this).hide()})});ko.bindingHandlers.executeOnEnter={init:function(n,t,i,r){var u=i();$(n).keypress(function(n){var t=n.which?n.which:n.keyCode;return t===13?(u.executeOnEnter.call(r),!1):!0})}};var HomePage={start:function(n,t){cheatSheetWidget.initialize();$(".tabs").tabs();var i=new HomePageViewModel(n,t,exchangeRates);i.initialize();console.log("*** Home page");newChart.selectedHistoryOption=1;newChart.buildChart(!0,n);ko.applyBindings(i);i.calculator.setFocus()},refreshExchangeRateTime:function(){autoUpdate.refreshRatesUpdatedTime()}},HomePageViewModel=function(n,t,i){var r=this;return r.siteVariables=n,r.initialExchangeRate=i,r.realtimeSparkLine=new RealtimeSparklineViewModel(n),r.observableExchangeRates=new ObservableExchangeRateViewModel(n),r.webSite=new ko.observable(n.WebSite),r.conversionTitle=new ko.observable("Conversion from "+n.FromCurrency+" to "+n.ToCurrency),r.currencyPair=n.FromCurrency+n.ToCurrency,r.calculator=new CalculatorViewModel(i),r.feeCalculator=new FeeCalculatorViewModel(i),r.showBrexitEffectVisible=ko.observable(!1),r.showingBrexitEffect=ko.observable(!1),r.showBrexitEffectText=ko.observable("Show Pre-Brexit Vote Rate"),r.initialize=function(){console.log("Homepage initialize");r.observableExchangeRates.initialize(t,newChart.addPoint);(r.currencyPair==="GBPEUR"||r.currencyPair==="EURGBP")&&r.showBrexitEffectVisible(!0);(r.currencyPair==="GBPUSD"||r.currencyPair==="USDGBP")&&r.showBrexitEffectVisible(!0);r.realtimeSparkLine.initialize(r.initialExchangeRate);r.observableExchangeRates.realtimeSparklineCallback=r.realtimeSparkLine.newRate},r.showBrexitEffect=function(){r.showingBrexitEffect()?(newChart.hideBrexitEffect(),r.showBrexitEffectText("Show Pre-Brexit Vote Rate")):(newChart.showBrexitEffect(r.currencyPair),r.showBrexitEffectText("Hide Pre-Brexit Vote Rate"));r.showingBrexitEffect(!r.showingBrexitEffect())},r},newChart={key:"F6A76A3B-CBA7-46FC-BF7C-1C6DCB280ECF",flipped:!0,selectedHistoryOption:0,chart:null,chartMinDate:Date.now()-24192e5,chartDateRange:"all",currentMin:0,currentMax:0,siteName:"Dollars2Pounds.com",buildChart:function(n,t,i){t!==undefined&&t!==null&&(newChart.siteName=t.WebSite+".com");newChart.chart=newChart.createChart2("highchartContainer",n);newChart.flipped?newChart.addSeries(exchangeRates.C2Currency,exchangeRates.C1Currency,null,!0,function(n){i!==undefined&&i!==null&&i(n);newChart.addSeries(exchangeRates.C1Currency,exchangeRates.C2Currency,null,!1,null)}):newChart.addSeries(exchangeRates.C1Currency,exchangeRates.C2Currency,null,!0,i)},convertTimesToMs:function(n){return $.map(n,function(n){return[[n[0]*1e3,n[1]/1e5]]})},addSeries:function(n,t,i,r,u){newChart.chart.showLoading("Loading exchange rate history for "+n+t);var f="/WebApi/DailyChartData/"+n+"/"+t+"/"+newChart.key;f+="?range="+newChart.chartDateRange;exchangeRates.Amount!==1&&(f+="?amount="+exchangeRates.Amount);$.getJSON(f,function(n){if(n===null||n===undefined){console.warn("No data returned for chart series.");return}n.SeriesDataSeconds&&n.SeriesDataSeconds.length>0&&(console.warn("Found "+n.SeriesDataSeconds.length+" chart points for "+n.SeriesCaption),n.SeriesData=newChart.convertTimesToMs(n.SeriesDataSeconds));var t=newChart.addChartSeries(n,i,r);newChart.chart.hideLoading();u!==null&&u(t)})},hideBrexitEffect:function(){newChart.chart.yAxis[0].removePlotLine("23June2016");newChart.chart.yAxis[0].setExtremes()},showBrexitEffect:function(n){var u={color:"red",dashStyle:"shortdash",width:2,label:{text:"Pre-Brexit Vote (rate @ 23 June 2016)"},id:"23June2016"},t=0,i,r;n==="GBPEUR"?t=.768273:n==="EURGBP"?t=1.30162:n==="USDGBP"?t=1.47994:n==="GBPUSD"&&(t=.6757);u.value=t;newChart.chart.yAxis[0].addPlotLine(u);i=newChart.chart.yAxis[0].max;r=newChart.chart.yAxis[0].min;r>t&&(r=t-t/100);i<t&&(i=t+t/100);newChart.chart.yAxis[0].setExtremes(r,i)},addFlags:function(n){var t={type:"flags",name:"Brexit Vote",data:[{x:14667012e5,title:"Brexit Vote Day"},{x:14561604e5,title:"Brexit Vote Announced"}],onSeries:n,shape:"squarepin",showInLegend:!1};newChart.chart.addSeries(t)},addChartSeries:function(n,t,i){return newChart.chart.addSeries({type:"line",id:n.SeriesCaption,name:n.SeriesCaption,data:n.SeriesData,tooltop:{yDecimals:4},dataGrouping:{enabled:!0,groupPixelWidth:2},compare:t,connectNulls:!1,visible:i,showInNavigator:!0})},removeSeries:function(n){n.remove(!0,!1,!1)},addPoint:function(n){var i,t,r;if(n)try{newChart.addingPoints=!0;i=newChart.chart.series[0];t=[n.LastUpdatedDateTimeEpoch*1e3,parseFloat(n.C2Value)];i.addPoint(t,!0,!1,!0);r=newChart.chart.series[1];t=[n.LastUpdatedDateTimeEpoch*1e3,1/parseFloat(n.C2Value)];r.addPoint(t,!0,!1,!0)}catch(u){console.error("Failed to add point to chart: "+u)}finally{newChart.addingPoints=!1}},buildButtons:function(n){return n?[{type:"hour",count:1,text:"1h"},{type:"day",count:1,text:"1d"},{type:"week",count:1,text:"1w"},{type:"month",count:1,text:"1m"},{type:"month",count:3,text:"3m"},{type:"month",count:6,text:"6m"},{type:"year",count:1,text:"1y"},{type:"year",count:2,text:"2y"},{type:"year",count:5,text:"5y"},{type:"all",text:"All"}]:[{type:"hour",count:1,text:"1h"},{type:"day",count:1,text:"1d"},{type:"week",count:1,text:"1w"},{type:"month",count:1,text:"1m"},{type:"all",text:"All"}]},createChart2:function(n,t){var i=newChart.buildButtons(t);return new Highcharts.StockChart({chart:{zoomType:"x",renderTo:n},title:{text:"Exchange Rate History",margin:50,style:{fontSize:"22px"}},xAxis:{events:{afterSetExtremes:newChart.afterSetExtremes},minRange:6e4,ordinal:!1},yAxis:{title:{text:"Exchange rate"},opposite:!1},legend:{enabled:!0,align:"center",layout:"horizontal",verticalAlign:"bottom",y:20},plotOptions:{line:{allowPointSelect:!0,animation:!1,connectNulls:!1,compare:null}},rangeSelector:{buttons:i,selected:newChart.selectedHistoryOption,inputEnabled:!0},series:[],credits:{enabled:!0,text:newChart.siteName,url:"https://www."+newChart.siteName},exporting:{filename:"ExchangeRateHistory"}})},afterSetExtremes:function(n){var t,i;if((newChart.currentMin!==n.min||newChart.currentMax!==n.max)&&!newChart.addingPoints)for(newChart.addingPoints=!0,newChart.currentMin=n.min,newChart.currentMax=n.max,newChart.chart.showLoading("Loading data from server..."),t=0;t<newChart.chart.series.length;t++)i=newChart.chart.series[t],newChart.updateSeriesDataForZoomedArea(i)},updateSeriesDataForZoomedArea:function(n){var i=n.name;if(i.length===6){var r=i.substring(0,3),u=i.substring(3,6),t="/WebApi/ChartData/"+r+"/"+u+"/"+newChart.key;t+="?function=Ignore";t+="&dateMin="+newChart.currentMin;t+="&dateMax="+newChart.currentMax;t+="&threshold=2000";$.getJSON(t,function(n){n!==null&&(newChart.updateChartSeries(n),newChart.chart.hideLoading());newChart.addingPoints=!1})}},updateChartSeries:function(n){var t;if(n.SeriesDataSeconds.length>0){var r=n.SeriesCaption,u=newChart.chart.get(r),i=newChart.convertTimesToMs(n.SeriesDataSeconds);for(t=0;t<i.length;t++)u.addPoint(i[t],!1,!1);newChart.chart.redraw()}else console.warn("No points returned!")},createChart:function(n){window.chart=new Highcharts.StockChart({chart:{renderTo:"highchartContainer"},legend:{enabled:!0,align:"center",layout:"horizontal",verticalAlign:"top",y:30},rangeSelector:{buttons:[{type:"day",count:1,text:"1d"},{type:"week",count:1,text:"1w"},{type:"month",count:1,text:"1m"},{type:"month",count:3,text:"3m"},{type:"month",count:6,text:"6m"},{type:"year",count:1,text:"1y"},{type:"year",count:2,text:"2y"},{type:"year",count:5,text:"5y"},{type:"all",text:"All"}],selected:newChart.selectedHistoryOption,inputEnabled:!1},title:{text:"Exchange Rate History",margin:50,style:{fontSize:"22px"}},credits:{enabled:!1},series:[{name:n.SeriesCaption,data:n.SeriesData,tooltip:{yDecimals:4}}],exporting:{filename:"ExchangeRateHistory"}})},redraw:function(){newChart.chart.redraw()}},ObservableExchangeRateViewModel=function(n){var t=this;return console.log("ObservableExchangeRateViewModel: "+n.LastUpdated),console.log("From Currency: "+n.FromCurrency),console.log("From To: "+n.ToCurrency),t.id=null,t.fromCurrency=new ko.observable(n.FromCurrency),t.fromCurrencySymbol=new ko.observable(n.FromCurrencySymbol),t.toCurrency=new ko.observable(n.ToCurrency),t.toCurrencyCymbol=new ko.observable(n.ToCurrencySymbol),t.rateValue=new ko.observable(n.ExchangeRate),t.rateDelta=new ko.observable,t.inverseRateValue=new ko.observable(n.InverseRate),t.inverseRateDelta=new ko.observable,t.rawLastUpdated=new ko.observable(n.LastUpdated),t.lastUpdatedMessage=new ko.observable(moment(n.LastUpdated)),t.lastUpdatedLink=new ko.observable,t.convertFromAmount=new ko.observable(n.ConvertFromAmount),t.convertedAmount=new ko.observable(""),t.lastDailyRate=null,t.chartingCallback=null,t.realtimeSparklineCallback=null,t.initialize=function(n,i){t.lastDailyRate=n;t.chartingCallback=i;var r=$.connection.exchangeRatesHub;$.connection.hub.logging=!1;$.connection.hub.stateChanged(function(n){if(console.log("SignalR State change. New state: "+n.newState),n.newState===$.signalR.connectionState.connecting&&console.log("SignalR connecting..."),n.newState===$.signalR.connectionState.connected){console.log("SignalR connected...");var t=exchangeRates.C1Currency+exchangeRates.C2Currency;console.log("Watching currency pair: "+t);r.server.watch(t)}n.newState===$.signalR.connectionState.reconnecting&&console.log("SignalR Reconnecting...");n.newState===$.signalR.connectionState.disconnected&&console.log("SignalR Disconnected.")});r.client.updateRates=function(n){t.updatedRates(n);try{t.chartingCallback!==null&&t.chartingCallback(n);t.realtimeSparklineCallback!==null&&t.realtimeSparklineCallback(n)}catch(i){console.error("error updating chart. "+i)}};$(window).bind("unload",function(){var n=exchangeRates.C1Currency+exchangeRates.C2Currency;r.server.stopWatching(n);console.log("Un-subscribed from currency: "+n)});console.log("Using www.Dollars2Pounds.com for SignalR");$.connection.hub.url="https://www.Dollars2Pounds.com/signalr";$.connection.hub.logging=!0;$.connection.hub.start();window.setInterval(t.refreshLastUpdated,1e3);t.updateConvertedAmount()},t.updatedRates=function(n){if(n==null){console.log("Returned result was null for autoUpdate");return}t.inverseRateDelta(t.getFormattedDelta(n.C1Value-t.inverseRateValue()));t.rateDelta(t.getFormattedDelta(n.C2Value-t.rateValue()));t.id=n.Id;t.inverseRateValue(n.C1Value);t.rateValue(n.C2Value);t.rawLastUpdated(n.LastUpdatedDateTime);var i=moment(n.LastUpdatedDateTime);t.updateLastUpdatedMessage(i);t.updateConvertedAmount();t.hightlightTextChange(t.inverseRateDelta(),$("#ratesC1Delta"),$("#ratesC1DeltaIcon"));t.hightlightTextChange(t.rateDelta(),$("#ratesC2Delta"),$("#ratesC2DeltaIcon"))},t.getFormattedDelta=function(n){return n=Math.round(n*1e4)/1e4,n===0&&(n=""),n>0&&(n="+"+n),n},t.hightlightChange=function(n,t){if(n>-5e-6&&n<5e-6){t.removeClass("deltaDown");t.removeClass("deltaUp");t.effect("highlight",{color:"#ffd800"},"slow");return}n>0?(t.removeClass("deltaDown"),t.addClass("deltaUp")):(t.addClass("deltaDown"),t.removeClass("deltaUp"))},t.hightlightTextChange=function(n,t,i){if(t.removeClass("deltaUp"),t.removeClass("deltaDown"),i.removeClass("glyphicon glyphicon-arrow-left"),i.removeClass("glyphicon glyphicon-arrow-down"),i.removeClass("glyphicon glyphicon-arrow-up"),i.removeClass("green"),i.removeClass("red"),n>-5e-5&&n<5e-5){i.addClass("glyphicon glyphicon-arrow-left");t.effect("highlight",{color:"#ffd800"},"slow");return}n>0?(t.addClass("deltaUp"),i.addClass("glyphicon glyphicon-arrow-up"),i.addClass("green")):(t.addClass("deltaDown"),i.addClass("glyphicon glyphicon-arrow-down"),i.addClass("red"))},t.refreshLastUpdated=function(){var n=moment(t.rawLastUpdated());t.updateLastUpdatedMessage(n)},t.updateLastUpdatedMessage=function(n){var i=n.format("LL");i+=" ";i+=n.format("HH:mm:ss");i+=" ";i+="(Delayed: "+n.twitter()+")";t.lastUpdatedMessage(i)},t.updateConvertedAmount=function(){try{var n="%v %s",i=accounting.formatMoney(t.convertFromAmount(),{symbol:t.fromCurrency(),format:n}),r=t.convertFromAmount()*t.inverseRateValue(),u=accounting.formatMoney(r,{symbol:t.toCurrency(),format:n});t.convertedAmount(i+" = "+u)}catch(f){console.error("Failed to update the converted amount."+f)}},t},RealtimeSparklineViewModel=function(n){var t=this;return t.siteVariables=n,t.sparkLine=null,t.initialize=function(n){try{t.sparkLine=t.createSparkLine("miniChart",n)}catch(i){console.error("Failed to initialize sparkline: "+i)}},t.newRate=function(n){var f,i,r,u,e;try{f=t.sparkLine.series[0];i=[n.LastUpdatedDateTimeEpoch*1e3,parseFloat(n.C2Value)];f.addPoint(i,!0,!1,!0);r=t.sparkLine.xAxis[0];i[0]>r.max&&(console.log("Data past end of sparkline. shifting x axis."),u=i[0]+12e4,e=u-36e5,r.setExtremes(e,u))}catch(o){console.error("Failed to add point to sparkline: "+o)}},t.convertTimesToMs=function(n){return $.map(n,function(n){return[[n[0]*1e3,n[1]/1e5]]})},t.createSparkLine=function(n,i){var r=i.lastUpdatedDateTimeEpoch*1e3,u=r+36e5,f=[[r,i.exchangeRate]],e=t.siteVariables.ToCurrency+t.siteVariables.FromCurrency;return new Highcharts.Chart({chart:{zoomType:"line",renderTo:n,backgroundColor:null,borderWidth:0,margin:[2,0,2,0],style:{overflow:"visible"}},exporting:{enabled:!1,buttons:{contextButton:{enabled:!1}}},title:{text:""},credits:{enabled:!1},xAxis:{type:"datetime",labels:{enabled:!1},title:{text:null},min:r,max:u,lineWidth:1},yAxis:{lineWidth:2,endOnTick:!1,startOnTick:!1,labels:{enabled:!1},title:{text:null},tickPositions:[0]},legend:{enabled:!1},tooltip:{hideDelay:0,outside:!0,shared:!0},plotOptions:{series:{animation:!1,lineWidth:1,shadow:!1,states:{hover:{lineWidth:1}},marker:{states:{hover:{radius:2}}},fillOpacity:.25},column:{negativeColor:"#910000",borderColor:"silver"},area:{marker:{enabled:!0,radius:1},lineWidth:1,states:{hover:{lineWidth:1}},threshold:null}},series:[{type:"area",data:f,name:e}]})},t},selectCurrenciesPage={initialize:function(){$("#FromSymbol").click(function(){$("#FromRadio0").attr("checked",!0)});$("#FromSymbol").autocomplete({source:"/webApi/Currency/AutoComplete",minLength:1,delay:0,select:function(){$("#FromRadio0").prop("checked",!0)}});$("#FromCurrency").click(function(){$("#FromRadio1").attr("checked",!0)});$("#FromCurrencyByCountry").click(function(){$("#FromRadio2").attr("checked",!0)});$("#ToSymbol").click(function(){$("#ToRadio0").attr("checked",!0)});$("#ToSymbol").autocomplete({source:"/webApi/Currency/AutoComplete",minLength:1,delay:0,select:function(){$("#ToRadio0").prop("checked",!0)}});$("#ToCurrency").click(function(){$("#ToRadio1").attr("checked",!0)});$("#ToCurrencyByCountry").click(function(){$("#ToRadio2").attr("checked",!0)})}}