var count_version = "1.0";
var Gsub_total_o = 0;
var Gsub_total = 0;
var Gfeet = 0;
var nwork1 = "";

function count(f,n,u)
{
  // PARAMETERS:
  // f = allways this.form
  // n = index of line 
  // u = field name containing # sq feet  
  cknum1(f.line[n].value);
  f.line[n].value = nwork1;
   
		   var A=document.getElementById("ADisplay"); // *** get current object values ***
		   var B=document.getElementById("BDisplay");
		   var C=document.getElementById("CDisplay");
		   A.innerHTML = ADisp; // *** assign global values ABCRates.js file***
		   B.innerHTML = BDisp;
		   C.innerHTML = CDisp;
		   var ARate = ADisp.substring(1) -0; // *** make numeric & strip off '$' ***
		   var BRate = BDisp.substring(1) -0;
		   var CRate = CDisp.substring(1) -0;
		   A.value = ARate;
		   B.value = BRate;
		   C.value = CRate;
  
  f.line_sum[n].value = f.line[n].value * u;
  f.line_sum[n].value = Math.ceil(f.line_sum[n].value * 1000) /1000;
  f.line_sum[n].value = Math.floor(f.line_sum[n].value * 1000) /1000;
  f.line_sum[n].value = Math.round(f.line_sum[n].value * 100)/100;
    var gt = 0;
    for(i=0; i < f.line_sum.length; i++)
    {
      gt += Math.ceil(f.line_sum[i].value * 1000) /1000;
    }
    gt = Math.round(gt * 1000)/1000;
    Gsub_total =  gt;
	f.sub_total.value = gt;
	final(f);

}

function counto(f,no,uo)
{
    //alert(f+" "+no+" "+uo);
	  cknum1(f.lineo[no].value);
  f.lineo[no].value = nwork1;

  f.line_sum_o[no].value = f.lineo[no].value * uo;
  f.line_sum_o[no].value = Math.ceil(f.line_sum_o[no].value * 1000) /1000;
  f.line_sum_o[no].value = Math.floor(f.line_sum_o[no].value * 1000) /1000;
  f.line_sum_o[no].value = Math.round(f.line_sum_o[no].value * 100)/100;
    var gto = 0;
    for(io=0; io < f.line_sum_o.length; io++)
    {
      gto += Math.ceil(f.line_sum_o[io].value * 1000) /1000;
    }
    gto = Math.round(gto * 1000)/1000;
    Gsub_total_o =  gto;
	f.sub_total_o.value = gto;	
	final(f);

}
// the 15% & 30% below should go into the global module that contains A, B, & C amounts ***********************
function final(f)
{
	f.total_usf30.value = (parseInt(Gsub_total) + parseInt(Gsub_total_o));
	var plus15;
	var plus30;
	plus30 = (parseInt(f.total_usf30.value) * .35) 
	f.total_usf31.value = Math.round((parseInt(f.total_usf30.value) + plus30));
	plus15 = (parseInt(f.total_usf31.value) * .15)
	f.total_usf32.value = Math.round((parseInt(f.total_usf31.value) + plus15));
	Gfeet = f.total_usf32.value;
	//alert("in final in count.js, \nGfeet:"+Gfeet+"\n ADisp:"+ADisp);
}

function cknum1(isn)
{
 var i;
 nwork1 = "";
 for (i=0; i < isn.length; i++)
  {
    var c = isn.charAt(i);
    if (((c < "0") || (c > "9"))) {}else{nwork1+=c}
  }
}
