// <![CDATA[

// Special thanks to: Kevin Reed http://www.tnetweather.com/
// Kevin was the first to decode the clientraw in PHP
// Special thanks to: Pinto http://www.joske-online.be/
// Pinto wrote the basic AJAX code for this page!
// Cheerfully borrowed from Tom at CarterLake.org and adapted by
// Ken True - Saratoga-weather.org  21-May-2006
// --- added flash-green on data update functions - Ken True  24-Nov-2006
//
// --- Version 2.00 - 13-Dec-2006 -- Ken True -repackaged AJAX function, added metric/english units
//     also included Mike Challis' counter script to display seconds since last update and error
//     handling for the fetch to fix to fix random error: NS_ERROR_NOT_AVAILABLE
//     Mike's site: http://www.carmosaic.com/weather/index.php
//     Thanks to FourOhFour on wxforum.net ( http://skigod.us/ ) for replacing all the
//     x.responseText.split(' ')[n] calls with a simple array lookup.. much better speed and
//     for his streamlined version of getUVrange.
// --- Version 2.01 - 17-Dec-2006 -- Corrected cloud height calculation
// --- Version 2.02 - 20-Dec-2006 -- added unescape to set_ajax_obs comparison for lastobs
// --- Version 2.03 - 07-Jan-2006 -- added wind m/s or km/h for metric variables
// --- Version 2.04 - 08-Jan-2006 -- use epoch time for get (thanks to johnnywx on WD forum)
//                                   so a numeric time without HTMLencoded characters is used
// --- Version 2.05a - 30-Jan-2006 -- added new 'anti-NaN' check from johnnywx to make sure full
//                                   clientraw.txt is read by looking for
//                                   '12345' at start and '!!' at end of record
// --- Version 2.06 - 24-Jun-2007 -- added '/' as delimiter for currentcond
// --- Version 2.07 - 21-Sep-2007 -- added support for dynamic thermometer.php display refresh
//
// for updates to this script, see http://saratoga-weather.org/scripts-WD-AJAX.php
// announcements of new versions will be on weather-watch.com and wxforum.net

// -- begin settings --------------------------------------------------------------------------
var flashcolor = '#00CC00'; // color to flash for changed observations RGB
var flashtime  = 2000;    // miliseconds to keep flash color on (2000 = 2 seconds);
var reloadTime3 = 5000;
var customrawFile = 'http://www.meteofan.eu/alex_custom.txt'; // location of 
var ajaxLoadercustomInBody = false; // set to true if you have <body onload="ajaxLoader(..."
var useunits = 'M';         // 'E'=USA(English) or 'M'=Metric
var useKnots = true;       // 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 = true;       //  set to false if no units are to be displayed

// -- end of settings -------------------------------------------------------------------------

// --- 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 counterSecs = 0;  // for MCHALLIS counter script from weather-watch.com (adapted by K. True)
var lastajaxtimeformat = 'unknown'; //used to reset the counter when a real update is done

// handle setup options for units-of-measure and whether to show them at all
var uomTemp = '&deg;F';
var uomWind = ' mph';
var uomBaro = ' inHg';
var uomRain = ' in';
var uomHeight = ' ft';
var dpBaro = 2;
var dpRain = 2;

var beaufortphp = 'http://www.meteofan.eu/jpgraph/src/Examples/Beaufort_realtime.php';


// strips off illegal chars &%$
String.prototype.stripOffIllegalChars = function() {
 return this.replace(/[^-+. 0-9]+/g,'');
}



function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function ajax_set_units( units ) {
  useunits = units;
  if (useunits != 'E') { // set to metric
	uomTemp = ' &deg;C';
	uomWind = ' km/h';
	if(useMPS)   { uomWind = ' m/s'; }
	uomBaro = ' hPa';
	uomRain = ' mm';
	uomHeight = ' m';
	dpBaro = 1;
	dpRain = 1;
  }
  if(useKnots) { uomWind = ' kts'; }
  if (! showUnits) {
	uomTemp = '';
	uomWind = '';
	uomBaro = '';
	uomRain = '';
	uomHeight = '';
  }
}

ajax_set_units(useunits);

// 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") {
    var elem = document.body.getElementsByTagName('span');
	var lookfor = 'className';
  } else {
    var elem = document.getElementsByTagName('span');
	var lookfor = 'class';
  }
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          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)
// Take wind direction value, return the
// text label based upon 16 point compass -- function by beeker425
//  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_wxIcon ( iconWD ) { 
// perform a lookup and return the graphic for the condition icon (using anole's
// wxsticker icon names
  $iconList = new Array(
	"day_clear.gif",           //  0 imagesunny.visible           Sunny
	"night_clear.gif",         //  1 imageclearnight.visible      Clear Night
	"day_cloudy2.gif",          //  2 imagecloudy.visible          Cloudy
	"day_cloudy3.gif",          //  3 imagecloudy.visible          Cloudy
	"night_cloudy.gif",        //  4 imagecloudynight.visible     Cloudy Night
	"day_partly_cloudy.gif",   //  5 imagedry.visible             Dry Clear           Partly cloudy
	"fog.gif",                 //  6 imagefog.visible             Fog
	"haze.gif",                //  7 imagehaze.visible            Hazy
	"day_heavy_rain.gif",      //  8 imageheavyrain.visible       Heavy Rain
	"day_mostly_sunny.gif",    //  9 imagemainlyfine.visible      Mainly Fine
	"mist.gif",                // 10 imagemist.visible            Misty
	"night_fog.gif",                 // 11 imagenightfog.visible        Night Fog
	"night_heavy_rain.gif",    // 12 imagenightheavyrain.visible  Night Heavy Rain
	"night_overcast.gif",        // 13 imagenightovercast.visible   Night Overcast
	"night_rain.gif",          // 14 imagenightrain.visible       Night Rain
	"night_light_rain.gif",    // 15 imagenightshowers.visible    Night Showers
	"night_snow.gif",          // 16 imagenightsnow.visible       Night Snow
	"night_tstorm.gif",        // 17 imagenightthunder.visible    Night Thunder
	"day_overcast.gif",        // 18 imageovercast.visible        Overcast
	"day_cloudy.gif",          // 19 imagepartlycloudy.visible    Partly Cloudy       Mainly cloudy
	"day_rain.gif",            // 20 imagerain.visible            Rain
	"day_heavy_rain.gif",      // 21 imagerain2.visible           Hard Rain
	"day_light_rain.gif",      // 22 imageshowers2.visible        Showers
	"day_sleet.gif",           // 23 imagesleet.visible           Sleet
	"day_sleet.gif",           // 24 imagesleetshowers.visible    Sleet Showers
	"day_snow.gif",            // 25 imagesnow.visible            Snowing
	"day_snow.gif",            // 26 imagesnowmelt.visible        Snow Melt
	"day_snow.gif",            // 27 imagesnowshowers2.visible    Snow Showers
	"day_clear.gif",           // 28 imagesunny.visible           Sunny
	"day_tstorm.gif",          // 29 imagethundershowers.visible  Thunder Showers
	"day_tstorm.gif",          // 30 imagethundershowers2.visible Thunder Showers
	"day_tstorm.gif",          // 31 imagethunderstorms.visible   Thunderstorms
	"tornado.gif",             // 32 imagetornado.visible         Tornado Warning
	"windy.gif",               // 33 imagewindy.visible           Windy
	"day_cloudy_stop_rainning.gif"           // 34 stopped rainning             Stopped Raining
	);					

  if (iconWD >= 0 && iconWD <= 34) { 
    return ("<img src=\"" + imagedir + "/" + $iconList[iconWD] + "\" " +
				"width=\"90\" height=\"72\" alt=\"Current condition icon\" />" );
  } else {
	return '';
  }

}



function ajax_ForecastIcon ( FCicon ) { 
// perform a lookup and return the graphic for the condition icon (using anole's
// FCsticker icon names
  $FCiconList = new Array(
	"day_clear.gif",           //  0 imageheavyrain.visible
	"day_mostly_sunny.gif",    //  1 imagemainlyfine.visible
	"day_mostly_sunny.gif",    //  2 imagemist.visible
	"fog.gif",                 //  3 imagenightfog.visible
	"night_heavy_rain.gif",    //  4 imagenightheavyrain.visible
	"night_cloudy.gif",        //  5 imagenightovercast.visible
	"night_rain.gif",          //  6 imagenightrain.visible
	"night_light_rain.gif",    //  7 imagenightshowers.visible
	"night_snow.gif",          //  8 imagenightsnow.visible
	"night_tstorm.gif",        //  9 imagenightthunder.visible
	"day_cloudy.gif",          // 10 imageovercast.visible
	"day_partly_cloudy.gif",   // 11 imagepartlycloudy.visible
	"day_rain.gif",            // 12 imagerain.visible
	"day_heavy_rain.gif",      // 13 imageheavyrain.visible
	"day_light_rain.gif",      // 14 imageshowers.visible
	"day_sleet.gif",           // 15 imagesleet.visible
	"day_sleet.gif",           // 16 imagesleetshowers.visible
	"day_snow.gif",            // 17 imagesnowing.visible
	"day_snow.gif",            // 18 imagesnowshowers.visible
	"day_snow.gif",            // 19 imagesnowmelt.visible
	"day_clear.gif",           // 20 imagesunny.visible
	"day_tstorm.gif",          // 21 imagethundershowers.visible
	"day_tstorm.gif",          // 22 imagethundershowers2.visible
	"day_tstorm.gif",          // 23 imagethunderstorms.visible
	"tornado.gif",             // 24 imagetornado.visible
	"windy.gif",               // 25 imagewindy.visible
	"day_partly_cloudy.gif"    // 26 stopped rainning
	);					

  if (FCicon >= 0 && FCicon <= 26) { 
    return ("<img src=\"" + imagedir + "/" + $FCiconList[FCicon] + "\" " +
				"width=\"45\" height=\"36\" alt=\"Current condition icon\" />" );
  } else {
	return '';
  }

}

// utility functions to handle conversions from clientraw data to desired units-of-measure
function convertTemp ( rawtemp ) {
	if (useunits == 'E') { // convert C to F
		return( (1.8 * rawtemp) + 32.0);
	} else {  // leave as C
		return (rawtemp * 1.0);
	}
}

function convertWind  ( rawwind ) {
	if (useKnots) { return(rawwind * 1.0); } //force usage of knots for speed
	if (useunits == 'E') { // convert knots to mph
		return(rawwind * 1.1507794);
	} else {  
	    if (useMPS) { // convert knots to m/s
		  return (rawwind * 0.514444444);
		} else { // convert knots to km/hr
		  return (rawwind * 1.852);
		}
	}
}

function convertWindKm  ( rawwind ) 
      { // convert knots to km/hr
	  return (rawwind * 1.852); }

function convertBaro ( rawpress ) {
	if (useunits == 'E') { // convert hPa to inHg
	   return (rawpress  / 33.86388158);
	} else {
	   return (rawpress * 1.0); // leave in hPa
	}
}

function convertRain ( rawrain ) {
	if (useunits == 'E') { // convert mm to inches
	   return (rawrain * .0393700787);
	} else {
	   return (rawrain * 1.0); // leave in mm
	}
}

function convertHeight ( rawheight ) {
	if (useunits == 'E') { // convert feet to meters if metric
	   return (Math.round(rawheight * 1.0).toFixed(0)); // leave in feet
	} else {
	   return (Math.round(rawheight / 3.2808399).toFixed(0));
	}
}

function ajax_get_beaufort ( wind ) { 
// return a phrase for the beaufort scale based on wind knots (native WD format)
  if (wind < 1 ) {return("0"); }
  if (wind < 4 ) {return("1"); }
  if (wind < 7 ) {return("2"); }
  if (wind < 11 ) {return("3"); }
  if (wind < 17 ) {return("4"); }
  if (wind < 22 ) {return("5"); }
  if (wind < 28 ) {return("6"); }
  if (wind < 34 ) {return("7"); }
  if (wind < 41 ) {return("8"); }
  if (wind < 48 ) {return("9"); }
  if (wind < 56 ) {return("10"); }
  if (wind < 64 ) {return("11"); }
  if (wind >= 64 ) {return("12"); }
  return("unknown " + wind);
}

// Warnings -------------------------------------------------------- Warnings -----------

function ajax_FWI_photo ( firephoto ) { 
// return a phrase for the beaufort scale based on wind knots (native WD format)
  if (firephoto < 8) {return("<img src=\"" + imagedir + "/" + "FWI_1.gif" + "\" /> "); }
  if (firephoto < 16) {return("<img src=\"" + imagedir + "/" + "FWI_2.gif" + "\" /> "); }
  if (firephoto < 24) {return("<img src=\"" + imagedir + "/" + "FWI_3.gif" + "\" /> "); }
  if (firephoto < 32) {return("<img src=\"" + imagedir + "/" + "FWI_4.gif" + "\" /> "); }
  if (firephoto >= 32) {return("<img src=\"" + imagedir + "/" + "FWI_5.gif" + "\" /> "); }
  return(" " + firephoto);
}

function ajax_temp_alert ( tempalert ) { 
// return a phrase for the temp alert
   if (tempalert < 3 ) {return("ice alert"); }
   return("-");
}

function ajax_temprate_alert (tempnow,tempbefore) { 
// return a phrase for the temp trend
  if ((tempnow - tempbefore) >= 1 ) {return("rising slowly"); }   
  if ((tempnow - tempbefore) >= 3 ) {return("rising rapidly"); }
  if ((tempbefore - tempnow) >= 1 ) {return("falling slowly"); }
  if ((tempbefore - tempnow) >= 3 ) {return("falling rapidly"); }
  return("-");
}


function ajax_hum_alert ( humalert ) { 
// return a phrase for the humidity alert
  if (humalert > 70 ) {return("wet"); }
  if (humalert < 40 ) {return("dry"); }
  return("-");
}

function ajax_baro_alert ( baroalert ) { 
// return a phrase for the temp alert
   if ((baroalert >= -0.7) && (baroalert <= 0.7)) { return("-"); }
   if ((baroalert > 0.7) && (baroalert < 2.0)) { return("Rising Slowly"); }
   if (baroalert >= 2.0) { return("Rising Rapidly"); }
   if ((baroalert < -0.7) && (baroalert > -2.0)) { return("Falling Slowly"); }
   if (baroalert <= -2.0) { return("Falling Rapidly"); }
   if (baroalert >= 4.0) {return("storm alert"); }
   if (baroalert <= -4.0) {return("storm alert"); }
}

function ajax_wind_alert ( windalert ) { 
// return a phrase for the wind alert
  if (windalert > 22 ) {return("windy"); }
  if (windalert < 1 ) {return("calm"); }
  return("-");
}

function ajax_rain_alert ( rainalert ) { 
// return a phrase for the rain alert
  if (rainalert > 0 ) {return("light rain"); }
  if (rainalert > 4 ) {return("rain"); }
  if (rainalert > 20 ) {return("heavy rain"); }
  return("-");
}

function ajax_uv_alert ( uvalert ) { 
// return a phrase for the uv alert
  if (uvalert > 0 && uvalert <= 2 ) {return("Minimal exposure"); }
  if (uvalert > 2 && uvalert <= 4 ) {return("Low exposure"); }
  if (uvalert > 4 && uvalert <= 6 ) {return("Moderate exposure"); }
  if (uvalert > 6 && uvalert <= 9 ) {return("High exposure"); }
  if (uvalert > 9) {return("Very High exposure"); }
  return("-");
}

function ajax_UV_photo ( UVphoto ) { 
// return a phrase for the uv photo
  if (UVphoto < 0.5) {return("<img src=\"" + imagedir + "/" + "C_UV00(cmyk).gif" + "\" /> "); }
  if (UVphoto >= 0.5 && UVphoto <= 1.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV01(cmyk).gif" + "\" /> "); }
  if (UVphoto > 1.5 && UVphoto <= 2.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV02(cmyk).gif" + "\" /> "); }
  if (UVphoto > 2.5 && UVphoto <= 3.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV03(cmyk).gif" + "\" /> "); }
  if (UVphoto > 3.5 && UVphoto <= 4.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV04(cmyk).gif" + "\" /> "); }
  if (UVphoto > 4.5 && UVphoto <= 5.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV05(cmyk).gif" + "\" /> "); }
  if (UVphoto > 5.5 && UVphoto <= 6.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV06(cmyk).gif" + "\" /> "); }
  if (UVphoto > 6.5 && UVphoto <= 7.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV07(cmyk).gif" + "\" /> "); }
  if (UVphoto > 7.5 && UVphoto <= 8.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV08(cmyk).gif" + "\" /> "); }
  if (UVphoto > 8.5 && UVphoto <= 9.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV09(cmyk).gif" + "\" /> "); }
  if (UVphoto > 9.5 && UVphoto <= 10.5 ) {return("<img src=\"" + imagedir + "/" + "C_UV10(cmyk).gif" + "\" /> "); }
  if (UVphoto > 10) {return("<img src=\"" + imagedir + "/" + "C_UV11(cmyk).gif" + "\" /> "); }
  return("-");
}

function ajax_solar_alert ( solaralert ) { 
// return a phrase for the solar alert
  if (solaralert >= 80 ) {return("-"); }
  if (solaralert >= 65 && solaralert <= 80) {return("some clouds"); }
  if (solaralert >= 45 && solaralert <= 64) {return("clouds"); }
  if (solaralert >= 11 && solaralert <= 44) {return("many clouds"); }
  if (solaralert > 0 && solaralert <= 10) {return("overcast"); }
  return("-");
}

function ajax_get_beaufort_max ( maxwind ) { 
// return a phrase for the beaufort scale based on wind knots (native WD format)
  if (maxwind < 1 ) {return("<img src=\"" + imagedir + "/" + "0_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 4 ) {return("<img src=\"" + imagedir + "/" + "1_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 7 ) {return("<img src=\"" + imagedir + "/" + "2_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 11 ) {return("<img src=\"" + imagedir + "/" + "3_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 17 ) {return("<img src=\"" + imagedir + "/" + "4_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 22 ) {return("<img src=\"" + imagedir + "/" + "5_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 28 ) {return("<img src=\"" + imagedir + "/" + "6_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 34 ) {return("<img src=\"" + imagedir + "/" + "7_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 41 ) {return("<img src=\"" + imagedir + "/" + "8_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 48 ) {return("<img src=\"" + imagedir + "/" + "9_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 56 ) {return("<img src=\"" + imagedir + "/" + "10_BFT_MAX.gif" + "\" /> "); }
  if (maxwind < 64 ) {return("<img src=\"" + imagedir + "/" + "11_BFT_MAX.gif" + "\" /> "); }
  if (maxwind >= 64 ) {return("<img src=\"" + imagedir + "/" + "12_BFT_MAX.gif" + "\" /> "); }
  return("unknown " + maxwind);
}


function ajax_beaufort_image ( wnd ) { 
// return beaufort scale image based on wind knots (native WD format)
  $BFiconList = new Array(
	"0_BEAUFURT.gif",
	"1_BEAUFURT.gif",
	"2_BEAUFURT.gif",
	"3_BEAUFURT.gif",
	"4_BEAUFURT.gif",
	"5_BEAUFURT.gif",
	"6_BEAUFURT.gif",
	"7_BEAUFURT.gif",
	"8_BEAUFURT.gif",
	"9_BEAUFURT.gif",
       "10_BEAUFURT.gif",
       "11_BEAUFURT.gif",
       "12_BEAUFURT.gif"
	);					
  if (wnd >= 0 && wnd <= 12) { 
    return ("<img src=\"" + imagedir + "/" + $BFiconList[wnd] + "\" /> ");
  } else {
	return '';
  }

}

function ajax_beaufort_sea ( wd ) { 
// return beaufort scale image based on wind knots (native WD format)
  $BSiconList = new Array(
	"0_sea.gif",
	"1_sea.gif",
	"2_sea.gif",
	"3_sea.gif",
	"4_sea.gif",
	"5_sea.gif",
	"6_sea.gif",
	"7_sea.gif",
	"8_sea.gif",
	"9_sea.gif",
	"10_sea.gif",
	"11_sea.gif"
	);					
  if (wd >= 0 && wd <= 11) { 
    return ("<img src=\"" + imagedir + "/" + $BSiconList[wd] + "\" /> ");
  } else {
	return '';
  }

}


function ajax_get_barotrend(btrnd) {
// routine from Anole's wxsticker PHP (adapted to JS by Ken True)
// input: trend in hPa or millibars
//   Barometric Trend(3 hour)

// Change Rates
// Rapidly: =.06 inHg; 1.5 mm Hg; 2 hPa; 2 mb
// Slowly: =.02 inHg; 0.5 mm Hg; 0.7 hPa; 0.7 mb

// 5 conditions
// Rising Rapidly
// Rising Slowly
// Steady
// Falling Slowly
// Falling Rapidly

// Page 52 of the PDF Manual
// http://www.davisnet.com/product_documents/weather/manuals/07395.234-VP2_Manual.pdf
// figure out a text value for barometric pressure trend
   if ((btrnd >= -0.7) && (btrnd <= 0.7)) { return("Steady"); }
   if ((btrnd > 0.7) && (btrnd < 2.0)) { return("Rising Slowly"); }
   if (btrnd >= 2.0) { return("Rising Rapidly"); }
   if ((btrnd < -0.7) && (btrnd > -2.0)) { return("Falling Slowly"); }
   if (btrnd <= -2.0) { return("Falling Rapidly"); }
  return(btrnd);
}

function ajax_genarrow( nowTemp, yesterTemp, Legend, textUP, textDN, numDp) {
// generate an <img> tag with alt= and title= for rising/falling values	
	
  var diff = nowTemp.toFixed(3) - yesterTemp.toFixed(3);
  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) {
// today 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 {
// today 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

// Mike Challis' counter function (adapted by Ken True)
//
function ajax_countup() {
 element = document.getElementById("ajaxcounter");
 if (element) {
  element.innerHTML = counterSecs;
  counterSecs++;
 }
}


// ------------------------------------------------------------------------------------------
//  main function.. read CUSTOMraw.txt and format <span class="ajax" id="ajax..."></span> areas
// ------------------------------------------------------------------------------------------
function ajaxLoadercustom(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 customraw = x.responseText.split('>');
    var wdpattern=/\d+\.\d+.*!!/; // looks for '!!nn.nn!!' version string 
	if(customraw[0] == '12345' && wdpattern.test(x.responseText) ) {

                var dirtyString = customraw[1];
                var HDiff = dirtyString.stripOffIllegalChars();
                set_ajax_obs("ajaxHDiff",HDiff);
                BaroDiff3H = customraw[2];
                set_ajax_obs("ajaxBaroDiff3H",BaroDiff3H)
                SeaCondition = customraw[3];
                set_ajax_obs("ajaxSeaCondition",SeaCondition);
                monthdayswithrain= customraw[4];
                set_ajax_obs("ajaxmonthdayswithrain",monthdayswithrain);
                AvgBft = customraw[5];
                set_ajax_obs("ajaxAvgBft",AvgBft);
                timeoflastrain = customraw[6];
                set_ajax_obs("ajaxtimeoflastrain",timeoflastrain);
                dateoflastrain = customraw[7];
                set_ajax_obs("ajaxdateoflastrain",dateoflastrain);
                sunshinemonth = customraw[8];
                set_ajax_obs("ajaxsunshinemonth",sunshinemonth);
                windruntoday = customraw[9];
                set_ajax_obs("ajaxwindruntoday",windruntoday);
                Evaportranspiration = customraw[10];
                set_ajax_obs("ajaxEvaportranspiration",Evaportranspiration);
                Evaportranspirationmonth = customraw[11];
                set_ajax_obs("ajaxEvaportranspirationmonth",Evaportranspirationmonth);
                airdensity = customraw[12];
                set_ajax_obs("ajaxairdensity",airdensity);
                abshum = customraw[13];
                set_ajax_obs("ajaxabshum",abshum);
                wetbulb = customraw[14];
                set_ajax_obs("ajaxwetbulb",wetbulb);
                dewdep = customraw[15];
                set_ajax_obs("ajaxdewdep",dewdep);
                currentwdet = customraw[16];
                set_ajax_obs("currentwdet",currentwdet);
                burntime = customraw[17];
                set_ajax_obs("ajaxburntime",burntime);
                vapourpressure = customraw[18];
                set_ajax_obs("ajaxvapourpressure",vapourpressure);
                rainduration = customraw[19];
                set_ajax_obs("ajaxrainduration",rainduration);
                wetbulbdiff = customraw[20];
                set_ajax_obs("ajaxwetbulbdiff",wetbulbdiff);
                hoursoffrost = customraw[21];
                set_ajax_obs("ajaxhoursoffrost",hoursoffrost);
                dewchangelasthour = customraw[22];
                set_ajax_obs("ajaxdewchangelasthour",dewchangelasthour);
                humchangelasthour = customraw[23];
                set_ajax_obs("ajaxhumchangelasthour",humchangelasthour);
                curdir10minutelabel = customraw[24];
                set_ajax_obs("ajaxcurdir10minutelabel",curdir10minutelabel);
                forecasticonword = customraw[25];
                set_ajax_obs("ajaxforecasticonword",forecasticonword);

                VPforecasttext = customraw[26];
                set_ajax_obs("ajaxVPforecasttext",VPforecasttext);
                highbaro = customraw[27];
                set_ajax_obs("ajaxhighbaro",highbaro);
                highbarotime = customraw[28];
                set_ajax_obs("ajaxhighbarotime",highbarotime);
                lowbaro = customraw[29];
                set_ajax_obs("ajaxlowbaro",lowbaro);
                lowbarotime = customraw[30];
                set_ajax_obs("ajaxlowbarotime",lowbarotime);
                highsolar = customraw[31];
                set_ajax_obs("ajaxhighsolar",highsolar);
                highsolartime = customraw[32];
                set_ajax_obs("ajaxhighsolartime",highsolartime);
                highhum = customraw[33];
                set_ajax_obs("ajaxhighhum",highhum);
                highhumtime = customraw[34];
                set_ajax_obs("ajaxhighhumtime",highhumtime);
                lowhum = customraw[35];
                set_ajax_obs("ajaxlowhum",lowhum);
                lowhumtime = customraw[36];
                set_ajax_obs("ajaxlowhumtime",lowhumtime);
                hightemp = customraw[37];
                set_ajax_obs("ajaxhightemp",hightemp);

                set_ajax_obs("ajaxhightemptoday",hightemp);
                hightempyesterday = customraw[64];           
                set_ajax_obs("ajaxhightempyesterday",hightempyesterday);

                var dirtyString = customraw[66];
                var hightemp1yearago = dirtyString.stripOffIllegalChars();      
                set_ajax_obs("ajaxhightemp1yearago",hightemp1yearago);

                hightemprecords = customraw[68];           
                set_ajax_obs("ajaxhightemprecords",hightemprecords);
                timeofhightemprecords = customraw[70];           
                set_ajax_obs("ajaxtimeofhightemprecords",timeofhightemprecords);

                hightemptime = customraw[38];
                set_ajax_obs("ajaxhightemptime",hightemptime);
                lowtemp = customraw[39];
                set_ajax_obs("ajaxlowtemp",lowtemp);

                set_ajax_obs("ajaxlowtemptoday",lowtemp);
                lowtempyesterday = customraw[65];           
                set_ajax_obs("ajaxlowtempyesterday",lowtempyesterday);

                var dirtyString = customraw[67];
                var lowtemp1yearago = dirtyString.stripOffIllegalChars();      
                set_ajax_obs("ajaxlowtemp1yearago",lowtemp1yearago);
                lowtemprecords = customraw[69];           
                set_ajax_obs("ajaxlowtemprecords",lowtemprecords);
                timeoflowtemprecords = customraw[71];           
                set_ajax_obs("ajaxtimeoflowtemprecords",timeoflowtemprecords);

                lowtemptime = customraw[40];
                set_ajax_obs("ajaxlowtemptime",lowtemptime);
                humchange24hour = customraw[41];
                set_ajax_obs("ajaxhumchange24hour",humchange24hour + " / 24 hrs");
                highwindtime = customraw[42];
                set_ajax_obs("ajaxhighwindtime",highwindtime);
                highuv = customraw[43];
                set_ajax_obs("ajaxhighuv",highuv);
                highuvtime = customraw[44];
                set_ajax_obs("ajaxhighuvtime",highuvtime);
                vpissstatus = customraw[45];
                set_ajax_obs("ajaxvpissstatus",vpissstatus);
                vpreception = customraw[46];
                set_ajax_obs("ajaxvpreception",vpreception);
                vpconsolebattery = customraw[47];
                set_ajax_obs("ajaxvpconsolebattery",vpconsolebattery);
                dayornight = customraw[50];
                set_ajax_obs("ajaxdayornight",dayornight);
                yesthitemp = customraw[51];
                set_ajax_obs("ajaxyesthitemp",yesthitemp);
                yestlotemp = customraw[52];
                set_ajax_obs("ajaxyestlotemp",yestlotemp);
                baro1hour = customraw[53];
                set_ajax_obs("ajaxbaro1hour",baro1hour);
                baro3hours = customraw[54];
                set_ajax_obs("ajaxbaro3hours",baro3hours);
                baro6hours = customraw[55];
                set_ajax_obs("ajaxbaro6hours",baro6hours);
                baro12hours = customraw[56];
                set_ajax_obs("ajaxbaro12hours",baro12hours);
                baro24hours = customraw[57];
                set_ajax_obs("ajaxbaro24hours",baro24hours);
                daysTmin5C = customraw[58];
                set_ajax_obs("ajaxdaysTmin5C",daysTmin5C);
                daysTmin0C = customraw[59];
                set_ajax_obs("ajaxdaysTmin0C",daysTmin0C);
                daysTmax30C = customraw[60];
                set_ajax_obs("ajaxdaysTmax30C",daysTmax30C);
                daysTmax35C = customraw[61];
                set_ajax_obs("ajaxdaysTmax35C",daysTmax35C);
                maxbaroyest = customraw[62];
                set_ajax_obs("ajaxmaxbaroyest",maxbaroyest);
                minbaroyest = customraw[63];
                set_ajax_obs("ajaxminbaroyest",minbaroyest);

//                set_ajax_obj("ajaxcam1","<img src="http://www.meteofan.eu/ftpcam_1.jpg" />");
               
		// now ensure that the indicator flashes on every AJAX fetch
        element = document.getElementById("ajaxindicator");
		if (element) {
          element.style.color = flashcolor;
		}

 	  } // END if(clientrawextra[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);

//get all of them every minute = 5000 milliseconds
//edit the location of your clienraw.txt twice!! (here and in the body onload)
	setTimeout("reset_ajax_color('')",flashtime); // change text back to default color 
    setTimeout("ajaxLoadercustom(customrawFile + '?' + new Date().getTime())", reloadTime3); // get new data after 5 secs
  }
} // end ajaxLoader function



// invoke when first loaded on page
if (! ajaxLoadercustomInBody) { ajaxLoadercustom(customrawFile + '?' + new Date().getTime(),reloadTime3); }


// ]]>
