/*******************************************************************************
 * OpenAjax.js
 *
 * Reference implementation of the OpenAjax Hub, as specified by OpenAjax Alliance.
 * Specification is under development at: 
 *
 *   http://www.openajax.org/member/wiki/OpenAjax_Hub_Specification
 *
 * Copyright 2006-2008 OpenAjax Alliance
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 * use this file except in compliance with the License. You may obtain a copy 
 * of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless 
 * required by applicable law or agreed to in writing, software distributed 
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 * specific language governing permissions and limitations under the License.
 *
 *
 *	01-20-2006, xWinLib enhacements by RadWebTech / Steve Repetti
 *  	Added enhaced wrapper support to subscribe, unsubscribe, ans publish methods
 *
 ******************************************************************************/

// prevent re-definition of the OpenAjax object
if(!window["OpenAjax"]){
	OpenAjax = new function(){
		var t = true;
		var f = false;
		var g = window;
		var ooh = "org.openajax.hub.";

		var h = {};
		this.hub = h;
		h.implementer = "http://openajax.org";
		h.implVersion = "1.0";
		h.specVersion = "1.0";
		h.implExtraData = {};
		var libs = {};
		h.libraries = libs;

		h.registerLibrary = function(prefix, nsURL, version, extra){
			libs[prefix] = {
				prefix: prefix,
				namespaceURI: nsURL,
				version: version,
				extraData: extra 
			};
			this.publish(ooh+"registerLibrary", libs[prefix]);
		}
		h.unregisterLibrary = function(prefix){
			this.publish(ooh+"unregisterLibrary", libs[prefix]);
			delete libs[prefix];
		}

		h._subscriptions = { c:{}, s:[] };
		h._cleanup = [];
		h._subIndex = 0;
		h._pubDepth = 0;

		h.subscribe = function(name, callback, scope, subscriberData, filter) 
		{
			if ( xlib && xlib.openajax ) {
				// encapsulate advanced wrapper, xWinLib
				return( xlib.openajax.subscribe( name, callback, scope, subscriberData, filter ) );
			}
			else {
				return( this.x_subscribe( name, callback, scope, subscriberData, filter ) );
			}
		}

		h.x_subscribe = function(name, callback, scope, subscriberData, filter)			
		{
			if(!scope){
				scope = window;
			}
			var handle = name + "." + this._subIndex;
			var sub = { scope: scope, cb: callback, fcb: filter, data: subscriberData, sid: this._subIndex++, hdl: handle };
			var path = name.split(".");
	 		this._subscribe(this._subscriptions, path, 0, sub);
			return handle;
		}


		h.publish = function(name, message)	
		{
			if ( xlib && xlib.openajax ) {
				// encapsulate advanced wrapper, xWinLib
				return( xlib.openajax.publish( name, message ) );
			}
			else {
				return( this.x_publish( name, message ) );
			}
		}

		h.x_publish = function(name, message)		
		{
			var path = name.split(".");
			this._pubDepth++;
			this._publish(this._subscriptions, path, 0, name, message);
			this._pubDepth--;
			if((this._cleanup.length > 0) && (this._pubDepth == 0)) {
				for(var i = 0; i < this._cleanup.length; i++) 
					this.unsubscribe(this._cleanup[i].hdl);
				delete(this._cleanup);
				this._cleanup = [];
			}
		}

		h.unsubscribe = function( sub ) 
		{
			if ( xlib && xlib.openajax ) {
				// encapsulate advanced wrapper, xWinLib
				return( xlib.openajax.unsubscribe( sub ) );
			}
			else {
				return( this.x_unsubscribe( sub ) );
			}
		}

		h.x_unsubscribe = function(sub) 
		{
			var path = sub.split(".");
			var sid = path.pop();
			this._unsubscribe(this._subscriptions, path, 0, sid);
		}
		
		h._subscribe = function(tree, path, index, sub) 
		{
			var token = path[index];
			if(index == path.length) {
				tree.s.push(sub);
			}
			else { 
				if(typeof tree.c == "undefined")
					 tree.c = {};
				if(typeof tree.c[token] == "undefined") {
					tree.c[token] = { c: {}, s: [] }; 
					this._subscribe(tree.c[token], path, index + 1, sub);
				}
				else 
					this._subscribe( tree.c[token], path, index + 1, sub);
			}
		}

		h._publish = function(tree, path, index, name, msg, pid) {
			if(typeof tree != "undefined") {
				var node;
				if(index == path.length) {
					node = tree;
				} else {
					this._publish(tree.c[path[index]], path, index + 1, name, msg, pid);
					this._publish(tree.c["*"], path, index + 1, name, msg, pid);
					node = tree.c["**"];
				}
				if(typeof node != "undefined") {
					var callbacks = node.s;
					var max = callbacks.length;
					for(var i = 0; i < max; i++) {
						if(callbacks[i].cb) {
							var sc = callbacks[i].scope;
							var cb = callbacks[i].cb;
							var fcb = callbacks[i].fcb;
							var d = callbacks[i].data;
							if(typeof cb == "string"){
								// get a function object
								cb = sc[cb];
							}
							if(typeof fcb == "string"){
								// get a function object
								fcb = sc[fcb];
							}
							if((!fcb) || (fcb.call(sc, name, msg, d))) {
								cb.call(sc, name, msg, d, pid);
							}
						}
					}
				}
			}
		}
			
		h._unsubscribe = function(tree, path, index, sid) {
			if(typeof tree != "undefined") {
				if(index < path.length) {
					var childNode = tree.c[path[index]];
					this._unsubscribe(childNode, path, index + 1, sid);
					if(childNode.s.length == 0) {
						for(var x in childNode.c) 
					 		return;		
						delete tree.c[path[index]];	
					}
					return;
				}
				else {
					var callbacks = tree.s;
					var max = callbacks.length;
					for(var i = 0; i < max; i++) 
						if(sid == callbacks[i].sid) {
							if(this._pubDepth > 0) {
								callbacks[i].cb = null;	
								this._cleanup.push(callbacks[i]);						
							}
							else
								callbacks.splice(i, 1);
							return; 	
						}
				}
			}
		}
		// The following function is provided for automatic testing purposes.
		// It is not expected to be deployed in run-time OpenAjax Hub implementations.
		h.reinit = function()
		{
			for (var lib in OpenAjax.hub.libraries) {
				delete OpenAjax.hub.libraries[lib];
			}
			OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "1.0", {});

			delete OpenAjax._subscriptions;
			OpenAjax._subscriptions = {c:{},s:[]};
			delete OpenAjax._cleanup;
			OpenAjax._cleanup = [];
			OpenAjax._subIndex = 0;
			OpenAjax._pubDepth = 0;
		}
	};
	// Register the OpenAjax Hub itself as a library.
	OpenAjax.hub.registerLibrary("OpenAjax", "http://openajax.org/hub", "1.0", {});

}

//////////////////////////////////////////////////////////////////////
//
//	XWINLIB JAVASCRIPT LIBRARY - version 1.1
//	(c) 2008-2010 by RadWeb Technologies LLC, All Rights Reserved
//  	written by Steve Repetti

///////////////////////////////////////
// Classes and Functions
//
//	xWindow( data )
//		actionFormatExt( action )
//		actionPreprocess( action )
//		actionRenderExternal( action )
//		borderSet( s, w, c, ReloadFlag )
//		borderThickness( )
//		bringtotop( )
//		contextmenu( flag )
//		contextmenuFunc( oparent )
//		create( )
//		destroy( IgnoreFade, ConfirmFlag )
//		display( style )
//		errGet( errnum )
//		errSet( errnum )
//		eventProcess( edata, e )
//		eventRun( etype, e )
//		footerFunc( o )
//		getMagneticChildren( ) 
//		headerFunc( o )
//		help( )
//		iframe( )
//		iframeBody( )
//		iframeDocument( )
//		isInWin( w )
//		isPackedString( s )
//		isVisible( style )
//		manualmove( )
//		maximize( flag )
//		minimize( flag )
//		olayerEnable( f )
//		origin( )
//		pack( prefix )
//		position( x, y, w, h )
//		positionDivs( x, y, w, h )
//		properties( )
//		reload( )
//		scrollTo( x, y, mode )
//		setposition( left, top, width, height, IsSetWin )
//		shadowSet( o )
//		share( )
//		sysmenu( flag )
//		sysmenuFunc( oparent )
//		timerProcess( )
//		tooltipFunc( e, flag )
//		transparencySet( lvl )
//		undock( )
//		unpack( s )
//		winAdjust( x )
//		winBody( )
//		winBodyGet( )
//		winBodySet( )
//		winFtrGet( )
//		winFtrSet( val )
//		winHdrGet( )
//		winHdrSet( val )
//		winChildrenArray( name )
//		winMove( left, top )
//		winRegister( )
//		winSize( w, h )
//		winUnregister( )
//		zIndexGet( )
//	
//	xLibrary( )
//		animateHeight( o, startH, endH, opts, cbFunc, NoHideScrollbars )
//		animateOptionsSet( o, opts )
//		dpConvertDesktop( toType, data )
//		dpConvertWindow( toType, data )
//		browserNew( x, y, w, h, id, url, opts )
//		debugPos( )
//		eventBind( el, eventname, eventhandler )
//		eventBody( )
//		eventCancel( e )
//		eventCancelBubble( e )
//		eventCancelDrag( e )
//		eventCancelDrop( e )
//		eventClickHandler( e, opts )
//		eventCurrentGet( ename )
//		eventCurrentSet( ename, eval )
//		eventDefaultNode( o )
//		eventGet( event )
//		eventPosition( e )
//		eventTarget( e )
//		eventUnbind( el, eventname, eventhandler )
//		eventUnbindAll( )
//		fontCreate( opts )
//		imageRender( iname, w, h )
//		imagePreload( iname, w, h )
//		imageRotate( id, val ) 
//		imageRotateInit( ) 
//		init( options )
//		initFromDivs( prefix )
//		initInternal( )
//		intervalClear( el )
//		intervalSet( el, interval )
//		isFrameBuster( url )
//		isInFrame( )
//		_jsErrorFunc( msg, url, l )
//		keyGet( e )
//		menuCurrentDelete( )
//		menuCurrentSet( w )
//		mouseButton( e )
//		mouseCursor( o, csr )
//		mousePos( e, IncludeScroll )
//		mouseX( e, IncludeScroll )
//		mouseY( e, IncludeScroll )
//		namespaceCreate( ns )
//		normalizeURL( url, isblank )
//		objFromData( data, pos, ReloadFlag, pSize, NoCreate, e )
//		objGenerate( oparent, otype, name, x, y, w, h, opts )
//		objLookup( id )
//		objNameFromId( otype )
//		objPreprocess( data, vname, val )
//		objRender( id, state, mode, opts )
//		objTooltip( e, oparent, flag, content, opts )
//		pageLayer( f, obj )
//		textSelected( )
//		UpdateFlag( flag, win )
//		winAdjustAspect( oval, x, y )
//		winAdjustGrid( x )
//		winAdjustPos( x, y, width, height, offset )
//		winAdjustX( x, width, offset )
//		winAdjustY( y, height, offset )
//		winCalcCenter( w, h, oparent )
//		winClipSet( o, x, y, w, h )
//		winDefPostion( )
//		winHeight( )
//		winModalLayer( flag )
//		winOffsetHeight( o, b, p )
//		winOffsetWidth( o, b, p )
//		winScrollPos( o )
//		winScrollWidth( )
//		winScrollX( o )
//		winScrollY( o )
//		winSize( )
//		winSortedArray( includeSys )
//		winSortFunc( a, b )
//		winStatus( s )
//		winWidth( )
//		winWidthAdjustment( b )
//		
//	xDate( dte )
//		diff( d1, d2, t )
//		format( fstr )
//
//	xDesktop						/* xlib.desktop */
//		bgSet( img )
//		dropInit( )
//		gridSet( )
//		gridRestore( )
//		save( mode )
//		scrollTo( x, y, mode )
//		winMove( data, mode, opts )
//
//	xFx( )
//		bgFade( obj, clrStart, clrEnd, steps, delay )
//		opacity( id, val )
//		opacityFade( id, opts, val )
//		typewriter( o, text, opts )
//
//	xlib_MenuProperties( w )
//		add( title, img, action )
//		calcHeight( )
//		render( )
//		
//	xlib_plugin( )
//
//	xMouseHandler( )
//		init( )
//
//	xWinFont( opts )
//		init( )
//		loadFromStyle( style )
//		render( text )
//
//	alltrim( s )
//	btnDefault( e, btn )
//	cbCheck( obj, flag )
//	chr( n )
//	chrcount( c, s )
//	dateFormat( dte, fstr )
//	dateFormatj( dte, formatstr )
//	datej( dte )
//	dateSetFromStr( date, time )
//	datetokey( dte )
//	dec2hex( n, c )
//  dollar( val )
//	domAdd( oparent, el, id )
//	domBorderSet( o, style, width, clr )
//	domDelete( obj )
//	domDeleteIE( d )
//	domImageSet( obj, src, FilterOnly )
//	domInnerHTML_get( o )
//	domInnerHTML_set( o, val )
//	domInsertAfter( refNode, newNode )
//	domObjByName( name )
//	domObject( objname, [oscope] )
//	domOuterHTML_get( o )
//	domOuterHTML_set( o, val )
//	domPurge( o );
//	domSelect( selector, filter, results )		// wrapper for the Sizzlejs.com library (must be separately loaded)
//	enterKey( e, f )
//	findPos( obj )
//	findPosX( obj )
//	findPosY( obj )
//	hex2dec( hx )
//	int( x )
//	isAlpha( s )
//	isImageOk( oimg )
//	isNumeric( s )
//	isUrl( url )
//	isvar( v )
//	jsDecode( str )
//	jsEncode( str )
//	jsInclude( jsFile )
//	keytodate( key )
//	lbAdd( o, id, val )
//	lbCurSelText( obj )
//	lbCurSelValue( obj, IsText )
//	lbDelete( o, item )
//	lbInsert( obj, id, val, index, maxnum )
//	lbSearchText( o, s, IsSet )
//	lbSearchValue( o, s, IsSet )
//	left( s, n )
//	len( s )
//	lower( str )
//	ltrim( s )
//	numFormat( n, ftype )
//	pad( str, num, pad, dir )
//	parseToObj( data );
//	ptContained( pt, rect )
//	pxWrap( x )
//	random( range )
//	rbCheck( rb, val )
//	rbSelectedIndex( obj, n )
//	rbSelectedValue( obj, n )
//	rectContained( r1, r2 )
//	rectIntersects( r1, r2 )
//	rectScale( w, h, wNew, hNew )
//	right( s, n )
//	rtrim( s )
//	str( c )
//	strabbr( s, l )
//	strat( s, s2 )
//	strati( s, s2 )
//	stratlast( sub, s )
//	stratlasti( sub, s )
//	stratnext( sub, s, n )
//	stratnexti( sub, s, n )
//  strcapfirst( s, nolower )
//	strcommas( n )
//	strcount( sub, s )
//	strcounti( substr, str )
//	strcrop( s, n )
//	strempty( val )
//	strextract( s, delim, n )
//	strswap( s, s1, s2 )
//  strswapi( s, s1, s2 )
//	substr( s, start, numchars )
//	tableCellObj( otable, row, col )
//	tableRowObj( otable, row )
//	untrim( str, num, pad )
//	upper( s )
//	urlExt( url )
//	urlFix( url )
//	urlType( url )
//	wait( ms )
//	x_ie_editClearSelection( e )
//	x_ie_eventCancel( e )
//	x_ie_eventGet( e )
//	x_ie_eventKey( e )
//	x_opera_eventCancel( e )
//	x_w3c_editClearSelection( e )
//	x_w3c_eventCancel( e )
//	x_w3c_eventGet( e )
//	x_w3c_eventKey( e )
//	xDragDataGet( e )
//	xDropDataGet( e )
//	xDropDataProcess( e )
//	xImageCalcSize( data, pos )
//	xImageCalcDone( )
//	xlib_ajaxCallback( http )
//	xlib_ajaxGetData( page, params )
//	xlib_ajaxGetPage( page, params, cbFunc )
//	xlib_ajaxPostData( page, params )
//	xlib_ajaxPostPage( page, data, cbFunc )
//	xlib_setHeaders( xmlhttp, aHeader )
//	xlib_PngFix( o )
//	xlibAjax( mtype, stype, page, params, cbFunc )
//	xlibInitPage( )
//	xMouseMoveCursor( eTarget, w )
//	xWebVar( vname, data )
//	xWin( name )
//	xWinArray( IncludeSys )
//	xWinContextMenu( e )
//	xWinDragDrop_w3c( e )
//  xWinError( e )
//	xWinEvent_Cancel( e )
//	xWinEvent_Click( e )
//	xWinEvent_DblClick( e )
//	xWinEvent_Drag( e )
//	xWinEvent_DragMove( e )
//	xWinEvent_Drop( e )
//	xWinEvent_ttOff( e )
//	xWinEvent_ttOn( e )
//	xWinFromElement( el )
//	xWinFromName( name )
//	xWinFromPoint( pt )
//	xWinIndexFromName( name )
//  xWinManualMove( w )
//	xWinMMHandler( e )
//	xWinModalResize( )
//	xWinModalScroll( )
//	xWinMouseDown( e )
//	xWinMouseMove( e )
//	xWinMouseUp( e )
//	xWinMoveDir( e, w )
//	xWinName( el )			// identify which window object an element is in
//	xWinNameGen( otype )
//	xWinOverBody( el )
//  xWinRecreate( id, data, UseParent )
//	xWinResize( e )
//	xWinScroll( e )
//  xWinVar( vname, data )

// 3rd party
//	Base64 (obj)
//	catchTab( e, obj )
//	easeInOut( minValue, maxValue, totalSteps, actualStep, powr )
//  replaceSelection( input, replaceString )
//  setSelectionRange( input, selectionStart, selectionEnd )
////////


////////////////////////////////////////
// global variables
//

// initialization options
var XINIT_ACTIVEWINDOWS = 1;		// must match scrapplet.fgl
var XINIT_RIGHTCLICK    = 2;
var XINIT_DESKTOP       = 4;
var XINIT_DESKTOPDROP   = 8;
var XINIT_ENABLEFX   	= 16;
var XINIT_OPENAJAX		= 32;
var XINIT_ALL           = 0x0000FFFF;
var XINIT_DEFAULTDIRS	= 0x00010000;
var XINIT_ALL_NODROP    = 0x0000FFFF;  XINIT_ALL_NODROP &= ~XINIT_DESKTOPDROP;

var xWinMaxNum          = 256;
var xWinIntDomains      = "localhost;scrapplet;xwinlib.com;dbweb20.com";	// semicolon delimited list of "friendly" domains to pass xid parameter to
var xWinImageDir        = "/libs/support";
var xWinThemesDir       = "/libs/themes";
var xWinDefaultTheme	= "";
var xWinBodyClass       = "smtxt";
var xWinTransLevel      = 60;
var xWinBgColor         = "#F0F0F0";
var xWinMoveOffset      = 8;
var xWinContextSideClr  = "#A0A0A0";
var xWinDefaultDisplay	= 1;
var xWinMinProp			= 0;

var xWinFtrBgColor		= "#404040";
var xWinHdrBgColor		= "#404040";
var xWinHdrBgImage		= "";
var xWinFtrBgImage		= "";

var xWinPropertyTheme	= null;
var xLibContextMenuFunc = null;

// window display
var WS_NORMAL           = 1;
var WS_HIDDEN           = 2;
var WS_VISIBLE          = 4;
var WS_MINIMIZED        = 8;
var WS_MAXIMIZED        = 16;

// window properties
var WS_HEADER           = 0x00000020;
var WS_FOOTER           = 0x00000040;
var WS_BORDER           = 0x00000080;
var WS_BORDERTHICK      = 0x00000100;
var WS_MOVEABLE         = 0x00000200;
var WS_RESIZABLE        = 0x00000400;
var WS_MINIMIZABLE      = 0x00000800;
var WS_MAXIMIZABLE      = 0x00001000;
var WS_UNDOCKABLE       = 0x00002000;		// only available with WS_EXTERNAL
var WS_ROLLUP           = 0x00004000;		// morework:
var WS_CLOSE            = 0x00008000;
var WS_SYSMENU          = 0x00010000;
var WS_CONTEXTMENU      = 0x00020000;		// invoked with right-click, or left-click + ctrl key (Mac users control-left-click, Opera users alt-left-click)
var WS_HELP             = 0x00040000;
var WS_COVER            = 0x00080000;		// morework:
var WS_SHADOW           = 0x00100000;		// currently only works with IE, does not work if BG is transparent
var WS_MODAL            = 0x00200000;
var WS_TRANSPARENT      = 0x00400000;
var WS_EXTERNAL         = 0x00800000;
var WS_NOFOCUS          = 0x01000000;
var WS_DRAG             = 0x02000000;
var WS_DROP             = 0x04000000;
var WS_ALWAYSONTOP      = 0x08000000;		// morework:
var WS_CHILD            = 0x10000000;
var WS_MAGNETIC			= 0x20000000;
var WS_NOTSHAREABLE		= 0x40000000;
var WS_SHAREMENU		= 0x80000000;


// window presets
var WS_POPUP            = WS_NORMAL | WS_HEADER | WS_BORDERTHICK | WS_MOVEABLE | WS_CLOSE;
var WS_MODALDIALOG      = WS_NORMAL | WS_HEADER | WS_BORDERTHICK | WS_MOVEABLE | WS_CLOSE | WS_MODAL;

// display modes
var DISP_NORMAL         = 1;
var DISP_CENTERED       = 2;
var DISP_DEFAULT        = 4;
var DISP_EVENTPOSITION  = 8;
var DISP_ANIM_TOOLTIP   = 16;
var DISP_FADE_IN        = 32;
var DISP_FADE_OUT       = 64;
var DISP_NOAUTOCLOSE    = 128;
var DISP_NOPROGRESS     = 256;

// num formating
var FORMAT_COMMAS       = 1;
var FORMAT_SUFFIX       = 2;
var FORMAT_CURRENCY		= 4;
var FORMAT_MINUTES		= 8;
var FORMAT_SECONDS		= 16;

// desktop variables
var DESKTOP_LAYOUT      = 1;
var DESKTOP_OBJECTS     = 2;
var DESKTOP_OBJMOVE     = 4;
var DESKTOP_INCLUDESYS	= 8;

// animation
var MOVE_INSTANT        = 1;
var MOVE_ANIMATE        = 2;
var MOVE_NORESIZE       = 4;		// more efficient move
var MOVE_SAVEPOS		= 8;		// will save object position after move, but NOT set update flag

var STATE_ON            = 1;
var STATE_OFF           = 0;
var STATE_TOGGLE        = -1;

var OTYPE_TEXTBLOCK			= 1;	// update objNameFromId( otype ) with any new otypes
var OTYPE_TEXTBLOCK_TRANS	= 2;	// also, tied to objScrapplet in scrapplet.fgl
var OTYPE_TEXTCAPTION		= 3;
var OTYPE_TEXTHEADLINE		= 4;
var OTYPE_TEXTFOOTNOTE		= 5;
var OTYPE_IMAGE				= 10;
var OTYPE_BACKGROUND		= 11;
var OTYPE_MUSIC				= 20;
var OTYPE_VIDEO				= 30;
var OTYPE_WEB				= 40;
var OTYPE_FEED				= 41;
var OTYPE_FRIENDS			= 50;
var OTYPE_GUESTBOOK			= 55;
var OTYPE_PROFILE			= 56;
var OTYPE_CONTACT			= 57;
var OTYPE_GALLERY			= 60;
var OTYPE_WIDGET 			= 70;
var OTYPE_DOCUMENT 			= 71;
var OTYPE_FLASH 			= 72;
var OTYPE_SCRIPT 			= 73;
var OTYPE_NAVIGATION 		= 74;
var OTYPE_DROPZONE			= 75;
var OTYPE_HTMLBLOCK			= 76;
var OTYPE_MAP				= 77;
var OTYPE_BUTTON			= 80;
var OTYPE_LINK				= 81;
var OTYPE_OBJECT			= 90;
var OTYPE_OAWIDGET			= 91;
var OTYPE_FORM_TEXT			= 100;
var OTYPE_FORM_TEXTAREA		= 101;
var OTYPE_FORM_SELECT		= 102;
var OTYPE_FORM_FILE			= 103;
var OTYPE_FORM_CHECKBOX		= 104;
var OTYPE_FORM_RADIO		= 105;
var OTYPE_FORM_PASSWORD		= 106;
var OTYPE_FORM_HIDDEN		= 107;

var OBJ_AJAXCONTENT     = 1;
var OBJ_CLEARONCLOSE    = 2;
var OBJ_ROLLDOWN        = 4;
var OBJ_ROLLUP          = 8;
var OBJ_ROLLRIGHT       = 16;
var OBJ_ROLLLEFT        = 32;

// mouse constants
var MOUSE_BUTTONLEFT    = 1;
var MOUSE_BUTTONCENTER  = 2;
var MOUSE_BUTTONRIGHT   = 4;
var MOUSE_DOWN          = 8;
var MOUSE_UP            = 16;

// errors
var ERR_NONAME          = 1001;
var ERR_ALREADYEXISTS   = 1002;
var ERR_TOOMANYWINDOWS  = 1003;

// keycode defines
var KEY_ALT				= 18;
var KEY_ARROWLEFT		= 37;
var KEY_ARROWUP			= 38;
var KEY_ARROWRIGHT		= 39;
var KEY_ARROWDOWN		= 40;
var KEY_BACKSPACE		= 8;
var KEY_CAPSLOCK		= 20;
var KEY_CTRL			= 17;
var KEY_DELETE			= 46;
var KEY_END				= 35;
var KEY_ENTER			= 13;
var KEY_ESCAPE			= 27;
var KEY_F1				= 112;
var KEY_F2				= 113;
var KEY_F3				= 114;
var KEY_F4				= 115;
var KEY_F5				= 116;
var KEY_F6				= 117;
var KEY_F7				= 118;
var KEY_F8				= 119;
var KEY_F9				= 120;
var KEY_F10				= 121;
var KEY_F11				= 122;
var KEY_F12				= 123;
var KEY_HOME			= 36;
var KEY_INSERT			= 45;
var KEY_NUMLOCK			= 144;
var KEY_PAGEUP			= 33;
var KEY_PAGEDOWN		= 34;
var KEY_SHIFT			= 16;
var KEY_SPACE			= 32;
var KEY_TAB				= 9;
var KEY_WINDOWS			= 91;

// data portability
var DP_WINDOWDATA		= 1;
var DP_DESKTOPDATA		= 2;

var DP_DELIMITED		= 16;	// must match the ajax values
var DP_JSON				= 32;
var DP_JSOBJ			= 64;
var DP_XML				= 128;
var DP_NAMEVALUE		= 256;
var DP_RAW				= 512;
var DP_SOURCE			= 1024;
var DP_QSTR				= 2048;
var DP_XOBJ				= 4096;

var DATA_UNKNOWN		= 0;
var DATA_IMAGE			= 1;
var DATA_VIDEO			= 2;
var DATA_MUSIC			= 4;
var DATA_DOCUMENT		= 8;
var DATA_FEED			= 16;
var DATA_HTML			= 32;
var DATA_JS				= 64;
var DATA_CSS			= 128;
var DATA_XML			= 256;
var DATA_ZIP			= 512;
var DATA_APP			= 1024;
var DATA_LINK			= 2048;

// xlibAjax constants
var AJAX_GET			= 1;
var AJAX_POST			= 2;
var AJAX_SYNCH			= 4;
var AJAX_ASYNCH			= 8;
var AJAX_DELIMITED		= DP_DELIMITED;
var AJAX_JSON			= DP_JSON;
var AJAX_JSOBJ			= DP_JSOBJ;
var AJAX_XML			= DP_XML;
var AJAX_NAMEVALUE		= DP_NAMEVALUE;
var AJAX_RAW			= DP_RAW;
var AJAX_SOURCE			= DP_SOURCE;
var AJAX_QSTR			= DP_QSTR;

var XLIB_SIG			= "$xLib$";
var XLIB_SIGBODY		= "xl-b";

// internal globals
var xWinList 			= [null];	// one-based array of window objects
var xWinZorder			= 1000;
var xWinIsTooltip 		= null;
var xScrollPos			= null;


////////////////////////////////
// common functions

function ltrim( s ) {
	while ( s.substring( 0,1 ) == ' ' ) {
		s = s.substring( 1, s.length );
	}
	return( s );
}

function rtrim( s ) {
	while ( s.substring( s.length-1, s.length ) == ' ' ) {
		s = s.substring( 0, s.length-1 );
	}
	return( s );
}

function untrim( str, num, pad ) {
	if ( ! str ) { return str; }
	var l = len( str );
	if ( l == num ) { return( str ); }
	if ( l < num ) {
		return( left( str, num ) );
	}
	return( pad( str, num, pad, 2 ) );
}


function right( s, n ) {
	if ( n <= 0 ) { return( "" ); }
	s = String( s );
	if ( n >= s.length ) { return( s ); }
	return s.substring( s.length, s.length - n );
}

function lower( s ) {
	return String( s ).toLowerCase( );
}

function alltrim( s ) {
	return ltrim( rtrim( s ) );
}

function upper( s ) {
	return String( s ).toUpperCase( );
}

function strat( s, s2 ) {
	return( s2.indexOf( s ) + 1 );
}

function strati( s, s2 ) {
	return strat( upper( s ), upper( s2 ) );
}

function dec2hex( n, c ) {
	var v = n.toString( 16 );
	if ( c ) {
		v = right( "00000000" + v, c );
	}
	return( v );
}

function domObject( objname, oscope ) {
	if ( oscope ) {
		return oscope.getElementById( objname );
	}
	return document.getElementById( objname );
}

function domSelect( selector, filter, results ) {
	// wrapper for the awesome Sizzlejs.com open source library
	// must be separately loaded
	return( Sizzle( selector, filter, results ) );
}

function btnDefault( e, btn ) {
	// onKeyDown="btnDefault( xlib.eventGet( event ), DefButton )"
	if ( xlib.eventKey( e ) == 13 ) {
		xlib.eventCancel( e );
		if ( typeof( btn ) == "string" ) {
  			btn = domObject( btn );
  		}

  		try {
			btn.click( );
  		}
		catch ( e ) {
  			btn.onclick( );
		}
   	}
}

function cbCheck( obj, flag ) {
	if ( typeof( obj ) == "string" ) {
		obj = domObject( obj );
	}
	if ( ! obj.disabled ) {
		if ( flag != null ) {
			obj.checked = flag;
		}
		else {
			obj.checked = ( ! obj.checked );
		}
	}
}


function len( s ) {
	if ( s == null ) {
		return( 0 );
	}
	return s.length;
}

function chr( n ) {
	return( String.fromCharCode( n ) );
}

function str( c ) {
	return( c.charCodeAt(0) );
}

function chrcount( c, s ) {
	var i, x=0, cnt;

	cnt = len( s );
	for ( i=0; i<cnt; i++ ) {
		if ( s.charAt( i ) == c ) { x++; }
	}

	return( x );
}

function counterToSeconds( tme ) {
	// tme = 00:00:00:00
	var a, cnt, i, j, ttl=0;

	a = tme.split( ":" );
	cnt = len( a );

	aSecs = [ 1, 60, 3600, 86400 ];


	for ( i=cnt-1,j=0; i>=0; i--, j++ ) {
		ttl += int( a[i] ) * aSecs[j];
	}

	return( ttl );
}

function dateFormat( dte, fstr ) {
	var a, d;
	if ( ! isvar( fstr ) ) {
		dte = fstr;
	}
	if ( ! dte ) {
		dte = new Date( );
	}
	else if ( typeof( dte ) == "string" ) {
		// format: MM-DD-YYYY
		a = dte.split( "-" );
		dte = new Date( int( a[2] ), int( a[0] ) - 1, int( a[1] ) );
	}

	d = new xDate( dte );
	return( d.format( fstr ) );
}

function dateSetFromStr( dte, tme ) {
	// dte = mm-dd-yyyy  time = hh:mm:ss
	var d, a;

	d = new Date( );

	a = dte.split( "-" );

	d.setFullYear( int( a[2] ) );
	d.setMonth( int( a[0] ) - 1 );
	d.setDate( int( a[1] ) );

	if ( isvar( tme ) ) {
		a = tme.split( ":" );
		d.setHours( int( a[0] ) );
		d.setMinutes( int( a[1] ) );
		d.setSeconds( int( a[2] ) );
	}

	return( d );
}

function keytodate( key ) {
	// key = "YYYYMMDD"
	return( substr( key, 5, 2 ) + "-" + substr( key, 7, 2 ) + "-" + left( key, 4 ) );
}
function datetokey( dte ) {
	// dte = "MM-DD-YYYY"
	return( substr( dte, 7, 4 ) + left( dte, 2 ) + substr( dte, 4, 2 ) );
}

function strswap( s, s1, s2 ) {
	var p = 0;
	if ( ! s ) {
		return( s );
	}
	while ( ( p = s.indexOf( s1, p ) ) > -1 ) {
		s = s.substring( 0, p ) + s2 + s.substring( p + s1.length );
		p += s2.length;
	}
	return( s );
}

function strswapi( s, s1, s2 ) { 
	// DO NOT CHANGE
	var p = 0; 
	s1 = lower( s1 );
	
	while ( ( p = lower( s ).indexOf( s1, p ) ) > -1 ) { 
		s = s.substring( 0, p ) + s2 + s.substring( p + s1.length ); 
		p += s2.length; 
	}
	return( s ); 
}

function domAdd( oparent, el, id ) {
	var obj;

	obj = document.createElement( el );
	obj.id = id;
	if ( oparent ) {
		oparent.appendChild( obj );
	}
	else {
		document.body.appendChild( obj );
	}
//	obj = domObject( obj.id );

	return( obj );
}

function domBorderSet( o, style, width, clr ) {
	o.style.borderStyle = style;
	o.style.borderWidth = width;
	o.style.borderColor = clr;
}

function domDeleteIE( d ) {
	// from http://javascript.crockford.com/memory/leak.html
	var a, i, l, n, o;
	if ( d ) {

		a = d.attributes;
		if ( a ) {
			l = a.length;
			for (i=0; i<l; i+=1 ) {
				if ( a[i] ) {
					n = a[i].name;
					if ( typeof( d[n] ) == 'function' ) {
						d[n] = null;
					}
				}
			}
		}
		a = d.childNodes;
		if ( a ) {
			l = a.length;
			for ( i=0; i<l; i+=1 ) {
				domDeleteIE( a[i] );
			}
		}
	}
}

function domDelete( obj ) {
	if ( ! obj ) {
		return;
	}

	if ( xlib.IsIE && obj ) {
//		try {
			domDeleteIE( obj );
//		} catch( e ) { }
	}
	try {
		if ( obj ) {
			obj.parentNode.removeChild( obj );
		}
	} catch( e ) { }
}

function domImageSet( o, src, FilterOnly ) {
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	if ( strati( ".png", src ) && xlib.pngfix ) {
		if ( ! FilterOnly ) {
	   		o.src = xWinImageDir + "/trans.gif";
	   	}
   		o.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
	}
	else {
		//if ( ! FilterOnly ) {
			o.src = src;
		//}
	}
}


function domPurge( d, OnlyChildren ) {
	// http://www.crockford.com/javascript/memory/leak.html
	var a, i, l, n;

	try {
		a = d.attributes
	}
	catch ( e ) {
		return;
	}

	if ( ! OnlyChildren ) {
		if (a) {
			l = a.length;
			for (i = 0; i < l; i += 1) {
				try {
					n = a[i].name;
					if (typeof d[n] == 'function') {
						d[n] = null;
					}
				} catch ( e ) { }
			}
		}
	}
	a = d.childNodes;
	if (a) {
		l = a.length;
		for (i = 0; i < l; i += 1) {
			try {
				domPurge(d.childNodes[i]);
			}
			catch ( e ) { }
		}
	}
}

function domInnerHTML_get( o, flag ) {
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	if ( ! o ) { return( "" ); }
	if ( ! flag ) {
		return o.innerHTML;
	}
	var data = o.innerHTML;
	domInnerHTML_set( o, "" );
	return( data )
}

function domInnerHTML_set( o, val, OnlyChildren ) {
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	if ( ! o ) { return; }
	if ( o.innerHTML.length ) { domPurge( o, OnlyChildren ); }
	o.innerHTML = val;
}

function domInsertAfter( refNode, newNode ) {
	refNode.parentNode.insertBefore( newNode, refNode.nextSibling );
}

function domOuterHTML_get( o ) {
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	if ( ! o ) { return( "" ); }
	return o.outerHTML;
}

function domOuterHTML_set( o, val, OnlyChildren ) {
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	if ( ! o ) { return; }
	if ( o.outerHTML.length ) { domPurge( o, OnlyChildren ); }
	o.outerHTML = val;
}

function domObjByName( name ) {
	document.getElementsByName( name );
}

function enterKey( e, f ) {
	// onKeyDown="enterKey( xlib.eventGet( event ), function )"
	if ( xlib.eventKey( e ) == 13 ) {
		//xlib.eventCancelBubble( e );
		//xlib.eventCancel( e );
		f( );
		return( false );
   	}
   	return( true );
}

function findPos( obj ) {
	var x, y;
	x = findPosX( obj );
	y = findPosY( obj );
	return( { "x":x, "y":y } );
}

function findPosX( obj ) {
	var curleft = 0;
	if ( obj.offsetParent ) {
		while ( 1 ) {
			curleft += obj.offsetLeft;
			if ( ! obj.offsetParent ) {
            	break;
            }
          	obj = obj.offsetParent;
		}
	}
    else if ( obj.x ) {
		curleft += obj.x;
	}
    return( curleft );
}

function findPosY( obj ) {
	var curtop = 0;
	if ( obj.offsetParent ) {
		while ( 1 ) {
			curtop += obj.offsetTop;
			if ( ! obj.offsetParent ) {
				break;
			}
          	obj = obj.offsetParent;
		}
	}
    else if ( obj.y ) {
		curtop += obj.y;
	}
	return( curtop );
}


function jsDecode( str ) {
	var d;
	try {
		d = decodeURIComponent( str );
		return( d );
	}
	catch ( e ) {
		return strswap( unescape( str ), "%2B", "+" );
	}
}

function jsEncode( str ) {
	var d = encodeURIComponent( str );
	d = strswap( d, "'", "%27");
	return( d );
}

function lbAdd( o, id, val ) {
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	o[o.length] = new Option( val, id );
}

function lbInsert( o, id, val, index, maxnum ) {
	var a, b, cnt, i, j;
	// 0-based

	if ( typeof( o ) == "string" ) { o = domObject( o ); }

	cnt = o.length;
	if ( index+1 > cnt ) {
		lbAdd( o, id, val );
		return;
	}
	cnt++;
	a = o.options;
	b = [];
	x = 0;
	for ( i=0, j=0; i<cnt; i++ ) {
		if ( maxnum && ( j >= maxnum ) ) {
			break;
		}
		if ( i == index ) {
			b[j++] = [ val, id ];
			x=1;
			continue;
		}
		b[j++] = [ a[i-x].text, a[i-x].id ];
	}

	o.length = 0;
	cnt = len( b );
	for ( i=0; i<cnt; i++ ) {
		o[i] = new Option( b[i][0], b[i][1] );
	}
}

function lbCurSelValue( o, IsText ) {
	if ( ! isvar( o ) ) return;
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	if ( o.selectedIndex < 0 ) { return( "" ); }
	return( IsText ? o[ o.selectedIndex ].text : o[ o.selectedIndex ].value );
}

function lbCurSelText( o ) {
	if ( ! isvar( o ) ) return;
	return lbCurSelValue( o, 1 );
}

function lbDelete( o, item ) {
	var cnt, i;

	cnt = o.length;
	if ( item < 0 || item >= cnt ) {
		return( 0 );
	}

	for ( i=item; i<cnt-1; i++ ) {
		o[i] = new Option( o[i+1].text, o[i+1].value );
	}
	o.length = cnt-1;

	return( 1 );
}


function int( n ) {
	try {
		if ( strempty( "" + n  ) ) {
			return( 0 );
		}
		return parseInt( n, 10 );
	}
	catch ( e ) {
		return( 0 );
	}
}

function hex2dec( hx ) {
	return parseInt( hx, 16 );
}

function isAlpha( s ) {
	var i, c;
	for ( i=0; i<s.length; i++ ) {
		c = s.charAt( i );
		if ( ( c < "a" || c > "z" ) && ( c < "A" || c > "Z" ) ) {
			if ( c != " " ) {
				return( 0 );
			}
		}
	}
	return( 1 );
}

function isNumeric( s ) {
	var i, c;
	for ( i=0; i<s.length; i++ ) {
		c = s.charAt( i );
		if ( ( c < "0" || c > "9" ) && ( c != "." ) && ( c != "-" ) ) {
			return( 0 );
		}
	}
	return( 1 );
}

function isUrl( url ) {
	if ( strat( "\n", url ) ||
		 strat( "<", url )
		  ) {

		return( 0 );
	}
	if ( strat( " ", alltrim( url ) ) ) {
		return( 0 )
	}

	if ( strati( "javascript:", url ) ) {
		return( 0 )
	}

//	if ( len( url ) > 2048 ) {
//		return( 0 )
//	}
	return( 1 );	// maybe!
}

function isvar( v ) {
	if ( typeof( v ) == "undefined" ) {
		return( 0 );
	}
	if ( v == null ) {
		return( 0 );
	}
	return( 1 );
}

function isImageOk( oimg ) {		// thanks to: http://talideon.com/weblog/2005/02/detecting-broken-images-js.cfm
    if ( ! oimg.complete ) {
        return false;
    }

    if ( typeof oimg.naturalWidth != "undefined" && oimg.naturalWidth == 0 ) {
        return false;
    }

    return true;
}

function jsInclude( jsFile ) {
	// onload = function( ) { jsInclude( 'main.js' ) }
	var scriptNode = document.createElement( 'script' );
	scriptNode.type = 'text/javascript';
	scriptNode.src = jsFile;
	document.getElementsByTagName( 'head' )[0].appendChild( scriptNode );
}


function lbSearchText( o, s, IsSet ) {
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	for ( var i=0; i<o.length; i++ ) {
		if ( o.options[i].text == s ) {
			if ( IsSet ) { o[i].selected = true; }
			return( i );
		}
	}
	return( -1 );
}

function lbSearchValue( o, s, IsSet ) {
	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	for ( var i=0; i<o.length; i++ ) {
		if ( o.options[i].value == s ) {
			if ( IsSet ) { o[i].selected = true; }
			return( i );
		}
	}
	return( -1 );
}

function left( s, n ) {
	if ( n <= 0 ) { return( "" ); }
	s = String( s );
	if ( n >= s.length ) { return( s ); }
    return s.substring( 0, n );
}

function random( range ) {
	//returns random number between 0 and range;
	return Math.floor( Math.random( ) * ( range + 1 ) );
}

function strabbr( s, l ) {
	if ( len( s ) <= l ) {
		return( s );
	}
	return( left( s, l ) + "..." );
}

function stratnext( sub, s, n ) {
	var i, ttl=0, x;
	if ( strcount( sub, s ) < n ) {
		return( 0 );
	}
	for ( i=1; i<=n; i++ ) {
		x = strat( sub, s, i );
		ttl += x;
		s = right( s, len( s ) - x );
	}
	return( ttl );
}

function stratlast( sub, s ) {
	var x = strcount( sub, s );
	return stratnext( sub, s, x );
}

function stratlasti( sub, s ) {
	var x;
	sub = upper( sub ); s = upper( s );
	x = strcount( sub, s );
	return stratnext( sub, s, x );
}

function stratnexti( sub, s, n ) {
	return stratnext( upper( sub ), upper( s ), n );
}

function strcapfirst( s, nolower ) {
	if ( nolower ) {
		return( upper( left( s, 1 ) ) + right( s, len( s ) - 1 ) );
	}
	return( upper( left( s, 1 ) ) + lower( right( s, len( s ) - 1 ) ) );
}

function strcommas( n ) {
	var a, v, reg;

	n = "" + n;
	a = n.split( "." );
	v = a[0];
	reg = /(\d+)(\d{3})/;
	while ( reg.test( v ) ) {
		v = v.replace( reg, '$1' + ',' + '$2' );
	}

	return( v + ( a[1] && a[1].length ? "." + a[1] : "" ) );
}


function strcount( sub, s ) {
	if ( ! sub ) {
		return 0;
	}

	var r=0;
	var pos = s.indexOf( sub, 0);
	while (pos > -1) {
		r++;
		pos = s.indexOf( sub, pos + 1 );
	}
	return( r );
}

function strcounti( sub, s ) {
	return strcount( upper( sub ), upper( s ) );
}

function strcrop( s, n ) {
	var cnt;

	if ( typeof( s ) != "string" ) { return( s ); }

	cnt = len( s );
	if ( n >= cnt ) { return( "" ); }

	return( left( s, cnt - n ) );
}


function strempty( val ) {
	if ( ! val ) { return( 1 ); }
	return( alltrim( val ).length ? 0 : 1 );
}

function strextract( s, delim, n ) {
	var a = String( s ).split( delim );
	if ( len( a ) < n ) {
		return( "" );
	}
	return a[n-1];
}

function substr( s, start, numchars ) {
	return s.substring( start-1, start + numchars - 1 );
}

function tableCellObj( otable, row, col ) {
	// one-based
	return otable.rows[ row - 1 ].cells[ col - 1 ];
}

function tableRowObj( otable, row ) {
	// one-based
	return otable.rows[ row - 1 ];
}

function urlExt( url ) {
	var x;

	if ( ! isUrl( url ) ) { return; }

	x = chrcount( ".", url );
	if ( ! x ) { return; }

//	return alltrim( strextract( url, ".", x + 1 ) );
	return alltrim( strextract( strextract( url, "?", 1 ), ".", x + 1 ) );
}

function urlFix( url ) {
	url = alltrim( url );
	if ( upper( left( url, 3 ) ) == "WWW" ) {
		url = "http://" + url;
	}
	if ( upper( left( url, 17 ) ) == "STATIC.FLICKR.COM" ) {
		url = "http://" + url;
	}

	return( url );
}

function urlType( url ) {
	var ext = urlExt( url );
	if ( ! ext ) {
		// look closer for a feed
		url = upper( url );
		if ( strati( "RSS.", url ) ||
		   strati( ".RSS", url ) ||
		   strati( "/RSS/", url ) ||
		   strati( "/FEEDS.", url ) ||
		   ( upper( right( url, 5 ) ) == "/ATOM" ) ||
		   ( upper( right( url, 4 ) ) == "/RSS" ) ) {
			return( DATA_FEED );
		}
		return( DATA_UNKNOWN );
	}
	switch ( upper( ext ) ) {
	  case "JPG":
	  case "JPEG":
	  case "GIF":
	  case "PNG":
	  case "ICO":
	  case "BMP":
	  case "TIFF":
		return( DATA_IMAGE );

	  case "WAV":
	  case "MP3":
	  case "MP2":
	  case "MPA":
	  case "AU":
		return( DATA_MUSIC );

	  case "MOV":
	  case "FLV":
	  case "QT":
	  case "SWF":
	  case "MPEG":
	  case "MPV2":
	  	return( DATA_VIDEO );

	  case "DOC":
	  case "XLS":
	  case "TXT":
	  case "PPT":
	  case "INI":
	  case "PDF":
	  	return( DATA_DOCUMENT );

	  case "JS":	return( DATA_JS );
	  case "CSS":	return( DATA_CSS );

	  case "XML":
	  case "XSL":
	  case "XSD":
	  case "RNG":
	  case "RDF":
	  	return( DATA_XML );

	  case "HTM":
	  case "HTML":
	  case "SHTML":
	  case "AP":
	  case "APX":
	  case "XHTML":
	  	return( DATA_HTML );

	  case "ZIP":
	  case "GZ":
	  case "GZC":
	  case "TGZ":
	  case "TAR":
	  	return( DATA_ZIP );

	  case "EXE":
	  case "COM":
	  case "XPI":
		return( DATA_APP );

	  case "RSS":
	  	return( DATA_FEED );
	}

	// look closer for a feed
	url = upper( url );
	if ( strati( "RSS.", url ) ||
	   strati( "=RSS", url ) ||
	   strati( ".RSS", url ) ||
	   strati( "/RSS/", url ) ||
	   strati( "/FEEDS.", url ) ||
	   ( upper( right( url, 5 ) ) == "/ATOM" ) ||
	   ( upper( right( url, 4 ) ) == "/RSS" ) ) {
	  	return( DATA_FEED );
	}
	return( DATA_LINK );
}


function wait( ms ) {
	var d, cd;
	d = new Date();
	do { cd = new Date( ); }
	while ( cd-d < ms );
}


function x_ie_eventGet( e ) {
	return( e ? e : window.event );
}
function x_w3c_eventGet( e ) {
	return( e );
}
function x_ie_eventCancel( e ) {
   	e.returnValue=false;
    e.cancel = true;
}
function x_opera_eventCancel( e ) {
	e.preDefault( );
}
function x_w3c_eventCancel( e ) {
	e.preDefault( );
}
function x_ie_eventKey( e ) {
	return e.keyCode;
}
function x_w3c_eventKey( e ) {
	return e.which;
}

var _winMM = null;
function xWinManualMove( w ) {
	if ( _winMM ) {
		xlib.eventUnbind( document, "keydown", xWinMMHandler );
	}
	_winMM = w;
	xlib.eventBind( document, "keydown", xWinMMHandler, true );
}

function xWinMMHandler( e ) {
    var k = xlib.keyGet( e );
    var w = _winMM;
    var x=1;

	if ( k.isALT ) {
		x = 25;
	}
	else if ( k.isCTRL ) {
		x = 10;
	}

    switch ( k.code ) {
      case KEY_ARROWLEFT:
		xlib.UpdateFlag( 1 );
		w.position( w.left - x, w.top, w.width, w.height, 1 );
		xlib.eventCancel( e );
		return( true );
      case KEY_ARROWUP:
		xlib.UpdateFlag( 1 );
		w.position( w.left, w.top - x, w.width, w.height, 1 );
		xlib.eventCancel( e );
		return( true );
      case KEY_ARROWRIGHT:
		xlib.UpdateFlag( 1 );
		w.position( w.left + x, w.top, w.width, w.height, 1 );
		xlib.eventCancel( e );
		return( true );
      case KEY_ARROWDOWN:
		xlib.UpdateFlag( 1 );
		w.position( w.left, w.top + x, w.width, w.height, 1 );
		xlib.eventCancel( e );
		return( true );
	  case KEY_ESCAPE:
		_winMM = null;
		xlib.eventUnbind( document, "keydown", xWinMMHandler );
        break;
    }
}


function xWinModalResize( ) {
	var obj, pt;
	obj = domObject( "xModalLayer" );
	if ( ! obj ) { return; }
	pt = xlib.winSize( );
	obj.style.width = pxWrap(pt.width);
	obj.style.height = pxWrap(pt.height);
}

function xWinModalScroll( ) {
	var pt = xlib.eventCurrentGet( "scollPos" );
	window.scrollTo( pt.x, pt.y );
}

function xImageCalcDone( ) {
	var pSize, pos, data;

	if ( ! xlib.oCalcImage ) { return; }

	pSize = { w: int( xlib.oCalcImage.width ), h: int( xlib.oCalcImage.height ) };

	xlib.eventUnbind( xlib.oCalcImage, "load", xImageCalcDone );

	domDelete( xlib.oCalcImage );
	xlib.oCalcImage = null;
	xlib.objFromData( xlib.ddData, xlib.ddPos, 1, pSize );
}

function xImageCalcSize( data, pos ) {
	if ( xlib.oCalcImage ) {
		domDelete( xlib.oCalcImage );
	}

	xlib.ddData = data;
	xlib.ddPos = pos;

	xlib.oCalcImage = new Image( );
	//xlib.oCalcImage.onload = function( ) { alert('boo'); }
	xlib.eventBind( xlib.oCalcImage, "load", xImageCalcDone );
	xlib.oCalcImage.src = data;
	
	if ( upper( xlib.browser ) == "CHROME" ) {
		xImageCalcDone( );
	}

}


function xWebVar( vname, data, IsInt ) {
	var val, x = strati( vname + "=", data );
	if ( ! x ) { return( "" ); }

	data = right( data, len( data ) - ( x + len( vname ) ) );
	val = decodeURIComponent( strextract( data, "&", 1 ) );

	if ( IsInt ) {
		val = strswap( val, "'", "" );
		val = strswap( val, "\"", "" );
		val = strswap( val, "\\", "" );
		return( int( val ) );
	}
	return( val );
}

function xWinVar( vname, data ) {
	var w = new xWindow( );
	w.unpack( data );
	return( w[vname] );
}

function rbCheck( rb, val ) {
	var i;

	if ( typeof( rb ) == "string" ) {
		rb = domObject( rb );
	}

	if ( typeof( val ) == "number" ) {
		rb[val].checked = true;
		return( 1 );
	}
	for ( i=0; i<rb.length; i++ ) {
		if ( rb[i].value == val ) {
			rb[i].checked = true;
			return( 1 );
		}
	}

	return( 0 );
}

function rbSelectedIndex( obj, n ) {
	var i;
	if ( typeof( obj ) == "string" ) {
		obj = domObject( obj );
	}
	if ( typeof( n ) != "number" ) {
		n = obj.length;
	}

	for ( i=0; i<n; i++ ) {
		if ( obj[i].checked ) { return( i ); }
	}
	return( -1 );
}

function rbSelectedValue( obj, n ) {
	var i;
	if ( typeof( obj ) == "string" ) {
		obj = domObject( obj );
	}

	if ( typeof( n ) != "number" ) {
		n = obj.length;
	}

	for ( i=0; i<n; i++ ) {
		if ( obj[i].checked ) { return( obj[i].value ); }
	}
	return( "" );
}

function ptContained( pt, r2 ) {
	var r1 = { left : pt.x, top : pt.y, width : 1, height : 1 }
	return( rectContained( r2, r1 ) );
}

function rectContained( r1, r2 ) {
	// is r2 contained in r1
    if ( ( r2.left >= r1.left ) && ( r2.left + r2.width <= r1.left + r1.width ) && ( r2.top >= r1.top ) && ( r2.top + r2.height <= r1.top + r1.height ) ) {
        return( 1 );
    }
    return( 0 );
}

function rectIntersects( r1, r2 ) {
	// does r1 intersect with r2
	if ( ( ( r1.left < ( r2.left + r2.width ) ) && ( r2.left < ( r1.left + r1.width ) ) ) && ( r1.top  < ( r2.top + r2.height ) ) ) {
        return( r2.top < ( r1.top + r1.height ) );
    }
    return( 0 );
}

function rectScale( w, h, wNew, hNew ) {
	var rRation, w2, h2;

	rRatio = w / h;
	h2 = Math.round( wNew * ( 1 / rRatio ) );
	if ( h2 >= hNew ) {
		return( { w : wNew, h : h2 } );
	}

	rRatio = h / w;
	w2 = Math.round( hNew * ( 1 / rRatio ) );
	if ( w2 >= wNew ) {
		return( { w : w2, h : hNew } );
	}

	return( { w : w, h : h } );
}

function dollar( val ) {
	return( numFormat( val, FORMAT_CURRENCY ) );
}

function numFormat( n, ftype ) {
	var x, s, a;

	if ( ! ftype ) {
		return( "" + n );
	}

	if ( ftype & FORMAT_CURRENCY ) {
		n = Math.round( n * 100 ) / 100;
		s = alltrim( "" + n );
		a = s.split( "." )
		n = a[0] + "." + ( a[1] != null ? left( a[1] + "00", 2 ) : "00" );
		n = strcommas( n );
	}

	if ( ftype & FORMAT_MINUTES ) {
		x = new xDate( );
		n = x.diff( null, null, int( n * 1000 * 60 ) );
	}

	if ( ftype & FORMAT_SECONDS ) {
		x = new xDate( );
		n = x.diff( null, null, int( n * 1000 ) );
	}

	if ( ftype & FORMAT_COMMAS ) {
		n = strcommas( n );
	}

	if ( ftype & FORMAT_SUFFIX ) {
		x = int( right( "0" + n, 2 ) );
		if ( ( x > 3 ) && ( x < 20 ) ) {
			n += "th";
		}
		else {
			switch ( right( "" + n, 1 ) ) {
			  case "1":	n += "st"; break;
			  case "2":	n += "nd"; break;
			  case "3":	n += "rd"; break;
			  default:  n += "th";
			}
		}
	}

	return( n );
}

// from open source open5G js lib
function parseToObj( data ) {
	// note: "class" vars are renamed as "_class"

	var aNames = new Array( ), aValues = new Array( ), i=0, k=0, c, buf, obj, s, tag;
	var cnt, IsIn, curtag, curDelim, IsDelim, curValue;

	data = strswap( data, "\r\n", " " );
	data = strswap( data, "\n", " " );

	tag = substr( data, 2, strat( " ", data ) - 2 );

	cnt = len( data );
	IsIn=0;
	curtag = "";
	curDelim = "";
	IsDelim = 0;
	curValue = "";
	for ( i=len( tag ) + 2; i<cnt; i++ ) {
		c = data.charAt(i);

		if ( IsIn ) {
			if ( ! IsDelim ) {
				switch ( c ) {
				  case " ":
				  	break;
				  case "'":
				  case "\"":
				  	IsDelim = 1;
				  	curDelim = c;
				  	break;
				  default:
				  	IsDelim = 1;
				  	curDelim = " ";
				  	curValue += c;
				}
				continue;
			}

			if ( ( c == curDelim ) || ( ( curDelim == " " ) && ( c == ">" ) ) ) {
				aValues[k++] = strswap( curValue, "\\", "\\\\" );
				curValue = "";
				IsIn = 0;
				IsDelim = 0;
			}
			else {
				curValue += c;
			}

			continue
		}

		switch ( c ) {
		  case " ":
		  	continue;
		  case "=":
		  	aNames[k] = curtag;
		  	curtag = "";
		  	IsDelim = 0;
		  	IsIn = 1;
		  	continue

		}
		curtag += c;

	}

	cnt = len( aNames );

	// generate obj string
	if ( ! cnt ) {
		buf = '( { "tagname" : "' + tag + '" } )';
	}
	else {
		buf = '( { "tagname" : "' + tag + '", ';
		for ( k=0; k<cnt; k++ ) {
			if ( aNames[k] == "class" ) {
				aNames[k] = "_" + aNames[k];
			}
			buf += '"' + aNames[k] + '" : "' + aValues[k] + '", ';
		}
		buf = strcrop( buf, 2 );
		buf += ' } )';
	}

	obj = eval( buf );
	obj.avars = aNames;

	if ( ! obj.id ) {
		obj.id = ""
	}

	obj.restore = function ( ) {
		var s, cnt, i;

		s = "<" + this.tagname;
		if ( ! strempty( this.id ) ) {
			s += " id=\"" + this.id + "\"";
		}
		cnt = this.avars.length;
		for ( i=0; i<cnt; i++ ) {
			if ( upper( this.avars[i] ) != "ID" ) {
				try {
					val = eval( "this." + this.avars[i] );
					if ( val != null ) {
						s += " " + this.avars[i] + "=\"" + val + "\"";
					}
				} catch( e ) { }
			}
		}
		s += ">";
		return( s );
	}

	return( obj );
}


function pxWrap( x ) {
	if ( strati( "px", "" + x ) ) {
		return( x );
	}
	return( "" + x + "px" );
}

////////////////////////
// Window functions

function xWinIndexFromName( name ) {
	var cnt, i, e;

	if ( ! name ) {
		return( 0 );
	}
	name = lower( name );
//	cnt = xWinList.length + 1;
	for ( i=1; i<xWinMaxNum; i++ ) {
		if ( xWinList[i] && name == lower( xWinList[i].name ) ) {
			return( i );
		}
	}

	return( 0 );
}

function xWinFromName( name ) {
	var i = xWinIndexFromName( name );
	if ( ! i ) {
		return( null );
	}
	return xWinList[i];
}

function xWinFromPoint( pt ) {
	var cnt, i, w, curW=null, curZ=0;

	cnt = xWinList.length + 1;
	for ( i=1; i<xWinMaxNum; i++ ) {
		w = xWinList[i];
		if ( ( w.left >= pt.x ) && ( ( w.left + w.width ) <= pt.x )	&&
			 ( w.top >= pt.y ) && ( ( w.top + w.height ) <= pt.y )) {
			 if ( w.zorder > curZ ) {
			 	curZ = w.zorder;
			 	curW = w;
			 }
		}
	}
	return( curW );
}

function xWin( name ) {
	return xWinFromName( name );
}

function xWinName( el ) {
	return( xWinFromElement( el ) );
}

function xWinFromElement( el ) {
	var obj;

	if ( typeof( el ) == "string" ) {
		el = domObject( el );
	}

	while ( 1 ) {
		if ( ! el ) {
			return( null );
		}
		if ( el.xid == "x-win" ) {
			return xWinFromName( el.xname );
		}
		el = el.parentNode;
	}
}

function xWinOverBody( el ) {
	var obj;

	if ( typeof( el ) == "string" ) {
		el = domObject( el );
	}

	while ( 1 ) {
		if ( ! el ) {
			return( 0 );
		}
		if ( el.xid == XLIB_SIGBODY ) {
			return( 1 );
		}

		el = el.parentNode;
	}
}

// event functions used by win event handlers
function xWinEvent_Click( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) { w.eventRun( 'Click', e ); }
}

function xWinEvent_DblClick( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) { w.eventRun( 'DblClick', e ); }
}

function xDragDataGet( e ) {
	var o, d;

//alert( e.data );

	o = xlib.eventTarget( e );
	switch ( o.nodeName ) {
	  case "IMG":
	  	d = "<img src='" + o.src + "' border=" + o.border + " width=" + o.width + " height=" + o.height + " alt=\"" + o.alt + "\"  title=\"" + o.title + "\">";
	  	break;

	  case "A":
	  	d = o.href;
	  	break;

	  default:
		d = xlib.textSelected( );
	}
	return( d );
}

function xWinEvent_Drag( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	xMouseE.dragData = xDragDataGet( e );
	if ( w ) {
		w.eventRun( 'Drag', e );
		if ( w.oaOpts && w.oaOpts & xlib.openajax.ID_DRAG ) {
			xlib.openajax.objPublish( e, xlib.openajax.ID_DRAG, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, xMouseE.dragData );
		}

	}
}
function xWinEvent_Drop( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) {
		// dropped on a window
		if ( ! w.eventRun( 'Drop', e ) ) {
			xDropDataProcess( e );
		}
		if ( w.oaOpts && w.oaOpts & xlib.openajax.ID_DROP ) {
			xlib.openajax.objPublish( e, xlib.openajax.ID_DROP, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, xDropDataGet( e ) );
		}
	}
	else {
		// dropped on the desktop
		xDropDataProcess( e );
	}

	xlib.eventCancelBubble( e );
	xlib.eventCancel( e );
}

function xWinError( e ) {
	if ( xlib.errorFunc ) {
		try {
			if ( ! e ) {
				e = xlib.eventGet( event );
			}
			xlib.errorFunc( e );
		}
		catch ( e ) {
			xlib.errorFunc( e );
		}
	}
}
function xWinEvent_Cancel( e ) {
	return xlib.eventCancel( xlib.eventGet( e ) );
}

function xWinEvent_DragMove( e ) {
	try {
	    e.dataTransfer.dropEffect = 'move';
	    e.returnValue = false;
	}
	catch ( e ) { }
}

function xWinEvent_ttOn( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) { w.tooltipFunc( e, 1 ); }
}
function xWinEvent_ttOff( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) { w.tooltipFunc( e, 0 ); }
}

function xlib_PngFix( o ) {
	var a, i, src;

	if ( ! xlib.pngfix ) {
		return;
	}

	if ( typeof( o ) == "string" ) { o = domObject( o ); }
	if ( ! o ) {
		o = xlib.eventBody( );
	}

	// check images
	try {
		a =  o.getElementsByTagName( 'img' );
		for ( i=0; i<a.length; i++ ) {
			if ( strati( ".PNG", a[i].src ) ) {
				src = a[i].src;
				a[i].src = xWinImageDir + "/trans.gif";
				a[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
			}
		}
	} catch ( e ) { }

	// table
	try {
		a =  o.getElementsByTagName( 'table' );
		for ( i=0; i<a.length; i++ ) {
			src = a[i].getAttribute( "background" );
			if ( strati( ".PNG", src ) ) {
				a[i].style.background = "";
				a[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
			}
		}
	} catch ( er ) { }

	// td
	try {
		a =  o.getElementsByTagName( 'td' );
		for ( i=0; i<a.length; i++ ) {
			src = a[i].getAttribute( "background" );
			if ( strati( ".PNG", src ) ) {
				a[i].style.background = "";
				a[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
			}
		}
	} catch ( err ) { }
}


////////////////////////////////////////
// Window Class
//
function xWindow( name, data, NoCreate ) {
	this.sig				= XLIB_SIG;

	this.name 				= name;
	this.otype				= 0;
	this.oparent 			= null;		// "this" of parent
	this.oparentid			= "";
	this.obj				= null;
	this.oHdr				= null;
	this.oBody				= null;
	this.oFtr				= null;
	this.oBG				= null;		// bg used for IE < 7
	this.olayer				= null;		// used for trans layer
	this.zParent			= "";

	this.issys				= 0;		// will not save if set to 1

	this.zorder				= 0;
	this.style				= 0;
	this.displayMode		= DISP_NORMAL;

	this.left				= 0;
	this.top				= 0;
	this.width				= 0;
	this.height				= 0;
	this.margin				= 0;
	this.padding			= 0;
	this.overflow			= "auto";
	this.opacity			= null;
	this.scrollTop 			= 0;
	this.scrollLeft 		= 0;

	this.bgMargin			= "";

	this.bgColor 			= xWinBgColor;
	this.bgImage			= "";
	this.transLevel			= xWinTransLevel;
	this.rotation			= 0;					// used for images

	this.borderStyle 		= "solid";
	this.borderWidth 		= 1;
	this.borderWidthThick 	= 4;
	this.borderColor 		= "black";

	this.header				= "";
	this.hdrHeight			= 22;
	this.hdrBgColor			= xWinHdrBgColor;
	this.hdrBgImage			= xWinHdrBgImage;
	this.hdrPadding			= 2;
	this.hdrTextClass		= "smtxt";
	this.hdrTextColor		= "white";
	this.funcHeader			= this.headerFunc;

	this.bodyClass			= xWinBodyClass;
	this.tooltip			= "";
	this.ttOpts				= "";
	this.ttWidth			= 300;
	this.ttBG				= "";

	this.footer				= "";
	this.ftrHeight			= 22;
	this.ftrBgColor			= xWinFtrBgColor;
	this.ftrBgImage			= xWinFtrBgImage;
	this.ftrPadding			= 2;
	this.ftrTextClass		= "smtxt";
	this.ftrTextColor		= "white";
	this.funcFooter			= this.footerFunc;

	this.helpFunc			= null;

	this.action				= "";
	this.imagedir			= xWinImageDir;
	this.shadow				= "";

	this.eCreate			= null;
	this.eDestroy			= null;
	this.eDisplay			= null;
	this.eDrag				= null;
	this.eDrop				= null;
	this.eClick				= null;
	this.eDblClick			= null;
	this.eResize			= null;
	this.eMove				= null;
	this.rollover			= "";

	this.eTimer				= "";
	this.eTimerInterval		= 0;
	this.eTimerReload		= 0;
	this.eTimerFunc			= null;

	this.theme				= xWinDefaultTheme;

	this.oaServices			= "";	// OpenAjax - services (str)
	this.oaSubscriptions	= "";	// OpenAjax - subscriptions (str)
	this.oaDefSrvs			= null;	// temp instance var { sid, opts }
	this.oaOpts				= 0;	// temp instance var (int)
	this.oa_aSubscriptions	= []	// temp instance var (array) (str)

	this.funcSysMenu		= this.sysmenuFunc;
	this.funcContextMenu	= this.contextmenuFunc;

	this.propCustom			= "";

	this.err				= null;

	if ( data && data.length ) {
		this.unpack( data );
		if ( name && ( ! strempty( name ) ) ) {
			this.name = name;
		}
		if ( ! strempty( this.theme ) ) {
			try {
				var w = eval( "theme_" + this.theme + "( )" );
				this.funcHeader = w.funcHeader;
				this.funcFooter = w.funcFooter;
				w = null;
			} catch( e ) { }
		}
		if ( ! NoCreate ) {
			this.create( );
		}
	}
}

//xWindow.prototype.debug = function( id ) {
//	if ( upper( this.name ) != "MYACCOUNTMENU" ) {
//		return;
//	}
//	alert( "debug: " + id );
//}

xWindow.prototype.create = function(oParentDocBody) {
	var o, style, w=0;
	var s, data, x;

	if ( ! this.name ) {
		this.errSet( ERR_NONAME );
		return( 0 );
	}

	if ( ! this.winRegister( ) ) {
		return( 0 );
	}
	if ( ( ! this.oparent ) && ( ! strempty( this.oparentid ) ) ) {
		this.oparent = domObject( this.oparentid );
	}

	// base parent object
    if (oParentDocBody) {
        this.obj = domAdd(oParentDocBody, "div", this.name);
    } else {
	this.obj = domAdd( this.oparent ? this.oparent.oBody : null, "div", this.name );
    }

	this.obj.xid = "x-win";
	this.obj.xname = this.name;

	style = this.style;

	o = this.obj.style;
	o.overflow = "hidden";
	o.position = "absolute";
	o.display = "block";
	o.visibility = "hidden";
	if ( this.opacity != null ) { xlib.fx.opacity( this.obj.id, this.opacity ); }

	if ( ( this.otype == OTYPE_IMAGE ) && ( this.rotation != 0 ) ) {
		this.overflow = "hidden";
		this.style = style &= ~WS_BORDER;
		this.style = style |= WS_TRANSPARENT;
		this.transLevel = 100;
	}
	else {
		if ( style & WS_BORDER ) {
			w = this.borderWidth;
		}
		else if ( style & WS_BORDERTHICK ) {
			w = this.borderWidthThick;
		}
		if ( w ) {
			domBorderSet( this.obj, this.borderStyle, w, this.borderColor );
		}
	}

	if ( style & WS_SHADOW && ( ! ( style & WS_TRANSPARENT ) ) ) {
		this.shadowSet( this.obj );
	}

	if ( left( this.bgColor, 1 ) == "#" ) {
		if ( len( this.bgColor ) > 7 ) {
			this.bgColor = left( this.bgColor, 7 );
		}
	}

	if ( this.margin && ( ! ( style & WS_TRANSPARENT ) ) ) {
		o.background = this.bgMargin.length ? this.bgMargin : this.bgColor;
	}
	o.backgroundImage = "";

//	if ( style & WS_DROP ) {
//		eDrop = this.eDrop ? " ondrop=\"xWinFromName('" + this.name + "').eventRun( 'Drop', xlib.eventGet( event ) );\" ondragenter='xlib.eventCancel(xlib.eventGet( event ));' ondragover='xlib.eventCancel(xlib.eventGet( event ));'" : "";
//	};

	if ( xlib.pngfix ) {
		// this is required for IE < 7 to make links work properly with transparent backgrounds
		this.oBG = domAdd( this.obj, "div", this.name + "_bg" );
		this.oBG.className = this.bodyClass;
		this.oBG.style.overflow = "hidden";
		this.oBG.style.position = "absolute";
		this.oBG.style.border = "none";
		this.oBG.style.backgroundImage = "";
		this.oBG.left=0; this.oBG.top=this.hdrHeight; this.oBG.width=0; this.oBG.height=0;
		this.oBG.position = "absolute";
	}

	// body
	this.oBody = domAdd( this.obj, "span", this.name + "_body" );
	this.oBody.className = this.bodyClass;
	this.oBody.xid = XLIB_SIGBODY;
	s = this.oBody.style;
	s.left=0; s.top=this.hdrHeight; s.width=0; s.height=0;
	s.position = "absolute";
	s.margin = this.margin;
	s.padding = this.padding;
	s.display = "inline";
	s.overflow = this.overflow;
	this.oBody.scrollTop = this.scrollTop;
	this.oBody.scrollLeft = this.scrollLeft;

	this.oBody.title = this.rollover;

	if ( this.displayMode & DISP_DEFAULT ) {
		this.displayMode = xWinDefaultDisplay;
	}

	if ( style & WS_TRANSPARENT ) {
		this.transparencySet( );
	}
	else {
		if ( this.bgImage ) {
			if ( xlib.pngfix && strati( ".png", this.bgImage ) ) {
				domImageSet( this.oBG, this.bgImage, 1 );
			}
			else {
				s.backgroundImage = "url(" + this.bgImage + ")";
			}
		}
		else {
			s.background = this.bgColor;
		}
	}

	// event handlers
	if ( ( style & WS_DRAG ) && this.eDrag ) {
		xlib.eventBind( this.oBody, xlib.IsIE ? "dragstart" : "draggesture", xWinEvent_Drag );
	}
	if ( ( style & WS_DROP ) && this.eDrop ) {
		xlib.eventBind( this.oBody, "drop", xWinEvent_Drop );
	//		xlib.eventBind( this.oBody, xlib.IsIE ? "drop": "dragdrop", xWinEvent_Drop );
	//if ( xlib.IsIE ) {
		xlib.eventBind( this.oBody, "dragenter", xWinEvent_Cancel );
		xlib.eventBind( this.oBody, "dragover", xWinEvent_Cancel );
	//}
	//else {
	//		xlib.eventBind( this.oBody, "dragenter", function( e ) { alert( 'dragenter' ); } );
	//		xlib.eventBind( this.oBody, "dragover", function( ) { alert( 'dragover' ); } );
	//}

		if ( style & WS_MOVEABLE ) {
			target.addEventListener("dragstart", xWinEvent_Cancel, false);
		}

	//  target.addEventListener("dragenter", eventReceived, false);
	//  target.addEventListener("dragleave", eventReceived, false);
	//  target.addEventListener("dragover", eventReceived, false);
	}
	if ( this.tooltip && this.tooltip.length ) {
		xlib.eventBind( this.oBody, "mouseover", xWinEvent_ttOn );
		if ( ! ( this.displayMode & DISP_NOAUTOCLOSE ) ) {
			xlib.eventBind( this.oBody, "mouseout", xWinEvent_ttOff );
		}
	}

	if ( this.eTimerInterval ) {
		this.eTimerFunc	= xlib.intervalSet( "xWin( '" + this.name + "' ).timerProcess( )", this.eTimerInterval * 1000 );
	}

	// footer
	if ( style & WS_FOOTER ) {
		this.oFtr = domAdd( this.obj, "div", this.name + "_f" );
		s = this.oFtr.style;
		s.left=pxWrap(0); s.top=pxWrap(0); s.width="100%"; s.height=pxWrap(this.ftrHeight);
		s.position = "absolute";
		domInnerHTML_set( this.oFtr, this.funcFooter( this ) );
	}


	// header
	if ( style & WS_HEADER ) {
		this.oHdr = domAdd( this.obj, "div", this.name + "_h" );
		s = this.oHdr.style;
		s.left=pxWrap(0); s.top=pxWrap(0); s.width="100%"; s.height=pxWrap(this.hdrHeight);
		s.position = "absolute";
		domInnerHTML_set( this.oHdr, this.funcHeader( this ) );
	}

	if ( ( ( this.style & WS_EXTERNAL ) && strempty( this.theme ) )
		|| ( ! strempty( this.theme ) && ( ! ( style & WS_HEADER || style & WS_FOOTER ) ) && this.style & WS_EXTERNAL ) )
		{  // let themes handle this
		if ( xlib.DisableExternalContent ) {
			domInnerHTML_set( this.oBody, "FRAME-BUSTER FIXER (find the offending object and delete it): " + this.action );
		}
		else if ( xlib.isFrameBuster( this.action ) ) {
			domInnerHTML_set( this.oBody, "FRAME-BUSTER ALERT: this link has been identified as a frame-buster. Add it to your page as a button or link, but do not embed it directly in the page.<p>" + this.action );
		}
		else {
			data = this.actionUpdateFromCustom( this.action );
			data = this.actionRenderExternal( this.actionPreprocess( data ) );
			domInnerHTML_set( this.oBody, data );
		}
	}
	else {
		data = this.actionUpdateFromCustom( this.action );
		data = this.actionPreprocess( data );
		if ( ( this.otype == OTYPE_IMAGE ) && ( this.rotation != 0 ) ) {
			this.oBody.style.overflow = this.overflow = "hidden";
			data = strswapi( data, "<img ", "<img id='" + this.name + "_ri' " );
			domInnerHTML_set( this.oBody, data );
		}
		else {
			domInnerHTML_set( this.oBody, data );
		}

        var browserInUpper = upper( xlib.browser );
		if ( browserInUpper == "SAFARI" ||  browserInUpper == "CHROME") {

            this.oBody.style.visibility = "hidden";
            
			a = this.oBody.getElementsByTagName( "img" );
			for ( i=0; i<len(a); i++ ) {
				a[i].addEventListener("dragstart", xWinEvent_Cancel, false);
				//alert( a[i].src );
			}
		}
	}

    var browserInUpper = upper( xlib.browser );
    if ( ( ( style & WS_MOVEABLE ) || ( style && WS_RESIZABLE ) ) &&
		( browserInUpper != "SAFARI" ) && ( browserInUpper != "CHROME" )) {
		this.olayer = domAdd( this.obj, "div", this.name + "_lyr" );
		o = this.olayer;
		o.style.overflow = "hidden";
		o.style.position = "absolute";
		o.style.left = 0;
		o.style.top = 0;
		o.style.width = "100%";
		o.style.height = "100%";
		o.style.zIndex = -1;
		domInnerHTML_set( o, "<img src='" + xWinImageDir + "/trans.gif' border=0 width=100% height=100% style=\"cursor:move;\">" );
		xlib_PngFix( o );
	}
	xlib_PngFix( this.obj );

	// register OpenAjax Services
	this.oaOpts = 0;
	if ( xlib.openajax && this.oaServices.length ) {
		this.oaDefSrvs = xlib.openajax.objRegisterServices( this.oaServices );
		this.oaOpts = this.oaDefSrvs ? this.oaDefSrvs.opts : 0;
	}

	this.eventProcess( this.eCreate );
	xlib.UpdateFlag( 1, this );

	// OpenAjax event - ID_CREATE
	if ( this.oaOpts ) {
		if ( this.oaOpts & xlib.openajax.ID_CREATE ) {
			xlib.openajax.objPublish( null, xlib.openajax.ID_CREATE, this, null, this.oaDefSrvs.sid, "" );
		}

		// OpenAjax event - ID_KEYDOWN
		if ( this.oaOpts & xlib.openajax.ID_KEYDOWN ) {
			xlib.eventBind( this.oBody, "keydown", this.oaKeyDown );
		}
		// OpenAjax event - ID_KEYUP
		if ( this.oaOpts & xlib.openajax.ID_KEYUP ) {
			xlib.eventBind( this.oBody, "keyup", this.oaKeyUp );
		}
		// OpenAjax event - ID_KEYPRESS
		if ( this.oaOpts & xlib.openajax.ID_KEYPRESS ) {
			xlib.eventBind( this.oBody, "keypress", this.oaKeyPress );
		}

		// OpenAjax event - ID_MOUSEOVER
		if ( this.oaOpts & xlib.openajax.ID_MOUSEOVER ) {
			xlib.eventBind( this.oBody, "mouseover", this.oaMouseOver );
		}
		// OpenAjax event - ID_MOUSEOUT
		if ( this.oaOpts & xlib.openajax.ID_MOUSEOUT ) {
			xlib.eventBind( this.oBody, "mouseout", this.oaMouseOut );
		}
	}


	// register all subscriptions
	if ( xlib.openajax && this.oaSubscriptions.length ) {
		if ( ! strempty( this.oaSubscriptions ) ) {
			xlib.openajax.getSubscriptions( this.oaSubscriptions );
			a = xlib.openajax.adataSubscriptions;
			cnt = len( a );
			for ( i=0; i<cnt; i++ ) {
			// morework: check status and if cb provided

				if ( a[i].status != 1 ) {
					continue;
				}
				if ( ! a[i].sid || strempty( a[i].sid ) || strempty( a[i].cb ) ) {
					continue;
				}

				try {
					if ( a[i].opts & xlib.openajax.ID_INTERNALHANDLER ) {
						eval( "cb = function( e, msg, data ) { " + jsDecode( a[i].cb ) + " }" );
					}
					else {
						eval( "cb = " + a[i].cb );
					}
				}
				catch ( e ) {
					cb = null;
				}


				if ( a[i].status == 1 ) {
					data = XLIB_SIG + "|({ winname:\"" + this.name + "\",win:null,opts:" + a[i].opts + ",data:\"" + a[i].data + "\"})";
					this.oa_aSubscriptions[ len( this.oa_aSubscriptions ) ] =
						xlib.openajax.subscribe( a[i].sid, cb, a[i].scope, data, a[i].filter );
				}
			}
		}
	}

	if ( this.isVisible( ) ) {
		this.display( );
	}


    // BUGFIX: on Safari and Google Chrome new image appears with small white bar at the right.
    // This hack allows render an image correctly.
    if ( browserInUpper == "SAFARI" ||  browserInUpper == "CHROME") {
        var oBodyVar = this.oBody;
        var oldWidth = parseInt(oBodyVar.style.width.replace(/px$/g, ""));

        oBodyVar.style.width = (oldWidth + 1) + "px";
        setTimeout(function(){
            oBodyVar.style.width = (oldWidth) + "px";

            oBodyVar.style.visibility = "visible";
        }, 1);
    }

    // BUGFIX: on Safari and Google Chrome new window which appears after dropping web link shows with right scroll bar.
    // This hack allows render a window without this scroll bar.
    if ((browserInUpper == "SAFARI"  ||  browserInUpper == "CHROME") && this.otype == OTYPE_WEB) {
        var parentHeight = parseInt(this.oBody.style.height.replace(/px$/g, ""));
        this.oBody.firstChild.style.height = parentHeight - 3;
    }

	return( 1 );
};


xWindow.prototype.oaKeyDown = function( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) {
		xlib.openajax.objPublish( e, xlib.openajax.ID_KEYDOWN, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, chr( xlib.eventKey( e ) ) );
	}
};
xWindow.prototype.oaKeyUp = function( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) {
		xlib.openajax.objPublish( e, xlib.openajax.ID_KEYUP, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, chr( xlib.eventKey( e ) ) );
	}
};
xWindow.prototype.oaKeyPress = function( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) {
		xlib.openajax.objPublish( e, xlib.openajax.ID_KEYPRESS, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, chr( xlib.eventKey( e ) ) );
	}
};

xWindow.prototype.oaMouseOver = function( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) {
		xlib.openajax.objPublish( e, xlib.openajax.ID_MOUSEOVER, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, "" );
	}
};

xWindow.prototype.oaMouseOut = function( e ) {
	var w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) {
		xlib.openajax.objPublish( e, xlib.openajax.ID_MOUSEOUT, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, "" );
	}
};


xWindow.prototype.display = function( style ) {
	var o, oM, pt, IsModal, x, y, w, h, cnt, i;

	style = style || this.style;

	this.style &= ~WS_NORMAL;
	this.style &= ~WS_HIDDEN;
	this.style &= ~WS_VISIBLE;
	this.style &= ~WS_MINIMIZED;
	this.style &= ~WS_MAXIMIZED;

	o = this.obj.style;
	IsModal = this.style & WS_MODAL;

	if ( this.displayMode & DISP_DEFAULT ) {
		this.displayMode = xWinDefaultDisplay;
	}

	// OpenAjax event - ID_DISPLAY
	if ( this.oaOpts && this.oaOpts & xlib.openajax.ID_DISPLAY ) {
		xlib.openajax.objPublish( null, xlib.openajax.ID_DISPLAY, this, null, this.oaDefSrvs.sid, "" + style );
	}

	if ( style & WS_HIDDEN ) {
		this.style |= WS_HIDDEN;
		this.obj.style.visibility = "hidden";
		if ( IsModal ) { xlib.winModalLayer( 0 ); }
		this.eventProcess( this.eDisplay );
		return;
	}

	if ( ( this.otype == OTYPE_IMAGE ) && ( this.rotation != 0 ) ) {
		xlib.imageRotate( this.name + "_ri", this.rotation );
//		setTimeout( "xlib.imageRotate( '" + this.name + "_ri', " + this.rotation + ");", 10 );
//		return;
	}

	if ( style & WS_VISIBLE ) {
		this.style |= WS_VISIBLE;
		this.obj.style.visibility = "visible";
		if ( IsModal ) { xlib.winModalLayer( 0 ); }
		this.eventProcess( this.eDisplay );
		return;
	}

	o.zIndex = this.zorder = this.zIndexGet( );
	if ( style & WS_MAGNETIC ) {
		cnt = xWinList.length;
		for ( i=1; i<cnt; i++ ) {
			w = xWinList[i];
			if ( w.name != this.name ) {
				if ( ( style & WS_MAGNETIC && this.isInWin( w ) ) || ( w.zParent == this.name ) ) {
					w.bringtotop( );
				}
			}
		}
	}
//	this.oBody.style.zIndex = this.zIndexGet( ) + 1000;

	if ( style & WS_MAXIMIZED ) {
		if ( IsModal ) { xlib.winModalLayer( 0 ); }

		this.style |= WS_MAXIMIZED;
		o.zIndex = this.zorder = this.zIndexGet( );
		pt = xlib.winScrollPos( );
		x = pt.x;
		y = pt.y;

		xScrollPos = pt;

		pt = xlib.winSize( );
		w = this.winAdjust( pt.width ) - 1;
		h = this.winAdjust( pt.height ) - 0;
		this.positionDivs( x, y, w, h );
	}
	else if ( style & WS_MINIMIZED ) {
		this.style |= WS_MINIMIZED;
	}
	else {

		// WS_NORMAL (default)
		this.style |= WS_NORMAL;

		if ( this.displayMode & DISP_CENTERED ) {
			pt = xlib.winCalcCenter( this.width, this.height, this.oparent );
			x = pt.x;
			y = pt.y;
		}
		else {
			x = this.left; y = this.top;
		}

//		if ( this.displayMode & DISP_NORMAL ) {
//			x = this.left; y = this.top;
//		}
//		else if ( this.displayMode & DISP_CENTERED ) {
//			pt = xlib.winCalcCenter( this.width, this.height, this.oparent );
//			x = pt.x;
//			y = pt.y;
//		}

		this.positionDivs( x, y, this.width, this.height );

		if ( IsModal ) {
			oM = xlib.winModalLayer( 1 );
			oM.style.zIndex = o.zIndex - 1;
		}
	}

//	this.obj.style.visibility = "visible";


	if ( this.displayMode & DISP_FADE_IN ) {
		xlib.fx.opacity( this.obj.id, 0 );
		this.obj.style.visibility = "visible";
		xlib.fx.opacityFade( this.obj.id, DISP_FADE_IN );
	}
	else {
		if ( ( this.otype == OTYPE_IMAGE ) && ( this.rotation != 0 ) ) {
			setTimeout( "xWin('" + this.name + "').obj.style.visibility = 'visible';", 10 );
		}
		else {
			this.obj.style.visibility = "visible";
		}
	}

	this.eventProcess( this.eDisplay );
};

xWindow.prototype.destroy = function( IgnoreFade, ConfirmFlag ) {
	var a, cnt, i, w, f;

	if ( ConfirmFlag ) {
		if ( ! confirm( "Are you sure you want to remove this object?" ) ) {
			return;
		}
	}

	xlib.UpdateFlag( 1, this );

	if ( ( this.displayMode & DISP_FADE_OUT ) && ( ! IgnoreFade ) ) {
		f = function( id ) {
			setTimeout( "xWin('" + id + "').destroy( 1 );", 700 );
		};
		xlib.fx.opacityFade( this, { mode: DISP_FADE_OUT, cbFunc: f } );
		return;
	}

	if ( this.oaOpts ) {
		// OpenAjax event - ID_KEYDOWN
		if ( this.oaOpts & xlib.openajax.ID_KEYDOWN ) {
			xlib.eventUnbind( this.oBody, "keydown", this.oaKeyDown );
		}
		// OpenAjax event - ID_KEYUP
		if ( this.oaOpts & xlib.openajax.ID_KEYUP ) {
			xlib.eventUnbind( this.oBody, "keyup", this.oaKeyUp );
		}
		// OpenAjax event - ID_KEYPRESS
		if ( this.oaOpts & xlib.openajax.ID_KEYPRESS ) {
			xlib.eventUnbind( this.oBody, "keypress", this.oaKeyPress );
		}

		// OpenAjax event - ID_MOUSEOVER
		if ( this.oaOpts & xlib.openajax.ID_MOUSEOVER ) {
			xlib.eventUnbind( this.oBody, "mouseover", this.oaMouseOver );
		}
		// OpenAjax event - ID_MOUSEOUT
		if ( this.oaOpts & xlib.openajax.ID_MOUSEOUT ) {
			xlib.eventUnbind( this.oBody, "mouseout", this.oaMouseOut );
		}

		// OpenAjax event - ID_DESTROY
		if ( this.oaOpts & xlib.openajax.ID_DESTROY ) {
			xlib.openajax.objPublish( null, xlib.openajax.ID_DESTROY, this, null, this.oaDefSrvs.sid, "" );
		}
	}

	// unsubscribe to any openajax services
	cnt = len( this.oa_aSubscriptions );
	for ( i=0; i<cnt; i++ ) {
		xlib.openajax.unsubscribe( this.oa_aSubscriptions[i] );
	}

	if ( this.eTimerFunc ) {
		xlib.intervalClear( this.eTimerFunc );
		this.eTimerFunc = null;
	}

	// delete the sysmenu
	if ( this.style & WS_SYSMENU ) {
		w = xWinFromName( this.name + "_sys" );
		if ( w ) { w.destroy( ); }
	}
	// delete context menu
	if ( this.style & WS_CONTEXTMENU ) {
		w = xWinFromName( this.name + "_cx" );
		if ( w ) { w.destroy( ); }
	}
	// delete the property window
	w = xWinFromName( this.name + "_prop" );
	if ( w ) { w.destroy( ); }

	if ( this.style & WS_MODAL ) {
		xlib.eventUnbind( window, "scroll", xWinModalScroll );
		xlib.eventUnbind( window, "resize", xWinModalResize );
	}

	a = this.winChildrenArray( this.name );
	cnt = len( a );
	if ( cnt ) {
		for ( i=0; i<cnt; i++ ) {
			a[i].destroy( );
		}
	}

	this.tooltipFunc( );

	this.eventProcess( this.eDestroy );
	this.winUnregister( );

	if ( this.style & WS_MODAL ) {
		xlib.winModalLayer( 0 );
	}

	domDelete( this.winBody( ) );
	domDelete( this.obj );

	if ( xlib.ffPlugin && xlib.ffPlugin.action ) {
		// reset FF dnd plugin
		xlib.ffPlugin.action.reset( );
	}
};

xWindow.prototype.duplicate = function( ) {
	var w = new xWindow( xWinNameGen( this.otype ), this.pack( ), 1 );
	w.left += 30;
	w.top += 30;
	if (! w.create( ) ) {
		alert( this.err );
	}
};


xWindow.prototype.timerProcess = function( e ) {
	if ( ( this.style & WS_EXTERNAL ) && this.eTimerReload ) {
		this.reload( );
	}
	if ( ! strempty( this.eTimer ) ) {
		try {
			eval( this.eTimer );
		}
		catch ( e ) {
			if ( this.eTimerFunc ) {
				xlib.intervalClear( this.eTimerFunc );
				this.eTimerFunc = null;
			}
		}
	}

	// OpenAjax event - ID_TIMER
	if ( this.oaOpts && this.oaOpts & xlib.openajax.ID_TIMER ) {
		xlib.openajax.objPublish( e, xlib.openajax.ID_TIMER, this, null, this.oaDefSrvs.sid, "" );
	}

};

xWindow.prototype.actionPreprocess = function( action ) {
	if ( xlib.actionPreprocessFunc ) {
		action = xlib.actionPreprocessFunc( action );
	}

	// correct flash zorder bug
	if ( strati( "<param name=\"movie\"", action ) ) {
		action = strswapi( action, "<param name=\"movie\"", "<param name='wmode' value='transparent'><param name=\"movie\"" );
	}
	else if ( strati( "<param name='movie'", action ) ) {
		action = strswapi( action, "<param name='movie'", "<param name='wmode' value='transparent'><param name='movie'" );
	}

	if ( strati( "type=\"application/x-shockwave-flash\"", action ) ) {
		action = strswapi( action, "type=\"application/x-shockwave-flash\"", "type=\"application/x-shockwave-flash\" wmode=\"transparent\"" );
	}
	else if ( strati( "type='application/x-shockwave-flash'", action ) ) {
		action = strswapi( action, "type='application/x-shockwave-flash'", "type='application/x-shockwave-flash' wmode='transparent'" );
	}

	if ( this.otype & OTYPE_TEXTBLOCK ) {
		action = strswap( action, "\r", "" );
		action = strswap( action, "\n", "<br>" );
	}


	return( action );
};

xWindow.prototype.actionUpdateFromCustom = function( action ) {
	var buf, a, cnt, i, o, b;

	if ( strempty( this.propCustom ) ) {
		return( action );
	}

	buf = strswap( this.propCustom, "\r", "" );
	a = buf.split( "\n" );
	cnt = len( a );
	for ( i=0; i<cnt; i++ ) {
		if ( strati( "formdata", a[i] ) ) {
			o = parseToObj( strextract( strextract( a[i], "<", 2 ), ">", 1 ) );
			a = o.value.split( "&" );
			cnt = len( a );
			for ( i=0; i<cnt; i++ ) {
				b = a[i].split( "=" );
				action = strswapi( action, "#" + b[0] + "#", jsDecode( b[1] ) );
				action = strswapi( action, "%23" + b[0] + "%23", b[1] );
			}
			break;
		}
	}

	return( action );
};


xWindow.prototype.iframe = function( ) {
	var o;
	if ( this.style & WS_EXTERNAL ) {
		o = domObject( this.name + "_iframe" );
	}
	return( o );
};

xWindow.prototype.iframeDocument = function( ) {
	var o = domObject( this.name + "_iframe" );
	if ( ! ( this.style & WS_EXTERNAL ) ) {
		return( null );
	}

	var doc = o.contentWindow;
  	if ( doc == undefined || doc == null ) {
    	doc = o.contentWindow.document;
    }

	return( doc );
};

xWindow.prototype.iframeBody = function( ) {
	var o = this.iframeDocument( );
	if ( ! o ) { return; }
	return( o.getElementsByTagName("body").item(0) );
};

xWindow.prototype.reload = function( ) {
	var o;
	if ( this.style & WS_EXTERNAL ) {
		o = domObject( this.name + "_iframe" );
		o.src = o.src;
	}
};

xWindow.prototype.winRegister = function( ) {
	var i;

	if ( xWinFromName( this.name ) ) {
		this.errSet( ERR_ALREADYEXISTS );
		return( 0 );
	}
	i = xWinList.length + 1;

	if ( i > xWinMaxNum ) {
		this.errSet( ERR_TOOMANYWINDOWS );
		return( 0 );
	}

	xWinList[ xWinList.length ] = this;
	return( 1 );
};

xWindow.prototype.winUnregister = function( ) {
	var i, cnt, j;

	i = xWinIndexFromName( this.name );
	if ( i ) {
		cnt = xWinList.length;
		for ( j=i; j<cnt; j++ ) {
			xWinList[j] = xWinList[j+1];
		}
		xWinList.pop( );
	}
};

xWindow.prototype.pack = function( prefix ) {
	var s="", n, v, style;

	prefix = prefix || "";

	style = this.style;
	this.style &= ~WS_SHAREMENU;

	for ( n in this ) {
		if ( typeof( n ) == "string" ) {
			if ( ! n.length ) {
				continue;
			}
			switch ( n ) {
			  case "obj":
			  case "oHdr":
			  case "oBody":
			  case "oFooter":
			  case "oBG":
			  case "olayer":
			  case "oparent":
			  case "zorder":
			  case "funcHeader":
			  case "funcFooter":
			  case "funcContextMenu":
			  case "helpFunc":
			  case "eTimerFunc":
			  case "oaDefSrvs":				// temp instance var
			  case "oaOpts":				// temp instance var
			  case "oa_aSubscriptions":		// temp instance var
			  case "oaSubriptions":
			  case "oaSubsriptions":
			  	if ( typeof( this[n] ) != "string" ) {
					continue;
				}
			}
			v = this[n];
			switch ( typeof( v ) ) {
			  case "number":
				s += prefix + "$" + n + "=" + v + "&";
				break;
			  case "string":
				if ( v.length ) {
					s += prefix + n + "=" + jsEncode( v ) + "&";
				}
				break;
			}
		}
	}
	this.style = style;

	return( s );
};

xWindow.prototype.unpack = function( s ) {
	var a, b, cnt, i, n, v;

	a = s.split( "&" );
	cnt = len( a );
	for ( i=0; i<cnt; i++ ) {
		b = a[i].split( "=" );

		switch ( b[0] ) {
		  case "obj":
		  case "oHdr":
		  case "oBody":
		  case "oFooter":
		  case "oBG":
		  case "olayer":
		  case "oparent":
		  case "zorder":
		  case "funcHeader":
		  case "funcFooter":
		  case "funcContextMenu":
		  case "oaDefSrvs":				// temp instance var
		  case "oaOpts":				// temp instance var
		  case "oa_aSubscriptions":		// temp instance var
		  case "oaSubriptions":
		  case "oaSubsriptions":
		  	continue;
		}

		try {
			if ( b[0].charAt( 0 ) == "$" ) {
				n = right( b[0], b[0].length - 1);
				v = b[1].indexOf(".") + 1 ? parseFloat( b[1] ) : int( b[1] );
			}
			else {
				n = b[0];
				v = jsDecode( b[1] );
			}

			this[n] = v;
		} catch ( e ) { }
	}

	return( cnt );
};


xWindow.prototype.transparencySet = function( lvl ) {

	lvl = ( lvl == null ? this.transLevel : lvl );
	this.style |= WS_TRANSPARENT;

	if ( int( lvl ) != 100 ) {
		if ( xlib.pngfix ) {
			this.oBG.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.imagedir + "/trans" + lvl + ".png',sizingMethod='scale')";
		}
		else {
			this.oBody.style.backgroundImage = "url(" + this.imagedir + "/trans" + lvl + ".png" + ")";
		}
	}
	else {
		this.oBody.style.backgroundImage = "";
	}
};

xWindow.prototype.isVisible = function( style ) {
	style = style ? style : this.style;
	if ( style & WS_NORMAL ||
		 style & WS_VISIBLE ||
		 style & WS_MINIMIZED ||
		 style & WS_MAXIMIZED ) {
		return( 1 );
	}
	return( 0 );
};

xWindow.prototype.isPackedString = function( s ) {
	if ( strati( XLIB_SIG, s ) || strati( jsEncode( XLIB_SIG ), s ) ) {
		return( 1 );
	}
	return( 0 );
};

xWindow.prototype.headerFunc = function( o ) {
	var s = "<table border=0 cellspacing=0 cellpadding=" + o.hdrPadding + " class='" + o.hdrTextClass + " xNoBorder' width=100% height=" + o.hdrHeight + " bgcolor='" + o.hdrBgColor + "' background='" + ( strempty( o.hdrBgColor ) ? o.hdrBgImage : "" ) + "' style='width:100%;'><tr>";

	if ( o.style & WS_SYSMENU ) {
		s += "<td width=18 class='xNoBorder'><img src='" + o.imagedir + "/win_sys0.png' width=18 height=18 border=0 onmouseover=\"domImageSet(this,'" + o.imagedir + "/win_sys1.png');\" onmouseout=\"domImageSet(this,'" + o.imagedir + "/win_sys0.png');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + o.name + "').sysmenu();\" title='Toggle System Menu'></td>";
	}

	s += "<td nowrap class='xNoBorder'><font color='" + o.hdrTextColor + "'>" + o.header + "</font></td>" +
		 "<td nowrap align=right class='xNoBorder' style='text-align:right;'>";

	if ( o.style & WS_HELP ) {
		s += "<img src='" + o.imagedir + "/win_help0.png' width=18 height=18 border=0 onmouseover=\"domImageSet(this,'" + o.imagedir + "/win_help1.png');\" onmouseout=\"domImageSet(this,'" + o.imagedir + "/win_help0.png');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + o.name + "').help();\" title='Help'>";
	}
	if ( ( o.style & WS_UNDOCKABLE ) && ( o.style & WS_EXTERNAL ) ) {
		s += "<img src='" + o.imagedir + "/win_undock0.png' width=18 height=18 border=0 onmouseover=\"domImageSet(this,'" + o.imagedir + "/win_undock1.png');\" onmouseout=\"domImageSet(this,'" + o.imagedir + "/win_undock0.png');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + o.name + "').undock();\" title='Undock'>";
	}
	if ( o.style & WS_MINIMIZABLE ) {
		s += "<img src='" + o.imagedir + "/win_min0.png' width=18 height=18 border=0 onmouseover=\"domImageSet(this,'" + o.imagedir + "/win_min1.png');\" onmouseout=\"domImageSet(this,'" + o.imagedir + "/win_min0.png');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + o.name + "').minimize();\" title='Minimize'>";
	}
	if ( o.style & WS_MAXIMIZABLE ) {
		s += "<img src='" + o.imagedir + "/win_max0.png' width=18 height=18 border=0 onmouseover=\"domImageSet(this,'" + o.imagedir + "/win_max1.png');\" onmouseout=\"domImageSet(this,'" + o.imagedir + "/win_max0.png');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + o.name + "').maximize();\" title='Maximize'>";
	}
	if ( o.style & WS_CLOSE ) {
		s += "<img src='" + o.imagedir + "/win_close0.png' width=18 height=18 border=0 onmouseover=\"domImageSet(this,'" + o.imagedir + "/win_close1.png');\" onmouseout=\"domImageSet(this,'" + o.imagedir + "/win_close0.png');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + o.name + "').destroy();\" title='Close'>";
	}

	s += "</td></tr></table>";
	return( s );
};

xWindow.prototype.help = function( ) {
	switch ( typeof( this.helpFunc ) ) {
	  case "string":
	  	eval( this.helpFunc );
	  	break;
	  case "function":
	  	this.helpFunc( this );
	  	break;
	}
};

xWindow.prototype.footerFunc = function( o ) {
	var s = "<table border=0 cellspacing=0 cellpadding=" + o.ftrPadding + " class='" + o.ftrTextClass + " xNoBorder' width=100% height=" + o.ftrHeight + " bgcolor='" + o.ftrBgColor + "' background='" + ( strempty( o.ftrBgColor ) ? o.ftrBgImage : "" ) + "' style='border:none;'><tr>" +
			"<td nowrap class='xNoBorder'><font color='" + o.ftrTextColor + "'>" + o.footer + "</font></td></tr></table>";
	return( s );
};

xWindow.prototype.getMagneticChildren = function( ) {
	var r21, r2, cnt, i, w, a;

	a = new Array( );
	if ( ! ( this.style & WS_MAGNETIC ) ) {
		return( a );
	}

	r1 = { left: this.left, top: this.top, width: this.width, height: this.height };

	cnt = xWinList.length;
	for ( i=1; i<cnt; i++ ) {
		w = xWinList[i];
		if ( ( ! w ) || ( w.name == this.name ) ) {
			continue;
		}

		if ( w.style & WS_NOFOCUS ) {
			continue;
		}

		r2 = { left: w.left, top: w.top, width: w.width, height: w.height };
		if ( ! rectContained( r1, r2 ) ) {
			continue;
		}

		a[len(a)] = w;
	}

	return( a );
};

xWindow.prototype.zIndexGet = function( ) {

	if ( this.style & WS_NOFOCUS ) {
		return( 1 );
	}

	if ( ( this.style & WS_MAXIMIZED ) ||
		 ( this.style & WS_ALWAYSONTOP ) ||
		 ( this.style & WS_MODAL ) ) {
		xWinZorder += 2;
		return( xWinZorder + 10000 );
	}

//	if ( this.style & WS_MAXIMIZED ) {
//		return( xWinZorder + xWinMaxNum );
//	}

//	if ( this.style & WS_ALWAYSONTOP ) {
//		return( xWinZorder + 9000 );
//	}

//	if ( this.style & WS_MODAL ) {
//		return( xWinZorder + 10000 );
//	}

	return( xWinZorder += 2 );
};


xWindow.prototype.maximize = function( flag ) {
	if ( flag == null ) {
		flag = ! ( this.style & WS_MAXIMIZED );
	}
	this.display( flag ? WS_MAXIMIZED : WS_NORMAL );
};

xWindow.prototype.minimize = function( flag ) {
return;
//	if ( flag == null ) {
//		flag = ! ( this.style & WS_MINIMIZED );
//	}
//	this.display( flag ? WS_MINIMIZED : WS_NORMAL );
};

xWindow.prototype.sysmenu = function( flag ) {
	var w = xWinFromName( this.name + "_sys" );

	if ( flag == null ) {
		flag = ! w;
	}
	if ( w ) {
		if ( flag )	{
			w.bringtotop( );
			return;
		}
		w.destroy( );
		return;
	}
	w = xWinFromName( this.name + "_cx" );
	if ( w ) { w.destroy( ); }
	this.funcSysMenu( this );
};


xWindow.prototype.sysmenuFunc = function( oparent ) {
	var w, x, y, menu;

	x = int( oparent.obj.style.left );
	y = int( oparent.obj.style.top ) + oparent.hdrHeight + oparent.borderThickness( );
	if ( oparent.oparent ) {
		x += int( oparent.oparent.obj.style.left ) + oparent.oparent.borderThickness( );
		y += int( oparent.oparent.obj.style.top ) + oparent.hdrHeight + oparent.oparent.borderThickness( );
	}

	w = new xWindow( );
	w.name = 	w.name = this.name + "_sys";
	w.issys = 1;
	w.style = WS_NORMAL | WS_MOVEABLE | WS_BORDER | WS_SHADOW | WS_ALWAYSONTOP;
	w.setposition( x, y, 200, 130 );
	w.bgColor = "#FFFFFF";

	menu = new xlib_MenuProperties( this );
	menu.sideColor = "#808080";
	
	if ( xWinMinProp ) {
		menu.add( "Manual Move", "", "xWin('" + this.name + "').manualmove( );" );
		menu.add( "Duplicate", "", "xWin('" + this.name + "').duplicate( )" );
		menu.add( "-", "" );
		menu.add( "Close window", "", "xWin('" + this.name + "').destroy( );" );
	}
	else {
		menu.add( "Properties", "", "xWin('" + this.name + "').properties( );" );
		menu.add( "Manual Move", "", "xWin('" + this.name + "').manualmove( );" );
		menu.add( "-", "" );
		menu.add( "Duplicate", "", "xWin('" + this.name + "').duplicate( )" );
		if ( ! ( this.style & WS_NOTSHAREABLE ) ) {
			menu.add( "Share", "", "xWin('" + this.name + "').share( )" );
		}
		menu.add( "Origin", "", "xWin('" + this.name + "').origin( )" );
		menu.add( "-", "" );
		menu.add( "Close window", "", "xWin('" + this.name + "').destroy( );" );
	}

	w.setposition( x, y, 160, menu.calcHeight( ) );
	w.action = menu.render( );

	w.create( );

	xlib.menuCurrentSet( w );
};

xWindow.prototype.contextmenu = function( flag ) {
	var w;
	if ( ! ( this.style & WS_CONTEXTMENU ) ) {
		return( 0 );
	}

	if ( ! xlib.pageObjMenuEnabled ) {
		return( 0 );
	}

	w = xWinFromName( this.name + "_cx" );

	if ( flag == null ) {
		flag = ! w;
	}
	if ( w ) {
		if ( flag )	{
			w.bringtotop( );
			return( 1 );
		}
		w.destroy( );
		return( 1 );
	}
	w = xWinFromName( this.name + "_sys" );
	if ( w ) { w.destroy( ); }
	this.funcContextMenu( this );

	return( 1 );
};

xWindow.prototype.contextmenuFunc = function( oparent ) {
	var w, x, y, h, o, pt, menu;

	w = new xWindow( );
	w.issys = 1;
	w.name = this.name + "_cx";
	w.style = WS_NORMAL | WS_MOVEABLE | WS_BORDER | WS_SHADOW | WS_ALWAYSONTOP;

	x = int( oparent.obj.style.left );
	y = int( oparent.obj.style.top ) + oparent.hdrHeight + oparent.borderThickness( );
    if ( oparent.oparent ) {
		x += int( oparent.oparent.obj.style.left ) + oparent.oparent.borderThickness( );
		y += int( oparent.oparent.obj.style.top ) + oparent.hdrHeight + oparent.oparent.borderThickness( );
	}

	pt = xlib.eventCurrentGet( "mPos" );
	x = pt.x; y = pt.y;

	w.padding = 0;
	w.bgColor = "#FFFFFF";

	menu = new xlib_MenuProperties( this );
	menu.sideColor = xWinContextSideClr;

	o = oparent.obj.style;

	if ( xWinMinProp ) {
		menu.add( "Manual Move", "", "xWin('" + this.name + "').manualmove( );" );
		menu.add( "Duplicate", "", "xWin('" + this.name + "').duplicate( )" );
		menu.add( "-", "" );
		menu.add( "Delete", "", "xWin('" + this.name + "').destroy( );" );
		menu.add( "Exit", "", "xWin('" + w.name + "').destroy( );" );
	}
	else {
		if ( this.style & WS_SHAREMENU ) {
			menu.add( "Share", "", "xWin('" + this.name + "').share( )" );
			menu.add( "Origin", "", "xWin('" + this.name + "').origin( )" );
			menu.add( "-", "" );
			menu.add( "Exit", "", "xWin('" + w.name + "').destroy( );" );
		}
		else {
			menu.add( "Properties", "", "xWin('" + this.name + "').properties( );" );
			menu.add( "Manual Move", "", "xWin('" + this.name + "').manualmove( );" );
			menu.add( "-", "" );
			menu.add( "Duplicate", "", "xWin('" + this.name + "').duplicate( )" );
			menu.add( "Share", "", "xWin('" + this.name + "').share( )" );
			menu.add( "Origin", "", "xWin('" + this.name + "').origin( )" );
			menu.add( "-", "" );
			menu.add( "Delete", "", "xWin('" + this.name + "').destroy( );" );
			menu.add( "Exit", "", "xWin('" + w.name + "').destroy( );" );
		}
	}

	h = menu.calcHeight( ) + ( w.borderThickness( ) * 2 );

	pt = xlib.winAdjustPos( x, y, 160, h, 10 );
	w.setposition( pt.x, pt.y, 160, h );
	w.action = menu.render( );
	w.create( );

	//w.obj.style.zIndex = this.obj.style.zIndex + 2;
	w.obj.style.zIndex += 10000;
	//w.bringtotop( );

	xlib.menuCurrentSet( w );
};

xWindow.prototype.manualmove = function( ) {
	xWinManualMove( this );
}

xWindow.prototype.properties = function( ) {
	var w, extra="", url="/properties.htm";

	// pass special keys to properties
	e = xlib.eventGlobal;
	if ( e ) {
		k = xlib.keyGet( e );
		if ( k.isCTRL ) {
			extra += "&IsCtrl=1";
		}
		if ( k.isALT ) {
			extra += "&IsAlt=1";
		}
		if ( k.isSHIFT ) {
			extra += "&IsShift=1";
		}
	}
	if ( ! strempty( this.propCustom ) ) {
		extra += "&IsCustom=1";
	}

	if ( xWinPropertyTheme ) {
		w = xWinPropertyTheme( this.name + "_prop", url + "?id=" + this.name + "&otype=" + this.otype + extra, 1 );
	}
	else {
		w = new xWindow( );
		w.name = this.name + "_prop";
		w.style = WS_NORMAL | WS_MOVEABLE | WS_MAXIMIZABLE | WS_RESIZABLE | WS_BORDERTHICK | WS_EXTERNAL | WS_HEADER | WS_CLOSE;
		w.action = url + "?id=" + this.name + "&otype=" + this.otype + extra;
	}
	w.style |= WS_ALWAYSONTOP
	w.displayMode = DISP_CENTERED | DISP_NOPROGRESS;
	w.issys = 1;
	if ( strempty( this.propCustom ) ) {
		w.header = "Properties - " + xlib.objNameFromId( this.otype ) + ( this.otype == OTYPE_OBJECT ? "" : " object" );
	}
	else {
		w.header = "Object Properties";
	}
	w.setposition( 0, 0, 560, 400 );
	w.create( );
};

xWindow.prototype.share = function( ) {
	var w;

	if ( this.style & WS_NOTSHAREABLE ) {
		alert( "Sorry, this object is set to non-shareable" );
		return;
	}

	if ( xWinPropertyTheme ) {
		w = xWinPropertyTheme( this.name + "_prop", "/propshare.htm?id=" + this.name + "&otype=" + this.otype, 1 );
//		w.style |= WS_EXTERNAL;
	}
	else {
		w = new xWindow( );
		w.name = this.name + "_prop";
		w.style = WS_NORMAL | WS_MOVEABLE | WS_MAXIMIZABLE | WS_RESIZABLE | WS_BORDERTHICK | WS_EXTERNAL | WS_HEADER | WS_CLOSE;
		w.action = "/propshare.htm?id=" + this.name + "&otype=" + this.otype;
	}
	w.style |= WS_ALWAYSONTOP
	w.displayMode = DISP_CENTERED | DISP_NOPROGRESS;
	w.issys = 1;
	w.header = "Share - " + xlib.objNameFromId( this.otype ) + ( this.otype == OTYPE_OBJECT ? "" : " object" );
	w.setposition( 0, 0, 560, 400 );
	w.create( );
};

xWindow.prototype.origin = function( ) {
	var w;

	if ( xWinPropertyTheme ) {
		w = xWinPropertyTheme( this.name + "_origin", "/propOrigin.htm?id=" + this.name + "&otype=" + this.otype, 1 );
	}
	else {
		w = new xWindow( );
		w.name = this.name + "_origin";
		w.style = WS_NORMAL | WS_MOVEABLE | WS_MAXIMIZABLE | WS_RESIZABLE | WS_BORDERTHICK | WS_EXTERNAL | WS_HEADER | WS_CLOSE;
		w.action = "/propOrigin.htm?id=" + this.name + "&otype=" + this.otype;
	}
	w.style |= WS_ALWAYSONTOP
	w.displayMode = DISP_CENTERED | DISP_NOPROGRESS;
	w.issys = 1;
	w.header = "Content Origin";
	w.setposition( 0, 0, 560, 400 );
	w.create( );
};

xWindow.prototype.undock = function( w, h ) {
	var url, pt, opt;

	if ( ! w ) {
		w=640;
	}
	if ( ! h ) {
		h=480;
	}

	if ( ! ( this.style & WS_EXTERNAL ) ) {
		return;
	}
	pt = { "x": ( screen.availWidth - w ) / 2, "y": ( screen.availHeight - h ) / 2 };
	url = this.actionFormatExt( this.action );
	opt = "left=" + pt.x + ",top=" + pt.y + ",width=" + w + ",height=" + h + ",status=yes,location=yes,toolbar=yes,scrollbars=yes,menubar=yes,directories=yes,resizable=yes";
	window.open( url, "_blank", opt );
};


xWindow.prototype.isInWin = function( w ) {
	var r2, r1;
	r2 = { left: this.left, top: this.top, width: this.width, height: this.height };
	r1 = { left: w.left, top: w.top, width: w.width, height: w.height };
	return( rectContained( r2, r1 ) );
};

xWindow.prototype.bringtotop = function( ) {
	var w, i, cnt;

	if ( this.style & WS_NOFOCUS ) {
		return( 1 );
	}

	if ( this.zorder == xWinZorder ) {
		return( 0 );
	}

	this.zorder = this.obj.style.zIndex = this.zIndexGet( );
	if ( this.oparent ) {
		this.oparent.bringtotop( );
	}

	// process zParents and WS_MAGNETIC
	cnt = xWinList.length;
	for ( i=1; i<cnt; i++ ) {
		w = xWinList[i];
		if ( w.name != this.name ) {
			if ( ( this.style & WS_MAGNETIC && this.isInWin( w ) ) || ( w.zParent == this.name ) ) {
				w.bringtotop( );
			}
		}
	}

	w = xWinFromName( this.name + "_sys" );		// sys menu
	if ( w ) { w.bringtotop( ); }
	w = xWinFromName( this.name + "_cx" );		// context menu
	if ( w ) { w.bringtotop( ); }

	return( 1 );
};

xWindow.prototype.winAdjust = function( x ) {
	var b;
	x = x == null ? 0 : x;
	if ( xlib.IsIE ) {
		return( x );
	}
	b = this.borderThickness( );
	return( x - ( 2 * b ) );
};


xWindow.prototype.positionDivs = function( x, y, w, h ) {
	var b=0, as, top=0, bot, offset=0, bT, w2, h2, IsNoSave, s;

	IsNoSave = ( ( this.style & WS_MAXIMIZED ) || ( this.style & WS_MINIMIZED ) || ( this.style & WS_HIDDEN ) );

	if ( x != null ) {
		x = int( x );
		if ( ! IsNoSave ) { this.left = x; }
	}
	if ( y != null ) {
		y = int( y );
		if ( ! IsNoSave ) { this.top = y; }
	}
	if ( w != null ) {
		w = int( w );
		if ( w < 0 ) { w = 0; }
		if ( ! IsNoSave ) { this.width = w; }
	}
	if ( h != null ) {
		h = int( h );
		if ( h < 0 ) { h = 0; }
		if ( ! IsNoSave ) { this.height = h; }
	}

	s = this.obj.style;

	try {

		if ( x != null ) { s.left = pxWrap( x ); }
		if ( y != null ) { s.top = pxWrap( y ); }

	} catch ( e ) { return; }

	if ( xlib.IsIE ) {
		if ( w != null ) { s.width = pxWrap( w ); }
		if ( h != null ) { s.height = pxWrap( h ); }
		if ( ( w == null ) && ( h == null ) ) {
			return;
		}

		bT = this.borderThickness( );
		bot = h - ( bT * 2 );

		if ( this.style & WS_HEADER ) {
			top = this.hdrHeight;
			b += bT;
		}
		if ( this.style & WS_FOOTER ) {
			b += bT;
			if ( ! ( this.style & WS_HEADER ) ) {
				b += bT;
			}
			bot = h - this.ftrHeight - b;
			this.oFtr.style.top = pxWrap( bot );
		}

		if ( w != null ) {
			w = w - ( bT * 2 ) - ( this.margin * 2 );
			this.oBody.style.width = pxWrap( w < 0 ? 0 : w );
		}

		if ( h != null ) {
			h = bot - top - ( this.margin * 2 );
			this.oBody.style.top = pxWrap( top );
			this.oBody.style.height = pxWrap( h < 0 ? 0 : h );
		}

		if ( xlib.pngfix ) {
			this.oBG.style.left = this.oBody.style.left;
			this.oBG.style.top = this.oBody.style.top;
			this.oBG.style.width = this.oBody.style.width;
			this.oBG.style.height = this.oBody.style.height;
		}

		return;
	}

	w2 = this.winAdjust( w );
	h2 = this.winAdjust( h );

	if ( w != null ) { s.width = pxWrap(w2); }
	if ( h != null ) { s.height = pxWrap(h2); }

	if ( ( w == null ) && ( h == null ) ) {
		return;
	}

//xlib.winStatus( "x:" + x + ", y:" + y + ", w:" + w + ", h:" + h );

	b = this.borderThickness( ) * 2;
	bT = xlib.winScrollWidth( ) + ( xlib.OS == "Mac" ? 5 : 3 );
	bot = h2 - ( this.margin * 2 ) - ( this.padding * 2 );

	if ( this.style & WS_HEADER ) {
		top = this.hdrHeight;
	}
	if ( h != null && this.style & WS_FOOTER ) {
		this.oFtr.style.top = pxWrap( h - this.ftrHeight - b );
		bot -= this.ftrHeight;
	}

	if ( w != null ) {
		//w = w2 - bT
		w -= ( this.padding * 2 ) + ( this.margin * 2 ) + b;
		this.oBody.style.width = pxWrap( w < 0 ? 0 : w );
	}

	if ( h != null ) {
		//top -= this.margin;
		this.oBody.style.top = pxWrap( top );
		this.oBody.style.height = pxWrap( ( bot - top ) < 0 ? 0 : bot - top );
	}
};

xWindow.prototype.position = function( x, y, w, h, MagneticFlag ) {
	var o;
	if ( x == null && y == null && w == null && h == null ) {
		w = this.obj.style;
		o = [ { "left": int( w.left ), "top": int( w.top ), "width": int( w.width ), "height": int( w.height ) } ];
		return o[0];
	}
	this.setposition( x, y, w, h, 1, MagneticFlag );
};

xWindow.prototype.setposition = function( left, top, width, height, IsSetWin, MagneticFlag ) {
	var xOffet=0, yOffset=0, a, cnt, i;

	if ( left && left.x ) {		// support for POINT data
		top = left.y;
		left = left.x;
	}

	if ( left != null ) {
		xOffset = left - this.left;
		this.left = left;
	}
	if ( top != null ) {
		yOffset = top - this.top;
		this.top = top;
	}
	if ( width != null ) { this.width = width; }
	if ( height != null ) { this.height = height; }

	if ( IsSetWin ) {
		if ( ( this.style & WS_MAXIMIZED ) || ( this.style & WS_MINIMIZED ) ) {
			return;
		}
		this.positionDivs( left, top, width, height );
	}

	// when moving with mouse, this is handled in the mousemove event instead of here
	if ( MagneticFlag ) {
		a = this.getMagneticChildren( )
		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			if ( IsSetWin ) {
				a[i].left += xOffset;
				a[i].top += yOffset;
			}
			a[i].obj.style.left = int( a[i].obj.style.left ) + xOffset;
			a[i].obj.style.top = int( a[i].obj.style.top ) + yOffset;
		}
	}

};

xWindow.prototype.scrollTo = function( x, y, mode ) {
	this.oBody.scrollLeft = x;
	this.oBody.scrollTop = y;
};

xWindow.prototype.winBody = function( ) {
	var o;
	// returns the body object
	if ( this.theme.length ) {
		o = domObject( this.name + "_bTheme" );
		if ( o ) {
			return( o );
		}
	}
	return domObject( this.name + "_body" );
};

xWindow.prototype.winBodyGet = function( ) {
	return domInnerHTML_get( this.winBody( ) );
};
xWindow.prototype.winBodySet = function( val ) {
	return domInnerHTML_set( this.winBody( ), val );
};

xWindow.prototype.winHdrGet = function( ) {
	return domInnerHTML_get( this.name + "_h" );
};
xWindow.prototype.winHdrSet = function( val ) {
	return domInnerHTML_set( this.name + "_h", val );
};
xWindow.prototype.winFtrGet = function( ) {
	return domInnerHTML_get( this.name + "_f" );
};
xWindow.prototype.winFtrSet = function( val ) {
	return domInnerHTML_set( this.name + "_f", val );
};


xWindow.prototype.winChildrenArray = function( name ) {
	var cnt, i, a=[];

	name = typeof( name ) == "string" ? name : name.name;

	cnt = xWinList.length + 1;
	for ( i=1; i<=xWinMaxNum; i++ ) {
		if ( xWinList[i] && xWinList[i].oparent && xWinList[i].oparent.name ) {
			if ( xWinList[i].oparent.name == name ) {
				if ( xWinList[i].name != name ) {
					a[a.length] = xWinList[i];
				}
			}
		}
	}
	return( a );
};

xWindow.prototype.winMove = function( left, top ) {
	this.setposition( left, top, this.width, this.height, 1 );
	if ( this.eMove ) {
		xlib.eventCurrentSet( "eMove", { left:left, top:top } );
		this.eventRun( 'Move', null );
	}
};

xWindow.prototype.winSize = function( w, h ) {
	this.setposition( this.left, this.top, w, h, 1 );
	if ( this.eResize ) {
		xlib.eventCurrentSet( "eResize", { width:w, height:h } );
		this.eventRun( 'Resize', null );
	}
};

xWindow.prototype.actionRenderExternal = function( action, params ) {
	if ( params ) {
		if ( ! strat( "?", action ) ) {
			action += "?" + params;
		}
		else {
			action += "&" + params;
		}
	}

	if ( ! ( this.displayMode & DISP_NOPROGRESS ) ) {
		action = "/progress.htm?_url_=" + jsEncode( action );
	}
	return( "<iframe id='" + this.name + "_iframe' src='" + this.actionFormatExt( action ) + "' width='100%' height='100%' frameborder=0 scrolling='auto' allowtransparency='true'></iframe>" );
};

xWindow.prototype.actionFormatExt = function( action, params ) {
	var a, cnt, i, f, x, base;

	if ( ! action.length ) {
		return( "about:blank" );
	}

	// check for one or more lines of comments
	if ( strat( "//", action ) ) {
		action = strswap( action, "\r\n", "\n" );
		a = action.split( "\n" );
		action = "";
		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			if ( strempty( a[i] ) || ( left( alltrim( a[i] ), 2 ) == "//" ) ) {
				continue;
			}
			action = a[i];
			break;
		}
		if ( strempty( action ) ) {
			return( "about:blank" );
		}
	}

	// check for "friendly" domains
	a = xWinIntDomains.split( ";" );
	cnt = len( a );
	f = 0;
	for ( i=0; i<cnt; i++ ) {
		if ( strati( a[i] + ".", action ) ) {
			f = 1;
			break;
		}
	}
	if ( ( ! f ) && ( left( action, 1 ) == "/" ) ) {
		f = 1;
	}
//	if ( f && strati( "progress.htm", action ) ) {
//		f = 0;
//	}

	// add xid for friendly domains
	if ( f ) {
		x = strati( "xid=", action );
		flag = 0;
		if ( x ) {
			action = strswapi( action, strextract( right( action, len( action ) - x + 1 ), "&", 1 ), "xid=" + this.name );
			flag = 1;
		}
		x = strati( "xid%3d", action );
		if ( x ) {
			base = "xid%3d" + strextract( strextract( right( action, len( action ) - x - 5 ), "%", 1 ), "&", 1 )
			action = strswapi( action, base, "xid%3d" + this.name );
		}

		if ( ! flag ) {
			if ( action.indexOf( "?" ) + 1 ) {
				action += "&xid=" + this.name;
			}
			else {
				action += "?xid=" + this.name;
			}
		}
	}

	return( action );
};

xWindow.prototype.borderThickness = function( ) {
	if ( this.style & WS_BORDER ) {
		return this.borderWidth;
	}
	if ( this.style & WS_BORDERTHICK ) {
		return this.borderWidthThick;
	}
	return( 0 );
};


xWindow.prototype.borderSet = function( s, w, c, ReloadFlag ) {
	var b;

	if ( this.style & WS_BORDER ) {
		b = this.borderWidth = int( w );
	}
	else if ( this.style & WS_BORDERTHICK ) {
		b = this.borderWidth = int( w );
	}

	this.obj.style.border = s + " " + b + "px " + c;

	if ( ReloadFlag ) {
		this.display( WS_NORMAL );
	}
};

xWindow.prototype.olayerEnable = function( f ) {
    var browserInUpper = upper(xlib.browser);
    if ( browserInUpper == "SAFARI" || browserInUpper == "CHROME") {
		// safari maintains event messages while dragging
		// morework: set cursor for safari
		return;
	}
	try {
		this.olayer.style.zIndex = f ? this.obj.style.zIndex + 1 : -1;
	} catch ( e ) { }
};

xWindow.prototype.eventRun = function( etype, e ) {
	switch ( etype ) {
	  case "DblClick":
		xlib.editClearSelection( e );		// fall through
	  case "Click":
	  	if ( xlib.eventDefaultNode( xlib.eventTarget( e ) ) ) {
	  		return( 0 );
	  	}
	}
	return( this.eventProcess( this["e" + etype], e ) );
};

xWindow.prototype.eventProcess = function( edata, e ) {
	if ( ! edata ) {
		return( 0 );
	}
	xlib.eventCurrentSet( "win", this );
	xlib.eventCurrentSet( "winName", this.name );
	try {
		if ( typeof( edata ) == "string" ) {
			eval( edata );
		}
		else {
			edata( this, e );
		}
	} catch ( err ) { return( 0 ); }
	return( 1 );
};

xWindow.prototype.shadowSet = function( o ) {
	//return;		// more trouble than it's worth
	if ( xlib.IsIE && ( xlib.version >= 7 ) ) {
		o = typeof( o ) == "undefined" ? this.obj : o;
		o.style.filter = this.shadow.length ? this.shadow : "progid:DXImageTransform.Microsoft.Shadow(color=gray, direction=135, strength=5);";
	}
};

xWindow.prototype.tooltipFunc = function( e, flag ) {
	var w, n, o, m, borderWidth, opts, f;
	var mode=this.displayMode, width=this.ttWidth, height=0, offset=5, bgColor=this.ttBG, bgImage=null;
	var xOffset=0, yOffset=10, padding=4, shadow=1, opacity=null;

	borderWidth = 1;	// must match the xTooltip class in xstyle.css

	if ( ! strempty( this.ttOpts ) ) {
		opts = eval( this.ttOpts );
		if ( opts ) {
			mode = opts.mode || mode;
			width = opts.width || width;
			height = opts.height || height;
			offset = opts.offset || offset;
			bgColor = opts.bgColor || bgColor;
			bgImage = opts.bgImage || bgImage;
			xOffset = opts.xOffset || xOffset;
			yOffset = opts.yOffset || yOffset;
			padding = opts.padding || padding;
			opacity = opts.opacity || opacity;
			shadow = opts.shadow == null ?  shadow : opts.shadow;
		}
	}

	n = this.name + "_tt";
	o = domObject( n );
	if ( ! flag ) {
		if ( ! o ) {
			return;
		}

		if ( ! e ) {
			domDelete( o );
			xWinIsTooltip = null;
			return;
		}

		w = xWinFromElement( xlib.eventTarget( e ) );
		if ( ! ( xMouseE.isInMove || xMouseE.isInSize ) ) {
			if ( w && w.name == this.name ) {
				return;
			}
		}

		if ( mode & DISP_ANIM_TOOLTIP ) {
			f = function( o ) {
				domDelete( o );
			};
			xlib.animateHeight( o, int( o.offsetHeight ) - ( borderWidth * 2 ), 1, { interval: 10, power: 0.5, steps: 10 }, f );
		}
		else {
			domDelete( o );
		}
		xWinIsTooltip = null;
		return;
	}

	if ( xWinIsTooltip ) {
		xWinIsTooltip.tooltipFunc( e, 0 );
	}

	if ( xMouseE.isInMove || xMouseE.isInSize ) {
		return;
	}

	if ( o ) {
		o.style.zIndex = this.zIndexGet( ) + 10000;
		return;
	}

	m = xlib.mousePos( e );
	m.x += xOffset;
	m.y += yOffset;

	o = domAdd( null, "div", n );
	o.className = "xTooltip";
	if ( xlib.IsIE ) {
		o.style.width = width;
		if ( height ) { o.style.height = height; }
	}
	else {
		o.style.width = width - ( ( padding + borderWidth ) * 2 );
		if ( height ) { o.style.height = height - ( ( padding + borderWidth ) * 2 ); }
	}
	o.style.left = xlib.winAdjustX( m.x + xlib.winScrollX( ), o.style.width, offset );
	o.style.top = m.y + xlib.winScrollY( );
	domInnerHTML_set( o, this.tooltip );

	if ( bgColor ) { o.style.background = bgColor; }
	if ( bgImage ) {
		o.style.background = "";
		o.style.border = "none";
		if ( xlib.pngfix && strati( ".png", bgImage ) ) {
			domImageSet( o, bgImage, 1 );
		}
		else {
			o.style.backgroundImage = "url(" + bgImage + ")";
		}
//		o.style.backgroundImage = "url(" + bgImage + ")";
	}
	o.style.padding = padding;
	if ( opacity != null ) {
		xlib.fx.opacity( o.id, opacity );
	}
	else {
		if ( shadow ) { this.shadowSet( o ); }
	}
	o.style.zIndex = this.zIndexGet( ) + 10000;

	xlib_PngFix( o );

	if ( mode & DISP_ANIM_TOOLTIP ) {
		xlib.animateHeight( o, 1, xlib.winOffsetHeight( o, padding, borderWidth ), opts );
	}
	else {
		o.style.visibility = 'visible';
	}
	xWinIsTooltip = this;
};


xWindow.prototype.errSet = function( errnum ) {
	this.err = errnum;
};

xWindow.prototype.errGet = function( errnum ) {
	var a, cnt, i;
	desc = desc ? desc : "";

	a = [
		ERR_NONAME,				"No window ID specified",
		ERR_ALREADYEXISTS, 		"The window name already exists",
		ERR_TOOMANYWINDOWS,		"Too many windows defined"
	];

	if ( ! isvar( errnum ) ) {
		errnum = this.err;
	}

	cnt = len( a );
	for ( i=0; i<cnt; i+=2 ) {
		if ( errnum == a[i] ) {
			return( { "num" : errnum, "desc" : a[i+1] } );
		}
	}

	return( null );
};





//////////////////////////////
// mouse handlers

function xMouseHandler( ) {
	this.win = null;
	this.prevWin = null;
	this.button = 0;
	this.wPos = null;	// window position & size
	this.ePos = null;	// event position
	this.isInMove = 0;
	this.isInSize = 0;
	this.dir = "";		// resize direction  n/ne/e/se/s/sw/w/nw
	this.defCursor = "";
	this.dragData = null;
	this.eTarget = null;
	this.isGrid = 0;
	this.aMagneticChildren = null;

	this.init( );
}
xMouseHandler.prototype.init = function( ) {
	if ( this.win ) {
		this.win.olayerEnable( 0 );
	}
	this.win = null;
	this.button = 0;
	this.wPos = null;
	this.ePos = null;
	this.isInMove = 0;
	this.isInSize = 0;
	this.eTarget = null;
	this.mouseoutHandler = null;
	//this.dragData = null;
};
var xMouseE = new xMouseHandler( );

function xDropDataGet( e ) {
	var d, txt, url;

	if ( xMouseE.dragData ) {
		d = xMouseE.dragData;
		xMouseE.dragData = null;
	}
	else {
//		if ( xlib.IsIE ) {
		if ( ! xlib.IsFF ) {
			txt = e.dataTransfer.getData("Text");
			url = e.dataTransfer.getData("url");
//			txt2 = e.dataTransfer.getData("text/plain");
			d = txt ? txt : url;
//alert( "txt=" + txt + ", url=" + url + ", txt2=" + txt2 );
			//if ( ! d ) { alert( "no drop data" ); }
		}
		else {
			// MOREWORK:
			alert( e.originalTarget );
		}
	}

	return( d );
}

function xWinMoveDir( e, w ) {
	var m, x, y, d="", o, o2, b, adj;

	if ( ( w.style & WS_MAXIMIZED ) || ( w.style & WS_MINIMIZED ) ) {
		return( "" );
	}
	o = w.position( );

	if ( w.oparent ) {
		o2 = w.oparent.position( );
		b = w.oparent.borderThickness( );
		o.left += o2.left + b;
		o.top += o2.top + b;
	}
	b = w.borderThickness( );
	adj = xlib.winWidthAdjustment( b );

	m = xlib.mousePos( e );

	x = m.x + xlib.winScrollX( );
	y = m.y + xlib.winScrollY( );

//	x = m.x + xlib.winScrollX( w.oparent ? w.oparent.oBody : null );
//	y = m.y + xlib.winScrollY( w.oparent ? w.oparent.oBody : null );
//	xlib.winStatus( m.x + xlib.winScrollX( w.oparent ? w.oparent.oBody : null ) );

	if ( w.oparent && w.oparent.style & WS_HEADER ) {
		o.top += w.oparent.hdrHeight;
	}

//	xlib.winStatus( "x:" + x + ", y:" + y + ", l:" + o.left + ", t:" + o.top + ", w:" + o.width + ", h:" + o.height );

	if ( x < o.left || x > o.left + o.width + adj || y < o.top || y > o.top + o.height + adj ) {
		return( "" );
	}

	if ( x <= o.left + xWinMoveOffset ) {
		if ( y <= o.top + xWinMoveOffset ) { d = "nw"; }
		else if ( y >= o.top + o.height + adj - xWinMoveOffset ) { d = "sw"; }
		else { d = "w"; }
	}
	else if ( x >= o.left + o.width + adj - xWinMoveOffset ) {
		if ( y <= o.top + xWinMoveOffset ) { d = "ne"; }
		else if ( y >= o.top + o.height + adj - xWinMoveOffset ) { d = "se"; }
		else { d = "e"; }
	}
	else if ( y < o.top + xWinMoveOffset ) {
		d = "n";
	}
	else if ( y > o.top + o.height + adj - xWinMoveOffset ) {
		d = "s";
	}

	return( d );
}

function xMouseMoveCursor( eTarget, w ) {
	if ( xWinOverBody( eTarget ) ) {
		if ( w.eDrop && ( w.style & WS_DROP ) ) {
			xlib.mouseCursor( eTarget, "crosshair" );
		}
		else if ( w.eClick || w.eDblClick ) {
			xlib.mouseCursor( eTarget, "pointer" );
		}
		else {
			xlib.mouseCursor( eTarget, xMouseE.defCursor.length ? xMouseE.defCursor : "auto" );
		}
	}
	else {
		xlib.mouseCursor( eTarget, xMouseE.defCursor.length ? xMouseE.defCursor : "auto" );
	}
}

function xWinMouseMove( e ) {
	var eTarget, x, y, w, h, oF=5, win, m, min=10, offset=0, k, d, mpos;
	var xOffset, yOffset, a, cnt, i

	m = xMouseE;
	e = xlib.eventGet( e );

	if ( xlib.IsIE ) {					// firefox, safari, and opera reset the mousebutton event on mousemove! grrrr.
		m.button = xlib.mouseButton( e );
	}

	eTarget = m.eTarget ? m.eTarget : xlib.eventTarget( e );
//	eTarget = xlib.eventTarget( e );
	if ( xlib.eventDefaultNode( eTarget ) ) {
		return( true );
	}

	win = xWinFromElement( eTarget );
	m.win = win;

	xlib.eventCurrentSet( "mPos", xlib.eventPosition( e ) );

	if ( m.win ) {
		xMouseMoveCursor( eTarget, win );
		if ( m.button & MOUSE_BUTTONLEFT ) {

			if ( ( m.win.style & WS_MAXIMIZED ) || ( m.win.style & WS_MINIMIZED ) ) {
				return( true );
			}

			if ( ( ! m.isInMove ) && ( m.win.style & WS_RESIZABLE ) ) {
				mpos = xlib.mousePos( e );
				if ( m.isInSize ) {
					if ( ! m.ePos ) {
						return( true );
					}

					if ( ( ! xlib.pageSizeEnabled ) && ( ! m.win.issys ) ) {
						return( true );
					}

					// process resize
					xlib.editClearSelection( e );
					mpos = xlib.mousePos( e, 1 );

					m.win.olayerEnable( 1 );
					xlib.pageLayer( 1, m.win.obj );

					x=m.wPos.left; y=m.wPos.top; w=m.wPos.width; h=m.wPos.height;

					k = xlib.keyGet( e );

					if ( m.dir.indexOf( "n" ) + 1 ) {
						y = m.wPos.top + mpos.y - m.ePos.y;
						h = m.wPos.height - mpos.y + m.ePos.y;
						if ( k.isSHIFT ) { w = xlib.winAdjustAspect( m.wPos.width, m.wPos.height, h ); }
						if ( k.isCTRL )	{
							h = xlib.winAdjustGrid( h );
							if ( k.isSHIFT ) { w = xlib.winAdjustGrid( w ); }
						}
					}
					if ( m.dir.indexOf( "e" ) + 1 ) {
						w = m.wPos.width + mpos.x - m.ePos.x;
						if ( k.isSHIFT ) { h = xlib.winAdjustAspect( m.wPos.height, m.wPos.width, w ); }
						if ( k.isCTRL )	{
							w = xlib.winAdjustGrid( w );
							if ( k.isSHIFT ) { h = xlib.winAdjustGrid( h ); }
						}
					}
					if ( m.dir.indexOf( "s" ) + 1 ) {
						h = m.wPos.height + mpos.y - m.ePos.y;
						if ( k.isSHIFT ) { w = xlib.winAdjustAspect( m.wPos.width, m.wPos.height, h ); }
						if ( k.isCTRL )	{
							h = xlib.winAdjustGrid( h );
							if ( k.isSHIFT ) { w = xlib.winAdjustGrid( w ); }
						}
					}
					if ( m.dir.indexOf( "w" ) + 1 ) {
						x = m.wPos.left + mpos.x - m.ePos.x;
						w = m.wPos.width - mpos.x + m.ePos.x;
						if ( k.isSHIFT ) { h = xlib.winAdjustAspect( m.wPos.height, m.wPos.width, w ); }
						if ( k.isCTRL )	{
							w = xlib.winAdjustGrid( w );
							if ( k.isSHIFT ) { h = xlib.winAdjustGrid( h ); }
						}
					}

					if ( ! xlib.IsIE ) {
						offset = m.win.borderThickness( ) * 2;
					}

					if ( w != null ) {
						if ( w < min ) { return( true ); }
						if ( ! xlib.IsIE ) { w += offset; }
					}
					if ( h != null ) {
						if ( h < min ) { return( true ); }
						if ( ! xlib.IsIE ) { h += offset; }
					}
					//xlib.winStatus( "x:" + x + ", y:" + y + ", w:" + w + ", h:" + h );
					xlib.UpdateFlag( 1, m.win );
					m.win.position( x, y, w, h );

					if ( m.win.eResize ) {
						xlib.eventCurrentSet( "eResize", { width:w, height:h } );
						m.win.eventRun( 'Resize', e );
					}

					// OpenAjax event - ID_WINSIZE
					if ( m.win.oaOpts && m.win.oaOpts & xlib.openajax.ID_WINSIZE ) {
						xlib.openajax.objPublish( e, xlib.openajax.ID_WINSIZE, m.win, { x:w, y:h }, m.win.oaDefSrvs.sid, "" );
					}

					return xlib.eventCancel( e );
				}
			}

			if ( ( ! m.isInSize ) && ( m.win.style & WS_MOVEABLE ) ) {
				// process move
				if ( ! m.ePos ) {
					return( true );
				}

				if ( ( ! xlib.pageMoveEnabled ) && ( ! m.win.issys ) ) {
					return( true );
				}

				xlib.editClearSelection( e );
				mpos = xlib.mousePos( e );

				if ( ! m.isInMove ) {
					if ( ( Math.abs( mpos.x - m.ePos.x ) < oF ) &&
						 ( Math.abs( mpos.y - m.ePos.y ) < oF ) ) {
						return( true );
					}
					m.win.olayerEnable( 1 );
					xlib.pageLayer( 1, m.win.obj );

					m.isInMove = 1;
					if ( xlib.keyGet( e ).isCTRL )	{
						m.isGrid = xlib.desktop.gridSet( );
					}

					m.aMagneticChildren = m.win.getMagneticChildren( );
					if ( this.mouseoutHandler ) {
						xlib.eventUnbind( m.win.oBody, "mouseout", "xWinMouseUp" );
					}
					this.mouseoutHandler = xlib.eventBind( m.win.oBody, "mouseout", "xWinMouseUp" );
				}

				if ( xWinIsTooltip ) {
					xWinIsTooltip.tooltipFunc( e, 0 );
				}

				x = xlib.winScrollX( ) + m.wPos.left + mpos.x - m.ePos.x;
				y = xlib.winScrollY( ) + m.wPos.top + mpos.y - m.ePos.y;

				if ( xlib.keyGet( e ).isCTRL )	{
					x = xlib.winAdjustGrid( x );
					y = xlib.winAdjustGrid( y );
				}

				xOffset = x - m.win.left;
				yOffset = y - m.win.top

				xlib.UpdateFlag( 1, m.win );
				m.win.position( x, y );

				if ( m.win.eMove ) {
					xlib.eventCurrentSet( "eMove", { left:x, top:y } );
					m.win.eventRun( 'Move', e );
				}

				// OpenAjax event - ID_WINMOVE
				if ( m.win.oaOpts && m.win.oaOpts & xlib.openajax.ID_WINMOVE ) {
					xlib.openajax.objPublish( e, xlib.openajax.ID_WINMOVE, m.win, { x:x,y:y }, m.win.oaDefSrvs.sid, "" );
				}

				a = m.aMagneticChildren;
				cnt = len( a );
				for ( i=0; i<cnt; i++ ) {
					a[i].left += xOffset;
					a[i].top += yOffset;
					a[i].obj.style.left = a[i].left;
					a[i].obj.style.top = a[i].top;
				}

				//xlib.winStatus( "x:" + x + ", y:" + y );
				//return( true );

				xlib.eventCancelBubble( e );
				return xlib.eventCancel( e );
			}
		}

		if ( m.win.style & WS_RESIZABLE ) {
			d = xWinMoveDir( e, m.win );
			if ( ( ! xlib.pageSizeEnabled ) && ( ! m.win.issys ) ) {
				return( true );
			}
			if ( d.length ) {
				if ( ! m.defCursor.length ) {
					m.defCursor = eTarget.style.cursor.indexOf( "-" ) ? "" : eTarget.style.cursor;
				}
				xlib.mouseCursor( eTarget, d + "-resize" );
			}
			else {
				xMouseMoveCursor( eTarget, m.win );

				m.defCursor = "";
				//m.init( );

				return( true );
			}
		}

		//m.init( );
		//return( xlib.eventCancel( e ) );
		return( true );
	}
	else {
		if ( xWinIsTooltip ) {
			if ( ! ( xWinIsTooltip.displayMode & DISP_NOAUTOCLOSE ) ) {
				xWinIsTooltip.tooltipFunc( e, 0 );
			}
		}
	}

if ( 0 ) {
	win = xWinFromElement( eTarget );
	if ( win ) {
		xMouseMoveCursor( eTarget, win );
		if ( win.style & WS_RESIZABLE ) {
			m.win = win;
			xWinMouseMove( e );
		}
	}
}

	return( true );
}


function xWinMouseDown( e ) {
	var m, w, topFlag, eTarget;

	e = xlib.eventGet( e );
	m = xMouseE;
	if ( m.win ) {
		m.init( );
	}

	eTarget = xlib.eventTarget( e )
	if ( xlib.eventDefaultNode( eTarget ) ) {
		return( true );
	}

	m.button = xlib.mouseButton( e );
	xlib.eventCurrentSet( "mButton", m.button );
	xlib.eventCurrentSet( "mPos", xlib.eventPosition( e ) );

	m.win = xWinFromElement( eTarget );
	if ( m.win ) {
		if ( m.prevWin && ( m.prevWin.name != m.win.name ) ) {
			xlib.dblclkTime = xlib.clkTime = 0;
		}
		m.prevWin = m.win;
	}
	else {
		xlib.menuCurrentSet( null );
		xlib.dblclkTime = xlib.clkTime = 0;
	}

	xlib.eventClickHandler( e, m.button | MOUSE_DOWN );

	if ( m.button & MOUSE_BUTTONLEFT ) {
		if ( m.win ) {
			m.eTarget = xlib.eventTarget( e );

//			if ( m.win & WS_DRAG ) {
//				m.dragData = xDragDataGet( e );
//			}

			if ( m.win.oparent && ( m.win.style & WS_CHILD ) ) {
				// MOREWORK: this needs to moved into mousemove, cause click/dbl click events not working otherwise
				m.win = m.win.oparent;
			}
			topFlag = m.win.bringtotop( );	// morework: opera has scrollbar bug when this is active
									// also, opera does not fire the onmouseup event when releasing over a scrollbar
			m.ePos = xlib.eventPosition( e );
			m.wPos = m.win.position( );

			if ( m.win.style & WS_RESIZABLE ) {
				m.dir = xWinMoveDir( e, m.win );
				if ( m.dir.length ) {
					m.isInMove = 0;
					m.isInSize = 1;
					if ( this.mouseoutHandler ) {
						xlib.eventUnbind( m.win.oBody, "mouseout", "xWinMouseUp" );
					}
					this.mouseoutHandler = xlib.eventBind( m.win.oBody, "mouseout", "xWinMouseUp" );

					if ( xlib.keyGet( e ).isCTRL )	{
						m.isGrid = xlib.desktop.gridSet( );
					}
				}
			}

//			if ( xlib.eventDefaultNode( m.eTarget ) ) {
			if ( topFlag || xlib.eventDefaultNode( m.eTarget ) || ( m.eTarget.getAttribute( "type" ) == "button" ) ) {
				//return( true );
			}

			if ( ! xlib.IsFF ) {
				return( true );
			}

			return( xlib.eventCancel( e ) );  // must be enabled for FF move, disabled for drag
		}
	}

	return( true );
}

function xWinMouseUp( e ) {
	var m, btn, eTarget;
//return( true );
	e = xlib.eventGet( e );

	eTarget = xlib.eventTarget( e )
	if ( xlib.eventDefaultNode( eTarget ) ) {
		return( true );
	}

	m = xMouseE;
	btn = xlib.eventCurrentGet( "mButton" );

	if ( m.isGrid ) {
		m.isGrid = xlib.desktop.gridRestore( );
	}

	if ( ! xlib.keyGet( e ).isALT ) {
		xlib.eventClickHandler( e, MOUSE_UP );
	}

	if ( m.isInMove || m.isInSize ) {
		xlib.pageLayer( 0 );
		xlib.mouseCursor( m.eTarget, "auto" );
		m.init( );
		xlib.eventCancelBubble( e );
		return xlib.eventCancel( e );
	}

	if ( m.win ) {
		if ( xlib.startupOptions & XINIT_RIGHTCLICK ) {
			if ( ( btn & MOUSE_BUTTONRIGHT ) || ( ( btn & MOUSE_BUTTONLEFT ) && xlib.keyGet( e ).isALT ) ) {
				xlib.eventGlobal = e;
				if ( m.win.contextmenu( ) ) {
					m.init( );
					xlib.pageLayer( 0 );
					xlib.mouseCursor( m.eTarget, "auto" );
					xlib.eventCancelBubble( e );
					return xlib.eventCancel( e );
				}
			}
		}
		xlib.pageLayer( 0 );
		xlib.mouseCursor( m.eTarget, "auto" );
	}
	m.init( );

	return( true );
}


function xWinArray( IncludeSys ) {
	var i, cnt, a = {};

	cnt = len( xWinList );
	for ( i=1; i<cnt; i++ ) {
		if ( xWinList[i] ) {
			if ( IncludeSys ) {
				a[len(a)] = xWinList[i];
			}
			else {
				if ( ! xWinList[i].issys ) {
					a[len(a)] = xWinList[i];
				}
			}
		}
	}
	return( a );
}

function xWinContextMenu( e ) {
	var w, btn;
	//e = xlib.eventGet( e );
	w = xWinFromElement( xlib.eventTarget( e ) );
	if ( w ) {
		btn = xlib.eventCurrentGet( "mButton" );
		if ( ( btn & MOUSE_BUTTONRIGHT ) || ( ( btn & MOUSE_BUTTONLEFT ) && xlib.keyGet( e ).isALT ) ) {
//		if ( ( btn & MOUSE_BUTTONRIGHT ) || ( ( btn & MOUSE_BUTTONLEFT ) && xlib.keyGet( e ).isCTRL ) ) {
//			if ( w.contextmenu( ) ) {
				return xlib.eventCancel( e );
//			}
		}
	}
	else if ( xLibContextMenuFunc ) {
		return( xLibContextMenuFunc( e ) );
	}
	return( true );
}


function xWinRecreate( id, data ) {
	var w = xWin( id );
	if ( w ) {
		w.destroy( );
	}
	if ( xlib.IsIE ) {
		setTimeout( "new xWindow( '" + id + "', '" + data + "' );", 10 ); // required for flash
	}
	else {
		w = new xWindow( id, data );
	}
	return( w );
}

function xWinResize( e ) {
	var cnt, i;
	e = xlib.eventGet( e );

	cnt = xWinList.length;
	for ( i=1; i<cnt; i++ ) {
		if ( xWinList[i].style & WS_MAXIMIZED ) {
			xWinList[i].maximize( 1 );
		}
	}
	return( true );
}

function xWinScroll( e ) {
	var cnt, i, IsMax=0;
	e = xlib.eventGet( e );

	cnt = xWinList.length;
	for ( i=1; i<cnt; i++ ) {
		if ( xWinList[i].style & WS_MAXIMIZED ) {
			IsMax = 1;
			break;
		}
	}
	if ( IsMax ) {
		window.scrollTo( xScrollPos.x, xScrollPos.y );
	}
}


////////////////////////////////////
// drag and drop


function xDropDataProcess( e ) {
	var data, pos;

	data = xDropDataGet( e );
	if ( strempty( data ) ) { return; }

	pos = xlib.mousePos( e, 1 );
	if ( xlib.openajax && xlib.openajax.dndEnabled ) {
		xlib.openajax.publish( "xwinlib_dnd", "({ data : \"" + jsEncode( data ) + "\", pos : { x : " + pos.x + ", y : " + pos.y + " } })" );
	}
	else {
		xlib.objFromData( data, pos, 0, null, 0, e );
	}
}

function xWinNameGen( otype ) {
	var s, d, x;

	while ( 1 ) {

		d = new xDate( );
		s = strswap( xlib.objNameFromId( otype ), " ", "" ) + "_";
		s += dec2hex( int( d.format( "YYMMDD" ) ) );
		s += dec2hex( int( d.format( "HHMNSS" ) ) );
		s += dec2hex( random( 1000 ) );

		if ( ! xWinFromName( s ) ) {
			break;
		}

	}

	return( s );
}

function xWinDragDrop_w3c( e ) {
	var win;

	e = xlib.eventGet( e );

	xlib.winStatus( e.nodeName );

	win = xWinFromElement( xlib.eventTarget( e ) );
	if ( win ) {
		win.eventRun( 'Drop', e );
		return;
	}


//data - this property returns the URLs of any dropped objects as an Array of Strings.
//type - this property indicates the type of event.
//target - this property indicates the object to which the event was originally sent.
//screenX - the cursor location when the click event occurs.
//screenY - the cursor location when the click event occurs.
//modifiers - lists the modifier keys (shift, alt, ctrl, etc.) held down when the click event occurs.

	var IsAlt = e.altKey ? 1 : 0;		// key modifiers
	var IsCtrl = e.ctrlKey ? 1 : 0;
	var IsShift = e.shiftKey ? 1 : 0;

	win = xWinFromElement( xlib.eventTarget( e ) );



	alert( "data:" + xMouseE.dragData + ", win:" + win.name + ", alt:" + IsAlt + ", ctrl:" + IsCtrl + ", shift:" + IsShift );

}





////////////////////////////////////////////////////////////////////////////////////
// xLibrary - Core
//


function xLibrary( ) {
	this.ver = "1.0";
	this.browser = "";
	this.version = "";
	this.OS = "";
	this.IsIE = 0;
	this.IsFF = 0;
	this.IsFF_Plugin = 0;
	this.DisableExternalContent = 0;

	this.eventGlobal = null;

	this.startupOptions = 0;
	this.errorFunc = null;

	this.actionPreprocessFunc = null;

	this.editClearSelection = null;

	this.eventHandlers = [];
	this.eventGet = null;
	this.eventKey = null;

	// "current" events
	this.mButton = 0;
	this.mPos = null;

	this.olayer = null;		// used for window move/resize

	this._scrollwidth = -1;
	this.scrollPos = null;

	this.topOffset = 0		// used to adjust y-position for navbar toggle

	this.pageMoveEnabled = 1;	// global enablers
	this.pageSizeEnabled = 1;
	this.pageObjMenuEnabled = 1;

	this.desktop = null;
	this.fx = null;

	this.animSteps = 15;
	this.animInterval = 10;
	this.animPower = 0.5;

	this.pngfix = 0;

	this.clkTime = 0;
	this.dblclkTime = 0;
	this.clkCount = 0;
	this.eClkTime = 0;
	this.eDblClkTime = 0;

	this.clkDelay = 500;		// opera requires longer delay on win objects!!??
	this.dblclkDelay = 1100;

	this.oCalcImage = null;			// used for dynamically calculating image size
	this.xImageLoaded = 0;
	this.xImageTimeout = 100;

	this.ddData = "";
	this.ddPos = null;

	this.curMenu = null;

	this.defX = 15;
	this.defY = 70;

	this.ReqUpdate = 0;

	this.ffPlugin = null;
	this.lookupFunc = null;

	this.openajax = null;

	this.jsDisableError = 0;
	this.jsErrorFunc = this._jsErrorFunc;

	this.initInternal( );

	this.aFrameBusters = [];

	this.rotator = null;
}

xLibrary.prototype.init = function( options ) {
	this.startupOptions = options;
	if ( options & XINIT_ACTIVEWINDOWS ) {
		this.eventBind( document, "mousemove", xWinMouseMove );
		this.eventBind( document, "mousedown", xWinMouseDown );
		this.eventBind( document, "mouseup", xWinMouseUp );
		this.eventBind( window, "resize", xWinResize );
		this.eventBind( window, "scroll", xWinScroll );
		if ( ! this.IsIE ) {
			if ( this.options & XINIT_DESKTOPDROP ) {
				//this.eventBind( document, "dragdrop", xWinEvent_Drop, true );
			}
		}
	}
	if ( options & XINIT_RIGHTCLICK ) {
		this.eventBind( document, "contextmenu", xWinContextMenu );
//		this.eventBind( document, "contextmenu", xWinEvent_Cancel );
	}
	if ( options & XINIT_ENABLEFX ) {
		this.fx = new xFx( );
	}
	if ( options & XINIT_DEFAULTDIRS ) {
		xWinImageDir = "http://www.xwinlib.com/libs/support";
		xWinThemesDir = xWinImageDir;
	}
	if ( options & XINIT_DESKTOP ) {
		this.desktop = new xDesktop( );
	}

	if ( options & XINIT_OPENAJAX ) {
		this.openajax = new oaInterface( );
	}

	if ( ! xlib.IsIE ) {
		// jkd: http://www.codingforums.com/archive/index.php/t-123103.html
		HTMLElement.prototype.__defineGetter__("outerHTML", function() {
		var span = document.createElement("span"); span.appendChild(this.cloneNode(true));
		return span.innerHTML;
		});

		HTMLElement.prototype.__defineSetter__("outerHTML", function(html) {
		var range = document.createRange();
		this.innerHTML = html;
		range.selectNodeContents(this);
		var frag = range.extractContents();
		this.parentNode.insertBefore(frag, this);
		this.parentNode.removeChild(this);
		});
	}

	if ( upper( xlib.browser ) == "CHROME" ) {
		document.addEventListener("DOMContentLoaded", function(e) {

			var plugin = document.createElement("embed");
			plugin.setAttribute("id", "xWinLibChromePluginId");
			plugin.setAttribute("type", "application/mozilla-npruntime-scriptable-plugin");
			plugin.setAttribute("width", "0");
			plugin.setAttribute("height", "0");

			document.body.appendChild(plugin);
		}, false);
	}

	//this.eventBind( window, "error", xWinError );

	xlibInitPage( );
};


xLibrary.prototype.initInternal = function( ) {
	xEnvironment.init( );

	this.browser = xEnvironment.browser;
	this.IsIE = strati( "EXPLORER", this.browser );
	this.IsFF = ( xEnvironment.browser == "Firefox" || xEnvironment.browser == "Mozilla" ) ? 1 : 0;
	this.version = xEnvironment.version;
	this.OS = xEnvironment.OS;

	this.pngfix = ( this.IsIE && ( this.version < 7 ) );
//this.pngfix=1;

	switch ( this.browser.toUpperCase( ) ) {
	  case "EXPLORER":
		this.eventGet 			= x_ie_eventGet;
		this.eventKey 			= x_ie_eventKey;
		this.editClearSelection = x_ie_editClearSelection;
		break;

	  case "OPERA":
		this.clkDelay 			= 700;		// opera requires longer delay on win objects!!??
		this.dblclkDelay 		= 1500;
	  	this.eventGet 			= x_w3c_eventGet;
		this.eventKey 			= x_w3c_eventKey;
		this.editClearSelection = x_w3c_editClearSelection;
		break;

	  default:
		this.animSteps = 10;
		this.animInterval = 5;
		this.animPower = 0.5;

	  	this.eventGet 			= x_w3c_eventGet;
		this.eventKey 			= x_w3c_eventKey;
		this.editClearSelection = x_w3c_editClearSelection;
	}

	if ( this.IsIE && ( this.version < 7 ) ) {
		// fix png files for IE
		this.eventBind( window, "load", xlib_PngFix );
	}

	// remove all of the page events on unload
	this.eventBind( window, "unload", this.eventUnbindAll );

};

xLibrary.prototype.initFromDivs = function( prefix ) {
	var a, cnt, i, w;
	var obj, name;

	if ( prefix == null ) {
		prefix = "xwinlib";
	}

	a = document.getElementsByTagName( "div" );
   	for( var i=0; i<len(a); i++ ) {
   		if ( ! a[i] ) {
   			continue;
   		}

   		if ( ! strati( prefix + "_", a[i].id ) ) {
   			continue;
   		}
   		obj = a[i];

   		name = right( obj.id, len( obj.id ) - ( len( prefix ) + 1 ) );
   		//name = obj.id

		win = new xWindow( name );
		win.style = WS_NORMAL | WS_MOVEABLE | WS_TRANSPARENT;
		win.overflow = "hidden";

		win.padding = int( obj.style.padding );
		win.margin = int( obj.style.margin );

		winstyle = obj.style.winstyle;
		if ( winstyle ) {
			win.style = eval( obj.style.winstyle );
		}

		if ( ! strempty( obj.style.border ) ) {
			win.borderWidth = int( obj.style.borderWidth );
			win.borderStyle = obj.style.borderStyle;
			win.borderColor = obj.style.borderColor;
			win.style |= WS_BORDER;
		}

		win.otype = 1;
		win.transLevel= 100;

		win.setposition( int( obj.style.left ), int( obj.style.top ), int( obj.style.width ), int( obj.style.height ) );
		win.action = domInnerHTML_get( obj );
		domInnerHTML_set( obj, "" );

		win.create( );
	}
};

xLibrary.prototype.isFrameBuster = function( url ) {
	var a, cnt, i;
	url = lower( url );

	a = this.aFrameBusters;
	cnt = len( a );
	for ( i=0; i<cnt; i++ ) {
		if ( strati( a[i], url ) ) {
			return( 1 );
		}
	}
	return( 0 );
};


xLibrary.prototype.UpdateFlag = function( flag, win ) {
	if ( flag == null ) {
		return( this.ReqUpdate );
	}
	if ( win && win.issys ) {
		return;
	}
	this.ReqUpdate = flag;
};

xLibrary.prototype.isInFrame = function( ) {
	return( self == top ? 0 : 1 );
};

xLibrary.prototype.namespaceCreate = function( ns ) {
	var a, i, nSpace;

	a = ns.split( "." );
	nSpace = a[i];
	for ( i=0; i<len(a); i++ ) {
		if ( typeof( nSpace ) == "undefined" ) {
			eval( nSpace + "={};" );
		}
		if ( i+1 < a.length ) {
			nSpace += "." + a[i+1];
		}
	}

};

xLibrary.prototype.fontCreate = function( opts ) {
	var f = new xWinFont( opts );
	return( f );
};

////////////////////////////
// event functions

xLibrary.prototype.eventBind = function( el, eventname, eventhandler, UseCapture ) {

	UseCapture = UseCapture == null ? false : UseCapture;

	if ( typeof( el ) == "string" ) {
		el = document.getElementById( el );
	}

	try {
		if ( el.addEventListener ) {
			el.addEventListener( eventname, eventhandler, UseCapture );
		}
		else if ( el.attachEvent ) {
			el.attachEvent( "on" + eventname, eventhandler );
		}

		this.eventHandlers.push( el, eventname, eventhandler );
	} catch( e ) { }
};

xLibrary.prototype.eventUnbind = function( el, eventname, eventhandler ) {
	if ( typeof( el) == "string" ) {
        el = document.getElementById( el );
	}
	try {
		if ( el.detachEvent ) {
			el.detachEvent( "on" + eventname, eventhandler );
		}
		else if ( el.removeEventListener ) {
			el.removeEventListener( eventname, eventhandler, false );
		}
	} catch( e ) { }
};

xLibrary.prototype.eventUnbindAll = function( ) {
	var i, cnt=0, o;

	if ( this.eventHandlers ) {
		cnt = this.eventHandlers.length;
	}

	for ( i=0; i<cnt; i+=3 ) {
		try {
			this.eventUnbind( this.eventHandlers[i], this.eventHandlers[i+1], this.eventHandlers[i+2] );
		} catch ( err ) { }
	}
	this.eventHandlers = null;

	if ( this.olayer ) {
		domDelete( this.olayer );
	}
	if ( xlib.IsFF ) {
		o = domObject( "ffplugin_img" );
		if ( o ) {
			domDelete( o );
		}
	}

};

xLibrary.prototype.eventTarget = function( e ) {
	var t;

	e = e ? e : window.event;

	if ( e.target ) {
		t = e.target;
	}
	else if ( e.srcElement ) {		// IE
		t = e.srcElement;
	}
	if ( t.nodeType == 3 ) {		// fixes Safari bug
		t = t.parentNode;
	}

	return( t );
};

xLibrary.prototype.eventCancel = function( e ) {
	if ( e.preventDefault ) {
		e.preventDefault( );
	}
	else {
		e.returnValue = false;
	}
	return( false );
};

xLibrary.prototype.eventCancelBubble = function( e ) {
	if ( xlib.IsIE ) {
		e.cancelBubble = true;
	}
	else {
		e.stopPropagation( );
	}
};

xLibrary.prototype.eventCancelDrag = function( e ) {
	return this.eventCancel( e );
};
xLibrary.prototype.eventCancelDrop = function( e ) {
	return this.eventCancel( e );
};


xLibrary.prototype.eventPosition = function( e ) {
	// return x/y including scroll offset
	var m, s;

	m = xlib.mousePos( e );
	s = xlib.winScrollPos( );

//	return [ { "x": m.x + s.x, "y": m.y + s.y } ][0];
	return ( { "x": m.x + s.x, "y": m.y + s.y } );
};

xLibrary.prototype.eventClickHandler = function( e, opts ) {
	var t, w, d = new Date( );

	if ( opts & MOUSE_BUTTONRIGHT ) {
		return;
	}

	if ( opts & MOUSE_DOWN ) {
		this.clkTime = d.getTime( );
	}
	else if ( opts & MOUSE_UP ) {
		t = d.getTime( );
		if ( t <= this.clkTime + this.clkDelay ) {
			if ( t <= this.dblclkTime + this.dblclkDelay ) {
				// double click
				w = xWinFromElement( xlib.eventTarget( e ) );
				if ( w ) {
					if ( w.eDblClick ) {
						this.eventCurrentSet( "eDblClkTime", t - this.dblclkTime );
						w.eventRun( 'DblClick', e );
					}

					// OpenAjax event - ID_DBLCLICK
					if ( w.oaOpts && w.oaOpts & xlib.openajax.ID_DBLCLICK ) {
						xlib.openajax.objPublish( e, xlib.openajax.ID_DBLCLICK, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, "" );
					}

				}
				this.clkTime = 0;
				this.dblclkTime = 0;
			}
			else {
				// click
				// MOREWORK: reset if 2nd click occurs from a different window
				this.dblclkTime = this.clkTime;
				if ( xMouseE.win ) {
					if ( xMouseE.win.eClick ) {
						this.eventCurrentSet( "eClkTime", t - this.clkTime );
						xMouseE.win.eventRun( 'Click', e );
					}
					// OpenAjax event - ID_CLICK
					w = xMouseE.win;
					if ( w.oaOpts && w.oaOpts & xlib.openajax.ID_CLICK ) {
						xlib.openajax.objPublish( e, xlib.openajax.ID_CLICK, w, xlib.eventPosition( e ), w.oaDefSrvs.sid, "" );
					}
				}
			}
		}
		else {
			this.clkTime = 0;
			this.dblclkTime = 0;
		}
	}
};

xLibrary.prototype.eventBody = function( ) {
	return document.getElementsByTagName("body").item(0);
};

xLibrary.prototype.eventDefaultNode = function( o ) {
    switch ( o.nodeName ) {
      case "INPUT":
      	if ( o.getAttribute( "type" ) == "button" ) {
      		return( 0 );
      	}
      case "TEXTAREA":
      case "SELECT":
      case "EMBED":
      case "OBJECT":
      case "A":
		return( 1 );
	}
	return( 0 );
};

xLibrary.prototype.eventCurrentSet = function( ename, val ) {
	this[ename] = val;
};

xLibrary.prototype.eventCurrentGet = function( ename ) {
	return this[ename];
};

xLibrary.prototype.intervalSet = function( el, interval ) {
	return window.setInterval( el, interval );
};

xLibrary.prototype.intervalClear = function( el ) {
	return window.clearInterval( el );
};

xLibrary.prototype._jsErrorFunc = function( msg, url, l ) {
	this.jsDisableError = 1;
	if ( this.jsDisableError ) {
		return( true );
	}
	return( confirm( "ERROR DETECTED:\n\n" + msg + "\n\nLinenum: " + l + "\n\nContinue?" ) );
};


//////////////////
// key functions
//////////////////

xLibrary.prototype.keyGet = function( e ) {
    var plugin = document.getElementById("xWinLibChromePluginId");
	// mac: control=ctrl, shift=shift, option=alt
	// safari: does not support CTRL key detection
	var o;

	if ( ! e ) {
		o = {
			"code": 0,
			"isALT": 0,
			"isCTRL": 0,
			"isSHIFT": 0
		};
	}
	else {
	    if (plugin != null && plugin.IsAltPressed != null && plugin.IsCtrlPressed != null && plugin.IsShiftPressed != null) {
	    	    o = {
	    		    "code": ( e && e.which ? e.which : e.keyCode ),
			        "isALT": e.altKey ? true : plugin.IsAltPressed() == "true",
			        "isCTRL": e.ctrlKey ? true : plugin.IsCtrlPressed() == "true",
			        "isSHIFT": e.shiftKey ? true : plugin.IsShiftPressed() == "true"
		    };
	    } else {
		o = {
			"code": ( e && e.which ? e.which : e.keyCode ),
			"isALT": e.altKey,
			"isCTRL": e.ctrlKey,
			"isSHIFT": e.shiftKey
		    };
		}
	}
	return( o )	;
};




////////////////////
// mouse functions
////////////////////

xLibrary.prototype.mouseX = function( e, IncludeScroll ) {
	// returns x-coord (excluding scrollX)
	var x=0;

	if ( e.pageX ) {
		x = e.pageX - this.winScrollX( );
	}
	else if ( e.clientX ) {
		x = e.clientX;
	}

	if ( IncludeScroll ) {
		x += this.winScrollX( );
	}

	return( x );
};

xLibrary.prototype.mouseY = function( e, IncludeScroll ) {
	// returns y-coord (excluding scrollY)
	var y=0;

	if ( e.pageY ) {
		y = e.pageY - this.winScrollY( );
	}
	else if ( e.clientY ) {
		y = e.clientY;
	}

	if ( IncludeScroll ) {
		y += this.winScrollY( );
	}

	return( y );
};

xLibrary.prototype.mousePos = function( e, IncludeScroll ) {
	if ( IncludeScroll ) {
		return( { "x" : this.mouseX( e, 1 ), "y" : this.mouseY( e, 1 ) } );
	}
	// returns x/y-coord (excluding scrollX/Y)
	return( { "x" : this.mouseX( e ), "y" : this.mouseY( e ) } );
};

xLibrary.prototype.mouseButton = function( e ) {
	if ( ! e ) {
		return( 0 );
	}
	if ( e.which == null ) {
		if ( ! e.button ) { return( 0 ) };
		return( ( e.button < 2 ) ? ( ( e.button == 1 ) ? MOUSE_BUTTONLEFT : 0 ) : ( ( e.button == 4 ) ? MOUSE_BUTTONCENTER : MOUSE_BUTTONRIGHT ) );
	}
	if ( ! e.which ) { return( 0 ) };
	return( ( e.which < 2 ) ? ( ( e.which == 1 ) ? MOUSE_BUTTONLEFT : 0 ) : ( ( e.which == 2 ) ? MOUSE_BUTTONCENTER : MOUSE_BUTTONRIGHT ) );
};

xLibrary.prototype.mouseCursor = function( o, csr ) {
	try {
		o.style.cursor = csr;
	} catch( e ) { }
};


/////////////////////
// window functions
/////////////////////


xLibrary.prototype.winWidth = function( ) {
//	if ( xlib.isInFrame( ) ) {
//		return( screen.height );
//	}
    if ( window.innerWidth ) {
        return( int( window.innerWidth ) - 0 );
    }
    return document.body.clientWidth;
};

xLibrary.prototype.winHeight = function( ) {
//	if ( xlib.isInFrame( ) ) {
//		return( screen.height );
//	}
    if ( window.innerHeight ) {
        return( int( window.innerHeight ) - 0 );
    }
    if ( document.documentElement && document.documentElement.clientHeight ) {
    	return( document.documentElement.clientHeight );
    }

    return document.body.clientHeight;
};

xLibrary.prototype.winSize = function( ) {
	return( { "width" : this.winWidth( ), "height" : this.winHeight( ) } );
};

xLibrary.prototype.winScrollX = function( o ) {
	var x = 0;

	if ( o ) {
		return o.scrollLeft;
	}

	if( window.pageXOffset ) {
		x = window.pageXOffset;
	}
	else if( document.body && document.body.scrollLeft ) {
		x = document.body.scrollLeft;
	}
	else if( document.documentElement && document.documentElement.scrollLeft ) {
		x = document.documentElement.scrollLeft;
	}
	else if( window.scrollX ) {
		x = window.scrollX;
	}
	return( x );
};

xLibrary.prototype.winScrollY = function( o ) {
	var y = 0;

	if ( o ) {
		return o.scrollTop;
	}

	if( window.pageYOffset ) {
		y = window.pageYOffset;
	}
	else if ( document.body && document.body.scrollTop ) {
		y = document.body.scrollTop;
	}
	else if( document.documentElement && document.documentElement.scrollTop ) {
		y = document.documentElement.scrollTop;
	}
	else if( window.scrollY ) {
		y = window.scrollY;
	}

	return( y );
};

xLibrary.prototype.winScrollPos = function( o ) {
	return( { "x" : this.winScrollX( o ), "y" : this.winScrollY( o ) } );
};

xLibrary.prototype.winScrollWidth = function( ) {
	if ( this._scrollwidth != -1 ) {
		return this._scrollwidth;
	}

	var inner = document.createElement('p');
	inner.style.width = '100%';
	inner.style.height = '200px';

	var outer = document.createElement('div');
	outer.style.position = 'absolute';
	outer.style.top = '0px';
	outer.style.left = '0px';
	outer.style.visibility = 'hidden';
	outer.style.width = '200px';
	outer.style.height = '150px';
	outer.style.overflow = 'hidden';
	outer.appendChild (inner);

	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = 'scroll';
	var w2 = inner.offsetWidth;
	if (w1 == w2) { w2 = outer.clientWidth; }

	document.body.removeChild (outer);

	this._scrollwidth = w1 - w2;

	return this._scrollwidth;
};


xLibrary.prototype.winSortedArray = function( includeSys ) {
	// return array of window objects sorted by zorder
	var i, cnt, a, b, j;

	a = new Array( );
	b = new Array( );

	cnt = xWinList.length;
	for ( i=1, j=0; i<cnt; i++ ) {
		if ( xWinList[i] ) {
			if ( ( ! xWinList[i].issys ) || ( xWinList[i].issys && includeSys ) ) {
				a[j++] = new Array( xWinList[i], xWinList[i].zorder );
			}
		}
	}
	if ( ! j ) {
		return( null );
	}

	a.sort( xlib.winSortFunc );
	cnt = len( a );
	for ( i=0; i<cnt; i++ ) {
		b[i] = a[i][0];
	}

	return( b );
};

xLibrary.prototype.winSortFunc = function( a, b ) {
    var x = a[1];
	var y = b[1];
    return ( ( x < y ) ? -1 : ( ( x > y ) ? 1 : 0 ) );
};


xLibrary.prototype.winStatus = function( s ) {
	// NOTE: IE7: Internet Options > Security > Custom Level > Allow status bar updates via script
	// safari: no status?
	window.status = s;
};

xLibrary.prototype.winAdjustX = function( x, width, offset ) {
	// make sure the window does not overhang the browser
	var xScroll, winWidth;

	x = typeof( x ) == "number" ? x : int( x );
	width = typeof( width ) == "number" ? width : int( width );

	xScroll  = this.winScrollX( );
	winWidth = this.winWidth( );

	if 	( x + width + offset > xScroll + winWidth ) {
		x = ( xScroll + winWidth ) - ( width + offset );
	}
	if ( x < xScroll + offset ) {
		x = xScroll + offset;
	}
	return( x );
};

xLibrary.prototype.winAdjustY = function( y, height, offset ) {
	// make sure the window does not overhang the browser
	var yScroll, winHeight;

	y = typeof( y ) == "number" ? y : int( y );
	height = typeof( height ) == "number" ? height : int( height );

	yScroll  = this.winScrollY( );
	winHeight = this.winHeight( );

	if 	( y + height + offset > yScroll + winHeight ) {
		y = ( yScroll + winHeight ) - ( height + offset );
	}
	if ( y < yScroll + offset ) {
		y = yScroll + offset;
	}
//xlib.winStatus( "y:" + y + ", height:" + height + ", winHeight:" + winHeight );

	return( y );
};

xLibrary.prototype.winAdjustPos = function( x, y, width, height, offset ) {
	x = this.winAdjustX( x, width, offset );
	y = this.winAdjustY( y, height, offset );
	return( { "x" : x, "y" : y } );
};

xLibrary.prototype.winCalcCenter = function( w, h, oparent ) {
	var x, y, h2;

	w = typeof( w ) == "number" ? w : int( w );
	h = typeof( h ) == "number" ? h : int( h );

	if ( oparent ) {
		x = ( oparent.width - w ) / 2;
		h2 = oparent.height - ( oparent.style & WS_HEADER ? oparent.hdrHeight : 0 ) - ( oparent.style & WS_FOOTER ? oparent.ftrHeight : 0 );
		y = ( h2 - h ) / 2;

		x = x < 0 ? 0 : x;
		y = y < 0 ? 0 : y;

		return( { "x" : int( x ), "y" : int( y ) } );
	}
	x = int( ( ( this.winWidth( ) - w ) / 2 ) + this.winScrollX( ) );
	y = int( ( ( this.winHeight( ) - h ) / 2 ) + this.winScrollY( ) );

	x = x < 0 ? 0 : x;
	y = y < 0 ? 0 : y;

	return( { "x" : x, "y" : y } );
};

xLibrary.prototype.winClipSet = function( o, x, y, w, h ) {
	if ( x == null ) { x = int( o.style.left ); }
	if ( y == null ) { y = int( o.style.top ); }
	if ( w == null ) { w = int( o.style.width ); }
	if ( h == null ) { h = int( o.style.height ); }

	// top, right, bot, left
	o.style.clip = "rect(0px " + w + "px " + h + "px 0px)";
};

xLibrary.prototype.winModalLayer = function( flag ) {
	var obj, id="xModalLayer", pt, flag;

	if ( flag ) {
		obj = domObject( id );
		if ( obj ) {
			return( obj );
		}

//		obj = domAdd( null, "img", id );
//		domImageSet( obj, xWinImageDir + "/xModalLayer.png" );

		obj = domAdd( null, "div", id );
		obj.style.backgroundImage = "url(" + xWinImageDir + "/xModalLayer.png)";

		obj.style.position = "absolute";
		obj.style.left = pxWrap(xlib.winScrollX( ));
		obj.style.top = pxWrap(xlib.winScrollY( ));
		if ( ! this.IsIE ) {
			obj.style.width = "100%";
			obj.style.height = "100%";
		}
		else {
			// IE doesn't handle width/height 100% properly
			pt = this.winSize( );
			obj.style.width = pxWrap(pt.width);
			obj.style.height = pxWrap(pt.height);
			this.eventBind( window, "resize", xWinModalResize );
		}

		this.eventCurrentSet( "scollPos", xlib.winScrollPos( ) );
		this.eventBind( window, "scroll", xWinModalScroll );

		obj.style.visibility = "visible";

		return( obj );
	}
	else {
		// make sure there are no other modal windows to display
		flag = 0;
		cnt = xWinList.length;
		for ( i=1; i<cnt; i++ ) {
			w = xWinList[i];
			if ( w.style & WS_MODAL ) {
				flag = 1;
				w.bringtotop( );
			}
		}
		if ( flag ) {
			return( obj );
		}

		this.eventUnbind( window, "scroll", xWinModalScroll );

		obj = domObject( id );
		domDelete( obj );
	}
	return( null );
};

xLibrary.prototype.winWidthAdjustment = function( b ) {
	// some browsers calc their width different based on the OS and window width
	// used for determining mouse positioning for resize
	if ( xlib.IsIE ) {
		return( 0 );
	}
//	if ( ( xlib.OS == "Mac" ) && ( xlib.browser == "Firefox" ) ) {
	if ( xlib.browser == "Firefox" ) {
		return( b * 2 );
	}
	else if ( xlib.browser == "Chrome" ) {
		return( 0 );
	}
	return( b*2 );
};


xLibrary.prototype.winAdjustAspect = function( oval, x, y ) {
	var z;
	if ( x == y ) { return( oval ); }
	if ( y > x ) {
		z = ( y - x ) / x;
		return( oval + int( oval * z, 10 ) );
	}
	z = ( x - y ) / x;
	return( oval - int( oval * z, 10 ) );
};


xLibrary.prototype.winAdjustGrid = function( x ) {
	return( Math.round( x / this.desktop.gridSize ) * this.desktop.gridSize );
};


xLibrary.prototype.winOffsetWidth = function( o, b, p ) {
	if ( this.IsIE ) { return o.offsetWidth; }
	return( o.offsetWidth - ( ( b + p ) * 2 ) );
};
xLibrary.prototype.winOffsetHeight = function( o, b, p ) {
	if ( this.IsIE ) { return o.offsetHeight; }
	return( o.offsetHeight - ( ( b + p ) * 2 ) );
};

xLibrary.prototype.winDefPostion = function( ) {
	var pt;
	if ( this.defX > 400 ) {
		this.defX = 15;
		this.defY += 25;
	}
	if ( this.defY > 400 ) {
		this.defY = 70;
	}
	pt = { x:this.defX, y:this.defY };

	pt.x += xlib.winScrollX( );
	pt.y += xlib.winScrollY( );

	this.defX += 25;
	this.defY += 25;
	return( pt );
};

xLibrary.prototype.pageLayer = function( f, obj ) {
	var o;

//	if ( upper( xlib.browser ) == "SAFARI" ) {
//		return;
//	}
	if ( ! this.olayer ) {
		if ( ! f ) {
			return;
		}
		this.olayer = domAdd( null, "div", "page_lyr" );
		o = this.olayer;
		o.style.overflow = "hidden";
		o.style.position = "absolute";
		o.style.left = xlib.winScrollX( );
		o.style.top = xlib.winScrollY( );
		o.style.width = "100%";
		o.style.height = "100%";
		o.style.visibility = "hidden";
		o.style.zIndex = -1;
		domInnerHTML_set( o, "<img src='" + xWinImageDir + "/trans.gif' border=0 width='100%' 'height=100%' ondragstart='return false;' onclick='xlib.pageLayer( 0 );'>" );
		xlib_PngFix( o );
	}
	o = domObject( "page_lyr" );
	if ( f ) {
		o.style.visibility = "visible";
		o.style.zIndex = obj.style.zIndex + 10001;
	}
	else {
		o.style.visibility = "hidden";
	}
};

xLibrary.prototype.menuCurrentSet = function( w ) {
	if ( ( ! w ) || ( this.curMenu && ( this.curMenu.name != w.name ) ) ) {
		this.menuCurrentDelete( );
	}
	this.curMenu = w;
};

xLibrary.prototype.menuCurrentDelete = function( ) {
	var w;
	if ( this.curMenu ) {
		w = xWin( this.curMenu.name );
		if ( w ) {
			w.destroy( );
		}
		this.curMenu = null;
	}
};

xLibrary.prototype.textSelected = function( ) {
	var txt = "";

	if ( window.getSelection ) {
		txt = window.getSelection( );
	}
	else if ( document.getSelection ) {
		txt = document.getSelection( );
	}
	else if ( document.selection ) {
		txt = document.selection.createRange( ).text;
	}
	return( txt );
};

xLibrary.prototype.objPreprocess = function( data, vname, val ) {
	return( strswap( data, vname, val ) );
};

xLibrary.prototype.debugPos = function( ) {
	// add to mousemove event
	// xlib.eventBind( document, "mousemove", xlib.debugPos );
	var m, s, w;
	m = this.mousePos( this.eventGet( event ) );
	s = this.winScrollPos( );
	w = this.winSize( );
	this.winStatus( "SCROLL: x=" + s.x + ", y=" + s.y + " MOUSE: x=" + m.x + ", y=" + m.y + " WINDOW: w=" + w.width + ", h=" + w.height );
};


xLibrary.prototype.imageRender = function( iname, w, h ) {
	return( "<img src='" + iname + "' border=0 width=" + w + " height=" + h + ">" );
};

xLibrary.prototype.imagePreload = function( iname, w, h ) {
	var img;

	if ( w && h ) {
		img = new Image( w, h );
	}
	else {
		img = new Image( );
	}
	img.src = iname;
	return( img );
};

xLibrary.prototype.imageRotate = function( id, val ) {
	var r = this.imageRotatorInit( );
	if ( r ) {
		val = val > 359 || val < -359 ? 0 : val;
		r.specify( 'rotate', '' + val );
		id = left( id, 1 ) == "#" ? id : "#" + id;
//alert( id + ", " + val );
		r.swap( id );
	}
};

xLibrary.prototype.imageRotatorInit = function( ) {
	// initialize the swfir rotator object
	// requires /libs/swfir.swf  and /libs/swfir_smr.js
	if ( ! this.rotator ) {
		try {
			this.rotator = new swfir();
			this.rotator.specify( 'src', '/libs/swfir.swf' );
		}
		catch ( e ) {
			this.rotator = null;
		}
	}
	return( this.rotator );
};

xLibrary.prototype.animateOptionsSet = function( o, opts ) {
	if ( opts ) {
		o.animInterval = opts.interval ? opts.interval : this.animInterval;
		o.animPower = opts.power ? opts.power : this.animPower;
		o.animSteps = opts.steps ? opts.steps : this.animSteps;
	}
	else {
		o.animInterval = this.animInterval;
		o.animPower = this.animPower;
		o.animSteps = this.animSteps;
	}
};


xLibrary.prototype.objLookup = function( id, datatype ) {
	var data="", w, otype, d;

	if ( ! datatype ) {
		datatype = DP_XOBJ;
	}

	if ( this.lookupFunc ) {
		data = this.lookupFunc( id );
	}

	if ( strempty( data ) ) {
		data = xlibAjax( AJAX_GET, AJAX_SYNCH, "/ws.htm", "cmd=OBJ_LOOKUP&id=" + id );
	}

	if ( datatype & DP_XOBJ ) {
		otype = parseInt( xWinVar( "otype", data ) );
		w = new xWindow( xWinNameGen( otype ), data, 1 );
		return( w );
	}
	return( data );
};

xLibrary.prototype.objFromData = function( data, pos, ReloadFlag, pSize, NoCreate, e, oParentDocBody) {
	var utype, win, w=0, h=0;
	var action, k, xbg;
	var xobj, defFlag, xdata, title, xname;
	var isoa=0;

	if ( ! pos ) {
		pos = xlib.winDefPostion( );
	}

	if ( strati( "sig=%24xLib%", data ) ) {
		win = new xWindow( xWinNameGen( OTYPE_WEB ), data, 1 );
		win.left = pos.x; win.top = pos.y;
		win.create(oParentDocBody);
		return( win );
	}

	if ( isUrl( data ) ) {
		// special handlers
		if ( strati( "images.google.com", data ) || strati( "google.com/imgres", data ) ) {
			w = xWebVar( "w", data, 1 );
			h = xWebVar( "h", data, 1 );
			d = urlFix( xWebVar( "imgurl", data ) );
			if ( ! strempty( d ) ) {
				data = d;
			}
		}
		else if ( strati( "images.search.yahoo.com", data ) ) {
			data = jsDecode( data );
			w = xWebVar( "w", data, 1 );
			h = xWebVar( "h", data, 1 );
			d = urlFix( xWebVar( "imgurl", data ) );
			if ( ! strempty( d ) ) {
				data = d;
			}
		}
		else if ( strati( "bing.com/images/", data ) ) {
			d = urlFix( xWebVar( "furl", data ) );
			if ( ! strempty( d ) ) {
				data = d;
			}
		}
		else if ( strati( "search.live.com", data ) ) {
			d = urlFix( xWebVar( "furl", data ) );
			if ( ! strempty( d ) ) {
				data = d;
			}
		}
		else if ( strati( "search.aol.com/aol/redir?src=image", data ) ) {
			data = jsDecode( data );
			w = xWebVar( "width", data, 1 );
			h = xWebVar( "height", data, 1 );
			d = urlFix( xWebVar( "img", data ) );
			if ( ! strempty( d ) ) {
				data = d;
			}
		}
		else if ( strati( "photobucket.com", data ) ) {
			action = xWebVar( "action", data );
			if ( action == "view" ) {
				d = urlFix( strextract( data, "?", 1 ) + xWebVar( "current", data ) );
				if ( ! strempty( d ) ) {
					data = d;
				}
			}
		}

		utype = xWebVar( "xtype", data, 1 );
		if ( ! utype ) {
			utype = urlType( data ) ;
		}

		if ( strati( ".shutterfly.com/media", data ) ) {
			utype = DATA_IMAGE;
		}
		else if ( strati( ".snapfish.com/", data ) ) {
			utype = DATA_IMAGE;
		}
		else if ( strati( "flickr.com/photos/", data ) ) {
			utype = DATA_IMAGE;
		}

		switch ( utype ) {
		  case DATA_IMAGE:
			if ( e ) {
				k = xlib.keyGet( e );
				xbg = int( "0" + xWebVar( "xbg", data ) );
				if ( k.isCTRL || xbg )	{
					xlib.desktop.bgSet( data, null, 1 );
					return;
				}
			}

		  	if ( ! w + h ) {
		  		if ( pSize) {
		  			w = pSize.w;
		  			h = pSize.h;
		  		}
		  		else {
					xImageCalcSize( data, pos );
					return;
				}
			  	if ( w + h < 1 ) {
			  		w = 300; h = 200;
			  	}
		  	}

			win = xlib.objGenerate( null, OTYPE_IMAGE, xWinNameGen( OTYPE_IMAGE ), pos.x, pos.y, w, h, { img: data, title:"" } );
			break;

		  case DATA_FEED:
			data = "/rss.htm?url=" + jsEncode( data );
			w = 400; h = 300;
			win = xlib.objGenerate( null, OTYPE_FEED, xWinNameGen( OTYPE_FEED ), pos.x, pos.y, w, h, { data: data } );
			win.header = "#TITLE#";
			win.bgColor = "#ffffff";
		  	break;

		  default:
		  	if ( strempty( data ) ) {
				alert( "Unable to resolve request." );
		  		return;
		  	}

			data = xlib.normalizeURL( data );
			if ( strati( "_oam.xml", data ) ) {		// support for OAWIDGETS
				isoa = 1;
				data = "/oamViewer.htm?url=" + jsEncode( data );
			}

			// process lookup
			xobj = xWebVar( "xobj", data );
			xname = xWebVar( "xname", data );
			defFlag = 1;
			if ( ! strempty( xobj ) ) {
				xdata = ""
				if ( xlib.keyGet( e ).isCTRL ) {
					xdata = xlib.objLookup( xobj + "_CTRL", DP_RAW );
				}
				else if ( xlib.keyGet( e ).isALT ) {
					xdata = xlib.objLookup( xobj + "_ALT", DP_RAW );
				}
				if ( strempty( xdata ) ) {
					xdata = xlib.objLookup( xobj, DP_RAW );
				}
				if ( ! strempty( xdata ) ) {
					xdata = xlib.objPreprocess( xdata, "#XDATA#", xWebVar( "xdata", data ) );
					xdata = xlib.objPreprocess( xdata, "#XTITLE#", strswap( jsDecode( xWebVar( "xtitle", data ) ), "+", " " ) );
					otype = parseInt( xWinVar( "otype", xdata ) );
					win = new xWindow( strempty( xname ) ? xWinNameGen( otype ) : xname, xdata, 1 );
					win.left = pos.x
					win.top = pos.y
					defFlag =0;
				}
			}
			if ( defFlag ) {
				if ( xlib.keyGet( e ).isCTRL ) {
					win = xlib.objLookup( "fbLink" );
					win.action = xlib.objPreprocess( win.action, "#TITLE#", strabbr( data, 30 ) );
					win.eClick = xlib.objPreprocess( "" + win.eClick, "#ACTION#", data );
					win.left = pos.x
					win.top = pos.y
				}
				else if ( xlib.keyGet( e ).isALT ) {
					win = xlib.objLookup( "fbLinkButton" );
					win.action = xlib.objPreprocess( win.action, "#TITLE#", strabbr( data, 30 ) );
					win.eClick = xlib.objPreprocess( "" + win.eClick, "#ACTION#", data );
					win.left = pos.x
					win.top = pos.y
				}
				else {
					w = 500; h = 400;
					win = xlib.objGenerate( null, OTYPE_WEB, xWinNameGen( OTYPE_WEB ), pos.x, pos.y, w, h, { action: data } );
				}
			}
			if ( isoa ) {
				win.header = "OpenAjax Widget - Meta File";
			}
		}
	}
	else {
		if ( strati( "www.gmodules.com", data ) ) {		// google gadgets
			action = strswap( data, "&amp;", "&" );
			w = xWebVar( "w", action, 1 ) + 5;
			h = xWebVar( "h", action, 1 ) + 30;
			win = xlib.objGenerate( null, OTYPE_WIDGET, xWinNameGen( OTYPE_WIDGET ), pos.x, pos.y, w, h, { data: data } );
			win.header = strswap( jsDecode( xWebVar( "title", action ) ), "+", " " );
			win.displayMode |= DISP_NOPROGRESS;
		}
		else if ( strati( "<script", data ) ) {
			w = 300; h = 200;
			win = xlib.objGenerate( null, OTYPE_WIDGET, xWinNameGen( OTYPE_WIDGET ), pos.x, pos.y, w, h, { data: data } );
			win.header = "Script Widget";
			win.displayMode |= DISP_NOPROGRESS;
		}
		else if ( strati( "<object", data ) || strati( "<embed", data )  ) {
			action = strswap( data, "&amp;", "&" );
			w = xWebVar( "width", action, 1 ) + 5;
			h = xWebVar( "height", action, 1 ) + 30;
			win = xlib.objGenerate( null, OTYPE_WIDGET, xWinNameGen( OTYPE_WIDGET ), pos.x, pos.y, w, h, { data: data } );
			win.header = "Object";
			win.displayMode |= DISP_NOPROGRESS;
		}
		else if ( strati( "javascript:", data ) ) {
			title = strswap( jsDecode( xWebVar( "xtitle", data ) ), "+", " " );
			if ( strempty( title ) ) {
				title = strabbr( strextract( strswapi( data, "javascript:", "" ), "(", 1 ), 30 );
			}
			if ( xlib.keyGet( e ).isALT ) {
				win = xlib.objLookup( "fbLink" );
				win.style &= ~WS_EXTERNAL;
				win.action = xlib.objPreprocess( win.action, "#TITLE#", title );
				win.eClick = strswapi( data, "javascript:", "" );
				win.left = pos.x
				win.top = pos.y
			}
			else {
				win = xlib.objLookup( "fbLinkButton" );
				win.style &= ~WS_EXTERNAL;
				win.action = xlib.objPreprocess( win.action, "#TITLE#", title );
				win.eClick = strswapi( data, "javascript:", "" );
				win.left = pos.x
				win.top = pos.y
			}
		}
		else {
			w = 300; h = 200;
//			if ( strati( "<script", data ) ) {
//				win = xlib.objGenerate( null, OTYPE_SCRIPT, xWinNameGen( OTYPE_SCRIPT ), pos.x, pos.y, w, h, { data: data, transLevel: 80 } );
//			}
//			else {
				win = xlib.objGenerate( null, OTYPE_HTMLBLOCK, xWinNameGen( OTYPE_HTMLBLOCK ), pos.x, pos.y, w, h, { source: data, transLevel: 80 } );
//			}
if ( 0 ) {
			w = 300; h = 200;
			win = xlib.objGenerate( null, OTYPE_WIDGET, xWinNameGen( OTYPE_WIDGET ), pos.x, pos.y, w, h, { data: data } );
			win.header = "HTML";
			win.displayMode |= DISP_NOPROGRESS;
}
		}



	}
	if ( ! NoCreate ) {
		if ( win ) { win.create(oParentDocBody); }
	}
	return( win );
};


xLibrary.prototype.objGenerate = function( oparent, otype, name, x, y, w, h, opts ) {
	var o, title="";
	var bgColor = xWinBgColor;
	var padding = 10;
	var style = WS_NORMAL | WS_BORDER;
	//var oFont = opts && opts.oFont ? opts.oFont : null;
	var font = null;
	var action = "";
	var data = "";

	w = int( w );
	h = int( h );

	o = new xWindow( name );
	if ( ! o ) { return( null ); }

	switch ( otype ) {
	  case OTYPE_TEXTBLOCK:
	  	bgColor = "white";
		style = WS_NORMAL | WS_TRANSPARENT | WS_BORDER | WS_RESIZABLE | WS_MOVEABLE | WS_CONTEXTMENU;
	  	padding = 10;
	  	o.transLevel = opts ? opts.transLevel || 60 : 60;
	  	action = opts ? opts.text || "" : "";
	  	break;

	  case OTYPE_TEXTBLOCK_TRANS:
	  	bgColor = "";
	  	style = WS_NORMAL | WS_TRANSPARENT | WS_MOVEABLE | WS_RESIZABLE | WS_BORDER;
	  	padding = 10;
	  	o.transLevel = opts ? opts.transLevel || 60 : 60;
	  	action = opts ? opts.text || "" : "";
	  	break;

	  case OTYPE_HTMLBLOCK:
	  	bgColor = "";
	  	style = WS_NORMAL | WS_TRANSPARENT | WS_MOVEABLE | WS_RESIZABLE | WS_BORDER;
	  	padding = 10;
	  	o.transLevel = opts ? opts.transLevel || 60 : 60;
	  	action = opts ? opts.source || "" : "";
//	  	action = strswap( action, "\r\n", "<br>" );

//	  	bgColor = "";
//	  	style = WS_NORMAL;
//	  	padding = 0;
//	  	o.overflow = "hidden";
//	  	action = opts ? opts.source || "" : "";
	  	break;

	  case OTYPE_DROPZONE:
	  	bgColor = "#FFFFD0";
	  	style = WS_NORMAL | WS_BORDER | WS_DROP;
	  	action = opts ? opts.text || "" : "";
	  	break;

	  case OTYPE_IMAGE:
	  	style = WS_NORMAL | WS_BORDER | WS_MOVEABLE | WS_RESIZABLE;
	  	padding = 0;

		if ( strati( ".png", opts.img ) || strati( ".gif", opts.img ) ) {
			style |= WS_TRANSPARENT;
			o.transLevel = 100;
			style &= ~WS_BORDER;
		}
		else {
		  	w += o.borderThickness( ) * 2;
	  		h += o.borderThickness( ) * 2;
	  	}

	  	action = opts ? "<img src='" + opts.img + "' border=0 width=100% height=100% >" || "" : "";
        o.eClick = xWebVar( "xaction", opts.img );

//	  	" + ( opts && opts.title ? "title=\"" + opts.title + "\"" : "" ) + "
//	  	action = opts ? "<img src='" + opts.img + "' border=0 width=100% height=100% " + ( opts && opts.title ? "title=\"" + opts.title + "\"" : "" ) + ">" || "" : "";
	  	break;

	  case OTYPE_WEB:
	  	style = WS_NORMAL | WS_EXTERNAL | WS_BORDERTHICK | WS_MOVEABLE | WS_UNDOCKABLE | WS_RESIZABLE | WS_HEADER | WS_MAXIMIZABLE | WS_CLOSE | WS_SYSMENU;
	  	action = opts ? opts.action || "" : "";
//		if ( ! strempty( xWinDefaultTheme ) ) {
//			try {
//				var buO = o;
//				o = eval( "theme_" + xWinDefaultTheme + "('" + name + "',\"" + action + "\",1)" );
//				style = o.style;
//				padding = o.padding;
//				bgColor = o.bgColor;
//			} catch( e ) {
//				o = buO;
//			}
//		}
		title = strswap( jsDecode( xWebVar( "xtitle", action ) ), "+", " " );
		o.header = strabbr( strempty( title ) ? action : title, 40 );
	  	break;

	  case OTYPE_SCRIPT:
	  case OTYPE_FLASH:
	  case OTYPE_WIDGET:
	  	style = WS_NORMAL | WS_EXTERNAL | WS_BORDERTHICK | WS_MOVEABLE | WS_RESIZABLE | WS_HEADER | WS_CLOSE;
	  	padding = 0;
	  	o.overflow = "hidden";
	  	w += o.borderThickness( ) * 2;
	  	h += o.hdrHeight + o.borderThickness( ) * 2;
	  	data = opts ? opts.data || "" : "";
	  	o.displayMode |= DISP_NOPROGRESS;
	  	action = "/widget.htm?data=" + jsEncode( data ) + "&xid=" + name;
	  	break;
	  case OTYPE_FEED:
	  	style = WS_NORMAL | WS_EXTERNAL | WS_BORDERTHICK | WS_MOVEABLE | WS_UNDOCKABLE | WS_RESIZABLE | WS_HEADER | WS_MAXIMIZABLE | WS_CLOSE | WS_SYSMENU;
	  	action = opts ? ( opts.data + "&xid=" + name ) || "" : "";
	  	break;
	}

	if ( opts ) {
		style = opts.style || style;
		bgColor = opts.bgColor || bgColor;
		padding = opts.padding != null ? opts.padding : padding;
		font = opts.font;
	}

	if ( font ) {
		o.action = font.render( action );
	}
	else {

		if ( ( ! strempty( xWinDefaultTheme ) ) && ( style & WS_HEADER || style & WS_FOOTER ) ){
			try {
				var buO = o;
				o = eval( "theme_" + xWinDefaultTheme + "('" + name + "',\"" + action + "\"," + ( style & WS_EXTERNAL ) + ")" );
				o.header = strabbr( strempty( title ) ? action : title, 60 );
				style = o.style;
				padding = o.padding;
				bgColor = o.bgColor;
			} catch( e ) {
				o = buO;
			}
		}
		else {
			o.action = action;
		}


//		if ( strempty( xWinDefaultTheme ) ) {
//			o.action = action;
//		}
	}

	if ( opts && opts.title ) {
		o.rollover = opts.title;
	}

	o.eDrag = opts ? opts.eDrag || null : null;
	o.eDrop = opts ? opts.eDrop || null : null;

	o.style = style | WS_CONTEXTMENU;

  	o.padding = padding;
  	o.bgColor = bgColor;

	o.oparent = oparent;
	o.otype = otype;

	o.setposition( x, y, w, h );

	return( o );
};

xLibrary.prototype.objNameFromId = function( otype ) {
	switch ( otype ) {
	  case OTYPE_TEXTBLOCK:			return( "Text Block" );
	  case OTYPE_TEXTBLOCK_TRANS:	return( "Text Block Transparent" );
	  case OTYPE_TEXTCAPTION:		return( "Text Caption" );
	  case OTYPE_TEXTHEADLINE:		return( "Text Headline" );
	  case OTYPE_TEXTFOOTNOTE:		return( "Text Footnote" );
	  case OTYPE_IMAGE:				return( "Image" );
	  case OTYPE_BACKGROUND:		return( "Background" );
	  case OTYPE_MUSIC:				return( "Music" );
	  case OTYPE_VIDEO:				return( "Video" );
	  case OTYPE_WEB:				return( "Web" );
	  case OTYPE_FEED:				return( "Feed" );
	  case OTYPE_FRIENDS:			return( "Friends" );
	  case OTYPE_GUESTBOOK:			return( "Guestbook" );
	  case OTYPE_PROFILE:			return( "Profile" );
	  case OTYPE_CONTACT:			return( "Contact" );
	  case OTYPE_GALLERY:			return( "Gallery" );
	  case OTYPE_WIDGET:			return( "Widget" );
	  case OTYPE_DOCUMENT:			return( "Document" );
	  case OTYPE_FLASH:				return( "Flash" );
	  case OTYPE_SCRIPT:			return( "Script" );
	  case OTYPE_NAVIGATION:		return( "Navigation" );
	  case OTYPE_DROPZONE:			return( "Dropzone" );
	  case OTYPE_MAP:				return( "Map" );
	  case OTYPE_HTMLBLOCK:			return( "HTML Block" );
	  case OTYPE_BUTTON:			return( "Button" );
	  case OTYPE_LINK:				return( "Link" );
	  case OTYPE_OBJECT:			return( "Object" );
	  case OTYPE_OAWIDGET:			return( "OA Widget" );
	  case OTYPE_FORM_TEXT:			return( "Form Element - Text" );
	  case OTYPE_FORM_TEXTAREA:		return( "Form Element - Textarea" );
	  case OTYPE_FORM_SELECT:		return( "Form Element - Select" );
	  case OTYPE_FORM_FILE:			return( "Form Element - File" );
	  case OTYPE_FORM_CHECKBOX:		return( "Form Element - Checkbox" );
	  case OTYPE_FORM_RADIO:		return( "Form Element - Radio" );
	  case OTYPE_FORM_PASSWORD:		return( "Form Element - Password" );
	  case OTYPE_FORM_HIDDEN:		return( "Form Element - Hidden" );
	}
	return( "unknown" );
};

xLibrary.prototype.objRender = function( id, state, mode, opts ) {
	var o, flag, data, f;

	o = domObject( id );
	if ( ! o ) { return( 0 ); }

	flag = ( state != -1 ? state : o.style.display != "block" );

	if ( ! flag ) {
		if ( mode & OBJ_ROLLDOWN ) {
			f = function( o ) {
				o.style.display = "none"; o.style.visibility = "hidden";
				if ( o.mode & OBJ_CLEARONCLOSE ) {
					if ( xlib.IsIE ) {
						// IE needs a brief delay!!!???
						setTimeout( "domInnerHTML_set( '" + o.id + "', '' );", 100 );
					}
					else {
						domInnerHTML_set( o, "" );
					}
				}
			};
			o.mode = mode;
			xlib.animateHeight( o, int( o.style.height ), 1, opts, f );
		}
		else {
			o.style.display = "none";
			o.style.visibility = "hidden";
			if ( mode & OBJ_CLEARONCLOSE ) {
				domInnerHTML_set( o, "" );
			}
		}
		return( 1 );
	}

	if ( mode & OBJ_AJAXCONTENT ) {
		// supported options: opts.ajaxAddress, opts.ajaxMethod, opts.ajaxSynch, opts.ajaxRtype, opts.ajaxCallback
		data = xlibAjax( opts.ajaxMethod, opts.ajaxSynch, strextract( opts.ajaxAddress, "?", 1 ), "req=AJAX_REQ&rtype=" + opts.ajaxRtype + "&" + strextract( opts.ajaxAddress, "?", 2 ), opts.ajaxCallback );
		if ( opts.ajaxSynch & AJAX_SYNCH ) {
			domInnerHTML_set( o, data );
		}
	}

	if ( mode & OBJ_ROLLDOWN ) {
		o.style.height = 1;
	}
	o.style.display = "block";
	o.style.visibility = "visible";

	if ( mode & OBJ_ROLLDOWN ) {
		xlib.animateHeight( o, 1, opts.rollHeight, opts, null );
	}
	return( 1 );
};


xLibrary.prototype.objTooltip = function( e, oparent, flag, content, opts ) {
	var n, o, m, f, borderWidth;
	var mode=0, width=200, height=0, offset=5, bgColor=null, bgImage=null;
	var xOffset=0, yOffset=10, padding=4, opacity=null, shadow=0;

	borderWidth = 1;	// must match the xTooltip class in xstyle.css

	n = oparent.id + "_tt";
	o = domObject( n );

	if ( opts ) {
		mode = opts.mode || mode;
		width = opts.width || width;
		height = opts.height || height;
		offset = opts.offset || offset;
		bgColor = opts.bgColor || bgColor;
		bgImage = opts.bgImage || bgImage;
		xOffset = opts.xOffset || xOffset;
		yOffset = opts.yOffset || yOffset;
		padding = opts.padding || padding;
		opacity = opts.opacity || opacity;
		shadow = opts.shadow == null ? shadow : opts.shadow;
	}

	if ( ! flag ) {
		if ( ! o ) {
			return;
		}

		if ( mode & DISP_ANIM_TOOLTIP ) {
			f = function( o ) {
				domDelete( o );
			};
			xlib.animateHeight( o, int( o.offsetHeight ) - ( borderWidth * 2 ), 1, opts, f );
		}
		else {
			domDelete( o );
		}

		return;
	}

	if ( o ) {
		o.style.zIndex = xWinZorder + 10000;
		return;
	}

	m = xlib.mousePos( e );
	m.x += xOffset;
	m.y += yOffset;

	o = domAdd( null, "div", n );
	o.className = "xTooltip";
	if ( this.IsIE ) {
		o.style.width = width;
		if ( height ) { o.style.height = height; }
	}
	else {
		o.style.width = width - ( ( padding + borderWidth ) * 2 );
		if ( height ) { o.style.height = height - ( ( padding + borderWidth ) * 2 ); }
	}

	o.style.left = xlib.winAdjustX( m.x + xlib.winScrollX( ), o.style.width, offset );
	o.style.top = m.y + xlib.winScrollY( );

	if ( opacity != null ) {
		xlib.fx.opacity( o.id, opacity );
	}
	else {
		if ( shadow ) { this.shadowSet( o ); }
	}
	domInnerHTML_set( o, content );

	if ( bgColor ) { o.style.background = bgColor; }
	if ( bgImage ) {
		o.style.background = "";
		o.style.border = "none";
		if ( xlib.pngfix && strati( ".png", bgImage ) ) {
			domImageSet( o, bgImage, 1 );
		}
		else {
			o.style.backgroundImage = "url(" + bgImage + ")";
		}
//		o.style.backgroundImage = "url(" + bgImage + ")";
	}
	o.style.padding = padding;
	o.style.zIndex = xWinZorder + 10000;

	xlib_PngFix( o );

	if ( mode & DISP_ANIM_TOOLTIP ) {
//		xlib.animateHeight( o, 1, int( o.offsetHeight ) - ( borderWidth * 2 ), opts );
		xlib.animateHeight( o, 1, xlib.winOffsetHeight( o, padding, borderWidth ), opts );
	}
	else {
		o.style.visibility = 'visible';
	}
};


xLibrary.prototype.browserNew = function( x, y, w, h, id, url, opts ) {
	var win;

	id = id || "_blank";
	opts = opts || "NORMAL";

	x = x < 0 ? ( screen.availWidth - w ) / 2 : x;
	y = y < 0 ? ( screen.availHeight - h ) / 2 : y;

	switch ( upper( opts ) ) {
  	  case "NORMAL":
		opts = "status=yes, location=yes, toolbar=yes, scrollbars=yes, menubar=yes, directories=yes, resizable=yes";
		break;
	  case "POPUP":
		opts = "status=no, location=no, toolbar=no, scrollbars=yes, menubar=no, directories=no, resizable=yes";
		break;
	  case "POPUP2":
		opts = "status=no, location=no, toolbar=no, scrollbars=yes, menubar=no, directories=no, resizable=no";
		break;
	}

	win = window.open( url, id, "left=" + x + ", top=" + y + ", width=" + w + ", height=" + h + " " + opts );
	if ( win ) { win.focus( ); }

  	return( win );
};


xLibrary.prototype.normalizeURL = function( url, isblank ) {
	var s;

	url = alltrim( url );
	if ( strempty( url ) ) {
		return( isblank ? "" : "/" );
	}

	if ( lower( left( url, 5 ) ) == "file:" ) {
		return( url );
	}

	if ( left( url, 1 ) == "/" ) {
		// relative address
		return( url );
	}
	url = strswap( url, "'", "" );
	url = strswap( url, "\"", "" );

	if ( lower( left( url, 4 ) ) != "http" ) {
		if ( ! strat( ".", url ) && ! strat( "localhost", url )) {
			url += ".com";
		}
		if ( lower( left( url, 3 ) ) != "www" ) {
			url = "http://www." + url;
		}
		else {
			url = "http://" + url;
		}
	}
	else if ( ! strat( ".", url ) && ! strat( "localhost", url )) {
		url += ".com";
	}

	s = strextract( url, "/", 3 );
	if ( chrcount( ".", s ) > 2 ) {
		url = strswap( url, "www.", "" );
	}

	return( url );
};

xLibrary.prototype.animateHeight = function( o, startH, endH, opts, cbFunc, NoHideScrollbars ) {
	var h;

	this.animateOptionsSet( o, opts );

	startH = int( startH );
	if ( startH < 1 ) {
		startH = 1;
	}
	endH = int( endH );
	if ( endH < 1 ) {
		endH = 1;
	}

	if ( o.objMoveFunc ) {
		xlib.intervalClear( o.objMoveFunc );
	}

	o._overflow = o.style.overflow;
	if ( ! NoHideScrollbars ) {
		o.style.overflow = "hidden";
	}

	o.style.height = startH;
	o.style.visibility = 'visible';
	o.curStep = 0;

	o.objMoveFunc = xlib.intervalSet(
		function( ) {
			h = easeInOut( startH, endH, o.animSteps, o.curStep, o.animPower );
			if ( h > 0 ) {
				o.style.height = h;
			}

			o.curStep++;
			if ( o.curStep > o.animSteps ) {
				xlib.intervalClear( o.objMoveFunc );
				o.objMoveFunc = null;
				o.style.overflow = o._overflow;

				if ( cbFunc ) {
					if ( typeof( cbFunc ) == "string" ) {
						eval( cbFunc );
					}
					else {
						cbFunc( o );
					}
				}
			}
		},
		o.animInterval );
};

xLibrary.prototype.dpConvertWindow = function( toType, data ) {
	var a, b, i, cnt, s="", n, v, typ;

	if ( toType & DP_QSTR ) {
		return( data );
	}

	a = data.split( "&" );
	cnt = len( a );
	if ( toType & DP_NAMEVALUE ) {
		for ( i=0; i<cnt; i++ ) {
			if ( a[i].length ) {
				s += a[i] + "\n";
			}
		}
	}
	else if ( toType & DP_JSON ) {
		s += "( {\r\n";
		for ( i=0; i<cnt; i++ ) {
			if ( ! a[i].length ) {
				continue;
			}
			b = a[i].split( "=" );
			if ( left( b[0], 1 ) == "$" ) {
				s += "  " + right( b[0], len( b[0] ) - 1 ) + ": " + ( strat( ".", b[1] ) ? parseFloat( b[1] ) : int( b[1] ) ) + ",\n";
			}
			else {
				s += "  " + b[0] + ": \"" + b[1] + "\",\n";
			}
		}
		if ( right( s, 2 ) == ",\n" ) {
			s = left( s, len( s ) - 2 ) + "\n";
		}
		s += "} );\r\n";
	}
	else if ( toType & DP_XML ) {
		s += "<OBJECT xmlns:xwin='http://www.xwinlib.com/schema' xwin:type='object' xwin:class='WINDOW'>\n";
		for ( i=0; i<cnt; i++ ) {
			if ( ! a[i].length ) {
				continue;
			}
			b = a[i].split( "=" );
			if ( left( b[0], 1 ) == "$" ) {
				n = right( b[0], len( b[0] ) - 1 );
				v = ( strat( ".", b[1] ) ? parseFloat( b[1] ) : int( b[1] ) );
				typ = strat( ".", b[1] ) ? "float" : "integer";
				s += "  <" + upper( n ) + " xwin:name='" + n + "' xwin:type='" + typ + "' xwin:len='" + len( v ) + "'>" + v + "</" + upper( n ) + ">\n";
			}
			else {
				s += "  <" + upper( b[0] ) + " xwin:name='" + b[0] + "' xwin:type='encString' xwin:len='" + len( b[1] ) + "'>" + b[1] + "</" + upper( b[0] ) + ">\n";
			}
		}
		if ( right( s, 2 ) == ",\n" ) {
			s = left( s, len( s ) - 2 ) + "\n";
		}
		s += "</OBJECT>\n";
	}

	return( s );
};

xLibrary.prototype.dpConvertDesktop = function( toType, data ) {
	var a, b, c, i, j, cnt, cnt2, s="", n, v, typ, x;

	if ( toType & DP_QSTR ) {
		return( data );
	}

	a = data.split( "\n" );
	cnt = len( a );
	if ( toType & DP_NAMEVALUE ) {
		for ( i=0; i<cnt; i++ ) {
			b = a[i].split( "&" );
			cnt2 = b.length;
			for ( j=0; j<cnt2; j++ ) {
				if ( b[j].length ) {
					s += b[j] + "\n";
				}
			}
		}
	}
	else if ( toType & DP_JSON ) {
		s += "( {\n";
		// desktop
		b = a[0].split( "&" );
		cnt2 = b.length;
		for ( j=0; j<cnt2; j++ ) {
			if ( ! b[j].length ) {
				continue;
			}

			c = b[j].split( "=" );
			x = strat( "_", c[0], 1 );
			if ( x ) { c[0] = right( c[0], len( c[0] ) - x ); }
			if ( left( c[0], 1 ) == "$" ) {
				n = right( c[0], len( c[0] ) - 1 );
				v = ( strat( ".", c[1] ) ? parseFloat( c[1] ) : int( c[1] ) );
				s += "  " + n + ": " + v + ",\n";
			}
			else {
				if ( ! int( c[0] ) ) {
					s += "  " + c[0] + ": \"" + c[1] + "\",\n";
				}
			}
		}
		// windows
		s += "  aWindows: [\n";
		for ( j=0; j<cnt2; j++ ) {
			if ( ! b[j].length ) {
				continue;
			}

			c = b[j].split( "=" );
			x = strat( "_", c[0], 1 );
			if ( x ) { c[0] = right( c[0], len( c[0] ) - x ); }
			if ( left( c[0], 1 ) != "$" ) {
				if ( int( c[0] ) ) {
					s += "    " + c[0] + ": \"" + c[1] + "\",\n";
				}
			}
		}
		if ( right( s, 2 ) == ",\n" ) {
			s = left( s, len( s ) - 2 ) + "\n";
		}
		s += "  ]\n";
		s += "} );\n";
	}
	else if ( toType & DP_XML ) {
		s += "<OBJECT xmlns:xwin='http://www.xwinlib.com/schema' xwin:type='object' xwin:class='DESKTOP'>\n";
		// desktop
		b = a[0].split( "&" );
		cnt2 = b.length;
		for ( j=0; j<cnt2; j++ ) {
			if ( ! b[j].length ) {
				continue;
			}

			c = b[j].split( "=" );
			x = strat( "_", c[0], 1 );
			if ( x ) { c[0] = right( c[0], len( c[0] ) - x ); }
			if ( left( c[0], 1 ) == "$" ) {
				n = right( c[0], len( c[0] ) - 1 );
				v = ( strat( ".", c[1] ) ? parseFloat( c[1] ) : int( c[1] ) );
				typ = strat( ".", c[1] ) ? "float" : "integer";
				s += "  <" + upper( n ) + " xwin:name='" + n + "' xwin:type='" + typ + "' xwin:len='" + len( v ) + "'>" + v + "</" + upper( n ) + ">\n";
			}
			else {
				if ( ! int( c[0] ) ) {
					s += "  <" + upper( c[0] ) + " xwin:name='" + c[0] + "' xwin:type='encString' xwin:len='" + len( c[1] ) + "'>" + c[1] + "</" + upper( c[0] ) + ">\n";
				}
			}
		}

		// windows
		s += "  <AWINDOWS xwin:type='variableArray'>\n";
		for ( j=0; j<cnt2; j++ ) {
			if ( ! b[j].length ) {
				continue;
			}

			c = b[j].split( "=" );
			x = strat( "_", c[0], 1 );
			if ( x ) { c[0] = right( c[0], len( c[0] ) - x ); }
			if ( left( c[0], 1 ) != "$" ) {
				if ( int( c[0] ) ) {
					s += "    <" + upper( c[0] ) + " xwin:name='" + c[0] + "' xwin:type='encString' xwin:len='" + len( c[1] ) + "'>" + c[1] + "</" + upper( c[0] ) + ">\n";
				}
			}
		}
		if ( right( s, 2 ) == ",\n" ) {
			s = left( s, len( s ) - 2 ) + "\n";
		}
		s += "  </AWINDOWS>\n";
		s += "</OBJECT>\n";
	}

	return( s );
};


////////////////////
// event functions
////////////////////

function xlibInitPage( ) {
	var o = xlib.eventBody( );

	if ( ! o ) {
		setTimeout( "xlibInitPage( )", 90 );
		return;
	}

	if ( ( xlib.startupOptions & XINIT_DESKTOP ) && ( xlib.startupOptions & XINIT_DESKTOPDROP ) ) {
		xlib.desktop.dropInit( );
	}
}



/////////////////
// edit function
/////////////////

function x_ie_editClearSelection( e ) {
	document.selection.empty();
}

function x_w3c_editClearSelection( e ) {
	if ( window.getSelection( ).removeAllRanges ) {
		// ff, opera
		window.getSelection( ).removeAllRanges( );
	}
	else if ( window.getSelection( ).collapse ) {
		// safari
		window.getSelection( ).collapse( );
	}
}


function xlibAjax( mtype, stype, page, params, cbFunc, opts ) {
	// mtype = method, AJAX_GET or AJAX_POST
	// stype = synch, AJAX_SYNCH, AJAX_ASYNCH
	// opts = { userid, password, aHeader[[name,val]] }
	if ( ! params ) {
		params = "";
	}
	else {
		if ( mtype == AJAX_GET ) {
			if ( left( params, 1 ) != "?" ) {
				params = "?" + params;
			}
		}
		else {
			if ( left( params, 1 ) == "?" ) {
				params = right( params, len( params ) -1 );
			}
		}
	}
	if ( stype == AJAX_ASYNCH ) {
		// sample callback: xlib_ajaxCallback( http )
		if ( mtype == AJAX_GET ) {
			xlib_ajaxGetPage( page, params, cbFunc, opts );
		}
		else {
			xlib_ajaxPostPage( page, params, cbFunc, opts );
		}
		return;
	}

	if ( mtype == AJAX_GET ) {
		return xlib_ajaxGetData( page, params, opts );
	}
	return xlib_ajaxPostData( page, params, opts );
}


function xlib_ajaxGetPage( page, params, cbFunc, opts ) {
	xmlhttp = xlib_ajaxInit( );
	if ( opts && opts.userid && opts.password ) {
		xmlhttp.open( 'GET', page + params, true, opts.userid, opts.password );
	}
	else {
		xmlhttp.open( 'GET', page + params, true );
	}
	xlib_setHeaders( xmlhttp, opts );

	xmlhttp.onreadystatechange = function( ) {
		if ( xmlhttp.readyState == 1 ) {
		}
		else if ( xmlhttp.readyState==4 ) {
			if ( cbFunc != null ) {
				cbFunc( xmlhttp );
			}
		}
	};
	xmlhttp.send( null );
	return;
}


function xlib_ajaxPostPage( page, data, cbFunc, opts ) {
	var doAsync = true;

	xmlhttp = xlib_ajaxInit( );
	if ( opts && opts.userid && opts.password ) {
		xmlhttp.open( 'POST', page, doAsync, opts.userid, opts.password );
	}
	else {
		xmlhttp.open( 'POST', page, doAsync );
	}
	xlib_setHeaders( xmlhttp, opts );

	xmlhttp.onreadystatechange = function( ) {
		if ( xmlhttp.readyState == 1 ) {
		}
		else if ( xmlhttp.readyState==4 ) {
			if ( cbFunc != null ) {
				cbFunc( xmlhttp );
			}
		}
	};
	xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" );
	xmlhttp.send( data );

	return;
}


function xlib_ajaxGetData( page, params, opts ) {
	// synchronously get web data
	var data;

	xmlhttp = xlib_ajaxInit( );
	if ( opts && opts.userid && opts.password ) {
		xmlhttp.open( 'GET', page + params, false, opts.userid, opts.password );
	}
	else {
		xmlhttp.open( 'GET', page + params, false );
	}
	xlib_setHeaders( xmlhttp, opts );
//alert( "a" );
	xmlhttp.onreadystatechange = function( ) {
		if ( xmlhttp.readyState == 1 ) {
		}
		else if ( xmlhttp.readyState==4 ) {
		}
	};
//alert( "b" );
	try {
		xmlhttp.send( null );
	} catch ( e ) {}
//alert( "c" );
	
	data = xmlhttp.responseText;
//alert( "d" );
	xmlhttp = null;

	return( data );
}


function xlib_ajaxPostData( page, params, opts ) {
	// synchronously post web data
	var data;

	xmlhttp = xlib_ajaxInit( );
	if ( opts && opts.userid && opts.password ) {
		xmlhttp.open( 'POST', page, false, opts.userid, opts.password );
	}
	else {
		xmlhttp.open( 'POST', page, false );
	}
	xlib_setHeaders( xmlhttp, opts );

	xmlhttp.onreadystatechange = function( ) {
		if ( xmlhttp.readyState == 1 ) {
		}
		else if ( xmlhttp.readyState==4 ) {
		}
	};
	xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" );

	try {
		xmlhttp.send( params );
	}
	catch( e ) {
		alert( "Error processing AJAX request. This may be caused by too much information on one page. You can try and consolidate objects or split the content accross multiple pages." );
		xmlhttp = null;
		return( "" );
	}

	data = xmlhttp.responseText;
	xmlhttp = null;

	return( data );
}


function xlib_ajaxInit( ) {
	var xmlhttp=false;

	try {
    	xmlhttp = new ActiveXObject( 'Msxml2.XMLHTTP' );
    }
    catch ( e ) {
    	try {
         	xmlhttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
    	}
    	catch ( er ) {
         	xmlhttp = false;
    	}
 	}

 	if ( ( ! xmlhttp ) && ( typeof( XMLHttpRequest ) !='undefined' ) ) {
     	xmlhttp = new XMLHttpRequest( );
	}
	return( xmlhttp );
}


function xlib_setHeaders( xmlhttp, opts ) {
	var cnt, i;

	if ( opts && opts.aHeader ) {
		cnt = len( aHeader );
		for ( i=0; i<cnt; i++ ) {
			xmlhttp.setRequestHeader( aHeader[i][0], aHeader[i][1] );
		}
	}
}


// sample callback
function xlib_ajaxCallback( http ) {
	var data = http.responseText;
	http = null;
}


function xlib_MenuProperties( w ) {
	this.win = w;
	this.adata = [];
	this.spacing = 0;
	this.padding = 3;
	this.classText = "xMenuText";
	this.classOn = "xMenuOn";
	this.classOff = "xMenuOff";
	this.isImages = 0;
	this.lineHeight = 22;
	this.borderHeight = w ? w.borderThickness( ) : 2;
	this.offset = 6;
	this.sideColor = "#ffc168";
	this.isSide = 1;
	this.separator = xWinImageDir + "/dotBlack.gif";
}

xlib_MenuProperties.prototype.add = function( title, img, action ) {
	this.adata[ this.adata.length ] = [ title, img, action ];
};

xlib_MenuProperties.prototype.calcHeight = function( ) {
	var a, i, t=( this.offset * 2 ) + ( this.borderHeight * 2 );

	a = this.adata;
	for ( i=0; i<len(a); i++ ) {
		if ( a[i][0] == "-" ) {
			t += ( ( this.spacing + this.padding ) * 2 ) + 1;
		}
		else {
			t += this.lineHeight;
		}
	}
	return( t );
};

xlib_MenuProperties.prototype.render = function( ) {
	var s="", i, cnt, a, img;

	s += "<table border=0 width=100% height=100% cellspacing=0 cellpadding=0 class='xMenuPlain'><tr>";
	if ( this.isSide ) {
		s += "<td width=15 class='xMenuPlain' style='background:" + this.sideColor + ";'>&nbsp;</td>";
	}
	s += "<td class='xMenuPlain' valign=top><table width=100% width=100% border=0 cellspacing=0 cellpadding=0 style='border:none;' class='xMenuPlain'><tr height=" + this.offset + "><td class='xMenuPlain'></td></tr><tr><td class='xMenuPlain'>";
	s += "<table border=0 width=100% width=100% cellspacing=" + this.spacing + " cellpadding=" + this.padding + " class='" + this.classOff + "' style='border:none;'>";
	a = this.adata;
	cnt = len( a );
	for ( i=0; i<cnt; i++ ) {
		if ( a[i][0] == "-" ) {
			s += "<tr height=1><td class='xMenuPlain' colspan=" + ( this.isImages ? 2 : 1 ) + "><img src='" + this.separator + "' border=0 width='100%' height='1'></td></tr>";
		}
		else {
			img = a[i][1].length ? "<img src='" + a[i][1] + "' border=0>" : "&nbsp;";
			if ( strempty( a[i][2] ) ) {
				s += "<tr height=" + this.lineHeight + " class='" + this.classText + "'>";
			}
			else {
				s += "<tr height=" + this.lineHeight + " onClick=\"" + a[i][2] + "; xlib.menuCurrentSet( );\" onmouseover=\"this.className='" + this.classOn + "'\" onmouseout=\"this.className='" + this.classOff + "'\">";
			}
			if ( this.isImages ) { s += "<td class='xMenuPlain' width=16 nowrap>" + img + "</td>"; }
			s += "<td class='xMenuPlain'>&nbsp;" + a[i][0] + "</td></tr>";
		}
	}
	s += "</table></td></tr>";
	s += "<tr height=" + this.offset + "><td class='xMenuPlain'></td></tr>";
	s += "</table></td></tr></table>";
	return( s );
};



function xlib_plugin( ) {
	this.action = null;
}


xlib_plugin.prototype = {

	init : function( ) {
		// initialize callback in plugin
        document.xlib_cbPlugin = function(obj, pos, data, title, oParentDocBodyId, e ) {

            function getBodyById (id) {
                var result = document.getElementById(id);

                if (result != null) {
                    return result;
                }

                var iframes = document.getElementsByTagName("iframe");

                if (iframes != null) {
                    for (var i = 0; i < iframes.length; i++) {

                        var fd = iframes[i].contentDocument;

                        var result = fd.getElementById(id);

                        if (result != null) {
                            return result;
                        }
                    }
                }

                var frames = document.getElementsByTagName("frame");

                if (frames != null) {
                    for (var i = 0; i < frames.length; i++) {

                        var fd = frames[i].contentDocument;

                        var result = fd.getElementById(id);

                        if (result != null) {
                            return result;
                        }
                    }
                }
            }

            var parentBody = getBodyById(oParentDocBodyId);
//            alert(oParentDocBodyId + " "+ parentBody);

			if ( obj != undefined ) {
				xlib.ffPlugin.action = obj;
			}
			else {
				if ( xlib.openajax && xlib.openajax.dndEnabled ) {
					xlib.openajax.publish( "xwinlib_dnd", "({ data : \"" + jsEncode( data ) + "\", pos : { x : " + pos.x + ", y : " + pos.y + " } })" );
				}
				else {
                    xlib.objFromData(data, pos, 0, null, 0, e, parentBody);
			}
		}
		};
	}
};


//////////////////////////
// 3rd Party Routines
//

// Generic Animation Step Value Generator: http://www.hesido.com
function easeInOut( minValue, maxValue, totalSteps, actualStep, powr ) {
	var delta = maxValue - minValue;
	var stepp = minValue + ( Math.pow( ( ( 1 / totalSteps ) * actualStep ), powr ) * delta );
	return Math.ceil( stepp );
}

// BrowserDetect from Quirksmode:  http://www.quirksmode.org/js/detect.html
var xEnvironment = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.userAgent,
			subString: "iPad",
			identity: "iPad",
			versionSearch: "Version"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};


//////////////////
// setSelectionRange and replaceSelection by Craig: http://www.standardscompliance.com/
// catchTab modified by SMR.

function setSelectionRange( input, selectionStart, selectionEnd ) {
  if (input.setSelectionRange) {
    input.focus();
    input.setSelectionRange(selectionStart, selectionEnd);
  }
  else if (input.createTextRange) {
    var range = input.createTextRange();
    range.collapse(true);
    range.moveEnd('character', selectionEnd);
    range.moveStart('character', selectionStart);
    range.select();
  }
}

function replaceSelection( input, replaceString ) {
	if (input.setSelectionRange) {
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd);

		if (selectionStart != selectionEnd){
			setSelectionRange(input, selectionStart, selectionStart + 	replaceString.length);
		}else{
			setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length);
		}

	}else if (document.selection) {
		var range = document.selection.createRange();

		if (range.parentElement() == input) {
			var isCollapsed = range.text == '';
			range.text = replaceString;

			 if (!isCollapsed)  {
				range.moveStart('character', -replaceString.length);
				range.select();
			}
		}
	}
}

function catchTab( e, obj, replaceStr ) {
	// onkeydown="return catchTab( xlib.eventGet( event ), this )" wrap="off"
	// note: must have ID and NAME defined!
	var k = xlib.eventKey( e );
	if ( k == KEY_TAB ){
		if ( replaceStr ) {
			replaceSelection( obj, replaceStr );
		}
		else {
			replaceSelection( obj, String.fromCharCode( KEY_TAB ) );
		}
		setTimeout( "domObject('" + obj.id + "').focus();", 0 );
		return false;
	}
}


/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function pad( str, num, pad, dir ) {		// http://www.sourcesnippets.com/javascript-string-pad.html
	// dir =
	//	STR_PAD_LEFT = 1;
	//	STR_PAD_RIGHT = 2;
	//	STR_PAD_BOTH = 3;
	if ( ! isvar(num) ) { num = 0; }
	if ( ! isvar(pad) ) { pad = ' '; }
	if ( ! isvar(dir) ) { dir = 2; }

	if (num + 1 >= str.length) {
		switch (dir){
			case 1:
			str = Array(num + 1 - str.length).join(pad) + str;
			break;

			case 3:
			var right = Math.ceil((padlen = num - str.length) / 2);
			var left = padlen - right;
			str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
			break;

			default:
			str = str + Array(num + 1 - str.length).join(pad);
			break;
 		}
	}
 	return str;
 }


//
// end: 3rd Party Routines
//////////////////////////////////



function xDesktop( ) {
	this.contextmenuHandler = null;
	this.gridSize = 10;
	this.gridBG = "";
	this.gridBGImage = xWinImageDir + "/grid.gif";
	this.gridRepeat = "";
}


xDesktop.prototype = {

	dropInit: function( ) {
		xlib.eventBind( xlib.eventBody( ), "dragenter", xWinEvent_Cancel, false );
		xlib.eventBind( xlib.eventBody( ), "dragover", xWinEvent_Cancel, false );
//		if ( xlib.IsIE ) {
		if ( ! xlib.IsFF ) {
			xlib.eventBind( xlib.eventBody( ), "drop", xWinEvent_Drop, true );
		}
		else {
			// only initialize if top level
			if ( xlib.IsFF ) {
				try {
//					if ( top.location.href == window.location.href ) {
						xlib.ffPlugin = new xlib_plugin( );
						xlib.ffPlugin.init( );

						// see if plugin is present
						obj = document.createElement('img');
						obj.id = "ffplugin_img";
						obj.src = "chrome://xwinlib/content/ico_favicon.gif";
						obj.style.position = 'absolute';
						obj.style.top = '0px';
						obj.style.left = '0px';
						obj.style.visibility = 'hidden';
						document.body.appendChild( obj );
						xlib.eventBind( obj, "load", function() { xlib.IsFF_Plugin=1; domDelete( this ); }, true );
//					}
				} catch ( e ) { };
			}
		}
	},

	bgSet: function( img, clr, tiled, centered, scrollable, bgpos ) {
		document.body.background = "";
		if ( img !== null ) {
			try {
				document.body.style.backgroundImage = "url(" + img + ")";
			}
			catch ( e ) {
				document.body.style.backgroundImage = "";
			}
		}
		if ( clr !== null ) {
			document.body.style.backgroundColor = clr;
		}
		if ( tiled !== null ) {
			document.body.style.backgroundRepeat = tiled ? "repeat" : "no-repeat";
		}
		else {
			document.body.style.backgroundRepeat = "repeat";
		}
		if ( centered !== null ) {
			document.body.style.backgroundPosition = centered ? "center" : "0px 0px";
			document.body.style.backgroundAttachment = "fixed";
		}
		if ( scrollable !== null ) {
			document.body.style.backgroundAttachment = scrollable ? "scroll" : "fixed";
		}
		document.body.style.backgroundPosition = strempty( bgpos ) ? "" : bgpos;
		xlib.UpdateFlag( 1 );
	},

	gridSet: function( ) {
		this.gridBG = document.body.style.backgroundImage;
		this.gridRepeat = document.body.style.backgroundRepeat;
		document.body.style.backgroundImage = "url(" + this.gridBGImage + ")";
		document.body.style.backgroundRepeat = "repeat";
		return( 1 );
	},

	gridRestore: function( ) {
		document.body.style.backgroundImage = this.gridBG;
		document.body.style.backgroundRepeat = this.gridRepeat;
		this.gridBG = "";
		this.gridRepeat = "";
		return( 0 );
	},

	save: function( mode ) {
		var cnt, i, s="", w, x, y, a, bd;

		cnt = xWinList.length;

		if ( mode & DESKTOP_LAYOUT ) {
			// returns positioning data for all windows
			// name, x, y, w, h, z, dispMode
			for ( i=1; i<cnt; i++ ) {
				w = xWinList[i];

				if ( w.issys && ( ! ( mode & DESKTOP_INCLUDESYS ) ) ) {
					continue;
				}

				if ( w.displayMode & DISP_CENTERED ) {
					x = int( w.obj.style.left ); y = int( w.obj.style.top );
				}
				else {
					x = w.left; y = w.top;
				}
				s += w.name + "," + x + "," + y + "," + w.width + "," + w.height + "," + w.zorder + "," + w.displayMode + ";";
			}
		}
		else if ( mode & DESKTOP_OBJECTS ) {
			// returns an array of all window objects
			a = [];
			for ( i=1; i<cnt; i++ ) {
				if ( xWinList[i].issys && ( ! ( mode & DESKTOP_INCLUDESYS ) ) ) {
					continue;
				}
				a[a.length] = xWinList[i];
			}
			return( a );
		}
		else if ( mode & DESKTOP_OBJMOVE ) {
			// returns an array of all window objects + positioning info
			// ??
			a = [];
			for ( i=1; i<cnt; i++ ) {
				if ( xWinList[i].issys && ( ! ( mode & DESKTOP_INCLUDESYS ) ) ) {
					continue;
				}
				a[a.length] = xWinList[i];
			}
			return( a );
		}
		else {
			// desktop config
			bd = xlib.eventBody( );
			s += "desktop_className=" + bd.className + "&";
			s += "desktop_bgColor=" + bd.style.backgroundColor + "&";
			s += "desktop_background=" + jsEncode( bd.style.backgroundImage ) + "&";
			// style attribs:
			s += "desktop_overflow=" + bd.style.overflow + "&";
			s += "desktop_backgroundAttachment=" + bd.style.backgroundAttachment + "&";
			s += "desktop_backgroundRepeat=" + bd.style.backgroundRepeat + "&";
			s += "desktop_backgroundPosition=" + bd.style.backgroundPosition;

			a = xlib.winSortedArray( );
			cnt = len( a );

			// packed string of all window data
			for ( i=0; i<cnt; i++ ) {
				if ( a[i].issys && ( ! ( mode & DESKTOP_INCLUDESYS ) ) ) {
					continue;
				}
				s += "&xwin_" + i + "=" + jsEncode( a[i].pack( ) );
			}
		}

		return( s );
	},

	winMove: function( data, mode, opts ) {
		// data = xlib.desktop.save( DESKTOP_LAYOUT )
		// opts = params object
		var a, b, cnt, i, w, xOffset, yOffset;
		var aW, ndx, max, achild, wcnt, j, w2;

		mode = mode ? mode : MOVE_INSTANT;
		isSave = mode & MOVE_SAVEPOS;

		a = data.split( ";" );
		cnt = len( a );

		// check for WS_MAGNETIC objects
		for ( i=0; i<cnt; i++ ) {
			if ( ! a[i].length ) {
				continue;
			}
			b = a[i].split( "," );
			w = xWinFromName( b[0] );
			if ( ( ! w ) || ( ! ( w.style & WS_MAGNETIC ) ) ) {
				continue;
			}
			achild = w.getMagneticChildren( );
			wcnt = achild.length;

			xOffset = w.left - b[1];
			yOffset = w.top - b[2];

			for ( j=0; j<wcnt; j++ ) {
				w2 = achild[j]
				a[len(a)] = w2.name + "," + ( w2.left - xOffset ) + "," + ( w2.top - yOffset ) + "," + w2.width + "," + w2.height + "," + ( w.zorder + 2 + i ) + "," + w2.displayMode;

			}
		}
		cnt = len( a );

		if ( mode & MOVE_INSTANT ) {
			max = 0;
			for ( i=0; i<cnt; i++ ) {
				if ( ! a[i].length ) {
					continue;
				}
				b = a[i].split( "," );
				w = xWinFromName( b[0] );
				if ( w ) {
					//w.bringtotop( );
					if ( mode & MOVE_NORESIZE ) {
						w.obj.style.left = b[1];
						w.obj.style.top = b[2];
						if ( isSave ) {
							w.left = b[1];
							w.top = b[2]
						}
					}
					else {
						w.positionDivs( b[1], b[2], b[3], b[4] );
						//w.obj.style.zIndex = w.zorder = w.zIndexGet( );
					}
					if ( w.style & WS_ALWAYSONTOP ) {
						w.obj.style.zIndex = w.zIndexGet( );
					}
					else {
						try {
							w.obj.style.zIndex = w.zorder = int( b[5] ) + 2 + ( i * 2 );
						} catch(e){}

						if ( w.zorder > max ) {
							max = w.zorder;
						}
					}
				}
			}
			if ( max ) {
				xWinZorder = max + 2;
			}
			return;
		}
		else if ( mode & MOVE_ANIMATE ) {
			aW = [];		// owin, [sX,eX], [sY,eY], [sW,eW], [sH,eW]

			max = 0;
			for ( i=0; i<cnt; i++ ) {
				if ( ! a[i].length ) {
					continue;
				}
				b = a[i].split( "," );
				w = xWinFromName( b[0] );
				if ( w ) {
					aW[aW.length] = {
						win: w,
						sX: int( w.obj.style.left ), 	eX: int( b[1] ),
						sY: int( w.obj.style.top ), 	eY: int( b[2] ),
						sW: int( w.obj.style.width ), 	eW: int( b[3] ),
						sH: int( w.obj.style.height ), eH: int( b[4] )
					};
					if ( w.style & WS_ALWAYSONTOP ) {
						w.obj.style.zIndex = w.zIndexGet( );
					}
					else {
						try {
							w.obj.style.zIndex = w.zorder = int( b[5] ) + 2 + ( i * 2 );
						} catch (e) {}
						if ( w.zorder > max ) {
							max = w.zorder;
						}
					}
				}
			}
			if ( max ) {
				xWinZorder = max + 2;
			}

			w = aW[0].win;

			if ( w.obj.winMoveFunc ) {
				xlib.intervalClear( w.obj.winMoveFunc );
//				xlib.intervalClear( w.winMoveFunc );
			}
			w.obj.curStep = 0;
			w.obj.isSave = isSave;

			xlib.animateOptionsSet( w.obj, opts );

			w.obj.winMoveFunc = xlib.intervalSet(
				function( ) {
					var i, ptPos, ptSize;
					for ( i=0; i<aW.length; i++ ) {

//						if ( ( aW[i].sX == aW[i].eX ) && ( aW[i].sY == aW[i].eY ) &&
//							( aW[i].sW == aW[i].eW ) && ( aW[i].sH && aW[i].eH ) ) {
//							continue;
//						}

						ptPos = [
							easeInOut( aW[i].sX, aW[i].eX, w.obj.animSteps, w.obj.curStep, w.obj.animPower ),
							easeInOut( aW[i].sY, aW[i].eY, w.obj.animSteps, w.obj.curStep, w.obj.animPower )
						];

						if ( mode & MOVE_NORESIZE ) {
							aW[i].win.obj.style.left = ptPos[0];
							aW[i].win.obj.style.top = ptPos[1];
						}
						else {
							ptSize = [
								easeInOut( aW[i].sW, aW[i].eW, w.obj.animSteps, w.obj.curStep, w.obj.animPower ),
								easeInOut( aW[i].sH, aW[i].eH, w.obj.animSteps, w.obj.curStep, w.obj.animPower )
							];

							aW[i].win.position( ptPos[0], ptPos[1], ptSize[0], ptSize[1] );
						}
						//aW[i].win.obj.style.zIndex = aW[i].win.zorder = aW[i].win.zIndexGet( );
					}

					w.obj.curStep++;
					if ( w.obj.curStep > w.obj.animSteps ) {

						if ( w.obj.isSave ) {
							for ( i=0; i<aW.length; i++ ) {
								aW[i].win.left = int( aW[i].win.obj.style.left );
								aW[i].win.top = int( aW[i].win.obj.style.top );
								aW[i].win.width = int( aW[i].win.obj.style.width );
								aW[i].win.height = int( aW[i].win.obj.style.height );
							}
						}

						xlib.intervalClear( w.obj.winMoveFunc );
						w.obj.winMoveFunc = null;
					}
				},
				w.obj.animInterval );
		}
	},

	scrollTo: function( x, y, mode ) {
		window.scrollTo( x, y );
	}
};


function xFx( ) {
	this.id = "fx";

this.cnt=0;
}

xFx.prototype = {

	bgFade: function( obj, clrStart, clrEnd, steps, delay ) {
		if ( ! obj ) {
			obj = document;
		}

		if ( obj.fadeFunc ) {
			xlib.intervalClear( obj.fadeFunc );
		}

		obj.fade = {
			curstep: 0,
			steps: steps,
			delay: delay,
			red: [ hex2dec( substr( clrStart, 1, 2 ) ), hex2dec( substr( clrEnd, 1, 2 ) ) ],
			green: [ hex2dec( substr( clrStart, 3, 2 ) ), hex2dec( substr( clrEnd, 3, 2 ) ) ],
			blue: [ hex2dec( substr( clrStart, 5, 2 ) ), hex2dec( substr( clrEnd, 5, 2 ) ) ]
		};

		obj.fadeFunc = xlib.intervalSet(
			function( ) {
				var int1, int2, r, g, b, clr;

				int1 = ( obj.fade.steps - obj.fade.curstep ) / obj.fade.steps;
				int2 = obj.fade.curstep / obj.fade.steps;

				r = Math.floor( ( obj.fade.red[0] * int1 ) + ( obj.fade.red[1] * int2 ) );
				g = Math.floor( ( obj.fade.green[0] * int1 ) + ( obj.fade.green[1] * int2 ) );
				b = Math.floor( ( obj.fade.blue[0] * int1 ) + ( obj.fade.blue[1] * int2 ) );

				clr = dec2hex( r, 2 ) + dec2hex( g, 2 ) + dec2hex( b, 2 );

				obj.bgColor = "#" + clr;

				obj.fade.curstep++;
				if ( obj.fade.curstep > obj.fade.steps ) {
					xlib.intervalClear( obj.fadeFunc );
					obj.fadeFunc = null;
				}
			},
			obj.fade.delay );
	},


	opacity: function( id, val ) {
		// accepts dom element, val=0-10
		var o = ( typeof( id ) == "string" ) ? domObject( id ) : id;

		if ( xlib.IsIE ) {
			if ( val == 10 ) {
				o.style.filter = null;
			}
			else {
				o.style.filter = 'alpha(opacity=' + ( val * 10 ) + ')';
			}
		}
		else {
			o.style.opacity = val / 10;
		}
	},

	opacityFade: function ( id, opts, val ) {
		var mode=DISP_FADE_IN, delay=50, cbFunc=null, i, name;

		if ( typeof( id ) != "string" ) {
			if ( id.sig	== XLIB_SIG ) {
				name = id.name;
				id = id.obj.id;
			}
			else {
				id = name = id.id;
			}
		}
		else {
			name = id;
		}

		if ( opts ) {
			if ( typeof( opts ) == "number" ) {
				mode = opts;
			}
			else {
				mode = opts.mode || mode;
				delay = opts.delay || delay;
				cbFunc = opts.cbFunc || cbFunc;
			}
		}

		if ( mode & DISP_FADE_IN ) {
			val = val == null ? 10 : val;
			for ( i=0; i<=val; i++ ) {
				setTimeout( "xlib.fx.opacity( '" + id + "', " + i + " )", delay * i );
			}
		}
		else if ( mode & DISP_FADE_OUT ) {
			val = val == null ? 0 : val;
			for ( i=10; i>=val; i-- ) {
				setTimeout( "xlib.fx.opacity( '" + id + "', " + i + " )", delay * ( 11 - i ) );
			}
		}
		if ( cbFunc ) {
			cbFunc( name );
		}

	},


	typewriter: function( o, text, opts ) {
		var delay=50;

		if ( typeof( o ) == "string" ) { o = domObject( o ); }
		if ( ! o ) { return; }

		if ( opts ) {
			delay = opts.delay ? opts.delay : delay;
		}

		if ( o.fxTypeFunc ) {
			xlib.intervalClear( o.fxTypeFunc );
		}
		o.fxTypeDelay = delay;
		o.fxTypeStep = 0;
		o.fxTypeText = text;

		o.fxTypeFunc = xlib.intervalSet(
			function( ) {
				if ( substr( text, o.fxTypeStep, 1 ) == "<" ) {
					o.fxTypeStep += strat( ">", right( text, len( text ) - o.fxTypeStep ) );
				}
				domInnerHTML_set( o, left( text, o.fxTypeStep ) );
				o.fxTypeStep++;
				if ( o.fxTypeStep > o.fxTypeText.length ) {
					xlib.intervalClear( o.fxTypeFunc );
					o.fxTypeFunc = null;
				}

			}, o.fxTypeDelay );
	}

};




function xWinFont( opts ) {

	this.measure = "pt";

	if ( ! opts ) {
		this.classname = null;
		this.name = null;
		this.size = null;
		this.color = null;
		this.bgColor = null;
		this.weight = null;
		this.decoration = null;
		this.align = null;
		this.valign = null;
		this.lineheight = null;
		return;
	}
	this.classname = opts.classname || "smtxt";
	this.name = opts.name || null;
	this.size = opts.size || null;
	this.color = opts.color || null;
	this.bgColor = opts.bgColor || null;
	this.weight = opts.weight || null;
	this.decoration = opts.decoration || null;
	this.align = opts.align || null;
	this.valign = opts.valign || null;
	this.lineheight = opts.lineheight || null;
}

xWinFont.prototype.init = function( ) {
	this.classname = null;
	this.name = null;
	this.size = null;
	this.color = null;
	this.bgColor = null;
	this.weight = null;
	this.decoration = null;
	this.align = null;
	this.valign = null;
	this.lineheight = null;
};

xWinFont.prototype.loadFromStyle = function( style ) {
	var a, i, cnt, name, val;

	this.init( );

	a = style.split( ";" );
	cnt = len( a );
	for ( i=0; i<cnt; i++ ) {
		name = lower( alltrim( strextract( a[i], ":", 1 ) ) );
		val = alltrim( strextract( a[i], ":", 2 ) );

		switch ( name ) {
		  case "classname":
		  	this.classname = val;
		  	break;
		  case "font-family":
		  	this.name = val;
		  	break;
		  case "font-size":
		  	this.size = val;
		  	this.size = strswap( this.size, "pt", "" );
		  	this.size = strswap( this.size, "px", "" );
		  	break;
		  case "font-weight":
		  	this.weight = val;
		  	break;
		  case "font-style":
		  	this.decoration = val;
		  	break;
		  case "text-decoration":
		  	if ( lower( this.decoration ) != "italic" ) {
		  		this.decoration = val;
		  	}
		  	break;
		  case "color":
		  	this.color = val;
		  	break;
		  case "background":
		  	this.background = val;
		  	break;
		  case "text-align":
		  	this.align = val;
		  	break;
		  case "text-valign":
		  	this.valign = val;
		  	break;
		  case "valign":
		  	this.valign = val;
		  	break;
		  case "line-height":
		  	this.lineheight = val;
		  	break;
		}
	}
};

xWinFont.prototype.render = function( text ) {
	var s = "";

	if ( this.valign ) {
		s += "<table border=0 cellspacing=0 cellpadding=0 width=100% height=100% class='" + this.classname + " xNoBorder' style='border:none;'><tr valign='" + this.valign + "'><td align='" + this.align + "'>";
	}

	s += "<font ";
	if ( this.classname ) {
		s += "class='" + this.classname + "' ";
	}

	s += "style='";
	if ( this.align ) {
		s += "text-align:" + this.align + "; ";
	}
	if ( this.name ) {
		s += "font-family:" + this.name + "; ";
	}
	if ( this.size ) {
		s += "font-size:" + this.size + this.measure + "; ";
	}
	if ( this.color ) {
		s += "color:" + this.color + "; ";
	}
	if ( this.bgColor ) {
		s += "background:" + this.bgColor + "; ";
	}
	if ( this.weight ) {
		s += "font-weight:" + this.weight + "; ";
	}
	if ( this.lineheight ) {
		s += "line-height:" + this.lineheight + "; ";
	}
	if ( this.decoration ) {
		if ( strati( "PLAIN", this.decoration ) ) {
			s += "text-decoration:none; ";
		}
		else if ( strati( "ITALIC", this.decoration ) ) {
			s += "font-style:" + this.decoration + "; ";
			s += "text-decoration:none; ";
		}
		else {
			s += "text-decoration:" + this.decoration + "; ";
		}
	}

	s += "'>" + text + "</font>";

	if ( this.valign ) {
		s += "</td></tr></table>";
	}

	return( s );
};

function datej( dte ) {
	var a, year, month, day, Y, M, D, A, B, C, E, F;

	if ( ! dte ) {
		dte = new Date( );
	}
	else if ( typeof( dte ) == "string" ) {
		// format: MM-DD-YYYY
		a = dte.split( "-" );
		dte = new Date( int( a[2] ), int( a[0] ) - 1, int( a[1] ) );
	}

	// http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html
	Y = dte.getFullYear( );
	M = dte.getMonth( );
	D = dte.getDate( );

	A = Math.floor(Y/100);
	B = Math.floor(A/4);
	C = 2 - A + B;
	C=0;

	E = Math.floor(365.25*(Y + 4716));

	F = Math.floor(30.6001*(M + 1));

	return( int( C + D + E + F - 1524.5 ) );
}

function dateFormatj( dte, formatstr ) {
	var year, day, dte, xdte;
	var Z, F, W, X, A, B, C, D, E;

	if ( ! formatstr ) {
		formatstr = "MM-DD-YYYY";
	}

	// http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html
	Z = dte+0.5;
	F = Z - Math.floor(Z);

	Z = Math.floor(Z);
	W = Math.floor((Z - 1867216.25)/36524.25);
	X = Math.floor(W/4);
	A = Z;

	B = A + 1524;
	C = Math.floor((B - 122.1)/365.25);
	D = Math.floor(365.25*C);
	E = Math.floor((B - D)/30.6001);

	month = E>13? E-13: E-1;
	day = B - D - Math.floor(30.6001*E) +F;
	year = month<3? C-4715: C-4716;

	dte = new Date(year, month, day+1);

	xdte = new xDate( dte );

	return( xdte.format( formatstr ) );
}

function xDate( dte ) {
	var a;

	if ( ! dte ) {
		dte = new Date( );
	}
	else if ( typeof( dte ) == "string" ) {
		// format: MM-DD-YYYY
		a = dte.split( "-" );
		dte = new Date( int( a[2] ), int( a[0] ) - 1, int( a[1] ) );
	}
	this.date = dte;
	this.aMonth = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
	this.aDay = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
}

xDate.prototype.diff = function( d1, d2, t ) {
	var d, w, dy, h, m, s;

	d = new Date();

	if ( ! t ) {
		try {
			d.setTime( Math.abs( d1.getTime( ) - d2.getTime( ) ) );
			t = d.getTime();
		}
		catch ( e ) {
			return( "00" );
		}
	}

	w = Math.floor( t / ( 1000 * 60 * 60 * 24 * 7 ) );
	t -= w * ( 1000 * 60 * 60 * 24 * 7 );

	dy = Math.floor( t / ( 1000 * 60 * 60 * 24 ) );
	t -= dy * ( 1000 * 60 * 60 * 24 );

	h = Math.floor( t / ( 1000 * 60 * 60 ) );
	t -= h * ( 1000 * 60 * 60 );

	m = Math.floor( t / ( 1000 * 60 ) );
	t -= m * ( 1000 * 60 );

	s = Math.floor( t / 1000 );
	t -= s * 1000;

	return( right( "00" + ( dy + ( w * 7 ) ), 2 ) + ":" + right( "00" + h, 2 ) + ":" + right( "00" + m, 2 ) + ":" + right( "00" + s , 2 ) );
};

xDate.prototype.format = function( fstr ) {
	// date:
	// mm   = month as "1"					dd   = day as "1"			YY   = day as "01"
	// MM   = month as "01"					DD   = day as "01"			YYYY = day as "2001"
	// MMM  = month as "Jan"				DDD  = day as "1st"
	// MMMM = month as "January"			DDDD = day as "Saturday"

	// time:
	// hh   = hour as "05" (12-hour clock)	MN = minutes as "01"		ap   = am/pm as "am"
	// HH   = hour as "17" (24-hour clock)	SS = seconds as "01"		AP   = am/pm as "AM"
	//										SSSS = milliseconds as "0001"
	// TZ   = timezone, GMT offset

	var d = this.date, mo, da, yr, hr;

	fstr = fstr || "MM-DD-YYYY hh:MN:SS ap";

	mo = d.getMonth( );
	if ( strat( "MMMM", fstr ) ) { fstr = strswap( fstr, "MMMM", this.aMonth[ mo ] ); }
	if ( strat( "MMM", fstr ) ) { fstr = strswap( fstr, "MMM", left( this.aMonth[ mo ], 3 ) ); }
	if ( strat( "MM", fstr ) ) { fstr = strswap( fstr, "MM", right( "0" + ( mo + 1 ), 2 ) ); }
	if ( strat( "mm", fstr ) ) { fstr = strswap( fstr, "mm", mo + 1 ); }

	da = d.getDate( );
	if ( strat( "DDDD", fstr ) ) { fstr = strswap( fstr, "DDDD", this.aDay[ d.getDay( ) ] ); }
	if ( strat( "DDD", fstr ) ) { fstr = strswap( fstr, "DDD", numFormat( da, FORMAT_SUFFIX ) ); }
	if ( strat( "DD", fstr ) ) { fstr = strswap( fstr, "DD", right( "0" + da, 2 ) ); }
	if ( strat( "dd", fstr ) ) { fstr = strswap( fstr, "dd", da ); }

	yr = d.getFullYear( );
	if ( strat( "YYYY", fstr ) ) { fstr = strswap( fstr, "YYYY", yr ); }
	if ( strat( "YY", fstr ) ) { fstr = strswap( fstr, "YY", right( yr, 2 ) ); }

	hr = d.getHours( );
	if ( strat( "HH", fstr ) ) { fstr = strswap( fstr, "HH", right( "0" + hr, 2 ) ); }
	if ( strat( "hh", fstr ) ) { fstr = strswap( fstr, "hh", right( "0" + ( hr > 12 ? hr - 12 : hr ), 2 ) ); }

	if ( strat( "MN", fstr ) ) { fstr = strswap( fstr, "MN", right( "0" + d.getMinutes( ), 2 ) ); }
	if ( strat( "SSSS", fstr ) ) { fstr = strswap( fstr, "SSSS", right( "000" + d.getMilliseconds( ), 4 ) ); }
	if ( strat( "SS", fstr ) ) { fstr = strswap( fstr, "SS", right( "0" + d.getSeconds( ), 2 ) ); }

	if ( strat( "AP", fstr ) ) { fstr = strswap( fstr, "AP", hr > 11 && hr < 24 ? "PM" : "AM" ); }
	if ( strat( "ap", fstr ) ) { fstr = strswap( fstr, "ap", hr > 11 && hr < 24 ? "pm" : "pm" ); }

	if ( strat( "TZ", fstr ) ) { fstr = strswap( fstr, "TZ", "" + ( d.getTimezoneOffset()/60 * (-1) ) ); }

	return( fstr );
};

function oaInterface( ) {

	this.version 		= "1.0";

	this.ID_CREATE		= 1;
	this.ID_DESTROY		= 2;
	this.ID_DISPLAY		= 4;
	this.ID_CLICK		= 8;
	this.ID_DBLCLICK	= 16;
	this.ID_DRAG		= 32;
	this.ID_DROP		= 64;
	this.ID_TIMER		= 128;
	this.ID_MOUSEOVER	= 256;
	this.ID_MOUSEOUT	= 512;
	this.ID_KEYDOWN		= 1024;
	this.ID_KEYUP		= 2048;
	this.ID_KEYPRESS	= 4096;
	this.ID_WINMOVE		= 8192;
	this.ID_WINSIZE		= 16384;
	this.ID_MESSAGE		= 32768;

	this.ID_INTERNALHANDLER	= 65536;

	this.KEY_ALT			= 1;
	this.KEY_CTRL			= 2;
	this.KEY_SHIFT			= 4;

	this.MOUSE_BUTTONLEFT   = 1;
	this.MOUSE_BUTTONCENTER = 2;
	this.MOUSE_BUTTONRIGHT  = 4;

	this.aServices = [];			// (str) sid, (str) desc, (int) opts
	this.adataServices = [];		// (obj) OpenAjaxInterface_service
	this.aSubscriptions = [];		// (int) handle, (str) sid, (str) data
	this.adataSubscriptions = [];	// (obj) OpenAjaxInterface_subscribe

	this.cbPublishAll = null;		// used to tap into the publish stream

	this.dndEnabled = 0;
	this.msgCnt = 0;

	this.aEvents = [ "CREATE", "DESTROY", "DISPLAY", "CLICK", "DBLCLICK", "DRAG", "DROP", "TIMER", "MOUSEOVER", "MOUSEOUT", "KEYDOWN", "KEYUP", "KEYPRESS", "WINMOVE", "WINSIZE" ];

	try {
		this.common = OpenAjax;
		this.init( );
	} catch ( e ) {}

}

	oaInterface.prototype.init = function( ) {
		this.common.hub.registerLibrary( "xWinLib", "http://www.xwinlib.com/OpenAjaxHub", "1.0", {} );
	};

	oaInterface.prototype.getServices = function( data ) {
		var a, b, i, cnt

		this.adataServices = [];

		if ( strempty( data ) ) {
			return( 0 );
		}

		a = data.split( ";" );
		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			b = a[i].split( "|" );
			this.adataServices[ len( this.adataServices ) ] = new OpenAjaxInterface_service( b[0], b[1], b[2], b[3] );
		}

		return( 1 );
	};

	oaInterface.prototype.putServices = function( ) {
		var a, cnt, i, s="";

		a = this.adataServices;
		cnt = len( a );
		if ( ! cnt ) {
			return( "" );
		}
		for ( i=0; i<cnt; i++ ) {
			s += "" + a[i].status + "|" + a[i].sid + "|" + a[i].desc + "|" + a[i].opts + ";";
		}
		s = left( s, len( s ) - 1 );

		return( s );
	};

	oaInterface.prototype.getSubscriptions = function( data ) {
		var a, b, i, cnt

		this.adataSubscriptions = [];

		if ( strempty( data ) ) {
			return( 0 );
		}

		a = data.split( ";" );
		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			b = a[i].split( "|" );
			this.adataSubscriptions[ len( this.adataSubscriptions ) ] = new OpenAjaxInterface_subscribe( b[0], b[1], b[2], b[3], b[4], b[5], b[6] );
		}

		return( 1 );
	};

	oaInterface.prototype.registerService = function( sid, desc, opts ) {
		var x = this.aIndex( this.aServices, sid )
		if ( x >= 0 ) {
			this.aServices[ x ] = [ sid, desc, this.aServices[ x ][1] |= opts ];
			return( 1 );
		}
		this.aServices[ len( this.aServices ) ] = [ sid, desc, opts ];
		return( 1 );
	};

	oaInterface.prototype.objRegisterServices = function( data ) {
		var a, i, cnt, rval=null;
		if ( typeof( data ) == "array" ) {
			this.adataServices = data;
		}
		else {
			this.getServices( data );
		}
		a = this.adataServices;
		cnt = len( a );	if ( cnt > 1 ) { cnt = 1; }	// limit to one
		for ( i=0; i<cnt; i++ ) {
			if ( a[i].status == 1 ) { 	// active
				this.registerService( a[i].sid, a[i].desc, a[i].opts );
				rval = { sid : a[i].sid, opts : a[i].opts };
			}
		}
		return( rval );	// returns { sid, opts } for default service
	};

	oaInterface.prototype.unregisterService = function( sid ) {
		var index = this.aIndex( this.aServices, sid );
		if ( index < 0 ) {
			return( 0 );
		}
		this.aServices = this.aIndexDelete( this.aServices, index );
		return( 1 );
	};

	oaInterface.prototype.aIndex = function( a, val, col ) {
		var cnt, i;

		if ( col == null ) {
			col = 0;
		}
		val = lower( val );

		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			if ( lower( a[i][col] ) == val ) {
				return( i );
			}
		}
		return( -1 );
	};

	oaInterface.prototype.aIndexDelete = function( a, index ) {
		var cnt, i, b=[];

		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			if ( i == index ) {
				continue
			}
			b[ len(b) ] = a[i];
		}
		return( b );
	};

	oaInterface.prototype.aLibraries = function( ) {
		var n, o, a = [];
		for ( n in this.common.hub.libraries ) {
			o = this.common.hub.libraries[n];
			a[ len(a) ] = { prefix : n, namespaceURI : o.namespaceURI, version : o.version, extra : o.extra };
		}
		return( a );
	};

	oaInterface.prototype.subscribe = function( sid, cb, scope, data, filter ) {
		var h = this.common.hub.x_subscribe( sid, cb, scope, data, filter )
		if ( this.aIndex( this.aSubscriptions, h ) < 0 ) {
			this.aSubscriptions[ len( this.aSubscriptions ) ] = [ h, sid, data ];
		}
		return( h );
	};

	oaInterface.prototype.unsubscribe = function( h ) {
		var index = this.aIndex( this.aSubscriptions, h );
		if ( index > -1 ) {
			this.aSubscriptions = this.aIndexDelete( this.aSubscriptions, h );
		}
		return( this.common.hub.x_unsubscribe( h ) );
	};

	oaInterface.prototype.libraryList = function( lf ) {
		var a, cnt, i, o, s="";
		lf = lf || "<br>";
		a = this.aLibraries( );
		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			o = a[i];
			s += o.prefix + ", " + o.namespaceURI + ", " + o.version + lf;
		}
		return( s );
	};

	oaInterface.prototype.subscriptionList = function( lf ) {
		var a, cnt, i, o, s="";
		lf = lf || "<br>";
		a = this.aSubscriptions;
		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			s += "" + a[i][0] + ", " + a[i][1] + ", " + a[i][2] + lf;
		}
		return( s );
	};

	oaInterface.prototype.serviceList = function( lf ) {
		var a, cnt, i, o, s="";
		lf = lf || "<br>";
		a = this.aServices;
		cnt = len( a );
		for ( i=0; i<cnt; i++ ) {
			s += "" + a[i][0] + lf;
		}
		return( s );
	};

	oaInterface.prototype.publish = function( sid, data ) {
		// morework: add opts check to see if subscriber wants this message
		this.msgCnt++;
		if ( this.cbPublishAll ) {
			this.cbPublishAll( sid, data );
		}
		this.common.hub.x_publish( sid, data );
	};

	oaInterface.prototype.getData = function( data ) {
		// { winname, win, opts, data }
		var o = this.getMessage( data );
		if ( o ) {
			o.win = xWin( o.winname );
		}
		return( o );
	};

	oaInterface.prototype.getMessage = function( data ) {
		var x;

		x = strat( "|", data );
		if ( ! x ) {
			return( null );
		}
		if ( left( data, x-1 ) != XLIB_SIG ) {
			return( null );
		}

		data = right( data, len( data ) - x );

		try {
			return( eval( data ) );
		}
		catch ( e ) {
			return( null );
		}
	};

	oaInterface.prototype.objPublish = function( e, mtype, w, pt, sid, msg ) {
		var o, k, kbtn=0, x, y, n;

		o = new OpenAjaxInterface_message( );

	    k = xlib.keyGet( e );
		if ( k.isALT ) { kbtn |= this.KEY_ALT; }
		if ( k.isCTRL ) { kbtn |= this.KEY_CTRL; }
		if ( k.isSHIFT ) { kbtn |= this.KEY_SHIFT; }

		o.sid = sid;
		o.mtype = mtype;
		o.winname = w.name;
		o.msg = msg;
		if ( pt ) {
			o.pt = { x : pt.x, y : pt.y };
		}
		else {
			o.pt = { x : 0, y : 0 };
		}

		o.mouseButton = xlib.mouseButton( e );

		o.key = k.code;
		o.keyButton = kbtn;

		s = XLIB_SIG + "|({"

		for ( n in o ) {
			v = o[n];
			switch ( typeof( v ) ) {
			  case "string":
				s += n + ":\"" + v + "\",";
				break
			  case "number":
				s += n + ":" + v + ",";
				break
			}
			if ( n == "pt" ) {
				s += "pt:{";
				if ( v ) {
					s += "x:" + v.x + ",";
					s += "y:" + v.y;
				}
				else {
					s += "x:0,";
					s += "y:0";
				}
				s += "},";
			}
		}
		s = left( s, len( s ) - 1 );
		s += "})";

		return( this.common.hub.publish( sid, s ) );
	};

	oaInterface.prototype.msgTypeDesc = function( mval ) {
		var cnt, i;
		cnt = len( this.aEvents );
		for ( i=0; i<cnt; i++ ) {
			if ( mval == eval( "xlib.openajax.ID_" + this.aEvents[i] ) ) {
				return( this.aEvents[i] );
			}
		}
		return( "Unknown" );
	};

	oaInterface.prototype.initDragAndDrop = function( flag ) {

		if ( flag ) {
			if ( this.dndEnabled ) {
				return;
			}
			this.registerService( "xwinlib_dnd", "Global drag and drop service" );
			this.dndEnabled = 1;
		}
		else {
			this.unregisterService( "xwinlib_dnd" );
			this.dndEnabled = 0;
		}
	};



function OpenAjaxInterface_message( ) {
	this.sid = "";
	this.mtype = 0;
	this.winname = "";
	this.msg = "";
	this.pt = { x:0, y:0 };
	this.mouseButton = 0;
	this.key = 0;
	this.keyButton = 0;
	this.data = "";
	this.lib = "";			// used for remote interfacing
}

function OpenAjaxInterface_service( status, sid, desc, opts ) {
	this.status = int( status );
	this.sid = sid;
	this.desc = desc;
	this.opts = int( opts );
	if ( isNaN( this.opts ) ) {
		this.opts = 0;
	}
}

function OpenAjaxInterface_subscribe( status, sid, cb, scope, data, filter, opts ) {
	this.status = int( status );
	this.sid = sid;
	this.cb = cb;
	this.scope = scope;
	this.data = data;
	this.filter = filter;
	this.opts = int( opts );
	if ( isNaN( this.opts ) ) {
		this.opts = 0;
	}
}

/////////////////////////////////
// Init Library

var xlib = new xLibrary( );


// xWinLib_themes.js

function theme_XP( name, content, IsExternal ) {
	var w = new xWindow( name );
	w.theme = "XP";

	w.style = WS_NORMAL | WS_MAXIMIZABLE | WS_CLOSE | WS_MOVEABLE | WS_RESIZABLE | WS_HEADER | WS_FOOTER | WS_BORDER;
	if ( IsExternal ) { w.style |= WS_EXTERNAL; }

	w.borderWidth = 4;
	w.borderColor = "#5e89cb";
	w.hdrHeight = 30;
	w.funcHeader = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=2 height=30 class=smtxtw width='100%' background='" + xWinThemesDir +"/xp_hdrBG.gif'><tr>" +
			"<td>&nbsp;" + w.header + "</td><td align=right style='text-align:right;'>";

		if ( w.style & WS_MINIMIZABLE ) {
			s += "<img src='" + xWinThemesDir +"/xp_min.gif' width=21 height=21 border=0 onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/xp_minOn.gif');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/xp_min.gif');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + w.name + "').minimize();\" title='Minimize'>";
		}
		if ( w.style & WS_MAXIMIZABLE ) {
			s += "<img src='" + xWinThemesDir +"/xp_max.gif' width=21 height=21 border=0 onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/xp_maxOn.gif');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/xp_max.gif');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + w.name + "').maximize();\" title='Maximize'>";
		}
		if ( w.style & WS_CLOSE ) {
			s += "<img src='" + xWinThemesDir +"/xp_close.gif' width=21 height=21 border=0 onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/xp_closeOn.gif');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/xp_close.gif');\" ondragstart='return false;' style='cursor:pointer;' onClick=\"xWinFromName('" + w.name + "').destroy();\" title='Close'>";
		}

		s += "</td></tr></table>";
		return( s );
	};

	w.ftrHeight = 22;
	w.funcFooter = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=2 height=22 class=smtxtw width='100%' background='" + xWinThemesDir +"/xp_hdrBG.gif'><tr>" +
			"<td>&nbsp;" + w.footer + "</td></tr></table>";
		return( s );
	};
	w.padding = 10;
	content = IsExternal ? w.actionRenderExternal( content ) : content;
	w.action = content;

	return( w );
}

function theme_Vista( name, content, IsExternal ) {
	var w = new xWindow( name );
	w.theme = "Vista";

	w.style = WS_NORMAL | WS_TRANSPARENT | WS_MINIMIZABLE | WS_MAXIMIZABLE | WS_CLOSE | WS_MOVEABLE | WS_RESIZABLE | WS_HEADER | WS_FOOTER;
	if ( IsExternal ) { w.style |= WS_EXTERNAL; }
	w.transLevel = 100;

	w.hdrHeight = 30;
	w.funcHeader = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=0 height=30 class=smtxtw width='100%'><tr>" +
			"<td width=8 background='" + xWinThemesDir +"/vista_tl.png'></td>" +
			"<td background='" + xWinThemesDir +"/vista_tc.png'>&nbsp;<b>" + w.header + "</b></td><td valign=top align=right style='text-align:right;' nowrap background='" + xWinThemesDir +"/vista_tc.png'>";

		if ( w.style & WS_MINIMIZABLE ) {
			s += "<img src='" + xWinThemesDir +"/vista_min.png' width=27 height=18 border=0 style='cursor:pointer; position:relative; top:1;' onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/vista_minOn.png');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/vista_min.png');\" ondragstart='return false;' onClick=\"xWinFromName('" + w.name + "').minimize();\" title='Minimize'>";
		}
		if ( w.style & WS_MAXIMIZABLE ) {
			s += "<img src='" + xWinThemesDir +"/vista_max.png' width=25 height=18 border=0 style='cursor:pointer; position:relative; top:1;' onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/vista_maxOn.png');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/vista_max.png');\" ondragstart='return false;' onClick=\"xWinFromName('" + w.name + "').maximize();\" title='Maximize'>";
		}
		if ( w.style & WS_CLOSE ) {
			s += "<img src='" + xWinThemesDir +"/vista_close.png' width=43 height=18 border=0 style='cursor:pointer; position:relative; top:1;' onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/vista_closeOn.png');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/vista_close.png');\" ondragstart='return false;' onClick=\"xWinFromName('" + w.name + "').destroy();\" title='Close'>";
		}

		s += "<td width=8 background='" + xWinThemesDir +"/vista_tr.png'></td></tr></table>";
		return( s );
	};

	w.ftrHeight = 8;
	w.funcFooter = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=0 height=8 class=smtxtw width='100%'><tr height=8 class='xtiny'>" +
			"<td width=8 background='" + xWinThemesDir +"/vista_bl.png'></td>" +
			"<td background='" + xWinThemesDir +"/vista_bc.png'><img src='" + xWinImageDir + "/trans.gif'></td>" +
			"<td width=8 background='" + xWinThemesDir +"/vista_br.png'></td>" +
			"</tr></table>";
		return( s );
	};

	w.padding = 0;
	w.overflow = "hidden";	

	content = IsExternal ? w.actionRenderExternal( content ) : content;
	w.action = "<table border=0 cellspacing=0 cellpadding=0 class=txt width='100%' height='100%'><tr valign=top>" +
		"<td nowrap width=8 background='" + xWinThemesDir +"/vista_lc.png'></td>" +
		"<td id='" + name + "_bTheme' background='" + w.imagedir + "/trans30.png' style='padding:10; border:solid 1px #A0A0A0;' class=txtw>" + content + "</td>" +
		"<td nowrap width=8 background='" + xWinThemesDir +"/vista_rc.png'></td>" +
		"</tr></table>";

	return( w );
}


function theme_Mac( name, content, IsExternal ) {
	var w, map, img;

	w = new xWindow( name );
	w.theme = "Mac";

	w.style = WS_NORMAL | WS_MAXIMIZABLE | WS_CLOSE | WS_MOVEABLE | WS_RESIZABLE | WS_HEADER;
	if ( IsExternal ) { w.style |= WS_EXTERNAL; }

	map = name + "_hmap";
	img = name + "_bimg";

	w.hdrHeight = 23;
	w.funcHeader = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=0 height=23 class=smtxt width='100%'><tr>" +
			"<td nowrap width=8 background='" + xWinThemesDir +"/mac_tl.png'></td>" +
			"<td nowrap width=61 background='" + xWinThemesDir +"/mac_tc.gif'>" + 
			"<img id='" + img + "' src='" + xWinThemesDir +"/mac_btns.gif' width=61 height=17 border=0 usemap='#" + map + "' style='cursor:pointer;' onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/mac_btnsOn.gif');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/mac_btns.gif');\" ondragstart='return false;'></td>" +
			"<td nowrap background='" + xWinThemesDir +"/mac_tc.gif' align=center>&nbsp;" + w.header + "</td>" +
			"<td width=61 background='" + xWinThemesDir +"/mac_tc.gif'></td>" +
			"<td nowrap width=8 background='" + xWinThemesDir +"/mac_tr.png'></td>" +
			"</tr></table>" +
			"<map name='" + map + "'>" +
			"<area shape='rect' coords='2,2,15,15' href='' onclick=\"javascript:xWin('" + w.name + "').destroy(); return false;\" title='close' onmouseover=\"domImageSet('" + img + "','" + xWinThemesDir +"/mac_btnsOn.gif');\" onmouseout=\"domImageSet('" + img + "','" + xWinThemesDir +"/mac_btns.gif');\">" +		// safari requires mouseover/out for each map element
			"<area shape='rect' coords='23,2,36,15' href='' onclick=\"javascript:xWin('" + w.name + "').minimize(); return false;\" title='minimize' onmouseover=\"domImageSet('" + img + "','" + xWinThemesDir +"/mac_btnsOn.gif');\" onmouseout=\"domImageSet('" + img + "','" + xWinThemesDir +"/mac_btns.gif');\">" +
			"<area shape='rect' coords='44,2,57,15' href='' onclick=\"javascript:xWin('" + w.name + "').maximize(); return false;\" title='maximize' onmouseover=\"domImageSet('" + img + "','" + xWinThemesDir +"/mac_btnsOn.gif');\" onmouseout=\"domImageSet('" + img + "','" + xWinThemesDir +"/mac_btns.gif');\">" +
			"</map>";
		return( s );
	};

	w.overflow = "hidden";	
	w.padding = 0;
	w.bgImage = xWinThemesDir + "/mac_bg.gif";
	content = IsExternal ? w.actionRenderExternal( content ) : content;
	w.action = "<table style='border:solid 1px #8c8c8c' border=0 cellspacing=0 cellpadding=10 class=txt width='100%' height='100%'>" + 
		"<tr valign=top><td id='" + name + "_bTheme'>" + content + "</td></tr></table>";

	return( w );
}


function theme_Enlightenment( name, content, IsExternal ) {
	var w, map, img;

	w = new xWindow( name );
	w.theme = "Enlightenment";

	w.style = WS_NORMAL | WS_TRANSPARENT | WS_MAXIMIZABLE | WS_CLOSE | WS_MOVEABLE | WS_RESIZABLE | WS_HEADER | WS_FOOTER;
	if ( IsExternal ) { w.style |= WS_EXTERNAL; }

	w.transLevel = 100;

	map = name + "_hmap";
	img = name + "_bimg";

	w.hdrHeight = 29;
	w.funcHeader = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=0 height=29 class=smtxt width='100%'><tr>" +
			"<td nowrap width=70 background='" + xWinThemesDir +"/enlightenment_tl.png'></td>" +
			"<td nowrap background='" + xWinThemesDir +"/enlightenment_tc.png' class=smtxtw>" + w.header + "&nbsp;</td>" +
			"<td nowrap width=101>" +
			"<img id='" + img + "' src='" + xWinThemesDir +"/enlightenment_tr.png' width=101 height=29 border=0 usemap='#" + map + "' style='cursor:pointer;' onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/enlightenment_trOn.png');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/enlightenment_tr.png');\" ondragstart='return false;'></td>" +
			"</tr></table>" +
			"<map name='" + map + "'>" +
			"<area shape='rect' coords='40,6,54,47' href='' onclick=\"javascript:xWin('" + w.name + "').minimize(); return false;\" title='minimize' onmouseover=\"domImageSet('" + img + "','" + xWinThemesDir +"/enlightenment_trOn.png');\" onmouseout=\"domImageSet('" + img + "','" + xWinThemesDir +"/enlightenment_tr.png' );\">" +		// safari requires mouseover/out for each map element
			"<area shape='rect' coords='59,6,73,47' href='' onclick=\"javascript:xWin('" + w.name + "').maximize(); return false;\" title='maximize' onmouseover=\"domImageSet('" + img + "','" + xWinThemesDir +"/enlightenment_trOn.png');\" onmouseout=\"domImageSet('" + img + "','" + xWinThemesDir +"/enlightenment_tr.png');\">" +
			"<area shape='rect' coords='78,6,92,47' href='' onclick=\"javascript:xWin('" + w.name + "').destroy(); return false;\" title='close' onmouseover=\"domImageSet('" + img + "','" + xWinThemesDir +"/enlightenment_trOn.png');\" onmouseout=\"domImageSet('" + img + "','" + xWinThemesDir +"/enlightenment_tr.png');\">" +
			"</map>";
		return( s );
	};

	w.ftrHeight = 12;
	w.funcFooter = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=0 height=12 class=smtxt width='100%'><tr>" +
			"<td nowrap width=46 background='" + xWinThemesDir +"/enlightenment_bl.png'></td>" +
			"<td nowrap background='" + xWinThemesDir +"/enlightenment_bc.png' class=smtxtw>" + w.footer + "&nbsp;</td>" +
			"<td nowrap width=30 background='" + xWinThemesDir +"/enlightenment_br.png'>&nbsp;</td><tr></table>";
		return( s );
	};

	w.overflow = "hidden";	
	w.padding = 0;

	content = IsExternal ? w.actionRenderExternal( content ) : content;
	w.action = "<table border=0 cellspacing=0 cellpadding=0 class=txt width='100%' height='100%'><tr valign=top>" +
		"<td nowrap width=12 background='" + xWinThemesDir +"/enlightenment_cl.png'></td>" +
		"<td id='" + name + "_bTheme' background='" + w.imagedir + "/trans50.png' style='padding:10; border:solid 1px #A0A0A0;' class=txtw>" + content + "</td>" +
		"<td nowrap width=8 background='" + xWinThemesDir +"/enlightenment_cr.png'></td>" +
		"</tr></table>";

	return( w );
}

function theme_Black( name, content, IsExternal, opts ) {
	var w, trans=0, h='100%';

	if ( opts ) {
		trans = opts.trans == null ? trans : opts.trans;
	}

	w = new xWindow( name );
	w.theme = "Black";

	w.style = WS_NORMAL | WS_TRANSPARENT | WS_MAXIMIZABLE | WS_CLOSE | WS_MOVEABLE | WS_RESIZABLE | WS_HEADER | WS_FOOTER;

	if ( IsExternal ) { w.style |= WS_EXTERNAL; }

	w.transLevel = 100;

	w.hdrHeight = 25;
	w.funcHeader = function( w ) {
		var s = "<div id='dlgbox'><table border=0 cellspacing=0 cellpadding=0 class=txt width='100%' height='30'>" + 
			"<tr><td class='tl' nowrap></td><td class='smtxtg tc' nowrap valign='top'><b><div style='position:absolute; top:11px; left:18px;'>" + w.header + "</div></b>&nbsp;</td>" +
			"<td class='tr' nowrap><div style='position:relative; top:3px; left:-4px;'><img src='" + w.imagedir + "/win_close0.png' width=18 height=18 border=0 onmouseover=\"domImageSet(this,'" + w.imagedir + "/win_close1.png');\" onmouseout=\"domImageSet(this,'" + w.imagedir + "/win_close0.png');\" ondragstart='return false;' onClick=\"xWin('" + w.name + "').destroy();\" title='Close'></div></td></tr></table></div>";
		return( s );
	};

	w.ftrHeight =20;
	w.funcFooter = function( w ) {
		var s = "<div id='dlgbox'><table class='dlgbox' border=0 width='100%' height=20 cellspacing=0 cellpadding=0>" +
 			"<tr valign=top><td class='bl' nowrap></td><td class='bc'></td><td class='br' nowrap></td></tr></table></div>";
			return( s );
	};


	w.padding = 0;
	w.overflow = "hidden";	
	w.displayMode = DISP_NORMAL | DISP_NOPROGRESS;
	content = IsExternal ? w.actionRenderExternal( content, "xid=" + name ) : content;
	w.action = "<div id='dlgbox'><table border=0 width='100%' height='100%' cellspacing=0 cellpadding=0>" +
		"<tr valign=top><td class='cl' nowrap></td><td class='cc' valign='top'><div id='" + name + "_bTheme' style='position:relative; width:100%; height:" + h + "; overflow:auto;'>" + content + "</div></td><td class='cr' nowrap></td></tr></table></div>";

	return( w );
}


function objScrapplet( ) {
	this.IsAdmin = 0;
	this.defaultTimerDelay = 3;
	this.pgid = "";
	this.pgowner = "";
	this.pgtitle = "";
	this.pgaddr = "";
	this.userurl = "";
	this.userId = "";
	this.sessionKey = "";
	this.userOptions = 0;
	this.userName = "";

	this.OPT_PGEDIT_NODISPLAYHELP = 1;

	xWinContextSideClr = "#6d84b4";
	xWinPropertyTheme = theme_Facebook;

	this.PreprocessLoad = 0;
	this.data = null;
}

objScrapplet.prototype = {
	
	actionPreprocessor: function( action ) {
		if ( ! strat( "@@", action ) ) {
			return( action );
		}

		if ( ! this.PreprocessLoad ) {
			data = xlibAjax( AJAX_POST, AJAX_SYNCH, "/ws.htm", "cmd=ACTION_PREPROCESS&action=" + jsEncode( action ) + "&pgid=" + scrapplet.pgid + "&pgowner=" + scrapplet.pgowner );
			scrapplet.PreprocessLoad = 1;
			scrapplet.data = eval( data );
		}

		action = strswapi( action, "@@USER_PIC", scrapplet.data.user_pic );
		action = strswapi( action, "@@USER_NAME", scrapplet.data.user_name );
		action = strswapi( action, "@@USER_HOMEPAGE", scrapplet.data.user_homepage );
		action = strswapi( action, "@@USER_LOCATION", scrapplet.data.user_location );
		action = strswapi( action, "@@USER_THUMBNAIL", scrapplet.data.user_thumbnail );
		action = strswapi( action, "@@USER_NETWORKS", scrapplet.data.user_networks );

		action = strswapi( action, "@@NETWORK_FACEBOOK", scrapplet.data.network_facebook );
		action = strswapi( action, "@@NETWORK_MYSPACE", scrapplet.data.network_myspace );
		action = strswapi( action, "@@NETWORK_FRIENDFEED", scrapplet.data.network_friendfeed );
		action = strswapi( action, "@@NETWORK_TWITTER", scrapplet.data.network_twitter );
		action = strswapi( action, "@@NETWORK_LINKEDIN", scrapplet.data.network_linkedin );
		action = strswapi( action, "@@NETWORK_YOUTUBE", scrapplet.data.network_youtube );
		action = strswapi( action, "@@NETWORK_FLICKR", scrapplet.data.network_flickr );

		action = strswapi( action, "@@PAGE_OWNER_PIC", scrapplet.data.page_owner_pic );
		action = strswapi( action, "@@PAGE_OWNER_NAME", scrapplet.data.page_owner_name );
		action = strswapi( action, "@@PAGE_OWNER_HOMEPAGE", scrapplet.data.page_owner_homepage );
		action = strswapi( action, "@@PAGE_OWNER_LOCATION", scrapplet.data.page_owner_location );
		action = strswapi( action, "@@PAGE_OWNER_THUMBNAIL", scrapplet.data.page_owner_thumbnail );
		action = strswapi( action, "@@PAGE_OWNER_NETWORKS", scrapplet.data.page_owner_networks );
		
		action = strswapi( action, "@@PAGE_ID", scrapplet.data.page_id );
		action = strswapi( action, "@@PAGE_TITLE", scrapplet.data.page_title );
		action = strswapi( action, "@@PAGE_ADDRESS", scrapplet.data.page_address );

		return( action );
	},


	atCommands: function( ) {
		this.pageLoad( 'atcmd', '@@Commands', '/commands.htm', { UseButtons: 0 } );
	},

	backgroundFind: function( ) {
		var url = "http://images.google.com/images?gbv=2&hl=en&safe=on&q=backgrounds";
		xlib.browserNew( -1, -1, 800, 600, "_blank", url );
	},

	clearall: function( ) {
		var i, awin, cnt, a;
		if ( confirm( "Clear all objects from the page?" ) ) {

			awin = parent.xWinList;
			cnt = awin.length + 1;

			a = new Array( );
			for ( i=1; i<cnt; i++ ) {
				if ( awin[i] && ( ! awin[i].issys ) ) {
					a[len(a)] = awin[i].name;
				}
			}

			cnt = len( a );
			for ( i=0; i<cnt; i++ ) {
				xWin( a[i] ).destroy( );
			}
			
			//parent.document.body.style.backgroundImage = "";
			//parent.document.body.style.backgroundColor = "#ffffff";
			
			xlib.UpdateFlag( 1 );
		}
	},
	
	fileManager : function( varname, frameid, src1, src2, reffile, dirname ) {
		varname = varname == null ? "" : varname;
		frameid = frameid == null ? "" : frameid;
		src1 = src1 == null ? "" : src1;
		src2 = src2 == null ? "" : src2;
		reffile = reffile == null ? "" : reffile;
		dirname = dirname == null ? "" : dirname;
		this.pageLoad( "fm", "File Manager", "/vfm.htm?varname=" + varname + "&frameid=" + frameid + "&src1=" + src1 + "&src2=" + src2 + "&reffile=" + jsEncode( reffile ) + "&dirname=" + jsEncode( dirname ), { UseButtons: 0, w:640, h:440 } );
	},
	
	galleryView: function( id ) {
		scrapplet.pageLoad( 'vgallery', 'View Gallery', '/galleryView_' + id + '.htm?id=' + id, { UseButtons:0 } );
	},

	goHome : function( ) {
		top.document.location = ( strempty( scrapplet.userId ) ? "http://www.scrapplet.com" : "/" + scrapplet.userId );
	},

	help: function( obj ) {
		this.pageLoad( "hlp", "Help", "/objhelp.htm?id=" + obj.name, { UseButtons: 0 } );
	},

	imgToggle: function( w, w1, h1, w2, h2 ) {
		var data;
	
		if ( w.width == w1 ) {
			data = w.name + "," + w.left + "," + w.top + "," + w2 + "," + h2 + "," + w.zorder + "," + w.displayMode; 
		}
		else {
			data = w.name + "," + w.left + "," + w.top + "," + w1 + "," + h1 + "," + w.zorder + "," + w.displayMode; 
		}
		xlib.desktop.winMove( data, MOVE_ANIMATE );
	},

	loadRichDrop: function( ) {
		var w, width=560, height=400, left=0, top=0, name="objrich", opts, url;
		var displayMode = DISP_CENTERED | DISP_NOPROGRESS;

		w = xWin( name );
		if ( w ) { 
			w.destroy( ); w=null;
			return;
		}

		opts = { w : width, h : height, displayMode : displayMode };

		url = "/objAdd_RichDrop.htm?pgid=" + this.pgid;
		w = theme_Facebook( name, url, 1, opts );
		w.displayMode = displayMode;
		w.style |= WS_ALWAYSONTOP | WS_CONTEXTMENU;
		w.issys = 1;
		w.header = "Rich Content";
		w.setposition( left, top, width, height );
		
		w.oaSubscriptions = "1|xwinlib_dnd|" + jsEncode( "var odata = xlib.openajax.getData( data ); odata.win.iframeDocument( ).dndProcess( msg, data );" ) + "||||" + xlib.openajax.ID_INTERNALHANDLER, 
		
		w.create( );
	},

	logout: function( ) {
		if ( ! confirm( "Are you sure you want to logoff?" ) ) {
			return;
		}

		if ( this.userId == this.pgowner ) {
			if ( xlib.UpdateFlag( ) ) {
				if ( confirm( "Changes detected, save the page before logging out?" ) ) {
					scrapplet.save( );
				}
			}
		}
		xlibAjax( AJAX_GET, AJAX_SYNCH, "/ws.htm", "cmd=LOGOUT" );
		top.location = "/explore.htm";
	},
	
	ModalDialog: function( name, title, url ) {
		var w, left=0, top=0;
		w = theme_Facebook( name, url, 1, null );
		w.displayMode = DISP_CENTERED | DISP_NOPROGRESS;
		w.style |= WS_ALWAYSONTOP | WS_MODAL;
		w.issys = 1;
		w.header = title;
		w.setposition( left, top, 560, 400 );
		w.create( );
	},

	musicFind: function( ) {
		var url ="http://audio.search.yahoo.com/search/audio";
		xlib.browserNew( -1, -1, 800, 600, "_blank", url );
	},

	objAdd: function( typeDesc ) {
		this.pageLoad( "objAdd", "Add Object - " + typeDesc, "/objAdd_" + strswap( typeDesc, " ", "" ) + ".htm" );
	},

	objAnimate : function( ) {
		scrapplet.pageLoad( 'objanim', 'Object animation', '/objAnimation.htm', { UseButtons:1 } );
	},

	objCreate : function( id, title, action ) {

		w = parent.xlib.objLookup( id );
		if ( w ) {
			title = title || "";
			action = action || "";
			w.action = xlib.objPreprocess( w.action, "#TITLE#", title );
			w.eClick = xlib.objPreprocess( w.eClick, "#ACTION#", action );
			w.setposition( parent.xlib.winDefPostion( ) );
			w.create( );
		}
	},
	
	pageLoad: function( name, title, url, opts ) {
		var w, width=560, height=400, left=0, top=0;
		var displayMode = DISP_CENTERED | DISP_NOPROGRESS;

		w = xWin( name );
		if ( w ) { 
			w.destroy( ); w=null;
			return;
		}

		if ( opts ) {
			if ( opts.left != null ) { left = opts.left; }
			if ( opts.top != null ) { top = opts.top; }
			if ( opts.w != null ) { width = opts.w; }
			if ( opts.h != null ) { height = opts.h; }
			if ( opts.displayMode != null ) { displayMode = opts.displayMode; }
		}

		url += ( strat( "?", url ) ? "&" : "?" ) + "pgid=" + this.pgid;
		if ( ! strati( "xid=", url ) ) {
			url += "&xid=" + name;
		}
		w = theme_Facebook( name, url, 1, opts );
		w.displayMode = displayMode;
		w.style |= WS_ALWAYSONTOP;
		w.issys = 1;
		w.header = title;
		w.setposition( left, top, width, height );
		w.create( );
	},

	pageShare: function( ) {
		var url = "http://www.facebook.com/share.php?u=" + jsEncode( this.pageurl );
		xlib.browserNew( -1, -1, 800, 600, "_blank", url );
	},

	pageWizard: function( isnew ) {
		var isnew = isnew == null ? 0 : isnew;
		scrapplet.pageLoad( 'pwiz', 'Page Wizard', '/pageWizard.htm?isnew=' + isnew, { UseButtons:0 } );
	},

	panelToggle_left: function( id, tabwidth, OpenFlag ) {
		var w, x, data;

		if ( typeof( id ) == "string" ) {
			w = xWin( id );
		}
		else {
			w = id;
		}
		if ( ! w ) {
			return;
		}

		if ( OpenFlag == null ) {
		  	OpenFlag = int( w.obj.style.left ) < 0;
		}

		x = OpenFlag ? 0 : tabwidth - int( w.obj.style.width );
		data = w.name + "," + x + "," + int( w.obj.style.top ) + ",0,0," + w.zorder + "," + w.displayMode;

		xlib.desktop.winMove( data, MOVE_ANIMATE | MOVE_NORESIZE | MOVE_SAVEPOS );

		try {
			domObject( "scNavTop" ).style.zIndex = xWinZorder + 10000;
		}
		catch ( e ) { }
	},

	pictureFind: function( ) {
		var url = "http://images.google.com/images?gbv=2&hl=en&safe=on";
		xlib.browserNew( -1, -1, 800, 600, "_blank", url );
	},

	playerMusic: function( title, musicFile, autostart, replay ) {
		var w, url, pt;

		replay = replay === null ? 0 : replay;
		autostart = autostart === null ? 1 : autostart;

		url = "/music/mplayer.htm?title=" + jsEncode( title ) + "&url=" + musicFile + "&replay=" + replay + "&autostart=" + autostart;
		name = xWinNameGen( OTYPE_MUSIC );
		w = theme_Facebook( name, url, 1, { UseButtons: 0, trans: 1 } );
		w.style &= ~( WS_MAXIMIZABLE | WS_RESIZABLE | WS_ALWAYSONTOP );
		w.style |= WS_CONTEXTMENU;
		w.otype = OTYPE_MUSIC;
		w.header = "Scrapplet Music Player";
		pt = xlib.winDefPostion( );
		w.setposition( pt.x, pt.y, 236, 80 );
		w.create( );
	},

	playerVideo: function( title, file, autostart, replay ) {
		var w, url, pt;

		replay = replay === null ? 0 : replay;
		autostart = autostart === null ? 1 : autostart;

		url = "/video/vplayer.htm?title=" + jsEncode( title ) + "&url=" + file + "&replay=" + replay + "&autostart=" + autostart;
		name = xWinNameGen( OTYPE_VIDEO );
		w = theme_Facebook( name, url, 1, { UseButtons: 0, trans: 1 } );
		w.style &= ~( WS_MAXIMIZABLE | WS_ALWAYSONTOP );
		w.style |= WS_CONTEXTMENU;
		w.otype = OTYPE_VIDEO;
		w.header = "Scrapplet Video Player";
		pt = xlib.winDefPostion( );
		w.setposition( pt.x, pt.y, 360, 315 );
		w.create( );
	},

	pointsEarn: function( ) {
		scrapplet.pageLoad( 'pointsEarn', 'Earn Scrapplet Points', '/pointsEarn.htm' );
	},

	restore: function( ) {
		if ( ! xlib.UpdateFlag( ) ) {
			alert( "Nothing to restore, no changes detected." );
		}
		else if ( confirm( "Restoring the page will discard any changes. Continue?" ) ) {
			xlib.UpdateFlag( 0 );
			document.location.reload( );
		}
	},

	save: function( ) {
		var s = xlibAjax( AJAX_POST, AJAX_SYNCH, "/ws.htm", "cmd=PAGE_SAVE&pgid=" + this.pgid + "&data=" + jsEncode( xlib.desktop.save( ) ) );
		if ( s == "1" ) {
			xlib.UpdateFlag( 0 );
			scrapplet.winMessage( "Page successfully saved.", 1 );
		}
		else {
			alert( s );
			//scrapplet.winMessage( s, -1 );
		}
	},

	userOptionSet: function( opt, IsAdd ) {
		var x = xlibAjax( AJAX_POST, AJAX_SYNCH, "/ws.htm", "cmd=USER_OPTIONS&opt=" + opt + "&isadd=" + IsAdd );
		this.userOptions = int( x );
	},

	userSitemap: function( id ) {
		var w = xWin( "_sitemap" );
		if ( w ) { 
			w.destroy( ); w=null;
			return;
		}
		
		w = theme_Facebook( "_sitemap", "/viewSiteMap.htm?userid=" + id, 1, { UseButtons:0 } );
		w.style |= WS_ALWAYSONTOP;
		w.issys = 1;
		w.header = "Site Map";
		w.setposition( 10, 65, 560, 400 );
		w.create( );
	},

	userView: function( id ) {
		xlib.browserNew( -1, -1, 800, 600, "_blank", "http://www.facebook.com/profile.php?id=" + id );
	},

	videoFind: function( ) {
		var url = "http://www.youtube.com";
		xlib.browserNew( -1, -1, 800, 600, "_blank", url );
	},

	viewOnWeb: function( ) {
		//var url = "http://www.scrapplet.com/" + this.userurl;
		xlib.browserNew( -1, -1, 800, 600, "_blank", this.userurl );
	},

	webData: function( url, stag, etag, cbfunc ) {
		stag = typeof( stag ) == "undefined" ? "" : stag;
		etag = typeof( etag ) == "undefined" ? "" : etag;
		if ( cbfunc ) {
			xlibAjax( AJAX_GET, AJAX_SYNCH, "/webData.htm", "url=" + jsEncode( url ) + "&stag=" + jsEncode( stag ) + "&etag=" + jsEncode( etag ), cbfunc );
			return;
		}
		return( xlibAjax( AJAX_GET, AJAX_SYNCH, "/webData.htm", "url=" + jsEncode( url ) + "&stag=" + jsEncode( stag ) + "&etag=" + jsEncode( etag ) ) );
	},

	webSearch: function( s ) {
		var url;

		pref = lbCurSelText( "top_websrch" );
		switch ( pref ) {
 		  case "images":
			url = "http://images.google.com/images" + ( s ? "?q=" + jsEncode( s ) : "" );
 		  	break;
 		  case "music":
 		  	url ="http://audio.search.yahoo.com/search/audio" + ( s ? "?p=" + jsEncode( s ) : "" );
 		  	break;
 		  case "videos":
 		  	url = "http://www.youtube.com" + ( s ? "/results?search_type=&search_query=" + jsEncode( s ) : "" );
 		  	break;
 		  case "news":
 		  	url = "http://news.google.com/news" + ( s ? "?q=" + jsEncode( s ) : "" );
 		  	break;
 		  case "blogs":
 		  	url = "http://blogsearch.google.com/blogsearch" + ( s ? "?q=" + jsEncode( s ) : "" );
 		  	break;
 		  case "maps":
 		  	url = "http://maps.google.com/maps" + ( s ? "?q=" + jsEncode( s ) : "" );
 		  	break;
 		  case "users":
 		  	scrapplet.pageLoad( 'search', 'Search Scrapplet', "/progress.htm?_url_=" + jsEncode( '/search.htm' ) + "&searchstr=" + jsEncode( s ), { UseButtons: 0 } );
			return;
 		  case "tags":
 		  	scrapplet.pageLoad( 'tags', 'Scrapplet Tags', "/progress.htm?_url_=" + jsEncode( '/tags.htm' ) + "&tag=" + jsEncode( s ), { UseButtons: 0 } );
			return;
 		  default:
			url = "http://www.google.com/cse?cx=partner-pub-0824294425504272:vdh2f45wpnq&ie=ISO-8859-1" + ( s ? "&q=" + jsEncode( s ) : "" );
		}

		xlib.browserNew( -1, -1, 800, 600, "_blank", url );

//		var url = "http://www.google.com";
//		if ( s ) {
//			url += "/search?hl=en&safe=on&q=" + jsEncode( s );
//		}
//		xlib.browserNew( -1, -1, 800, 600, "_blank", url );
	},

	webSearchBox: function( ) {
		var pt, w = new xWindow( );
		w.otype = OTYPE_HTMLBLOCK;
		w.name = xWinNameGen( w.otype );
		w.style = WS_NORMAL | WS_TRANSPARENT | WS_BORDER | WS_MOVEABLE | WS_CONTEXTMENU;
		pt = xlib.winDefPostion( );
		w.setposition( pt.x, pt.y, 370, 30 );
		w.action = "<table border=0 cellspacing=0 cellpadding=0 width=100% height=100% class=smtxtw><tr><td style='text-align:center'>" + 
				   "Search the Web: <input type=text class=smtxt id='" + w.name + "_ss' style='width:200' onKeyDown=\"btnDefault( xlib.eventGet( event ), '" + w.name + "_ssbtn' );\">" +
				   "<input id='" + w.name + "_ssbtn' type=button class=smtxt value='go' style='width:25' onclick=\"scrapplet.webSearch(domObject('" + w.name + "_ss').value);\">" +
				   "</td></tr></table>";
		w.create( );
	},

	winInit: function( data ) {
		var w;
		
		try {
			w = new xWindow( null, data, 1 );
			if ( this.IsAdmin ) {
				w.style |= WS_CONTEXTMENU;
			}
			else {
				if ( w.style & WS_NOTSHAREABLE ) {
					w.style &= ~WS_CONTEXTMENU;
				}
				else {
					w.style |= WS_CONTEXTMENU;
					w.style |= WS_SHAREMENU;
				}
			}
			w.create( );
		}
		catch ( e ) { }
	},

	winMessage: function( msg, secs ) {
		var w;

		if ( ! secs ) {
			secs = this.defaultTimerDelay;
		}
		
		w = xWin( "winmsg" );
		if ( w ) {
			clearTimeout( w.timer );
			w.destroy( );
		}
	
		w = theme_Facebook( "winmsg", "<table bgColor=white border=0 width=100% height='100%'><tr valign=center><td align=center style='text-align:center;'><h2>" + msg + "</h2></td></tr></table>", 0, { UseButtons: 0 } );
		w.issys = 1;
		w.setposition( 0, 0, 300, 100 );
		w.style |= WS_ALWAYSONTOP;
		w.displayMode = DISP_CENTERED;
		w.create( );
		

		if ( secs != -1 ) {
			w.timer = setTimeout( "try { xWin('winmsg').destroy( ) } catch ( e ) {};", secs * 1000 );
		}
	
	}


};


function theme_Facebook( name, content, IsExternal, opts ) {
	var w, UseButtons=1, trans=0;
	
	if ( opts ) {
		UseButtons = opts.UseButtons == null ? UseButtons : opts.UseButtons;
		trans = opts.trans == null ? trans : opts.trans;
	}

	w = new xWindow( name );
	w.theme = "Facebook";

	w.style = WS_NORMAL | WS_TRANSPARENT | WS_MAXIMIZABLE | WS_CLOSE | WS_MOVEABLE | WS_RESIZABLE | WS_HEADER | WS_FOOTER | WS_ALWAYSONTOP;
	if ( IsExternal ) { w.style |= WS_EXTERNAL; }

	w.transLevel = 100;
	w.hdrHeight = 32;
	w.funcHeader = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=0 height=32 class=smtxtw width='100%'><tr valign=bottom>" +
			"<td width=8 background='" + xWinThemesDir +"/fb_tl.png'></td>" +
			"<td style='padding:5;' background='" + xWinThemesDir +"/fb_tc.png'><b>" + w.header + "</b></td>" +
			"<td align=right style='padding:5; text-align:right;' nowrap background='" + xWinThemesDir +"/fb_tc.png'>";

		if ( w.style & WS_MINIMIZABLE ) {
			s += "<img src='" + xWinThemesDir +"/fb_min.png' width=18 height=14 border=0 style='cursor:pointer; position:relative; top:1;' onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/fb_minOn.png');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/fb_min.png');\" ondragstart='return false;' onClick=\"xWin('" + w.name + "').minimize();\" title='Minimize'>";
		}
		if ( w.style & WS_MAXIMIZABLE ) {
			s += "<img src='" + xWinThemesDir +"/fb_max.png' width=18 height=14 border=0 style='cursor:pointer; position:relative; top:1;' onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/fb_maxOn.png');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/fb_max.png');\" ondragstart='return false;' onClick=\"xWin('" + w.name + "').maximize();\" title='Maximize'>";
		}
		if ( w.style & WS_CLOSE ) {
			s += "<img src='" + xWinThemesDir +"/fb_close.png' width=18 height=14 border=0 style='cursor:pointer; position:relative; top:1;' onmouseover=\"domImageSet(this,'" + xWinThemesDir +"/fb_closeOn.png');\" onmouseout=\"domImageSet(this,'" + xWinThemesDir +"/fb_close.png');\" ondragstart='return false;' onClick=\"xWin('" + w.name + "').destroy();\" title='Close'>";
		}

		s += "<td width=8 background='" + xWinThemesDir +"/fb_tr.png'></td></tr></table>";
		return( s );
	};

	w.ftrHeight = 8;
	w.funcFooter = function( w ) {
		var s = "<table border=0 cellspacing=0 cellpadding=0 height=8 class=smtxtw width='100%'><tr height=8 class='xtiny'>" +
			"<td width=8 background='" + xWinThemesDir +"/vista_bl.png'></td>" +
			"<td background='" + xWinThemesDir +"/vista_bc.png'><img src='" + xWinImageDir + "/trans.gif'></td>" +
			"<td width=8 background='" + xWinThemesDir +"/vista_br.png'></td>" +
			"</tr></table>";
		return( s );
	};

	w.padding = 0;
	w.overflow = "hidden";	
	w.displayMode = DISP_NORMAL | DISP_NOPROGRESS;
	content = IsExternal ? w.actionRenderExternal( content ) : content;
	w.action = "<table border=0 cellspacing=0 cellpadding=0 class=txt width='100%' height='100%'>" + 
		"<tr valign=top>" +
		"<td nowrap width=8 background='" + xWinThemesDir +"/vista_lc.png'></td>" +
		"<td id='" + name + "_bTheme' " + ( trans ? "" : "bgColor='#FFFFFF' " ) + "style='padding:0; border:solid 0px #A0A0A0;' class=txtw>" + content + "&nbsp;</td>" +
		"<td nowrap width=8 background='" + xWinThemesDir +"/vista_rc.png'></td>" +
		"</tr>";
		
	if ( UseButtons ) {
		w.action += "<tr valign=center height=30>" +
		"<td nowrap width=8 background='" + xWinThemesDir +"/vista_lc.png'></td>" +
		"<td bgColor='#f2f2f2' style='text-align:right; padding:2; border:solid 1px #cccccc;' class=txtw>" + 
		"<input type=button class=inputbutton id='btnOk' value='Ok' style='width:80;' onClick=\"try { xWin('" + name + "').iframeDocument( ).processSubmit( ); } catch( e ) { } \"> <input type=button class='inputbutton inputaux' value='Cancel' id='btnCancel' style='width:80;' onClick=\"xWin('" + w.name + "').destroy();\">" +
		"</td>" +
		"<td nowrap width=8 background='" + xWinThemesDir +"/vista_rc.png'></td>" +
		"</tr>";
	}

	w.action += "</table>";

	return( w );
}

function pageView( id ) {
	top.location = "/" + id;
}

function pageEdit( ) {
	var w = parent.xWin('pgedit');
	if ( w ) {
		parent.xWin('pgedit').destroy( );
		return;
	}
	adminMenu.pageEditMenu( );
}

function yourLinks( ) {
	top.scrapplet.pageLoad( 'links', 'User Links', '/userLinks.htm?userid=' + scrapplet.userId, { UseButtons:0 } );
}

function pageProperties( ) {
	if ( top.scrapplet.userId != top.scrapplet.pgowner ) {
		alert( "You can only access properties for your own pages!" );
		return( 0 );
	}
	top.adminMenu.pageProperties( );
}

function ditchAds( ) { 
	scrapplet.pageLoad( 'options', 'Scrapplet Membership Options', '/options.htm' ); 
}

function searchtopGo( ) {
	var a, i, cnt, str = domObject( "searchtop" ).value;

	a = new Array( "com", "net", "org", "mobi", "eu", "edu", "gov", "info", "uk", "cn", "biz", "tv", 
		"de", "bz", "us", "ca", "pro", "cc", "htm", "html", "pl", "asp", "aspx", "cfm" );

	cnt = len( a );
	for ( i=0; i<cnt; i++ ) {
		if ( strati( "." + a[i], str ) ) {
		  	xlib.browserNew( -1, -1, 800, 600, "_blank", xlib.normalizeURL( str ) );
			return;
		}
	}
	
	scrapplet.webSearch( str );
}

function ratepage( ) {
	parent.scrapplet.pageLoad( 'rate', 'Rate this Scrapplet page', '/pageRate.htm', { UseButtons: 1 } );
	try {
		parent.xWin( "<[ ! xid ]>" ).destroy( );
	} catch ( e ) { }
}


function sourceView( src ) {
	scrapplet.pageLoad( 'src', 'View Source', '/sourceViewer.htm?subcmd=' + src, { w:620, h:470 } );
}

function toggleFieldHeight( id, w, h ) {
	var o = domObject( id );
	o.style.height = int( o.style.height ) == w ? h : w;
}


function adminNavMenu( ) {
	this.curmenu = null;
	this.timer = null;
	this.timerDelay = 1500;
	
	this.emWidthOpen = 385;
	this.emWidthClosed = 61;
}

adminNavMenu.prototype = {

	pageEditMenuHelp: function( ) {
		var w, height, pt;
		
		w = xWin( "pgedit" );
		if ( ! w ) {
			return;
		}
		h = w.height == this.emWidthClosed ? this.emWidthOpen : this.emWidthClosed;
		pt = xlib.winAdjustPos( w.left, w.top, w.width, h, 5 );
		w.setposition( pt.x, pt.y, w.width, h, 1 );
	},

	pageEditMenuUpdate: function( ) {
		var w, obj = domObject( "OPT_PGEDIT_NODISPLAYHELP" );
		
		w = xWin( "pgedit" );
		if ( w ) {
			if ( obj.checked ) {
			}
			else {
				if ( w.height != this.emWidthClosed ) {
					this.pageEditMenuHelp( );
				}
			}
		}
		scrapplet.userOptionSet( scrapplet.OPT_PGEDIT_NODISPLAYHELP, obj.checked ? 0 : 1 );
	},

	pageEditMenu: function( ) {
		var w, name, pt;

		name = "pgedit";
		w = xWin( name );
		if ( w ) {
			w.destroy( );
			return( 0 );
		}

		if ( scrapplet.userId != scrapplet.pgowner ) {
			alert( "You can only edit your own pages!" );
			return( 0 );
		}
		
		w = new xWindow( name );
		w.issys = 1;
		w.style = WS_NORMAL | WS_HEADER | WS_BORDER | WS_MOVEABLE | WS_CLOSE | WS_ALWAYSONTOP | WS_HELP;
		w.overflow = "hidden";
		w.padding = 5;
		w.otype = OTYPE_HTMLBLOCK;
		w.bgColor = "#ffffff";
		w.borderColor = "#000000";
		w.borderWidth = 2;
//		w.hdrBgColor = "#b70004";
		w.hdrBgColor = "";
		w.hdrBgImage = "/images/editbgRed.gif";
		w.eDisplay = "domObject('wsearch').focus()";
		w.eDestroy = "adminMenu.close( )";
		w.header = "&nbsp;Object Toolbar &#187; " + scrapplet.pgtitle;
		w.helpFunc = function( o ) { adminMenu.pageEditMenuHelp( ); }

		w.width = 570;
		w.height = scrapplet.userOptions & scrapplet.OPT_PGEDIT_NODISPLAYHELP ? this.emWidthClosed : this.emWidthOpen;
		if ( w.height != this.emWidthClosed ) {
			w.displayMode |= DISP_CENTERED;
		}
		pt = xlib.winCalcCenter( 570, 61 );
		w.setposition( pt.x, 62 + xlib.winScrollY( ), 570, w.height );
		w.action = "<table border=0 cellspacing=0 cellpadding=2><tr>\n" + 
			"<td><a href='/' title='' onclick='return false;' onmouseover=\"adminMenu.display( 'system', xlib.eventGet( event ), 1 );\"><img src='/images/action_off.png' onmouseover=\"domImageSet( this, '/images/action_on.png' );\" onmouseout=\"domImageSet( this, '/images/action_off.png' );\" width=26 height=20></a></td>\n" + 
			"<td><a href='/' onclick='scrapplet.save( ); return false;' title='' onmouseover='adminMenu.close( );'><img src='/images/save_off.png' onmouseover=\"domImageSet( this, '/images/save_on.png' );\" onmouseout=\"domImageSet( this, '/images/save_off.png' );\" width=36 height=20></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'text', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'text', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Text.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'background', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'background', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Image.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'pictures', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'pictures', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Pictures.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'music', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'music', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Music.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'video', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'video', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Video.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'web', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'web', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Web.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'friends', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'friends', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Friends.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'galleries', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'galleries', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Comment.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'advanced', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'advanced', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Scan.png' width=16 height=16></a></td>\n" + 
			"<td onmouseover=\"this.style.background='#fbffb4';\" onmouseout=\"this.style.background='white';\"><a href='/' onclick=\"adminMenu.display( 'settings', xlib.eventGet( event ), 1 ); return false;\" title='' onmouseover=\"adminMenu.display( 'settings', xlib.eventGet( event ), 1 );\"><img src='/images/ico_Main.png' width=16 height=16></a></td>\n" + 
			"<td nowrap> &nbsp; Search: <input type=text class=smtxt id='wsearch' onKeyDown=\"btnDefault( xlib.eventGet( event ), 'wsearchE' )\" style='width:200;'></td>\n" + 
			"<td><a href='/' id='wsearchE' onclick=\"scrapplet.webSearch( domObject('wsearch').value ); return false;\"><img src='/images/ico_Find.png' width=16 height=16></a></td>\n" + 
			"</tr></table><br>\n" +
			
			"<table border=0 cellspacing=0 cellpadding=2 width=100% ><tr height=3><td></td></tr><tr valign=top>\n" + 
			"<td width=180><img src='/images/editKey.jpg' border=0 width=180 height=257>\n" +
			"</td><td style='padding:10; margin:0;'>\n" + 
			"<b>THREE EASY STEPS:</b><ol><li>Add objects to your page<br><br><li>Drag them around and resize them<br><br><li>Right-click objects to access their properties (Mac users control-left-click, Opera users alt-left-click)</ol>\n" +
			"<b>TIP</b>: Toggle the object toolbar from your pages using ALT-F2, toggle the menu bar from any page using F2.<br><br>\n" +
			"<b>TRICK</b>: Once you add an object to your Scrapplet page, use your left-mouse-button to move and resize the image. Hold the CTRL button to enable snap-to-grid, and the SHIFT button to maintain aspect ratio while resizing.<br><br>\n" +
		    "<center>" +
		    "<a href='/dashboard.htm' onclick=\"javascript:adminWindow( 'dashboard' ); return false;\">Dashboard</a> | \n" +
		  	"<a href='/pageRecommendations.htm' onclick=\"javascript:scrapplet.pageLoad( 'pgrec', 'Edit Page', '/pageRecommendations.htm', { UseButtons:0 } ); return false;\">Recommendations</a> | \n" +
//		  	"<a href='/tutorial.htm' onclick=\"javascript:scrapplet.pageLoad( 'quickStart', 'Scrapplet Tutorials', '/quickStart.htm', { UseButtons: 0 } ); return false;\">Tutorials</a> | \n" +
		    "<a href='/help.htm' onclick=\"javascript:scrapplet.pageLoad( 'help', 'Help', '/help.htm', { UseButtons: 0, w:700, h:480 } ); return false;\">Help</a> | " +
		  	"<a href='/techsupport' target='_top'>Support</a>" +
			"</center></td>\n" +
			"</tr></table>\n" +
		  	"<center><br><input type=checkbox onclick='adminMenu.pageEditMenuUpdate( );' id='OPT_PGEDIT_NODISPLAYHELP' " + ( scrapplet.userOptions & scrapplet.OPT_PGEDIT_NODISPLAYHELP ? "" : "checked" ) + "> Always display help when initially editing page</center>\n";
			

		w.create( );
		
		xlib.eventBind( w.obj, "mousedown", function( ) { adminMenu.close( ); return true; } );
		
		return( 1 );
	},

	display: function( name, e ) {
		var x, y, w, pt, margin, b=0, xBase=0, yBase=0;

		w = xWin( 'pgedit' );
		if ( w && ( w == this.curmenu ) ) {
			this.curmenu.bringtotop( );
			return;
		}

		if ( this.curmenu ) {
			xlib.eventUnbind( document, 'mousemove', adminMenuClose );
			xlib.intervalClear( this.timer );
			this.close( );
		}

		if ( e ) {
			pt = xlib.mousePos( e, 1 );
			x = pt.x;
			y = pt.y;
			if ( y < 30 ) {
				y = 30;
			}
			yBase = y;

			w = xWin( "pgedit" );
			if ( w ) {
				xBase = w.left;
				y = w.top + 52;
			}
		}
		
		if ( w && ( ! e )) {
			b = w.borderThickness( );
			x += w.left + b;
			y += w.top + b;
		}

		this.curmenu = w = new xWindow( name );

		w.style = WS_NORMAL | WS_MOVEABLE | WS_BORDER | WS_ALWAYSONTOP;
		w.bgColor = "#FFFFFF";
		w.borderColor = "#3b5998";
		w.issys = 1;
	
		menu = new xlib_MenuProperties( );
		menu.padding = 2;
		menu.spacing = 0;
		menu.offset = 4;
		menu.isSide = 0;
		menu.lineHeight = 21;
		menu.separator = xWinImageDir + "/dotGrayLight.gif";
		margin = " &nbsp;&nbsp; ";

		switch ( upper( name ) ) {
		  case "SYSTEM":
		  	x = xBase + 8;
			menu.add( margin + this.menuWithIcon( "/images/ico_PageAdd.png", "Add New Page" ), "", "scrapplet.pageWizard( );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_PageEdit.png", "Edit Different Page" ), "", "scrapplet.pageLoad( 'pageSelect', 'Select Page to Edit', '/pageSelect.htm' );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_PageDelete.png", "Delete Page" ), "", "scrapplet.pageLoad( 'pageDelete', 'Delete Scrapplet', '/pageDelete.htm', { UseButtons: 0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Restore.png", "Restore" ), "", "scrapplet.restore( );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Delete.png", "Clear" ), "", "scrapplet.clearall( );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Import.png", "Import" ), "", "scrapplet.pageLoad( 'pageImport', 'Import Scrapplet', '/pageImport.htm', { UseButtons: 0 } );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Export.png", "Export" ), "", "scrapplet.pageLoad( 'pageExport', 'Export Scrapplet', '/pageExport.htm', { UseButtons: 0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "/images/ico_DistroMash.png", "Share" ), "", "scrapplet.pageLoad( 'distroMash', 'DistroMash', '/distroMash.htm', { w:750, h:520 } );" );
			break;

		  case "TEXT":
		  	x = xBase + 80;
			menu.add( margin + this.menuWithIcon( "/images/ico_Text.png", "Text block" ), "", "scrapplet.objAdd( 'Text' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Headline" ), "", "scrapplet.objAdd( 'Text Headline' );" );
			menu.add( margin + this.menuWithIcon( "", "Caption" ), "", "scrapplet.objAdd( 'Text Caption' );" );
			menu.add( margin + this.menuWithIcon( "", "Footnote" ), "", "scrapplet.objAdd( 'Text Footnote' );" );
		  	break;

		  case "BACKGROUND":
		  	x = xBase + 98;
			menu.add( margin + this.menuWithIcon( "/images/ico_Image2.png", "Set background" ), "", "scrapplet.objAdd( 'Background' );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_View.png", "Background gallery" ), "", "scrapplet.galleryView( 'backgrounds' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Find.png", "Find backgrounds" ), "", "scrapplet.backgroundFind( );" );
		  	break;

		  case "PICTURES":
		  	x = xBase + 118;
			menu.add( margin + this.menuWithIcon( "/images/ico_Picture.png", "Add picture" ), "", "scrapplet.objAdd( 'Picture' );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Pictures.png", "Your pictures" ), "", "scrapplet.objAdd( 'Your Pictures' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Find.png", "Find pictures" ), "", "scrapplet.pictureFind( )" );
//			menu.add( margin + this.menuWithIcon( "/images/ico_Upload.png", "Upload pictures" ), "", "scrapplet.objAdd( 'Upload Pictures' );" );
		  	break;

		  case "MUSIC":
		  	x = xBase + 138;
			menu.add( margin + this.menuWithIcon( "/images/ico_Music.png", "Add music" ), "", "scrapplet.objAdd( 'Music' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Find.png", "Find music" ), "", "scrapplet.musicFind( );" );
//			menu.add( margin + this.menuWithIcon( "/images/ico_Upload.png", "Upload music" ), "", "scrapplet.objAdd( 'Upload Music' );" );
		  	break;

		  case "VIDEO":
		  	x = xBase + 158;
			menu.add( margin + this.menuWithIcon( "/images/ico_Video.png", "Add video" ), "", "scrapplet.objAdd( 'Video' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Find.png", "Find videos" ), "", "scrapplet.videoFind( );" );
//			menu.add( margin + this.menuWithIcon( "/images/ico_Upload.png", "Upload video" ), "", "scrapplet.objAdd( 'Upload Video' );" );
		  	break;

		  case "WEB":
		  	x = xBase + 178;
			menu.add( margin + this.menuWithIcon( "/images/ico_Web.png", "Websites" ), "", "scrapplet.objAdd( 'Website' );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Feed.png", "Feeds" ), "", "scrapplet.objAdd( 'Feed' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Find.png", "Search the web" ), "", "scrapplet.webSearch( );" );
			menu.add( margin + this.menuWithIcon( "", "Search box" ), "", "scrapplet.webSearchBox( );" );
		  	break;

		  case "FRIENDS":
		  	x = xBase + 198;
			menu.add( margin + this.menuWithIcon( "/images/ico_Friends.png", "Your friends" ), "", "scrapplet.objAdd( 'Friends' );" );
			menu.add( "-", "" );
//			menu.add( margin + this.menuWithIcon( "", "Friends list" ), "", "scrapplet.objAdd( 'FriendsList' );" );
			menu.add( margin + this.menuWithIcon( "", "Thumbnails" ), "", "scrapplet.objAdd( 'FriendsThumbnails' );" );
		  	break;

		  case "GALLERIES":
		  	x = xBase + 218;
			menu.add( margin + this.menuWithIcon( "", "Your galleries (0)" ), "", "scrapplet.objAdd( 'GalleriesYours' );" );
			menu.add( "-", "" );
//			menu.add( margin + this.menuWithIcon( "", "Buttons" ), "", "scrapplet.galleryView( 'buttons' );" );
//			menu.add( margin + this.menuWithIcon( "", "Frames" ), "", "scrapplet.galleryView( 'frames' );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_View.png", "Backgrounds" ), "", "scrapplet.galleryView( 'backgrounds' );" );
			menu.add( margin + this.menuWithIcon( "/images/ico_Window.png", "Windows" ), "", "scrapplet.galleryView( 'windows' );" );
//			menu.add( margin + this.menuWithIcon( "/images/ico_Comment.png", "Balloons" ), "", "scrapplet.galleryView( 'ballons' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Get more..." ), "", "scrapplet.objAdd( 'GalleriesGet' );" );
		  	break;

		  case "ADVANCED":
		  	x = xBase + 238;
			menu.add( margin + this.menuWithIcon( "", "Rich Content" ), "", "scrapplet.loadRichDrop( );" );
			menu.add( margin + this.menuWithIcon( "", "Paste" ), "", "scrapplet.objAdd( 'Paste' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "HTML" ), "", "scrapplet.objAdd( 'HTML' );" );
			menu.add( margin + this.menuWithIcon( "", "Widgets" ), "", "scrapplet.objAdd( 'Widget' );" );
			menu.add( margin + this.menuWithIcon( "", "Flash" ), "", "scrapplet.objAdd( 'Flash' );" );
			menu.add( margin + this.menuWithIcon( "", "Map" ), "", "adminMenu.mapCreate( );" );
			menu.add( margin + this.menuWithIcon( "", "Script" ), "", "scrapplet.objAdd( 'Script' );" );
			menu.add( margin + this.menuWithIcon( "", "Documents" ), "", "scrapplet.objAdd( 'Docs' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Animation" ), "", "scrapplet.pageLoad( 'objanim', 'Object animation', '/objAnimation.htm', { UseButtons:1 } );" );
			menu.add( margin + this.menuWithIcon( "", "Navigation" ), "", "scrapplet.objAdd( 'Navagation' );" );
			menu.add( margin + this.menuWithIcon( "", "Guestbook" ), "", "adminMenu.guestbookCreate( );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Clear all" ), "", "scrapplet.clearall( );" );
		  	break;

		  case "SETTINGS":
		  	x = xBase + 258;
			menu.add( margin + this.menuWithIcon( "", "Object Gallery" ), "", "scrapplet.pageLoad( 'objGal', 'Object Gallery', '/objGallery.htm', { UseButtons: 1 } );" );
			menu.add( margin + this.menuWithIcon( "", "Your Object Repository" ), "", "scrapplet.pageLoad( 'pageobj', 'Your Object Repository', '/objRepository.htm?myscope=All+My+Objects' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Page properties" ), "", "adminMenu.pageProperties( );" );
			menu.add( margin + this.menuWithIcon( "", "Page objects" ), "", "scrapplet.pageLoad( 'pageobj', 'Page Objects', '/pageObjects.htm' );" );
			menu.add( margin + this.menuWithIcon( "", "Page tags" ), "", "scrapplet.pageLoad( 'Tags', 'Tags', '/pageTags.htm' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Page recommendations" ), "", "scrapplet.pageLoad( 'pgrec', 'Page Recommendations', '/pageRecommendations.htm', { UseButtons:0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Data Portability" ), "", "scrapplet.pageLoad( 'dp', 'Data Portability', '/dataPortability.htm', { UseButtons:0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Search engine visibility" ), "", "scrapplet.pageLoad( 'seo', 'Search Engines', '/pageSEO.htm', { UseButtons:0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Object animation" ), "", "scrapplet.pageLoad( 'objanim', 'Object animation', '/objAnimation.htm', { UseButtons:1 } );" );
		  	break;


		  case "DASHBOARD":
		  	x = 54;
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "My Dashboard" ), "", "adminWindow( 'dashboard' );" );
			menu.add( margin + this.menuWithIcon( "", "My Scrapplets" ), "", "adminWindow( 'main' );" );
			menu.add( margin + this.menuWithIcon( "", "My Favorites" ), "", "adminWindow( 'favorites' );" );
			menu.add( margin + this.menuWithIcon( "", "My Friends" ), "", "adminWindow( 'myfriends' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "My home page" ), "", "document.location= '/" + scrapplet.userId + "'" );
		  	break;

		  case "PAGES":
		  	x = 128;
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "Site map" ), "", "scrapplet.userSitemap('" + scrapplet.pgowner + "');" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Page Properties" ), "", "adminMenu.pageProperties( );" );
			menu.add( margin + this.menuWithIcon( "", "Background" ), "", "scrapplet.objAdd( 'Background' );" );
			menu.add( margin + this.menuWithIcon( "", "Tags" ), "", "scrapplet.pageLoad( 'Tags', 'Tags', '/pageTags.htm' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Add" ), "", "scrapplet.pageWizard( );" );
			menu.add( margin + this.menuWithIcon( "", "Copy" ), "", "scrapplet.pageLoad( 'pageCopy', 'Copy Scrapplet Page', '/pageCopy.htm', { UseButtons: 0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Delete" ), "", "scrapplet.pageLoad( 'pageDelete', 'Delete Scrapplet', '/pageDelete.htm', { UseButtons: 0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Templates" ), "", "scrapplet.pageLoad( 'pgtemp', 'Page Templates', '/pageGallery.htm', { w:700, h:500 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Import" ), "", "scrapplet.pageLoad( 'pageImport', 'Import Scrapplet', '/pageImport.htm', { UseButtons: 0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Export" ), "", "scrapplet.pageLoad( 'pageExport', 'Export Scrapplet', '/pageExport.htm', { UseButtons: 0 } );" );
//			menu.add( margin + this.menuWithIcon( "", "Embed" ), "", "xlib.browserNew( -1, -1, 800, 600, 'pageembed', 'pageEmbed', 'POPUP' )" );
			menu.add( margin + this.menuWithIcon( "", "Distribute" ), "", "scrapplet.pageLoad( 'distroMash', 'Page Distribution', '/distroMash.htm', { w:750, h:520 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Ratings" ), "", "scrapplet.pageLoad( 'rate', 'Rate this Scrapplet page', '/pageRate.htm', { UseButtons:1, left:10, top:65, displayMode:0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Recommendations" ), "", "scrapplet.pageLoad( 'pgrec', 'Page Recommendations', '/pageRecommendations.htm', { UseButtons:0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Search engines (SEO)" ), "", "scrapplet.pageLoad( 'seo', 'Search Engine Optimization', '/pageSEO.htm', { UseButtons:0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Restore" ), "", "scrapplet.restore( );" );
		  	break;

		  case "OBJECTS":
		  	x = 175;
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "Toolbar" ), "", "pageEdit( );" );
			menu.add( margin + this.menuWithIcon( "", "Object Gallery" ), "", "scrapplet.pageLoad( 'objGal', 'Object Gallery', '/objGallery.htm', { UseButtons: 1 } );" );
			menu.add( margin + this.menuWithIcon( "", "Object Repository" ), "", "scrapplet.pageLoad( 'pageobj', 'Your Object Repository', '/objRepository.htm?myscope=All+My+Objects' );" );
			menu.add( margin + this.menuWithIcon( "", "Objects on Page" ), "", "scrapplet.pageLoad( 'pageobj', 'Objects on Page', '/pageObjects.htm' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Paste" ), "", "scrapplet.objAdd( 'Paste' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "HTML" ), "", "scrapplet.objAdd( 'HTML' );" );
			menu.add( margin + this.menuWithIcon( "", "Widget" ), "", "scrapplet.objAdd( 'Widget' );" );
//			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Text" ), "", "scrapplet.objAdd( 'Text' );" );
			menu.add( margin + this.menuWithIcon( "", "Button" ), "", "scrapplet.objCreate( 'fbLinkButton', 'click me!', '/faq.htm' );" );
			menu.add( margin + this.menuWithIcon( "", "Picture/image" ), "", "scrapplet.objAdd( 'Picture' );" );
			menu.add( margin + this.menuWithIcon( "", "Website/page" ), "", "scrapplet.objAdd( 'Website' );" );
			menu.add( margin + this.menuWithIcon( "", "News Feed" ), "", "scrapplet.objAdd( 'Feed' );" );
			menu.add( margin + this.menuWithIcon( "", "Music" ), "", "scrapplet.objAdd( 'Music' );" );
			menu.add( margin + this.menuWithIcon( "", "Video" ), "", "scrapplet.objAdd( 'Video' );" );
			menu.add( margin + this.menuWithIcon( "", "Map" ), "", "adminMenu.mapCreate( );" );
			menu.add( margin + this.menuWithIcon( "", "Guestbook" ), "", "adminMenu.guestbookCreate( );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Clear all" ), "", "scrapplet.clearall( );" );
		  	break;

		  case "USERS":
		  	x = 231;
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "Activities" ), "", "scrapplet.pageLoad( 'friend', 'User Activities / Info', '/friend.htm?userid=" + scrapplet.userId + "', { UseButtons:0, left:10, top:65, displayMode:0, w:600, h:440 } );" );
			menu.add( margin + this.menuWithIcon( "", "Links" ), "", "scrapplet.pageLoad( 'links', 'User Links/Networks', '/userLinks.htm', { UseButtons:0, left:10, top:65, displayMode:DISP_NOPROGRESS } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Send message" ), "", "scrapplet.pageLoad( 'msgSend', 'Send Message', '/msgSend.htm', { UseButtons:1, left:10, top:65, displayMode:0, w:600, h:440 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "View guestbook" ), "", "adminMenu.guestbookCreate( );" );
			menu.add( margin + this.menuWithIcon( "", "Sign guestbook" ), "", "scrapplet.pageLoad( 'gbadd', 'Add Guestbook Message', '/guestbookAdd.htm?pgowner=" + scrapplet.pgowner + "&pgid=" + scrapplet.pgid + "', { UseButtons: 1 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "My Friends" ), "", "adminWindow( 'myfriends' );" );
		  	break;

		  case "TOOLS":
		  	x = 275;
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "File Manager" ), "", "scrapplet.fileManager( );" );
			menu.add( margin + this.menuWithIcon( "", "Rich Content" ), "", "scrapplet.loadRichDrop( );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Navigation" ), "", "scrapplet.objAdd( 'Navagation' );" );
			menu.add( margin + this.menuWithIcon( "", "Tag Cloud" ), "", "scrapplet.pageLoad( 'tags', 'Tag Cloud', '/tags.htm', { UseButtons:0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Animation" ), "", "scrapplet.pageLoad( 'objanim', 'Object animation', '/objAnimation.htm', { UseButtons:1 } );" );
//			menu.add( margin + this.menuWithIcon( "", "Objects on page" ), "", "scrapplet.pageLoad( 'pageobj', 'Objects on Page', '/pageObjects.htm' );" );
			menu.add( "-", "" );
//			menu.add( margin + this.menuWithIcon( "", "Tags" ), "", "scrapplet.pageLoad( 'tags', 'Tags', '/tags.htm', { UseButtons:0 } );" );
//			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Data Portability" ), "", "scrapplet.pageLoad( 'dp', 'Data Portability', '/dataPortability.htm', { UseButtons:0 } );" );
			menu.add( margin + this.menuWithIcon( "", "OpenAjax Hub Console" ), "", "scrapplet.pageLoad( 'oa', 'OpenAjax Hub Console', '/oaConsole.htm', { UseButtons:0, w:750, h:520 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "UserID/Password Encoder" ), "", "scrapplet.objCreate( 'authencode' );" );
			menu.add( margin + this.menuWithIcon( "", "uuEncode/Decode" ), "", "scrapplet.pageLoad( 'uuEncDec', 'uuEncode / Decode', '/utilEncodeDecode.htm', { UseButtons:0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Object Queue" ), "", "scrapplet.pageLoad( 'regobj', 'Current Object Queue', '/objQueue.htm', { UseButtons:0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "HTML Characters" ), "", "xlib.browserNew( -1, -1, 800, 600, '_blank', 'http://www.ascii.cl/htmlcodes.htm' );" );
			menu.add( margin + this.menuWithIcon( "", "HTML Colors" ), "", "xlib.browserNew( -1, -1, 800, 600, '_blank', 'http://en.wikipedia.org/wiki/Web_colors' );" );
			menu.add( margin + this.menuWithIcon( "", "HTML Styles" ), "", "xlib.browserNew( -1, -1, 800, 600, '_blank', 'http://www.w3schools.com/Html/html_styles.asp' );" );
		  	break;

		  case "TOOLS2":
		  	x = 333;
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "File Manager" ), "", "scrapplet.fileManager( );" );
			menu.add( margin + this.menuWithIcon( "", "Tag Cloud" ), "", "scrapplet.pageLoad( 'tags', 'Tag Cloud', '/tags.htm', { UseButtons:0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "OpenAjax Hub Console" ), "", "scrapplet.pageLoad( 'oa', 'OpenAjax Hub Console', '/oaConsole.htm', { UseButtons:0, w:750, h:520 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "UserID/Password Encoder" ), "", "scrapplet.objCreate( 'authencode' );" );
			menu.add( margin + this.menuWithIcon( "", "uuEncode/Decode" ), "", "scrapplet.pageLoad( 'uuEncDec', 'uuEncode / Decode', '/utilEncodeDecode.htm', { UseButtons:0 } );" );
//			menu.add( margin + this.menuWithIcon( "", "Object Queue" ), "", "scrapplet.pageLoad( 'regobj', 'Current Object Queue', '/objQueue.htm', { UseButtons:0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "HTML Characters" ), "", "xlib.browserNew( -1, -1, 800, 600, '_blank', 'http://www.ascii.cl/htmlcodes.htm' );" );
			menu.add( margin + this.menuWithIcon( "", "HTML Colors" ), "", "xlib.browserNew( -1, -1, 800, 600, '_blank', 'http://en.wikipedia.org/wiki/Web_colors' );" );
			menu.add( margin + this.menuWithIcon( "", "HTML Styles" ), "", "xlib.browserNew( -1, -1, 800, 600, '_blank', 'http://www.w3schools.com/Html/html_styles.asp' );" );
		  	break;

		  case "EXPLORE":
		  case "EXPLORE2":
		  	x = upper( name ) == "EXPLORE" ? 365 : 420;
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "Explore users, pages, & tags" ), "", "document.location='/explore.htm';" );
			menu.add( margin + this.menuWithIcon( "", "Explore all-stars" ), "", "document.location='/allstars.htm';" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "What's new" ), "", "document.location='/Content/whatsnew.htm';" );
			break;

		  case "MYACCOUNTMENU":
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "<i>" + scrapplet.userName + "</i>" ), "", "" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "My home page" ), "", "document.location= '/" + scrapplet.userId + "'" );
			menu.add( margin + this.menuWithIcon( "", "Dashboard" ), "", "adminWindow( 'dashboard' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Profile" ), "", "adminWindow( 'myaccount', 'profile' );" );
			menu.add( margin + this.menuWithIcon( "", "Preferences" ), "", "adminWindow( 'myaccount', 'preferences' );" );
			menu.add( margin + this.menuWithIcon( "", "Networks" ), "", "adminWindow( 'myaccount', 'networks' );" );
			menu.add( margin + this.menuWithIcon( "", "Platforms" ), "", "adminWindow( 'myaccount', 'platforms' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Points" ), "", "scrapplet.pageLoad( 'points', 'Scrapplet Points', '/points.htm' );" );
			menu.add( margin + this.menuWithIcon( "", "Stats" ), "", "scrapplet.pageLoad( 'stats', 'Scrapplet Stats', '/stats.htm' );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Logout" ), "", "scrapplet.logout( );" );
		  	break;

		  case "HELPMENU":
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "Main help" ), "", "scrapplet.pageLoad( 'help', 'Help', '/help.htm', { UseButtons:0, w:700, h:480 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "FAQ" ), "", "scrapplet.pageLoad( 'faq', 'FAQ', '/faq.htm', { UseButtons: 0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Support" ), "", "document.location='/TechSupport';" );
			menu.add( margin + this.menuWithIcon( "", "Tutorial" ), "", "scrapplet.pageLoad( 'quickStart', 'Scrapplet Tutorials', '/quickStart.htm', { UseButtons: 0 } );" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "About" ), "", "scrapplet.pageLoad( 'about', 'About Scrapplet', '/about.htm', { UseButtons: 0 } );" );
		  	break;

		  case "MOREMENU":
		  	y = 27;
			menu.add( margin + this.menuWithIcon( "", "Scrapplet Home" ), "", "document.location= '/';" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Business" ), "", "document.location= '/content/business';" );
			menu.add( margin + this.menuWithIcon( "", "Hosting" ), "", "document.location= '/content/hosting';" );
			menu.add( margin + this.menuWithIcon( "", "Press" ), "", "document.location= '/content/press';" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "What's New!" ), "", "document.location='/content/whatsnew.htm';" );
			menu.add( margin + this.menuWithIcon( "", "Latest news" ), "", "scrapplet.pageLoad( 'lnews', 'Latest News', '/news.htm', { UseButtons: 0 } );" );
			menu.add( margin + this.menuWithIcon( "", "Tour" ), "", "document.location='/content/tour/index.htm';" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "RadWebTech" ), "", "top.document.location= 'http://www.radwebtech.com';" );
			menu.add( margin + this.menuWithIcon( "", "xWinLib" ), "", "top.document.location= 'http://www.xwinlib.com';" );
			menu.add( "-", "" );
			menu.add( margin + this.menuWithIcon( "", "Developers" ), "", "document.location= '/content/developers';" );
		  	break;

		}

		width = 180;
		height = menu.calcHeight( );

		pt = xlib.winAdjustPos( x, y, width, height, 10 );
		x = pt.x;
		y = pt.y;

		w.setposition( x, y, width, height );
		w.action = menu.render( );
		w.create( );
		xlib.menuCurrentSet( w );

		this.timer = xlib.intervalSet( "adminMenuClose( );", this.timerDelay );
	},
	
	menuWithIcon: function( icon, text ) {
		if ( strempty( icon ) ){
			return( text );
		}
		return( "<img src='" + icon + "' border=0 width=15 height=15> &nbsp; <span style='position:relative; top:-2;'>" + text + "</span>" );
	},
	
	close: function( ) {
		if ( this.timer ) {
			xlib.intervalClear( this.timer );
			this.timer = null;
		}
		if ( this.curmenu ) {
			xlib.eventUnbind( document, 'mousemove', adminMenuClose );
			this.curmenu.destroy( );
			this.curmenu = null;
		}
	},

	guestbookCreate: function( ) {
		var win = xlib.objLookup( "guestbook" );
		win.left = 15;
		win.top = 70;
		win.create( );
	},

	mapCreate: function( ) {
		var win = xlib.objLookup( "map" );
		win.left = 15;
		win.top = 70;
		win.create( );
	},

	pageProperties: function( ) {
		if ( xlib.UpdateFlag( ) ) {
			if ( confirm( "Changes detected, click OK to save or CANCEL to continue without saving." ) ) {
				scrapplet.save( );		
				xlib.UpdateFlag( 0 );
			}
		}
		scrapplet.pageLoad( 'pageProperties', 'Page Properties', '/pageProperties.htm', { displayMode: DISP_CENTERED, w:620, h:460 } );
	}
	
};


function adminMenuClose( e ) {
	if ( ! ( xMouseE && xMouseE.win && ( xMouseE.win.name == adminMenu.curmenu.name ) ) ) {
		adminMenu.close( );
	}
}

function adminWindow( winname, subpage ) {
	var w;
	
	if ( subpage == null ) {
		subpage = "";
	}
	
	w = xWin( 'admin' );
	if ( w ) {
		o = domObject( "admin_iframe" );
		if ( o ) {
			if ( strati( "/" + winname + ".", o.src ) ) {
				w.destroy( );
			}
			else {
				o.src = "/" + winname + ".htm";
			}
			return;
		}
		w.destroy( );
	}
	scrapplet.pageLoad( 'admin', 'Scrapplet Administration', '/' + winname + '.htm' + ( strempty( subpage ) ? "" : "?curpage=" + subpage ), { UseButtons:0, w:750, h:520 } );
}

	
var adminMenu = new adminNavMenu( );


