/****************************************************************************
*
*	Pivotal eService 5.0	
*	
*	Name:		utils.js
*	Purpose:	Utility javascript functions used throught eService.
*	Date:		January 1, 2003
* 
*	Revision History
*	
*	Revision	Date		Authour		Description
*	P5i6.8		2005/01/11	Kevin		Replaced function utils_parseDate with the same function from demo site.
*   	P5i6.12		2005/03/14  	Jonathan	Put in HF2 changes
*							RD Issue # 65536-5380, 45992
*   	P5i6.17		2005/09/02	Jonathan	Changed the size of the foreign key pop up window
*   	P5i6.28		2006/11/14	Jonathan	Created a new function to track a downloaded file 'utils_TrackDownload'
*	P5i6.40 	2008/03/30	Jonathan	Added XML return check to see if the customer has a valid support contract for the product selected.
*							Only Product Downloads will be checked in the ASF 'CF Contact'.
*	N/A		2009/03/12	Jonathan	Sun Java VM 6 Update 10 or higher causes a Null value to be returned
*							when the date is parsed if it is an empty string or null
****************************************************************************/

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 )
{
	//alert('utils_setButtons');
	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);
	//P5i6.17 2005/09/02 JF - Increased the size of the window to accommodate more entries that are set in customizationsettings.xml
	var oFKWindow = window.open( sURL, "", "height=495,width=350,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 )
{

	//2009/03/12 JF - Sun Java VM 6 Update 10 or higher causes a Null value to be returned
	//		  when the date is parsed if it is an empty string or null.
	if(sDate == '' || sDate == null){
		return '';
	}
	
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	return oApplet.formatDate( sDate, "LONG" );
}
//2005/1/5 Kevin - build a date string in US English format 
function utils_formatDate2(sDate)
{
	if(sDate == '' || sDate == null){
		return '';
	}
	var arrDate = sDate.split('-');
	var strDate =  ' ' + arrDate[2] + ', ' + arrDate[0];
	switch (arrDate[1]){
		case '1':
			strDate = 'January' + strDate;
			break;
		case '01':
			strDate = 'January' + strDate;
			break;
		case '2':
			strDate = 'February' + strDate;
			break;
		case '02':
			strDate = 'February' + strDate;
			break;
		case '3':
			strDate = 'March' + strDate;
			break;
		case '03':
			strDate = 'March' + strDate;
			break;
		case '4':
			strDate = 'April' + strDate;
			break;
		case '04':
			strDate = 'April' + strDate;
			break;
		case '5':
			strDate = 'May' + strDate;
			break;
		case '05':
			strDate = 'May' + strDate;
			break;
		case '6':
			strDate = 'June' + strDate;
			break;
		case '06':
			strDate = 'June' + strDate;
			break;
		case '7':
			strDate = 'July' + strDate;
			break;
		case '07':
			strDate = 'July' + strDate;
			break;
		case '8':
			strDate = 'August' + strDate;
			break;
		case '08':
			strDate = 'August' + strDate;
			break;
		case '9':
			strDate = 'September' + strDate;
			break;
		case '09':
			strDate = 'September' + strDate;
			break;
		case '10':
			strDate = 'October' + strDate;
			break;
		case '11':
			strDate = 'November' + strDate;
			break;
		case '12':
			strDate = 'December' + strDate;
			break;
	}
	return strDate;
}


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" );

//Jan 11, 2005 Kevin -- This function is copied from demo site
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 oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	
	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;
		}
	}
	
	return null;
}

//Jan 11, 2005 Kevin -- This is the original function
function utils_parseDate3( 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 dateStringArray = sDate.split(",")
	if ( dateStringArray.length < 2 || dateStringArray[1] == "" ){
		return null;
	}
	
	var oApplet = utils_getClientStateWindow().document.dateTimeFormatterApplet;
	
	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;
			}
		}
	}
	
	return null;
}

//Jan 04, 2004 Kevin -- I function ignored the java applet
function utils_parseDate2( 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 dateStringArray = sDate.split(",")
	if ( dateStringArray.length < 2 || dateStringArray[1] == "" ){
		return null;
	}
	
	var thedate = new Date(sDate);
	//alert(thedate.getFullYear() + '-' + (thedate.getMonth() + 1) + '-' + thedate.getDate());
	return thedate.getFullYear() + '-' + (thedate.getMonth() + 1) + '-' + thedate.getDate();
}

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;
			if(oElement.value == 'undefined'){
				oElement.value = '';
			}

		} 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":
		{
			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;
}

//P5i6.17 - Used to execute a custom LCS commands
function utils_ExecuteScript(sURL, intOutputMethod)
{

	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
		var oXMLHTTP = new XMLHttpRequest() ;
	// code for IE
	else if (window.ActiveXObject)
		// Create an instance of the XML HTTP Request object
		var oXMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );		


	// Prepare the XMLHTTP object for a HTTP POST 
	oXMLHTTP.open( "POST", sURL, false );

	// Execute the request
	try {
		oXMLHTTP.send();
		//alert(oXMLHTTP.responseText) ;
		switch (intOutputMethod) {
			case '0': 
				return(oXMLHTTP.responseText) ; 
				break;
			case '1': 
				return(oXMLHTTP.responseXML) ; 
				break;
			case '2': 
				return(oXMLHTTP.responseBody) ; 
				break;
			case '3': 
				return(oXMLHTTP.responseStream) ; 
				break;
			default:
				return(oXMLHTTP.responseText) ;
		}
		
	}
	catch (e) {
		return null;
	}

}

//P5i6.28 - Used to track the downloaded item and create a record attached to the contact
function utils_TrackDownload(sDownloadType, sNotes, sRecordId, sContactId)
{
	var sURL = "";
	var sTrackDownload = "";

	sURL = "xmlloader.asp?type=ExecuteServiceScript&ScriptName=AddDownloadDetails&OutputType=0&formid=8000000000000146";
	sURL = sURL + "&cparam=" + sDownloadType;
	sURL = sURL + "&cparam=" + sNotes;		
	sURL = sURL + "&cparam=" + "0x" + sRecordId;
	sURL = sURL + "&cparam=" + "0x" + sContactId;

	var sTrackDownload = utils_ExecuteScript(sURL,1) ;	
	return sTrackDownload;
}

//P5i6.28 - Used to track the downloaded item and create a record attached to the contact
//P5i6.40 - Added XML return check to see if the customer has a valid support contract for the product selected.
//			Only Product Downloads will be checked in the ASF 'CF Contact'.
//function utils_TrackDownload(sDownloadType, sNotes, sRecordId, sContactId)
//{
//	var sURL = "";
//	var sTrackDownload = "";
//
//	sURL = "xmlloader.asp?type=ExecuteServiceScript&ScriptName=AddDownloadDetails&OutputType=0&formid=8000000000000146";
//	sURL = sURL + "&cparam=" + sDownloadType;
//	sURL = sURL + "&cparam=" + sNotes;		
//	sURL = sURL + "&cparam=" + "0x" + sRecordId;
//	sURL = sURL + "&cparam=" + "0x" + sContactId;
//
//	var sTrackDownload = utils_ExecuteScript(sURL,1) ;	
//	xmlDoc = new ActiveXObject( "Msxml2.DOMDocument.3.0" );
//	xmlDoc.loadXML(sTrackDownload);
//	
//	try
//	{
//		blnValidSupport = xmlDoc.selectSingleNode("/commandResult/data/returnParameters/booleanParameter[0]").text;
//		varMessage = xmlDoc.selectSingleNode("/commandResult/data/returnParameters/stringParameter[0]").text;
//	}
//	catch (e)
//	{
//		return false;
//	}
//	
//	if (blnValidSupport == "false") 
//	{
//		alert (varMessage);
//		return false;
//	}
//	else
//		return true;	
//	
//	
//	
//}

//P5i6.40 - This method will restrict download access to product
//          downloads based on what the customer is allowed to see according to their license contract.
function utils_CheckProductLicenseSecurity(sSecurityCheckType, sRecordId, sContactId)
{
	var sURL = "";
	var sSecurityCheck = "";

	if (sSecurityCheckType != "Product Downloads")
		return true;
	

	sURL = "xmlloader.asp?type=ExecuteServiceScript&ScriptName=CheckProductLicenseSecurity&OutputType=0&formid=8000000000000146";
	sURL = sURL + "&cparam=" + sSecurityCheckType;
	sURL = sURL + "&cparam=" + "0x" + sRecordId;
	sURL = sURL + "&cparam=" + "0x" + sContactId;

	var sSecurityCheck = utils_ExecuteScript(sURL,1) ;	
	xmlDoc = new ActiveXObject( "Msxml2.DOMDocument.3.0" );
	xmlDoc.loadXML(sSecurityCheck);

	try
	{
		blnValidSupport = xmlDoc.selectSingleNode("/commandResult/data/returnParameters/booleanParameter[0]").text;
		varMessage = xmlDoc.selectSingleNode("/commandResult/data/returnParameters/stringParameter[0]").text;
	}
	catch (e)
	{
		return false;
	}
	
	if (blnValidSupport == "false") 
	{
		alert (varMessage);
		return false;
	}
	else
		return true;	
	
	
	
}
