
var currentMeasurementUnit = 'bushels';


function getCurrentMeasurementUnits()
{
	var radioObjs = document.dropmsgform.unit;
	for (var i = 0; i < radioObjs.length; i++)
	{	
		if (radioObjs[i].checked)
		{	return radioObjs[i].value;
		}
	}
}


function convertMeasurementUnits()
{
	var newUnits = getCurrentMeasurementUnits();
	if (newUnits == currentMeasurementUnit)
	{	return true;
	}
	currentMeasurementUnit = newUnits;

	var allTags = document.all ? document.all : document.getElementsByTagName('*');

	for (var i = 0; i < allTags.length; i++)
	{	
		var idBits = allTags[i].id.split('_');
		if (idBits.length == 3)
		{	if (idBits[0] == 'futuresPrice' || idBits[0] == 'basisPrice' || idBits[0] == 'totalPrice')
			{
				var newPrice = allTags[i].innerHTML;
				if (isNumeric(newPrice))
				{
					if (currentMeasurementUnit == 'bushels')
					{	newPrice = newPrice / 39.368;
					}else if (currentMeasurementUnit == 'metric')
					{	newPrice = newPrice * 39.368;
					}
					allTags[i].innerHTML = newPrice.toFixed(2);
				}
			}
		}
	}

}



function isNumeric(value)
{	if (value == null || value == '' || !value.toString().match(/^[-]?\d*\.?\d*$/))
	{	
		return false;
	}
	return true;
}

