
//
// Begin class HTImg
//

function HTImg()
{
	this.sAltText   = ''
	this.sSrc       = ''
	this.nBorder    = 0
	this.sAlign     = ''
	this.sWidth     = ''
	this.sHeight    = ''
	this.sTitle     = ''

	this.sName      = '' // The link's HTML "name" attribute
	this.sID         = ''
}

// Function for generating an image reference
// If sAttributes is specified, it adds ADDITIONAL attributes to the image
HTImg.prototype.getHTML = function( sAttributes )
{
	var sHTML = (isEmptyString(sAttributes) ? '' : sAttributes)

	// NOTE: We can't put the border=0 into style sheets
	//       because it doesn't work in NN4
	sHTML += ' src="' + HtmlEncode(this.sSrc) + '" border="' + this.nBorder + '"'

	// Add alt text
	sHTML += ' alt="' + HtmlEncode(this.sAltText) + '"'

	if ( !isEmptyString(this.sName) )
		sHTML += ' name="' + HtmlEncode(this.sName) + '"'
	if ( !isEmptyString(this.sID) )
		sHTML += ' id="' + HtmlEncode(this.sID) + '"'
	if ( !isEmptyString(this.sAlign) )
		sHTML += ' align="' + HtmlEncode(this.sAlign) + '"'
	if ( !isEmptyString(this.sWidth) )
		sHTML += ' width="' + HtmlEncode(this.sWidth) + '"'
	if ( !isEmptyString(this.sHeight) )
		sHTML += ' height="' + HtmlEncode(this.sHeight) + '"'
	if ( !isEmptyString(this.sTitle) )
		sHTML += ' title="' + HtmlEncode(this.sTitle) + '"'

	// Build the full IMG reference
	sHTML = '<img ' + sHTML + '>'

	return sHTML
}

function getHTImgHTML( sSrc, nBorder, sAltText, sAlign, sWidth, sHeight, sName, sID )
{
	var img = new HTImg();

	img.sSrc       = sSrc;
	img.nBorder    = ( nBorder == null ? 0 : nBorder );
	img.sAltText   = ( sAltText == null ? '' : sAltText );
	img.sAlign     = ( sAlign == null ? '' : sAlign );
	img.sWidth     = ( sWidth == null ? '' : sWidth );
	img.sHeight    = ( sHeight == null ? '' : sHeight );
	img.sName      = ( sName == null ? '' : sName );
	img.sID        = ( sID == null ? '' : sID );

	return img.getHTML();
}

//
// Begin class HTLink
//

function HTLink()
{
	this.sText       = ''
	this.sHTML       = '' // Overrides sText when specified
	this.sHREF       = ''
	this.sTarget     = ''
	this.sStatusMsg  = ''
	this.sTitle      = ''

	this.sImg        = ''
	this.sImgAlign   = ''
	this.sImgAltText = ''

	this.sName       = '' // The link's HTML "name" attribute
	this.sID         = ''
}

// Function for generating a hypertext link
// If sAttributes is specified, it adds ADDITIONAL attributes to the anchor
HTLink.prototype.getHTML = function( sAttributes, sImgAttributes )
{
	var sHTML = '';

	// Check if this is a text link or an image link.
	var sObjectToLink     = '';
	if ( isEmptyString( this.sImg ) )
	{
		if ( isEmptyString( this.sHTML ) )
			sObjectToLink = HtmlEncode(this.sText);
		else
			sObjectToLink = this.sHTML;
	}
	else
	{
		// NOTE: We can't put the border=0 into style sheets
		//       because it doesn't work in NN4
		var objImg = new HTImg()
		objImg.sSrc     = this.sImg
		objImg.sAlign   = this.sImgAlign
		if ( isEmptyString( this.sImgAltText ) )
			objImg.sAltText = this.sText
		else
			objImg.sAltText = this.sImgAltText
		sObjectToLink = objImg.getHTML(sImgAttributes)
	}

	// If there is no HREF, then we simply output the text
	// or image tag.
	var sHREF = this.sHREF;
	if ( isEmptyString(sHREF) )
		sHTML = sObjectToLink;
	else 
	{
		// Set up the remaining attributes
		var sAnchorAttributes = (isEmptyString(sAttributes) ? '' : sAttributes);
		sAnchorAttributes += ' href="' + HtmlEncode(sHREF) + '"';
		if (!isEmptyString(this.sTarget))
			sAnchorAttributes += ' target="' + this.sTarget + '"';
		if (!isEmptyString(this.sID))
			sAnchorAttributes += ' id="' + this.sID + '"';
		if (!isEmptyString(this.sName))
			sAnchorAttributes += ' name="' + this.sName + '"';
		if (!isEmptyString(this.sTitle))
			sAnchorAttributes += ' title="' + HtmlEncode(this.sTitle) + '"';

		// Add status line mouseover/mouseout attributes
		if (isEmptyString(this.sStatusMsg))
			sAnchorAttributes += ' onmouseover="window.status=\'\';return true"'
		else
			sAnchorAttributes += ' onmouseover="window.status=\'' + this.sStatusMsg + '\';return true"'
			                    + ' onmouseout="window.status=\'\';return true"'

		// Wrap the anchor tag
		sHTML = '<a ' + sAnchorAttributes + '>' + sObjectToLink + '</a>';
	}

	return sHTML;
}

function LinkArray()
{
	this.arLinks = new Array();
}

LinkArray.prototype.clear = function()
{
	this.arLinks.length = 0;
}

LinkArray.prototype.getNumLinks = function()
{
	return this.arLinks.length;
}

LinkArray.prototype.addLink = function( objLink )
{
	this.arLinks[this.arLinks.length] = objLink;
}

LinkArray.prototype.getLink = function( i )
{
	if ( (i < 0) || (i > this.arLinks.length) ) 
		return null;

	return this.arLinks[i];
}

//
// Begin class HTInput
//

function HTInput()
	{
	this.sType = 'text'
	this.sName = ''
	this.sValue = ''
	this.nSize = ''
	this.nMaxLength = ''
	this.sID = ''
	this.sTitle = ''

	this.onFocus = null
	this.onBlur = null
	this.onClick = null
	}

HTInput.prototype.getHTML = function( sAttributes )
	{
	var sHTML = '<input type="' + this.sType + '"'
	                + ' name="' + HtmlEncode(this.sName) + '"'
					+ ' id="' + ((!isEmptyString(this.sID)) ? HtmlEncode(this.sID) : HtmlEncode(this.sName)) + '"'
					+ ' title="' + ((!isEmptyString(this.sTitle)) ? HtmlEncode(this.sTitle) : '') + '"'
	                + ' value="' + HtmlEncode(this.sValue) + '"'
	                + ((this.nSize > 0) ? ' size="' + this.nSize + '"' : '')
	                + ((this.nMaxLength > 0) ? ' maxlength="' + this.nMaxLength + '"' : '')
	                + ((!isEmptyString(this.onFocus)) ? ' onFocus="' + this.onFocus + '"' : '')
	                + ((!isEmptyString(this.onBlur)) ? ' onBlur="' + this.onBlur + '"' : '')
	                + ((!isEmptyString(this.onClick)) ? ' onClick="' + this.onClick + '"' : '')
	                + ((!isEmptyString(sAttributes)) ? (' ' + sAttributes) : '')
	                + '>\n'

	return sHTML
	}

function getHTInputHTML( type, name, value, attributes )
	{
	input = new HTInput()
	input.sType     = type
	input.sName     = name
	input.sValue    = value

	return input.getHTML(attributes)
	}

function HTSelect()
	{
	this.sName     = ''
	this.sValue    = ''
	this.nSize     = 0
	this.fMultiple = false
	this.sID       = ''
	this.sTitle    = ''

	this.aValues   = null;
	this.aLabels   = null;

	this.onChange = null
	}

HTSelect.prototype.getHTML = function( sAttributes )
	{
	var htm = '<select'
	          + ' name="' + HtmlEncode(this.sName) + '"'
	          + ' id="' + ((!isEmptyString(this.sID)) ? HtmlEncode(this.sID) : HtmlEncode(this.sName)) + '"'
	          + ' title="' + ((!isEmptyString(this.sTitle)) ? HtmlEncode(this.sTitle) : '') + '"'
	          + ((this.nSize > 0) ? ' size="' + this.nSize + '"' : '')
	          + ((this.fMultiple) ? ' multiple' : '')
	          + ((!isEmptyString(this.onChange)) ? ' onChange="' + this.onChange + '"' : '')
	          + ((!isEmptyString(sAttributes)) ? (' ' + sAttributes) : '')
	          + '>\n'

	for ( var i=0; i < this.aLabels.length; i++ )
		{
		var val = this.aLabels[i];
		if ( (this.aValues != null) && (this.aValues[i] != null) )
			val = this.aValues[i];

		var selected = '';
		if ( (this.sValue != null) && (this.sValue == val) )
			selected = ' selected';

		htm += '<option' + selected + ' value="' + HtmlEncode(val) + '">' + HtmlEncode( this.aLabels[i] ) + '</options>\n';
		}

	htm += '</select>\n';

	return htm;
	}