/*	Array args holds all of the xml strings that handleHttpResponse() will search for.
	Just push a new element on to search for it and display in the "feed" div
*/

var args = new Array();

/*
args.push("credit");
args.push("credit_URL");*/
args.push("temperature_string");
var output;
var http = false;

function handleHttpResponse() {
	if(http.readyState == 4) {
		//alert("Status Code " + http.status + ": " + http.statusText);
		if(http.status == 200) {
			results = http.responseText;
			for(var i = 0; i < args.length; i++) {
				output = results.substring(results.search(args[i]) + (args[i].length + 1), results.search("</" + args[i]));
				var iconField = "icon_url_name";
				var weatherIcon = results.substring(results.search(iconField) + (iconField.length + 1), results.search("</" + iconField));
				document.getElementById("feed").innerHTML = "<p>" + output + "<br /><a href='http://www.wrh.noaa.gov/forecast/MapClick.php?site=pih&smap=1&textField1=42.87139&textField2=-112.44472'>weather information</a></p><img src='http://www.isu.edu/templates/v1/images/weather/" + weatherIcon.replace(".jpg", ".png") + "' alt='' height='32' width='32' onerror=\"this.src='http://www.isu.edu/template/v1/images/weather/noicon.gif'\" />";
			}
		}
		/*else {
			alert("Request for Weather Feed not completed. Status Code Not 200: \n" + http.statusText);
		}*/
	}
}

function getHTTPObject() {
	var url = "/websc/exports/feeds/KPIH.xml" + "?ms=" + new Date().getTime();
	if (window.XMLHttpRequest) {
		try {
			http = new XMLHttpRequest();
		}
		catch (e) {
			http = false;
		}
	}
	else if(window.ActiveXObject) {
		try {
			http = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				http = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(f) {
				http = false;
			}
		}
	}
	http.open("GET", url, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
	setTimeout("getHTTPObject()", 600000);
}