function convertvalue(form) {
//  get conversion factors from selected options
var i = form.fromunit.selectedIndex;
var fromunitvalue = form.fromunit.options[i].value; 
var j = form.tounit.selectedIndex;
var tounitvalue = form.tounit.options[j].value;
//  convert value    
form.tovalue.value = space((form.fromvalue.value * fromunitvalue) / tounitvalue);
return true;
}

function space (num)
{
	num = num + '';
	// exit if scientific notation
	if (num.indexOf('e') > -1){ return num; }

	var dec = num.indexOf('.');

	var left, right = '';
	if (dec >= 0)
	{
		left = num.substring(0, dec);
		right = num.substring(dec + 1);
	}
	else
		left = num;

	var new_left = '', new_right = '';
	for (var i = 0; i < right.length; i++)
	{
		new_right += right.charAt(i);
		if (i % 3 == 2 && i != right.length - 1)
			new_right += ' ';
	}
	for (var i = left.length - 1; i >= 0; i--)
	{
		new_left = left.charAt(i) + new_left;
		if ((left.length - 1 - i) % 3 == 2 && i != 0)
			new_left = ' ' + new_left;
	}

	return (dec >= 0) ? new_left + '.' + new_right : new_left;
}

function clearcell(cell) {
cell.value = "";
return true;
}