	function convertform(form, elm) {
		var valid = '1234567890.,';
		var check = false;
		for (var i=0; i < elm.value.length; i++) {
			tmp = elm.value.substring(i,i+1);
			if (tmp == ',') {
				elm.value = elm.value.replace(/,/,".")
			}
			if (valid.indexOf(tmp) < 0) {
				alert('Only digits are allowed in the Quantity field.');
				elm.focus();
				check = false;
				return false;
			}
			else {
				check = true;
			}	
		}
		if (check == true) {
			var firstvalue = elm.value / eval("factor" + elm.name.substring(3,4));
			var tmpelm; 
			for (var i = 0; i < count; i++) {
				if (elm != form.elements[i]){
					tmpelm = form.elements[i];
					tmpelm.value = formatvalue((firstvalue * eval("factor" + tmpelm.name.substring(3,4))), rsize);				
				}
			}
		}
	}

	function convertf(form, elm) {
		var valid = '1234567890.,';
		var check = false;
		for (var i=0; i < elm.value.length; i++) {
			tmp = elm.value.substring(i,i+1);
			if (tmp == ',') {
				elm.value = elm.value.replace(/,/,".")
			}
			if (valid.indexOf(tmp) < 0) {
				alert('Only digits are allowed in the Quantity field.');
				elm.focus();
				check = false;
				return false;
			}
			else {
				check = true;
			}	
		}
	}
					  
	function formatvalue(input, size) {
	 	var invalid = "**************************";
	 	var nines = "999999999999999999999999";
	 	var str = "" + input;
		var fltin = parseFloat(str);
	 	if (str.length <= size) {
			return str;
		}	
	 	if (str.indexOf("e") != -1 || fltin > parseFloat(nines.substring(0,size)+".4")) {
			return invalid.substring(0, size);
		}	
	  	var rounded = "" + (fltin + (fltin - parseFloat(str.substring(0, size))));
	  	return rounded.substring(0, size);
	}
	
	
	function convert_cm_kg(form){
		var total_cm_kg = 1;
		for (var i=0; i<=2; i++) {
		var tmp = eval('document.convert.val'+ i);
		if (tmp.value > 0 |! tmp.value == '') {
			total_cm_kg = total_cm_kg * Math.round(tmp.value);
		}
	}
	if (total_cm_kg > 0) {
		document.convert.cm_kg.value  = Math.round(total_cm_kg / 6000);
	}
}

function convert_inches_kg(form){
		var total_inches_kg = 1;
		for (var i=3; i<=5; i++) {
		var tmp = eval('document.convert.val'+ i);
		if (tmp.value > 0 |! tmp.value == '') {
			total_inches_kg = total_inches_kg * Math.round(tmp.value);
		}
	}
	if (total_inches_kg > 0) {
		document.convert.inches_kg.value  = Math.round(total_inches_kg / 366);
	}
}

function convert_inches_pounds(form){
		var total_inches_pounds = 1;
		for (var i=6; i<=8; i++) {
		var tmp = eval('document.convert.val'+ i);
		if (tmp.value > 0 |! tmp.value == '') {
			total_inches_pounds = total_inches_pounds * Math.round(tmp.value);
		}
	}
	if (total_inches_pounds > 0) {
		document.convert.inches_pounds.value  = Math.round(total_inches_pounds / 166);
	}
}
