//W3C AAA Compliance

function W3CPopulateEmptyElements() {
	//Image alt tags
	images = document.getElementsByTagName("IMG")
	for (i=0;i<images.length;i++) {
		if (images[i].alt == "") {
			images[i].alt = images[i].src
		}
	}
	//Table summary tags
	tables = document.getElementsByTagName("TABLE")
	for (i=0;i<tables.length;i++) {
		if (tables[i].summary == "") {
			tables[i].summary = "EHA"
		}
	}
}
	
//SWAP CSS FUNCTION

var textsizetype = "normal"
var backgroundtype = "dark"

function GetCookies() {
	var cookiestring = findcookie('CUPcontrols')
	if (cookiestring != null)  {
		var cookiebits = cookiestring.split('#'); 
		textsizetype = cookiebits[2];
		backgroundtype = cookiebits[3];
		if (textsizetype == 'large') TextSize('large');
		if (backgroundtype == 'dark') DarkBackgroundColor();
	}
}

function TextSize(type){
	if (type=='large') {
		unsetActiveStyleSheet('main')
		unsetActiveStyleSheet('main_large')
		setActiveStyleSheet('main_large')
		textsizetype = "large"
	} else {
		unsetActiveStyleSheet('main_large')	
		setActiveStyleSheet('main')
		textsizetype = "normal"
	}
	savecookies()
}

function ToggleBackgroundColor() {
	if (backgroundtype=='dark') {
		unsetActiveStyleSheet('main_dark')	
		setActiveStyleSheet('main')
		backgroundtype = "normal"
	} else {
		unsetActiveStyleSheet('main')
		unsetActiveStyleSheet('main_dark')
		setActiveStyleSheet('main_dark')
		backgroundtype = "dark"
	}
	savecookies()
}

function DarkBackgroundColor() {
	unsetActiveStyleSheet('main')
	unsetActiveStyleSheet('main_dark')
	setActiveStyleSheet('main_dark')
}

function savecookies() {
	var datenow = new Date();
	datenow.setTime(datenow.getTime()+(30*24*60*60*1000));//first number is days to keep
	document.cookie = "CUPcontrols=#REMOVED_FETURE_pagewidth#"+textsizetype+"#"+backgroundtype+"#;expires="+datenow.toGMTString()+"; path=/";
}

function findcookie(nameof) {
	var namefind = nameof + "="
	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(namefind) == 0) return c.substring(namefind.length,c.length)
	}
	return null
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
	   if(a.getAttribute("title") == title) a.disabled = false;
	 }
   }
}

function unsetActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
	   if(a.getAttribute("title") == title) a.disabled = true;
	 }
   }
}

//ZOOM FUNCTION

var zoomfactor = 0
var zoompoint = new Array()
zoompoint[0]=1.00
zoompoint[1]=1.25
zoompoint[2]=1.50
zoompoint[3]=1.75
zoompoint[4]=2.00
zoompoint[5]=2.25
zoompoint[6]=2.50

function Zoom(direction) {
	if (BrowserDetect.browser == "Explorer") {
		if (direction == "in") {
			if (zoomfactor<zoompoint.length-1) {
				zoomfactor++
			}
		} else {
			if (zoomfactor > 0) {
				zoomfactor--
			}
		}
		document.getElementById("wholepage").style.zoom = zoompoint[zoomfactor]
	} else {
		alert("These zoom controls are only possible in Microsoft Internet Explorer. If you are using an alternative browser such as Firefox or Opera please use the zoom functions built into the browser menu")
	}
}

//Keyboard shortcuts

