
/*
	"Hemi" JavaScript Framework
	Engine for Web Applications 3.1
	Composite file "hemi.comp.js" release: 3.1.9
	Copyright 2002 - 2010. All Rights Reserved.
	Author: Stephen W. Cote
	Email: sw.cote@gmail.com
	Project: http://www.whitefrost.com/Hemi/
	BSD License: http://www.whitefrost.com/Hemi.license.txt
*/
(function(){H.include("hemi.task");H.include("hemi.util");H.include("hemi.object");H.include("hemi.object.xhtml");H.include("hemi.data.form");H.include("hemi.util.logger");H.include("hemi.driver");H.include("hemi.app.space.definitions");H.namespace("app.space",H,{service:null,serviceImpl:
function(){var t=this,_m=H.message.service,_x=H.xml;H.util.logger.addLogger(t,"Space","Application Space","600");t.p={pn:"space_loader",pa:"[nothing]",pat:"default",ph:"space_service_initialized",pht:"event",dn:"space",da:"[nothing]",dat:"default",dh:"space_initialized",dht:"event",eac:0,space_id_counter:0,space_id_label:"hemi.space",al:1};t.o={ts:new H.task.serviceImpl()};t.getPrimarySpace=function(){return t.getSpaceByName(t.p.pn);};t.clearAppSpace=function(i){var _p=t.o,o,b,h;if(typeof i==D.S)o=t.getSpace(i);if(typeof i==D.O)o=i;if(t.isSpace(o)){b=o.eo;for(h=b.length-1;h>=0;h--){H.registry.service.sendDestroyTo(b[h].object);}H.data.form.service.removeDataForm(o.space_id);o.eo=[];o.en=[];o.ei=[];o.space_css_map=[];o.space_implementations=[];if(o.space_element){_x.removeChildren(o.space_element);if(o.space_element.parentNode)o.space_element.parentNode.removeChild(o.space_element);}this.removeSpace(o);}else{_m.S("Invalid space reference '"+i+"'","200.4");}};t.clearAppSpaces=function(){var _p=t.o,a,i,o,h,b,_t;a=_p.spaces;_t=_p.ts;for(i=a.length-1;i>=0;i--){t.clearAppSpace(a[i]);}this.clearSpaces();_t.clearTasks();};t.loadSpaces=function(b,d,pr,xr){var _p=t.o,m=[],i,p;if(document.body==null){this.logError("Space unable to initialize due to unexpected DOM.");return 0;}p=_x.queryNodes((d?d:document.body),"div",null,"is-space","1");H.util.absorb(p,m);p=_x.queryNodes((d?d:document.body),"span",null,"is-space","1");H.util.absorb(p,m);p=_x.queryNodes((d?d:document.body),"form",null,"is-space","1");H.util.absorb(p,m);this.logDebug("Loading Spaces "+(b?1:0)+":"+m.length);if(!b&&!m.length&&!_p.spaces.length){m.push(document.body);document.body.setAttribute("is-space","1");}if(b){this.logDebug("Force load a primary space","1.2");m=[1];}for(i=0;i<m.length;i++){if(!b)e=m[i];t.createSpace(e,b,pr,xr);}};t.createSpace=function(e,b,pr,xr,fCallBack){var _p=t.o,o,m=[],i,v,_s=t.p,s="p",x,_t,a,at,h,ht,l,n,z,c,p,q,pn;_t=_p.ts;x=_t.addTaskLoader;c=++_s.space_id_counter;if(_p.spaces.length>0){s="d";x=_t.addTask;n=_s[s+"n"]+"_"+c;}else{n=_s[s+"n"];}z=_s.space_id_label+"_"+c;if(!b){if(H.IsAttributeSet(e,"space-name")){n=e.getAttribute("space-name");}else{e.setAttribute("space-name",n);}if(H.IsAttributeSet(e,"space-id")){z=e.getAttribute("space-id");}else{e.setAttribute("space-id",z);}}if(t.getSpaceByName(n)){this.logDebug("Space "+n+"("+z+")is already loaded.","1.3");return null;}if(!b&&H.IsAttributeSet(e,"space-action"))a=e.getAttribute("space-action");else a=_s[s+"a"];if(!b&&H.IsAttributeSet(e,"space-action-type"))at=e.getAttribute("space-action-type");else at=_s[s+"at"];if(!b&&H.IsAttributeSet(e,"space-handler"))h=e.getAttribute("space-handler");else h=_s[s+"h"];if(!b&&H.IsAttributeSet(e,"space-handler-type"))ht=e.getAttribute("space-handler-type");else ht=_s[s+"ht"];if(!b&&H.IsAttributeSet(e,"space-config-task"))_s.pt=e.getAttribute("space-config-task");this.logDebug("Tasking space service:"+n+" / "+at+" / "+a+" / "+ht+" / "+h);o=x(n,at,a,ht,h);l=_p.spaces.length;v=t.newSpaceObject((b?0:e),z,n,o,l,fCallBack);if(pr)v.Processor=pr;if(xr)v.XhtmlHandler=xr;if(!l)v.is_primary=1;else{_t.addTaskDependency(o,_s.pn);if(_s.pt)_t.addTaskDependency(o,_s.pt);}t.addNewSpace(v,n,z);v.space_state=1;_t.executeTask(o);return v;};t.configureSpace=function(o,c){var v,_s=t.p,s,_t=t.o.ts,_p=t.o,i,a,sf=0;s=_s.pd;v=_t.getTaskByName(_s.pt);if(typeof o==D.S)o=t.getSpace(o);if(!c&&!H.IsAttributeSet(o.space_element,"space-config"))c="self";if(t.isSpace(o)){o.space_state=3;a=o.eo;for(i=a.length-1;i>=0;i--)H.registry.service.sendDestroyTo(a[i].object);o.eo=[];o.en=[];o.ei=[];o.space_css_map=[];o.space_implementations=[];if(typeof c==D.S&&c=="self"&&o.space_element)s=sf=1;if(!sf&&o.space_element&&o.space_element.getAttribute("space-config")!="self")_x.removeChildren(o.space_element);o.config_name=0;if(!v||(_t.isTask(v)&&v.handled&&typeof v.data==D.O)){if(!sf&&(o.space_element&&H.IsAttributeSet(o.space_element,"space-config"))||D.TS(c)){s=(D.TS(c))?c:o.space_element.getAttribute("space-config");if(s&&s=="self"){o.space_element.removeAttribute("space-config");sf=1;}}if(!s){this.logDebug("Page config not specified.");return 0;}o.config_name=s;this.logDebug("Process configuration '"+s+"' for "+o.space_name);t.PC(o,v,s);o.space_implementations=[];o.space_state=4;_m.publish("onspaceconfigload",o);}else{this.logDebug("Space config not present.");}}else{this.logWarning("Invalid space reference for configureSpace","200.4");}};t.PC=function(o,v,s,p,x,b){var a,i,n,q,r,m,u,g,j,def,f,b,c,h,k,l,e=0,w,br,cx,cxv,cxp,ab,nr,sf=0,ck,nl,ci;if(s=="self"&&typeof p==D.U)p=o.space_element;else if(typeof p==D.U&&v&&v.data)p=_x.queryNode(v.data.documentElement,"configuration",0,"id",s);if(!p){this.logWarning("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;def=ci=k=g=ab=cx=ck=0;j=[];cs=s;if(s=="self")sf=1;if(n.nodeType==1){if(n.getAttribute("avoid")=="1"||n.getAttribute("is-space")=="1")continue;q=n.nodeName.toLowerCase();w=o.space_implementations[q];if(w){k=w.p;cx=w.cs;cxp=w.cp;ab=w.ab;br=w.nr;sf=w.sf;ck=w.ck;g=w.g;f=w.f;def=w.def;cn=w.cn;ci=1;}else if((def=H.app.space.definitions.service.getDefinition(q))){k=def.use_parent;cx=def.context_switch;cxp=def.context_path;cn=def.swap_name;ab=def.is_abstract;br=(def.no_recursion?0:1);if(cx&&cs=="self"){sf=0;ck=1;}if(cxp)cxp=t.PO(o,v,cxp,n,x,b,p,cs);if((u=def.namespace)&&(g=H.lookup(def.namespace))){if(g&&(u=def.method_reference)){if(D.TF(g[u]))g=g[u](t.PO(o,v,def.method_reference_parameter,n,x,b,p,cs));}}w={};w.p=k;w.cs=cx;w.cp=cxp;w.ab=ab;w.nr=br;w.sf=sf;w.ck=ck;w.g=g;w.def=def;w.cn=cn;if(o.space_implementations[q])alert('overwrite '+q+' / '+def);o.space_implementations[q]=w;}if(def||ci){if(ci){def=w.def;}if(def){z=def.constructor_params;if(!ci){f=t.PO(o,v,def.constructor,n,x,b,p,cs);w.f=f;}else if(!f){var s1=[];for(var s2 in w)s1.push(s2);}w=z.length;for(h=0;h<w;){m=z[h++];u=0;if(D.TS(m)&&m.match(/^ora:/i))u=t.PO(o,v,m,n,x,b,p,cs);else u=m;j[j.length]=u;}}nr=H.GetSpecifiedAttribute(n,"aid");if(nr)n.setAttribute("id",nr+(++t.p.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{this.logError("Unexpected implementation for "+q+" with g="+g+" and f="+f,"200.4");}}else{_m.S("apply #3 "+q+" abstracted","200.1");w=x;}}catch(e){this.logError("Parse Configuration:"+(e.description?e.description:e.message)+" from q="+q+" and f="+f+" and k="+k+" and x="+x+" and g="+g,"12.1");}if(k){e=w;w=x;}o.addSpaceObject(w,w&&w.p&&w.p.cid?w.p.cid:H.GetSpecifiedAttribute(n,"rid"));if(cx&&w){if(ck&&cn){k=document.createElement(cn);n.parentNode.insertBefore(k,n);n.parentNode.removeChild(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(o.dp)cxp=o.dp;nr=(cxp?_x.selectSingleNode(w,cxp,w.documentElement):w.documentElement);if(!nr)nr=w.documentElement;o.Processor(o,nr);if(!sf)_x.setInnerXHTML(n,nr,0,(!ck?v.data:0),0,0,0,o.XhtmlHandler);}w=x;}if(br)t.PC(o,v,cs,n,w,e);if(w&&w.t&&w.t.match(/^xhtml_component$/)){w.post_init();}}else{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{_m.S("No object definition for "+n.nodeName+"(1);treating as HTML","200.1");}}}else if(n.nodeType==3){if(n.nodeValue.replace(/\s/g,"").length&&typeof x==D.O&&typeof x.getContainer==D.F){o.Processor(o,n);if(!sf)_x.setInnerXHTML(x.getContainer(),n,1,0,0,0,0,o.XhtmlHandler);}}}}catch(e){this.logError("PC Error:"+(e.message?e.message:e.description),"200.4");this.logError("PC Error:n="+n+" / q="+q,"200.4");}};t.PO=function(o,v,r,e,x,b,q,s){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="attr";}if(r.match(/integer_(\S*)$/i)){a=r.match(/integer_(\S*)$/i)[1];r="integer";}if(r.match(/xpath-node-value:(\S*)/i)){a=r.match(/xpath-node-value:(\S*)/i)[1];r="xpath-node-value";}if(r.match(/xpath-node-value-list:(\S*)/i)){a=r.match(/xpath-node-value-list:(\S*)/i)[1];r="xpath-node-value-list";}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(H.IsAttributeSet(d,"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");p=[];for(c=0;c<a.length;c++){d=a[c];if(H.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 "space_object":z=o;break;case "space_config":z=s;break;case "space_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 "space_id":z=o.space_id;break;default:z=r;break;}return z;};t.newSpaceObject=function(e,i,n,k,x,f){var r={space_element:e,space_id:i,space_name:n,space_index:x,config_name:0,task:k,is_primary:0,eo:[],en:[],ei:[],space_css_map:[],Processor:
function(o,n){},XhtmlHandler:0,space_implementations:[],space_state:0,space_callback:f,removeSpaceObject:
function(i){var o=this.eo,x=this.ei,m=this.en,s;if(!D.TN(x[i]))return;s=o[x[i]];if(s.rid)delete m[s.rid];o[x[x]]=0;delete x[i];},addSpaceObject:
function(w,q){var l=this.eo.length,n;if(w!=null&&typeof w==D.O&&H.registry.service.isRegistered(w)&&typeof this.ei[w.i]!=D.N){n=(w.getContainer?w.getContainer():0);this.eo[l]={object:w,config:cs,rid:q};this.ei[w.i]=l;if(q&&typeof this.en[q]!=D.N)this.en[q]=l;var aC=(n&&n.className?n.className.split(" "):[]);for(var c=0;c<aC.length;c++){if(!D.TO(this.space_css_map[aC[c]]))this.space_css_map[aC[c]]=[];this.space_css_map[aC[c]].push(l);}}},getSpaceObjectsByClass:
function(cN){var a=[],o;if(D.TO(this.space_css_map[cN])){for(var c=0;c<this.space_css_map[cN].length;c++){o=this.eo[this.space_css_map[cN][c]];if(o)a.push(o);}}return a;},getContainer:
function(){return this.space_element;},getSpaceObjects:
function(){return this.eo;},getSpaceObject:
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;},getSpaceObjectByName:
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;}};H.prepareObject("space_object","3.1.9",1,r);return r;};t.handle_window_load=function(){if(t.p.al)t.loadSpaces();};t.handle_space_initialized=function(s,v){var e;this.logDebug("Starting space "+v.task.task_name,"11.1");if(typeof v==D.O&&typeof v.task==D.O&&(e=t.getSpaceByName(v.task.task_name))){e.space_state=2;if(e.is_primary){this.logWarning("Space "+e.space_id+" is the primary space and should not be handled by this event.","11.2");}else{this.logDebug("Space "+e.space_id+" initialized","11.3");}t.configureSpace(e);if(D.TF(e.space_callback))e.space_callback(this,e);H.util.EH(e.space_element,"space-onload");}else{this.logError("Invalid space reference for space_initialized","11.4");}};t.HEI=function(){var _p=t.o,e;this.logDebug("Starting space service","10.1");_p.spaces[0].space_state=2;if(_p.spaces.length){e=_p.spaces[0].space_element;t.configureSpace(_p.spaces[0]);if(D.TF(e.space_callback))e.space_callback(this,e);H.util.EH(e,"space-onload");}return 1;};t.destroy=function(){var _m=H.message.service;_m.unsubscribe(t,"onremoveobject","H");_m.unsubscribe(t,"dom_event_window_load","handle_window_load");_m.unsubscribe(t,"space_initialized","handle_space_initialized");_m.unsubscribe(t,"space_service_initialized","HEI");};t.H=function(s,i){var s=t.o.spaces,h=0,o;for(;h<s.length;){o=s[h++];if(!o)continue;o.removeSpaceObject(i);}};H.IM(t,"base_object","space_service","3.1.9");H.object.addObjectAccessor(t,"space");_m.subscribe(t,"onremoveobject","H");_m.subscribe(t,"dom_event_window_load","handle_window_load");_m.subscribe(t,"space_initialized","handle_space_initialized");_m.subscribe(t,"space_service_initialized","HEI");H.registry.service.addObject(t);t.r=4;}},1);}());
/* End Hemi Framework 3.1 */

