<!--
// Special thanks to: Kevin Reed http://www.tnetweather.com
// Kevin was the first to decode the clientraw in PHP
// Special thanks to: Pinto http://www.joske-online.be
// Pinto wrote the basic AJAX code for this page!
//
// --- added flash-change on data update functions from Ken at http://www.saratoga-weather.org
// -- begin settings
//
// Cheerfully borrowed the ajaxmessage idea from Matthew Romer at WaWa Weather - http://wawaweather.net/
//
var flashcolor = '#DD0000'; // color to flash for changed observations
var flashtime = '2000'; // miliseconds to keep flash color on (2000 = 2 seconds);
var messagecount = 0;
// -- end of settings 
var ie4=document.all;

function getElementsByName_iefix(tag, name) {

  var elem = document.getElementsByTagName(tag);
  var arr = new Array();
  for(i = 0,iarr = 0; i < elem.length; i++) {
    att = elem[i].getAttribute("name");
    if(att == name) {
      arr[iarr] = elem[i];
      iarr++;
    }
  }
return arr;
}

function reset_ajax_color( ) {
// reset all the <span name="ajax"...> styles to have no color override
  if (ie4) {
    elements = getElementsByName_iefix("span","ajax");
  } else {
    elements = document.getElementsByName("ajax");
  }
  numelements = elements.length;
  for (var index=0;index!=numelements;index++) {
    element = elements[index];
    element.style.color='';
  }
}

function windDir ($winddir)
// Take wind direction value, return the
// text label based upon 16 point compass -- function by Kevin Reed
{
   $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 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
  element = document.getElementById(name);
  lastobs = element.getAttribute("lastobs");
  element.setAttribute("lastobs",value);
  if (value != lastobs) {
    element.style.color=flashcolor;
  }
  element.innerHTML = value;
}
// --- end of flash-change functions

function ajaxLoader(url) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  }
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {

		//Temp
		temp = (1.8 * x.responseText.split(' ')[4]) + 32.0;
		temp = parseFloat(temp.toFixed(1));
		set_ajax_obs("ajaxtempnodp", temp.toFixed(0) + "&deg;F");
    
		set_ajax_obs("ajaxtemp", temp.toFixed(1) + " &deg;F");

		temptrend = ((1.8 * x.responseText.split(' ')[4]) + 32.0) - ((1.8 * x.responseText.split(' ')[90]) + 32.0);
		if (temptrend > 0) {
			temptrend = "+" + temptrend.toFixed(1);
			document.getElementById("ajaxtemptrendgraphic").innerHTML = '&nbsp;<img src="greenup.gif" height="15" width="15" alt="Temperature Rising" title="Temperature Rising">';
		} else if (temptrend < 0) {
			temptrend = temptrend.toFixed(1);
			document.getElementById("ajaxtemptrendgraphic").innerHTML = '&nbsp;<img src="reddown.gif" height="15" width="15" alt="Temperature Falling" title="Temperature Falling">';
		} else {
			temptrend = "+" + temptrend.toFixed(1);
			document.getElementById("ajaxtemptrendgraphic").innerHTML = '';
		}
		set_ajax_obs("ajaxtemptrend", temptrend + " &deg;F /hr");

		// FeelsLike
		//temp = x.responseText.split(' ')[4];
		if (temp <= 50.0 ) {

			feelslike = x.responseText.split(' ')[44]; //use WindChill
		} else if (temp >=80.0) {
			feelslike = x.responseText.split(' ')[112]; //use Heat Index
		} else {
			feelslike = x.responseText.split(' ')[4];  // use temperature
		}
		feelslike  = (1.8 * feelslike) + 32.0;
		set_ajax_obs("ajaxfeelslike",feelslike.toFixed(1) + " &deg;F");

		//Humidity ...
		set_ajax_obs("ajaxhum", x.responseText.split(' ')[5] + "%");

		//Pressure...
		press = x.responseText.split(' ')[6] / 33.86388158;
		set_ajax_obs("ajaxbaro", press.toFixed(2) + " in.");

		presstrend = x.responseText.split(' ')[50] / 33.86388158;
		if (presstrend > 0) {
			presstrend = "+" + presstrend.toFixed(3);
			document.getElementById("ajaxpresstrendgraphic").innerHTML = '&nbsp;<img src="greenup.gif" height="15" width="15" alt="Pressure Rising" title="Pressure Rising">';
		} else if (presstrend < 0) {
			presstrend = presstrend.toFixed(3);
			document.getElementById("ajaxpresstrendgraphic").innerHTML = '&nbsp;<img src="reddown.gif" height="15" width="15" alt="Pressure Falling" title="Pressure Falling">';
		} else {
			presstrend = "+" + presstrend.toFixed(3);
			document.getElementById("ajaxpresstrendgraphic").innerHTML = '';
		}
		set_ajax_obs("ajaxpresstrend", presstrend + " in. /hr");

		//Windspeed ...
		wind = x.responseText.split(' ')[2]* 1.1507794;
		set_ajax_obs("ajaxwind", wind.toFixed(1) + " mph");

		gusthour = x.responseText.split(' ')[133]* 1.1507794;
		set_ajax_obs("ajaxgusthour", gusthour.toFixed(1) + " mph at ");

		gustminute = x.responseText.split(' ')[140]* 1.1507794;

		if (wind > gustminute) {
			set_ajax_obs("ajaxgustminute", "Gust: " + wind.toFixed(1) + " mph");
		} else {
			set_ajax_obs("ajaxgustminute", "Gust: " + gustminute.toFixed(1) + " mph");
		}

		gusthourtime = x.responseText.split(' ')[134];
		gusthourtime = gusthourtime.replace( "_" , " ");
		set_ajax_obs("ajaxgusthourtime", gusthourtime.toLowerCase());

		gusttoday = x.responseText.split(' ')[71]* 1.1507794;
		set_ajax_obs("ajaxgusttoday", gusttoday.toFixed(1) + " mph at ");

		gustdaytime = x.responseText.split(' ')[135];
		gustdaytime = gustdaytime.replace( "_" , " ");
		set_ajax_obs("ajaxgusttodaytime", gustdaytime.toLowerCase());
							
		val = windDir(x.responseText.split(' ')[3]);
		set_ajax_obs("ajaxwinddir", "&nbsp;" + val);
 		document.getElementById("ajaxwindicon").innerHTML = '&nbsp;<img src=./winddir/' + val + '.gif width="14" height="14" alt="Wind from ' + val + '" title="Wind from ' + val + '"></img>';

		//Rain ...
		rain = x.responseText.split(' ')[7]* .0393700787;
		set_ajax_obs("ajaxrain",rain.toFixed(2) + " in. ");

		rain = x.responseText.split(' ')[8]* .0393700787;
		set_ajax_obs("ajaxrainmo",rain.toFixed(2) + " in. ");

		//Dewpoint ...
		dew = (1.8 * x.responseText.split(' ')[72]) + 32.0;
		set_ajax_obs("ajaxdew",dew.toFixed(1) + " &deg;F");

		ajaxdatetimeformat = x.responseText.split(' ')[32];
		ajaxdatetimeformat = ajaxdatetimeformat.replace( "_" , " ");
		ajaxdatetimeformat = ajaxdatetimeformat.replace( "-" , "");
		timelength = ajaxdatetimeformat.length;
		ajaxendtimeformat = ajaxdatetimeformat.substring(timelength,timelength-2);
		ajaxdatetimeformat = ajaxdatetimeformat.substring(0,timelength-6) + ' ' + ajaxendtimeformat;
		// set_ajax_obs("ajaxdatetime",ajaxdatetimeformat);
		document.getElementById("ajaxdatetime").innerHTML = ajaxdatetimeformat;

		element = document.getElementById("ajaxindicator");
		if (element) { // V1.04 set indicator if <span id="ajaxindicator" name="ajax"> exists
			element.style.color = flashcolor;
		}

   }
    }
    x.open("GET", url, true);
    x.send(null);

//get all of them every minute = 5000 milliseconds
//edit the location of your clienraw.txt twice!! (here and in the body onload)
//get all of them every minute = 5000 milliseconds
//edit the location of your clienraw.txt twice!! (here and in the body onload)
    setTimeout("reset_ajax_color()",2000); // change text back to default color after 2 secs
    setTimeout("ajaxLoader('clientraw.txt?'+new Date())", 6000); // get new data after 5 secs
                             
  }
}

function ajaxLoader2(url) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  }
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {

		//Time ...
		set_ajax_obs("ajaxgetrawtime", x.responseText.split('|')[1]);

		//Time last tip ...
		tiptime = ' at ' + x.responseText.split('|')[35];
		tiptime = tiptime.replace( " at -" , "");
		set_ajax_obs("ajaxtimeoflastrain", tiptime);

		//Wetbulb
		wetbulb = parseFloat(x.responseText.split('|')[147]);
		set_ajax_obs("ajaxwetbulb", wetbulb.toFixed(1) + ' &deg;F');

		//Rain days
		set_ajax_obs("ajaxraindays", x.responseText.split('|')[34]);		

		//Rain last hour
		set_ajax_obs("ajaxrainhour", x.responseText.split('|')[33] + ' /hr');

		//Rain last 3 hours
		set_ajax_obs("ajaxrain3hour", x.responseText.split('|')[146] + ' /3 hr');

		//Temp trend 2 hour
		temptrend = parseFloat(x.responseText.split('|')[36]) - parseFloat(x.responseText.split('|')[113]);
		if (temptrend > 0) {
			temptrend = "+" + temptrend.toFixed(1);
		} else if (temptrend < 0) {
			temptrend = temptrend.toFixed(1);
		} else {
			temptrend = "+" + temptrend.toFixed(1);
		}
		set_ajax_obs("ajaxtemptrend2hour", temptrend + " &deg;F /2 hr");

		//Humidity trend
		humtrend = x.responseText.split('|')[40] - x.responseText.split('|')[89];
		if (humtrend > 0) {
			humtrend = "+" + humtrend.toFixed(0);
			document.getElementById("ajaxhumtrendgraphic").innerHTML = '&nbsp;<img src="greenup.gif" height="15" width="15" alt="Humidity Rising" title="Humidity Rising">';
		} else if (humtrend < 0) {
			humtrend = humtrend.toFixed(0);
			document.getElementById("ajaxhumtrendgraphic").innerHTML = '&nbsp;<img src="reddown.gif" height="15" width="15" alt="Humidity Falling" title="Humidity Falling">';
		} else {
			humtrend = "+" + humtrend.toFixed(0);
			document.getElementById("ajaxhumtrendgraphic").innerHTML = '';
		}
		set_ajax_obs("ajaxhumtrend", humtrend + "% /hr");

		//Humidity trend 2 hour
		humtrend = parseFloat(x.responseText.split('|')[40]) - parseFloat(x.responseText.split('|')[117]);
		if (humtrend > 0) {
			humtrend = "+" + humtrend.toFixed(0);
		} else if (humtrend < 0) {
			humtrend = humtrend.toFixed(0);
		} else {
			humtrend = "+" + humtrend.toFixed(0);
		}
		set_ajax_obs("ajaxhumtrend2hour", humtrend + "% /2 hr");

		//Pressure trend 2 hour
		presstrend = parseFloat(x.responseText.split('|')[41]) - parseFloat(x.responseText.split('|')[118]);
		if (presstrend > 0) {
			presstrend = "+" + presstrend.toFixed(3);
		} else if (presstrend < 0) {
			presstrend = presstrend.toFixed(3);
		} else {
			presstrend = "+" + presstrend.toFixed(3);
		}
		set_ajax_obs("ajaxpresstrend2hour", presstrend + " in. /2 hr");

		//Humidity day high low
		timelower = x.responseText.split('|')[18].toLowerCase();
		humday = parseFloat(x.responseText.split('|')[17]);
		set_ajax_obs("ajaxhumdayhigh", humday .toFixed(0) + '% at ' + timelower);
		timelower = x.responseText.split('|')[20].toLowerCase();
		humday = parseFloat(x.responseText.split('|')[19]);
		set_ajax_obs("ajaxhumdaylow", humday.toFixed(0) + '% at ' + timelower);

		//Pressure day high low
		timelower = x.responseText.split('|')[25].toLowerCase();
		pressday = parseFloat(x.responseText.split('|')[24]);
		set_ajax_obs("ajaxpressdayhigh", pressday .toFixed(3) + ' in. at ' + timelower);
		timelower = x.responseText.split('|')[27].toLowerCase();
		pressday = parseFloat(x.responseText.split('|')[26]);
		set_ajax_obs("ajaxpressdaylow", pressday.toFixed(3) + ' in. at ' + timelower);

		//Temp day high low
		timelower = x.responseText.split('|')[7].toLowerCase();
		tempday = parseFloat(x.responseText.split('|')[6]);
		set_ajax_obs("ajaxtempdayhigh", tempday.toFixed(1) + ' &deg;F at ' + timelower);
		timelower = x.responseText.split('|')[9].toLowerCase();
		tempday = parseFloat(x.responseText.split('|')[8]);
		set_ajax_obs("ajaxtempdaylow", tempday.toFixed(1) + ' &deg;F at ' + timelower);

		//Wind Trend
		windtrendhour = ((parseFloat(x.responseText.split('|')[37]) + parseFloat(x.responseText.split('|')[38])) / 2) - ((parseFloat(x.responseText.split('|')[86]) + parseFloat(x.responseText.split('|')[87])) / 2);
		if (windtrendhour >= 0) {
			windtrendhour = "+" + windtrendhour.toFixed(0);
		} else {
			windtrendhour = windtrendhour.toFixed(0);
		}
		set_ajax_obs("ajaxwindtrendhour", windtrendhour + "  mph /hr");

		//Wind Trend 2 hour
		windtrend2hour = ((parseFloat(x.responseText.split('|')[37]) + parseFloat(x.responseText.split('|')[38])) / 2) - ((parseFloat(x.responseText.split('|')[114]) + parseFloat(x.responseText.split('|')[115])) / 2);
		if (windtrend2hour >= 0) {
			windtrend2hour = "+" + windtrend2hour.toFixed(0);
		} else {
			windtrend2hour = windtrend2hour.toFixed(0);
		}
		set_ajax_obs("ajaxwindtrend2hour", windtrend2hour + "  mph /2 hr");

		document.getElementById("ajaxradar").src = "/radar/miniradar.jpg"+"?"+new Date();

		document.getElementById("ajaxadvise").src = "wu-advisory.php"+"?"+new Date();

		document.getElementById("ajaxclwebcam").src = "carterlakecamlivethumb.jpg"+"?"+new Date();

		document.getElementById("ajaxcitycam").src = "webcam2.jpg"+"?"+new Date();

		messagecount = Math.floor(Math.random()*12);

		if (messagecount == 0) {
			document.getElementById("ajaxmessage").innerHTML = "Weather - if it's not live, it's history. We're live 24 hours a day";
		}
		if (messagecount == 1) {
			document.getElementById("ajaxmessage").innerHTML = "As seen on WOWT-NBC Channel 6 Precision Weather";
		}
		if (messagecount == 2) {
			document.getElementById("ajaxmessage").innerHTML = "Carter Lake's only source for live, local weather";
		}
		if (messagecount == 3) {
			document.getElementById("ajaxmessage").innerHTML = "Omaha valley's only source for live lightning alerts and tracking";
		}
		if (messagecount == 4) {
			document.getElementById("ajaxmessage").innerHTML = "Some weather cams say they're live, ours truly is live - since 2004";
		}
		if (messagecount == 5) {
			document.getElementById("ajaxmessage").innerHTML = "Why wait? Live weather - webcam - lightning - NOAA radio";
		}
		if (messagecount == 6) {
			document.getElementById("ajaxmessage").innerHTML = "You want live? This page updates over 14,000 times a day";
		}
		if (messagecount == 7) {
			document.getElementById("ajaxmessage").innerHTML = "When storms roll in, tune to live NOAA Weather Radio KIH61";
		}
		if (messagecount == 8) {
			document.getElementById("ajaxmessage").innerHTML = "What you see on our weather cam is happening right now - live since 2004";
		}
		if (messagecount == 9) {
			document.getElementById("ajaxmessage").innerHTML = "How live is your weather? Our site is showing the weather now";
		}
		if (messagecount == 10) {
			document.getElementById("ajaxmessage").innerHTML = "No ads, no popups, no spam - just the weather";
		}
		if (messagecount == 11) {
			document.getElementById("ajaxmessage").innerHTML = "Omaha valley's only source for live NOAA weather radio on the Internet";
		}

   }
    }
    x.open("GET", url, true);
    x.send(null);

//edit the location of your clienraw.txt twice!! (here and in the body onload)
    setTimeout("reset_ajax_color()",2000); // change text back to default color after 2 secs
    setTimeout("ajaxLoader2('wx30.html?'+new Date())", 150000); // get new data after 150 secs
                             
  }
}

// -->
