//Used by the form validation function.
function isEmpty(inputStr) {
if (inputStr == null || inputStr == "") {
	return true
	}
else {
	return false;
	}
}

/*Tabbed context panel functions*/

//Var to keep track of current tab. Initially empty.
var currentTab = null;

/*Function to switch between tabbed info panels. Note that you need to call this from body onload to make the default panel appear once the page has loaded*/
function showPanel(id) {
/*Check that the browser supports getElementById. This will protect older or simpler browsers*/
if (document.getElementById) {
	//The target tab.
	var tabName = id;
	//The target info panel.
	var infoPanel = id + "Info";
	//The currently selected info panel.
	var currentInfoPanel = currentTab + "Info";

	/*If currentTab has a value, which it should, hide the appropriate element and highlight the matching tab*/
	if (currentTab != null) {
		//Hide the current info panel.
		document.getElementById(currentInfoPanel).style.display = "none";
		//Return the current tab to normal.
		document.getElementById(currentTab).className = "none";
		}
	//Show the target info panel.
	document.getElementById(infoPanel).style.display = "block";
	//Highlight the target tab.
	document.getElementById(tabName).className = "tabActive";

	/*Set currentTab to the newly selected tab so it gets processed next time round*/
	currentTab = tabName;
	/*Call updateAccessibility() because the normal text size mechanism gets broken by this function being attached to body onload*/
	updateAccessibility();
	}
}


/*Style switcher*/
function setActiveStyleSheet(title,imageName) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  //If the page has loaded it's safe to update the text size buttons.
  if ((document.getElementById("textSmaller")) && (document.getElementById("textLarger"))) {
  	updateAccessibility();
  	}
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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 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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  //updateAccessibility();
}

//Protect from older browsers.
if (document.getElementById) {
	window.onunload = function(e) {
		var title = getActiveStyleSheet();
		createCookie("style", title, 365);
		}
	}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

//Update the text size buttons.
function updateAccessibility() {
var activeStyle = getActiveStyleSheet();
if (document.getElementById) {
	if (activeStyle == "bigText") {
		document.getElementById("textSmaller").src = "../../images/textSmaller.gif";
		document.getElementById("textLarger").src = "../../images/textLargerActive.gif";
		}
	else {
		document.getElementById("textSmaller").src = "../../images/textSmallerActive.gif";
		document.getElementById("textLarger").src = "../../images/textLarger.gif";
		}
	}
}
/*End of style switcher*/