// -------------------------------------------------------------------------------------------------
// handle style sheet switching to enable switching between different font sizes
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++) {
	//alert(a.getAttribute("title"));
	  
    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);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
// -------------------------------------------------------------------------------------------------

// routines to handle internal admin and modification popups:
// user authentication window
function doadmin(url) 
{
	newwindow=window.open(url,'','directories=0,location=0,status=0,scrollbars=1,toolbar=0,menubar=0,resizable=1,top=100,left=200,height=300,width=500');
	if (window.focus) {newwindow.focus()}
	return false;
}
// assign URL to SNL menu option
function doAssignURL(snlid, snlname) 
{
	var url = '/cms/assignURL.aspx?snlid=' + snlid + '&snlname=' + snlname
	newwindow=window.open(url,'','directories=0,location=0,status=0,scrollbars=1,toolbar=0,menubar=0,resizable=1,top=100,left=100,height=680,width=720');
	if (window.focus) 
		{newwindow.focus()}
	return false;
}
// edit FAQ / A to Z
function doedit(url) {
	newwindow=window.open(url,'','directories=0,location=0,status=0,scrollbars=1,toolbar=0,menubar=0,resizable=1,top=100,left=100,height=500,width=600');
	if (window.focus) {newwindow.focus()}
	return false;
}


// -------------------------------------------------------------------------------------------------
// support multiple onload function calls
var old = window.onload; // catch any existing onload calls 1st
window.onload = function () {
  if (old) { // execute existing onloads
    old();
  }
  for(var ii=0; arguments.callee.actions.length > ii; ii++)
  {
    arguments.callee.actions[ii]();
  }
};
window.onload.actions = [];

// call e.g., window.onload.actions.push(myFunction);