

function setActiveStyleSheet(title,theParent) {
  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;
    }
  }
 /* <changeImage> */
 if(document.getElementById('increase')){
    var element=document.getElementById('increase').getElementsByTagName('LI');
    var temp="";
	for(i=0;i<element.length;i++){ 	
	    var el = element[i].childNodes[0].getAttribute('Id');	        	        
	        if(el.substr(el.length-2,el.length-1)=='On'){	 	    	                   
	            element[i].childNodes[0].setAttribute('id',el.substr(0,el.length-2));	            
	            temp=element[i].childNodes[0];	            
	        }	        
	    }	
	  // if the parent is null then  	  	  
	  if(typeof(theParent)!="undefined"){
	    theParent.setAttribute('id',theParent.getAttribute('id')+'On');  
	  }else{ // is the first time, get the initial selection
	    temp.setAttribute('id',temp.getAttribute('id')+'On');  	    
	    }	    	
	}
 /* </changeImage> */  
}

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 getIncrease(title){

  if (title == "medfont")         
    return document.getElementById('increaseMedium'); 
  else if (title == "largefont")  
    return document.getElementById('increaseLarge');  
  else                            
    return document.getElementById('increaseNormalOn'); 
    
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();  
  var increase = getIncrease(title);  
  setActiveStyleSheet(title,increase);

}

window.onunload = function(e) {
  var title = getActiveStyleSheet();  
  createCookie("style", title, 365);
}
