// global variables to keep track of the request
// and the function to call when done
var ajaxreq = null;
// ajaxRequest: Sets up a request
function createXTR() {
  if (window.XMLHttpRequest) {
	  return new XMLHttpRequest();
  } else if (window.ActiveXObject) {
      var msxml = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0",
          "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
      for (var i = 0; i < msxml.length; i++) {
        try {
          var object = new ActiveXObject(msxml[i]);
          return object;
        } catch (ignore) {
        }
      }
      //throw new Error("IE error");
	  alert("MSIE Error");
  }
  return null;
};

function ajaxRequest(filename) {
   ajaxreq = createXTR();
   if (ajaxreq) {
	   ajaxreq.open("GET", filename);
	   ajaxreq.onreadystatechange = ajaxResponse;
	   ajaxreq.send(null);
   }
};

function ajaxCallback () {
	createNavBar();
	setupMenu();
};

// ajaxResponse: Waits for response and calls a function
function ajaxResponse() {
   	if (ajaxreq.readyState == 4) {
  		if (ajaxreq.status == 200) {
        // if the request succeeded...
           if (ajaxCallback) {
			   ajaxCallback();
		   }
        } else {
			alert("Request failed: " + ajaxreq.statusText);
		}
	}
};

