<!--

window.onload = function() {
	initialize();
}

function initialize() {
	initializeCollapse();
	//initialise_userpopup();
	
	// Handle bookmarks where page gets squidged when summary collapses
	if (location.hash!=""){
	var as = document.getElementsByTagName("a");
	for(i=0;i<as.length;i++){
		if (as[i].getAttribute("name")==location.hash.replace("#","")) {
			as[i].focus();
			break;
		}
	}
	}
	
}

function initializeCollapse() {
	// Attempt to set all the collapsible sections
	try {
    if (document.getElementById("summary")) {
			initializeCollapsibleSection("summary", true);
		}
    if (document.getElementById("alternateFormats")) {
    	initializeCollapsibleSection("alternateFormats", true);
    }
    if (document.getElementById("relatedInternal")) {
	  	initializeCollapsibleSection("relatedInternal", false);
	  }
    if (document.getElementById("relatedExternal")) {
	  	initializeCollapsibleSection("relatedExternal", false);
	  }
    if (document.getElementById("additionalSettings")) {
	  	initializeCollapsibleSection("additionalSettings", true);
	  }	  
    if (document.getElementById("footnotes")) {
	  	initializeCollapsibleSection("footnotes", false);
	  }	  	  
    if (document.getElementById("comments")) {
			initializeCollapsibleSection("comments", false);
		}	  
  }
  catch (err) {
	// No need for a formal error handler in the final version
	alert("Error initializing collapse: " + err.description); 
  }
}

function addUnderline(element) {
	element.style.textDecoration = "underline";
	}

function removeUnderline(element) {
	element.style.textDecoration = "none";
	}

function initializeCollapsibleSection(section, state) {
	var collapsibleSection;
	var collapsibleHeading;
	var collapsibleBody;
	var children; 
	if (document.getElementById) {
		// Get all child objects
		collapsibleSection = document.getElementById(section);
		children = collapsibleSection.childNodes; 
		if (children != null) {
			// Find the collapsible body
			for (i=0; i < children.length; i++) {
				if (children[i].className == "collapsibleBody") {
					collapsibleBody = children[i];
					break;
				}
			}
			// Find the collapsible heading
			for (j=0; j < children.length; j++) {
				if (children[j].className == "collapsibleHeading") {
					collapsibleHeading = children[j];
					break;
				}
			}
			// Set the collapsible body to open or closed
			if (collapsibleBody != null){
				if (state == true){
					collapsibleBody.style.display = "none";
				} 
				else {
					collapsibleBody.style.display = "";
				}
			}
		}
		// Append an onclick event to the collapsible heading
		try {
			collapsibleHeading.onclick = function() {
				toggleCollapsibleSection(collapsibleHeading, collapsibleBody);
				}
		}
		catch (err) {
			alert("Error setting function: " + err.description);
		}
		// Append CSS rules to the collapsible heading
		collapsibleHeading.onmouseover = function () {addUnderline(collapsibleHeading)};
		collapsibleHeading.onmouseout = function () {removeUnderline(collapsibleHeading)};
		collapsibleHeading.style.paddingLeft = "12px";
		collapsibleHeading.style.cursor = "pointer";
		collapsibleHeading.style.height = "1em";
		collapsibleBody.style.marginLeft = "12px";
		if (collapsibleBody.style.display == "none") {
			collapsibleHeading.style.fontWeight = "normal";
			collapsibleHeading.style.backgroundImage = "url(\"/images/open-section.gif\")";
		}
		else {
			collapsibleHeading.style.backgroundImage = "url(\"/images/close-section.gif\")";
			collapsibleHeading.style.fontWeight = "bold";
		}
	}
	else if (document.all) {
		alert("Non-W3C DOM");
	}
}

function toggleCollapsibleSection(collapsibleHeading, collapsibleBody) {
	if (collapsibleBody.style.display.toLowerCase() == "none") {
		collapsibleHeading.style.fontWeight = "bold";
		collapsibleHeading.style.backgroundImage = "url(\"/images/close-section.gif\")";
		collapsibleBody.style.display = "";
	}
	else {
		collapsibleHeading.style.fontWeight = "normal";
		collapsibleHeading.style.backgroundImage = "url(\"/images/open-section.gif\")";
		collapsibleBody.style.display = "none";
	}
}

/*

// Blog stuff (TEstING)

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while(obj=obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return[curleft,curtop];
}

var current_user_id = 0;

function showUser() {
	current_user_id = this.id.replace(/[^_]*_(.*)/,"$1");
	var foaf_doc = httpGet("http://testbed.plan9.netfundi.com/_scripts/logon/foaf.asp?"+current_user_id);
	var xml = false;
	if (window.ActiveXObject) {
		xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
		xml.loadXML(foaf_doc);	
	}
	else {
		xml = Sarissa.getDomDocument();
		xml = (new DOMParser()).parseFromString(foaf_doc, "text/xml");
	}
	var xsl = false;
	if (window.ActiveXObject) {
		xsl = new ActiveXObject("Microsoft.XMLDOM");
	}
	else {
		xsl = Sarissa.getDomDocument();
	}
	xsl.async = false;
	xsl.load("/xsl/foaf.xsl");
	if (xml && xsl) {
		var transformedText = xml.transformNode(xsl);
		transformedText = transformedText.replace(/&lt;/gi,"<")
		transformedText = transformedText.replace(/&gt;/gi,">")
		transformedText = transformedText.replace(/&amp;/gi,"&")
		transformedText = transformedText.replace(/&amp;/gi,"&")
		transformedText = transformedText.replace(/<!DOC[^>]*>/,"")
		transformedText = transformedText.replace(/<a([^>]*)>/gi,function(m1,m2) {
			var a_string = "<a";
			if (m2.substring(m2.length-1,m2.length)=="/") {
			var b = m2.substring(0,	m2.length-1) + "></a>";
			a_string += b;
			}
			else {
			a_string = m1;			
			}
			return(a_string);
		});
		var user_div = document.getElementById("user");
		user_div.innerHTML = transformedText;
		var pos = findPos(this);
		var pos_left = pos[0];
		var pos_top = pos[1];
		user_div.style.top = pos_top+"px";
		user_div.style.left = pos_left+"px";
		user_div.style.display = "block";			
	}

}

function hideUser() {
	var user_div = document.getElementById("user");
	user_div.style.display = "none";
}


function gotoUser() {
	if (current_user_id!=0) location.href="/account/user/?userid="+current_user_id;
}

function initialise_userpopup() {
	var user_classes = document.getElementsByTagName("span");
	for(var i=0;i<user_classes.length;i++) {
		if (user_classes[i].className=='user') {
			user_classes[i].onmouseover = showUser;
			}
	}
	var user_div = document.getElementById("user");
	user_div.onmouseout = hideUser;
	user_div.onmousedown = gotoUser;
}

*/

//-->
