/************************************************************************
* File: accessibility.js
* Date of creation: 18/09/2009
* Author: Marie Manandise
* Function: contains all functions related to user's layout preferences
* 					and record of those prefenrences between pages and sessions
*************************************************************************/


// Function to change font sizes
function minFontSize(){var size = "75%"; changeFontSize(size);}
function medFontSize(){var size = "100%"; changeFontSize(size);}
function maxFontSize(){var size = "125%"; changeFontSize(size);}
	
function changeFontSize(s){
		document.body.style.fontSize=s;
		sizeFont = s;
}

//Functions to change stylesheet
function lowStyle(){setActiveStyleSheet("lowgraph");reload();}
function defaultStyle(){setActiveStyleSheet("default");reload();}
		
function reload(){
			if(navigator.appName == 'Microsoft Internet Explorer'){
						 	location.reload();
			}
}
		
		
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;
     					}
   		}
}

//Read current prefenrences
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;
}
		
//Read user's preferences from previous pages or visits
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;
}

//Record user's preferences in a cookie
function createCookie(name,value, nname, vvalue, 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+"&"+nname+"="+vvalue+expires+"; path=/";
}

//Read user's preferences from cookie						
function readCookie(name) {
  		var ca = document.cookie.split(';');
			var c="";
			var myReg = /\&/;
			for (var i = 0; i<ca.length; i++){
						 if (myReg.test(ca[i])){
						 c = ca[i];
						 }
			}
			var d = c.split('&');
			if (name == "style"){
				  var result = d[0].split('=');
					return result[1];									
			}else{ 
					var result = d[1].split('=');
					return result[1];
			}
}
		

