

/*------------------------------------------------------------------------
 * get_style()
 * 
 * Returns the title of the current active stylesheet.
 *------------------------------------------------------------------------*/

function get_style() {
  var elems = document.getElementsByTagName("link");
  var n, elem, title;

  for (n = 0; (elem = elems[n]); n++) {
     if (elem.getAttribute("rel").indexOf("style") != -1 
     && (title = elem.getAttribute("title"))
     && !elem.disabled)
       return title;
  }
  return null;
}


/*------------------------------------------------------------------------
 * set_style(title)
 * 
 * Set the active stylesheet by enabling the <link rel="style" ...> 
 * element that has a title attribute matching the title argument,
 * and disabling all others.
 *------------------------------------------------------------------------*/

function set_style(title) {
  var elems = document.getElementsByTagName("link");
  var n, elem, tattr;

  for (n = 0; n < elems.length; n++) {
    elem = elems[n];

    if (elem.getAttribute("rel").indexOf("style") != -1 
    && (tattr = elem.getAttribute("title"))) {
      elem.disabled = true;
      if (tattr == title) 
        elem.disabled = false;
    }
  }
  return false;
}


/*------------------------------------------------------------------------
 * set_cookie(name, value, days)
 * 
 * Set a cookie with the name and value passed as the first two arguments, 
 * set to expire in the number of days specified in the third argument.
 *------------------------------------------------------------------------*/

function set_cookie(name, value, days) {
  var expires;

  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days*24*60*60*1000));
    expires = "; expires=" + date.toGMTString();
  }
  else 
    expires = "";

  document.cookie = name + "=" + value + expires + "; path=/";
}


/*------------------------------------------------------------------------
 * get_cookie(name)
 * 
 * Returns the value of the cookie identified by the name argument.
 *------------------------------------------------------------------------*/

function get_cookie(name) {
  var namestr  = name + "=";
  var cookbits = document.cookie.split(';');
  var n;

  for(n = 0; n < cookbits.length; n++) {
    var c = cookbits[n];

    /* remove leading whitespace */
    while (c.charAt(0) == ' ') 
      c = c.substring(1, c.length);

    /* if the name start this cookie fragment, return the value */
    if (c.indexOf(namestr) == 0) 
      return c.substring(namestr.length, c.length);
  }
  return null;
}


/*------------------------------------------------------------------------
 * text_style()
 * blue_style()
 * orange_style()
 * 
 * Set the stylesheet to various different styles
 *------------------------------------------------------------------------*/

function text_style() {
  set_style('Text');
  return false;
}

function blue_style() {
  set_style('Blue');
  return false;
}

function orange_style() {
  set_style('Orange');
  return false;
}

function purple_style() {
  set_style('Purple');
  return false;
}

function green_style() {
  set_style('Green');
  return false;
}


function about_style(name) {
    document.getElementById("skinfo").innerHTML = "Select the " + name + " stylesheet";
}

function unabout_style() {
    document.getElementById("skinfo").innerHTML = "Stylesheet Selector";
}


function preload_images() {
image1 = new Image();
image1.src = "/logo/blue/cogspin.gif";
image2 = new Image();
image2.src = "/logo/orange/cogspin.gif";
}



window.onunload = function(e) { 
  /* set a cookie to remember the stylesheet for next time */
  var style;
  if (style = get_style()) 
    set_cookie("stylesheet", style, 365);
}

/* set style */
var style;
if (style = get_cookie("stylesheet")) 
  set_style(style);

preload_images();

