//TD 780 Functions from here is applied for text zooming
var prefsLoaded = false;
var currentFontSize;
//font size lower and upper limits
var min=10;
var max=13;

//zoom in function
function increaseFontSize(globalSize) {
   //globalSize is defined in the global settings
   var s = globalSize;
   var p = document.getElementsByTagName('p');
   //get all p tags in the module
   for(i=0;i<p.length;i++) {
      //if fontSize attribute exists get size from there
      if(p[i].style.fontSize) {
         s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         s = globalSize;
      }
      //increment until upper limit
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
   //store size in the global variable
   currentFontSize = s;
}

//zoom out function
function decreaseFontSize(globalSize) {
   //globalSize is defined in the global settings
   var s = globalSize;
   var p = document.getElementsByTagName('p');
   //get all p tags in the module
   for(i=0;i<p.length;i++) {
      //if fontSize attribute exists get size from there
      if(p[i].style.fontSize) {
         s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         s = globalSize;
      }
      //decrement until lower limit
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }
   //store size in the global variable
   currentFontSize = s;
}

//save font size in a cookie when leaving the page
window.onunload = saveSettings;

function saveSettings(){
	//create cookie only if size is changed or if cookie already existed
	if (typeof currentFontSize != "undefined"){
		//cookie expires in 365 days
		createCookie("fontSize", currentFontSize, 365);
	}
}

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=/";
};

//called on page load
function setUserOptions(){
	//do this only once
	if(!prefsLoaded){
		//get cookie value if it exists
		cookie = readCookie("fontSize");
		if (cookie != null){
			//currentFontSize = cookie ? cookie : 11;
			currentFontSize = cookie;
			//set font size
			setFontSize(currentFontSize);
		}
		prefsLoaded = true;
	}
}

function setFontSize(fontSize){
	//set font size attribute of all p tags
	//var stObj = (document.getElementsByTagName) ? document.getElementsByTagName('p') : document.all('p');
	//stObj.style.fontSize = fontSize + 'px';
	var p = document.getElementsByTagName('p');
	for(i=0;i<p.length;i++) {
		p[i].style.fontSize = fontSize+"px"
	}
};

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;
};
