// <![CDATA[

// Special thanks to: Pinto http://www.joske-online.be/ and Tom http://www.carterlake.org/
// They pioneered the basic AJAX code using WD clientraw.txt which was
// cheerfully borrowed from Tom at CarterLake.org and adapted by
// Ken True - Saratoga-weather.org  21-May-2006
// --- Version 2.03 - 21-Sep-2007 -- added support for dynamic thermometer.php display updates
//
// for updates to this script, see http://saratoga-weather.org/scripts-VWS-AJAX.php
// announcements of new versions will be on ambientwxsupport.com and wxforum.net

// -- begin settings --------------------------------------------------------------------------
var flashcolor = '#CC0000'; // RGB color to flash for changed observations
var flashtime  = 1000;    // miliseconds to keep flash color on (1000 = 1 seconds);
var reloadTime = 2000;      // reload AJAX conditions every 2 seconds (= 2000 ms)
var wflashDataTxt = 'data.txt'; // relative path to the extra data.txt file
var wflashDir = '/';   // URL for directory for WeatherFlash relative to this script with
//                               trailing '/'.  In Root = '/', in /wflash = '/wflash/'
var imagedir = 'ajax-images';  // place for wind arrows, rising/falling arrows, etc.
var useunits = 'E';         // 'E'=USA(English) or 'M'=Metric or 'W'=use WeatherFlash settings

var useKnots = false;       // set to true to use wind speed in Knots (otherwise 
							// wind in km/hr for Metric or mph for English will be used.
var useMPS   = false;       // set to true for meters/second for metric wind speeds, false= km/h
var showUnits = false;       //  set to false if no units are to be displayed
var useAMPM   = true;       // set to false for 24hr time (only used for update time value)
var showNoWind = true;      // true shows wind=0 as 'Calm' and gust=0 as 'No Wind'
//                          // flase shows wind=0 as '0' and gust=0 as '0'
var thermometer = 'thermometer.php'; // script for dynamic thermometer PNG image (optional)
// -- end of settings -------------------------------------------------------------------------

// WeatherFlash
var wflashFile = wflashDir+'wflash.txt'; // location of wflash.txt relative to this page on website
var wflashFile2 = wflashDir+'wflash2.txt'; // location of wflash2.txt relative to this page on website
var wflashUnitsFile = wflashDir+'Data/Units.txt'; // location of Config/Units.txt file for wflash
// --- you don't need to customize the stuff below, the actions are controlled by the 
//  settings above.  
var ie4=document.all;
var browser = navigator.appName;
var ie8 = false;
if (ie4 && /MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion>=8) {
   ie4=false;
   ie8=true;
 }
}
var counterSecs = 0;  // for MCHALLIS counter script from weather-watch.com (adapted by K. True)
var lastajaxtime = 'unknown'; //used to reset the counter when a real update is done
// --------------- DON'T change thise defaults ---- they are the units used in wflash.txt, wflash2.txt
var uomTemp = '&deg;'; 	var uomTempCnvt = 0;
var uomWind = 'mph';   	var uomWindCnvt = 0;
var uomBaro = 'in';  	var uomBaroCnvt = 0;
var uomRain = 'in';    	var uomRainCnvt = 0;
var uomHumid= '%';      
var uomSolar= ' W/m<sup>2</sup>';
var uomHeight = 'ft';  	var uomHeightCnvt = 0;
var uomDistance = ' miles'; var uomDistanceCnvt = 0;
var uomPerHr = '/hr';
var uomWindDir = '&deg;';
var dpBaro = 2;
var dpRain = 2;
//----------------------------------------------------------------------------------------------------
function ajax_set_units( units ) {
//   Establish overall units for  script to use
//   Default is English (like in wflash.txt/wflash2.txt
//   ='M' chooses Metric  C, km/h, hPa, mm, m, km (option for m/s for wind)
//   ="W" forces pull of values from Config/Units.txt file (Weather Flash default settings file)
if (units == 'M') { // set to metric
	uomTemp = '&deg;C'; 	uomTempCnvt = 1;
	uomWind = ' km/h';		uomWindCnvt = 1;
	if(useMPS)   { uomWind = ' m/s'; uomWindCnvt = 3;}
	uomBaro = ' hPa'; 		uomBaroCnvt = 3;
	uomRain = ' mm';  		uomRainCnvt = 1;
	uomHeight = ' m'; 		uomHeightCnvt = 1;
	uomDistance = ' km'; 	uomDistanceCnvt = 1;
	dpBaro = 1;
	dpRain = 1;
  }
  if(useKnots) { uomWind = ' kts'; uomWindCnvt = 2;}
  if(units == "W") { // get the units to use first (runs once)
    ajaxGetUnits(wflashUnitsFile + '?' + new Date().getTime()); 
  }

} // end ajax_set_units()

ajax_set_units(useunits); // set up the units to ues

// utility function to display UOM based on showUnits flag
function ajaxUOM ( uom ) {
	if (showUnits) { 
		return( uom );
	} else {
		return( "" );
	}
}

// utility function to display UOM based on showUnits flag
function nilWind ( v1, v2 ) {
	if (showNoWind) { 
		return( v1 );
	} else {
		return( v2 );
	}
}

// utility functions to handle conversions from clientraw data to desired units-of-measure
function convertTemp ( rawtemp ) {
	var retval = 0;
	if (uomTempCnvt == 0) { // leave in F
		retval = rawtemp * 1.0 ;
	} else {  // convert to C
		retval = (rawtemp - 32) * 0.57;
	}
	return(retval.toFixed(1));
}

function convertTempRate ( rawtemp ) {
	var retval = 0;
	if (uomTempCnvt == 0) { // leave in F rate
		retval = rawtemp * 1.0 ;
	} else {  // convert to C rate
		retval = rawtemp * 0.55555 ;
	}
	return(retval.toFixed(1));
}

function convertWind  ( rawwind ) {
  var retval = 0;
  switch (uomWindCnvt) { // convert from MPH to
	case 0 : // MPH
  		retval = rawwind * 1.0;
		break;
	case 1: // KPH
		retval = rawwind * 1.609344;
		break;
	case 2: // knots
		retval = rawwind * 0.868976242;
		break;
	case 3: // meters per second
		retval = rawwind * 0.44704;
		break;
	default:
	    retval = rawwind * 1.0;
  }
  
  return (retval.toFixed(0));

}

function convertBaro ( rawbaro ) {
  var retval = 0;
  switch (uomBaroCnvt) { // convert from inHg to
	case 0 : // inHg
  		retval = rawbaro * 1.0;
		break;
	case 1: // mmHg
		retval = rawbaro * 25.4;
		break;
	case 2: // mb
		retval = rawbaro * 33.86;
		break;
	case 3: // hPa
		retval = rawbaro * 33.86;
		break;
	default:
	    retval = rawbaro * 1.0;
  
  }
  
  return (retval.toFixed(dpBaro));
}

function convertRain ( rawrain ) { // convert from inches to
	var retval = 0;
	if (uomRainCnvt == 0) { // leave in in
		retval = rawrain * 1.0 ;
	} else {  // convert to mm
		retval = rawrain * 25.4;
	}
	return(retval.toFixed(dpRain));
}

function convertHeight ( rawheight ) { // convert from feet to
	var retval = 0;
	if (uomHeightCnvt == 0) { // leave in feet
		retval = rawrain * 1.0 ;
	} else {  // convert to meters
		retval = rawrain * 0.3048;
	}
	return(retval.toFixed(0));
}

function convertDistance ( rawdist ) { // convert from miles to
	var retval = 0;
	if (uomDistanceCnvt == 0) { // leave in miles
		retval = rawdist * 1.0 ;
	} else {  // convert to km
		retval = rawdist * 1.609344;
	}
	return(retval.toFixed(1));
}


// utility functions to navigate the HTML tags in the page
function get_ajax_tags ( ) {
// search all the span tags and return the list with class="ajax" in it
//
  if (ie4 && browser != "Opera" && ! ie8) {
    var elem = document.body.getElementsByTagName('span');
	var lookfor = 'className';
  } else {
    var elem = document.getElementsByTagName('span');
	var lookfor = 'class';
  }
     var arr = new Array();
	 var iarr = 0;
     for(var i = 0; i < elem.length; i++) {
          var att = elem[i].getAttribute(lookfor);
          if(att == 'ajax') {
               arr[iarr] = elem[i];
               iarr++;
          }
     }

     return arr;
}

function reset_ajax_color( usecolor ) {
// reset all the <span class="ajax"...> styles to have no color override
      var elements = get_ajax_tags();
	  var numelements = elements.length;
	  for (var index=0;index!=numelements;index++) {
         var element = elements[index];
	     element.style.color=usecolor;
 
      }
}

function set_ajax_obs( name, value ) {
// store away the current value in both the doc and the span as lastobs="value"
// change color if value != lastobs

		var element = document.getElementById(name);
		if (! element ) { return; } // V1.04 -- don't set if missing the <span id=name> tag
		var lastobs = element.getAttribute("lastobs");
		element.setAttribute("lastobs",value);
		if (value != unescape(lastobs)) {
          element.style.color=flashcolor;
		}
		element.innerHTML =  value;
}

function set_ajax_uom( name, onoroff ) {
// this function will set an ID= to visible or hidden by setting the style="display: "
// from 'inline' or 'none'

		var element = document.getElementById(name);
		if (! element ) { return; } 
		if (onoroff) {
          element.style.display='inline';
		} else {
          element.style.display='none';
		}
}

// --- end of flash-green functions

function windDir ($winddir)
//  see http://www.weather-watch.com/smf/index.php/topic,20097.0.html
{
   $windlabel = new Array("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW");
   return $windlabel[Math.floor(((parseInt($winddir) + 11) / 22.5) % 16 )];
}

function ajax_getUVrange ( uv ) { // code simplified by FourOhFour on wxforum.net
// generate a styled, word description of current UV index
   var uvword = "Unspec.";
   if (uv <= 0) {
       uvword = "None";
   } else if (uv < 3) {
       uvword = "<span style=\"border: solid 1px; background-color: #A4CE6a;\">&nbsp;Low&nbsp;</span>";
   } else if (uv < 6) {
       uvword = "<span style=\"border: solid 1px; background-color: #FBEE09;\">&nbsp;Medium&nbsp;</span>";
   } else if (uv < 8) {
       uvword =  "<span style=\"border: solid 1px; background-color: #FD9125;\">&nbsp;High&nbsp;</span>";
   } else if (uv < 11) {
       uvword =  "<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;Very&nbsp;High&nbsp;</span>";
   } else {
       uvword =  "<span style=\"border: solid 1px; color: #FFFF00; background-color: #807780;\">&nbsp;Extreme&nbsp;</span>";
   }
   return uvword;
} // end ajax_getUVrange function

function ajax_genarrow( nowVal, priorVal, Legend, textUP, textDN, numDp) {
// generate an <img> tag with alt= and title= for rising/falling values	
	
  var diff = nowVal.toFixed(numDp) - priorVal.toFixed(numDp);
  var absDiff = Math.abs(diff);
  var diffStr = '' + diff.toFixed(numDp);  // sprintf("%01.0f",$diff);
  var absDiffStr = '' + absDiff.toFixed(numDp); // sprintf("%01.0f",$absDiff);
  var image = '';
  var msg = '';
  
  if (diff == 0) {
 // no change
    image = '&nbsp;'; 
  } else if (diff > 0) {
// now is greater 
//    msg = textUP + " by " + diff.toFixed(1); // sprintf($textDN,$absDiff); 
	msg = textUP.replace(/\%s/,absDiffStr);
    image = "<img src=\"" + imagedir + "/rising.gif\" alt=\"" + msg + 
	"\" title=\""+ msg + 
	"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";
  } else {
// now is lesser
    msg = textDN.replace(/\%s/,absDiffStr); // sprintf($textDN,$absDiff); 
//	msg = textDN.replace(/\%s/,absDiffStr);
    image = "<img src=\"" + imagedir + "/falling.gif\" alt=\"" + msg + 
	"\" title=\""+ msg + 
	"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";
  }

   if (Legend) {
       return (diff + Legend + image);
	} else {
	   return image;
	}
} // end genarrow function

function ajax_format_time(rawtime) {
// convert 24hr time to 12hr time (for updated time only)
	if (! useAMPM ) {
		return(rawtime); // keep it as 24hr time
	}
	
	var hms = rawtime.split(":");
	
	var amOrPm = "am";
	if (hms[0] > 11) {amOrPm = "pm";}
	if (hms[0] > 12) {hms[0] = hms[0] - 12;}
	if (hms[0] == 0) {hms[0] = 12;}
	return(hms[0] + ":" + hms[1] + ":" + hms[2] + amOrPm);
}
// Mike Challis' counter function (adapted by Ken True)
//
function ajax_countup() {
 element = document.getElementById("ajaxcounter");
 if (element) {
  element.innerHTML = counterSecs;
  counterSecs++;
 }
}

// ------------------------------------------------------------------------------------------
//  function.. read Units.txt and reset the uomVVVV and dpVVVV values as needed .. run once
// ------------------------------------------------------------------------------------------
function ajaxGetUnits(url) {
// read the Units.txt file and set our uomVVVV and dpVVVV values 
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);
	
  }
  if (x) { // got something back
    x.onreadystatechange = function() {
    try { if (x.readyState == 4 && x.status == 200) { // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE 
      var wunits = x.responseText.split('&');
	  var t = '';
	  var i = 0;
	  for (i=0;i<wunits.length;i++) {
		  var uparts = wunits[i].split('=');
		  t = t+"'"+uparts[0]+"' = '"+uparts[1]+"'\n";
		  
		  switch (uparts[0]) { // handle the units values
		    case "Distance" :
			  if (uparts[1] == 'miles') { uomDistance = ' miles';	uomDistanceCnvt = 0; }
			  if (uparts[1] == 'km')    { uomDistance = ' km'; 		uomDistanceCnvt = 1; }
			  t = t+"Set='"+uomDistance+"'\n";
			  break;
		    case "Altitude" :
			  if (uparts[1] == 'ft') { uomHeight = ' ft';  	uomHeightCnvt = 0;}
			  if (uparts[1] == 'm') { uomHeight = ' m'; 	uomHeightCnvt = 1;}
			  t = t+"Set='"+uomHeight+"'\n";
			  break;
		    case "Rain" :
			  if (uparts[1] == 'in') { uomRain = ' in'; dpRain = 2;	uomRainCnvt = 0;}
			  if (uparts[1] == 'mm') { uomRain = ' mm'; dpRain = 1;	uomRainCnvt = 1;}
			  t = t+"Set='"+uomRain+"' dpRain='"+dpRain+"'\n";
			  break;
		    case "Wind" :
			  if (uparts[1] == 'mph') { uomWind = 'mph';	uomWindCnvt = 0;}
			  if (uparts[1] == 'kph') { uomWind = ' km/h';	uomWindCnvt = 1;}
			  if (uparts[1] == 'knots') { uomWind = ' kts';	uomWindCnvt = 2;}
			  if (uparts[1] == 'm/s') { uomWind = ' m/s';	uomWindCnvt = 3;}
			  t = t+"Set='"+uomWind+"'\n";
			  break;
		    case "Pressure" :
			  if (uparts[1] == 'inHg') { uomBaro = ' inHg'; dpBaro = 2;		uomBaroCnvt = 0;}
			  if (uparts[1] == 'mmHg') { uomBaro = ' mmHg'; dpBaro = 1;		uomBaroCnvt = 1;}
			  if (uparts[1] == 'mb') { uomBaro = ' mb'; dpBaro = 1;			uomBaroCnvt = 2;}
			  if (uparts[1] == 'hPa') { uomBaro = ' hPa'; dpBaro = 1;		uomBaroCnvt = 3;}
			  t = t+"Set='"+uomBaro+"' dpBaro='"+dpBaro+"'\n";
			  break;
		    case "Temperature" :
			  var tmp = uparts[1];
			  if (tmp.match(/F$/i) ) { uomTemp = '&deg;F';	uomTempCnvt = 0;}
			  if (tmp.match(/C$/i) ) { uomTemp = '&deg;C';	uomTempCnvt = 1;}
			  t = t+"Set='"+uomTemp+"'\n";
			  break;
			default :
		    // no 'default'
		  } // end switch (uparts[0])
		
	  } // end for
//	  alert(t);
      x.abort();

// 	  } // END if(wunits[0] 

	 } // END if (x.readyState == 4 && x.status == 200)

    } // END try

   	catch(e){ }  // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE

    } // END x.onreadystatechange = function() {
    x.open("GET", url, true);
    x.send(null);
//	alert("did Open and send of null");
  }
  
} // end ajaxGetUnits function

// ------------------------------------------------------------------------------------------
//  main function.. read wflash.txt and format <span class="ajax" id="ajax..."></span> areas
// ------------------------------------------------------------------------------------------
function ajaxLoaderVWSf(url) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);
  }
  if (x) { // got something back
    x.onreadystatechange = function() {
    try { if (x.readyState == 4 && x.status == 200) { // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE 
    var wflash = x.responseText.split(',');
	// now make sure we got the entire wflash.txt  -- thanks to Johnnywx
	// valid wflash.txt has 'F=nnnnnnnnnn'
	var wdpattern=/F\=(\d+)/; 
	if( wdpattern.test(wflash[0]) ) { // got it.. process wflash.txt
        // main routine ---
		var datestamp = wflash[0]; // extracted from the F=() in the first string
		// Note: F=nnnnn: the value is number of seconds since Jan 01, 1900 00:00:00 UTC
		datestamp = datestamp.replace(wdpattern,"$1");
		var datezero = new Date('Jan 01, 1900 00:00:00 UTC');
		var datetime = new Date();
		datetime.setTime(datestamp*1000 + datezero.getTime()); // adjust date to offset from zero time
		set_ajax_obs("ajaxdatetime",datetime);
		set_ajax_obs("ajaxdatetimelocale",datetime.toLocaleString());
	
		//BEGIN TEMPERATURE DATA
        set_ajax_obs("ajaxdegree0",uomTemp);
        set_ajax_obs("ajaxdegree1",uomTemp);

		//CURRENT TEMPERATURE
		var temperature = convertTemp(wflash[9]);
        set_ajax_obs("ajaxtemp",temperature+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxtemprightnow",temperature+ajaxUOM(uomTemp));
	
		//CURRENT TEMPERATURE RATE
		var temprate = convertTempRate(wflash[37]);
		set_ajax_obs("ajaxtemprate",temprate+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		set_ajax_obs("ajaxtemparrow", 
			   ajax_genarrow(temperature*1.0, temperature-temprate*1.0, '', 
				 'Increasing %s'+uomTemp+' per hour.',
				 'Decreasing %s'+uomTemp+' per hour.',1)
		);	
		//END TEMPERATURE DATA
	
	
		//Current UV Index
	
		var uv = wflash[19];
		uv = uv * 1.0;
		set_ajax_obs("ajaxuv",uv.toFixed(1));
	
		var uvrate = wflash[47];
		uvrate = uvrate * 1.0;
		set_ajax_obs("ajaxuvrate",uvrate.toFixed(1)+ajaxUOM(uomPerHr));
	
		var	uvword = ajax_getUVrange(uv);
		set_ajax_obs("ajaxuvword",uvword);
	
		//Current Solar Radiation
		var solar = wflash[20];
		solar = solar * 1.0;
		set_ajax_obs("ajaxsolar",solar.toFixed(0)+ajaxUOM(uomSolar));
	
		var solarrate = wflash[48];
		solarrate = solarrate * 1.0;
		set_ajax_obs("ajaxsolarrate",solarrate.toFixed(0)+ajaxUOM(uomSolar)+ajaxUOM(uomPerHr));
	
		//Current Evaportranspiration
		var et = convertRain(wflash[18]);
		set_ajax_obs("ajaxet",et+ajaxUOM(uomRain));
	
		var etrate = convertRain(wflash[46]);
		etrate = etrate * 1.0;
		set_ajax_obs("ajaxetrate",etrate+ajaxUOM(uomRain)+ajaxUOM(uomPerHr));
	
		//BEGIN HEAT INDEX DATA
		//CURRENT HEAT INDEX
		if (wflash[9] >= 70) { // NOAA sez need 80F+ for Heat Index
			var heatindex = convertTemp(wflash[23]);
			set_ajax_obs("ajaxheatidx",heatindex+ajaxUOM(uomTemp));
		
			//CURRENT HEAT INDEX RATE
			var heatindexrate = convertTempRate(wflash[51]);
			set_ajax_obs("ajaxheatidxrate",heatindexrate+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
	
			set_ajax_obs("ajaxheatidxarrow", 
				   ajax_genarrow(heatindex*1.0, heatindex-heatindexrate*1.0, '', 
					 'Increasing %s'+uomTemp+' per hour.',
					 'Decreasing %s'+uomTemp+' per hour.',1)
			);	
		} else {
			set_ajax_obs("ajaxheatidx",'---');
			set_ajax_obs("ajaxheatidxrate",'---');
			set_ajax_obs("ajaxheatidxarrow",'');
		}
		//END HEAT INDEX DATA
	
		//BEGIN WIND CHILL DATA
		//CURRENT WIND CHILL
		if (wflash[9] <= 40) { // NOAA sez Wind Chill starts at 40F
			var windchill = convertTemp(wflash[21]);
			set_ajax_obs("ajaxwindchill",windchill+'&deg;');
		
			//CURRENT WIND CHILL RATE
			var windchillrate = convertTempRate(wflash[49]);
			set_ajax_obs("ajaxwindchillrate",windchillrate+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		
			set_ajax_obs("ajaxwindchillarrow", 
				   ajax_genarrow(windchill*1.0, windchill-windchillrate*1.0, '', 
					 'Increasing %s'+uomTemp+' per hour.',
					 'Decreasing %s'+uomTemp+' per hour.',1)
			);	
		} else {
			set_ajax_obs("ajaxwindchill",'---');
			set_ajax_obs("ajaxwindchillrate",'---');
			set_ajax_obs("ajaxwindchillarrow",'');
		}
		//END WIND CHILL DATA
	
		//BEGIN PRESSURE DATA
		set_ajax_obs("ajaxbaroin",uomBaro);

		//CURRENT PRESSURE (Sea Level)
		var pressure = convertBaro(wflash[25]);
		set_ajax_obs("ajaxbaro",pressure);
	
		//CURRENT PRESSURE RATE (Sea Level)
		var barometerrate = convertBaro(wflash[53]);
		set_ajax_obs("ajaxbarorate",barometerrate+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
	
		set_ajax_obs("ajaxbaroarrow",
			   ajax_genarrow(pressure*1.0, pressure-barometerrate*1.0, '', 
				 'Rising %s '+uomBaro+'/hour.',
				 'Falling %s '+uomBaro+'/hour.',2)
		);	
		//END PRESSURE DATA
	
		//BEGIN RAW BAROMETER DATA
		//CURRENT RAW BAROMETER
		var rawbaro = convertBaro(wflash[10]);
		set_ajax_obs("ajaxrawbaro",rawbaro+ajaxUOM(uomBaro));
	
		//CURRENT RAW BAROMETER RATE
		var rawbarorate = convertBaro(wflash[38]);
		set_ajax_obs("ajaxrawbarorate",rawbarorate+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
	
		set_ajax_obs("ajaxrawbaroarrow",
			   ajax_genarrow(rawbaro*1.0, rawbaro-rawbarorate*1.0, '', 
				 'Rising %s '+uomBaro+'/hour.',
				 'Falling %s '+uomBaro+'/hour.',2)
		);	
		//END RAW BAROMETER DATA
	
		//BEGIN WIND DATA
		//CURRENT WIND GUST RATE
		var gustrate = convertWind(wflash[33]);
		set_ajax_obs("ajaxgustrate",gustrate+ajaxUOM(uomWind)+ajaxUOM(uomPerHr));
	
		//CURRENT WIND RATE
		var windrate = convertWind(wflash[32]);
		set_ajax_obs("ajaxwindrate",windrate+ajaxUOM(uomWind)+ajaxUOM(uomPerHr));
	
		//WIND DIRECTION DATA
		var winddir2 = wflash[3];
		winddir2 = winddir2 * 1.0;
		set_ajax_obs("ajaxwinddir2",winddir2.toFixed(0)+ajaxUOM(uomWindDir));
	
		//CURRENT WIND GUST
		var gust = convertWind(wflash[5]);
 
 		//CURRENT WIND SPEED
		var wind = convertWind(wflash[4]);
		set_ajax_obs("ajaxwinduom",uomWind);
		set_ajax_obs("ajaxgustuom",uomWind);
		var windcardinal = windDir(wflash[3]);
	
		if (wind >= 0.1) {
			set_ajax_obs("ajaxwind",wind);
			set_ajax_uom("ajaxwinduom",true);
		} else {
			set_ajax_obs("ajaxwind",nilWind('Calm','0'));
			set_ajax_uom("ajaxwinduom",false);
		}
	
		if (gust > 0.0) {
			set_ajax_obs("ajaxgust",gust);
			set_ajax_uom("ajaxgustuom",true);
		} else {
			set_ajax_obs("ajaxgust",nilWind('none','0'));
			set_ajax_uom("ajaxgustuom",false);
		}
	
		if (gust > 0.0 || wind > 0.0) {
			set_ajax_obs("ajaxwindicon","<img src=\""+imagedir+"/"+windcardinal + ".gif\" width=\"12\" height=\"12\" alt=\"Wind from" +
			windcardinal + "\" title=\"Wind from " + windcardinal + "\" /> ");
			set_ajax_obs("ajaxwinddir",windcardinal);
////                                                                                                           .................
			set_ajax_obs("ajaxfromthe",'from the ');
////                                                                                                           .................
		} else {
			set_ajax_obs("ajaxwindicon",nilWind(" ","<img src=\""+imagedir+"/"+windcardinal + ".gif\" width=\"12\" height=\"12\" alt=\"Wind from" +
			windcardinal + "\" title=\"Wind from " + windcardinal + "\" /> "));
			set_ajax_obs("ajaxwinddir",nilWind('',windcardinal));
////                                                                                                           .................
			set_ajax_obs("ajaxfromthe",'');	
////                                                                                                           .................
		}
////                                                                                                           .................
        // Wind Chill and Wind speed danger
		if (wind > 4 && windchill < 20.0) {
			set_ajax_obs("ajaxchilldanger", 'Dangerous Wind Chill');
		} else {
			set_ajax_obs("ajaxchilldanger", '');
			}
////                                                                                                           .................
	
		//CURRENT WIND RATE
		var winddirrate = convertWind(wflash[31]);
		set_ajax_obs("ajaxwinddirrate",winddirrate+ajaxUOM(uomWindDir)+ajaxUOM(uomPerHr));
		//END WIND DATA
	
		//BEGIN RAIN DATA
		//YEARLY RAIN
		var rainyr = convertRain(wflash[11]);
		rainyr = rainyr * 1.0;
		set_ajax_obs("ajaxrainyr",rainyr+ajaxUOM(uomRain));
		//END RAIN DATA
	
		//BEGIN HUMIDITY DATA
		//CURRENT HUMIDITY
		var humidity = wflash[7];
		humidity = humidity * 1.0;
		set_ajax_obs("ajaxhumidity",humidity.toFixed(0)+'%');
	
		//CURRENT HUMIDITY RATE
		var humidityrate = wflash[35];
		humidityrate = humidityrate * 1.0;
		set_ajax_obs("ajaxhumidityrate",humidityrate.toFixed(0)+ajaxUOM(uomHumid)+ajaxUOM(uomPerHr));
		set_ajax_obs("ajaxhumidityarrow", 
			   ajax_genarrow(humidity*1.0, humidity-humidityrate*1.0, '', 
				 'Increasing %s% per hour.',
				 'Decreasing %s% per hour.',1)
		);	
		//END HUMIDITY DATA
	
		//BEGIN DEW POINT DATA
		//CURRENT DEW POINT
		var dew = convertTemp(wflash[24]);
		set_ajax_obs("ajaxdew",dew+ajaxUOM(uomTemp));
	
		//CURRENT DEW POINT RATE
		var dewrate = convertTempRate(wflash[52]);
		set_ajax_obs("ajaxdewrate",dewrate+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		set_ajax_obs("ajaxdewarrow", 
			   ajax_genarrow(dew*1.0, dew-dewrate*1.0, '', 
				 'Increasing %s'+uomTemp+' per hour.',
				 'Decreasing %s'+uomTemp+' per hour.',1)
		);	
		//END DEW POINT DATA
	
		//UPDATED TIME AND DATE
		// note: date will be from wflash2[275]
		var ajaxtime = wflash[1];
		ajaxtime = ajaxtime.replace( "+" , "0");
		ajaxtime = ajax_format_time(ajaxtime);
		set_ajax_obs("ajaxtime",ajaxtime);
 
  		if (lastajaxtime != ajaxtime) {
			counterSecs = 0;                      // reset timer
			lastajaxtime = ajaxtime; // remember this time
		}

		// now ensure that the indicator flashes on every AJAX fetch
        element = document.getElementById("ajaxindicator");
		if (element) {
          element.style.color = flashcolor;
		}

 	  } // END if(wflash[0] 

	 } // END if (x.readyState == 4 && x.status == 200)

    } // END try

   	catch(e){}  // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE

    } // END x.onreadystatechange = function() {
    x.open("GET", url, true);
    x.send(null);

	setTimeout("reset_ajax_color('')",flashtime); // change text back to default color 
    setTimeout("ajaxLoaderVWSf(wflashFile + '?' + new Date().getTime())", reloadTime); // get new data after 5 secs
  }
} // end ajaxLoaderVWSf function

// ------------------------------------------------------------------------------------------
//  main function.. read wflash2.txt and format <span class="ajax" id="ajax..."></span> areas
// ------------------------------------------------------------------------------------------
function ajaxLoaderVWSf2(url) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);
  }
  if (x) { // got something back
    x.onreadystatechange = function() {
    try { if (x.readyState == 4 && x.status == 200) { // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE 
    var wflash2 = x.responseText.split(',');
	// now make sure we got the entire wflash.txt  -- thanks to Johnnywx
	// valid wflash2.txt has 'S=HH:MM:SS'
	var wdpattern=/S\=.*:/; // looks for 'S=HH:MM:SS' timestamp
	if( wdpattern.test(wflash2[0]) ) { // got it.. process wflash2.txt


		//BEGIN TEMPERATURE DATA
		//High AND TIME TEMPERATURE
		var hightemperature = convertTemp(wflash2[36]);
		set_ajax_obs("ajaxhightemp",hightemperature+ajaxUOM(uomTemp));
		hightemperaturetime = wflash2[64];
		set_ajax_obs("ajaxhightemptime",hightemperaturetime) ;
		
		//LOW AND TIME TEMPERATURE
		var lowtemperature = convertTemp(wflash2[92]);
		set_ajax_obs("ajaxlowtemp",lowtemperature+ajaxUOM(uomTemp));
		lowtemperaturetime = wflash2[120];
		set_ajax_obs("ajaxlowtemptime",lowtemperaturetime) ;
		
		//AVERAGE TEMPERATURE
		var avgtemperature = convertTemp(wflash2[8]);
		set_ajax_obs("ajaxavgtemp",avgtemperature+ajaxUOM(uomTemp));
		
		//High Rate AND TIME TEMPERATURE
		var highratetemperature = convertTempRate(wflash2[148]);
		set_ajax_obs("ajaxhighratetemp",highratetemperature+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		highratetemperaturetime = wflash2[176];
		set_ajax_obs("ajaxhighratetemptime",highratetemperaturetime) ;
		
		//Low Rate AND TIME TEMPERATURE
		var lowratetemperature = convertTempRate(wflash2[204]);
		set_ajax_obs("ajaxlowratetemp",lowratetemperature+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		lowratetemperaturetime = wflash2[232];
		set_ajax_obs("ajaxlowratetemptime",lowratetemperaturetime) ;
		//END TEMEPRATURE DATA
		
		
		
		//BEGIN DEW POINT DATA
		//High AND TIME DEW POINT
		var highdewpoint = convertTemp(wflash2[51]);
		set_ajax_obs("ajaxhighdew",highdewpoint+ajaxUOM(uomTemp));
		highdewpointtime = wflash2[79];
		set_ajax_obs("ajaxhighdewtime",highdewpointtime) ;
		
		//LOW AND TIME DEW POINT
		var lowdewpoint = convertTemp(wflash2[107]);
		set_ajax_obs("ajaxlowdew",lowdewpoint+ajaxUOM(uomTemp));
		lowdewpointtime = wflash2[135];
		set_ajax_obs("ajaxlowdewtime",lowdewpointtime) ;
		
		//AVERAGE DEW POINT
		var avgdewpoint = convertTemp(wflash2[23]);
		set_ajax_obs("ajaxavgdew",avgdewpoint+ajaxUOM(uomTemp));
		
		//High Rate AND TIME DEW POINT
		var highratedewpoint = convertTempRate(wflash2[163]);
		set_ajax_obs("ajaxhighratedew",highratedewpoint+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		highratedewpointtime = wflash2[191];
		set_ajax_obs("ajaxhighratedewtime",highratedewpointtime) ;
		
		//Low Rate AND TIME DEW POINT
		var lowratedewpoint = convertTempRate(wflash2[219]);
		set_ajax_obs("ajaxlowratedew",lowratedewpoint+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		lowratedewpointtime = wflash2[247];
		set_ajax_obs("ajaxlowratedewtime",lowratedewpointtime) ;
		//END DEW POINT DATA
		
		
		
		//BEGIN HUMIDITY DATA
		//High AND TIME HUMIDITY
		var highhumidity = wflash2[34];
		highhumidity = highhumidity * 1.0;
		set_ajax_obs("ajaxhighhumidity",highhumidity.toFixed(0)+ajaxUOM(uomHumid));
		highhumiditytime = wflash2[62];
		set_ajax_obs("ajaxhighhumiditytime",highhumiditytime) ;
		
		//LOW AND TIME HUMIDITY
		var lowhumidity = wflash2[90];
		lowhumidity = lowhumidity * 1.0;
		set_ajax_obs("ajaxlowhumidity",lowhumidity.toFixed(0)+ajaxUOM(uomHumid));
		lowhumiditytime = wflash2[118];
		set_ajax_obs("ajaxlowhumiditytime",lowhumiditytime) ;
		
		//AVERAGE HUMIDITY
		var avghumidity = wflash2[6];
		avghumidity = avghumidity * 1.0;
		set_ajax_obs("ajaxavghumidity",avghumidity.toFixed(0)+ajaxUOM(uomHumid));
		
		//High Rate AND TIME HUMIDITY
		var highratehumidity = wflash2[146];
		highratehumidity = highratehumidity * 1.0;
		set_ajax_obs("ajaxhighratehumidity",highratehumidity.toFixed(0)+ajaxUOM(uomHumid)+ajaxUOM(uomPerHr));
		highratehumiditytime = wflash2[174];
		set_ajax_obs("ajaxhighratehumiditytime",highratehumiditytime) ;
		
		//Low Rate AND TIME HUMIDITY
		var lowratehumidity = wflash2[202];
		lowratehumidity = lowratehumidity * 1.0;
		set_ajax_obs("ajaxlowratehumidity",lowratehumidity.toFixed(0)+ajaxUOM(uomHumid)+ajaxUOM(uomPerHr));
		lowratehumiditytime = wflash2[230];
		set_ajax_obs("ajaxlowratehumiditytime",lowratehumiditytime) ;
		//END HUMIDITY DATA
		
		
		
		//BEGIN WIND SPEED DATA
		//High AND TIME WIND SPEED
		var highwindspeed = convertWind(wflash2[31]);
		set_ajax_obs("ajaxhighwind",highwindspeed+ajaxUOM(uomWind));
		highwindspeedtime = wflash2[59];
		set_ajax_obs("ajaxhighwindtime",highwindspeedtime) ;
		
		//LOW AND TIME WIND SPEED
		var lowwindspeed = convertWind(wflash2[87]);
		set_ajax_obs("ajaxlowwind",lowwindspeed+ajaxUOM(uomWind));
		lowwindspeedtime = wflash2[115];
		set_ajax_obs("ajaxlowwindtime",lowwindspeedtime) ;
		
		//AVERAGE WIND SPEED
		var avgwindspeed = convertWind(wflash2[3]);
		set_ajax_obs("ajaxavgwind",avgwindspeed+ajaxUOM(uomWind));
		
		//High Rate AND TIME WIND SPEED
		var highratewindspeed = convertWind(wflash2[143]);
		set_ajax_obs("ajaxhighratewind",highratewindspeed+ajaxUOM(uomWind)+ajaxUOM(uomPerHr));
		highratewindspeedtime = wflash2[171];
		set_ajax_obs("ajaxhighratewindtime",highratewindspeedtime) ;
		
		//Low Rate AND TIME WIND SPEED
		var lowratewindspeed = convertWind(wflash2[199]);
		set_ajax_obs("ajaxlowratewind",lowratewindspeed+ajaxUOM(uomWind)+ajaxUOM(uomPerHr));
		lowratewindspeedtime = wflash2[227];
		set_ajax_obs("ajaxlowratewindtime",lowratewindspeedtime) ;
		//END WIND SPEED DATA
		
		
		
		//BEGIN WIND GUST DATA
		//High AND TIME WIND GUST
		var highwindgust = convertWind(wflash2[32]);
		set_ajax_obs("ajaxhighgust",highwindgust+ajaxUOM(uomWind));
		highwindgusttime = wflash2[60];
		set_ajax_obs("ajaxhighgusttime",highwindgusttime) ;
		
		//LOW AND TIME WIND GUST
		var lowwindgust = convertWind(wflash2[88]);
		set_ajax_obs("ajaxlowgust",lowwindgust+ajaxUOM(uomWind));
		lowwindgusttime = wflash2[116];
		set_ajax_obs("ajaxlowgusttime",lowwindgusttime) ;
		
		//AVERAGE WIND GUST
		var avgwindgust = convertWind(wflash2[4]);
		set_ajax_obs("ajaxavggust",avgwindgust+ajaxUOM(uomWind));
		
		//High Rate AND TIME GUST SPEED
		var highratewindgust = convertWind(wflash2[144]);
		set_ajax_obs("ajaxhighrategust",highratewindgust+ajaxUOM(uomWind)+ajaxUOM(uomPerHr));
		highratewindgusttime = wflash2[172];
		set_ajax_obs("ajaxhighrategusttime",highratewindgusttime) ;
		
		//Low Rate AND TIME GUST SPEED
		var lowratewindgust = convertWind(wflash2[200]);
		lowratewindgust = lowratewindgust * 1.0;
		set_ajax_obs("ajaxlowrategust",lowratewindgust+ajaxUOM(uomWind)+ajaxUOM(uomPerHr));
		lowratewindgusttime = wflash2[228];
		set_ajax_obs("ajaxlowrategusttime",lowratewindgusttime) ;
		//END WIND GUST DATA
		
		
		
		//BEGIN WIND Direction DATA
		//High AND TIME Direction
		var highwinddirection = wflash2[30];
		highwinddirection = highwinddirection * 1.0;
		set_ajax_obs("ajaxhighwinddir",highwinddirection.toFixed(0)+ajaxUOM(uomWindDir));
		highwinddirectiontime = wflash2[58];
		set_ajax_obs("ajaxhighwinddirtime",highwinddirectiontime) ;
		
		//LOW AND TIME WIND Direction
		var lowwinddirection = wflash2[86];
		lowwinddirection = lowwinddirection * 1.0;
		set_ajax_obs("ajaxlowwinddir",lowwinddirection.toFixed(0)+ajaxUOM(uomWindDir));
		lowwinddirectiontime = wflash2[114];
		set_ajax_obs("ajaxlowwinddirtime",lowwinddirectiontime) ;
		
		//AVERAGE WIND Direction
		var avgwinddirection = wflash2[2];
		avgwinddirection = avgwinddirection * 1.0;
		set_ajax_obs("ajaxavgwinddir",avgwinddirection.toFixed(0)+ajaxUOM(uomWindDir));
		
		//High Rate AND TIME Direction
		var highratewinddirection = wflash2[142];
		highratewinddirection = highratewinddirection * 1.0;
		set_ajax_obs("ajaxhighratewinddir",highratewinddirection.toFixed(0)+ajaxUOM(uomWindDir)+ajaxUOM(uomPerHr));
		highratewinddirectiontime = wflash2[170];
		set_ajax_obs("ajaxhighratewinddirtime",highratewinddirectiontime) ;
		
		//Low Rate AND TIME Direction
		var lowratewinddirection = wflash2[198];
		lowratewinddirection = lowratewinddirection * 1.0;
		set_ajax_obs("ajaxlowratewinddir",lowratewinddirection.toFixed(0)+ajaxUOM(uomWindDir)+ajaxUOM(uomPerHr));
		lowratewinddirectiontime = wflash2[226];
		set_ajax_obs("ajaxlowratewinddirtime",lowratewinddirectiontime) ;
		//END WIND Direction DATA
		
		
		
		//BEGIN BAROMETER DATA (Sea Level Pressure)
		//High AND TIME BAROMETER
		var highbarometer = convertBaro(wflash2[52]);
		set_ajax_obs("ajaxhighbarometer",highbarometer+ajaxUOM(uomBaro));
		highbarometertime = wflash2[80];
		set_ajax_obs("ajaxhighbarometertime",highbarometertime) ;
		
		//LOW AND TIME BAROMETER
		var lowbarometer = convertBaro(wflash2[108]);
		set_ajax_obs("ajaxlowbarometer",lowbarometer+ajaxUOM(uomBaro));
		lowbarometertime = wflash2[136];
		set_ajax_obs("ajaxlowbarometertime",lowbarometertime) ;
		
		//AVERAGE BAROMETER
		var avgbarometer = convertBaro(wflash2[24]);
		set_ajax_obs("ajaxavgbarometer",avgbarometer+ajaxUOM(uomBaro));
		
		//High Rate AND TIME BAROMETER
		var highratebarometer = convertBaro(wflash2[164]);
		set_ajax_obs("ajaxhighratebarometer",highratebarometer+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
		highratebarometertime = wflash2[192];
		set_ajax_obs("ajaxhighratebarometertime",highratebarometertime) ;
		
		//Low Rate AND TIME BAROMETER
		var lowratebarometer = convertBaro(wflash2[220]);
		set_ajax_obs("ajaxlowratebarometer",lowratebarometer+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
		lowratebarometertime = wflash2[248];
		set_ajax_obs("ajaxlowratebarometertime",lowratebarometertime) ;
		//END BAROMETER DATA


		//BEGIN RAW BAROMETER DATA
		//High AND TIME BAROMETER
		var highrawbaro = convertBaro(wflash2[37]);
		set_ajax_obs("ajaxhighrawbaro",highrawbaro+ajaxUOM(uomBaro));
		highrawbarotime = wflash2[65];
		set_ajax_obs("ajaxhighrawbarotime",highrawbarotime) ;
		
		//LOW AND TIME BAROMETER
		var lowrawbaro = convertBaro(wflash2[93]);
		set_ajax_obs("ajaxlowrawbaro",lowrawbaro+ajaxUOM(uomBaro));
		lowrawbarotime = wflash2[121];
		set_ajax_obs("ajaxlowrawbarotime",lowrawbarotime) ;
		
		//AVERAGE BAROMETER
		var avgrawbaro = convertBaro(wflash2[9]);
		avgrawbaro = avgrawbaro * 1.0;
		set_ajax_obs("ajaxavgrawbaro",avgrawbaro+ajaxUOM(uomBaro));
		
		//High Rate AND TIME BAROMETER
		var highraterawbaro = convertBaro(wflash2[149]);
		set_ajax_obs("ajaxhighraterawbaro",highraterawbaro+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
		highraterawbarotime = wflash2[177];
		set_ajax_obs("ajaxhighraterawbarotime",highraterawbarotime) ;
		
		//Low Rate AND TIME BAROMETER
		var lowraterawbaro = convertBaro(wflash2[205]);
		set_ajax_obs("ajaxlowraterawbaro",lowraterawbaro+ajaxUOM(uomBaro)+ajaxUOM(uomPerHr));
		lowraterawbarotime = wflash2[233];
		set_ajax_obs("ajaxlowraterawbarotime",lowraterawbarotime) ;
		//END RAW BAROMETER DATA
		
		
		//BEGIN HEAT INDEX DATA
		//High AND TIME HEAT INDEX
		var highheatidx = convertTemp(wflash2[50]);
		set_ajax_obs("ajaxhighheatidx",highheatidx+ajaxUOM(uomTemp));
		highheatidxtime = wflash2[78];
		set_ajax_obs("ajaxhighheatidxtime",highheatidxtime) ;
		
		//LOW AND TIME HEAT INDEX
		var lowheatidx = convertTemp(wflash2[106]);
		set_ajax_obs("ajaxlowheatidx",lowheatidx+ajaxUOM(uomTemp));
		lowheatidxtime = wflash2[134];
		set_ajax_obs("ajaxlowheatidxtime",lowheatidxtime) ;
		
		//AVERAGE HEAT INDEX
		var avgheatidx = convertTemp(wflash2[22]);
		set_ajax_obs("ajaxavgheatidx",avgheatidx+ajaxUOM(uomTemp));
		
		//High Rate AND TIME HEAT INDEX
		var highrateheatidx = convertTempRate(wflash2[162]);
		set_ajax_obs("ajaxhighrateheatidx",highrateheatidx+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		highrateheatidxtime = wflash2[190];
		set_ajax_obs("ajaxhighrateheatidxtime",highrateheatidxtime) ;
		
		//Low Rate AND TIME HEAT INDEX
		var lowrateheatidx = convertTempRate(wflash2[218]);
		set_ajax_obs("ajaxlowrateheatidx",lowrateheatidx+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		lowrateheatidxtime = wflash2[246];
		set_ajax_obs("ajaxlowrateheatidxtime",lowrateheatidxtime) ;
		//END HEAT INDEX DATA
		
		
		
		//BEGIN WIND CHILL DATA
		//High AND TIME WIND CHILL
		var highwindchill = convertTemp(wflash2[48]);
		set_ajax_obs("ajaxhighwindchill",highwindchill+ajaxUOM(uomTemp));
		highwindchilltime = wflash2[76];
		set_ajax_obs("ajaxhighwindchilltime",highwindchilltime) ;
		
		//LOW AND TIME WIND CHILL
		var lowwindchill = convertTemp(wflash2[104]);
		set_ajax_obs("ajaxlowwindchill",lowwindchill+ajaxUOM(uomTemp));
		lowwindchilltime = wflash2[132];
		set_ajax_obs("ajaxlowwindchilltime",lowwindchilltime) ;
		
		//AVERAGE WIND CHILL
		var avgwindchill = convertTemp(wflash2[20]);
		set_ajax_obs("ajaxavgwindchill",avgwindchill+ajaxUOM(uomTemp));
		
		//High Rate AND TIME WIND CHILL
		var highratewindchill = convertTempRate(wflash2[160]);
		set_ajax_obs("ajaxhighratewindchill",highratewindchill+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		highratewindchilltime = wflash2[188];
		set_ajax_obs("ajaxhighratewindchilltime",highratewindchilltime) ;
		
		//Low Rate AND TIME WIND CHILL
		var lowratewindchill = convertTempRate(wflash2[216]);
		set_ajax_obs("ajaxlowratewindchill",lowratewindchill+ajaxUOM(uomTemp)+ajaxUOM(uomPerHr));
		lowratewindchilltime = wflash2[244];
		set_ajax_obs("ajaxlowratewindchilltime",lowratewindchilltime) ;
		//END WIND CHILL DATA
		
		//BEGIN UV DATA
		//High AND TIME UV
		var highuv = wflash2[46];
		highuv = highuv * 1.0;
		set_ajax_obs("ajaxhighuv",highuv.toFixed(1));
		highuvtime = wflash2[74];
		set_ajax_obs("ajaxhighuvtime",highuvtime) ;
		
		//LOW AND TIME UV
		var lowuv = wflash2[102];
		lowuv = lowuv * 1.0;
		set_ajax_obs("ajaxlowuv",lowuv.toFixed(1));
		lowuvtime = wflash2[130];
		set_ajax_obs("ajaxlowuvtime",lowuvtime) ;
		
		//AVERAGE UV
		var avguv = wflash2[18];
		avguv = avguv * 1.0;
		set_ajax_obs("ajaxavguv",avguv.toFixed(1));
		
		//High Rate AND TIME UV
		var highrateuv = wflash2[158];
		highrateuv = highrateuv * 1.0;
		set_ajax_obs("ajaxhighrateuv",highrateuv.toFixed(1)+ajaxUOM(uomPerHr));
		highrateuvtime = wflash2[186];
		set_ajax_obs("ajaxhighrateuvtime",highrateuvtime) ;
		
		//Low Rate AND TIME UV
		var lowrateuv = wflash2[214];
		lowrateuv = lowrateuv * 1.0;
		set_ajax_obs("ajaxlowrateuv",lowrateuv.toFixed(1)+ajaxUOM(uomPerHr));
		lowrateuvtime = wflash2[242];
		set_ajax_obs("ajaxlowrateuvtime",lowrateuvtime) ;
		//END UV DATA
		
		
		//BEGIN SOLAR DATA
		//High AND TIME SOLAR
		var highsolar = wflash2[47];
		highsolar = highsolar * 1.0;
		set_ajax_obs("ajaxhighsolar",highsolar.toFixed(0)+ajaxUOM(uomSolar));
		highsolartime = wflash2[75];
		set_ajax_obs("ajaxhighsolartime",highsolartime) ;
		
		//LOW AND TIME SOLAR
		var lowsolar = wflash2[103];
		lowsolar = lowsolar * 1.0;
		set_ajax_obs("ajaxlowsolar",lowsolar.toFixed(0)+ajaxUOM(uomSolar));
		lowsolartime = wflash2[131];
		set_ajax_obs("ajaxlowsolartime",lowsolartime) ;
		
		//AVERAGE SOLAR
		var avgsolar = wflash2[19];
		avgsolar = avgsolar * 1.0;
		set_ajax_obs("ajaxavgsolar",avgsolar.toFixed(0)+ajaxUOM(uomSolar));
		
		//High Rate AND TIME SOLAR
		var highratesolar = wflash2[159];
		highratesolar = highratesolar * 1.0;
		set_ajax_obs("ajaxhighratesolar",highratesolar.toFixed(0)+ajaxUOM(uomSolar)+ajaxUOM(uomPerHr));
		highratesolartime = wflash2[187];
		set_ajax_obs("ajaxhighratesolartime",highratesolartime) ;
		
		//Low Rate AND TIME SOLAR
		var lowratesolar = wflash2[215];
		lowratesolar = lowratesolar * 1.0;
		set_ajax_obs("ajaxlowratesolar",lowratesolar.toFixed(0)+ajaxUOM(uomSolar)+ajaxUOM(uomPerHr));
		lowratesolartime = wflash2[243];
		set_ajax_obs("ajaxlowratesolartime",lowratesolartime) ;
		//END SOLAR DATA
		
		
		//BEGIN EVAPOTRANSPIRATION DATA
		//High AND TIME EVAPOTRANSPIRATION
		var highet = convertRain(wflash2[45]);
		set_ajax_obs("ajaxhighet",highet+ajaxUOM(uomRain));
		highettime = wflash2[73];
		set_ajax_obs("ajaxhighettime",highettime) ;
		
		//LOW AND TIME EVAPOTRANSPIRATION
		var lowet = convertRain(wflash2[101]);
		set_ajax_obs("ajaxlowet",lowet+ajaxUOM(uomRain));
		lowettime = wflash2[129];
		set_ajax_obs("ajaxlowettime",lowettime) ;
		
		//AVERAGE EVAPOTRANSPIRATION
		var avget = convertRain(wflash2[17]);
		set_ajax_obs("ajaxavget",avget+ajaxUOM(uomRain));
		
		//High Rate AND TIME EVAPOTRANSPIRATION
		var highrateet = convertRain(wflash2[157]);
		set_ajax_obs("ajaxhighrateet",highrateet+ajaxUOM(uomRain)+ajaxUOM(uomPerHr));
		highrateettime = wflash2[185];
		set_ajax_obs("ajaxhighrateettime",highrateettime) ;
		
		//Low Rate AND TIME EVAPOTRANSPIRATION
		var lowrateet = convertRain(wflash2[213]);
		set_ajax_obs("ajaxlowrateet",lowrateet+ajaxUOM(uomRain)+ajaxUOM(uomPerHr));
		lowrateettime = wflash2[241];
		set_ajax_obs("ajaxlowrateettime",lowrateettime) ;
		//END EVAPOTRANSPIRATION DATA
		
		
		//BEGIN MISC DATA
		//DAILY WIND RUN
		dailywindrun = convertDistance(wflash2[258]);
		set_ajax_obs("ajaxdailywindrun",dailywindrun+ajaxUOM(uomDistance));
		
		//MONTHLY WIND RUN
		monthlywindrun = convertDistance(wflash2[265]);
		set_ajax_obs("ajaxmonthlywindrun",monthlywindrun+ajaxUOM(uomDistance));
		
		//YEARLY WIND RUN
		yearlywindrun = convertDistance(wflash2[268]);
		set_ajax_obs("ajaxyearlywindrun",yearlywindrun+ajaxUOM(uomDistance));
		
		//HEAT STRESS
		heatstress = wflash2[269];
		heatstress = heatstress.replace(/\+/g," ");
		set_ajax_obs("ajaxheatstress",heatstress);
		
		//COMFORT LEVEL
		comfortlevel = wflash2[270];
		comfortlevel = comfortlevel.replace(/\+/g," ");
		set_ajax_obs("ajaxcomfortlevel",comfortlevel);
		
		//RAW BAROMETER TREND
		rawbarotrend = wflash2[272];
		rawbarotrend = rawbarotrend.replace(/\+/g," ");
		set_ajax_obs("ajaxrawbarotrend",rawbarotrend);
		
		//SEA LEVEL PRESSURE TREND
		pressuretrend = wflash2[273];
		pressuretrend = pressuretrend.replace(/\+/g," ");
		set_ajax_obs("ajaxbarotrend",pressuretrend);
		
		//DAILY DEGREE DAY COOLING
		degreedaycool = wflash2[260];
		degreedaycool = degreedaycool * 1.0;
		set_ajax_obs("ajaxdegreedaycool",degreedaycool.toFixed(1));
		
		//DAILY DEGREE DAY HEATING
		degreedayheat = wflash2[259];
		degreedayheat = degreedayheat * 1.0;
		set_ajax_obs("ajaxdegreedayheat",degreedayheat.toFixed(1));
		
		//MONTHLY DEGREE DAY COOLING
		degreemonthcool = wflash2[264];
		degreemonthcool = degreemonthcool * 1.0;
		set_ajax_obs("ajaxdegreemonthcool",degreemonthcool.toFixed(1));
		
		//MONTHLY DEGREE DAY HEATING
		degreemonthheat = wflash2[263];
		degreemonthheat = degreemonthheat * 1.0;
		set_ajax_obs("ajaxdegreemonthheat",degreemonthheat.toFixed(1));
		
		//YEARLY DEGREE DAY COOLING
		degreeyearcool = wflash2[267];
		degreeyearcool = degreeyearcool * 1.0;
		set_ajax_obs("ajaxdegreeyearcool",degreeyearcool.toFixed(1));
		
		//YEARLY DEGREE DAY HEATING
		degreeyearheat = wflash2[266];
		degreeyearheat = degreeyearheat * 1.0;
		set_ajax_obs("ajaxdegreeyearheat",degreeyearheat.toFixed(1));
		
		beaufort = wflash2[274];
		beaufort = beaufort.replace(/\+/g," ");
		set_ajax_obs("ajaxbeaufort",beaufort);
		
		forecast = wflash2[271];
		forecast = forecast.replace(/\+/g," ");
		set_ajax_obs("ajaxforecast",forecast);
		
		set_ajax_obs("ajaxsunrise",wflash2[277]);
		set_ajax_obs("ajaxsunset",wflash2[278]);
		set_ajax_obs("ajaxmoonrise",wflash2[279]);
		set_ajax_obs("ajaxmoonset",wflash2[280]);
		
		//END MISC DATA
		
		//BEGIN RAIN DATA
		//DAILY RAIN
		var rain = convertRain(wflash2[254]);
		set_ajax_obs("ajaxrain",rain+ajaxUOM(uomRain));
		
		//24 HOURS RAIN
		var rain24 = convertRain(wflash2[256]);
		set_ajax_obs("ajaxrain24",rain24+ajaxUOM(uomRain));
		
		//HOURLY RAIN
		var rainhr = convertRain(wflash2[255]);
		set_ajax_obs("ajaxrainhr",rainhr+ajaxUOM(uomRain));
		
		//MONTHLY RAIN
		var rainmo = convertRain(wflash2[262]);
		set_ajax_obs("ajaxrainmo",rainmo+ajaxUOM(uomRain));
		
		//RAIN RATE
		var rainrate = convertRain(wflash2[257]);
		set_ajax_obs("ajaxrainratehr",rainrate+ajaxUOM(uomRain)+ajaxUOM(uomPerHr));
		//END RAIN DATA
		  
		//UPDATED DATE
		var ajaxdate = wflash2[275];
		set_ajax_obs("ajaxdate",ajaxdate);
	
////                                                                                                           .................
        timesunrise = wflash2[277]; //sunset time
        timesunset = wflash2[278]; //sunrise time
        timesunrise = timesunrise.replace(/\am/g," ");
        timesunset = timesunset.replace(/\pm/g," ");
        timesunrise=timesunrise.split(":");
        timesunset=timesunset.split(":");

        risemin = timesunrise[0]*60;    //  converts sunrise clock time to minutes
        risemins = timesunrise[1];
        var actualrisemins = Math.ceil(risemin/1)+(risemins/1);

        setmin = Math.ceil((timesunset[0]/1)+12)*60;    //  converts sunset clock time to minutes
        setmins = timesunset[1];
        var actualsetmins = Math.ceil(setmin/1)+(setmins/1);

        var middaytime = Math.ceil((actualsetmins/1)+(actualrisemins/1))/2;

        dawnstart = (actualrisemins - 24);
        duskend = (actualsetmins + 24);
        astrostart = (actualrisemins - 72);
        astroend = (actualsetmins + 72);

        timenow = wflash2[0].replace(/\I=&S=/g," ");
        timenow = timenow.split(":");
        nowtime = Math.ceil(((timenow[0]/1)*60)+(timenow[1]/1));
  
        if (nowtime*1 > astroend*1) {	
		     set_ajax_obs("ajaxastro", 'NIGHT TIME');
            }
          else if (nowtime*1 == astroend*1) {	
		     set_ajax_obs("ajaxastro", 'ASTRONOMICAL DUSK');
            }
          else if (nowtime*1 > duskend*1) {	
		     set_ajax_obs("ajaxastro", 'ASTRONOMICAL DUSK');
            }
          else if (nowtime*1 == duskend*1) {	
		     set_ajax_obs("ajaxastro", 'CIVIL DUSK');
            }
          else if (nowtime*1 > actualsetmins*1) {	
		     set_ajax_obs("ajaxastro", 'CIVIL DUSK');
            }
          else if (nowtime*1 == actualsetmins*1) {	
		     set_ajax_obs("ajaxastro", '- SUNSET ! -');
            }
          else if (nowtime*1 > middaytime*1) {	
		     set_ajax_obs("ajaxastro", 'CIVIL TWILIGHT');
            }
          else if (nowtime*1 == middaytime*1) {	
		     set_ajax_obs("ajaxastro", 'MID-DAY');
            }
          else if (nowtime*1 > actualrisemins*1) {	
		     set_ajax_obs("ajaxastro", 'CIVIL TWILIGHT');
            }
          else if (nowtime*1 == actualrisemins*1) {	
		     set_ajax_obs("ajaxastro", '- SUNRISE ! -');
            }
          else if (nowtime*1 >= dawnstart*1) {	
		     set_ajax_obs("ajaxastro", 'CIVIL DAWN');
            }
          else if (nowtime*1 >= astrostart*1) {	
		     set_ajax_obs("ajaxastro", 'ASTRONOMICAL DAWN');
            }
          else if (nowtime*1 < astrostart*1) {	
		     set_ajax_obs("ajaxastro", 'NIGHT TIME');
            }

////                                                                                                           .................
		// now ensure that the indicator flashes on every AJAX fetch
        element = document.getElementById("ajaxindicator");
		if (element) {
          element.style.color = flashcolor;

		}

 	  } // END if(wflash[0] = '12345' and '!!' at end)

	 } // END if (x.readyState == 4 && x.status == 200)

    } // END try

   	catch(e){}  // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE

    } // END x.onreadystatechange = function() {
    x.open("GET", url, true);
    x.send(null);

    setTimeout("ajaxLoaderVWSf2(wflashFile2 + '?' + new Date().getTime())", reloadTime); // get new data after 5 secs
  }
} // end ajaxLoaderVWSf2 function
// ------------------------------------------------------------------------------------------
//  function.. read data.txt and and decode values .. run once
// ------------------------------------------------------------------------------------------
function ajaxGetDataTxt(url) {
// read the data.txt file and set up all-time records
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);
   
  }
  if (x) { // got something back
    x.onreadystatechange = function() {
    try { if (x.readyState == 4 && x.status == 200) { // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE
      var data = x.responseText.split(','); // assuming comma-delimited format
// record highs and lows
		
        set_ajax_obs("ajaxdatenow",data[2]); 
        set_ajax_obs("ajaxrechi",data[16]+ajaxUOM(uomTemp)); 
        set_ajax_obs("ajaxreclo",data[17]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxtodhi",data[18]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxtodlo",data[19]+ajaxUOM(uomTemp));

// mesonet data
        set_ajax_obs("ajaxmestemp1",data[20]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmestemp2",data[21]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmestemp3",data[22]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmestemp4",data[23]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmestemp5",data[24]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmestemp6",data[25]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmestemp7",data[26]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmestemp8",data[27]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmestemp9",data[28]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmesneig1",data[29]);
        set_ajax_obs("ajaxmesneig2",data[30]);
        set_ajax_obs("ajaxmesneig3",data[31]);
        set_ajax_obs("ajaxmesneig4",data[32]);
        set_ajax_obs("ajaxmesneig5",data[33]);
        set_ajax_obs("ajaxmesneig6",data[34]);
        set_ajax_obs("ajaxmesneig7",data[35]);
        set_ajax_obs("ajaxmesneig8",data[36]);
        set_ajax_obs("ajaxmesneig9",data[37]);
        set_ajax_obs("ajaxmesloc1",data[38]);
        set_ajax_obs("ajaxmesloc2",data[39]);
        set_ajax_obs("ajaxmesloc3",data[40]);
        set_ajax_obs("ajaxmesloc4",data[41]);
        set_ajax_obs("ajaxmesloc5",data[42]);
        set_ajax_obs("ajaxmesloc6",data[43]);
        set_ajax_obs("ajaxmesloc7",data[44]);
        set_ajax_obs("ajaxmesloc8",data[45]);
        set_ajax_obs("ajaxmesloc9",data[46]);
//     end of mesonet

//     begin of highs and lows
        set_ajax_obs("ajaxwindmohi",data[47]+ajaxUOM(uomWind));
        set_ajax_obs("ajaxwindyrhi",data[48]+ajaxUOM(uomWind));
        set_ajax_obs("ajaxnormtemphi",data[49]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxnormtemplo",data[50]+ajaxUOM(uomTemp));        
        set_ajax_obs("ajaxwindmodate",data[51]);
        set_ajax_obs("ajaxwindyrdate",data[52]);
        set_ajax_obs("ajaxrectemphidate",data[53]);
        set_ajax_obs("ajaxrectemplodate",data[54]);
        set_ajax_obs("ajaxmonthhidate",data[59]+ajaxUOM(uomTemp));
        set_ajax_obs("ajaxmonthlodate",data[61]);
        set_ajax_obs("ajaxtempyrhi",data[71]);
        set_ajax_obs("ajaxtempyrhidate",data[72]);
        set_ajax_obs("ajaxtempyrlo",data[73]);
        set_ajax_obs("ajaxtempyrlodate",data[74]);
        set_ajax_obs("ajaxwindyrhi",data[75]);
        set_ajax_obs("ajaxwindyrhidate",data[76]);
        set_ajax_obs("ajaxuvyrhi",data[77]);
        set_ajax_obs("ajaxuvyrhidate",data[78]);
        set_ajax_obs("ajaxsolaryrhi",data[79]);
        set_ajax_obs("ajaxsolaryrhidate",data[80]);
        set_ajax_obs("ajaxchillyrlo",data[81]);
        set_ajax_obs("ajaxchillyrlodate",data[82]);
        set_ajax_obs("ajaxhixyrhi",data[83]);
        set_ajax_obs("ajaxhixyrhidate",data[84]);
        set_ajax_obs("ajaxdewyrhi",data[85]);
        set_ajax_obs("ajaxdewyrhidate",data[86]);
        set_ajax_obs("ajaxbaroyrhi",data[87]);
        set_ajax_obs("ajaxbaroyrhidate",data[88]);
        set_ajax_obs("ajaxbaroyrlo",data[89]);
        set_ajax_obs("ajaxbaroyrlodate",data[90]);

//      misc data

        var monthhigh = data[58];
        monthhigh = monthhigh.split(".");
        monthhi = monthhigh[0];
        set_ajax_obs("ajaxmonthhi",monthhi);

        var monthlow = data[60];
        monthlow = monthlow.split(".");
        monthlo = monthlow[0];
        set_ajax_obs("ajaxmonthlo",monthlo);

//     rain data
        set_ajax_obs("ajaxraining",data[55]);
        set_ajax_obs("ajaxlastraindate",data[56]);
        set_ajax_obs("ajaxworldid",data[57]);

//   shows record high temp if it occurs
  if (data[16] <= data[18]) { 
			set_ajax_obs("ajaxhirecset",'RECORD HIGH TEMPERATURE TODAY WAS ');
			
		} else {
			set_ajax_obs("ajaxhirecset",'');
			}

//   shows record low temp if it occurs    
  if (data[19] <= data[17]) {   // if todays lowrecord is >  todays low
			set_ajax_obs("ajaxlorecset",'RECORD LOW TEMPERATURE TODAY WAS ');

		} else if (data[19] >= data[17]) {
			set_ajax_obs("ajaxlorecset",'');
			}

//   strips off the decimal point for todays HIGH and LOW temp
        var hitoday = data[18];
        var rechi = data[16];
        hitoday = hitoday * 1;
        rechi = rechi * 1;
        set_ajax_obs("ajaxhitoday", hitoday.toFixed(0)); 

        var lotoday = data[19];
        var reclow = data[17];
        lotoday = lotoday * 1;
        reclow = reclow * 1;
        set_ajax_obs("ajaxlotoday", lotoday.toFixed(0)); 

//   show TIED or BROKEN BY

  if (data[16] <= data[18]) { 
			set_ajax_obs("ajaxhirecsetby", Math.ceil((hitoday-rechi)-1) + ' degrees');
		} else {
			set_ajax_obs("ajaxhirecsetby", '');
			}

  if (data[19] <= data[17]) { 
			set_ajax_obs("ajaxlorecsetby", Math.ceil((reclow-lotoday)-1) + ' degrees');

		} else if (data[19] >= data[17]) {
			set_ajax_obs("ajaxlorecsetby",'');
			}

// shows TIED or Degrees if  record low temp was set USE "ajaxrecolonow"
        var lowtodays = data[19];
        var recolow = data[17];
        lowtodays = lowtodays.split(".");
        recolow = recolow * 1;
        lowtoday =  lowtodays[0] * 1;
		
		
  		if ((recolow - lowtoday) == 0) {
            set_ajax_obs("ajaxrecorlonow", 'RECORD: The record low temperature for today was tied !');

   		}	else if ((recolow - lowtoday) == 1) {
            set_ajax_obs("ajaxrecorlonow",'RECORD: The record low temperature for today was broken by 1 degree !');

   		}	else if ((recolow - lowtoday) >= 2) {
            set_ajax_obs("ajaxrecorlonow", 'RECORD: The record low temperature for today was broken by ' + Math.ceil(recolow-lowtoday) + ' degrees !');

   		}	else if ((recolow - lowtoday) <= 0) {
            set_ajax_obs("ajaxrecorlonow", '');

   		}
//  ////////////     ///    shows JUST MISSED the record  lo
        var lowestoday = data[19];
        var recolowes = data[17];
        lowestoday = lowestoday.split("."); 
        lowesttoday = lowestoday[0];
 		
  		if ((lowesttoday - recolow) >= 6) {
            set_ajax_obs("ajaxmisslo", '');

   		}	else if ((lowesttoday - recolow) == 5) {
            set_ajax_obs("ajaxmisslo",'Todays low temperature is 5 degrees away from the record low !');

   		}	else if ((lowesttoday - recolow) == 4) {
            set_ajax_obs("ajaxmisslo",'Todays low temperature is 4 degrees away from the record low !');

   		}	else if ((lowesttoday - recolow) == 3) {
            set_ajax_obs("ajaxmisslo",'Todays low temperature is 3 degrees away from the record low !');

   		}	else if ((lowesttoday - recolow) == 2) {
            set_ajax_obs("ajaxmisslo",'Todays low temperature is 2 degrees away from the record low !');

   		}	else if ((lowesttoday - recolow) == 1) {
            set_ajax_obs("ajaxmisslo",'Todays low temperature is 1 degree away from the record low !');
 
   		}	else if ((lowesttoday - lowtoday) <= 0) {
            set_ajax_obs("ajaxmisslo", '');

   		}

// shows TIED or Degrees if  record high temp was set USE "ajaxrecorhinow"
        var hightoday = data[18];
        var recohigh = data[16];
        hightoday = hightoday * 1;
        recohigh = recohigh * 1;
        hightoday =  hightoday.toFixed(0);
		
  		if ((hightoday - recohigh) == 0) {
            set_ajax_obs("ajaxrecorhinow", 'RECORD: The record high temperature for today was tied !');

   		}	else if ((hightoday - recohigh) == 1) {
            set_ajax_obs("ajaxrecorhinow",'RECORD: The record high temperature for today was broken by 1 degree !');

   		}	else if ((hightoday - recohigh) >= 2) {
            set_ajax_obs("ajaxrecorhinow", 'RECORD: The record high temperature for today was broken by ' + Math.ceil(hightoday - recohigh) + ' degrees !');

   		}	else if ((hightoday - recohigh) <= 0) {
            set_ajax_obs("ajaxrecorhinow", '');

   		}
//         shows JUST MISSED the record high

        var hightodays = data[18];
        var recohighs = data[16];
        hightodays = hightodays.split(".");
        recorhigh = recohighs * 1;
        highrtoday =  hightodays[0] * 1;

  		if ((recorhigh - highrtoday) >= 6) {
            set_ajax_obs("ajaxmisshi", '');

   		}	else if ((recorhigh - highrtoday) == 5) {
            set_ajax_obs("ajaxmisshi",'Todays high temperature is 5 degrees away from the record high !');

   		}	else if ((recorhigh - highrtoday) == 4) {
            set_ajax_obs("ajaxmisshi",'Todays high temperature is 4 degrees away from the record high !');

   		}	else if ((recorhigh - highrtoday) == 3) {
            set_ajax_obs("ajaxmisshi",'Todays high temperature is 3 degrees away from the record high !');

   		}	else if ((recorhigh - highrtoday) == 2) {
            set_ajax_obs("ajaxmisshi",'Todays high temperature is 2 degrees away from the record high !');

   		}	else if ((recorhigh - highrtoday) == 1) {
            set_ajax_obs("ajaxmisshi",'Todays high temperature is 1 degree away from the record high !');
 
   		}	else if ((recorhigh - highrtoday) <= 0) {
            set_ajax_obs("ajaxmisshi", '');

   		}

        var metarsky = data[62];
        var metarweather = data[63];

      if (metarsky == '') {
            metarsky = metarweather;
        }  
//   shows Raining if rain rate exists

      if (data[55] >= 1.30) {
            set_ajax_obs("ajaxrainnow",'INTENSE THUNDERSTORM now occurring');

        } else if (data[55] >= 0.70) {
            set_ajax_obs("ajaxrainnow",'THUNDERSTORM now occurring');
        } else if (data[55] >= 0.30) {
            set_ajax_obs("ajaxrainnow",'HEAVY RAIN');
        } else if (data[55] >= 0.11) {
            set_ajax_obs("ajaxrainnow",'Moderate rain');
        } else if (data[55] >= 0.02) {
            set_ajax_obs("ajaxrainnow",'Light rain');
        } else if (data[55] == 0.01) {
            set_ajax_obs("ajaxrainnow",'Drizzle or snowfall');
        }  else if (data[55] == 0.00) {
            set_ajax_obs("ajaxrainnow",metarsky);
        }

//   HOW MANY DAYS SINCE THE LAST RAIN         //////////////////////////////////////

   var lrd=data[56].split("/");
   var tyd=data[1].split("/");

// Date of LAST RAIN
   MM=lrd[0]*1
   DD=lrd[1]*1
   YY=(lrd[2]*1)+2000*1
   HR=4
   MN=22
with (Math) {
   HR = HR + (MN / 60);
   GGG = 1;
   if (YY <= 1585) GGG = 0;
JD = -1 * floor(7 * (floor((MM + 9) / 12) + YY) / 4);
   S = 1;
   if ((MM - 9)<0) S=-1;
A = abs(MM - 9);
   J1 = floor(YY + S * floor(A / 7));
   J1 = -1 * floor((floor(J1 / 100) + 1) * 3 / 4);
   JD = JD + floor(275 * MM / 9) + DD + (GGG * J1);
   JD = JD + 1721027 + 2 * GGG + 367 * YY - 0.5;
   JD = JD + (HR / 24);

   stringJD = "" + JD + "00000";
   dotIndex = stringJD.indexOf(".");
   stringJD = stringJD.substring(0, dotIndex+0);
}

   MMa=tyd[0]*1
   DDa=tyd[1]*1
   YYa=(tyd[2]*1)+2000*1
   HRa=4
   MNa=22
with (Math) {
   HRa = HRa + (MNa / 60);
   GGGa = 1;
   if (YYa <= 1585) GGGa = 0;
JDa = -1 * floor(7 * (floor((MMa + 9) / 12) + YYa) / 4);
   Sa = 1;
   if ((MMa - 9)<0) Sa=-1;
Aa = abs(MMa - 9);
   J1a = floor(YYa + Sa * floor(Aa / 7));
   J1a = -1 * floor((floor(J1a / 100) + 1) * 3 / 4);
   JDa = JDa + floor(275 * MMa / 9) + DDa + (GGGa * J1a);
   JDa = JDa + 1721027 + 2 * GGGa + 367 * YYa - 0.5;
   JDa = JDa + (HRa / 24);

   stringJDa = "" + JDa + "00000";
   dotIndex = stringJDa.indexOf(".");
   stringJDa = stringJDa.substring(0, dotIndex+0);
}

        if ((stringJDa*1 - stringJD*1) >= 2) {
            set_ajax_obs("ajaxlastdayrain", Math.ceil(stringJDa*1 - stringJD*1) + ' days ago');
   		   }  
	    else if ((stringJDa*1 - stringJD*1) == 1) {
            set_ajax_obs("ajaxlastdayrain", 'Yesterday');
   		   }	
  		else if ((stringJDa*1 - stringJD*1) == 0) {
            set_ajax_obs("ajaxlastdayrain", 'Today');
           }   
////////////////////////////////////////////////////////////////////////////////////////////////////

// --- end of processing data[n] values
      x.abort();

//      } // END if(wunits[0]

    } 

    } 


      catch(e){ }  // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE

    } // END x.onreadystatechange = function() {
    x.open("GET", url, true);
    x.send(null);

    setTimeout("ajaxGetDataTxt(wflashDataTxt + '?' + new Date().getTime())", reloadTime); // get new data after 5 secs

  }
 
} // end ajaxGetDataTxt function
// ---------------------------------------------------------------------------------------------
//


// ---------------------------------------------------------------------------------------------
// the following runs once when this script is loaded by the browser.
//

// Start the countup timer
window.setInterval("ajax_countup()", 1000); // run the counter for seconds since update

// Start the pair of AJAX loaders .. they'll reinvoke themselves
ajaxLoaderVWSf(wflashFile + '?' + new Date().getTime()); 
ajaxLoaderVWSf2(wflashFile2 + '?' + new Date().getTime()); 
ajaxGetDataTxt(wflashDataTxt + '?' + new Date().getTime());


// ---------------- end of ajaxVWSwxf.js --------------------------------
// ]]>