function setActiveStyleSheet(title) {

  var i, a, main;

  var kfn = document.getElementsByTagName('*');

  for(i=0; i<kfn.length; i++) {

    a = kfn[i];

    if(a.getAttribute("type") == 'text/css' && a.getAttribute("title")) {

      a.disabled = true;

      if(title != '' && a.getAttribute("title") == title) a.disabled = false;

    }

  }

}



function getActiveStyleSheet() {

  var i, a;

  var kfn = document.getElementsByTagName('*');

  for(i=0; i<kfn.length; i++) {

    a = kfn[i];

    if(a.getAttribute("type") == 'text/css' && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");

  }

  return null;

}



function getPreferredStyleSheet() {

  var i, a;

  var kfn = document.getElementsByTagName('*');

  for(i=0; i<kfn.length; i++) {

    a = kfn[i];

    if(a.getAttribute("type") == 'text/css' && 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 styleSwicther(name) {	

	if (document.getElementsByTagName) { 

		document.writeln('<dl>')
		
			document.writeln('<dt>Color scheme</dt>')
			
			document.writeln('<dd class="style1"><a href="" onclick="setActiveStyleSheet(\'Design 1\');return false; return bgcolor=\'white\';" onkeypress="setActiveStyleSheet(\'Design 1\');return false; return bgcolor=\'white\';" class="styleOne"  title="Design 1">A</a></dd>')
			
			document.writeln('<dd class="style2"><a href="" onclick="setActiveStyleSheet(\'Design 2\');return false; return bgcolor=\'white\';" onkeypress="setActiveStyleSheet(\'Design 2\');return false; return bgcolor=\'white\';" class="styleTwo" title="Design 2">A</a></dd>')
			
			document.writeln('<dd class="style3"><a href="" onclick="setActiveStyleSheet(\'Design 3\');return false; return bgcolor=\'black\';" onkeypress="setActiveStyleSheet(\'Design 3\');return false; return bgcolor=\'black\'" class="styleThree" title="Design 3">A</a></dd>')
		
		document.writeln('</dl>')

	}

}



window.onload = function(e) {

  var cookie = readCookie("barbour-abi-style");

  var title = cookie ? cookie : getPreferredStyleSheet();

}



window.onunload = function(e) {

  var title = getActiveStyleSheet();

  createCookie("barbour-abi-style", title, 365);

}



var cookie = readCookie("barbour-abi-style");

var title = cookie ? cookie : getPreferredStyleSheet();

setActiveStyleSheet(title);
