function getElement(value){
    if (document.getElementById){
        // this is the way the standards work
        var elem = document.getElementById(value);
    }else if (document.all){
        // this is the way old msie versions work
        var elem = document.all[value];
    }else if (document.layers){
    // this is the way nn4 works
        var elem = document.layers[value];
    }
    return elem;
}

function calculateFees(value){
    var url = 'phprepository/lib/permit_fees.logic.php?valuation='+value;
    var loader01 = new net.ContentLoader(url, showFees);
}

function showFees(){
    var xmldoc = this.req.responseXML;
    var xmlRow = xmldoc.getElementsByTagName("permit_fees")[0];

    process_fees(xmlRow.getElementsByTagName("without_subs")[0], 'wo');
    process_fees(xmlRow.getElementsByTagName("with_subs")[0], 'with');
    }

function process_fees(fees, prepend){
    if(fees){
        var xmlAttrs = fees.attributes;
        getElement(prepend + '_permit_fee').value = addCommas(xmlAttrs.getNamedItem("permit_fee").value);
        getElement(prepend + '_plan_check_fee').value = addCommas(xmlAttrs.getNamedItem("plan_check_fee").value);
        getElement(prepend + '_city_sales_tax').value = addCommas(xmlAttrs.getNamedItem("city_sales_tax").value);
        getElement(prepend + '_county_sales_tax').value = addCommas(xmlAttrs.getNamedItem("county_sales_tax").value);
        getElement(prepend + '_total').value = addCommas(xmlAttrs.getNamedItem("total").value);
    }
}
function addCommas(nStr)
{
  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 x1 + x2;
}
