 function convertform(form) {
	 document.forms[0].count = 6;
	 document.forms[0].rsize = 7;
	 document.forms[0].val1.factor = 1;
	 document.forms[0].val2.factor = 39.37007874;
	 document.forms[0].val3.factor = 3.280839895;
	 document.forms[0].val4.factor = 1.093613298; 
	 document.forms[0].val5.factor = 0.00062137119;
	 document.forms[0].val6.factor = 0.000547045;
	 
  var firstvalue = 0;
  for (var i = 1; i <= form.count; i++) {
   if (form[i].value != null && form[i].value.length != 0) {
    for (var j = 0; j < form[i].value.length; j++) {
	 var ch = form[i].value.substring(j, j + 1)
	 if ((ch < '0' || '9' < ch) && ch != '.') {
	  alert('O valor ' + form[i].value + ' não é válido!\nPor favor, digite um valor numérico!');
	  clearform(form);
	  return false;
	 }
	}
   if (i == 1 && form[2].value != '') return false;
   firstvalue = form[i].value / form[i].factor;
   break;
  }
 }
 if (firstvalue == 0) {
  clearform(form);
  return false;
 }
 for (var i = 1; i <= form.count; i++) {
  form[i].value = firstvalue * form[i].factor;
  form[i].value = formatvalue(form[i].value, form.rsize);
 }
 return true;
 }
 
 function formatvalue(input, rsize) {
  var invalid = '**************************';
  var nines = '999999999999999999999999';
  if (input.length <= rsize) return input;
  if (strpos(input, 'e') != -1 || eval(input) > eval(nines.substring(0,rsize)+'.4')) return invalid.substring(0, rsize);
  var rounded = '' + (eval(input) + (eval(input) - eval(input.substring(0, rsize))));
  return rounded.substring(0, rsize);
 }

 function strpos(str, ch) {
  for (var i = 0; i < str.length; i++)
  if (str.substring(i, i+1) == ch) return i;
  return -1;
 }

 function resetform(form) {
  clearform(form);
  form[1].value = 1;
  convertform(form);
  return true;
 }
 
 function clearform(form) {
  for (var i = 1; i <= form.count; i++) form[i].value = '';
  return true;
 }
