
//var displayPageUrl='https://p1.kvcc.edu/viplite/announce/display.php';
var displayPageUrl='/viplite/announce/display.php';
var announcementDiv=null;
var failureTimer=null;

var xmlHttp = false;
function doAjaxGet(url,callBackFunction) {
    xmlHttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        xmlHttp = false;
      }
    }
    @end @*/
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }
    try {
        xmlHttp.open("GET",url,true);
        xmlHttp.onreadystatechange=callBackFunction;
        xmlHttp.send(null);
        return 1;
    }catch(e) {
        //alert("Try the other thing, I guess..." + e);
    }
    //none of our methods worked, the caller must deal with it.
    xmlHttp=false;
    return 0;
}

function getAnnouncements(announcementDivName, maxAnnouncements, collapsed) {
    announcementDiv=document.getElementById(announcementDivName);
    announcementDiv.innerHTML="<p>Loading announcements...</p>";
    doAjaxGet(displayPageUrl + '?maxAnnouncements=' + maxAnnouncements + '&collapsed=' + (collapsed ? 'true' : 'false'), processAnnouncements);
    failureTimer=setTimeout('announcementDiv.innerHTML="<p>Failed to get announcements.</p>";', 10000);
}

function NoOperation() {
    return 0;
}

function processAnnouncements() {
    if(xmlHttp.readyState == 4) {
        announcementDiv.innerHTML=xmlHttp.responseText;
        xmlHttp.onreadystatechange=NoOperation;
        clearTimeout(failureTimer);
    }else {
        //announcementDiv.innerHTML=announcementDiv.innerHTML+"<p>processAnnouncements got readyState " + xmlHttp.readyState + ".</p>";
    }
}

function toggleElementDisplay(elementID) {
	var e=document.getElementById(elementID);
	if(e.style.display=="block") {
		e.style.display="none";
	}else {
		e.style.display="block";
	}
}
