function cleartext(inputname)
{
	if (inputname.value == "WEIGHT")
	{
		inputname.value = "";
	}
};
function blurWeight()
{
	if (document.getElementById("Weight").value == "")
	{
		document.getElementById("Weight").value = "WEIGHT";
	}
};
function writeText(strName, strValue, intWidth)
{
	if (document.layers)
	{
		document.write("<input id=\"Weight\" name=\"" + strName + "\" value=\"" + strValue + "\" type=\"text\" onblur=\"blurWeight()\" onkeyup=\"convertIt()\" onFocus=\"cleartext(" + strName + ")\" size=\"" + Math.round(parseInt(intWidth / 11)) + "\">");
	}
	else
	{
		document.write("<input id=\"Weight\" name=\"" + strName + "\" value=\"" + strValue + "\" type=\"text\" onblur=\"blurWeight()\" onkeyup=\"convertIt()\" onFocus=\"cleartext(" + strName + ")\" class=\"textarea\" style=\"width:" + intWidth + "px;\">");
	}
};
function convertIt()
{
	var intFrom, intTo, intWeight, intTotal, strWeight;
	intWeight = document.convert.weight.value;
	intFrom = document.convert.elements[1].options[document.convert.elements[1].selectedIndex].value;
	intTo = document.convert.elements[2].options[document.convert.elements[2].selectedIndex].value;
	if (intWeight != "" && intWeight != "WEIGHT" && document.getElementById("from").selectedIndex != 0 && document.getElementById("to").selectedIndex != 0 && isNaN(intWeight) == false)
	{
		//figure out which value to use ie kg, ton etc
		switch(parseFloat(intTo))
		{
			case 0.001:
				strWeight = "Metric Tons";
				break;
			case 1:
				strWeight = "Kilograms";
				break;
			case 1000:
				strWeight = "Grams";
				break;
			case 0.000984206527611061:
				strWeight = "Long Tons";
				break;
			case 0.00110231131092439:
				strWeight = "Short Tons";
				break;
			case 0.0220462262184878:
				strWeight = "Hundredweight";
				break;
			case 0.15747304441777:
				strWeight = "Stone";
				break;
			case 2.20462262184878:
				strWeight="Pounds";
				break;
			case 35.2739619495804:
				strWeight="Ounces";
				break;
		}
		//get total
		intTotal = parseFloat(intWeight / intFrom * intTo);
		//round off to 2 significant figures
		if (intTotal < 1)
		{
			temp = intTotal;
			exp = 3;
			while (temp < 1)
			{
				intExp = Math.pow(10, exp);
				temp = intTotal * intExp;
				exp++;
			}
			intExp = intExp * 10;
		}
		else
		{
			intExp = 100;
		}
		intTotal = (Math.round(intTotal * intExp)) / intExp;
		if (document.all)
		{
			document.all.answer.innerHTML = intTotal + " " + strWeight;
		}
		else if (document.layers)
		{
			document.answer.document.write(intTotal + " " + strWeight);
			document.answer.document.close();
		}
		else if(document.getElementById)
		{
			document.getElementById("answer").innerHTML = intTotal + " " + strWeight;
		}
	}
	else
	{
		document.getElementById("answer").innerHTML = "";
	}
};
function aolFrig()
{
	if (blnAOL)
	{
		if (document.all)
		{
			document.all.answer.style.top = 534;
		}
		else if (document.getElementById)
		{
			document.getElementById("answer").style.top = 534;
		}
	}
};
