function map_email_link () {
//
// currentl not called on loading - commented out in line 92 below.
//
//within a pge email links are set to 'emailform2'
//which is a page with a disguised email waddress for manual use
//when the users browser has JScript disabled
//if JScript is enabled the when a page loads this script runs to
//redirect to 'emailform3' instead
	var links = document.getElementsByTagName('a');
	for (var i=0;i<links.length;i++) {
		var href = links[i].getAttribute('href'); 
		var joff ='emailform2';
		var jon='emailform3';
		if (href.indexOf(joff)!=-1) {
         var toTheLeft = href.substring(0, href.indexOf(joff));
         var toTheRight = href.substring(href.indexOf(joff)+joff.length, href.length);
         var temp = toTheLeft + jon + toTheRight;
			links[i].href=temp;
		}
	}
}	

//the next functions use cookies to set / change the ddefault style

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")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

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;
}

function changestyle(title) {
  setActiveStyleSheet(title);
  createCookie("style", title, 365);
}

function getchosenstyle() {
	var parameter=location.search.substring(1,location.search.length);
	if (parameter.length>2 && parameter != "") changestyle(parameter);
}

//when a page loads the email mapping function is called
//as is the function to read the preferred style
window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
//  map_email_link ();
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
