/*
toggleme.js

The basis for this script can be found at: http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html

Search for "Add a function to each P element with the class trigger to collapse and expand the following element (by setting its display style to block or none)."

Additional modifications by Jitendra and Elaine, 2006

*/

addEvent(window, "load", dohides);

function dohides() {
	var dls,dts,tostyle,tohide,newspan,newtext;
	// get all dt elements, loop over them
	dts=document.getElementsByTagName('dt');
	//alert (dts[1].parentNode);
	for (i=0;i<dts.length;i++) {
			// get the next sibling until it really is an element, if so, hide it
			if (dts[i].parentNode.className == 'toggleMe') {
				tostyle=dts[i];
				tostyle.className='closed';
			// get the next sibling until it really is an element, if so, hide it						
				tohide=dts[i].nextSibling;
				while(tohide.nodeType!=1) {
					tohide=tohide.nextSibling;
					}
				tohide.className='closed';
/// assemble a link and take the content of the p as its text
				newspan=document.createElement('span');
				newtext=document.createTextNode(dts[i].firstChild.nodeValue);
				newspan.appendChild(newtext);
				newspan.href='#'
// create a new object attribute, this saves us looping in the showhide function
// add the event handlers
				newspan.colobj=tohide;
				newspan.colobj1=tostyle;
				newspan.onclick=function() {
					showhide(this.colobj);
					showstyle(this.colobj1);
					return false;
					}
// replace the paragraph with the link
				dts[i].replaceChild(newspan,dts[i].firstChild)
					//alert (dts[0].firstChild);
				}
			}
	}
	
	function doshow() {
	var dls,dts,tostyle,toshow,newspan,newtext;
	// get all dt elements, loop over them
	dts=document.getElementsByTagName('dt');
	//alert (dts[1].parentNode);
	for (i=0;i<dts.length;i++) {
			// get the next sibling until it really is an element, if so, show it
			if (dts[i].parentNode.className == 'toggleMe') {
				tostyle=dts[i];
				tostyle.className='open';
			// get the next sibling until it really is an element, if so, show it						
				toshow=dts[i].nextSibling;
				while(toshow.nodeType!=1) {
					toshow=toshow.nextSibling;
					}
				toshow.className='open';
/// assemble a link and take the content of the p as its text
				newspan=document.createElement('span');
				newtext=document.createTextNode(dts[i].firstChild.nodeValue);
				newspan.appendChild(newtext);
				newspan.href='#'
// create a new object attribute, this saves us looping in the showhide function
// add the event handlers
				newspan.colobj=toshow;
				newspan.colobj1=tostyle;
				newspan.onclick=function() {
					//alert('step4.1');
					showhide(this.colobj);
					//alert('step 4.2');
					showstyle(this.colobj1);
					//alert('step 4.3');
					return false;
					}
// replace the paragraph with the link
				//dts[i].replaceChild(newspan,dts[i].firstChild)
					//alert (dts[0].firstChild);
				}
			}
	}
		
		// dt
		function showstyle(x) {
			if(x) {
				x.className=x.className=='closed'?'open':'closed';
				//alert (x.className);
			}
		}
		
		// dd
		function showhide(o) {
			if(o) {
				o.className=o.className=='closed'?'open':'closed';
				//alert (o.className);
			}
		}
		
/* Utility functions */

function addEvent(obj, evType, fn) {
 /* Adds an eventListener for browsers which support it
     Written by Scott Andrew: nice one, Scott */
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, false);
		return true;
		}
	else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r; 
		} 
	else {
		return false;
		}
	}