function stripNonNumeric( str ){
  str += '';
  var rgx = /^\d|\.|-$/;
  var out = '';
  for( var i = 0; i < str.length; i++ ){
    if( rgx.test( str.charAt(i) ) ){
      if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||
             ( str.charAt(i) == '-' && out.length != 0 ) ) ){
        out += str.charAt(i);
      }
    }
  }
  return out;
}
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;
}
function leed(form) {var sqft = stripNonNumeric(form.sqft.value);var price = stripNonNumeric(form.price.value)/1000;var product = form.product.value;var mr4 = 0.186;var mr5 = 0.9859;var bsf = 6.74;var psf = 4.5;var clayee = 6000;var clayco2 = 0.9;var fabee = 1000;var fabco2 = 0.1;var concee = 1500;var concco2 = 0.9;var fapee = 1000;var fapco2 = 0.1;if ((product == 'Modular Fly Ash Brick (FAB)') || (product == 'Utility Fly Ash Brick (FAB)')) {var units = sqft*bsf;var cost = units*price;var totalee = (units*clayee)-(units*fabee);var totalco2 = (units*clayco2)-(units*fabco2);var totalmr4 = cost*mr4;var totalmr5 = cost*mr5;} else {var units = sqft*psf;var cost = units*price;var totalee = (units*concee)-(units*fapee);var totalco2 = (units*concco2)-(units*fapco2);var totalmr4 = cost*mr4;var totalmr5 = cost*mr5;}var mr4 = totalmr4.toFixed(2); var mr5 = totalmr5.toFixed(2); var ee = totalee.toFixed(0); var co2 = totalco2.toFixed(1); form.newprice.value = addCommas(price*1000);form.one.value = addCommas(mr4);form.two.value = addCommas(mr5);form.three.value = addCommas(ee);form.four.value = addCommas(co2);return false;}