/* this file contains the following:
- change contrast (stylesheet switcher)
- resize text
- unobtrusive JavaScript: 
	- add print link
	- show hidden div
*/

/*========================   STYLESWITCHER - USED TO CHANGE CONTRAST BY SWITCHING STYLESHEETS  =========================================*/
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 styleSwitcherReadCookie() {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

function styleSwitcherCreateCookie() {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

/*========================   end STYLESWITCHER - USED TO CHANGE CONTRAST BY SWITCHING STYLESHEETS   ===============================*/


/*========================   RESIZE TEXT =========================================*/

var prefsLoaded = false;
var defaultFontSize = 80;
var currentFontSize = defaultFontSize;


function changeFontSize(sizeDifference){
currentFontSize = (defaultFontSize * sizeDifference);
setFontSize(currentFontSize);
fontSizeCreateCookie("fontSize", currentFontSize, 365);

};

function setFontSize(fontSize){
document.body.style.fontSize = fontSize + '%';
};

function fontSizeCreateCookie(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 fontSizeReadCookie(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 readFontSizeValue (){
	setFontSize(fontSizeReadCookie("fontSize"))
}

/*========================   end RESIZE TEXT =========================================*/

/*========================   ADD "PRINT THIS PAGE" LINK  ========================*/
/* The "print this page" link will only be added if javascript is enabled in the user's browser */
function addPrintLink(){

         if(!document.getElementById){return;}

         var ul = document.getElementById("skipul");

         if(!ul){return;}

         var li = document.createElement("li");

         var a = document.createElement("a");

         /*a.setAttribute("onclick", "window.print();");

         a.setAttribute("href", "#");this wasn't working in IE6 and IE7*/
		 
		 a.setAttribute("href", "javascript:window.print();"); 
		 
         var text = document.createTextNode("Print this page");

         a.appendChild(text);

         li.appendChild(a);

         ul.appendChild(li);

}

/*========================   end ADD "PRINT THIS PAGE" LINK  ========================*/



/*========================   SHOW JAVASCRIPT FUNCTIONALITY ON PAGES WHERE IT IS HIDDEN BY DEFAULT  ========================*/
/* This is used on the Change Text Size and Change Contrast pages
The links to change text size or change the contrast will only be visible if javascript is enabled in the user's browser  - this makes sure users don't see links or functionality that won't work when JavaScript is disabled.
The links (which use JavaScript) are contained within a div with id "divJS". 
In the stylesheets, "divJS" is set to display: none to hide the contents by default. 
If JavaScript is enabled, this script changes the style to display: block so that the contents of the div will be displayed and users can see and use the JavaScript functionality. 
*/

function showDivContainingJavascriptFunctionality (){
        if(document.getElementById("divJS")){document.getElementById("divJS").style.display = "block";}
}


/*========================  end SHOW JAVASCRIPT FUNCTIONALITY ON PAGES WHERE IT IS HIDDEN BY DEFAULT  ========================*/


