<!-- Begin to hide script contents from old browsers.

// RemoveTrailingSpaces: Right trim the string and return the trimmed value
function RemoveTrailingSpaces(strVal) {
  var nPos = 0;

  if (IsEmpty(strVal))
    return strVal;

  for (nPos = strVal.length-1; nPos >= 0; nPos--) {
    if (whitespace.indexOf(strVal.charAt(nPos)) == -1)
      break;
  }

  return (nPos == strVal.length-1 ? strVal.substring(0) : strVal.substring(0, nPos+1));
}

// RemoveLeadingSpaces: Left trim the string and return the trimmed value
function RemoveLeadingSpaces(strVal) {
  var nPos = 0;

  if (IsEmpty(strVal))
    return strVal;

  for (nPos = 0; nPos < strVal.length; nPos++) {
    if (whitespace.indexOf(strVal.charAt(nPos)) == -1)
      break;
  }

  return strVal.substring(nPos);
}

// RemoveSpaces: Remove leading and trailing spaces
function RemoveSpaces(strVal) {
  return (IsEmpty(strVal) ? strVal:RemoveLeadingSpaces(RemoveTrailingSpaces(strVal)));
}

// IsEmpty: Check whether string strVal is empty
function IsEmpty(strVal) {
  return ((strVal == null) || (strVal.length == 0));
}

// whitespace characters: ' ', '\t', '\r', '\n'
var whitespace = " \t\n\r";

// IsWhitespace: Check if string strVal has only the whitespace characters
function IsWhitespace(strVal) {
	var nPos = 0;

	if (IsEmpty(strVal))
		return false;

	for (nPos = 0; nPos < strVal.length; nPos++)
		if (whitespace.indexOf(strVal.charAt(nPos)) == -1)
			return false;

	return true;
}

// Replace: replaces one occurrence of strVal with strWith in strSrc
function Replace(strSrc, strVal, strWith) {
	var nPos = 0, strLeft="", strRight="";

	// check if empty (or) no string is found to replace
	if (IsEmpty(strSrc) || (strSrc.indexOf(strVal) < 0))
		return strSrc;

	nPos = strSrc.indexOf(strVal);
	strLeft = strSrc.substring(0, nPos);
	nPos += strVal.length;
	strRight = strSrc.substring(nPos);

	return (strLeft + strWith + strRight);
}

// ReplaceAll : replace all occurrences of strVal with strWith in strSrc
function ReplaceAll(strSrc, strVal, strWith) {
	var strBuffer=strSrc;

	while (strBuffer.indexOf(strVal) >= 0)
		strBuffer = Replace(strBuffer, strVal, strWith);

	return (strBuffer);
}

// Occurs: return no of occurrences of strVal within strSrc
function Occurs(strVal, strSrc) {
	var nCnt = 0, strBuffer=strSrc;

	while (strBuffer.indexOf(strVal) >= 0) {
		strBuffer = Replace(strBuffer, strVal, "");
		nCnt++;
	}

	return (nCnt);
}

///////////////////////////////////////////////////////////////////////////////
//
// NOTE: 
//  -- alway RemoveSpaces field value before calling any of these functions
//  -- if field is empty, the function call will return true
//
///////////////////////////////////////////////////////////////////////////////

// IsDigit: check if val has digits (0-9)
function IsDigit(val) {
	var strBuffer = new String(val);
	var nPos = 0;

	if (IsEmpty(strBuffer))
		return false;

	for (nPos = 0; nPos < strBuffer.length; nPos++)
		if (strBuffer.charAt(nPos) < '0' || strBuffer.charAt(nPos) > '9')
			return false;

	return true;
}

// IsAlpha: check if val has alphabets only (a-z, A-Z)
function IsAlpha(val) {
	var strBuffer = new String(val);
	var nPos = 0;

	if (IsEmpty(strBuffer))
		return false;

	for (nPos = 0; nPos < strBuffer.length; nPos++)
		if (!((strBuffer.charAt(nPos) >= 'a' && strBuffer.charAt(nPos) <= 'z') ||
			(strBuffer.charAt(nPos) >= 'A' && strBuffer.charAt(nPos) <= 'Z')))
			return false;

	return true;
}

// IsInteger: check if nVal is integer type
function IsInteger(nVal) {
	var strBuffer = new String(nVal);
	var nPos = 0, nStart = 0;

	if (IsEmpty(strBuffer))
		return true;
	if (IsWhitespace(strBuffer))
		return false;

	// check if -ve or +ve sign occurs in the beginning
	if ((strBuffer.charAt(0) == '-') || (strBuffer.charAt(0) == '+'))
		nStart = 1;
	else
		nStart = 0;

	for (nPos = nStart; nPos < strBuffer.length; nPos++)
		if (strBuffer.charAt(nPos) < '0' || strBuffer.charAt(nPos) > '9')
			return false;

	return true;	
}

// IsFloat: check if fVal is floating-point type
//	LIMITATION: no scientific notation (for eg: xxxx.xxE+xx)
function IsFloat(fVal) {
	var strBuffer = new String(fVal);
	var nPos = 0, nStart = 0;

	if (IsEmpty(strBuffer))
		return true;
	if (IsWhitespace(strBuffer))
		return false;

	// check if -ve or +ve sign occurs in the beginning
	if ((strBuffer.charAt(0) == '-') || (strBuffer.charAt(0) == '+'))
		nStart = 1;
	else
		nStart = 0;

	for (nPos = nStart; nPos < strBuffer.length; nPos++)
		if ((strBuffer.charAt(nPos) < '0' || strBuffer.charAt(nPos) > '9') && 
				(strBuffer.charAt(nPos) != '.'))
			return false;

	return true;
}


///////////////////////////////////////////////////////////////////////////////
//
// Commify
//
// The following function is used to add commas to a number
//
// Input:  Number to commify
// 
// Return: Commified number
//
///////////////////////////////////////////////////////////////////////////////

function Commify(tNum) {

//var Num = document.form.input.value;

var Num = tNum.toString();
var newNum = "";
var newNum2 = "";
var count = 0;

//check for decimal number
	if (Num.indexOf('.') != -1){ //number ends with a decimal point
		if (Num.indexOf('.') == Num.length-1){
			Num += "00";
		}
		if (Num.indexOf('.') == Num.length-2){ //number ends with a single digit
			Num += "0";
		}

		var a = Num.split("."); 
		Num = a[0]; //the part we will commify
		var end = a[1] //the decimal place we will ignore and add back later
	}
	else {var end = "00";} 

	//this loop actually adds the commas 
	for (var k = Num.length-1; k >= 0; k--){
		var oneChar = Num.charAt(k);
		if (count == 3){
			newNum += ",";
			newNum += oneChar;
			count = 1;
			continue;
		}
		else {
			newNum += oneChar;
			count ++;
		}
	} //but now the string is reversed!

//re-reverse the string
	for (var k = newNum.length-1; k >= 0; k--){
		var oneChar = newNum.charAt(k);
		newNum2 += oneChar;
	}

// add dollar sign and decimal ending from above
//	newNum2 = "$" + newNum2 + "." + end;
	newNum2 = newNum2 + "." + end;
//	document.form.newValue.value = newNum2;
return newNum2;
}

///////////////////////////////////////////////////////////////////////////////
//
// RoundNumber
//
// The following function is used to round real numbers to a
// a given precision.
//
// Input:  Number to round
//         Precision
//
// Return: Rounded number
//
///////////////////////////////////////////////////////////////////////////////

function RoundNumber(num, precision) {

  var roundedNum, sign, oldNum, decimalValue;

  roundedNum = parseFloat(num);
  if ( isNaN(roundedNum) )
    return num;

  // Change neg numbers to positive for rounding and then change them back
  sign = roundedNum < 0.0? -1.0 : 1.0;
  roundedNum *= sign;

  // Move decimal point to the right according to the precision
  roundedNum *= Math.pow( 10, precision );
  oldNum = roundedNum;
  roundedNum = Math.floor( roundedNum );   
  decimalValue = oldNum - roundedNum;

  if ( decimalValue >= 0.499999999 )
    roundedNum += 1.0;

  // Move decimal point back to the correct position
  roundedNum /= Math.pow( 10, precision );

  // Put the correct sign back on the number
  if ( roundedNum != 0.0 )
    roundedNum *= sign;

  return roundedNum;

}


///////////////////////////////////////////////////////////////////////////////
//
// FormatNumber
//
// The following function is used to format a number to a specified precision.
//
// Input:  Number
//         Precision
//
// Return: Rounded number as a string
//
///////////////////////////////////////////////////////////////////////////////

function FormatNumber(num, precision) {

  var rNum = RoundNumber( num, precision );
  var strNum = new String(rNum);
  var i = 0, decPos = 0;
  var decimalFound = false;
  var numPlaces = 0;

  for (i = 0; i < strNum.length; i++) {
    if (strNum.charAt(i) == '.') {
      decPos = i;
      decimalFound = true;
    }
  }

  if ( decimalFound ) {
    numPlaces = strNum.length - decPos - 1;
  }
  else {
    strNum += '.';
  }

  for (i = numPlaces; i < precision; i++) {
    strNum += '0';
  }

  return strNum;

}

///////////////////////////////////////////////////////////////////////////////
//
// ConvertToFloat
//
// The following function is used to convert a string to a float
//
// Input:  Number
//
// Return: Converted float
//
///////////////////////////////////////////////////////////////////////////////

function ConvertToFloat( str ) {
	var strBuffer = new String(str);
	var nPos = 0;
  var newStr = "";
  var digitFound = false;
  var negNum = false;

  RemoveSpaces( strBuffer );

  if ( IsEmpty( strBuffer ) ) {
    return( 0.0 );
  }

  for (nPos = 0; nPos < strBuffer.length; nPos++) {
    var currChar = strBuffer.charAt(nPos);
    if (currChar != '(' && currChar != '$' &&
        currChar != ','&& currChar != ')') {
      if ( currChar >= '0' && currChar <= '9' ) {
        digitFound = true;
      }
      newStr += currChar;
    } else if ( currChar == '(' ) {
      negNum = true;
    }
  }

  if ( digitFound ) {
    return( negNum? parseFloat( newStr ) * -1.0 : parseFloat( newStr ) );
  } else {
    return( 0.0 );
  }

}

///////////////////////////////////////////////////////////////////////////////
//
// DisableField
//
// The following function disables the given element
//
///////////////////////////////////////////////////////////////////////////////

function DisableField ( field ) {
	field.disabled = !(field.disabled);
}


///////////////////////////////////////////////////////////////////////////////
//
// CancelEvent
//
// The following function cancels a window event
//
///////////////////////////////////////////////////////////////////////////////

function CancelEvent( bubble ) {
  window.event.returnValue = false;
  if ( bubble ) window.event.cancelBubble = true;
}

///////////////////////////////////////////////////////////////////////////////
//
// GetContainerWith
//
// Starting with the given node, find the nearest containing element
// with the specified tag name and style class.
//
///////////////////////////////////////////////////////////////////////////////

function GetContainerWith(node, tagName, className) {

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        HasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

///////////////////////////////////////////////////////////////////////////////
//
// HasClassName
//
// Return true if the given element currently has the given class name.
//
///////////////////////////////////////////////////////////////////////////////

function HasClassName(el, name) {

  var i, list;

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

///////////////////////////////////////////////////////////////////////////////
//
// RemoveClassName
//
// Remove the given class name from the element's className property.
//
///////////////////////////////////////////////////////////////////////////////

function RemoveClassName(el, name) {
  var i, curList, newList;

  if (el.className == null)
    return;

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

///////////////////////////////////////////////////////////////////////////////
//
// GetPageOffsetLeft
//
// Return the x coordinate of an element relative to the page.
//
///////////////////////////////////////////////////////////////////////////////

function GetPageOffsetLeft(el) {
  var x;

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += GetPageOffsetLeft(el.offsetParent);

  return x;
}

///////////////////////////////////////////////////////////////////////////////
//
// GetPageOffsetTop
//
// Return the x coordinate of an element relative to the page.
//
///////////////////////////////////////////////////////////////////////////////

function GetPageOffsetTop(el) {
  var y;

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += GetPageOffsetTop(el.offsetParent);

  return y;
}

///////////////////////////////////////////////////////////////////////////////
//
// LogDebugMsg
//
// Write the given message to the debug "DIV" element
//
// Note:  "debugMsg" needs to be defined in the document
//
///////////////////////////////////////////////////////////////////////////////

function LogDebugMsg(str) {
  var debugEl = document.all.debugMsg;
  var debugMsg = debugEl.innerHTML;

  debugMsg += str + "<BR>";
  debugEl.innerHTML = debugMsg;
}

///////////////////////////////////////////////////////////////////////////////
//
// HandlePrintEvent
//
// Handle the event when in print mode.  Don't allow the user to
// click on any thing except the print and close button.
//
///////////////////////////////////////////////////////////////////////////////

function HandlePrintEvent() {
  var printButton = document.all.printButton;
  var closeButton = document.all.closeButton;

  if ( printButton.contains(window.event.srcElement) ||
       closeButton.contains(window.event.srcElement) ) {
    return true;
  } else {
    CancelEvent( true );
    return false;
  }

  return true;
}

///////////////////////////////////////////////////////////////////////////////
//
// SetPrintEvents
//
// Reset all element events when in print mode.
//
///////////////////////////////////////////////////////////////////////////////

function SetPrintEvents() {
  //document.onmousedown = HandlePrintEvent;
  //document.onclick = HandlePrintEvent;

  // Reset all <DIV> events
  var allDiv = document.all.tags("DIV");
  for ( var div = 0; div < allDiv.length; div++ ) {
    var id = new String(allDiv[div].id);
    var prefix = id.substring(0,1);
    if ( prefix != '_' ) {
      allDiv[div].onmousedown = HandlePrintEvent;
      allDiv[div].onclick = HandlePrintEvent;
      allDiv[div].style.cursor = 'default';
    }
  }

  // Reset all <TD> events
  var allTd = document.all.tags("TD");
  for ( var td = 0; td < allTd.length; td++ ) {
    var id = new String(allTd[td].id);
    var prefix = id.substring(0,1);
    if ( prefix != '_' ) {
      allTd[td].onmousedown = HandlePrintEvent;
      allTd[td].onclick = HandlePrintEvent;
      allTd[td].style.cursor = 'default';
    }
  }

  // Reset all <SPAN> events
  var allSpan = document.all.tags("SPAN");
  for ( var span = 0; span < allSpan.length; span++ ) {
    var id = new String(allSpan[span].id);
    var prefix = id.substring(0,1);
    if ( prefix != '_' ) {
      allSpan[span].onmousedown = HandlePrintEvent;
      allSpan[span].onclick = HandlePrintEvent;
      allSpan[span].style.cursor = 'default';
    }
  }

  // Reset all anchor "<A>" events
  var allA = document.all.tags("A");
  for ( var a = 0; a < allA.length; a++ ) {
    var id = new String(allA[a].id);
    var prefix = id.substring(0,1);
    if ( prefix != '_' ) {
      allA[a].onmousedown = HandlePrintEvent;
      allA[a].onclick = HandlePrintEvent;

      var printButton = document.all.printButton;
      var closeButton = document.all.closeButton;
      if ( !printButton.contains(allA[a]) && 
           !closeButton.contains(allA[a]) ) {
        allA[a].style.cursor = 'default';
      }
    }
  }

  // Reset all img "<IMG>" events
  for ( var i = 0; i < document.images.length; i++ ) {
    var id = new String(document.images[i].id);
    var prefix = id.substring(0,1);
    if ( prefix != '_' ) {
      document.images[i].onmousedown = HandlePrintEvent;
      document.images[i].onclick = HandlePrintEvent;
      document.images[i].style.cursor = 'default';
    }
  }

  // Reset events for all form elements
  for ( var d = 0; d < document.forms.length; d++ ) {
    var id = new String(document.forms[d].id);
    var prefix = id.substring(0,1);
    if ( prefix != '_' ) {
      document.forms[d].onmousedown = HandlePrintEvent;
      document.forms[d].onclick = HandlePrintEvent;
      document.forms[d].style.cursor = 'default';
    }
    for ( var e = 0; e < document.forms[d].elements.length; e++ ) {
      var id = new String(document.forms[d].elements[e].id);
      var prefix = id.substring(0,1);
      if ( prefix != '_' ) {
        document.forms[d].elements[e].onmousedown = HandlePrintEvent;
        document.forms[d].elements[e].onclick = HandlePrintEvent;
        document.forms[d].elements[e].style.cursor = 'default';
      }
    }
  }
}

///////////////////////////////////////////////////////////////////////////////
//
// CheckElHidden
//
// Check to see if the given element is contained within a hidden object.  It
// traverses up the object tree until no parent is found, or until it finds
// a parent that is hidden.
//
// Input:  Element to check
// 
// Return: true if 'hidden' found in object tree
//         false otherwise
//
///////////////////////////////////////////////////////////////////////////////

function CheckElHidden( el ) {
  if ( el ) {
    if ( el.currentStyle.visibility == 'hidden' )
      return true;

    var parentEl =  el.parentElement;
    while ( parentEl ) {
      if ( parentEl.currentStyle.visibility == 'hidden' )
        return true;
      parentEl = parentEl.parentElement;
    }
  }

  return false;
}

// End the hiding here. -->
