// JavaScript Document

window.onload = init;
//alert ('hi');

// Toggles Font-Size and Line-Height on content pages.
	function changeLabel(toggle){
		if(document.getElementById("puText")){
			// Number of <li> tags in the document, as well as an array containing references
			var LI_length = document.getElementById("rightColumn").getElementsByTagName("li").length;
			var LI_arr = document.getElementById("rightColumn").getElementsByTagName("li");
			
			// Number of <p> tags in the document, with an array of references
			var P_length = document.getElementById("rightColumn").getElementsByTagName("p").length;
			var P_arr = document.getElementById("rightColumn").getElementsByTagName("p");
			
			// Toggles the Text Size Icon and resizes text
			if(toggle == 'large'){
				document.getElementById("puText").className = "small";
				document.getElementById("puText").href = "javascript:changeLabel('small');";
				document.getElementById("puText").title = "Reduce Text";
				document.getElementById("rightColumn").style.fontSize = "130%";
				// Change all <li>s lineHeight to greater percentage
					for(k = 0; k < LI_length; k++){ 
						LI_arr[k].style.lineHeight = "150%" 
					}
				// Change all <p>s lineHeight to greater percentage
					for(j = 0; j < P_length; j++){ 
						P_arr[j].style.lineHeight = "150%" 
					}
				createCookie('textSize', 'large', '30');
				} 
			else {
				document.getElementById("puText").className = "large";
				document.getElementById("puText").href = "javascript:changeLabel('large');";
				document.getElementById("puText").title = "Enlarge Text";
				document.getElementById("rightColumn").style.fontSize = "";
				// Change all <li>s back to default lineHeight
					for(k = 0; k < LI_length; k++){ 
						LI_arr[k].style.lineHeight = ""; 
					}
				// Change all <p>s back to default lineHeight
					for(j = 0; j < P_length; j++){ 
						P_arr[j].style.lineHeight = ""
					}
					createCookie('textSize', 'small', '30');
				}
		}
	}



// Used to set a cookie with the user's font-size preference
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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	//alert('Cookie\n' + name + '\ncreated with a value ' + value);
}

// Returns the cookie value
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;
}

// Used onLoad to set document text size
function userTextSize(){
	size = readCookie('textSize'); 
	changeLabel(size);
	document.getElementById('pageUtils').style.display = 'block';
	{
		if (document.getElementById('rightColumnPrint')) {
				document.getElementById('puText').style.display = 'none';
				document.getElementById('puPrint').style.display = 'none';
			}
		}
}



var newwindow = '';

function popitup(url)
{
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,'name','height=600,width=600,status=yes,toolbar=no,menubar=yes,location=no,scrollbars=yes');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}


function init() {
	try { userTextSize(); }		catch(e) { }
	/* Tab initialization */
}


	
