/* code for handling the outline tree */
 var openImg = new Image();
   openImg.src = "open.gif";
 var closedImg = new Image(); 
   closedImg.src = "closed.gif";
   
   function showBranch(branch){
      var objBranch = document.getElementById(branch);
      if (!objBranch)
         return;
      objBranch = objBranch.style;
      if(objBranch.display=="block")
         objBranch.display="none";
      else
         objBranch.display="block";
      swapFolder('I' + branch);
   }
   
  
   function swapFolder(img){
      objImg = document.getElementById(img);
      if(objImg.src.indexOf('closed.gif')>-1)
         objImg.src = openImg.src;
      else
         objImg.src = closedImg.src;
   }

/* code to handle dynamically loading content */
var STATE_UNINITIALIZED=0;
var STATE_LOADING=1;
var STATE_LOADED=2;
var STATE_INTERACTIVE=3;
var STATE_COMPLETE=4;

function loadDoc(url, proc, sync) {
	var req=null;
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (req) {
		if (proc)   
			req.onreadystatechange = proc;
        req.open("GET", url, sync);
    }
    return req;
}

/* code for setting size of primary div's when size needed */
   function setHeightWidth(){
      var availableHeight = 0;
      var availableWidth = 0;
      if(document.all) {
         availableHeight = document.body.clientHeight;
         availableWidth = document.body.clientWidth;
      }
      else {
         availableHeight = innerHeight;
         availableWidth = innerWidth;
      }  
   
      var tree = document.getElementById('outline').style;
      tree.height = availableHeight - 20 - 80;
      
      var ad = document.getElementById('adblock').style;
      ad.left= availableWidth - 140;
      
      var c = document.getElementById('content').style;
      c.width= availableWidth - 180 - 145;

      var h = document.getElementById('header').style;
      h.width= availableWidth - 140;
   }

   var creq=null;
   var oreq=null;

/* ONLOAD handler */
   window.onload=function(){
	/*
	oreq = loadDoc("helpOutline.xml", processOutline, true);
	oreq.send(null);
*/
	setHeightWidth();
	/* update the location in the outline */
	var loc = document.getElementById("outline_loc");
	if (loc){
		var html = new String(loc.innerText);
		var s = html.split(',');
		for (i = 0; i < s.length; i++) {
		   showBranch(s[i]);
		} 
	}
}
/* ONRESIZE handler */
	window.onresize=function(){
	setHeightWidth();
	}
	
   function showLeaf(doc){
	location.href=doc;
	}

/* finish the outline processing */
function processOutline(){
  if (oreq == null)
	return;
  var ready=oreq.readyState;
  var data=null;
  var c = document.getElementById('outline')
  if (c == null)
    return;
  if (ready!=STATE_COMPLETE){
    data="loading...["+ready+"]";
    c.innerHTML = data;
    return;
  }
  /* handle the outline transformation  */
  /* load the xslt file, helpOutline.xsl synchronously  */
  var xreq = loadDoc("helpOutline.xsl", null, false);
  xreq.send(null);
  
  var outl = document.getElementById("outline");

  if (window.XSLTProcessor) {  /* code for firefox */
    var xslStylesheet = xreq.responseXML;
	var xsltProcessor = new XSLTProcessor();
	  
	xsltProcessor.importStylesheet(xslStylesheet);

	var xmlDoc = oreq.responseXML;
	var fragment = xsltProcessor.transformToFragment(xmlDoc, document);

	outl.innerHTML = "";
	outl.appendChild(fragment);
  }
  else if (window.ActiveXObject) {  /* code for Microsoft */
	try {
	xmldom  = new ActiveXObject("MSXML2.DOMDocument.4.0");
	xmldom.validateOnParse = true;
	xmldom.async = false;
	xmldom.resolveExternals = false;
	xmldom.loadXML(oreq.responseText);

	xsltdom = new ActiveXObject("MSXML2.DOMDocument.4.0");
	xsltdom.validateOnParse = true;
	xsltdom.async = false;
	xsltdom.resolveExternals = false;
	xsltdom.loadXML(xreq.responseText); 

	output = xmldom.transformNode(xsltdom);
	outl.innerHTML = output;
	}
	catch(err) {
	outl.innerHTML = err.description;
	} 
  }
}


