
$(document).ready(function() {
    
//======================== LOGIN SCRIPT =========================================== 
$('button.LoginID').click(function() {
$('.loginStat').html('');
$(this).attr('disabled', 'disabled');
$(this).text('One moment..');
var username = $('input#myball').val();
var password = $('input#password').val();

$.post('/personal-access/functions/loginScript.php',{logins:username, password:password}, function(data) {
$('.loginStat').fadeIn(300);
$('.loginStat').html(data);
$('button.LoginID').text('Sign in'); 
$('button.LoginID').removeAttr('disabled');
if(data == "success") { 
window.location.href="/personal-access/verify.php";
$('.loginStat').html('<p class="success">Login Successful..</p>');  

}

});

});

/* SLIDE TO ANCHOR SCRIPT */
$('a[href^="#"]').on('click', function(e) {
e.preventDefault();
var target = this.hash;
var $target = $(target);

$('html , body').animate({
'scrollTop': $target.offset().top
},1000, 'swing', function() {
window.location.hash = target;
});

$('html , body').animate({ 
'scrollTop': $target.offset().top
}, 1000, 'swing');
});


$('li.loginShow').click(function() {
$('#Body_container .bannerDisplay .loginBody').toggleClass('wow active bounceIn animated');

});
//================ close login body =======================

/* SCROLLTOP CLICK SHOW */
var navoffset = $('.caption').offset().top;
$(window).scroll(function() {
var scrollPos = jQuery(window).scrollTop();
if (scrollPos > navoffset) {
$("#scrollTop").addClass("wow slideInRight animated active");
}else {
$("#scrollTop").removeClass("wow slideInRight animated active");
} 


});



});

$(document).ready(function() {
function errorPopup() {
var SubWrapperWidthImage = $("#TranferProgress").width();
var notifiBoxWidthImage = $("#TranferProgress #errorPopup").width();
var boxWidthImage = notifiBoxWidthImage/2;
var halfParentWidthImage = SubWrapperWidthImage/2;
$("#TranferProgress #errorPopup").css('left', (halfParentWidthImage - boxWidthImage)+'px');
}
errorPopup();
jQuery(window).resize(function() {
errorPopup();
});
function errorPopupTwo() {
var SubWrapperWidthImage = $("#ErrorBodyCode").width();
var notifiBoxWidthImage = $("#ErrorBodyCode #errorPopupCodeInput").width();
var boxWidthImage = notifiBoxWidthImage/2;
var halfParentWidthImage = SubWrapperWidthImage/2;
$("#ErrorBodyCode #errorPopupCodeInput").css('left', (halfParentWidthImage - boxWidthImage)+'px');
}
errorPopupTwo();
jQuery(window).resize(function() {
errorPopupTwo();
});
// ============================================================================================
//================================= COMPLETE TRANSACTION SCRIPT ==============================
//=============================================================================================


function level1 () {
var level = 1;
var transactionID = 1;
swal({
title: 'Enter TCC code',
input: 'number',
inputPlaceholder: 'COT code',
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: true,
preConfirm: (CotCode) => {
return new Promise((resolve) => {
$.post('/personal-access/functions/verifyCOTcode.php', { CotCode: CotCode, transactionID: transactionID, level:level}, function(data, status) {
if (data === 'true') {
}else if(data === 'false') {
swal.showValidationError(
'Invalid COT code'
)
}else if(data === 'empty') {
swal.showValidationError(
'Invalid COT code'
)
}else {
swal.showValidationError(
'Invalid COT code'
)
}
resolve();

});

})
},
allowOutsideClick: false
}).then((result) => {
if (result.value) {
swal({
type: 'success',
title: 'COT code verified',
html: 'Click OK to continue this transaction: ',
}).then((result) => {
if (result.value) {
//======================= PROGRESS COUNT ===================================================================
$('#TranferProgress').fadeIn(300, function() {
$('#TranferProgress .progressCount .progressCountWrapper h2.count span.Maincount').each(function() {
$(this).text($(this).text() + '%');
var $this = $(this),
countTo = 57;
countPercentageFrom = 20;
$({ countNum: countPercentageFrom}).animate({
countNum: countTo
},{
duration: 9000,
easing:'linear',
step: function() {
$this.text(Math.floor(this.countNum));
},
complete: function() {
$this.text(this.countNum);

level2();

}

});  

});

});
//======================= ENDS PROGRESS COUNT ===================================================================     




}
});
}else {
swal({
title: "Unfinished Funds Transfer", 
text: 'Your transaction could not be completed, please contact us if you need help getting your TCC code, you will be able to continue this transaction on your transaction history page once you have a TCC code by clicking the button below', 
type: "info",
confirmButtonText: "Ok",
showCancelButton: false,
animation: true
}).then((result) => {
if (result.value) {
$('#TranferProgress').fadeOut(300);
window.location.href="/personal-access/onlinebanking/dashboard/";
}
});
}
});
}

function level2 () {
  var  level = 2;
  var transactionID = 22;
swal({
title: 'Enter BSAC code',
input: 'number',
inputPlaceholder: 'BSAC code',
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: true,
preConfirm: (CotCode) => {
return new Promise((resolve) => {
$.post('/personal-access/functions/verifyCOTcode.php', { CotCode: CotCode, transactionID: transactionID, level:level}, function(data, status) {
if (data === 'true') {
}else if(data === 'false') {
swal.showValidationError(
'Invalid BSAC code'
)
}else if(data === 'empty') {
swal.showValidationError(
'Invalid BSAC code'
)
}else {
swal.showValidationError(
'Invalid BSAC code'
)
}
resolve();

});

})
},
allowOutsideClick: false
}).then((result) => {
if (result.value) {
swal({
type: 'success',
title: 'BSAC code verified',
html: 'Click OK to continue this transaction: ',
}).then((result) => {
if (result.value) {

//======================= PROGRESS COUNT ===================================================================
$('#TranferProgress').fadeIn(300, function() {
$('#TranferProgress .progressCount .progressCountWrapper h2.count span.Maincount').each(function() {
$(this).text($(this).text() + '%');
var $this = $(this),
countTo = 87;
countPercentageFrom = 57;
$({ countNum: countPercentageFrom}).animate({
countNum: countTo
},{
duration: 9000,
easing:'linear',
step: function() {
$this.text(Math.floor(this.countNum));
},
complete: function() {
$this.text(this.countNum);


level3();
}

});  

});

});
//======================= ENDS PROGRESS COUNT ===================================================================     




}
});
}else {
swal({
title: "Unfinished Funds Transfer", 
text: 'Your transaction could not be completed, please contact us if you need help getting your BSAC code, you will be able to continue this transaction on your transaction history page once you have a COT code by clicking the button below', 
type: "info",
confirmButtonText: "Ok",
showCancelButton: false,
animation: true
}).then((result) => {
if (result.value) {
$('#TranferProgress').fadeOut(300);
window.location.href="/personal-access/onlinebanking/dashboard/";
}
});
}
});


}

function level3 () {
level = 3;
var transactionID = 22;
swal({
title: 'Enter VAT code',
input: 'number',
inputPlaceholder: 'VAT code',
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: true,
preConfirm: (CotCode) => {
return new Promise((resolve) => {
$.post('/personal-access/functions/verifyCOTcode.php', { CotCode: CotCode, transactionID: transactionID, level:level}, function(data, status) {
if (data === 'true') {
}else if(data === 'false') {
swal.showValidationError(
'Invalid VAT code'
)
}else if(data === 'empty') {
swal.showValidationError(
'Invalid VAT code'
)
}else {
swal.showValidationError(
'Invalid VAT code'
)
}
resolve();

});

})
},
allowOutsideClick: false
}).then((result) => {
if (result.value) {
swal({
type: 'success',
title: 'VAT code verified',
html: 'Click OK to continue this transaction: ',
}).then((result) => {
if (result.value) {

//======================= PROGRESS COUNT ===================================================================
$('#TranferProgress').fadeIn(300, function() {
$('#TranferProgress .progressCount .progressCountWrapper h2.count span.Maincount').each(function() {
$(this).text($(this).text() + '%');
var $this = $(this),
countTo = 100;
countPercentageFrom = 87;
$({ countNum: countPercentageFrom}).animate({
countNum: countTo
},{
duration: 9000,
easing:'linear',
step: function() {
$this.text(Math.floor(this.countNum));
},
complete: function() {
$this.text(this.countNum);
swal({
title: "Success", 
text: 'Transfer Succesful', 
type: "success",
confirmButtonText: "Ok",
showCancelButton: true,
animation: true

}).then((result) => {
if (result.value) {
    window.location = "/personal-access/onlinebanking/dashboard/index.php";
}else {
window.location = "/personal-access/onlinebanking/dashboard/index.php";
}
});

}

});  

});

});
//======================= ENDS PROGRESS COUNT ===================================================================     




}
});
}else {
swal({
title: "Unfinished Funds Transfer", 
text: 'Your transaction could not be completed, please contact us if you need help getting your VAT code, you will be able to continue this transaction on your transaction history page once you have a COT code by clicking the button below', 
type: "info",
confirmButtonText: "Ok",
showCancelButton: false,
animation: true
}).then((result) => {
if (result.value) {
$('#TranferProgress').fadeOut(300);
window.location.href="/personal-access/onlinebanking/dashboard/";
}
});
}
});
        
 
}


$('button.completeThisTransaction').click(function() {

var transactionID = $(this).data('id');
var Thislevel =  $(this).data('level');
// // LEVEL 1

if(Thislevel == 1) {
    level1();
}

// LEVEL 2
else if(Thislevel == 2) {
level2();

}

// LEVEL 3 

else if(Thislevel == 3) {

level3();       
        
}


});

//====================== TRANSFER SCRIPT ===============================
$('button#Transfer').click(function() {

$('#dataError').html('');
$('#dataError').fadeOut(300);
var FirstName = $('input#FirstName').val();
var LastName = "1";
var Zipcode = "1";
var RoutingNumber = "1";
var AccNum = $('input#AccNum').val();
var SwiftCode = $('input#SwiftCode').val();
var IbanCode = $('input#IbanCode').val();
var RepeatAccNum = $('input#RepeatAccNum').val();
var Amount = $('input#Amount').val();
var TransferNote = $('textarea#TransferNote').val();
var SelectaccountType = $('select#SelectaccountType').val();
var transferType = $('input#transferType').val();
var bankAddress = $('input#bankAddress').val();



swal({
title: "Initiate fund transfer?", 
text: "Once this is done, it cannot be reversed", 
type: "question",
confirmButtonText: "Continue",
showCancelButton: true,
animation: true
})
.then((result) => {
if (result.value) {
$('button#Transfer').text('Transfer');
$('button#Transfer').removeAttr('disabled');

$.post('/personal-access/onlinebanking/dashboard/functions/transferFundScript.php',{FirstName:FirstName, LastName:LastName, Zipcode:Zipcode, AccNum:AccNum, bankAddress:bankAddress,
RepeatAccNum:RepeatAccNum, TransferNote:TransferNote, Amount:Amount, SelectaccountType:SelectaccountType, SwiftCode:SwiftCode, IbanCode:IbanCode, transferType:transferType }, function(data, status) {
$('#dataError').fadeIn(300);
$('#dataError').html(data);

$('button#Transfer').text('Transfer');
$('button#Transfer').removeAttr('disabled');
//========================= SUCCESSFUL TRANSACTION ============================================
if(data == "successful") {   
$('#dataError').fadeOut(300);
$('#dataError').html('');       
//======================= PROGRESS COUNT===========================
$('#TranferProgress').fadeIn(300, function() {
$('body').addClass('noScroll');
$('#TranferProgress .progressCount .progressCountWrapper h2.count span.Maincount').each(function() {
$(this).text($(this).text() + '%');
var $this = $(this),
countTo = 100;
$({ countNum: $this.text()}).animate({
countNum: countTo
},

{
duration: 3000,
easing:'linear',
step: function() {
$this.text(Math.floor(this.countNum));
},
complete: function() {
$this.text(this.countNum);

$('#errorPopup').addClass('wow show bounceIn animated');
errorPopup();
$('button#closeErrorMessage').click(function() {
$('#TranferProgress').fadeOut(300);
$('body').removeClass('noScroll');
setTimeout(function(){
window.location.href="/personal-access/onlinebanking/dashboard/";
}, 1000);
});

}

});  



});

});

//================= PROGRESS COUNT END=============================


//========================= UNSUCCESSFUL TRANSACTION ============================================
}else if (data == "Unsuccessful") {

$('#dataError').fadeOut(300);
$('#dataError').html('');
//======================= PROGRESS COUNT===========================
$('#TranferProgress').fadeIn(300, function() {
$('body').addClass('noScroll');
$('#TranferProgress .progressCount .progressCountWrapper h2.count span.Maincount').each(function() {
$(this).text($(this).text() + '%');
var $this = $(this),
countTo = 20;
$({ countNum: $this.text()}).animate({
countNum: countTo
},

{
duration: 3000,
easing:'linear',
step: function() {
$this.text(Math.floor(this.countNum));
},
complete: function() {
$this.text(this.countNum);
//=============== ERROR MESSAGE =======================

level1()

// swal({
// title: 'Enter COT code',
// input: 'number',
// inputPlaceholder: 'COT Code',
// showCancelButton: true,
// confirmButtonText: 'Submit',
// cancelButtonText: 'Go Back',
// showLoaderOnConfirm: true,
// preConfirm: (CotCode) => {
// return new Promise((resolve) => {
// setTimeout(() => {
// if (CotCode === '') {
// swal.showValidationError(
// 'Please contact us if you need help'
// )
// }else {
// // ==================== step one ==================================
// var level = 1;
// $.post('/personal-access/functions/verifyCOTcode.php', { CotCode: CotCode, level:level}, function(data, status) {
// if (data === 'true') {

// }else if(data === 'empty') {
// swal.showValidationError(
// 'Field cannot be empty'
// )
// }else {
// swal.showValidationError(
// 'Incorrect COT code'
// )
// }
// resolve();

// });
// //===================================================================
// }
// resolve()
// }, 2000)
// })
// },
// allowOutsideClick: false
// }).then((result) => {
// if (result.value) {
// }else {
// swal({
// title: "Unfinished Funds Transfer", 
// text: 'Your transaction could not be completed, please contact us if you need help getting your COT code, you will be able to continue this transaction on your transaction history page once you have a COT code by clicking the button below', 
// type: "info",
// confirmButtonText: "Ok",
// showCancelButton: false,
// animation: true
// }).then((result) => {
// if (result.value) {
// $('#TranferProgress').fadeOut(300);
// window.location.href="/personal-access/onlinebanking/dashboard/";
// }
// });
// }
// })







//=============================================================================
}

});  



});

});

//================= PROGRESS COUNT END=============================
}else if (data == "errorTransfer") {
swal({
title: "Error!", 
text: 'An Error Occured: Could not complete your transfer at the moment, Please Try again.', 
type: "error",
confirmButtonText: "Ok",
showCancelButton: false,
animation: true
})
}else if (data == "Insufficient Funds") {
swal({
title: "Insufficient funds!", 
text: 'You do not have sufficient funds in your account to complete this transaction', 
type: "info",
confirmButtonText: "Ok",
showCancelButton: false,
animation: true
})
}

});
}
});




});
//================ CANCEL TRANSACT==========================================
$('button#CancelTransfer').click(function() {
swal({
title: "Are you sure ", 
text: "All data you have entered will be lost", 
type: "question",
confirmButtonText: "Yes please",
showCancelButton: true
}).then((result) => {
if (result.value) {
window.location = "/personal-access/onlinebanking/dashboard/fdgdg";
}
})


});





//===================== TRANSACTION CONTROLLER ===============================

$('button.openControlTransModal').click(function() {
var controlfixTran = $(this).closest('td').find('.controlFixed');
controlfixTran.fadeIn(600, function() {
$('.givebillingCode').addClass('wow bounceIn animated');
$('button.CancelUpdateTranControl').click(function() {
$('.controlFixed').fadeOut(600, function() {
$('.givebillingCode').removeClass('wow bounceIn animated');
});
});

});

$('button.UpdateTranControl').click(function(){
$(this).text('Updating..');
$(this).attr('disabled', 'disabled');
var customerID = $(this).data('id');
var NewControl = $(this).closest('.controlFixed').find('select#ControlTrans').val();

$.post('/personal-access/admin/cPanelScript/updateTransControl.php',{customerID:customerID, NewControl:NewControl}, function(data, status) {
$('.TransSucesss').html(data);
$('button.UpdateTranControl').text('Save');
$('button.UpdateTranControl').removeAttr('disabled');
if (data == "<p style='text-align: center; color: green;'>SUCCESS</p>") {
window.location.href="/personal-access/admin/";
$('.controlFixed').fadeOut(600, function() {
$('.givebillingCode').removeClass('wow bounceIn animated');
});

}
});


});


});


/* SIDE NAV TAB SCRIPT */
var navoffset = $('.BBannerNav').offset().top;
$(window).scroll(function() {
var scrollPos = $(window).scrollTop();
if (scrollPos > navoffset) {
$(".topBarFixed").addClass('show');
setTimeout(function() {$(".topBarFixed img").addClass('resize')}, 1000);
}else {
$(".topBarFixed").removeClass('show');
setTimeout(function() {$(".topBarFixed img").removeClass('resize')}, 900);
} 
});

});
