
// <![CDATA[
// -- begin settings --------------------------------------------------------------------------
var flashcolor = '#00CC00'; // color to flash for changed observations RGB
var flashtime  = 3000;    // miliseconds to keep flash color on (2000 = 2 seconds);
var reloadTime = 5000;      // reload AJAX conditions every 5 seconds (= 5000 ms)
var rlt	=1000;
var clientrawFile = '/dbfull.php'; // location of dbtest.php 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 = 'E';         // '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 showUnits = true;       //  set to false if no units are to be displayed
// -- end of settings -------------------------------------------------------------------------

// --- you don't need to customize the stuff below, the actions are controlled by the 
//  settings above.  

var ie4=document.all;
var browser = navigator.appName;
var counterSecs = 0;  // for MCHALLIS counter script from weather-watch.com (adapted by K. True)
var lastajaxtimeformat = 'unknown'; //used to reset the counter when a real update is done

// handle setup options for units-of-measure and whether to show them at all
var uomTemp = '&deg;F';
var uomWind = ' mph';
var uomBaro = ' inHg';
var uomRain = ' in';
var uomHeight = ' ft';
var dpBaro = 2;
var dpRain = 2;
var first = 0;
var first1 = 0;
var first2 = 0;
var firstadv = 0;
var firstevt = 0;
var firstart = 2;
var alertpridata = "";
var unique = 0;

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

ajax_set_units(useunits);

// utility functions to navigate the HTML tags in the page
function get_ajax_tags ( ) {
// search all the span tags and return the list with class="ajax" in it
//
  if (ie4 && browser != "Opera") {
    var elem = document.body.getElementsByTagName('span');
	var lookfor = 'className';
  } else {
    var elem = document.getElementsByTagName('span');
	var lookfor = 'class';
  }
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute(lookfor);
          if(att == 'ajax') {
               arr[iarr] = elem[i];
               iarr++;
          }
     }

     return arr;
}

function reset_ajax_color( usecolor ) {
// reset all the <span class="ajax"...> styles to have no color override
      var elements = get_ajax_tags();
	  var numelements = elements.length;
	  for (var index=0;index!=numelements;index++) {
         var element = elements[index];
	     element.style.color=usecolor;

        element = document.getElementById("ajaxactive");
		if (element) {
         		element.innerHTML =  '       ';
			}

 
      }
}

function set_ajax_obs( name, value ) {
// store away the current value in both the doc and the span as lastobs="value"
// change color if value != lastobs

		var element = document.getElementById(name);
		if (! element ) { return; } // V1.04 -- don't set if missing the <span id=name> tag
		var lastobs = element.getAttribute("lastobs");
		element.setAttribute("lastobs",value);
		if (value != unescape(lastobs)) {
          element.style.color=flashcolor;
		}
		element.innerHTML =  value;
}

function set_ajax_uom( name, onoroff ) {
// this function will set an ID= to visible or hidden by setting the style="display: "
// from 'inline' or 'none'

		var element = document.getElementById(name);
		if (! element ) { return; } 
		if (onoroff) {
          element.style.display='inline';
		} else {
          element.style.display='none';
		}
}

// --- end of flash-green functions

function windDir ($winddir)
// Take wind direction value, return the
// text label based upon 16 point compass -- function by beeker425
//  see http://www.weather-watch.com/smf/index.php/topic,20097.0.html
{
   $windlabel = new Array("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW");
   return $windlabel[Math.floor(((parseInt($winddir) + 11) / 22.5) % 16 )];
}

function ajax_wxIcon ( iconWD ) { 
// perform a lookup and return the graphic for the condition icon (using anole's
// wxsticker icon names
  $iconList = new Array(
	"day_clear.gif",           //  0 imagesunny.visible
	"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
	);					

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

}

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

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

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

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

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

function ajax_get_beaufort ( wind ) { 
// return a phrase for the beaufort scale based on wind knots (native WD format)
  if (wind < 1 ) {return("Calm"); }
  if (wind < 4 ) {return("Light air"); }
  if (wind < 7 ) {return("Light breeze"); }
  if (wind < 11 ) {return("Gentle breeze"); }
  if (wind < 17 ) {return("Moderate breeze"); }
  if (wind < 22 ) {return("Fresh breeze"); }
  if (wind < 28 ) {return("Strong breeze"); }
  if (wind < 34 ) {return("Near gale"); }
  if (wind < 41 ) {return("Gale"); }
  if (wind < 48 ) {return("Strong gale"); }
  if (wind < 56 ) {return("Storm"); }
  if (wind < 64 ) {return("Violent storm"); }
  if (wind >= 64 ) {return("Hurricane"); }
  return("unknown " + wind);
}

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

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

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

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

function ajax_getUVrange ( uv ) { // code simplified by FourOhFour on wxforum.net
   var uvword = "Unspec.";
   if (uv <= 0) {
       uvword = "None";
   } else if (uv < 3) {
       uvword = "<span style=\"border: solid 1px; background-color: #A4CE6a;\">&nbsp;Low&nbsp;</span>";
   } else if (uv < 6) {
       uvword = "<span style=\"border: solid 1px; background-color: #FBEE09;\">&nbsp;Medium&nbsp;</span>";
   } else if (uv < 8) {
       uvword =  "<span style=\"border: solid 1px; background-color: #FD9125;\">&nbsp;High&nbsp;</span>";
   } else if (uv < 11) {
       uvword =  "<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\">&nbsp;Very&nbsp;High&nbsp;</span>";
   } else {
       uvword =  "<span style=\"border: solid 1px; color: #FFFF00; background-color: #807780;\">&nbsp;Extreme&nbsp;</span>";
   }
   return uvword;
} // end ajax_getUVrange function

function ajax_genarrow( nowTemp, yesterTemp, Legend, textUP, textDN, numDp) {
// generate an <img> tag with alt= and title= for rising/falling values	
	
  var diff = nowTemp.toFixed(3) - yesterTemp.toFixed(3);
  var absDiff = Math.abs(diff);
  var diffStr = '' + diff.toFixed(numDp);  // sprintf("%01.0f",$diff);
  var absDiffStr = '' + absDiff.toFixed(numDp); // sprintf("%01.0f",$absDiff);
  var image = '';
  var msg = '';
  
  if (diff == 0) {
 // no change
    image = '&nbsp;'; 
  } else if (diff > 0) {
// today is greater 
//    msg = textUP + " by " + diff.toFixed(1); // sprintf($textDN,$absDiff); 
	msg = textUP.replace(/\%s/,absDiffStr);
    image = "<img src=\"" + imagedir + "/rising.gif\" alt=\"" + msg + 
	"\" title=\""+ msg + 
	"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";
  } else {
// today is lesser
    msg = textDN.replace(/\%s/,absDiffStr); // sprintf($textDN,$absDiff); 
//	msg = textDN.replace(/\%s/,absDiffStr);
    image = "<img src=\"" + imagedir + "/falling.gif\" alt=\"" + msg + 
	"\" title=\""+ msg + 
	"\" width=\"7\" height=\"8\" style=\"border: 0; margin: 1px 3px;\" />";
   
  }

   if (Legend) {
       return (diff + Legend + image);
	} else {
	   return image;
	}
} // end genarrow function

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


function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function stateChangedAdvisory() 
{ 
if (xmlHttp.readyState==4)
	{
	var urllink = '/wx0.php';
	alertpridata = "";
	var data = xmlHttp.responseText.split("\n");
	if (data[0].indexOf("no active watches, warnings or advisories") < 0) 
		{
		if (data[0].indexOf("Watch") > 0) 
			{
			firstart=0;
			alertpridata = '<div class="watchBox"><a href= /wx0.php style="color: #FFFFFF;"><b>' + data[0] + " - is in effect" + '</span></b> ... [Click here for more]</a></div><br />';
			}
		else if (data[0].indexOf("Warning") > 0) 
			{
			if (data[0].indexOf("Severe Thunderstorm Warning") >= 0) urllink = "http://www.weather.gov/view/validProds.php?prod=SVR&node=KRAH";
//			if (data[0].indexOf("Flash Flood Warning") >= 0) urllink = "http://www.weather.gov/view/validProds.php?prod=FFS&node=KRAH";
			alertpridata = '<div class="warningBox"><a href= ' + urllink + ' style="color: #FFFFFF;"><b>' + data[0] + " - is in effect" + '</span></b> ... [Click here for more]</a></div><br />';
			}
		else 	{
			urllink = "wx0.php";
			if (data[0].indexOf("Air Quality Alert") >= 0) urllink = "http://daq.state.nc.us/airaware/ozone/Triangle.html";
//			if (data[0].indexOf("Special Weather Statement") >= 0) urllink = "http://www.weather.gov/view/validProds.php?prod=SPS&node=KRAH";
//			if (data[0].indexOf("Short Term Forecast") >= 0) urllink = "http://www.weather.gov/view/validProds.php?prod=NOW&node=KRAH";
			if (data[0].indexOf("Severe Weather Statement") >= 0) urllink = "http://www.weather.gov/view/validProds.php?prod=SVS&node=KRAH";
//			if (data[0].indexOf("Wind Advisory") >= 0) urllink = "http://www.weather.gov/view/validProds.php?prod=NPW&node=KRAH";
//			if (data[0].indexOf("Dense Fog Advisory") >= 0) urllink = data[1];
//			if (data[0].indexOf("Frost Advisory") >= 0) urllink = data[1];
	      		alertpridata = '<div class="advisoryBox"><a href= ' + urllink + ' style="color: #FFFFFF;"><b>' + data[0] + '</span></b> ... [Click here for more]</a></div><br />';
			}
		}
	document.getElementById("advisory1").innerHTML=alertpridata;
	}
}

function stateChangedAlertPrimary() 
{ 
if (xmlHttp.readyState==4)
	{ 
	document.getElementById("advisory").innerHTML=xmlHttp.responseText;
	}
}


function stateChangedAlert() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("alert").innerHTML=xmlHttp.responseText;
}
}


// ------------------------------------------------------------------------------------------
//  main function.. get weather data and format <span class="ajax" id="ajax..."></span> areas
// ------------------------------------------------------------------------------------------
//
// r - 30
// d - 40
// m - 20	
// y - 20
//
// WS - 10
// WAS - 11
// DHWS - 38
// DHWSTime - 39
// RS 19 Storm Rain "in"
// RS 20 Storm Rain Start date 
// Rday 21 total rain day
// Rmon 22 total rain month
// Ryear 23 total rain year
//
//	for T > 57 °F or T = 57 °F
//	HI = -42.379 + 2.04901523*T + 10.14333127*RH - 0.22475541*T*RH - 0.00683783*T**2 - 0.05481717*RH**2 + 0.00122874*T**2*RH + 0.00085282*T*RH**2 - 0.00000199*(T*RH)**2  
//
//	WC = 35.74+(0.6215*T)-(35.75*WAS**0.16)+(0.4275*T*WAS**0.16)
//
//
function ajaxLoader(url) {
	alertpri="";
//		set_ajax_obs("ajaxbigtemp",rlt);	
  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

	if(clientraw[111] == '!!') { // got it.. process clientraw.txt

		var date = clientraw[2].split('-');
		var time = clientraw[3].split(':');


		//Temperature
		set_ajax_obs("To",clientraw[9] + uomTemp);
		set_ajax_obs("Tobig",clientraw[9] + uomTemp);
		set_ajax_obs("Tomin",clientraw[48] + uomTemp);
		set_ajax_obs("Tomax",clientraw[49] + uomTemp);
		set_ajax_obs("TTomin",clientraw[50]);
		set_ajax_obs("TTomax",clientraw[51]);




//		templast = convertTemp(clientraw[90]);
//		set_ajax_obs("ajaxtemparrow", 
//		   ajax_genarrow(temp, templast, '', 
//			 'Warmer %s'+uomTemp+' than last hour.',
//			 'Colder %s'+uomTemp+' than last hour.',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);

		//Humidity ...

		set_ajax_obs("RHo",clientraw[14] + "%");
		set_ajax_obs("RHomin",clientraw[45] + "%");
		set_ajax_obs("RHomax",clientraw[44] + "%");
		set_ajax_obs("TRHomin",clientraw[47]);
		set_ajax_obs("TRHomax",clientraw[46]);


			
		//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",clientraw[47] + 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
//	for T > 57 °F or T = 57 °F
//	HI = -42.379 + 2.04901523*T + 10.14333127*RH - 0.22475541*T*RH - 0.00683783*T**2 - 0.05481717*RH**2 + 0.00122874*T**2*RH + 0.00085282*T*RH**2 - 0.00000199*(T*RH)**2  

//	WC = 35.74+(0.6215*T)-(35.75*WAS**0.16)+(0.4275*T*WAS**0.16)


		T = clientraw[9];
		H = clientraw[14];
		W = clientraw[11];
     if (T <= 45.0 && W >= 3 ) {
		var zz = Math.pow(3,0.16);
//		WC = 35.74+(0.6215*T)-(35.75*W**0.16)+(0.4275*T*W**0.16);
		WC = 35.74 + (0.6215*T) - 35.75*zz + 0.4275*T*zz;
		  feelslike = WC; //use WindChill
		} else if (T >=80.0) {
			HI = -42.379+2.04901523*T+10.14333127*H-0.22475541*T*H-0.00683783*T*T-0.05481717*H*H+0.00122874*T*T*H + 0.00085282*T*H*H - 0.00000199*(T*H)*(T*H);
		  		if (HI > T)
				{  
		  		feelslike = HI; //use Heatindex
				} else {
		  		feelslike = T;
				}
//			}
		} else {
		  feelslike = T;   // use temperature
		}

		feelslike  = (Math.round(10*feelslike))/10;
		set_ajax_obs("ajaxfeelslike",feelslike + uomTemp);
		
		// 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...
		set_ajax_obs("ajaxbaro", clientraw[6] + 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, '', 
//			 'Rising %s '+uomBaro+'/hour.',
//			 'Falling %s '+uomBaro+'/hour.',2)
//			 );	
		
//		set_ajax_obs("ajaxbarotrendtext",ajax_get_barotrend(clientraw[50]));

//		pressuremin = convertBaro(clientraw[132]);
		set_ajax_obs("ajaxbaromin",clientraw[34] + uomBaro);
		set_ajax_obs("ajaxbaromintime",clientraw[36]);


//		pressuremax = convertBaro(clientraw[131]);
		set_ajax_obs("ajaxbaromax",clientraw[35] + uomBaro);
		set_ajax_obs("ajaxbaromaxtime",clientraw[37]);
		set_ajax_obs("ajaxbarotendency",clientraw[4]);
//		set_ajax_obs("ajaxbaroforecast",clientraw[5]);
 		set_ajax_obs("ajaxbarotpic","<img src=\""+clientraw[78]+".png\">");
 		set_ajax_obs("ajaxbarofpic","<img src=\""+clientraw[79]+".jpg\">");



        //Wind gust
//		gust    = convertWind(clientraw[140]);
//		maxgust = convertWind(clientraw[71]);
//		if (maxgust > 0.0 ) {
//		  set_ajax_obs("ajaxmaxgust",maxgust.toFixed(1) + uomWind);
//		} else {
//		  set_ajax_obs("ajaxmaxgust",'None');
//		}

		//Windspeed ...
		set_ajax_obs("WAS",clientraw[11] + uomWind);

//		wind = convertWind(clientraw[2]);
//		beaufort = ajax_get_beaufort(clientraw[2]);
//		set_ajax_obs("ajaxbeaufort",beaufort);

       //WIND DIRECTION ...
		set_ajax_obs("DIR0",clientraw[12]+"&deg, ");
//		set_ajax_obs("DIR1",clientraw[42]+"&deg, ");
//		set_ajax_obs("DIR2",clientraw[43]+"&deg, ");
//		set_ajax_obs("DIR3",clientraw[44]+"&deg, ");
//		set_ajax_obs("DIR4",clientraw[45]+"&deg, ");
//		set_ajax_obs("DIR5",clientraw[46]+"&deg");

//        val = windDir(clientraw[3]);

//       if (wind > 0.0) {
		set_ajax_obs("WSmax",clientraw[38] + uomWind);
		set_ajax_obs("WSmaxTime",clientraw[39]);
//		set_ajax_uom("ajaxwinduom",true);
//	   } else {
//		set_ajax_obs("ajaxwind","Calm");
//		set_ajax_uom("ajaxwinduom",false);
//	   }
	   
//	   if (gust > 0.0) {
//		set_ajax_obs("ajaxgust",gust.toFixed(1) + uomWind);
//		set_ajax_uom("ajaxgustuom",true);
//	   } else {
//		set_ajax_obs("ajaxgust","None");
//		set_ajax_uom("ajaxgustuom",false);
//	   }
	   
// 	   if (gust > 0.0 || wind > 0.0) {
// 		set_ajax_obs("ajaxwindicon","<img src=\"" + imagedir + "/" +  val + ".gif\" width=\"14\" height=\"14\" alt=\"Wind from" + 
//		val + "\" title=\"Wind from " + val + "\" /> ");
		set_ajax_obs("ajaxwinddir",clientraw[12]+"&deg  "+clientraw[13]);
//	   } else {
// 		set_ajax_obs("ajaxwindicon","");
//		set_ajax_obs("ajaxwinddir","");
//	   }

//		windmaxavg = convertWind(clientraw[113]);
//		set_ajax_obs("ajaxwindmaxavg",windmaxavg.toFixed(1) + uomWind);

		//  Solar Radiation
		set_ajax_obs("SR",clientraw[18]);
		solarpct = (clientraw[18]/1200)*100; 
		set_ajax_obs("ajaxsolarpct",solarpct.toFixed(1));
		set_ajax_obs("DHSR",clientraw[62]);
		set_ajax_obs("DHSRTime",clientraw[63]);

		
		// UV Index		
		uv       = clientraw[17];
		set_ajax_obs("UV",uv) ;
		set_ajax_obs("DHUV",clientraw[64]);
		set_ajax_obs("DHUVTime",clientraw[65]);
		uvword = ajax_getUVrange(uv);
		set_ajax_obs("ajaxuvword",uvword);

		//Rain ...
//		rain = convertRain(clientraw[7]);
		set_ajax_obs("R1h",clientraw[15] + uomRain);
		set_ajax_obs("R1hmax",clientraw[66] + uomRain);
		set_ajax_obs("TR1hmax",clientraw[67]);

		set_ajax_obs("WC",clientraw[47] + uomTemp);
		set_ajax_obs("DP",clientraw[30] + uomTemp);
		if (clientraw[20] != "n/a") 
		{
			var daterain = clientraw[20].split('-');
			set_ajax_obs("timelastrain",daterain[2]+-+8+-+daterain[0]);
  			var Dcur = Date.UTC(date[0], date[1]-1, date[2]);
  			var Drain = Date.UTC( daterain[2], 07, daterain[0]);
			set_ajax_obs("daysnorain",(Dcur-Drain)/864e5);
		}else{
			set_ajax_obs("timelastrain",clientraw[20]);
			set_ajax_obs("daysnorain", "n/a");
		}

		set_ajax_obs("ajaxrain", clientraw[15] + uomRain);

		rainydy = convertRain(clientraw[21]);
//		set_ajax_obs("ajaxrainydy", clientraw[21] + uomRain);

//		rainmo = convertRain(clientraw[8]);
		set_ajax_obs("ajaxrainmo", clientraw[22] + uomRain);

//		rainyr = convertRain(clientraw[9]);
		set_ajax_obs("ajaxrainyr",clientraw[23] + uomRain);

		rainratehr = convertRain(clientraw[15]) * 60; // make per hour rate.
		set_ajax_obs("ajaxrainratehr",rainratehr.toFixed(dpRain+1) + uomRain);

	if (document.getElementById("advisory1") ) {  // don't process if missing the <span id=name> tag
		if(firstadv > 0)firstadv = firstadv - 1;
   		if (firstadv == 0){
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
		  	{
		  		alert ("Your browser does not support AJAX!");
			} 
			var url1='/alert-durham';
			url1=url1+"?"+Math.random();
			xmlHttp.onreadystatechange=stateChangedAdvisory;
			xmlHttp.open("GET",url1,true);
			xmlHttp.send(null);
			firstadv = 0;
		}
	}

	if (document.getElementById("advisory") ) {  // don't process if missing the <span id=name> tag
		if(firstevt > 0)firstevt = firstevt - 1;
   		if (firstevt == 0){
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
		  	{
		  		alert ("Your browser does not support AJAX!");
			} 
			var url2='/advisory';
			url2=url2+"?"+Math.random();
			xmlHttp.onreadystatechange=stateChangedAlertPrimary;
			xmlHttp.open("GET",url2,true);
			xmlHttp.send(null);
			firstevt = 12;
		}
	}

	if (document.getElementById("alert") ) {  // don't process if missing the <span id=name> tag
		if(firstart > 0)firstart = firstart - 1;
   		if (firstart == 0){
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
		  	{
		  		alert ("Your browser does not support AJAX!");
			} 
			var url3='/alert-durham.html'+"?"+Math.random();
			xmlHttp.onreadystatechange=stateChangedAlert;
			xmlHttp.open("GET",url3,true);
			xmlHttp.send(null);
			firsteart = 12;
		}
	}



		if(first > 0)first = first - 1;
   		if ((first == 0)&&(document.images.myImageName)){
	      	document.images.myImageName.src = 'graph.gif?' + Math.random();
			first = 12;
		}

		if(first1 > 0)first1 = first1 - 1;
	  	if ((first1 == 0)&&(document.images.WebCamImageName)){
	     	document.images.WebCamImageName.src = 'cam2.jpg?' + Math.random();
			first1 = 12;	
		}


		if(first2 > 0)first2 = first2 - 1;
	  	if ((first2 == 0)&&(document.images.RadarImageName)){
	     	document.images.RadarImageName.src = 'radarcompimg1.jpg?' + Math.random();
			first2 = 12;	
		}


		// current date and time of observation in clientraw.txt
		ajaxtimeformat = clientraw[3];
		ajaxdateformat = clientraw[2];

		ajaxtimeformat = ajaxtimeformat.replace( ":" , "");
		ajaxtimeformat = ajaxtimeformat.replace( ":" , "");
		ajaxdateformat = ajaxdateformat.replace( "-" , "");
		ajaxdateformat = ajaxdateformat.replace( "-" , "");

//		ajaxtimeformat = ajaxtimeformat.toLowerCase();
		ajaxdatetime = ajaxdateformat+ajaxtimeformat;
//		set_ajax_obs("ajaxdatetime",ajaxdateformat+ajaxtimeformat);
		set_ajax_obs("ajaxdate",clientraw[2]);
		set_ajax_obs("ajaxtime",clientraw[3]);
		
		if (lastajaxtimeformat != ajaxdatetime) {
			counterSecs = 0;                      // reset timer
			lastajaxtimeformat = ajaxdatetime; // remember this time
		// now ensure that the indicator flashes on every successful AJAX fetch
        element = document.getElementById("ajaxindicator");
		if (element) {
         	 element.style.color = flashcolor;
			}

		}
		
		// current condition icon and description
		set_ajax_obs("ajaxconditionicon",
			ajax_wxIcon(clientraw[48])
			);


//		currentcond = clientraw[49];
//		currentcond = currentcond.replace(/_/g,' ');
//		currentcond = currentcond.replace(/\\/g,', ');
//		currentcond = currentcond.replace(/\//g,', ');
//		set_ajax_obs("ajaxcurrentcond",currentcond);


	
		// cloud height
//		cloudheight = clientraw[73];
//		set_ajax_obs("ajaxcloudheight",convertHeight(cloudheight) + uomHeight);
		
		// now ensure that the ntwork activity indicator flashes on every AJAX fetch
        element = document.getElementById("ajaxactive");
		if (element) {
          	element.style.color=flashcolor;
          	element.innerHTML =  "&sect  ";
		}

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

//get all of them every minute = rlt milliseconds

	setTimeout("reset_ajax_color('')",flashtime); // change text back to default color
 
    setTimeout("ajaxLoader(clientrawFile)", rlt); // get new data after rlt time
	rlt = reloadTime;

   } // END   if (x) {

} // END ajaxLoader function


  window.setInterval("ajax_countup()", 1000); // run the counter for seconds since update

// invoke when first loaded on page
// if (! ajaxLoaderInBody) "ajaxLoader(clientrawFile)"; }
//		set_ajax_obs("ajaxtemp",rlt);
	rlt = 1000;
  if (! ajaxLoaderInBody) { setTimeout("ajaxLoader(clientrawFile)", 1); }


//	alertpridata = innerHTML=xmlHttp.responseText;
//	if (xmlHttp.responseText != "NO CURRENT ADVISORIES" && warning != "SHORT TERM FORECAST" && warning != "SPECIAL WEATHER STATEMENT") {
//		if (xmlHttp.responseText.indexOf("WATCH") > 0) {
//		}
//		else if (xmlHttp.responseText.indexOf("WARNING") > 0) {
//			alertpridata = '<div class="warningBox"><a href= /advisory style="color: #FFFFFF;"><b>' + xmlHttp.responseText + '</span></b> IN EFFECT ... [Click here for more]</a></div><br />';
//		}
//		else {
//      	alertpridata = '<div class="advisoryBox"><a href= /advisory style="color: #FFFFFF;"><b>' + xmlHttp.responseText + '</span></b> IN EFFECT ... [Click here for more]</a></div><br />';
//		}





// ]]>