
var SelProv;

window.onload = function(){
    
    var arr = document.getElementsByName("Prov");
    if(arr.length > 0){
        SelProv = arr[0];
        if(SelProv){
            SelProv.onchange = CalculateSalesTax;
        }
    }
    
    var sel_service = document.getElementById("Service");
    if(sel_service){
        sel_service.onchange = ChangeAmount;
    }
};

var ServiceTypes = {
    'nodeal' : {
        tax : 0,
        msg : 'Choose your payment plan here.'
    },
    'Monthly' : {
        tax : 75,
        msg : 'Yes. Please charge $75.00 a month '
    },
    'Quarterly' : {
        tax : 250,
        msg : 'Yes. Please charge $250.00 for 3 months '
    },
    'Annually' : {
        tax : 750,
        msg : 'Yes. Please charge $750.00 annually '
    }
}
var StatesTax = {
    'British Columbia' : 5,
    'Alberta' : 5,
    'Saskatchewan' : 5,
    'Manitoba' : 5,
    'Ontario' : 13,
    'Quebec' : 5,
    'New Brunswick' : 5,
    'Newfoundland' : 5,
    'Nova Scotia' : 5,
    'Prince Edward Island' : 5,
    'North' : 5
};

var nAmount = 0;

function ChangeAmount(){
    nAmount = ServiceTypes[this.value].tax;
    var msg_charge = document.getElementById("msg_charges");
    msg_charge.innerHTML = ServiceTypes[this.value].msg;
    CalculateSalesTax();
}
function CalculateSalesTax(){
    
    var arr = document.getElementsByName("Prov");
    var arr2 = document.getElementsByName("amount");
    if(arr.length > 0 && arr2.length > 0){
        SelProv = arr[0];
        var oTxtAmount = arr2[0];
        if(SelProv && oTxtAmount){
            var strState = SelProv.value;
            var nTax = StatesTax[strState];
            if(!isNaN(nTax)){
               var nAmountWithTax = (nAmount * (1 + nTax / 100)).toFixed(2);
               oTxtAmount.value = 'Total $' + nAmountWithTax + ' with applicable tax';
            }
        }
    }
    
}







