// *************************************************************
// Common JS for CMC website
// *************************************************************


// Text resizer. Size values are used as percentage font size for BODY element

SMALL   = 76
MEDIUM  = 90      // the default (same as BODY font-size in style sheet)
LARGE   = 100

DAYS   = 365     // days to retain cookie which remembers user choice of text size
COOKIE = "CMCTextSizer"

/*************************************************************/

window.onload = loadFunctions

function loadFunctions()
{
	// run on page load

	// set custom text size if previously saved to cookie, else use deafult
	checkTextSize();

	// ie6 is set in template HTML using Conditional Comments
    if (window.ie6) 
	{
		// IE6 workaround code here
		// reserved for future use
	}
}

// vars used by checkBrowser() & checkIt()
// from www.quirksmode.org
var detect = window.navigator.userAgent.toLowerCase();
var OS, browser, version, total, thestring;
 
function checkTextSize()
{
   // retrieves any cookie-stored text size preference
   var cookie = readCookie(COOKIE);
   if (cookie != null) setTextSize(cookie) 
}
                           
function setTextSize(strSize) 
{
   // sets font size in percent for BODY and highlights user choice

   // get matching numeric font size value for strSize (defined as constant)
   intFontSize = eval(strSize.toUpperCase())
   if (intFontSize.NaN) intFontSize = SMALL 

   document.body.style.fontSize = intFontSize + "%"
   createCookie(COOKIE, strSize, DAYS);

}

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=/";
}

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 doToday()
{
// write out today's date
	var mydate = new Date()
	var year = mydate.getYear()
	var month = mydate.getMonth()
	var daym = mydate.getDate()
	if (daym < 10) daym = "0" + daym
	var aMonth = new Array("January","February","March",
	"April","May","June","July","August","September","October",
	"November","December")
	document.write(daym + ' ' + aMonth[month] + ', ' + year)
}

