﻿// JScript File

String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

function toggleCheckBox(ckb) {
    var objs = document.getElementsByName(ckb.id);
    var onOff = ckb.checked;
    for(var i=0 ; i < objs.length ; i++) {
        objs[i].checked = onOff; 
    }
}

function UpdateAmount(txtAmt, tax, islocal) {
    var amount = +txtAmt.value;
    
    if(isNaN(amount)) {
        txtAmt.value = '';
        amount = 0;
    }
    if(islocal == 'True')
    {
        var txtGST = document.getElementById('txtGST');
        if(txtGST)
            txtGST.innerHTML = (amount*tax).toFixed(2);
    
        var txtTotalAmount = document.getElementById('txtTotalAmount');
        if(txtTotalAmount)
            txtTotalAmount.innerHTML = (amount*(1+tax)).toFixed(2);        
    }
    else
    { 
         var txtTotalAmount = document.getElementById('txtTotalAmount');
            if(txtTotalAmount)
                txtTotalAmount.innerHTML = amount;
    }
}

function CheckAll(name, values) {
    var objs = document.getElementsByName(name);
    
    document.getElementById(name).checked = true;
    for(var i = 0 ; i < objs.length ; i++) {
        var c = values.match('^'+objs[i].value+'$|^'+objs[i].value+',|,'+objs[i].value+',|,'+objs[i].value+'$') != null;
        objs[i].checked = c;
        if(!c)
            document.getElementById(name).checked = false;
    }
}

