// <![CDATA[

/*
WARNING - this has a few special mods to work BIGGEST graphic !!!

 beteljuice has adapted Ken Trues AJAX script so it can be used with:
  Cumulus 1.8.5  or higher
 beteljuice October 2008 
 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

 V1.0 open Jan 09
 
 The idea is you edit / add / modify for yourself ;-)
 for updates to this script, see - haven't decided yet
 announcements of new versions will be on - somewhere to be announced
 
 IMPORTANT *******************
 Your html page MUST have
 <div id="ajaxEND" style="display; none:"></div>
just before the closing </body> tag
 
*/


// -- begin settings --------------------------------------------------------------------------
var here = 'http://www.wheelocknet.net/betel/';  // URL PATH to the 'AJAX' directory (include trailing / )
var currdatFile = 'http://www.wheelocknet.net/cumulus/realtime.txt'; // URL location of realtime.txt 
var station_day = 0;	// when does your data 'day' begin - 0 = 00:00, 1 = 09:00
var station_alt = 209;	// height of baro Above Sea Level - METRES please !
var imagedir = 'ajax-images';  // place for wind arrows, rising/falling arrows, etc.
var flashcolor = '#00CC00'; // color to flash for changed observations RGB
var flashtime  = 1000;       // miliseconds to keep flash color on (2000 = 2 seconds);
var reloadTime = 10000;       // reload AJAX conditions every 10 seconds (= 10000 ms)
var maxupdates = 0;	         // Maximum Number of updates allowed (set to zero for unlimited)
                             // maxupdates * reloadTime / 1000 = number of seconds to update

// 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   = '.gif';      // extension of the graphic filename
var wrHeight = '58';        // windrose graphic height=
var wrWidth  = '58';        // windrose graphic width=
var wrCalm   = 'wr-calm.gif';  // set to full name of graphic for calm display ('wr-calm.gif')
// -- end of settings -------------------------------------------------------------------------

// -- language settings -- you don't need to customize this area if you are using English -----
// -- if you use the 'extras' there may be some additional work to do in the script ! - go investigate

var langPauseMsg = 'Updates paused - reload page to start'; // substitute this for ajaxindicator when
                             // maxupdates has been reached and updating paused.

var langDays = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var langMonths = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

// -----------------------------------------------------0-------1--------2-------3-------4------5-------6-------7-------8-------9	
var langDate_suffix = new Array ( "th.", "st.", "nd.", "rd.","th." ,"th.", "th.", "th.", "th.", "th.");	// eg. 1st 2nd 3rd etc. starts 0th ;-)

var langBaroTrend = new Array ( "Steady", "Rising Slowly", "Rising Rapidly", "Falling Slowly", "Falling Rapidly");

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 langBeaufort_desc = new Array ( /* Beaufort 0 to 12 DESCRIPTION in array */
 "Smoke rises vertically.<br />Tree leaves don't move.", "Smoke drift indicates wind direction.", "Wind felt on face. Leaves rustle.", "Leaves and twigs in constant motion.", "Dust and loose paper raised.<br />Small branches move.", "Small trees sway.", "Large branches move.<br />Wind whistles in wires.", "Whole trees move.<br />Walking affected.", "Twigs break off trees.<br />Walking difficult.", "Slight structural damage.<br />Branches break. <font color=\"red\">TAKE COVER</font>", "Considerable structural damage.<br />Trees uprooted.  <font color=\"red\">TAKE COVER</font>", "Widespread damage.<br /> <font color=\"red\">TAKE COVER</font>", "Severe and extensive damage.<br /> <font color=\"red\">TAKE COVER</font>"
);


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 langWindVerbose = new Array( /* can be used in text for wind direction */
	"North", "North-Northeast", "Northeast", "East-Northeast", 
	"East", "East-Southeast", "Southeast", "South-Southeast", 
	"South", "South-Southwest", "Southwest", "West-Southwest", 
	"West", "West-Northwest", "Northwest", "North-Northwest");


var langWindCalm = 'Calm';
var langWindFrom = 'Wind from the '; 	/* used on alt/title tags on wind direction arrow*/

var langBaroRising = 'Risen %s hPa since last data'; /* used for 'change' arrow alt/title tags .. %s marks where value will be placed */
var langBaroFalling = 'Fallen %s hPa since last data';

var langThermoCurrently = 'Currently: '; /* used on alt/title tags for thermometer */
var langTempRising = 'Risen %s since last data'; /* used for change since last arrow alt/title tags .. %s marks where value will be placed */
var langTempFalling = 'Fallen %s since last data';
var langTempTrendRising = 'Trend: Rising %s '; /* used for trend arrow alt/title tags .. %s marks where value will be placed */
var langTempTrendFalling = 'Trend: Falling %s ';

var langCBHRising_ft = 'Risen %s ft. since last data'; /* used for 'change' arrow alt/title tags .. %s marks where value will be placed */
var langCBHFalling_ft = 'Fallen %s ft. since last data';
var langCBHRising_m = 'Risen %s m. since last data';
var langCBHFalling_m = 'Fallen %s m. since last data';

var langComfort = new Array ( /* Comfort text from  Extreme Cold => Extreme Hot */
	"SEVERE DANGER", "Extremely Cold", "Uncomfortably Cold", "Cold", "Cool", "Comfortable",
	"Warm", "Uncomfortably Hot", "SEVERE DANGER");


// -- 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)


// 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;
}	// END function get_ajax_tags


function check_ajax_class(elem) {
// check element id for class="ajax" in it

  if (ie4 && browser != "Opera") {
	var lookfor = 'className';
  } else {
	var lookfor = 'class';
  }

  var class_check = "";
  var att = elem.getAttribute(lookfor);
  if(att == 'ajax') {
       class_check = 1;
   }
   return class_check;
}
// --- END function check_ajax_class()



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;
 
      }
}	// END function reset_ajax_color



function get_last( name ) {
// return STORED value - best use BEFORE Rset_ajax_obs ! - typically used for 'change since last'
		var element = document.getElementById(name);
		if (! element ) { return ; } // -- don't set if missing the <span id=name> tag
		var prevobs = element.getAttribute("lastobs");
		return prevobs;
}	// END function get_last



// This is the function that sets the elements 'variable' content
function Rset_ajax_obs( name, value, uom ) {
// store away the current value in both the doc and the span as lastobs="value" and forward Unit Of Measure (or user suffix)
/* explanation
	Rset_ajax_obs( *span id*, *content value*, *suffix - usually Unit of Measure*);
*/

		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");
//		if (value != unescape(lastobs)) {
		if (value != lastobs) {
			element.setAttribute("lastobs",value);

  			if(check_ajax_class(element) ) {	// only change text colour if class = 'ajax'
           			element.style.color=flashcolor;
 			}

 // ********** mod for biggest graphic ONLY
 if(name == "ajaxObs_native") {	// used in this one ONLY for data graphic
set_ajax_uom('beteljuice_biggest_data', 'true');
 setTimeout("set_ajax_uom('beteljuice_biggest_data', '')",flashtime); // hide beteljuice flash graphics 
 }
 			element.innerHTML =  value+uom;
		 	 if ( doTooltip ) { element.setAttribute("title",'AJAX tag:  '+name); }
		}
}	// END function Rset_ajax_obs



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 function set_ajax_uom

// --- end of flash-green functions



function windDir ($winddir) // used for direction graphics
// 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 )];
}	// END function windDir


function windDirLang ($winddir) // user language NNW
// 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 )];
}	// END function windDirLang


function windDirVerbose ($winddir) // user language North-Northwest
// Take wind direction value, return the VERBOSE
// text label based upon 16 point compass -- function by beeker425
{
   return langWindVerbose[Math.floor(((parseInt($winddir) + 11) / 22.5) % 16 )];
}	// END function windDirVerbose


function ajax_genarrow( nowValue, thenValue, Legend, textUP, textDN, numDp, steady) {
// generate an <img> tag with alt= and title= for rising/falling values
// modified by beteljuice - steady img optional	
	
  var diff = (nowValue *1).toFixed(numDp) - (thenValue *1).toFixed(numDp);
 	var absDiff = Math.abs(diff);
  var diffStr = '' + diff.toFixed(numDp);  // sprintf("%01.0f",$diff);
  var absDiffStr = '' + absDiff.toFixed(numDp); // sprintf("%01.0f",$absDiff);
  var image = '';
  var msg = '';
  

  if (diff == 0) {
 // no change
	if(!steady){steady = false;}
	if(steady ){		//  want a graphic for no change
	    msg = "Steady";	// *************** Non-English users change this ! *************************
	    image = "<img src=\"" + here + imagedir + "/steady.gif\" alt=\"" + msg + 
	"\" title=\""+ msg + 
	"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";
	} else { 
// 	   image = '&nbsp;'; 
	    msg = "";
	    image = "<img src=\"" + here + imagedir + "/spacer.gif\" alt=\"" + msg + 
	"\" title=\""+ msg + 
	"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";
	}
  } else if (diff > 0) {
// now is greater 
	msg = textUP.replace(/\%s/,absDiffStr);
    image = "<img src=\"" + here + imagedir + "/rising.gif\" alt=\"" + msg + 
	"\" title=\""+ msg + 
	"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";

  } else {
// now is lesser
    msg = textDN.replace(/\%s/,absDiffStr); // sprintf($textDN,$absDiff); 
    image = "<img src=\"" + here + 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++;
 }
}



// ----- day and month functions ---------
// to get Sun, Mon, etc. use .getDayName(true) else .getDayName()
Date.prototype.getDayName = function(shortName) {
	if (shortName) {
		return langDays[this.getDay()].substr(0,3);
	} else {
		return langDays[this.getDay()];
	}
}	// END get day name


function getMonthName(mon, shortName) {
	if(shortName) {
		return langMonths[mon -1].substr(0,3);
	} else {
		return langMonths[mon -1];
	}
}	// END get month name


// ------ beaufort look-up --- 
// Cumulus only gives bf num for ave, so we have to reverse engineer for ave. max.
// input is mph

function getBft(mph) {
	mph = parseInt(mph);
	if(mph <1) { Bft = 0;}
	if(mph >= 1 && mph <= 3){ Bft = 1;}
	if(mph >3 && mph <= 7){ Bft = 2;}
	if(mph >7 && mph <= 12){ Bft = 3;}
	if(mph >12 && mph <= 17){ Bft = 4;}
	if(mph >17 && mph <= 24){ Bft = 5;}
	if(mph >24 && mph <= 30){ Bft = 6;}
	if(mph >30 && mph <= 38){ Bft = 7;}
	if(mph >38 && mph <= 46){ Bft = 8;}
	if(mph >46 && mph <= 54){ Bft = 9;}
	if(mph >54 && mph <= 63){ Bft = 10;}
	if(mph >63 && mph <= 72){ Bft = 11;}
	if(mph >72){ Bft = 12;}
	return Bft;
} // END getBft




// ------------------------------------------------------------------------------------------
//  main function.. read realtime.txt and format <span class="ajax" id="......"></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 currdat = x.responseText.replace(/\r\n/g, "");	// this gets rid of any line ending
   	var currdat = currdat.split(' ');	// populate the array

	// now make sure we got a realtime.txt with minimum content 
	// If we have a valid currdat file AND updates is < maxupdates
	if(currdat[47] && ( updates <= maxupdates || maxupdates > 0  ) ) {
		if (maxupdates > 0 ) {updates++; } // increment counter if needed

// ----- time / date  --------------------------------------------------------------- ORDER CHANGED from original
 		ajaxtimeformat = currdat[1];

		if(lastajaxtimeformat != ajaxtimeformat) {		//  filestamp check

// we need to work on the date just to get the day of the week, and we have to do a fiddle because it's only a two digit year

			jdate_year = ("20" + currdat[0].substr(6)) *1;	// change "20xx" to a number
			jdate_month = currdat[0].substr(3, 2) *1;	// change to a number
			jdate_day = currdat[0].substr( 0, 2) *1;	// change to a number

			jdate = new Date(jdate_year, jdate_month -1, jdate_day, currdat[1].substr(0, 2), currdat[1].substr(3, 2));

			dname_long = jdate.getDayName();	// eg. Monday
			dname_short = jdate.getDayName(true);	// eg Mon
			mname_long = getMonthName(jdate_month);	// eg. February
			mname_short = getMonthName(jdate_month, true);	// eg Feb

// OK - let's create some 'user' date / time formats

/* explanation
	Rset_ajax_obs( *span id*, *content value*, *suffix - usually Unit of Measure*);
*/

// complete string Mon Mar 07 00:58:59 2008
			Rset_ajax_obs("ajaxObs_native", dname_short + ' ' + mname_short + ' ' + currdat[0].substr(0, 2) + ' ' + currdat[1] + ' ' + jdate_year, "");

// Mar 07, 2008
			Rset_ajax_obs("ajaxObs_date",  mname_short + ' ' + currdat[0].substr(0, 2) +  ', ' + jdate_year, ""); 
			wk_date = currdat[0].substr(0, 2) ;		// start working out date suffix
			suff = wk_date.substr(1) *1;	// get last character (as a number again)
			if(wk_date == "11" || wk_date == "12" || wk_date == "13") { suff = 0; }	// fix to stop 11st / 12nd / 13rd
			suff = langDate_suffix[suff];	// lookup correct suffix - END
 
// Mar 7th 2008
			Rset_ajax_obs("ajaxObs_date_suff", mname_short + " " + jdate_day + suff + " " + jdate_year, "");

// 07 Mar 2008
			Rset_ajax_obs("ajaxObs_date2", currdat[0].substr(0, 2) + " " + mname_short + " " + jdate_year, "");

// 7th Mar 2008
			Rset_ajax_obs("ajaxObs_date2_suff", jdate_day + suff + " " + mname_short + " " + jdate_year, ""); 

// 19:45
			Rset_ajax_obs("ajaxObs_time", currdat[1].substr(0, 5), "");	

// 19:45:32
			Rset_ajax_obs("ajaxObs_timess", currdat[1], "");	

// Mon - for Monday use dname_long
			Rset_ajax_obs("ajaxObs_dname", dname_short, "");	

// October - for Oct use mname_short
			Rset_ajax_obs("ajaxObs_mname", mname_long, "");	

// 2008
			Rset_ajax_obs("ajaxCopy_year", jdate_year, "");
					
			if(station_day == 1) {	// data begins @ 09:00
				Rset_ajax_obs("ajax_station_day", "09:00", "");
				(currdat[1].substr(0, 2) *1 <9 ? date_day = jdate_day - 1 : date_day = jdate_day);	
				since_date = new Date(jdate_year, jdate_month -1, date_day, "9");
				diff = jdate - since_date;
				diff_hr = parseInt(diff / 3600000);
				diff_min = currdat[1].substr(3, 2);
				data_hours = diff_hr + ":" + diff_min + " hrs";
				Rset_ajax_obs("ajax_data_hours", diff_hr + ":" + diff_min, " hrs");
			} else {		// anything else day begins @ 00:00
				Rset_ajax_obs("ajax_station_day", "00:00", "");
				data_hours = currdat[1].substr(0, 5) + " hrs";
				Rset_ajax_obs("ajax_data_hours", currdat[1].substr(0, 5), " hrs");
			}


// misc - Cumulus version eg. 1.8.2
			Rset_ajax_obs("Cumulus_ver", currdat[38], "");			


// misc - Cumulus build eg. 246
			Rset_ajax_obs("Cumulus_build", currdat[39], "");			



// ----- Temperature (External) ---------------------------------------------
// as of cumlus ver 1.8.3 build 531, trend is ave/hr over 3hrs


// providing both C and F because you maybe old fashioned and want to display both
			t_temp = currdat[2] *1	// force current temp to numeric
			t_temp_Hi = currdat[26] *1	// force max temp to numeric
			t_temp_Lo = currdat[28] *1	// force min temp to numeric
			t_temp_trend = currdat[25] *1	// force temp trend to numeric

// better find out units we are getting from file ;-)
			if(currdat[14] == "C") {	// data temperatures are Celcius
//			uom_temp = "&deg;C";	// may be used as a suffix later
				temp_C = t_temp;
				temp_C_max = t_temp_Hi;
				temp_C_min = t_temp_Lo;
				temp_trend = t_temp_trend;

				temp_F = t_temp * 9 / 5 + 32;
				temp_F_max = t_temp_Hi * 9 / 5 + 32;
				temp_F_min = t_temp_Lo * 9 / 5 + 32;

			} else {		// data must be Farenheit

				temp_C = (t_temp - 32) / 9 * 5;
				temp_C_max = (t_temp_Hi - 32) / 9 * 5;
				temp_C_min = (t_temp_Lo - 32) / 9 * 5;

				temp_F = t_temp;
				temp_F_max = t_temp_Hi ;
				temp_F_min = t_temp_Lo;
				temp_trend = t_temp_trend;
			}

	// generate 'change since last arrow' if required 
			templast_C = get_last("ajaxtemp_C"); 	// let's do a subsequent change check
			if(templast_C){		// prevents trend arrow on initial data grab
				Rset_ajax_obs("ajaxtemparrow_C", ajax_genarrow(temp_C, templast_C, '', langTempRising, langTempFalling, 1 ) ,"");	
			}

			Rset_ajax_obs("ajaxtemp_C", temp_C.toFixed(1), '&deg;C');
			Rset_ajax_obs("ajaxbigtemp_C", temp_C.toFixed(0), '&deg;C');

// duplicate for F, I don't know which you are going to use ;-)

	// generate 'change since last arrow' if required 
			templast_F = get_last("ajaxtemp_F");
			if(templast_F){
				Rset_ajax_obs("ajaxtemparrow_F", ajax_genarrow(temp_F, templast_F, '', langTempRising, langTempFalling, 1) ,"");	
			}

			Rset_ajax_obs("ajaxtemp_F", temp_F.toFixed(1), "&deg;F");
			Rset_ajax_obs("ajaxbigtemp_F", temp_F.toFixed(0), "&deg;F");


// temperature trend
	// generate arrow if required
			if(currdat[14] == "C") {	// data temperatures are Celcius
				uom_temp = "&deg;C/hr";	// may be used as a suffix later
			} else {
				uom_temp = "&deg;F/hr";
			}

// using optional true parameter to generate 'steady' graphic (not normally used with 'change' arrow)
			Rset_ajax_obs("ajaxtemptrend", ajax_genarrow( temp_trend, 0, '', langTempTrendRising + uom_temp, langTempTrendFalling + uom_temp, 1, true) , "");	
			Rset_ajax_obs("ajaxtemptrend_value", temp_trend , uom_temp);	

/* If you want INTERNAL values duplicate above with different variable names
	and use currdat[22] for data
*/


	// create some min / max external temp user variables
			Rset_ajax_obs("ajaxtemp_C_Min", temp_C_min.toFixed(1), "");	// NB. no suffix / unit
			Rset_ajax_obs("ajaxtemp_C_Max", temp_C_max.toFixed(1), "");	// NB. no suffix / unit
			Rset_ajax_obs("ajaxtemp_F_Min", temp_F_min.toFixed(1), "");	// NB. no suffix / unit
			Rset_ajax_obs("ajaxtemp_F_Max", temp_F_max.toFixed(1), "");	// NB. no suffix / unit

			Rset_ajax_obs("ajaxtemp_Min_time", currdat[29], "");	// eg. 03:24
			Rset_ajax_obs("ajaxtemp_Max_time", currdat[27], "");	// eg. 12:24

// END temperature

 
// ----- Humidity (External) ---------------------------------------------------------

			humidity = currdat[3] * 1;	// make numeric for other calcs later
//			Rset_ajax_obs("ajaxhumidity", humidity, "%");
			rh_last = get_last("ajaxhumidity");	
			Rset_ajax_obs("ajaxhumidity", humidity, "%");

// arrow for change since last obs
			if(rh_last){
				Rset_ajax_obs("ajaxhumidity_last_arrow", ajax_genarrow(humidity, rh_last, '', "Risen since last sample", "Fallen since last sample",0) ,"");	
			}
/* if you want INTERNAL value duplicate with a different var name and use currdat[23] */
// END humidity

		

// ------ Dewpoint ------------------------------------------------------------

			dp_temp = currdat[4] *1;	// force dp to numeric

// better find out units we are getting from file ;-)
			if(currdat[14] == "C") {	// data temperatures are Celcius
				dew_C = dp_temp;				
				dew_F = dp_temp * 1.8 + 32;
			} else {
				dew_C = (dp_temp - 32) / 1.8;				
				dew_F = dp_temp ;
			}				

			Rset_ajax_obs("ajax_dp_C", dew_C.toFixed(1), "&deg;C");
			Rset_ajax_obs("ajax_dp_F", dew_F.toFixed(1), "&deg;F");
// END dewpoint



// ----- WindChill ------------------------------------------------------------------------------ seems to be related to gust
// -- If calculated by Cumulus with respect to average windspeed, else base station dependent

			wc_temp = currdat[24] *1;	// force data to numeric

// better find out units we are getting from file ;-)
			if(currdat[14] == "C") {	// data temperatures are Celcius
				windchill_C = wc_temp;
				windchill_F = wc_temp * 1.8 + 32;
			} else {
				windchill_C = (wc_temp - 32) / 1.8;				
				windchill_F = wc_temp ;
			}				

			Rset_ajax_obs("ajaxwindchill_C", windchill_C.toFixed(1), "&deg;C");
			Rset_ajax_obs("ajaxwindchill_F", windchill_F.toFixed(1), "&deg;F");
// END windchill



// ------ Heat Index ----------------------------------------------------------------------------
			if(currdat[41]) {	// existance check - not in early versions
				HI_temp = currdat[41] *1;	// force data to numeric

// better find out units we are getting from file ;-)
				if(currdat[14] == "C") {	// data temperatures are Celcius
					heatidx_C = HI_temp;
					heatidx_F = HI_temp * 1.8 + 32;
				} else {
					heatidx_C = (HI_temp - 32) / 1.8;				
					heatidx_F = HI_temp ;
				}				
				Rset_ajax_obs("ajaxheatidx_F", heatidx_F.toFixed(1), "&deg;F");
				Rset_ajax_obs("ajaxheatidx_C", heatidx_C.toFixed(1), "&deg;C");
			}
// END heat index (NB. by using .toFixed() the values are TEXT)



// ------ Humidex - Canadian style (uses DP instead of humidity for base ------------------

			if(currdat[42]) {	// existance check - not in early versions
				Hdex_temp = currdat[42];

				Rset_ajax_obs("ajaxhumidex", Hdex_temp, "");
			}
// END humidex



// ------ FeelsLike ------------------------------------------------------------------------------
		  if (temp_C <= 16.0 ) {		 // note.. using temps in C and converting for F
		 		feelslike_C = windchill_C; //use WindChill
			} else if (temp_C >=27.0 && humidity >= 40) {
		 		feelslike_C = heatidx_C;   // use HeatIndex
			} else {
				feelslike_C = temp_C
			}
	    Rset_ajax_obs("ajaxfeelslike_C", feelslike_C.toFixed(1), "&deg;C");
			feelslike_F = ((feelslike_C * 1.8) +32).toFixed(1);
 	    Rset_ajax_obs("ajaxfeelslike_F", feelslike_F, "&deg;F");

// used for thermometer 'mouseover'
			thermometerstr_C = langThermoCurrently +  temp_C.toFixed(1) + "\&deg;C, Feels like " + feelslike_C + "\&deg;C"; 
			thermometerstr_F = langThermoCurrently +  temp_F.toFixed(1) + "\&deg;F, Feels like " + feelslike_F + "\&deg;F"; 
// END feels like


		
//------------ Create Comfort Index Text - various reasoning ! -------------
			CI_text = "";				// default if reasoning fails !

			if ((temp_C >= 15) && (temp_C < 25)) {
				CI_text = langComfort[5];  // comfortable
			}
			if ((temp_C >= 25) && (temp_C < 38)) {	// I know this looks high, but its to cover a low Heat Index
				CI_text = langComfort[6];
			}
			if ((temp_C >= 32) && (heatidx_C < 38)){
				CI_text = langComfort[7];
			}
			if (heatidx_C >= 38) {
				CI_text = langComfort[8];
			}
			if (windchill_C < 15) {
				CI_text = langComfort[4];
				if (windchill_C < 5) {
					CI_text = langComfort[3];
				}
				if (windchill_C < 0) {
					CI_text = langComfort[2];
				}
				if (windchill_C < -20) {
					CI_text = langComfort[1];
				}
				if (windchill_C < -35) {
					CI_text = langComfort[0];
				}
			}
	       	Rset_ajax_obs("ajaxcomfort", CI_text, "");
// END comfort index text



		
// ------ Pressure -----------------------------------------------------------------------
// as of cumlus ver 1.8.3 builg 531, trend is ave/hr over 3hrs

			press_temp = currdat[10] *1;	// force data to numeric
			press_temp_Lo = currdat[36] *1;	// force data to numeric
			press_temp_Hi = currdat[34] *1;	// force data to numeric
			press_temp_trend = currdat[18] *1;	// force data to numeric

// better find out units we are getting from file ;-)
			if(currdat[15] == "in") {	// data pressure are inHg
				pressure_rel_hPa = press_temp * 33.8639;	// conversion figure from NOAA
				pressure_rel_hPa_Min = press_temp_Lo * 33.8639 ;	
				pressure_rel_hPa_Max = press_temp_Hi * 33.8639;	
				pressure_rel_hPa_Trend = press_temp_trend * 33.8639;	

				pressure_rel_inHg = press_temp;
				pressure_rel_inHg_Min = press_temp_Lo;	
				pressure_rel_inHg_Max = press_temp_Hi;	
				pressure_rel_inHg_Trend = press_temp_trend;	

			} else {		// data is quoted as hpa OR mb (or anything else !)

				pressure_rel_hPa = press_temp;	
				pressure_rel_hPa_Min = press_temp_Lo;	
				pressure_rel_hPa_Max = press_temp_Hi;	
				pressure_rel_hPa_Trend = press_temp_trend;	

				pressure_rel_inHg = press_temp * 0.02953;	// conversion figure from NOAA
				pressure_rel_inHg_Min = press_temp_Lo * 0.02953;	
				pressure_rel_inHg_Max = press_temp_Hi * 0.02953;	
				pressure_rel_inHg_Trend = press_temp_trend * 0.02953;	
			}

// hPa relative
			barolast_rel_hPa = get_last("ajaxbaro_rel_hPa");	// for change arrow
			Rset_ajax_obs("ajaxbaro_rel_hPa", pressure_rel_hPa.toFixed(1), " hPa");
// inHg relative
			barolast_rel_inHg = get_last("ajaxbaro_rel_inHg");	// for change arrow
			Rset_ajax_obs("ajaxbaro_rel_inHg", pressure_rel_inHg.toFixed(2), " inHg");

// arrows for change since last obs
			if(barolast_rel_hPa){
				Rset_ajax_obs("ajaxbaro_rel_hPa_last_arrow", ajax_genarrow(pressure_rel_hPa, barolast_rel_hPa, '', langBaroRising, langBaroFalling,1) , "");	
			}

			if(barolast_rel_inHg){
				Rset_ajax_obs("ajaxbaro_rel_inHg_last_arrow", ajax_genarrow(pressure_rel_inHg, barolast_rel_inHg, '', langBaroRising, langBaroFalling,2) , "");	
			}
		
// pressure Min / Max
			Rset_ajax_obs("ajaxbaro_rel_hPa_Min", pressure_rel_hPa_Min.toFixed(1), " hPa");
			Rset_ajax_obs("ajaxbaro_rel_hPa_Max", pressure_rel_hPa_Max.toFixed(1), " hPa");	

			Rset_ajax_obs("ajaxbaro_rel_inHg_Min", pressure_rel_inHg_Min.toFixed(2), " inHg");
			Rset_ajax_obs("ajaxbaro_rel_inHg_Max", pressure_rel_inHg_Max.toFixed(2), " inHg");	

			Rset_ajax_obs("ajaxbaro_rel_Min_Time", currdat[37], "");
			Rset_ajax_obs("ajaxbaro_rel_Max_Time", currdat[35], "");

//   Barometric Trend (3 hour) - NB. cumulus gives an hourly average of last 3 hrs
//   so we need to x3 for our weather decisions

// 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_IM_06312.pdf
// figure out a text value for barometric pressure trend

			weather_trend = pressure_rel_hPa_Trend * 3;
		  if ((weather_trend >= -0.7) && (weather_trend <= 0.7)) { 
				pressure_trend_text = langBaroTrend[0];
				p_arrow = 0;	// steady
			}
   		if ((weather_trend > 0.7) && (weather_trend < 2.0 )) {
				pressure_trend_text = langBaroTrend[1];
				p_arrow = 1;	// rising
			}
   		if (weather_trend >= 2.0) {
				pressure_trend_text = langBaroTrend[2]; 
				p_arrow = 1;	// rising
			}
   		if ((weather_trend < -0.7) && (weather_trend > -2.0)) {
				pressure_trend_text = langBaroTrend[3]; 
				p_arrow = -1;	// falling
			}
   		if (weather_trend <= -2.0) { 
				pressure_trend_text = langBaroTrend[4]; 
				p_arrow = -1;	// falling
			}

			pressure_rel_hPa_Trend_rate = (pressure_rel_hPa_Trend > 0.0 ? "+" + pressure_rel_hPa_Trend.toFixed(1) : pressure_rel_hPa_Trend.toFixed(1));

			Rset_ajax_obs("ajaxbarotrend_hPa_rate",pressure_rel_hPa_Trend_rate, " hPa");

			pressure_rel_inHg_Trend_rate = (pressure_rel_inHg_Trend > 0.0 ? "+" + pressure_rel_inHg_Trend.toFixed(2) : pressure_rel_inHg_Trend.toFixed(2));

			Rset_ajax_obs("ajaxbarotrend_inHg_rate",pressure_rel_inHg_Trend_rate, " inHg");


// OK trend arrow has to ignore 'ordinary' math comparrison and obey parameters set above
// using optional true parameter to generate 'steady' graphic (not normally used with 'change' arrow)
	
			Rset_ajax_obs("ajaxbarotrend_arrow",  ajax_genarrow(p_arrow, 0, '', pressure_trend_text, pressure_trend_text,2, true), "");	

			Rset_ajax_obs("ajaxbarotrendtext", pressure_trend_text, "");


/* at the time of writing Cumulus only has one (relative) value for pressure */
// END pressure



// -------- Wind -------------------------------------------------- lots of conversions to do
// ----- Windspeed --------------------------------------------------------------------
/* we are calculating all units from any given unit except Beaufort No. which is separate data
windrun is Statute Miles or Kilometers or Nautical Miles since 00:00 OR 09:00 */

			ws_ave_temp = currdat[5] *1;	// force data to numeric
			ws_gust_temp = currdat[6] *1;	// force data to numeric
			ws_gust_recent_temp = currdat[40] *1;	// force data to numeric
			ws_windrun = currdat[17] *1;	// force data to numeric - miles / km / nautical miles
			ws_ave_max_temp = currdat[30] *1; // force data to numeric
			ws_gust_max_temp = currdat[32] *1; // force data to numeric




// better find out units we are getting from file ;-)
// conversion figures are from NOAA
			if(currdat[13] == "mph") {	// data windspeeds are mph ;-)
				wind_mph = ws_gust_temp;
				wind_mph_ave = ws_ave_temp;
				wind_mph_recent = ws_gust_recent_temp;
				wind_mph_ave_max = ws_ave_max_temp;
				wind_mph_gust_max = ws_gust_max_temp;
				windrun_miles = ws_windrun;

				wind_ms = ws_gust_temp * 0.44704;		// windspeed metres per sec
				wind_ms_ave = ws_ave_temp * 0.44704;
				wind_ms_recent = ws_gust_recent_temp * 0.44704;
				wind_ms_ave_max = ws_ave_max_temp * 0.44704;
				wind_ms_gust_max = ws_gust_max_temp * 0.44704;

				wind_k = ws_gust_temp * 1.4667;	// windspeed kilometres per hour
				wind_k_ave = ws_ave_temp * 1.4667;
				wind_k_recent = ws_gust_recent_temp * 1.4667;
				wind_k_ave_max = ws_ave_max_temp * 1.4667;
				wind_k_gust_max = ws_gust_max_temp * 1.4667;
				windrun_k = ws_windrun * 1.609344;

				wind_kts = ws_gust_temp * 0.8689762;	// windspeed knots
				wind_kts_ave = ws_ave_temp * 0.8689762;
				wind_kts_recent = ws_gust_recent_temp * 0.8689762;
				wind_kts_ave_max = ws_ave_max_temp * 0.8689762;
				wind_kts_gust_max = ws_gust_max_temp * 0.8689762;
				windrun_kts = ws_windrun * 0.8689;
			}

			if(currdat[13] == "kts") {	// data windspeeds are knots 
				wind_mph = ws_gust_temp * 1.1507794;
				wind_mph_ave = ws_ave_temp * 1.1507794;
				wind_mph_recent = ws_gust_recent_temp * 1.1507794;
				wind_mph_ave_max = ws_ave_max_temp * 1.1507794;
				wind_mph_gust_max = ws_gust_max_temp * 1.1507794;
				windrun_miles = ws_windrun * 1.50779;

				wind_ms = ws_gust_temp * 0.514444;		// windspeed metres per sec
				wind_ms_ave = ws_ave_temp * 0.514444;
				wind_ms_recent = ws_gust_recent_temp * 0.514444;
				wind_ms_ave_max = ws_ave_max_temp * 0.514444;
				wind_ms_gust_max = ws_gust_max_temp * 0.514444;

				wind_k = ws_gust_temp * 1.852;	// windspeed kilometres per hour
				wind_k_ave = ws_ave_temp * 1.852;
				wind_k_recent = ws_gust_recent_temp * 1.852;
				wind_k_ave_max = ws_ave_max_temp * 1.852;
				wind_k_gust_max = ws_gust_max_temp * 1.852;
				windrun_k = ws_windrun * 1.582;

				wind_kts = ws_gust_temp;	// windspeed knots
				wind_kts_ave = ws_ave_temp;
				wind_kts_recent = ws_gust_recent_temp;
				wind_kts_ave_max = ws_ave_max_temp;
				wind_kts_gust_max = ws_gust_max_temp;
				windrun_kts = ws_windrun;
			}

			if(currdat[13] == "m/s") {	// data windspeeds are metres per sec
				wind_mph = ws_gust_temp * 2.23694;
				wind_mph_ave = ws_ave_temp * 2.23694;
				wind_mph_recent = ws_gust_recent_temp * 2.23694;
				wind_mph_ave_max = ws_ave_max_temp * 2.23694;
				wind_mph_gust_max = ws_gust_max_temp * 2.23694;
				windrun_miles = ws_windrun * 0.00062;

				wind_ms = ws_gust_temp;		// windspeed metres per sec
				wind_ms_ave = ws_ave_temp;
				wind_ms_recent = ws_gust_recent_temp;
				wind_ms_ave_max = ws_ave_max_temp;
				wind_ms_gust_max = ws_gust_max_temp;

				wind_k = ws_gust_temp * 3.6;	// windspeed kilometres per hour
				wind_k_ave = ws_ave_temp * 3.6;
				wind_k_recent = ws_gust_recent_temp * 3.6;
				wind_k_ave_max = ws_ave_max_temp * 3.6;
				wind_k_gust_max = ws_gust_max_temp * 3.6;
				windrun_k = ws_windrun * 0.001;

				wind_kts = ws_gust_temp * 1.9438445;	// windspeed knots
				wind_kts_ave = ws_ave_temp * 1.9438445;
				wind_kts_recent = ws_gust_recent_temp * 1.9438445;
				wind_kts_ave_max = ws_ave_max_temp * 1.9438445;
				wind_kts_gust_max = ws_gust_max_temp * 1.9438445;
				windrun_kts = ws_windrun * 0.00053995;
			}

			if(currdat[13] == "km/h") {	// data windspeeds are kilometres per hour
				wind_mph = ws_gust_temp * 0.681818;	// windspeed mph
				wind_mph_ave = ws_ave_temp * 0.681818;
				wind_mph_recent = ws_gust_recent_temp * 0.681818;
				wind_mph_ave_max = ws_ave_max_temp * 0.681818;
				wind_mph_gust_max = ws_gust_max_temp * 0.681818;
				windrun_miles = ws_windrun * 0.62137;

				wind_ms = ws_gust_temp * 0.277778;		// windspeed metres per sec
				wind_ms_ave = ws_ave_temp * 0.277778;
				wind_ms_recent = ws_gust_recent_temp * 0.277778;
				wind_ms_ave_max = ws_ave_max_temp * 0.277778;
				wind_ms_gust_max = ws_gust_max_temp * 0.277778;

				wind_k = ws_gust_temp;	// windspeed kilometres per hour
				wind_k_ave = ws_ave_temp;
				wind_k_recent = ws_gust_recent_temp;
				wind_k_ave_max = ws_ave_max_temp;
				wind_k_gust_max = ws_gust_max_temp;
				windrun_k = ws_windrun;

				wind_kts = ws_gust_temp * 0.5399568;	// windspeed knots
				wind_kts_ave = ws_ave_temp * 0.5399568;
				wind_kts_recent = ws_gust_recent_temp * 0.5399568;
				wind_kts_ave_max = ws_ave_max_temp * 0.5399568;
				wind_kts_gust_max = ws_gust_max_temp * 0.5399568;
				windrun_kts = ws_windrun * 0.53995;
			}

// define some user (html) variables

			Rset_ajax_obs("ajax_wind_mps", wind_ms.toFixed(1), " m/s");
			Rset_ajax_obs("ajax_wind_kph", wind_k.toFixed(1), " km/h");
			Rset_ajax_obs("ajax_wind_mph", wind_mph.toFixed(1), " mph");
			Rset_ajax_obs("ajax_wind_kts", wind_kts.toFixed(1), " kts");

			Rset_ajax_obs("ajax_wind_mps_ave", wind_ms_ave.toFixed(1), " m/s");
			Rset_ajax_obs("ajax_wind_kph_ave", wind_k_ave.toFixed(1), " km/h");
			Rset_ajax_obs("ajax_wind_mph_ave", wind_mph_ave.toFixed(1), " mph");
			Rset_ajax_obs("ajax_wind_kts_ave", wind_kts_ave.toFixed(1), " kts");

			Rset_ajax_obs("ajax_wind_mps_recent", wind_ms_recent.toFixed(1), " m/s");
			Rset_ajax_obs("ajax_wind_kph_recent", wind_k_recent.toFixed(1), " km/h");
			Rset_ajax_obs("ajax_wind_mph_recent", wind_mph_recent.toFixed(1), " mph");
			Rset_ajax_obs("ajax_wind_kts_recent", wind_kts_recent.toFixed(1), " kts");

			Rset_ajax_obs("ajax_wind_ave_max_TIME", currdat[31], "");
			Rset_ajax_obs("ajax_wind_mps_ave_max", wind_ms_ave_max.toFixed(1), " m/s");
			Rset_ajax_obs("ajax_wind_kph_ave_max", wind_k_ave_max.toFixed(1), " km/h");
			Rset_ajax_obs("ajax_wind_mph_ave_max", wind_mph_ave_max.toFixed(1), " mph");
			Rset_ajax_obs("ajax_wind_kts_ave_max", wind_kts_ave_max.toFixed(1), " kts");

			Rset_ajax_obs("ajax_wind_gust_max_TIME", currdat[33], "");
			Rset_ajax_obs("ajax_wind_mps_gust_max", wind_ms_gust_max.toFixed(1), " m/s");
			Rset_ajax_obs("ajax_wind_kph_gust_max", wind_k_gust_max.toFixed(1), " km/h");
			Rset_ajax_obs("ajax_wind_mph_gust_max", wind_mph_gust_max.toFixed(1), " mph");
			Rset_ajax_obs("ajax_wind_kts_gust_max", wind_kts_gust_max.toFixed(1), " kts");

// NB Beaufort No is a Wind AVERAGE value !!!
			wind_bf = currdat[12] *1;	// windspeed beaufort number (forced to numeric)
			Rset_ajax_obs("ajax_wind_bf_num", wind_bf.toFixed(0), "");	// hint; put 'Force: ' before # in html
			Rset_ajax_obs("ajaxbeaufort",langBeaufort[wind_bf], "");
			Rset_ajax_obs("ajaxbeaufort_desc",langBeaufort_desc[wind_bf], "");

			wind_bf_ave_max = getBft(wind_mph_ave_max);	// windspeed beaufort number
			Rset_ajax_obs("ajax_wind_bf_num_max", wind_bf_ave_max, "");	// hint; put 'Force: ' before # in html
			Rset_ajax_obs("ajaxbeaufort_max",langBeaufort[wind_bf_ave_max], "");
			Rset_ajax_obs("ajaxbeaufort_desc_max",langBeaufort_desc[wind_bf_ave_max], "");

			Rset_ajax_obs("ajax_windrun_miles", windrun_miles.toFixed(2) + " miles/" + data_hours, "");
			Rset_ajax_obs("ajax_windrun_km", windrun_k.toFixed(2) + " km/" + data_hours, "");
			Rset_ajax_obs("ajax_windrun_nautical", windrun_kts.toFixed(2) + " nautical miles/" + data_hours, "");


// WIND DIRECTION ... NOW (gust)
// we only use data degrees - this script translates to user language
// bugg*r - from 1.8.3 cumulus uses 360 as North but also uses 0 to indicate Calm !

 	    val_org = currdat[7] *1;
 	    if(val_org == 360){val_org = 0;} // used in math to determine array[x]
 	    val = windDir(val_org); // NOT user translated - to enable graphics names
 	    val2 = currdat[7] *1;
 	    if(wind_mph > 0){	// run with the directions as given - * trial comfort calm
				valLang = windDirLang( val_org ); /* to enable translations */
				valLangVerbose = windDirVerbose( val_org ); /* to enable translations */
 			Rset_ajax_obs("ajaxwind_deg", val2, "&deg;");	// wind degrees, - * trial comfort 'calm'
			} else {	// give a 'comfort' direction for calm [?]
				valLang = "--";
				valLangVerbose = "--"
 			Rset_ajax_obs("ajaxwind_deg", "--", "&deg;");	// wind degrees, - * trial comfort 'calm'
			}
			
// 			Rset_ajax_obs("ajaxwind_deg", val2, "&deg;");	// wind degrees, even when 'calm'
Rset_ajax_obs("ajaxwinddir",valLang, "");	// NNW - * trial comfort calm
Rset_ajax_obs("ajaxwinddir_long",valLangVerbose, "");	// North-Northwest - * trial comfort calm


	   
 // ************ large (35px) arrow points INTO wind, gives '?' graphic when calm
 			(wind_mph > 0 ? green_val = val : green_val = "0");
 			Rset_ajax_obs("ajaxwindarrow_green",
	<!--	  "<img src=\"" + here + imagedir + "/green_"+green_val+".png\" width=\"35\" height=\"35\" alt=\"" +  -->
	<!--	  langWindFrom + valLang + "\" title=\"" +langWindFrom + valLang + " (" + val2 + "\&deg;)\" /> ", ""); -->
			
			  "<img src=\"" + imagedir + "/green_"+green_val+".png\" width=\"35\" height=\"35\" alt=\"" + 
		  langWindFrom + valLang + "\" title=\"" +langWindFrom + valLang + " (" + val2 + "\&deg;)\" /> ", "");



// direction compass rose and wind arrows - arrows NOT displayed if 'calm'
	  	if (wind_mph > 0) {
// 9px wind arrow - points in wind direction
 				Rset_ajax_obs("ajaxwindicon_9",
		 "<img src=\"" + here + imagedir + "/" +  val + "_9.gif\" width=\"9\" height=\"9\" alt=\"" + 
		  langWindFrom + valLang + "\" title=\"" +langWindFrom + valLang + " (" + val2 + "\&deg;)\" /> ", "");
// 14px wind arrow - points in wind direction
 				Rset_ajax_obs("ajaxwindicon_14",
		 "<img src=\"" + here + imagedir + "/" +  val + "_14.gif\" width=\"14\" height=\"14\" alt=\"" + 
		  langWindFrom + valLang + "\" title=\"" +langWindFrom + valLang + " (" + val2 + "\&deg;)\" /> ", "");
// small windrose (compass)
				Rset_ajax_obs("ajaxwindiconwr",
		  "<img src=\"" + here + imagedir + "/" +wrName +  val + wrType + "\" width=\""+
		   wrWidth+"\" height=\""+wrHeight+"\" alt=\"" + 
		  langWindFrom + valLang + "\" title=\"" +langWindFrom + valLang + "\" /> ", "");
// direction as text
//				Rset_ajax_obs("ajaxwinddir",valLang, "");	// NNW
//				Rset_ajax_obs("ajaxwinddir_long",valLangVerbose, "");	// North-Northwest
	  	 } else {
 // NO wind arrows if Calm - remove below and if(wind_mph > 0.0)  argument if not wanted
				Rset_ajax_obs("ajaxwindicon_9","", "");
				Rset_ajax_obs("ajaxwindicon_14","", "");
//				Rset_ajax_obs("ajaxwinddir","", "");
//				Rset_ajax_obs("ajaxwinddir_long","", "");
				if (wrCalm != '') {	// if you have set an alternative (windrose) graphic for calm
 			 		Rset_ajax_obs("ajaxwindiconwr",
		  "<img src=\"" + here + imagedir + "/" + wrCalm + "\" width=\""+
		   wrWidth+"\" height=\""+wrHeight+"\" alt=\"" + 
		  langBeaufort[0] + "\" title=\"" +langBeaufort[0] + "\" /> ", "");
				}
			 }
// END wind arrows
// END wind now (gust)


// ----- Wind Average (10min) Direction (degrees) ------ since 1.8.5
			if(currdat[46]) {	// prove existance check
			
// we only use data degrees - this script translates to user language
// bugg*r - from 1.8.3 cumulus uses 360 as North but also uses 0 to indicate Calm !

 	    	val_org_ave = currdat[46] *1;
 	    	if(val_org_ave == 360){val_org_ave = 0;} // used in math to determine array[x]
 	    	val_ave = windDir(val_org_ave); // NOT user translated - to enable graphics names
 	    	val2_ave = currdat[46] *1;

 	    if(wind_mph_ave > 0){	// run with the directions as given - * trial comfort calm
				valLang_ave = windDirLang( val_org_ave ); /* to enable translations */
				valLangVerbose_ave = windDirVerbose( val_org_ave ); /* to enable translations */
 				Rset_ajax_obs("ajaxwind_deg_ave", val2_ave, "&deg;");	// wind degrees
		} else {	// give a 'comfort' direction for calm [?]
				valLang_ave = "--";
				valLangVerbose_ave = "--"
 				Rset_ajax_obs("ajaxwind_deg_ave", "--", "&deg;");	// wind degrees, - * trial comfort 'calm'
		}


Rset_ajax_obs("ajaxwinddir_ave",valLang_ave, "");	// NNW - * trial comfort calm
Rset_ajax_obs("ajaxwinddir_long_ave",valLangVerbose_ave, "");	// North-Northwest - * trial comfort calm

 //				Rset_ajax_obs("ajaxwind_deg_ave", val2_ave, "&deg;");	// wind degrees, even when 'calm'


	   
 // ************ large (35px) arrow points INTO wind, gives '?' graphic when calm
 			(wind_mph_ave > 0 ? green_val_ave = val_ave : green_val_ave = "0");
			Rset_ajax_obs("ajaxwindarrow_green_ave",
		  "<img src=\"" + here + imagedir + "/green_"+green_val_ave+".png\" width=\"35\" height=\"35\" alt=\"" + 
		  langWindFrom + valLang_ave + "\" title=\"" +langWindFrom + valLang_ave + " (" + val2_ave + "\&deg;)\" /> ", "");


// direction compass rose and wind arrows - arrows NOT displayed if 'calm'
	  		if (wind_mph_ave > 0) {
// 9px wind arrow - points in wind direction
 					Rset_ajax_obs("ajaxwindicon_9_ave",
		 "<img src=\"" + here + imagedir + "/" +  val_ave + "_9.gif\" width=\"9\" height=\"9\" alt=\"" + 
		  langWindFrom + valLang_ave + "\" title=\"" +langWindFrom + valLang_ave + " (" + val2_ave + "\&deg;)\" /> ", "");
// 14px wind arrow - points in wind direction
 					Rset_ajax_obs("ajaxwindicon_14_ave",
		 "<img src=\"" + here + imagedir + "/" +  val_ave + "_14.gif\" width=\"14\" height=\"14\" alt=\"" + 
		  langWindFrom + valLang_ave + "\" title=\"" +langWindFrom + valLang_ave + " (" + val2_ave + "\&deg;)\" /> ", "");
// small windrose (compass)
					Rset_ajax_obs("ajaxwindiconwr_ave",
		  "<img src=\"" + here + imagedir + "/" +wrName +  val_ave + wrType + "\" width=\""+
		   wrWidth+"\" height=\""+wrHeight+"\" alt=\"" + 
		  langWindFrom + valLang_ave + "\" title=\"" +langWindFrom + valLang_ave + "\" /> ", "");
// direction as text
//					Rset_ajax_obs("ajaxwinddir_ave",valLang_ave, "");	// NNW
//					Rset_ajax_obs("ajaxwinddir_long_ave",valLangVerbose_ave, "");	// North-Northwest
	  	 	} else {
 // NO wind arrows if Calm - remove below and if(wind_mph > 0.0)  argument if not wanted
					Rset_ajax_obs("ajaxwindicon_9_ave","", "");
					Rset_ajax_obs("ajaxwindicon_14_ave","", "");
//					Rset_ajax_obs("ajaxwinddir_ave","", "");
//					Rset_ajax_obs("ajaxwinddir_long_ave","", "");
					if (wrCalm != '') {	// if you have set an alternative (windrose) graphic for calm
 			 			Rset_ajax_obs("ajaxwindiconwr_ave",
		  "<img src=\"" + here + imagedir + "/" + wrCalm + "\" width=\""+
		   wrWidth+"\" height=\""+wrHeight+"\" alt=\"" + 
		  langBeaufort[0] + "\" title=\"" +langBeaufort[0] + "\" /> ", "");
					}
			 	}
// END wind Average arrows
			}
// END wind Average
// END WIND



// ----- Rain -------------------------------------------------------------------------------
// since Cumulus 1.8.4 rain rate is calulated from last 5 mins
// Tip: you could use this to determine 'raining now' advisory, would require >= 0.1 unit/5mins
// since build 602 'rain last hour available'

			if(currdat[47]) {	// prove existance check build 602+
				rain_hr_temp = currdat[47] *1;	// force data to numeric
			} else {
				rain_hr_temp = -10;	// making sure variable is declared even if it is 'empty'
			}

			rain_rate_temp = currdat[8] *1;	// force data to numeric
			rain_today_temp = currdat[9] *1;	// force data to numeric
			rain_yesterday_temp = currdat[21] *1;	// force data to numeric
			rain_month_temp = currdat[19] *1;	// force data to numeric
			rain_year_temp = currdat[20] *1;	// force data to numeric


// better find out units we are getting from file ;-)
// conversion figures are from NOAA
			if(currdat[16] == "mm") {	// data units are mm
				rain_mm_rate = rain_rate_temp;
				rain_mm1 = rain_hr_temp;
				rain_mm24 = rain_today_temp;
				rain_mm_ago = rain_yesterday_temp;
				rain_mm_mon = rain_month_temp;
				rain_mm_year = rain_year_temp;

				rain_in_rate = rain_rate_temp / 25.4;
				rain_in1 = rain_hr_temp / 25.4;
				rain_in24 = rain_today_temp / 25.4;
				rain_in_ago = rain_yesterday_temp / 25.4;
				rain_in_mon = rain_month_temp / 25.4;
				rain_in_year = rain_year_temp / 25.4;

			} else{ 	// data units must be inches

				rain_mm_rate = rain_rate_temp * 25.4;
				rain_mm1 = rain_hr_temp * 25.4;
				rain_mm24 = rain_today_temp * 25.4;
				rain_mm_ago = rain_yesterday_temp * 25.4;
				rain_mm_mon = rain_month_temp * 25.4;
				rain_mm_year = rain_year_temp * 25.4;

				rain_in_rate = rain_rate_temp;
				rain_in1 = rain_hr_temp;
				rain_in24 = rain_today_temp;
				rain_in_ago = rain_yesterday_temp;
				rain_in_mon = rain_month_temp;
				rain_in_year = rain_year_temp;
			}

// prepare for 'change since last' arrows
			rain_then_mm = get_last("ajaxrain_mm_rate");
			rain_then_in = get_last("ajaxrain_in_rate");

// set some (html) user variables
			if(rain_hr_temp >= 0) {	// build 602+ check
				Rset_ajax_obs("ajaxrain_mm_1hr", rain_mm1.toFixed(1), " mm");
			}
			Rset_ajax_obs("ajaxrain_mm_today", rain_mm24.toFixed(1), " mm");
			Rset_ajax_obs("ajaxrain_mm_yesterday", rain_mm_ago.toFixed(1), " mm");
			Rset_ajax_obs("ajaxrain_mm_month", rain_mm_mon.toFixed(1), " mm");
			Rset_ajax_obs("ajaxrain_mm_year", rain_mm_year.toFixed(1), " mm");
			Rset_ajax_obs("ajaxrain_mm_rate", rain_mm_rate.toFixed(1), " mm/hr");
// lets make a change since last arrow - NB. requires ajaxrain_mm_rate somewhere on the html page
			if(rain_then_mm){
				Rset_ajax_obs("ajax_rain_mm_arrow", ajax_genarrow(rain_mm_rate.toFixed(1), rain_then_mm, '', '', '', 0) , "");
			}


			if(rain_hr_temp >= 0) {	// build 602+ check
				Rset_ajax_obs("ajaxrain_in_1hr", rain_in1.toFixed(2), " in");
			}
			Rset_ajax_obs("ajaxrain_in_today", rain_in24.toFixed(2), " in");
			Rset_ajax_obs("ajaxrain_in_yesterday", rain_in_ago.toFixed(2), " in");
			Rset_ajax_obs("ajaxrain_in_month", rain_in_mon.toFixed(2), " in");
			Rset_ajax_obs("ajaxrain_in_year", rain_in_year.toFixed(2), " in");
			Rset_ajax_obs("ajaxrain_in_rate", rain_in_rate.toFixed(2), " in/hr");
// lets make a change since last arrow - NB. requires ajaxrain_in_rate somewhere on the html page
			if(rain_then_in){
				Rset_ajax_obs("ajax_rain_in_arrow", ajax_genarrow(rain_in_rate.toFixed(2), rain_then_in, '', '', '', 0) , "");
			}

// END rain



// ---- Compute Cloud Base Height -------------------------------

			CBH_change_ft = get_last("ajax_CBH_ft");		// if there is change lets create a change since last arrow 
			CBH_change_m = get_last("ajax_CBH_m");
			CBH_m = 125*(temp_C - (dew_C *1));	// cloudbase local in metres
// betel(temp_C + " tC, " + dew_C *1 + " DP, " + CBH_m);
			if(CBH_m < 0) CBH_m = 0;	// stop negative values
			Rset_ajax_obs("ajax_CBH_m", CBH_m.toFixed(0), " m");
			CBH_ft = CBH_m * 3.281;	// cloud base local in feet
			if(CBH_ft < 0) CBH_ft = 0;	// stop negative values
			Rset_ajax_obs("ajax_CBH_ft", CBH_ft.toFixed(0), " ft");
			if(CBH_change_ft){
				Rset_ajax_obs("ajax_CBH_last_arrow", ajax_genarrow(CBH_ft.toFixed(0), CBH_change_ft, '', langCBHRising_ft, langCBHFalling_ft, 0) , "");
			} else {
				if(CBH_change_m){
					Rset_ajax_obs("ajax_CBH_last_arrow", ajax_genarrow(CBH_m.toFixed(0), CBH_change_m, '', langCBHRising_m, langCBHFalling_m, 0) , "");
				}
		 }
// END cloud base height



// ----- UV Index ------------
				Rset_ajax_obs("ajax_UV", currdat[43], "");	// effectively a text value, no processing

	
			
// ----- Evapo Trans whotsit ------------
				Rset_ajax_obs("ajax_EVT", currdat[44], "");	// effectively a text value, no processing


	
// ----- Solar Radiation ------------
				Rset_ajax_obs("ajax_SR", currdat[45], " W/m<sup>2</sup>");	// effectively a text value, no processing



// BEYOND ver 1.8.4 build 605 ... add logic here









// ********** EXTRAS and duplicates *************************************************************
// remember - we are still in the ajax 'grab' loop
// you can remove all these if required, or add to them ;-)




// ------- short Zambretti Forecast
// IMPORTANT - requires zambretti/betelcast.js between page <head> .. </head> tags
// BEFORE betel_cumulus_ajax.js

			if(self.z_where != null) {	// check to see if betelcast.js has been loaded
// set variables to send to betel_cast() - if you live near poles / equator / Southern hemisphere - read script !

				(wind_mph_ave >= 1 ? z_wind = val_ave : z_wind = "calm");
				(p_arrow == -1 ? z_trend = 2 : z_trend = p_arrow);
				what_forecast = betel_cast( pressure_rel_hPa, jdate_month, z_wind, z_trend);
			} else {
				what_forecast = new Array("* betelcast.js MISSING *", 0);
			}

			Rset_ajax_obs("betelcast", what_forecast[0], "");
// --- END forecast



// ----------- EXTRA - beteljuices BIGGEST graphic
// IMPORTANT requires earlier betelcast call (zambretti)

george = document.getElementById("ship_direction");
if(george){	// no point doing all this if not the page !

// - EXTRA - beteljuice 'biggest' barometer
// get rounded hpa - limits - stitch url

		new_baro = pressure_rel_hPa.toFixed(0);
		if(new_baro < 940 || new_baro > 1060) {	// limits check
			biggest_baro_needle = "EXTRAS/beteljuice_barro_knackered.png";
		} else {
			biggest_baro_needle = "EXTRAS/beteljuice_baro_arrow_" + new_baro + ".png";
		}

		 Rset_ajax_obs("beteljuice_biggest_baro", "<img src = \"" + biggest_baro_needle + "\" alt = \"" + new_baro + " hPa, Relative, " + pressure_trend_text + "\" title = \"" +new_baro +" hPa, Relative, " + pressure_trend_text + "\" />", "");


// -- EXTRA biggest hygrometer
if(humidity >= 20 && humidity <= 100) {	// limits check
	Rset_ajax_obs("biggest_RH", "<img src=\"EXTRAS/hygro_" + humidity + ".png\" alt=\"" +humidity + "% Relative Humidity\" title=\"" +humidity + "% Relative Humidity\" />", "");
}


// -- EXTRA biggest thermometer
temp_needle = temp_C.toFixed(0);
 if(temp_needle == -0) { temp_needle = 0 ; }	// to cover toFixed() anomaly
 if(temp_needle >= -15 && temp_needle <= 50) {	// limits check
	Rset_ajax_obs("biggest_thermo", "<img src=\"EXTRAS/thermo_" + temp_needle + ".png\" alt=\"" + temp_C.toFixed(1) + "\&deg;C / " + temp_F.toFixed(1) + "\&deg;F\" title=\"" + temp_C.toFixed(1) + "\&deg;C / " + temp_F.toFixed(1) + "\&deg;F\" />", "");
 }


// --- EXTRA biggest 'clock'

big_clock_hr = currdat[1].substr(0, 2) *1 ;	 // 0 - 23
if(big_clock_hr > 11) { big_clock_hr = big_clock_hr - 12; }	// 0 - 11 analogue format
// do code as for 60 x hr graphics 
// hr graphic = hr * 5 + ( mins / 12 ), 12 mins = 1 'min' scale for hour hand

big_clock_min = currdat[1].substr(3, 2);
big_clock_min_math = big_clock_min *1;
big_clock_hr = big_clock_hr * 5 + Math.floor( big_clock_min_math / 12);	// ideal answer 0 - 59 positions

// do a construct of hour and minute graphic :
Rset_ajax_obs("biggest_clock_hour", "<img src=\"EXTRAS/hour_" + big_clock_hr + ".png\"  />", "");
Rset_ajax_obs("biggest_clock_min", "<img src=\"EXTRAS/min_" + big_clock_min + ".png\" alt=\"" + currdat[1].substr(0, 5) + " hrs\" title=\"" + currdat[1].substr(0, 5) + " hrs\"  />", "");

// day / date / month
// simple text boxes, can't be bothered with spans and checks, rewrite every cycle

<!-- doIt = document.getElementById('biggest_day'); -->
// doIt.value = dname_short;
//	suff = wk_date.substr(1) *1;	// get last character (as a number again)
// if(wk_date == "11" || wk_date == "12" || wk_date == "13") { suff = 0; }	// fix to stop 11st / 12nd / 13rd
//	suff = langDate_suffix[suff];	// lookup correct suffix
// date_biggest = (wk_date *1) + suff;
// doIt = document.getElementById('biggest_date');
// doIt.value = date_biggest;
// doIt = document.getElementById('biggest_month');
// doIt.value = mname_short;



// -- EXTRA 'ship' wind guage

	ship_wind_k = wind_k.toFixed(1);	// as a string (x)y.z
	ship_wind_check = ship_wind_k *1;
	set_ajax_uom('ship_wind_dot', '1');
	if(ship_wind_check < 10) {
		wind_1 = ship_wind_k.substr(0, 1);
		wind_2 = ship_wind_k.substr( 2, 1);
	}
	if(ship_wind_check >= 10) {
		set_ajax_uom('ship_wind_dot', '');
		ship_wind_check=ship_wind_check.toFixed(0);
 		ship_wind_check=ship_wind_check + "";
		wind_1 = ship_wind_check.substr(0,1);
		wind_2 = ship_wind_check.substr(1,1);
	}
//  stitch 'digits' together
	Rset_ajax_obs("ship_wind_1", "<img src=\"../betel/EXTRAS/digit40_" + wind_1 + ".png\"  />", "");
	Rset_ajax_obs("ship_wind_2", "<img src=\"../betel/EXTRAS/digit40_" + wind_2 + ".png\"  />", "");
									
//  wind direction graphic and text
// from 1.85 beta - calm = 0 degrees (N) windirection

		if(ship_wind_k >0) {Rset_ajax_obs("ship_direction", "<img src=\"../betel/EXTRAS/beteljuice_ship40_" + valLang + ".png\" alt=\"" + langWindFrom + valLang + "\" title=\"" +langWindFrom + valLang + " (" + val2 + "\&deg;)\" />", "");
			Rset_ajax_obs("ship_direction_text", valLang, "");
		} else {	// calm - no 'sail' graphic, make direct text "---"
			Rset_ajax_obs("ship_direction", "", "");
			Rset_ajax_obs("ship_direction_text", "---", "");
		}


	Rset_ajax_obs("biggest_outlook", what_forecast[0], "");
	Rset_ajax_obs("biggest_feels", feelslike_C, "\&deg;C");
	Rset_ajax_obs("biggest_comfort", CI_text, "");
	Rset_ajax_obs("biggest_rain_24", rain_mm24.toFixed(1), " mm");
	Rset_ajax_obs("biggest_rain_1", rain_mm1.toFixed(1), " mm");
}
// END beteljuices BIGGEST graphic


// ---- Wheelos Catalan wind names ----------------------------------

 if(val_org_ave >= 0 && val_org_ave <= 29) { // Sector 1 - Provences
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Aire de Provences" ;
		sector = "1a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Provenccotes" ;
		sector = "1b";
		}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Provences" ;
		sector = "1c"
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Provencada" ;
		sector = "1d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Provences" ;
		sector = "1e";
	}
 } // END sector 1


if(val_org_ave >= 30 && val_org_ave <= 64) { // Sector 2 - Gregal
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Aire de Gregal" ;
		sector = "2a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Gregalet" ;
		sector = "2b";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Gregal" ;
		sector = "2c";
		}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Gregalada" ;
		sector = "2d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Gregal" ;
		sector = "2e";
		}
 } // END sector 2


if(val_org_ave >= 65 && val_org_ave <= 99) { // Sector 3 - Llevant
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Ventet de Bon Temps" ;
		sector = "3a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Ventot de Llevant" ;
		sector = "3b";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Llevant" ;
		sector = "3c";
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Llevantada" ;
		sector = "3d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Llevant" ;
		sector = "3e";
	}
 } // END sector 3


if(val_org_ave >= 100 && val_org_ave <= 144) { // Sector  4 - Xaloc
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Foranell" ;
		sector = "4a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Xaloquet" ;
		sector = "4b";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Xaloc" ;
		sector = "4c";
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Xalocada" ;
		sector = "4d"
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Xaloc" ;
		sector = "4e";
		}
 } // END sector 4


if(val_org_ave >= 145 && val_org_ave <= 167) { // Sector 5A - Garbi
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector ="0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Aire de Garbi" ;
		sector = "5a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Garbinet Llarg" ;
		sector = "5b1";
		}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Garbi Llarg" ;
		sector = "5c1";
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Garbinada" ;
		sector = "5d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Garbi" ;
		sector = "5e";
	}
 } // END sector 5A


if(val_org_ave >= 168 && val_org_ave <= 191) { // Sector 5B - Garbi
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Aire de Garbi" ;
		sector = "5a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Ventot de Garbi Rodo" ;
		sector = "5b2";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Garbi Rodo" ;
		sector = "5c2";
		}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Garbinada" ;
		sector = "5d";
		}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Garbi" ;
		sector = "5e";
	}
 } // END sector 5B


if(val_org_ave >= 192 && val_org_ave <= 214) { // Sector 5c - Garbi
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Aire de Garbi" ;
		sector = "5a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Ventot de Garbi Terrer" ;
		sector = "5b3";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Garbi Terrer" ;
		sector = "5c3";
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Garbinada" ;
		sector = "5d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Garbi" ;
		sector = "5e";
	}
 } // END sector 5c


if(val_org_ave >= 215 && val_org_ave <= 249) { // Sector 6 - Llebeig
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Oratge Terral" ;
		sector = "6a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Ventot de Llebeig" ;
		sector = "6b";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Llebeig" ;
		sector = "6c";
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Llebetjada" ;
		sector = "6d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Llebig" ;
		sector = "6e";
	}
 } // END sector 6


if(val_org_ave >= 250 && val_org_ave <= 294) { // Sector 7 - Ponent
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Oratge Terral" ;
		sector = "6a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Ponentot" ;
		sector = "7b";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Ponent" ;
		sector = "7c";
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Ponentada" ;
		sector = "7d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Ponent" ;
		sector = "7e";
	}
 } // END sector 7


if(val_org_ave >= 295 && val_org_ave <= 329) { // Sector 8 - Mestral
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Aire de Mestral" ;
		sector = "8a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Mestralo" ;
		sector = "8b";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Mestral" ;
		sector = "8c";
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Mestralada" ;
		sector = "8d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Mestral" ;
		sector = "8e";
	}
 } // END sector 8


if(val_org_ave >= 320 && val_org_ave <= 360) { // Sector 9 - Mestral
    if(wind_k_ave== 0) {
		cat_wind = "Bafa perduda" ;
		sector = "0";
	}
	if(wind_k_ave > 0 && wind_k_ave < 8) {
		cat_wind = "Aire de Tramuntana" ;
		sector = "9a";
	}
    if(wind_k_ave > 8 && wind_k_ave < 16) {
		cat_wind = "Tramuntaneta" ;
		sector = "9b";
	}
    if(wind_k_ave >= 16 && wind_k_ave < 31) {
		cat_wind = "Tramutana" ;
		sector = "9c";
	}
    if(wind_k_ave >= 31 && wind_k_ave < 61) {
		cat_wind = "Tramuntanada" ;
		sector = "9d";
	}
    if(wind_k_ave >= 61) {
		cat_wind = "Gropada de vent de Tramuntana" ;
		sector = "9e";
	}
 } // END sector 9
 
 // Start Sectors
 
 
 cat_wind_sector = "<img src=\"http://www.wheelocknet.net/betel/EXTRAS/Rosa_vents_" + sector + ".gif\">";   

// betel('sector = ' + sector + ' Img = ' + cat_wind_sector); 

Rset_ajax_obs("Catalan_Wind", cat_wind, "");
 Rset_ajax_obs("Catalan_Wind_Sector", cat_wind_sector, ""); 


// <!--  Rset_ajax_obs("Catalan_Wind", cat_wind, ""); -->







// --------- END Extras and Duplicates ---------------------

			counterSecs = 0;                      // reset timer
			lastajaxtimeformat = ajaxtimeformat; // remember this time

		
		} // END filestamp check

// ******** beteljuice mod for BIG graphic
		// now ensure that the beteljuice_graphic flashes on every AJAX fetch
        	element = document.getElementById("beteljuice_biggest_pulse");
		if (element) {
			set_ajax_uom("beteljuice_biggest_pulse", "true");
		}


		// now ensure that the indicator flashes on every AJAX fetch
        element = document.getElementById("ajaxindicator");
		if (element) {
          element.style.color = flashcolor;
		}
		if (maxupdates > 0 && updates > maxupdates-1) { /* chg indicator to pause message */
			Rset_ajax_obs("ajaxindicator",langPauseMsg, "");
		}
		Rset_ajax_obs('ajaxupdatecount',updates, "");       /* for test pages */
		Rset_ajax_obs('ajaxmaxupdatecount',maxupdates, ""); /* for test pages */


 	  } // END if(currdat content checks)

	 } // 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 

// ************** big graphic mod
    setTimeout("set_ajax_uom('beteljuice_biggest_pulse', '')",flashtime); // hide beteljuice flash graphics 


	if ( (maxupdates == 0) || (updates < maxupdates-1)) {
      setTimeout("ajaxLoader(currdatFile + '?' + new Date().getTime())", reloadTime); // get new data 
    }
  }
} // end ajaxLoader function



// invoke when first loaded on page
var ajax_attempt = 0;

function start_up() {
	if(document.getElementById('ajaxEND')) {
		ajaxLoader(currdatFile + '?' + new Date().getTime());
 		window.setInterval("ajax_countup()", 1000); // run the counter for seconds since update
	} else {
		ajax_attempt++;
		if(ajax_attempt >= 50) {
			betel('Page has failed to download fully'); // 50 attempts for page to format
		} else {
			setTimeout('start_up()', 200);
		}
	}
}

start_up();



/* this is for debug - errors within ajax can do all sorts of strange things !
   normal alert may or may not work, this being called outside of the loop is more likely
   to work (depends on the error)
   line before or line after where you think the problem is use
   betel("Here");
   or 
   betel(varname);
*/

function betel(msg) {
alert(msg);
}

// ]]>