// <![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
// --- Version 2.08 - 07-Nov-2007 -- added useMPH to force wind display in Miles-per-hour and
//                                   added optional Wind-Rose, optional new current icon display graphics
// --- Version 2.09 - 23-Dec-2007 -- added maxupdates feature, new ajax variables from K. Reed www.tnetweather.com
// --- Version 2.10 - 18-Jan-2008 -- fixed icon=34 for ra1.jpg
// --- Version 2.11 - 21-Feb-2008 -- added icon=35 for windyrain.gif/.jpg
// --- Version 2.12 - 07-Mar-2008 -- added fix for 'flashing icon/thermometer' from Jim at jcweather.us
// --- Version 2.13 - 11-Mar-2008 -- changed Wind-rose defaults to .png type (Carterlake/AJAX/PHP templates)
// --- Version 2.14 - 29-Mar-2008 -- fixed UV words with  color: black; for display on dark/black template (MCHALLIS)
// --- Version 2.15 - 28-Apr-2008 -- added ajaxFixConditions() and translation capability
// --- Version 2.16 - 20-May-2008 -- added headcolorword processing V1.0 from MCHALLIS
// --- Version 2.17 - 25-Jun-2008 -- added gizmo-specific ajax variables
//
// 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 reloadTime = 10000;       // reload AJAX conditions every 5 seconds (= 5000 ms)
var maxupdates = 50;	         // Maxium Number of updates allowed (set to zero for unlimited)
                             // maxupdates * reloadTime / 1000 = number of seconds to update
var clientrawFile = './clientraw.txt'; // location of clientraw.txt relative to this page on website
var ajaxLoaderInBody = false; // set to true if you have <body onload="ajaxLoader(..."
var imagedir = './ajax-images';  // place for wind arrows, rising/falling arrows, etc.
var useunits = 'M';         // 'E'=USA(English) or 'M'=Metric
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 useMPH   = false;       // set to true to force MPH for both English and Metric units
var useFeet  = false;       // set to true to force Feet for height in both English and Metric
var showUnits = true;       //  set to false if no units are to be displayed
var thermometer = './thermometer.php'; // script for dynamic thermometer PNG image (optional)
// optional settings for the Wind Rose graphic in ajaxwindiconwr as wrName + winddir + wrType
var wrName   = 'wr-';       // first part of the graphic filename (followed by winddir to complete it)
var wrType   = '.png';      // extension of the graphic filename
var wrHeight = '80';        // windrose graphic height=
var wrWidth  = '80';        // windrose graphic width=
var wrCalm   = 'wr-calm.png';  // set to full name of graphic for calm display ('wr-calm.gif')
// -- end of settings -------------------------------------------------------

// -- start of trend arrow settings by vouhead ------------------------------
var trendarrow0 = "<img src=ajax-images/barotrendarrow0.gif >";
var trendarrow1 = "<img src=ajax-images/barotrendarrow1.gif >";
var trendarrow2 = "<img src=ajax-images/barotrendarrow2.gif >";
var trendarrow3 = "<img src=ajax-images/barotrendarrow3.gif >";
var trendarrow4 = "<img src=ajax-images/barotrendarrow4.gif >";
var trendarrow5 = "<img src=ajax-images/barotrendarrow5.gif >";
var trendarrow6 = "<img src=ajax-images/barotrendarrow6.gif >";
// -- end of trend arrow settings by vouhead -------------------------------

// -- start of trend image settings by vouhead -----------------------------
var trendimage0 = "<img src=ajax-images/barotrend0.png >";
var trendimage1 = "<img src=ajax-images/barotrend1.png >";
var trendimage2 = "<img src=ajax-images/barotrend2.png >";
var trendimage3 = "<img src=ajax-images/barotrend3.png >";
var trendimage4 = "<img src=ajax-images/barotrend4.png >";
var trendimage5 = "<img src=ajax-images/barotrend5.png >";
var trendimage6 = "<img src=ajax-images/barotrend6.png >";
var trendimage6out = "<img src=ajax-images/barotrend6out.png >";
var trendimage7 = "<img src=ajax-images/barotrend7.png >";
var trendimage8 = "<img src=ajax-images/barotrend8.png >";
var trendimage9 = "<img src=ajax-images/barotrend9.png >";
var trendimage10 = "<img src=ajax-images/barotrend10.png >";
var trendimage11 = "<img src=ajax-images/barotrend11.png >";
var trendimage12 = "<img src=ajax-images/barotrend12.png >";
var trendimage12out = "<img src=ajax-images/barotrend12out.png >";
// -- end of trend image settings by vouhead -------------------------------

// -- start of baro image settings by vouhead ------------------------------
var baroimage0 = "<img src=ajax-images/baro0.png >";
var baroimage1 = "<img src=ajax-images/baro1.png >";
var baroimage2 = "<img src=ajax-images/baro2.png >";
var baroimage3 = "<img src=ajax-images/baro3.png >";
var baroimage4 = "<img src=ajax-images/baro4.png >";
var baroimage5 = "<img src=ajax-images/baro5.png >";
var baroimage6 = "<img src=ajax-images/baro6.png >";
var baroimage7 = "<img src=ajax-images/baro7.png >";
var baroimage8 = "<img src=ajax-images/baro8.png >";
var baroimage9 = "<img src=ajax-images/baro9.png >";
var baroimage10 = "<img src=ajax-images/baro10.png >";
var baroimage11 = "<img src=ajax-images/baro11.png >";
var baroimage12 = "<img src=ajax-images/baro12.png >";
var baroimage13 = "<img src=ajax-images/baro13.png >";
var baroimage14 = "<img src=ajax-images/baro14.png >";
var baroimage15 = "<img src=ajax-images/baro15.png >";
var baroimage16 = "<img src=ajax-images/baro16.png >";
var baroimage17 = "<img src=ajax-images/baro17.png >";
var baroimage18 = "<img src=ajax-images/baro18.png >";
var baroimage19 = "<img src=ajax-images/baro19.png >";
var baroimage20 = "<img src=ajax-images/baro20.png >";
var baroimage21 = "<img src=ajax-images/baro21.png >";
var baroimage22 = "<img src=ajax-images/baro22.png >";
var baroimage23 = "<img src=ajax-images/baro23.png >";
var baroimage24 = "<img src=ajax-images/baro24.png >";
// -- end of baro image settings by vouhead --------------------------------

// -- start of UVsun image settings by vouhead -----------------------------
var UVsunimg01 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_sl.gif width=28 height=22 border=0 align=absmiddle alt=";
var UVsunimg02 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_wup.gif width=28 height=22 border=0 align=absmiddle alt=";
var UVsunimg03 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_bsl.gif width=28 height=22 border=0 align=absmiddle alt=";
var UVsunimg04 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_1uv.gif width=28 height=22 border=0 align=absmiddle alt=";
var UVsunimg05 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_l.gif width=28 height=22 border=0 align=absmiddle alt=";
var UVsunimg06 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_m.gif width=30 height=22 border=0 align=absmiddle alt=";
var UVsunimg07 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_h.gif width=30 height=22 border=0 align=absmiddle alt=";
var UVsunimg08 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_vh.gif width=30 height=22 border=0 align=absmiddle alt=";
var UVsunimg09 = "<a href=./wxuv-1.php /><img src=ajax-images/sun_e.gif width=30 height=22 border=0 align=absmiddle alt=";
// -- end of UVsun image settings by vouhead -------------------------------

// -- language settings -- you don't need to customize this area if you are using English 
// ------------------------ ***** BE SURE TO INCLUDE &nbsp; FOR SPACE ***** -------------
// substitute this for ajaxindicator when maxupdates has been reached and updating paused.
var langPauseMsg = '<img src=ajax-images/updatepaused.gif ><span style=\"border: dotted 1px; color: #FE6000; background-color: #FFFFFF;\">' + 
                   'Updates paused! Please reload page to start again!</span>'; 
                                                                                
var langMonths = new Array ( "January","February","March","April","May",
			"June","July","August","September","October","November","December");
var langDays = new Array ( "Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun");	

var langBaroTrend = new Array (
 "Steady", "Rising slowly", "Rising", "Rising rapidly", "Falling slowly", "Falling", "Falling rapidly");

var langBaroWith = new Array ( 
 "with");

var langUVWords = new Array (
 "None", "Low", "Medium", "High",
 "Very&nbsp;High", "Extreme" );

// ------------- Start of langWords for Burntime by vouhead -----------------------------
var langburntimeUVWords = new Array (
"Sunburn&nbsp;in&nbsp;90&nbsp;to&nbsp;120&nbsp;minutes" , "Sunburn&nbsp;in&nbsp;60&nbsp;to&nbsp;90&nbsp;minutes" , 
"Sunburn&nbsp;in&nbsp;50&nbsp;to&nbsp;60&nbsp;minutes" , "Sunburn&nbsp;in&nbsp;40&nbsp;to&nbsp;50&nbsp;minutes" , 
"Sunburn&nbsp;in&nbsp;30&nbsp;to&nbsp;40&nbsp;minutes" ,"Sunburn&nbsp;in&nbsp;25&nbsp;to&nbsp;30&nbsp;minutes" , 
"Sunburn&nbsp;in&nbsp;20&nbsp;to&nbsp;25&nbsp;minutes" , "Sunburn&nbsp;in&nbsp;15&nbsp;to&nbsp;20&nbsp;minutes" ,
"Sunburn&nbsp;in&nbsp;10&nbsp;to&nbsp;15&nbsp;minutes" , "Sunburn&nbsp;in&nbsp;5&nbsp;to&nbsp;10&nbsp;minutes" , 
"Sunburn&nbsp;in&nbsp;1&nbsp;to&nbsp;5&nbsp;minutes" ,"Avoid&nbsp;direct&nbsp;sun&nbsp;exposure" , 
"Avoid&nbsp;any&nbsp;sun&nbsp;exposure" , "About&nbsp;the&nbsp;UV&nbsp;index");

// ------------- End of langWords for Burntime by vouhead ------------------------------

//-------------- Start of langWords for ThunderAlert by vouhead ------------------------

var langthunderalertWords = new Array ( /* by vouhead */
"In&nbsp;less&nbsp;than&nbsp;30&nbsp;km" , "Go&nbsp;to&nbsp;Vouhead&nbsp;Weather&nbsp;Lightning&nbsp;Detector");

//-------------- End of langWords for ThunderAlert by vouhead --------------------------

// ------------ Start of langWords for Hazardous Conditions by vouhead
var langHZdousCondWords = new Array ( 
"Hazardous&nbsp;Conditions" , //-----0 
"Outlook" ,     //-------------------1
"Conditions" ,  //-------------------2
"Temp." ,       //-------------------3
"(10m)" ,     //---------------------4
"*&nbsp;Possible&nbsp;Frost&nbsp;Conditions" , //-------5
"*&nbsp;Close&nbsp;to&nbsp;Frost&nbsp;Conditions" ,  //----------------6
"*&nbsp;Almost&nbsp;Frost&nbsp;Conditions" , //-------7
"*&nbsp;Frost&nbsp;Conditions" , //------------------------------------8
"*&nbsp;Close&nbsp;to&nbsp;Heatwave&nbsp;Conditions" , //------------------9
"*&nbsp;Very&nbsp;close&nbsp;to&nbsp;Heatwave&nbsp;Conditions" , //--------10
"*&nbsp;Possible&nbsp;Heatwave&nbsp;Conditions" , //-----------------------11
"*&nbsp;Heatwave&nbsp;Conditions" , //-------------------------------------12
"*&nbsp;Heatwave&nbsp;Conditions&nbsp;and<br/>&nbsp;&nbsp;&nbsp;Discomfort&nbsp;Conditions" , //--------------------13
"*&nbsp;Heatwave&nbsp;Conditions&nbsp;and<br/>&nbsp;&nbsp;&nbsp;Severe&nbsp;Discomfort&nbsp;Conditions" , //--------14 
"Wind" , //-----------------------15
"*&nbsp;Strong&nbsp;Wind" , //----16
"*&nbsp;Strong&nbsp;Gust" , //----17 
"*&nbsp;High&nbsp;Difference&nbsp;between&nbsp;the<br/>&nbsp;&nbsp;&nbsp;Gust&nbsp;and&nbsp;Wind&nbsp;speeds" , //-----18 
"Rain" ,       //---------------------------------19 
"*&nbsp;High&nbsp;Rain&nbsp;Total" , //-----------20
"*&nbsp;High&nbsp;RainRate" ,  //-----------------21
"UV&nbsp;Index" ,    //---------------------------22
"*&nbsp;Quick&nbsp;Sunburn&nbsp;Conditions" , //--23
"*&nbsp;Instandly&nbsp;Sunburn&nbsp;Conditions" , //--24 
"Temperature&nbsp;(1,5&nbsp;m)" , //------------------25
"Pressure" , //------------------26
"Humid. (10m)" , //------------------27
"Pressure&nbsp;&&nbsp;Humidity&nbsp;(10m)"); //------------------27

// ------------ End of langWords for Hazardous Conditions by vouhead

var langBeaufort = new Array ( /* Beaufort 0 to 12 in array */
 "Calm", "Light air", "Light breeze", "Gentle breeze", "Moderate breeze", "Fresh breeze" ,
 "Strong breeze", "Near gale", "Gale", "Strong gale", "Storm" ,
 "Violent storm", "Hurricane"
);

var langWindDir = new Array( /* used for alt and title tags on wind dir arrow and wind direction display */
	"N", "NNE", "NE", "ENE", 
	"E", "ESE", "SE", "SSE", 
	"S", "SSW", "SW", "WSW", 
	"W", "WNW", "NW", "NNW");

var langWindCalm = 'Calm';
var langGustNone = 'None';
var langWindFrom = 'Wind from '; /* used on alt/title tags on wind direction arrow*/

var langBaroRising = 'Rising %s '; /* used for trend arrow alt/title tags .. %s marks where value will be placed */
var langBaroFalling = 'Falling %s ';
var langBaroPerHour = '/hour.'; /* will be assembled as rising/falling + value + uom + perhour text */
var langBaroPerHr = '/hr'; /* --- Added by Vouhead --- */

var langThermoCurrently = 'Currently: '; /* used on alt/title tags for thermometer */
var langThermoMax     = 'Max: ';
var langThermoMin     = 'Min: ';

var langTempRising = 'Warmer %s '; /* used for trend arrow alt/title tags .. %s marks where value will be placed */
var langTempFalling = 'Colder %s ';
var langTempLastHour = ' than last hour.';

var langTransLookup = new Object;  // storage area for key/value for current conditions translation

var langHeatWords = new Array (
'Unknown', 
'Extremely Hot', 'Very Hot', 'Uncomfortably Hot', 'Hot', 'Warm', 
'Comfortable', 
'Cool', 'Cold', 'Uncomfortably Cold', 'Very Cold', 'Extremely Cold' );

// -- end of language 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 updates = 0;		// update counter for limit by maxupdates
var lastajaxtimeformat = 'unknown'; //used to reset the counter when a real update is done
var doTooltip = 0;   // set to 1 to have ajaxed variable names appear as tooltips (except for graphics)

// handle setup options for units-of-measure and whether to show them at all
var uomTemp = '&deg;F';
var uomMoist = ' cb';  /* --- Added by Vouhead --- */
var uomWind = ' mph';
var uomBaro = ' inHg';
var uomRain = ' in';
var uomHeight = ' ft';
var dpBaro = 2;
var dpRain = 2;


function ajax_set_units( units ) {
  useunits = units;
  if (useunits != 'E') { // set to metric
	uomTemp = '&deg;C';
	uomMoist = ' cb';  /* --- Added by Vouhead --- */
	uomWind = ' km/h';
	uomBaro = ' hPa';
	uomRain = ' mm';
	uomRainhr = ' mm/hr'; /* --- Added by Vouhead --- */ 
	uomHeight = ' m';
	dpBaro = 1;
	dpRain = 1;
  }
  if(useKnots) { uomWind = ' kts'; }
  if(useMPS)   { uomWind = ' m/s'; }
  if(useMPH)   { uomWind = ' mph'; }
  if(useFeet)  { uomHeight = ' ft'; }
  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();
	 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;
		  if ( doTooltip ) { element.setAttribute("title",'AJAX tag '+name); }
		  element.innerHTML =  value; // moved inside to fix flashing issue (Jim at jcweather.us)
		}
}

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 windDirLang ($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
{
   return langWindDir[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
	"night_clear.gif",         //  1 imageclearnight.visible
	"day_partly_cloudy.gif",   //  2 imagecloudy.visible
	"day_partly_cloudy.gif",   //  3 imagecloudy2.visible
	"night_partly_cloudy.gif", //  4 imagecloudynight.visible
	"day_clear.gif",           //  5 imagedry.visible
	"fog.gif",                 //  6 imagefog.visible
	"haze.gif",                //  7 imagehaze.visible
	"day_heavy_rain.gif",      //  8 imageheavyrain.visible
	"day_mostly_sunny.gif",    //  9 imagemainlyfine.visible
	"mist.gif",                // 10 imagemist.visible
	"fog.gif",                 // 11 imagenightfog.visible
	"night_heavy_rain.gif",    // 12 imagenightheavyrain.visible
	"night_cloudy.gif",        // 13 imagenightovercast.visible
	"night_rain.gif",          // 14 imagenightrain.visible
	"night_light_rain.gif",    // 15 imagenightshowers.visible
	"night_snow.gif",          // 16 imagenightsnow.visible
	"night_tstorm.gif",        // 17 imagenightthunder.visible
	"day_cloudy.gif",          // 18 imageovercast.visible
	"day_partly_cloudy.gif",   // 19 imagepartlycloudy.visible
	"day_rain.gif",            // 20 imagerain.visible
	"day_rain.gif",            // 21 imagerain2.visible
	"day_light_rain.gif",      // 22 imageshowers2.visible
	"day_sleet.gif",           // 23 imagesleet.visible
	"day_sleet.gif",           // 24 imagesleetshowers.visible
	"day_snow.gif",            // 25 imagesnow.visible
	"day_snow.gif",            // 26 imagesnowmelt.visible
	"day_snow.gif",            // 27 imagesnowshowers2.visible
	"day_clear.gif",           // 28 imagesunny.visible
	"day_tstorm.gif",          // 29 imagethundershowers.visible
	"day_tstorm.gif",          // 30 imagethundershowers2.visible
	"day_tstorm.gif",          // 31 imagethunderstorms.visible
	"tornado.gif",             // 32 imagetornado.visible
	"windy.gif",               // 33 imagewindy.visible
	"day_partly_cloudy.gif",   // 34 stopped rainning
	"windyrain.gif"            // 35 windy/rain (new with V2.11)
	);					

  if (iconWD >= 0 && iconWD <= 35) { 
    return ("<img src=\"" + imagedir + "/" + $iconList[iconWD] + "\" " +
				"width=\"25\" height=\"25\" alt=\"Current condition icon\" />" );
  } else {
	return '';
  }

}

function ajax_wxIconJPG ( iconWD ) { 
// perform a lookup and return the graphic for the condition icon (using NWS icons)
  $iconList = new Array(
	"skc.jpg",          //  0 imagesunny.visible
	"nskc.jpg",         //  1 imageclearnight.visible
	"bkn.jpg",          //  2 imagecloudy.visible
	"sct.jpg",          //  3 imagecloudy2.visible
	"nbkn.jpg",         //  4 imagecloudynight.visible
	"sct.jpg",          //  5 imagedry.visible
	"fg.jpg",           //  6 imagefog.visible
	"hazy.jpg",         //  7 imagehaze.visible
	"ra.jpg",           //  8 imageheavyrain.visible
	"few.jpg",          //  9 imagemainlyfine.visible
	"mist.jpg",         // 10 imagemist.visible
	"nfg.jpg",          // 11 imagenightfog.visible
	"nra.jpg",          // 12 imagenightheavyrain.visible
	"novc.jpg",         // 13 imagenightovercast.visible
	"nra.jpg",          // 14 imagenightrain.visible
	"nshra.jpg",        // 15 imagenightshowers.visible
	"nsn.jpg",          // 16 imagenightsnow.visible
	"ntsra.jpg",        // 17 imagenightthunder.visible
	"ovc.jpg",          // 18 imageovercast.visible
	"bkn.jpg",          // 19 imagepartlycloudy.visible
	"ra.jpg",           // 20 imagerain.visible
	"ra.jpg",           // 21 imagerain2.visible
	"shra.jpg",         // 22 imageshowers2.visible
	"ip.jpg",           // 23 imagesleet.visible
	"ip.jpg",           // 24 imagesleetshowers.visible
	"sn.jpg",           // 25 imagesnow.visible
	"sn.jpg",           // 26 imagesnowmelt.visible
	"sn.jpg",           // 27 imagesnowshowers2.visible
	"skc.jpg",          // 28 imagesunny.visible
	"scttsra.jpg",      // 29 imagethundershowers.visible
	"hi_tsra.jpg",      // 30 imagethundershowers2.visible
	"tsra.jpg",         // 31 imagethunderstorms.visible
	"nsvrtsra.jpg",     // 32 imagetornado.visible
	"wind.jpg",         // 33 imagewindy.visible
	"ra1.jpg",          // 34 stopped rainning
	"windyrain.jpg"     // 35 windy/rain (new with V2.11)
	);					

  if (iconWD >= 0 && iconWD <= 35) { 
    return ("<img src=\"" + imagedir + "/" + $iconList[iconWD] + "\" " +
				"width=\"55\" height=\"58\" 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' || useMPH ) { // 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 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' || useFeet ) { // 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_number ( wind ) { 
// return a number 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("0");
}

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(1 hour)

// Change Rates
// Rapidly: =.06 inHg; 1.5 mm Hg; 2 hPa; 2 mb
// Slowly: =.02 inHg; 0.5 mm Hg; 0.4 hPa; 0.7 mb
// Normal: = 1.4 hPa;

// 7 conditions --- /* --- Added 2 conditions by Vouhead --- */ 
// Rising Rapidly
// Rising /* ------------ Added --- */ 
// Rising Slowly
// Steady
// Falling Slowly
// Falling /* ----------- Added --- */ 
// Falling Rapidly

// Page 52 of the PDF Manual
// http://www.davisnet.com/product_documents/weather/manuals/07395.234-VP2_Manual.pdf    
// "Steady", "Rising Slowly", "Rising", "Rising Rapidly", "Falling Slowly", "Falling", "Falling Rapidly"
// figure out a text value for barometric pressure trend

   if ((btrnd >= -0.1) && (btrnd <= 0.1)) { return(langBaroTrend[0]); }
   if ((btrnd > 0.1) && (btrnd <= 1.0)) { return(langBaroTrend[1]); }
   if ((btrnd > 1.0) && (btrnd < 2.0)) { return(langBaroTrend[2]); }
   if (btrnd >= 2.0) { return(langBaroTrend[3]); }
   if ((btrnd < -0.1) && (btrnd >= -1.0)) { return(langBaroTrend[4]); }
   if ((btrnd < -1.0) && (btrnd > -2.0)) { return(langBaroTrend[5]); }
   if (btrnd <= -2.0) { return(langBaroTrend[6]); }
  return(btrnd);
}

// ---------------------------------------------- Start of Barotrenarrow code --- by vouhead -----
function ajax_get_barotrendarrow(batrndarw) {
   if ((batrndarw >= -0.1) && (batrndarw <= 0.1)) { return(trendarrow0); } 
   if ((batrndarw > 0.1) && (batrndarw <= 1.0)) { return(trendarrow1); }    
   if ((batrndarw > 1.0) && (batrndarw < 2.0)) { return(trendarrow2); }    
   if (batrndarw >= 2.0) { return(trendarrow3); }                       
   if ((batrndarw < -0.1) && (batrndarw >= -1.0)) { return(trendarrow4); }    
   if ((batrndarw < -1.0) && (batrndarw > -2.0)) { return(trendarrow5); }  
   if (batrndarw <= -2.0) { return(trendarrow6); }                     
  return(batrndarw);
}
// ---------------------------------------------- End of Barotrendarrow code

// ---------------------------------------------- Start of Barotrendimage code --- by vouhead -----
function ajax_get_barotrendimg(batrnd) {   
   if ((batrnd >= -0.1) && (batrnd <= 0.1)) { return(trendimage0); } 
   if ((batrnd > 0.1) && (batrnd <= 0.4)) { return(trendimage1); }    
   if ((batrnd > 0.4) && (batrnd <= 0.7)) { return(trendimage2); }
   if ((batrnd > 0.7) && (batrnd <= 1.1)) { return(trendimage3); }
   if ((batrnd > 1.1) && (batrnd <= 1.4)) { return(trendimage4); }    
   if ((batrnd > 1.4) && (batrnd <= 1.8)) { return(trendimage5); } 
   if ((batrnd > 1.8) && (batrnd <= 2.0)) { return(trendimage6); }          
   if (batrnd > 2.0) { return(trendimage6out); }                       
   if ((batrnd < -0.1) && (batrnd >= -0.4)) { return(trendimage7); }    
   if ((batrnd < -0.4) && (batrnd >= -0.7)) { return(trendimage8); } 
   if ((batrnd < -0.7) && (batrnd >= -1.1)) { return(trendimage9); }  
   if ((batrnd < -1.1) && (batrnd >= -1.4)) { return(trendimage10); }  
   if ((batrnd < -1.4) && (batrnd >= -1.8)) { return(trendimage11); }  
   if ((batrnd < -1.8) && (batrnd >= -2.0)) { return(trendimage12); }      
   if (batrnd < -2.0) { return(trendimage12out); }                     
  return(batrnd);
}
// ---------------------------------------------- End of Barotrendimage code

// ---------------------------------------------- Start of Baroimage code --- by vouhead -----
function ajax_get_baroimg(baro) {
   if (baro < 981.20) { return(baroimage0); }                         
   if ((baro >= 981.20) && (baro < 983.70)) { return(baroimage1); }   
   if ((baro >= 983.70) && (baro < 986.20)) { return(baroimage2); }    
   if ((baro >= 986.20) && (baro < 988.70)) { return(baroimage3); }   
   if ((baro >= 988.70) && (baro < 991.20)) { return(baroimage4); }   
   if ((baro >= 991.20) && (baro < 993.70)) { return(baroimage5); }
   if ((baro >= 993.70) && (baro < 996.20)) { return(baroimage6); }   
   if ((baro >= 996.20) && (baro < 998.70)) { return(baroimage7); }   
   if ((baro >= 998.70) && (baro < 1001.20)) { return(baroimage8); }   
   if ((baro >= 1001.20) && (baro < 1003.70)) { return(baroimage9); }   
   if ((baro >= 1003.70) && (baro < 1006.20)) { return(baroimage10); }   
   if ((baro >= 1006.20) && (baro < 1008.70)) { return(baroimage11); }   
   if ((baro >= 1008.70) && (baro < 1011.20)) { return(baroimage12); }   
   if ((baro >= 1011.20) && (baro < 1013.70)) { return(baroimage13); }    
   if ((baro >= 1013.70) && (baro < 1016.20)) { return(baroimage14); }   
   if ((baro >= 1016.20) && (baro < 1018.70)) { return(baroimage15); }   
   if ((baro >= 1018.70) && (baro < 1021.20)) { return(baroimage16); }
   if ((baro >= 1021.20) && (baro < 1023.70)) { return(baroimage17); }   
   if ((baro >= 1023.70) && (baro < 1026.20)) { return(baroimage18); }   
   if ((baro >= 1026.20) && (baro < 1028.70)) { return(baroimage19); }   
   if ((baro >= 1028.70) && (baro < 1031.20)) { return(baroimage20); }   
   if ((baro >= 1031.20) && (baro < 1033.70)) { return(baroimage21); }   
   if ((baro >= 1033.70) && (baro < 1036.20)) { return(baroimage22); }  
   if ((baro >= 1036.20) && (baro < 1038.70)) { return(baroimage23); }  
   if (baro >= 1038.70) { return(baroimage24); }                      
  return(baro);
}
// ---------------------------------------------- End of Baroimage code

function ajax_getUVrange ( uv ) { // code simplified by FourOhFour on wxforum.net
   var uvword = "Unspec.";
   if (uv <= 0) {
       uvword = langUVWords[0];
   } else if (uv < 3) {
       uvword = "<span style=\"border: dotted 1px; color: #700394; background-color: #6EAB24;\">&nbsp;"+langUVWords[1]+"&nbsp;</span>";
   } else if (uv < 6) {
       uvword = "<span style=\"border: dotted 1px; color: #700394; background-color: #F9F100;\">&nbsp;"+langUVWords[2]+"&nbsp;</span>";
   } else if (uv < 8) {
       uvword = "<span style=\"border: dotted 1px; color: #700394; background-color: #FC7216;\">&nbsp;"+langUVWords[3]+"&nbsp;</span>";
   } else if (uv < 11) {
       uvword = "<span style=\"border: dotted 1px; color: #700394; background-color: #E62621;\">&nbsp;"+langUVWords[4]+"&nbsp;</span>";
   } else {
       uvword = "<span style=\"border: dotted 1px; color: #E62621; background-color: #8E4A86;\">&nbsp;"+langUVWords[5]+"&nbsp;</span>";
   }
   return uvword;
} // end ajax_getUVrange function

   // ------------ Start of Burntime code --- by vouhead ----- 
 
function ajax_get_burnUVtime ( uv ) { 
   var uvword = "Unspec.";
   if (uv <= 0) {
       uvword = "<img src=vouhead-images/sun.gif + align=absmiddle >" +"&nbsp;</span>";
   } else if (uv <= 1) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunS.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[0]+"&nbsp;</span>";
   } else if (uv <= 2) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunS.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[1]+"&nbsp;</span>";
   } else if (uv <= 3) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunM.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[2]+"&nbsp;</span>";
   } else if (uv <= 4) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunM.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[3]+"&nbsp;</span>";
   } else if (uv <= 5) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunM.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[4]+"&nbsp;</span>";
   } else if (uv <= 6) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunM.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[5]+"&nbsp;</span>";
   } else if (uv <= 7) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunM.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[6]+"&nbsp;</span>";    
   } else if (uv <= 8) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunB.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[7]+"&nbsp;</span>";    
   } else if (uv <= 9) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunB.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #700394; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[8]+"&nbsp;</span>";    
   } else if (uv <= 10) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunB.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #FF0000; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[9]+"&nbsp;</span>";
   } else if (uv <= 11) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunB.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #FF0000; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[10]+"&nbsp;</span>";    
   } else if (uv <= 12) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunB.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #FF0000; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[11]+"&nbsp;</span>";    
   } else if (uv > 12) {
       uvword = "<a href=wxuv-1.php ><img src=vouhead-images/sunB.gif border=none align=absmiddle alt=" + langburntimeUVWords[13] + "></a>" + "<span style=\"border: dotted 1px; color: #FF0000; background-color: #B8DD22;\">&nbsp;"+langburntimeUVWords[12]+"&nbsp;</span>";                                        
   }
   return uvword;
} 
   // ------------- End of Burntime code 

   //======= Start of Sun icon next UV index code --- by vouhead -----
   
function ajax_get_UVsunimg ( solar,uv ) { 
   if ((solar == 0) && (uv == 0)) { return(UVsunimg01); }  
   if ((solar > 0) && (solar < 25) && (uv >= 0) && (uv < 1)) { return(UVsunimg02); }  
   if ((solar >= 25) && (solar < 50) && (uv >= 0) && (uv < 1)) { return(UVsunimg03); }  
   if ((solar >= 50) && (uv < 1)) { return(UVsunimg04); }  
   if ((solar > 0) && (uv >= 1) && (uv < 3)) { return(UVsunimg05); }  
   if ((solar > 0) && (uv >= 3) && (uv < 6)) { return(UVsunimg06); }  
   if ((solar > 0) && (uv >= 6) && (uv < 8)) { return(UVsunimg07); }  
   if ((solar > 0) && (uv >= 8) && (uv < 11)) { return(UVsunimg08); }  
   if ((solar > 0) && (uv >= 11))  { return(UVsunimg09); }  
} 
   //======= End of Sun icon in next UV index code
   
   // ------------ Start of ThunderAlert code --- by vouhead -----
   
   function ajax_get_ThunderAlert ( iconWD ) { 
   var Thunderword = "Unspec.";
   if (iconWD < 17) {
       Thunderword = "";
   } else if (iconWD == 17) {
       Thunderword = "<a href=wxlightning-sshot.php ><img src=vouhead-images/thunderalert.gif border=none align=absmiddle alt=" + 
       langthunderalertWords[1] + "></a>" + "<span style=\"border: dotted 1px; color: #FF0000; background-color: #FFBA00;\">&nbsp;" + 
       langthunderalertWords[0]+"&nbsp;</span>";
   } else if ((iconWD > 17) && (iconWD < 31)) {
       Thunderword = "";                                         
   } else if (iconWD == 31) {
       Thunderword = "<a href=wxlightning-sshot.php ><img src=vouhead-images/thunderalert.gif border=none align=absmiddle alt=" + 
       langthunderalertWords[1] + "></a>" + "<span style=\"border: dotted 1px; color: #FF0000; background-color: #FFBA00;\">&nbsp;" + 
       langthunderalertWords[0]+"&nbsp;</span>";
   } else if (iconWD > 31) {
       Thunderword = "";                                      
   }
   return Thunderword;   
} 
  // ------------- End of ThunderAlert code
  
  // ------------ Start of Hazardous Conditions code --- by vouhead -----
    // ------------ Start Values for Table tags
      // ------TEMP & TEMP+1,5m    
   function ajax_get_HZdsCondvlstmp ( temp,temp1,wind,humidity,humidity1 ) { 
   var HZdousCondtmp = "";
   // ---- FROST
   if (((temp < 1.0) && (temp >= 0.7)) && ((temp1 < 1.0) && (temp1 >= 0.7))) {
       HZdousCondtmp = langHZdousCondWords[5] + "<br/>";
   } else if (((temp < 0.7) && (temp >= 0.5)) && ((temp1 < 0.7) && (temp1 >= 0.5))) {
        HZdousCondtmp = langHZdousCondWords[6] + "<br/>";
   } else if (((temp < 0.5) && (temp > 0.1)) && ((temp1 < 0.5) && (temp1 > 0.1))) {
        HZdousCondtmp = langHZdousCondWords[7] + "<br/>";
   } else if ((temp > 0.1) && (temp1 <= 0.1)) {
        HZdousCondtmp = langHZdousCondWords[8] + "<br/>";
   } else if ((temp <= 0.1) && (temp1 <= 0.1)) {
        HZdousCondtmp = langHZdousCondWords[8] + "<br/>";
   // ---- HEATWAVE            
   } else if (((temp > 37.0) || (temp <= 39.0)) && (temp1 > 36.0) && (temp1 <= 38.0) && (wind < 30.0)) {
        HZdousCondtmp = langHZdousCondWords[9] + "<br/>";        
   } else if (((temp > 39.0) || (temp1 > 38.0)) && (wind > 2.0) && (wind < 10.0) && (humidity <= 40.0) && (humidity1 <= 40.0)) {
        HZdousCondtmp = langHZdousCondWords[10] + "<br/>";        
   } else if (((temp > 39.0) || (temp1 > 38.0)) && (wind > 2.0) && (wind < 10.0) && ((humidity > 40.0) || (humidity1 > 40.0))) {
        HZdousCondtmp = langHZdousCondWords[11] + "<br/>";                
   } else if (((temp > 39.0) || (temp1 > 38.0)) && (wind <= 2.0) && (humidity < 50.0) && (humidity1 < 50.0)) {
        HZdousCondtmp = langHZdousCondWords[12] + "<br/>";        
   } else if (((temp > 39.0) || (temp1 > 38.0)) && (wind <= 2.0) && ((humidity >= 50.0) && (humidity < 70.0) || (humidity1 >= 50.0) && (humidity1 < 70.0))) {
        HZdousCondtmp = langHZdousCondWords[13] + "<br/>";        
   } else if (((temp > 39.0) || (temp1 > 38.0)) && (wind <= 2.0) && (humidity >= 70.0) && (humidity1 >= 70.0)) {
        HZdousCondtmp = langHZdousCondWords[14] + "<br/>";        
   }
   return HZdousCondtmp;   
}

      // ------WIND
   function ajax_get_HZdsCondvlswnd ( wind,gust ) {
   var diffgustwind = gust - wind; 
   var HZdousCondwnd = "";
   if ((wind > 50.0) && (gust < 60.0)) {
       HZdousCondwnd = langHZdousCondWords[16] + "<br/>";
   } else if ((wind < 50.0) && (gust > 60.0) && (diffgustwind < 20.0)) {
        HZdousCondwnd = langHZdousCondWords[17] + "<br/>";
   } else if ((wind < 50.0) && (gust > 60.0) && (diffgustwind > 20.0)) {
        HZdousCondwnd = langHZdousCondWords[17] + "<br/>" + langHZdousCondWords[18] + "<br/>";
   } else if ((wind > 50.0) && (gust > 60.0) && (diffgustwind < 20.0)) {
        HZdousCondwnd = langHZdousCondWords[16] + "<br/>" + langHZdousCondWords[17] + "<br/>";
   } else if ((wind > 50.0) && (gust > 60.0) && (diffgustwind > 20.0)) {
        HZdousCondwnd = langHZdousCondWords[16] + "<br/>" + langHZdousCondWords[17] + "<br/>" + langHZdousCondWords[18] + "<br/>";
   }
   return HZdousCondwnd;   
}

      // ------RAIN
   function ajax_get_HZdsCondvlsrn ( rain,rainratehr ) {
   var HZdousCondrn = "";
   if ((rain > 20.0) && (rainratehr < 50.0)) {
       HZdousCondrn = langHZdousCondWords[20] + "<br/>";
   } else if ((rain < 20.0) && (rainratehr > 50.0)) {
        HZdousCondrn = langHZdousCondWords[21] + "<br/>";
   } else if ((rain > 20.0) && (rainratehr > 50.0)) {
        HZdousCondrn = langHZdousCondWords[20] + "<br/>" + langHZdousCondWords[21] + "<br/>";
   }
   return HZdousCondrn;   
}

      // ------UV
   function ajax_get_HZdsCondvlsuv ( uv ) {
   var HZdousConduv = "";
   if ((uv >= 10.0) && (uv <= 11.0)) {
       HZdousConduv = langHZdousCondWords[23] + "<br/>";
   } else if (uv > 11.0) {
        HZdousConduv = langHZdousCondWords[24] + "<br/>";
   }
   return HZdousConduv;   
}
 
    // ------------ End Values for Table tags
  
    // ------------ Start Titles to change in yellow+img
      // ------ In *Outlook* for changing to *Hazardous Conditions* 
   function ajax_get_HZdsCondtls ( temp,temp1,wind,gust,rain,rainratehr,uv ) {
   if ( // ---- FROST
      ((temp < 1.0) || (temp1 < 1.0)) ||
      ((temp < 0.7) || (temp1 < 0.7)) ||
      (((temp < 0.5) && (temp >= 0.1)) && ((temp1 < 0.5) && (temp1 >= 0.1))) ||
      ((temp > 0.1) && (temp1 < 0.1)) ||
      ((temp < 0.1) && (temp1 < 0.1)) ||
        // ---- HEATWAVE            
      (((temp > 37.0) || (temp <= 39.0)) && (temp1 > 36.0) && (temp1 <= 38.0) && (wind < 30.0)) ||
      (((temp > 39.0) || (temp1 > 38.0)) && (wind > 2.0) && (wind < 10.0) && (humidity <= 40.0) && (humidity1 <= 40.0)) ||
      (((temp > 39.0) || (temp1 > 38.0)) && (wind > 2.0) && (wind < 10.0) && ((humidity > 40.0) || (humidity1 > 40.0))) ||
      (((temp > 39.0) || (temp1 > 38.0)) && (wind <= 2.0) && (humidity < 50.0) && (humidity1 < 50.0)) ||
      (((temp > 39.0) || (temp1 > 38.0)) && (wind <= 2.0) && ((humidity >= 50.0) && (humidity < 70.0) || (humidity1 >= 50.0) && (humidity1 < 70.0))) ||
      (((temp > 39.0) || (temp1 > 38.0)) && (wind <= 2.0) && (humidity >= 70.0) && (humidity1 >= 70.0)) ||
       // ---- OTHERS
      (wind > 50.0) || (gust > 60.0) || (rain > 20.0) || (rainratehr > 25.0) || (uv >= 10.0)) {
      return ("<table width=\"100%\"  hight=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr>" +
              "<td style=\"font-size: 100%; background-color: #F2EE37; border: 1px dotted red; text-align:center\">" +
              "<img src=ajax-images/warningL.gif border=none align=absmiddle ><span style=\" font-size: 100%; color: red; \">" + 
              langHZdousCondWords[0] + "</span></td></tr></table>");
   } else {
	    return ("<span style=\" color: #F2EE37; \">" + langHZdousCondWords[1] + "</span>");
   }
}

      // ------ In *Conditions / Temp. (10m)*  
   function ajax_get_HZdsCondtls1 ( temp,temp1,wind,gust,rain,rainratehr,uv ) { 
   if (temp < 1.0) {
      return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[2] + "/" + langHZdousCondWords[3] + langHZdousCondWords[4] + 
              "</span><img src=ajax-images/warningtempLow.gif border=none align=absmiddle >");
   } else if (temp > 37.0) {
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[2] + "/" + langHZdousCondWords[3] + langHZdousCondWords[4] + 
              "</span><img src=ajax-images/warningtempHi.gif border=none align=absmiddle >");
   } else if ((wind > 70.0) || (gust > 80.0) || (rain > 20.0) || (rainratehr > 50.0) || (uv >= 10.0)) {
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[2] + "</span><span style=\" font-size: 100%; color: F2EE37; \">&nbsp;/&nbsp;" + 
              langHZdousCondWords[3] + "&nbsp;" + langHZdousCondWords[4] + "</span>");
   } else {
	     return ("<span style=\" color: #F2EE37; \">" + langHZdousCondWords[2] + "&nbsp;/&nbsp;" + langHZdousCondWords[3] + 
	             "&nbsp;" + langHZdousCondWords[4] + "</span>");
   }
} 

      // ------ In *Temperature (1,5 m)*
   function ajax_get_HZdsCondtls1a ( temp1 ) { 
   var diffgustwind = gust - wind;
   if (temp1 < 1.0) {
      return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[25] + "</span><img src=ajax-images/warningtempLow.gif border=none align=absmiddle >");
   } else if (temp1 > 36.0) {
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[25] + "</span><img src=ajax-images/warningtempHi.gif border=none align=absmiddle >");
   } else {
	     return ("<span style=\" color: #F2EE37; \">" + langHZdousCondWords[25] + "</span>");
   }
}  
 
      // ------ In *Wind*
   function ajax_get_HZdsCondtls2 ( wind,gust ) { 
   var diffgustwind = gust - wind;
   if ((wind > 50.0) && (gust < 60.0)) {
      return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[15] + "</span><img src=ajax-images/warningwind.gif border=none align=absmiddle >");
   } else if ((wind < 50.0) && (gust > 60.0) && (diffgustwind < 20.0)) {
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[15] + "</span><img src=ajax-images/warninggust.gif border=none align=absmiddle >");
   } else if ((wind < 50.0) && (gust > 60.0) && (diffgustwind > 20.0)){
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[15] + "</span><img src=ajax-images/warninggustdiff.gif border=none align=absmiddle >");
   } else if ((wind > 50.0) && (gust > 60.0) && (diffgustwind < 20.0)) {
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[15] + "</span><img src=ajax-images/warningwindgust.gif border=none align=absmiddle >");
   } else if ((wind > 50.0) && (gust > 60.0) && (diffgustwind > 20.0)) {
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[15] + "</span><img src=ajax-images/warningwindgustdiff.gif border=none align=absmiddle >");              
   } else {
	     return ("<span style=\" color: #F2EE37; \">" + langHZdousCondWords[15] + "</span>");
   }
}  

      // ------ In *Rain*
   function ajax_get_HZdsCondtls3 ( rain,rainratehr ) { 
   if ((rain > 20.0) && (rainratehr < 25.0)) {
      return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[19] + "</span><img src=ajax-images/warningrain.gif border=none align=absmiddle >");
   } else if ((rain < 20.0) && (rainratehr > 25.0)) {
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[19] + "</span><img src=ajax-images/warningrainrate.gif border=none align=absmiddle >");
   } else if ((rain > 20.0) && (rainratehr > 25.0)) {
       return ("<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[19] + "</span><img src=ajax-images/warningrainrainrate.gif border=none align=absmiddle >");
   } else {
	     return ("<span style=\" color: #F2EE37; \">" + langHZdousCondWords[19] + "</span>");
   }
}  

      // ------ In *UV Index* 
   function ajax_get_HZdsCondtls4 ( uv ) { 
   if ((uv >= 10.0) && (uv <= 11.0)){
      return ("<img src=ajax-images/warninguv10.gif border=none align=absmiddle ><span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[22] + "</span>&nbsp;<span class=\"ajax\" id=\"ajaxUVsunimg\"><a href=\"./wxuv-1.php\">" + 
              "<img src=\"./ajax-images/uvNO.gif\" width=\"28\" height=\"22\" align=\"absmiddle\" border=\"0\" alt=" + langburntimeUVWords[13] + 
              " title=" + langburntimeUVWords[13] + "></a></span>");
   } else if (uv > 11.0) {
       return ("<img src=ajax-images/warninguv11.gif border=none align=absmiddle ><span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[22] + "</span>&nbsp;<span class=\"ajax\" id=\"ajaxUVsunimg\"><a href=\"./wxuv-1.php\">" + 
              "<img src=\"./ajax-images/uvNO.gif\" width=\"28\" height=\"22\" align=\"absmiddle\" border=\"0\" alt=" + langburntimeUVWords[13] + 
              " title=" + langburntimeUVWords[13] + "></a></span>");
   } else {
	     return ("<span style=\" color: #F2EE37; \">" + langHZdousCondWords[22] + "</span>&nbsp;<span class=\"ajax\" id=\"ajaxUVsunimg\"><a href=\"./wxuv-1.php\">" + 
              "<img src=\"./ajax-images/uvNO.gif\" width=\"28\" height=\"22\" align=\"absmiddle\" border=\"0\" alt=" + langburntimeUVWords[13] + 
              " title=" + langburntimeUVWords[13] + "></a></span>");
   }
}  

      // ------ In *Pressure & Humidity (10m)* for Pressure 
   function ajax_get_HZdsCondtls5 ( pressure,pressuretrend ) { 
   if ((pressure > 1000.0) && (pressure <= 1040.0) && (pressuretrend < -2)) {
      return ("<img src=ajax-images/warningprs1.gif border=none align=absmiddle >" +
              "<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[26] + "</span><span style=\" color: #F2EE37; \">&nbsp;&&nbsp;" + langHZdousCondWords[27] + "</span>");
   } else if ((pressure >= 980.0) && (pressure <= 1000.0) && (pressuretrend < -2)) {
       return ("<img src=ajax-images/warningprs2.gif border=none align=absmiddle >" +
              "<span style=\" font-size: 100%; color: red; background-color: #F2EE37;\">" + 
              langHZdousCondWords[26] + "</span><span style=\" color: #F2EE37; \">&nbsp;&&nbsp;" + langHZdousCondWords[27] + "</span>");
   } else {
	     return ("<span style=\" color: #F2EE37; \">" + langHZdousCondWords[28] + "</span>");
   }
}  

    // ------------ End Titles to change in yellow+img
  
    // ------------ Start Table in *Outlook Table*
   function ajax_get_HZdsCondtbl ( temp,temp1,wind,gust,rain,rainratehr,uv ) {
   if ((temp < 1.0) || (temp1 < 1.0) || (temp > 37.0) || (temp1 > 36.0) || (wind > 50.0) || (gust > 60.0) || (rain > 20.0) || (rainratehr > 25.0) || (uv >= 10.0)){
      return ("<table width=\"100%\"  cellpadding=\"0\" cellspacing=\"0\"><tr><td style=\"font-size: 8pt; color: red; background-color: #F2EE37;" + 
              "border: 1px dotted red; text-align:left\">"  + HZdousCondtmp + HZdousCondwnd + HZdousCondrn + HZdousConduv + "</td></tr></table>");
  } else {
	    return  "";
  }
}  
    // ------------ End Table in *Outlook Table*
  // ------------- End of Hazardous Conditions code

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

// function to add colored heatColorWord by Mike Challis
// final version 1.00 
function heatColor(temp,WindChill,Humidex) {
  var hcWord = langHeatWords[0];
  if (temp > 32 && Humidex > 29) {
  if (Humidex > 54) { return ('<span style="border: dotted 1px; color: #F2EE37; background-color: #FF0000;">&nbsp;'+langHeatWords[1]+'&nbsp;</span>'); }
  if (Humidex > 45) { return ('<span style="border: dotted 1px; color: #F2EE37; background-color: #FF6868;">&nbsp;'+langHeatWords[2]+'&nbsp;</span>'); }
  if (Humidex > 39) { return ('<span style="border: dotted 1px; color: #F2EE37; background-color: #FF8900;">&nbsp;'+langHeatWords[3]+'&nbsp;</span>'); }
  if (Humidex > 29) { return ('<span style="border: dotted 1px; color: #700394; background-color: #FDA844;">&nbsp;'+langHeatWords[4]+'&nbsp;</span>'); }
 } else if (WindChill < 16 ) {
  if (WindChill < -12) { return ('<span style="border: dotted 1px; color: #F2EE37; background-color: #160290;">&nbsp;'+langHeatWords[11]+'&nbsp;</span>'); }
  if (WindChill < -7)  { return ('<span style="border: dotted 1px; color: #F2EE37; background-color: #0600FF;">&nbsp;'+langHeatWords[10]+'&nbsp;</span>'); }
  if (WindChill < -1)  { return ('<span style="border: dotted 1px; color: #F2EE37; background-color: #006CFF;">&nbsp;'+langHeatWords[9]+'&nbsp;</span>'); }
  if (WindChill < 8)   { return ('<span style="border: dotted 1px; color: #700394; background-color: #74C4FB;">&nbsp;'+langHeatWords[8]+'&nbsp;</span>'); }
  if (WindChill < 16)  { return ('<span style="border: dotted 1px; color: #700394; background-color: #C5E5FB;">&nbsp;'+langHeatWords[7]+'&nbsp;</span>'); }
 }  else if (WindChill >= 16 && temp <= 32) {
  if (temp < 26) { return ('<span style="border: dotted 1px; color: #700394; background-color: #6EAB24;">&nbsp;'+langHeatWords[6]+'&nbsp;</span>'); }
  if (temp <= 32) { return ('<span style="border: dotted 1px; color: #700394; background-color: #FCC482;">&nbsp;'+langHeatWords[5]+'&nbsp;</span>'); }
  }
  return hcWord;
}

// Mike Challis' counter function (adapted by Ken True)
//
function ajax_countup() {
 var element = document.getElementById("ajaxcounter");
 if (element) {
  element.innerHTML = counterSecs;
  counterSecs++;
 }
}

function ucFirst ( str ) {
   return str.substr(0,1).toUpperCase() + str.substr(1,str.length);
}
//
// slice and dice the clientraw[49] for possible translation of current weather
//
function ajaxFixupCondition( rawcond ) {

  var cond = rawcond;
  cond = cond.replace(/_/gm,' ');  // replace any _ with blank.
  cond = cond.replace(/[\r\n]/gm,'');  // remove embedded CR and/or LF
  var conds = cond.split('/');  // split up the arguments.
  var tstr = '';
  for (var i = 0;i<conds.length;i++) {
    var t = conds[i];
	t = t.toLowerCase();
	t = ucFirst(t);
    t = t.replace(/\s+$/,'');  // trim trailing blanks
	if(langTransLookup[t]) { 
	  conds[i] = langTransLookup[t];
	} else {
	  conds[i] = t;
	}
  }
  if (conds[0].length == 0) { conds.splice(0,1);  } // remove blank entry
  if (conds[0] == conds[2]) { conds.splice(2,1); } // remove duplicate last entry
  
  return(conds.join(', '));


}

// ------------------------------------------------------------------------------------------
//  main function.. read clientraw.txt and format <span class="ajax" id="ajax..."></span> areas
// ------------------------------------------------------------------------------------------
function ajaxLoader(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 clientraw = x.responseText.split(' ');
	// now make sure we got the entire clientraw.txt  -- thanks to Johnnywx
	// valid clientraw.txt has '12345' at start and '!!' at end of record
	var wdpattern=/\d+\.\d+.*!!/; // looks for '!!nn.nn!!' version string 
	// If we have a valid clientraw file AND updates is < maxupdates
	if(clientraw[0] == '12345' && wdpattern.test(x.responseText) && 
	    ( updates <= maxupdates || maxupdates > 0  ) ) {
		if (maxupdates > 0 ) {updates++; } // increment counter if needed

		//Temperature
		temp = convertTemp(clientraw[4]);
		set_ajax_obs("ajaxtemp", temp.toFixed(1) + uomTemp);
		set_ajax_obs("ajaxtempNoU", temp.toFixed(1));
		set_ajax_obs("gizmotemp", temp.toFixed(1) + uomTemp);
		set_ajax_obs("ajaxbigtemp",temp.toFixed(0) + uomTemp);

		templast = convertTemp(clientraw[90]);
		temparrow = ajax_genarrow(temp, templast, '', 
			 langTempRising+uomTemp+langTempLastHour,
			 langTempFalling+uomTemp+langTempLastHour,1)
		
		set_ajax_obs("ajaxtemparrow",temparrow); 
		set_ajax_obs("gizmotemparrow",temparrow); 
		   
	    temprate = temp - templast;
		temprate = temprate.toFixed(1);
//		if (temprate > 0.0) { temprate = '+' + temprate;} // add '+' for positive rates //*** EXCLUDET ---- by Vouhead -----
		set_ajax_obs("ajaxtemprate",temprate + uomTemp);
		set_ajax_obs("gizmotemprate",temprate + uomTemp);

		tempmax = convertTemp(clientraw[46]);
		set_ajax_obs("ajaxtempmax",tempmax.toFixed(1) + uomTemp);

		tempmin = convertTemp(clientraw[47]);
		set_ajax_obs("ajaxtempmin",tempmin.toFixed(1) + uomTemp);
		
		thermometerstr = langThermoCurrently +  + temp.toFixed(1) + uomTemp + 
		  ", " + langThermoMax + tempmax.toFixed(1) + uomTemp +
		  ", " + langThermoMin + tempmin.toFixed(1) + uomTemp;

		set_ajax_obs("ajaxthermometer",
			"<img src=\"" + thermometer + "?t=" + temp.toFixed(1) + "\" " +
				"width=\"54\" height=\"170\" " +
				"alt=\"" + thermometerstr + "\" " +
				"title=\"" + thermometerstr + "\" />" );
				
		//Temperature Extra Sensor 1 (1,5m) /* --- Added by Vouhead --- */
		temp1 = convertTemp(clientraw[20]);
		set_ajax_obs("ajaxtemp1", temp1.toFixed(1) + uomTemp);

		//Humidity ...
		humidity = clientraw[5];
		set_ajax_obs("ajaxhumidity",humidity);
		set_ajax_obs("gizmohumidity",humidity);
		
		hummax = clientraw[163]; /* --- Added by Vouhead --- */
		set_ajax_obs("ajaxhummax",hummax);

		hummin = clientraw[164]; /* --- Added by Vouhead --- */
		set_ajax_obs("ajaxhummin",hummin);
		// ((sorry.. no min/max data for humidity available in clientraw.txt)) ? vouhead
		
		//Humidity Extra Sensor 1 (1,5m) /* --- Added by Vouhead --- */
		humidity1 = clientraw[26];
		set_ajax_obs("ajaxhumidity1",humidity1);
		
		//Leaf Wetness  (0,5m) /* --- Added by Vouhead --- */
		leafwetness = clientraw[156];
		set_ajax_obs("ajaxleafwetness",leafwetness);
		
		//Soil Temp&Moisture /* --- Added by Vouhead --- */
		//Soil Temp (-10cm) 		
		soiltemp = clientraw[14];
		set_ajax_obs("ajaxsoiltemp",soiltemp + uomTemp);
		//Soil Temp (-50cm) 
		soiltemp1 = clientraw[22];
		set_ajax_obs("ajaxsoiltemp1",soiltemp1 + uomTemp);
		//Soil Moist (-10cm) 	
		soilmoist = clientraw[157];
		set_ajax_obs("ajaxsoilmoist",soilmoist + uomMoist);
		//Soil Moist (-50cm) ----NO DATA NOW in clientraw ----- 
		//soilmoist1 = clientraw[---]; ----NO DATA NOW in clientraw -----
		//set_ajax_obs("ajaxsoilmoist1",soilmoist1 + uomMoist); ----NO DATA NOW in clientraw -----
		
		//Dewpoint ...
		dew = convertTemp(clientraw[72]);
		set_ajax_obs("ajaxdew",dew.toFixed(1) + uomTemp);
		set_ajax_obs("gizmodew",dew.toFixed(1) + uomTemp);
		dewmin = convertTemp(clientraw[139]);
		set_ajax_obs("ajaxdewmin",dewmin.toFixed(1) + uomTemp);
		dewmax = convertTemp(clientraw[138]);
		set_ajax_obs("ajaxdewmax",dewmax.toFixed(1) + uomTemp);

		// Humidex
		humidex = convertTemp(clientraw[45]);
		set_ajax_obs("ajaxhumidex",humidex.toFixed(1) + uomTemp);
		humidexmin = convertTemp(clientraw[76]);
		set_ajax_obs("ajaxhumidexmin",humidexmin.toFixed(1) + uomTemp);
		humidexmax = convertTemp(clientraw[75]);
		set_ajax_obs("ajaxhumidexmax",humidexmax.toFixed(1) + uomTemp);

		//  WindChill
		windchill = convertTemp(clientraw[44]);
		set_ajax_obs("ajaxwindchill",windchill.toFixed(1) + uomTemp);
		windchillmin = convertTemp(clientraw[78]);
		set_ajax_obs("ajaxwindchillmin",windchillmin.toFixed(1) + uomTemp);
		windchillmax = convertTemp(clientraw[77]);
		set_ajax_obs("ajaxwindchillmax",windchillmax.toFixed(1) + uomTemp);

		// Heat Index
		heatidx = convertTemp(clientraw[112]);
		set_ajax_obs("ajaxheatidx",heatidx.toFixed(1) + uomTemp);
		heatidxmin = convertTemp(clientraw[111]);
		set_ajax_obs("ajaxheatidxmin",heatidxmin.toFixed(1) + uomTemp);
		heatidxmax = convertTemp(clientraw[110]);
		set_ajax_obs("ajaxheatidxmax",heatidxmax.toFixed(1) + uomTemp);

		// FeelsLike
		temp = clientraw[4]; // note.. temp in C
        if (temp <= 16.0 ) {
		  feelslike = clientraw[44]; //use WindChill
		} else if (temp >=27.0) {
		  feelslike = clientraw[45]; //use Humidex
		} else {
		  feelslike = temp;   // use temperature
		}
		feelslike  = Math.round(convertTemp(feelslike));
        set_ajax_obs("ajaxfeelslike",feelslike + uomTemp);

		// # mike challis added heatColorWord feature
		var heatColorWord = heatColor(clientraw[4],clientraw[44],clientraw[45]);
		set_ajax_obs("ajaxheatcolorword",heatColorWord);
		
		// Apparent temperature
		apparenttemp = convertTemp(clientraw[130]);
		set_ajax_obs("ajaxapparenttemp",apparenttemp.toFixed(1) + uomTemp);
		apparenttempmin = convertTemp(clientraw[136]);
		set_ajax_obs("ajaxapparenttempmin",apparenttempmin.toFixed(1) + uomTemp);
		apparenttempmax = convertTemp(clientraw[137]);
		set_ajax_obs("ajaxapparenttempmax",apparenttempmax.toFixed(1) + uomTemp);
		
		//Pressure...
		pressure = convertBaro(clientraw[6]);
		set_ajax_obs("ajaxbaro",pressure.toFixed(dpBaro) + uomBaro);
		set_ajax_obs("ajaxbaroNoU",pressure.toFixed(dpBaro));
		set_ajax_obs("gizmobaro",pressure.toFixed(dpBaro) + uomBaro);
		pressuretrend = convertBaro(clientraw[50]);
		pressuretrend = pressuretrend.toFixed(dpBaro+1);
		if (pressuretrend > 0.0) {pressuretrend = '+' + pressuretrend; } // add '+' to rate
		set_ajax_obs("ajaxbarotrend",pressuretrend + uomBaro + langBaroPerHr); /* --- Added langBaroPerHr by Vouhead --- */
		set_ajax_obs("gizmobarotrend",pressuretrend + uomBaro);
		set_ajax_obs("ajaxbaroarrow",
		   ajax_genarrow(pressure, pressure-pressuretrend, '', 
			 langBaroRising+uomBaro+langBaroPerHour,
			 langBaroFalling+uomBaro+langBaroPerHour,2)
			 );	
		barotrendtext = ajax_get_barotrend(clientraw[50]);
		set_ajax_obs("ajaxbarotrendtext",barotrendtext + ' ' + langBaroWith);  /* --- Added langBaroWith by Vouhead --- */
//		set_ajax_obs("ajaxbarotrendtext",barotrendtext); 
		set_ajax_obs("gizmobarotrendtext",barotrendtext);

		barotrendarrow = ajax_get_barotrendarrow(clientraw[50]);
		set_ajax_obs("ajaxbarotrendarw",barotrendarrow);  /* --- Added barotrendarrow by Vouhead --- */
//		set_ajax_obs("gizmobarotrendarw",barotrendarrow);

		barotrendimg = ajax_get_barotrendimg(clientraw[50]);
		set_ajax_obs("ajaxbarotrendimg",barotrendimg);  /* --- Added barotrendimg by Vouhead --- */
//		set_ajax_obs("gizmobarotrendimg",barotrendimg);

		baroimage = ajax_get_baroimg(clientraw[6]);
		set_ajax_obs("ajaxbaroimage",baroimage);  /* --- Added baroimg by Vouhead --- */
//		set_ajax_obs("gizmobaroimage",baroimage);

		pressuremin = convertBaro(clientraw[132]);
		set_ajax_obs("ajaxbaromin",pressuremin.toFixed(dpBaro) + uomBaro);
		pressuremax = convertBaro(clientraw[131]);
		set_ajax_obs("ajaxbaromax",pressuremax.toFixed(dpBaro) + uomBaro);

        //Wind gust
		gust    = convertWind(clientraw[140]);
		maxgust = convertWind(clientraw[71]);
		if (maxgust > 0.0 ) {
		  set_ajax_obs("ajaxmaxgust",maxgust.toFixed(1) + uomWind);
		} else {
		  set_ajax_obs("ajaxmaxgust",'None');
		}

		//Windspeed ...
		wind = convertWind(clientraw[2]);
		beaufortnum = ajax_get_beaufort_number(clientraw[2]);
		set_ajax_obs("ajaxbeaufortnum",beaufortnum);
		set_ajax_obs("ajaxbeaufort",langBeaufort[beaufortnum]);

       //WIND DIRECTION ...
        val = windDir(clientraw[3]);
		valLang = windDirLang(clientraw[3]); /* to enable translations */

       if (wind > 0.0) {
		set_ajax_obs("ajaxwind",wind.toFixed(1) + uomWind);
		set_ajax_obs("ajaxwindNoU",wind.toFixed(1));
		set_ajax_obs("gizmowind",wind.toFixed(1) + uomWind);
		set_ajax_uom("ajaxwinduom",true);
	   } else {
		set_ajax_obs("ajaxwind",langWindCalm);
		set_ajax_obs("ajaxwindNoU",langWindCalm);
		set_ajax_obs("gizmowind",langWindCalm);
		set_ajax_uom("ajaxwinduom",false);
	   }
	   
	   if (gust > 0.0) {
		set_ajax_obs("ajaxgust",gust.toFixed(1) + uomWind);
		set_ajax_obs("ajaxgustNoU",gust.toFixed(1));
		set_ajax_obs("gizmogust",gust.toFixed(1) + uomWind);
		set_ajax_uom("ajaxgustuom",true);
	   } else {
		set_ajax_obs("ajaxgust",langGustNone);
		set_ajax_obs("ajaxgustNoU",langGustNone);
		set_ajax_obs("gizmogust",langGustNone);
		set_ajax_uom("ajaxgustuom",false);
	   }
	   
   	   if (gust > 0.0 || wind > 0.0) {
		windicon = 	"<img src=\"" + imagedir + "/" +  val + ".gif\" width=\"14\" height=\"14\" alt=\"" + 
		  langWindFrom + valLang + "\" title=\"" + langWindFrom + valLang + "\" /> ";
 		set_ajax_obs("ajaxwindicon",windicon);
		set_ajax_obs("gizmowindicon",windicon);
 		set_ajax_obs("ajaxwindiconwr",
		  "<img src=\"" + imagedir + "/" +wrName +  val + wrType + "\" width=\""+
		   wrWidth+"\" height=\""+wrHeight+"\" alt=\"" + 
		  langWindFrom + valLang + "\" title=\"" +langWindFrom + valLang + "\" /> ");
		set_ajax_obs("ajaxwinddir",valLang);
		set_ajax_obs("gizmowinddir",valLang);
	   } else {
 		set_ajax_obs("ajaxwindicon","");
 		set_ajax_obs("gizmowindicon","");
		set_ajax_obs("ajaxwinddir","");
		set_ajax_obs("gizmowinddir","");
		if (wrCalm != '') {
 		 set_ajax_obs("ajaxwindiconwr",
		  "<img src=\"" + imagedir + "/" + wrCalm + "\" width=\""+
		   wrWidth+"\" height=\""+wrHeight+"\" alt=\"" + 
		  langBeaufort[0] + "\" title=\"" + langBeaufort[0] + "\" /> ");
		}
	   }

		windmaxavg = convertWind(clientraw[113]);
		set_ajax_obs("ajaxwindmaxavg",windmaxavg.toFixed(1) + uomWind);
		
		windmaxgust = convertWind(clientraw[71]);
		set_ajax_obs("ajaxwindmaxgust",windmaxgust.toFixed(1) + uomWind);

		windmaxgusttime = clientraw[135];
		windmaxgusttime = windmaxgusttime.toLowerCase();
		windmaxgusttime = windmaxgusttime.replace( "_" , "");
		set_ajax_obs("ajaxwindmaxgusttime",windmaxgusttime);
		

		//  Solar Radiation
		solar    = clientraw[127] * 1.0;
		set_ajax_obs("ajaxsolar",solar.toFixed(0));

        solarpct = clientraw[34];
		set_ajax_obs("ajaxsolarpct",solarpct);
		
		// UV Index		
		uv       = clientraw[79];
		set_ajax_obs("ajaxuv",uv) ;
		set_ajax_obs("gizmouv",uv) ;

		uvword = ajax_getUVrange(uv);
		set_ajax_obs("ajaxuvword",uvword);
		set_ajax_obs("gizmouvword",uvword);
		
	 // ---- Start of Burntime code by vouhead 
	
		uvword = ajax_get_burnUVtime(uv); 
		set_ajax_obs("ajaxburnuvtime",uvword);
	
	 // ---- End of Burntime code

	 // ---- Start of UVsunimg code by vouhead    
	
		UVsunimg = ajax_get_UVsunimg(solar,uv); 
		set_ajax_obs("ajaxUVsunimg",UVsunimg + langburntimeUVWords[13] + "\" title=\"" + langburntimeUVWords[13] + "\" /></a>");
	
	 // ---- End of UVsunimg code
	 
	 // ---- Start of ThunderAlert code by vouhead		
		iconWD       = clientraw[48];		
		Thunderword = ajax_get_ThunderAlert(iconWD);
		set_ajax_obs("ajaxThunderword",Thunderword);
		set_ajax_obs("gizmoThunderword",Thunderword);
			
	 // ---- End of ThunderAlert code 
	
		//Rain ...
		rain = convertRain(clientraw[7]);
		set_ajax_obs("ajaxrain",rain.toFixed(dpRain) + uomRain);
		set_ajax_obs("ajaxrainNoU",rain.toFixed(dpRain));
		set_ajax_obs("gizmorain",rain.toFixed(dpRain) + uomRain);

		rainydy = convertRain(clientraw[19]);
		set_ajax_obs("ajaxrainydy",rainydy.toFixed(dpRain)+ uomRain);

		rainmo = convertRain(clientraw[8]);
		set_ajax_obs("ajaxrainmo",rainmo.toFixed(dpRain) + uomRain);

		rainyr = convertRain(clientraw[9]);
		set_ajax_obs("ajaxrainyr",rainyr.toFixed(dpRain) + uomRain);

		rainratehr = convertRain(clientraw[10]) * 60; // make per hour rate.
		set_ajax_obs("ajaxrainratehr",rainratehr.toFixed(dpRain+1) + uomRainhr);

		rainratemax = convertRain(clientraw[11]) * 60; // make per hour rate
		set_ajax_obs("ajaxrainratemax",rainratemax.toFixed(dpRain+1) + uomRainhr);

	 // ---- Start of Hazardous Conditions code by vouhead    
		HZdousCondtmp = ajax_get_HZdsCondvlstmp(temp,temp1,wind,humidity,humidity1);
		
		HZdousCondwnd = ajax_get_HZdsCondvlswnd(wind,gust);
		
		HZdousCondrn = ajax_get_HZdsCondvlsrn(rain,rainratehr);
		
		HZdousConduv = ajax_get_HZdsCondvlsuv(uv);		 		 

		HZdousCondtls = ajax_get_HZdsCondtls(temp,temp1,wind,gust,rain,rainratehr,uv); 
		set_ajax_obs("ajaxHZdousCondtls",HZdousCondtls);

		HZdousCondtls1 = ajax_get_HZdsCondtls1(temp,temp1,wind,gust,rain,rainratehr,uv); 
		set_ajax_obs("ajaxHZdousCondtls1",HZdousCondtls1);
		
		HZdousCondtls1a = ajax_get_HZdsCondtls1a(temp1); 
		set_ajax_obs("ajaxHZdousCondtls1a",HZdousCondtls1a);
		
		HZdousCondtls2 = ajax_get_HZdsCondtls2(wind,gust); 
		set_ajax_obs("ajaxHZdousCondtls2",HZdousCondtls2);
		
		HZdousCondtls3 = ajax_get_HZdsCondtls3(rain,rainratehr); 
		set_ajax_obs("ajaxHZdousCondtls3",HZdousCondtls3);
		
		HZdousCondtls4 = ajax_get_HZdsCondtls4(uv); 
		set_ajax_obs("ajaxHZdousCondtls4",HZdousCondtls4);

		HZdousCondtls5 = ajax_get_HZdsCondtls5(pressure,pressuretrend); 
		set_ajax_obs("ajaxHZdousCondtls5",HZdousCondtls5);

		HZdousCondtbl = ajax_get_HZdsCondtbl(temp,temp1,wind,gust,rain,rainratehr,uv); 
		set_ajax_obs("ajaxHZdousCondtbl",HZdousCondtbl);
		
	 // ---- End of Hazardous Conditions code 
	 
// ------------------------------------------------------------------------	 

		// Provides Date String Objects in the form of
		// ntime = HH:MM                as in 17:24
		// ndate = Mon DD, YYYY         as in Nov 14, 2007
		// tday  = 3 letter Abr of Day  as in Wed
		//
		// All combined you could end up with   Mon Nov 14, 2007
		// 
		// Uses clientraw elements:
		// Hour 29  Min 30  Day 35  Month 36  Year 141
		// Added 2007-11-14 by Kevin Reed TNETWeather.com
		//======================================================================
		ntime = clientraw[29] + ":" + clientraw[30];
		ndate = langMonths[ clientraw[36] -1 ].substring(0,3) + " " + clientraw[35] + " " + clientraw[141];
		ndate2 = clientraw[35] + "-" +langMonths[ clientraw[36] -1 ].substring(0,3) + "-" +  clientraw[141];
		myDate = new Date( langMonths[ clientraw[36] - 1 ] + " " + clientraw[35] + ", " + clientraw[141] );
		tday = langDays[myDate.getDay()];
		//
		set_ajax_obs("ajaxndate", ndate );
		set_ajax_obs("ajaxndate2",ndate2);
		set_ajax_obs("ajaxntime", ntime );
		set_ajax_obs("ajaxntimess", ntime + ":" + clientraw[31]);
		set_ajax_obs("ajaxdname", tday );

		// current date and time of observation in clientraw.txt
		ajaxtimeformat = clientraw[32];
		ajaxdateformat = clientraw[74];
		ajaxtimeformat = ajaxtimeformat.split('-')[1];
		ajaxtimeformat = ajaxtimeformat.replace( "_" , "");
		ajaxtimeformat = ajaxtimeformat.toLowerCase();

		set_ajax_obs("ajaxdatetime",ajaxdateformat + " " +ajaxtimeformat);
		set_ajax_obs("ajaxdate",ajaxdateformat);
		set_ajax_obs("ajaxtime",ajaxtimeformat);
		set_ajax_obs("gizmodate",ajaxdateformat);
		set_ajax_obs("gizmotime",ajaxtimeformat);
		
		if (lastajaxtimeformat != ajaxtimeformat) {
			counterSecs = 0;                      // reset timer
			lastajaxtimeformat = ajaxtimeformat; // remember this time
		}
		
		// current condition icon and description
		set_ajax_obs("ajaxconditionicon",
			ajax_wxIcon(clientraw[48])
			);

		set_ajax_obs("ajaxconditionicon2",
			ajax_wxIconJPG(clientraw[48])
			);


		currentcond = clientraw[49];
//		currentcond = currentcond.replace(/_/g,' ');
//		currentcond = currentcond.replace(/^\/Dry\//g,'');
		currentcond = currentcond.replace(/\\/g,', ');
//		currentcond = currentcond.replace(/\//g,', ');
        currentcond = ajaxFixupCondition(currentcond);
		set_ajax_obs("ajaxcurrentcond",currentcond);
		set_ajax_obs("gizmocurrentcond",currentcond);
		
		// cloud height
		cloudheight = clientraw[73];
		set_ajax_obs("ajaxcloudheight",convertHeight(cloudheight) + uomHeight);

//--- Start of Cloud Height graphic code ----

		stationAlt = 21; // your station altitude in meters if you want ASL (meters = ft / 3.2808399)
		temp = clientraw[ 4];
		dewp = clientraw[72];
		pres = convertBaro(clientraw[6]);
		wind = convertWind(clientraw[1]); // gust = clientraw[2]
		wdir = windDirLang(clientraw[3]);
		rain = convertRain(clientraw[7]);
		cloudheight = Math.max(0,(temp-dewp)/0.00802)*1.0 + stationAlt; // in meters
		altitude = (useunits=="E") ? Math.round(cloudheight*3.2808399) : Math.round(cloudheight);
		above = (stationAlt>0)? ' ASL' : ' AGL';
		cloudText = altitude.toString() + uomHeight + above;
		param = '?uom=' + useunits + '&alti=' + uomHeight + '&wind=' + uomWind + '&buster=' + altitude + pres + wind + wdir + rain;
		set_ajax_obs("ajaxcloudheightimg"
			,'<img src="cloud-base.php' + param
			+ '" alt="'    + cloudText
			+ '" title="'  + cloudText
			+ '" width="100" height="200" hspace="0" vspace="0" align="" border="0" style="" />');
			
//--- End of Cloud Height graphic code ----
		
		// now ensure that the indicator flashes on every AJAX fetch
        var element = document.getElementById("ajaxindicator");
		if (element) {
          element.style.color = flashcolor;
		}
        var element = document.getElementById("gizmoindicator"); // separate gizmo ajax variable
		if (element) {
          element.style.color = flashcolor;
		}
		if (maxupdates > 0 && updates > maxupdates-1) { /* chg indicator to pause message */
			set_ajax_obs("ajaxindicator",langPauseMsg);
		}
		set_ajax_obs('ajaxupdatecount',updates);       /* for test pages */
		set_ajax_obs('ajaxmaxupdatecount',maxupdates); /* for test pages */

 	  } // END if(clientraw[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);

//  reset the flash colors, and restart the update unless maxupdate limit is reached

    setTimeout("reset_ajax_color('')",flashtime); // change text back to default color 

	if ( (maxupdates == 0) || (updates < maxupdates-1)) {
      setTimeout("ajaxLoader(clientrawFile + '?' + new Date().getTime())", reloadTime); // get new data 
    }
  }
} // end ajaxLoader function

//element = document.getElementById("ajaxcounter");
//if (element) {
  window.setInterval("ajax_countup()", 1000); // run the counter for seconds since update
//}

// invoke when first loaded on page
if (! ajaxLoaderInBody) { ajaxLoader(clientrawFile + '?' + new Date().getTime(), reloadTime); }


// ]]>