// this is added to make IE case sensitive in getElementById()
// from ajax.phpmagazine.net online; originally from Mike Bulman
document._getElementById = document.getElementById;
document.getElementById = function(id) {
        var a = [];
        var o = document._getElementById(id);
        if (!o) return o;
        while (o.id != id) {
            a.push({i:o.id,e:o});
            o.id='';
            o = document._getElementById(id);
           if (!o) return o;
       }
       for (j=0,jj=a.length; j<jj; j++) a[j].e.id = a[j].i;
       a = null;
       return o;
}


function loadLevel(myForm){
	//document.getElementById('debug').innerHTML="Level: "+myForm.level.value+"<br>"+"Subject: "+myForm.subject.value+"<br>";
	var level=myForm.level.value;
	var subject=myForm.subject.value;

	document.location=subject+level+".html";
}

function find_elt(elt,arr){

	for(var i=0;i<arr.length;i++){
		if(elt.match(arr[i])){
			return i;
		}

	}

	return false;

}


function toggleAll(){
	if(document.cookie){
		for(var i=0;i<allItems.length;i++){
			var c=allItems[i][0];
			var m=allItems[i][1];
			var c_name=allItems[i][2];
			if(readCookie(c_name)){toggle(c,m,c_name);}

		}
	}

}



function toggle(elt,array,cookie){
	var element=document.getElementById(elt);
	var lastChosen=readCookie(cookie);

	if(!element.style.display || element.style.display=="none" || (lastChosen==elt && !element.style.display)){
		element.style.display="block";
		createCookie(cookie,elt,1);

		for(var i=0;i<array.length;i++){
			if(array[i] != elt){
				document.getElementById(array[i]).style.display="none";
			}
		}
	}else{
		element.style.display="none";
		var c=readCookie(cookie);
		if(c){eraseCookie(cookie);}
	}
}

function toggleNoPersist(elt,array){
	var element=document.getElementById(elt);

	if(!element.style.display || element.style.display=="none"){
		element.style.display="block";
		turnSelectedOn(elt);
		for(var i=0;i<array.length;i++){
			if(array[i] != elt){
				document.getElementById(array[i]).style.display="none";
				turnSelectedOff(array[i]);
			}
		}
	}else{
		element.style.display="none";
	}

}

function turnSelectedOn(elt){
        var new_elt=elt+"_sel";
        var e=document.getElementById(new_elt);
        if(e != null) {
                e.className="selected";
        }
}

function turnSelectedOff(elt){
        var new_elt=elt+"_sel";
        var e=document.getElementById(new_elt);
        if(e != null) {
                e.className="";
        }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/**
 * mm_menu 20MAR2002 Version 6.0
 * Andy Finnell, March 2002
 * Copyright (c) 2000-2002 Macromedia, Inc.
 *
 * based on menu.js
 * by gary smith, July 1997
 * Copyright (c) 1997-1999 Netscape Communications Corp.
 *
 * Netscape grants you a royalty free license to use or modify this
 * software provided that this copyright notice appears on all copies.
 * This software is provided "AS IS," without a warranty of any kind.
 */

// this function highlights the box on the left of segment headers with the appropriate color

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_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,winName,features);
}



/* fixes some style issues when window is resized */
function adjustStyle(){
	var resources=document.getElementById('col1');
	var features=document.getElementById('col2');

	//alert(resources.clientHeight);

	if(document.body.clientWidth < 959){
		resources.style.width="95%";
		features.style.width="95%";
		features.style.border="none";
		resources.style.border="none";
		features.style.marginLeft="0px";
		features.style.marginTop="10px";
		resources.style.marginBottom="0px";
		//resources.style.float="none";
		//features.style.float="none";
		//resources.style.marginBottom="10px";
	}else{
		resources.style.width="305px";
		features.style.width="55%";
		features.style.marginTop="-225px";
		resources.style.marginBottom="230px";

		if(resources.clientHeight > features.clientHeight){
			resources.style.borderRight="1px solid #F7DE00";
			features.style.borderLeft="none";
		}else{
			resources.style.borderRight="none";
			features.style.borderLeft="1px solid #F7DE00";
		}
	}
}

function getURLVar(urlVarName) {
//divide the URL in half at the '?'
	try{
		var urlHalves = String(document.location).split('?');
		var urlVarValue = '';
		if(urlHalves[1]){
			//load all the name/value pairs into an array
			var urlVars = urlHalves[1].split('&');
			//loop over the list, and find the specified url variable
			for(i=0; i<=(urlVars.length); i++){
				if(urlVars[i]){
					//load the name/value pair into an array
					var urlVarPair = urlVars[i].split('=');
					if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
						//I found a variable that matches, load it's value into the return variable
						urlVarValue = urlVarPair[1];
					}
				}
			}
		}
		return urlVarValue;
	}

	catch(err){
		return false;
	}
}

function adjustStyles(){
	var top_picklist=document.getElementById('level_nav').getElementsByTagName('table')[0];
	var resources=document.getElementById('col1');
	var features=document.getElementById('col2');
	var level_nav=document.getElementById('level_nav');

	//alert(top_picklist.clientWidth);
	//alert(features.offsetTop);
	//alert(navigator.appName);


	if(navigator.appName=="Microsoft Internet Explorer"){
		features.style.marginTop="10px";
		resources.style.height="100%";
	}else{
		features.style.marginTop="0px";
	}

	level_nav.style.width="100%";

	if(document.body.clientWidth < 959){
		features.style.cssFloat="none";
		resources.style.cssFloat="none";
		resources.style.marginBottom="10px";
		features.style.border="none";
		features.style.marginLeft="0px";
		resources.style.width="95%";
		features.style.width="95%";

	}else{
		features.style.cssFloat="left";
		resources.style.cssFloat="left";
		resources.style.marginBottom="230px";
		features.style.borderLeft="1px solid #F7DE00";
		features.style.marginLeft="0px";
		resources.style.width="305px";
		features.style.width="58%";
		resources.style.height="100%";
		features.style.height="100%";

	}


}

function getBrowser(){
	return navigator.appName;
}
