var temp, temp2, cookieArray, cookieArray2, cookieCount;

function showhidemenu(flib){
	flib.getElementsByTagName('ul').style.display=(flib.getElementsByTagName('ul').style.display=="block")?"none":"block";
	flib.span.style.backgroundImage=(flib.getElementsByTagName('ul').style.display=="block")?"url(images/nav_arrow2.gif)":"url(images/nav_arrow1.gif)";
}



var initiate = function(){
	cookieCount=0;
	
	if(document.cookie){
		cookieArray=document.cookie.split(";");
		cookieArray2=new Array();
	
		for(i in cookieArray){
			cookieArray2[cookieArray[i].split("=")[0].replace(/ /g,"")]=cookieArray[i].split("=")[1].replace(/ /g,"");
		}
	}
	
	cookieArray=(document.cookie.indexOf("state=")>=0)?cookieArray2["state"].split(","):new Array();
	temp=document.getElementById("containerul");
	
	for(var o=0;o<temp.getElementsByTagName("li").length;o++){
		if(temp.getElementsByTagName("li")[o].getElementsByTagName("ul").length>0){
			
			
			temp.getElementsByTagName("li")[o].getElementsByTagName("ul")[0].style.display = "none";
			
			if(cookieArray[cookieCount]=="true"){
				showhide(temp.getElementsByTagName("li")[o]);
			}
			
			cookieCount++;
		}
	}
}



function showhide(el){
	el.getElementsByTagName("ul")[0].style.display=(el.getElementsByTagName("ul")[0].style.display=="block")?"none":"block";
	el.getElementsByTagName("span")[0].style.backgroundImage=(el.getElementsByTagName("ul")[0].style.display=="block")?"url(images/nav_arrow2.gif)":"url(images/nav_arrow1.gif)";
}



function writeCookie(){		// Runs through the menu and puts the "states" of each nested list into an array, the array is then joined together and assigned to a cookie.
	cookieArray=new Array()
	for(var q=0;q<temp.getElementsByTagName("li").length;q++){
		if(temp.getElementsByTagName("li")[q].childNodes.length>0){
			if(temp.getElementsByTagName("li")[q].childNodes[0].nodeName=="SPAN" && temp.getElementsByTagName("li")[q].getElementsByTagName("ul").length>0){
				cookieArray[cookieArray.length]=(temp.getElementsByTagName("li")[q].getElementsByTagName("ul")[0].style.display=="block");
			}
		}
	}
	document.cookie="state="+cookieArray.join(",")+";expires="+new Date(new Date().getTime() + 365*24*60*60*1000).toGMTString();
}

function showhidemenu(el){
	//alert('hello');
	el = document.getElementById(el);
	el.getElementsByTagName("ul")[0].style.display=(el.getElementsByTagName("ul")[0].style.display=="block")?"none":"block";
	el.style.backgroundImage=(el.getElementsByTagName("ul")[0].style.display=="block")?"url(/images/nav_arrow2.gif)":"url(/images/nav_arrow1.gif)";
	//writeCookie();
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,'image',features);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) {
   test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}
