// Populate the mobile basket item count
$(function () {
var mobileBasket = $('.navbar-basket .basket-count');
if (mobileBasket.length) {
// Find the actual basket count and update the mobile count
var basketCount = $('span[id$="BasketItemCount"]').text();
mobileBasket.text(basketCount);
}
});
// Toggle password visibility
$(function () {
$('.password-reveal').on('click', function () {
var passwordField = document.getElementById('ucLogin_txtPassword');
if (passwordField == undefined) {
passwordField = document.getElementById('ContentPlaceHolder1_UserLogin1_txtPassword');
}
if (passwordField.type === "password") {
passwordField.type = "text";
} else {
passwordField.type = "password";
}
$('.password-reveal').toggleClass('fa-eye fa-eye-slash color-primary');
});
});
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i = 0; i < gy.length; i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
/* Prevent any null issues */
return "";
}
function PrinterFriendlyCompany(id, reportType, tab) {
var url = "../Company/printcompanyreport.aspx" +
"?type=" + reportType +
"&id=" + id +
"&tab=" + tab;
window.open(url);
}
function PrinterFriendlyInternationalCompany(id, reportType, tab) {
var url =
"../Company/PrintInternationalCompanyReport.aspx" +
"?type=" + reportType +
"&id=" + id +
"&tab=" + tab;
window.open(url);
}
function PrinterFriendlyDirector(directorNumber,country, tab)
{
var url =
"../Director/printdirectorreport.aspx" +
"?directornumber=" + directorNumber +
"&country=" + country +
"&tab=" + tab;
window.open(url);
}
function PrinterFriendlyNonLtdCompany(id, tab)
{
var url =
"../Company/printcompanyreportnonltd.aspx" +
"?id=" + id +
"&tab=" + tab;
window.open(url);
}
// Smooth scroll to anchors
$(function () {
// Select all links with hashes
$('.smooth-scroll, .report-sections a')
// Remove links that don't actually link to anything
.not('[href="#"]')
.not('[href="#0"]')
.click(function (event) {
// On-page links
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
&&
location.hostname == this.hostname
) {
// Figure out element to scroll to
var target = $("[id$='" + this.hash.replace("#", "") + "']");
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
// Does a scroll target exist?
if (target.length) {
// Only prevent default if animation is actually gonna happen
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
}
}
});
});
// Report progress fill
function ReportTachometerInit(sectionCount) {
$('.tachometer-section').empty();
// Get the rating to pass in
var rating = $('#tachometer-rating').text();
// Get the window size and adjust tachometer size accordingly
var isMobileView = $(window).width() < 768;
// Generate the markup first
GenerateTachometerMarkup(rating, isMobileView, sectionCount);
var tachometerContainer = $('#tachometer-section');
if (tachometerContainer.length) {
// Set radius for all circles
var r = 150;
if (isMobileView) {
r = 120;
}
var circles = document.querySelectorAll('.circle');
var total_circles = circles.length;
for (var i = 0; i < total_circles; i++) {
circles[i].setAttribute('r', r);
}
// Set meter's wrapper dimension
var meter_dimension = (r * 2) + 100;
var wrapper = document.querySelector('#tachometer-wrapper');
wrapper.style.width = meter_dimension + 'px';
wrapper.style.height = meter_dimension + 'px';
// Add strokes to circles
var cf = 2 * Math.PI * r;
var semi_cf = cf / 2;
// Set the rating boundaries
var green = (semi_cf / 100) * 30;
var amber = (green / 100) * 165;
var orange = (green / 100) * 230;
if (sectionCount != 3) {
document.querySelector('#outline_curves')
.setAttribute('stroke-dasharray', semi_cf + ',' + cf);
document.querySelector('#high')
.setAttribute('stroke-dasharray', semi_cf + ',' + cf);
document.querySelector('#moderate')
.setAttribute('stroke-dasharray', orange + ',' + cf);
document.querySelector('#limited')
.setAttribute('stroke-dasharray', amber + ',' + cf);
document.querySelector('#low')
.setAttribute('stroke-dasharray', green + ',' + cf);
document.querySelector('#outline_ends')
.setAttribute('stroke-dasharray', 2 + ',' + (semi_cf - 2));
document.querySelector('#mask')
.setAttribute('stroke-dasharray', semi_cf + ',' + cf);
// Bind range slider event
var slider = document.querySelector('#slider');
var lbl = document.querySelector("#lbl");
var mask = document.querySelector('#mask');
var meter_needle = document.querySelector('#meter_needle');
function range_change_event() {
var percent = slider.value;
var meter_value = semi_cf - ((percent * semi_cf) / 100);
mask.setAttribute('stroke-dasharray', meter_value + ',' + cf);
meter_needle.style.transform = 'rotate(' + (270 + ((percent * 180) / 100)) + 'deg)';
lbl.textContent = percent + '%';
}
slider.addEventListener('input', range_change_event);
range_change_event();
}
}
}
function GenerateTachometerMarkup(rating, isMobileView, sectionCount) {
var tachometerContainer = $('#tachometer-section'),
riskRating = "",
ratingSymbol = "",
ratingImage = "";
if (sectionCount == 3) {
if (rating >= 20) {
riskRating = "Pass";
ratingSymbol = "";
ratingImage = "/Images/aml-pass.png";
} else if (rating < 20 && rating > -1) {
riskRating = "Refer";
ratingSymbol = "";
ratingImage = "/Images/aml-refer.png";
} else {
riskRating = "Fail";
ratingSymbol = "";
ratingImage = "/Images/aml-fail.png";
}
} else {
if (rating <= 29) {
riskRating = "High";
} else if (rating >= 30 && rating <= 50) {
riskRating = "Moderate";
} else if (rating >= 51 && rating <= 70) {
riskRating = "Limited";
} else if (rating >= 71 && rating <= 100) {
riskRating = "Low";
}
}
if (tachometerContainer.length) {
// Adjust the styling for mobile
if (isMobileView) {
tachometerContainer.addClass('mobile-view');
} else {
tachometerContainer.removeClass('mobile-view');
}
if (sectionCount == 3) {
tachometerContainer.append('
' + riskRating + ' ' + rating + '' + ratingSymbol + '
');
} else {
tachometerContainer.append('' + riskRating + ' Risk ' + rating + '
');
}
}
}
// Line charts
function initLineChart(id, showCurrency) {
var lineChart = document.getElementById(id),
lblHdn = [],
dataHdn = [],
legendHdnContainer = document.getElementById(id + "-legendHdn"),
legendHdn = [];
if (document.body.contains(legendHdnContainer)) {
legendHdn = legendHdnContainer.value.split("|");
$('.' + id + '-lbl').each(function () {
lblHdn.push($(this).text());
});
$('.' + id + '-data').each(function () {
dataHdn.push($(this).text().replace("£", "").replace(/\,/g, ""));
});
if (document.body.contains(lineChart)) {
Chart.defaults.global.defaultFontFamily = "Open Sans";
var chart = new Chart(lineChart, {
type: 'line',
data: {
labels: lblHdn.reverse(),
datasets: [{
label: legendHdn,
yAxisID: 'A',
data: dataHdn.reverse(),
pointBackgroundColor: '#cda78c',
backgroundColor: '#cda78c',
borderColor: '#cda78c',
borderWidth: 2,
fill: false
}]
},
options: {
barThickness: 0.4,
maintainAspectRatio: false,
legend: {
position: 'top'
},
scales: {
yAxes: [{
id: 'A',
type: 'linear',
position: 'left',
ticks: {
beginAtZero: true,
callback: function (value, index, values) {
if (showCurrency == true) {
return float2pound(value);
} else {
return value;
}
}
}
}],
xAxes: [{
gridLines: {
drawOnChartArea: false
},
barPercentage: 0.4
}]
},
tooltips: {
callbacks: {
label: function (tooltipItem, chart) {
var datasetLabel = chart.datasets[tooltipItem.datasetIndex].label || '';
if (showCurrency) {
return datasetLabel + ': ' + float2pound(tooltipItem.yLabel);
} else {
return datasetLabel + ': ' + tooltipItem.yLabel;
}
}
}
}
}
});
}
}
}
function float2pound(value) {
var poundValue = "£" + (value).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
return poundValue.substring(0, poundValue.length - 3);
}
// Enable the payment button when agreeing to terms and conditions
$(function () {
var termsChk = $('#terms-chk'),
checkoutBtn = $('.btn-checkout');
if (termsChk.is(':checked')) {
checkoutBtn.removeAttr('disabled');
} else {
checkoutBtn.attr('disabled', true);
}
termsChk.on('change', function () {
if ($(this).is(':checked')) {
checkoutBtn.removeAttr('disabled');
} else {
checkoutBtn.attr('disabled', true);
}
});
});
function ClearVoucherText(voucherCode) {
var dataValue = { "name": voucherCode };
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "/ws/CreditserveService.asmx/RemoveDiscount",
data: JSON.stringify(dataValue),
beforeSend: function () {
// Disable button
$('.discount-text-container').removeClass('input-success');
$("#DiscountRemoveButton").attr('disabled', 'disabled');
$("#DiscountRemoveButton").val('Removing...');
},
success: function (data) {
var model = JSON.parse(data.d);
$("#DiscountRemoveButton").show();
// Update the basket
updateBasketDetails(model);
$("#DiscountRemoveButton").removeAttr('disabled', 'disabled').val('Remove');
$("div[id$='DiscountCodeResult']").show();
$("span[id$='DiscountCodeResultLabel']").html(model.Message);
$("ul[id$='ulDiscountCodeResult']")[0].className = "discountSuccess";
$("#ContentPlaceHolder1_ucbasket_DiscountCodeText")[0].value = "";
}
});
$("div[id$='divPrice']").hide();
$("div[id$='divDiscount']").hide();
}
function discountSubmitButton(voucherCode) {
var dataValue = { "name": voucherCode };
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "/ws/CreditserveService.asmx/ApplyDiscount",
data: JSON.stringify(dataValue),
beforeSend: function () {
// Disable button
$('.discount-text-container').removeClass('input-success');
$("#DiscountSubmitButton").attr('disabled', 'disabled');
$("#DiscountSubmitButton").val('Applying...');
},
success: function (data) {
var model = JSON.parse(data.d);
$("#DiscountRemoveButton").show();
if (model.Success.valueOf() == false) {
$("#DiscountSubmitButton").removeAttr('disabled', 'disabled').val('Apply');
$("div[id$='DiscountCodeResult']").show();
$("span[id$='DiscountCodeResultLabel']").html(model.Message);
$("ul[id$='ulDiscountCodeResult']")[0].className = "discountFail";
}
else {
// Update the basket
updateBasketDetails(model);
$("#DiscountSubmitButton").removeAttr('disabled', 'disabled').val('Apply');
$("div[id$='DiscountCodeResult']").show();
$("span[id$='DiscountCodeResultLabel']").html(model.Message);
$("ul[id$='ulDiscountCodeResult']")[0].className = "discountSuccess";
$("div[id$='divPrice']").show();
$("div[id$='divDiscount']").show();
}
}
});
}
function updateBasketDetails(data) {
$("span[id$='lblPriceValue']").text("£" + data.Price.toFixed(2));
$("label[id$='lblDiscountCode']").text("Discount (" + data.DiscountCode + ")");
$("span[id$='lblDiscountValue']").text("-£" + data.Discount.toFixed(2));
$("span[id$='lblSubTotal']").text("£" + data.SubTotal.toFixed(2));
$("span[id$='lblVat']").text("£" + data.Vat.toFixed(2));
$("span[id$='lblTotal']").text("£" + data.Total.toFixed(2));
$("label[id$='divBasketTotal']").text("£" + data.Total.toFixed(2));
}
// Monitoring Import validation panel toggle
function showMonitoringImportValidation() {
document.getElementById('divValidate').style.display = "block";
var msg = document.getElementById('ContentPlaceHolder1_ctrlImportMonitoring_message');
if (msg != null) { msg.style.display = 'none'; }
}
// Monitoring Import disable validation controls
function showMonitoringImportLoader() {
var divL = document.getElementById('ContentPlaceHolder1_ctrlImportMonitoring_divLoader');
var ie = document.getElementById('ContentPlaceHolder1_ctrlImportMonitoring_chkIgnoreErrors');
var vach = document.getElementById('ContentPlaceHolder1_ctrlImportMonitoring_chkValidateAgainstCompaniesHouse');
var ri = document.getElementById('ContentPlaceHolder1_ctrlImportMonitoring_chkRemoveItems');
var i = document.getElementById('ContentPlaceHolder1_ctrlImportMonitoring_lnkImportFile');
divL.style.display = 'block'
//ie.disabled = 'true';
//vach.disabled = 'true';
//ri.disabled = 'true';
//i.disabled = 'true';
i.innerText = ' Importing...'
}