// Last updated 2006-02-21
function addRowToTable()
{
  var tbl = document.getElementById('quote');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  
  // First Cell
  var cellFirst = row.insertCell(0);
  var textNode = document.createTextNode(iteration);
  cellFirst.appendChild(textNode);
  
  // Second cell
  var cellSecond = row.insertCell(1);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'qty[]';
  el.id = 'qty';
  el.size = 6;
  cellSecond.appendChild(el);

  // Third cell
  var cellThird = row.insertCell(2);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'stk[]';
  el.id = 'stk';
  el.size = 10;
  cellThird.appendChild(el);

  // Forth cell
  var cellFourth = row.insertCell(3);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'desc[]';
  el.id = 'desc';
  el.size = 68;
  cellFourth.appendChild(el);

  // Fifth cell
  var cellFifth = row.insertCell(4);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'cost[]';
  el.id = 'cost';
  el.size = 8;
  cellFifth.appendChild(el);

  // Sixth cell
  var cellSixth = row.insertCell(5);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'total[]';
  el.id = 'total';
  el.size = 8;
  cellSixth.appendChild(el);
  
}


function sumTotals() {
 var tbl = document.getElementById('quote');
 var lastRow = tbl.rows.length - 2;
 var i=0;
 var total=0;
 var anyValues=0;

 while (i<=lastRow) {
  if (isValidNum(document.QuoteForm.cost[i])) {  // check to make sure numeric
        return false;
  }

  if ( isValidNum(document.QuoteForm.qty[i])) {  // check to make sure numeric
        return false;
  }


  
  if (  ! document.QuoteForm.qty[i].value =="" || ! document.QuoteForm.cost[i].value ==""){
   if (! isNotNull(document.QuoteForm.desc[i].value)) {
        alert( "You must provide a description \n of the product" );
        document.QuoteForm.desc[i].focus();
        return false;
   } 
   document.QuoteForm.total[i].value = eval((document.QuoteForm.qty[i].value -0) * (document.QuoteForm.cost[i].value -0)).toFixed(2);
   total = eval((total - 0) + (document.QuoteForm.total[i].value - 0)).toFixed(2);
   anyValues=anyValues+1
  }
  i=i+1

 }
 
 document.QuoteForm.Qtotal.value = total;
 
 if ( anyValues == 0 ) {
  alert ( "You cannot submit an\n empty Quotation form.");
  return false;
 }

}

