//////////////////PARSE XML/XSLT ////////////////////////////////

var req;
var styleReq;
var stylesheetDoc;
var dest;

function loadStylesheet(){
  if (window.XMLHttpRequest){
      url = "http://www.kentlaw.edu/student_orgs/sba/organizations_sba.xsl";
      styleReq = new XMLHttpRequest();
      styleReq.onreadystatechange = processStylesheetChange;
      styleReq.open("GET", url, true);
      styleReq.send(null);
  } else if (window.ActiveXObject) {
        url = "http://www.kentlaw.edu/student_orgs/sba/organizations_sba.xsl";
        styleReq = new ActiveXObject("Microsoft.XMLHTTP");
        if (styleReq) {
            styleReq.onreadystatechange = processStylesheetChange;
            styleReq.open("GET", url, true);
            styleReq.send();
        }
   }
}
function processStylesheetChange(){
  if (styleReq.readyState == 4){
    if (styleReq.status == 200){
	
       if (window.ActiveXObject){

           stylesheetDoc = new ActiveXObject("Microsoft.XMLDOM");
           stylesheetDoc.async = false;
           stylesheetDoc.loadXML(styleReq.responseText);
   			loadHTML('http://www.kentlaw.edu/students/organizations.xml','organizations');

       } else if (window.XMLHttpRequest) {

           var dp = new DOMParser();
           stylesheetDoc = dp.parseFromString(styleReq.responseText, "text/xml");
   			loadHTML('http://www.kentlaw.edu/students/organizations.xml','organizations');
			

       }

    } else {
       alert("Can't load stylesheet:"+styleReq.status);
    }
  }
}


function loadHTML(url, destination){
  dest = destination;
  if (window.XMLHttpRequest){
      req = new XMLHttpRequest();
      req.open("GET", url, true);
      req.onreadystatechange = processStateChange;
      req.send(null)
  } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processStateChange;
            req.open("GET", url, true);
            req.send();
        }
   }
}
function processStateChange(){
  statusDiv = document.getElementById("status");
  if (req.readyState == 0){ statusDiv.innerHTML = "UNINITIALIZED"; }
  if (req.readyState == 1){ statusDiv.innerHTML = "LOADING"; }
  if (req.readyState == 2){ statusDiv.innerHTML = "LOADED"; }
  if (req.readyState == 3){ statusDiv.innerHTML = "INTERACTIVE"; }
  if (req.readyState == 4){    if (req.status == 200){
       response = req.responseText;

          if (window.ActiveXObject) {

              var theDocument = new ActiveXObject("Microsoft.XMLDOM");
              theDocument.async = false;
              theDocument.loadXML(req.responseText);

              destinationDiv = document.getElementById(dest);			
              destinationDiv.innerHTML = theDocument.transformNode(stylesheetDoc);///////////////ERROR HERE.

          } else if (window.XMLHttpRequest){

              var parser = new DOMParser();
              theDocument = parser.parseFromString(req.responseText, "text/xml");

              var xsltProcessor = new XSLTProcessor();
              xsltProcessor.importStylesheet(stylesheetDoc);
              response = xsltProcessor.transformToFragment(theDocument, document);

              destinationDiv = document.getElementById(dest);
              destinationDiv.innerHTML = "";
              destinationDiv.appendChild(response);

		  }

    } else {
       statusDiv.innerHTML = "Error: Status "+req.status;
    }
  }
}



