//*************************************************************//
// This code is copyright Robert Munck, Mill Creek Systems LC, //
// 3605 Mill Creek Road, Haymarket VA 20169 USA, munck@acm.org //
// It may be used without permission in any non-commercial     //
// web site, but we would appreciate a modest acknowledgment   //
// somewhere on your site and a link to our site at            //
//            http://mill-creek-systems.com                    //
//                                         Bob Munck 10/14/98  //
//*************************************************************//

// See http://mill-creek-systems.com/WebTips/ExpandingOutline/index.html
// for a complete discussion of this code. This file implements all
// of the basic and advanced features discussed there.
//
// The style sheet rules found in demo.css must accompany this code.

function expandingInit() {
	var tc=document.all.tags("UL");
	for (var ti=0;ti<tc.length;ti++) {
		if ( tc(ti).className=="expanding") {
			if(tc(ti).allbutton) {
				tc(ti).insertAdjacentHTML((tc(ti).allbutton=='bottom')?'beforeEnd':'afterBegin',
					'<SPAN ONCLICK="expand(this)" STYLE="color:blue;font:bold 80%;cursor:hand;" '+
					'ONMOUSEOVER="this.style.color=\'red\'" ONMOUSEOUT="this.style.color=\'blue\'"> </SPAN>');
				setCollapsed(tc(ti),tc(ti).all.tags("SPAN")(0));
				}
			doLev(tc(ti));
			}
		}
	}

function doLev(lul) {
	var lic=lul.children.tags("LI");
	for (var li=0;li<lic.length;li++) {
		lic(li).className="ent";
		lic(li).onclick='';
		lic(li).style.cursor="text";
		cc=lic(li).children.tags("UL");
		if (cc.length==1) {
			lic(li).className="Cnode";
			lic(li).onclick=doclick;
			lic(li).style.cursor="hand";
			doLev(cc(0));
		} else {
			cc=lic(li).children.tags("DIV");
			if (cc.length==1) {
				lic(li).className="Cnode";
				lic(li).onclick=doclick;
				lic(li).style.cursor="hand";
            lic(li).title=lic(li).title+" Click to show answer";
				}
			}
		}
	}

function doclick() {
	var ln=window.event.srcElement;
	while (ln.tagName!="LI" && ln.tagName!="BODY") ln=ln.parentElement;
	if (ln.className=="Enode") {
		ln.className = "Cnode";
      ln.title="Click to show answer";
	} else if (ln.className=="Cnode") {
		ln.className = "Enode";
      ln.title="Click to hide answer";
      }
	if ((ln.offsetTop-document.body.scrollTop+ln.offsetHeight)>window.document.body.clientHeight)
		document.body.scrollTop += ln.offsetTop-document.body.scrollTop;
	event.cancelBubble=true;
	}
	
function expand(spanob) {
	var ob=spanob.parentElement;
	if (ob.isCollapsed) {
		expandall(ob);
		setExpanded(ob,spanob);
	} else {
		hideall(ob);
		setCollapsed(ob,spanob);
		}
	}

function setExpanded(ob,spanob) {
	ob.isCollapsed=false;
	spanob.innerText="[ collapse all ]";
	spanob.title="Hide all answers";
	}

function setCollapsed(ob,spanob) {
	ob.isCollapsed=true;
	spanob.innerText="[ expand all ]";
	spanob.title="Show all answers";
	}

function expandall(outline) {
	dc=outline.all.tags("LI");
	for (i=0; i<dc.length; i++)
		if (dc(i).className=="Cnode") {
			dc(i).className="Enode";
         dc(i).title="Click to hide answer";
         }
	dc=outline.all.tags("UL");
	for (i=0; i<dc.length; i++) {
		if ((dc(i).className=="expanding") && dc(i).allbutton)
			setExpanded(dc(i),dc(i).all.tags("SPAN")(0));
		}
	}
                
function hideall(outline){
	dc=outline.all.tags("LI");
	for (i=0; i<dc.length; i++)
		if (dc(i).className=="Enode") {
			dc(i).className="Cnode";
         dc(i).title="Click to show answer";
         }
	dc=outline.all.tags("UL");
	for (i=0; i<dc.length; i++) {
		if ((dc(i).className=="expanding") && dc(i).allbutton)
			setCollapsed(dc(i),dc(i).all.tags("SPAN")(0));
		}
	}
////////////// End of Expanding Outline Code ////////////////////////

function setFontSize(size) {
	document.CSize.v=parseInt(size);
	document.body.style.fontSize=(document.CSize.v+'%');
	setCookie("FontSize",document.CSize.v);
	}

function setCookie(name, value) {
  var curCookie = name + "=" + escape(value);
  document.cookie = curCookie;
	}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
		}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
	}


