function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = /  /g;
   while (temp.match(obj)) { temp = temp.replace(obj, " "); }
   return temp;
}

function getWeather(icaofield)
{
	if (document.getElementById)
	{
		var icaocode = document.getElementById(icaofield);
		if (icaocode != null)
		{
			icaocode = new String(icaocode.value);
			icaocode = trim(icaocode);
			iscode = false;
			if (icaocode.length == 3) { icaocode = 'K'+icaocode.toUpperCase(); iscode = true };
			if (icaocode.length == 4) { icaocode = icaocode.toUpperCase(); iscode = true };
			if (iscode == true) {
				window.open ("http://adds.aviationweather.gov/metars/index.php?station_ids="+icaocode+"&std_trans=translated&hoursStr=most+recent+only&chk_metars=on");
				//location.href = "weather.aspx?icao="+icaocode;
			} else {
				window.open ("http://www.accuweather.com/adcbin/public/int_getcity.asp?where="+icaocode+"&partner=accuweather");
			};
		};
	};
};