// Urgent Message Engine
// Written by Paul Ottley
// Modified with permision by David LeMieux
// copyright 2006


// Global Variable
var req2;

// Call Page pg - pg = url.
function callPage2(pg){
  loadXMLDoc2(pg);
}

// Implementation of Ajax
function loadXMLDoc2(url) {
	req2 = false;
    //document.getElementById("debugger").innerHTML += "I made it into the loadXMLDoc method <br />";
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req2 = new XMLHttpRequest();
        } catch(e) {
			req2 = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req2 = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req2 = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req2 = false;
        	}
		}
    }
	if(req2) {
		
		// Call the process
		req2.onreadystatechange = processReqChange2;
		req2.open("GET", url, true);
		req2.send("");
			
	}
}

// This is the method that will be used to handle the request
function processReqChange2() {
    //document.getElementById("debugger").innerHTML += "<br />Did I make it to the processReqChange method? Yes! readyState=" + req2.readyState;
    // only if req2 shows "loaded"
	//alert("1: readyState: " + req2.readyState + " status: " + req2.status + " response: " + req2.responseText);
    if (req2.readyState == 4) {
        // only if "OK"
        if (req2.status == 200) {
            // ...processing statements go here...
            var respText = req2.responseText;
			if (respText == "") return;
			urgDiv = returnClass2("announcementMessage");
			urgDiv.innerHTML = respText;
			urgDiv.className = "announcementMessage";
				} 
		else {
            //alert("There was a problem retrieving the XML data:\n" + req2.statusText);
        }
    }
}


function returnClass2(name) { 
   //Populate the array with all the page tags 
   var allPageTags=document.getElementsByTagName("*"); 
   //Cycle through the tags using a for loop 
   for (i=0; i<allPageTags.length; i++) { 
      //Pick out the tags with our class name 
      if (allPageTags[i].className==name) { 
         //Manipulate this in whatever way you want 
         return allPageTags[i];
      } 
   } 
} 