function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function printWindow() {
	bV = parseInt(navigator.appVersion);
	if (bV >= 4) window.print();
}


var defaultFontSize13 = 13;
var defaultFontSize15 = 15;
var defaultFontSize11 = 11;

window.onload = setUserOptions;

function ChangeFontSize(amt) 
{

	var minSize = 8;
	var maxSize = 18;
	var minSize3 = 6;
	var maxSize3= 16;
	var minSize4 = 12;
	var maxSize4= 22;
	
	var currentSize = getClassProperty("content","fontSize");
	var currentSize3 = getClassProperty("contentsmall", "fontSize");
	var currentSize4 = getClassProperty("subheader", "fontSize");
	
	currentSize = currentSize.replace("px","");
	currentSize3 = currentSize3.replace("px","");
	currentSize4 = currentSize4.replace("px","");
	
	var newSize = parseInt(currentSize) + amt;
	var newSize3 = parseInt(currentSize3) + amt;
	var newSize4 = parseInt(currentSize4) + amt;
	
	if (newSize >= minSize && newSize <= maxSize)
	{
		changeClassProperty("content","fontSize",newSize + "px");
		changeClassProperty("contentlink","fontSize",newSize + "px");

		setCookie("fontSize",newSize,180,"/");
	}
	
	if (newSize3 >= minSize3 && newSize3 <= maxSize3)
	{
		changeClassProperty("contentsmall","fontSize",newSize3 + "px");
		
		setCookie("fontSize3",newSize3,180,"/");
	}
	
	if (newSize4 >= minSize4 && newSize4 <= maxSize4)
	{
		changeClassProperty("subheader","fontSize",newSize4 + "px");
		setCookie("fontSize4",newSize4,180,"/");
	}	
}

var defaultFontSize = 1;

function ChangeFontSizeEM(amt) 
{
	var minSize = 0.6;
	var maxSize = 1.4;
	
	var currentSize = getClassProperty("default_font","fontSize");
	currentSize = currentSize.replace("em","");
	
	var newSize = parseFloat(currentSize) + amt;
	
	if (newSize >= minSize && newSize <= maxSize)
	{
		changeClassProperty("default_font","fontSize",newSize + "em");

		setCookie("fontSizeEM",newSize,180,"/");
	}
}
  
// get the value of a property of a CSS Rule
function getClassProperty(sClassName,sProperty) 
{
	sClassName="."+sClassName;
	var sheets = document.styleSheets;
	var rules;
	var styleObj;
	for (i=0;i< sheets.length; i++) 
	{
		rules=sheets[i].cssRules || sheets[i].rules;
		for (var j=0; j<rules.length; j++) 
		{
			if (rules[j].selectorText && rules[j].selectorText==sClassName) 
			{
				styleObj=rules[j].style;

				return styleObj[sProperty];
			}
		}
	}
}

// set the value of a property of a CSS Rule
function changeClassProperty(sClassName,sProperty,sValue) 
{
	sClassName="."+sClassName;
	var sheets = document.styleSheets;
	var rules;
	var styleObj;
	for (i=0;i< sheets.length; i++)
	{
		rules=sheets[i].cssRules || sheets[i].rules;
		for (var j=0; j<rules.length; j++) 
		{
			if (rules[j].selectorText && rules[j].selectorText==sClassName) 
			{
				styleObj=rules[j].style;
				styleObj[sProperty]=sValue;
				break;
			}
		}
	}
}

function setCookie(name,value,days,path,domain,secure) 
{
  var expires, date;
  if (typeof days == "number") 
  {
    date = new Date();
    date.setTime( date.getTime() + (days*24*60*60*1000) );
		expires = date.toGMTString();
  }
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name) 
{
  var nameq = name + "=";
  var c_ar = document.cookie.split(';');
  for (var i=0; i<c_ar.length; i++) 
  {
    var c = c_ar[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
  }
  return null;
}

function setUserOptions()
{
	cookie = getCookie("fontSize");
	cookie3 = getCookie("fontSize3");
	cookie4 = getCookie("fontSize4");
	cookieEM = getCookie("fontSizeEM");
	
	currentFontSize = cookie ? cookie : defaultFontSize13;
	currentFontSize3 = cookie3 ? cookie3 : defaultFontSize11;
	currentFontSize4 = cookie4 ? cookie4 : defaultFontSize15;
	currentFontSizeEM = cookieEM ? cookieEM : defaultFontSize;
	
	changeClassProperty("content","fontSize",currentFontSize + "px");
	changeClassProperty("contentlink","fontSize",currentFontSize + "px");

	changeClassProperty("contentsmall","fontSize",currentFontSize3 + "px");
	
	changeClassProperty("subheader","fontSize",currentFontSize4 + "px");	
	
	/* For the EM style */
	changeClassProperty("default_font","fontSize",currentFontSizeEM + "em");	
}

function preloadImages() 
	{
		var Pic = new Array();
		Pic[0] = "images/header/services_2.gif"
		Pic[1] = "images/header/facilities_2.gif"
		Pic[2] = "images/header/news_2.gif"
		Pic[3] = "images/header/environment_2.gif"

		var p = Pic.length;
		var preLoad = new Array();
		for (i = 0; i < p; i++) 
		{
			preLoad[i] = new Image();
			preLoad[i].src = Pic[i];
		}
		return preLoad;
	}
	
function MM_openBrWindow(theURL,winName,features) 
   { 
     window.open(theURL,winName,features); 
   }
   
function SetCookie(cookieName,cookieValue,nDays) 
{
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) { nDays=1; }
    
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}

function checkCookie(cookieName)
{
    theCookie=getCookie(cookieName);
    if (theCookie!=null && theCookie!="")
    {
        return theCookie;
    }
    else
    {
        return "";
    }
}

function toggleCookie(cookieName)
{
    var cookieValue = checkCookie(cookieName);
    
    //if the cookieValue is empty
    if(cookieValue == "")
    {
        //set the cookie to be expanded
        SetCookie(cookieName, "expanded", "1");
    }
    else
    {
        //check if the value is expanded
        if(cookieValue == "expanded")
        {
            //set the cookie to be collapsed
            SetCookie(cookieName, "collapsed", "1");
        }
        else
        {
            //set the cookie to be expanded
            SetCookie(cookieName, "expanded", "1");
        }
    }
}
   