/***********************************************************
/js/textsize.js
***********************************************************/


var startingTextSize="3";  //-- DECLARE GLOBAL VARIABLE AND SET TO DEFAULT TEXT SIZE

initialize();              //-- CALL FUNCTION TO EXECUTE IMMEDIATELY

function initialize()
{
  if (document.cookie != "")                          //-- IF A COOKIE EXISTS...
  {
    startingTextSize = document.cookie.split("=")[1]; //-- ...GET USER-PREFERRED TEXT SIZE AND...
  }
  setCSS(startingTextSize);                           //-- ...ACTIVATE CORRESPONDING STYLE SHEET.
}

//---------------------------------------------
// Activate the style sheet corresponding to the selected text size.
// Note: Because the switch statement will not automatically cast a variable to
// the designated data-type, the passed variable must first be converted to data-type
// string. This is done by creating a String object then converting the String object
// to data-type string, using the toString() method.
//---------------------------------------------
function setCSS(fontSize)
{
  fontObject = new String(fontSize);

  font=fontObject.toString();

  document.getElementById("textsize1").disabled=true;
  document.getElementById("textsize2").disabled=true;
  document.getElementById("textsize3").disabled=true;
  document.getElementById("textsize4").disabled=true;
  document.getElementById("textsize5").disabled=true;
  document.getElementById("textsize6").disabled=true;

  switch (font)
  {
    case "1":
      document.getElementById("textsize1").disabled=false;
      break;
    case "2":
      document.getElementById("textsize2").disabled=false;
      break;
    case "3":
      document.getElementById("textsize3").disabled=false;
      break;
    case "4":
      document.getElementById("textsize4").disabled=false;
      break;
    case "5":
      document.getElementById("textsize5").disabled=false;
      break;
    case "6":
      document.getElementById("textsize6").disabled=false;
      break;
    default:
      document.getElementById("textsize3").disabled=false;
      break;
  }
}

//---------------------------------------------
// Create two cookies; one identifies the text size and the other
// sets the expiration date of the cookie to one month after the
// date the cookie is set. Why one month? Because it is an easy
// future expiration date to code.
//---------------------------------------------
function setCookie()
{
  textSize = document.formTextSize.textSize.value;

  todayDate = new Date();

  dd=todayDate.getDate();
  mm=todayDate.getMonth();
  yyyy=todayDate.getFullYear();

  if (mm==11)
  {
    mm=01;
    yyyy++;
  }
  else
    mm++;

  expireDate=new Date(yyyy, mm, dd);

  document.cookie="textSize=" + textSize + "; expires=" + expireDate.toGMTString();
}

//---------------------------------------------
// This function is called when the user clicks
// the plus sign to make the text larger.
//---------------------------------------------
function enlarge()
{
  current = document.formTextSize.textSize.value; //-- Get current text size.

  if (! (current=="1"||current=="2"||current=="3"||current=="4"||current=="5"||current=="6") )
  {
    document.formTextSize.textSize.value="3";

    current = document.formTextSize.textSize.value;
  }

  if ( current != "6" )
  {

    newSize = Number(current) + 1;

    document.formTextSize.textSize.value = newSize; //-- Save new text size in hidden field

    setCSS(newSize);
  }

  setCookie();                     //-- Save new text size as cookie
}

//---------------------------------------------
// This function is called when the user clicks
// the minus sign to make the text smaller.
//---------------------------------------------
function reduce()
{
  current=document.formTextSize.textSize.value;

  if (! (current=="1"||current=="2"||current=="3"||current=="4"||current=="5"||current=="6") )
  {
    document.formTextSize.textSize.value="3";

    current = document.formTextSize.textSize.value;
  }

  if ( current != "1" )
  {
    newSize = Number(current) - 1;

    document.formTextSize.textSize.value = newSize;

    setCSS(newSize);
  }

  setCookie();
}

//---------------------------------------------
// This function is called when the page is first displayed.
// Set the value of the hidden field to the font size.
//---------------------------------------------

function initializeTextSize()
{
  document.formTextSize.textSize.value = startingTextSize;
}
