
/*
	Engine for Web Applications
	Composite file "engcomp.js" release: 1.2.32.2207.2004
	Copyright 2002 - 2004. All Rights Reserved.
	Rights to copy, archive, distribute, or alter this software are described in the license.
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	Project: http://www.whitefrost.com/projects/engine/
	License: http://www.whitefrost.com/projects/engine/code/engine.license.txt
*/

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

/*
	Package Functions
*/

var $EPS=[],$EPI=[],$EPV="1.1.1.2207.2004";

var D = {
	S:"string",
	O:"object",
	F:"function",
	U:"undefined",
	N:"number"
/*	XSLTPROCESSOR:XSLTProcessor*/
	
};

var data_undefined;

D.X = (typeof XMLHttpRequest != D.U?XMLHttpRequest:data_undefined);
D.A = (typeof ActiveXObject != D.U?ActiveXObject:data_undefined);

function $EP(c){
	var a,i=0,s,w=window,o,l;
	o = w;
	if(typeof c==D.S){
		if(!$EPI[c]){
			l = $EPS.length;
			$EPI[c]=l;
			$EPS[l]=c;
		}
		a = c.split(".");
		for(;i<a.length;){
			s=a[i++];
			if(typeof o[s] != D.O) o[s]={};
			o = o[s];
		}
	}
}

function GetPackage(c){
	return ValidatePackage(c,1);
}

function ValidatePackage(c,b){
	var a,i=0,s,w=window,o,l;
	o = w;
	if(typeof c == D.S){
		a = c.split(".");
		l = a.length;
		if(l==0) return 0;
		for(;i<l;){
			s=a[i++];
			if(typeof o[s] != D.O) return 0;
			o = o[s];
		}
	}
	else{
		return 0;
	}
	if(b) return o;
	return 1;
}


function Package(c){
	$EP(c);
}



/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E");


/*
	package $E
*/
$E={
	ci:{},
	gc:0,
	v:"1.1.14.2207.2004",


	h:function(s){
		var i = c = 0;
		for(; s && i < s.length; ++i){
			c = (c + s.charCodeAt(i) * (i + 1)) & 0xFFFFFFFF;
		}
		return c.toString(16);
	},
	gnbid:function(){
		var d = new String(parseInt(Math.random() * 9999)).toString();
		for(i = d.length; i < 4; i++) d = "0" + d;
		return d;
	},
	guid:function(){
		var _j = $E;
		var i = _j.gnbid() + "-" + _j.gnbid();
		var d = _j.h(new String(new Date().getTime()).toString())
				+ "-" + _j.h(location.href)
				+ "-" + i
			;
		return d;
	},
	
	merge:function(o,n,s){
		/*
			o = object
			n = name
			s = string data
		*/
		var _j = $E;
		/* add string data to class imports */
		_j.ci[n] = s;
		/* implement import onto object */
		_j.IM(o,n);
	
	}
	
};

$E.GG=function(){

	var d=new Date(),t,i=4,r,l,x=0;
	t=new String(d.getTime());
	r=new String(parseInt(Math.random() * (1000 * i)));
	l=r.length;
	for(;x <i - l;x++) r="0" + r;
	return ( "swc-" + (++$E.gc) + "-" + t + "-" + r);

/*	return ("swc-" + $E.guid());*/
}

$E.IM=function(o,s){
	var _js = $E,v,a=arguments,i;

	/*
		big hack here, but I don't want to include o, I don't want it to be an eval,
		and apply requires the argArray param to be the arguments object
	*/
	
	var n_a = [];
	for(i=1;i<a.length;i++)
		n_a[n_a.length] = a[i];
	
	/*
		According to the references, this should break because n_a is not the arguments object
	*/
	v = _js.FN.apply(this.caller,n_a);
	
	if(
		typeof o == D.O
		&&
		typeof v == D.O
	){
		for(i in v)
			o[i]=v[i];
		
	}
};

$E.FN=function(s){
	var _js=$E,v,a=arguments;
	if(typeof _js.ci[s]==D.S){
		eval("v=" + _js.ci[s]);
		return v;
	}
	switch(s){
		case "code_object":
			return {

				code_name:a[1],
				/* request_ok */
				ro:a[2],
				/* request_notok */
				rno:a[3],
				/* response_ok */
				po:a[4],
				/* response_notok */
				pno:a[5],
				description:a[6]

			};
			break;
		case "service_object":
			return {
				service_id:$E.GG(),
				service_name:a[1],

				service_state:0,
				rc:a[2],
				pc:0,
				rd:0,
				pd:0,
				getResponseData:function(){return this.pd;},
				code_name:a[3],
				handler:a[4],
				request_handler:a[5],
				response_handler:a[6],
				completed:0
			};
			break;

		case "engine_object":
			return {
				engine_element:a[1],
				engine_id:a[2],
				engine_name:a[3],
				engine_index:a[5],
				config_name:0,
				task:a[4],
				is_primary:0,
				eo:[],
				en:[],
				ei:[],
				
				
				engine_implementations:[],
				
				
				getContainer:function(){return this.engine_element;},
				getObjects:function(){return this.eo;},
				getObject:function(i){if(typeof this.ei[i] == D.N && typeof this.eo[this.ei[i]]==D.O){return this.eo[this.ei[i]];}return 0;},
				isObject:function(n){if(typeof n == D.S &&	typeof this.en[n] == D.N && typeof this.eo[this.en[n]] == D.O){return 1;}return 0;},
				getObjectByName:function(n){if(typeof n == D.S && typeof this.en[n] == D.N && typeof this.eo[this.en[n]] == D.O){return this.eo[this.en[n]];}return 0;},
				pw:[],
				getPrimitiveWire:function(i){if(typeof i == D.S && typeof this.pw[i] != D.U) return this.pw[i];return 0;},
				ds:0,
				setDataSource:function(s){this.ds = s;},
				getDataSource:function(){return this.ds;},
				dp:0,
				setDataPath:function(s){this.dp = s;},
				getDataPath:function(){return this.dp;},
				data_variant:[],
				setDataVariant:function(i,v){if(typeof i == D.N){this.data_variant[i] = v;return 1} return 0;},
				getDataVariant:function(i){if(typeof i == D.N && typeof this.data_variant[i] != D.U){return this.data_variant[i];} return 0;}

			};		
			break;
/*	
		case "web_service_object":
			return {
				service_id:$E.GG(),
				service_name:a[1],
				wsdl_url:a[2],
				wsdl_state:0,
				wsdl_xml:0,
				wsdl_imports:[],
				wsdl_import_count:0
			};
			break;

		case "bootstrap_object":
*/
		case "task_object":
			return {
				task_state:0,
				handled:0,
				task_name:a[1],
				action_type:a[2],
				action:a[3],
				handler_type:a[4],
				handler:a[5],
				task_id:a[6],
				index:a[7],
				transaction_id:a[8],
				data:0,
				depends:[],
				executed:0,
				busy:0,
				ad:0,
				parent_id:0,
				setAutoDestroy:function(b){this.ad = (b?1:0);}
				
				
			};
			break;
/*
		case "event_object":
			return {
				event_name:a[1],
				target:a[2]
			};
			break;

		case "event_listener":
			return {
				object:a[1],
				event_name:a[2],
				function_pointer:a[3],
				target:a[4]
			};
			break;
*/
		case "base_object":
			return{
				i:$E.GG(),
				getObjectId:function(){return this.i;},
				t:a[1],
				getObjectType:function(){return this.t;},
				v:a[2],
				getObjectVersion:function(){return this.v;},
				r:0,
				getReadyState:function(){return this.r;},
				getStatus:function(){return this.o.s;},
				getPointers:function(){return this.o.p;}
			};
			break;

		case "basic_message":
			return {
				entry:a[1],
				index:-1,
				data:a[2],
				time:new Date(),
				id:_js.GG()
			};
			break;
		case "basic_message_subscription":
			return {
				object:a[1],
				subscription_name:a[2],
				handler:a[3],
				target:a[4]
			};
			break;
		case "packet_object":
			return {
				packet_id:a[1],
				packet_name:a[2],
				participants:[],
				participant_count:0,
				packet_state:0,

				/*block_start applies only when an owner_id is specified*/
				bst:0,
				btt:0,
				bet:0,
				/*
					serve_type

						1 = (default) can be served to a participant until it returns true
							endTransaction is called when all are true

						2 = can be served to a participant only once
							endTransaction is called immediately
				*/
				serve_type:1,

				setBlockStartTransaction:function(b){this.bst = (b?1:0);},
				setBlockServeTransaction:function(b){this.btt = (b?1:0);},
				setBlockEndTransaction:function(b){this.bet = (b?1:0);},
				setServeType:function(i){this.btt = (!isNaN(i)?i:0);},
				/* timestamp */
				st:0,
				/* timestamp */
				sp:0,
				
				is_open:0,
				is_finalized:0,
				errors:0,
				owner_id:a[3],
				data:a[4],
				handler:a[5]
			};
			break;
/*
		case "generic_object":
			return {
				parent_object:0,
				child_objects:[],
				child_objects_index:{},
				r:0,
				top_object:0,
				layout_manager:0,
				style_manager:0,
				object_debug:function(){
					alert(this.i);
				},
				o:{
					p:{},
					style_names:{},
					event_handlers:[],
					internal_event_listeners:[],
					dom_event_listeners:[]
				}
			};
*/
			break;
		default:
/*			alert("skip: " + s);*/
			break;
/*
		case "basic_message_publication":
			return {
				subscription_name:a[1],
				data:a[2]
			};
			break;
*/
	}
	return null;
}
/*
$E.IM($E._application_scope,"base_object","application_scope","0.1");
$E._application_scope.add_object($E._application_scope);
*/
		
		
			

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.dom");
$E.dom.event={
	v:"0.0.6.2207.2004",
	_gevt:function(o){
		return (typeof event == D.O)?event:o;
	},
	_gevt_cancel:function(o){
		(typeof o.preventDefault != D.F)?(o.returnValue=false):o.preventDefault();
	},
	_gevt_dest:function(e){
/*
		var s=$E.dom.event._gevt(o);
		if(s==null){
			$E.event.api.EventFactory.log("Bad event reference","515.3",1);
			return s;
		}
*/
		return (e.relatedTarget)?e.relatedTarget:e.toElement;	
	},
	_gevt_org:function(e){
		return (e.relatedTarget)?e.relatedTarget:e.fromElement;	
	},

	_gevt_src:function(o){
		var s=$E.dom.event._gevt(o);
		if(s==null){
			$E.message.MessageService.S("Bad event reference","515.3",1);
			return o;
		}
		return (s.target)?s.target:s.srcElement;
	},

	
	addEventBuffer:function(o){
		var e = "createHandler";
	/*				if(typeof window[o.i] != D.O) $E.dom.api(o);*/
		try{
			o[e]=function(s,r,x,l){
				var b = (typeof r == D.O && r!=null?1:0),t=this,e,h,f;
				r = (b)?r:t;
				e = "_prehandle_" + s;
				
				/* reset b to determine how the event handler retrieves the object reference*/
				b = (l?1:0);
				h = 
					"f=function(){\n"
					+ "try{\n"
					+ "var o="+ (b?'$E.registry.ObjectRegistry.getObject(\"' + r.i + '\")':"this") + ";\n"
/*
					+ "if(typeof o!=\"object\")return;\no._handle_" + s + "(arguments[0]);"
*/
/*if(!$E.util.driver.ApplicationDriver*/
					+ "if(typeof o!=\"object\" || o == null){alert('Object is invalid');return;}\nreturn o._handle_" + s + ".apply(o,arguments);"
					+ "}\ncatch(e){ alert(r.i + \"::\" + s + \"::\" + (e.description?e.description:e.message));}\n"
					+ "}"
				;
				eval(h);
				if(!x) t[e] = f;
				return f;
			};
		}
		catch(e){
			alert("Error: " + e.description);
		}
	},
	
	
	

	addEventListener:function(o,e,f,b){

		/*
			o = object
			e = event name
			f = function pointer
			b = trap
		*/
		if(typeof o.addEventListener != D.U){
			o.addEventListener(e,f,b);
		}
		else if(typeof o.attachEvent != D.U){
			o.attachEvent("on" + e,f);
		}
/*
		var c = $E.dom.browser.client;

		switch(c.bswitch){
			case 1:
				o.attachEvent("on" + e,f);
				break;
			case 2:
				o.addEventListener(e,f,b);
				break;		
		}
*/
	},
	
	removeEventListener:function(o,e,f,b){
		if(typeof o.removeEventListener != D.U){
			o.removeEventListener(e,f,b);
		}
		else if(typeof o.detachEvent != D.U){
			o.detachEvent("on" + e,f);
		}
/*
		var c = $E.dom.browser.client;
		switch(c.bswitch){
			case 1:
				o.detachEvent("on" + e,f);
				break;
			case 2:
				o.removeEventListener(e,f,b);
				break;		
		}
*/
	},
	
	getAbsoluteTop:function(o){
		return $E.dom.event.getAbsolutePosition(o,1);
	},
	getAbsoluteLeft:function(o){
		return $E.dom.event.getAbsolutePosition(o,0);
	},
	
	getAbsolutePosition:function(o,b){
		var c=o,i=0;

		while(c != null && !c.nodeName.match(/body/i)){
			i += (b?(c.offsetTop?c.offsetTop:0):(c.offsetLeft?c.offsetLeft:0));
			c = c.offsetParent;
		}
		return i;
	}
}


/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2003, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.thread");
$E.thread={
	newInstance:function(o){

		/*
			o = reference object
		*/
		
		if(!$E.registry.ObjectRegistry.isRegistered(o)){
			$E.message.MessageService.S("Object must be registered to use a thread.","200.4",1);
			return 0;
		}

		var n = $E.FN("base_object","thread","1.1.0.2207.2004");

		n.o = {
	
			s:{
				r:"handle_thread_run",
				s:"handle_thread_start",
				t:"handle_thread_stop",
				d:"1000",
				i:0,
				m:0,
				/* z = object's id */
				z:o.i,

				/*
					y = all stop; some error happened and everything should grind to a halt
					
					There is no recovery from All Stop.  The object is frozen once this happens.
				*/
				y:0
			},
			
			p:{
				o:o
			}
	
		};
	
		n.run = function(d){
			var t = this, _s;
			_s = t.o.s;
			if(!t.getIsRunnable() || _s.i) return 0;
			
			if(typeof d != D.N || d < 0) d = _s.d;
			
			/* m = 1; interval */
			_s.m = 1;
/*			_s.i = window.setInterval(t.R,d);*/
			
			if(typeof t.o.p.o[_s.s] == D.F) t.o.p.o[_s.s](t);
			
			_s.i = window.setInterval("$E.registry.ObjectRegistry.getObject('" + t.i + "').R()",d);
			return 1;
		};
	
		n.R = function(){
			var t = this, _s, _p, _m = $E.message.MessageService;
			_s = t.o.s;
			_p = t.o.p;

			/*
				If there is no interval/timer value, or the thread is in All Stop mode, then just return
			*/
			if(!_s.i || _s.y) return 0;
			
			if(typeof _p.o == D.O && _p.o.r > 4){

				
				_m.S("Thread " + t.i + " for " + _s.z + " was stopped as the object is in termination mode.","200.4");
				
				if(!t.stop()){
					_s.y = 1;
					
					_m.S("Thread would not stop.  All Stop now effective","200.4");
					
				}
				return 0;
			}
			
			try{
				_p.o[_s.r](t);
				if(_s.m == 2){
					_s.i = 0;
					_s.m = 0
				}
			}
			catch(e){
				/* if an interval */
				if(_s.m == 1){
					window.clearInterval(_s.i);
				}
				_s.i = 0;
			}
			
			return 1;
		};

		n.allStop = function(){
			this.o.s.y = 1;
			this.stop();
		};
		
		n.stop = function(){
			var t = this, _s;

			_s = t.o.s;
			if(!_s.i) return 0;
			/* if it's a timeout */
			if(_s.m == 2){
				window.clearTimeout(_s.i);
			}
			else if(_s.m == 1){
				window.clearInterval(_s.i);
			}
			else{
				/* return 0 here because 'm' is an unexpected state */
				return 0;
			}

			if(typeof t.o.p.o[_s.t] == D.F) t.o.p.o[_s.t](t);
			
			_s.m = 0;
			_s.i = 0;
			return 1;
		};
		
		n.getIsRunning = function(){
			if(this.o.s.i) return 1;
			return 0;
		};
		
		n.getIsRunnable = function(){
			var _c = this.o, o;
			o = _c.p.o;
			if(
				typeof o == D.O
				&&
				typeof o[_c.s.r] == D.F
			) return 1;
			
			return 0;
	
		};

		n.destroy = function(){
			var t = this;
			/* only do this once */
			if(t.r < 5){

				t.stop();
				t.r = 5;

				
				$E.message.MessageService.S("Destroy thread " + this.i,"200.1");
				

				$E.message.MessageService.unsubscribe(t,"onremoveobject","H");

				/* It is up to the object to remove itself from the registry */
				$E.registry.ObjectRegistry.removeObject(t);

			}
		};

		n.H = function(s,i){

			if(i == this.o.s.z){
				
				$E.message.MessageService.S("Handle remove object in thread " + this.i + " for " + i,"200.1");
				
				this.destroy();
			}
		};
		

		$E.registry.ObjectRegistry.addObject(n);
		$E.message.MessageService.subscribe(n,"onremoveobject","H");
		
		o = 0;
		
		return n;
	}
}
/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.util");
$E.util = {
	v:"0.1.1.2207.2004",

	getDate:function(i){
		var d = new Date();
		return i?d:d.getTime();
	},
	
	EH:function(e,h){
		if(typeof e == D.O && typeof e.getAttribute != D.U && typeof e.getAttribute(h) == D.S){
			try{
				eval(e.getAttribute(h));
			}
			catch(z){
				$E.message.MessageService.S("Error evaluating [engine]." + h + ": " + (z.description?z.description:z.message),"515.4",1);
			}
		}	
	}
	
	

};


/*
BUG BUGS

	06/17/2003
		Status: fixed
		
		XML Requests are stored in an array so as to keep track of the request for asynchronous and synchronous actions.
		A property on a request item is used for caching, if caching is enabled.

		Whether caching is enabled or the request is synchronous or asynchronous,
		a race condition ensues if multiple requests are made at the same time, with the same id.
		The bug is the first request is incomplete, and subsequent requests fail in cache request,
		or fail in the internal request handler.
		
		The solution was to tack on a unique back-up id if the same-id request is incomplete.
		This results in two requests for the same XML file, but the result is returned with the original request id.
		If caching is enabled, then the cache return the same-id request once the first request is finished.

		This was originally fixed only for cached, synchronous requests, but then expanded to included all requests.


	05/30/2003
		Status: fixed; duplicate clean-up still open

		Latest Mozilla build, 1.4RC1 won't use the same event listener for the same object.
		Solution: add event listener at the time of the request, then strip it off later.
		
		This will also clean up the duplicate code for adding event listeners for pooled and non-pooled objects, which is pretty much the same.

	05/08/2003
		Status: fixed; refer race-condition fix
		
		The IE sync bug cropped up again outside of the cached http feature.
		If the feature is turned off, it seems the requests can get
		stacked up (see Engine Demo #10 in IE), and cause the browser to hang
		or fail (see Moz) to completely load the XML.
		
		Multiple requests seem to be ok, up to an undetermined point.
		
		The feature should be left intact for heavy use anyway, but it is crucial to
		note because it then becomes a requirement for heavy use.

	12/28/2002
		Status: fixed
		
		Fixed bug in P; this was causing a monster headache!

*/

/*

	Usage:
	
		Synchronous GET:
			[xml_dom_object] = getXml(path);
		Asynchronous GET:
			[int] = getXml(path,custom_handler,1,{optional_id});
		Cached Asynchronous GET:
			[int] = getXml(path,custom_handler,1,request_id,1);
		Synchronous POST:
			[xml_dom_object] = postXml(path,data);
		Asynchronous POST:
			[int] = postXml(path,data,custom_handler,1,{optional_id});

		Notes:
			custom_handler, required for asynchronous requests, is invoked with two parameters:
			"onloadxml", and a generic object.  The object includes two properties:
			object.id is the request id, and object.xdom refers to the XML DOM.
			If the request fails, object.xdom will be null.
			
*/

$EP("$E.xml");

$E.xml={
	v:"1.1.131.2207.2004",
/*
	_xml_request:null,
	_xml_request_id:null,
*/
	r:[],
	rm:[],

	
	ce:1,
	setCacheEnabled:function(b){
		$E.xml.clearCache();
		$E.xml.ce = b;
	},

	getCacheEnabled:function(){
		return $E.xml.ce;
	},
	

	
	nr:[
		["soapenc","http://schemas.xmlsoap.org/soap/encoding/"],
		["wsdl","http://schemas.xmlsoap.org/wsdl/"],
		["soap","http://schemas.xmlsoap.org/wsdl/soap/"],
		["SOAP-ENV","http://schemas.xmlsoap.org/soap/envelope/"]
	],
	nl:{},
	nu:{},
	nh:0,
	

	
	ho:[],
	hu:0,
	hc:0,
	hs:5,
	hm:10,
	
	/* notate whether the pool was created */
	hp:0,

	/* notate whether the pool was created */
	he:1,
/*	he:(typeof D.X == D.F?1:0),*/

	/* static class init - used to add in message subscriptions on demand */
	si:0,

	setPoolEnabled:function(b){
		$E.xml.he = b;
	},

	getPoolEnabled:function(){
		return $E.xml.he;
	},
	
	
	
	newXmlDocument:function(n){
		/*
			n = required "root node" name;
		*/
		
		var r = 0,e;
		if(!n) return 0;
		if(typeof document.implementation != D.U && typeof document.implementation.createDocument != D.U){
			r = document.implementation.createDocument("",n,null);
		}
		else{
			r = new D.A("MSXML.DOMDocument");
			e = r.createElement(n);
			r.appendChild(e);
		}
		return r;
	},
	
	clear:function(){
		var _x = $E.xml;

		
		_x.clearCache();
		
		
		
		_x.R();
		
		
		_x.r = [];
		rm = [];
		
		return 1;

	},

	
	clearCache:function(){
		var _x = $E.xml,i = 0,o;
		for(;i<_x.r.length;i++){
			o = _x.r[i];
			if(o.c && typeof o.cd == D.O){
				
				$E.message.MessageService.S("Clear cached DOM for " + o.i,"200.1");
								
				o.cd = 0;
			}
		}
	},
	
	
	

	getXmlHttpArray:function(){
		return $E.xml.ho;
	},
	
	R:function(){
		var _x = $E.xml,i = 0,o;
		_x.hp = 1;
		_x.hu=0;
		_x.ho=[];
		_x.hc = _x.hs;
		for(;i < _x.hs; i++)
			o = _x.ho[i] = _x.O(1,i);
		
	},
	
	testXmlHttpObject:function(){
		return $E.xml.O(null,null,1);
	},
	O:function(b,i,z){
		/*
			b = return a hash for use with pooling
			i = pool index value.  b must be true for i to be used
			z = used for testing object creation
		*/
		var o = null,v,f,_m = $E.message.MessageService;
		if(typeof D.X != D.U){	
			o = new D.X();
			if(z) return 1;
		}
		else if(typeof D.A != D.U){
			try{
				o = new D.A("MSXML2.XMLHTTP.3.0");
				if(z) return 1;
			}
			catch(e){
				_m.S("XMLError: " + (e.description?e.description:e.message),"512.4",(z?1:0));
			}
			if(z) return 0;
		}
		
		if(b && typeof i == D.N){
			v= {
				o:o,
				u:0,
/*				use_count:0,*/
				i:i,
				/* vid = variant id */
				v:-1,
				h:0
			};

			return v;
		}
		else{
	
			return o;
	
		}
	
	},
	
	P:function(i,y){
		var _x = $E.xml,b=0,o,a;
		a = _x.ho;

		if(typeof a[i] == D.O){
			o = a[i];
			if(o.i >= _x.hs)

				
				{
				$E.message.MessageService.S("Destroy returned pool object #(" + o.i + ")","200.1");
				
				
				a[i] = 0;
			
			}
			

			
			$E.message.MessageService.S("Drop handlers for pool object #(" + o.i + ")","200.1");
			

			try{
				if(!y){
					if(typeof D.X != D.U && o.o instanceof D.X)
						o.o.removeEventListener("load",o.h,false);
					
					else if(typeof D.A != D.U &&  o.o instanceof D.A)
						o.o.onreadystatechange=_x.B;
					
					o.h = 0;
				}
			}
			catch(e){
				$E.message.MessageService.S("Error in P: " + (e.description?e.description:e.message),"512.4",1);
			}		

			o.o.abort();
			o.u = 0;
			o.v = -1;


/*
				if(typeof D.A != D.U && o.o instanceof D.A)
					o.o.onreadystatechange = o.h;
*/				
			_x.hu--;
		}
		
		else{
			$E.message.MessageService.S("Invalid pool id '" + i + "'","200.4");
		}
		
		return 1;
	},
	G:function(y){
		var _x = $E.xml,i = 0,b=0,o,a,_m=$E.message.MessageService,n=-1,z = 0;

		if(!_x.hp) _x.R();
		a = _x.ho;
		for(;i<a.length;i++){
			if(typeof a[i] == D.O && typeof a[i].u == D.N && !a[i].u){
				a[i].u = 1;
				b = i;
				/* yes, we indeed got a good mark */
				z = 1;
				break;
			}
			/* mark the next known null marker for re-use*/
			if(n == -1 && !a[i])
				n = i;
			
		}

		if(!z){
			b = (n > -1)?n:a.length;
			if(b < _x.hm){
				a[b] = _x.O(1,b);
				a[b].u = 1;
				
				_m.S("Allocate additional objects to pool (" + b + ")","200.1");
				
			}
			else{
				_m.S("Max pool size reached!","200.4");
				return null;
			}
		}

		if(b > -1){
			_x.hu++;
			o = a[b];
			try{
				if(!y){
					if(typeof D.X != D.U && o.o instanceof D.X){
						o.h = function(){$E.xml.L(b);};
						o.o.addEventListener("load",o.h,false);
					}
					else if(typeof D.A != D.U &&  o.o instanceof D.A){
						o.h = function(){$E.xml.S(b);};
						/*
							Can't attach an event to this object with attachEvent
						*/
						o.o.onreadystatechange=o.h;
					}
				}
			}
			catch(e){
				_m.S("Error in G: " + (e.description?e.description:e.message),"512.4",1);
			}		

			return o;
		}
		
		return null;

	},
	
	
	L:function(i){
		/*
			i = xml id
		*/
		var _x=$E.xml,o,v,_m=$E.message.MessageService,z;
		try{
		
		
			if(_x.he && typeof _x.ho[i] == D.O){
				z = _x.ho[i].v;
				if(z == -1){
					_m.S("Invalid pool index for " + i,"200.4",1);
					return 0;
				}
				i = z;
			}
		
		
			if(typeof _x.rm[i] == D.N){
				o = _x.r[_x.rm[i]];
				
				v = {"xdom":null,"id":(o.bi?o.bi:i)};
				
				
				if(
					o.u.match(/^file:/i)
					&&
					typeof D.A == "function"
					&&
					o.o instanceof D.A
				){
					var mp = new D.A("MSXML.DOMDocument");
					mp.loadXML(o.o.responseText);
					v.xdom = mp;
				} else  if(o.o != null && o.o.responseXML != null)
					v.xdom = o.o.responseXML;
				
				else if(o.o != null)
					_m.S("Error loading '" + o.u + "'. Response text is: " + o.o.responseText,"540.4",1);
				
				else
					_m.S("Error loading '" + o.u + "'. The internal XML object reference is null.  Async is " + o.a + "; Pool Index is " + o.pi,"540.4",1);
				
	
				o.r = 1;
			
				if(o.ih){
/*				
					if(typeof D.X == D.F && o.obj instanceof D.X){
						o.obj.removeEventListener("load",o.ih,false);
					}
					else if(typeof D.A == D.F &&  o.obj instanceof D.A){
						o.obj.onreadystatechange=0;
					}
*/
					o.ih = 0;
				}
				
				
				if(_x.ce && o.c){
					o.cd = v.xdom;
				}
				
				
				$E.message.MessageService.publish("onloadxml",v);
				if(typeof o.h==D.F) o.h("onloadxml",v);
	
				/*
					clear out the request object
				*/
				
				if(o.pi > -1)
					_x.P(o.pi,!o.a);
				
				
				o.o = 0;
	
			}
			else{
				_m.S("Invalid id reference: " + i,"200.4",1);
			}

		}
		catch(e){
			_m.S("Error in handle_xml_request_load: " + (e.description?e.description:e.message),"512.4",1);
		}
	},

	S:function(i){
		var _x=$E.xml,o;

		/*
			Slightly different behavior for pooled requests and non-pooled requests.
			
			Ultimately, the issue IE won't detach the onreadystate event handler, so the index into the pool is passed
			instead of the unique request id.  This should actually be better anyway as it removes the need to constantly 
			attach and detach event handlers on the pooled objects.
		*/
		
		if(_x.he && typeof _x.ho[i] == D.O){
			o = _x.ho[i];
			if(o != null && typeof o.o == D.O && o.o.readyState == 4){
				_x.L(i);
			}
		}
		else  if(typeof _x.rm[i] == D.N){
			o = _x.r[_x.rm[i]];
			if(typeof o.o == D.O && o.o.readyState == 4){

				_x.L(i);
			}
		}
	},
	/*
		getXml(path,handler,async,id,caching);
		
		id is optional.  Use this where two or more xml transactions will be directed
		through the same handler.
		
	*/
	getXml:function(p,h,a,i,c){
	/*
			p = path
			h = handler
			a = async
			i = id
			c = cached
	*/
		return $E.xml.X(p,h,a,i,0,null,c);
	},
	postXml:function(p,d,h,a,i){
		/*
			Caching is not provided for the postXml wrapper.
		*/
		return $E.xml.X(p,h,a,i,1,d,0);
	},
	/*
		_request_xml is asynchronous.
	*/
	X:function(p,h,a,i,x,d,c){
		/*
			p = path
			h = handler
			a = async
			i = id
			x = is_post as bool
			d = data as string or DomDocument
			
			r = pool/new x obj
			b = bool
			
			c = cache result
		*/
		
		var _x=$E.xml,f,o=null,v,_m=$E.message.MessageService,y,z,r,b,b_ia,g,bi=0;
		
		if(!_x.si) _x.StaticInitialize();

		if(typeof p != D.S || p.length == 0){
			_m.S("Invalid path parameter in X","512.4",1);
			return 0;
		}
		
		if(typeof c==D.U) c = 0;
		if(typeof x==D.U) x = 0;
		if(typeof d==D.U) d = null;

		z = (x?"POST":"GET");
		if(typeof i!=D.S) i=$E.GG();

		/* check for a cached instance */
		if(
			typeof _x.rm[i] == D.N
			&&
			typeof _x.r[_x.rm[i]] == D.O
		){
			r = _x.r[_x.rm[i]];

			
			if(_x.ce && r.c && typeof r.cd == D.O){
				b = {"xdom":r.cd,"id":i};				
				_m.publish("onloadxml",b);
				if(typeof h == D.F) h("onloadxml",b);

				
				//_m.S("Return cached copy","200.1");
				

				return r.cd;
			}
			
			
			/*
				Race condition for an XML document with a specific id,
				that hasn't finished loading
				
				If there is a request, and that request isn't complete,
				then cook up a backup-request id and disable caching
			*/
			/*
				06/17/2003
					Removed '!r.a && ' check for sync only requests
					Removed 'r.c' check for caching
			*/
			 else  if(!r.r){
				/* force disable caching for this request */
				c = 0;
				/* backup the id */
				bi = i;
				/* create a random id */
				i = $E.GG();
				
				_m.S("Handle race condition for XML Id '" + bi + "'","200.4");
				
			}
			
		}

		
		/* get a new XML object, or a pooled object depending on the settings */
		
		b = _x.he;
		if(b){
			
			{
			
			r = _x.G(!a);
			
			if(r) _m.S("Request pooled object #" + r.i,"200.1");
			}
			
		}
		else{
		
			r = _x.O();
		
		}
		
		/*
			Unable to obtain an XML object, so bail out.
		*/
		if(!(b?(r&&r.o):r)){
			_m.S("Null XML object in in X.","512.4");
			return 0;
		}

		/* update the pool id reference, if pooling is enabled */
		
		if(b) r.v = i;
		
		
		y = _x.r.length;

		_x.r[y] = {
			u:p,
			i:i,
			bi:bi,
			a:a,
			o:(b?r.o:r),
			ih:0,
			h:h,
/*			method:(x?1:0),*/

			
			pi:(b?r.i:-1),
			

			
			c:c,
			cd:0,
			
			/* completed */
			r:0
		};
		
		_x.rm[i]=y;
		o = _x.r[y].o;


		if(!p.match(/:\/\//)){
			var m,e=new RegExp("^/");
			if(!p.match(e)){
				m=location.pathname;
				if(m.match(/\\/)) m = m.replace(/\\/g,"/");
				m=m.substring(0,m.lastIndexOf("/")+1);
				p=m + p;
			}
			if(!location.protocol.match(/^file:$/i))
				p=location.protocol + "//" + location.host + p;
			
			else
				p = location.protocol + "//" + p;
			
		}

/*
		if(!p.match(/:\/\//)){
			var m,e=new RegExp("^/");
			if(!p.match(e)){
				m=location.pathname;
				m=m.substring(0,m.lastIndexOf("/")+1);
				p=m + p;
			}
			p=location.protocol + "//" + location.host + p;
		}
*/
		_x.r[y].u = p;

		/*
			Add event handlers based on instance of XML object
			
			Must check for typeof object before instanceof or IE will bomb out.
			
			Check for:
				a) this is not a pooled request; pooled requests use index->id maps
				b) this as an async request
				c) the type of request object
		*/
		b_ia = (typeof D.A != D.U &&  o instanceof D.A)?1:0;
		try{
			/*
				05/30/2003
				Remove check for async only because non-pooled async requests should also go through the load listener.
			*/
			if(!b && typeof D.X != D.U && o instanceof D.X){
				_x.r[y].ih = function(){$E.xml.L(i);};
				o.addEventListener("load",_x.r[y].ih,false);
			}
			else if(!b && a && b_ia){
				_x.r[y].ih = function(){$E.xml.S(i);};
				/*
					Can't attach an event to this object with attachEvent
				*/
				o.onreadystatechange=_x.r[y].ih;
			}
		}
		catch(e){
			_m.S("Error in X: " + (e.description?e.description:e.message),"512.4",1);
		}		

		
		/*
			There is a problem with the D.A not liking the multiple levels of object references,
			particularly the embedded array reference into the http_objects array used for pooling.
			The good news is this only seems to apply to syncronous requests, and only for D.As.
			The bad news is fixing the problem requires the following:
				- change the onreadystatechange handler to point elsewhere.  Since this can't be null, its pointed at an empty stub function.
				- set the array reference for http_objects to null.
			At this point, those referencers are:
		*/
		
		if(b && !a){
/*			if(b_ia) o.onreadystatechange = _x.B;*/
			_x.ho[_x.r[y].pi] = 0;
		}
		
		
		g = (a?true:false);
		o.open(z,p,g);
		o.send(d);
		if(!a){
			/*
				Don't use the reference in the requests array here because it loses context when he open and send methods are invoked.
				Instead, since this is synchronous, just use 'o'
				
				This is symptomatic of the IE problem mentioned above, but the root cause seems to be
				the manner in which the D.A is stored in the array.
				
				The issue manifests as querying responseXML throws an error, or undefined and the object references get out of sync.
				This can be tested by comparing o == _x.r[y].obj
				
				With the IE fix in place, the test is true.
				Mozilla is false, but that isn't an issue (right now) because the response can still be obtained.
			*/

			z = o.responseXML;

			
			if(
				p.match(/^file:/i)
				&&
				b_ia
			){
				var mp = new D.A("MSXML.DOMDocument");
				mp.loadXML(o.responseText);
				z = mp;

			}
			
			
			/*
				Now that the request has been made, time for part 2 of the IE Synchronous problem.
				Reset the pool object (where the o property contains the XMLHTTPRequest object) to the array.
				Also, manually invoke the L method
			*/
			
			if(b){
				/*&& b_ia*/
				_x.ho[_x.r[y].pi] = r;
				_x.L(_x.r[y].pi);
			}
			
			
			_x.r[y].o = null;
			
			if(!b && _x.r[y].pi > -1)
				_x.P(_x.r[y].pi,!a);
			
			
			return z;
		}
		return 1;
	},

	
	transformNode:function(x, s, n, i, j, p){
		/*
			x = xml document
			s = xsl document
			n = optional node reference
			i = optional id for requesting XML
			j = optional id for requesting XSL
			p = optional cache bit for requesting XSL
		*/

		var xp, o = null,_m = $E.message.MessageService,_x = $E.xml,v,a,b,c,d;

		if(typeof x == D.S && x.length > 0){
			if(p && !i) p =0;
			v = x;
			x = _x.getXml(x,0,0,i,p);

			if(v.match(/\?(\S*)$/)){
				v = v.match(/\?(\S*)/)[1];
				a = v.split("&");
				for(b=0;b<a.length;b++){
					c = a[b].split("=");
					x.documentElement.setAttribute(c[0],c[1]);
				}
			}
		}

		if(typeof s == D.S && s.length > 0){
			if(p && !j) p =0;
			s = _x.getXml(s,0,0,j,p);
		}
		
		if(typeof x != D.O || x == null || typeof s != D.O || s == null){
			_m.S("Invalid parameters in transformNode. Xml Node = " + x + ", xsl document = " + s,"512.4",1);
			return o;
		}

		if(typeof n != D.O) n = x;

		try{
			if(typeof XSLTProcessor != D.U){
				xp = new XSLTProcessor();
				xp.importStylesheet(s);
				o = xp.transformToFragment(n,document);
				if(o) o = o.firstChild;
			}
	
			else if(typeof D.A != D.U && x instanceof D.A){
				o = new D.A("MSXML.DOMDocument");
				
				
				xp = n.transformNode(s);
				o.loadXML(xp);
				o = o.documentElement;
				

			}
			else{
				_m.S("Error in transformNode: " + (e.description?e.description:e.message),"512.4",1);
			}
		}
		catch(e){
			_m.S("Error in transformNode: " + (e.description?e.description:e.message),"512.4",1);
		}
		
		return o;

	},
	

	
	HN:function(){
		var _x = $E.xml,a,i=0,o;
		_x.nu = {};
		_x.nl = {};
		for(;i< _x.nr.length;i++){
			o = _x.nr[i];
			_x.nu[o[0]]=o[1];
			_x.nl[o[1]]=o[0];
		}
		_x.nh=1;
	},
	getURIForURL:function(u){
		var _x = $E.xml,q;
		if(!_x.nh) _x.HN();
		q = _x.nl[u];
		return (q?q:"");
	},
	getURLForURI:function(i){
		var _x = $E.xml,q;
		if(!_x.nh) _x.HN();
		q = _x.nu[i];
		return (q?q:"");
	},
	

	lookupNamespaceURI:function(n){
		
		var _x = $E.xml;
		if(!_x.nh) _x.HN();
		if(_x.nu[n])
			
			{
			$E.message.MessageService.S("Resolving '" + n + "' as '" + _x.nu[n] + "'","200.1");
			
			return _x.nu[n];
			
			}
			else{
				$E.message.MessageService.S("Could not resolve '" + n + "'","200.1");
			}
			
		
		return "";
	},
	
		
	selectSingleNode:function(d,x,c){
		/*
			d = XmlDocument
			x = xpath
			c = context node
		*/
		var s,i,n;
		if(typeof d.evaluate != D.U){
			c = (c ? c : d.documentElement);
			s = d.evaluate(x,c,$E.xml,0,null);

			return s.iterateNext();
		}
		else if(typeof d.selectNodes != D.U){
			return (c ? c : d).selectSingleNode(x);
		}

		return 0;
	
	},
	selectNodes:function(d,x,c){
		/*
			d = XmlDocument
			x = xpath
			c = context node
		*/
		var s,a = [],i,n;
		if(typeof d.evaluate != D.U){
			c = (c ? c : d.documentElement);
			s = d.evaluate(x,c,$E.xml,0,null);

			n = s.iterateNext();

			while( typeof n == D.O && n != null){
				a[a.length] = n;
				n = s.iterateNext();
			}

			return a;

		}

		else if(typeof d.selectNodes != D.U){
			return (c ? c : d).selectNodes(x);
		}

		return a;
	
	},
		
	
	
	/*
		queryNode is useful for light DOM queries when
		XPath is not available, or when querying against an HTML
		DOM for nodes with specific attribute values.
	*/
	queryNodes:function(x,p,n,a,v){
		return $E.xml.Q(x,p,n,a,v,1);
	},
	queryNode:function(x,p,n,a,v){
		return $E.xml.Q(x,p,n,a,v,0);
	},
	Q:function(x,p,n,a,v,z){
		/*
			 x = xdom
			 p = parent path
			 n = node path
			 a = attribute name
			 v = attribute value
			 
			 z = node or nodes
		*/

		var i=0,b,e,c,r=[];
		if(!z) r = null;
		
		c = x.getElementsByTagName(p);
		
		if(typeof n==D.S){

			if(!c.length){
				if(!z) return null;
				else return r;
			}
			c = c[0]; 
			e = c.getElementsByTagName(n);
		}
		else e = c;

		
		for(;i<e.length;i++){
			b = e[i];
			if((!a && !v) || (b.getAttribute(a) == v)){
				/*
					single query
				*/
				if(!z){
					r = b;
					break;
				}

				else r[r.length]=b;
				
			}
		}
		return r;
	},
	
	
	serialize:function(n){
		var v;
		if(typeof XMLSerializer != D.U){
			return (new XMLSerializer()).serializeToString(n);
		}
		else if(typeof n.xml == D.S){
			return n.xml;
		}
	},
	
	
	
	getCDATAValue:function(n){
		var c,d="",i=0,e;

		if(n == null) return d;

		c = n.childNodes;
		for(;i<c.length;i++){
			e=c[i];
			if(e.nodeName=="#cdata-section") d+=e.nodeValue;
		}
		return d;
	},
	getInnerText:function(s){
		var r = "",a,i,e;
		if(typeof s == D.S) return s;
		if(s == null) return r;
		if(typeof s== D.O && s.nodeType==3) return s.nodeValue;
		if(s.hasChildNodes()){
			a = s.childNodes;
			for(i=0;i<a.length;i++){
				e = a[i];
				if(e.nodeType==3) r+=e.nodeValue;
				if(e.nodeType==1 && e.hasChildNodes()){
					r+=this.getInnerText(e);
				}
			}
		}
		return r;
	},
	removeChildren:function(o){
		var i;
		for(i=o.childNodes.length-1;i>=0;i--)
			o.removeChild(o.childNodes[i]);
		
	},
	setInnerXHTML:function(t,s,p,d,z,c,h){
		/*
			t = target
			s = source
			p = preserve
			d = target document object
			z = no recursion
			
			c = preserve whitespace
			
			h = html refactor ; clone the node instead of creating the element and copy attributes
			
			
			
			r = return node reference
		*/
		var y,e,a,l,x,n,v,r = 0,b;
		
		/* typeof d == D.U */
		if(!d) d = document;
		
		b = (d == document?1:0);
		
		if(!p)
			$E.xml.removeChildren(t);
		

		y=(s && typeof s==D.O)?s.nodeType :(typeof s==D.S)?33:-1;
		switch(y){
			case 1:
				if(h){
					e = s.cloneNode(false);
				}
				else{
					e=d.createElement(s.nodeName);
					a=s.attributes;
					l=a.length;
					for(x=0;x<l;x++){
						n=a[x].nodeName;
						v=a[x].nodeValue;
	
						/*
							Must check for d == document to make sure whether this is the HTML DOM or not, because
							these cases only apply to IE oddness in the HTML DOM, not the XML DOMs.
						*/
						/* stupid IE */
						if(b && n=="style"){
							e.style.cssText=v;
						}
						/* stupid IE */
						else if(b && n=="id"){
							e.id=v;
						}
	
						/* stupid IE */
						/*  && $E.dom.browser.client.bswitch==1){ */
						else if(b && n=="class"){
							e.className=v;
						}
	
						/* stupid IE */
						else if(b && n.match(/^on/i)){
							eval("e." + n + "=function(){" + v  +"}");
						}
						else{
							e.setAttribute(n,v);
						}
					}
				}
				if(!z && s.hasChildNodes()){
					a=s.childNodes;
					l=a.length;
					for(x=0;x<l;x++)
						this.setInnerXHTML(e,a[x],1,d,z,c,h);
					
				}

				/* stupid IE */
				if(b && s.nodeName.match(/input/i) && s.getAttribute("checked")){
					e.checked=true;
				}

				t.appendChild(e);
				r = e;
				break;
			case 3:
				e=s.nodeValue;
				if(e){
/*
					e=e.replace(/^\s* /,"");
					e=e.replace(/\s*$/,"");
*/
					e=e.replace(/\s+/g," ");
					t.appendChild(d.createTextNode(e));
					r = e;
				}
				break;
			/* CDATA */
			case 4:
				e = s.nodeValue;
				t.appendChild(d.createCDATASection(e));
				break;
			case 8:
				/*
					Ignore comments
				*/
				break;
			case 33:
				e=s;
				if(e){
					if(!c){
						e=e.replace(/^\s*/,"");
						e=e.replace(/\s*$/,"");
						e=e.replace(/\s+/g," ");
					}
					t.appendChild(d.createTextNode(e));
					r = e;
				}
				break;
			default:
				
				$E.message.MessageService.S("Skip node type: " + y,"200.1");
				
				break;
		}
		return r;
	},
	

	/* stub is used for swapping handlers on IE */	
	B:function(){
		/* do nothing */
	},
	
	StaticInitialize:function(){
		$E.message.MessageService.subscribe($E.xml,"destroy","_handle_destroy");
		$E.xml.si = 1;
	},
	
	_handle_destroy:function(s, v){
		
		var _x = $E.xml;
		
		$E.message.MessageService.unsubscribe($E.xml,"destroy","_handle_destroy");

		
		_x.clearCache();
		
		
		

		
		
		_x.r = [];
		rm = [];	
		_x.hp = 0;
		_x.hu = 0;
		_x.ho=[];

	}
};



/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.registry");

$E.registry={
	ObjectRegistry:null,
	ObjectRegistryImpl:function(){
		var t=this;
		t.o = {
			s:{
				rt:0
			},
			p:{
				o:[],
				om:[]
			
			}
		};
		
		/* Verify the object conforms to the expected object design */
		t.canRegister=function(o){
			if(
				typeof o != D.O
				||
				(
					typeof o.i != D.S
					||
					typeof o.t != D.S
					||
					typeof o.v != D.S
					||
					typeof o.r != D.N
				)
			){
				return 0;
			}
			return 1;
			
		};
		
		t.addObject=function(o){
			var i,m,p;

			if(!t.canRegister(o)){
				if(ValidatePackage("$E.message") && $E.message.MessageService != null){
					$E.message.MessageService.S("Invalid Object Structure","540.4",1);
				}
				else{
					alert("Invalid Object Structure");
				}
				return 0;
			}
			if(t.isRegistered(o)){
				$E.message.MessageService.S("Object '" + o.i + "' is already registered","540.4");
				return 0;
			}
			p = t.o.p;
			i = o.i;
			
			if(typeof p.om[i] != D.N){
			
				m = p.o.length;
				p.o[m]=o;
				p.om[i]=m;

				if(
					t.o.s.rt
					&&
					ValidatePackage("$E.transaction")
					&&
					$E.transaction.TransactionService != null
				){
					$E.transaction.TransactionService.register(o);
				}
				
				return 1;
			}
			return 0;
		};


		t.removeObject=function(o, b){
			/*
			 * o = object
			 * b = suppress message
			 * 
			 */
			var i=o.i,m,p;
			p = t.o.p;
		
			if(typeof p.om[i] == D.N){
				m = p.om[i];
				/*
					set o[m] to 0 because null matches as typeof an object
					set om[i] to null because 0 matches as typeof a number
				*/
				p.o[m]=0;
				p.om[i]=null;

				if(!b) $E.message.MessageService.publish("onremoveobject",i);

				return 1;
			}
			return 0;
		};

		t.getObjects = function(){
			return t.o.p.o;
		};

		t.getObjectsMap = function(){
			return t.o.p.om;
		};

		t.getObject=function(i){
			var p = t.o.p;
			if(
				typeof p.om[i] == D.N
				&&
				typeof p.o[p.om[i]] == D.O
			){
				return p.o[p.om[i]];
			}
			return null;
		};

		t.isRegistered=function(i){
			
			if(typeof i == D.O){
				if(typeof i.i == D.U) return 0;
				i = i.i;
			}
		

			if(typeof t.o.p.om[i] == D.N){
				return 1;
			}
			return 0;
		};
	
		t.sendSigterm=function(){
			var o,i,p=t.o.p;
			/*for(i = 0; i < p.o.length;){*/
			for(i = p.o.length - 1; i >=0;){
				o = p.o[i--];
				/*if(!t.isRegistered(o)) continue;*/
				if(o!=null && o.r == 4 && typeof o.sigterm ==  D.F){
					o.sigterm();
					/*t.removeObject(o,1);*/
					
					$E.message.MessageService.S("Terminate object " + o.t + " (" + o.i + "):","200.1");
					
				}
				
				else{
					$E.message.MessageService.S("Don't terminate object " + o.t + " (" + o.i + "):","200.2");
				}
				
			}
			
			for(i = 0; i < p.o.length;){
				o = p.o[i++];
				if(t.isRegistered(o))
					t.removeObject(o,1);
			}
			
		};

		t.sendDestroyTo=function(o){
			if(
				t.isRegistered(o)
				&&
				typeof o.destroy == D.F
			){
				o.destroy();
				return 1;
			}

			return 0;
		};

		
		$E.IM(t,"base_object","object_registry","1.1.0.2207.2004");
		t.addObject(t);
	}
}

$E.registry.ObjectRegistry=new $E.registry.ObjectRegistryImpl();


/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.message");


/*
	
	Core API:
	
		S - replaces LoggerFactory.log
			This sends a message.  It doesn't expect a response.
			
		subscribe - replaces EventFactory.addEventListener
			This instructs the Message service to register an object as a
			recipient to a published message.
			
		publish - replaces EventFactory.fireEvent
			This instructs the Message service to publish a message to 
			any object that is subscribed to that type of message.  This suggests
			that messages have a pre-identified set of names.
		
*/

$E.message={
	MessageService:null,
	MessageServiceImpl:function(){
		/*
			o and the p and s child hashes are defined
			under the generic_ and spec_ objects in the config.
			
			However, the message service must be online prior to that, and may never
			use the config at all, so here defines its own.
			
			This could also be wrapped into another base def.
		*/
		var t=this;
		t.o={
			p:{
				/* subscriptions */
				s:[],
				/* delayed publications */
				dd:[],
				/* message entries */
				e:[]
				/*
				,
				ld:[]
				*/
			},
			s:{
				dd:0,
				me:200,
				rt:1
			},
			data:{
				l:["ALL","DEBUG","ADVISORY","NORMAL","WARNING","ERROR","FATAL","NONE"],
				lm:{ALL:0,DEBUG:1,ADVISORY:2,NORMAL:3,WARNING:4,ERROR:5,FATAL:6,NONE:7},
				ed:[

/*
					["Generic Error","An error occured.",100],
					["Status","[specify s message]",200],
					["Status","Created new instance.",201],
					["Status","Initialized.",202],
					["Status","Updated s.",203],
					["Status Debug","Message resulted from a debug action",204],
					["Operation Successful","The operation was successfully completed.",210],
					["Configuration Successful","An application component was successfully configured.",211],
					["Network Operation Successful","The network operation was successfully completed.",280],
					["Partial Operation Successful","A partial operation was successfully completed.",290],
					["Redirection","Operation was redirected to another process.",300],
					["Data Source Not Found","The specified data source was not found.",400],
					["File Not Found","The specified file source was not found.",410],		
					["Application Error","An application error occured.",500],
					["Application Configuration Error","An application error occured due to a missing or an incorrect configuration.",510],
					["Application Configuration Error","Invalid argument.",511],
					["Application Configuration Error","Object reference does not exist.",512],
					["Application Configuration Error","A configuration error occured due to insufficient permissions.",513],
					["Application Event Error","An error occured processing the event.",515],
					["Application Event Halted","An event handler was halted, probably because a UI element was mistakenly exposed.",516],
					["Internal Application Error","An internal application error occured, probably due to incomplete code.",520],
					["Internal Routine Halted","An internal routine was halted, probably because it would have caused an out-of-bounds exception, or it was going to exceed a pre-configured limit.",530],
					["Invalid Data Type","An unexpected data type was referenced.",540],
					["External Application Error","An external error occured with a referenced application.",550]
*/
				]
			}

		};


		t.setReportThreshold=function(i){
			var c=t.o;
			if(typeof i == D.N) i = c.data.l[i];
			if(typeof c.data.lm[i] == D.N){
				c.s.rt = c.data.lm[i];
			}
		};

		t.clearEntries=function(){
			t.o.p.e = [];
		};

		t.getDeliveryDelay=function(){
			return t.o.s.dd;
		};
		
		t.setDeliveryDelay=function(i){
			if(typeof i == D.N && i >= 0){
				t.o.s.dd = i;
			}
		};

		t.subscribe=function(o,e,f,v){
			/*
				o = reference object
				e = message name
				f = function pointer/function name as string
				v = reference object used to filter subscription to this object
			*/
			var c,l,a = arguments;
			c=t.o;
			
			if(a.length==4){
				if(!o) o=window;
				if(!v) v=null;
			}
			if(a.length==2){
				
				var t1=a[0],t2=a[1];
				o=window;
				e=t1;
				f=t2;
			}
			
			if(typeof c.p.s[e] != D.O) c.p.s[e]=[];
			l = c.p.s[e].length;
			c.p.s[e][l]=$E.FN("basic_message_subscription",o,e,f,v);
			
			return 0;

		};

		t.unsubscribe=function(o,e,f){
			/*
				o = object
				e = event
				f = function pointer
			*/
			
			var t=this,a=[],l,i=0,z,c,g = arguments;
			c = t.o;
			
			if(g.length==2){
				var t1=g[0],t2=g[1];
				o=window;
				e=t1;
				f=t2;
			}
			if(typeof c.p.s[e] != D.O) return 0;
			
			l=c.p.s[e].length;
			for(;i<l;i++){
				z = c.p.s[e][i];

				if(
					z.object != o
/*					|| z.event_name != e*/
					|| z.handler != f
				){
					a[a.length]=z;
				}
			}
			c.p.s[e]=a;
			return 1;
		};

		/*
			sigterm is used to instruct the message service that it should stop
			processing delayed messages, move its readystate to an unloading state,
			and set the delivery delay to 0, which is immediate.
			
			Clear out all publications
		*/
		t.sigterm=function(){
			var t=this,c;

			c = t.o;
			t.r = 5;
			c.s.dd=0;
			c.p.dd = [];
			c.p.e = [];
		};

		t.flush=function(){
			t.o.p.dd=[];
		};
		
		t._P=function(i){
			/*
				i = delayed entry id
			*/
			var t=this,d,c;
			c = t.o;
			if(t.r != 4) return;
			if(typeof i == D.S && typeof c.p.dd[i] == D.O){
				d = c.p.dd[i];
				t.P(d.event,d.data);
				c.p.dd[i] = 0;
			}
		};
		t.publish=function(e,o){

			var t=this,c,x,d;
			c = t.o;
			/*if(t.r != 4 || !$E.registry.ObjectRegistry.isRegistered(t)) return;*/
			
			if(c.s.dd){
				d = c.p.dd;
				x = $E.GG();
				d[x] = {data:o,event:e};
				setTimeout("try{if($E.registry.ObjectRegistry.isRegistered('" + t.i + "')) $E.registry.ObjectRegistry.getObject('" + t.i + "')._P('" + x + "');}catch(e){alert('Publish Error In " + e + " To " + t.t + "');}",c.s.dd);
			}
			else{
				t.P(e,o);
			}
		};
		t.P=function(e,o){
			var t=this,c,j,l,i,z,x,d;
			if(t.r != 4) return;

			c = t.o;
/*			j=$E.FN("basic_message_publication",e,o);*/
			if(typeof c.p.s[e] != D.O) return;
			
			l=c.p.s[e].length;

			/*
				Be sure to back out of the array in case the publication results in an object unsubscribing
				from the publication, and thus shifting the array.
			*/
			for(i=l-1;i>=0;){
				z=c.p.s[e][i--];
				if(
/*
					z.subscription_name==e
					&&
					(
*/
						!z.target || z.target==o
/*
					)
*/
				){

					try{
						if(typeof z.handler == D.S)
							z.object[z.handler](e,o);
						
						if(typeof z.handler == D.F)
							z.handler(e,o);

					}
					catch(e){
						alert("Publish Error: " + e.message + "\n" + z.subscription_name + "\n" + z.handler );
					}

				}
			}
		};
		
		
		
		t._debugDelayPublish=function(i){
			var t=this,d,c;
			c = t.o;
			if(t.r != 4) return;
			if(typeof i == D.S && typeof c.p.dd[i] == D.O){
				d = c.p.dd[i];
				t._debugPublish(d.event,d.data);
				c.p.dd[i] = 0;
			}
		};

		t.debugPublish=function(e,o,b){
			var t=this,c,x,d;
			c = t.o;
			
			if(!b && c.s.dd){
				d = c.p.dd;
				x = $E.GG();
				d[x] = {data:o,event:e};
				setTimeout("$E.registry.ObjectRegistry.getObject('" + t.i + "')._debugDelayPublish('" + x + "')",c.s.dd);
				return 1
			}
			else{
				return t._debugPublish(e,o);
			}
		};
		t._debugPublish=function(e,o){
			var t=this,c,j,l,i=0,z,x,d,s = [];

			c = t.o;
			if(typeof c.p.s[e] != D.O) return;
			
			l=c.p.s[e].length;
			for(;i<l;i++){
				z=c.p.s[e][i];
				if(	!z.target || z.target==o ){
						if(typeof z.handler == D.S)
							s.push(z.object.i + "[" + z.handler + "]");
						
						if(typeof z.handler == D.F)
							s.push(z.object.i + "[" + z.handler + "]");

				}
			}
			t.S(s.join(", "),"204.3");
			return s.join("\n");
		};
		
		
		t.sendMessage=function(d,s,p){
			return t.S(d,s,p);
		};
		t.S=function(d,s,p){
			/*
				d = data
				xxx l = level
				p = type
				s = string
				o = object
				t = this
			*/

			var o=null,v,c,t=this,ms;
			c=t.o;
			
			if(t.r != 4) return;

			if(typeof s != D.S) s = "200";

			v = t.I(s);

			if(v.t < c.s.rt){
				return o;
			}

			if(typeof p != D.N) p = 0;
		
			if(p) o=t.R(s,d,v);
			else o=t.C(s,d,v);

			ms = t.M(o);
			if(ms==null) ms = "[message error]";

			t.publish("onsendmessage",{message:ms,level:v.t,description:o.d});


			return o;
		};
		t.R=function(s,d,v){
			var t=this,o;
			
			o=t.C(s,d,v);
			
			alert(t.M(o));
			return o;
		};
		t.C=function(s,d,v){
			var o=$E.FN("basic_message",v,d),i,c,t=this;
			c = t.o;
			i = c.p.e.length;
			
			if(i >= c.s.me && c.s.me > 0){
				c.p.e.shift();
				i--;
			}
			
			o.index=i;
			c.p.e[i]=o;
			return o;
		};
		

		t.M=function(o){
			var v = "[error]",a,l,d,c,t=this;
			c = t.o;

			if(typeof o==D.O){
				a=t.D(o);

				d = o.time;
				
				var m = new String(d.getMinutes()),
					s = new String(d.getSeconds()),
					ms = new String(d.getMilliseconds())
				;

				if(s.length == 1) s="0" + s;
				if(m.length == 1) m = "0" + m;

				if(ms.length == 1) ms = "0" + ms;
				if(ms.length == 2) ms = "0" + ms;

				
				v =	d.getHours() + ":" + m + ":" + s + ":" + ms + "::";

				v+=t.G(o.entry.t) + ": ";


				v+=(a!=null?a[0]:":"); /* Default Message */

				v+=" (" + o.entry.m + ").";
				o.d = (a!=null?a[1]:""); /* was a[2]*/
				if(o.data){
					v+=" " + o.data;
				}
				else{
					v+=" " + o.d;
				}
			}

			
			return v;
		};
		t.G=function(i){
			return this.o.data.l[i];
		};
	
		t.D=function(o){
			var v=null,f=100,l,m,n,i=0,a,d,c,t=this;
			c = t.o;
			/*
				v = return value
				f = offset
				l = length
				m = major
				n = minor
				t = this
			*/
			if(typeof o==D.O){
				l=c.data.ed.length;
				m=o.entry.mc;
		
				n=o.entry.nc;

				for(;i<l;i++){
					a=c.data.ed[i];
					if(a.length>=2){
						d=a[2];
						if(m >= d && m < (d + f))
							v=a;
						
						if(v != null && m > (d + f)) break;
					}
				}
			}	

			return v;
		};

		t.I=function(s){
			var a=[],c,i=100,o,m=0,n,x=900,d,p,y;
			o=i;
			if(s) a=s.split(".");
			/*
				 a = array
				 c = code
				 i = offset
				 o = offset
				 x  = max
				 m = major
				 n = minor
				 l = loc
				 d = class
				 p = id
				 
			*/
			
			c=(a[0])?parseInt(a[0]):200;
		
			for(y=i;y<=x;y+=100){
				if(c >= i && c < (y + i))
					m=i;
				
				if(m > 0 && m <= (y+100)) break;
			}
		
			if(m < 0 || m > 900 || c < 0 || c > 900){
				m=200;
				c=200;
			}
		
			n=c - m;
			d=(a[1])?parseInt(a[1]):3;
			if(d > 7 || d < 0)d=3;
			l=(a[2])?parseInt(a[2]):0;
			p=(a[3])?parseInt(a[3]):0;

			return {
				mc:c,
				mb:m,
				nc:n,
				t:d,
				l:l,
				id:p,
				d:"",
				m:c + "." + d + "." + l + "." + p
			};

		};

		$E.IM(t,"base_object","message_service","1.1.2.2207.2004");

		$E.registry.ObjectRegistry.addObject(t);
				
		t.r = 4;
	}
}
$E.message.MessageService=new $E.message.MessageServiceImpl();
/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.object");

$E.object={
	v:"1.1.0.2207.2004",
	newInstance:function(s,z){
		var o = $E.FN("generic_object"),
			_m=$E.message.MessageService,
			_r=$E.registry.ObjectRegistry
		;
		$E.IM(o,"base_object",s,z);
		if(_r.addObject(o)){
	
			$E.dom.event.addEventBuffer(o);
/*
			$E.dom.css.addStyleBuffer(o);
	
			o.createHandler("debug");
	
			o._handle_debug=function(){
				alert("debug handler: " + this.i);
			};
		
			_m.subscribe(o,"ondebug","_handle_debug");
*/		
		}
		return o;
	},
	/*
		IOA
		
		Given an object that

	*/
	IOA:function(o,s){
	
		if(typeof o!=D.O || typeof o.o != D.O || typeof o.o.p != D.O){
			alert("Invalid object reference in ocjo.IOA");
			return 0;
		}
	
		o.o.p[s + "s"] = [];
		o.o.p[s + "names"] = [];
		o.o.p[s + "index"] = [];
		var 
			s_name = s.substring(0,1).toUpperCase() + s.substring(1,s.length),
			f
		;
		
		o["get" + s_name + "ByName"]=eval(
			'f = function(s){'
			+ ' var c=this.o.p;'
			+ ' if(typeof c.' + s + 'names[s]==D.N) return c.' + s + 's[c.' + s + 'names[s]];'
			+ ' return 0;'
			+ ' }'
		);

		o["get" + s_name] = eval(
			'f = function(i){var _p = this.o.p;if(typeof _p.' + s + 'index[i] == D.N&&typeof _p.' + s + 's[_p.' + s + 'index[i]] == D.O){return _p.' + s + 's[_p.' + s + 'index[i]];}return 0;};'
		);
		o["get" + s_name + "s"] = eval(
			'f = function(){return this.o.p.' + s + 's;};'
		);
		
		o["is" + s_name] = eval(
			'f = function(o){var _p = this.o.p;if(typeof o == D.S){if(this.get' + s_name + '(o)) return 1;return 0;}if(typeof o==D.O&&o!=null&&typeof _p.' + s + 'index[o.' + s + '_id] == D.N&&typeof _p.' + s + 's[_p.' + s + 'index[o.' + s + '_id]] == D.O){return 1;}return 0;};'
		);
		return 1;
	}
}
				

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
	
*/

/*
	ApplicationDriver performs three basic tasks:
		- publishes a notification when the browser window loads
		- publishes a notification when the browser window unloads
		- stores global configuration
*/

$EP("$E.util.driver");
$E.util.driver={
	ApplicationDriver:null,
	ApplicationDriverImpl:function(){
		var t=this,_j=$E,_x=$E.xml,_m=$E.message.MessageService;


		t.o={
			s:{
				l:0,
/*
				application_loaded:0,
				application_ui_ready:0,
*/
				/* window_loaded */
				wl:0,
				/* window unloaded */
				wu:0,
				gc:0
			},
			p:{
				/* application_config */
				application_config:0
			}
		};

		t._terminate = function(){
			_m.publish("destroy",window);
		};
		t.getConfig = function(){
			return t.o.p.a;
		};
		t.setConfig = function(o,b){
			/*
				o = config object
				b = switch; publish a message that the config was loaded.
			*/

			t.o.s.l = 1;
			t.o.p.a = o;
			if(b) _m.publish("application_config_loaded",o);
		};

		t._handle_window_unload = function(){
			/*
				handling the window unload event is done to reduce the possibility
				of errors, and also to propogate a destroy event to all objects.
				
				In order for this propogation to be effective, and for potential
				errors be squashed, the event_delay on the eventfactory is set to 0.
			*/
			this.destroy();
		};
		
		/*
		 * if a sigterm is detected, then invoke destroy but don't propogate the
		 * sigterm by invoking sendSigterm
		 */
		t.sigterm = function(){
			this.destroy(1);
		};

		t.destroy = function(b){
			var t = this;
			if(!t.o.s.wu){
				t.o.s.wu = 1;
				t.o.p.a = 0;
				if(!b) _j.registry.ObjectRegistry.sendSigterm();

				this._terminate();

				t.r = 5;

				_j.dom.event.removeEventListener(window,"unbeforeload",t._prehandle_window_unload);
				_j.dom.event.removeEventListener(window,"unload",t._prehandle_window_unload);
				_j.dom.event.removeEventListener(window,"load",t._prehandle_window_load);


			}
		};


		t._handle_window_load=function(){
			t.o.s.wl=1;
			/*
				This just propogates the window onload event back to
				any other component that cares to know, such as the TaskService.
				
				There is less impact than using an anonymous function to wrap
				the object instance.
			*/
			_m.publish("dom_event_window_load",this);
		};

		/*
			Add event buffer was designed for DOM events as a way
			of creating instance-specific handlers.
		*/

		$E.dom.event.addEventBuffer(t);

		$E.IM(t,"base_object","driver_utility","1.1.0.2207.2004");
		$E.registry.ObjectRegistry.addObject(t);

		t.createHandler("window_load",0,0,1);
		t.createHandler("window_unload",0,0,1);

		_j.dom.event.addEventListener(window,"unbeforeload",t._prehandle_window_unload);
		_j.dom.event.addEventListener(window,"unload",t._prehandle_window_unload);
		_j.dom.event.addEventListener(window,"load",t._prehandle_window_load);
		
		t.r = 4;

	}

};

/* Create a new application driver */
$E.util.driver.ApplicationDriver=new $E.util.driver.ApplicationDriverImpl();

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.util.config");

$E.util.config={
	newInstance:function(s,h,a){
		/*
			ui.object.newInstance draws on js.object.newInstance.
			j.o.n implements the event and style code, and draws on the base
			generic object class definition.
		*/
		var n = {
			o:{
				p:{
					config:[],
					config_map:[],
					config_load_handler:0
				},
				s:{
					config_path:0,
					/* config_loaded */
					l:0,
					load_async:0,
					element_parent_name:"config",
					element_name:"param",
					attr_name_name:"name",
					attr_value_name:"value"
				}
			}
		};
		


		n.setElementParentName=function(s){
			this.o.s.element_parent_name = s;
		};
		n.setElementName=function(s){
			this.o.s.param_child_name = s;
		};
		n.setAttrNameName=function(s){
			this.o.s.attr_name_name = s;
		};
		n.setAttrValueName=function(s){
			this.o.s.attr_value_name = s;
		};

		n.clearConfig = function(){
			var t = this, _p;
			_p = t.o.p;
			
			_p.config = [];
			_p.config_map = [];
			
		};
		
		n.destroy = function(){
			var t = this;
			if(t.r != 5){
				$E.message.MessageService.subscribe(t,"onloadxml","HLX");
				t.clearConfig();
				t.o.p.config_load_handler = 0;
			}
		};
		
		n.sigterm = function(){
			this.destroy();	
		};
		
		n.reload=function(){
			var t = this,_s,_p;
			t.clearConfig();
			_s = t.o.s;
			_p = t.o.p;
			if(_s.config_path){
				t.load(_s.config_path, _p.config_load_handler, _s.load_async);
			}
		};
		
		n.load=function(s,h,a){
			/*
				s = source
				a = async?
				h = handler if async
			*/
			var t = this,_j = $E,o,c;
			c = t.o;
			c.p.config_load_handler = (typeof h==D.F?h:0);
			c.s.config_path = s;
			c.s.load_async = a;

			o=_j.xml.getXml(s,null,a,t.i);
			
			/*
				If not asynchronous, then parse the result right now.
				
				02/13/2003 - parse right now, but block parsing in the handler for sync requests.
			*/
			if(!a)
				t._parse_config(o);
			


		};
		
		n.HLX=function(s,v){
			var t = this;

			/* Only invoke the parse method if the xml file was loaded asynchronously */
			if(v.id == t.i && t.o.s.load_async){
				this._parse_config(v.xdom);
			}
		};

		n.getParams=function(){
			return this.o.p.config;
		};
		
		n.getParam=function(x){
			var t=this,c,o;
			c = t.o;
			if(!c.s.l) return null;
			if(typeof x==D.S)
				x = c.p.config_map[x];
			
			if(typeof x==D.N && typeof c.p.config[x]==D.O)
				return c.p.config[x].value;
			
			return null;
		};

		n.parseConfig=function(o){
			return this._parse_config(o);
		};

		n._parse_config=function(o){
			var t = this,c,p,i=0,a,n,v;
			c = t.o;
			t.r = 3;
			if(typeof o == D.O && o.documentElement != null){
				c.s.l = 1;

				a = $E.xml.queryNodes(o.documentElement,c.s.element_parent_name,c.s.element_name,0,0);/*$E.xml.selectNodes(o,c.s.element_parent_name + "/" + c.s.element_name,o.documentElement);*/

				for(;i<a.length;i++){
					p = a[i];
					n = p.getAttribute(c.s.attr_name_name);
					if(typeof n==D.S && n.length > 0){
						v = p.getAttribute(c.s.attr_value_name);
						if(typeof v!=D.S) v = "";

						c.p.config_map[n]=c.p.config.length;

						if(v == "#cdata" && p.hasChildNodes())
							v = $E.xml.getCDATAValue(n);
						
						c.p.config[c.p.config.length]={"name":n,"value":v};
					}
				}
				
				t.r = 4;
			}

			if(typeof c.p.config_load_handler == D.F){
				c.p.config_load_handler("onconfigload",this);
			}

		};

		$E.IM(n,"base_object","config_utility","1.1.2.2207.2004");
		$E.registry.ObjectRegistry.addObject(n);
		


		/*
			Use the message service to pick up the xml loaded event for asynchronous
			operations because:
				- the handler loses its scope to the object instance
				- and that's bad
				
			Doing so means that the handler must correctly identify the config
			
			
			02/13/2003 - I switched it over to using just a function pointer because I can't repro the problem, and it seems lame to have to use the subscription
				Addendum - Ok, found the problem.  It loses context for parts of the object -- very weird.  So, this work around is valid again.
				
				Repro example:
					Specify the handler as a pointer instead of using the message
					Try to alert this.i - this should work
					Now, try to alert some other function or property that is not part of the base object definition.  This fails.
		*/

		$E.message.MessageService.subscribe(n,"onloadxml","HLX");

		if(typeof h == D.S && typeof window[h] == D.F){
			h = window[h];
		}
		
		if(typeof s == D.S){
			if(!a) a =0;
			n.load(s,h,a);
		}
		
		if(typeof s == D.O && s != null){
			n._parse_config(s);
		}
		
		return n;

	}
}
/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.wires");
$E.wires.primitive={
	PrimitiveWire:null,
	PrimitiveWireImpl:function(){
		var t = this;
		t.o={
			p:{
				/* wires */
				w:[]
			},
			s:{
				/* counter */
				c:0
			}
		};
		
		t.sigterm = function(){
			if(this.r != 5){
				var _p = this.o.p;
				_p.w = [];
				this.r =5;
			}		
		};
		
		t.invoke=function(i,args,b,z,p,o,m){
			/*
				 i = id

				 args = array of arguments to pass to the action and handler

				 b = force handle even if invoke doesn't return true
				 z = skip handler
				 p = preserve data
				 o = handler only
				 m = multi-purposed; don't flag usage;
				 
				 
				 r = return value from action; returned for z
				 
			*/
			var c = t.o,h,a,d,r=0;
			h = c.p.w[i];

			if(typeof args != D.O) args = [];


			if(typeof h==D.O){

				a = (typeof h.ap==D.O && typeof h.a==D.S)?1:0;
/*
				h.ap.testC();
				h.ap[h.a]();
	v = _js.FN.apply(this.caller,n_a);
*/
				if(
					(
						o
						||
						(!h.i && (r = ( a ? h.ap[h.a].apply(h.ap,args) : h.a.apply(window,args) )) )
					)
					||
					b
				){
					if(!m) h.i = 1;
					if(z) return r;

					a = (typeof h.hp==D.O && typeof h.h==D.S)?1:0;
					/* d = (typeof h.hp==D.O && typeof h.h==D.S)?h.hp[h.h]:h.h; */
/* typeof d == D.F && */
					if(!h.r){
						
						if(a){
							if(typeof h.hp[h.h] == D.F) h.hp[h.h].apply(h.hp,args);
							/* else alert("$E.wires.primitive::invoke Error = Invalid function pointer " + h.h); */
						}
						else{
							if(typeof h.h == D.F) h.h.apply(window,args);
							/* else alert("$E.wires.primitive::invoke Error = Invalid function pointer " + h.h); */
						}
						/* d(); */
						if(!m) h.r=1;

						/*
							unless specified, nuke the data after use
							WireService may want to keep it around
						*/

						if(!p) c.p.w[i] = 0;
						return r;
					}
				}
			}
			else{
				alert("$E.wires.primitive::invoke Error = Invalid wire reference with " + i);
			}
			return 0;
		};

		t.getWire=function(i){
			var c = t.o,h;
			h = c.p.w[i];
			if(typeof h==D.O){
				return h;
			}
			return 0;
		};
		
		t.fireWire=function(i){
			var c = t.o,h;
			h = c.p.w[i];
			if(typeof h==D.O){
				/* set the invocation flag */
				h.i=1;
				t.invoke(i,0,1);
			}
		};

		t.wire=function(xp,x,yp,y,ep,e,tl){
			/*
				xp = Action Package
				x = Action
				yp = Handler Package
				y = Handler
				ep = Error Package
				e = Error
				
			*/
			
			if(typeof tl != D.S) tl = "swc.ocjw.primitive";

			try{
				if(typeof xp == D.S) xp = eval(xp);
				if(typeof yp == D.S) yp = eval(yp);
				if(typeof ep == D.S) ep = eval(ep);
			}
			catch(e){
				alert("ocjw.wire.Error: " + e.toString());
				return 0;
			}

/*
			if(arguments.length == 2){
				y = x;
				x = xp;
				yp = xp = 0;
			}
*/
			var i = tl + "." + (++t.o.s.c),c = t.o;
			if(!xp) xp=window;
			if(!yp) yp=window;
			if(!ep) ep=window;
			c.p.w[i] = {ap:xp,a:x,hp:yp,h:y,ep:ep,e:e,i:0,r:0};
			return i;
		};

		$E.IM(t,"base_object","primitive_wire","0.0.1.2207.2004");
		$E.registry.ObjectRegistry.addObject(t);
		t.r = 4;
	}


}
$E.wires.primitive.PrimitiveWire=new $E.wires.primitive.PrimitiveWireImpl();


/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/


/*
	BUG
	
		Need a way to reset a wire.
*/
$EP("$E.wires");

$E.wires.wire={
	newInstance:function(){
		var t = this;
	
		t.o={
			p:{
				w:[],
				h:[],
				/* track the actions for use in disseminating handlers*/
				l:[],
				pw:new $E.wires.primitive.PrimitiveWireImpl()
			},
			s:{
				counter:0,
				wire_id_label:"swc.ocjw.wire",
				can_signal:1
			}
		};
		
		t.sigterm = function(){
			if(this.r != 5){
				var _p = this.o.p;
				_p.w = [];
				_p.h = [];
				_p.l = [];
				this.r =5;
			}		
		};

		t.getLength = function(){
		
		};
		
		t.setCanSignal = function(b){
			t.o.s.can_signal = (b?1:0);
		};
		
		t.getCanSignal = function(){
			return t.o.s.can_signal;
		};
		
		/*
			Invoke should be alterned to use the same method as primitiveInvoke,
			where the b argument, used to skip the check for whether the handler should be used,
			is replaced with a z argument for forcing the handler in lieu of executing the action.
			
			This woud make the invoke method more consistent with the implementation.
			
			At the moment, active implementations are being switched to use hard wires.
			
			Hard Wiring as a masking API for making non-signalling wires.
			Invoke is much more robust than primitiveInvoke, which is used for hard wiring, and remains as it includes
			the process for signalling.
		*/

		t.invoke = function(args,xp,x,b,o){
			var i=-1,l,d,
				_p = t.o.p,
				_s = t.o.s,
				w,wl,
				pw,r,a
			;
			
			if(typeof args!=D.O) args = [];
			
			/*
				i = variant index
				l = lookup id
				d = link id composed of 'l'
				w = wire pointer
				wl = wire linkage
				r = return value
				
				b = skip force handler
				o = handler only
			*/

			try{
				if(typeof xp == D.S) xp = eval(xp);
			}
			catch(e){
				alert("ocjw.invoke.Error: " + e.toString());
				return 0;
			}
			
			if(typeof xp != D.U && x){
			
				l = (xp!=null?(xp.i?xp.i:(xp.id?xp.id:(xp.name?xp.name:0))):0);
				d = l + "-" + x;
				if(typeof _p.l[d] == D.O){
					wl = _p.l[d];
				}
				else{
					alert("Invalid Wire Reference (" + d + ") in $E.wires.js::invoke");
				}
			}
			else{
				if(typeof _p.w[0] == D.O){
					w = _p.w[0];
					wl = _p.l[w.la + "-" + w.a];
				}
			}
			
			if(typeof wl == D.O && wl.length > 0){
				w = _p.w[wl[0]];
				
				/*
					invoke the primitive wire action,
					don't force handler,
					skip the handler,
					preserve the data
					don't specify handler only
					set as multi-purposed
				*/
				
				
				/* add request interceptor hook-up here */
				
				if(!o) r = _p.pw.invoke(w.pid,args,0,1,0,0,1);

				if(
					(
						o
						||
						(!w.i && r)
					)
					||
					b
				){

					w.i = 1;

					for(i = 0;i<wl.length;i++){
						w = _p.w[wl[i]];
						
						/*
							invoke the primitivewire action
							force the handler
							don't skip the handler
							preserve the data
							specify handler only
							set as multi-purposed
						*/
	
						/* add response interceptor hook-up here */
						
						_p.pw.invoke(w.pid,args,1,0,1,1,1);
						if(_s.can_signal){

							d = w.lh + "-" + w.h;

							/* reuse l */
							if(typeof _p.l[d] == D.O){
								
								/* reuse w */
								l = _p.w[_p.l[d][0]];
								
								/*
									Get the primitive wire data.
									Some data is being stored twice on the wire,
									but for the most part it should only be located
									in one place.  So, use the primitive wire data.
									Note that this does add an extra lookup.
								*/

								pw = _p.pw.getWire(l.pid);
								if(pw){

									/*
										Enforce one-time linkage to avoid loops.
									*/
									if(!l.i) t.invoke(args,pw.ap,pw.a,0,1);
								}
							}

						}
						/*
							The previous code does a lookup into the linkage for cross-linking
							
							And that, my friends, is the basic hook to a signals & slots implementation.
							
							A generic S&S class can then define the standard API which makes the corresponding
							wire setup.
							
						*/
						
					}				
				}
				else{

/*					alert("wire action false");*/

				}

			}

			return r;
		};

		t.addInterceptor = function(o){
			/* Adds an object request or response interceptor */
		};

		t.join = function(yp,y){
			/*
			 add this handler to the linkage of the first wire
			
			 this is done by taking the first wire, and then creating a new wire
			 with the new handler.
			*/
			
		};
		t.wire = function(xp,x,yp,y,ep,e){
			var v,i,a,
				_p = t.o.p,
				_s=t.o.s
			;
/*
			if(arguments.length == 2){
				y = x;
				x = xp;
				yp = xp = 0;
			}
*/

			try{
				if(typeof xp == D.S) xp = eval(xp);
				if(typeof yp == D.S) yp = eval(yp);
				if(typeof ep == D.S) ep = eval(ep);
			}
			catch(e){
				alert("ocjw.wire.Error: " + e.toString());
				return 0;
			}

			/* primitive wires are created out of all values. */
			
			i = _p.pw.wire(xp,x,yp,y,ep,e,_s.wire_id_label);

			v = {
				pid:i,
				a:x,
				h:y,

				/* link action id */
				la:(xp!=null?(xp.i?xp.i:(xp.id?xp.id:(xp.name?xp.name:0))):0),

				/* link handler id */
				lh:(yp!=null?(yp.i?yp.i:(yp.id?yp.id:(yp.name?yp.name:0))):0),

				/* link error id */
				le:(ep!=null?(ep.i?ep.i:(ep.id?ep.id:(ep.name?ep.name:0))):0),
				
				id:0,
				i:0
			};

			v.id = v.a + "-" + v.h + "-" + v.pid;
			
			_p.h[v.id] = _p.w.length;
			_p.w[_p.w.length] = v;

			/* re-use i */
			i = v.la + "-" + v.a;

			if(typeof _p.l[i] != D.O) _p.l[i] = [];
			
			a = _p.l[i];
			a[a.length] = _p.h[v.id];
			
			return 1;
		};
	
		t.primitiveWire = function(xp,x,yp,y,ep,e){
			var _p = t.o.p,
				_s=t.o.s
			;

			try{
				if(typeof xp == D.S) xp = eval(xp);
				if(typeof yp == D.S) yp = eval(yp);
				if(typeof ep == D.S) ep = eval(ep);
			}
			catch(e){
				alert("ocjw.wire.Error: " + e.toString());
				return 0;
			}

			/* primitive wires are created out of all values. */

			return _p.pw.wire(xp,x,yp,y,ep,e,_s.wire_id_label);
		};

		t.invokePrimitive = function(args,i,o,z){
			/*
				i = primitive wire id
				z = skip handler
				o = handler only, don't execute action
			*/
			var _pw = t.o.p.pw,r;
			
			if(typeof i == D.S ){
				if(!o){
					r = _pw.invoke(i,args,0,1,0,0,1);
				}
				if(
					o
					||
					r
				){
					if(!z){
						_pw.invoke(i,args,1,0,1,1,1);
					}
				}
				else{
/*					wire action returned false */

				}
			}

			return r;
		};

		t.invokeHardWireAction=function(o,i,a){
			/*
				o = object reference that contains primitive wire data
				i = wire id
				a = optional argument addition
				
				b = action_args array
				c = copy array
				a = optional args array
			*/
			var pw, c = [], b, l, k=0,_m = $E.message.MessageService;
			if(typeof o != D.O || typeof o.pw != D.O){
				_m.S("Invalid object reference for primitive wire","511.4");
				return 0;
			}
			pw = o.getPrimitiveWire(i);
			if(typeof pw != D.O){
				_m.S("Invalid primitive wire id " + i,"511.4");
				return 0;
			}
			
			b = pw.action_arguments;
			for(;k < b.length;) c[k] = b[k++];
			if(typeof a == D.O && (l = a.length) )
				for(k=0;k < l;) c[c.length] = a[k++];


			return t.invokePrimitive(c,pw.id,0,1);
		};

		t.invokeHardWireHandler=function(o,i,a){
			var pw,c = [], b, l, k=0,_m = $E.message.MessageService;
			if(typeof o != D.O || typeof o.pw != D.O){
				_m.S("Invalid object reference for primitive wire","511.4");
				return 0;
			}
			pw = o.getPrimitiveWire(i);
			if(typeof pw != D.O){
				_m.S("Invalid primitive wire id " + i,"511.4");
				return 0;
			}
			b = pw.handler_arguments;
			for(;k < b.length;) c[k] = b[k++];
			if(typeof a == D.O && (l = a.length) )
				for(k=0;k < l;) c[c.length] = a[k++];

			return t.invokePrimitive(c,pw.id,1,0);
		};

		/*
			A hard wire binds arguments with the action and handler.
		*/		
		t.hardWire=function(o,i,action_args,handler_args,ac,a,hc,h,ec,e,error_args){
			/*
				o = an object that has a pw hash object.
				i = id used for the pw hash lookup.  The value will be the primitive wire id, pid.
				ac = action class
				a = action
				hc = handler class
				h = handler
				ec = error class
				e = error
				
				pid = primitive id
			*/
			if(typeof o != D.O || typeof o.pw != D.O) return 0;

			var pid = t.primitiveWire(ac,a,hc,h,ec,e);
			if(pid != 0){
				o.pw[i] = {id:pid,action_arguments:action_args,handler_arguments:handler_args,error_arguments:error_args};
			}
			return pid;
		};

		$E.IM(t,"base_object","wire_service","0.0.0.2207.2004");
		$E.registry.ObjectRegistry.addObject(t);
		t.r = 4;
		return t;
	}
}

/*$E.wires.WireService=new $E.wires.WireServiceImpl();*/
/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/


/*
	The API requirements are:
		startTransaction
		endTransaction
		doTransaction
		
		startTransaction must return a boolean.  If it does not return true, the transaction will not be opened.
		doTransaction returns a boolean
*/
$EP("$E.transaction");

$E.transaction={

	TransactionService:null,
	
	TransactionServiceImpl:function(){

		var t = this;
	
		t.o={
			p:{
				r:[],
				rm:[]
			},
			s:{
				a:0,
				c:0,
				l:"swc.ocjt.transaction"
			}
		};
		
		t.sigterm = function(){
			var t = this,_p, a,i=0;
			_p = t.o.p;
			if(t.r != 5){
				_p.r = [];
				_p.rm = [];
				/* shut down all open transactions */
				a = _p.packets;
				for(;i < a.length; i++)
					t.closeTransaction(a[i].packet_id);
					
				_p.packets = [];
				_p.packetnames = [];
				_p.packetindex = [];
				
			}
		};
		
		t.getRegisteredObjects = function(){
			return this.o.p.r;	
		};
		t.getRegisteredObjectsMap = function(){
			return this.o.p.rm;	
		};

		t.canRegister=function(o){
			var _o = $E.registry.ObjectRegistry;
			if(
				/* object must be registered to use the transaction service */
				!_o.isRegistered(o.i)
				||
				/* object must also define the following API */
				typeof o.doTransaction != D.F
				||
				typeof o.startTransaction != D.F
				||
				typeof o.endTransaction != D.F
				
			){
				return 0;
			}
			return 1;
		};

		/*
			Is a given object registered with the transaction service?
			Note: this ultimately requires an object to be registered with the
			ObjectRegistry as only such objects may be registered with the TS service.
		*/
		t.isRegistered=function(o){
			var _p = t.o.p;

			if(
				typeof o == D.O && o != null
				&&
				typeof _p.rm[o.i] == D.N
				&&
				_p.r[_p.rm[o.i]]
			){
				return 1;
			}
			return 0;
		};

		/*
			Records an i with the transaction service if that object conforms to
			the required API, and is registered with the ObjectRegistry.
			

				
		*/		
		t.register=function(o){
			var _p = t.o.p,_m = $E.message.MessageService;
			if(
				!t.canRegister(o)
				||
				o.t == "transaction_service"
			){

				_m.S("Unable to register object " + o.t + " with transaction service","511.4");
				return 0;
			}

			_p.rm[o.i] = _p.r.length;
			_p.r[_p.r.length] = o.i;

			
			//_m.S("Transaction Service: registered object " + o.t + " (" + o.i + ")","210.1");
			
			
			return 1;
		};

		/*
			Enable an object to participate with a specific transaction.
			An object must be registered with the transaction service in order to 
			be added to the participant list.
		*/
		t.addTransactionParticipant = function(o,p){
			/*
				o = object
				p = transaction packet
			*/
			var _m = $E.message.MessageService;
			
			if(
				/* if the object is registered */
				t.isRegistered(o)
				&&
				/* and if the packet is really an active transaction packet */
				t.isPacket(p)
				&&
/*
				// and if this isn't the owner
				o.i != p.owner_id
				&&
*/
				/* and if this object is not already participating */
				!p.participants[o.i]
			){
				p.participants[o.i] = 1;
				p.participant_count++;

				/* invoke startTransaction for the object */
				if(!p.bst) o.startTransaction(t,p);

				
				//_m.S("Add participant " + o.i + " to transaction " + p.packet_id,"210.1");
				

				return 1;
			}
			return 0;
		};

		t.removeTransactionParticipant = function(o,p){
			/*
				o = object
				p = transaction packet
			*/
			var _m = $E.message.MessageService;
			
			if(
				/* if the object is registered */
				t.isRegistered(o)
				&&
				/* and if the packet is really an active transaction packet */
				t.isPacket(p)
				&&
/*
				// and if this isn't the owner
				o.i != p.owner_id
				&&
*/
				/* and if this object is participating */
				p.participants[o.i]
			){
				p.participants[o.i] = 0;
				p.participant_count--;

				
				_m.S("Remove participant " + o.i + " from transaction " + p.packet_id,"210.1");
				

				return 1;
			}
			return 0;
		};

		t.serveTransaction = function(p,x,b){
			/*
				p = transaction packet
				x = controller id, defaults to owner_id if not specified
				b = skip serving the controller
				
				o = object
				a = array of transaction participants
				i = item in array a
				d = object id a[i]
				r = return value from doTransaction
				
			*/
			var _m = $E.message.MessageService,
				_o = $E.registry.ObjectRegistry,
				o,a,i,d,r
			;
			
			if(t.isPacket(p)){
	
				if(!p.is_open || !p.participant_count) return 0;
	
				if(typeof x == D.U) x = p.owner_id;
				a = p.participants;

				/* serve the controller first */
				if(
					x
					&&
					_o.isRegistered(x)
					&&
					!b
					&&

					(
						(p.serve_type == 1 && a[x]!=2)
						||
						(p.serve_type == 2 && !a[x])
					)
				){


					o = _o.getObject(x);
					if(t.isRegistered(o) && a[o.i]){
						r = (o.doTransaction(t,p)?1:0);
						if(r && p.serve_type == 1) a[x] = 2;
					}

				}
/*
				_m.S("Test: x=" + x + ", block = " + p.btt + " / " + (!x || !p.btt),"200.1");
*/
				if(!x || !p.btt){

					for(i in a){
						d = a[i];

						if(
							/* the object is participating */
							a[i]
							&&
							/* the transaction doesn't continue serving until true, or the serve action returned true */
							(
								(p.serve_type == 1 && a[i]!=2)
								||
								(p.serve_type == 2 && !a[i])
							)
							&&
							_o.isRegistered(i)
							&&
							i != x
						){

							
							_m.S("Serve transaction to object id " + i,"203.1");
							
							
							o = _o.getObject(i);
							if(t.isRegistered(o)){
								r = (o.doTransaction(t,p)?1:0);
								if(r && p.serve_type == 1) a[i] = 2;
							}

						}
/*
						else{
							_m.S("Don't serve transaction to object id " + i + " / " + _o.isRegistered(i) + " / " + a[i] + " / " + p.serve_type,"203.1");
						}
*/
					}
				}
				/* reuse r; */
				r = 1;
				
				/*
					Determine if all participants are finished with the transaction.
				*/
				for(i in a){
					if(
						(p.serve_type == 1 && a[i]!=2)
						||
						(p.serve_type == 2 && !a[i])
					){
						r = 0;
						break;
					}
				}

				if(r) t.XT(p);
/*
				stop_time = $E.util.getDate();
				_m.S("Serve Transaction Time: " + (stop_time - start_time) + " / Finished = " + r,"200.1");
*/


				return 1;
			}
			else{
				_m.S("Invalid transaction packet.","511.4");
			}
			return 0;
		};
		
		t.XT = function(p){
 			var _m = $E.message.MessageService,
				_o = $E.registry.ObjectRegistry,
				a,i,o
			;

 			if(t.isPacket(p)){
				if(p.is_open){
					a = p.participants;
					p.is_open = 0;

					if(
						p.owner_id
						&&
						_o.isRegistered(p.owner_id)
					){
						o = _o.getObject(p.owner_id);
						o.endTransaction(t,p);
					}
					if(!p.owner_id || !p.bet){
						for(i in a){
							if(p.owner_id != i){
								o = _o.getObject(i);
								if(	o != null ){
									o.endTransaction(t,p);
								}
								else{
									_m.S("Null object reference " + i,"540.4");
								}
							}
							
							a[i] = 0;
							
						}
					}

					
					p.sp = $E.util.getDate();
					p.is_finalized = 1;

										
					_m.S("Transaction ended in " + (p.sp - p.st),"203.1");
					

					if(typeof p.handler == D.F){
						p.handler(t,p);
					}
					
				}
				else{
					_m.S("Transaction packet is not open.","200.4");
				}
				
				
				
			}
			else{
				_m.S("Invalid transaction packet.","200.4");
			}
			
		};
		
		t.ST = function(p,o){
			/*
				 p = parent object
				 o = transaction object
				 
				 
			*/

			var n,a = t.o.p.r,c;

			/*
				if a parent is specified, the parent will get to start the transaction
				and determine whether other  objects need to receive the startTransaction call
			*/

			if(typeof p == D.O){
				/*
					block applies when a parent is provided and is used to allow an 
					object to determine whether other objects should/need to receive
					the startTransaction call
				*/

				o.bst = 1;

				v = 
					o.participants[p.i] = 
						(p.startTransaction(t,o) ? 1 : 0);
				
				o.participant_count += v;
				
			}
			/*
				if a parent wasn't specified, or the parent disabled block_start
			*/
/*

// NOT USED BECAUSE START IS CALLED IMMEDIATELY FROM OPEN

			if(!p || !o.bst){
			/ * reuse c and n * /
				for(c = 0;c<a.length;c++){
					/ * this isn't the parent because * /
					/ * the parent already received the call above * /

					if(p && p.i == a[c]) continue;
					n = $E.registry.ObjectRegistry.getObject(a[c]);

					if(	n != null ){
						v = 
							o.participants[n.i] = 
								(n.startTransaction(t,o) ? 1 : 0);
	
						o.participant_count += v;
					}
	
				}
			}
*/
			if(o.participant_count){
				o.st = $E.util.getDate();
				o.is_open = 1;
				return 1;
				
			}
				
			return 0;
			
		};
		
		t.closeTransaction = function(i){
			/*
				transaction name;
			*/
			var _p = t.o.p,o,m,_m = $E.message.MessageService;
			o = t.getPacket(i);
			if(t.isPacket(o)){
				m = _p.packetindex[i];
				
				_p.packetnames[o.packet_name] = 0;
				_p.packetindex[i] = 0;
				_p.packets[m] = 0;

				
				_m.S("Close transaction " + i,"200.1");
				
/*
				if(typeof o.handler == D.F){
					o.handler(t,o);
				}
*/
			}
			else{
				_m.S("Invalid packet id " + i,"200.4");
			}
		};
		
		t.openTransaction = function(n,p,d,f){
			/*
				n = transaction name
				p = parent object; can be null, or must be registered with the transaction service
				i = transaction id
				o = new transaction
				c = index into transactions array
				d = data
				a = pointer to r array
				v = registered object 
			*/

			var i,
				_j = $E,
				o,
				c,
				_p = t.o.p,
				_s = t.o.s,
				_m = $E.message.MessageService
			;
			


			i = _s.l + ":" + (++_s.c);
			
			if(typeof n == D.U) n = i;
			if(typeof d == D.U) d = 0;
			if(typeof f == D.U) f = 0;
			
			if(typeof p == D.O){
				if(!t.isRegistered(p)){
					_m.S("Invalid transaction owner.","200.4");
					return 0;
				}
			}
			else{
				p = 0;
			}
			
			/*
				Check to see if a transaction exists with this name.
				If so, then just return the name again.
			*/
			if(
				typeof _p.packetnames[n] == D.N
				&&
				typeof _p.packets[_p.packetnames[n]] == D.O
				&&
				_p.packets[_p.packetnames[n]].is_open
			){
				_m.S("Transaction " + n + " is already open.","200.4");

				return 0;
			}
			
			o = _j.FN("packet_object",i,n,p.i,d,f);
			
			c = _p.packets.length;
			_p.packetnames[n] = c;
			_p.packetindex[i] = c;
			_p.packets[c] = o;



			if(t.ST(p,o)){
				/* _m.S("Transaction " + n + " was opened for " + o.participant_count + " object(s).","200.1");*/
				if(_s.a) t.serveTransaction(o);
			}
			else{
				_m.S("Transaction " + n + " was not opened.","200.4");
			}

			
			return i;
			
		};
		$E.object.IOA(t,"packet");
		$E.IM(t,"base_object","transaction_service","0.1a");
		$E.registry.ObjectRegistry.addObject(t);
		t.r = 4;
	}
}

$E.transaction.TransactionService=new $E.transaction.TransactionServiceImpl();

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002 - 2004, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

/*
	BUGS
		BUG: circa line 672 in i
			When a task imports another task, a dependency was not being set.
			Adding the dependency fails because the parent task fails to wait for it.
			
		FIX: Don't move a task from the handled to the completed state unless there are no dependencies
		FIX: Add the new task as a dependent to the parent task
			
	
		BUG: EVENT should be MESSAGE		
*/

/*
 * 2004/07/21
 * Add better cleanup
 * 
 */

$EP("$E.task");

$E.task={
	TaskService:null,
	TaskServiceImpl:function(){
		var t=this,
			_j=$E,
			_x=$E.xml,
			_m=$E.message.MessageService,
			_t=$E.transaction.TransactionService
		;
		
		t.o={
			p:{
/*
				tasks:[],
				taskindex:[],
				tasknames:[],
*/
				rd:[]
			},
			s:{
				/* external_tasks_name */
				etn:0,
				/* etl */
				etl:0,

				wl:0,
				/* task_id_counter:0, */
				til:"task_trans_",
				sd:0

			},
			data:{
				a:0,
				b:1,
				c:2,
				d:3,
				e:4,
				f:5,
				
				g:99,
				
				h:"xml",
				i:"task",
				j:"import-task",
				k:D.F,
				l:"event",
				m:"script",
				
				/*
					the xpath context is used for identifying the exact location of the tasks node 
					if tasks is the root, then the context should be empty
				*/
				n:"" /* tasks/ */
				
				
			}
		};

		t.clearTask=function(i){
			var _p = t.o.p,o,l;

			if(typeof i == D.S) o = t.getTask(i);
			if(typeof i == D.O) o = i;

			if(t.isTask(o)){
			
				if(o.task_state < t.o.data.f){

					
					_m.S("Set task " + o.task_name + " to self destruct.","200.1");
					

					o.setAutoDestroy(1);
					return 1;
				}
			
				l = _p.taskindex[o.task_id];
				
				_p.tasks[l] = 0;
				_p.taskindex[o.task_id]=null;
				_p.tasknames[o.task_name]=null;

				_t.closeTransaction(o.transaction_id);

				
				_m.S("Clear task " + o.task_id,"200.1");
					
				
				return 1;
			}
			else{
				_m.S("Invalid task id " + i,"200.4",1);
			}
			return 0;
		};
		t.clearTasks = function(){
			var _p = t.o.p,_s = t.o.s,a,i,o;
			a = _p.tasks;

			_p.tasks = [];
			_p.taskindex = [];
			_p.tasknames = [];
			_p.rd = [];
/*
			_s.driver_name = 0;
			_s.driver_loaded = 0;
*/
			_s.etn = 0;
			_s.etl = 0;
			
			/* _s.task_id_counter = 0; */
			
			for(i = 0;i<a.length;i++){
				o = a[i];
				_t.closeTransaction(o.transaction_id);
			}
			
			if(_s.wl){
				t.returnDependency("dom_event_window_load");
			}

			
			_m.S("Reset task information.","200.1");
			

		};
		t.destroy = function(){
			var t = this;
			if(t.r != 5){
				t.r = 5;
				$E.message.MessageService.unsubscribe(t,"dom_event_window_load","_handle_window_load");
				$E.message.MessageService.unsubscribe(t,"destroy","HWD",window);
				t.clearTasks();
				t.o.p.rd = [];
/*
				c.p.tasks=[];
				c.p.taskindex=[];
				c.p.tasknames=[];
*/
			}
		};

		t.sigterm=function(){
			this.destroy();
		};

		t.HWD=function(s,v){
			this.destroy();
		};
/*
		t.isDriverLoaded = function(){
			return t.o.s.driver_loaded;
		};
*/
		t.isExternalLoaded = function(){
			return t.o.s.etl;
		};
/*
		t.getTaskByName=function(s){
			var c=t.o.p;
			if(typeof c.tasknames[s]==D.N) return c.tasks[c.tasknames[s]];
			return 0;
		};

		t.getTask = function(i){
			var _p = t.o.p;
			if(
				typeof _p.taskindex[i] == D.N
				&&
				typeof _p.tasks[_p.taskindex[i]] == D.O
			){
				return _p.tasks[_p.taskindex[i]];
			}
			return 0;
		};

		t.isTask = function(o){
			var _p = t.o.p;
			if(
				typeof o == D.O && o != null
				&&
				typeof _p.taskindex[o.task_id] == D.N
				&&
				typeof _p.tasks[_p.taskindex[o.task_id]] == D.O
			){
				return 1;
			}
			return 0;
		};
*/		
		t.addTaskDependency=function(o,d){
			/*
				o = task object
				d = dependency name
			*/
			/*
				If the task dependency has not already been returned,
				then add it.
			*/
			if(t.isTask(o) && !t.o.p.rd[d]){
				o.depends[o.depends.length]=d;

				
				_m.S("Add dependency on " + d + " to " + o.task_name,"200.1");
				

				return 1;
			}

			return 0;

			/*
				fix for window load
			*/
			
			/*
			if(
				t.o.s.window_loaded
				&&
				i == "_dom_event_window_load"
			){
				t.returnDependency("_dom_event_window_load",1);
			}
			*/
		
		};

		t.getTaskDepends=function(o){
			var h,m,r=[];
			
			if(!t.isTask(o)) return r;
			
			if(!o.depends.length) return r;
			for(h=0;h<o.depends.length;h++)
				r[h]=o.depends[h];

			return r;
		};

		t.returnDependency=function(v){
			
			var o,_p = t.o.p;
			
			if(t.isTask(v)){
				o = v;
				v = v.task_name;
			}
			else{
				o = t.getTaskByName(v);
			}

			/* _m.S("Return dependency " + v,"200.1");*/

			/*
				If the dependency is a task, then check that task state
				and promote it to be handled.
				
				This has the effect of forcing a task to be completed regardless
				of whether its action or handler were executed.
			*/
			if(
				t.isTask(o)
				&&
				o.task_state < t.o.data.e

			){
				
				o.task_state = t.o.data.e;
			}

			if(!_p.rd[v]){
				_p.rd[v] = 1;

				
				_m.S("Return dependency '" + v + "'","200.1");
				

				t.UT(v);
			}

			return 1;		

		};

		t.clearDependency=function(v){
			
			var o,_p = t.o.p;
			
			if(t.isTask(v)){
				o = v;
				v = v.task_name;
			}
			else{
				o = t.getTaskByName(v);
			}

			if(_p.rd[v]){
				_p.rd[v] = 0;

				
				_m.S("Clear dependency '" + v + "'","200.1");
				

				t.UT(v);
			}

			return 1;		

		};
		
		t.UT=function(s){
			var a,o,i,h,m,_d = t.o.data;
			a = t.o.p.tasks;
			
			for(i=0;i<a.length;i++){
				o = a[i];

				if(
					typeof o != D.O
					||
					o.task_state == _d.f
					/* || !o.depends.length */
					
				){
					continue;
				}

				m = 0;

				for(h=0;h<o.depends.length;h++){
					if(o.depends[h] == s){
						o.depends[h] = 0;
					}
					else if(o.depends[h] != 0){
						m = 1;
					}
				}
				if(!m){
					o.depends = [];
					t.serveTaskTransaction(o);
				}
			}

		};
		

		t.isTaskComplete = function(o){
			if(
				t.isTask(o)
				&&
				o.task_state == t.o.data.f
			){
				return 1;
			}
			return 0;
		};
		t.serveTaskTransaction = function(o){
			var t = this;
			if(t.isTask(o) && t.o.s.sd){
				setTimeout("$E.registry.ObjectRegistry.getObject('" + t.i + "').ST('" + o.task_id + "')",t.o.s.sd);
			}
			else{
				t.ST(o);
			}
		};
		t.ST = function(o){

			if(typeof o == D.S) o = t.getTask(o);

			if(t.isTask(o)){
				var z = _t.getPacket(o.transaction_id),_d = t.o.data;
				if(z){
					/* _m.S("Execute task " + o.task_id + " via transaction service","200.1");*/
					_t.serveTransaction(z,t.i);
					return 1;
				}
				else{
					_m.S("Task could not be executed as a transaction.","200.4");
					return 0;
				}
			}
			else{
				_m.S("Tasks: object is not a task.  Auto-Destroyed tasks may also cause this message.","511.4");
			}
		};

		/*
			executeTaskHandler
			
			if a task was executed, but not the handler,
			this allows the handler to be executed and thus complete the transaction
			if there are no dependencies
		*/
		t.executeTaskHandler = function(o){
			var _d = t.o.data;
			if(t.isTask(o)){
				if(o.task_state == _d.c && o.executed && !o.handled){
					o.task_state = _d.d;

					
					_m.S("Execute task handler " + o.task_name + " (" + o.task_state + " / " + o.executed + " / " + o.handled + ")","200.1");
					
					
					t.serveTaskTransaction(o);
					return 1;
				}
				else{
					_m.S("Task handler " + o.task_name + " (" + o.task_state + " / " + o.executed + " / " + o.handled + ") cannot be served at this time.","511.4");
				}
			}
			else{
				_m.S("Task object cannot be executed.","511.4");
			}
			return 0;
		};

		t.executeTaskHandlerByName = function(n){
			return t.executeTaskHandler(t.getTaskByName(n));
		};

		t.executeTaskByName = function(n){
			t.executeTask(t.getTaskByName(n));
		};

		t.executeTask = function(o){
			/*
				o = task object
				
				z = transaction
			*/
			var _d = t.o.data;
			


			if(t.isTask(o)){
				if(o.task_state != _d.b){

					
					_m.S("Task cannot be executed from state " + o.task_state,"200.1");
					

					return 0;
				}
				o.task_state = _d.c;
				t.serveTaskTransaction(o);
				
			}
			else{
				_m.S("Task object cannot be executed.","511.4");
			}
		};
		
		t.importTaskFromXml=function(n,p,d,b){
			/*
				n = task node / task name
				p = parent task
				d = xml document
				b = execute this task immediately
				
				r = rid
				i = id
				
				v = variant
				
			*/
			var r,i,a,at,h,ht,z,_c = t.o,x,pi,v;
			
			if(
				typeof d != D.O
			){
				if(p && p.action_type.match(/xml/) && typeof p.data == D.O){
					d = p.data;
					pi = p.task_id;
				}
				else if(_c.s.etl){
					z = t.getTaskByName(t.o.s.etn);
					if(z) d = z.data;
				}
			}
			
			if(!pi && p) pi = (p.parent_id ? p.parent_id : p.task_id);
			
			if(typeof d != D.O || d == null){

				
				_m.S("Unable to import task from null xml document.","200.4");
				

				return 0;
			}
			
			if(typeof n == D.S){
				z = _x.queryNode(d.documentElement,"task",0,"id",n);/*_x.selectSingleNode(d,_c.data.n + "task[@id = '" + n + "']",d.documentElement);*/
				if(typeof z == D.O && z != null){
					return t.importTaskFromXml(z,p,d,b);
				}
				else{
					_m.S("Task '" + n + "' does not exist","200.4");
				}
			}

			if(
				typeof n == D.O
				&& n != null
				&& typeof d == D.O
				&& d != null
			){
				if( (r = n.getAttribute("rid")) != null){
					z = _x.queryNode(d.documentElement,"task",0,"id",r);/*_x.selectSingleNode(d,_c.data.n + "task[@id = '" + r + "']",d.documentElement);*/
					if(typeof z == D.O && z != null){
						/* _m.S("Import task from reference-id " + r,"200.1");*/
						if(n.getAttribute("auto-execute") == "1") b = 1;
						t.importTaskFromXml(z,p,0,b);
						return 1;
					}
					else{
						_m.S("Task id " + r + " does not exist","200.4");
					}
				}
				else if( ( i = n.getAttribute("id")) != null){
	
					/* _m.S("Import task from id " + i,"200.1");*/
	
					a = n.getAttribute("action");
					at = n.getAttribute("action-type");
					h = n.getAttribute("handler");
					ht = n.getAttribute("handler-type");
	
					if(typeof p==D.O){
						t.addTaskDependency(p,i);
						/*p.depends[p.depends.length]=i;*/
					}
					
					p = t.addTask(i,at,a,ht,h);
					
					
					
					if(!t.isTask(p)) return 0;
					if(pi) p.parent_id = pi;
					
					z = n.getElementsByTagName("task");/*_x.selectNodes(d,"task",n);*/
					
					for(x = 0;x<z.length;x++)
						t.importTaskFromXml(z[x],p);
					
					
					z = n.getElementsByTagName("depends");/*_x.selectNodes(d,"depends",n);*/
					for(x = 0;x<z.length;x++){
						if(typeof z[x].getAttribute("rid") == D.S){
							t.addTaskDependency(p,z[x].getAttribute("rid"));
						}
					}
					
					if(b){
						/* _m.S("Auto-Execute task " + p.task_name,"200.1"); */
						t.executeTask(p);
					}
					
					return 1;
	
				}
				else{
					_m.S("Task does not define an id or reference-id","200.4");
				}
			}
			return 0;
		};
/*
		t.executeTaskDriver=function(n,at,a,ht,h){
			var i = t.addTaskDriver(n,at,a,ht,h);
			t.executeTask(i);
		};

		t.addTaskDriver=function(n,at,a,ht,h){
			t.o.s.driver_loaded=0;
			t.o.s.driver_name = n;
			return t.addTask(n,at,a,ht,h);

		};
*/
		t.executeTaskLoader=function(n,at,a,ht,h){
			var i = t.addTaskLoader(n,at,a,ht,h);
			t.executeTask(i);
		};

		t.addTaskLoader=function(n,at,a,ht,h){
			t.o.s.etl=0;
			t.o.s.etn = n;
			return t.addTask(n,at,a,ht,h);
		};

		t.addTask=function(n,at,a,ht,h){
			/*
				n = config name of bootstrap
				p = type/protocol
				xxx s = source/action
				at = action type
				a = action
				ht = handler type
				h = handler
				xxx d = dependencies
			*/
			var v,i,l,c,tid;

			c=t.o;
			/*i = c.s.til + (++c.s.task_id_counter);*/
			i = c.s.til + (++$E.util.driver.ApplicationDriver.o.s.gc);
			if(typeof c.p.tasknames[n]==D.N){

				
				_m.S("Duplicate task id","511.1");
				

				return 0;
			}

			l=c.p.tasks.length;
			if(typeof h!=D.S && typeof h!=D.F) h = 0;
			if(!h) ht=0;

			v = _j.FN("task_object",n,at,a,ht,h,i,l,0);

			c.p.tasks[l]=v;
			c.p.tasknames[n]=l;
			c.p.taskindex[i]=l;
			
			tid = _t.openTransaction(i,t,{id:i,name:n});

			v.transaction_id = tid;
			

			
			return v;

		};
		
		t.doTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var v,_d = t.o.data,_s = t.o.s;
			v = t.getTask(p.data.id);
			if(v){
				/* _m.S("Tasks: do transaction (" + v.transaction_id + ") for " + v.task_name + " at state " + v.task_state,"200.1"); */
				switch(v.task_state){

					case _d.b:
					
						break;

					case _d.c:
						if(!v.executed){
							v.executed = 1;
							/* _m.S("Perform Task Action " + v.action_type,"200.1");*/
							t.EA(v,0);
						}
						break;
					case _d.d:
						if(!v.handled){

							if(v.task_name == _s.etn){
								_s.etl=1;
							}

							if(!v.depends.length){
								v.handled = 1;

								
								_m.S("Perform Task " + v.task_name + " Handler " + v.handler_type,"200.1");
								

								t.EA(v,1);
							}
							else{
								/* _m.S("Delay task handler until dependencies are finished","200.1"); */
							}					
						}
						break;
					case _d.e:

												
						_m.S("Verify task " + v.task_name + " / d = " + v.depends.length + " / ex = " + v.executed + " / hd = " + v.handled + " / s = " + v.task_state,"200.1");						
						

						if(!v.depends.length){
							v.task_state = _d.f;
							t.serveTaskTransaction(v);
						}
						break;
					case _d.f:
						if(
							!v.depends.length
							&&
							v.executed
							&&
							v.handled
						){
							t.returnDependency(v.task_name);
						}
						else{
							_m.S("Task " + v.task_name + " was completed without an action, handler, or with dependencies","200.4");
						}
						
						return 1;
						break;
					case _d.g:
						return 1;
						break;
					default:
						_m.S("Task " + v.task_name + " in state " + v.task_state + " will not be handled.","200.4");
						break;
				}
			}
			else{
				_m.S("Invalid task reference for " + p.data.id,"200.4");
			}

			return 0;
		};
		
		t.EA=function(o,z){
			/*
				o = task object
				z = switch for using the action or handler
			
			*/
			
			var x,y,_d = t.o.data,_s = t.o.s,d,n,z,r,i,v;
			x = (z?o.handler:o.action);
			y = (z?o.handler_type:o.action_type);
			/* _m.S("Execute task action: " + y,"200.1"); */
			if(t.isTask(o)){
				switch(y){
					case _d.l:
						if(o.task_state == _d.d) o.task_state = _d.e;
						if(o.task_state <= _d.c) o.task_state = _d.d;
						_m.publish(x,{service:t,task:o});
						t.serveTaskTransaction(o);
						break;
					case _d.h:
						_x.getXml(x,t.HLX,1,o.task_id);
						break;
					case _d.i:
						t.executeTaskByName(x);
						t.serveTaskTransaction(o);
						return 1;
						break;
					case _d.j:

						
						/*_m.S("Task execute for " + x + " not ready.","200.4");*/
						_m.S("Execute task import for " + x + " as a dependent to " + o.task_name,"200.1");
						

						t.importTaskFromXml(x,o);
/*
						t.addTaskDependency(o,x);
*/
/*						if(z){*/
							if(o.task_state == _d.d) o.task_state = _d.e;
							if(o.task_state <= _d.c) o.task_state = _d.d;
							t.executeTaskByName(x);
							t.serveTaskTransaction(o);
							
							
							return 1;
/*						}*/
						
						break;
					case _d.m:
						if(x == "#cdata"){
							try{
								v = (o.parent_id ? t.getTask(o.parent_id) : 0);
								if(!v || !t.isTask(v)) v = (_s.etl ? t.getTaskByName(_s.etn) : 0);
								if(v){
									d = v.data;
									z = _x.queryNode(d.documentElement,"task",0,"id",o.task_name);/*_x.selectSingleNode(d,_d.n + "task[@id = '" + o.task_name + "']",d.documentElement);*/
									if(typeof z == D.O && z != null){
										n = _x.getCDATAValue(z);
										eval(n);
										/* move the task state up one */
/*
										if(o.task_state == _d.d) o.task_state = _d.e;
										if(o.task_state <= _d.c) o.task_state = _d.d;
*/
										t.serveTaskTransaction(o);
										return 1;
									}
									else{
										_m.S("Null task id pointer","200.4");
										return 0;
									}

								}
								else{
									_m.S("Cannot execute #cdata task action without xml document","200.4");
									return 0;
								}
							}
							catch(e){
								_m.S("Error executing #cdata action: " + (e.description?e.description:e.message),"200.4");
								return 0;
							}
						}
						break;
					case _d.k:

						try{
							z = eval(x);
							r = 1;
							if(typeof z == D.F){
								r = z(o.task_name,t);
							}
							
							if(r){
								if(o.task_state == _d.d) o.task_state = _d.e;
								if(o.task_state <= _d.c) o.task_state = _d.d;
							}

							t.serveTaskTransaction(o);
						}
						catch(e){
							_m.S("Error executing function action: " + (e.description?e.description:e.message),"200.4");
							return 0;
						}


						break;
					default:
						/* _m.S("Advancing unhandled task execution " + y + " from " + o.task_state,"200.4");*/

						if(o.task_state == _d.d) o.task_state = _d.e;
						if(o.task_state <= _d.c) o.task_state = _d.d;

						t.serveTaskTransaction(o);
						break;
				}
			}
			else{
				_m.S("Invalid task reference","200.4");
			}
			return 0;
		};
		
		/*
			The transaction_id is not set on the task object until after
			startTransaction is invoked.
		*/
		
		t.startTransaction=function(s,p){
			/*
				s = service
				p = packet
				
			*/
			var v,_d = t.o.data;
			v = t.getTask(p.data.id);
			if(v){
		
				v.task_state = _d.b;
				/*_m.S("Tasks: start transaction " + p.transaction_name + " for " + t.t,"200.1");*/
			}
			else{
				_m.S("Invalid task id " + p.data.id,"200.4");
			}
			return 1;

		};
		
		
		t.endTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var v = t.getTask(p.data.id);
			if(v.ad){
				v.task_state = t.o.data.g;
				t.clearTask(v);
			}

			
			_m.S("End task " + v.task_name + " for " + t.t,"200.1");
			

			return 1;
		};

		t.HLX=function(n,x){

			var i = x.id,c=t.o,b,_d,a,z;
			_d = c.data;
				/* if this was a bootstrap event*/

			b = t.getTask(i);
			
			if(b){

				if(
					typeof x.xdom != D.U
				){
					b.data = x.xdom;
				}
				else{
					_m.S("Null XML Response","512.5",1);
				}

				b.task_state = _d.d;

				/* _m.S("Task " + b.task_name + " action (" + b.action_type + ") completed.","200.1");*/

				t.serveTaskTransaction(b);

			}
			else{
				_m.S("Invalid task identifier in xml handler","200.4")
			}
		};
		
		t._handle_window_load=function(){
			t.o.s.wl = 1;
			t.returnDependency("dom_event_window_load");
		};

		_j.IM(t,"base_object","task_service","0.1a");
		
		_j.object.IOA(t,"task");
		
		_j.registry.ObjectRegistry.addObject(t);
		_t.register(t);

		_m.subscribe(t,"dom_event_window_load","_handle_window_load");
		_m.subscribe(t,"destroy","HWD",window);
		
		t.r = 4;

	}
}

$E.task.TaskService=new $E.task.TaskServiceImpl();

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
	
*/

/*
	BUGS
		fixed - Primary and default actions and handlers should also be declarative on engine elements


	DECLARATIONS
		is-engine
		engine-id
		engine-action
		engine-action-type
		engine-handler
		engine-handler-type
		engine-onload
		engine-config-task
		engine-config
*/

/*
	Engine Component Config
		v = {
				object:{object reference},
				config:"{name of current configuration}",
				rid:"{reference id}"
			}
*/

$EP("$E.engine");
$E.engine={
	EngineService:null,
	EngineServiceImpl:function(){
		var t=this,
			_j=$E,
			_x=$E.xml,
			_m=$E.message.MessageService
			/*_t=$E.task.TaskService*/
		;



		t.o={
			s:{
				pn:"engine_loader",
				pa:"[nothing]",
				pat:"default",
				ph:"engine_service_initialized",
				pht:"event",
				
				dn:"engine",
				da:"[nothing]",
				dat:"default",
				dh:"engine_started",
				dht:"event",

				eac:0,
				ic:0,
				il:"swc.ocj.engine",
				
				/* automatically load engines when window.onload fires */
				al:1,

				/* name of the task that loaded the configuration, if any */
				/* page_pt */
				pt:"load_engine_config",

				/* name of the page configuration to use as a default */
				/* page_pd */
				pd:0 /*"debug"*/
				
			},
			p:{
/*
				engines:[],
				enginenames:[],
				engineindex:[],
*/
				ts:new $E.task.TaskServiceImpl(),
				ws:$E.wires.wire.newInstance()
			}
		};

		t.getWireService = function(){
			return t.o.p.ws;
		};
		t.getTaskService = function(){
			return t.o.p.ts;
		};

		/*
			AutoLoad is only valid prior to the window.onload event firing
		*/
		t.setAutoLoad=function(b){
			t.o.s.al = (b?1:0);
		};
		t.setConfigurationTaskName=function(s){
			t.o.s.pt = s;
		};
		t.setDefaultConfiguration=function(s){
			t.o.s.pd = s;
		};
		t.setPrimaryEngineAction=function(s){
			t.o.s.pa = s;
		};
		t.setPrimaryEngineActionType=function(s){
			t.o.s.pat = s;
		};
		t.setPrimaryEngineHandler=function(s){
			t.o.s.ph = s;
		};
		t.setPrimaryEngineHandlerType=function(s){
			t.o.s.pht = s;
		};
		t.getComponentFromEngine=function(i,c,b){
				/*
					i = engine id
					c = component id
					b = switch to return the object, or the object container
				*/
			var _m = $E.message.MessageService,
				e,
				o
			;
			e = t.getEngine(i);
			if(!t.isEngine(e)){
				_m.S("Invalid engine reference","200.4",1);
				return 0;
			}
			o = e.getObjectByName(c);
			if(!o){
				_m.S("Invalid engine component reference '" + c + "'","200.4",1);
				return 0;
			}
			if(typeof o.object == "object"){
				if(!b){
					return o.object
				}
				else if(typeof o.object.getContainer == "function"){
					return o.object.getContainer();
				}
			}

			return 0;

		};

		t.sigterm = function(){
			this.destroy();
		};
		t.destroy = function(){
			var t = this,_m = $E.message.MessageService;
			if(t.r != 5){

				_m.unsubscribe(t,"dom_event_window_load","handle_window_load");
				_m.unsubscribe(t,"engine_started","HES");
				_m.unsubscribe(t,"engine_service_initialized","HEI");

				t.r = 5;
				t.clearEngines();
			}
		};

		t.clearEngine = function(i){
			var _p = t.o.p,o,b,h;

			if(typeof i == D.S) o = t.getEngine(i);
			if(typeof i == D.O) o = i;
			
			if(t.isEngine(o)){
				
				b = o.eo;
				for(h = b.length - 1; h >= 0; h--){
					_j.registry.ObjectRegistry.sendDestroyTo(b[h].object);
				}

				o.eo = [];
				o.en = [];
				o.ei = [];
				
				
				o.engine_implementations = [];
				
				
				if(o.engine_element){
					_x.removeChildren(o.engine_element);
					o.engine_element.parentNode.removeChild(o.engine_element);
				}
				

				_p.engines[o.engine_index] = null;
				_p.engineindex[o.engine_id] = null;
				_p.enginenames[o.engine_name] = null;
				
				
				_m.S("Clear engine '" + i + "'","200.1");
				
			}
			else{
				_m.S("Invalid engine reference '" + i + "'","200.4");
			}
		};
		
		t.clearEngines=function(){

			var _p = t.o.p,a,i,o,h,b,_t;
			a = _p.engines;
			_t = _p.ts;
			
			/*
				Clean up any objects associated with the engines
			*/
			
			for(i = a.length - 1;i >= 0; i--){
				t.clearEngine(a[i]);

/*
				b = a[i].eo;
				for(h=b.length-1;h>=0;h--){
					_j.registry.ObjectRegistry.sendDestroyTo(b[h].object);
				}
*/			
			}

			_p.engines = [];
			_p.engineindex = [];
			_p.enginenames = [];
			/*
			for(i = 0;i<a.length;i++){
				o = a[i];
				_t.clearTask(o.task);
			}
			*/
			
			_t.clearTasks();

						
			_m.S("Reset engine information.","200.1");
			

		};
		


		t.getPrimaryEngine = function(){
			return t.getEngineByName(t.o.s.pn);
		};

		t.handle_window_load=function(){
/*			_m.S("Engine Service Init","200.1");*/
			if(t.o.s.al) t.loadEngines();
		};
		t.loadEngines=function(b){
			/*
				b = switch used to force load the primary engine
			
				o = task for engine
				m = array of engine elements
				e = element in a array
				i = iterator
				v = engine object instance
				s = default for engine; varies whether it is the primary engine
				x = method used to add task, varies whether it is the primary engine
				
				a = action
				at = action_type
				h = handler
				ht = handler_type
				
				l = length
				
				n = name
				z = id
				
				pn = page config task name
			*/

			var _p = t.o.p,o,m=[],e,i,v,_s = t.o.s,s = "p",x,_t,a,at,h,ht,l,n,z,c,p,q,pn;

			_t = _p.ts;
			x = _t.addTaskLoader;
			
			if(document.body == null){
				_m.S("Engine unable to initialize due to unexpected DOM.","200.5",1);
				return 0;
			}

			q = document.getElementsByTagName("engine");
			for(i=0;i<q.length;i++){ m[m.length]=q[i]; }

			p = _x.queryNodes(document.body,"div",null,"is-engine","1");
			for(i=0;i<p.length;i++){ m[m.length]=p[i]; }

			/*
				force load a primary engine if no <engine /> tag was provided
			*/
			if(!b && !m.length && !_p.engines.length) return t.loadEngines(1);

			if(b){

				
				_m.S("Force load a primary engine","200.1");
				

				m = [1];
			}
			
			for(i = 0;i < m.length; i++){
				if(!b) e = m[i];
				
				c = ++_s.ic;
				
				if(_p.engines.length > 0){
					s = "d";
					x = _t.addTask;
					n = _s[s + "n"] + "_" + c;
				}
				else{
					n = _s[s + "n"];
				}
				
				z = _s.il + "_" + c;
				
				/* if forced, the element is invalid so check for !b */
				/*  && typeof e == D.O && e != null */
				if(!b){
					if(typeof e.getAttribute("name") == D.S){
						n = e.getAttribute("name");
					}
					else{
						e.setAttribute("name",n);
					}
					if(typeof e.getAttribute("engine-id") == D.S){
						z = e.getAttribute("engine-id");
					}
					else{
						e.setAttribute("engine-id",z);
					}
				}

				if(t.getEngineByName(n)){
					
					_m.S("Engine " + n + " (" + z + ") is already loaded.","200.1");
					
					continue;
				}
/*				
				a = _s[s + "engine_action"];
				at = _s[s + "engine_action_type"];
				h = _s[s + "engine_handler"];
				ht = _s[s + "engine_handler_type"];
*/			
				if(!b && typeof e.getAttribute("engine-action") == D.S){
					a = e.getAttribute("engine-action");
				}
				else{
					a = _s[s + "a"];
				}
				if(!b && typeof e.getAttribute("engine-action-type") == D.S){
					at = e.getAttribute("engine-action-type");
				}
				else{
					at = _s[s + "at"];
				}
				if(!b && typeof e.getAttribute("engine-handler") == D.S){
					h = e.getAttribute("engine-handler");
				}
				else{
					h = _s[s + "h"];
				}
				if(!b && typeof e.getAttribute("engine-handler-type") == D.S){
					ht = e.getAttribute("engine-handler-type");
				}
				else{
					ht = _s[s + "ht"];
				}

				if(!b && typeof e.getAttribute("engine-config-task") == D.S){
					_s.pt = e.getAttribute("engine-config-task");
				}
				
				o = x(
					n,
					at,
					a,
					ht,
					h
				);

				l = _p.engines.length;
				
				v = $E.FN("engine_object",(b?0:e),z,n,o,l);

				/*
					The first engine is the primary.
				*/
				if(!l) v.is_primary = 1;
				/*
					add a dependency on the primary engine to load
					and for the page_pt to be complete
				*/
				else{
					_t.addTaskDependency(o,_s.pn);
					_t.addTaskDependency(o,_s.pt);
				}
				_p.engines[l]=v;
				_p.enginenames[n]=l;
				_p.engineindex[z]=l;
				
				_t.executeTask(o);				
			}
		};

		t.bindElement = function(o, n){
			/*
				o = Engine object
				n = node
			*/
			
			var 
				_s = t.o.s,
				_p=t.o.p,
				z,
				c,
				_a = $E.appcomp,
				r
			;
			
			if(typeof o == D.S) o = t.getEngine(o);
			if(typeof n != D.O || !t.isEngine(o)) return 0;
			
			r = n.getAttribute("rid");
			r = r ? r : 0;
			

			c = $E.xhtml.XHTMLComponent.newInstance(n,1,r,o.engine_id,$E.xhtml.form.XHTMLFormComponent);

			l = o.eo.length;
			if(
				c != null
				&& 
				typeof c == D.O
				&&
				_j.registry.ObjectRegistry.isRegistered(c)
				&&
				typeof o.ei[c.i] != D.N
			){
				o.eo[l] = {object:c,config:"_bind",rid:r};
				o.ei[c.i] = l;

				if(r && typeof o.en[r] != D.N){
					o.en[r] = l;

					
					//_m.S("Register component '" + c.i + "' with friendly name '" + r + "'","200.1");
					

				}

				
				else{
					//_m.S("Register component '" + c.i + "' without friendly name","200.1");
				}
				

			}

			if(c && c.t && c.t.match(/^xhtml_component$/)){
				c.post_init();
			}			

			return 1;

		};

		t.applyConfiguration=function(o,c){
			/*
				o = Engine object
				c = config_name
				
				v = task object
				
				sf = self
			*/
			var v,_s = t.o.s,s,_t = t.o.p.ts,_p=t.o.p,i,a,sf=0;
			s = _s.pd;
			
			v = _t.getTaskByName(_s.pt);
			if(typeof o == D.S) o = t.getEngine(o);

			
			var start_apply = new Date().getTime();
			

			if(t.isEngine(o)){

				a = o.eo;
				for(i=a.length-1;i>=0;i--)
					_j.registry.ObjectRegistry.sendDestroyTo(a[i].object);
				
	
				o.eo = [];
				o.en = [];
				o.ei = [];
				
				
				o.engine_implementations = [];
				
				
				/* only allow 'self' if the engine has an HTML element behind it */
				if(typeof c == D.S && c == "self" && o.engine_element){
					sf = 1;
					s = sf;
				}

				if(!sf && o.engine_element && o.engine_element.getAttribute("engine-config") != "self") _x.removeChildren(o.engine_element);

				o.config_name = 0;
				/*
				 * 2004/07/21
				 * Change check for if task is complete it if the task was handled
				 */
				if(_t.isTask(v) && v.handled && typeof v.data == D.O){
					
					if(!sf && (o.engine_element && o.engine_element.getAttribute("engine-config")) || typeof c == D.S){
						s = (typeof c == D.S)?c:o.engine_element.getAttribute("engine-config");
						if(s && s=="self"){
							/* self can only be used once */
							o.engine_element.removeAttribute("engine-config");
							sf = 1;
						}
					}
					
					if(!s){

						
						_m.S("Page config not specified.","200.1");
						

						return 0;
					}
					o.config_name = c;

					
					_m.S("Process page config '" + s + "' for " + o.engine_name,"200.1");
					

					t.PC(o,v,s);
					
					
					o.engine_implementations = [];
					
					
					_m.publish("onengineconfigload",o);

				}
				
				else{
					_m.S("Page config not present.","200.1");
				}
				
			}
			else{
				_m.S("Invalid engine reference for applyConfiguration","200.4");
			}

			
			var stop_apply = new Date().getTime();
			_m.S("applyPageConfiguration Apply Time: " + (stop_apply - start_apply),"200.1");
			
			
		};
		/*
		 * 2004/07/02
		 * 
		 * if page_config is 'self' then:
		 * a) don't validate page config
		 * b) don't copy any source
		 * 
		 */
		t.PC=function(o,v,s,p,x,b){
			/*
				o = (validated) engine object
				v = (validated) task object
				s = page config name
				p = parent node
				x = object instance
				b = return value of parent impl

				cs = current config name
				p = page config node
				a = array of nodes
				h = iterator
				i = iterator
				n = node
				
				q = node query
				
				d = def node
				
				r = tmp val
				m = tmp val
				w = tmp val
				u = tmp val
				g = tmp val
				j = tmp val
				k = tmp val
				y = tmp node
				z = tmp nodeset
				f = tmp val
				c = tmp val
				e = tmp val
				l = tmp val
				
				nl = node length
				
				br = block recursion
				
				cx = context switch
				cxn = context switch type (object_ref probably)
				cxp = context switch path as an xpath, probably
				
				ck = context parent; the output html node is the outbound parent node.  This is used when importing data into self referenced configurations
				cn = context swap name, used with ck
								
				ab = abstract implementation
				
				sf = bool: is self
				ci = cached implementation

			*/
			
			
			var start_parse = new Date().getTime();
			

			var a,i,n,q,d,r,m,u,g,j,y,z,f,b,c,h,k,l,e=0,w,br,cx,cxv,cxp,ab,nr,sf=0,ck,nl,ci;
			
			/* self must have an engine_element, and that becomes the default parent */
			if(s == "self" && typeof p==D.U) p = o.engine_element;
			else if(typeof p==D.U)
				p = _x.queryNode(v.data.documentElement,"configuration",0,"id",s);/*_x.selectSingleNode(v.data,"configuration[@id = '" + s + "']",v.data.documentElement);*/

			if(p){
				a = p.childNodes;
				nl = a.length;
				//_m.S("Node count " + nl,"200.1");
				for(i=0;i<nl;i++){
					n = a[i];
					br = 1;

					/* g = package name for implementation */
					/* k = bit used to specify whether the constructor is on the parent; eg: as with menuitems and resultitems */
					/* j = params array used when applying a constructor */

					d = ci = k = g = ab = cx = ck = 0;
					j = [];
					cs = s;
					
					if(s == "self") sf = 1;

					if(n.nodeType == 1){
						/*
						 * 2004/07/02
						 * Make sure to cast the node name to lower case
						 */
						q = n.nodeName.toLowerCase();
						
						/*
						 * 2004/07/20
						 * Cache experiment to try to improve performance on IE
						 * 
						 */
						
						w = o.engine_implementations[q];
						if(w){

							k = w.p;
							cx = w.cs;
							cxp = w.cp;
							z = w.z;
							ab = w.ab;
							br = w.nr;
							sf = w.sf;
							ck = w.ck;
							g = w.g;
							f = w.f;
							/*j = w.j;*/
							y = w.y;
							cn = w.cn;
							ci = 1;

							
							//_m.S("Process cached implementation for " + q,"200.1");
							
						}
						else d = t.getObjectDefinition(v.data,q);/*_x.selectSingleNode(v.data,"object-definitions/definition[@id = '" + q + "' or matdef[@rid = '" + q + "']]",v.data.documentElement);*/

						if(d){
							/* y = implementation node; re-used throughout statement */
							y = d.getElementsByTagName("implementation");/*_x.selectSingleNode(v.data,"implementation",d);*/
							if(y.length) y = y[0];
							else y = 0;
							
							/* process implementation for element */

							if(y){

								
								_m.S("Process implementation for " + q,"200.1");
								

								z = y.getElementsByTagName("package");/*_x.selectSingleNode(v.data,"package",y);*/
								if(z.length) z = z[0];
								else z = 0;
								
								k = (y.getAttribute("use-parent")=="1"?1:0);
								cx = (y.getAttribute("context-switch") == "1"?1:0);
								cxp = y.getAttribute("context-path");
								cn = y.getAttribute("swap-name");

								ab = (y.getAttribute("abstract")=="1"?1:0);
								br = (y.getAttribute("no-recursion")=="1"?0:1);

								/* if this is a self reference, and the context switched, then push config reference to switchedself */
								if(cx && cs == "self"){
									/*cs = "switchedself";*/

									
									_m.S("Switched off 'self' for context change in " + q,"200.1");
									
									sf = 0;
									ck = 1;
								}

								if(cxp) cxp = t.PO(o,v,cxp,n,x,b,p,cs);




								if(z && (u = z.getAttribute("pid")) && ValidatePackage(u)){
									g = GetPackage(u);
									
									if(g && (u = z.getAttribute("mid")) ){
										if(typeof g[u] == D.F) g = g[u](t.PO(o,v,z.getAttribute("midparam"),n,x,b,p,cs));
									}
									
								}
								
								w = {};
								w.p = k;
								w.cs = cx;
								w.cp = cxp;
								w.z = z;
								w.ab = ab;
								w.nr = br;
								w.sf = sf;
								w.ck = ck;
								w.g = g;
								/*
								// assigned later w.f = f;
								// assigned later w.c
								// assigned later w.z
								w.j = j;
								*/
								w.y = y;
								w.cn = cn;
								o.engine_implementations[q] = w;
								

							} /* end if (check_implemention) */
						
						} /* end  check for d */

						if(d || ci){
							
							if(ci){
								y = w.c;
							}
							else{
							
							y = y.getElementsByTagName("constructor");/*_x.selectSingleNode(v.data,"constructor[@name]",y);*/
							if(y.length) y = y[0];
							else y = 0;
							
							w.c = y;
							}
							
							
							/*
							 * 2004/07/21
							 * Don't cache the params because they include object
							 * references - everything would wind up being applied to
							 * the same object
							 */
							
							if(y){
								/*f = y.getAttribute("name");*/
								
								if(!ci){
								

									f = t.PO(o,v,y.getAttribute("name"),n,x,b,p,cs);
									
									z = y.getElementsByTagName("param");/*_x.selectNodes(v.data,"param",y);*/
								
									/*o.engine_implementations[q].f = f;*/
									w.f = f;
									w.z = z;

								}
								else
									z = w.z;
										
								
								

								
								w = z.length;

								for(h = 0; h < w;){
									m = z[h++];
									u = 0;
									if(m.getAttribute("value")){
										r = m.getAttribute("value");
										if(r.match(/^ora:/i))
											u = t.PO(o,v,r,n,x,b,p,cs);
										else
											u = r;
										
									}
									j[j.length]=u;
								}
							} /* end if (check_constructor) */

							/*
								g is a package
							*/
							nr = n.getAttribute("aid");
							nr = (typeof nr == D.S && nr.length ? nr : 0);
							
							if(nr)
								n.setAttribute("id",nr + (++t.o.s.eac));
							
							
							try{
								if(!ab){
									if(typeof g==D.O && g != null && typeof g[f] == D.F){

										
										/*_m.S("apply #1 " + f,"200.1");*/
										

										w = g[f].apply(0,j);
									}
									else if(k && typeof x[f] == D.F){

										
										/*_m.S("apply #2 " + f,"200.1");*/
										

										w = x[f].apply(x,j);
									}
									else{
										_m.S("Unexpected implementation with g=" + g + " and f=" + f,"200.4");
									}
								} /* end if not abstracted */
								else{
									/*
										Abstracted: just push out w to x
									*/ 
									w = x;
								} /* end if abstracted*/
							}
							catch(e){
								alert("Parse Configuration:" + (e.description?e.description:e.message) + " from f = " + f + " and " + x);
							}

							/* if use parent */
							if(k){
								e = w;
								w = x;
							} /* end if use parent*/
							
							/* if use context parent */
							/*
							if(ck){
								
							}
							*/
							/* end if context parent*/
							
							l = o.eo.length;
							/*
								reuse q
							*/

							
							q = n.getAttribute("rid");
							q = (typeof q == D.S && q.length ? q : 0);

							if(
								w != null
								&& 
								typeof w==D.O
								&&
								_j.registry.ObjectRegistry.isRegistered(w)
								&&
								typeof o.ei[w.i] != D.N
							){
								o.eo[l] = {object:w,config:cs,rid:q};
								o.ei[w.i] = l;
			
								if(q && typeof o.en[q] != D.N){
									o.en[q] = l;

									
									//_m.S("Register component " + n.nodeName + " (" + w.i + ") with friendly name " + q,"200.1");
									

								}

								
								else{
									//_m.S("Register component " + n.nodeName + " (" + w.i + ") without friendly name","200.1");
								}
								

							}

							/*
								A context switch is used for importing xml data, where the return value
								of the object implementation is an XML document, and cxp is null or an xpath.
							*/

						
							/*
							 * 
							 * 2004/07/02
							 * BUG BUG 
							 * For 'ck' implementations, setInnerXHTML can't use custom
							 * elements such as import-xml 
							 */
							if(cx && w){
								if(ck && cn){
									k = document.createElement(cn);
									n.parentNode.appendChild(k);
									if(typeof k.swapNode != D.U) k.swapNode(n);
									n = k;
								}
								if(!w.documentElement){
									
									_m.S("setInnerXHTML #1 " + q + " (1)","200.1");
									
									_x.setInnerXHTML(n,w,0,(!ck ? v.data : 0));
									
								}
								else{
									/*
										If a data_path (dp) was used, assume it is for use to replace the context path from the config file.
									*/
									if(o.dp) cxp = o.dp;

									/* reuse nr */
			
									nr = (cxp?_x.selectSingleNode(w,cxp,w.documentElement):w.documentElement);
									if(!nr) nr = w.documentElement;

									
									_m.S("setInnerXHTML #2 " + q + " (1)","200.1");
									

									_x.setInnerXHTML(n,nr,0,(!ck ? v.data : 0));

								}
								/*
									Switch the context back to the parent
								*/
								w = x;
							}
							
							if(br) t.PC(o,v,cs,n,w,e);
							
							if(w && w.t && w.t.match(/^xhtml_component$/)){
								w.post_init();
							}
							
						} /* end check for implementation or cached implementation */
						else{
							/* just copy the whole node */
							if(typeof x == D.U) x = o;
							if(typeof x == D.O && x != null && typeof x.getContainer == D.F){
								if(!sf) _x.setInnerXHTML(x.getContainer(),n,true);
							}
							
							else{
								//_m.S("No object definition for " + n.nodeName + " (1); treating as HTML","200.1");
							}
							
						}
					}
					else if(n.nodeType == 3){
						if(n.nodeValue.replace(/\s/g,"").length && typeof x == D.O && typeof x.getContainer == D.F){
							if(!sf) _x.setInnerXHTML(x.getContainer(),n,1);
						}
						
						else{
							//_m.S("No object definition for " + n.nodeName + " (3); treating as HTML","200.1");
						}
						
					}

				} /* end for(i;childNodes.length) */
			} /* end (if p) */
			else{
				_m.S("Page config for " + s + " not found.","200.4");
			}

			
			var stop_parse = new Date().getTime();
			//_m.S("PC Parse Time: " + (stop_parse - start_parse) + " for " + nl + " nodes","200.1");
			

		};
		/*
			ORA = object request alias; just a token that is used to reference a context object
		*/ 
		t.PO=function(o,v,r,e,x,b,q,s){
			/*
				o = engine object
				v = task object
				r = ora value
				e = originating xml element
				x = parent object instance
				b = parent reference; return value from where the parent object was created
				q = html parent
				s = config name
				
				a = variant used for name substring.
				z = return value;
				
				
				p = variant
				c = counter
				d = variant
				f = variant
			*/
			var z = 0,a,n,p,d,f,c,up,i;
			if(typeof r != D.S) return;
			r = r.replace(/^ora:/i,"");

			if(r.match(/(\S*)_parent$/i) ){
				r = r.match(/(\S*)_parent$/i)[1];
				up = 1;
			}

			if( r.match(/(\S*)_attr$/i) ){
				a = r.match(/(\S*)_attr$/i)[1];
/*				r = r.replace(/(\S*)[^attr$]/i,"");*/
				r = "attr";
			}
			if( r.match(/integer_(\S*)$/i) ){
				a = r.match(/integer_(\S*)$/i)[1];
/*				r = r.replace(/(\S*)[^attr$]/i,"");*/
				r = "integer";
			}
			if( r.match(/xpath-node-value:(\S*)/i)){
				a = r.match(/xpath-node-value:(\S*)/i)[1];
				r = "xpath-node-value";
/*				r = r.replace(/(:\S*)[^xpath-node-value]/i,"");*/
			}
			if( r.match(/xpath-node-value-list:(\S*)/i)){
				a = r.match(/xpath-node-value-list:(\S*)/i)[1];
				r = "xpath-node-value-list";
/*				r = r.replace(/(:\S*)[^xpath-node-value]/i,"");*/
			}

			switch(r){
				case "node_context":
					z = e;
					break;
				case "element_context":
					z = q;
					break;
				case "bool_true":
					z = 1;
					break;
				case "data_source":
					z = o.ds;
					break;
				case "parent_reference":
					z = b;
					break;
				case "xml_document":
					z = v.data;
					break;
				case "xpath-node-value-list":
					f = _x.selectNodes(v.data,a,e);
					p = [];
					for(c=0;c<f.length;c++){
						d = f[c];
						if(d.getAttribute("value")){
							/*p[p.length] = d.getAttribute("value");*/
							p[p.length] = t.PO(o,v,d.getAttribute("value"),e,x,b,q,s);
						}
					}
					z = p;				
					break;
				case "xpath-node-value":
					n = _x.selectSingleNode(v.data,a,e);
					if(n){
						z = n.nodeValue;
					}
					break;
				case "params_array":
					a = e.getElementsByTagName("param");/*_x.selectNodes(v.data,"params/param",e);*/
					p = [];
					for(c=0;c<a.length;c++){
						d = a[c];
						if(d.getAttribute("value")){
							p[p.length] = d.getAttribute("value");
						}
					}
					z = p;				
					break;
				case "integer":
					z = parseInt(a);
					if(isNaN(z)) z = 0;
					break;
				case "attr":
					if(a){
						if(up){
							z = e.parentNode.getAttribute(a);
						}
						else{
							z = e.getAttribute(a);
						}
					}
					break;
/*
				case "name_attr":
					z = e.getAttribute("name");
					break;
				case "url_attr":
					z = e.getAttribute("url");
					break;
				case "id_attr":
					z = e.getAttribute("id");
					break;
				case "value_attr":
					z = e.getAttribute("value");
					break;
*/
				case "engine_object":
					z = o;
					break;
				case "engine_config":
					z = s;
					break;
				case "engine_element":
					z = o[r];
					break;
				case "parent_element":
					if(typeof x == D.U) x = o;
					if(typeof x.getContainer == D.F){
						z = x.getContainer();
					}
					break;
				case "engine_id":
					z = o.engine_id;
					break;
				default:

					
					_m.S("Unexpected/Pass-through ORA query: " + r,"200.4");
					

					z = r;
					break;
			}
			/*
				Just a fix-up for URLs so the engine id can be jacked into the query string.
				This was added to be picked up by the transformNode function in the $E.xml package,
				where the query params are jacked into the XML document element.
				
				This achieves the affect of (simply) passing parameters to the XML file, and thus, the XSL file.
			*/
			if(typeof z == D.S && z.match(/\?/) && z.match(/%ora:/)){
				up = z.substring(z.lastIndexOf("?")+1,z.length).split("&");
				for(c = 0;c<up.length;c++){
					d = up[c];
					if(!d.match(/%ora:/)) continue;
					n = new RegExp(d.match(/%ora:\S*%/));
					a = d.match(/%ora:(\S*)%/i)[1];
					if(a.match(/data_variant_\d*/)){
						i = parseInt(a.match(/data_variant_(\d*)/)[1]);
						if(isNaN(i)) i = -1;
						a = "data_variant";
					}
					r = 0;
					switch(a){
						case "eid":
							r = o.engine_id;
							break;
						case "data_variant":
							if(i >= 0){
								r = o.getDataVariant(i);
							}
							break;
						case "data_source":
							r = o.ds;
							break;

					}
					z = z.replace(n,r);
				}
			}
			return z;
		};
		
		t.getObjectDefinition = function(x, n){
			/*
			//object-definitions/definition[@id = '" + q + "' or matdef[@rid = '" + q + "']]",v.data.documentElement);	  
			 x = XML DOM
			 n = query name 
			 
			*/
			
			var o = 0,a,i=0,l,c,m,k,p,r;
			a = x.getElementsByTagName("definition");
			l = a.length;
			for(;i < l;){
				c = a[i++];
				if(c.getAttribute("id") == n){
					o = c;
					break;
				}
				
				m = c.getElementsByTagName("matdef");
				p = m.length;
				for(k = 0;k < p;){
					r = m[k++];
					if(r.getAttribute("rid") == n){
						/* if a matdef matches, then set the return value to the definition, not the matdef element */
						o = c;
						break;
					}
				}
				if(o) break;
			}
			return o;
				
		};
		
		t.HES=function(s,v){
			
			/*
				Use the task_name to retrieve the reference to the engine instance.
				The engine name was used when creating the original task, so it should exist.
			*/
			
			var e;
			
			_m.S("Starting engine " + v.task.task_name,"200.1");
			
			if( typeof v == D.O && typeof v.task == D.O && (e = t.getEngineByName(v.task.task_name)) ){
				if(e.is_primary){
					_m.S("Engine " + e.engine_id + " is the primary engine and should not be handled by this event.","200.5",1);
				}

				
				else{
					_m.S("Engine " + e.engine_id + " started","200.1");
				}
				

				t.applyConfiguration(e);
				_j.util.EH(e.engine_element,"engine-onload");
			}
			else{
				_m.S("Invalid engine reference for engine_started","200.4");
			}

		};
		
		t.HEI=function(){
			var _p = t.o.p,e;
			
			_m.S("Starting engine service","200.1");
			
			if(_p.engines.length){
				e = _p.engines[0].engine_element;
				t.applyConfiguration(_p.engines[0]);
				_j.util.EH(e,"engine-onload");
			}
/*
			t.o.p.task_service.returnDependency(t.o.s.primary_engine_handler);
*/
			return 1;
		};

		/*
			Add event buffer was designed for DOM events as a way
			of creating instance-specific handlers.
		*/

		$E.IM(t,"base_object","engine_service","1.2.12.2207.2004");
		_j.object.IOA(t,"engine");
		
		_m.subscribe(t,"dom_event_window_load","handle_window_load");
		_m.subscribe(t,"engine_started","HES");
		_m.subscribe(t,"engine_service_initialized","HEI");

		$E.registry.ObjectRegistry.addObject(t);
		t.r = 4;
	}

};

/* Create a new application driver */
$E.engine.EngineService=new $E.engine.EngineServiceImpl();

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2003, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

/*
	ocj.appcomp
		This file is parameterized because it is used for two primary purposes:
			1) A dynamic loader for application components
			2) An application component binder
			
		In #1, an XML node is used for code delivery.
		In #2, source code is injected at the SOURCE_CODE token point, and the PACKAGE, CLASS,
			and LABEL tokens are substituted with specified names.  This means the dynamic portion
			is not used, and so should also be parameterized (which isn't done yet).
		

		Application Components are 'locked' by the r after initialization to prevent being overwritten through re-initialization.
		An overwrite can happen when synchronously loading multiple components from the same XML file with the same component id.
		It therefore necessary to first 'release' the component prior to initializing it again.

*/

$EP("$E.appcomp");

$E.appcomp.ApplicationComponent = {
	
	o:{
		s:{
			/* id on an element that points to an appcomp entry */
			c:"acid",
			/* id on an element that points to a config item, which represents and appcomp definition path */
			g:"accfgid",
			/* default component config id; see above */
			k:"appcomp_path",
			/* id set on an element that refers back to the application component */
			r:"acrid",
			/* participant id for application components */
			p:"participant-id"

		}
	},
	

	bindComponent:function(o, i, c, p){
		/*
			o = object
			i = definition id
			c = definition path
			p = participant id; if not specified, it is the definition id
		*/
		var _a = $E.appcomp.ApplicationComponent, z, q = o, r;
		r = _a.o.s.r;
		
		if(typeof q == D.S){
			q = $E.registry.ObjectRegistry.getObject(o);
			if(q != null && typeof q.getContainer == D.F) q = q.getContainer();
		}
		if(typeof q != D.O || q == null)

			
			{
			$E.message.MessageService.S("Invalid ID reference '" + o + "' in bindComponent","200.4");
			

			return 0;
			
			}
			

		if(typeof q[r] == D.S)
			
			{
			$E.message.MessageService.S("Object is already bound to '" + q[r] + "'","200.4");
			

			return 0;
			
			}
			
		
		/* #1 Create a new ApplicationComponent for 'o' */
		z = _a.newInstance(0,0,o,0,p,1);

		/* #2 Enabled bindings (for events) - this must be done prior to loading the component definition */
		/*z.setBindingEnabled(true);*/
		z.loadComponent(i,c);
		if(typeof q.setAttribute == D.U)
			q[r] = z.i;
		
		else
			q.setAttribute(r,z.i);
		
		
		
		//$E.message.MessageService.S("Bind to application component " + z.getObjectId(),"200.1");	
		

		return z;
	},

	newInstance:function(i,o,c,f,p,b){
		/*
			i = id
			o = node context
			c = container id
			f = load handler
			p = participant id; used for transactions
			b = binding enabled
		*/

		var n = $E.FN("base_object","application_component","1.1.22.2207.2004");
		if(typeof o == D.F) f = o;
		if(typeof o != D.O) o = 0;
		if(typeof i != D.S) i = 0;
		if(typeof p != D.S) p = 0;
		if(typeof c == D.U) c = 0;
		if(typeof b == D.U) b = 0;		
		n.o={
			p:{
				/* mark handlers being used */
				/* This is used when filtering events through the dispatch */
				
				ts:$E.token.TokenStack
				
/*
				mh:[]			
*/
			},
			s:{
				/* c = component path */
				c:0,
				/* component name */
				n:0,
				/* container id */
				e:c,
				/* use friendly id - recommended only when there are unique appcomp ids*/
				i:1,
				/* element_parent_name */
				p:"application-components",
				/*  element_name */
				m:"application-component",

				
				/* async */
				a:0,
				

				/* load handler */
				h:f,
				/* binding_enabled */
				
				b:b,

				/* event binding list */
				eb:"change,focus,blur,mouseover,mouseout,click",
				/* transactional */
				t:1,
				/* transaction name */
				tn:p,
				/* transaction id */
				ti:0
			}
		};
		
		if(i && 1) n.i = i;

		/*
			A sigterm message is invoked when the window unloads,
			or when everything is shut off unexpectedly.
			
			This also relies on a signal from a containment component, such as ocju.driver
		*/
		n.sigterm = function(){
			this.destroy();
		};

		/*
			Destroy is invoked by a containment component, such as an ocj.engine, or by listening for the 'destroy' publication, and specifying this function as the handler.
			Invoking ocju.driver.ApplicationDriver._terminate will publish the destroy message.
			
			The only time this is directly invoked is from ocj.engine
		*/
		n.destroy=function(){
			var t = this;

			/* only do this once */
			if(t.r < 5){

				
				$E.message.MessageService.unsubscribe(t,"onloadxml","HLX");
				

				if(typeof t.component_destroy == D.F) t.component_destroy();
				t.r = 5;

				
				$E.token.TokenStack.removeTokens(t);
				

				$E.transaction.TransactionService.removeTransactionParticipant(t,t.getPacket());
				/* It is up to the object to remove itself from the registry */
				$E.registry.ObjectRegistry.removeObject(t);

			}
		};
		
		n.getTokenStack = function(){
			return this.o.p.ts;
		};
		
		
		n.setAsync = function(b){
			this.o.s.a = b;
		};
		n.release = function(){
			/*
				Back off the r so another definition may  be loaded
			*/
			this.r = 2;
		};
		
		
		n.setBindingEnabled = function(b){
			this.o.s.b = b;
		};

		n.getBindingEnabled = function(){
			return this.o.s.b;
		};

		n.setContainerId = function(s){
			this.o.s.e = s;
		};

		n.getContainerId = function(s){
			return this.o.s.e;
		};

		n.getComponentName = function(){
			return this.o.s.n;
		};
		
		n.getContainer = function(){
			var o = this.o.s.e;
			if(!o) return 0;
			if(typeof o == D.S) o = $E.registry.ObjectRegistry.getObject(o);
			if(o != null && typeof o.getContainer == D.F) o = o.getContainer();
			return o;

		};

		
		n.loadComponent = function(l,c){
			/*
				c = component path
				l = component label
			*/
			
			var t = this, _s, _x = $E.xml,_p;
			_s = t.o.s,_p = t.o.p;
			
			if(typeof c != D.S || typeof l != D.S) return 0;
			_s.c = c;
			_s.n = l;

			/* a/synchronous get, cache the request */
			
			/*
				Just use the path for the cache id for sync requests
			*/
			_x.getXml(c,null,_s.a,(_s.a ? t.i : c),!(_s.a));
		};
		
		
		n.init = function(o){
			var t = this,_s;
			/* s is specified here only for the compiled version */
			_s = t.o.s;

				

			t.r = 1;

			if(typeof o == D.O)
				t.importNodeDefinition(o);

		};

		n.HLX=function(s,v){
			var t = this, o, _x = $E.xml,x,_s;
			_s = t.o.s;

/*
	05/11/2003
		Check for r < 4 because multiple requests using the same cache id 
		and same comparison id will cause the component to be loaded multiple times.
*/

			if(v.id == (_s.a ? t.i : _s.c) && t.r < 4){
				x = v.xdom;
				o = _x.queryNode(x.documentElement,_s.m,0,"id",_s.n);/*_x.selectSingleNode(x,"/" + _s.p + "/" + _s.m + "[@id = '" + _s.n + "']",x.documentElement);*/
				/*
				 * 2004/07/22
				 * Removed the alert-level on the warning message
				 */
				if(o != null) t.importNodeDefinition(o);
				else $E.message.MessageService.S("Invalid component definition for '" + _s.n + "' in '" + _s.m + "'","200.4");

			}
			
		};
		
		
		n.importNodeDefinition = function(x){
			/*
				x = xml node
				i = id
				s = string data
			*/
			var i,t = this, _s, p;
			_s = t.o.s;
			
			t.r = 3;
			
			if(typeof x != D.O || x == null){
				
				$E.message.MessageService.S("Invalid object in importNodeDefinition","200.1");
				
				return 0;
			}

			i = x.getAttribute("id");
			p = x.getAttribute($E.appcomp.ApplicationComponent.o.s.p);
			
/*			if(!_s.n) _s.n = i;*/
			
			return n.importComponentDefinition($E.xml.getCDATAValue(x),i,p);

			
		};
/*		
		n._handle_dispatch = function(e){
			var h, r, t = this;

			e = $E.dom.event._gevt(e);

			h = '_handle_' + e.type;
			if(typeof t[h] != D.F) return 0;

			try{
				t[h](e);
			}
			catch(e){
				$E.message.MessageService.S((e.description?e.description:e.message),"200.4",1);
			}

		};
*/		
		n.importComponentDefinition = function(s,i,pn){
			/*
				s = component string 
				i = id 
				p = participant id
			*/
			
			var t = this,_s;
			_s = t.o.s;
			if(typeof s != D.S) return 0;
			
			/*
				If there is already a component definition loaded, then invoke any destroy handler.
			*/
			if(typeof t.component_destroy == D.F) t.component_destroy();
			/*
				Back out the r for a moment.
				If something fails, then the component won't be ready (duh)
			*/

			t.r = 3;

			if(i) _s.n = i;
			else _s.n = $E.GG();

			if(pn) _s.tn = pn;
			else if(!_s.tn) _s.tn = _s.n;

			s = '{' + s + '}';
			$E.merge(t, _s.n, s);
			
			/*
				Invoke the component initialization handler.
			*/

	

			var a, l, h, o = _s.e,ph;
			if(_s.b && _s.eb && o){
	
				$E.dom.event.addEventBuffer(t);

				if(typeof o == D.S) o = $E.registry.ObjectRegistry.getObject(o);

				if(o){

					if(typeof o.getContainer == D.F) o = o.getContainer();


					a = _s.eb.split(",");
					for(l=0;l<a.length;l++){
						h = '_handle_' + a[l];
						ph = '_prehandle_' + a[l];
						/*
							Is it necessary to remove event listeners when objects are destroyed?
						*/
						if(typeof t[ph] == D.F){
							$E.dom.event.removeEventListener(o,a[l],t[ph]);
							t[ph] = null;
						}
						
						if(typeof t[h] == D.F){
							t.createHandler(a[l],0,0,1);
							$E.dom.event.addEventListener(o,a[l],t[ph]);
						}
					}
				}
			}

/*	
			THIS IS FOR FILTERING EVENTS THROUGH THE DISPATCHER

			var a, l, h, o = _s.e,ph,_p = t.o.p,mh;
			if(_s.b && _s.eb && o){
	
				$E.dom.event.addEventBuffer(t);

				if(typeof o == D.S) o = $E.registry.ObjectRegistry.getObject(o);

				if(o){

					if(typeof o.getContainer == $D.F) o = o.getContainer();
					ph = '_prehandle_dispatch';


					if(typeof t[ph] != D.F) t.createHandler('dispatch',0,0,1);

					a = _s.eb.split(",");
					for(l=0;l<a.length;l++){
						mh = a[l] + ph;
						h = '_handle_' + a[l];

						if(_p.mh[mh]){
							$E.dom.event.removeEventListener(o,a[l],t[ph]);
							_p.mh[mh] = 0;
						}
						
						if(typeof t[h] == D.F){
							$E.dom.event.addEventListener(o,a[l],t[ph]);
							_p.mh[mh] = 1;
						}
					}
				}
			}
*/
		
			var _t = $E.transaction.TransactionService,p;
			if(_s.t && _t.canRegister(t)){
				/* register the component */
				_t.register(t);

				/* Get any packets with this application component name */
				p = _t.getPacketByName(_s.tn);
				if(p){
					_s.ti = p.packet_id;
					p.setBlockStartTransaction(false);
					_t.addTransactionParticipant(t,p);
				}
				else{
					_s.ti = _t.openTransaction(_s.tn,t,{type:0,src:0,data:0});

				}
			}
			
			if(typeof t.component_init == D.F) t.component_init();
			
			t.r = 4;


				
			if(typeof _s.h == D.F) _s.h("onloadappcomp",t);
	

		};


		
		n.getPacket = function(n){
			var _t = $E.transaction.TransactionService;
			if(n)  return _t.getPacketByName(n);
			else return _t.getPacket(this.o.s.ti);
		};

		/*
			serveTransaction is a quick wrapper for setting the packet type, packet source, and
			volleying it to other application components.
		*/
		n.serveTransaction=function(v,r,b,n){
			/*
				v = variant value
				r = variant value
				b = bool; serve to owner
				n = alternate packet name
			*/
			var _t = $E.transaction.TransactionService,p,t = this;

			p = t.getPacket(n);
			if(p){
				p.data.type = v;
				p.data.src = r;
				_t.serveTransaction(p,t.i,(!b));
				return 1;
			}
			return 0;
		};

		n.doTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var t=this, q, qh;

			if(typeof t._handle_transaction == D.F) t._handle_transaction(s,p);
			q = p.data.type;
			qh = '_handle_' + q;
			if(q && typeof t[qh] == D.F) t[qh](s,p);

			
			$E.message.MessageService.S("Do Transaction for " + t.i + " on target " + qh,"200.1");
			

			return 0;
		};
		
		n.startTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var
				_m = $E.message.MessageService,
				t=this;
				
			if(typeof t._handle_begin_transaction == D.F) t._handle_begin_transaction(s,p);
				
			
			//_m.S("Start transaction " + p.packet_name + " for " + t.t,"200.1");
			

			return 1;
		};
		
		
		n.endTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var t=this;

 			if(typeof t._handle_end_transaction == D.F) t._handle_end_transaction(s,p);
 
 			
			$E.message.MessageService.S("End transaction " + p.packet_name + " for " + t.t,"200.1");
			

			return 1;
		};

		
		n.evaluateWireReference=function(b,n,a){
			/*
				b = action-only
				n = optional wire name to supercede a hardcoded definition
				a = option array list
			*/
			if(typeof a != D.O) a = 0;
			var t = this,
				o,
				_e = $E.engine.EngineService,
				w,
				i,
				e,
				s
			;
			o = t.getContainer();
	
			/* Must be an XHTML Component; check node type */
			if(!o || o.nodeType != 1) return 0;
			
			w = (n ? n : o.getAttribute("wire"));
	
			/* erid is auto-added by XHTMLComponent */
			i = o.getAttribute("erid");
	
			e = _e.getEngine(i);
			if(_e.isEngine(e) && e.getPrimitiveWire(w)){
				s = _e.getWireService();
				if(s.invokeHardWireAction(e,w,a)){
					if(!b) s.invokeHardWireHandler(e,w);
					return 1;
				}
			}
			return 0;
		};
		

		
		n.getReferenceId = function(){
			var c = $E.registry.ObjectRegistry.getObject(this.getContainerId());
			/* c = XHTLM Component */
			if(!c) return 0;
			/* ReferenceId = EngineID or specified id */
			return c.getReferenceId();
		};
		

		
		
		/*
			Make component initialization dependent on the addObject call.
		*/
		if($E.registry.ObjectRegistry.addObject(n)){
			
			/*
				Use the message service to pick up the xml loaded event for asynchronous
				operations because the handler loses its scope to the object instance
				Doing so means that the handler must correctly identify the config
			
				Refer to notes in ocju.config for repro steps
			*/
			
			$E.message.MessageService.subscribe(n,"onloadxml","HLX");
			
			
			n.init(o);
		}
		else{
			$E.message.MessageService.S("Could not add application component to registry","200.4");
		}
		
		return n;
	}
}

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.xhtml");

$E.xhtml.XHTMLComponent = {
	newInstance:function(hp, xn, cid, rid, cc, cn, cp, cf){
		/*
			hp = html_parent
			xn = xhtml_node
			cid = component_id (eg: friend_name)
			rid = reference_id (eg: engine id)
			cc = component_collection (eg: XHTMLFormComponent)
			cn = component name
			cp = component path
			cf = component config name
		*/
		
		/*
			If hp is a parent node, and xn is an XML node, then the node is duplicated.
			
			If hp is an object and xn is a number, then hp is assumed to be a reference node.
		*/
		if(!xn) return null;
		if(!hp && typeof xn == D.O) hp = document;
		if(!cid) cid = 0;
		if(!cc) cc =0;
		if(typeof cc == D.S) cc = GetPackage(cc);

		
		var n = $E.FN("base_object","xhtml_component","1.2.6.2207.2004");
	
		n.o={
			p:{
				/* container object */
				c:0,
				/* html parent */
				r:hp,
				/* component collection */
				cc:cc,
				/* application component */
				a:0

			},
			s:{
				rid:rid,
				cid:cid,
				/* component name */
				cn:cn,
				/* component config path */
				cp:cp,
				/* config name */
				cf:cf
/*
				vp:0
*/
			}
		};
		
		/* getContainer is commonly used by the engine syntax parser when adding xhtml as xml into the live DOM for an object instance */
		n.getContainer=function(){
			return this.o.p.c;
		};
		n.getReferenceId = function(){
			return this.o.s.rid;
		};
		n.getApplicationComponent = function(){
			var _p = this.o.p;
			if(_p.a) return _p.a;
			return 0;
		};
		
		n.sigterm = function(){
			this.destroy();
		};
		
		n.destroy=function(){
			var _p,t = this,_s;
			_p = t.o.p;
			_s = t.o.s;
			
			if(t.r != 5){
				if(_p.cc && _s.cid) _p.cc.synchronizeComponent(t);

				if(_p.a) _p.a.destroy();

				if(_p.c &&_p.r && _p.c.parentNode == _p.r)
					_p.r.removeChild(_p.c);
				
				$E.registry.ObjectRegistry.removeObject(t);

				/*
				 * 2004/07/22
				 * Clean up object references
				 */
				_p.c = 0;
				_p.r = 0;
				_p.cc = 0;
				_p.a = 0;
				
				t.r = 5;
			}

		};		

		n.init_component=function(){
			var t = this, o, p, _s = t.o.s,_p = t.o.p, _ac = $E.appcomp.ApplicationComponent,i,d,a,dc,dp;
			if(typeof hp == D.O && typeof xn == D.O && (!_s.cf || _s.cf != "self")){
				
				$E.message.MessageService.S("Create XHTML " + _s.cf,"200.1");
				
				o = $E.xml.setInnerXHTML(hp,xn,1,0,1);
			}
			else if(typeof xn == D.O){
				o = xn;
			}
			else{
				
				$E.message.MessageService.S("Skip Create XHTML","200.1");
				
				o = hp;
			}
			if(_s.rid && o && !o.getAttribute("erid")) o.setAttribute("erid",_s.rid);
			
			t.o.p.c = o;

			i = (_s.cn ? _s.cn : o.getAttribute(_ac.o.s.c));

			if( i ){

				if(_s.cp){
					dp = _s.cp;
				}
				else{
					a = o.getAttribute(_ac.o.s.g);
					if(!a || a.length == 0) a = _ac.o.s.k;
					dc = $E.util.driver.ApplicationDriver.getConfig();
					if(dc) dp = dc.getParam(a);
				}
				if(dp){

					
					//$E.message.MessageService.S("Setup component binding to " + dp + " for " + i,"200.1");
					
					/*
					_p.a = _ac.newInstance(0,0,t.i);
					_p.a.setBindingEnabled(1);
					_p.a.loadComponent(i,dp);
					*/
					_p.a = _ac.bindComponent(t.i,i,dp);

				}
				else{
					$E.message.MessageService.S("Component binding to " + dp + " for " + i + " using " + a + " failed.","200.4");
				}
				
			}
			
			t.r = 4;
			
		};

		/*
			post_init is invoked by the engine service
		*/
		n.post_init = function(){
			var _s = this.o.s,_p = this.o.p;
			if(_p.cc && typeof _p.cc.addComponent == D.F) _p.cc.addComponent(this,_s.rid);		
		};

		$E.registry.ObjectRegistry.addObject(n);
		n.init_component();

		return n;
	}
};

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.xhtml");

$E.xhtml.validator = {
	XHTMLValidator:0,
	XHTMLValidatorImpl:function(){
		
		var t = this,
			_x = $E.xml,
			_m = $E.message.MessageService;
		
		t.o = {
			p:{
				/* patterns */
				p:[]
			},
			s:{
				p:0,
				l:0,
				a:1
			}
		};
		t.getPatternsFilePath = function(){
			return t.o.s.p;
		};
		t.getPatternsLoaded = function(){
			return t.o.s.l;
		};
		
		t.P = function(d){
			/*
				d = XML document
			*/
			if(!d || d.documentElement == null) return 0;
			
			var a = _x.selectNodes(d,"pattern",d.documentElement),
				pid, /* pattern_id */
				vt, /* validation_type*/
				vc, /* validation_comparison */
				ed, /* error_descripton */
				mp, /* match_pattern */
				rp, /* replace_pattern */
				an, /* allow_null */
				e, /* element */
				i = 0, /* iterator */
				y, /* iterator */
				ii,
				_p = t.o.p,
				_s = t.o.s,
				p
			;
			p = _p.p;
			_s.l = 0;
			for(;i < a.length; i++){
				e = a[i];
				pid = e.getAttribute("id");
				vt = e.getAttribute("validation-type");
				vc = e.getAttribute("comparison");
				an = e.getAttribute("allow-null");
				if(
					typeof pid != D.S || !pid.length
					||
					typeof vt != D.S || !vt.length
				){
					alert("Invalid pattern id ('" + pid + "') or validation-type ('" + vt + "')");
					continue;
				}
				if(typeof p[pid] != D.U){
					alert("Pattern id '" + pid + "' is already defined.");
					continue;
				}
		
				mp = _x.getCDATAValue( _x.selectSingleNode(d,"match",e) );
				if(!mp.length) mp = 0;
		
				/* replace pattern can be a zero-length string */
				rp = _x.getInnerText( _x.selectSingleNode(d,"replace",e) );

				ed = _x.getInnerText( _x.selectSingleNode(d,"error-description",e) );
				if(!ed.length) ed = 0;
				
				var v = {
					id:pid,
					vt:vt,
					c:(typeof vc == D.S && vc.match(/^1|true$/i))?true:false,
					an:(typeof an == D.S && an.match(/^1|true$/i))?true:false,
					mp:mp,
					rp:rp,
					ed:ed,
					i:[]
				};
				
				ii = _x.selectNodes(d,"include[@rid]",e);
				for(y = 0;y < ii.length;y++){
					v.i[v.i.length] = ii[y].getAttribute("rid");
				}
				
				p[pid] = v;

				
				_m.S("Importing validation pattern '" + v.id + "'","200.1");
				

				if(!_s.l) _s.l = 1;
			}

			
		};



		t.G=function(o){
			return t.Q(o,null,0);
		};
		t.S=function(o,v){
			return t.Q(o,1,v);
		};

		t.Q = function(o,q,v){
			/*
				o = field
				q = query type
				v = value
			*/
			var r;
			switch(o.type){
				case "textarea":
				case "password":
				case "text":
					if(!q) r = o.value;
					else r = o.value = v;
					break;
				/* unhandled field types return false; */
				default:
					return 0;
					break;
			}
			return r;
		};

		t.getValidationErrorText = function(o){
			var r,i,p,_p = t.o.p;
			/*
				o = field
				r = ret value
				i = id
				p = pattern obj
			*/

			if(typeof o != D.O && typeof o != D.S){
				return "Invalid field reference";
			}	
		
			if(typeof o == D.S) i = o;
			else i = o.getAttribute("pattern-id");
		
			if(!i){
				return "Field doesn't define a validation pattern id";
			}
			
			p =  _p.p[i];
			if(typeof p != D.O){
				return "Pattern id '" + i + "' is not a valid id.";
			}
			
			if(p.ed) r = p.ed;
			else r = "Undefined error for " + i;
			
			return r;
			
		};
		t.getIsWebSafe = function(o){
			return t.validateField(o,"web-safe");
		};

		t.validateField = function(o,i){
			/*
				o = field
				i = pid
			*/
		
			var r = 0,
				ir = 1,
				tir,
				pid = 0,
				po,
				v,
				_p = t.o.p,
				c
			;

			/* return false if there is no object */
			if(typeof o != D.O){
				_m.S("Invalid field reference in validateField.","200.4",1);
				return 0;
			}
			
			if(typeof i == D.S) pid = i;
			else pid = o.getAttribute("pattern-id");
		
			/* return true if there is no pattern-id */
			if(!pid){
				return 1;
			}
			
			po = _p.p[pid];

			/* return false if the pattern_id was invalid/not loaded */
			if(typeof po != D.O){
				_m.S("Pattern id is invalid in validateField.","200.4",1);
				return 0;
			}
		
			for(c = 0; c < po.i.length;c++){
				/*
					imported patterns only get applied when they return false and
					the current return value is true;
				*/
				tir = t.validateField(o,po.i[c]);
				if(ir && !tir) ir = 0;
			}
			
			v = t.G(o);
			/*
				If the field value is 0, then the field type was not handled.
				This is not a bug, and 0 should be fine as an integer because field values will be 
				strings.
			*/
			/* check typeof == "number" because "" == 0*/
			if(typeof v == D.N && v == 0){
				return 1;
			}
		
			if(po.mp){
				try{
					re = new RegExp(po.mp);
					switch(po.vt){
						case "replace":
							r = 1;
							if(typeof po.rp == D.S){
								v = v.replace(re,po.rp);
								t.S(o,v);
							}
							break;
						case "bool":
							if(
								/*
									Obviously, an allow-null won't work if the validation
									pattern includes an import to a non-empty string.
								*/
								(po.an && v.length == 0)
								||
								(v.match(re) != null ) == po.c
							){
								r = 1;
							}
							break;
					}
				}
				catch(e){
					_m.S("Error in validator.validateField:: " + (e.description?e.description:e.message),"200.4",1);
				}
			}
			
			if(po.vt == "none") r = 1;
			/*
				if the return value is true, but the include return value is false
				set the return value to false
			*/
			if(r && !ir) r = 0;
			
			return r;
		};

		
		t.HLX = function(s,v){
		
			if(v.xdom){
				t.P(v.xdom);
			}
			else{
				_m.S("Null DOM pointer in validator.HLX","200.4");
			}
			
		};
		
		t._handle_load_config = function(s,v){
			var z;
			if(v && (z = v.getParam("validation_patterns_file"))){
				t.load(z);
			}
		};

		t.load=function(p){
			/* p = patterns file */
			var _s = t.o.s;
			_s.p = p;

			if(_s.a){
				_x.getXml(p,t.HLX,1,t.i,0);
			}

		};
		
		$E.IM(t,"base_object","xhtml_validator","0.0.0.2207.2004");
		$E.registry.ObjectRegistry.addObject(t);
		t.r = 4;

		_m.subscribe(t,"application_config_loaded","_handle_load_config");

	}
}
$E.xhtml.validator.XHTMLValidator=new $E.xhtml.validator.XHTMLValidatorImpl();
/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

/*
	BUG 02/10/2003
		components aren't synchronized while visible, so a call to getValue returns no value
		Components should be syrchronized when getValue is called.
		
		Also, add a getXElement method, with the same stipulation as above regarding synchronization.
*/

$EP("$E.xhtml");

$E.xhtml.form = {
	XHTMLFormComponent:0,
	XHTMLFormComponentImpl:function(){
		
		var t = this,
			_x = $E.xml,
			_m = $E.message.MessageService,
			_j = $E;
		
		t.o = {
			p:{

			},
			s:{
				a:1,
				l:"ocj-xhtmlform"
			}
		};
		
		/*
			Returns the visible/active elements for the specified form index
		*/
		t.getElements = function(fi){
			if(typeof fi == D.U) fi = t.o.s.l;
			
			var f = t.getFormByName(fi), a, r = [], c = 0,i;
			if(!f)
				
				{
				_m.S("Invalid form reference '" + fi + "'","200.4");
				

				return 0;
				
				}
				
				
			a = f.getElements();
			for(i=0;i<a.length;i++){
				if(a[i].r) r[c++] = a[i];
			}
			
			return r;
		};

		t.resetAll = function(){
			var _p = t.o.p;
			_p.forms = [];
			_p.formindex = [];
			_p.formnames = [];
		};

/*
From XHTMLFormComponent HTC adaption: 
function resetForm(sFormName, bRestoreDefaultValue){
	var u;
	/ * Set to undefined; for use when overloading * /
	if(sFormName == null) sFormName = u;
	return clearForm(sFormName,true,bRestoreDefaultValue);
}

*/
		t.resetForm = function(fi,q){
			/*
				fi = form index
				q = recover form; reset back to default value as opposed to reset to previous value
			*/
			return t.clearForm(fi,1,q);
		};
		
		t.clearForm = function(fi,b,q){
			/*
				fi = form id
				b = reset-switch
				q = recover form - b must be true
			*/
			var _p = t.o.p,f,o,i,a,y,z;

			/* use base label if no form index is provided */
			if(typeof fi == D.U) fi = t.o.s.l;

			f = t.getFormByName(fi);
			if(!f)
				
				{
				_m.S("Invalid form reference '" + fi + "'","200.4");
				

				return 0;
				
				}
				
				
			a = f.getElements();
			for(i=0;i<a.length;i++){
				o = a[i];
				/* Reset */
				if(o.e && b){
					z = _j.registry.ObjectRegistry.getObject(o.oid);
					if(z)
						t.synchronizeComponent(z,1,0,q);
					
				}
				/* clear */
				else if(o.e){
					switch(o.t){
						case "hidden":
						case "text":
						case "password":
						case "textarea":
							o.e.value = "";
							break;
					
					
						case "select-one":
							o.e.selectedIndex = -1;
							break;
					
						case "checkbox":
							o.e.checked = false;
							break;
					}
				}
			}
			return 1;
		};
		t.getElement = function(n,fi){
			var o = t.getXElement(n,fi);
			/*
				Object doesn't exist, or object isn't rendered
			*/
			if(!o || !o.r) return 0;
			return o.e;
			
		};
		t.getXElement = function(n,fi){
			var _p = t.o.p,f;

			if(typeof fi == D.U) fi = t.o.s.l;
			f = t.getFormByName(fi);

			if(f) return f.getElementByName(n);

			
			_m.S("Invalid form reference '" + fi + "' for '" + n + "'","200.4");
			

			return 0;
		};

		t.getValue = function(n,fi){
			var o = t.getXElement(n,fi);
			if(o){

				/* if the element is rendered, perform a synchronize prior to retrieving value */
				if(o.r) t.synchronizeComponent(_j.registry.ObjectRegistry.getObject(o.oid),0,1);
				if(typeof o.v != D.O)
					return o.v;
				
				else
					return o.v.value;
				
			}

			
			_m.S("Invalid element reference '" + n + "'","200.4");
			

			return 0;
		};
		
		t.setValue = function(n,v,fi){
			var o = t.getXElement(n,fi);
			if(o){
				o.v = v;
				if(o.r) t.synchronizeComponent(_j.registry.ObjectRegistry.getObject(o.oid),1,1);
				return 1;
			};
			return 0;
		};

		t.synchronizeComponent = function(x,b,l,q,s){
			/*
				x = XHTMLComponent
				b = sync-in/sync-out
				l = set-link
				q = reset to default value before synchronizing; should be used when b is true
				s = set default value
			*/
			if(!x) return 0;
			
			var o,fi,f,_s = t.o.s,z,y,i,a;
			/* use default label if no label is specified */
			if( !(fi = x.o.s.rid) ) fi = _s.l;
			
			if( !(f = t.getFormByName(fi)) ){
				_m.S("Invalid form reference '" + fi + "' in synchronizeComponent","200.4");
				return 0;
			}
			
			o = f.getElementByName(x.o.s.cid);
			if(o){

				if(b & q) o.v = o.d;

				switch(o.t){
					case "checkbox":
						if(!b) o.v = x.getContainer().checked;
						else x.getContainer().checked = o.v;
						break;
					case "hidden":
					case "password":
					case "text":
					case "textarea":
						if(!b) o.v = x.getContainer().value;

						else x.getContainer().value = o.v;
						break;
					
					
					case "select-one":
						if(!b){
							z = x.getContainer().selectedIndex;
							if(z > -1){
								y = x.getContainer().options[z];
								o.v = {i:z,value:(y.value?y.value:y.text),text:y.text};
							}
						}
						else{
							if(typeof o.v == D.O && typeof o.v.i == D.N && x.getContainer().options.length > o.v.i){
								x.getContainer().selectedIndex = o.v.i;
							}
						}
						break;
					
					case "wideselect":
						if(!b){
							y = x.getApplicationComponent();
							z = y.getSelectedIndex();
							if(z > -1){
								o.v = {i:z,value:y.getSelectedValue(),text:y.getSelectedText()};
							}
							else{
								if(typeof o.v == D.O && typeof o.v.i == D.N && y.getItemSize() > o.v.i){
									y.selectItem(o.v.i);
								}
							}
						}
						break;
					
					default:
						
						_m.S("Unhandled form field type '" + o.t + "'","200.1");
						
						break;
				}
				
				if(!b && !l){
					if(_s.a) t.validate(o.n,0,fi);

					o.e = 0;
					o.oid = 0;
					o.r = 0;
				}
				else{
					o.e = x.getContainer();
					o.oid = x.i;
					o.r = 1;
				}

				
				_m.S("Synchronize " + (b?"in":"out") + " '" + o.n + "'","200.1");
								
				
			}

			
			else{
				_m.S("Object is not registered with the XHTMLFormComponent.","200.1");			
			}
			
		};
		t.addComponent = function(o,ri){
			/*
				o = XHTMLComponent
				ri = reference id for forms containment
				
				A component must have a component_id, which is a friendly name id
			*/
			var _p = t.o.p, i, v, tp = 0, e, l, p,_s = this.o.s,f,_f;
			if(o && o.t && o.t.match(/xhtml_component/) && o.o.s.cid){
				if(typeof ri != D.S) ri = _s.l;
				if(! (f = t.getFormByName(ri)) ){
					f = {
						i:ri,
						/* add in o.p for the objectAccessor */
						o:{
							p:{}
						}
					};
					_j.object.IOA(f,"element");
					l = _p.forms.length;
					_p.forms[l] = f;
					_p.formindex[_s.l + "-" + l] = l;
					_p.formnames[ri] = l;
				}

				i = o.o.s.cid;
				if(!f.getElementByName(i)){
					e = o.getContainer();
					if( !(p = e.getAttribute("pattern-id")) ){
						p = 0;
					}
					if(e.type) tp = e.type;
/*					if(e.nodeName.match(/textarea/i) && e.nodeName.match(/^select/i)) tp = e.nodeName.toLowerCase();*/
					_f = f.o.p;
					l = _f.elements.length;
					v = {
						t:tp,
						/* value */
						v:0,
						/* default/original value */
						d:0,
						n:i,
						i:l,
						oid:o.i,
						vp:p,
						e:e,
						vd:0,
						f:ri,
						/* r = rendered */
						r:1
					};

					_f.elements[l] = v;
					_f.elementindex[o.i] = l;
					_f.elementnames[i] = l;

					t.synchronizeComponent(o,0,1,0,1);
/*					t.synchronizeComponent(o,0,1);*/
					
					v.d = v.v;

					
					_m.S("Add " + i + " (" + tp + ") with pattern " + p,"200.1");
					
				}
				else{
					t.synchronizeComponent(o,1);

					
					_m.S("Skip " + i,"200.1");
					

				}
			}

			
			else{
				//_m.S("Don't add","200.1");
			}
			

		};
		
		t.validateForm = function(fi,b){
			/*
				fi = form index
				b = visual marker
			*/
			var a = t.getElements(fi),i=0,r=1,o;
			
			for(;i<a.length;i++){
				r = t.validate(a[i]);
				if(!r){
					if(b){
						$E.message.MessageService.S(
							$E.xhtml.validator.XHTMLValidator.getValidationErrorText(a[i].e),
							"200.4",
							1
						);
						a[i].e.focus();
					}
					
					return r;
				}
			}
			return r;
		};
		
		t.validate = function(n,w,fi){
			/*
				n = xelement name
				w = validation id
				f = form reference
			*/
			/* return true if the validator is not present, or there is no validation id for this component */
			var _s = this.o.s,v,_m = $E.message.MessageService,r,o;
			if(typeof n == D.O){
				o = n;
				if(typeof o.getAttribute != D.U) o = t.getXElement(o.getAttribute("erid"),o.getAttribute("rid"));
			}
			else o = t.getXElement(n,fi);
			if(!o){
				_m.S("Invalid XElement reference '" + n + "'","200.4",1);
				return 0;
			}
			
			if(!o.r){
			
								
				_m.S("Unlinked XElement in XHTMLFormComponent for '" + n + "'.  Returning previously validated value.","200.2");
				
				
				return o.vd;
			
			}

			if((!w && !o.vp) || !ValidatePackage("$E.xhtml.validator")){

				
				_m.S("Pattern not defined or validator not implemented in XHTMLFormComponent.validate","200.1");
				

				return 1;
			}

			/* use 'w' in preference over the specified pattern */
			if(typeof w != D.S) w = o.vp;
			
			v = $E.xhtml.validator.XHTMLValidator;

			/* if there are no patterns, then something may be amiss, so return false but send along a message */
			if(!v.getPatternsLoaded()){

				
				_m.S("Validate patterns not loaded for use by XHTMLComponent.validate method.","200.3");
				

				return 0;
			}
			
			r = v.validateField(o.e,w);
			if(!r){
				_m.S("Validation Error: " + v.getValidationErrorText(w),"200.4");
			}

			
			else{
				_m.S("Validated '" + n + "' with '" + w + "'","200.1");
			}
			

			o.vd = r;
			return r;

		};
		
		$E.IM(t,"base_object","xhtml_form","0.0.15.2207.2004");
		$E.registry.ObjectRegistry.addObject(t);
		t.r = 4;

/*		_j.object.IOA(t,"element");*/
		_j.object.IOA(t,"form");
	}
}
$E.xhtml.form.XHTMLFormComponent=new $E.xhtml.form.XHTMLFormComponentImpl();
/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2003, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

/*
	ocj.template
		This file represents a basic, transaction-ready component template
*/

$EP("$E.template");

$E.template.template={
	newInstance:function(){

		var n = $E.FN("base_object","object_template","0.0.2.2207.2004");
	
		n.o={
			p:{

			},
			s:{
				/* template_id_label */
				til:"swc.ocjt.template",
				/* template_s */
				ts:0,
				/* transaction_id */
				ti:0
			}
		};

		/*
			A sigterm message is invoked when the window unloads,
			or when everything is shut off unexpectedly.
			
			This also relies on a signal from a containment component, such as ocju.driver
		*/
		n.sigterm = function(){
			this.destroy();
		};

		/*
			Destroy is invoked by a containment component, such as an ocj.engine, or by listening for the 'destroy' publication, and specifying this function as the handler.
			Invoking ocju.driver.ApplicationDriver._terminate will publish the destroy message.
			
			The only time this is directly invoked is from ocj.engine
		*/
		n.destroy=function(){
			var t = this;

			/* only do this once */
			if(t.r < 5){
				t.r = 5;
				/* It is up to the object to remove itself from the registry */
				$E.registry.ObjectRegistry.removeObject(t);
			}
		};

		/*

			The transaction API implementation is only included in the template for demonstration purposes.
		*/
				
		n.continueTransaction=function(){
			var _t = $E.transaction.TransactionService,
				p,
				t = this

			;
			p = _t.getPacket(t.o.s.ti);

			if(p){
				t.o.s.ts = 1;

/*				_t.serveTransaction(p);*/

				return 1;
			}
			return 0;
			
		};
		
		n.doTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var t=this;

			
			$E.message.MessageService.S("Do Transaction for " + t.i,"200.1");
			

			return t.o.s.ts;
		};
		n.startTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var
				_m = $E.message.MessageService,
				t=this;
				
			if(!t.o.s.ti){

				
				_m.S("Start transaction " + p.packet_name + " for " + t.t,"200.1");
				

				t.o.s.ti = p.packet_id;
				return 1;
			}

			
			else{
				_m.S("Don't start transaction " + p.packet_name + " for " + t.t,"200.1");
				return 0;
			}
			
		};
		
		
		n.endTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var t=this;

			
			$E.message.MessageService.S("End transaction " + p.packet_name + " for " + t.t,"200.1");
			

			t.o.s.ti = 0;
			t.o.s.ts = 0;
			return 1;
		};


		$E.registry.ObjectRegistry.addObject(n);
		
		return n;
	}
}

/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
*/

$EP("$E.token");

$E.token={
	TokenStack:null,
	TokenStackImpl:function(){
		var t=this;
		t.o = {
			s:{
				/* enable_overstack */
				e:0
			},
			p:{
				t:[],
				tn:[]
			}
		};
		
		t.addToken = function(o, n, v, b){
			/*
				o = object owner; used to prevent overstacking
				n = some name
				v = some value
				b = overwrite token
			*/
			
			var _p = t.o.p,
				_r = $E.registry.ObjectRegistry,
				_m = $E.message.MessageService,
				l,
				nl
			;
			if(!_r.isRegistered(o)) return 0;
			
			if(typeof n != D.S) return 0;
			l = _p.t.length;
			
			if(!t.o.s.e && t.CO(o, n)){
				if(!b){
					_m.S("Overstacked " + n + " for " + o.i,"200.4");
					return 0;
				}
				/* otherwise, remove the existing token for the specified owner */
				t.removeToken(o,n);
			}
			
			if(typeof _p.tn[n] == D.U) _p.tn[n] = [];
			nl = _p.tn[n].length;
			_p.tn[n][nl] = l;
			_p.t[l] = {owner_id:o.i,index:l,token_name:n,token_value:v};
			
			return 1;

		};
		t.getTokens = function(n){
			var _p = t.o.p;
			if(typeof _p.tn[n] != D.O) return [];
			return _p.tn[n];
		};
		t.getTokenValue = function(n, z){
			var v = t.getToken(n,z);
			return (v ? v.token_value : 0);
		};
		
		t.getToken = function(n,z){
			/*
				n = token name
				z = start index
			*/
			var _p = t.o.p, a, v;
			if(typeof _p.tn[n] != D.O) return 0;
			a = _p.tn[n];
			if(typeof z != D.N) z = 0;
			if(z < 0 || z >= a.length) return 0;
			for(;z < a.length; z++){
				if(typeof a[z] == D.N && a[z] >= 0)
					return _p.t[a[z]];

			}
			return 0;
			
		};

		t.getTokenByOwner = function(n,o){
			var _p = t.o.p,
				a,
				i = 0,
				z,
				y,
				_r = $E.registry.ObjectRegistry
			;
			if(!_r.isRegistered(o)) return 0;
			if(typeof _p.tn[n] != D.O) return 0;
			a = _p.tn[n];
			for(; i < a.length;i++){
				z = a[i];
				/* typeof _p.t[z] != D.O){*/
				if(typeof z != D.N || z < 0 || z > _p.t.length  || typeof _p.t[z] == D.U){
					$E.message.MessageService.S("Invalid reference for " + n + " with " + o.i + " at " + i,"200.4");
					continue;
				}
				y = _p.t[z];
				if(y.owner_id == o.i) return y;
			}
			return 0;

		};
		
		t.getTokensByOwner = function(o){
			var _p = t.o.p,
				a,
				i = 0,
				z,
				y,
				r = [],
				_r = $E.registry.ObjectRegistry,
				_m = $E.message.MessageService
			;
			if(!_r.isRegistered(o)){
				_m.S("Unregistered object","200.4");
				return r;
			}
			for(;i < _p.t.length;i++){
				if(typeof _p.t[i] != D.O)
					continue;

				y = _p.t[i];
				if(y.owner_id == o.i)
					r[r.length] = y;

			}
			
			return r;
			
		};
		t.removeTokens = function(o){
			var a = t.getTokensByOwner(o), i = 0;
/*			$E.message.MessageService.S("Remove tokens: " + a.length,"200.4");*/
			for(;i < a.length;i++){
				this.removeToken(o,a[i].token_name);
			}
		};
		
		t.removeToken = function(o, n){
			var a,i=0,_p = t.o.p,ti,_r = $E.registry.ObjectRegistry;
			if(!_r.isRegistered(o)){
				$E.message.MessageService.S("Owner object is not registered","200.4");
				return 0;
			}
			if(typeof _p.tn[n] != D.O){
				a = [];
				$E.message.MessageService.S("Token Reference does not exist in removeToken for " + n,"200.1");
			}
			else{
				a = _p.tn[n];
			}
			for(;i < a.length;i++){
				z = a[i];
				if(typeof z != D.N || z < 0 || z > _p.t.length || typeof _p.t[z] != D.O){
					continue;
				}
				y = _p.t[z];
				if(y.owner_id == o.i){
					ti = y.index;
					_p.tn[n][i] = -1;
					break;
				}
			}
			if(typeof _p.t[ti] == D.O) _p.t[ti] = 0;
		};
		
		t.CO = function(o, n){
			return (typeof this.getTokenByOwner(o, n) == D.O ? 1 : 0);
/*			return (this.getTokenByOwner(n, o) ? 1 : 0);*/
		};

		$E.IM(t,"base_object","token_ring","0.1.36.2207.2004");
		$E.registry.ObjectRegistry.addObject(t);
	}
}

$E.token.TokenStack = new $E.token.TokenStackImpl();


$EP("org.cote.js");
org.cote.js = $E;

