//=============================================================================================================
// File:		ucbUtilities.js
// Purpose: 	Some simple utility functions
// Author:		JDH/1999-2002

// Function:	SmallCaps
// Purpose: 	Builds a small caps HTML string out of the specified input string.  The small font size
//				specifies the size of the small font.  The large font is at the current size.
// Arguments:	inputString - The string to turn into small caps
//				nFontSize - The font size to use for lower case letters.
//
function SmallCaps( inputString, nSmallFontSize )
{
	s = "";
	bInSmall = false
	for( nChar = 0; nChar < inputString.length; nChar++ )
	{
		if ( inputString.charAt( nChar ) >= 'a' && inputString.charAt( nChar ) <= 'z' )
		{
			if ( !bInSmall )
			{
				bInSmall = true;
				s = s + "<span style=font-size:" + nSmallFontSize + "pt>";
			}
			s = s + inputString.charAt( nChar ).toUpperCase();
		}
		else
		{
			if ( bInSmall )
			{
				bInSmall = false;
				s = s + "</span>";
			}
			s = s + inputString.charAt( nChar );
		}
	}
	if ( bInSmall )
		s = s + "</span>";
	return s;
}

// Class:		StaticText
// Purpose: 	Portable static text object.  In IE this renders a <DIV> tag and then alters
//				the text dynamically through the DOM.  In NetScape this puts in an edit
//				text field and fills the value dynamically.
// Arguments:	variableName - The name of the variable
//				formName - The name of the form this is contained in.  (In Netscape input
//					will not be built if they have no containing form.)
//				width - The width (in characters) of the field.  (Not used in IE)
//
function StaticText( variableName, formName, width )
{
	this.variableName = variableName;
	this.width = width;
	this.formName = formName;

	// Poll the system version to find out the capabilities of this browser 
	// (from Hamilton Meyer.)
    this.NS = (navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) >= 3);
    this.MSIE = (navigator.appName == 'Microsoft Internet Explorer') && (parseInt(navigator.appVersion) >= 4);
    this.MACIE = (navigator.appName == 'Microsoft Internet Explorer') && (navigator.appVersion.indexOf('Macintosh') != -1);
}

// Function:	Place
// Purpose: 	Places the static text item in the HTML document by doing document.write.
// Arguments:	None
//
StaticText.prototype.Place = function( )
{
	if ( this.MSIE )
	{
		UCBBodyWrite( "<div ID=\"" + this.variableName + "\"></div>" );
	}
	else if ( this.NS )
	{
		UCBBodyWrite( "<input type=\"text\" size=" + this.width + " name=\"" + this.variableName + "\">" );
	}
}

// Function:	SetValue
// Purpose: 	Sets the static text variable.
// Arguments:	newValue - The new value of the item
//
StaticText.prototype.SetValue = function( newValue )
{
	if ( this.MSIE )
	{
		var s = this.variableName + ".innerText = '" + newValue + "';";
		eval( s );
	}
	else if ( this.NS )
	{
		document[ this.formName ][ this.variableName ].value = newValue;
	}
}

function UCBBodyWrite( HTMLText )
{
	document.write( HTMLText );
}

function UCBGetBodyDocument( )
{
	return document;
}

function UCBGetBodyDocumentName()
{
	return "document";
}
