function init() {
   document.body.style.height = document.documentElement.scrollHeight+'px';
}

function getAbsY(elm) {
	if (elm.y) return elm.y;
	pos = 0;

	while (elm != null) {
		pos += elm["offsetTop"];
		elm = elm.offsetParent;
	}

	return pos;
}

function submitForm(formObj) {
	// TODO: Probably have a check for netscape or IE here
	formObj.submit();
} // submitForm



// Remove leading and trailing whitespace from a string
function trimWhitespace(string) {
	var newString  = '';
	var substring  = '';
	beginningFound = false;

	// copy characters over to a new string
	// retain whitespace characters if they are between other characters
	for (var i = 0; i < string.length; i++) {

		// copy non-whitespace characters
		if (string.charAt(i) != ' ' && string.charCodeAt(i) != 9) {

			// if the temporary string contains some whitespace characters, copy them first
			if (substring != '') {
				newString += substring;
				substring = '';
			}
			newString += string.charAt(i);
			if (beginningFound == false) beginningFound = true;
		}

		// hold whitespace characters in a temporary string if they follow a non-whitespace character
		else if (beginningFound == true) substring += string.charAt(i);
	}
	return newString;
}

function gotoLink(sel)
{
	window.location = sel.options[sel.selectedIndex].value;
}

/* for navigating from a dropdown box */
function goToPage(theOptionValue){
   location = theOptionValue.options[theOptionValue.selectedIndex].value;
   }

// Clears the search text field when it is given the focus (if user has not entered anything)
var searchText;

function clearSearchText(formfield, text) {
	searchText = text;
	if (formfield.value == searchText) formfield.value = '';
}

// Refills the search text field on blur if it is empty
function fillSearchText(formfield) {
	if (formfield.value == '') formfield.value = searchText;
}
function isDefined(property) {
  return (typeof property != 'undefined');
}

// call init when document finishes loading
if (isDefined(window.addEventListener)) {
   window.addEventListener('load', init, false);
}
else if (isDefined(window.attachEvent)) {
   window.attachEvent('onload', init);
}

// get width of browser
function getInnerWidth(win) {
  var winWidth;
  if (navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Netscape6') == -1) {
    winWidth = win.document.body.clientWidth;
  }
  else if (document.compatMode == "CSS1Compat") {
    winWidth = win.document.documentElement.clientWidth;
  }
  else if (navigator.appName == 'Netscape') {
    winWidth = win.innerWidth;
  }
  else {
    winWidth = win.document.body.clientWidth;
  }
  return winWidth;
}

// write out style for main container
function positionMainContainer() {
   var winWidth = getInnerWidth(window);
   var left = parseInt((winWidth > 807) ? (winWidth - 807) / 2 : 0);

   doc = '<style>#mainContainer { ';
   doc += 'left: ' + left + 'px; ';
   doc += '}';
   document.write(doc + '</style>');
}

function repositionMainContainer() {
   if (document.getElementById) {
      var container = document.getElementById('mainContainer');
      var winWidth = getInnerWidth(window);

      if (document.getElementById('mainContainer'))
      {
      container.style.left = ((winWidth > 807) ? (winWidth - 807) / 2 : 0) + 'px';
	  }
   }
}
function bannerFlash() {
	if (!HasFlash) {
		var divBanner = document.getElementById('bannerID');
		var divBannerMain = document.getElementById('bannerMainID');
		
		$(divBannerMain).addClassName('displayNone');
		$(divBanner).addClassName('flashBanner');
		
		divBanner.innerHTML = '<div>We are sorry but Flash plug-in is needed to view some content on this site. If  \
							   you believe you have the flash player installed, first remove it using the Adobe \
							   Flash uninstall program and then reinstall the Flash Player. Please visit \
							   Adobe\'s web site for installation troubleshooting <br />Please click the icon to \
							   download the he latest version of Flash... <br /> \
							   <a target="_blank" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"> \
							   <img src="/img/AdobeLogo.GIF" width="88px" height="31px" /> </a> </div>';
		}
}

function handleValidationError(elementId, messages)
{
   $(elementId).innerHTML = "";
   var errorMsg = "";
   if (messages.length > 0) {
       errorMsg = "<ul>";
       for (var i = 0; i < messages.length; i++)
       {
         errorMsg += "<li>"+ messages[i] + "</li>";
       }
       errorMsg += "</ul>";
   }
   $(elementId).innerHTML = errorMsg;
   $(elementId).show();
}

function handleSystemExceptionError(elementId, message)
{
   $(elementId).innerHTML = "<ul><li>"+message+"</li><ul>";
   $(elementId).show();
}

function handleDisplayText(elementId, message)
{
   if (message != null) {
      $(elementId).innerHTML = message;
      $(elementId).show();
   }
}

function clearControl(elementId)
{
  $(elementId).innerHTML = '';
}

onresize = repositionMainContainer;
