// JavaScript Document
// new 1-1-010101


/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

var ignoreMe = 'a';
var menuNum;

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
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;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
	ignoreMe = 'a';
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"

// remebr to open up the other menu as well  IF there is more than one sub menu add it to the result list

switch (cookievalue){

case "sub2": // declare the name of the "sub" staement that holds the sub menu to be diaplyed  within it.
document.getElementById("three1").style.display="block"; // add the name of the block to be displayed to the elementById
break;

}
}
readHighlightCookie();
}// end function

/*mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm*/




function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc

break
}
inc++
}
if (ignoreMe != 'yes'){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
	}//end if
	ignore = "a";
//	   alert("ignore = a ");
}// end function

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate





//#################################################################################################################################
//###############################################  next level menu  ###############################################################

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenusub{display: none;}\n')
document.write('</style>\n')
}

function ThreeMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenusub") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}





//#################################################################################################################################
//###############################################  next level menu  ###############################################################
var cookieNameM = 'higlightMenu';
var nameOFcookieM;
var myMenu;
var changeMenu;
var changeColor = '#000000';
var myMenuStyle;

function addHighlightCookie(menuID, menuStyle){

//cookieNameM = 'highlightMenu';
setCookieM('highlightMenu', menuID)	

//cookieNameM = 'menuStyle';
setCookieM('menuStyle', menuStyle)
// alert ('set cookies' + menuID);
	
	
} // end function addHighlightCookie



function readHighlightCookie(){

//cookieNameM = 'highlightMenu';
myMenu = getCookieM('highlightMenu');	
//alert('highlight this menu -->> ' + myMenu); // used for testing only

//cookieNameM = 'menuStyle';
myMenuStyle = getCookieM('menuStyle');
//alert('highlight this colour -->> ' + myMenuStyle);// used for testing only

switch(myMenuStyle){
case 'orange':	
changeColor = '#FF8200';
break;
case 'dkblue':	
changeColor = '#000099';
break;
case 'menuBlue':	
// changeColor = '#2E8CCE'; // this color looked TOO much like the background//
changeColor = '#CC3300';
break;
}//end switch



changeMenu = document.getElementById(myMenu);

if (changeMenu) {
changeMenu.style.color = changeColor;//'inherit' pick up this value from bottom of sheet
}

}// end function readHighlightCookie




//mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
function setCookieM(cookieNameM,value) // this function will set the cookie value
{
document.cookie=cookieNameM+ "=" +escape(value);
}


// mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm



function checkCookieM(cookieNameM) // this function check if the cookie is set   DO NOT ALTER
{
cookieValue=getCookie(cookieNameM);
if (cookieValue!=null && cookieValue!="" || cookieValue !="next")
  {
  nameOFcookieM = cookieNameM;// do nothing
  setCookieM(cookieNameM, 0);
  }
else 
  {
  TABname = 1; // the attempt questionnumber
    {
    setCookieM(cookieNameM,TABname); // the third value is not set as we do not want this remebered if the browser closes
    nameOFcookieM = cookieNameM;// do nothing
	}
  }
}



//mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

function getCookieM(c_name) // function to read the vlaue of the cookie DO NOT ALTER
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 ;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return ""
}

//mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm


// function killTrack destroys the cookie that was set to show where the menu was left open.
// it kills all cookies including the ones where you see the menu highlighted

function kilTrack(){
	setCookie('switchmenu', "" , -1);
	setCookie('highlightMenu', "" , -1);
	setCookie('menuStyle', "" , -1);
}


function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function ignoreMenu(menuID){
 ignoreMe = "yes"
 // alert("ignore = yes ");
 blockid="sub2"
 // killTrack();
 menuNum = ('menu' + menuID)
 setCookieM('highlightMenu', menuNum)
 setCookieM('menuStyle', "menuBlue")
 
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}
