// Based on script developped by Ken True - Saratoga-weather.org  21-May-2006 

// -- begin settings --------------------------------------------------------------------------
var flashcolor = '#00A000'; // color to flash for changed observations RGB
var flashtime  = 1000;       // miliseconds to keep flash color on (2000 = 2 seconds);
var reloadTime = 3000;       // reload AJAX conditions every 5 seconds (= 5000 ms)
var maxupdates = 0;             // 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   = '';       // first part of the graphic filename (followed by winddir to complete it)
var wrType   = '.png';      // extension of the graphic filename
var wrHeight = '40';        // windrose graphic height=
var wrWidth  = '40';        // windrose graphic width=
var wrCalm   = 'wr-calm.png';  // set to full name of graphic for calm display ('wr-calm.gif')

var currentv = 0;  // current wind value in progress bar
var targetv = 0;   //target wind
var currentv1 = 0;  // current wind value in progress bar
var targetv1 = 0;   //target wind
var currentv10 = 0;  // current wind value in progress bar
var targetv10 = 0;   //target wind
var currentdir = 0;
var targetdir = 0;
var targethour = 0;
var currenthour = 0;
var current1m = 0;
var target1m = 0;
var targetday = 0;
var currentday = 0;
var WindreloadTime = 45;  // change progressbar value every 45 ms  =  30 frame / s
var FirstWindreloadTime = 3000;  // change progressbar value every 45 ms  =  30 frame / s
var stepv = 0.8;  // step for wind bar;
var stepd = 2; // step for windir progression
var gust = 0;
var lasttime = '';

// -- end of settings -------------------------------------------------------------------------

// -- language settings -- you don't need to customize this area if you are using English -----

var langPauseMsg = 'Recharger la page pour afficher les données en temps réel. <br/>Affichage en pause depuis le'; // substitute this for ajaxindicator when
                             // maxupdates has been reached and updating paused.

var langOfflineMsg = 'Aucunes données reçues de la station depuis le'; // substitute this for ajaxindicator when
                             // maxupdates has been reached and updating paused.

var langMonths = new Array ( "Janvier","Février","Mars","Avril","Mai",
            "Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre");
var langDays = new Array ( "Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sun");    

var langBaroTrend = new Array (
 "Stable", "En hausse lente", "En hausse rapide", "En baisse lente", "En baisse rapide");

var langUVWords = new Array (
 " ", "UV bas", "UV modéré", "UV élevé",
 "UV très&nbsp;élevé", /* be sure to include &nbsp; for space */
 "UV extrême" );

var langBeaufort = new Array ( /* Beaufort 0 to 12 in array */
 "Vent calme", "Très légère brise", "Légère brise", "Petite brise", "Jolie brise", "Bonne brise",
 "Vent frais", "Grand frais", "Coup de vent", "Fort coup de vent", "Tempête",
 "Violente tempête", "Ouragan"
);

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", "SSO", "SO", "OSO", 
    "O", "ONO", "NO", "NNO");

var langWindCalm = 'Calme';
var langGustNone = 'Calme';
var langWindFrom = 'Vent de '; /* used on alt/title tags on wind direction arrow*/

var langBaroRising = 'En hausse %s '; /* used for trend arrow alt/title tags .. %s marks where value will be placed */
var langBaroFalling = 'En baisse %s ';
var langBaroPerHour = '/hr.'; /* will be assembled as rising/falling + value + uom + perhour text */

var langThermoCurrently = 'Actuellement: '; /* used on alt/title tags for thermometer */
var langThermoMax     = 'Max: ';
var langThermoMin     = 'Min: ';

var langTempRising = 'En hausse %s '; /* used for trend arrow alt/title tags .. %s marks where value will be placed */
var langTempFalling = 'En baisse %s ';
var langTempLastHour = ' durant la derni&egrave;re heure.';

var langTransLookup = new Object;  // storage area for key/value for current conditions translation

var langHeatWords = new Array (
 'Unknown', 'Danger! canicule extr&ecirc;me', 'Danger! Chaleur extr&ecirc;me', 'Attention! Chaleur extreme', 'Extr&egrave;mement chaud ', 'Canicule',
 'Très chaud', 'Chaud','Assez chaud', 'Doux', 'Frais', 'Froid', 'Froid vif', 'Glacial', 'Froid extr&ecirc;me' );

// -- 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 uomWind = ' mph';
var uomBaro = ' inHg';
var uomRain = ' in';
var uomHeight = ' ft';
var dpBaro = 2;
var dpRain = 2;
var webcam = 'webcam1backg.jpg';
var webcamnum = 1;
var curbackground = "";

maxwinddata = 100;     // size of array  
var lastwind = new Array(maxwinddata);   // arrays for real time graphic
var lastgust = new Array(maxwinddata);

for (i = 0; i <= maxwinddata; i++) {
lastwind[i] = null;
lastgust[i] = null;
}


function ajax_set_units( units ) {
  useunits = units;
  if (useunits != 'E') { // set to metric
    uomTemp = '&deg;C';
    uomWind = ' km/h';
    uomBaro = ' hPa';
    uomRain = ' mm';
    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);

function set_webcam() {
  var currentDate = new Date();      
  var rday = currentDate.getDate();
  var rmonth = currentDate.getMonth();
  var ryear = currentDate.getFullYear();
  var rhour = currentDate.getHours();
  var rminute = currentDate.getMinutes();
  rminute=Math.floor(rminute/10);
  nocache = ""+ryear+""+rmonth+""+rday+""+rhour+""+rminute;
if (webcamnum == 1) {
      webcam = "webcam2backg.jpg?nocache="+nocache;
      webcamnum=2;
} else { 
      webcam = "webcam1backg.jpg?nocache="+nocache;
      webcamnum=1;
  }
}

// utility functions to navigate the HTML tags in the page
function get_ajax_tags ( ) {
// search all the span tags and return the list with class="ajax" in it
//
  if (ie4 && browser != "Opera") {
    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') || (att == 'gustlabel')) {
               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) ) {
          if ((name != "ajaxwindmaxgustminute") && (name != "ajaxwindmaxgustminutekts") && (name != "ajaxgustkts") && (name != "ajaxgust") && (name != "ajaxgust_1") && (name != "ajaxgust_1kts") && (name != "ajaxwind1") && (name != "ajaxwind1kts") && (name != "ajaxwind") && (name != "ajaxwindkts") && (name != "ajaxwindmaxgust") && (name != "ajaxwindmaxgustkts") && (name != "ajaxwindmaxgusth") && (name != "ajaxwindmaxgusthkts") && (name != "ajaxwindmaxgust_1")&& (name != "ajaxwindmaxgusth_1") && (name != "ajaxwindmaxgust_1kts")&& (name != "ajaxwindmaxgusth_1kts")) {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';
        }
}

function set_ajax_background( name, image ) {
    // 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 (curbackground != image) {
                element.style.backgroundImage = 'url('+image+')';
                curbackground = image;
            }
            
    }

// --- 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", "SSO", "SO", "OSO", "O", "ONO", "NO", "NNO");
   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)
    "night_partly_cloudy.gif"
    );                    

  if (iconWD >= 0 && iconWD <= 36) { 
    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.png",          //  0 imagesunny.visible
    "nskc.png",         //  1 imageclearnight.visible
    "bkn.png",          //  2 imagecloudy.visible
    "sct.png",          //  3 imagecloudy2.visible
    "nbkn.png",         //  4 imagecloudynight.visible
    "sct.png",          //  5 imagedry.visible
    "fg.png",           //  6 imagefog.visible
    "hazy.png",         //  7 imagehaze.visible
    "ra.png",           //  8 imageheavyrain.visible
    "few.png",          //  9 imagemainlyfine.visible
    "mist.png",         // 10 imagemist.visible
    "nfg.png",          // 11 imagenightfog.visible
    "nra.png",          // 12 imagenightheavyrain.visible
    "novc.png",         // 13 imagenightovercast.visible
    "nra.png",          // 14 imagenightrain.visible
    "nshra.png",        // 15 imagenightshowers.visible
    "nsn.png",          // 16 imagenightsnow.visible
    "ntsra.png",        // 17 imagenightthunder.visible
    "ovc.png",          // 18 imageovercast.visible
    "bkn.png",          // 19 imagepartlycloudy.visible
    "ra.png",           // 20 imagerain.visible
    "ra.png",           // 21 imagerain2.visible
    "shra.png",         // 22 imageshowers2.visible
    "ip.png",           // 23 imagesleet.visible
    "ip.png",           // 24 imagesleetshowers.visible
    "sn.png",           // 25 imagesnow.visible
    "sn.png",           // 26 imagesnowmelt.visible
    "sn.png",           // 27 imagesnowshowers2.visible
    "skc.png",          // 28 imagesunny.visible
    "scttsra.png",      // 29 imagethundershowers.visible
    "hi_tsra.png",      // 30 imagethundershowers2.visible
    "tsra.png",         // 31 imagethunderstorms.visible
    "nsvrtsra.png",     // 32 imagetornado.visible
    "wind.png",         // 33 imagewindy.visible
    "ra1.png",          // 34 stopped rainning
    "windyrain.png" ,     // 35 windy/rain (new with V2.11)
    "nfew.png"           // 36 few night
    );                    

  
  
  if (iconWD >= 0 && iconWD <= 36) { 
    return ("<img src=\"" + imagedir + "/" + $iconList[iconWD] + "\" " +
                "width=\"35\" height=\"35\" alt=\"Current condition icon\" />" );
 } else {
    return '';
 }

}

function ajax_wxBackgroundJPG ( iconWD, cond ,cam,solrad) { 
    // perform a lookup and return the graphic for the condition icon (using NWS icons)
      $iconList = new Array(
        "soleil.jpg",          //  0 imagesunny.visible
        "lune.jpg",         //  1 imageclearnight.visible
        "nuageux.jpg",          //  2 imagecloudy.visible
        "peunuageux.jpg",          //  3 imagecloudy2.visible
        "nuageux_nuit.jpg",         //  4 imagecloudynight.visible
        "nuageux2.jpg",          //  5 imagedry.visible
        "brouillard.jpg",           //  6 imagefog.visible
        "brouillard.jpg",         //  7 imagehaze.visible
        "pluie.jpg",           //  8 imageheavyrain.visible
        "peunuageux.jpg",          //  9 imagemainlyfine.visible
        "brume.jpg",         // 10 imagemist.visible
        "brouillard.jpg",          // 11 imagenightfog.visible
        "pluie.jpg",          // 12 imagenightheavyrain.visible
        "couvert.jpg",         // 13 imagenightovercast.visible
        "pluie.jpg",          // 14 imagenightrain.visible
        "pluie.jpg",        // 15 imagenightshowers.visible
        "neige.jpg",          // 16 imagenightsnow.visible
        "orage.jpg",        // 17 imagenightthunder.visible
        "couvert.jpg",          // 18 imageovercast.visible
        "nuageux.jpg",          // 19 imagepartlycloudy.visible
        "pluie.jpg",           // 20 imagerain.visible
        "pluie.jpg",           // 21 imagerain2.visible
        "pluie.jpg",         // 22 imageshowers2.visible
        "pluie.jpg",           // 23 imagesleet.visible
        "pluie.jpg",           // 24 imagesleetshowers.visible
        "neige.jpg",            // 25 imagesnow.visible
        "neige.jpg",           // 26 imagesnowmelt.visible
        "neige.jpg",           // 27 imagesnowshowers2.visible
        "soleil.jpg",          // 28 imagesunny.visible
        "orage.jpg",      // 29 imagethundershowers.visible
        "orage.jpg",      // 30 imagethundershowers2.visible
        "orage.jpg",         // 31 imagethunderstorms.visible
        "pluie.jpg",     // 32 imagetornado.visible
        "blanc.jpg",         // 33 imagewindy.visible
        "blanc.jpg",          // 34 stopped rainning
        "pluie.jpg",     // 35 windy/rain (new with V2.11)
        "nuageux_nuit.jpg"          //  36 imagecloudy.visible
        );                    

  //if (solrad == 0) iconWD = 1;
  
    if (iconWD == 1)  return (imagedir + "/" + $iconList[iconWD] ); 
    if (iconWD == 4)  return (imagedir + "/" + $iconList[iconWD] ); 
    if (iconWD == 8)  return (imagedir + "/" + $iconList[iconWD] );
    if (iconWD == 30)  return (imagedir + "/" + $iconList[iconWD] );
    if (iconWD == 36)  return (imagedir + "/" + $iconList[iconWD] );
    if (iconWD >= 11 && iconWD <= 17) {return (imagedir + "/" + $iconList[iconWD] )}
    if (iconWD >= 20 && iconWD <= 27) {return (imagedir + "/" + $iconList[iconWD] )} 
    if (cond == '---') {return (imagedir + "/blanc.jpg")}
    
     if (solrad == 0)  return (imagedir + "/" + $iconList[iconWD] );
    
 

   return (webcam) ;   
     
 //     if (iconWD >= 0 && iconWD <= 36) { 
 //       return (imagedir + "/" + $iconList[iconWD] );
 //     } 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(3 hour)

// Change Rates
// Rapidly: =.06 inHg; 1.5 mm Hg; 2 hPa; 2 mb
// Slowly: =.02 inHg; 0.5 mm Hg; 0.7 hPa; 0.7 mb

// 5 conditions
// Rising Rapidly
// Rising Slowly
// Steady
// Falling Slowly
// Falling Rapidly

// Page 52 of the PDF Manual
// http://www.davisnet.com/product_documents/weather/manuals/07395.234-VP2_Manual.pdf
// figure out a text value for barometric pressure trend
   if ((btrnd >= -0.7) && (btrnd <= 0.7)) { return(langBaroTrend[0]); }
   if ((btrnd > 0.7) && (btrnd < 2.0)) { return(langBaroTrend[1]); }
   if (btrnd >= 2.0) { return(langBaroTrend[2]); }
   if ((btrnd < -0.7) && (btrnd > -2.0)) { return(langBaroTrend[3]); }
   if (btrnd <= -2.0) { return(langBaroTrend[4]); }
  return(btrnd);
}

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: solid 1px; color: black; background-color: #A4CE6a;\">&nbsp;"+langUVWords[1]+"&nbsp;</span>";
   } else if (uv < 6) {
       uvword = "<span style=\"border: solid 1px; color: black; background-color: #FBEE09;\">&nbsp;"+langUVWords[2]+"&nbsp;</span>";
   } else if (uv < 8) {
       uvword =  "<span style=\"border: solid 1px; color: black; background-color: #FD9125;\">&nbsp;"+langUVWords[3]+"&nbsp;</span>";
   } else if (uv < 11) {
       uvword =  "<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;"+langUVWords[4]+"&nbsp;</span>";
   } else {
       uvword =  "<span style=\"border: solid 1px; color: #FFFF00; background-color: #807780;\">&nbsp;"+langUVWords[5]+"&nbsp;</span>";
   }
   return uvword;
} // end ajax_getUVrange function

function ajax_getsun ( pct ) { 
   var sunword = " ";
   if (pct == 0) {
         sunword = "<span style=\"border: solid 1px; color: white; background-color: #0000B0;\">&nbsp;sombre&nbsp;</span>";
   } //else if (pct <= 7) {
     //      sunword = "<span style=\"border: solid 1px; color: white; background-color: #606060;\">&nbsp;nuages épais/brouillard&nbsp;</span>";
   //} else if (pct < 70) {
    //       sunword = "<span style=\"border: solid 1px; color: white; background-color: #A0A0A0;\">&nbsp;nuages&nbsp;</span>";
  // } else if (pct < 85) {
  //     sunword = "<span style=\"border: solid 1px; color: black; background-color: #D0D0E0;\">&nbsp;nuages partiels&nbsp;</span>";
    else if (pct >= 64) {
       sunword = "<span style=\"border: solid 1px; color: black; background-color: #FFFF00;\">&nbsp;ensoleillé&nbsp;</span>";
   } 
       
   return sunword;
} // end ajax_getsun function

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 > 30 && Humidex > 29) {
  if (Humidex > 50) { return ('<span style="border: solid 1px; color: white; background-color: #BA1928;">&nbsp;'+langHeatWords[1]+'&nbsp;</span>'); }
  if (Humidex > 43) { return ('<span style="border: solid 1px; color: white; background-color: #E02538;">&nbsp;'+langHeatWords[2]+'&nbsp;</span>'); }
  if (Humidex > 39) { return ('<span style="border: solid 1px; color: black; background-color: #E178A1;">&nbsp;'+langHeatWords[4]+'&nbsp;</span>'); }
  if (Humidex > 29) { return ('<span style="border: solid 1px; color: white; background-color: #CC6633;">&nbsp;'+langHeatWords[6]+'&nbsp;</span>'); }
 } else if (WindChill < 15 ) {
  if (WindChill < -15) { return ('<span style="border: solid 1px; color: black; background-color: #91ACFF;">&nbsp;'+langHeatWords[14]+'&nbsp;</span>'); }
  if (WindChill < -5)  { return ('<span style="border: solid 1px; color: white; background-color: #806AF9;">&nbsp;'+langHeatWords[13]+'&nbsp;</span>'); }
  if (WindChill < -1)  { return ('<span style="border: solid 1px; color: white; background-color: #3366FF;">&nbsp;'+langHeatWords[12]+'&nbsp;</span>'); }
  if (WindChill < 8)   { return ('<span style="border: solid 1px; color: white; background-color: #6699FF;">&nbsp;'+langHeatWords[11]+'&nbsp;</span>'); }
  if (WindChill < 15)  { return ('<span style="border: solid 1px; color: black; background-color: #89B2EA;">&nbsp;'+langHeatWords[10]+'&nbsp;</span>'); }
 }  else if (WindChill >= 15 && temp <= 30) {
  if (temp < 22) { return ('<span style="border: solid 1px; color: black; background-color: #66CC66;">&nbsp;'+langHeatWords[9]+'&nbsp;</span>'); }
  if (temp < 26) { return ('<span style="border: solid 1px; color: black; background-color: #FBEE09;">&nbsp;'+langHeatWords[8]+'&nbsp;</span>'); }
  if (temp <= 30) { return ('<span style="border: solid 1px; color: black; background-color: #CC9933;">&nbsp;'+langHeatWords[7]+'&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(', '));


}

function drawwgauge(windir){
    canvas = null;      // the canvas for the plot itself
    overlay = null;     // canvas for interactive stuff on top of plot
    eventHolder = null; // jQuery object that events should be bound to
    ctx = null, octx = null;
    target = null;
    //options = null,
    maxRadius = null;
    centerLeft = null;
    centerTop = null;
    total = 0;
    redraw = true;
    redrawAttempts = 10;
    shrink = 0.95;
    legendWidth = 0;
    processed = false;
    raw = false;
    axes = { xaxis: {}, yaxis: {}, x2axis: {}, y2axis: {} };
    plotOffset = { left: 0, right: 0, top: 0, bottom: 0};
    canvasWidth = 0;
    canvasHeight = 0;
    plotWidth = 0;
    plotHeight = 0;
    
     function makeCanvas(width, height) {
         var c = document.createElement('canvas');
         c.width = width;
         c.height = height;
         if ($.browser.msie) // excanvas hack
             c = window.G_vmlCanvasManager.initElement(c);
         return c;
     }
     
     function setupgauge()
        {
            // calculate maximum radius and center point
            maxRadius =  Math.min(canvas.width,canvas.height)/2;
            centerTop = (canvas.height/2);
            centerLeft = (canvas.width/2);
            
            if (centerLeft<maxRadius)
                centerLeft = maxRadius;
            else if (centerLeft>canvas.width-maxRadius)
                centerLeft = canvas.width-maxRadius;
        }
     
    var placeholder = $("#ajaxwdir");
    var winddirs = 'N,NE,E,SE,S,SO,O,NO';
    var wdirs = winddirs.split(',');
    var numbersoffset = -10;
    var dotsoffset = 2;
    var angle = 360;
    var radians = function (deg) { return deg * Math.PI/180; };
    var a = 135;
    var html = '';
    
    
    
    canvasWidth = placeholder.width();
    canvasHeight = placeholder.height();
    placeholder.empty();
    placeholder.html(""); // clear placeholder
    
    if (placeholder.css("position") == 'static')
        placeholder.css("position", "relative"); // for positioning labels and overlay

    if (canvasWidth <= 0 || canvasHeight <= 0)
        throw "Invalid dimensions for plot, width = " + canvasWidth + ", height = " + canvasHeight;

    if ($.browser.msie) // excanvas hack
        window.G_vmlCanvasManager.init_(document); // make sure everything is setup
    
    // the canvas
    
    canvas = $(makeCanvas(canvasWidth, canvasHeight)).appendTo(placeholder).get(0);
    
    ctx = canvas.getContext("2d");
    setupgauge();
    
    var radius = maxRadius/2;
    
    ctx.clearRect(0,0,canvas.width,canvas.height);
    var b = -90;
    var t = 0*1;
    
    // light circle
    ctx.beginPath();
              ctx.arc(centerTop, centerLeft, radius-dotsoffset, 0, Math.PI * 2, true);
    ctx.strokeStyle = 'rgba(52,52,52,0.8)';
              ctx.closePath();
              ctx.lineWidth = 1;
              ctx.stroke();
              ctx.save();
              ctx.restore();

    // Dir-words
    for (var i = 1; i < 360;) {
              var ao = 0;var bo = 0;
              if(b == -90) { var ao = 2;var bo = -3;var font ='font-size: 10px;'; }
              else if(b == 90) { var ao = 2;var font ='font-size: 10px;'; }
              else if(b == 0) { var ao = 2;var font ='font-size: 10px;';}
              else if(b == 180) {var ao = 2;var font ='font-size: 10px;';}
              else {var font = '';}
              var labelx = (centerLeft + Math.cos(radians(b)) * (radius-numbersoffset));
    var labely = (centerTop + Math.sin(radians(b)) * (radius-numbersoffset));
    var html = '<span  class="gaugeLabel" id="gaugeLabel'+i+'" style="position:absolute;top:' + (bo+labely-6*1) + 'px;left:' + (ao+labelx-6*1) + 'px;"><div>' + wdirs[t] + "</div></span>";
    placeholder.append(html);
    t++;
    t++;
    b += 90;
    i = i+90*1;
    }
    
    ctx.translate(centerLeft,centerTop);           
    // Arrow
    ctx.fillStyle = "rgb(0,160,0)";
    var wdir = windir;
    var wdir = (Math.PI*(-0.5 + wdir * 2 / 360));
    ctx.rotate(wdir);
    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.lineTo(28, -7);
    ctx.bezierCurveTo(21, -3, 21, 3, 28, 7); 
    ctx.lineTo(0, 0);
    ctx.fill();   
    
      
}

function barcolor(windvalue) {
    var wcolor="";
    var currentval = -Math.log(1-windvalue/100)/0.03;
     
    if (currentval > 0) {wcolor='#c0c0ff';} 
    if (currentval > 1) {wcolor='#b6c6ef';} 
    if (currentval > 2) {wcolor='#adcddf';} 
    if (currentval > 3) {wcolor='#a3d3cf';} 
    if (currentval > 4) {wcolor='#9ad9bf';} 
    if (currentval > 5) {wcolor='#90e0b0';} 
    if (currentval > 6) {wcolor='#86e6a0';} 
    if (currentval > 7) {wcolor='#7dec90';} 
    if (currentval > 8) {wcolor='#73f280';} 
    if (currentval > 9) {wcolor='#6af970';} 
    if (currentval > 10) {wcolor='#60ff60';} 
    if (currentval > 11) {wcolor='#68ff5b';} 
    if (currentval > 12) {wcolor='#70ff56';} 
    if (currentval > 13) {wcolor='#78ff52';} 
    if (currentval > 14) {wcolor='#80ff4d';} 
    if (currentval > 15) {wcolor='#88ff48';} 
    if (currentval > 16) {wcolor='#90ff43';} 
    if (currentval > 17) {wcolor='#98ff3e';} 
    if (currentval > 18) {wcolor='#a0ff3a';} 
    if (currentval > 19) {wcolor='#a8ff35';} 
    if (currentval > 20) {wcolor='#b0ff30';} 
    if (currentval > 21) {wcolor='#b7ff2b';} 
    if (currentval > 22) {wcolor='#bfff26';} 
    if (currentval > 23) {wcolor='#c7ff22';} 
    if (currentval > 24) {wcolor='#cfff1d';} 
    if (currentval > 25) {wcolor='#d7ff18';} 
    if (currentval > 26) {wcolor='#dfff13';} 
    if (currentval > 27) {wcolor='#e7ff0e';} 
    if (currentval > 28) {wcolor='#efff0a';} 
    if (currentval > 29) {wcolor='#f7ff05';} 
    if (currentval > 30) {wcolor='#ffff00';} 
    if (currentval > 31) {wcolor='#fff705';} 
    if (currentval > 32) {wcolor='#ffef0a';} 
    if (currentval > 33) {wcolor='#ffe70e';} 
    if (currentval > 34) {wcolor='#ffdf13';} 
    if (currentval > 35) {wcolor='#ffd718';} 
    if (currentval > 36) {wcolor='#ffcf1d';} 
    if (currentval > 37) {wcolor='#ffc722';} 
    if (currentval > 38) {wcolor='#ffbf26';} 
    if (currentval > 39) {wcolor='#ffb72b';} 
    if (currentval > 40) {wcolor='#ffb030';} 
    if (currentval > 41) {wcolor='#ffa835';} 
    if (currentval > 42) {wcolor='#ffa03a';} 
    if (currentval > 43) {wcolor='#ff983e';} 
    if (currentval > 44) {wcolor='#ff9043';} 
    if (currentval > 45) {wcolor='#ff8848';} 
    if (currentval > 46) {wcolor='#ff804d';} 
    if (currentval > 47) {wcolor='#ff7852';} 
    if (currentval > 48) {wcolor='#ff7056';} 
    if (currentval > 49) {wcolor='#ff685b';} 
    if (currentval > 50) {wcolor='#ff6060';} 
    if (currentval > 51) {wcolor='#ff6065';} 
    if (currentval > 52) {wcolor='#ff606b';} 
    if (currentval > 53) {wcolor='#ff6070';} 
    if (currentval > 54) {wcolor='#ff6075';} 
    if (currentval > 55) {wcolor='#ff607b';} 
    if (currentval > 56) {wcolor='#ff6080';} 
    if (currentval > 57) {wcolor='#ff6085';} 
    if (currentval > 58) {wcolor='#ff608a';} 
    if (currentval > 59) {wcolor='#ff6090';} 
    if (currentval > 60) {wcolor='#ff6095';} 
    if (currentval > 61) {wcolor='#ff609a';} 
    if (currentval > 62) {wcolor='#ff60a0';} 
    if (currentval > 63) {wcolor='#ff60a5';} 
    if (currentval > 64) {wcolor='#ff60aa';} 
    if (currentval > 65) {wcolor='#ff60b0';} 
    if (currentval > 66) {wcolor='#ff60b5';} 
    if (currentval > 67) {wcolor='#ff60ba';} 
    if (currentval > 68) {wcolor='#ff60bf';} 
    if (currentval > 69) {wcolor='#ff60c5';} 
    if (currentval > 70) {wcolor='#ff60ca';} 
    if (currentval > 71) {wcolor='#ff60cf';} 
    if (currentval > 72) {wcolor='#ff60d5';} 
    if (currentval > 73) {wcolor='#ff60da';} 
    if (currentval > 74) {wcolor='#ff60df';} 
    if (currentval > 75) {wcolor='#ff60e5';} 
    if (currentval > 76) {wcolor='#ff60ea';} 
    if (currentval > 77) {wcolor='#ff60ef';} 
    if (currentval > 78) {wcolor='#ff60f4';} 
    if (currentval > 79) {wcolor='#ff60fa';} 
    if (currentval > 80) {wcolor='#ff60ff';}
    if (currentval > 85) {wcolor='#a060a0';}
    if (currentval > 90) {wcolor='#906090';}
    return wcolor; 
}


function setgustbar() {
 
 var deltav = targetv-currentv;
 var deltav1 = targetv1-currentv1;
 var deltav10 = targetv10-currentv10;
 var delta1m = target1m-current1m;
 var deltahour = targethour-currenthour;
 var deltaday = targetday-currentday;
 
 if (Math.abs(deltav) < stepv) { deltav=0; currentv = targetv}
 if (deltav > 0) { currentv = currentv+stepv;}
 if (deltav < 0) { currentv = currentv-stepv;}
 
 if (Math.abs(deltav1) < stepv) { deltav1=0; currentv1 = targetv1}
 if (deltav1 > 0) { currentv1 = currentv1+stepv;}
 if (deltav1 < 0) { currentv1 = currentv1-stepv;}
 
 if (Math.abs(deltav10) < stepv) { deltav10=0; currentv10 = targetv10}
 if (deltav10 > 0) { currentv10 = currentv10+stepv;}
 if (deltav10 < 0) { currentv10 = currentv10-stepv;}
 
 if (Math.abs(deltaday) < stepv) { deltaday=0; currentday = targetday}
 if (deltaday > 0) { currentday = currentday+stepv;}
 if (deltaday < 0) { currentday = currentday-stepv;}
 
 if (Math.abs(deltahour) < stepv) { deltahour=0; currenthour = targethour}
 if (deltahour > 0) { currenthour = currenthour+stepv;}
 if (deltahour < 0) { currenthour = currenthour-stepv;}
 
 if (Math.abs(delta1m) < stepv) { delta1m=0; current1m = target1m}
 if (delta1m > 0) { current1m = current1m+stepv;}
 if (delta1m < 0) { current1m = current1m-stepv;}
 
 var deltad=(targetdir-currentdir);
 
 if (Math.abs(deltad) <= stepd) {
     deltad=0;
     currentdirs=targetdir;
 }
 if ((deltad > 0) && (deltad >= 180)) {
     currentdir=(currentdir-stepd) % 360;
 }
 if ((deltad > 0) && (deltad < 180)) {
     currentdir=(currentdir+stepd) % 360;
      }
 if ((deltad < 0) && (deltad > -180)) {
     currentdir=(currentdir-stepd) % 360;
 }
 if ((deltad < 0) && (deltad <= -180)) {
     currentdir=(currentdir+stepd) % 360;
 }
 if (currentdir < 0) {
     currentdir = 360 + currentdir;
 }
 
 if ($('#stab-1').css('display') != 'none') {
    $('#gustbar').progressbar('value', currentv);
    $('#gustbar > div').css('background',barcolor(currentv));
    $('#vent1min').progressbar('value', currentv1);
    $('#vent1min > div').css('background',barcolor(currentv1));
    $('#vent10min').progressbar('value', currentv10);
    $('#vent10min > div').css('background',barcolor(currentv10));
    $('#vent10min').progressbar('value', currentv10);
    $('#vent10min > div').css('background',barcolor(currentv10));
    $('#maxhour').progressbar('value', currenthour);
    $('#maxhour > div').css('background',barcolor(currenthour));
    $('#maxminute').progressbar('value', current1m);
    $('#maxminute > div').css('background',barcolor(current1m));
    $('#maxday').progressbar('value', currentday);
    $('#maxday > div').css('background',barcolor(currentday));
     if ( (-Math.log(1-currentday/100)/0.03) >= 50) { 
            $('#ajaxwindmaxgust').css('color','white');
        } else {
            $('#ajaxwindmaxgust').css('color','black');   
        } 
      if ((-Math.log(1-currenthour/100)/0.03) >= 50) { 
            $('#ajaxwindmaxgusth').css('color','white');
        } else {
            $('#ajaxwindmaxgusth').css('color','black');   
        } 
      if ((-Math.log(1-current1m/100)/0.03) >= 50) { 
            $('#ajaxwindmaxgustminute').css('color','white');
        } else {
            $('#ajaxwindmaxgustminute').css('color','black');   
        } 
    drawwgauge(currentdir);}
 
 setTimeout("setgustbar('')",WindreloadTime); // change wind progress bar
}

// ------------------------------------------------------------------------------------------
//  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]);
        dif1 = convertTemp(clientraw[22]) - temp;
        dif2 = convertTemp(clientraw[24]) - temp;
        set_ajax_obs("ajaxtemp", temp.toFixed(1) + uomTemp);
        set_ajax_obs("ajaxtemp2", temp.toFixed(1) + uomTemp);
        set_ajax_obs("ajaxtemp_1", temp.toFixed(1) + uomTemp);
        set_ajax_obs("ajaxbigtemp",temp.toFixed(1) + uomTemp);
        
        if (dif1 > 0) {
            set_ajax_obs("ajaxdif1", "+"+dif1.toFixed(1) + uomTemp);
            set_ajax_obs("ajaxdif2", "+"+dif1.toFixed(1) + uomTemp);}
        else {
            set_ajax_obs("ajaxdif1", dif1.toFixed(1) + uomTemp);
            set_ajax_obs("ajaxdif2", dif1.toFixed(1) + uomTemp);}
        
//        if (dif2 > 0) {set_ajax_obs("ajaxdif2","+"+ dif2.toFixed(1) + uomTemp);}
//        else {set_ajax_obs("ajaxdif2", dif2.toFixed(1) + uomTemp);}
        
        if (temp >= 0) {set_ajax_obs("ajaxgel"," ");}
        if (temp >= 0) {set_ajax_obs("ajaxgel_1"," ");}
        
        
        templast = convertTemp(clientraw[90]);
        set_ajax_obs("ajaxtemparrow", 
           ajax_genarrow(temp, templast, '', 
             langTempRising+uomTemp+langTempLastHour,
             langTempFalling+uomTemp+langTempLastHour,1)
           );    
        temprate = temp - templast;
        temprate = temprate.toFixed(1);
        if (temprate > 0.0) { temprate = '+' + temprate;} // add '+' for positive rates
        set_ajax_obs("ajaxtemprate",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);
        
        tempi = convertTemp(clientraw[12]);
        set_ajax_obs("ajaxtempi",tempi.toFixed(1) + uomTemp);
        set_ajax_obs("ajaxtempi_1",tempi.toFixed(1) + uomTemp);
        
        tempc = convertTemp(clientraw[20]);
        set_ajax_obs("ajaxtempc",tempc.toFixed(1) + uomTemp);
        set_ajax_obs("ajaxtempc_1",tempc.toFixed(1) + uomTemp);
        
        
        amplitude = tempmax - tempmin;
        set_ajax_obs("ajaxtempampl",amplitude.toFixed(1)); 
        
        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 + "\" />" );

        //Humidity ...
        humidity = clientraw[5];
        set_ajax_obs("ajaxhumidity",humidity);
        set_ajax_obs("ajaxhumidity_1",humidity);
        // sorry.. no min/max data for humidity available in clientraw.txt
        
        humi = clientraw[13];
        set_ajax_obs("ajaxhumi",humi);
        set_ajax_obs("ajaxhumi_1",humi);
        
        leaf = clientraw[156];
        set_ajax_obs("ajaxleaf",leaf);   
        //Dewpoint ...
        dew = convertTemp(clientraw[72]);
        set_ajax_obs("ajaxdew",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);
        set_ajax_obs("ajaxheatcolorword1",heatColorWord);
        set_ajax_obs("ajaxheatcolorword_1",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);
        pressuretrend = convertBaro(clientraw[50]);
        pressuretrend = pressuretrend.toFixed(dpBaro+1);
        if (pressuretrend > 0.0) {pressuretrend = '+' + pressuretrend; } // add '+' to rate
        set_ajax_obs("ajaxbarotrend",pressuretrend + uomBaro);
        set_ajax_obs("ajaxbaroarrow",
           ajax_genarrow(pressure, pressure-pressuretrend, '', 
             langBaroRising+uomBaro+langBaroPerHour,
             langBaroFalling+uomBaro+langBaroPerHour,2)
             );    
        
        set_ajax_obs("ajaxbarotrendtext",ajax_get_barotrend(clientraw[50]));

        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[2]);
        gustkts = clientraw[2]*1.0;
        maxgust = convertWind(clientraw[71]);
        maxgustkts = clientraw[71]*1.0;
        if (maxgust > 0.0 ) {
          set_ajax_obs("ajaxmaxgust",maxgust.toFixed(1) + uomWind);
          set_ajax_obs("ajaxmaxgustkts",maxgustkts.toFixed(1) + uomWind);
        } else {
          set_ajax_obs("ajaxmaxgust",'None');
          set_ajax_obs("ajaxmaxgustkts",'None');
        }

        //Windspeed ...
        wind = convertWind(clientraw[158]);
        wind1 = convertWind(clientraw[1]); 
        windkts = clientraw[158]*1.0;
        wind1kts = clientraw[1]*1.0; 
        
      //WIND DIRECTION ...
        val = windDir(clientraw[3]);
        valLang = windDirLang(clientraw[3]); /* to enable translations */
        targetdir = clientraw[3];
        
        beaufortnum = ajax_get_beaufort_number(clientraw[2]);
        set_ajax_obs("ajaxbeaufortnum",targetdir + '° - ' + beaufortnum);
        set_ajax_obs("ajaxbeaufort",langBeaufort[beaufortnum]);
        set_ajax_obs("ajaxbeaufort1",langBeaufort[beaufortnum]);

       if (wind >= 50) { 
            $('#ajaxwind').css('color','white');
        } else {
            $('#ajaxwind').css('color','black');   
        } 
        
       if (wind > 0.0) {
        set_ajax_obs("ajaxwind",wind.toFixed(1) + uomWind);
        set_ajax_obs("ajaxwindkts",windkts.toFixed(1) + " noeuds");
        set_ajax_uom("ajaxwinduom",true);
       } else {
        set_ajax_obs("ajaxwind",langWindCalm);
        set_ajax_uom("ajaxwinduom",false);
       }
        if (wind1 >= 50) { 
            $('#ajaxwind1').css('color','white');
        } else {
            $('#ajaxwind1').css('color','black');   
        } 
        if (wind1 > 0.0) { 
        set_ajax_obs("ajaxwind1",wind1.toFixed(1) + uomWind);
        set_ajax_obs("ajaxwind1kts",wind1kts.toFixed(1) + " noeuds");
        set_ajax_uom("ajaxwinduom",true);
       } else {
        set_ajax_obs("ajaxwind1",langWindCalm);
        set_ajax_obs("ajaxwind1kts",langWindCalm);
        set_ajax_uom("ajaxwinduom",false);
       }
        targetv = (1-Math.exp(-gust*0.03))*100;
        targetv1 = (1-Math.exp(-wind1*0.03))*100;
        targetv10 = (1-Math.exp(-wind*0.03))*100;
        
       
        
  //      if (lasttime == clientraw[29] + ":" + clientraw[30] + ":" + clientraw[31] ) 
  //         {lastgust.push(null);} 
  //      else 
          lastgust.push(gust);  
        
        lasttime = clientraw[29] + ":" + clientraw[30] + ":" + clientraw[31];             
       
        if (lastwind.length > maxwinddata) {
                    lastgust.splice(0,1);
        }
        
        $('#gustline').sparkline(lastgust, { width: 130 , height : 30, lineColor : 'black', fillColor : false });
        //$('#windline').sparkline(lastwind, { width: 200 , height : 30, lineColor : 'black', fillColor : false }); 
       
       if (gust > 0.0) {
        set_ajax_obs("ajaxgust","&nbsp;"+gust.toFixed(1) + uomWind);
        set_ajax_obs("ajaxgustkts","&nbsp;"+gustkts.toFixed(1) + " noeuds");
        set_ajax_obs("ajaxgust_1","&nbsp;"+gust.toFixed(1) + uomWind);
        set_ajax_obs("ajaxgust_1kts","&nbsp;"+gustkts.toFixed(1) + " noeuds");
        set_ajax_obs("ajaxgust2",gust.toFixed(1) + uomWind);
        set_ajax_uom("ajaxgustuom",true);
        set_ajax_obs("ajaxwinddir_1",valLang);
       } else {
        set_ajax_obs("ajaxgust","&nbsp;"+langGustNone);
        set_ajax_obs("ajaxgustkts","&nbsp;"+langGustNone);
        set_ajax_obs("ajaxgust_1","&nbsp;"+langGustNone);
        set_ajax_obs("ajaxgust_1kts","&nbsp;"+langGustNone);
        set_ajax_obs("ajaxgust2",langGustNone);
        set_ajax_uom("ajaxgustuom",false);
        set_ajax_obs("ajaxwinddir_1","");
       }
      
       
       
          if (gust > 0.0 || wind > 0.0) {
        set_ajax_obs("ajaxwindicon",
         "<img src=\"" + imagedir + "/" +  val + ".gif\" width=\"14\" height=\"14\" alt=\"" + 
          langWindFrom + valLang + "\" title=\"" + langWindFrom + valLang + "\" /> ");
 //        set_ajax_obs("ajaxwindiconwr",
//          "<img src=\"/charts/wdirgauge.php?a=" + targetdir + "\" width=\"80\" height=\"80\"/> ");
//        if (Math.abs(targetdir-currentdir) > 0) {JsChartViewer.get('ajaxwdir').streamUpdate(1);}
//        currentdir=targetdir;
        set_ajax_obs("ajaxwinddir",valLang);
        
       } else {
        set_ajax_obs("ajaxwindicon","");
        set_ajax_obs("ajaxwinddir","");
        
        if (wrCalm != '') {
         set_ajax_obs("ajaxwindiconwr",
          "<img src=\"" + imagedir + "/" + wrCalm + "\" width=\""+
           wrWidth+"\" height=\""+wrHeight+"\" alt=\"" + 
          langBeaufort[0] + "\" title=\"" +langBeaufort[0] + "\" /> ");
        }
       }
        windmaxgustminute = convertWind(clientraw[140]);
        windmaxgustminutekts = clientraw[140]*1.0;
        
         
       if (windmaxgustminute > 0.0) {
        set_ajax_obs("ajaxwindmaxgustminute",windmaxgustminute.toFixed(1) + uomWind);
        set_ajax_obs("ajaxwindmaxgustminutekts",windmaxgustminutekts.toFixed(1) + " noeuds");
        
       } else {
        set_ajax_obs("ajaxwindmaxgustminute","&nbsp;"+langGustNone);
        set_ajax_obs("ajaxwindmaxgustminutekts","&nbsp;"+langGustNone);
        
       }
       
        windmaxavg = convertWind(clientraw[113]);
        set_ajax_obs("ajaxwindmaxavg",windmaxavg.toFixed(1) + uomWind);
        
        windmaxgust = convertWind(clientraw[71]);
        windmaxgustkts = clientraw[71]*1.0;
       
        set_ajax_obs("ajaxwindmaxgust",windmaxgust.toFixed(1) + uomWind);
         set_ajax_obs("ajaxwindmaxgustkts",windmaxgustkts.toFixed(1) + " noeuds");
        set_ajax_obs("ajaxwindmaxgust_1",windmaxgust.toFixed(1) + uomWind);
        set_ajax_obs("ajaxwindmaxgust_1kts",windmaxgustkts.toFixed(1) + " noeuds");
        
        windmaxgusth = convertWind(clientraw[133]);
        windmaxgusthkts = clientraw[133]*1.0;
        
        
        set_ajax_obs("ajaxwindmaxgusth",windmaxgusth.toFixed(1) + uomWind);
        set_ajax_obs("ajaxwindmaxgusthkts",windmaxgusthkts.toFixed(1) + " noeuds");
        set_ajax_obs("ajaxwindmaxgusth_1",windmaxgusth.toFixed(1) + uomWind);
        set_ajax_obs("ajaxwindmaxgusth_1kts",windmaxgusthkts.toFixed(1) + " noeuds");
        
        target1m = (1-Math.exp(-windmaxgustminute*0.03))*100;
        targethour = (1-Math.exp(-windmaxgusth*0.03))*100;
        targetday = (1-Math.exp(-windmaxgust*0.03))*100;

        windmaxgusttime = clientraw[135];
        windmaxgusttime = windmaxgusttime.toLowerCase();
        windmaxgusttime = windmaxgusttime.replace( "_" , "");
        set_ajax_obs("ajaxwindmaxgusttime",windmaxgusttime);
        set_ajax_obs("ajaxwindmaxgusttime_1",windmaxgusttime);
        
        windmaxgusthtime = clientraw[134];
        windmaxgusthtime = windmaxgusthtime.toLowerCase();
        windmaxgusthtime = windmaxgusthtime.replace( "_" , "");
        set_ajax_obs("ajaxwindmaxgusthtime",windmaxgusthtime);
        

        //  Solar Radiation
        solar    = clientraw[127] * 1.0;
        set_ajax_obs("ajaxsolar",solar.toFixed(0));
        set_ajax_obs("ajaxsolar_1",solar.toFixed(0));

        solarpct = clientraw[34];
        set_ajax_obs("ajaxsolarpct",solarpct);
        
        sunword = ajax_getsun(solarpct);
        set_ajax_obs("ajaxsunword",sunword);
        set_ajax_obs("ajaxsunword_1",sunword);
        
        // UV Index        
        uv       = clientraw[79];
        set_ajax_obs("ajaxuv",uv) ;

        uvword = ajax_getUVrange(uv);
        set_ajax_obs("ajaxuvword",uvword);
        set_ajax_obs("ajaxuvword1",uvword);

        //Rain ...
        rain = convertRain(clientraw[7]);
        if (rain > 0) {
            set_ajax_obs("ajaxrain",rain.toFixed(dpRain) + uomRain);
            set_ajax_obs("ajaxrain_1",rain.toFixed(dpRain) + uomRain);}
        else {
            set_ajax_obs("ajaxrain"," ");
            set_ajax_obs("ajaxrain_1"," ");
            }
        

        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.
        
        
        

        rainratemax = convertRain(clientraw[11]) * 60; // make per hour rate
        set_ajax_obs("ajaxrainratemax",rainratemax.toFixed(dpRain+1) + uomRain);
        
        if (rainratehr >= 0.6) {
            set_ajax_obs("ajaxrainratehr","Taux de précipitation :<br />" + rainratehr.toFixed(dpRain+1) + uomRain+"/h");  
            set_ajax_obs("ajaxrainratehr_1","Taux de précipitation : " + rainratehr.toFixed(dpRain+1) + uomRain+"/h");  
            set_ajax_obs("ajaxrainratehr_iphone","<br/>Taux de précipitation : " + rainratehr.toFixed(dpRain+1) + uomRain+"/h"); 
            set_ajax_obs("ajaxdesert"," ");
            set_ajax_obs("ajaxdesert_1"," ");}
        
        if (rainratehr < 0.6) {
            set_ajax_obs("ajaxrainratehr"," "); 
            set_ajax_obs("ajaxrainratehr_1"," "); 
            set_ajax_obs("ajaxrainratehr_iphone"," "); 
           }

        // 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);
        
        if (lastajaxtimeformat != ajaxtimeformat) {
            counterSecs = 0;                      // reset timer
            lastajaxtimeformat = ajaxtimeformat; // remember this time
        }
        
        ajicon = clientraw[48];
        ajiconp = ajicon;
        
        if (solar == 0 && dif1 <= -1.4) {
              ajicon = 1;
              nightcondition = " ciel dégagé";
            }
        
        if (solar == 0 && dif1 > -1.4) {
              ajicon = 36;    
              nightcondition = " partiellement nuageux";
            }
        
        if (solar == 0 && dif1 > -0.9) {
              ajicon = 4;
              nightcondition = " nuageux";
            }
        
        if (solar == 0 && dif1 > -.5) {
              ajicon = 18;    
              nightcondition = " couvert";
            }

        if (ajiconp == 8 || ajiconp == 12 || ajiconp == 14 || ajiconp == 15 || ajiconp == 16 || ajiconp == 20 || ajiconp == 21 || ajiconp == 22 || ajiconp == 23 || ajiconp == 24 || ajiconp == 25 || ajiconp == 26 || ajiconp == 27 || ajiconp == 35 || ajiconp == 35) {
              ajicon = ajiconp;
              nightcondition = "";
        }
        
 //       if (humidity < 80 && leaf ==15) {
 //         ajicon = 20;    
 //       }    
        
        
        
        // current condition icon and description
        set_ajax_obs("ajaxconditionicon",
            ajax_wxIcon(ajicon)
            );

        set_ajax_obs("ajaxconditionicon2",
            ajax_wxIconJPG(ajicon)
            );
        
         

        currentcond = clientraw[49];
//        currentcond = currentcond.replace(/_/g,' ');
        currentcond = currentcond.replace(/\/sec/g,'');
        currentcond = currentcond.replace(/\\/g,', ');
//        currentcond = currentcond.replace(/\//g,', ');
// METAR translation English to French begins
currentcond = currentcond.replace(/Cloudy_with_clear_patches/g,'principalement nuageux');
currentcond = currentcond.replace(/Clear/g,'d&eacute;gag&eacute;');
//currentcond = currentcond.replace(/Sc/g,'partiellement nuageux');
currentcond = currentcond.replace(/A_few_clouds_/g,'quelques nuages');
currentcond = currentcond.replace(/Scattered_clouds_/g,'nuages &eacute;pars');
currentcond = currentcond.replace(/partly_cloudy/g,'partiellement nuageux');
currentcond = currentcond.replace(/partly_clear/g,'partiellement nuageux');
currentcond = currentcond.replace(/mostly_cloudy_-/g,'nuageux');
currentcond = currentcond.replace(/mostly_cloudy/g,'nuageux');
currentcond = currentcond.replace(/mostly_clear/g,'principalement d&eacute;gag&eacute;');
currentcond = currentcond.replace(/obscured/g,'brumeux');
currentcond = currentcond.replace(/overcast/g,'couvert');
currentcond = currentcond.replace(/Overcast_/g,'couvert')
currentcond = currentcond.replace(/Crepuscule/g,'Cr&eacute;puscule');
currentcond = currentcond.replace(/Haze/g,'Brume');

if (solar == 0 && nightcondition !="") {
currentcond = "nuit,"+nightcondition;    
}

// METAR translation English to French ends
if (humidity < 85 && leaf ==15) {
      currentcond = currentcond + ", quelques gouttes";    
    }
    

set_ajax_background("ajaxbackground",
        ajax_wxBackgroundJPG(ajicon,currentcond,webcam,solar)
        );


        set_ajax_obs("ajaxcurrentcond",ajaxFixupCondition(currentcond));
        
        // cloud height
        cloudheight = clientraw[73];
        set_ajax_obs("ajaxcloudheight",convertHeight(cloudheight) + uomHeight);

        
        // 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 */
            set_ajax_obs("ajaxindicator",langPauseMsg);
            var mlist = $('#ajaxbackground').sortable("toArray");
            for (var i = 0, n = mlist.length; i < n; i++ ) {
                $('#p'+(i+1)).css({'opacity': '0.5'});
            set_ajax_background("ajaxbackground",imagedir + "/blanc.jpg");
            $(".personnaliser").hide();
            }
        }
        if (crage > 900) { /* no data received since 900 seconds */
            set_ajax_obs("ajaxindicator",langOfflineMsg);
            var mlist = $('#ajaxbackground').sortable("toArray");
            for (var i = 0, n = mlist.length; i < n; i++ ) {
                $('#p'+(i+1)).css({'opacity': '0.5'});
            set_ajax_background("ajaxbackground",imagedir + "/blanc.jpg");
            $(".personnaliser").hide();
            }
        }       
        
        
        
        
        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 ((crage < 900) && ((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
//}

  window.setInterval("set_webcam()", 20000); // run the counter for seconds since update
    
// invoke when first loaded on page
//if (! ajaxLoaderInBody) { ajaxLoader(clientrawFile + '?' + new Date().getTime(), reloadTime); }
//setTimeout("setgustbar()",FirstWindreloadTime); // change wind progress bar

// ]]>
