function validateChars(instring) {
    for (var i=0, outstr='', vChars="0123456789eE-."; i<instring.length; i++) {
       if (vChars.indexOf(instring.charAt(i)) != -1) {
          outstr += instring.charAt(i)
       }
    }
    return outstr;
} 

function calculateWeight() {
	var inVal
	var outVal 
	var inName
	var outName
	var qty
	var multiple;
	var tmp;

	qty = document.convertWeight.weightQty.value;
	qty = validateChars(qty);
	qty = parseFloat(qty);

	inVal = document.convertWeight.weightFrom[document.convertWeight.weightFrom.selectedIndex].value;
	outVal = document.convertWeight.weightTo[document.convertWeight.weightTo.selectedIndex].value;
	inName = document.convertWeight.weightFrom.options[document.convertWeight.weightFrom.selectedIndex].text;
	outName = document.convertWeight.weightTo.options[document.convertWeight.weightTo.selectedIndex].text;

	if (isNaN(qty)) {
		qty = 1;
	}
	document.convertWeight.weightQty.value = qty;

	multiple = eval("(" + inVal + ")/(" + outVal + ")");
	tmp = Math.round((qty * multiple) * 10000000)/10000000;
	document.convertWeight.weightResult.value = qty + " " + inName + " = " + tmp + " " + outName;
}