// This is old SJU code. Should be updated to support jQuery.

var curStyleIndex = 0;
var styleArray = new Array();
styleArray[0] = "Text small";
styleArray[1] = "Text medium";
styleArray[2] = "Text large";
styleArray[3] = "Text extra-large";

checkStylesheet();

window.onload = function(e) {	
	checkStylesheet();
	checkBoundaries(curStyleIndex);
}

function checkStylesheet()
{
	cookieStyleIndex = getCookie("text_style");

	if (cookieStyleIndex != "null")
	{
		setStylesheet(cookieStyleIndex);
		curStyleIndex = cookieStyleIndex;
	}
	return true;
}

function doStyle(cookieName, styleIndex)
{
	if ((styleIndex >= 0) && (styleIndex < styleArray.length))
	{
		setStylesheet(styleIndex);
		createCookie(cookieName, styleIndex, 365);
		curStyleIndex = styleIndex;
	}
	checkBoundaries(styleIndex);
}

function cookieExists(cookieName)
{
	if (document.cookie != "")
	{
		var theCookieList = document.cookie.split(";");

		for (i = 0; i < theCookieList.length; i++)
		{
			var currCookieName = theCookieList[i].split("=")[0];
			var currCookieValue = theCookieList[i].split("=")[1];

			if (currCookieName.indexOf(cookieName) != -1)
			{
				if (currCookieValue == "null")
				{
					return false;
				}

				return true;
			}
		}
	}

	return false;
}

function getCookie(cookieName)
{
	if (cookieExists(cookieName))
	{
		var theCookieList = document.cookie.split(";");

		for (var i = 0; i < theCookieList.length; i++)
		{
			if (theCookieList[i].split("=")[0].indexOf(cookieName) != -1)
			{
				return theCookieList[i].split("=")[1];
			}
		}
	}

	return "null";
}

function setStylesheet(styleIndex)
{
	var currTag;

	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				currTag.disabled = true;

				if(currTag.getAttribute("title") == styleArray[styleIndex])
				{				
					currTag.disabled = false;
				}
			}
		}
	}
	else
	{
		alert("You may not switch styles with this browser.");
	}
}

function checkBoundaries(styleIndex) 
{
	var textLarge = document.getElementById("text_larger");
	var textSmall = document.getElementById("text_smaller");
	if (textLarge != null) {
		textLarge.className = "";
		textSmall.className = "";
		if (styleIndex >= styleArray.length - 1) textLarge.className = "disabled";
		else if (parseInt(styleIndex) <= 0) textSmall.className = "disabled";
	}
}