// This function formats numbers by adding commas
function numberFormat(nStr,prefix){
    var prefix = prefix || '';
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1))
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    return prefix + x1 + x2;
}

function getVal(item){
    var tmpVar = document.getElementById(item).value;
    tmpVar = tmpVar.replace(",","");
    tmpVar = tmpVar.replace("$","");

     //alert( "getval item = " + item);
   if(tmpVar != "")
    {
     return parseFloat(tmpVar);
    }
   else{
     return 0;
        }
 }
 
function SumUpBalance()
{
    var rowTotal = 0;
    for (var i = 1; i < 12; i++)
    {
        rowTotal += getVal(i);
    }

       // alert( "rowTotal = " + rowTotal);
     rowTotal = numberFormat(rowTotal,"")
    document.getElementById('13').value  = rowTotal;
    return 0 ;
}


function validateForm() {
with (document.payables) {
var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
if (company.value == "") alertMsg += "\nYour company name";
if (name.value == "") alertMsg += "\nYour name";
if (phone.value == "") alertMsg += "\nYour phone";
if (email.value == "") alertMsg += "\nYour e-mail";
if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
alert(alertMsg);
return false;
} else {
return true;
} } }


