var arrFactors = new Array(5);
//var prevValue = 0;
var prevBox = null;
var decimalPlaces = 6;

arrFactors[1] = parseFloat('1');
arrFactors[2] = parseFloat('0.5');
arrFactors[3] = parseFloat('2.2046226218487758072297380134503');
arrFactors[4] = parseFloat('0.0011023113109243879036148690067251');
arrFactors[5] = parseFloat('0.001');
arrFactors[6] = parseFloat('9.8420652761106062822756161314744e-4');
arrFactors[7] = parseFloat('9.806652');

function roundDP(n, decplaces) {
  var t = Number('1e' + decplaces);
  return Math.round(n * t) / t;
}

function convert(form, id) {
  var val, fromFactor, i;
  
  // start at 1 since 0 is catid element
  val = parseFloat(form["input" + id].value);
  //if (isNaN(val) || prevValue == val) return;
  if (isNaN(val)) return;

  if (val == '' || isNaN(val)) val = 0;
  fromFactor = arrFactors[id];
  
  for (i = 1; i <= 7; i++) 
    if (i != id) form["input" + i].value = roundDP(arrFactors[i] / fromFactor * val, decimalPlaces); 
}

function enterBox(form, id) {
  //prevValue = parseFloat(form["input" + id].value);
  // highlight the new box for visibility
  if (form["input" + id].style) {
    if (prevBox != null) {
      form["input" + prevBox].style.color = '';
      //document.getElementById('lbl' + prevBox).style.fontWeight = 'normal';
    }
    form["input" + id].style.color = '#0000ff';
    //document.getElementById('lbl' + id).style.fontWeight = 'bold';
  }
  prevBox = id;
}
