/** Standard.js
 * Collection of JavaScript methods used by many different pages across all modules.
 * andrew@ares.com 10/2002
 */


/* Centralized method to retrieve a handle to the Applet */
function getApplet()
{
	// "old" way:
	//return top.document.applets.PreView;
	// New way:
	return top.myApplet;
}

/* Causes the DEFAULT hint/help message to appear in the top frame */
function setMainText()
{
	//top.setSelected(false);
}

/* Returns the name of the next and previous pages */
function nextPageName()
{
	return "Page" + getPageID(1) + ".html";
}
function prevPageName()
{
	return "Page" + getPageID(-1) + ".html";
}
function getPageID(nOffset)
{
	var nPage = nCurPage + nOffset;
	while ( isPageSkipped(nPage) )
	{
		nPage = nPage + nOffset;
	}
	return nPage;
}
function isPageSkipped ( nPage )
{
/* Un-comment this section of code if you ever need to use the PageSkipped functionality:
	try {
		var sSkipPages = "," + top.sPagesToSkip + ",";
	} catch ( e ) 
	{
		// Means that top.sPagesToSkip is not defined:
		return false;
	}
	if ( sSkipPages != null &&
		 sSkipPages.length > 0 &&
		 sSkipPages.indexOf("," + nPage + ",") > -1 )
	{
		return true;
	}
	// alert ( "isPageSkipped() did not find page " + nPage 
		  + " in list of pages to skip (\"" + sSkipPages + "\")");
*/
	return false;
}

/* Initializes the top-frame help/hint */
function initHelp()
{
	top.setDefaultText(strDefText);
	top.setSelected(false);
}

/* Methods used by click-up and click-down controls (scrollers or thumbwheels): */
function increment ( control )
{
	addVal ( control, 1 );
}
function decrement ( control )
{
	addVal ( control, -1 );
}
function addVal ( control, value )
{
	var myApplet = getApplet();
	var sValue = control.value;
	if ( sValue != null && sValue.length > 0 )
	{
		// Currency and Percentage value handling:
		var sStart = sValue.substr(0, 1);
		var sAfter = sValue.substr(1);
		var sEnd = sValue.substr(sValue.length - 1);
		var sBefore = sValue.substr(0, sValue.length - 1);
		//alert ( "sStart = '" + sStart + "', sAfter = '" + sAfter + "', sEnd = '" + sEnd + "', sBefore = '" + sBefore + "'" );
		if ( sStart == "$" && ! isNaN ( sAfter ) )
		{
			// Increment/decrement numeric part then add back the currency sign:
			control.value = sStart + " " + (parseInt( trim(sAfter) ) + value);
			
		} else
		if ( sEnd == "%" && ! isNaN ( sBefore ) )
		{
			// Increment/decrement numeric part then add back the percentage sign:
			control.value = (parseInt( trim(sBefore) ) + value) + sEnd;
		} else
		if ( ! isNaN ( sValue ) )
		{
			control.value = parseInt(sValue) + value;
		}
		saveTextValue(myApplet, control);
	}
}

/* Set an option in a Select control to be selected: */
function selectItem( control, selVal )
{
	var selValUpper = selVal.toUpperCase();
	for(var i=0; i < control.options.length; i++)
	{
		if(control.options[i].value.toUpperCase() == selValUpper)
		{
			control.options[i].selected=true;
			return;
		}
	}
}

/* Load a Text control with its value from the Spreadsheet */
function initTextControl ( myApplet, control )
{
	initTextControlFull ( myApplet, control, "" );
}

/* Load a Text control with a Percent-formatted value from the Spreadsheet */
function initTextControlPct ( myApplet, control )
{
	initTextControlFull ( myApplet, control, "Format=Percent" );
}

/* Load a Text control with a value from the Spreadsheet - can specify formatting, as follows:
 * - Comma-separated list (Case Insensitive);
 * - "Round=?", where ? is a number:  # of significant digits to leave in rounding; -99 = no rounding
 * - "Format=Percent" OR "Format=Pct":  specify percent formatting for the value being returned
 * - "Format=Currency" OR "Format=Cur": specify currency formatting for the value being returned
 */
function initTextControlFull ( myApplet, control, sRestrictions )
{
	// Initializes a TextControl's value.
	if ( control == null )
	{
		alert ( "Trying to init. a NULL control !" );
	}
	var sLinked = getLinkedCellValue( control );

	if ( sLinked == null || sLinked.length == 0 )
	{
		alert ( "Cannot init. text control '" + control.name 
			  + "' because control.Linked_Cell is '" + sLinked + "'." );
		return;
	}
	control.value = getCellValueFull ( myApplet, sLinked, sRestrictions );
}

/* Writes a Checkbox control's value to the appropriate cell in the spreadsheet 
 * (two methods:  with and without passed Applet handle) */
function saveCheckboxValueFull ( control )
{
	var myApplet = getApplet(); //top.document.applets.PreView;
	saveCheckboxValue ( myApplet, control );
}
function saveCheckboxValue ( myApplet, control )
{

	var sLinked = getLinkedCellValue( control );

	if ( sLinked == null || sLinked.length == 0 )
	{
		alert ( "Cannot save value of Checkbox control '" + control.name 
			  + "' because control.Linked_Cell is '" + sLinked + "'." );
		return;
	}
	var sValue = 0;
	if ( control.checked )
		sValue = 1;
	//alert ("The OLD value of checkbox '" + control.name + "' is " + getCellValue ( myApplet, sLinked ) );
	//alert ("The NEW value of checkbox '" + control.name + "' is " + sValue );
	if ( sLinked != null && sLinked.length > 0 )
	{
		myApplet.setCellValue ( sLinked, sValue );
	}
}

/* */
function initCheckboxControlFull ( control )
{
	var myApplet = getApplet(); //top.document.applets.PreView;
	initCheckboxControl ( myApplet, control );
}
function initCheckboxControl ( myApplet, control )
{
	var sLinked = getLinkedCellValue( control );
	if ( sLinked == null || sLinked.length == 0 )
	{
		alert ( "Cannot init. Checkbox control '" + control.name 
			  + "' because control.Linked_Cell is '" + sLinked + "'." );
		return;
	}
	var sValue = getCellValue ( myApplet, sLinked );
	var sChecked = true;
	if ( sValue == 0 )
		sChecked = false;
	control.checked = sChecked;
}

/* Toggles the checked state of the specified checkbox, updating the associated
 * text control as appropriate.
 */
function toggleCheckBox(tboxId, cboxId, wsControl)
{
	var tbox;
	var cbox;
	
	if (is.nav6up || is.ie6up)
	{
		tbox = document.getElementById(tboxId);
		cbox = document.getElementById(cboxId);
	}
	else
	{
		tbox = eval("document.mainForm." + tboxId);
		cbox = eval("document.mainForm." + cboxId);
	}
	
	if (cbox.checked == true)
		initTextControl(top.myApplet, wsControl);
	else
	{
		tbox.value = '0';
		saveTextValueFull(wsControl);
	}
	
	tbox.style.backgroundColor = (cbox.checked == true) ? 'white' : '#ddddff';
	tbox.readOnly = (cbox.checked == true) ? false : true;
}

/* Writes a radio control's value to the appropriate cell in the spreadsheet 
 * (two methods:  with and without passed Applet handle) */
function saveRadioValueFull ( control )
{
	var myApplet = getApplet(); //top.document.applets.PreView;
	saveRadioValue ( myApplet, control );
}
function saveRadioValue ( myApplet, control )
{
	// Cycle through the actual radio buttons, to reset 
	//	the spreadsheet value for the non-selected ones 
	//	and set it for the selected one:
	var nIdx;
	for ( nIdx = 0; nIdx < control.length; nIdx++ )
	{
		var ctrlButton = control[nIdx];
		var sLinked = getLinkedCellValue ( ctrlButton );
		if ( sLinked == null || sLinked.length == 0 )
		{
			alert ( "Cannot save value of Radio control '" + ctrlButton.name + "' button " + nIdx
				  + " because control.button.Linked_Cell is '" + sLinked + "'." );
			return;
		}
		var sValue = 0;
		if ( ctrlButton.checked )
			sValue = 1;
		//alert ("The OLD value of Radio '" + ctrlButton.name + "' button " + nIdx + " is " + getCellValue ( myApplet, sLinked ) );
		//alert ("The NEW value of Radio '" + ctrlButton.name + "' button " + nIdx + " is " + sValue );
		myApplet.setCellValue ( sLinked, sValue );
	}
}

/* */
function initRadioControlFull ( control )
{
	var myApplet = getApplet(); //top.document.applets.PreView;
	initRadioControl ( myApplet, control );
}
function initRadioControl ( myApplet, control )
{
	// Cycle through the actual radio buttons, to set 
	//	them to the spreadsheet values:
	var nIdx;
	for ( nIdx = 0; nIdx < control.length; nIdx++ )
	{
		var ctrlButton = control[nIdx];
		var sLinked = getLinkedCellValue ( ctrlButton );
		if ( sLinked == null || sLinked.length == 0 )
		{
			alert ( "Cannot set value of Radio control '" + ctrlButton.name + "' button " + nIdx 
				  + " because control.button.Linked_Cell is '" + sLinked + "'." );
			return;
		}
		var sValue = getCellValueFull ( myApplet, sLinked, "");
		if ( sValue == 0 )
			ctrlButton.checked = false;
		else
			ctrlButton.checked = true;
		//alert ("The value of Radio '" + ctrlButton.name + "' button " + nIdx + " is " + sValue );
	}
}


/* Retrieves the specific cell's value from the Applet; sLink specifies the (linked) cell */
function getCellValue ( myApplet, sLink )
{
	return getCellValueFull ( myApplet, sLink, "");
}

/* Retrieves the specific cell's value from the Applet, with formatting restrictions; 
 * sLink specifies the (linked) cell; sRestrictions is as follows:
 * - Comma-separated list (Case Insensitive);
 * - "Round=?", where ? is a number:  # of significant digits to leave in rounding; -99 = no rounding
 * - "Format=Percent" OR "Format=Pct":  specify percent formatting for the value being returned
 * - "Format=Currency" OR "Format=Cur": specify currency formatting for the value being returned
 */
function getCellValueFull ( myApplet, sLink, sRestrictions )
{
	if ( sLink == null )
	{
		alert ( "getCellValueFull called with sLink == null -- will return empty string." );
		return "";
	}
	if ( sLink.length == 0 )
	{
		alert ( "getCellValueFull called with sLink = empty string -- will return empty string." );
		return "";
	}

	var sValue = myApplet.getCellValueNew ( sLink, sRestrictions );

	if ( sValue == null )
	{
		//alert ( "getCellValueNew('" + sLink + "', '" + sRestrictions + "') returned NULL!" );
		return "";
	}
	sValue = new String(sValue);
	if ( sValue.indexOf("EXCEPTION THROWN IN APPLET:") != -1)
	{
		sValue = "";
	}

	if( sValue.indexOf( "$" ) > -1 )
	{
		sValue = new String( exchangeRateConversion( myApplet, sValue, sRestrictions ) );
	}

	return sValue;
}


// Griz


function exchangeRateConversion( myApplet, sValue, sRestrictions )
{
	rVal = sValue;
	var currencySymbol = new String( myApplet.getCellValueNew ( "CurrencySymbol", "" ) );
	var exchangeRate = myApplet.getCellValueNew ( "ExchangeRate", "Round=5" );

	// Convert to US currency	
	if( sValue.indexOf( currencySymbol.charAt(0) ) > -1 && exchangeRate != "1"  )
	{
		// Debug
		// alert( "Convert to US currency" );

		// Remove currency symbol and commas
		sValue = RemoveCommas( sValue.substring( sValue.indexOf( currencySymbol.charAt(0) ) + 1, sValue.length ) );


		// Calculate and Format number
		rVal = new String( parseFloat( sValue ) / parseFloat(exchangeRate) );

		rVal = "$ " + rVal;
	}

	// Convert to Foreign Currency
	if( sValue.indexOf('$') > -1 && exchangeRate != "1" )
	{
		// Debug
		// alert( "Convert to Foreign Currency" );

		// Remove currency symbol and commas
		sValue = RemoveCommas( sValue.substring( sValue.indexOf('$') + 1, sValue.length ) );

		// Calculate and Format number
		rVal = new String( parseFloat(exchangeRate) * parseFloat( sValue ) );

		rVal = currencySymbol + " " + formatCurrency( rVal, sRestrictions );
	}

	return rVal;
}

/* Strips all commas from a string */
function RemoveCommas( sValue )
{
	var rVal = sValue;

	if( sValue.indexOf( ',' ) > -1 )
	{
		rVal = "";
		// Look for all characters that are not commas
		for( i = 0; i < sValue.length; i++ )
		{
			if( sValue.charAt( i ) != ',' )
				rVal += sValue.charAt( i );
		}
	}
	return rVal;
}


/* Formats a number string to include commas and the such. As of right now
 * this is only intended for currency values. */
function formatCurrency( sValue, sRestrictions )
{
	//Debug statement
	//alert( "Format Currency: " + sRestrictions );

	var splitRestrictions = sRestrictions.split(',');
	var rounded = false;


	// Check for formatting restrictions
	for( i = 0; i < splitRestrictions.length; i++ )
	{
		var args = splitRestrictions[i].split('=');

		// Round if needed
		if( args[0].toLowerCase() == "round" )
		{
			var multiplier;
			multiplier = Math.pow( 10, parseInt(args[1]) );
			sValue = Math.round(sValue * multiplier) / multiplier;
			rounded = true;
		}
	}

	// If there is a remainder strip it off in preperation for the next set of operations
	var remainder = new String( sValue );
	if( sValue >= 1 && remainder.indexOf('.') > -1 && rounded == true )
	{
		remainder = remainder.substring( remainder.indexOf('.'), remainder.length );
	}
	else
	{
		remainder = "";
	}


	// Add commas to the string
	var formatted = "";
	if( sValue >= 1 )
	{
		sValue = new String (Math.round( sValue ))
		for( i = 0; i < sValue.length; i ++ )
		{
			formatted += sValue.charAt(i);
	
			var left = (sValue.length - (i + 1));
			if( left != 0 && left % 3 == 0 )
				formatted += ',';
		}

		sValue = formatted + remainder; // Recombine formatted string remainder
	}

	return sValue;
}
// Griz  


/* Get a delimited list of values, from a range of cells.
 * sRange must be in the format, "[SHEETNAME]![COL][ROW]:[COL][ROW]", e.g. "CHARTS!C13:D14".
 * Returns a | delimited list of cell names, in the format "[SHEETNAME]![COL][ROW], 
 * e.g. "CHARTS!C13|CHARTS!C14|CHARTS!D13|CHARTS!D14" 				*/
function getCellRangeValues ( myApplet, sRange )
{
	var sDelim = "|";
	//alert ( "Calling:  myApplet.getRangeList ( '" + sRange + "', '" + sDelim + "' )" );
	var sValues = myApplet.getRangeList ( sRange, sDelim );
	//alert ( "myApplet.getRangeList ( ... ) returned: '" + sValues + "'" );
	return sValues;
}
function getCellRangeValuesFull ( sRange )
{
	var myApplet = getApplet ();
	return getCellRangeValues ( myApplet, sRange );
}

/* Initializes a <SELECT> control as needed, determining whether it needs loading or just defaulting */
function initSelectControl ( myApplet, control )
{
	// Initializes a control of type SELECT.
	// Some instances will require clearing and re-loading the OPTIONs
	// for the SELECT, others won't need any work.
	var sLinkedValues = control.Linked_Values_Cell;
	var sLinked = getLinkedCellValue( control );

	if ( sLinkedValues == null || sLinkedValues.length == 0 )
	{
		if ( sLinked == null )
		{
			alert ( "Cannot init. Select control '" + control.name 
				  + "' because control.Linked_Cell is '" + sLinked + "'." );
			return;
		}
		// just set the default:
		var sDefault = getCellValueFull ( myApplet, sLinked, "Round=5" );
		selectItem ( control, sDefault );
	}
	else
	{
		// remove any existing OPTIONs, and add in new ones:
		if ( control.options.length > 0 )
		{
			while ( control.options.length > 0 )
			{
				control.options.remove ( 0 );
			}
		}
		// Retrieve and add the options:
		var sLinkedChoices = control.Linked_Choices_Cell;
		if ( sLinkedChoices == null || sLinkedChoices.length == 0 )
		{
			alert ( "Cannot init. Select control '" + control.name 
				  + "' because control.Linked_Choices_Cell is '" + sLinkedChoices + "'." );
			return;
		}
		var sLinkedDefault = control.Linked_Defaults_Cell;
		if ( sLinkedDefault == null || sLinkedDefault.length == 0 )
		{
			alert ( "Cannot init. Select control '" + control.name 
				  + "' because control.Linked_Defaults_Cell is '" + sLinkedDefault + "'." );
			return;
		}
		var sValues        = getCellValue ( myApplet, sLinkedValues );
		var sChoices       = getCellValue ( myApplet, sLinkedChoices );
		var sDefaultValue  = getCellValueFull ( myApplet, sLinkedDefault, "Round=-99" ).toUpperCase();
		//alert ( "sDefaultValue = " + sDefaultValue );

		var nValues1 = myApplet.getRangeSize ( sValues );
		var nValues2 = myApplet.getRangeSize ( sChoices );
		
		// Should be identical, but just in case take the least of the two:
		if ( nValues2 < nValues1 ) nValues1 = nValues2;
		var nX;
		var sValue;
		var sCaption;
		for ( nX = 1; nX <= nValues1; nX++ )
		{
			sValue	 = myApplet.getRangeItem ( sValues,  nX );
			sCaption = myApplet.getRangeItem ( sChoices, nX );
			if ( sValue == null || sValue.length == 0 )
			{
				alert ( "Cannot completely init. Select control '" + control.name 
					  + "' Option # " + nX + " because the corresponding Values Range item is '" + sValue + "'." );
			} else
			if ( sCaption == null || sCaption.length == 0 )
			{
				alert ( "Cannot completely init. Select control '" + control.name 
					  + "' Option # " + nX + " because the corresponding Captions Range item is '" + sCaption + "'." );
			} else
			{
				sValue	 = getCellValueFull ( myApplet, sValue, "Round=5" );
				//alert ( "sValue (" + nX + ") = " + sValue );
				sCaption = getCellValueFull ( myApplet, sCaption, "Round=5" );
				//alert ( "sCaption (" + nX + ") = " + sCaption );
				// Add new option:
				var oNew = new Option ( sCaption, sValue );
				control.options[control.options.length] = oNew;
				//control.options.add ( oNew, nX - 1 );
				// Check if it's the default:
				if ( sValue.toUpperCase() == sDefaultValue )
					control.options[nX - 1].selected = true;
			}
		}
	}
}

/* [OBS] Retrieves the hint for the specified control, and displays it in the top frame */
function setHint ( control )
{
	var sHint = getHintFull ( control );
	top.setHelpText ( sHint ); 
	top.setSelected ( true );
}

/* Returns the hint for the specified control (two methods:  with and without passed Applet handle) */
function getHintFull ( control )
{
	var myApplet = getApplet(); //top.document.applets.PreView;
	var hint = getHint ( myApplet, control );

	
	if ((hint == null) || (hint == ""))
		hint = "No help available.";
	
	return hint;
}
function getHint ( myApplet, control )
{
	// Retrieves the hint from a control, either from the spreadsheet
	// or directly in the control itself.
	var sHint = null;
	var sHintType = "true";//getHintType ( control );

	if ( sHintType.toLowerCase() == "false" )
	{ // Retrieve from the spreadsheet:

		var sLinked;
		sLinked = getHintCell ( control );
		if ( sLinked == null )
		{
			//alert ( "Cannot retrieve Hint for control '" + control.name 
			//	  + "' because control.hintCell is null." );
			return "";
		}
		sHint = getCellValue ( myApplet, sLinked );
	} 
	else 
	{ // Retrieve from the control itself:

		sHint = control.hint;
		if ( sHint != null )
		{
			var sHintExtra = control.hint2;
			if ( sHintExtra != null && sHintExtra.length > 0 )
				sHint = sHint + sHintExtra;
			sHintExtra = control.hint3;
			if ( sHintExtra != null && sHintExtra.length > 0 )
				sHint = sHint + sHintExtra;
			sHintExtra = control.hint4;
			if ( sHintExtra != null && sHintExtra.length > 0 )
				sHint = sHint + sHintExtra;
			sHintExtra = control.hint5;
			if ( sHintExtra != null && sHintExtra.length > 0 )
				sHint = sHint + sHintExtra;
		}
	}
	if ( sHint == null )
		return "";
	return sHint;
}

/* Takes a Text control's value that is a percent, whether with a trailing % or not, and
 * writes it to the appropriate cell in the spreadsheet (two methods:  with and without 
 * passed Applet handle) */
function saveTextValuePctFull ( control )
{
	var myApplet = getApplet(); //top.document.applets.PreView;
	saveTextValuePct ( myApplet, control );
}
function saveTextValuePct ( myApplet, control )
{
	if ( control == null )
		return;
	var sValue = trim ( control.value );
	if ( sValue != null )
	{
		var sEnd = sValue.substr(sValue.length - 1);
		var sBefore = sValue.substr(0, sValue.length - 1);

		if ( sValue.substr(sValue.length - 1) != "%" )
		{
			control.value = sValue + "%";
		}		
	}
	saveTextValue ( myApplet, control );
}

/* Writes a Text control's value to the appropriate cell in the spreadsheet 
 * (two methods:  with and without passed Applet handle) */
function saveTextValueFull ( control )
{
	var myApplet = getApplet(); //top.document.applets.PreView;
	saveTextValue ( myApplet, control );
}
function saveTextValue ( myApplet, control )
{
	var sLinked = getLinkedCellValue( control );
	if ( sLinked == null || sLinked.length == 0 )
	{
		alert ( "Cannot save value of Text control '" + control.name 
			  + "' because control.Linked_Cell is '" + sLinked + "'." );
		return;
	}
	var sValue = exchangeRateConversion( myApplet, control.value, "" );	// Griz

	var bChanged = false;	// True if we need to re-update the control's value after saving
	var sFormat = "";

	if ( sLinked != null && sLinked.length > 0 )
	{
		// Currency and Percentage value handling:
		var sStart = sValue.substr(0, 1);
		var sAfter = sValue.substr(1);
		var sEnd = sValue.substr(sValue.length - 1);
		var sBefore = sValue.substr(0, sValue.length - 1);
		//alert ( "sStart = '" + sStart + "', sAfter = '" + sAfter + "', sEnd = '" + sEnd + "', sBefore = '" + sBefore + "'" );
		if ( sStart == "$" && ! isNaN ( sAfter ) )
		{
			sValue = trim ( sAfter );
			bChanged = true;
			sFormat = "Format=Currency";
		} else
		if ( sEnd == "%" && ! isNaN ( sBefore ) )
		{
			var sNewValue = trim ( sBefore );
			sValue = (sNewValue / 100);
			bChanged = true;
			sFormat = "Format=Percent";
		}
		if ( isNaN ( sValue ) )
		{
			//alert ( "Value '" + sValue + "' is not a number - bounds checks will not be performed." );
		} else
		{
			// Check bounds:
			var sUpper = control.maxval;
			var sLower = control.minval;
			var bNotify = true;	// default
			if ( control.minmaxnotify != null )
			{
				bNotify = control.minmaxnotify;
			}
			//alert ( "bNotify = " + bNotify + " because control.minmaxnotify = " + control.minmaxnotify );
			if ( sUpper != null && parseFloat(sUpper) < parseFloat(sValue) )
			{
				if ( bNotify == true )
				{
					alert ( "Warning, you entered a value out of bounds (" + sValue 
						+ ") - it will be replaced with the maximum value allowed ("
						+ sUpper + ")." );
				}
				sValue = sUpper;
				bChanged = true;
			} else
			if ( sLower != null && parseFloat(sLower) > parseFloat(sValue) )
			{
				if ( bNotify == true )
				{
					alert ( "Warning, you entered a value out of bounds (" + sValue 
						+ ") - it will be replaced with the minimum value allowed ("
						+ sLower + ")." );
				}
				sValue = sLower;
				bChanged = true;
			}
		}
		myApplet.setCellValue ( sLinked, sValue );	
		if ( bChanged )
		{	// Reload value from spreadsheet, since we had to change it on the way in:
			initTextControlFull ( myApplet, control, sFormat );
		}
	}
}

/* Writes a Select control's selected value to the appropriate cell in the spreadsheet 
 * (two methods:  with and without passed Applet handle) */
function saveSelectValueFull ( control )
{
	var myApplet = getApplet(); //top.document.applets.PreView;
	saveSelectValue ( myApplet, control );
}
function saveSelectValue ( myApplet, control )
{
	var sLinked = getLinkedCellValue( control );
	if ( sLinked == null || sLinked.length == 0 )
	{
		alert ( "Cannot save value of Select control '" + control.name 
			  + "' because control.Linked_Cell is '" + sLinked + "'." );
		return;
	}

	if ( sLinked != null && sLinked.length > 0 )
	{
		//alert ( "Saving value for control " + control.name + " to cell " + sLinked );
		myApplet.setCellValue ( sLinked, control.options[control.selectedIndex].value );
	}
}

/* This function gets the value stored in the Linked_Cell property even if the tag
 * does not conform to our coding standard case. It will find one of 4 occurences */
function getLinkedCellValue( control )
{
	var sLinked = control.Linked_Cell;

	if ( sLinked == null ) {
		sLinked = control.linked_cell;
	}
	if ( sLinked == null ) {
		sLinked = control.Linked_cell;
	}
	if ( sLinked == null ) {
		sLinked = control.linked_Cell;
	}
	return sLinked;
}

/* This function gets the value stored in the HintType property even if the tag
 * does not conform to our coding standard case. It will find one of 4 occurences */
function getHintType( control )
{
	var sHintType = control.HintType;

	if ( sHintType == null ) {
		sHintType = control.hinttype;
	}
	if ( sHintType == null ) {
		sHintType = control.Hinttype;
	}
	if ( sHintType == null ) {
		sHintType = control.hintType;
	}
	return sHintType;
}

/* This function gets the value stored in the HintCell property even if the tag
 * does not conform to our coding standard case. It will find one of 4 occurences */
function getHintCell( control )
{
	var sHintCell = control.HintCell;

	if ( sHintCell == null ) {
		sHintCell = control.hintCell;
	}
	if ( sHintCell == null ) {
		sHintCell = control.Hintcell;
	}
	if ( sHintCell == null ) {
		sHintCell = control.hintcell;
	}
	return sHintCell;
}

/** ltrim = Left trim, rtrim = right trim, trim - remove spaces on the left,
  * right, and both sides of the passed string, respectively 
  */
function trim ( str )
{
	return ltrim ( rtrim ( str ) );
}

function ltrim ( str )
{
	while ( str.charAt(0) == ' ' )
		str = str.substr ( 1 );
	return str;
}

function rtrim ( str )
{
	var nPos = str.length;
	while ( str.charAt(nPos - 1) == ' ' )
	{
		nPos-- ;
	}
	return str.substr ( 0, nPos );
}


function Test()
{
	alert("Success");
}
///////////////////////////////////////////////////////////////////////////////////
//
// The following section is being added to this file for use with web site tracking
//
///////////////////////////////////////////////////////////////////////////////////

//
// QueryString
//
/*
function QueryString(key)
{
alert( "there" );
     //var value = null;

   // QueryString.keys = new Array();
   // QueryString.values = new Array();

//keys = new Array();
//values = new Array();

   // QueryString_Parse( QueryString.keys, QueryString.values );


//     for (var i = 0; i < QueryString.keys.length; i++)
//     {
//          if ( QueryString.keys[i] == key )
//          {
//               value = QueryString.values[i];
//               break;
//          }
//     }
    //return value;
}


function QueryString_Parse( QueryString.keys, QueryString.values )
{
     var query = window.location.search.substring(1);
     var pairs = query.split("&");
     
     for (var i = 0; i < pairs.length; i++)
     {
          var pos = pairs[i].indexOf('=');

          if ( pos >= 0 )
          {
               var argname = pairs[i].substring(0,pos);
               var value = pairs[i].substring(pos+1);
               QueryString.keys[QueryString.keys.length] = argname;
               QueryString.values[QueryString.values.length] = value;          
          }
     }

}*/