﻿/* These functions are all involved in setting the font size used by pages
in the site. They respond to clicks on the decrease, reset and increase font size 
links top left of each page.
*/
var min=8;
var max=18;

window.onload = function(e) 
{
	var currentSize = 1;
	var x = readCookie('bankSize');
	if (x != null) 
	{
		setFontSize(x);
	}
} 

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) 
{
	//***********RUN BY****************
	//var x = readCookie('ppkcookie1')
	//if (x) {
	//	[do something with x]
	//}
	//*********************************
	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) 
{
//	this is run by eg "eraseCookie('bankSize')";
	createCookie(name,"",-1);
}

document.getElementsByClassName = function(cl) 
{
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) 
    {
        var classes = elem[i].className;
        if (myclass.test(classes)) retnode.push(elem[i]);
    }
return retnode;
}; 

function increaseFontSize() 
{
   /*
   var x = readCookie('bankSize');
   var s = parseInt(x);
   if(s<=max) 
   {
      s += 2;
   }
   SetFontSize(s);
   //save new size in cookie
   createCookie('bankSize',s,1);
   alert(s);
   */
   var p = document.getElementsByClassName("SiteText");
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 14;
      }
      if(s<=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
   var p = document.getElementsByClassName("SectionHeader");
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 13;
      }
      if(s<=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
   var p = document.getElementsByClassName("readonlyTextbox");
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 13;
      }
      if(s<=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
   //save new size in cookie
   createCookie('bankSize',s,1);
}
function decreaseFontSize() 
{
   //var p = document.getElementsByTagName('div');
   var p = document.getElementsByClassName("SiteText");
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 14;
      }
      if(s>=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
   var p = document.getElementsByClassName("SectionHeader");
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 13;
      }
      if(s>=min) 
      {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
   var p = document.getElementsByClassName("readonlyTextbox");
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 13;
      }
      if(s>=min) 
      {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
   //save new size in cookie
   createCookie('bankSize',s,1);
}
function setFontSize(fSize) 
{
   //var p = document.getElementsByTagName('div');
   var sSize = parseInt(fSize);
   var hSize = parseInt(fSize) + 1;
   var p = document.getElementsByClassName("SiteText");
   for(i=0;i<p.length;i++) 
   {
       p[i].style.fontSize = sSize+"px"
   }
   var p = document.getElementsByClassName("SectionHeader");
   for(i=0;i<p.length;i++) 
   {
       p[i].style.fontSize = hSize+"px"   
   }
   var p = document.getElementsByClassName("readonlyTextbox");
   for(i=0;i<p.length;i++) 
   {
       p[i].style.fontSize = sSize+"px"   
   }
}
function resetFontSize() 
{
   //var p = document.getElementsByTagName('div');
   var p = document.getElementsByClassName("SiteText");
   for(i=0;i<p.length;i++) 
   {
       p[i].style.fontSize = "14px"
   }
   var p = document.getElementsByClassName("SectionHeader");
   for(i=0;i<p.length;i++) 
   {
       p[i].style.fontSize = "13px"   
   }
   var p = document.getElementsByClassName("readonlyTextbox");
   for(i=0;i<p.length;i++) 
   {
       p[i].style.fontSize = "14px"   
   }
   //save new size in cookie
   createCookie('bankSize',14,1);
}