/*
	Utility functions to be used site-wide
*/

function $(id){ return document.getElementById(id); }

function trim(s) 
{
	while (s.substring(0,1) == ' ') 
		s = s.substring(1,s.length);

	while (s.substring(s.length-1,s.length) == ' ') 
		s = s.substring(0,s.length-1);

	return s;
}

function isNumeric(sText)
{
	var ValidChars = "0123456789."; //Take the "." out if number is an int
	var Char;
	for (i = 0; i < sText.length; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
			isNumber = false;
		else
			isNumber = true;
	}
	return isNumber;
}

function mailTo(toEmail, ccEmail, subject, body)
{
	var ampand = '?';
	var urlstr = 'mailto:' + escape(toEmail);
	
	if (ccEmail) {
		urlstr = urlstr + ampand + 'cc=' + escape(ccEmail);
		ampand = '&';	
	}
	
	if (subject) {
		urlstr = urlstr + ampand + 'subject=' + escape(subject);
		ampand = '&';		
	}
	
	if (body) {
		urlstr = urlstr + ampand + 'body=' + escape(body);
		ampand = '&';
	}

	window.location = urlstr;
}

// It's rather common to want to execute a javascript function after the page has loaded.
// However, with a dynamic site it becomes troublesome to use the traditional window.onload technique,
// because various pieces of code will break other pieces of code, since only one of the calls will succeed.
// 
// To get around this problem, use the AddOnload function instead.
// Old Technique: window.onload = myFunction;
// New Technique: AddOnload(myFunction);
//
// Note that for print pages you'll still have to include this file, or use the window.onload technique. 

var OnloadArray = new Array();
function AddOnload(f)
{
	OnloadArray[OnloadArray.length] = f;
}
function Onload()
{
	for(var i = 0; i < OnloadArray.length; i++)
	{
		OnloadArray[i]();
	}
}

