function clearFields() {
	var txtF = WeatherTable.all.tags("input")("txtF");
	var txtC = WeatherTable.all.tags("input")("txtC");
	
    txtF.value = "";
    txtC.value = "";
}

function sendError() {
    alert("Please enter a number.");
}

function checknumber() {
    var x = WeatherTable.all.tags("input")("txtF");
    var y = WeatherTable.all.tags("input")("txtC");
	var nx = x.split("");
	var ny = y.split("");
	if(nx[0] == "-") { x = nx[1];}
	if(ny[0] == "-") { y = ny[1];}
        var anum = /(^\d+$)|(^\d+\.\d+$)/;
        if ( (anum.test(x) || anum.test(y)) && (x != "" || y != "") )
                testresult=true;
        else {
                alert("Please enter a valid number.");
                testresult=false;
        }
        return (testresult);
}
function updateCelsius() {       
	var txtF = WeatherTable.all.tags("input")("txtF");
	var txtC = WeatherTable.all.tags("input")("txtC");
	
	txtC.value = Math.round((5.0/9.0) * (txtF.value - 32.0));
}
function updateFahrenheit() {
	var txtF = WeatherTable.all.tags("input")("txtF");
	var txtC = WeatherTable.all.tags("input")("txtC");
    
	txtF.value = Math.round((9.0/5.0) * txtC.value + 32.0);
}
function convertTemperature() 
{   
	var txtF = WeatherTable.all.tags("input")("txtF");
	var txtC = WeatherTable.all.tags("input")("txtC");
	 
	if ( (txtF.value != "") && (txtC.value == "") )
	{
		//if(checknumber())
		//{
			updateCelsius();
		//}
	}
	else if( (txtF.value == "") && (txtC.value != "") )
	{
		//if(checknumber())
		//{
			updateFahrenheit();
		//}
	}
	else if( (txtF.value == "") && (txtC.value == "") )
	{
		sendError();
	}
	else
	{
		//if(checknumber())
		//{
			txtC.value = "";
			updateCelsius();
		//}
	}
}
