// JavaScript Document
// <script language="JavaScript" type="text/JavaScript">
// Example:
// alert( readCookie("myCookie") );
var ToggleSections=true;	//If an unactivated section is clicked, the active section is
							//  toggled off
var CurrentSection=1;
var MaxDivs=-1;
var sections, arrows;

function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}


// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}


// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function CountSections(SectionName) {
	var x=0;
	var MaxSections=-1;
	for (x=0;x<10;x++) {
		if (findObj(SectionName + x) && ((x-MaxSections)==1) ) {
			MaxSections=x;
		}
	}
	return MaxSections;
}


function ActivateDiv(n, force) {
	// Show the indicated section, hide all the rest.
	// force causes a section to be displayed (not toggled off)
	//    even though it is already active
	var x;
	if (MaxDivs<0) {
		MaxDivs=CountSections("section");
	}

	//sections=findObj("section");
	//sections=document.getElementsByName("section");
	//sections=document.getElementById("section");
	//arrows=document.getElementById("arrow");
	for (x = 0; x <= MaxDivs; x++) {
//	for (x = 0; x < sections.length; x++) {
		if (x != n) {
			if (ToggleSections) {
				hidediv(x);
			}
		} else {
			if (force) {
				showdiv(x);
				writeCookie("ActiveSection", n, 1);
			} else {
				if (findObj("section"+x).style.display == "none") {
				//if (sections[x].style.display == "none") {
					showdiv(x);
					
					writeCookie("ActiveSection", n, 1);
				} else {
					hidediv(x);
					writeCookie("ActiveSection", -1, 1);
				}
			}
		}
		CurrentSection=n;
	}
}

function hidediv(n) {
	showHideLayers("section"+n, 'hide');
	findObj("arrow" + n).src = "../images/rightarrow.gif";
	//sections[n].style.display = "none";
	//arrows[n].src = "../images/rightarrow.gif";
}

function showdiv(n) {
	showHideLayers("section"+n, 'show');
	findObj("arrow" + n).src = "../images/downarrow.gif";
	//sections[n].style.display = "";
	//arrows[n].src = "../images/downarrow.gif";
}

function GetCurrentSection () {
	return readCookie("ActiveSection");
}

function debug(msg) {
	window.status = msg;
}

// * Dependencies * 
// this function requires the following snippets:
// JavaScript/readable_MM_functions/findObj
//
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'show',Layer2,'hide');
function showHideLayers()
{ 
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-1); i+=2)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+1];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = "";
        else if(visStr == 'hide') visStr = "none";
      }
      obj.display = visStr;
    }
  }
}

CurrentSection = readCookie("ActiveSection");  //reads last active section
