/******************************************************************************
*
*	Pivotal eService 5.0
*
*	File:		utils.js 
*	Purpose:	Utility javascript functions used throught eService.
*	Date:		January 1, 2003
*
******************************************************************************/

var sUtils_TempTitle = null;
function utils_setTitle( sTitle )
{
	if ( window.parent.bodytop == null || window.parent.bodytop.updateHeaderTitle == null )
	{
		// The header frame is still loading, set a timer event to try again...
		sUtils_TempTitle = sTitle;
		window.setTimeout( "utils_setTitle(sUtils_TempTitle)", 100 );
	} else {
		window.parent.bodytop.updateHeaderTitle( sTitle );
	}
}
var sUtils_TempViewSetting = null;
function utils_showLastLogin(sDisplay)
{
	if ( window.parent.bodytop == null || window.parent.bodytop.showLastLogin == null )
	{
		// The header frame is still loading, set a timer event to try again...
		sUtils_TempViewSetting = sDisplay;
		window.setTimeout( "utils_showLastLogin(sUtils_TempViewSetting)", 100 );
	} else {
		parent.bodytop.showLastLogin(sDisplay);
	}

}


function utils_formDeleteCallback( sCallbackId, sCallbackParam, oData )
{
	if ( oData.length > 0 )
	{
		var strMessage = "";
		for ( var i = 0; i < oData.length; i++ )
		{
			strMessage = strMessage + oData[i] + "<br/>"
		}
		openErrorDialog("", 5, strMessage, 2);
		window.top.goBack();
	}else
	 	window.top.goBack();
}

var oUtils_RightButtons, oUtils_RightHandlers, oUtils_LeftButtons, oUtils_LeftHandlers, sUtils_SelectedLeftButton
function utils_setButtons( oRightButtons, oRightHandlers, oLeftButtons, oLeftHandlers, sSelectedLeftButton )
{
	if ( parent.bodybottom == null || parent.bodybottom.updateFooterButtons == null )
	{
		oUtils_RightButtons = oRightButtons;
		oUtils_RightHandlers = oRightHandlers;
		oUtils_LeftButtons = oLeftButtons;
		oUtils_LeftHandlers = oLeftHandlers;
		sUtils_SelectedLeftButton = sSelectedLeftButton;
		window.setTimeout( "utils_setButtons(oUtils_RightButtons, oUtils_RightHandlers, oUtils_LeftButtons, oUtils_LeftHandlers, sUtils_SelectedLeftButton)", 100 );
	} else {
		parent.bodybottom.updateFooterButtons( oRightButtons, oRightHandlers, oLeftButtons, oLeftHandlers, sSelectedLeftButton );
	}
}

function utils_isInternetExplorer()
{
	var bValue;

	if ( navigator.appName == "Microsoft Internet Explorer" )
		bValue = true;	
	else
		bValue = false;

	return bValue;
}

function utils_isValidId( sId )
{
	if ( sId == null || sId.length != 16 ) return false;

	var sTemp = sId.toUpperCase();
	for ( var i = 0; i < 16; i++ )
	{
		var cChar = sTemp.charAt(i);
	
		if ( cChar != '0' && cChar != '1' && cChar != '2' && cChar != '3' &&
			 cChar != '4' && cChar != '5' && cChar != '6' && cChar != '7' &&
			 cChar != '8' && cChar != '9' && cChar != 'A' && cChar != 'B' &&
			 cChar != 'C' && cChar != 'D' && cChar != 'E' && cChar != 'F' )
		{
			return false;
		}
	}
	return true;
}

function utils_HTMLEncode( sString )
{
	var testXMLChars = />|<|&|\"|\'|%/;
	
	if ( testXMLChars.test( sString ) ){
		sString = sString.replace(/&/g, "&amp;");
		sString = sString.replace(/>/g, "&gt;");
		sString = sString.replace(/</g, "&lt;");
		sString = sString.replace(/\"/g, "&quot;");
		sString = sString.replace(/\'/g, "&apos;");			// Apostrophe case was missing. Fixed in RD Issue#: 45591 - Cannot add file attachements that contain an ampersand (&) or an apostrophe (') in filename. - APC June 2004
	}
	if ( sString == null )
		sString = "";
		
	return sString;
}


function utils_displayDateSelector( sDateValue, sCallbackFunction, sCallbackParameter )
{
	var objInputElement = document.getElementById(sCallbackParameter);
	
	var xPosition = utils_getElementLeftOffset(objInputElement);
	var yPosition = utils_getElementTopOffset(objInputElement, DATE_SELECTOR);

	var oKeys = new Array();
	var oValues = new Array();
	var i = 0;

	oKeys[i] = "type";
	oValues[i++] = "dateselector";

	oKeys[i] = "value";
	oValues[i++] = sDateValue;
	
	oKeys[i] = "callbackfunction";
	oValues[i++] = sCallbackFunction;
	oKeys[i] = "callbackparam";
	oValues[i++] = sCallbackParameter;
	
	oKeys[i] = "targetType";
	oValues[i++] = "regular";
	
	var sURL = nav_buildURL( "xmlloader.asp", oKeys, oValues );
	var oWindow = window.open( sURL, "", "height=200,width=250,status=no,toolbar=no,scrollbars=no,menubar=no,dependent=yes,location=no,resizable=yes,fullscreen=0,left=" + xPosition + ",top=" + yPosition );
	return oWindow;
}

function utils_getElementLeftOffset(formFieldElement)
{
    if (!formFieldElement && this)               
        formFieldElement = this;                         

    var total_horizontal_offset;
    var horizontal_offset;
    
    if ( parent.parent.frames.bodymain.screenTop){
		//ie values
		var scroll_offset = parent.parent.frames.bodymain.document.body.scrollLeft;
		var page_offset = parent.parent.frames.bodymain.screenLeft;
    }else {
    	//netscape values
		var scroll_offset = window.pageXOffset;
		var page_offset =  screen.width - screen.availWidth + window.screen.left + parent.parent.frames.menumain.document.body.offsetWidth;
    }

	horizontal_offset = page_offset + scroll_offset;
	
    var currentElementLeftPosition = formFieldElement.offsetLeft;          
    var parentElementsLeftPostion = formFieldElement.offsetParent;       
    while (parentElementsLeftPostion != null)
    {                                            
        currentElementLeftPosition += parentElementsLeftPostion.offsetLeft;  
        parentElementsLeftPostion = parentElementsLeftPostion.offsetParent;  
    }
    
    total_horizontal_offset = currentElementLeftPosition + horizontal_offset;
    
    return total_horizontal_offset;       
}

function utils_getElementTopOffset(formFieldElement, type)
{
    if (!formFieldElement && this)
    {
        formFieldElement = this;
    }

    if ( parent.parent.frames.bodymain.screenTop){
		//ie values
		var screen_height = document.body.clientHeight;
		var scroll_offset = parent.parent.frames.bodymain.document.body.scrollTop;
		var page_offset = parent.parent.frames.bodymain.screenTop;
		//height corresponds the IE's rendering of the date & selector popup windows
		var FIELD_HEIGHT = 20;
		if ( type == SELECTOR )
			var SIZE_OF_POPUP = 410;
		else
			var SIZE_OF_POPUP = 210;

    }else {
    	//netscape values
		var screen_height = window.innerHeight;
		var scroll_offset = window.pageYOffset;
		var page_offset = screen.height - screen.availHeight +window.screenY - parent.parent.frames.bodytop.document.body.offsetHeight + window.outerHeight - window.innerHeight - parent.parent.frames.bodybottom.document.body.offsetHeight;
		//height corresponds the Netscape's rendering of the date & selector popup windows
		var FIELD_HEIGHT = 10;
		if ( type == SELECTOR )
			var SIZE_OF_POPUP = 430;
		else
			var SIZE_OF_POPUP = 225;	
    }
    
    var bottom_threshold = .20 * screen_height;
    var vertical_offset = page_offset - scroll_offset;
    var total_vertical_offset;
    
    var currentElementTopPosition = formFieldElement.offsetTop;
    var parentElementsTopPostion = formFieldElement.offsetParent;
    while (parentElementsTopPostion != null)
    {
        currentElementTopPosition += parentElementsTopPostion.offsetTop;
        parentElementsTopPostion = parentElementsTopPostion.offsetParent;
    }
    
    if ( currentElementTopPosition + FIELD_HEIGHT + SIZE_OF_POPUP - scroll_offset > screen_height ){
		total_vertical_offset = currentElementTopPosition - SIZE_OF_POPUP - FIELD_HEIGHT + vertical_offset;	
		if ( total_vertical_offset < 0 )
			total_vertical_offset = currentElementTopPosition - FIELD_HEIGHT + vertical_offset;	
	}else
		total_vertical_offset = currentElementTopPosition + FIELD_HEIGHT + vertical_offset;
      
    return total_vertical_offset;
}

var DATE_SELECTOR = 0;
var SELECTOR = 1;




function utils_displayComboSelector( oComboValues, sCallbackFunction, sCallbackParameter)
{
	var objInputElement = document.getElementById(sCallbackParameter);
	var xPosition = utils_getElementLeftOffset(objInputElement);
	var yPosition = utils_getElementTopOffset(objInputElement, SELECTOR);

	var strHTML = "";
	
	strHTML += "<HTML>\n";
	strHTML += "  <HEAD>\n";
	strHTML += "    <LINK REL=\"STYLESHEET\" TYPE=\"text/css\" HREF=\"css/foreignkey.css\"></LINK>\n";
	strHTML += "    <SCRIPT language=\"javascript\" src=\"javascript/combo.js\"></SCRIPT>\n";
	strHTML += "    <SCRIPT language=\"javascript\">\n";
	strHTML += "      function combo_returnValue( sValue )\n";
	strHTML += "      {\n";
	strHTML += "        window.opener." + sCallbackFunction + "('COMBO',g_sCallbackParameter,sValue);\n";
	strHTML += "        window.close();";
	strHTML += "      }\n";
	strHTML += "      var g_sCallbackParameter = \"" + sCallbackParameter + "\";\n";
	strHTML += "      function onUnload()\n";
	strHTML += "      {\n";
//	strHTML += "		if (window.opener.form_closeSelectorWindow != null)\n";									// Commented out during RD Issue#: 65536-5228 - July 2004 APC
	strHTML += "		if (window.opener != null && window.opener.form_closeSelectorWindow != null)\n";		// Added during RD Issue#: 65536-5228 - July 2004 APC
	strHTML += "			window.opener.form_closeSelectorWindow(self);\n";
	strHTML += "      }\n";
	strHTML += "    </SCRIPT>\n";
	strHTML += "  </HEAD>\n";
	strHTML += "  <BODY onunload=\"onUnload();\">\n";
	strHTML += "    <TABLE class=\"selectionTable\" border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n";
	
	for ( var i = 0; i < oComboValues.length; i++ )
	{
		var sClassname;
		if ( i % 2 == 0 )
			sClassname = "selectionRow1";
		else
			sClassname = "selectionRow2";
		strHTML += "      <TR><TD class=\"" + sClassname + "\"><A class=\"selectionLink\" oncontextmenu=\"return false\" href=\"javascript:combo_returnValue(&quot;" + oComboValues[i] + "&quot;)\">" + utils_HTMLEncode(oComboValues[i]) + "</A></TD></TR>\n";
	}
	
	strHTML += "    </TABLE>\n";
	strHTML += "  </BODY>\n";
	strHTML += "</HTML>\n";
	
	var oComboWindow = window.open("","","height=400,width=250,status=no,toolbar=no,scrollbars=yes,menubar=no,dependent=yes,location=no,resizable=yes,fullscreen=0,left=" + xPosition + ",top=" + yPosition );

	if ( oComboWindow != null )
	{
		oComboWindow.document.open();
		oComboWindow.document.write( strHTML );
		oComboWindow.document.close();
	}
	return oComboWindow;
}

function utils_displayForeignKeySelector( sTable, sQueryId, oParams, sCallbackFunction, sCallbackParameter )
{
	var objInputElement = document.getElementById(sCallbackParameter);
	var xPosition = utils_getElementLeftOffset(objInputElement);
	var yPosition = utils_getElementTopOffset(objInputElement, SELECTOR);
	
	var oKeys = new Array();
	var oValues = new Array();
	var i = 0;

	oKeys[i] = "type";
	oValues[i++] = "foreignkey";
	
	if ( sTable != null )
	{
		if ( utils_isValidId(sTable) )
		{
			oKeys[i] = "tableId";
			oValues[i++] = sTable;
		} else {
			oKeys[i] = "tableName";
			oValues[i++] = sTable;
		}
	}
	if ( sQueryId != "" )
	{
		oKeys[i] = "queryId";
		oValues[i++] = sQueryId;
		
		if ( oParams != null )
		{
			if (oParams.length == 0) {				// Added during RD Issue#: 45849 - July 2004 APC
				oKeys[i] = "filterwithnoparams";	// Added during RD Issue#: 45849 - July 2004 APC
				oValues[i++] = 1;					// Added during RD Issue#: 45849 - July 2004 APC
			}										// Added during RD Issue#: 45849 - July 2004 APC

			for ( var j = 0; j < oParams.length; j++ )
			{
				oKeys[i] = "parameter";
				oValues[i++] = oParams[j];
			}
		}
	}

	oKeys[i] = "firstRun"
	oValues[i++] = "true"

	oKeys[i] = "callbackfunction";
	oValues[i++] = sCallbackFunction;
	oKeys[i] = "callbackparam";
	oValues[i++] = sCallbackParameter;
	
	oKeys[i] = "targetType";
	oValues[i++] = "regular";
	
	var sURL = nav_buildURL( "foreignkeyFrame.asp", oKeys, oValues );
	var objInputElement = document.getElementById(sCallbackParameter);
	var oFKWindow = window.open( sURL, "", "height=255,width=300,status=no,toolbar=no,scrollbars=yes,menubar=no,dependent=yes,location=no,resizable=yes,fullscreen=0, left=" + xPosition + ",top=" + yPosition );
	return oFKWindow;
}


function utils_stringParamReplace( sString, oParams )
{
	var sResult = "";
	var oRegExp;
	var oMatches;
	var sNewSubstring;
	var iLastMatch;

	oRegExp = new RegExp( "%([%\\d])", "g");
	iEndLastMatch = 0;
	
	while ( (oMatch = oRegExp.exec( sString )) != null )
	{
		sResult += sString.substring( iEndLastMatch, oMatch.index );

		if ( oMatch[1] == "%" )
		{
			oResult += "%";
		} else {
			// oMatch[1] must be a digit...
			var iIndex = parseInt( oMatch[1] ) - 1;
			if ( iIndex < oParams.length )
			{
				sResult += oParams[iIndex];
			}
		}

		iEndLastMatch = oMatch.index + oMatch[0].length;
	}
	
	if ( iEndLastMatch < sString.length )
	{
		sResult += sString.substring( iEndLastMatch, sString.length );
	}
	
	return sResult;
}

function utils_getClientStateWindow()
{
	if ( window.parent.clientstate != null )
	{
		return window.parent.clientstate;
	}
	if ( window.parent.parent.clientstate != null )
	{
		return window.parent.parent.clientstate;
	}
	if ( window.parent.parent.parent.clientstate != null )
	{
		return window.parent.parent.parent.clientstate;
	}
	return null;
}

function utils_isFormatterReady()
{
	if ( utils_isInternetExplorer() )
	{
		if ( utils_getClientStateWindow() == null ) return false;
		var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
		return ( oApplet != null && oApplet.readyState != null && oApplet.readyState == 4 );
	} else {
		if ( utils_getClientStateWindow() == null ) return false;
		var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
		return ( oApplet != null );
	}
}


function utils_testAppletSupport()
{
	if ( utils_isFormatterReady() )
	{
		if ( utils_isInternetExplorer() )
		{
			var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
			if ( oApplet.object == null ) 
				return false;
			else
				return true;
				
		} else {
			if (navigator.javaEnabled()){
				if ( utils_parseInteger( 5 ) != null )
					return true;
				else
					return false;
			} else
				return false;
		}	
	} else {
		window.setTimeout( "utils_testAppletSupport()", 250 );
	}
}

function utils_formatDate( sDate )
{
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	return oApplet.formatDate( sDate, "LONG" );
}

function utils_formatTime( sTime )
{
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	return oApplet.formatTime( sTime, "SHORT" );
}

function utils_formatTimestamp( sTimestamp )
{
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	return oApplet.formatTimestamp( sTimestamp, "LONG", "SHORT" );
}

function utils_formatInteger( sInteger )
{
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	return oApplet.formatInteger( sInteger + "" );
}

function utils_formatFloat( sFloat )
{
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	return oApplet.formatFloat( sFloat + "", 2 );
}

function utils_parseInteger( sInteger )
{
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	return oApplet.parseInteger( sInteger + "" );
}


function utils_parseFloat( sFloat )
{
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	return oApplet.parseFloat( sFloat + "" );
}

var oTypesArray = new Array( "SHORT", "MEDIUM", "LONG", "FULL" );

function utils_parseDate( sDate )
{
	if ( sDate == null || sDate == "" )
	{
		// This case fixes a bug in the Sun JVM that throws a NullPointerException if parseDate() is
		// passed an empty string...
		return null;
	}
	
	var	strSeparator;														// RD Issue#: 65536-5905 - APC Aug 2004
	var dateStringArray = sDate.split(",")									// Test 1, try splitting on comma
	if ( dateStringArray.length < 2 || dateStringArray[1] == "" )
	{
		dateStringArray = sDate.split("/")									// APC Test 2, try splitting on forward slash. RD Issue: 65536-4989
		if ( dateStringArray.length < 3 || dateStringArray[1] == "" )		// APC RD Issue: 65536-4989
		{																	// APC RD Issue: 65536-4989
			dateStringArray = sDate.split(".")								// APC Test 3, try splitting on period. RD Issue: 65536-4989
			if ( dateStringArray.length < 3 || dateStringArray[1] == "" )	// APC RD Issue: 65536-4989
				strSeparator = "";											// RD Issue: 46712 -Jan 2005. Fixed the date format issue in foreign language enviroment
			else															// RD Issue#: 65536-5905 - APC Aug 2004
				strSeparator = ".";											// RD Issue#: 65536-5905 - APC Aug 2004
		}																	// APC RD Issue: 65536-4989
		else																// RD Issue#: 65536-5905 - APC Aug 2004
			strSeparator = "/";												// RD Issue#: 65536-5905 - APC Aug 2004
	}	

	// In order to check that a text string contains a valid date, the following known date formats are
	// used in conjunction with a method exposed by the DataFormatter java applet called parseDateUsingPattern.
	// If the routine returns a valid date then this routine will return it.  If not, then this routine calls
	// theDataFormatter's parseDate routine once for each know format type (FULL, LONG, MEDIUM, SHORT) to see
	// if it can match the date.											// RD Issue#: 65536-5905 - APC Aug 2004
	//
	// This logic caters for the following date patterns:
	// "yyyy/MM/dd", yyyy.MM.dd"; "yyyy/dd/MM", "yyyy.dd.MM"; "dd/MM/yyyy", "dd.MM.yyyy"; "MM/dd/yyyy", "MM.dd.yyyy"
	// If other ones are needed, the code must be updated accordingly
	var strPattern = "";											// Initialize the Pattern to an empty string
	if (dateStringArray.length == 3) {								// If we have a 3 part date format
		// Do we have a valid numeric 4 digit Year in 1st part of date?
		if (dateStringArray[0].length == 4 && utils_IsValid4DigitYear(dateStringArray[0]) == true) {
			if (dateStringArray[1] <= 12) {							// if the middle part is the Month
				if (strSeparator == "/")							// if the separator is a "/"
					strPattern = "yyyy/MM/dd";						// Define the Date pattern to try and match on
				else
					strPattern = "yyyy.MM.dd";						// Define the Date pattern to try and match on
			}
			else 
			{														// treat the middle part as the Day
				if (strSeparator == "/")							// if the separator is a "/"
					strPattern = "yyyy/dd/MM";						// Define the Date pattern to try and match on
				else
					strPattern = "yyyy.dd.MM";						// Define the Date pattern to try and match on
			}
		}
		// Do we have a valid numeric 4 digit Year in 3rd part of date?
		if (dateStringArray[2].length == 4 && utils_IsValid4DigitYear(dateStringArray[2]) == true) {
			if (dateStringArray[1] <= 12) {							// if the middle part is the Month
				if (strSeparator == "/")							// if the separator is a "/"
					var strPattern = "dd/MM/yyyy";					// Define the Date pattern to try and match on
				else
					var strPattern = "dd.MM.yyyy";					// Define the Date pattern to try and match on
			}
			else 
			{														// treat the middle part as the Day
				if (strSeparator == "/")							// if the separator is a "/"
					var strPattern = "MM/dd/yyyy";					// Define the Date pattern to try and match on
				else
					var strPattern = "MM.dd.yyyy";					// Define the Date pattern to try and match on
			}
		}
	}
	
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;

	var sParsedDate;
	if (strPattern != "")
	{
		sParsedDate = oApplet.parseDateUsingPattern( sDate, strPattern );
		if ( sParsedDate != null && sParsedDate != "" ) 
			return sParsedDate;
	}
	else
	{
		for ( var i = 0; i < oTypesArray.length; i++ )							
		{
			if ( oApplet.parseDate( sDate, oTypesArray[i] )){
				var sParsedDate = oApplet.parseDate( sDate, oTypesArray[i] );
				if ( sParsedDate != null && sParsedDate != "" ) return sParsedDate;
			}
		}
	}
	
/////////////////////////////////////////////////////////////////////////////////	
// Commented out during RD Issue#: 65536-5905 - APC Aug 2004
//	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	
//	for ( var i = 0; i < oTypesArray.length; i++ )							// APC RD Issue: 65536-4989
//	for ( var i = oTypesArray.length-1; i >=0; i-- )						// APC RD Issue: 65536-4989.  Reverse the order in which we test the formats.
//	{
//		if ( oApplet.parseDate( sDate, oTypesArray[i] )){
//			var sParsedDate = oApplet.parseDate( sDate, oTypesArray[i] );
//			if ( sParsedDate != null && sParsedDate != "" ) return sParsedDate;
//		}
//	}
/////////////////////////////////////////////////////////////////////////////////	

	return null;
}




function utils_parseTime( sTime )
{
	// If sTime is an empty string, return null. RD Issue#: 65536-5380 - Added by APC Aug 2004
	if ( sTime == null || sTime == "" )
		return null;

	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	
	for ( var i = 0; i < oTypesArray.length; i++ )
	{
		var sParsedTime = oApplet.parseTime( sTime, oTypesArray[i] );
		if ( sParsedTime != null && sParsedTime != "" ) return sParsedTime;
	}
	
	return null;
}

function utils_formatEmbeddedValues( oValueArray )
{
	for ( var i = 0; i < oValueArray.length; i++ )
	{
		var sFormattedValue = utils_formatValues( oValueArray[i][2], oValueArray[i][1] );
		var oElement = document.getElementById( oValueArray[i][0] );
		
		if ( sFormattedValue != "" )
		{
			oElement.innerHTML = sFormattedValue;
		} else {
			
		}
	}
}


function utils_formatParameterValues ( oValueArray ) 
{

	for ( var i = 0; i < oValueArray.length; i++ )
	{
		var sFormattedValue = utils_formatValues( oValueArray[i][2], oValueArray[i][1] );

		var oElement = document.getElementById( oValueArray[i][0] );
		
		if ( sFormattedValue != "" )
		{
			oElement.value = sFormattedValue;
		} else {
		}
	}
}

function utils_formatValues( sType, value )
{
	var sFormattedValue
	
	switch( sType )
	{
		case "FLOAT":
		{
			if ( value == "" ) value = "0";
			sFormattedValue = utils_formatFloat( value );
			break;
		}
		case "INT":
		{
			if ( value == "" ) value = "0";
			sFormattedValue = utils_formatInteger( value );
			break;
		}
		case "DATE":
		{
			// If the supplied date is an empty string, return an empty string.  Under the SUN VM the 
			// utils_formatDate routine returns a value of "undefined" when passed an empty string which 
			// then gets displayed in the control.	Under Microsoft's Java VM, it returns an empty string
			// which is fine.										// RD Issue: 65536-5085 Aug 2004 APC
			if ( value == "" )										// RD Issue: 65536-5085 Aug 2004 APC
				sFormattedValue = value;							// RD Issue: 65536-5085 Aug 2004 APC
			else													// RD Issue: 65536-5085 Aug 2004 APC
				sFormattedValue = utils_formatDate( value );
			break;
		}
		case "TIME":
		{
			sFormattedValue = utils_formatTime( value );
			break;
		}
		// TimeStamp case added during RD Issue: 45992 - Aug 2004 by APC
		case "TIMESTAMP":
		{
			sFormattedValue = utils_formatTimestamp( value );
			break;
		}
	}

	return sFormattedValue;

}


function utils_sessionTimeOut()
{
	alert( g_LDSTRING_MESSAGE_SESSION_TIMED_OUT );
	nav_openType( false, 'logoff' );
}

function utils_setSessionTimeOut( intTimeOut )
{
	window.setTimeout("utils_sessionTimeOut()", intTimeOut);
	return;
}

function utils_Hex (iNum)
{
	var hex=iNum.toString(16);
	if (hex.length == 0)
		hex = '00';
	else if (hex.length == 1)
		hex = '0' + hex;
	return hex;
}

//used to encode a query string parameter
function utils_URLParamEncode( sURLParameter )
{
    var iCounter;
    var sEncodedURLParameter;
    
    sEncodedURLParameter = "";
    for (iCounter = 0; iCounter < sURLParameter.length; iCounter ++ ) {
        if ( ((sURLParameter.substr(iCounter, 1) >= "A") && (sURLParameter.substr(iCounter, 1) <= "Z")) ||
        ((sURLParameter.substr(iCounter, 1) >= "a") && (sURLParameter.substr(iCounter, 1) <= "z")) ||
        ((sURLParameter.substr(iCounter, 1) >= "0") && (sURLParameter.substr(iCounter, 1) <= "9")) )
            sEncodedURLParameter = sEncodedURLParameter + sURLParameter.substr(iCounter, 1);
        else
            sEncodedURLParameter = sEncodedURLParameter + "%" + utils_Hex(sURLParameter.substr(iCounter, 1).charCodeAt(0));
    }
    return sEncodedURLParameter;
}

// This routine checks for a valid 4 digit numeric year value - Added by APC Aug 2004 during RD Issue: 65536-4989
function utils_IsValid4DigitYear(sYear)
{
   var sRefString = "1234567890";						// A Year value can only contain the following characters
   var iCount;											// Loop counter variable
   var sTempChar;										// A working variable to test each character of the sYear param

   if (sYear.length != 4)								// A 4 didgit Year value is required
		return (false);									// Invalid Year
     
   for (iCount=0; iCount < sYear.length; iCount++)
   {
      sTempChar = sYear.substring ( iCount, iCount+1 );
      
      if ( sRefString.indexOf (sTempChar, 0) == -1)		// Is current character a valid Year character?
         return (false);								// If Not a valid Year char, return false
   }
   
   return(true);										// If we've made it this far the Year is valid, return True
 }

