// thanks to http://www.white-hat-web-design.co.uk/articles/js-fontsize.php

window.onload = function() {
  var p = document.getElementById('content');
  var s = readCookie('myTextSize');
  if (s) {
    p.style.fontSize = s+"%";
    createCookie('myTextSize',s,0);
  }
}

var min=80;
var max=200;
function increaseFontSize() {
  var p = document.getElementById('content');
  var s = readCookie('myTextSize');
  if (s) {
    var s = parseInt(s.replace("%",""));
  }
  if (!s) {
    var s = 100;
  }
  if(s!=max) {
    s += 10;
  }
  p.style.fontSize = s+"%";
  createCookie('myTextSize',s,0);
}

function decreaseFontSize() {
  var p = document.getElementById('content');
  var s = readCookie('myTextSize');
  var s = parseInt(s.replace("%",""));
  if(!s) {
    var s = 100;
  }
  if(s!=min) {
    s -= 10;
  }
  p.style.fontSize = s+"%";
  createCookie('myTextSize',s,0);
}

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 var 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 eraseCookie(name) {
  createCookie(name,"",-1);
}
