//PMCKAY
//adjusted setActiveStylesheet function to cope with the addition of ctl00_ onto the ID of the control
//this doesn't seem to happen in any other project, I think it is due to the Header.Databind call that was necessary
//to get the CSS links to resolve correctly.

function setActiveStyleSheet(title,id) {
  var i, a, main, rep, name;  rep = "ctl00_";  id = id.replace(rep, "");    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	if (a.getAttribute("title") && a.getAttribute("id"))    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title").indexOf(title) != -1 && a.getAttribute("id")  && a.getAttribute("title")) {
      a.disabled = true;       name = a.getAttribute("id");       name = name.replace(rep, "");       if(name == id) a.disabled = false;    }  }}function getActiveStyleSheet(title) {  var i, a;  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  	if (a.getAttribute("title") && a.getAttribute("id"))    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title").indexOf(title) != -1 && a.getAttribute("id") && a.getAttribute("title") && !a.disabled) return a.getAttribute("id");  }  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("id") && 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("styleColour");  var styleColour = cookie ? cookie : getPreferredStyleSheet();  setActiveStyleSheet('colour',styleColour);
    var cookie = readCookie("styleText");  var styleText = cookie ? cookie : getPreferredStyleSheet();  setActiveStyleSheet('text',styleText);
  }window.onunload = function(e) {  var Stylecolour = getActiveStyleSheet('colour');  createCookie("styleColour", Stylecolour, 365);
    var styleText = getActiveStyleSheet('text');  createCookie("styleText", styleText, 365);}var cookie = readCookie("styleColour");var styleColour = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet('colour',styleColour);
var cookie = readCookie("styleText");var styleText = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet('text',styleText);

