// Functions 'fetchContent', 'fetchDone' and 'load'
// Loads a named div with content from an external file

// call code with the name of the external file and the id of the div you want to put the content into

// <a href="file1.html" onclick="load('file1.html','content');return false;">File 1</a>

function fetchContent(url, target) {
  document.getElementById(target).innerHTML = '<p class="black">Fetching results...</p>';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {fetchDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function fetchDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" Fetch Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function load(name, div) {
	fetchContent(name,div);
	return false;
}

// *** End of function block for loading a div with content from an external file



// Function 'switchdiv'
// Sets display to none for a list of divs named d1, d2... dn
// and finally fades in the div identified by 'divon'

function switchdiv(ndivs, divon)
// Sets display to none for a list of divs - divs must be named d1, d2, d3 etc (no gaps!)
// Finally fades in the div identified by 'divon'
		{  var i=1;
			for (i=1;i<=ndivs;i++)
			{ 
			var whichLayer="d" + i ;
			var elem, vis;  
				if( document.getElementById ) // this is the way the standards work    
					elem = document.getElementById( whichLayer );  
				else if( document.all ) // this is the way old msie versions work      
					elem = document.all[whichLayer];  
				else if( document.layers ) // this is the way nn4 works    
					elem = document.layers[whichLayer];  
			vis = elem.style;  
			if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
// Uncomment the below line to use this as a toggle (on/off - off/on)
//				vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; 
				vis.display = (vis.display==''||vis.display=='block')?'none':'block';
			}
		Effect.Appear(divon);
}

// *** End of function switchdiv
