
// DHTML support utilities

function ecsToIE( div, left, top, width, height )
{
	var		s = div.style;

	s.pixelTop = top;
	s.pixelLeft = left;
	s.pixelWidth = width;
	s.pixelHeight = height;
}

function ecsToNS( div, left, top, width, height )
{
	div.moveTo( left, top );
	div.resizeTo( width, height );
}

function ecsMoveIE( div, left, top )
{
	var		s = div.style;

	if ( s.pixelTop )
	{
		// IE only

		s.pixelTop = top;
		s.pixelLeft = left;
	}
	else
	{
		s.left = left;
		s.top = top;
	}
}

function ecsMoveNS( div, left, top )
{
	div.moveTo( left, top );
}

function ecsSizeIE( div, width, height )
{
	var		s = div.style;

	s.pixelWidth = width;
	s.pixelHeight = height;
}

function ecsSizeNS( div, width, height )
{
	div.resizeTo( width, height );
}

function ecsMoveByIE( div, left, top )
{
	var		s = div.style;

	s.pixelTop += top;
	s.pixelLeft += left;
}

function ecsMoveByNS( div, left, top )
{
	div.moveBy( left, top );
}

function ecsByIE( div, left, top, width, height )
{
	var		s = div.style;

	s.pixelTop += top;
	s.pixelLeft += left;
	s.pixelWidth += width;
	s.pixelHeight += height;
}

function ecsByNS( div, left, top, width, height )
{
	div.moveBy( left, top );
	div.resizeBy( width, height );
}

function ecsShowIE( div )
{
	var		s = div.style;

	s.visibility = "visible";
	s.display = "";
}

function ecsShowNS( div )
{
	div.visibility = "show";
}

function ecsHideIE( div )
{
	var		s = div.style;

	s.visibility = "hidden";
	s.display = "none";
}

function ecsHideNS( div )
{
	div.visibility = "hide";
}

function ecsAboveIE( div1, div2 )
{
	div1.style.zIndex = div2.style.zIndex + 1;
}

function ecsAboveNS( div1, div2 )
{
	div1.zIndex = div2.zIndex + 1;
}

function ecsDivNS( name )
{
	return ecsDivNS2( name, document.layers );
}

function ecsDivNS2( name, layers )
{
	var	i;

	var	div = null;

	for ( i = 0; i < layers.length; i++ )
	{
		if ( name == layers[ i ].id )
		{
			div = layers[ i ];
			break;
		}
	}

	if ( div == null )
	{
		for ( i = 0; i < layers.length; i++ )
		{
			div = ecsDivNS2( name, layers[ i ].document.layers )

			if ( div != null )
			{
				break;
			}
		}
	}

	return div;
}

function ecsDivIE( name )
{
	return document.getElementById( name );
}

function ecsImgNS( name )
{
	return ecsImgNS2( name, document );
}

function ecsImgNS2( name, doc )
{
	var	i;

	var	img = null;

	if ( doc.images )
	{
		for ( i = 0; i < doc.images.length; i++ )
		{
			if ( name == doc.images[ i ].name )
			{
				img = doc.images[ i ];
				break;
			}
		}
	}

	if ( img == null )
	{
		for ( i = 0; i < doc.layers.length; i++ )
		{
			img = ecsImgNS2( name, doc.layers[ i ].document )

			if ( img != null )
			{
				break;
			}
		}
	}

	return img;
}

function ecsStyleIE( name )
{
	return ecsDiv( name ).style;
}

function ecsWriteNS( name, text )
{
	var		div = ecsDiv( name );
	var		doc = div.document;

	doc.open();
	doc.write( text );
	doc.close();
}

function ecsWriteIE( name, text )
{
	ecsDiv( name ).innerHTML = text;
}

function ecsWriteDivNS( div, text )
{
	var		doc = div.document;

	doc.open();
	doc.write( text );
	doc.close();
}

function ecsWriteDivIE( div, text )
{
	div.innerHTML = text;
}

ecsMoveBy   = (ECS__IE || ECS__NS7) ? ecsMoveByIE : ecsMoveByNS;
ecsTo       = (ECS__IE || ECS__NS7) ? ecsToIE : ecsToNS;
ecsSize	    = (ECS__IE || ECS__NS7) ? ecsSizeIE : ecsSizeNS;
ecsMove	    = (ECS__IE || ECS__NS7) ? ecsMoveIE : ecsMoveNS;
ecsBy       = (ECS__IE || ECS__NS7) ? ecsByIE : ecsByNS;
ecsShow     = (ECS__IE || ECS__NS7) ? ecsShowIE : ecsShowNS;
ecsHide     = (ECS__IE || ECS__NS7) ? ecsHideIE : ecsHideNS;
ecsAbove    = (ECS__IE || ECS__NS7) ? ecsAboveIE : ecsAboveNS;
ecsDiv      = (ECS__IE || ECS__NS7) ? ecsDivIE : ecsDivNS;
ecsStyle    = (ECS__IE || ECS__NS7) ? ecsStyleIE : ecsDivNS;
ecsImg      = (ECS__IE || ECS__NS7) ? ecsDivIE : ecsImgNS;
ecsWrite    = (ECS__IE || ECS__NS7) ? ecsWriteIE : ecsWriteNS;
ecsWriteDiv = (ECS__IE || ECS__NS7) ? ecsWriteDivIE : ecsWriteDivNS;

function ecsVisible( div, state )
{
	if ( state )
	{
		ecsShow( div );
	}
	else
	{
		ecsHide( div );
	}
}

function ecsExpandCollapse( div )
{
	ecsVisible( div, !ecsIsVisible( div ) )
}

//-----------------------------------------------------------------------------
// Layer visibility.
//-----------------------------------------------------------------------------

function ecsHideLayer( div )
{
	if ( ECS__NS )
	{
		div.visibility = "hide";
	}
	else
	{
		div.style.visibility = "hidden";
	}
}

function ecsShowLayer( div )
{
	if ( ECS__NS )
	{
		div.visibility = "show";
	}
	else
	{
		div.style.visibility = "visible";
	}
}

function ecsIsVisible( div )
{
	if ( ECS__NS )
	{
		return ( div.visibility == "show" );
	}
	else
	{
		return ( ( div.style.visibility == "visible" ) || ( div.style.visibility == "" ) );
	}
}

//-----------------------------------------------------------------------------
// Layer positioning.
//-----------------------------------------------------------------------------

function ecsMoveLayerTo( div, x, y )
{
	div.style.left = x;
	div.style.top = y;
}

function ecsMoveLayerBy( div, dx, dy )
{
	if ( ECS__NS )
	{
		div.style.left = ecsGetLeft( div ) + dx;
		div.style.top = ecsGetTop( div ) + dy;
	}
	else
	{
		div.style.pixelLeft += dx;
		div.style.pixelTop += dy;
	}
}

function ecsGetLeft( div )
{
	if ( ECS__NS )
	{
		return ecsGetStyleValue_Integer( div.style.left );
	}
	else
	{
		return div.style.pixelLeft;
	}
}

function ecsGetTop( div )
{
	if ( ECS__NS )
	{
		return ecsGetStyleValue_Integer( div.style.top );
	}
	else
	{
		return div.style.pixelTop;
	}
}

function ecsGetRight( div )
{
	if ( ECS__NS )
	{
		return ( div.left + ecsGetWidth( div ) );
	}
	else
	{
		return ( div.style.pixelLeft + ecsGetWidth( div ) );
	}
}

function ecsGetBottom( div )
{
	if ( ECS__NS )
	{
		return ( div.top + ecsGetHeight( div ) );
	}
	else if (ECS__IE)
	{
		return ( div.style.pixelTop + ecsGetHeight( div ) );
	}
}

function ecsGetPageLeft( div )
{
	var x = 0;
	while ( div.offsetParent != null )
	{
		x += div.offsetLeft;
		div = div.offsetParent;
	}
	x += div.offsetLeft;

	return x;
}

function ecsGetPageTop( div )
{
	var	y = 0;
	while ( div.offsetParent != null )
	{
		y += div.offsetTop;
		div = div.offsetParent;
	}
	y += div.offsetTop;

	return y;
}

function ecsGetWidth( div )
{
	if ( ECS__NS )
	{
		return div.offsetWidth;

		if ( div.document.width )
		{
			return div.document.width;
		}
		else
		{
			return ( div.clip.right - div.clip.left );
		}
	}
	else
	{
		if ( div.style.pixelWidth )
		{
			return div.style.pixelWidth;
		}
		else
		{
			return div.clientWidth;
		}
	}
}

function ecsGetHeight( div )
{
	if ( ECS__NS )
	{
		return div.offsetHeight;

		if ( div.document.height )
		{
			return div.document.height;
		}
		else
		{
			return ( div.clip.bottom - div.clip.top );
		}
	}
	else
	{
		if ( false && div.style.pixelHeight )
		{
			return div.style.pixelHeight;
		}
		else
		{
			return div.clientHeight;
		}
	}
}

function ecsGetZIndex( div )
{
	if ( ECS__NS )
	{
		return div.zIndex;
	}
	else
	{
		return div.style.zIndex;
	}
}

function ecsSetZIndex( div, z )
{
	if ( ECS__NS )
	{
		div.zIndex = z;
	}
	else
	{
		div.style.zIndex = z;
	}
}

//-----------------------------------------------------------------------------
// Layer clipping.
//-----------------------------------------------------------------------------

function ecsSetClip( div, clipleft, cliptop, clipright, clipbottom )
{
	if ( false ) //( ECS__NS )
	{
		div.clip.left	= clipleft;
		div.clip.top = cliptop;
		div.clip.right = clipright;
		div.clip.bottom = clipbottom;
	}
	else
	{
		div.style.clip = 'rect(' + cliptop + ' ' + clipright + ' ' + clipbottom + ' ' + clipleft + ')';
	}
}

function ecsGetClipLeft( div )
{
	if ( false ) //( ECS__NS )
	{
		return div.clip.left;
	}
	else
	{
		var str = div.style.clip;

		if ( !str )
		{
			return 0;
		}

		var clip = ecsGetIEClipValues( str );

		return clip[ 3 ];
	}
}

function ecsGetClipTop( div )
{
	if ( false ) //( ECS__NS )
	{
		return div.clip.top;
	}
	else
	{
		var str = div.style.clip;

		if ( !str )
		{
			return 0;
		}

		var clip = ecsGetIEClipValues( str );

		return clip[ 0 ];
	}
}

function ecsGetClipRight( div )
{
	if ( false ) //( ECS__NS )
	{
		return div.clip.right;
	}
	else
	{
		var str = div.style.clip;

		if ( !str )
		{
			return div.style.pixelWidth;
		}

		var clip = ecsGetIEClipValues( str );

		return clip[ 1 ];
	}
}

function ecsGetClipBottom( div )
{
	if ( false ) //( ECS__NS )
	{
		return div.clip.bottom;
	}
	else
	{
		var str = div.style.clip;

		if ( !str )
		{
			return div.style.pixelHeight;
		}

		var clip = ecsGetIEClipValues( str );

		return clip[ 2 ];
	}
}

function ecsGetClipWidth( div )
{
	if ( false ) //( ECS__NS )
	{
		return div.clip.width;
	}
	else
	{
		var str = div.style.clip;

		if ( !str )
		{
			return div.style.pixelWidth;
		}

		var clip = ecsGetIEClipValues( str );

		return ( clip[ 1 ] - clip[ 3 ] );
	}
}

function ecsGetClipHeight( div )
{
	if ( false ) //( ECS__NS )
	{
		return div.clip.height;
	}
	else
	{
		var str = div.style.clip;

		if ( !str )
		{
			return(div.style.pixelHeight);
		}

		var clip = ecsGetIEClipValues( str );

		return ( clip[ 2 ] - clip[ 0 ] );
	}
}

function ecsGetIEClipValues( str )
{
	var i;

	var clip = new Array();

	i = str.indexOf( "(" );
	clip[ 0 ] = parseInt( str.substring( i + 1 ) );

	i = str.indexOf( " ", i + 1 );
	clip[ 1 ] = parseInt( str.substring( i + 1 ) );

	i = str.indexOf( " ", i + 1 );
	clip[ 2 ] = parseInt( str.substring( i + 1 ) );

	i = str.indexOf( " ", i + 1 );
	clip[ 3 ] = parseInt( str.substring( i + 1 ) );

	return clip;
}

//-----------------------------------------------------------------------------
// Layer scrolling.
//-----------------------------------------------------------------------------

function ecsScrollTo( div, x, y, bound )
{
	var dx = ecsGetClipLeft( div ) - x;
	var dy = ecsGetClipTop( div ) - y;

	ecsScrollBy( div, -dx, -dy, bound );
}

function ecsScrollBy( div, dx, dy, bound )
{
	var cl = ecsGetClipLeft( div );
	var ct = ecsGetClipTop( div );
	var cr = ecsGetClipRight( div );
	var cb = ecsGetClipBottom( div );

	if ( bound )
	{
		if ( ( cl + dx ) < 0 )
		{
			dx = -cl;
		}
		else if ( ( cr + dx ) > ecsGetWidth( div ) )
		{
			dx = ecsGetWidth( div ) - cr;
		}

		if ( ( ct + dy ) < 0 )
		{
			dy = -ct;
		}
		else if ( ( cb + dy ) > ecsGetHeight( div ) )
		{
			dy = ecsGetHeight( div ) - cb;
		}
	}

	if ( ( dx != 0 ) || ( dy != 0 ) )
	{
		ecsSetClip( div, cl + dx, ct + dy, cr + dx, cb + dy );
		ecsMoveLayerBy( div, -dx, -dy );
	}
}

//-----------------------------------------------------------------------------
// Layer background.
//-----------------------------------------------------------------------------

function ecsSetBgColor( div, color )
{
	div.style.backgroundColor = color;
}

function ecsSetBgImage( div, src )
{
	div.style.backgroundImage = "url(" + src + ")";
}

//-----------------------------------------------------------------------------
// Layer utilities.
//-----------------------------------------------------------------------------

function ecsGetLayer( name )
{
	if ( document.getElementById )
	{
		return document.getElementById( name );
	}
	else if ( ECS__NS )
	{
		return ecsFindLayer( name, document );
	}
	else if ( document.all )
	{
		return eval( 'document.all.' + name );
	}
}

function ecsFindLayer( name, doc )
{
	var i;
	var div;

	for ( i = 0; i < doc.layers.length; i++ )
	{
		div = doc.layers[ i ];

		if ( div.name == name )
		{
			return div;
		}

		if ( div.document.layers.length > 0 )
		{
			div = ecsFindLayer( name, div.document );

			if ( div != null )
			{
				return div;
			}
		}
	}

	return null;
}

//-----------------------------------------------------------------------------
// Window and page properties.
//-----------------------------------------------------------------------------

function ecsGetWindowWidth()
{
	if ( ECS__NS )
	{
		return window.innerWidth;
	}
	else
	{
		return document.body.clientWidth;
	}
}

function ecsGetWindowHeight()
{
	if ( ECS__NS )
	{
		return window.innerHeight;
	}
	else
	{
		return document.body.clientHeight;
	}
}

function ecsGetPageWidth()
{
	if ( ECS__NS )
	{
		return document.width;
	}
	else
	{
		return document.body.scrollWidth;
	}
}

function ecsGetPageHeight()
{
	if ( ECS__NS )
	{
		return document.height;
	}
	else
	{
		return document.body.scrollHeight;
	}
}

function ecsGetPageScrollX()
{
	if ( ECS__NS )
	{
		return window.pageXOffset;
	}
	else
	{
		return document.body.scrollLeft;
	}
}

function ecsGetPageScrollY()
{
	if ( ECS__NS )
	{
		return window.pageYOffset;
	}
	else
	{
		return document.body.scrollTop;
	}
}

function ecsGetStyleValue_Integer( val )
{
    if ( isNaN( parseInt( val ) ) )
    {
        return 0;
    }
    else
    {
        return parseInt( val );
    }
}

// glyph button support

ecs__altOnGlyph = true;
ecs__glyphs = new Array()

function ecsGlyph( alttag, imageOn1, imageOff1, imageOn2, imageOff2, mouseOverAction, mouseOutAction, clickAction1, clickAction2, addPositionToClickAction, state )
{
	this.fAltTag = alttag;

	this.fImageOn1 = new Image();
	this.fImageOn1.src = imageOn1;

	this.fImageOff1 = new Image();
	this.fImageOff1.src = imageOff1;

	this.fImageOn2 = new Image();
	this.fImageOn2.src = ( imageOn2 == null ) ? imageOn1 : imageOn2;

	this.fImageOff2 = new Image()
	this.fImageOff2.src = ( imageOff2 == null ) ? imageOff1 : imageOff2;

	this.fImageOn = state ? this.fImageOn2 : this.fImageOn1;
	this.fImageOff = state ? this.fImageOff2 : this.fImageOff1;

	this.fMouseOverAction = mouseOverAction;
	this.fMouseOutAction = mouseOutAction;

	this.fClickAction1 = clickAction1;
	this.fClickAction2 = ( clickAction2 == null ) ? clickAction1 : clickAction2;

	this.fClickAction = state ? clickAction2 : clickAction1;

	this.fAddPositionToClickAction = addPositionToClickAction;

	this.fState = state;

	this.fIndex = ecs__glyphs.length;
}

function ecsGenerateGlyph( alttag, imageOn, imageOff, imageWidth, imageHeight, mouseOverAction, mouseOutAction, clickAction, anchorClass, imgClass, addPositionToClickAction )
{
	return ecsGenerateCreate( alttag, imageOn, imageOff, null, null, imageWidth, imageHeight, mouseOverAction, mouseOutAction, clickAction, null, anchorClass, imgClass, addPositionToClickAction, false, null );
}

function ecsGenerateGlyph2( alttag, imageOn1, imageOff1, imageOn2, imageOff2, imageWidth, imageHeight, mouseOverAction, mouseOutAction, clickAction1, clickAction2, anchorClass, imgClass, addPositionToClickAction )
{
	return ecsGenerateCreate( alttag, imageOn1, imageOff1, imageOn2, imageOff2, imageWidth, imageHeight, mouseOverAction, mouseOutAction, clickAction1, clickAction2, anchorClass, imgClass, addPositionToClickAction, false, null );
}

function ecsGenerateGlyph3( alttag, imageOn, imageOff, imageWidth, imageHeight, mouseOverAction, mouseOutAction, clickAction, align )
{
	return ecsGenerateCreate( alttag, imageOn, imageOff, null, null, imageWidth, imageHeight, mouseOverAction, mouseOutAction, clickAction, null, null, null, null, false, align );
}

function ecsGenerateCreate( alttag, imageOn1, imageOff1, imageOn2, imageOff2, imageWidth, imageHeight, mouseOverAction, mouseOutAction, clickAction1, clickAction2, anchorClass, imgClass, addPositionToClickAction, state, align )
{
	var		i = ecs__glyphs.length;

	ecs__glyphs[ i ] = new ecsGlyph( alttag, imageOn1, imageOff1, imageOn2, imageOff2, mouseOverAction, mouseOutAction, clickAction1, clickAction2, addPositionToClickAction, state );

	var		s = '<a';

	if ( ECS__NS )
	{
		s += ( ' href="javascript:void(0)"' );
	}

	s += ( ' onmouseover="return ecsGlyphMouseOver(' + i + ',event)"' );
	s += ( ' onmouseout="return ecsGlyphMouseOut(' + i + ',event)"' );
	s += ( ' onclick="return ecsGlyphClick(' + i + ',event)"' );
	s += ( ' oncontextmenu="if (!event.ctrlKey) return ecsGlyphClick(' + i + ',event)"' );

	if ( anchorClass != null )
	{
		s += ( ' class=' + anchorClass );
	}

	s += ( '><img ' + 'name="glyph_' + i + '" src="' + ecs__glyphs[ i ].fImageOff.src + '" border="0"' );

	if ( imageWidth )
	{
		s += ( ' height=' + imageHeight );
	}

	if ( imageHeight )
	{
		s += ( ' width=' + imageWidth );
	}

	if ( ECS__IE )
	{
		s += ( ' align="' + ( (align!=null) ? align : 'middle' ) + '"' );
	}

	if ( ecs__altOnGlyph  && ( alttag != null ) )
	{
		s += ( ' alt="' + alttag + '"' );
	}
	else
	{
		s += ( ' alt=""' );
	}

	if ( imgClass != null )
	{
		s += ( ' class="' + imgClass + '"' );
	}

	s += ( '></a>' );

	document.write( s );

	return ecs__glyphs[ i ];
}

function ecsGlyphClick( i, e )
{
	var glyph = ecs__glyphs[ i ];
	var	action = glyph.fClickAction;

	if ( glyph.fState )
	{
		glyph.fImageOn = glyph.fImageOn1;
		glyph.fImageOff = glyph.fImageOff1;
		glyph.fClickAction = glyph.fClickAction1;
	}
	else
	{
		glyph.fImageOn = glyph.fImageOn2;
		glyph.fImageOff = glyph.fImageOff2;
		glyph.fClickAction = glyph.fClickAction2;
	}

	glyph.fState = !glyph.fState;

	document.images[ 'glyph_' + i ].src = glyph.fImageOn.src;

	if ( action != null )
	{
		var		cmd;

		if ( glyph.fAddPositionToClickAction )
		{
			var x;
			var y;

			if ( ECS__IE )
			{
				x = event.clientX;	// + document.body.scrollLeft;
				y = event.clientY;	// + document.body.scrollTop;
			}
			else
			{
				x = e.pageX;
				y = e.pageY;
			}

			cmd = action + '(' + ( x - ecs__popupOffsetX ) + ',' + ( y - ecs__popupOffsetY ) + ')';
		}
		else
		{
			cmd = action;
		}

		eval( cmd );
	}

	return false;
}

function ecsGlyphMouseOver( i, e )
{
	var glyph = ecs__glyphs[ i ];

	document.images[ 'glyph_' + i ].src = glyph.fImageOn.src;

	if ( glyph.fMouseOverAction != null )
	{
		eval( glyph.fMouseOverAction );
	}

	if ( !ecs__altOnGlyph && ( glyph.fAltTag != null ) )
	{
		status = glyph.fAltTag;
	}
	else
	{
		status = '';
	}

	return true;
}

function ecsGlyphMouseOut( i, e )
{
	var	glyph = ecs__glyphs[ i ]

	document.images[ 'glyph_' + i ].src = glyph.fImageOff.src;

	if ( glyph.fMouseOutAction != null )
	{
		eval( glyph.fMouseOutAction );
	}

	status = '';

	return true;
}

function ecsGlyphSetState( glyph, state )
{
	glyph.fState = state;

	if ( ! glyph.fState )
	{
		glyph.fImageOn = glyph.fImageOn1;
		glyph.fImageOff = glyph.fImageOff1;
		glyph.fClickAction = glyph.fClickAction1;
	}
	else
	{
		glyph.fImageOn = glyph.fImageOn2;
		glyph.fImageOff = glyph.fImageOff2;
		glyph.fClickAction = glyph.fClickAction2;
	}

	document.images[ 'glyph_' + glyph.fIndex ].src = glyph.fImageOff.src;

	return true;
}


function ecsLinkPopup( popupData )
{
	if ( event.ctrlKey )
	{
		return true;
	}
	else
	{
		var x;
		var y;

		if ( ECS__IE )
		{
			x = event.clientX;	// + document.body.scrollLeft;
			y = event.clientY;	// + document.body.scrollTop;
		}
		else
		{
			x = e.pageX;
			y = e.pageY;
		}

		document.applets.POPUPMENU.setdata( popupData );
		document.applets.POPUPMENU.popup( x, y );

		return false;
	}
}

// trim strings

function ecsTrim( val )
{
	var i;

	for ( i = 0; i < val.length; i++ )
	{
		if ( val.charAt( i ) != ' ' )
		{
			break;
		}
	}

	val = val.substr( i );

	for ( i = val.length; i > 0; i-- )
	{
		if ( val.charAt( i - 1 ) != ' ' )
		{
			break;
		}
	}

	val = val.substr( 0, i );

	return val;
}

function ecsDetectClientXSL()
{
	var retval = false;

	try
	{
		new ActiveXObject( 'Msxml2.DOMDocument.3.0' );
		retval = true;
	}
	catch ( ex )
	{
	}

	try
	{
		new ActiveXObject( 'Msxml2.DOMDocument.4.0' );
		retval = true;
	}
	catch ( ex )
	{
	}

	return retval;
}

function ecsFormat( format )
{
	var		retval;

	if ( arguments.length == 0 )
	{
		retval = '';
	}
	else
	{
		retval = arguments[ 0 ];

		for ( var i = 1; i < arguments.length; i++ )
		{
			var	arg = '{' + ( i - 1 ) + '}';
			var	idx = retval.indexOf( arg );

			if ( idx >= 0 )
			{
				retval = retval.substring( 0, idx ) + arguments[ i ] + retval.substring( idx + arg.length );
			}
		}
	}

	return retval;
}

function drawMenu( e, menuPopupCmd )
{
	document.applets.POPUPMENU.setdata( menuPopupCmd );
	document.applets.POPUPMENU.popup( e.clientX, e.clientY );

	return false;
}

function drawBox( obj, clazzName )
{
	obj.className = clazzName;
}

function drawNoBox( obj, clazzName )
{
	obj.className = clazzName;
}

function ecsToJS( s )
{
	return s.replace( /'/g, "\\'" );
}

function ecsToC( s )
{
	return s.replace( /"/g, '\\"' );
}

function ecsToXML( s )
{
	var		len = s.length;
	var		buf = '';

	for ( var i = 0; i < len; i++ )
	{
		var	c = s.charAt( i );

		if ( c < ' ' )
		{
			switch ( c )
			{
				case '\t':
				{
					buf += '&#09;';
					break;
				}
				case '\r':
				{
					buf += '&#0D;';
					break;
				}
				case '\n':
				{
					buf += '&#0A;';
					break;
				}
			}
		}
		else
		{
			switch ( c )
			{
				case '<':
				{
					buf += '&lt;';
					break;
				}
				case '>':
				{
					buf += '&gt;';
					break;
				}
				case '&':
				{
					buf += '&amp;';
					break;
				}
				case '"':
				{
					buf += '&quot;';
					break;
				}
				case '\'':
				{
					buf += '&apos;';
					break;
				}
				default:
				{
					buf += c;
					break;
				}
			}
		}
	}

	return buf;
}

function updateDateField( changedField, dateField, year, month, day, hour, minute, second, year1, optionalTime )
{
	var		t;

	if ( changedField.selectedIndex == 0 )
	{
		if ( hour != null )
		{
			hour.selectedIndex = 0;
		}

		if ( minute != null )
		{
			minute.selectedIndex = 0;
		}

		if ( second != null )
		{
			second.selectedIndex = 0;
		}

		if ( ( changedField == year ) ||
			 ( changedField == month ) ||
			 ( changedField == day ) ||
			 ( !optionalTime && ( ( changedField == hour   ) ||
								  ( changedField == minute ) ||
								  ( changedField == second ) ) ) )
		{
			month.selectedIndex = 0;
			day.selectedIndex = 0;
			year.selectedIndex = 0;

			dateField.value = '?'
		}
		else
		{
			dateField.value = updateDateFieldCalc( year, month, day, hour, minute, second )
		}
	}
	else
	{
		var	tmp = new Date();

		if ( year.selectedIndex == 0 )
		{
			year.selectedIndex = tmp.getFullYear() - year1 + 1;
		}

		if ( month.selectedIndex == 0 )
		{
			if ( year.selectedIndex == ( tmp.getFullYear() - year1 + 1 ) )
			{
				month.selectedIndex = tmp.getMonth() + 1;
			}
			else
			{
				month.selectedIndex = 1;
			}
		}

		if ( day.selectedIndex == 0 )
		{
			if ( month.selectedIndex == ( tmp.getMonth() + 1 ) )
			{
				day.selectedIndex = tmp.getDate();
			}
			else
			{
				day.selectedIndex = 1;
			}
		}

		if ( !optionalTime ||
			 ( hour && ( hour.selectedIndex != 0 ) ) ||
			 ( minute && ( minute.selectedIndex != 0 ) ) ||
			 ( second && ( second.selectedIndex != 0 ) ) )
		{
			if ( hour && ( hour.selectedIndex == 0 ) )
			{
				hour.selectedIndex = 1;
			}

			if ( minute && ( minute.selectedIndex == 0 ) )
			{
				minute.selectedIndex = 1;
			}

			if ( second && ( second.selectedIndex == 0 ) )
			{
				second.selectedIndex = 1;
			}
		}

		var		monthIndex = month.selectedIndex;
		var		dayIndex = day.selectedIndex;

		if ( month.options[ monthIndex ].value == '2' )
		{
			day.options[ 31 ] = null;
			day.options[ 30 ] = null;

			var yearValue = year.options[ year.selectedIndex ].value;

			if ( ( ( yearValue % 400 ) == 0 ) || ( ( ( yearValue % 100 ) !=0 ) && ( ( yearValue % 4 ) == 0 ) ) )
			{
				if ( day.options[ 29 ] == null )
				{
					day.options[ 29 ] = new Option( '29' );
					day.options[ 29 ].value = '29';
				}

				if ( dayIndex > 29 )
				{
					day.selectedIndex = 29;
				}
			}
			else
			{
				day.options[ 29 ] = null;

				if ( dayIndex > 28 )
				{
					day.selectedIndex = 28;
				}
			}
		}

		if ( month.options[ monthIndex ].value ==  '1' ||
			 month.options[ monthIndex ].value ==  '3' ||
			 month.options[ monthIndex ].value ==  '5' ||
			 month.options[ monthIndex ].value ==  '7' ||
			 month.options[ monthIndex ].value ==  '8' ||
			 month.options[ monthIndex ].value == '10' ||
			 month.options[ monthIndex ].value == '12'	  )
		{
			if ( day.options[ 29 ] == null )
			{
				day.options[ 29 ] = new Option( '29' );
				day.options[ 29 ].value = '29';
			}

			if ( day.options[ 30 ] == null )
			{
				day.options[ 30 ] = new Option( '30' );
				day.options[ 30 ].value = '30';
			}

			if ( day.options[ 31 ] == null )
			{
				day.options[ 31 ] = new Option( '31' );
				day.options[ 31 ].value = '31';
			}
		}

		if ( month.options[ monthIndex ].value ==  '4' ||
			 month.options[ monthIndex ].value ==  '6' ||
			 month.options[ monthIndex ].value ==  '9' ||
			 month.options[ monthIndex ].value == '11'	  )
		{
			if ( day.options[ 29 ] == null )
			{
				day.options[ 29 ] = new Option( '29' );
				day.options[ 29 ].value = '29';
			}

			if ( day.options[ 30 ] == null )
			{
				day.options[ 30 ] = new Option( '30' );
				day.options[ 30 ].value = '30';
			}

			day.options[ 31 ] = null;

			if ( dayIndex > 30 )
			{
				day.selectedIndex = 30;
			}
		}

		dateField.value = updateDateFieldCalc( year, month, day, hour, minute, second );

		setDirty();
	}
}

function updateDateFieldCalc( year, month, day, hour, minute, second )
{
	var		t;

	t  = year.options[ year.selectedIndex ].value;
	t += ',' + month.options[ month.selectedIndex ].value;
	t += ',' + day.options[ day.selectedIndex ].value;

	if ( hour )
	{
		t += ',' + hour.options[ hour.selectedIndex ].value;
	}
	else
	{
		t += ',00';
	}

	if ( minute )
	{
		t +=  ',' + minute.options[ minute.selectedIndex ].value;
	}
	else
	{
		t += ',00';
	}

	if ( second )
	{
		t +=  ',' + second.options[ second.selectedIndex ].value;
	}
	else
	{
		t += ',00';
	}

	return t;
}

// Set the StartDate and EndDate fields of the given form.
// To be used with edatefield.jsp:GetRange().

function setStartAndEndDates( frm, startYear, startMonth, startDay, startHour, endYear, endMonth, endDay, endHour )
{
	frm.StartDate_year.selectedIndex = startYear - 1990 + 1;
	frm.StartDate_month.selectedIndex = startMonth + 1;

	// update date field to set the day popups to the correct range

	updateDateField(
		frm.StartDate_year,
		frm.StartDate,
		frm.StartDate_year,
		frm.StartDate_month,
		frm.StartDate_day,
		frm.StartDate_hour,
		null,
		null,
		1990,
		false );

	frm.StartDate_day.selectedIndex = startDay;
	frm.StartDate_hour.selectedIndex = startHour + 1;

	// update date field again to set the underlying date field to the
	// correct values (including day and hour).

	updateDateField(
		frm.StartDate_year,
		frm.StartDate,
		frm.StartDate_year,
		frm.StartDate_month,
		frm.StartDate_day,
		frm.StartDate_hour,
		null,
		null,
		1990,
		false );

	// end date...

	frm.EndDate_year.selectedIndex = endYear - 1990 + 1;
	frm.EndDate_month.selectedIndex = endMonth + 1;

	// update date field to set the day popups to the correct range

	updateDateField(
		frm.EndDate_year,
		frm.EndDate,
		frm.EndDate_year,
		frm.EndDate_month,
		frm.EndDate_day,
		frm.EndDate_hour,
		null,
		null,
		1990,
		false );

	frm.EndDate_day.selectedIndex = endDay;
	frm.EndDate_hour.selectedIndex = endHour + 1;

	// update date field again to set the underlying date field to the
	// correct values (including day and hour).

	updateDateField(
		frm.EndDate_year,
		frm.EndDate,
		frm.EndDate_year,
		frm.EndDate_month,
		frm.EndDate_day,
		frm.EndDate_hour,
		null,
		null,
		1990,
		false );
}

