
/** Makes the asynchronous call to get the current weather. */
function getWeather() {
    createXMLHttpRequest();
    if (xmlHttp != null) {
        xmlHttp.onreadystatechange = handleWeatherCallStateChange;
        xmlHttp.open("GET", "weather_feed.php", true);
        if (window.ActiveXObject) {
            xmlHttp.send();
        } else {
            xmlHttp.send(null);
        }
    }	
}

/** 
 * Call back function called when state changes for getWeather call.
 * If state is 200, then update the weather element with response text.
 */
function handleWeatherCallStateChange() {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var text = xmlHttp.responseText;
            var weather = document.getElementById("weather");
            if ((weather != null) && (text != null)) {
                    weather.innerHTML = text;
            }
        }
    }
}


/* 
 * Functions used to update the radar image on the weather page. 
 * Starts a timer that updates the radar image (BOX_0 .. BOX_7).
 */
var radarTimerID = 0;
var radarPicNum = 0;
var iterations = 0;

function updateRadarTimer() {
   if (radarTimerID) {
      clearTimeout(radarTimerID);
      radarTimerID = 0;
   }
   radarPicNum--;
   if (radarPicNum < 0) {
       radarPicNum = 7;       
       iterations++;
   }

   var radar = document.getElementById("radar");
   if (radar != null) {
       radar.src = "http://www.srh.noaa.gov/Ridge/lite/N0R/BOX_" + radarPicNum + ".png";
   }
   
   if (iterations < 12) {
       radarTimerID = setTimeout("updateRadarTimer()", 1200);
   }
}

function stopRadarTimer()
{
   if (radarTimerID) {
      clearTimeout(radarTimerID);
      radarTimerID = 0;
   }
}


