﻿//******************************************************************************
//* This code is to change the size of the fonts.  This is part of making a page
//* section 508 compliant.
//******************************************************************************
//* Joseph Guido
//* Compuware Corporation - copyright 2007
//******************************************************************************

var min=1;
var max=1.3;
var autoChangeCount = 0;
var setAutoChangeCount = true;

function AutoChangeFontSize()
{
    setAutoChangeCount = false;
    if(autoChangeCount > 0)
    {
        //increase font size
        for(var i = 0; i < autoChangeCount; i++)
        {
            increaseFontSize();
        }
    }
    else
    {
        //decrease font size
        for(var i = autoChangeCount; i > 0; i--)
        {
            decreaseFontSize();
        }        
    }
    setAutoChangeCount = true;
}

function SetFontSize(size)
{
    var request = new Sys.Net.WebRequest();
    request.set_url("AjaxSupport.asmx/SetFontSize");  
    var req = "fontSize=" + size;
    request.set_body(req); 
    request.invoke(); 
}

function increaseFontSize() 
{
   var p = document.getElementsByTagName('body');
   for(var i = 0; i < p.length; i++) 
   {
      if(p[i].style.fontSize) 
      {} 
      else 
      {
         var s = 1;
      }

      if(p[i].style.fontSize) 
      {
         var s = parseFloat(p[i].style.fontSize.replace("em",""));
      } 
      
      if(s < max) 
      {
         s += .1;
      }
      
      p[i].style.fontSize = s+"em"
   }
   if(setAutoChangeCount && autoChangeCount < 3)
   {
        SetFontSize(++autoChangeCount);
   }
}

function decreaseFontSize() 
{
   var p = document.getElementsByTagName('body');
   for(var i = 0; i < p.length; i++) 
   {
      if(p[i].style.fontSize) 
      {} 
      else 
      {
         var s = 1;
      }

      if(p[i].style.fontSize) 
      {
         var s = parseFloat(p[i].style.fontSize.replace("em",""));
      } 
      
      if(s > min) 
      {
         s -= .1;
      }
      
      p[i].style.fontSize = s+"em"
   }   
   if(setAutoChangeCount && autoChangeCount > 0)
   {
        SetFontSize(--autoChangeCount);
   }
}
