// JavaScript Document

// default functions
function loadimage(imageName, imageLocation)
{
   if (document.images) document.images[imageName].src = imageLocation;
   return true;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


// gallery switch function
function gallerySwitch() {
	frm = document.skip.nav;
	url = frm.options[frm.selectedIndex].value
	window.parent.location.href= url; 
}	

// popup window function
function winBRopen(theURL, Name, popW, popH, scroll) { // V 1.0
	var winleft = (screen.width - popW) / 2;
	var winUp = (screen.height - popH) / 2;
	winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable=no'
	Win = window.open(theURL, Name, winProp)
	if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }

}

//alternating row color
function alternate(id){ 
 if(document.getElementsByTagName){  
   var table = document.getElementById(id);   
   var rows = table.getElementsByTagName("tr");   
   for(i = 0; i < rows.length; i++){           
 //manipulate rows 
     if(i % 2 == 0){ 
       rows[i].className = "content"; 
     }else{ 
       rows[i].className = "highlight"; 
     }       
   } 
 } 
}


// AARP font larger/smaller function

function setActiveStyleSheet(title){
var tags = document.getElementsByTagName("link");
var type, i, a;
for(i = 0; i < tags.length; i++){
a = tags[i];
if(title){
if(title.indexOf("fontSize") != -1){
type = "font";
}
if(title.indexOf("toggle") != -1){
type = "toggle";
}
if(type == "toggle"){
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf("toggle") != -1){
a.disabled = true;
if(a.getAttribute("title") == title){
a.disabled = false;
}
}
}

if(type == "font"){
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf("fontSize") != -1){
a.disabled = true;
if(a.getAttribute("title") == title){
a.disabled = false;
}
}
}

}
}

}

function getActiveToggle(){
var tags = document.getElementsByTagName("link");
var i, a;
for(i = 0; i < tags.length; i++){
a = tags[i];
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf("toggle") != -1 && !a.disabled){
return a.getAttribute("title");
}
}
}

function getActiveFont(){
var tags = document.getElementsByTagName("link");
var i, a, title;
for(i = 0; i < tags.length; i++){
a = tags[i];
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title").indexOf("fontSize") != -1 && !a.disabled){
return a.getAttribute("title");
}
}
}

function changeFontSize(arg){
var title, y;
var title = getActiveFont();
var x = title.split("fontSize")[1];
var direction = arg.split("fontSize")[1];
if(direction == "Up"){
if(x >= 3){
x = 2;
}
y = "fontSize" + (parseInt(x) + 1);
}

if(direction == "Down"){
if(x < 1){
x = 1;
}
else{
y = "fontSize" + (parseInt(x) - 1);
}
}
setActiveStyleSheet(y);
}

function getPreferredStyleSheet(){
var tags = document.getElementsByTagName("link");
var type, i, a;
for(i = 0; i < tags.length; i++){
a = tags[i];
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")){
return a.getAttribute("title");
}

}
}

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");
if(cookie){
var cookiesp = cookie.split('|');
var toggle = cookiesp[0];
var font = cookiesp[1];
setActiveStyleSheet(toggle);
setActiveStyleSheet(font);
}
else{
setActiveStyleSheet(getPreferredStyleSheet());
}
}

window.onunload = function(e){
var toggle = getActiveToggle();
var font = getActiveFont();
if(font == undefined){
font = null;
}
else{
font = font;
}
var titles = toggle+"|"+font;
createCookie("style", titles, 365);
}

var cookie = readCookie("style");
if(cookie){
var cookiesp = cookie.split('|');
var toggle = cookiesp[0];
var font = cookiesp[1];
setActiveStyleSheet(toggle);
setActiveStyleSheet(font);
}
else{
setActiveStyleSheet(getPreferredStyleSheet());
}

function getPrintURL(){
url = document.location;
printURL = url + '\/?print';
window.location = printURL;
}

