
/*
	Engine for Web Applications
	Composite file "engcomp.js" release: 2.1.1
	Copyright 2002 - 2009. All Rights Reserved.
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/projects/engine/
	Limited 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 Engine = {
	pa:[],
	ix:[],
	v:"2.1.1",
	_js_imports:[],
	
	Import : function(i, t){
	
	},
	Package : function(c){
		var a,i=0,s,w=window,o,l;
		o = w;
		if(D.TS(c)){
			if(!Engine.ix[c]){
				l = Engine.pa.length;
				Engine.ix[c]=l;
				Engine.pa[l]=c;
			}
			a = c.split(".");
			for(;i<a.length;){
				s=a[i++];
				if(!D.TO(o[s])) o[s]={};
				o = o[s];
			}
		}
	}


	
	,
	GetPackage : function(c){
		return Engine.PackageExists(c,1);
	},
	PackageExists : function(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(!D.TO(o[s])) return 0;
				o = o[s];
			}
		}
		else{
			return 0;
		}
		if(b) return o;
		return 1;
	}
	
};

var D = {
	S:"string",
	O:"object",
	F:"function",
	U:"undefined",
	N:"number",
	T : function(v,t){return (typeof v == t);},
	TS : function(v){return D.T(v,D.S);},
	TO : function(v){return D.T(v,D.O);},
	TF : function(v){return D.T(v,D.F);},
	TU : function(v){return D.T(v,D.U);},
	TN : function(v){return D.T(v,D.N);}
/*	XSLTPROCESSOR:XSLTProcessor*/
	
};

var data_undefined;

D.X = (typeof XMLHttpRequest != D.U?XMLHttpRequest:data_undefined);
D.A = (typeof ActiveXObject != D.U?ActiveXObject:data_undefined);


/* LEGACY SUPPORT */
function P(c){
	return Engine.Package(c);
}
function ValidatePackage(p){
	return Engine.PackageExists(p);
}


/*
	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.
*/

Engine.Package("$E");






/*
	package $E
*/
$E={

	ci:{},

	gc:0,
	uid_prefix:"swc-",

	v:"2.1.1",

	GetSpecifiedAttribute : function(o, n){
		return $E.IsAttributeSet(o, n, 1);
	},

	IsAttributeSet : function(o, n, b){
		if(o == null || !D.TO(o) || o.nodeType != 1) return 0;
		var s = o.getAttribute(n);
		if(!D.TS(s) || s.length == 0) return 0;
		return (b ? s : 1);
	},
	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()
			,i
		;
		for(i = d.length; i < 4; i++) d = "0" + d;
		return d;
	},
	
	guid:function(){
		var _j = $E;
		var i = _j.gnbid() + "-" + _j.gnbid();
		return _j.h(new String(new Date().getTime()).toString())
				+ "-" + _j.h(location.href)
				+ "-" + i
			;
	},

	combine : function(s,t){
			for(var i in s){
				if(typeof t[i] == "undefined") t[i]=s[i];
			}
			return t;
	},
	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 ( $E.uid_prefix + (++$E.gc) + "-" + t + "-" + r);

/*	return ("swc-" + $E.guid());*/
}

$E.newObject=function(n,v,r){
	var o = {};
	$E.prepareObject(n,v,r,o);
	return o;
}

$E.prepareObject = function(n, v, r, o){
	if(!o) o = {};
	if(!o.o) o.o = {};
	if(!o.o.p) o.o.p = {};	
	if(!o.o.s) o.o.s = {};	
	if(!n) n = "custom_object";
	if(!v) v = "1.0";
	$E.IM(o,"base_object",n,v);
	if(r) $E.registry.ObjectRegistry.addObject(o);
};
$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(
		D.TO(o)
		&&
		D.TO(v)
	){
		for(i in v)
			o[i]=v[i];
		
	}
};
$E.FN=function(s){
	var _js=$E,v,a=arguments;
	if(D.TS(_js.ci[s])){
		eval("v=" + _js.ci[s]);
		return v;
	}
	switch(s){
		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;

		default:
/*			alert("skip: " + s);*/
			break;

	}
	return null;
};

Engine.Package("$E.error");
$E.error.traceRoute  = function(v){

      var r = "",a = [],i = 0, n, q, g, t,l;
      if(v != null){
           while(v && v != null ){
                n = $E.error.G(v.toString());
                if(n == null){
                     v = null;
                     break;
                }
                n += "(";
                g = v.arguments;
                for(i = 0; g && i < g.length; i++){
                     if(i > 0) n += ", ";
                     q = "";
                     
                     t = typeof g[i];
                     l = v;
                     if(t == D.S){
						q = "\"";
						if(l.length > 25) l = l.substring(0,22) + "...";
					}
                     else if(t == D.O) l = "obj";
                     else if(t == D.F) l = "func";
                     
                     n += q + (t == D.O ? "obj" : l) + q + " {as " + t + "}";
                }
                n += ")";
                a.push(n);
                v = v.caller;
           }
           r = a.reverse().join("->");
      }
      else{
           r = "null";
      }
      return r;

 };
     
$E.error.G = function(s){
	
      var a = s.match(/function\s([A-Za-z0-9_]*)\(/gi),r = null;     
      if(s == r) return r;
 
      if(a != null && a.length){
           s = a[0];
           s = s.replace(/^function\s+/,"");
           s = s.replace(/^\s*/,"");
           s = s.replace(/\s*$/,"");
           s = s.replace(/\($/,"");
           return s;
	  }
	  return r;
};

/*
$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.
*/


P("$E.dom");
$E.dom.event={
	v:"2.1.1",
	
	_gevt:function(o){
		return (typeof event == D.O)?event:o;
	},

	_gevt_cancel:function(o){
		(typeof o.preventDefault != D.F)?(o.returnValue=false):o.preventDefault();
		o.cancelBubble = true;
	},

	_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 " + r.i + " is invalid for event " + s + "');return;}\nreturn o._handle_" + s + ".apply(o,arguments);"
					+ "}\ncatch(e){ alert(r.i + \"::\" + s + \"::\" + (e.description?e.description:e.message) + \"\\n\" + $E.error.traceRoute(f.caller));}\n"
					+ "}"
				;
				eval(h);
				if(!x) t[e] = f;
				return f;
			};
		
		}
		catch(e){
			alert("Error: " + e.description);
		}
		
	},
	
	
	


	disableMotionCapture:function(o){
		var f;
		if(typeof document.removeEventListener == D.F){
			document.removeEventListener("mousemove",o.onmousemove,true);
			document.removeEventListener("mouseup",o.onmouseup,true);
		}
		else if(typeof (f = o.releaseCapture) == D.O){
			f();
		}
/*
		var c = $E.dom.browser.client;
		switch(c.bswitch){
			case 1:
				o.releaseCapture();
				break;
			case 2:
				document.removeEventListener("mousemove",o.onmousemove,true);
				document.removeEventListener("mouseup",o.onmouseup,true);	
				break;
		}
*/
	},

	enableMotionCapture:function(o){
		var f;
		if(typeof document.addEventListener == D.F){
			document.addEventListener("mousemove",o.onmousemove,true);
			document.addEventListener("mouseup",o.onmouseup,true);
		}
		
		else if(typeof (f = o.setCapture) != D.U){
			f();
		}
		
/*
		var c = $E.dom.browser.client;
		switch(c.bswitch){
			case 1:
				o.setCapture();
				break;
			case 2:
				document.addEventListener("mousemove",o.onmousemove,true);
				document.addEventListener("mouseup",o.onmouseup,true);
				break;
		}
*/
	},

	
	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;		
		}
*/
	}

}



Engine.Package("$E.dom");
$E.dom.css={
	/*_get_offset_client_height*/
	v:"2.1.1",

	getOffsetClientHeight:function(o){
		var r=0,m;
		if(o){
			m=parseInt(o.style.borderLeftHeight) + parseInt(o.style.borderRightHeight);
			if(!isNaN(m)){
				r += m;
			}
			m=parseInt(o.style.paddingTop) + parseInt(o.style.paddingBottom);
			if(!isNaN(m)){
				r += m;
			}
		}
		return r;

	},

	/*_get_offset_client_width*/
	getOffsetClientWidth:function(o){
		var r=0,m;
		if(o){
			m=parseInt(o.style.borderLeftWidth) + parseInt(o.style.borderRightWidth);
			if(!isNaN(m)){
				r += m;
			}
			m=parseInt(o.style.paddingLeft) + parseInt(o.style.paddingRight);
			if(!isNaN(m)){
				r += m;
			}
		}
		return r;

	},

	/*_gabs_top*/
	getAbsoluteTop:function(o){
		var c=o,t=0;
		while(c!=null && c.nodeName.toLowerCase() != "body"){
			t+=c.offsetTop;
			c=c.offsetParent;
		}
		return t;
	},

	/*_gabs_left*/
	getAbsoluteLeft:function(o){
		var c=o,l=0;

		while(c!=null && c.nodeName.toLowerCase() != "body"){
			l+=c.offsetLeft;
			c=c.offsetParent;
		}	
		return l;
	},
		
	getAbsoluteTop:function(o,r){
		return $E.dom.css.getAbsolutePosition(o,r,1);
	},

	getAbsoluteLeft:function(o,r){
		return $E.dom.css.getAbsolutePosition(o,r,0);
	},
	
	getAbsolutePosition:function(o,r,b){
		var c=o,i=0;

		while(c != null && (!r || r != c) && c.nodeName && !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.
*/

Engine.Package("$E");
$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","2.1.1");
		


		
		
		
		n.o = {
	
			s:{
				r:"handle_thread_run",
				s:"handle_thread_start",
				t:"handle_thread_stop",
				d:"1000",

				/* u = interval in use */
				u:0,
				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.restart = function(){
			if(!this.stop(1) || !this.run(this.o.s.u, 1)) return 0;
			return 1;
		};

		n.getLastInterval = function(){
			return this.o.s.u;
		};

		n.run = function(d,b){
			var t = this, _s;
			_s = t.o.s;
			if(!t.getIsRunnable() || _s.i) return 0;
			
			if(!D.TN(d) || d < 0) d = _s.d;
			_s.u = d;
			
			/* m = 1; interval */
			_s.m = 1;
/*			_s.i = window.setInterval(t.R,d);*/
			
			if(!b && D.TF(t.o.p.o[_s.s])) 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;
			_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(D.TO(_p.o) && _p.o.r > 4){

				
				if(!t.stop()){
					_s.y = 1;
					
				}
				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(b){
			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(!b && D.TF(t.o.p.o[_s.t])) 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(
				D.TO(o)
				&&
				typeof D.TF(o[_c.s.r])
			) 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.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){
				
				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.
*/

Engine.Package("$E.util");
$E.util = {

	v:"2.1.1",


	getDate:function(i){
		var d = new Date();
		return i?d:d.getTime();
	},
	
	EH:function(e,h){
		/* don't use shorthand for e.getAttribute, typeof == unknown will throw an error */
		if(D.TO(e)&& typeof e.getAttribute != D.U && D.TS(e.getAttribute(h))){
			try{
				eval(e.getAttribute(h));
			}
			catch(z){
				$E.message.MessageService.S("Error evaluating [engine]." + h + ": " + (z.description?z.description:z.message),"515.4",1);
			}
		}	
	}
};


/*
	Engine for Web Applications
	Source: $E.util.url
	Copyright 2002 - 2008. All Rights Reserved.
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/projects/engine/
	License: http://www.whitefrost.com/projects/engine/code/engine.license.txt
*/


Engine.Package("$E.util.url");

$E.util.url={
	qualifyToHost:function(u){
		var _u = $E.util.url.newInstance(document.URL,0);
		return _u.qualify(u);
	},
	newInstance:function(v,b){



		
		
		


		var n = $E.FN("base_object","url_composite","2.1.1");
		
		if(b) v = $E.util.url.qualifyToHost(v);
		
		n.o={
			s:{
				/* original_value */
				ov:0,
				/* protocol */
				r:0,
				/* domain */
				d:0,
				/* path */
				p:0,
				/* file */
				f:0,
				/* query */
				q:0,
				/* qualified */
				x:(b?1:0)
			}
		};
		n.getFile=function(){
			return this.o.s.f;
		};

		n.getQuery=function(){
			return this.o.s.q;
		};

		n.getDomain=function(){
			return this.o.s.d;
		};

		n.getPath=function(){
			return this.o.s.p;
		};

		n.getProtocol=function(){
			return this.o.s.r;
		};
		
		n.qualify=function(u){
			/*
				u = url
				
				f = full url
			*/
			var f = u,_s,t=this;
			_s = t.o.s;


			/* don't bother with fully qualified urls */
			if(!u.match(/\/\//)){
	
				/* if there is no leading slash, or it starts with a ./ */
				if(!u.match(/^\//) || u.match(/^\.\//)){
					if(u.match(/^\.\//)) u=u.substring(2,u.length);
					f = _s.r + "://" + _s.d + _s.p + u;
				}
				else{
					/* if the url has a leading slash */
					if(u.match(/^\//)){
						f = _s.r + "://" + _s.d + u;
					}
					else{
						/* need to count back */

					}
				}
			}
	
			return f;
		};
		
		n._init = function(o){
			/*
			
				o = original value
				
				u = url
				
				i = variant index
				v = variant value
				m = variant marker
			*/
			var _s,t=this,u,v,m;
			_s = t.o.s;
			u = _s.ov = o;

			if(u.match(/\?/)){
				i=u.indexOf("?");
				_s.q=u.substring(i+1,u.length);
				u=u.substring(0,i);
			}
			if(u.match(/\/\//)){
				i=u.indexOf("//");
				v=u.substring(0,i + 2);
				u=u.substring(i+2,u.length);
				if(v.match(/:/)){
					m=v.indexOf(":");
					_s.r=v.substring(0,m);
				}
				else{
					_s.r="http";
				}
			}
			if(!u.match(/\//)){
				if(!_s.r) _s.r="http";
				_s.d=u;
				u="";
			}

			i=u.indexOf("/");
			if(i > -1){
				_s.d=u.substring(0,i);
				u=u.substring(i,u.length);
			}
			if(!_s.r) _s.r="http";

			if(u.length){
				i=u.lastIndexOf("/");
				if(i > -1){
					v=u.substring(0,i + 1);
					_s.p=v;
					u=u.substring(i + 1,u.length);
				}
			}
			if(u.length){
				_s.f=u;
			}
			
		};

		n._init(v);
		return n;
	}
}



/*
	libXmlRequest
	Source: $E.xml
	Copyright 2002 - 2008. All Rights Reserved.
	Version: 2.1.1
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/projects/engine/
	License: http://www.whitefrost.com/projects/engine/code/engine.license.txt
*/

/*
	REMARKS

		The org, org.cote, and $E defs are a literal translation from the Engine project.
		The structure is left intact for compatibility.
	
		The package structure is considered part of the branding and copyright; do not alter it.


	BROWSER SUPPORT
		
		Mozilla-based browsers (eg: Mozilla, Firebird, NS 7)
			XSL and XPath supported as of 1.2

		Internet Explorer 5.01 and later
			MSXML Support is defined as MSXML2.XMLHTTP.3.0

		Safari 1.0.3: XMLHttpRequest, no XPath, no XSL




		Opera 8: XMLHttpRequest, no XPath, no XSL

		Konqueror: No / unknown

	SERVER SUPPORT NOTE
	
		Some Application Servers such as Perl and PhP expect XML Posts to be set with a specific content type.
		The default encoding for version SPEC-1.5.1.0909.2005 is "text/xml".
		It may be necessary to specify "application/x-www-form-urlencoded" or "multipart/form-data" for posted XML data to be interpreted on the server.

	USAGE
	
		Synchronous GET:
			[xml_dom_object] = getXml(path);

			Example:
			var oXml = $E.xml.getXml("/Data/Test1.xml");

		Asynchronous GET:
			[int] = getXml(path,custom_handler,1,{optional_id});

			Example:
			function HandleXml(s,v){
				var oXml = v.xdom;
			}
			$E.xml.getXml("/Data/Test1.xml",HandleXml,1);
			
		Cached Asynchronous GET:
			[int] = getXml(path,custom_handler,1,request_id,1);
			
			Example:
			function HandleXml(s,v){
				var oXml = v.xdom;
			}
			$E.xml.getXml("/Data/Test1.xml",HandleXml,1,"cache-me",1);
			
		Synchronous POST:
			[xml_dom_object] = postXml(path,data);
			
			Example:
			
			var oPostThis = $E.xml.newXmlDocument("Request");
			var oData = oPostThis.createElement("data");
			oData.setAttribute("id","data-id");
			oData.setAttribute("value","data-value");
			oPostThis.documentElement.appendChild(oData);
			
			var oResponseXml = $E.xml.postXml("/Data/TestData.aspx",oPostThis);
			
		Asynchronous POST:
			[int] = postXml(path,data,custom_handler,1,{optional_id});
			
			Example:
			
			
			function HandleXml(s,v){
				var oResponseXml = v.xdom;
			}
			var oPostThis = $E.xml.newXmlDocument("Request");
			var oResponseXml = $E.xml.postXml("/Data/TestData.aspx",oPostThis,HandlePostXml,1);
			

		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.
			
	INTERNAL NOTES
		
		The spec for XMLHttpRequest specifies that all handlers are cleared after each request.
		Therefore, the internal handlers are cleared after each request.  If not, they don't fire on subsequent requests.

	BUGS and BUG FIXES

		02/26/2009 : Update raw text handling
			Add better raw text handling for JSON support.  Include a few JSON hooks for convenience.
			

        04/23/2008 : IE 7 Fix for native XMLHttpRequest via FileSystem
            Add a special case for IE 7 support of local filesystem requests via XMLHttpRequest
            The resolution was to degrade to a DOM Document load.
	
	    04/17/2007 : Merge
	        Merge corrections between different versions of library.
	        Investigate issue with Mozilla posting on Vista to IIS 7

		11/15/2005 : Typo
			Fixed typo for asynchronous non-cached non-IE requests.

		10/10/2005 : Safari bug fixes
			Add corrections for Safari request header and creating new XML documents

		09/09/2005 : clearCache wasn't actually clearing the cache.		
			Some method cleanup required.
			
			The internal event handler, and therefore any custom event handler, for asynchronous calls that fail due to exceeding the pool size, was not being called.  This has been fixed.
			
		09/08/2005 : Improve support
			Improved support for Opera and Safari.

		06/17/2003 : Race condition occurs in multiple requests using the same request id
			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 : Event handler problem in Mozilla 1.4RC1
			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 : Event handler problem in IE
			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!



pseudo code for selectSingleNode / selectNodes

window.selectNodes = function (d,v,c){
  var elName = v.replace(/[^\w].*$/,'');
  elName = d.getElementsByTagName(elName);
  var attrToMatch = v.replace(/^.*@/,'').replace(/\s*=.*$/,'');
  var valToMatch = v.replace(/^[^']*'/,'').replace(/'.*$/,'');
  for(var i=0;elName[i];i++){if(elName[i].getAttribute(attrToMatch)==valToMatch){return [elName[i]];}}
  return [];
}
*/

Engine.Package("$E.xml");



			





$E.xml={
	v:"2.1.1",
	
	xml_content_type:"text/xml",
	text_content_type:"text/plain",

	
	auto_content_type:1,

	form_content_type:"application/x-www-form-urlencoded",
/*
	_xml_request:null,
	_xml_request_id:null,
*/
	r:[],
	rm:[],

	ax_http_control:"MSXML2.XMLHTTP.4.0",

	ax_dom_control:"MSXML.DOMDocument",

	gadget_mode:0,
	gadget_xml_control:"Core.Gadget.GadgetXmlHttp",
	gadget_base_path:0,
	base_path:0,

	
	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;
	},
	
	
	
	parseXmlDocument:function(s){
		/*
			s = String of XML data
		*/
		
		var r = 0,e;
		if(!s) return 0;
		if(typeof DOMParser != D.U){
			e = new DOMParser();
			r = e.parseFromString(s,"text/xml");
		}
		else if(typeof D.A != D.U){
			r = new D.A($E.xml.ax_dom_control);
			r.async = false;
			r.loadXML(s);
		}
		else{
		}
		return r;
	},
	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);
			/* Safari bug */
			if(r != null && r.documentElement == null){
				r.appendChild(r.createElement(n));
			}
		}
		else if(typeof D.A != D.U){
			r = new D.A($E.xml.ax_dom_control);
			e = r.createElement(n);
			r.appendChild(e);
		}
		else{
		}
		return r;
	},
	
	clear:function(){
		var _x = $E.xml;

		
		_x.clearCache();
		
		
		
		_x.R();
		
		
		_x.r = [];
		rm = [];
		
		return 1;

	},

	
	/*
		2005/09/09 - better clear out the cached ids and arrays as well as nullifying the object p
	*/
	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){
								
				o.cd = 0;
			}
			o.obj = null;
			o.ih = null;
			o.h = null;
		}
		_x.r = [];
		_x.rm = [];
	},

	
	
	
	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($E.xml.ax_http_control);
				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)

				
				
				a[i] = 0;
			

			

			
			try{
			
				if(!y){
					/* 2005/09/07 Fix for Opera 8 */
					/*
						Why bother checking the instance of?
						Either XMLHttpRequest is here and use it, or it's not so don't use it
					*/
					/*if(typeof XMLHttpRequest == "function" || (typeof XMLHttpRequest == "object" &&  o.xml_object instanceof XMLHttpRequest))*/
					/* 2005/09/08 Fix for Safari */
					if(typeof D.X != D.U){
						if(typeof o.o.removeEventListener == D.F)
							o.o.removeEventListener("load",o.h,false);
						else
							o.o.onreadystatechange = _x.B;
					}
					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--;
		}
		
		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;
				
			}
			else{
				_m.S("Max pool size reached!","200.4");
				return null;
			}
		}

		if(b > -1){
			_x.hu++;
			o = a[b];
			
			try{
			
				if(!y){

					/* 2005/09/07 Fix for Opera 8 */
					/*
						Why bother checking the instance of?
						Either XMLHttpRequest is here and use it, or it's not so don't use it
					*/
					
					/*if(typeof XMLHttpRequest == "function" || (typeof XMLHttpRequest == "object" &&  o.xml_object instanceof XMLHttpRequest)){*/
					/* 2005/09/08 Fix for Safari */
					if(typeof D.X != D.U){
						if(typeof o.o.addEventListener == D.F){
							o.h = function(){$E.xml.L(b);};
							o.o.addEventListener("load",o.h,false);
						}
						else{
							o.h = function(){$E.xml.S(b);};
							o.o.onreadystatechange = o.h;
						}
					}
					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 = {text:null, xdom:null, json: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($E.xml.ax_dom_control);
					mp.loadXML(o.o.responseText);
					v.xdom = mp;
				} else  if(o.o != null && (o.t || o.o.responseXML != null)){
					if(o.t){
						v.text = o.o.responseText;
						if(o.t == 2 && typeof JSON != D.U){
							try{
								v.json = JSON.parse(v.text,_x.JSONReviver);
							}
							catch(e){
								v.json = null;
								v.error = e.message;
							}
						}
					}
					else v.xdom = o.o.responseXML;
				}
				
				else if(o.o != null)
				    /* v.xtext = o.o.responseText;   */
					_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);
			}
		}
	},
	
	getJSON: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,2);
	},
	getText: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,1);
	},
	/*
		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);
	},
	
	postJSON:function(p,d,h,a,i){
		/*
			Caching is not provided for the postXml wrapper.
		*/
		if(typeof JSON == "undefined"){
			alert("Missing JSON interpreter");
			return 0;
		}
		return $E.xml.X(p,h,a,i,1,JSON.stringify(d),0,2);
	},
	postText: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,1);
	},
	
	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,t){
		/*
			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
			
			t = treat response only as text.  1 == text, 2 == json

		*/
		
		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(
			_x.ce
			&&
			typeof _x.rm[i] == D.N
			&&
			( r = _x.r[_x.rm[i]] )
		){
			
			if(r.c && (typeof r.cd == D.O || typeof r.ct == D.S)){
				if(!t)
					b = {xdom:r.cd, id:i};
				else{
					b = {text:r.ct, id:i};
					if(t == 2 && typeof JSON != D.U)
						b.json = JSON.parse(r.ct,_x.JSONReviver);	
					
				}
				if(b){
					_m.publish("onloadxml",b);
					if(typeof h == D.F) h("onloadxml",b);

					

					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();
				
			}
			
		}

		
		/* get a new XML object, or a pooled object depending on the settings */
		
		b = _x.he;
		if(_x.gadget_mode){
			a = 0;
			b = 0;
			p = _x.gadget_base_path + p;
			r = new ActiveXObject(_x.gadget_xml_control);
		}
		else if(b){
			
			r = _x.G(!a);
			
		}
		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");

			/* 2005/09/09 - raise the handler for async requests */
			b = {text:null, xdom:null, error:"Null XML object in X", id:i};
			if(typeof h == D.F) h("onloadxml",b);

			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,
			
			r:0,
			t:t
		};
		
		_x.rm[i]=y;
		o = _x.r[y].o;

		if(!p.match(/:\/\//)){
			var m,e=new RegExp("^/");
			if(!p.match(e)){
				if(_x.base_path){
					p = _x.base_path + p;
				}
				else{
					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;
		
		
		if(b_ia && typeof XMLHttpRequest != D.U && p.match(/^file/i)){
		        _x.P(_x.r[y].pi,!a);
		        o = new D.A($E.xml.ax_dom_control);
		        if(bi) i = bi;
				o.load(p);
				b = {xdom:o,id:i};
				_m.publish("onloadxml",b);
				if(typeof h == D.F) h("onloadxml",b);

				

				return o;
		}
		
		
		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){*/
			/*if(!b && a && (typeof XMLHttpRequest == "function" || (typeof XMLHttpRequest == "object" && o instanceof XMLHttpRequest))){*/

			if(!b &&  a && typeof D.X != D.U){
				if(typeof o.addEventListener == D.F){
					_x.r[y].ih = function(){$E.xml.L(i);};
					o.addEventListener("load",_x.r[y].ih,false);
				}
				else{
					_x.r[y].ih = function(){$E.xml.S(i);};
					o.onreadystatechange=_x.r[y].ih;
				}
			}

			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);

		if (typeof o.setRequestHeader != D.U) {
			z = (t ? _x.text_content_type : _x.xml_content_type );
			if(_x.auto_content_type && !t && typeof d == D.S) z = $E.xml.form_content_type;
			o.setRequestHeader("Content-Type", z);

		}
		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 = (t ? o.responseText : o.responseXML);

			
			if(
				!t
				&&
				p.match(/^file:/i)
				&&
				b_ia
			){
				var mp = new D.A($E.xml.ax_dom_control);
				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);
			}
			else{
			
				 _x.L(i);
							
			
			}			
			
			
			_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, t){
		/*
			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!= null){
					if(t) o = $E.xml.serialize(o);
					else o = o.firstChild;
					
				}
			}
	
			else if(typeof D.A != D.U && x instanceof D.A){
				o = new D.A($E.xml.ax_dom_control);
				
				
				xp = n.transformNode(s);
				if(t) o = xp;
				else{
					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])
			
			return _x.nu[n];
			
		
		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 || e.nodeType == 4) r+=e.nodeValue;
				if(e.nodeType==1 && e.hasChildNodes()){
					r+=$E.xml.getInnerText(e);
				}
			}
		}
		return r;
	},
	
	removeChildren:function(o){
		var i;
		for(i=o.childNodes.length-1;i>=0;i--)
			o.removeChild(o.childNodes[i]);
		
	},
	
	
	swapNode : function (n,c){
		if(!n || !c) return;
		if(typeof n.swapNode != D.U) n.swapNode(c);
		else{
		    var s = n.nextSibling;
			var p = n.parentNode;
			p.replaceChild(n,c);
			p.insertBefore(c, s);
		}
	},
	
	setInnerXHTML:function(t,s,p,d,z,c,h,ch){
		/*
			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,f;
		
		/* 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;
		
		try{
		
		switch(y){
			case 1:
				if(h){
					e = s.cloneNode(false);
				}
				else{
				    f = s.nodeName;
				    if(typeof ch == D.F) f = ch(y,f);
				    if(!f) return 0;
					e=d.createElement(f);
					a=s.attributes;
					l=a.length;
					for(x=0;x<l;x++){
						n=a[x].nodeName;
						v=a[x].nodeValue;
    				    if(typeof ch == D.F){
    				        n = ch(2,n);
    				        v = ch(2,v);
    				    }
	
						/*
							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++)
						$E.xml.setInnerXHTML(e,a[x],1,d,z,c,h,ch);
					
				}

				/* stupid IE */
				if(b && s.nodeName.match(/input/i) && $E.IsAttributeSet("checked")){
					e.checked=true;
				}

				t.appendChild(e);
				r = e;
				break;
			case 3:
				e=s.nodeValue;
    		    if(typeof ch == D.F) e = ch(y,e);
				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:
				try{
				e = s.nodeValue;
				if(typeof ch == D.F) e = ch(y,e);
				t.appendChild(d.createCDATASection(e));
				}
				catch(er){ alert(e + "\n" + ch + "\n" + t.nodeName);}
				break;
			case 8:
				/*
					Ignore comments
				*/
				break;
			case 33:
				e=s;
				if(typeof ch == D.F) e = ch(y,e);
				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:
				
				break;
		}
		
		}
		catch(e){
			$E.message.MessageService.S( (e.message ? e.message : e.description) + " in type " + y + " : " + $E.error.traceRoute($E.xml.setInnerXHTML),"200.4");
		}
		
		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=[];

	},

	JSONReviver : function (k, v) {
		var a;
		if( typeof v == "string" && (a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(v)))
			return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],+a[5], +a[6]));
		return v;
	}
};





		
		
		

/*
	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.
*/

Engine.Package("$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(
				!D.TO(o)
				||
				(
					!D.TS(o.i)
					||
					!D.TS(o.t)
					||
					!D.TS(o.v)
					||
					!D.TN(o.r)
				)
			){
				return 0;
			}
			return 1;
			
		};
		
		t.addObject=function(o){
			var i,m,p;

			if(!t.canRegister(o)){
				if(_js_validate_package("$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(!D.TN(p.om[i])){
			
				m = p.o.length;
				p.o[m]=o;
				p.om[i]=m;

				if(
					t.o.s.rt
					&&
					_js_validate_package("$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(D.TN(p.om[i])){
				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(
				D.TN(p.om[i])
				&&
				D.TO(p.o[p.om[i]])
			){
				return p.o[p.om[i]];
			}
			return null;
		};

		t.isRegistered=function(i){
			
			if(D.TO(i)){
				if(D.TU(i.i)) return 0;
				i = i.i;
			}
		

			if(D.TN(t.o.p.om[i])){
				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 && D.TF(o.sigterm)){
					o.sigterm();
					/*t.removeObject(o,1);*/
					
				}
				
			}
			
			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)
				&&
				D.TF(o.destroy)
			){
				o.destroy();
				return 1;
			}

			return 0;
		};

		
		$E.IM(t,"base_object","object_registry","2.1.1");
		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.
*/

P("$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(D.TN(i)) i = c.data.l[i];
			if(D.TN(c.data.lm[i])){
				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(D.TN(i) && i >= 0){
				t.o.s.dd = i;
			}
		};
		
		t.newSubscriptionObject = function(o,n,h,g){
			return {
				object:o,
				subscription_name:n,
				handler:h,
				target:g
			};
		};

		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(!D.TO(c.p.s[e])) c.p.s[e]=[];
			l = c.p.s[e].length;
			c.p.s[e][l] = t.newSubscriptionObject(o,e,f,v);
			/*$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(!D.TO(c.p.s[e])) 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(D.TS(i) && D.TO(c.p.dd[i])){
				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(!D.TO(c.p.s[e])) 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(D.TS(z.handler))
							z.object[z.handler](e,o);
						
						else if(D.TF(z.handler))
							z.handler(e,o);
					
					}
					catch(e){
						alert("Publish Error: " + e.message + "\n" + z.subscription_name + " : " + z.handler + "\n" + $E.error.traceRoute(z.object[z.handler]));
					}
					

				}
			}
		};
		
		
		
		
		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(!D.TS(s)) s = "200";

			v = t.I(s);

			if(v.t < c.s.rt){
				return o;
			}

			if(!D.TN(p)) p = 0;
		
			if(p) o=t.R(s,d,v);
			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.newBasicMessage = function(e,d){
			return {
				entry:e,
				index:-1,
				data:d,
				time:new Date(),
				id:$E.GG()
			};
		};
		t.C=function(s,d,v){
			var o,i,c,t=this;
			o = t.newBasicMessage(v,d);
			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(D.TO(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(D.TO(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","2.1.1");*/
		$E.prepareObject("message_service","2.1.1",1,t);

		/*$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.
*/


Engine.Package("$E.object");

$E.object={
	v:"2.1.1",
	
	newInstance:function(s,z){
		var o = $E.newObject(s,v,1);
		$E.dom.event.addEventBuffer(o);
		return o;
	},
	/*
		IOA
		
		Given an object that

	*/
	

	







	IOA:function(o,s){
	
		if(!D.TO(o) || !D.TO(o.o) || !D.TO(o.o.p)){
			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
*/

Engine.Package("$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,
				signal_terminate:0,
				gc:0
			},
			p:{
				/* application_config */
				application_config:0
			}
		};

		t._terminate = function(){
			if(t.o.s.signal_terminate) _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, _s = this.o.s;
			if(!_s.wu){
				_s.wu = 1;
				t.o.p.a = 0;
				if(_s.signal_terminate){
					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","2.1.1");
		$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.
*/

Engine.Package("$E.util");

$E.util.config={
	newInstance:function(s,h,a){
		var n = {

			o:{
				p:{
					config:[],
					config_map:[],
					config_load_handler:0
				},
				s:{
					config_path:0,
					/* config_loaded */
					l:0,
					load_async:0,
					root_name : 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.unsubscribe(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.init=function(){
			var t = this;
			t.r = 4;
			t.o.s.l = 1;
			t.o.s.root_name = "web-application";
		};
		
		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 = (D.TF(h)?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.serialize = function(x){
			var t=this,c,o,l,i=0,x,p;
			c = t.o;
			l = c.p.config.length;
			if(!c.s.root_name) return null;
			if(!x) x = $E.xml.newXmlDocument(c.s.root_name);

			p = x.createElement(c.s.element_parent_name);
			x.documentElement.appendChild(p);
			for(;i < l;i++){
				if(c.p.config[i].value == null || D.TU(c.p.config[i].value)) continue;
				o = x.createElement(c.s.element_name);
				p.appendChild(o);
				o.setAttribute(c.s.attr_name_name,c.p.config[i].name);
				o.setAttribute(c.s.attr_value_name,"#cdata");
				o.appendChild(x.createCDATASection(c.p.config[i].value));
			
			}
			return x;
		};

		n.writeParam = function(o, x, v){
			var t = this, c, p, n, b = (v == null || D.TU(v));
			if(!o || !x) return 0;
			c = t.o;
			p = o.documentElement.getElementsByTagName(c.s.element_parent_name);
			if(p.length) p = p[0];
			else{
				p = o.createElement(c.s.element_parent_name);
				o.documentElement.appendChild(p);
			}
			n = $E.xml.selectSingleNode(o, c.s.element_name + "[@" + c.s.attr_name_name + " = '" +  x + "']",p);
			if(n && b)
				p.removeChild(n);
			else if(!b){
				if(!n){
					n = o.createElement(c.s.element_name);
					n.setAttribute(c.s.attr_name_name,x);
					p.appendChild(n);
				}
				else $E.xml.removeChildren(n);
								
				n.setAttribute(c.s.attr_value_name,"#cdata");
				n.appendChild(o.createCDATASection(v));
			}
			return t.setParam(x, v);
		};
		
		n.setParam=function(x, v){
			var t=this,c,o,l;
			c = t.o;
			if(!c.s.l) return null;
			
			if(D.TN(c.p.config_map[x]))
				if(c.p.config[c.p.config_map[x]]){
					c.p.config[c.p.config_map[x]].value = v;
					if(v == null || !D.TU(v)) c.p.config_map[x] = null;
				}
				else return 0;
			else if(v != null && !D.TU(v)){
				c.p.config_map[x]=c.p.config.length;
				c.p.config[c.p.config.length]={"name":x,"value":v};
			}
			
			return 1;
		};
				
		n.getParam=function(x){
			var t=this,c,o;
			c = t.o;
			if(!c.s.l) return null;
			if(D.TS(x))
				x = c.p.config_map[x];
			
			if(D.TN(x) && D.TO(c.p.config[x]))
				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(D.TO(o) && o.documentElement != null){
				c.s.l = 1;
				if(!c.s.root_name) c.s.root_name = o.documentElement.nodeName;

				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(D.TS(n) && n.length > 0){
						v = p.getAttribute(c.s.attr_value_name);
						if(!D.TS(v)) v = "";

						c.p.config_map[n]=c.p.config.length;

						if(v == "#cdata" && p.hasChildNodes())
							v = $E.xml.getCDATAValue(p);
						
						c.p.config[c.p.config.length]={"name":n,"value":v};
					}
				}
				
				t.r = 4;
			}

			if(D.TF(c.p.config_load_handler)){
				c.p.config_load_handler("onconfigload",this);
			}

		};

		$E.IM(n,"base_object","config_utility","2.1.1");
		$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(D.TS(h) && D.TF(window[h])){
			h = window[h];
		}
		
		if(D.TS(s)){
			if(!a) a =0;
			n.load(s,h,a);
		}
		
		else if(D.TO(s) && s != null){
			n._parse_config(s);
		}
		
		else if(D.TU(s)){
		/*
			alert(h);
			n.r = 4;
			n.s.l = 1;
			n.s.root_name = "Config";
		*/
		}
		
		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.
*/

Engine.Package("$E.wires");
$E.wires.primitive={
	PrimitiveWire:null,
	PrimitiveWireImpl:function(){


		
		
		

		var t = this;
		t.o={
			p:{
				/* wires */
				w:[]
			},
			s:{
				/* counter */
				c:0
			}
		};
		
		t.getWires = function(){
			return this.o.p.w;
		};
		
		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(!D.TO(args)) args = [];


			if(D.TO(h)){

				a = (D.TO(h.ap) && D.TS(h.a))?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 = (D.TO(h.hp) && D.TS(h.h))?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(D.TF(h.hp[h.h])) h.hp[h.h].apply(h.hp,args);
							/* else alert("$E.wires.primitive::invoke Error = Invalid function pointer " + h.h); */
						}
						else{
							if(D.TF(h.h)) 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(D.TO(h)){
				return h;
			}
			return 0;
		};
		t.fireWire=function(i){
			var c = t.o,h;
			h = c.p.w[i];
			if(D.TO(h)){
				/* 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(!D.TS(tl)) tl = "swc.ocjw.primitive";

			try{
				if(D.TS(xp)) xp = eval(xp);
				if(D.TS(yp)) yp = eval(yp);
				if(D.TS(ep)) 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","2.1.1");
		$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.
*/
Engine.Package("$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.getWires = function(){
			return this.o.p.w;
		};
		t.getWiresHash = function(){
			return this.o.p.h;
		};
		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(!D.TO(args)) 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(D.TS(xp)) xp = eval(xp);
			}
			catch(e){
				alert("ocjw.invoke.Error: " + e.toString());
				return 0;
			}
			
			if(!D.TU(xp) && x){
			
				l = (xp!=null?(xp.getObjectId ? xp.getObjectId() : (xp.id?xp.id:(xp.name?xp.name:0))):0);
				d = l + "-" + x;
				if(D.TO(_p.l[d])){
					wl = _p.l[d];
				}
				else{
					alert("Invalid Wire Reference (" + d + ") in $E.wires.js::invoke");
				}
			}
			else{
				if(D.TO(_p.w[0])){
					w = _p.w[0];
					wl = _p.l[w.la + "-" + w.a];
				}
			}
			
			if(D.TO(wl) && 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(D.TO(_p.l[d])){
								
								/* 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 S.
							
						*/
						
					}				
				}
				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(D.TS(xp)) xp = eval(xp);
				if(D.TS(yp)) yp = eval(yp);
				if(D.TS(ep)) 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(!D.TO(_p.l[i])) _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(D.TS(xp)) xp = eval(xp);
				if(D.TS(yp)) yp = eval(yp);
				if(D.TS(ep)) 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(D.TS(i)){
				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(!D.TO(o) || !D.TO(o.pw)){
				_m.S("Invalid object reference for primitive wire","511.4");
				return 0;
			}
			pw = o.getPrimitiveWire(i);
			if(!D.TO(pw)){
				_m.S("Invalid primitive wire id " + i,"511.4");
				return 0;
			}
			
			b = pw.action_arguments;
			for(;k < b.length;) c[k] = b[k++];
			if(D.TO(a) && (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(!D.TO(o) || !D.TO(o.pw)){
				_m.S("Invalid object reference for primitive wire","511.4");
				return 0;
			}
			pw = o.getPrimitiveWire(i);
			if(!D.TO(pw)){
				_m.S("Invalid primitive wire id " + i,"511.4");
				return 0;
			}
			b = pw.handler_arguments;
			for(;k < b.length;) c[k] = b[k++];
			if(D.TO(a) && (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(!D.TO(o) || !D.TO(o.pw)) 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","2.1.1");
		$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
*/
Engine.Package("$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 */
				!D.TF(o.doTransaction)
				||
				!D.TF(o.startTransaction)
				||
				!D.TF(o.endTransaction)
				
			){
				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(
				D.TO(o) && o != null
				&&
				D.TN(_p.rm[o.i])
				&&
				_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;

			
			
			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);

				

				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--;

				

				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(D.TU(x)) 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
						){

							
							
							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;

					

					if(D.TF(p.handler))
						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(D.TO(p)){
				/*
					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;

				

			}
			else{
				_m.S("Invalid packet id " + i,"200.4");
			}
		};
		t.newTransactionPacket = function(i,n,o,v,f){
			var p = {
				packet_id:i,
				packet_name:n,
				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:o,
				data:v,
				handler:f
			};
			$E.prepareObject("transaction_packet","2.1.1",1,p);
			return p;

		};
		
		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(D.TU(n)) n = i;
			if(D.TU(d)) d = 0;
			if(D.TU(f)) f = 0;
			
			if(D.TO(p)){
				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(
				D.TN(_p.packetnames[n])
				&&
				D.TO(_p.packets[_p.packetnames[n]])
				&&
				_p.packets[_p.packetnames[n]].is_open
			){
				_m.S("Transaction " + n + " is already open.","200.4");

				return 0;
			}
			
			o = t.newTransactionPacket(i, n, p.i, d, f);
			/*_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)){
				
				if(_s.a) t.serveTransaction(o);
			}
			
			else
				_m.S("Transaction " + n + " was not opened.","200.4");
			

			
			return i;
			
		};
		$E.object.IOA(t,"packet");
		$E.prepareObject("transaction_service","2.1.1",1,t);
		/*
		$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
 * 
 */



Engine.Package("$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.newTaskObject = function(n, at, a, ht, h, k, i, r, p){
			var o = {
				task_state:0,
				handled:0,
				task_name:n,
				action_type:at,
				action:a,
				handler_type:ht,
				handler:h,
				task_id:k,
				index:i,
				transaction_id:r,
				processor:p,
				data:0,
				depends:[],
				executed:0,
				busy:0,
				ad:0,
				parent_id:0,
				setAutoDestroy:function(b){this.ad = (b?1:0);}
				
				
			};
			$E.prepareObject("task_object","2.1.1",1,o);
			return o;
		};

		t.clearTask=function(i){
			var _p = t.o.p,o,l;

			if(D.TS(i)) o = t.getTask(i);
			else if(D.TO(i)) o = i;

			if(t.isTask(o)){
			
				if(o.task_state < t.o.data.f){

					

					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);

					
				
				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");
			}

			

		};

		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.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;

				

				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;

				

				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;

				

				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(
					!D.TO(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(D.TS(o)) 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;

					
					
					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){

					

					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(
				!D.TO(d)
			){
				if(p && p.action_type.match(/xml/) && D.TO(p.data)){
					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(!D.TO(d) || d == null){

				

				return 0;
			}
			
			if(D.TS(n)){
				z = _x.queryNode(d.documentElement,"task",0,"id",n);/*_x.selectSingleNode(d,_c.data.n + "task[@id = '" + n + "']",d.documentElement);*/
				if(D.TO(z) && z != null)
					return t.importTaskFromXml(z,p,d,b);
				
				else
					_m.S("Task '" + n + "' does not exist","200.4");
				
			}

			if(
				D.TO(n)
				&& n != null
				&& D.TO(d)
				&& d != null
			){
				r = $E.GetSpecifiedAttribute(n, "rid");
				i = $E.GetSpecifiedAttribute(n, "id");
				if(r){
					z = _x.queryNode(d.documentElement,"task",0,"id",r);/*_x.selectSingleNode(d,_c.data.n + "task[@id = '" + r + "']",d.documentElement);*/
					if(D.TO(z) && 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){
	
					/* _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(D.TO(p)){
						if(D.TF(p.processor)){
							a = p.processor(t,p,n,a);
							at = p.processor(t,p,n,at);
							h = p.processor(t,p,n,h);
							ht = p.processor(t,p,n,ht);
						}
						t.addTaskDependency(p,i);
						/*p.depends[p.depends.length]=i;*/
					}
					
					r = t.addTask(i,at,a,ht,h,(p?p.processor:0));
					
					
					
					if(!t.isTask(r)) return 0;
					if(pi) r.parent_id = pi;
					
					z = n.getElementsByTagName("task");/*_x.selectNodes(d,"task",n);*/
					
					for(x = 0;x<z.length;x++)
						t.importTaskFromXml(z[x],r);
					
					
					z = n.getElementsByTagName("depends");/*_x.selectNodes(d,"depends",n);*/
					for(x = 0;x<z.length;x++){
						if($E.IsAttributeSet(z[x],"rid")){
							t.addTaskDependency(p,z[x].getAttribute("rid"));
						}
					}
					
					if(b){
						/* _m.S("Auto-Execute task " + p.task_name,"200.1"); */
						t.executeTask(r);
					}
					
					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,f){
			var i = t.addTaskLoader(n,at,a,ht,h,f);
			t.executeTask(i);
		};

		t.addTaskLoader=function(n,at,a,ht,h,f){
			t.o.s.etl=0;
			t.o.s.etn = n;
			return t.addTask(n,at,a,ht,h,f);
		};

		t.addTask=function(n,at,a,ht,h,f){
			/*
				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
				f = dependency preprocessor
			*/
			var v,i,l,c;

			c=t.o;
			/*i = c.s.til + (++c.s.task_id_counter);*/
			i = c.s.til + (++$E.util.driver.ApplicationDriver.o.s.gc);
			if(D.TN( c.p.tasknames[n])){

				

				return 0;
			}

			l=c.p.tasks.length;
			if(!D.TS( h) && !D.TF( h)) h = 0;
			if(!h) ht=0;

			v = t.newTaskObject(n, at, a, ht, h, i, l, 0, f);
			/*_j.FN("task_object",n,at,a,ht,h,i,l,0,f);*/

			c.p.tasks[l]=v;
			c.p.tasknames[n]=l;
			c.p.taskindex[i]=l;
			
			v.transaction_id = _t.openTransaction(i,t,{id:i,name:n});
			
			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;

								

								t.EA(v,1);
							}
							else{
								/* _m.S("Delay task handler until dependencies are finished","200.1"); */
							}					
						}
						break;
					case _d.e:

						

						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:

						

						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(D.TO(z) && z != null){
										n = _x.getCDATAValue(z);
										if(o.processor) n = o.processor(o,v,z,n);
										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(D.TF(z)){
								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);
			}

			

			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(
					!D.TU(x.xdom)
				){
					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","2.1.1");*/
		$E.prepareObject("task_service","2.1.1",1,t);
		
		_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();



/*
	Engine Service
	Source: $E.engine
	Copyright 2002 - 2008. All Rights Reserved.
	Version: 2.1.1
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/projects/engine/
	License: http://www.whitefrost.com/projects/engine/code/engine.license.txt
	
*/


/*
	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}"
			}
*/

P("$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);
				}
				
				$E.xhtml.form.XHTMLFormComponent.removeForm(o.engine_id);

				o.eo = [];
				o.en = [];
				o.ei = [];
				
				
				o.engine_implementations = [];
				
				
				if(o.engine_element){
					
					
					
					_x.removeChildren(o.engine_element);
					if(o.engine_element.parentNode) 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;
				
				
			}
			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();

			

		};
		

		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.newEngineObject = function(e, i, n, k, x){
			var e = {
				engine_element:e,
				engine_id:i,
				engine_name:n,
				engine_index:x,
				config_name:0,
				task:k,
				is_primary:0,
				eo:[],
				en:[],
				ei:[],
				Processor:function(o,n){},
				XhtmlHandler:0,
				
				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;}

			};
			$E.prepareObject("engine_object","2.1.1",1,e);
			return e;

		};

		t.loadEngines=function(b, d, pr, xr){
			/*
				b = switch used to force load the primary engine
				d = optional context to search for the engines
			
				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 = (d ? d : document).getElementsByTagName("engine");
			for(i=0;i<q.length;i++){ m[m.length]=q[i]; }

			p = _x.queryNodes((d ? d : 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 = [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($E.IsAttributeSet(e,"name")){
						n = e.getAttribute("name");
					}
					else{
						e.setAttribute("name",n);
					}
					if($E.IsAttributeSet(e,"engine-id")){
						z = e.getAttribute("engine-id");
					}
					else{
						e.setAttribute("engine-id",z);
					}
				}

				if(t.getEngineByName(n)){
					
					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 && $E.IsAttributeSet(e,"engine-action")){
					a = e.getAttribute("engine-action");
				}
				else{
					a = _s[s + "a"];
				}
				if(!b && $E.IsAttributeSet(e,"engine-action-type")){
					at = e.getAttribute("engine-action-type");
				}
				else{
					at = _s[s + "at"];
				}
				if(!b && $E.IsAttributeSet(e,"engine-handler")){
					h = e.getAttribute("engine-handler");
				}
				else{
					h = _s[s + "h"];
				}
				if(!b && $E.IsAttributeSet(e,"engine-handler-type")){
					ht = e.getAttribute("engine-handler-type");
				}
				else{
					ht = _s[s + "ht"];
				}

				if(!b && $E.IsAttributeSet(e,"engine-config-task")){
					_s.pt = e.getAttribute("engine-config-task");
				}
				
				o = x(
					n,
					at,
					a,
					ht,
					h
				);

				l = _p.engines.length;
				
				v = t.newEngineObject((b?0:e),z,n,o,l);
				/*$E.FN("engine_object",(b?0:e),z,n,o,l);*/
				if(pr) v.Processor = pr;
				if(xr) v.XhtmlHandler = xr;

				/*
					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 = 0
			;
			
			if(typeof o == D.S) o = t.getEngine(o);
			if(typeof n != D.O || !t.isEngine(o)) return 0;
			
			if($E.IsAttributeSet(n,"rid"))
				r = n.getAttribute("rid");

			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;

					

				}

				

			}

			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);

			

			if(t.isEngine(o)){

				a = o.eo;
				for(i=a.length-1;i>=0;i--)
					_j.registry.ObjectRegistry.sendDestroyTo(a[i].object);
				
	            /*$E.xhtml.form.XHTMLFormComponent.removeForm(o.engine_id);*/
				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 && $E.IsAttributeSet(o.engine_element,"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){

						

						return 0;
					}
					o.config_name = c;

					

					t.PC(o,v,s);
					
					
					o.engine_implementations = [];
					
					
					_m.publish("onengineconfigload",o);

				}
				
			}
			

			
			
		};
		

		/*
		 * 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 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){
				_m.S("Page config for " + s + " not found.","200.4");
				return;
			}
			
			
			try{
			
			
				a = p.childNodes;
				nl = a.length;
				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){
						/*
						* 2008/02/07
						* Do not process nodes specifically marked for avoidance
						*
						*/
						if(n.getAttribute("avoid") == "1") continue;
						/*
						 * 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;

							
						}
						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){

								

								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";*/

									
									sf = 0;
									ck = 1;
								}

								if(cxp) cxp = t.PO(o,v,cxp,n,x,b,p,cs);




								if(z && (u = z.getAttribute("pid")) && Engine.PackageExists(u)){
									g = Engine.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($E.IsAttributeSet(m,"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 = $E.GetSpecifiedAttribute(n, "aid");
							
							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){

										

										w = g[f].apply(0,j);
									}
									else if(k && typeof x[f] == D.F){

										

										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(!w && ck && cn){
								k = document.createElement(cn);
								n.parentNode.appendChild(k);
								$E.xml.swapNode(k,n);
								
								
							}
							*/
							/* if use context parent */
							/*
							if(ck){
								
							}
							*/
							/* end if context parent*/
							
							l = o.eo.length;
							/*
								reuse q
							*/

							q = $E.GetSpecifiedAttribute(n, "rid");

							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;

									

								}

								

							}

							/*
								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.
							*/
							
							/*
							
								2008/11/04
								BUG BUG
								If the context switch parent (eg: import-xml) references an abstract,
								such as "html-fragment", the abstract needs to be swapped.
								
								Keep in mind caching rules must be considered. For example:
								
								<Template>
									<import-xml ...>[[EXTERN
										<html-fragment>
											<div>data</div>
										</html-fragment>]]
									</xml-xml>
								</Template>
							
							 * 
							 * 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);
									$E.xml.swapNode(k,n);
									n.parentNode.removeChild(n);
									
									

									/*
									if(typeof k.swapNode != D.U)
										
										k.swapNode(n);
										
										
									*/
									n = k;
								}
								if(!w.documentElement){
									
									o.Processor(o,w);
									if(!sf) _x.setInnerXHTML(n,w,0,(!ck ? v.data : 0),0,0,0,o.XhtmlHandler);
									
								}
								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;

									
									/*
									cx = n.getAttribute("acrid");
									k = 0;
									if(
										cx
										&&
										(q = $E.registry.ObjectRegistry.getObject(cx))
									){
										k = q._handle_xhtml_token;
										n = q.getTemplateContainer();
									}
									*/
									o.Processor(o,nr);
									if(!sf) _x.setInnerXHTML(n,nr,0,(!ck ? v.data : 0),0,0,0,o.XhtmlHandler);

								}
								/*
									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){
								
								o.Processor(o,n);
								if(!sf) _x.setInnerXHTML(x.getContainer(),n,true,0,0,0,0,o.XhtmlHandler);
							}
							
						}
					}
					else if(n.nodeType == 3){
						if(n.nodeValue.replace(/\s/g,"").length && typeof x == D.O && typeof x.getContainer == D.F){
								
							o.Processor(o,n);
							if(!sf) _x.setInnerXHTML(x.getContainer(),n,1,0,0,0,0,o.XhtmlHandler);
						}
						
					}

				} /* end for(i;childNodes.length) */
			
			}
			catch(e){
				_m.S("$E.engine.EngineService.PC Error: " +  (e.message ? e.message : e.description) ,"200.4");
				/* + "\n\n" + $E.error.traceRoute(t.PC) */
			}
			

			

		};
		/*
			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($E.IsAttributeSet(d,"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($E.IsAttributeSet(d, "value")){
							p[p.length] = d.getAttribute("value");
						}
					}
					z = p;				
					break;
				case "integer":
					z = parseInt(a);
					if(isNaN(z)) z = 0;
					break;
				case "node_name":
					if(up){
						z = e.parentNode.nodeName;
					}
					else{
						z = e.nodeName;
					}
					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:

					

					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;
			
			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);
				}

				

				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;
			
			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","2.1.1");
		_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.

*/

Engine.Package("$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",
			/* application component path to use */
			q:"appcomp_path"

		}
	},
	

	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)

			

			return 0;
			

		if(typeof q[r] == D.S)
			

			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);
		
		
		

		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.newObject("application_component","2.1.1");
		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 */
				tp:[]

				
				,ts:$E.token.TokenStack
				
/*
				mh:[]			
*/
			},
			s:{
				eic:1,
				edc:1,
				te:0,
				ei:0,
				/* 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,mouseup,mousedown,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._handle_xhtml_token = function(i,s){
            var r = s;

            if(i == 2 || i == 3){
				if(!r || !r.length || !r.match(/\$/)) return r;
	            
				r = r.replace(/\$\{this\}/g,"$E.registry.ObjectRegistry.getObject('" + n.i + "')");
				r = r.replace(/\$\{this\.id\}/g,n.i);

				if(typeof n.local_handle_xhtml_token == D.F) r = n.local_handle_xhtml_token(i,r);
			}
			else if(i == 1 && s.match(/^embedded-script$/i)) return 0;

            return r;
        };
		n.destroy = function(){
			var t = this, o,i;

			/* only do this once */
			if(t.r < 5){
				
				$E.message.MessageService.unsubscribe(this,"onengineconfigload","_handle_engineconfig_load");
				
				
				$E.message.MessageService.unsubscribe(t,"onloadxml","HLX");
				

				if(typeof t.component_destroy == D.F) t.component_destroy();
				t.cleanTemplate();
				
				t.r = 5;				
				
				if(typeof this.o.s.e == D.S && (o = $E.registry.ObjectRegistry.getObject(this.o.s.e)) && typeof o.destroy == D.F)
					o.destroy();
				
				var oE = this.getTemplateEngine();
				if(oE){
					$E.engine.EngineService.clearEngine(oE);
				}

				
				$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);
				
				/* cleanup p */
				for(i in t.o.p) t.o.p[i] = null;

			}
		};
		n.getTransactionName = function(){
			return this.o.s.tn;
		};

		
		
		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.post_init = function(o,i){
			if(typeof this.component_post_init == D.F) this.component_post_init();
		};


		n.setTemplateIsEngine = function(b){
			this.o.s.te = b;
		};

		n.getTemplateEngine = function(){
			var _s = this.o.s;
			if(!_s.te || !_s.ei) return 0;
			return $E.engine.EngineService.getEngine(_s.ei);
		};
		
		n.setBindingEnabled = function(b){
			this.o.s.b = b;
		};

		n.getBindingEnabled = function(){
			return this.o.s.b;
		};
		
		n.getDefinitionId = function(){
			return this.o.s.n;
		};

		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;
			$E.dom.event.addEventBuffer(t);
			this.createHandler("load_template",0,0,1);

				

			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){
				
				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();
			t.cleanTemplate();
			/*
				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){
			
			if(this.getReferenceId())
				_s.tn = this.getReferenceId();
			else
			
				_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){
	
				

				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._handle_template_processor = function(o,n){
			if(typeof n == D.O && n.nodeType == 1){
				this.importEmbeddedScript(n,1);
			}
		};
		n.importEmbeddedScript = function(oX,b){
			
		    var j,j2,a = oX.getElementsByTagName("embedded-script"), _p = this.o.p,i,t,x;
            for(i = a.length - 1; i >= 0 ; i--){
				t = $E.xml.getInnerText(a[i]);
				if(!b) a[i].parentNode.removeChild(a[i]);
				
				try{
				
					eval("x={" + t + "}");
					for(j in x){
						j2 = j;
						if(j2.match(/^embedded_init$/)){
							j2 = "embedded_init_" + this.o.s.eic++;
						}
						else if(j2.match(/^embedded_destroy$/)){
							j2 = "embedded_destroy_" + this.o.s.edc++;
						}
						_p.tp[_p.tp.length] = j2;
						this[j2] = x[j];
					}
				
				}
				catch(e){
					alert((e.description ? e.description : e.message));
				}
				
              
            }

		};
		n._handle_engineconfig_load = function(s, v){
			if(v && v.engine_element && v.engine_element.getAttribute("acrid") == this.i){
				this.o.s.ei = v.engine_id;
				this.InitializeTemplate();
			}
		};
		n.InitializeTemplate = function(){

            
            for(var i = 1; i < this.o.s.eic; i++){
				this["embedded_init_" + i]();
				this["embedded_init_" + i] = 0;
            }
            if(typeof this.template_init == D.F) this.template_init();
            this.template_init = 0;
            this.o.s.eic = 1;
            if(typeof this.local_template_init == D.F) this.local_template_init(this);
		};
        n._handle_load_template = function (s, v){
			if(v && v.xdom) this.loadTemplateFromNode(v.xdom.documentElement);
        };
        
        n.loadTemplateFromNode = function(oX){
			var a,o = this.getContainer(),x,i,t,_p = this.o.p,b = this.o.s.te,q,z;
			if(!oX) return;
			q = oX;
			z = this.o.s.tid;
			if(q.nodeName.match(/^Template$/) != null){
				if(z && q.getAttribute("id") != z) return;
			}
			else{
				a = oX.getElementsByTagName("Template");
				if(!a.length) return;
				if(!z) q = a[0];
				else{
					q = 0;
					for(i = 0; i < a.length; i++){
						if(a[i].getAttribute("id") == z){
							q = a[i];
							break;
						}
					}
					if(!q) return;
				}
			}
			
			this.o.s.tid = 0;

			if(typeof this.setTitle == D.F) this.setTitle(q.getAttribute("Title"));
			this.importEmbeddedScript(q);

            if(typeof this.getTemplateContainer == D.F) o = this.getTemplateContainer();
            
            $E.xml.removeChildren(o);
            
            a = q.childNodes;
            for(i = 0; i < a.length; )
				$E.xml.setInnerXHTML(o,a[i++], 1, 0, 0, 0, 0, this._handle_xhtml_token);
				
            if(b){
				o.setAttribute("engine-config","self");
				if(!this.o.s.ei){
					$E.message.MessageService.subscribe(this,"onengineconfigload","_handle_engineconfig_load");
					o.setAttribute("acrid",this.i);
					o.setAttribute("is-engine","1");
					this.createHandler("template_processor",0,0,1);
					$E.engine.EngineService.loadEngines(0,o.parentNode,this._prehandle_template_processor, this._handle_xhtml_token);
				}
				else{
					x = $E.engine.EngineService.getEngine(this.o.s.ei);
					$E.engine.EngineService.applyConfiguration(x,"self");
				}
            }
            else
				this.InitializeTemplate();
        };
        
        n.getTemplateObjectByName = function(i){
			var e = this.getTemplateEngine(),o;
			if(!e) return 0;
			o = e.getObjectByName(i);
			if(!o || !o.object || !o.object.getContainer) return 0;
			return o.object.getContainer();
        };
        





        n.loadTemplate = function(s, i){
            if(!s || !s.length) return;
			this.cleanTemplate();
			if(i) this.o.s.tid = i;
            $E.xml.getXml(s,this._prehandle_load_template,1);      
        };
        n.cleanTemplate = function(){
            var _p = this.o.p,i;
            if(typeof this.template_destroy == D.F) this.template_destroy();
            this.template_destroy = 0;
			for(i=1; i< this.o.s.edc; i++){
				this["embedded_destroy_" + i]();
				this["embedded_destroy_" + i] = 0;
			}
			this.o.s.edc = 1;

            for(i=0; i < _p.tp.length; ){
				if(_p.tp[i++]) this[_p.tp[i++]] = null;
            }
            _p.tp = [];

        };

		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);

			

			return 0;
		};
		
		n.startTransaction=function(s,p){
			/*
				s = service
				p = packet
			*/
			var
				
				t=this;
				
			if(typeof t._handle_begin_transaction == D.F) t._handle_begin_transaction(s,p);
				
			

			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);
 
 			

			return 1;
		};

		

		
		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();
		};
		
		n.getContainerComponentId = function(){
			var c = $E.registry.ObjectRegistry.getObject(this.getContainerId());
			/* c = XHTLM Component */
			if(!c) return 0;
			/* ComponentId = Object ID or specified id */
			return c.getComponentId();
		};
		

		
		
		/*
			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.
*/

Engine.Package("$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 && D.TO(xn)) hp = document;
		if(!cid){
			/* Typeof Unknown won't work with this */
			/* !D.TU(xn.getAttribute) */
			if(xn.nodeType == 1 && typeof xn.getAttribute != D.U){
				cid = xn.getAttribute("id");
				if(cid == null || cid.length == 0) cid = xn.getAttribute("name");
				if(cid == null || cid.length == 0) cid = 0;
			}
			else
				cid = 0;
		}
		if(!cc) cc =0;
		if(D.TS(cc)) cc = Engine.GetPackage(cc);

		
		var n = $E.FN("base_object","xhtml_component","2.1.1");
	
		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,
				/* linked component bit */
				lcp:0
/*
				vp:0
*/
			}
		};
		n.getComponentCollection = function(){
			return this.o.p.cc;
		};
		n.getIsComponentLinked = function(){
			return this.o.s.lcp;
		};
		/* 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.getComponentId=function(){
			return this.o.s.cid;
		};

		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 && (!_s.cf || _s.cf != "self"))
					
					_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,
				_dw = $E.dwac.DistributedComponent
			;
			if(D.TO( hp) && D.TO(xn) && (!_s.cf || _s.cf != "self")){
				
				o = $E.xml.setInnerXHTML(hp,xn,1,0,1);
			}
			else if(D.TO(xn)){
				o = xn;
			}
			else{
				
				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 if( (a = o.getAttribute(_ac.o.s.q)) && a.length > 0){
					dp = a;
				}
				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){

					
					/*
					_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");
				}
				
			}
			else if( (i = o.getAttribute(_dw.atkey)) != null && i.length > 0){
				_p.a = _dw.newInstance(t, o.getAttribute(_dw.aturi), o.getAttribute(_dw.attid), o.getAttribute(_dw.attk));
			}
			
			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 && D.TF(_p.cc.addComponent) && _p.cc.addComponent(this,_s.rid)) _s.lcp = 1;
			/* drop the collection pointer if it's not used */
			else _p.cc = 0;
			
			
			if(_p.a && D.TF(_p.a.post_init)) _p.a.post_init(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.
*/

Engine.Package("$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(
					!D.TS(pid) || !pid.length
					||
					!D.TS(vt) || !vt.length
				){
					alert("Invalid pattern id ('" + pid + "') or validation-type ('" + vt + "')");
					continue;
				}
				if(!D.TU(p[pid])){
					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:(D.TS(vc) && vc.match(/^1|true$/i))?true:false,
					an:(D.TS(an) && 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;

				

				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(!D.TO(o) && !D.TS(o)){
				return "Invalid field reference";
			}	
		
			if(D.TS(o)) i = o;
			else i = o.getAttribute("pattern-id");
		
			if(!i){
				return "Field doesn't define a validation pattern id";
			}
			
			p =  _p.p[i];
			if(!D.TO(p)){
				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(!D.TO(o)){
				_m.S("Invalid field reference in validateField.","200.4",1);
				return 0;
			}
			
			if(D.TS(i)) 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(!D.TO(po)){
				_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(D.TN(v) && v == 0){
				return 1;
			}
		
			if(po.mp){
				try{
					re = new RegExp(po.mp);
					switch(po.vt){
						case "replace":
							r = 1;
							if(D.TS(po.rp)){
								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","2.1.1");
		$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.
*/

Engine.Package("$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(D.TU( fi)) fi = t.o.s.l;
			
			var f = t.getFormByName(fi), a, r = [], c = 0,i;
			if(!f)
				

				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(D.TU( fi)) fi = t.o.s.l;

			f = t.getFormByName(fi);
			if(!f)
				

				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(D.TU( fi == D.U)) fi = t.o.s.l;
			f = t.getFormByName(fi);

			if(f) return f.getElementByName(n);

			

			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(!D.TO( o.v))
					return o.v;
				
				else
					return o.v.value;
				
			}

			

			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(D.TO( o.v) && D.TN( o.v.i) && 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(D.TO( o.v) && D.TN( o.v.i) && y.getItemSize() > o.v.i){
									y.selectItem(o.v.i);
								}
							}
						}
						break;
					
					default:
						
						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;
				}

								
				
			}

			
		};

		t.removeForm = function(v){
			var o, _p = this.o.p, i = 0, e, _f;
			if(D.TO(v)) o = v;
			else if(D.TS(v)) o = t.getFormByName(v);
			if(!o) return 0;
			_f = o.o.p;
			
			_p.forms[o.x] = 0;
			_p.formindex[o.i] = 0;
			_p.formnames[o.n] = 0;
			
			_f.elementindex = 0;
			_f.elementnames = 0;
			for(; i < _f.elements.length; ){
				e = _f.elements[i++];

				e.v = 0;
				e.d = 0;
				e.e = 0;
				
			}
			
			_f.elements = [];
			
			return 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,b = 0;
			if(o && o.t && o.t.match(/xhtml_component/) && o.o.s.cid){
				if(!D.TS(ri)) ri = _s.l;
				if(! (f = t.getFormByName(ri)) ){
					f = {
						i:ri,
						x:0,
						n:0,
						/* 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;
					f.x = l;
					f.n = _s.l + "-" + 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,
						getType:function(){return this.t},
						getIsRendered:function(){return this.r},
						getName:function(){return this.n},
						getValue:function(){return this.v},
						getObjectId:function(){return this.oid},
						getElement:function(){return this.e},
						getReferenceId:function(){return this.f}
					};

					_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;
					
					b = 1;

					
				}
				else{
					t.synchronizeComponent(o,1);

					

				}
			}

			
			return b;
		};
		
		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(D.TO(n)){
				o = n;
				if(!D.TU(o.getAttribute)) 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){
			
				
				
				return o.vd;
			
			}

			if((!w && !o.vp) || !Engine.PackageExists("$E.xhtml.validator")){

				

				return 1;
			}

			/* use 'w' in preference over the specified pattern */
			if(!D.TS(w)) 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()){

				

				return 0;
			}
			
			r = v.validateField(o.e,w);
			if(!r){
				_m.S("Validation Error: " + v.getValidationErrorText(w),"200.4");
			}

			

			o.vd = r;
			return r;

		};
		
		$E.IM(t,"base_object","xhtml_form","2.1.1");
		$E.registry.ObjectRegistry.addObject(t);
		t.r = 4;

/*		_j.object.IOA(t,"element");*/
		_j.object.IOA(t,"form");
/*		_j.object.IOA(t,"formnames");*/
	}
}
$E.xhtml.form.XHTMLFormComponent=new $E.xhtml.form.XHTMLFormComponentImpl();



/*
	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.
*/

Engine.Package("$E");

$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(!D.TS(n)) 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(D.TU(_p.tn[n])) _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(!D.TO(_p.tn[n])) 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(!D.TO(_p.tn[n])) return 0;
			a = _p.tn[n];
			if(!D.TN(z)) z = 0;
			if(z < 0 || z >= a.length) return 0;
			
			for(;z < a.length; z++){
				if(D.TN(a[z]) && 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(!D.TO(_p.tn[n])) return 0;
			a = _p.tn[n];
			for(; i < a.length;i++){
				z = a[i];
				/* typeof _p.t[z] != D.O){*/
				if(!D.TN(z) || z < 0 || z > _p.t.length  || D.TU(_p.t[z])){
					$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(!D.TO(_p.t[i]))
					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(!D.TO(_p.tn[n])){
				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(!D.TN(z) || z < 0 || z > _p.t.length || !D.TO(_p.t[z])){
					continue;
				}
				y = _p.t[z];
				if(y.owner_id == o.i){
					ti = y.index;
					_p.tn[n][i] = -1;
					break;
				}
			}
			if(D.TO(_p.t[ti])) _p.t[ti] = 0;
			
		};
		
		t.CO = function(o, n){
			return (D.TO(this.getTokenByOwner(n, o)) ? 1 : 0);
/*			return (this.getTokenByOwner(n, o) ? 1 : 0);*/
		};

		$E.IM(t,"base_object","token_ring","2.1.1");
		$E.registry.ObjectRegistry.addObject(t);
	}
}

$E.token.TokenStack = new $E.token.TokenStackImpl();


/*
	Raccoon Customer Experience Monitor
	Development version.
	Copyright 2005, All Rights Reserved.
	
	Using Engine for Web Applications framework.
	Copyright 2002 - 2005, All Rights Reserved.
			
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
*/


Engine.Package("$E.monitor");

$E.monitor = {
	MonitorService:null,
	MonitorServiceImpl:function(){
		var t = this;
		t.t = "MonitorService";
		t.v = "2.1.1";
		t.i = "monitor_service_1";
		t.r = 0;
		


		
		
		

		t.o = {
			p:{
				monitors:[],
				context_object:0
			},
			cookies:{
			
			},
			s:{
				/*
					1 = uninitialized
					2 = window not loaded
					3 = window loaded
					4 = window before unload
					5 = window unload
				*/
				ci:0,
				delay:1000,
				session_name:"MONITOR_SESSION_ID",
				document_rendered:0,
				hashed_cookies:0,
				window_interval:0,
				can_interval:1,
				window_state:0,
				application_id:0,
				dataset_id:0,
				last_image_index:0
			}
		};  /* end o */
		
		t.getContextObject = function(){
			return t.o.p.context_object;
		};

		t.getDatasetId = function(){
			return t.o.s.dataset_id;
		};
		
		t.getDocumentRendered = function(){
			return t.o.s.document_rendered;
		};
		
		t.getWindowState = function(){
			return t.o.s.window_state;
		};

		t.getSessionId = function(){
			return t.o.cookies[t.o.s.session_name];
		};

		t.getApplicationId = function(){
			return t.o.s.application_id;
		};

		t.getContextId = function(){
			return t.o.s.ci;
		};

		t.hashCookie = function(n,b,s){
			var c = t.o.s, k = t.o.cookies;
		   	if(!c.hashed_cookies++ || s)
				t.hashValue(document.cookie, ";", "=", k);
	
			/*
				Hash a specific cookie value
				This will take a sub-hash from a cookie and move the values
				up one level.
			*/
			if(b && D.TS(k[n]))
			    t.hashValue(k[n], "&", ":", k);
		};

		t.hashValue=function(c, d, s, k){
			if (c) {
				var j=0,
					l,
					a = c.split(d),
					f = eval("/\\s*([^\\s" + s + "]+)" + s + "(.+)\\s*/")
				;
				for (; a && j < a.length;) {
					l = a[j++].match(f);
					if (l)
						k[l[1]] = l[2].match(/^\d+$/) ? parseInt(l[2]) : l[2];  /* use this to convert all #s to actual # objects*/
		        }
    		}
		};

		t.absorb = function(a,b){
			var i = 0, l = a.length;
			for(;i<l;)
				b[b.length] = a[i++];
			
			
		};
		
		
		t.G = function(n){

			return t.o.p.context_object.getElementsByTagName(n);

		};
		
		t.doInterval = function(){
		
			var m = t.o.p.monitors,c = t.o.s,i=0,l,o,z;
			l = m.length;
			for(;i < l;){
				o = m[i++];
				z = o.o.s;
				if(D.TF(o.doInterval) && z.can_interval){
					if(z.interval_offset <= 0) z.interval_offset = 1;
					z.interval_offset--;
					/* individual monitors can override the interval offset to increase the delay between invocation */
					/*
						only invoke the interal if the offset is 0.
						the monitor is responsible for bumping it back up if a delay is desired
					*/
					if(z.interval_offset <= 0) o.doInterval();
				}
			}
			c.window_interval = window.setTimeout(t.handle_window_interval,c.delay);
			return 1;
		};

		t.handle_window_interval=function(){
			var c = t.o.s;
	
			/* if unloading */
			if(c.window_state > 3){
				window.clearTimeout(c.window_interval);
				c.window_interval = 0;
				return;
			}
			if(!c.can_interval) return;
	
			if(c.can_interval)
				if(!t.doInterval()){
					window.clearTimeout(c.window_interval);
					c.window_interval = 0;
					c.can_interval = 0;		
				}
		};
		
		t.handle_document_stop = function(e){
			t.DE("document_stop",e);
		};
		
		t.handle_window_load = function(e){
			var c = t.o.s;
			if(c.window_state >= 3) return;
			t.BE();
			c.window_state = 3;
			c.document_rendered = 1;
			t.DE("window_load",e);

		};
		
		t.handle_window_beforeunload = function(e){
			t.DE("window_beforeunload",e);
			t.o.s.window_state = 4;
			/*t.o.s.document_rendered = 0;*/
		};		

		t.handle_window_unload = function(e){

			var c = t.o.s;

			/* Validate the current context */
			/* don't try using D here because it may not be loaded anymore */
			if(!Engine || typeof Engine.PackageExists != "function") return;
			if(t.r == 4){
				
				t.r = 4.5;
				c.window_state = 5;
				t.DE("window_unload",e);
				c.document_rendered = 0;
			}				
			/* end action */
			t.r = 5;

		};

		t.DE = function(s, e, p2, p3){
			/*
				s = event key (eg: window_load)
				e = event object
			*/
			var m = t.o.p.monitors,i=0,l,o,n;
			n = "handle_" + s;
			l = m.length;
			for(;i < l;){
				o = m[i++];
				/* use string for datatype; the object may no longer be defined */
				if(o && typeof o[n] == "function")
					o[n](e,p2,p3);
				
			}
		};
		
		t.initializeMonitorService = function(){
			if(t.r) return 0;
			var 
			_a = $E.dom.event.addEventListener,
			d = document, w = window, f = false,c = t.o.s,o = t.o.cookies, p = t.o.p;
			t.r = 2;
			/*
			if(!$E.xml.testXmlHttpObject()){
				// Don't bother enabling monitor for anything that doesn't support XMLHTTP
				return 0;
			}
			*/
			/* don't use shorthand for typecheck because the variable isn't named in this scope */
			c.application_id = (typeof APPLICATION_ID != D.U)?APPLICATION_ID:"Global";
			c.dataset_id = (typeof DATASET_ID != D.U ? DATASET_ID :  "public");
			p.context_object = (typeof CONTEXT_OBJECT != D.U ? CONTEXT_OBJECT : document);
			
			/* Hash-up the cookies */
			t.hashCookie();
			
			c.ci = $E.guid();
			
			/* Create Session ID if needed */
			if(!o[c.session_name]){
				o[c.session_name] = c.ci;
				document.cookie=c.session_name + "=" + o[c.session_name] + ";";
			}
			
			_a(d,"stop",t.handle_document_stop,f);

			_a(w,"load",t.handle_window_load,f);
			_a(w,"unload",t.handle_window_unload,f);
			_a(w,"beforeunload",t.handle_window_beforeunload,f);
			
			/* reuse o */
			o = p.context_object;
			if(o == d) o = d.documentElement;
			_a(o,"contextmenu",t.handle_context_menu,f);
			_a(o,"mousemove",t.handle_mouse_move,f);
			_a(o,"click",t.handle_mouse_click,f);
			_a(o,"scroll",t.handle_document_scroll,f);
			_a(w,"focus",t.handle_window_focus,f);
			_a(w,"blur",t.handle_window_blur,f);
			_a(w,"keydown",t.handle_window_keydown,f);
			_a(w,"resize",t.handle_window_resize,f);

			if(w.onerror) w.ph_error = w.onerror;
			w.onerror = t.handle_window_error;
			
			
			t.ImageProbe();
			
			
			t.r = 4;
			
			t.doInterval();

		};
		
		t.handle_context_menu = function(e){
			t.DE("context_menu",e);
		};

		t.handle_window_error = function(m,u,l){
			t.DE("window_error",m,u,l);
			if(typeof window.ph_error == D.F)
				return window.ph_error.apply(window,arguments);
		};

		t.handle_mouse_click = function(e){
			t.DE("mouse_click",e);
		};
		
		t.handle_mouse_move = function(e){
			t.DE("mouse_move",e);
		};

		t.handle_document_scroll = function(e){
			t.DE("document_scroll",e);
		};

		t.handle_window_focus = function(e){
			t.DE("window_focus",e);
		};

		t.handle_window_blur = function(e){
			t.DE("window_blur",e);
		};

		t.handle_input_focus = function(e){
			t.DE("input_focus",e);
		};

		t.handle_input_blur = function(e){
			t.DE("input_blur",e);
		};

		t.handle_window_keydown = function(e){
			t.DE("window_keydown",e);
		};

		t.handle_window_resize = function(e){
			t.DE("window_resize",e);
		};

		t.handle_form_submit = function(e){
			t.DE("form_submit",e);
			var oF = $E.dom.event._gevt_src(e);
			if(oF && oF.nodeType == 1 && typeof oF.ph_submit == D.F)
				return oF.ph_submit.apply(oF,arguments);
		};

		t.handle_form_reset = function(e){
			t.DE("form_reset",e);
			var oF = $E.dom.event._gevt_src(e);
			if(oF && oF.nodeType == 1 && typeof oF.ph_reset == D.F)
				return oF.ph_reset.apply(oF,arguments);
		};


		t.handle_select_change = function(e){
			t.DE("select_change",e);
		};		

		t.BE = function(){
			var a = [],i,o,
				f = $E.dom.event.addEventListener,
				mc = t.handle_mouse_click,
				hs = t.handle_form_submit,
				hr = t.handle_form_reset,
				hc = t.handle_select_change,
				uf = t.handle_input_focus,
				ub = t.handle_input_blur
			;

			t.absorb(t.G("form"),a);
			t.absorb(t.G("a"),a);
			t.absorb(t.G("input"),a);
			t.absorb(t.G("area"),a);
			t.absorb(t.G("select"),a);
			t.absorb(t.G("textarea"),a);
			
			for(i=0;i<a.length;i++){

				o = a[i];

				if(!o.nodeName.match(/select/i)){
					f(o,"click",mc);
					f(o,"focus",uf);
					f(o,"blur",ub);
					f(o,"keydown",ub);
				}
				if(o.nodeName.match(/form/i)){

					if(o.onsubmit) o.ph_submit = o.onsubmit;
					o.onsubmit = hs;

					if(o.onreset) o.ph_onreset = o.onreset;
					o.onreset = hr;
				}
				else if(o.nodeName.match(/select/i)){
					f(o,"click",hc);
					f(o,"change",hc);
					f(o,"focus",hc);
					f(o,"blur",hc);
					f(o,"keydown",hc);
				}
			}
			
		};
		t.removeMonitor = function(o){
			var m = t.o.p.monitors,i = 0, b = 0;
			if(!o) return 0;
			for(; i < m.length; i++){
				if(m[i].getObjectId() == o.getObjectId()){
					m[i] = 0;
					b = 1;
				}
			}
			return b;
		};

		t.addMonitor = function(o,c){
			var m = t.o.p.monitors,r = $E.registry.ObjectRegistry;
			if(
				!D.TO(o)
				||
				o == null
				||
				r.isRegistered(o) == false
				||
				!D.TF(o.initializeMonitor)
			) return 0;

			
			if(!o.o.config_keys) o.o.config_keys = {};
			if(D.TO(o.o.config_keys) && D.TS(c))
				t.hashValue(c, "&", ":", o.o.config_keys);

			o.getConfigKeys = function(){return o.o.config_keys};
			o.getConfigKey = function(n){return o.o.config_keys[n];};			
			o.getMonitorService = function(){return t;};
			o.o.s.can_interval = 1;
			o.o.s.interval_offset = 0;

			if(o.initializeMonitor()){
				m[m.length] = o;
				return 1;
			}
			return 0;
			
		};

	    t.handle_image_load=function(e){
	        t.DE("image_load",e);
	    };
	    t.handle_image_abort=function(e){
	        t.DE("image_abort",e);
	    };
	    t.handle_image_error=function(e){
	        t.DE("image_error",e);
	    };

	    t.ImageProbe=function(){
	        var _a = $E.dom.event.addEventListener, _s = t.o.s,i,_i = document.images,l;
	        if(t.r > 4 || !_i) return;
	        l = _i.length;

	        for(i = _s.last_image_index; i < l; i++){
	            _i[i].onload = t.handle_image_load;
	            _i[i].onabort = t.handle_image_abort;
	            _i[i].onerror = t.handle_image_error;
	            
	            _i[i]._ix = i;
	        }
	        _s.last_image_index = l;
	        if(!_s.document_rendered) window.setTimeout(t.ImageProbe,10);
	    };
		$E.IM(t,"base_object","monitor_service","2.1.1");
		$E.registry.ObjectRegistry.addObject(t);
		$E.dom.event.addEventBuffer(t);
		/* t.createHandler('xml_post',0,0,1); */
		t.initializeMonitorService();
	
	}


	
};

$E.monitor.MonitorService = new $E.monitor.MonitorServiceImpl();



/*
	Wide Select Control
	Source: $E.ui.wideselect
	Copyright 2002 - 2008. All Rights Reserved.
	Version: 2.1.1
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/projects/engine/
	License: http://www.whitefrost.com/projects/engine/code/engine.license.txt
	
*/

/*

	Page Hashing
		keep a hash of ids for paged items so as to compare which items may or may not be currently in use.
		This was designed for using WideSelect as a transfer control where a data item may exist for some period of time within another field.
*/

/*
	Value Constructs
		Item Construct
			Each item in the visible or paged list has the following structure:

			v = {
				name:"{name}",
				data:"{value data}",
				id:"{unique item id}",
				index:"{item index}"
			}
		
		Paged Construct
			Paged items are stored internally in the following structure:
			v = {
				name:"{name}",
				data:"{value data | data construct}",
			}
			This value shouldn't need to be exposed anywhere.
			
			
		Paged Data Construct
			When items are paged, the following construct is loosely enforced as the
			value.  The purpose for this construct is to include the relevant data items
			for the label, an item id, and value.
			Although this means the label is used twice in the pageItem invocation, it also
			allows the single contstruct to be used in an array for importPageItems.
			
			v = {
				label:"{name}",
				id:"{id}",
				value:"{value}"
			}
		
*/


Engine.Package("$E.ui");


$E.ui.wideselect={
	newInstance:function(o, h, ph){
		/*
			o = object parent
			h = optional onclick handler
			ph = optional page navigate handler
		*/


		
		
		
		



		
		var n = $E.newObject("wideselect","2.1.1");		

		if(!D.TO(o)) o = document.body;
		
		n.o = {
			p:{
				/* parent_object */
				p:o,
				/* c = container  */
				c:0,
				/* b = buffer */
				b:[],
				/* r = results */
				r:[],
				/* rh = results hash */
				rh:[],
				/* h = optional click handler */
				h:h,
				/* ph = optional page navigate handler */
				ph:ph,
				a:null,
				v:[],

				/* g = pages */
				g:[],
				/* s = pages_hash */
				s:[],
				qr:[],
				qo:0
			},
			s:{
				/* m = buffer mark */
				m:0,
				buffered:1,
				auto_commit:1,
				is_commit:0,
				buffer_delay:20,
				buffer_step:10,

				auto_scroll:0,
				auto_select:0,
				maximum_items:100,
				maximum_rollover:1,
				item_id_counter:0,
				multiple:0,

				/* is paging enabled */
				is_paging:0,
				/* current page in the series */
				current_page:0,
				/* known maximum page count */
				maximum_page_size:0,
				/* max items per page */
				maximum_page_items:9,
				/* a marker used while paging data */
				page_marker:0,
				/* marker used to note that no more data was returned */
				page_stop:0,
				/* whash up the paged values */
				page_hashing:1,
				is_requested:0,
				can_request:0,
				
				cc:"wideselect_container",
				class_item:"wideselect_item",
				class_item_blocked:"wideselect_item_blocked",
				class_item_hover:"wideselect_item_hover",
				class_item_active:"wideselect_item_active"
			}
		};
		
		n.setMultiple = function(b){
			this.o.s.multiple=(b?1:0);
			this.deselectAllItems();
		};
		
		n.getMultiple = function(){
			return (this.o.s.multiple?true:false);
		};
		
		n.setMaximumItems = function(i){
			this.o.s.maximum_items = i;
		};
		
		n.getMaximumItems = function(){
			return this.o.s.maximum_items;
		};
		
		n.setMaximumPageItems = function(i){
			this.o.s.maximum_page_items = i;
		};
		
		n.getMaximumPageItems = function(){
			return this.o.s.maximum_page_items;
		};
		
		n.getCurrentPageItemCount = function(){
			var t = this, _p, _s;
			_p = t.o.p;
			_s = t.o.s;
			if(!D.TO(_p.g[_s.current_page])) _p.g[_s.current_page] = [];
			return _p.g[_s.current_page].length;
		};
		
		n.getContainer = function(){
			return this.o.p.c;
		};

		n.getBufferMark=function(){
			return this.o.s.m;
		};
		
		n.setResultHandler=function(f){
			this.o.p.h = f;
		};

		n.getBufferSize=function(){
			return this.o.p.b.length;
		};
		
		n.getItemSize=function(){
			return this.o.p.r.length;
		};
		
		n.getItems = function(){
			return this.o.p.r;
		};
		
		n.getItem=function(i){
			return this.o.p.r[i];
		};
		
		n.getActiveItem=function(){
			var c=this.o;
			if(c.p.a){
				return c.p.r[c.p.rh[c.p.a.getAttribute("rid")]]
			}
			return null;
		};

		n.setCanRequest = function(b){
			this.o.s.can_request = b;
		};

		n.setIsPaging = function(i){
			this.o.s.is_paging = (i?1:0);
			this.clearPagingValues();
		};

		n.getIsPaging = function(){
			return this.o.s.is_paging;
		};

		n.setPageStop = function(b){
			this.o.s.page_stop = (b?1:0);
		};
		
		n.getPageStop = function(){
			return this.o.s.page_stop;
		};
		
		n.setAutoCommit = function(b){
			this.o.s.auto_commit = b;
		};
		
		n.setAutoScroll = function(b){
			this.o.s.auto_scroll = b;
		};

		n.setAutoSelect = function(b){
			this.o.s.auto_select = b;
		};

		n.setMaximumRollover = function(b){
			this.o.s.maximum_rollover = b;
		};

		n.deselectAllItems = function(){
			var a, _p = this.o.p,i=0,l;
			a = _p.r;
			l = a.length;
			_p.v = [];
			_p.a = null;
			for(;i<l;i++){
				a[i].object.className = this.o.s.class_item;
			}
		};

		n.init=function(){
			var t=this,v,d,_m=$E.message.MessageService,_d=$E.dom.event,c,_p;

			c = t.o;
			_p = c.p;

			d = document.createElement("div");
			_p.p.appendChild(d);
			d.className = t.o.s.cc;
			
			_d.addEventBuffer(t);

			/*
			buffer_check is not used with the eventfactory
			but the handler is used to retrieve a pointer from the anonymous call
			of a timeout.
			
			 Yet another case where a probe would be nice.
			*/
			t.createHandler("buffer_check",0,0,1);
			t.createHandler("commit_buffer",0,0,1);

			t.createHandler("mouseover",0,0,1);
			t.createHandler("mouseout",0,0,1);
			t.createHandler("click",0,0,1);			

			_d.addEventListener(d,"mouseover",t._prehandle_mouseover,0);
			_d.addEventListener(d,"mouseout",t._prehandle_mouseout,0);
			_d.addEventListener(d,"click",t._prehandle_click,0);

			_m.subscribe(t,"destroy","HWD",window);
			/*_m.subscribe(t,"_buffer_updated","_handle_buffer_updated",t);*/

			_p.c = d;

			t.r = 4;

		};
		
		n.HWD=function(){
			this.destroy();
		};
/*		
		n.setMaximumItems=function(i){
			if(typeof i == "number" && i >= 0){
				this.o.s.maximum_items = i;
			}
		};
*/	
		n.setIsBuffered=function(b){
			var t=this,c;
			c=t.o;
			c.s.buffered=b;
			c.s.m=0;
			c.p.b=[];
		};
		
		n.setBufferOffset=function(i){
			this.o.s.buffer_step=i;
		};
		
		n.setBufferDelay=function(i){
			this.o.s.buffer_delay=i;
		};

		n.destroy=function(){
			var t=this,c_p;
			c=t.o;
			_p = c.p;
			if(t.r == 4){
				t.clearItems();
				_p.b=[];
				_p.p.removeChild(_p.c);
				$E.registry.ObjectRegistry.removeObject(t);
			}
			t.r = 0;
		};

		n.addItem=function(s,d){
			var t=this,c,_p;
			c=t.o;
			_p = c.p;
			if(t.r != 4) return;
			if(c.s.buffered){
				_p.b[_p.b.length]={name:s,data:d};

				if(c.s.auto_commit && !c.s.is_commit){
				
					/* this should be a probe */
					window.setTimeout(t._prehandle_buffer_check,c.s.buffer_delay);
					/* t.commitBuffer();*/
				}
			}
			else{
				t._addItem(s,d);
			}
		};
		
		n._handle_buffer_check=function(){
			var t=this,c;
			c=t.o;
			if(c.s.auto_commit && !c.s.is_commit){
				t._handle_commit_buffer();
			}
		};
		
		n.commitBuffer=function(){
			this._handle_commit_buffer();
		};
		
		n._handle_commit_buffer=function(){
			var t=this,c,l,b,m,i,v,_p;
			c = t.o;
			_p = c.p;
			c.s.is_commit=1;
			
			l=_p.b.length;
			b = false;
			m = c.s.m;
			for(i=m;i< (m + c.s.buffer_step) ;i++){
				if(i >= l){
					b=true;
					break;
				}
				v=_p.b[i];
				t._addItem(v.name,v.data);
				c.s.m++;
			}
			if(b){
				c.s.m=0;
				_p.b = [];
				c.s.is_commit=0;
				$E.message.MessageService.publish("onbuffercommitted",t);
			}
			else{
				window.setTimeout(t._prehandle_commit_buffer,c.s.buffer_delay);
			}
		};
		
		n.pageItem = function(s,d){
			var t = this, _p, _s, page_size, l, v = {name:s,data:d};
			_p = t.o.p;
			_s = t.o.s;
			page_size = _s.maximum_page_size;

			if(_s.is_paging){
		
				
				if(!D.TO(_p.g[page_size])) _p.g[page_size] = [];
				
				l = _p.g[page_size].length;
		
				if(l >= _s.maximum_page_items){
					page_size = (++_s.maximum_page_size);
					if(!D.TO(_p.g[page_size])) _p.g[page_size] = [];
					l = _p.g[page_size].length;
				}
		
				/* if page hashing is enabled, record this new id */
				if(_s.page_hashing) _p.s[d.id]=1;
		
		
				_p.g[page_size][l] = v;

			}
		};
		
		n.updatePage = function(){
			var t = this,
				_p = this.o.p,
				_s = this.o.s,
				a,
				b,
				i,
				p,
				c,
				o
/*				_m = $E.message.MessageService;*/
			;
		
			if(!_s.is_paging) return 0;
		
			c = _s.current_page;
			p = _s.maximum_page_size;





/*
			if(_s.page_stop)
				_m.S("Page " + (c + 1) + " of " + (p + 1),"200.1");
*/
				/*_p.btn_paging_ctrs_label.innerText = "Page " + (c+1) + " of " + (p + 1);*/
			
/*
			else
				_m.S("Page " + (c + 1) + " of n","200.1");
*/
				/*_p.btn_paging_ctrs_label.innerText = "Page " + (c+1) + " of n";*/
	
		
			t.clearItems();
			
			if(D.TO(_p.g[c])){
				for(i = 0; i < _p.g[c].length; i++){
					o = _p.g[c][i];
					if(_s.page_hashing && o.data && o.data.id && _p.qr[o.data.id])
						_p.s[o.data.id]=0;
						
		
					t.addItem(o.name, o.data);
				}
				/*
				if(t.getCanMoveNext()) t.addItem("more ...","_more");
				*/
			}
			else{
				t.addItem("Paging Error at Page #" + c,"_avoid");
			}
			/*_synchronize_result_options();*/
		};

		n._addItem=function(s,d){
			var t=this,e,i=$E.GG(),v,l,_p,_s;
			_s = t.o.s;
			_p = t.o.p;
			l = _p.r.length;
			
			if(
				_s.maximum_items > 0
				&& l >= _s.maximum_items
			){
				if(_s.maximum_rollover){
					t.clearItem(0);
					l--;
				}
				else{
					return;
				}
			}
			
			e = document.createElement("div");
		
			_p.c.appendChild(e);
			e.className = _s.class_item;

			if(
				(D.TS(d) && d != "_avoid")
				||
				(D.TO(d) && d.value != "_avoid")
			){
				e.setAttribute("is-result-item","1");
			}

			e.setAttribute("rid",i);
			/*e.appendChild(document.createTextNode(s));*/

			/* At the moment, wide select assumes and node references specified as the label are HTML nodes (the 7th param; 1)*/
			$E.xml.setInnerXHTML(e,s,0,0,0,0,1);


			v={
				name:s,
				data:d,
				object:e,
				id:i,
				index:l
			};
			
			_p.r[l] = v;
			_p.rh[i] =l;
			
			if(_s.auto_select) t.setActiveItem(l);
			if(_s.auto_scroll) t.scrollToItem(l);
		};

		n._handle_mouseover=function(v){
			var t=this,o,e,_p,_s, l;
			_s = t.o.s;
			_p = t.o.p;

			if(D.TN(v))
				o=_p.r[v].object;
			
			else{
				e=$E.dom.event._gevt(v);
				o=(!D.TU(v) && v.nodeType)?v:$E.dom.event._gevt_src(v);
				if(o && o.nodeType==3) o=o.parentNode;
				l = o;
				while(l){
					/* don't use shorthand for .getAttribute or it will throw an error */
				 	if(typeof l.getAttribute != D.U && l.getAttribute("is-result-item")){
						o = l;
						break;
					}
					l = l.parentNode;
				}
			}
			if(
				o.getAttribute("is-result-item")
				&&
				((
					_s.multiple
					&&
					!_p.v[o.getAttribute("rid")]
				)
				||
				(
					!_s.multiple
					&&
					o != _p.a
				))
				&&		
				(
					!_s.is_paging
					||
					(_s.page_hashing && _p.s[_p.r[_p.rh[o.getAttribute("rid")]].data.id])
				)
			){
				o.className = _s.class_item + " " + _s.class_item_hover;
				/*"wideselect_item wideselect_item_hover";*/
			}
		};
		n._handle_mouseout=function(v){
			var t=this,o,e,_p,_s,l;
			_s = t.o.s;
			_p = t.o.p;
			e=$E.dom.event._gevt(v);
			o=(!D.TU(v) && v.nodeType)?v:$E.dom.event._gevt_src(v);
			if(o && o.nodeType==3) o=o.parentNode;
			l = o;
			while(l){
			 	if(typeof l.getAttribute != D.U && l.getAttribute("is-result-item")){
					o = l;
					break;
				}
				l = l.parentNode;
			}
			if(
				o.getAttribute("is-result-item")
				&&
				((
					_s.multiple
					&&
					!_p.v[o.getAttribute("rid")]
				)
				||
				(
					!_s.multiple
					&&
					o != _p.a
				))
		
				&&
				
				(
					!_s.is_paging
					||
					(_s.page_hashing && _p.s[_p.r[_p.rh[o.getAttribute("rid")]].data.id])
				)
				
			){
				o.className = _s.class_item;
				/*"wideselect_item";*/
			}
		};

		n.setActiveItem=function(i){
			this.selectItem(i,1);
		};

		n.selectItem=function(i,b){
			var t = this,c;
			c=t.o;
			if(c.p.r[i] != null){
				t._handle_mouseover(i);
				t._handle_click(i,b);
				t.scrollToItem(i);
			}
		};
		
		n.scrollToItem=function(i){
			var t = this,c;
			c=t.o;
			if(c.p.r[i]!=null){
				c.p.c.scrollTop=c.p.r[i].object.offsetTop;
			}
		};
		
		n._handle_click=function(v,b){
			var t=this,o,e,_p,_s,l;
			_p = t.o.p;
			_s = t.o.s;
			if(D.TN(v)){
				o = _p.r[v].object;
			}
			else{
				e=$E.dom.event._gevt(v);
				o=(!D.TU(v) && v.nodeType)?v:$E.dom.event._gevt_src(v);
				if(o && o.nodeType==3) o=o.parentNode;
				l = o;
				while(l){
				 	if(typeof l.getAttribute != D.U && l.getAttribute("is-result-item")){
						o = l;
						break;
					}
					l = l.parentNode;
				}
			}
	
			if(
				o.getAttribute("is-result-item")
				&&
				(
					!_s.is_paging
					||
					(_s.page_hashing && _p.s[_p.r[_p.rh[o.getAttribute("rid")]].data.id])
				)	
			){
				/*if(o == _p.a){*/
				if(
					(
						_s.multiple
						&&
						_p.v[o.getAttribute("rid")]
					)
					||
					(
						!_s.multiple
						&&
						o == _p.a
					)
				){

					_p.v[o.getAttribute("rid")] = 0;
					_p.a = null;
					o.className = _s.class_item + " " + _s.class_item_hover;
					/*"wideselect_item wideselect_item_hover";*/
					return;
				}

				if(!_s.multiple && _p.a != null){
					_p.a.className= _s.class_item;
					_p.v[_p.a.getAttribute("rid")] = 0;
				}

				_p.a = o;
				_p.v[o.getAttribute("rid")] = 1;
				o.className = _s.class_item + " " + _s.class_item_active;
				/*"wideselect_item wideselect_item_active";*/

				if(!b){
					$E.message.MessageService.publish("onresultclick",t);
					if(D.TF(_p.h)) _p.h("onresultclick",_p.r[_p.rh[o.getAttribute("rid")]]);
				}
			}
		};
		
		n.clearItem=function(i){
			var t=this,o,c,d,_p,x;
			c=t.o;
			_p = c.p;
			o=_p.r[i];
			if(o){
				d=o.id;
				if(
					(
						c.s.multiple
						&&
						_p.v[d]
					)
					||
					(
						!c.s.multiple
						&&
						o != _p.a
					)
				){
					_p.a=null;
					_p.v[d] = 0;
				}
/*				if(o.object == c.s.a) c.s.a=null;*/
				_p.rh[d] = null;

				o = o.object;
				_p.c.removeChild(o);
				_p.r.splice(i,1);

				/* correct the object indices */
		
				for(x=i;x<_p.r.length;x++){
					_p.r[x].index = x;
					_p.rh[_p.r[x].id] = x;
				}

			}

		};

		n.clearItems=function(){
			var t=this,c,a,i,_p;
			c=t.o;
			_p = c.p;
			_p.a = null;
			_p.r = [];
			_p.rh = [];
			c.s.m = 0;
			_p.b=[];
			a = _p.c.childNodes;
			for(i = a.length - 1;i >= 0;i--){
				_p.c.removeChild(a[i]);
			}
		};

		n.clearPagingValues = function(){
			var _s = this.o.s,_p = this.o.p;
		
			_s.current_page=0;
			_s.maximum_page_size=0;
			_s.page_mark=0;
			_s.page_stop = 0;
			_p.g = [];
			_p.s = [];
			_p.qr = [];
		};
		
		n.reset = function(){
			var t = this;
			/* end any active request; this only applies if request was first invoked on an object */
			t.endRequest();
			/* clear out the result list */
			t.clearItems();
			/* clear out any  paged values */
			t.clearPagingValues();
		};

		n.moveFirst = function(){
			var _p = this.o.p,_s = this.o.s;
			_s.current_page = 0;
			this.updatePage();
			if(D.TF(_p.ph)) _p.ph("onpagenavigate",_s.current_page);
		};

		n.moveLast = function(){
			var _s = this.o.s, _p = this.o.p;
			if(_s.page_stop){
				_s.current_page = _s.maximum_page_size;
				this.updatePage();
				if(D.TF(_p.ph)) _p.ph("onpagenavigate",_s.current_page);
			}
		};

		n.getCanMoveNext = function(){
			return this.moveNext(1);
		};

		n.getCanMovePrevious = function(){
			return this.movePrevious(1);
		};
		n.moveNext = function(b){
			/* b = toggle to only evaluate the check */
			var _s = this.o.s, _p = this.o.p;
			if(
				(_s.current_page + 1) < _s.maximum_page_size
				||
				(_s.page_stop && (_s.current_page + 1) == _s.maximum_page_size)
			){
				if(!b){
					_s.current_page++;
					this.updatePage();
					if(D.TF(_p.ph)) _p.ph("onpagenavigate",_s.current_page);
				}
				return 1;
			}
/*
			/ * Get more data * /
			else if(!_s.page_stop){
				_s.current_page++;
			}
*/
			return 0;
		};
		
		n.movePrevious = function(b){
			/* b = toggle to only evaluate the check */
			var _s = this.o.s,_p = this.o.p;
			if((_s.current_page - 1) >= 0 && D.TO(_p.g[_s.current_page - 1])){
				if(!b){
					_s.current_page--;
					this.updatePage();
					if(D.TF(_p.ph)) _p.ph("onpagenavigate",_s.current_page);
				}
				return 1;
			}
			return 0;
		};

		n.importPageItems = function(a, b){
		/*
			XXX i = request id
			a = array of objects with the construct:
				{
					label:label (display name for the control)
					id:id (opt - used for page hashing)
					value:value (opt)
				}
				
			b = toggle to indicate that this is the last set of items
		*/
		
			if(!D.TO(a)) return 0;
		
			var n,
				c = 0,
				_s = this.o.s,
				v,
				z,
				s,
				l,
				_p = this.o.p,
				/* r = result count */
				r = a.length,
				t = this
			;
		
		
			if(r == 0){
				/* only add the zero label if there really are no items at all */
				if(_p.r.length == 0 && _p.g.length == 0){
					if(_s.is_paging)
						t.pageItem("Zero Items","_avoid");
					else
						t.addItem("Zero Items","_avoid");
				}
			}
			else{
		
				s = _s.page_mark;
				l = _s.maximum_page_items;
			
				for(z=0; z < a.length; z++){
					n = a[z];
					c++;
			
					if(_s.is_paging) t.pageItem(n.label,n);
					else t.addItem(n.label,n);
		
				}
				_s.page_mark += _s.maximum_page_items;
			}
		
			if(c < _s.maximum_page_items || b)
				_s.page_stop = 1;
					
			if(_s.is_paging) 
				t.updatePage();
		
		};
		
		n.getIsRequested = function(){
			return this.o.s.is_requested;
		};
		
		n.request = function(o){
			var t = this,_s,b;
			_s = t.o.s;
			if(!_s.can_request){
				$E.message.MessageService.S("Cannot request control","200.4");
				return;
			}
			if(_s.is_requested){
				b = (o == t.o.p.qo) ? 1 : 0;
				t.endRequest();
				if(b) return;

			}
		
			/*
				POSITION THE WIDESELECT CONTROL
			*/
			t.o.p.qo = o;
		
			t.alignControl(o);
		
			_s.is_requested = 1;
			
			if(_s.is_paging) t.updatePage();
			

		};

		n.endRequest = function(){
		
			var t = this, _p,_s;
			_p = t.o.p;
			_s = t.o.s;
			if(!_s.is_requested || !_s.can_request) return 0;

			_p.c.style.display = "none";
		
			if(_s.is_paging) t.clearItems();
			
			_s.is_requested = 0;
		
			_p.qo = null;
			return 1;

		};
		
		n.alignControl = function(o){
			var
				/* document width */
				/*p_w = document.documentElement.offsetWidth,*/
				/* document height */
				/*p_h = document.documentElement.offsetHeight,*/
				/* request object width */
				w = o.offsetWidth,
				/* request object height */
				h = o.offsetHeight,
				/* request object left */
				l = $E.dom.event.getAbsoluteLeft(o),
				/* request object top */
				t = $E.dom.event.getAbsoluteTop(o),
				/* main control width */
				c_w,
				/* main control height */
				c_h,
				/* rr_w = remaining right width */
				/*rr_w,*/
				/* rl_w = remaining left width */
				/*rl_w,*/
				_p = this.o.p,
				_s = this.o.s

			;

			_p.c.style.display = "block";

			c_w = _p.c.offsetWidth;
			c_h = _p.c.offsetHeight;	
/*
			rr_w = p_w - (l + w);
			rl_w = l;
*/
			/* don't care about top position right now, it's adjacent */
			_p.c.style.top = (t + h) + "px";
			_p.c.style.left = l + "px";
		
			/*
				use left side as there is not enough room on the right
				Note: this means the right side is favored
			*/
		
			/* PUT WIDESEL ON LEFT SIDE OF CONTROL */
/*
			if(rr_w < (c_w))
				_p.c.style.left = (l - c_w) + "px";
*/
			/* PUT WIDESEL ON RIGHT SIDE OF CONTROL */
/*
			else
				_p.c.style.left = (w + l) + "px";
*/
		};
		
		
		
		n.init();


		$E.registry.ObjectRegistry.addObject(n);

		return n;
	}
}


/*
	libStorage
	Source: $E.storage
	Copyright 2008 - 2009. All Rights Reserved.
	Version: 2.1.1
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/projects/engine/
	License: http://www.whitefrost.com/projects/engine/code/engine.license.txt
*/

/*
	NOTES
	
	BUGS
	
	WORK EXAMPLES
*/



/*
var org  = {};
org.cote = {};
$E = {};
*/
Engine.Package("$E");



$E.storage = {


	
	v:"2.1.1",
	
	storage_provider:0,
	
	preferred_storage_type:"auto",
	
	preferred_storage_types : ["auto","local","session","global"],
	
	getStorageProvider : function(){
		if($E.storage.storage_provider) return $E.storage.storage_provider;
		
		if(!D.TU($E.storage.DOMStorageProvider))
			return ($E.storage.storage_provider = $E.storage.DOMStorageProvider);
		else if(!D.TU($E.storage.IEStorageProvider))
			return ($E.storage.storage_provider = $E.storage.IEStorageProvider);
				
	},
	/*
	setItem : function(n, v){
		var o = $E.storage.getStorageProvider();
		if(!o) return 0;
		return o.setItem(n, v);		
	},
	getLength : function(){
		var o = $E.storage.getStorageProvider();
		if(!o) return 0;
		return o.getLength();
	},
	getStorage : function(){
	
	}
	*/
	
	testStorageSupported : function(){
		return ($E.storage.getStorageProvider() != null && $E.storage.getStorageProvider().getPreferredStorage() != null ? 1 : 0);
	}

};



Engine.Package("$E.storage");




if(typeof Storage != "undefined") 
$E.storage.DOMStorageProvider = {
	storage_type : "DOMStorage",
	session_storage : ( window.sessionStorage ? window.sessionStorage : 0),
	local_storage : ( window.localStorage ? window.localStorage : 0),
	global_storage : ( window.globalStorage ? window.globalStorage : 0),
	preferred_storage : 0,
	check_support: 0,
	getPreferredStorage : function(){
		var s = $E.storage.DOMStorageProvider;
		if(!s.check_support) s.init();
		return s.preferred_storage;
	},
	init : function(){
		var s = $E.storage.DOMStorageProvider;

		if(s.local_storage) s.preferred_storage = s.local_storage;
		else if(s.global_storage) s.preferred_storage = s.global_storage;
		else if(s.session_storage) s.preferred_storage = s.session_storage;

		s.check_support = 1;
	},
	getLength : function(){
		var o, s = $E.storage.DOMStorageProvider;
		o = s.getPreferredStorage();
		if(!o) return 0;
		if(o instanceof Storage) return o.length;
		return o[document.domain].length;
	},
	setItem : function(n,v){
		var o, s = $E.storage.DOMStorageProvider;
		o = s.getPreferredStorage();
		if(!o) return 0;
		if(o instanceof Storage) return o.setItem(n,v);
		return o[document.domain].setItem(n,v);
	},
	removeItem : function(n){
		var o, s = $E.storage.DOMStorageProvider;
		o = s.getPreferredStorage();
		if(!o) return 0;
		if(o instanceof Storage) return o.removeItem(n);
		return o[document.domain].removeItem(n);
	},
	key : function(i){
		var o, s = $E.storage.DOMStorageProvider;
		o = s.getPreferredStorage();
		if(!o) return 0;
		if(o instanceof Storage) return o.key(i);
		return o[document.domain].key(i);	
	},
	clear : function(i){
		var o, s = $E.storage.DOMStorageProvider;
		o = s.getPreferredStorage();
		if(!o) return 0;
		var i,l = s.getLength();
		for(i = l - 1; i >= 0; i--){
			s.removeItem(s.key(i));
		}
	}
	/*
		(
			$E.storage.DOMStorageProvider.local_storage
			?
			$E.storage.DOMStorageProvider.local_storage
			:
			$E.storage.DOMStorageProvider.session_storage
		)
	*/
};


Engine.Package("$E.storage");



if(typeof Storage == "undefined" && !D.TU(document.documentElement.addBehavior)) 
$E.storage.IEStorageProvider = {
	/*
	session_storage : 0,
	local_storage : 0,
	global_storage : 0,
	*/
	storage_type : "IEStorage",
	behavior_storage : 0,
	behavior_storage_reader : 0,
	check_support: 0,
	behavior_storage_name : "IEStorageProvider",
	
	getPreferredStorage : function(){
		var s = $E.storage.IEStorageProvider;
		if(!s.check_support) s.init();
		return s.behavior_storage;
	},
	init : function(){
		var s = $E.storage.IEStorageProvider, o, br;
		
		o = document.createElement("div");
		
		o.style.cssText = "position:absolute;display:none;width:1px;height:1px;top:0px;left:0px;";
		document.body.appendChild(o);
		o.addBehavior("#default#userData");
		
		if(typeof o.XMLDocument != "undefined"){
			o.load(s.behavior_storage_name);
			s.behavior_storage = o;
			br = s.behavior_storage_reader = $E.util.config.newInstance();
			br.setElementParentName("c");
			br.setElementName("p");
			br.setAttrNameName("n");
			br.setAttrValueName("v");
			br.parseConfig(o.XMLDocument);

		}
		s.check_support = 1;
		return s.behavior_storage;
	},
	
	getLength : function(){
		var o, s = $E.storage.IEStorageProvider,i=0,ar,r=0;
		o = s.getPreferredStorage();
		if(!o) return 0;
		if(s.behavior_storage){
			ar = s.behavior_storage_reader.getParams();
			for(;i < ar.length;i++)
				if(ar[i] != null && ar[i].value != null && typeof ar[i].value != "undefined") r++;
			
			return r;
		}
		return 0;
	},
	removeItem : function(n){
		$E.storage.IEStorageProvider.setItem(n,null);
	},
	getItem : function(n){
		var o, s = $E.storage.IEStorageProvider;
		o = s.getPreferredStorage();
		if(!o) return 0;
		if(s.behavior_storage)
			return s.behavior_storage_reader.getParam(n);
		
		return null;	
	},
	setItem : function(n, v){
		var o, s = $E.storage.IEStorageProvider;
		o = s.getPreferredStorage();
		if(!o) return 0;
		if(s.behavior_storage){
			s.behavior_storage_reader.writeParam(s.behavior_storage.XMLDocument,n,v);
			s.behavior_storage.save(s.behavior_storage_name);
			return 1;
		}
		return 0;
	},
	
	key : function(i){
		var o, s = $E.storage.IEStorageProvider, ar,m=0,n=0,z=0;
		o = s.getPreferredStorage();
		if(!o || i < 0) return 0;
		if(s.behavior_storage){
			ar = s.behavior_storage_reader.getParams();
			for(;n < ar.length;n++){
				if(ar[i].value == null || typeof ar[i].value == "undefined") continue;
				if(m == i){
					z = ar[i].name;
					break;
				}
				m++;
			}
			return z;
		}
		return 0;
	},
	
	clear : function(){
		var o, s = $E.storage.IEStorageProvider, ar,m=0,n=0,z=0;
		o = s.getPreferredStorage();
		if(!o) return 0;
		ar = s.behavior_storage_reader.getParams();
		for(var i= ar.length - 1; i >=0; i--){
			if(ar[i].value == null || typeof ar[i].value == "undefined") continue;
			s.behavior_storage_reader.writeParam(s.behavior_storage.XMLDocument,ar[i].name,null);
		}
		s.behavior_storage.save(s.behavior_storage_name);
		s.behavior_storage_reader.clearConfig();
		
	}
	/*
		(
			$E.storage.DOMStorageProvider.local_storage
			?
			$E.storage.DOMStorageProvider.local_storage
			:
			$E.storage.DOMStorageProvider.session_storage
		)
	*/
};




/*
	DWAC
	Source: $E.dwac
	Copyright 2009. All Rights Reserved.
	Version: 2.1.1
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/projects/engine/
	License: http://www.whitefrost.com/projects/engine/code/engine.license.txt
	
*/
Engine.Package("$E.dwac");

$E.dwac.DistributedComponent = {
	atkey : "is-dwac",
	aturi : "DWacControlUri",
	attk : "DWacControlTask",
	attid : "DWacTemplateId",

	newInstance : function(o, u, t, k,i){
		if(!o) return;
		/* Late bind the component */
		var b = 0;
		if(!D.TF(o.getObjectType) || o.getObjectType() != "xhtml_component"){
			o = $E.xhtml.XHTMLComponent.newInstance(o,1);
			b = 1;
		}
		var r = $E.appcomp.ApplicationComponent.newInstance(0,0,o.getObjectId(),0,0,0);
		r.getStatus().DWacControlUri = u;
		r.getStatus().DWacControlTask = k;
		r.getStatus().DWacTemplateId = t;
		r.component_init = function(){
			this.setTemplateIsEngine(1);
			this.getPointers().task_service = new $E.task.TaskServiceImpl();
			this.createHandler("processor",0,0,1);
		};
		r._handle_processor = function(Service, ParentTask, TaskName, Value){
			return this._handle_xhtml_token(2,Value);
		};
		r.component_post_init = function(){
			var sU = this.getStatus().DWacControlUri;
			var sT = this.getStatus().DWacControlTask;
			var sTId = this.getStatus().DWacTemplateId;
			if(typeof sTId != "string" || sTId.length == 0) sTId = 0;
			if(typeof sU == "string" && sU.length > 0){

				if(typeof sT == "string" && sT.length > 0){
					this.getStatus().dwac_template_path = sU;
					this.getPointers().dwac_task = this.getPointers().task_service.executeTaskLoader(
						"dwac_loader",
						"xml",
						sU,
						"import-task",
						sT,
						this._prehandle_processor
					);
				}
				else{
					this.LoadDwacTemplate(sU, sTId);
				}
			}
			
		};
		r.handle_dwac_task = function(s, v){
			var sU = this.getContainer().getAttribute("DWacControlUri");
			var sTId = this.getContainer().getAttribute("DWacTemplateId");
			if(typeof sTId != "string" || sTId.length == 0) sTId = 0;
			if(typeof sU == "string" && sU.length > 0) this.LoadDwacTemplate(sU,sTId);
		};
		r.LoadDwacTemplate = function(sPath, sTemplateId){
			this.getStatus().dwac_template_path = sPath;
			this.loadTemplate(sPath, sTemplateId);			
		};
		r.GetDwacTemplatePath = function(){
			return this.getStatus().dwac_template_path;
		};
		r.local_handle_xhtml_token = function(iType, sTokenValue){
			sTokenValue = sTokenValue.replace(/\$\{dwac\.path\}/g,this.GetDwacTemplatePath());
			return sTokenValue;
		};
		
		if(!i) i = $E.GG();
		r.importComponentDefinition("",i,0);
		if(b) r.component_post_init();

		return r;
		
	}
};

Engine.Package("org.cote.js");
org.cote.js = $E;
