// Livesite (c) Livesite Networks, LLC 2006-2009.  SHA1 Algorithms (c) Paul Johnston 2000-2002.

var ECMAScript={Name:"Livesite ECMAScript",Version:.014,Copyright:"Livesite (c) Livesite Networks, LLC 2006-2009.  SHA1 Algorithms (c) Paul Johnston 2000-2002.",About:function(){var names={};for(var i=0;i<ECMAScript.Packages.length;i++){var def=ECMAScript.Packages[i];var ns=def.namespace;var idx=ns.indexOf('.');var name=idx>0?ns.substr(0,idx):ns;names[name]=true;}
var pkgs=[];for(var ns in names){pkgs.push(ns);}
return[this.Name,this.Version,pkgs.sort().join(',')].join(';');},Packages:[],Instances:[],Extend:function(ns,func){ns=ns.toLowerCase();for(var n in ECMAScript.Class.prototype){if(ns==n)throw'illegal name-space name: '+ns;}
var def={'namespace':ns,'constructor':func};ECMAScript.Packages.push(def);for(var i=0;i<ECMAScript.Instances.length;i++){ECMAScript.Instances[i].extend(ns,func);}},Class:function(win,doc){this.window=win;this.document=doc;this.id='ecma'+Math.floor(Math.random()*100000);for(var i=0;i<ECMAScript.Packages.length;i++){var def=ECMAScript.Packages[i];this.extend(def.namespace,def.constructor);}
ECMAScript.Instances.push(this);}};ECMAScript.Class.prototype={window:null,document:null,extend:function(ns,func){var nses=ns.split('.');var name=nses.pop();var inst=this;for(var i=0,seg;seg=nses[i];i++){if(!inst[seg])inst[seg]={};inst=inst[seg];}
if(inst[name]){func.apply(inst[name],[this]);}else{inst[name]=new func(this);}}};ECMAScript.Extend('lang',function(ecma){this.createAbstractFunction=function(){return function(){throw'Abstract function not implemented';};};this.createObject=function(klass,args){var ctor=function(){};ctor.prototype=ecma.lang.createMethods(klass);var obj=new ctor();klass.apply(obj,args);return obj;};this.createConstructor=function(){return function(){if(this.construct)this.construct.apply(this,arguments);};};this.createMethods=function(func){if(arguments.length>1){var proto=null;var bases=null;for(var i=0;i<arguments.length;i++){func=arguments[i];if(typeof(func)!='function')
throw'Argument '+i+' is not a constructor function';var proxy=function(){};proxy.prototype=func.prototype;var stub=new proxy();if(!bases)bases=stub.__bases__?stub.__bases__:[];delete stub.__bases__;bases.push(stub);if(proto){ecma.util.overlay(proto,stub);}else{proto=new proxy();}}
proto.__bases__=bases;return proto;}else{if(typeof(func)!='function')
throw'single argument is not a constructor function';function proxy(){};proxy.prototype=func.prototype;return new proxy();}};this.createCallback=function(){var cbarr=ecma.lang.createCallbackArray.apply(null,arguments);var func=cbarr[0];var scope=cbarr[1];var args=cbarr[2];return function(){var argx=ecma.util.args(arguments);return func.apply(scope||this,argx.concat(args));}};this.createCallbackArray=function(func,scope,args){if(!args)args=[];if(typeof(func)!='function'&&func.length){if(func[2])args=args.concat(func[2]);scope=func[1];func=func[0];}
return[func,scope,args];}
this.callback=function(func,scope,args){var cbarr=ecma.lang.createCallbackArray(func,scope,args);return cbarr[0].apply(cbarr[1],cbarr[2]);};this.assert=function(expression,msg){if(!msg)msg='Assertion failed';if(expression)return;if(ecma.window.console.trace)ecma.window.console.trace(msg);throw new ecma.error.Assertion(msg);};});ECMAScript.Extend('lang',function(ecma){this.Constructor=function(){return ecma.lang.createConstructor.apply(this,arguments);};this.Methods=function(){return ecma.lang.createMethods.apply(this,arguments);};this.Callback=function(){return ecma.lang.createCallback.apply(this,arguments);};});ECMAScript.Extend('util',function(ecma){this.defined=function(unk){return unk===null?false:typeof(unk)=='undefined'?false:true;};this.isa=function(unk,klass){if(!klass)return false;if(unk instanceof klass)return true;if(unk&&unk.__bases__){for(var i=0;i<unk.__bases__.length;i++){if(ecma.util.isa(unk.__bases__[i],klass))return true;}}
return false;};this.isObject=function(unk){return unk&&unk.constructor&&typeof(unk)=='object';};this.isArray=function(unk){if(!ecma.util.isObject(unk))return false;return typeof(unk.constructor.prototype.push)=='function';};this.isAssociative=function(unk){if(!ecma.util.isObject(unk))return false;if(unk.__bases__){for(var i=0,base;base=unk.__bases__[i];i++){if(!ecma.util.isArray(base))return true;}}else{return!ecma.util.isArray(unk);}
return false;};this.args=function(args){if(!args)return[];var len=args.length||0;var result=new Array(len);while(len--)result[len]=args[len];return result;};this.use=function(){var args=this.args(arguments);var scope=args.shift();for(var i=0;i<args.length;i++){var ns=args[i];for(var name in ns){if(ecma.util.defined(scope[name])){throw"'"+name+"' is already defined in this scope: "+scope;}
scope[name]=ns[name];}}};this.evar=function(unk,scope){if(!unk||typeof(unk)!='string')throw'Provide a String';if(!unk.match(/[A-Za-z_\$][A-Za-z_\$\.0-9]+/))throw'Illegal object address';var result=undefined;try{if(scope){var func=function(){return eval(unk);}
result=func.apply(scope,[]);}else{result=eval(unk);}}catch(ex){}
return result;};this.asInt=function(unk,gez){var i=unk;if(typeof(unk)=='string'){i=parseInt(unk.replace("\w",""));}else{i=parseInt(unk);}
return isNaN(i)?0:gez&&i<0?0:i;};this.randomId=function(prefix,multiplier){if(!multiplier)multiplier=100000;var n=Math.floor(Math.random()*multiplier);return prefix?prefix+n:n;};var _incrementalIdMap=new Object();this.incrementalId=function(prefix,width){var idx=_incrementalIdMap[prefix];idx=_incrementalIdMap[prefix]=idx==null?1:idx+1;return width?prefix+ecma.util.pad(idx,width):prefix+idx;};this.pad=function(src,width,chr,rtl){if(!chr)chr='0';if(!rtl)rtl=false;if(width>100)throw new ecma.error.IllegalArg('width');if(width<1)throw new ecma.error.IllegalArg('width');if(chr.length!=1)throw new ecma.error.IllegalArg('chr');var len=new String(src).length;if(len>width)return src;var result=rtl?''+src:'';for(var i=len;i<width;i++){result+=chr;}
return rtl?result:result+src;};this.grep=function(target,a){if(!a||!ecma.util.defined(a.length))return null;var result=[];var func=target instanceof Function?target:function(a){return a==target;};for(var i=0;i<a.length;i++){if(func(a[i]))result.push(a[i]);}
return result.length>0?result:null;};this.overlay=function(){var args=ecma.util.args(arguments);var dest=args.shift();if(typeof(dest)!='object')throw'invalid argument';for(var i=0;i<args.length;i++){var src=args[i];if(!ecma.util.defined(src))continue;if(typeof(dest)!=typeof(src))throw'type mismatch';if(dest===src)continue;for(var k in src){if(typeof(dest[k])=='function'){dest[k]=src[k];}else if(typeof(dest[k])=='object'){this.overlay(dest[k],src[k]);}else{dest[k]=src[k];}}}
return dest;};this.keys=function(obj){if(!(obj instanceof Object))return null;var result=[];for(var k in obj){result.push(k);}
return result;};this.values=function(obj){if(!(obj instanceof Object))return null;var result=[];for(var k in obj){result.push(obj[k]);}
return result;};this.step=function(arr,func,scope,args){if(!ecma.util.isArray(arr))throw new ecma.error.IllegalArg('arr');if(typeof(func)!='function')throw new ecma.error.IllegalArg('func');if(!args)args=[];if(typeof(args.shift)!='function')args=ecma.util.args(args);if(!ecma.util.isArray(args))throw new ecma.error.IllegalArg('args');var errors=[];for(var i=0;i<arr.length;i++){try{args.unshift(arr[i]);func.apply(scope,args);}catch(ex){errors.push(ex);}finally{args.shift();continue;}}
if(errors.length){throw new js.error.Multiple(errors);}}});ECMAScript.Extend('error',function(ecma){this.Assertion=function(){Error.apply(this,arguments);};this.Assertion.prototype=ecma.lang.createMethods(Error);this.MissingArg=function(name){var message='Missing argument: '+name;Error.apply(this,[message]);};this.MissingArg.prototype=ecma.lang.createMethods(Error);this.IllegalArg=function(name){var message='Illegal argument: '+name;Error.apply(this,[message]);};this.IllegalArg.prototype=ecma.lang.createMethods(Error);this.Multiple=function(errors){this.errors=errors;this.message='Multiple exceptions';Error.apply(this,[this.message]);};this.Multiple.prototype=ecma.lang.createMethods(Error);this.Multiple.prototype.toString=function(){var result=this.message+"\n";for(var i=0,ex;ex=this.errors[i];i++){result+='  Exception #'+i+': '+ex.toString()+"\n";}
return result;};});ECMAScript.Extend('crypt',function(ecma){var hexcase=0;var b64pad="";var chrsz=8;this.hex_sha1=function(s){return binb2hex(core_sha1(str2binb(s),s.length*chrsz));}
this.b64_sha1=function(s){return binb2b64(core_sha1(str2binb(s),s.length*chrsz));}
this.str_sha1=function(s){return binb2str(core_sha1(str2binb(s),s.length*chrsz));}
this.hex_hmac_sha1=function(key,data){return binb2hex(core_hmac_sha1(key,data));}
this.b64_hmac_sha1=function(key,data){return binb2b64(core_hmac_sha1(key,data));}
this.str_hmac_sha1=function(key,data){return binb2str(core_hmac_sha1(key,data));}
function sha1_vm_test()
{return hex_sha1("abc")=="a9993e364706816aba3e25717850c26c9cd0d89d";}
function core_sha1(x,len)
{x[len>>5]|=0x80<<(24-len%32);x[((len+64>>9)<<4)+15]=len;var w=Array(80);var a=1732584193;var b=-271733879;var c=-1732584194;var d=271733878;var e=-1009589776;for(var i=0;i<x.length;i+=16)
{var olda=a;var oldb=b;var oldc=c;var oldd=d;var olde=e;for(var j=0;j<80;j++)
{if(j<16)w[j]=x[i+j];else w[j]=rol(w[j-3]^w[j-8]^w[j-14]^w[j-16],1);var t=safe_add(safe_add(rol(a,5),sha1_ft(j,b,c,d)),safe_add(safe_add(e,w[j]),sha1_kt(j)));e=d;d=c;c=rol(b,30);b=a;a=t;}
a=safe_add(a,olda);b=safe_add(b,oldb);c=safe_add(c,oldc);d=safe_add(d,oldd);e=safe_add(e,olde);}
return Array(a,b,c,d,e);}
function sha1_ft(t,b,c,d)
{if(t<20)return(b&c)|((~b)&d);if(t<40)return b^c^d;if(t<60)return(b&c)|(b&d)|(c&d);return b^c^d;}
function sha1_kt(t)
{return(t<20)?1518500249:(t<40)?1859775393:(t<60)?-1894007588:-899497514;}
function core_hmac_sha1(key,data)
{var bkey=str2binb(key);if(bkey.length>16)bkey=core_sha1(bkey,key.length*chrsz);var ipad=Array(16),opad=Array(16);for(var i=0;i<16;i++)
{ipad[i]=bkey[i]^0x36363636;opad[i]=bkey[i]^0x5C5C5C5C;}
var hash=core_sha1(ipad.concat(str2binb(data)),512+data.length*chrsz);return core_sha1(opad.concat(hash),512+160);}
function safe_add(x,y)
{var lsw=(x&0xFFFF)+(y&0xFFFF);var msw=(x>>16)+(y>>16)+(lsw>>16);return(msw<<16)|(lsw&0xFFFF);}
function rol(num,cnt)
{return(num<<cnt)|(num>>>(32-cnt));}
function str2binb(str)
{var bin=Array();var mask=(1<<chrsz)-1;for(var i=0;i<str.length*chrsz;i+=chrsz)
bin[i>>5]|=(str.charCodeAt(i/chrsz)&mask)<<(32-chrsz-i%32);return bin;}
function binb2str(bin)
{var str="";var mask=(1<<chrsz)-1;for(var i=0;i<bin.length*32;i+=chrsz)
str+=String.fromCharCode((bin[i>>5]>>>(32-chrsz-i%32))&mask);return str;}
function binb2hex(binarray)
{var hex_tab=hexcase?"0123456789ABCDEF":"0123456789abcdef";var str="";for(var i=0;i<binarray.length*4;i++)
{str+=hex_tab.charAt((binarray[i>>2]>>((3-i%4)*8+4))&0xF)+
hex_tab.charAt((binarray[i>>2]>>((3-i%4)*8))&0xF);}
return str;}
function binb2b64(binarray)
{var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var str="";for(var i=0;i<binarray.length*4;i+=3)
{var triplet=(((binarray[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((binarray[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((binarray[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(var j=0;j<4;j++)
{if(i*8+j*6>binarray.length*32)str+=b64pad;else str+=tab.charAt((triplet>>6*(3-j))&0x3F);}}
return str;}});ECMAScript.Extend('console',function(ecma){var _consoles=[];var _history=[];this.tee=function(console){if(console)_consoles.push(console);};this.log=function(){var args=ecma.util.args(arguments);var text=args.join(' ');_history.push(text);for(var i in _consoles){_consoles[i].log(_history.length+': '+text);}};this.flush=function(){for(var i=0;i<_history.length;i++){var text=_history[i];for(var j in _consoles){_consoles[j].log((i+1)+': '+text);}}}
this.trace=function(){for(var i in _consoles){if(_consoles[i].trace)_consoles[i].trace();}};this.history=function(){return _history;};});ECMAScript.Extend('data.base64',function(ecma){var _keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function _utf8_encode(str){if(typeof(str)!='string'){str=new String(str);}
str=str.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<str.length;n++){var c=str.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c);}
else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}
else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}
return utftext;}
function _utf8_decode(utftext){var str="";var i=0;var c=c2=c3=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){str+=String.fromCharCode(c);i++;}
else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);str+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}
else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);str+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return str;}
this.encode=function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=_utf8_encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}
output=output+
_keyStr.charAt(enc1)+_keyStr.charAt(enc2)+
_keyStr.charAt(enc3)+_keyStr.charAt(enc4);}
return output;};this.decode=function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=_keyStr.indexOf(input.charAt(i++));enc2=_keyStr.indexOf(input.charAt(i++));enc3=_keyStr.indexOf(input.charAt(i++));enc4=_keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2);}
if(enc4!=64){output=output+String.fromCharCode(chr3);}}
output=_utf8_decode(output);return output;};});ECMAScript.Extend('data.entities',function(ecma){function _isMarkup(cc){return cc==34||cc==38||cc==60||cc==62;}
function _isLower(cc){return cc<32&&cc!=9&&cc!=10&&cc!=13;}
function _isUpper(cc){return cc>=127;}
this.decode=function(s,bHtml){result='';for(i=0;i<s.length;i++){cc=s.charCodeAt(i);if(_isLower(cc)||_isUpper(cc)||(bHtml&&_isMarkup(cc))){var named=charCodeToNamedMap[cc];if(named){result+='&'+named+';';}else{result+='&#'+cc+';';}}else{result+=s.charAt(i);}}
return result;};var charCodeToNamedMap={34:'quot',38:'amp',60:'lt',62:'gt',160:'nbsp',161:'iexcl',162:'cent',163:'pound',164:'curren',165:'yen',166:'brvbar',167:'sect',168:'uml',169:'copy',170:'ordf',171:'laquo',172:'not',173:'shy',174:'reg',175:'macr',176:'deg',177:'plusmn',178:'sup2',179:'sup3',180:'acute',181:'micro',182:'para',183:'middot',184:'cedil',185:'sup1',186:'ordm',187:'raquo',188:'frac14',189:'frac12',190:'frac34',191:'iquest',192:'Agrave',193:'Aacute',194:'Acirc',195:'Atilde',196:'Auml',197:'Aring',198:'AElig',199:'Ccedil',200:'Egrave',201:'Eacute',202:'Ecirc',203:'Euml',204:'Igrave',205:'Iacute',206:'Icirc',207:'Iuml',208:'ETH',209:'Ntilde',210:'Ograve',211:'Oacute',212:'Ocirc',213:'Otilde',214:'Ouml',215:'times',216:'Oslash',217:'Ugrave',218:'Uacute',219:'Ucirc',220:'Uuml',221:'Yacute',222:'THORN',223:'szlig',224:'agrave',225:'aacute',226:'acirc',227:'atilde',228:'auml',229:'aring',230:'aelig',231:'ccedil',232:'egrave',233:'eacute',234:'ecirc',235:'euml',236:'igrave',237:'iacute',238:'icirc',239:'iuml',240:'eth',241:'ntilde',242:'ograve',243:'oacute',244:'ocirc',245:'otilde',246:'ouml',247:'divide',248:'oslash',249:'ugrave',250:'uacute',251:'ucirc',252:'uuml',253:'yacute',254:'thorn',255:'yuml',338:'OElig',339:'oelig',352:'Scaron',353:'scaron',376:'Yuml',402:'fnof',710:'circ',732:'tilde',913:'Alpha',914:'Beta',915:'Gamma',916:'Delta',917:'Epsilon',918:'Zeta',919:'Eta',920:'Theta',921:'Iota',922:'Kappa',923:'Lambda',924:'Mu',925:'Nu',926:'Xi',927:'Omicron',928:'Pi',929:'Rho',931:'Sigma',932:'Tau',933:'Upsilon',934:'Phi',935:'Chi',936:'Psi',937:'Omega',945:'alpha',946:'beta',947:'gamma',948:'delta',949:'epsilon',950:'zeta',951:'eta',952:'theta',953:'iota',954:'kappa',955:'lambda',956:'mu',957:'nu',958:'xi',959:'omicron',960:'pi',961:'rho',962:'sigmaf',963:'sigma',964:'tau',965:'upsilon',966:'phi',967:'chi',968:'psi',969:'omega',977:'thetasym',978:'upsih',982:'piv',8194:'ensp',8195:'emsp',8201:'thinsp',8204:'zwnj',8205:'zwj',8206:'lrm',8207:'rlm',8211:'ndash',8212:'mdash',8216:'lsquo',8217:'rsquo',8218:'sbquo',8220:'ldquo',8221:'rdquo',8222:'bdquo',8224:'dagger',8225:'Dagger',8226:'bull',8230:'hellip',8240:'permil',8242:'prime',8243:'Prime',8249:'lsaquo',8250:'rsaquo',8254:'oline',8260:'frasl',8364:'euro',8465:'image',8472:'weierp',8476:'real',8482:'trade',8501:'alefsym',8592:'larr',8593:'uarr',8594:'rarr',8595:'darr',8596:'harr',8629:'crarr',8656:'lArr',8657:'uArr',8658:'rArr',8659:'dArr',8660:'hArr',8704:'forall',8706:'part',8707:'exist',8709:'empty',8711:'nabla',8712:'isin',8713:'notin',8715:'ni',8719:'prod',8721:'sum',8722:'minus',8727:'lowast',8730:'radic',8733:'prop',8734:'infin',8736:'ang',8743:'and',8744:'or',8745:'cap',8746:'cup',8747:'int',8756:'there4',8764:'sim',8773:'cong',8776:'asymp',8800:'ne',8801:'equiv',8804:'le',8805:'ge',8834:'sub',8835:'sup',8836:'nsub',8838:'sube',8839:'supe',8853:'oplus',8855:'otimes',8869:'perp',8901:'sdot',8968:'lceil',8969:'rceil',8970:'lfloor',8971:'rfloor',9001:'lang',9002:'rang',9674:'loz',9824:'spades',9827:'clubs',9829:'hearts',9830:'diams'};});ECMAScript.Extend('data',function(ecma){var baseClass=Object;var proto=ecma.lang.createMethods(baseClass);this.XFR=function(encoding){this.encoding=encoding;};this.XFR.prototype=proto;proto.getClass=function(symbol){return symbol=='%'?ecma.data.HashList:symbol=='@'?ecma.data.Array:symbol=='$'?String:null;};proto.createObject=function(symbol){var klass=this.getClass(symbol);return new klass();};proto.createValue=function(symbol,value){if(value=='true')return true;if(value=='false')return false;var klass=this.getClass(symbol);if(klass===String)return value;return new klass(value);};proto.encodeComponent=function(str){return this.encoding=='base64'?ecma.data.base64.encode(str):ecma.window.encodeURIComponent(str);};proto.decodeComponent=function(str){return this.encoding=='base64'?ecma.data.base64.decode(str):ecma.window.decodeURIComponent(str);};proto.parse=function(str,classMap){var CHash=this.getClass('%');var CArray=this.getClass('@');var CScalar=this.getClass('$');var m=str.match(/^([\%\$\@]){/);if(!m)throw'str must begin with "%{", "@{", or "${"';if(m[1]=='$'){var value=str.substr(2,(str.length-3));return this.decodeComponent(value);}
var root=this.createObject(m[1],null);var pos=2;var node=root;var nodeParent=root;var parents=[];while(true){var open_pos=str.indexOf('{',pos);var close_pos=str.indexOf('}',pos);if(close_pos<open_pos&&close_pos>=0){node=parents.pop()||root;pos=close_pos+1;continue;}
if(open_pos<0)break;var key=str.substr(pos,(open_pos-pos));var len=key.length-1;var type=key.substr(len,1);key=key.substr(0,len);key=this.decodeComponent(key);pos=open_pos+1;if(type=='%'||type=='@'){parents.push(node);nodeParent=node;node=this.createObject(type,nodeParent);if(ecma.util.isa(nodeParent,CHash)){nodeParent.setValue(key,node);}else if(ecma.util.isa(nodeParent,CArray)){nodeParent.push(node);}}else{if(!this.getClass(type))throw'invalid data type: '+type;open_pos=str.indexOf('{',pos);if(open_pos>=0&&open_pos<close_pos)close_pos=open_pos-1;var vstr=str.substr(pos,(close_pos-pos));vstr=this.decodeComponent(vstr);var value=this.createValue(type,vstr);if(ecma.util.isa(node,CHash)){node.setValue(key,value);}else if(ecma.util.isa(node,CArray)){node.push(value);}else if(node&&node.setValue instanceof Function){node.setValue(value);}else{nodeParent+=value;}
pos=close_pos+1;}}
return root;};proto.format=function(obj){var result='';if(!ecma.util.defined(obj))return'${}';if(obj.toXFR){return obj.toXFR();}else if(ecma.util.isArray(obj)){var result='@{';for(var i=0;i<obj.length;i++){result+=ecma.data.xfr.format(obj[i]);}
return result+'}';}else if(ecma.util.isAssociative(obj)){var result='%{';for(var k in obj){var v=obj[k];result+=this.encodeComponent(k)+ecma.data.xfr.format(v);}
return result+'}';}else{return'${'+this.encodeComponent(obj)+'}';}};});ECMAScript.Extend('data',function(ecma){this.xfr=new ecma.data.XFR('base64');});ECMAScript.Extend('data',function(ecma){function _crossCheck(node){if(!ecma.util.isa(node,ecma.data.Node)){throw'child is not a data node';}
if(node.parentNode!==this){throw'child belongs to another parent';}}
function _setChildMembers(){this.firstChild=this.childNodes[0];this.lastChild=this.childNodes[this.childNodes.length-1];}
function _relink(index){for(var i=index-1;i<=index+1;i++){if(i<0)continue;if(i>=this.childNodes.length)break;var prevNode=i<1?null:this.childNodes[i-1];var currNode=i<this.childNodes.length?this.childNodes[i]:null;var nextNode=i<=this.childNodes.length?this.childNodes[i+1]:null;if(prevNode)prevNode.nextSibling=currNode;if(currNode)currNode.previousSibling=prevNode;if(currNode)currNode.nextSibling=nextNode;if(nextNode)nextNode.previousSibling=currNode;}}
function _unlink(node){return node.parentNode?node.parentNode.removeChild(node):node;}
function _vivify(node){return ecma.util.isa(node,ecma.data.Node)?node:this.createNode.apply(this,arguments);}
this.Node=function(data){this.data=data;this.childNodes=[];this.parentNode=null;this.previousSibling=null;this.nextSibling=null;this.firstChild=null;this.lastChild=null;this.index=null;};this.Node.prototype={createNode:function(data){return new ecma.data.Node(data);},appendChild:function(node){node=_vivify.apply(this,arguments);_unlink.call(this,node);node.previousSibling=this.lastChild;node.nextSibling=null;if(this.lastChild)this.lastChild.nextSibling=node;this.childNodes.push(node);node.index=this.childNodes.length-1;node.parentNode=this;_setChildMembers.call(this);this.onAdopt(node);return node;},insertBefore:function(node,child,args){_crossCheck.call(this,child);if(args){args.unshift(node)}else{args=[node];}
node=_vivify.apply(this,args);_unlink.call(this,node);var index=child.index;result=this.childNodes.splice(index,0,node);for(var i=index;i<this.childNodes.length;i++){this.childNodes[i].index=i;}
_relink.call(this,index);node.parentNode=this;_setChildMembers.call(this);this.onAdopt(node);return node;},insertAfter:function(node,child){_crossCheck.call(this,child);return child.nextSibling?this.insertBefore(node,child.nextSibling):this.appendChild(node);},removeChild:function(node){_crossCheck.call(this,node);var result=null;var index=0;for(;index<this.childNodes.length;index++){if(this.childNodes[index]===node){result=this.childNodes.splice(index,1);break;}}
if(!result){throw'programatic error, known child not found';}
for(var i=index;i<this.childNodes.length;i++){this.childNodes[i].index--;}
_relink.call(this,index);_setChildMembers.call(this);result.previousSibling=null;result.nextSibling=null;result.parentNode=null;result.index=null;this.onOrphan(result);return result;},replaceChild:function(node,child,args){_crossCheck.call(this,child);if(args){args.unshift(node)}else{args=[node];}
node=_vivify.apply(this,args);_unlink.call(this,node);node.previousSibling=child.previousSibling;node.nextSibling=child.nextSibling;node.index=child.index;var result=this.childNodes[child.index];this.childNodes[child.index]=node;node.parentNode=this;_setChildMembers.call(this);this.onAdopt(node);return result;},walk:function(callback,scope){var node=this.firstChild;while(node){try{callback.call(scope||this,node);}catch(ex){if(ex=='break'){break;}else if(ex!='continue'){throw ex;}}
if(node.hasChildNodes())node.walk(callback,scope);node=node.nextSibling;}},hasChildNodes:function(){return this.childNodes.length>0;},onAdopt:function(){},onOrphan:function(){}};});ECMAScript.Extend('data',function(ecma){this.addr_split=function(addr){if(!ecma.util.defined(addr)||addr===""||addr=='/')return[];if(addr instanceof Array)return addr;if(typeof(addr)!='string')return[addr];return addr.replace(/^\//,'').split('/');};this.addr_normalize=function(addr){if(!ecma.util.defined(addr)||addr==="")return'';if(typeof(addr)=='string'){addr=addr.replace(/\/{2,}/g,'/');if(addr=='/')return addr;addr=addr.replace(/\/$/,'');return addr;}};this.addr_ext=function(addr){var lastKey=this.addr_split(addr).pop();if(!lastKey)return;if(typeof(lastKey)!='string')return;if(lastKey.indexOf('.')<=0)return;return lastKey.split('.').pop();};this.addr_parent=function(addr){var parts=this.addr_split(addr);parts.pop();var result=parts.length?parts.join('/'):'';return addr.indexOf('/')==0?'/'+result:result;};this.addr_name=function(addr){var parts=this.addr_split(addr);return parts.pop();};this.addr_join=function(){var args=ecma.util.args(arguments);var addr=args.shift();if(!addr)throw'Missing Argument: addr';var list=addr instanceof Array?addr:[addr];list=list.concat(args);return ecma.data.addr_normalize(list.join('/').replace(/^\/\//,'/'));};});ECMAScript.Extend('data',function(ecma){this.Container=function(){};this.Container.prototype.get=ecma.lang.createAbstractFunction();this.Container.prototype.get=function(addr){var parts=ecma.data.addr_split(addr);var c=this;for(var i=0;i<parts.length;i++){if(typeof(c)=='undefined'||!c.getValue)return;c=c.getValue(parts[i]);}
return c;};this.Container.prototype.set=function(addr,value){var parts=ecma.data.addr_split(addr);var lastKey=parts.pop();if(ecma.util.defined(lastKey)){var ptr=this;for(var i=0;i<parts.length;i++){var key=parts[i];var node=ptr.getValue(key);if(!ecma.util.defined(node)){node=ptr.setValue(key,new ecma.data.HashList());}
ptr=node;}
return ptr.setValue(lastKey,value);}else if(ecma.util.isa(value,ecma.data.Container)){this.clear();value.iterate(function(k,v){this.set(k,v);},this);}};this.Container.prototype.remove=function(addr){var parts=ecma.data.addr_split(addr);var lastKey=parts.pop();if(!ecma.util.defined(lastKey))return;var parent=this.get(parts);if(ecma.util.isa(parent,ecma.data.Container))parent.removeValue(lastKey);};this.Container.prototype.walk=function(callback,scope,prefix,depth){if(!depth)depth=0;this.iterate(function(k,v){var addr=ecma.util.defined(prefix)?prefix+'/'+k:k;callback.apply(scope,[k,v,depth,addr,this]);if(ecma.util.isa(v,ecma.data.Container)){v.walk(callback,scope,addr,(depth+1));}},this);};this.Container.prototype.toObject=function(){var result=ecma.util.isa(this,ecma.data.Array)?[]:{};this.iterate(function(k,v){result[k]=typeof(v.toObject)=='function'?v.toObject():v;},this);return result;};this.Container.prototype.toXFR=function(){var result='';this.iterate(function(k,v){result+=ecma.data.xfr.encodeComponent(k);result+=v.toXFR?v.toXFR():'${'+ecma.data.xfr.encodeComponent(v)+'}';},this);return result;};});ECMAScript.Extend('data',function(ecma){this.Array=function(){this.clear();var args=ecma.util.args(arguments);if(args){this.data=args;this.length=this.data.length;}};this.Array.prototype=ecma.lang.Methods(ecma.data.Container);this.Array.prototype.clear=function(){this.data=[];this.length=0;};this.Array.prototype.getValue=function(key){return this.data[key];};this.Array.prototype.setValue=function(key,value){if(typeof(key)!='number')key=ecma.util.asInt(key);var result=this.data[key]=value;this.length=this.data.length;return result;};this.Array.prototype.indexOfValue=function(value){for(var i=0;i<this.data.length;i++){if(this.data[i]===value)return i;}
return null;};this.Array.prototype.push=function(value){return this.setValue(this.data.length,value);};this.Array.prototype.removeValue=function(key){if(typeof(key)!='number')key=ecma.util.asInt(key);var result=this.data.splice(key,1);this.length=this.data.length;return result;};this.Array.prototype.keys=function(){var result=[];for(var i=0;i<this.data.length;i++){result.push(i);}
return result;};this.Array.prototype.values=function(){return this.data;};this.Array.prototype.iterate=function(cb,scope){for(var i=0;i<this.data.length;i++){ecma.lang.callback(cb,scope,[i,this.data[i]]);}};this.Array.prototype.toXFR=function(){var result='';this.iterate(function(k,v){result+=v.toXFR?v.toXFR():'${'+ecma.data.xfr.encodeComponent(v)+'}';},this);return'@{'+result+'}';};});ECMAScript.Extend('data',function(ecma){this.HashList=function(){this.clear();for(var i=0;arguments&&i<arguments.length;i+=2){var k=arguments[i];var v=arguments[i+1];this.indicies.push(k);this.data[k]=v;}
this.length=this.indicies.length;};this.HashList.prototype=ecma.lang.Methods(ecma.data.Container);this.HashList.prototype.clear=function(){this.indicies=[];this.data={};this.length=0;};this.HashList.prototype.getValue=function(key){return this.data[key];};this.HashList.prototype.setValue=function(key,value,index){var currentIndex=this.indexOfKey(key);if(index){if(index<0||index>this.indicies.length)
throw new ecma.error.IllegalArgument('index');if(currentIndex!=null)this.indicies.splice(currentIndex,1);this.indicies.splice(index,0,key);}else{if(currentIndex==null)this.indicies.push(key);}
this.length=this.indicies.length;return this.data[key]=value;};this.HashList.prototype.indexOfKey=function(key){for(var i=0;i<this.indicies.length;i++){if(this.indicies[i]==key)return i;}
return null;};this.HashList.prototype.indexOfValue=function(value){for(var i=0;i<this.indicies.length;i++){if(this.data[this.indicies[i]]===value)return i;}
return null;};this.HashList.prototype.removeValue=function(key){for(var i=0;i<this.indicies.length;i++){if(this.indicies[i]==key){this.indicies.splice(i,1);break;}}
this.length=this.indicies.length;return delete this.data[key];};this.HashList.prototype.keys=function(){return this.indicies;};this.HashList.prototype.values=function(){var result=[];for(var i=0;i<this.indicies.length;i++){result.push(this.data[this.indicies[i]])}
return result;};this.HashList.prototype.iterate=function(cb,scope){for(var i=0;i<this.indicies.length;i++){var key=this.indicies[i];ecma.lang.callback(cb,scope,[key,this.data[key]]);}};this.HashList.prototype.toXFR=function(){return'%{'+ecma.data.Container.prototype.toXFR.apply(this,arguments)+'}';};this.OrderedHash=this.HashList;});ECMAScript.Extend('http',function(ecma){var proto={};this.Location=function(uri){if(uri){if(uri instanceof ecma.http.Location){this.copyLocation(uri);}else{this.parseUri(uri);}}else{this.copyDocumentLocation();}};this.Location.prototype=proto;proto.copyDocumentLocation=function(){this.copyLocation(ecma.document.location);};proto.copyLocation=function(loc){try{this.protocol=loc.protocol;this.hostname=loc.hostname;this.port=loc.port;this.pathname=loc.pathname;this.search=loc.search;this.hash=loc.hash;}catch(ex){this.protocol='';this.hostname='';this.port='';this.pathname='';this.search='';this.hash='';}};proto.getOrigin=function(){var origin=this.protocol+'//'+this.hostname;if(this.port)origin+=':'+this.port;return origin;};proto.isSameOrigin=function(loc){if(!(loc instanceof ecma.http.Location)){loc=new ecma.http.Location(loc);}
return loc.getOrigin()==this.getOrigin();};proto.isSameDocument=function(loc){if(!(loc instanceof ecma.http.Location)){loc=new ecma.http.Location(loc);}
return loc.getDocumentUri()==this.getDocumentUri();};proto.getUri=function(){return this.getOrigin()+this.getAddress()};proto.getDocumentUri=function(){return this.getOrigin()+this.pathname;};proto.getHref=function(){return new ecma.http.Location().isSameOrigin(this)?this.getAddress():this.getUri();};proto.getAddress=function(){return this.pathname+this.search+this.hash;};proto.getSearch=function(){return this.search?this.search.replace(/^\?/,''):'';};proto.getHash=function(){return this.hash?this.hash.replace(/^#/,''):'';};proto.addParameter=function(key,value){key=encodeURIComponent(key);value=encodeURIComponent(value);var prefix=this.search?this.search+'&':'?';return this.search=prefix+key+'='+value;};proto.getParameters=function(){var result={};if(!this.search)return result;var str=this.search.replace(/^\?/,'');if(!str)return result;var kvpairs=str.split(/[&;]/);for(var i=0;i<kvpairs.length;i++){var parts=kvpairs[i].split(/=/);var k=decodeURIComponent(parts.shift());var v=decodeURIComponent(parts.join());if(k==""&&v=="")continue;result[k]=result[k]!=undefined?result[k]instanceof Array?result[k].concat(v):[result[k],v]:v;}
return result;};proto.parseUri=function(uri){this.copyDocumentLocation();var href=undefined;if(uri.indexOf('//')==0){href=this.protocol+uri;}else if((uri.indexOf('?')==0)||(uri.indexOf('#')==0)){href=this.getOrigin()+this.pathname+uri;}else if(uri.indexOf('/')==0){href=this.getOrigin()+uri;}else if(uri.indexOf('://')==-1){var base=this.pathname.match(/\/$/)?this.pathname:ecma.data.addr_parent(this.pathname)+'/';href=this.getOrigin()+base+uri;}else{href=uri;}
var m=href.match(/^([^\/]+:)?\/\/([^\/#?:]*):?([0-9]*)([^#?]*)(\??[^#]*)(#?.*)/);if(!m)throw'cannot parse uri';this.protocol=m[1]?m[1].toLowerCase():ecma.document.location.protocol;this.hostname=m[2].toLowerCase();this.port=m[3]||'';this.pathname=m[4]||'';this.search=m[5]||'';this.hash=m[6]||'';};});ECMAScript.Extend('http',function(ecma){var _documentLocation=null
function _getDocumentLocation(){if(!_documentLocation)_documentLocation=new ecma.http.Location();return _documentLocation;}
this.HTTP_STATUS_NAMES={100:'Continue',101:'SwitchingProtocols',200:'Ok',201:'Created',202:'Accepted',203:'NonAuthoritativeInformation',204:'NoContent',205:'ResetContent',206:'PartialContent',300:'MultipleChoices',301:'MovedPermanently',302:'Found',303:'SeeOther',304:'NotModified',305:'UseProxy',306:'Unused',307:'TemporaryRedirect',400:'BadRequest',401:'Unauthorized',402:'PaymentRequired',403:'Forbidden',404:'NotFound',405:'MethodNotAllowed',406:'NotAcceptable',407:'ProxyAuthenticationRequired',408:'RequestTimeout',409:'Conflict',410:'Gone',411:'LengthRequired',412:'PreconditionFailed',413:'RequestEntityTooLarge',414:'RequestURITooLong',415:'UnsupportedMediaType',416:'RequestedRangeNotSatisfiable',417:'ExpectationFailed',500:'InternalServerError',501:'NotImplemented',502:'BadGateway',503:'ServiceUnavailable',504:'GatewayTimeout',505:'HTTPVersionNotSupported'};this.isSameOrigin=function(uri1,uri2){if(!(uri1))return false;var loc1=uri1 instanceof ecma.http.Location?uri1:new ecma.http.Location(uri1);var loc2=uri2||_getDocumentLocation();return loc1.isSameOrigin(loc2);};});ECMAScript.Extend('http',function(ecma){this.XHR_UNINITIALIZED=0;this.XHR_LOADING=1;this.XHR_LOADED=2;this.XHR_INTERACTIVE=3;this.XHR_COMPLETE=4;this.XHR_STATE_NAMES=['Uninitialized','Loading','Loaded','Interactive','Complete'];this.newXHR=function(){try{return new XMLHttpRequest();}catch(ex){try{return new ActiveXObject('Msxml2.XMLHTTP');}catch(ex){return new ActiveXObject('Microsoft.XMLHTTP');}}};this.Request=function(uri,options){this.uri=uri;this.method='GET';this.asynchronous=true;this.body=null;this.headers={'Accept':'*/*','Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'};this.events=[];var props={};for(var k in options){if(k.match(/^on/)){this.addEventListener(k,options[k]);}else{props[k]=options[k];}}
ecma.util.overlay(this,props);};this.Request.prototype.getEventListeners=function(type){var name=type.toLowerCase().replace(/^on/,'');return this.events[name];};this.Request.prototype.setEventListeners=function(type,listeners){var name=type.toLowerCase().replace(/^on/,'');this.events[name]=listeners;};this.Request.prototype.addEventListener=function(type,func,scope,args){var name=type.toLowerCase().replace(/^on/,'');var group=this.events[name];if(!group)group=this.events[name]=[];if(!scope)scope=this;if(!args)args=[];group.push([func,scope,args]);};this.Request.prototype.removeEventListener=function(type,func){var name=type.toLowerCase().replace(/^on/,'');var group=this.events[name];if(!group)return;for(var i=0;i<group.length;i++){var cb=group[i];var cbFunc=ecma.util.isArray(group[i])?group[i][0]:group[i]
if(cbFunc===func){group.splice(i--,1);break;}}};this.Request.prototype.getHeader=function(k,v){return this.headers[k];};this.Request.prototype.setHeader=function(k,v){return this.headers[k]=v;};this.Request.prototype.submit=function(body){this.body=this.parseBody(body);return this._submit();};this.Request.prototype._submit=function(){if(!ecma.http.isSameOrigin(this.uri))throw'SOP Violation';this.xhr=ecma.http.newXHR();this.xhr.open(this.method.toUpperCase(),this.uri,this.asynchronous);this.xhr.onreadystatechange=js.lang.Callback(this.onStateChange,this);for(var k in this.headers){this.xhr.setRequestHeader(k,this.headers[k]);}
this.fireEvent('Create');this.xhr.send(this.body);};this.Request.prototype.resubmit=function(){return this._submit();};this.Request.prototype.parseBody=function(body){if(!body)return null;if(ecma.util.isObject(body)){try{var result='';for(var k in body){var name=encodeURIComponent(k);var value=encodeURIComponent(body[k]);result+=name+'='+value+'&';}
return result;}catch(ex){return body;}}
return body;};this.Request.prototype.parseResponse=function(){};this.Request.prototype.onStateChange=function(){var state=this.xhr.readyState;if(state==ecma.http.XHR_COMPLETE){this.parseResponse();var name=ecma.http.HTTP_STATUS_NAMES[this.xhr.status];this.fireEvent(this.xhr.status);this.fireEvent(name);if(this.xhr.status>=200&&this.xhr.status<300){this.fireEvent('Success');}
if(this.xhr.status>=500&&this.xhr.status<600){this.fireEvent('Failure');}}
var name=ecma.http.XHR_STATE_NAMES[state];this.fireEvent(name);};this.Request.prototype.fireEvent=function(type){if(this['on'+type]){this['on'+type].call(this,this);}
var name=typeof(type)=='number'?type:type.toLowerCase();var group=this.events[name];if(!group)return;ecma.util.step(group,this.invokeListener,this);};this.Request.prototype.invokeListener=function(cb){var func,scope,args;var args=[this];if(ecma.util.isArray(cb)){func=cb[0];scope=cb[1];args=args.concat(cb[2]);}else{func=cb;scope=this;}
func.apply(scope,args);};});ECMAScript.Extend('platform',function(ecma){var _browsers=null;var _platforms=null;var _info=null;var _pkg=this;this.getInfo=function(){return _info;};this.Info=function(){this.browser=this.searchString(_browsers)||"An unknown browser";this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"an unknown version";this.os=this.searchString(_platforms)||"an unknown OS";},this.Info.prototype=proto={};proto.searchString=function(data){for(var i=0;i<data.length;i++){var dataString=data[i].string;var dataProp=data[i].prop;this.versionSearchString=data[i].versionSearch||data[i].identity;if(dataString){if(dataString.indexOf(data[i].subString)!=-1)
return data[i].identity;}
else if(dataProp)
return data[i].identity;}};proto.searchVersion=function(dataString){var index=dataString.indexOf(this.versionSearchString);if(index==-1)return;return parseFloat(dataString.substring(index+this.versionSearchString.length+1));};_browsers=[{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"OmniWeb"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{prop:window.opera,identity:"Opera"},{string:navigator.vendor,subString:"iCab",identity:"iCab"},{string:navigator.vendor,subString:"KDE",identity:"Konqueror"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.vendor,subString:"Camino",identity:"Camino"},{string:navigator.userAgent,subString:"Netscape",identity:"Netscape"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"},{string:navigator.userAgent,subString:"Gecko",identity:"Mozilla",versionSearch:"rv"},{string:navigator.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}];_platforms=[{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone/iPod"},{string:navigator.platform,subString:"Linux",identity:"Linux"}];_info=new _pkg.Info();this.isIE=_info.browser=='Explorer';this.isIE8=_info.browser=='Explorer'&&_info.version==8;});ECMAScript.Extend('dom',function(ecma){this.browser={isIE:!!(ecma.window.attachEvent&&ecma.window.navigator.userAgent.indexOf('Opera')===-1),isOpera:ecma.window.navigator.userAgent.indexOf('Opera')>-1,isWebKit:ecma.window.navigator.userAgent.indexOf('AppleWebKit/')>-1,isGecko:ecma.window.navigator.userAgent.indexOf('Gecko')>-1&&ecma.window.navigator.userAgent.indexOf('KHTML')===-1,isMobileSafari:!!ecma.window.navigator.userAgent.match(/Apple.*Mobile.*Safari/)},this.getEventPointer=function(event){var docElement=ecma.document.documentElement,body=ecma.dom.getRootElement()||{scrollLeft:0,scrollTop:0};return{x:event.pageX||(event.clientX+
(docElement.scrollLeft||body.scrollLeft)-
(docElement.clientLeft||0)),y:event.pageY||(event.clientY+
(docElement.scrollTop||body.scrollTop)-
(docElement.clientTop||0))};};this.getEventTarget=function(event){if(!event.target&&event.srcElement)return event.srcElement;return event.target;};this.addEventListener=function(target,type,listener,scope,args,useCapture){var elem=ecma.dom.getElement(target);if(!elem)throw new Error('No such element');if(!useCapture)useCapture=false;var name=type.toLowerCase().replace(/^on/,'');var func=scope||args?function(){var argz=ecma.util.args(arguments);return listener.apply(scope||this,argz.concat(args));}:listener;if(elem.addEventListener){elem.addEventListener(name,func,useCapture);}else if(elem.attachEvent){elem.attachEvent('on'+name,func);}else{throw new Error('Cannot add event listener');}
return func;};this.removeEventListener=function(target,type,listener,scope,useCapture){var elem=ecma.dom.getElement(target);if(!elem)throw new Error('No such element');if(!useCapture)useCapture=false;var name=type.toLowerCase().replace(/^on/,'');if(elem.removeEventListener){elem.removeEventListener(name,listener,useCapture);}else if(elem.detachEvent){elem.detachEvent('on'+name,listener);}else{throw'Cannot remove event listener';}}
this.stopEvent=function(event){if(!event)return;if(ecma.dom.browser.isIE){event.cancelBubble=true;event.returnValue=false;}else{event.preventDefault();event.stopPropagation();}
event.stopped=true;};this.setTimeout=function(func,delay,scope,args){var cb=function(){func.apply(scope||this,args||[]);};return ecma.window.setTimeout(cb,delay);};this.clearTimeout=function(id){return ecma.window.clearTimeout(id);};this.setInterval=function(func,interval,scope,args){var cb=function(){func.apply(scope||this,args||[]);};return ecma.window.setInterval(cb,interval);};this.clearInterval=function(id){return ecma.window.clearInterval(id);};this.waitUntil=function(func,cond,delay,scope,args){if(!ecma.util.defined(delay))delay=10;var decay=2;var cb=function(){if(cond.apply(scope||this,args||[])){func.apply(scope||this,args||[]);return true;}
return false;}
if(cb())return;var waitFunc;waitFunc=function(){if(cb())return;delay*=decay;ecma.dom.setTimeout(waitFunc,delay,scope,args);};ecma.dom.setTimeout(waitFunc,delay,scope,args);};this.getRootElement=function(){return ecma.document.rootElement||ecma.dom.getBody()||ecma.document.documentElement||ecma.document.lastChild||ecma.document;};this.getHead=function(){var heads=ecma.document.getElementsByTagName('head');return heads&&heads.length>0?heads[0]:ecma.dom.getRootElement();};this.getBody=function(){var bodies=ecma.document.getElementsByTagName('body');return bodies&&bodies.length>0?bodies[0]:undefined;};this.getFrame=function(id){if(typeof(id)=='object')return id;return frames[id]||ecma.dom.getElement(id);};this.getContentWindow=function(frameid){var iframe=ecma.dom.getFrame(frameid);if(!iframe)return;return iframe.contentWindow||iframe.window;};this.getContentDocument=function(frameid){var iframe=ecma.dom.getFrame(frameid);if(!iframe)return;return iframe.contentWindow?iframe.contentWindow.document:iframe.contentDocument||iframe.document;};this.getElementsByNodeType=function(elem,type){elem=ecma.dom.getElement(elem);if(!elem)return;var result=[];_getElementsByNodeType(elem,type,result,elem);return result;};function _getElementsByNodeType(elem,type,result,topElem){if(!elem)return;if(elem.nodeType==type&&elem!==topElem){result.push(elem);}else if(elem.childNodes){for(var i=0,node;node=elem.childNodes[i];i++){_getElementsByNodeType(node,type,result,topElem);}}}
this.canvas={getPosition:function(){var pos={windowX:ecma.dom.canvas.windowX(),windowY:ecma.dom.canvas.windowY(),scrollX:ecma.dom.canvas.scrollX(),scrollY:ecma.dom.canvas.scrollY(),pageX:ecma.dom.canvas.pageX(),pageY:ecma.dom.canvas.pageY()};pos.width=pos.windowX<pos.pageX?pos.pageX:pos.windowX;pos.height=pos.windowY<pos.pageY?pos.pageY:pos.windowY;return pos;},windowX:function(){var windowX=ecma.window.innerWidth||(ecma.document.documentElement&&ecma.document.documentElement.clientWidth)||ecma.dom.getRootElement().clientWidth||(ecma.document.documentElement&&ecma.document.documentElement.offsetWidth);return ecma.util.asInt(windowX);},windowY:function(){var windowY=ecma.window.innerHeight||(ecma.document.documentElement&&ecma.document.documentElement.clientHeight)||ecma.dom.getRootElement().clientHeight||(ecma.document.documentElement&&ecma.document.documentElement.offsetHeight);return ecma.util.asInt(windowY);},scrollX:function(){var scrollX=(ecma.document.documentElement&&ecma.document.documentElement.scrollLeft)||ecma.window.pageXOffset||ecma.dom.getRootElement().scrollLeft;return ecma.util.asInt(scrollX);},scrollY:function(){var scrollY=(ecma.document.documentElement&&ecma.document.documentElement.scrollTop)||ecma.window.pageYOffset||ecma.dom.getRootElement().scrollTop;return ecma.util.asInt(scrollY);},pageX:function(){var pageX=Math.max(ecma.util.asInt(ecma.document.documentElement.scrollWidth),ecma.util.asInt(ecma.dom.getRootElement().scrollWidth),ecma.util.asInt(ecma.dom.getRootElement().offsetWidth))
return ecma.util.asInt(pageX);},pageY:function(){var pageY=Math.max(ecma.util.asInt(ecma.document.documentElement.scrollHeight),ecma.util.asInt(ecma.dom.getRootElement().scrollHeight),ecma.util.asInt(ecma.dom.getRootElement().offsetHeight))
return ecma.util.asInt(pageY);}};this.getViewportPosition=function(){var c=ecma.dom.canvas.getPosition();return{'left':c.scrollX,'top':c.scrollY,'width':c.windowX,'height':c.windowY};};this.getElement=function(unk){return typeof(unk)=='object'?unk:typeof(unk)=='function'?unk():ecma.document.getElementById?ecma.document.getElementById(unk):ecma.document.all?ecma.document.all[unk]:ecma.document.layers?ecma.document.layers[unk]:false;};this.getParentElement=function(elem,tagName){elem=ecma.dom.getElement(elem);while(elem&&elem.parentNode){if(elem.parentNode.nodeType==1){if(!tagName||elem.parentNode.tagName==tagName){return elem.parentNode;}}
elem=elem.parentNode;}
return undefined;};this.getDescendantById=function(elem,id){elem=ecma.dom.getElement(elem);var result=null;if(elem.hasChildNodes()){for(var i=0,node;node=elem.childNodes[i];i++){if(node.id==id){result=node;}else{result=ecma.dom.getDescendantById(node,id);}
if(result)break;}}
return result;};this.createElement=function(){var args=ecma.util.args(arguments);var tagName=args.shift();if(!tagName)return;var attrs=args.shift();var children=args.shift();if(ecma.util.isArray(attrs)){children=attrs;attrs=undefined;}
var elem=undefined;if(tagName.nodeType){elem=tagName;}else if(tagName.indexOf('#')==0){var parts=tagName.split('=',2);if(parts.length==2){tagName=parts[0];if(!attrs)attrs={};if(attrs.nodeValue)throw'Multiple nodeValues';attrs.nodeValue=parts[1];}
if(tagName=='#text'){elem=ecma.document.createTextNode(attrs.nodeValue);}else{throw'Component not available: '+tagName;}
if(children)throw'Cannot append children to a #text node';return elem;}else{var parts=tagName.split('=',2);if(parts.length==2){tagName=parts[0];if(!attrs)attrs={};if(attrs.innerHTML)throw'Multiple innerHTMLs';attrs.innerHTML=parts[1];}
elem=attrs&&attrs.namespace&&ecma.document.createElementNS?ecma.document.createElementNS(attrs.namespace,tagName.toUpperCase()):ecma.document.createElement(tagName.toUpperCase());}
if(attrs){for(var k in attrs){if(!k)continue;if(k.toLowerCase()=='namespace')continue;var v=attrs[k];if(k.toLowerCase()=='style'&&typeof(v)=='object'){for(var k2 in v){var v2=v[k2];ecma.dom.setStyle(elem,k2,v2);}}else{ecma.dom.setAttribute(elem,k,v);}}}
if(children){ecma.dom.appendChildren(elem,ecma.dom.createElements.apply(ecma.dom,children));}
return elem;};this.createElements=function(){var args=ecma.util.args(arguments);var elems=new Array();while(args&&args.length>0){var attrs=null;var children=null;var childNodes=null;var elem=null;var tag=args.shift();if(!tag)continue;if(typeof(tag)!='string'&&tag.nodeType){elem=tag;}else{if(ecma.util.isAssociative(args[0])){attrs=args.shift();}
if(ecma.util.isArray(args[0])){children=args.shift();}
elem=ecma.dom.createElement(tag,attrs,children);}
elems.push(elem);}
return elems;};this.replaceChildren=function(elem,children){ecma.dom.removeChildren(elem);ecma.dom.appendChildren(elem,children);};this.appendChildren=function(elem,children){elem=ecma.dom.getElement(elem);if(!ecma.util.defined(elem))throw'elem not defined';if(!ecma.util.defined(children))throw new ecma.window.Error('missing children');for(var i=0;i<children.length;i++){var child=children[i];if(!ecma.util.defined(child))throw'undefined child node';if(child instanceof Array){ecma.dom.appendChildren(elem,child);}else{elem.appendChild(children[i]);}}};this.insertChildrenAfter=function(elem,children){elem=ecma.dom.getElement(elem);if(!ecma.util.defined(elem))throw'elem not defined';if(!ecma.util.defined(children))throw new ecma.window.Error('missing children');for(var i=0;i<children.length;i++){var child=children[i];if(!ecma.util.defined(child))throw'undefined child node';if(child instanceof Array){elem=ecma.dom.insertChildrenAfter(elem,child);}else{ecma.dom.insertAfter(child,elem);elem=elem.nextSibling;}}
return elem;};this.insertChildrenBefore=function(elem,children){elem=ecma.dom.getElement(elem);if(!ecma.util.defined(elem))throw'elem not defined';if(!ecma.util.defined(children))throw new ecma.window.Error('missing children');for(var i=0;i<children.length;i++){var child=children[i];if(!ecma.util.defined(child))throw'undefined child node';if(child instanceof Array){elem=ecma.dom.insertChildrenBefore(elem,child);}else{elem.parentNode.insertBefore(child,elem);}}
return elem;};this.insertAfter=function(elem,target){if(!(ecma.util.defined(target)&&ecma.util.defined(elem)))return;var p=target.parentNode;if(p.lastChild===target){p.appendChild(elem);}else{p.insertBefore(elem,target.nextSibling);}};this.removeChildren=function(elem){elem=ecma.dom.getElement(elem);if(!(elem&&elem.childNodes))return;for(var idx=elem.childNodes.length-1;idx>=0;idx--){elem.removeChild(elem.childNodes[idx]);}};this.removeElement=function(elem){elem=ecma.dom.getElement(elem);if(!elem)return;var pElem=elem.parentNode;if(!pElem)return;return pElem.removeChild(elem);};this.removeElements=function(){var args=ecma.util.args(arguments);while(args&&args.length>0){ecma.dom.removeElement(args.shift());}};this.removeElementOrphanChildren=function(elem){elem=ecma.dom.getElement(elem);if(!elem)return;var pElem=elem.parentNode;if(!pElem)return;while(elem.firstChild){pElem.insertBefore(elem.firstChild,elem);}
return pElem.removeChild(elem);};this.insertElementAdoptChildren=function(elem,parentElem){elem=ecma.dom.getElement(elem);parentElem=ecma.dom.getElement(parentElem);if(!(parentElem&&elem))return;if(parentElem.chilldNodes&&parentElem.chilldNodes.length>0){parentElem.insertBefore(elem,parentElem.firstChild);for(var i=1,node;node=parentElem.childNodes[i];i++){elem.appendChild(node);}}else{parentElem.appendChild(elem);}};this.replaceElement=function(newElem,elem){elem.parentNode.insertBefore(newElem,elem);return elem.parentNode.removeChild(elem);};this.isChildOf=function(elem,parentElem){var y=ecma.dom.getElement(parentElem);var x=ecma.dom.getElement(elem);while(x&&y){if(x===y)return true;if(x===x.parentNode)break;x=x.parentNode;}
return false;};this.makePositioned=function(elem){elem=ecma.dom.getElement(elem);var pos=ecma.dom.getStyle(elem,'position');if(pos=='static'||!pos){elem.style.position='relative';if(ecma.dom.browser.isOpera){ecma.dom.setStyle(elem,'top',0);ecma.dom.setStyle(elem,'left',0);}}
return elem;};this.getStyle=function(elem,propName){elem=ecma.dom.getElement(elem);if(!(elem&&propName))return;propName=ecma.dom.translateStyleName(propName);if(ecma.window.getComputedStyle){var hyphenated=ecma.util.asHyphenatedName(propName);var cs=ecma.document.defaultView.getComputedStyle(elem,undefined)
return cs?cs.getPropertyValue(hyphenated):undefined;}else if(elem.currentStyle){var camelCase=ecma.util.asCamelCaseName(propName);return elem.currentStyle[camelCase];}else{var camelCase=ecma.util.asCamelCaseName(propName);return elem.style[camelCase];}};this.setStyle=function(elem,propName,propValue,importance){var elem=ecma.dom.getElement(elem);if(!elem||!elem.style)return;propName=ecma.dom.translateStyleName(propName);if(ecma.util.defined(elem.style.setProperty)){elem.style.setProperty(propName,propValue,importance?importance:null);}else{propName=ecma.util.asCamelCaseName(propName);try{elem.style[propName]=propValue;}catch(ex){if(ecma.dom.browser.isIE){if(ex instanceof Object){ex.message='Cannot set style "'+propName+'" to "'+propValue+'".';ex.description=ex.message;ecma.console.log(ex.message);}}
throw ex;}}};this.translateAttributeName=function(name){if(name=='className'||name=='class'&&ecma.platform.isIE){if(ecma.document.documentMode&&ecma.document.documentMode>7){return'class';}else{return'className';}}
return name;};this.translateStyleName=function(name){if(name=='cssFloat'&&!ecma.dom.browser.isIE)return'float';if(name=='cssFloat'&&ecma.dom.browser.isIE)return'styleFloat';if(name=='float'&&ecma.dom.browser.isIE)return'styleFloat';if(name=='float'&&ecma.dom.browser.isOpera)return'cssFloat';return name;};this.setStyles=function(elem,styles,importance){for(var name in styles){ecma.dom.setStyle(elem,name,styles[name],importance);}};this.removeStyle=function(elem,propName){elem=ecma.dom.getElement(elem);propName=ecma.dom.translateStyleName(propName);if(!elem)throw new ecma.error.MissingArg('elem');if(!propName)throw new ecma.error.MissingArg('propName');if(typeof(elem.style.removeProperty)=='function'){elem.style.removeProperty(propName);}else{propName=ecma.util.asCamelCaseName(propName);try{elem.style[propName]=null;}catch(ex){if(ex instanceof Object){ex.description='Cannot remove style "'+propName+'".';}
throw ex;}}};this.hasClassName=function(elem,name){var classAttr=ecma.dom.getAttribute(elem,'class');if(!classAttr)return false;var names=classAttr.split(/\s+/);for(var i=0;i<names.length;i++){if(names[i]==name)return true;}
return false;};this.setClassName=function(elem,name){ecma.dom.setAttribute(elem,'class',name);}
this.addClassName=function(elem,name){var classAttr=ecma.dom.getAttribute(elem,'class');var names=ecma.util.defined(classAttr)?classAttr.split(/\s+/):[];for(var i=0;i<names.length;i++){if(names[i]==name)return;}
names.push(name);ecma.dom.setAttribute(elem,'class',names.join(' '));}
this.addClassNames=function(){var args=ecma.util.args(arguments);var elem=args.shift();if(!elem)return;for(var i=0;i<args.length;i++){ecma.dom.addClassName(elem,args[i]);}};this.removeClassName=function(elem,name){var classAttr=ecma.dom.getAttribute(elem,'class');if(!classAttr)return;var names=classAttr.split(/\s+/);for(var i=0;i<names.length;i++){if(names[i]==name)names.splice(i--,1);}
ecma.dom.setAttribute(elem,'class',names.join(' '));}
this.removeClassNames=function(){var args=ecma.util.args(arguments);var elem=args.shift();if(!elem)return;for(var i=0;i<args.length;i++){ecma.dom.removeClassName(elem,args[i]);}};this.getAttribute=function(elem,attrName){var elem=ecma.dom.getElement(elem);if(!elem)return;if(typeof(attrName)!='string')return;if(attrName.indexOf('_')==0){var v1=elem.getAttribute(attrName);var v2=elem[attrName];return v1===null||v1===undefined?v2:v1;}else if(attrName.indexOf('on')==0){attrName=attrName.toLowerCase();return elem[attrName];}else{attrName=ecma.dom.translateAttributeName(attrName);if(!ecma.util.defined(elem.getAttribute)||attrName.toLowerCase()=='text'||attrName.indexOf('inner')==0){return elem[attrName];}else{return elem.getAttribute(attrName);}}};this.setAttribute=function(elem,attrName,attrValue){var elem=ecma.dom.getElement(elem);if(!elem)return;if(typeof(attrName)!='string')return;if(attrName.indexOf('_')==0){elem[attrName]=attrValue;}else if(attrName.toLowerCase()=='value'){elem.value=attrValue;}else if(attrName.indexOf('on')==0){var eventName=attrName.substr(2).toLowerCase();if(ecma.util.isArray(attrValue)){ecma.dom.addEventListener(elem,eventName,attrValue[0],attrValue[1],attrValue[2]);}else if(typeof(attrValue)=='function'){ecma.dom.addEventListener(elem,eventName,attrValue);}else{attrName=attrName.toLowerCase();elem[attrName]=attrValue;}}else{attrName=ecma.dom.translateAttributeName(attrName);if(!ecma.util.defined(elem.setAttribute)||attrName.toLowerCase()=='text'||attrName.indexOf('inner')==0){elem[attrName]=attrValue;}else{elem.setAttribute(attrName,attrValue);}}};this.removeAttribute=function(elem,attrName){elem=ecma.dom.getElement(elem);if(!elem)return;elem.removeAttribute(attrName);};this.setOpacity=function(elem,opacity){opacity=(Math.round(opacity*10000)/10000);if(ecma.dom.browser.isIE){opacity*=100;ecma.dom.setStyle(elem,'-ms-filter','alpha(opacity='+opacity+')');ecma.dom.setStyle(elem,'filter','alpha(opacity='+opacity+')');}else if(ecma.dom.browser.isGecko){ecma.dom.setStyle(elem,'-moz-opacity',opacity);ecma.dom.setStyle(elem,'opacity',opacity);}else if(ecma.dom.browser.isWebKit){ecma.dom.setStyle(elem,'-khtml-opacity',opacity);ecma.dom.setStyle(elem,'opacity',opacity);}else{ecma.dom.setStyle(elem,'opacity',opacity);}};this.getCenteredPosition=function(elem,contextElem){elem=ecma.dom.getElement(elem);var vp;if(contextElem){vp=ecma.dom.getElementPosition(contextElem);}else{vp=ecma.dom.getViewportPosition();}
var pos=ecma.dom.getElementPosition(elem);var x=vp['left']+(vp['width']/2)-(pos['width']/2);var y=vp['top']+(vp['height']/2)-(pos['height']/2);if(x<vp['left'])x=vp['left'];if(y<vp['top'])y=vp['top'];return{'top':y,'left':x};};this.setPosition=function(elem,props){elem=ecma.dom.getElement(elem);if(!props)props={'position':'top-third'}
var attrVisibility=elem.style.visibility;var attrDisplay=elem.style.display;elem.style.visibility='hidden';elem.style.display='block';var vp=ecma.dom.getViewportPosition();var xy=ecma.dom.getCenteredPosition(elem,props.contextElem);if(props.position=='top-third'){var h=ecma.dom.getHeight(elem);var t=(vp.height-h)/3;if(t<0)t=ecma.util.asInt(ecma.dom.canvas.scrollY());if(t<ecma.dom.canvas.scrollY())t+=ecma.dom.canvas.scrollY();elem.style.left=xy.left+"px";elem.style.top=t+"px";}else if(props.position=='center'){elem.style.left=xy.left+"px";elem.style.top=xy.top+"px";}else if(props.position=='bottom-left'){vp['left']+=ecma.util.asInt(ecma.dom.getStyle(elem,'padding-left'));vp['top']-=ecma.util.asInt(ecma.dom.getStyle(elem,'padding-bottom'));elem.style.left=vp['left']+'px';elem.style.top=(vp['top']+vp['height']-ecma.dom.getHeight(elem))+'px';}else if(props.position=='bottom-right'){elem.style.right='0px';elem.style.bottom='0px';}
elem.style.visibility=attrVisibility;elem.style.display=attrDisplay;};this.getElementPosition=function(elem){elem=ecma.dom.getElement(elem);return{'left':ecma.dom.getLeft(elem),'top':ecma.dom.getTop(elem),'width':ecma.dom.getWidth(elem),'height':ecma.dom.getHeight(elem)};};this.getInnerPosition=function(elem){return{'top':ecma.dom.getInnerTop(elem),'left':ecma.dom.getInnerLeft(elem),'right':ecma.dom.getInnerRight(elem),'bottom':ecma.dom.getInnerBottom(elem),'width':ecma.dom.getInnerWidth(elem),'height':ecma.dom.getInnerHeight(elem)};};this.getTop=function(elem){elem=ecma.dom.getElement(elem);if(!elem)return 0;var result=elem.getBBox?elem.getBBox().y:elem.offsetTop;result+=ecma.dom.getTop(elem.offsetParent);return isNaN(result)?0:result;};this.getBottom=function(elem){return ecma.dom.getTop(elem)+ecma.dom.getHeight(elem);};this.getLeft=function(elem){elem=ecma.dom.getElement(elem);if(!elem)return 0;var result=elem.getBBox?elem.getBBox().x:elem.offsetLeft;result+=ecma.dom.getLeft(elem.offsetParent);return isNaN(result)?0:result;};this.getRight=function(elem){return ecma.dom.getLeft(elem)+ecma.dom.getWidth(elem);};this.getWidth=function(elem){elem=ecma.dom.getElement(elem);var result=elem.getBBox?elem.getBBox().width:elem.offsetWidth;return isNaN(result)?0:result;};this.getHeight=function(elem){elem=ecma.dom.getElement(elem);var result=elem.getBBox?elem.getBBox().height:elem.offsetHeight;return isNaN(result)?0:result;};this.getInnerTop=function(elem){elem=ecma.dom.getElement(elem);if(!elem)return 0;var result=elem.getBBox?elem.getBBox().y:elem.offsetTop+elem.clientTop;result+=ecma.dom.getInnerTop(elem.offsetParent);return isNaN(result)?0:result;};this.getInnerBottom=function(elem){return ecma.dom.getInnerTop(elem)+ecma.dom.getInnerHeight(elem);};this.getInnerLeft=function(elem){elem=ecma.dom.getElement(elem);if(!elem)return 0;var result=elem.getBBox?elem.getBBox().x:elem.offsetLeft+elem.clientLeft;result+=ecma.dom.getInnerLeft(elem.offsetParent);return isNaN(result)?0:result;};this.getInnerRight=function(elem){return ecma.dom.getInnerLeft(elem)+ecma.dom.getInnerWidth(elem);};this.getInnerWidth=function(elem){elem=ecma.dom.getElement(elem);var result=elem.getBBox?elem.getBBox().width:elem.clientWidth-elem.clientLeft;;if(!result)result=elem.offsetWidth-elem.clientLeft;return isNaN(result)?0:result;};this.getInnerHeight=function(elem){elem=ecma.dom.getElement(elem);var result=elem.getBBox?elem.getBBox().height:elem.clientHeight-elem.clientTop;;if(!result)result=elem.offsetHeight-elem.clientTop;return isNaN(result)?0:result;};this.getValues=function(elem,tagNames){elem=ecma.dom.getElement(elem);if(!elem)return;var result={};if(!tagNames)tagNames=['input','textarea','select'];for(var i=0,tagName;tagName=tagNames[i];i++){var nodeList=elem.getElementsByTagName(tagName);for(var j=0,node;node=nodeList[j];j++){var name=ecma.dom.getAttribute(node,'name');if(!name)continue;var value=ecma.dom.getValue(node);if(result[name]&&!value)continue;result[name]=ecma.dom.getValue(node);}}
return result;};this.getValue=function(elem){function resolveValue(value){if(value.match(/^&:/)){return ecma.dom.getValue(value.replace(/^&:/,''));}
return value;}
var elem=ecma.dom.getElement(elem);if(!elem)return;var value=undefined;switch(elem.tagName.toUpperCase()){case'INPUT':switch(elem.type.toUpperCase()){case'HIDDEN':value=resolveValue(elem.value);break;case'CHECKBOX':value=elem.checked?ecma.util.defined(elem.value)?resolveValue(elem.value):true:undefined;break;case'RADIO':if(elem.checked){value=ecma.util.defined(elem.value)?resolveValue(elem.value):true;}else{value=undefined;}
break;case'SUBMIT':case'PASSWORD':case'TEXT':value=elem.value;break;default:throw'Unhandled input type: '+elem.type;}
break;case'TEXTAREA':case'SELECT':value=elem.value;break;default:if(ecma.util.defined(elem.innerHTML)){value=elem.innerHTML;}else{throw'Unhandled tag: '+elem.tagName;}}
return value;};this.setValue=function(elem,value){var elem=ecma.dom.getElement(elem);if(!elem)return;switch(elem.tagName.toUpperCase()){case'INPUT':switch(elem.type.toUpperCase()){case'HIDDEN':case'PASSWORD':case'TEXT':elem.value=value;break;case'CHECKBOX':case'RADIO':var checked=elem.checked;if(typeof(value)=='boolean'){checked=value;}else{if(value=='on'){checked=true;}else if(value=='off'){checked=false;}else{elem.value=value;}}
elem.checked=checked;break;default:throw'Unhandled input type: '+elem.type;}
break;case'TEXTAREA':case'SELECT':elem.value=value;break;case'PRE':if(ecma.dom.browser.isIE){var div=ecma.dom.createElement('div',{innerHTML:'<pre>'+value+'</pre>'});ecma.dom.replaceChildren(elem,div.childNodes);}else{ecma.dom.setAttribute(elem,'innerHTML',value);}
break;default:if(ecma.util.defined(elem.innerHTML)){ecma.dom.setAttribute(elem,'innerHTML',value);}else if(ecma.util.defined(elem.innerText)){ecma.dom.setAttribute(elem,'innerText',value);}else{throw'Unhandled tag: '+elem.tagName;}}
return value;};this.clearSelection=function(){if(ecma.document.selection&&ecma.document.selection.empty){ecma.document.selection.empty();}else if(ecma.window.getSelection){var sel=ecma.window.getSelection();sel.removeAllRanges();}};});ECMAScript.Extend('util',function(ecma){this.asHyphenatedName=function(name){function upperToHyphenLower(match){return'-'+match.toLowerCase();}
return name.replace(/[A-Z]/g,upperToHyphenLower);};this.asCamelCaseName=function(name){function ucFirstMatch(str,p1,offest,s){return p1.toUpperCase();}
return name.replace(/-([a-z])/g,ucFirstMatch);};});ECMAScript.Extend('dom.constants',function(ecma){this.ELEMENT_NODE=1;this.ATTRIBUTE_NODE=2;this.TEXT_NODE=3;this.CDATA_SECTION_NODE=4;this.ENTITY_REFERENCE_NODE=5;this.ENTITY_NODE=6;this.PROCESSING_INSTRUCTION_NODE=7;this.COMMENT_NODE=8;this.DOCUMENT_NODE=9;this.DOCUMENT_TYPE_NODE=10;this.DOCUMENT_FRAGMENT_NODE=11;this.NOTATION_NODE=12;});ECMAScript.Extend('dom.node',function(ecma){this.isElement=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.ELEMENT_NODE&&node.tagName!='!';};this.isAttribute=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.ATTRIBUTE_NODE;};this.isText=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.TEXT_NODE;};this.isCdataSection=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.CDATA_SECTION_NODE;};this.isEntityReference=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.ENTITY_REFERENCE_NODE;};this.isEntity=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.ENTITY_NODE;};this.isProcessingInstruction=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.PROCESSING_INSTRUCTION_NODE;};this.isComment=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.COMMENT_NODE;};this.isDocument=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.DOCUMENT_NODE;};this.isDocumentType=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.DOCUMENT_TYPE_NODE;};this.isDocumentFragment=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.DOCUMENT_FRAGMENT_NODE;};this.isNotation=function(node){node=ecma.dom.getElement(node);return node&&node.nodeType&&node.nodeType==ecma.dom.constants.NOTATION_NODE;};});ECMAScript.Extend('console',function(ecma){function _initBrowserConsole(){try{if(ecma.dom.browser.isOpera){ecma.console.tee(new ecma.console.Opera());return;}
var win=ecma.window;while(win){if(win.console){ecma.console.tee(win.console);ecma.console.flush();break;}
if(win.parent===win)break;win=win.parent;}}catch(ex){}}
if(ecma.window.parent!==ecma.window){_initBrowserConsole();}else{ecma.dom.addEventListener(ecma.window,'load',_initBrowserConsole);}
this.TextArea=function(elem){this.ta=ecma.dom.getElement(elem);};this.TextArea.prototype.log=function(msg){var t=this.ta.ownerDocument.createTextNode(msg+"\n");this.ta.appendChild(t);this.ta.appendChild(this.ta.ownerDocument.createElement('br'));this._scroll();};this.TextArea.prototype.trace=function(){this.log('[TODO stack trace]');this._scroll();};this.TextArea.prototype._scroll=function(){};this.Opera=function(){};this.Opera.prototype.log=function(){if(!arguments.length)return;var args=ecma.util.args(arguments);ecma.window.opera.postError(args.join(' '));};});ECMAScript.Extend('dom.include',function(ecma){var _loaded={};function _getHead(){var heads=ecma.document.getElementsByTagName('head');if(!(heads&&heads[0])){var doc=ecma.dom.getRootElement();var head=ecma.dom.createElement('head');doc.appendChild(head);return head;}
return heads[0];}
function _setLoaded(event,id,cb){var target=ecma.dom.getEventTarget(event);if(ecma.dom.browser.isIE){if(target.readyState.match(/complete|loaded/))_loaded[id]=true;}else{_loaded[id]=true;}
if(_loaded[id]&&cb){cb.apply(target);}}
this.hasLoaded=function(id){return id&&ecma.util.defined(_loaded[id])?_loaded[id]:false;};this.script=function(attrs,cb){var elem=attrs.id?ecma.dom.getElement(attrs.id):undefined;if(elem){if(cb)cb.apply(elem);return elem;}
if(!attrs.type)attrs.type='text/javascript';if(!attrs.id)attrs.id=ecma.util.randomId('script');var head=_getHead();elem=ecma.dom.createElement('script',attrs);if(attrs.text){head.appendChild(elem);_loaded[attrs.id]=true;if(cb)cb.apply(elem);}else{if(ecma.dom.browser.isIE){ecma.dom.addEventListener(elem,'readystatechange',_setLoaded,this,[attrs.id,cb]);}else{ecma.dom.addEventListener(elem,'load',_setLoaded,this,[attrs.id,cb]);}
_loaded[attrs.id]=false;head.appendChild(elem);}
return elem;};this.style=function(attrs){var elem=attrs.id?ecma.dom.getElement(attrs.id):undefined;if(elem)return elem;if(!attrs.id)attrs.id=ecma.util.randomId('css');if(!attrs.type)attrs.type='text/css';var head=_getHead();if(attrs.href){if(!attrs.rel)attrs.rel='stylesheet';elem=ecma.dom.createElement('link',attrs);}else{var text=attrs.text;delete attrs.text;elem=ecma.dom.createElement('style',attrs);if(ecma.dom.browser.isIE){elem.styleSheet.cssText=text;}else{elem.appendChild(ecma.document.createTextNode(text));}}
head.appendChild(elem);return elem;};});ECMAScript.Extend('dom',function(ecma){this.KeyPress=function(options){this.opts={'trace':false};ecma.util.overlay(this.opts,options);this.handlers={};this.listeners={};this.repeat={};this.events=[];return this;};this.KeyPress.prototype={setHandler:function(sequence,func,scope){func=typeof(func)=='function'?func:new Function(func);this.handlers[sequence]=[func,scope];return this;},setListener:function(sequence,func,scope){func=typeof(func)=='function'?func:new Function(func);this.listeners[sequence]=[func,scope];return this;},attach:function(elem){elem=ecma.dom.getElement(elem);this.events=this.events.concat([new ecma.dom.EventListener(elem,'keydown',this.onKeyDown,this),new ecma.dom.EventListener(elem,'keypress',this.onKeyPress,this),new ecma.dom.EventListener(elem,'keyup',this.onKeyUp,this)]);return this;},detach:function(elem){elem=ecma.dom.getElement(elem);for(var i=0,evt;evt=this.events[i];i++){if(evt.target!==elem)continue;evt.remove();this.events.splice(i--,1);}
return this;},onKeyDown:function(event){this.trace(event);var seq=this.getSequence(event);if(seq.ismod)return;var handler=this.getHandler(seq);var listener=this.getListener(seq);if(handler||listener){this.repeat[seq.ascii]=0;if(handler)this.doEvent(event,handler,seq);if(listener)this.doEventListener(event,listener,seq);}},onKeyPress:function(event){var seq=this.getSequence(event);if(seq.ismod)return;var handler=this.getHandler(seq);var listener=this.getListener(seq);if(handler||listener){var doEvent=false;if(ecma.util.defined(this.repeat[seq.ascii])){this.repeat[seq.ascii]++;doEvent=this.repeat[seq.ascii]>1;}else{doEvent=true;}
if(doEvent){if(handler)this.doEvent(event,handler,seq);if(listener)this.doEventListener(event,listener,seq);}}},onKeyUp:function(event){var seq=this.getSequence(event);if(seq.ismod)return;delete this.repeat[seq.ascii];},doEvent:function(event,handler,seq){if(event.stopped)return;return handler[1]?handler[0].apply(handler[1],[event,seq]):handler[0](event);},doEventListener:function(event,listener,seq){return listener[1]?listener[0].apply(listener[1],[event,seq]):listener[0](event);},getHandler:function(seq){return this.handlers[seq.ascii]||this.handlers[seq.numeric]||this.handlers['*'];},getListener:function(seq){return this.listeners[seq.ascii]||this.listeners[seq.numeric]||this.listeners['*'];},getSequence:function(event,numeric){var char_code=this.getCharCode(event);var ascii_code=String.fromCharCode(char_code).toLowerCase();var prefix=event.ctrlKey?"ctrl+":"";if(event.altKey)prefix+="alt+";if(event.shiftKey)prefix+="shift+";var seq={ascii:prefix,numeric:prefix+char_code,ismod:false};var is_special=true;if(ecma.dom.browser.isGecko){is_special=event.keyCode&&!event.charCode;}
if(!is_special){seq.ascii+=ascii_code;}else{switch(char_code){case 8:seq.ascii+='backspace';break;case 9:seq.ascii+='tab';break;case 13:seq.ascii+='enter';break;case 16:seq.ascii='shift';break;case 17:seq.ascii='ctrl';break;case 18:seq.ascii='alt';break;case 27:seq.ascii+='esc';break;case 37:seq.ascii+='left';break;case 38:seq.ascii+='up';break;case 39:seq.ascii+='right';break;case 40:seq.ascii+='down';break;case 46:seq.ascii+='delete';break;case 36:seq.ascii+='home';break;case 35:seq.ascii+='end';break;case 33:seq.ascii+='pageup';break;case 34:seq.ascii+='pagedown';break;case 45:seq.ascii+='insert';break;default:seq.ascii+=ascii_code;}}
seq.ismod='shift'==seq.ascii||'ctrl'==seq.ascii||'alt'==seq.ascii;return seq;},getCharCode:function(event){return event.which?event.which:event.keyCode?event.keyCode:event.charCode?event.charCode:0;},doesTargetNativelyHandleEvent:function(){return
event.target&&event.target.tagName&&(event.target.tagName.toUpperCase().match(/^(BUTTON|A)$/)||(event.target.tagName.toUpperCase()=='INPUT'&&event.target.type&&event.target.type.toUpperCase()=='SUBMIT'))&&(ascii_code=='enter'||ascii_code=='space');},trace:function(event){if(!this.opts.trace)return;var seq=this.getSequence(event);ecma.console.log('ASCII seq: ',seq.ascii);ecma.console.log('ASCII num: ',seq.numeric);ecma.console.log(' charCode: ',event.charCode);ecma.console.log('  keyCode: ',event.keyCode);ecma.console.log('    which: ',event.which);ecma.console.log('     type: ',event.type);}};});ECMAScript.Extend('dom',function(ecma){this.StyleSheet=function(id){this.id=id||ecma.util.randomId('css');this.style=undefined;this.sheet=undefined;this.cssRules=undefined;this.cssRulesByName=undefined;};this.StyleSheet.prototype={vivify:function(){this.style=ecma.dom.getElement(this.id)||ecma.dom.createElement('style',{id:this.id,type:'text/css',rel:'stylesheet',media:'screen'});ecma.dom.getHead().appendChild(this.style);this.sheet=this.style.sheet||this.style.styleSheet;this.cssRules=this.sheet.cssRules||this.sheet.rules;this.cssRulesByName={};},objToStr:function(obj,opts){var result='';for(var name in obj){if(ecma.util.defined(opts)&&ecma.util.defined(opts.exclude)){if(name.match(opts.exclude)){continue;}}
result+=name+':'+obj[name]+';';}
return result;},strToObj:function(str){str=str.replace(/\r?\n\r?/g,'');var result={};var items=str.split(';');for(var i=0;i<items.length-1;i++){var key=items[i].split(/:/,1);var value=items[i].substr(key[0].length+1);value=value.replace(/^\s+/,'');var name=key[0];result[name]=value;}
return result;},cssNameToJsName:function(name){if(name=='float')return'cssFloat';if(name=='class')return'className';return ecma.util.asCamelCaseName(name);},jsNameToCssName:function(name){if(name=='cssFloat')return'float';if(name=='className')return'class';return ecma.util.asHyphenatedName(name);},createRule:function(name,props){if(!this.style)this.vivify();var str=this.objToStr(props);var rule=null;var idx=-1;if(ecma.util.defined(this.sheet.addRule)){idx=this.sheet.rules.length;this.sheet.addRule(name,str);rule=this.sheet.rules[idx];}else if(ecma.util.defined(this.sheet.insertRule)){idx=this.sheet.cssRules.length;this.sheet.insertRule(name+' {'+str+'}',idx);rule=this.sheet.cssRules[idx];}
this.cssRulesByName[name]=rule;return rule;},updateRule:function(name,props){if(!this.style)this.vivify();var rule=this.cssRulesByName[name];if(rule){for(var propName in props){ecma.dom.setStyle(rule,propName,props[propName]);}}else{rule=this.createRule(name,props);}
return rule;}};});ECMAScript.Extend('dom',function(ecma){this.EventListener=function(target,type,listener,scope,args,useCapture){this.target=ecma.dom.getElement(target);this.type=type;this.scope=scope;this.useCapture=useCapture;this.func=ecma.dom.addEventListener(this.target,this.type,listener,this.scope,args,this.useCapture);};var proto=this.EventListener.prototype={};proto.remove=function(){ecma.dom.removeEventListener(this.target,this.type,this.func,this.scope,this.useCapture);};});ECMAScript.Extend('thread',function(ecma){this.spawn=function(func,scope,args){ecma.dom.setTimeout(func,0,scope,args);}});ECMAScript.Extend('lsn',function(ecma){var _pendingAuth=null;var CRequest=ecma.http.Request;var proto=ecma.lang.createMethods(CRequest);this.Request=function(uri,userOptions){var options=ecma.util.overlay({method:'POST',loginURI:'/res/login/login.dlg',headers:{'Accept':'text/data-xfr','X-Accept-Content-Encoding':'base64','X-Content-Format':'text/data-xfr','X-Content-Encoding':'base64'}},userOptions);CRequest.apply(this,[uri,options]);};this.Request.prototype=proto;proto.parseBody=function(body){return body?ecma.data.xfr.format(body):null;};proto.parseResponse=function(){var c_type=this.xhr.getResponseHeader('X-Content-Format');var c_enc=this.xhr.getResponseHeader('X-Content-Encoding');if(c_type&&c_type=='text/data-xfr'){var xfr=this.getXFR(c_enc);this.responseHash=xfr.parse(this.xhr.responseText);}};proto.getXFR=function(encoding){return new ecma.data.XFR(encoding);};proto.onUnauthorized=function(){if(this.uri==this.loginURI)return;if(!_pendingAuth){_pendingAuth=this.showLoginDialog();}else{this.wait=ecma.dom.setInterval(this.resubmitAfterAuth,1000,this);}};proto.onForbidden=function(){if(ecma.dom.browser.isOpera){this.onUnauthorized();}};proto.resubmitAfterAuth=function(){if(_pendingAuth)return;ecma.dom.clearInterval(this.wait);this.resubmit();};proto.showLoginDialog=function(){var loginDialog=new ecma.lsn.ui.LoginDialog(this.loginURI);loginDialog.dlg.show({onSuccess:ecma.lang.createCallback(function(){_pendingAuth=null;this.resubmit();},this),onCancel:ecma.lang.createCallback(function(){_pendingAuth=null;},this)});return loginDialog.dlg;};});ECMAScript.Extend('action',function(ecma){var proto={};this.ActionDispatcher=function(){this.actionListeners=[];};this.ActionDispatcher.prototype=proto;proto.normalizeActionName=function(name){if(!name)return;if(!name.toLowerCase)return;return name.toLowerCase().replace(/^on/,'');};proto.addActionListener=function(name,listener,scope,args){name=this.normalizeActionName(name);this.removeActionListener(name,listener,scope);this.actionListeners.push({'name':name,'listener':listener,'scope':scope,'args':args});};proto.removeActionListener=function(name,listener,scope){name=this.normalizeActionName(name);for(var i=0,props;props=this.actionListeners[i];i++){if(props.name!==name)continue;if(props.listener!==listener)continue;if(props.scope!==scope)continue;this.actionListeners.splice(i--,1);break;}};proto.getActionListenersByName=function(name){var result=[];for(var i=0,props;props=this.actionListeners[i];i++){if(props.name==name)result.push(props);}
return result;}
proto.executeAction=function(){var args=ecma.util.args(arguments);var name=this.normalizeActionName(args.shift());var group=this.getActionListenersByName(name);var actionEvent=new ecma.action.ActionEvent(name,this);args.unshift(actionEvent);ecma.util.step(group,this.executeActionListener,this,args);};proto.executeActionListener=function(){var argz=ecma.util.args(arguments);var props=argz.shift();props.listener.apply(props.scope||this,argz.concat(props.args));};proto.dispatchAction=function(name){var args=ecma.util.args(arguments);var name=this.normalizeActionName(args.shift());var group=this.getActionListenersByName(name);var actionEvent=new ecma.action.ActionEvent(name,this);args.unshift(actionEvent);ecma.util.step(group,this.dispatchActionListener,this,args);};proto.dispatchActionListener=function(){var argz=ecma.util.args(arguments);var props=argz.shift();ecma.thread.spawn(props.listener,props.scope||this,argz.concat(props.args));};});ECMAScript.Extend('action',function(ecma){this.ActionEvent=function(name,dispatcher){this.name=name;this.dispatcher=dispatcher;};var proto={};this.ActionEvent.prototype=proto;});ECMAScript.Extend('hub',function(ecma){var _controller=null;this.getInstance=function(){if(!_controller){if(ecma.window!==ecma.window.top){try{_controller=ecma.window.parent.js.hub.getInstance();}catch(ex){}}
if(!_controller){_controller=new ecma.hub.Controller();}}
return _controller;};this.ccd=function(type){return type=='directory'||type.match(/^file-(data|multipart)/)||type.match(/^data-(array|hash)/)?true:false;};var Icons={};Icons['application-wireframe.png']='/res/icons/16x16/nodes/application-wireframe.png';Icons['applications-internet.png']='/res/icons/16x16/nodes/applications-internet.png';Icons['bgleft.png']='/res/icons/16x16/nodes/bgleft.png';Icons['canexp.png']='/res/icons/16x16/nodes/canexp.png';Icons['data-array.png']='/res/icons/16x16/nodes/data-array.png';Icons['data-hash.png']='/res/icons/16x16/nodes/data-hash.png';Icons['data-scalar.png']='/res/icons/16x16/nodes/data-scalar.png';Icons['directories.png']='/res/icons/16x16/nodes/directories.png';Icons['directory.png']='/res/icons/16x16/nodes/directory.png';Icons['file-bmp.png']='/res/icons/16x16/nodes/file-bmp.png';Icons['file-csv.png']='/res/icons/16x16/nodes/file-csv.png';Icons['file-data-array.png']='/res/icons/16x16/nodes/file-data-array.png';Icons['file-data.png']='/res/icons/16x16/nodes/file-data.png';Icons['file-doc.png']='/res/icons/16x16/nodes/file-doc.png';Icons['file-flv.png']='/res/icons/16x16/nodes/file-flv.png';Icons['file-gif.png']='/res/icons/16x16/nodes/file-gif.png';Icons['file-jar.png']='/res/icons/16x16/nodes/file-jar.png';Icons['file-jpeg.png']='/res/icons/16x16/nodes/file-jpeg.png';Icons['file-jpg.png']='/res/icons/16x16/nodes/file-jpg.png';Icons['file-mp3.png']='/res/icons/16x16/nodes/file-mp3.png';Icons['file-multipart-html.png']='/res/icons/16x16/nodes/file-multipart-html.png';Icons['file-multipart.png']='/res/icons/16x16/nodes/file-multipart.png';Icons['file-pdf.png']='/res/icons/16x16/nodes/file-pdf.png';Icons['file-pm.png']='/res/icons/16x16/nodes/file-pm.png';Icons['file-png.png']='/res/icons/16x16/nodes/file-png.png';Icons['file-text-cgi.png']='/res/icons/16x16/nodes/file-text-cgi.png';Icons['file-text-css.png']='/res/icons/16x16/nodes/file-text-css.png';Icons['file-text-ht.png']='/res/icons/16x16/nodes/file-text-ht.png';Icons['file-text-html.png']='/res/icons/16x16/nodes/file-text-html.png';Icons['file-text-js.png']='/res/icons/16x16/nodes/file-text-js.png';Icons['file-text-pl.png']='/res/icons/16x16/nodes/file-text-pl.png';Icons['file-text-pm.png']='/res/icons/16x16/nodes/file-text-pm.png';Icons['file-text.png']='/res/icons/16x16/nodes/file-text.png';Icons['folders.png']='/res/icons/16x16/nodes/folders.png';Icons['isempty.png']='/res/icons/16x16/nodes/isempty.png';Icons['isexp.png']='/res/icons/16x16/nodes/isexp.png';Icons['mpe-bg.png']='/res/icons/16x16/nodes/mpe-bg.png';Icons['mpe-data-array.png']='/res/icons/16x16/nodes/mpe-data-array.png';Icons['mpe-data-hash.png']='/res/icons/16x16/nodes/mpe-data-hash.png';Icons['mpe-data-scalar.png']='/res/icons/16x16/nodes/mpe-data-scalar.png';Icons['mpe-end.png']='/res/icons/16x16/nodes/mpe-end.png';Icons['noexp.png']='/res/icons/16x16/nodes/noexp.png';Icons['unknown.png']='/res/icons/16x16/nodes/unknown.png';Icons['user-home.png']='/res/icons/16x16/nodes/user-home.png';this.getIcon=function(type){var parts=type.split('-');var icon=undefined;while(!icon&&parts.length>0){var name=parts.join('-')+'.png';icon=Icons[name];parts.pop();}
return icon||Icons['unknown.png'];};});ECMAScript.Extend('hub',function(ecma){this.Controller=function(){this.cache=new ecma.hub.Node('/','directory');this.listeners=[];this.fetchq={};};this.Controller.prototype.addListener=function(callback,scope){this.listeners.push([callback,scope]);};this.Controller.prototype.removeListener=function(callback,scope){for(var i=0;i<this.listeners.length;i++){var listener=this.listeners[i];if(callback===listener[0]&&scope===listener[1]){this.listeners.splice(i--,1);}}};this.Controller.prototype.get=function(addr){return this.cache.get(addr);}
this.Controller.prototype.fetch=function(addr,optBranch,onFetch){addr=ecma.data.addr_normalize(addr);if(!addr)return;var qkey=optBranch?addr+'+branch':addr;if(this.fetchq[qkey])return;this.fetchq[qkey]=true;var req=new ecma.hub.Fetch(this,addr,qkey,onFetch);var node=this.get(addr);if(ecma.util.defined(node)&&node.mtime&&node.fetched){var d=new Date((1000*node.mtime));req.setHeader('If-Modified-Since',d.toUTCString());req.setHeader('Cache-Control','max-age=0; must-revalidate');}else{req.setHeader('Cache-Control','no-fetch');}
var params={};if(optBranch)params.branch=true;req.submit(params);};this.Controller.prototype.store=function(addr,value){var xcmd=new ecma.hub.XCommand(this,'store',addr,this.onStore);xcmd.submit({'value':value});};this.Controller.prototype.onStore=function(r){var addr=this._setCache(r);this._sendUpdates('stored',addr,true);};this.Controller.prototype.create=function(addr,name,type){var xcmd=new ecma.hub.XCommand(this,'create',addr,this.onCreate);xcmd.submit({'name':name,'type':type});};this.Controller.prototype.onCreate=function(r){var addr=this._setCache(r);this._sendUpdates('fetched',addr,true);};this.Controller.prototype.remove=function(addr){var xcmd=new ecma.hub.XCommand(this,'remove',addr,this.onRemove);xcmd.submit();};this.Controller.prototype.onRemove=function(r){var addr=r.responseHash.get('head/meta/addr');this.cache.remove(addr);this._sendUpdates('removed',addr,true);};this.Controller.prototype.copy=function(addr,dest){var xcmd=new ecma.hub.XCommand(this,'copy',addr,this.onCopy);xcmd.submit({'dest':dest});};this.Controller.prototype.onCopy=function(r){var dest=this._setCache(r);this._sendUpdates('fetched',dest,true);};this.Controller.prototype.move=function(addr,dest){var xcmd=new ecma.hub.XCommand(this,'move',addr,this.onMove);xcmd.submit({'dest':dest});};this.Controller.prototype.onMove=function(r){var dest=this._setCache(r);this.cache.remove(addr);this._sendUpdates('removed',addr,true);this._sendUpdates('fetched',dest,true);};this.Controller.prototype.reorder=function(addr,value){var xcmd=new ecma.hub.XCommand(this,'reorder',addr,this.onReorder);xcmd.submit({'value':value});};this.Controller.prototype.onReorder=function(r){var addr=this._setCache(r);this._sendUpdates('stored',addr,true);};this.Controller.prototype._setCache=function(r){var rh=r.responseHash;var type=rh.get('head/meta/type');var body=rh.get('body');var addr;if(type=='subset'){body.iterate(function(key,value){addr=this._merge(value);},this);}else{addr=this._merge(rh);}
return addr;};this.Controller.prototype._merge=function(struct){var addr=struct.get('head/meta/addr');var type=struct.get('head/meta/type');var mtime=struct.get('head/meta/mtime');var body=struct.get('body');var text=struct.get('head/meta/content');var node=new ecma.hub.Node(addr,type,mtime,body,text);if('directory'==node.type){node.iterate(function(k,v){var addr2=ecma.data.addr_normalize(node.addr+'/'+k);var child=new ecma.hub.Node(v.get('addr'),v.get('type'),v.get('mtime'));child.fetched=false;node.set(k,child);},this);var value=this.get(node.addr);if(ecma.util.isa(value,ecma.data.Container)){var keys=node.keys();for(var i=0;i<keys.length;i++){var k=keys[i];var v=value.get(k);if(ecma.util.isa(v,ecma.data.Container)){if(v.type==node.get(k).type){if(v.mtime>=node.get(k).mtime)node.set(k,v);}else{this.cache.remove(v.addr);this._sendUpdates('removed',v.addr,true);}}}
value.iterate(function(k,v){if(!ecma.util.defined(node.get(k))){this.cache.remove(v.addr);this._sendUpdates('removed',v.addr,true);}},this);}}else{node.walk(function(k,v,d,a){var addr2=ecma.data.addr_normalize(node.addr+'/'+a);var type=undefined;if(ecma.util.isa(v,ecma.data.Container)){type=v instanceof ecma.data.OrderedHash?'data-hash':v instanceof ecma.data.Array?'data-array':undefined;}else{type='data-scalar';var ext=ecma.data.addr_ext(k);if(ext)type+='-'+ext;}
var child=new ecma.hub.Node(addr2,type,mtime,v);node.set(a,child);},this);}
if(addr=='/'){this.cache.mtime=node.mtime;}
this.cache.set(addr,node);return addr;};this.Controller.prototype._sendUpdates=function(action,addr,modified){var value=action=='removed'?{'addr':addr}:this.get(addr);for(var i=0;i<this.listeners.length;i++){var callback=this.listeners[i][0];var scope=this.listeners[i][1];try{ecma.dom.setTimeout(callback,0,scope,[action,value,modified]);}catch(ex){this.listeners.splice(i--,1);}}};});ECMAScript.Extend('hub',function(ecma){this.XCommand=function(ctrl,cmd,addr,cb){if(!cmd)throw'No command provided';if(!addr)throw'No address provided';if(!cb)throw'No callback provided';var options={method:'POST',headers:{'X-Command':cmd}};ecma.lsn.Request.call(this,addr,options);this.ctrl=ctrl;this.cb=cb;};this.XCommand.prototype=ecma.lang.Methods(ecma.lsn.Request);this.XCommand.prototype.onSuccess=function(xhr){this.cb.call(this.ctrl,xhr);};this.XCommand.prototype.onInternalServerError=function(xhr){throw xhr.statusText+': '+xhr.responseText;};});ECMAScript.Extend('hub',function(ecma){this.Fetch=function(ctrl,addr,qkey,onFetch){var options={method:'POST',headers:{'X-Command':'fetch'}};ecma.lsn.Request.call(this,addr,options);this.addr=addr;this.ctrl=ctrl;this.qkey=qkey;this.onFetch=onFetch;};this.Fetch.prototype=ecma.lang.Methods(ecma.lsn.Request);this.Fetch.prototype.onSuccess=function(xhr){this.addr=this.ctrl._setCache(xhr);this.ctrl._sendUpdates('fetched',this.addr,true);if(this.onFetch)this.onFetch(this.ctrl.get(this.addr));};this.Fetch.prototype.onNotModified=function(xhr){this.ctrl._sendUpdates('fetched',this.addr,false);if(this.onFetch)this.onFetch(this.ctrl.get(this.addr));};this.Fetch.prototype.onNotFound=function(xhr){if(this.ctrl.get(this.addr)){this.ctrl.cache.remove(this.addr);this.ctrl._sendUpdates('removed',this.addr,true);}
if(this.onFetch)this.onFetch();};this.Fetch.prototype.onInternalServerError=function(xhr){if(this.ctrl.get(this.addr)){this.ctrl.cache.remove(this.addr);this.ctrl._sendUpdates('removed',this.addr,true);}
if(this.onFetch)this.onFetch();};this.Fetch.prototype.onComplete=function(xhr){delete this.ctrl.fetchq[this.qkey];};});ECMAScript.Extend('hub',function(ecma){this.Node=function(addr,type,mtime,body,text){ecma.data.OrderedHash.apply(this);if(ecma.util.isa(body,ecma.data.Container)){body.iterate(function(k,v){this.set(k,v);},this);this.content=text;}else{this.content=body;}
this.mtime=mtime;this.addr=addr;this.type=type;this.icon=ecma.hub.getIcon(type);this.ccd=ecma.hub.ccd(type);this.fetched=true;this.dateStr='';this.timeStr='';this.dateObj=mtime?new Date(1000*mtime):undefined;if(this.dateObj){this.dateStr+=this.dateObj.getFullYear();this.dateStr+='-'+this._zero(this.dateObj.getMonth());this.dateStr+='-'+this._zero(this.dateObj.getDate());this.timeStr+=this._zero(this.dateObj.getHours());this.timeStr+=':'+this._zero(this.dateObj.getMinutes());this.timeStr+=':'+this._zero(this.dateObj.getSeconds());}};this.Node.prototype=ecma.lang.Methods(ecma.data.OrderedHash);this.Node.prototype.toXFR=function(){return this.type.match(/^data-scalar/)?ecma.data.xfr.format(this.content):this.type.match(/^data-array/)?ecma.data.xfr.format(this.values()):ecma.data.OrderedHash.prototype.toXFR.apply(this);};this.Node.prototype._zero=function(num){return num<10?'0'+num:num;};});ECMAScript.Extend('hub',function(ecma){this.List=function(e,dm,ra,opts){if(!e instanceof Object)throw'Illegal argument: e';if(!dm instanceof ecma.hub.Controller)throw'Illegal argument: dm';if(!opts instanceof Object)throw'Illegal argument: opts';this.opts={};ecma.util.overlay(this.opts,this.defaults,opts);this.id=ecma.util.randomId('nlist-');this.dm=dm;this.ce=ecma.dom.getElement(e);this.re=undefined;this.ra=undefined;this.sel=undefined;this.lsel=undefined;this.trg=undefined;this.exp=undefined;this.hl=undefined;this.kp=undefined;this.kpe=undefined;ecma.dom.include.style({href:'/res/css/hub_list.css'});this.dm.addListener(this._devt,this);this.chroot(ra);this._initkp();};this.List.prototype={chroot:function(a){var ra=a||'/';if(ra==this.ra)return;this.ra=ra;this.sel=undefined;this.trg=undefined;this.exp=undefined;this.re=this._getbopt('showRoot')?this._new_dl():this._new_dl(this.ra);ecma.dom.replaceChildren(this.ce,[this.re]);},select:function(a,delay){a=this._defa(a);this.sel=a;this.trg=a;this.exp=undefined;var dt=this._e(a,'dt');var n=this.dm.get(a);if(delay&&dt&&n){this._hl(n);setTimeout(ecma.lang.Callback(function(n){if(n.addr==this.sel){this._fetch(a,true);}else{}},this,[n]),delay);}else{this._fetch(a,true);}},expand:function(a,optSel){a=this._defa(a);if(optSel)this.sel=a;this.trg=a;this.exp=a;this._fetch(a,true);},isExpanded:function(n){return this._isexp(n.addr);},getSelected:function(){if(!ecma.util.defined(this.sel))return undefined;return this.dm.get(this.sel);},expandSelected:function(event){if(event)js.dom.stopEvent(event);var n=this.getSelected();if(n)this._expand(n);},collapseSelected:function(event){if(event)js.dom.stopEvent(event);var n=this.getSelected();if(n)this._collapse(n);},selectPrevious:function(event){if(!this.sel)return;if(event)js.dom.stopEvent(event);var ui=this._ui(this.sel)
if(ui.dt.previousSibling){var a=this._etoa(ui.dt.previousSibling);while(this._isexp(a)){var cui=this._ui(a);if(cui.dl.lastChild){a=this._etoa(cui.dl.lastChild);}else{break;}}
this.select(a,250);}else{var pui=this._pui(this.sel);if(pui&&pui.dt){this.select(this._etoa(pui.dt),250);}}},selectNext:function(event){if(!this.sel)return;if(event)js.dom.stopEvent(event);var ui=this._ui(this.sel)
if(this._isexp(this.sel)&&ui.dl.firstChild){this.select(this._etoa(ui.dl.firstChild),250);}else if(ui.dd.nextSibling){this.select(this._etoa(ui.dd.nextSibling),250);}else{var pui=this._pui(this.sel);while(pui&&pui.dt){if(pui.dd.nextSibling){this.select(this._etoa(pui.dd.nextSibling),250);break;}
pui=this._pui(this._etoa(pui.dt));}}},focus:function(a){if(!a)return;var dt=this._e(a,'dt');if(!dt)return;dt.appendChild(this.kpe);this.kpe.focus();},defaults:{showRoot:true,autoExpand:false,canDisplay:true,canExpand:function(n){return n.ccd;},formatName:function(n,str){return str;},formatDetail:function(n){return[];},onClick:function(event,n){},onSelect:function(n){}},destroy:function(){this.dm.removeListener(this._devt,this);},_initkp:function(){var btnStyle={'margin':'0','padding':'0','width':'1px','height':'1px','border':'none','background':'transparent','position':'absolute','left':'0','z-index':'-1'};this.kpe=ecma.dom.getBody().appendChild(ecma.dom.createElement('button',{'class':'nlist','style':btnStyle}));this.kp=new ecma.dom.KeyPress({trace:false}).attach(this.kpe);this.kp.setHandler('up',this.selectPrevious,this);this.kp.setHandler('down',this.selectNext,this);this.kp.setHandler('left',this.collapseSelected,this);this.kp.setHandler('right',this.expandSelected,this);},_fetch:function(a,branch){this.dm.fetch(a,branch);},_devt:function(action,n,modified){if(action=='fetched'||action=='stored'){if(n.addr==this.trg){if(this._e(n.addr,'dt')&&!modified){if(n.addr==this.exp&&!this._isexp(n.addr)){this._populate(n);}}else{this._populate(n);}
this.exp=undefined;this.trg=undefined;var tgl=this._e(n.addr,'tgl');if(n.length>0&&ecma.dom.hasClassName(tgl,'empty')){var cnodes=n.values();for(var i=0;i<cnodes.length;i++){if(this._canDisplay(cnodes[i])){ecma.dom.removeClassNames(tgl,'empty');break;}}}
if(n.addr==this.sel)this._sel(n);}else if(this._e(n.addr,'dt')&&modified&&this._isexp(n.addr)){this._populate(n);}else if(!this._e(n.addr,'dt')&&this._p(n.addr,'dt')&&this._isexp(ecma.data.addr_parent(n.addr))&&this._canDisplay(n)){var pn=this._pn(n.addr);if(pn)this._populate(pn);}}else if(action=='removed'){var ui=this._ui(n.addr);var sel=undefined;if(ecma.util.defined(this.sel)&&this.sel.indexOf(n.addr)==0){if(ui.dt){var e=ui.dt.nextSibling&&ui.dt.nextSibling.nextSibling?ui.dt.nextSibling.nextSibling:ui.dt.previousSibling?ui.dt.previousSibling.previousSibling:ui.dt.parentNode;var sel=this._etoa(e);}else{sel=ecma.data.addr_parent(n.addr);}}
for(var k in ui){if(!(ui[k]&&ui[k].parentNode))continue;ui[k].parentNode.removeChild(ui[k]);}
if(sel)this.select(sel);this.focus(sel);}else{}},_populate:function(n){if(n.addr.indexOf(this.ra)!=0)return;var parts=[this.ra];if(n.addr!=this.ra){var a2=n.addr.substring(this.ra.length);parts=parts.concat(ecma.data.addr_split(a2));}
var segments=new Array();for(var i=0;i<parts.length;i++){segments.push(parts[i]);var seg_a=ecma.data.addr_join(segments);var seg_n=this.dm.get(seg_a);if(this._canDisplay(seg_n)){if(!this._e(seg_n.addr,'dl')){var nextsib=undefined;if((i+1)<parts.length){nextsib=this._e(ecma.data.addr_join(segments.concat(parts[i+1])),'dt');}
this._new(seg_n,nextsib);}else{this._update(seg_n);}}else{continue;}
if(seg_a==n.addr&&n.addr!=this.exp&&!this._isexp(n.addr))break;if(!this._canexp(seg_n))break;var h=0;var cnodes=seg_n.values();for(var j=0;j<cnodes.length;j++){var cn=cnodes[j];if(this._canDisplay(cn)){if(!this._e(cn.addr,'dl')){var nextsib=undefined;if((j+1)<cnodes.length){nextsib=this._e(cnodes[j+1].addr,'dt');}
this._new(cn,nextsib);}else{this._update(cn);}}else{h++;}}
var tgl=this._e(seg_n.addr,'tgl');if(h==seg_n.length){ecma.dom.addClassNames(tgl,'empty');ecma.dom.removeChildren(this._e(seg_n.addr,'dl'));}else{ecma.dom.removeClassNames(tgl,'empty');}}},_collapse:function(n){var ui=this._ui(n.addr);ecma.dom.removeClassNames(ui.tgl,'isexp');ecma.dom.setStyle(ui.dl,'display','none');},_expand:function(n){var ui=this._ui(n.addr);ecma.dom.setStyle(ui.dl,'display','block');this.trg=n.addr;this.exp=n.addr;this._fetch(n.addr);},_sel:function(n){this._hl(n);this.opts.onSelect.apply(this,[n]);this.lsel=this.sel;},_hl:function(n){var dt=this._e(n.addr,'dt');if(dt===this.hl)return;if(this.hl)ecma.dom.removeClassNames(this.hl,'sel');this.hl=dt;if(this.hl){ecma.dom.addClassNames(this.hl,'sel');this._scroll(n);this.focus(n.addr);return true;}
return false;},_scroll:function(n){var dt=this._e(n.addr,'dt');var pt=(this.ce.scrollTop);var ph=ecma.dom.getHeight(this.ce);var tt=ecma.dom.getTop(dt)-ecma.dom.getTop(this.ce);var tb=ecma.dom.getBottom(dt)-ecma.dom.getTop(this.ce);if(tb>(pt+ph)||(tt<pt)){var pm=ecma.util.asInt(pt+(ph/2));var m=ecma.util.asInt(tt-(ph/2));this.ce.scrollTop=m;}},_vis:function(n){var p_tgl=this._p(n.addr,'tgl');if(p_tgl)ecma.dom.addClassNames(p_tgl,'canexp','isexp');},_getbopt:function(name,n){return typeof(this.opts[name])=='function'?this.opts[name].apply(this,[n]):this.opts[name];},_autoExpand:function(n){return this._getbopt('autoExpand',n);},_canDisplay:function(n){return this._getbopt('canDisplay',n);},_formatName:function(n){var name=undefined;if(n.addr==this.ra){name=n.addr;}else{name=ecma.data.addr_name(n.addr);if(!ecma.util.defined(name))name=n.addr;}
return this.opts.formatName.apply(this,[n,name]);},_osel:function(event,n){this.focus(n.addr);this.opts.onClick.apply(this,[event,n]);if(event.stopped)return;this.sel=n.addr;if(this._canexp(n)&&this._autoExpand(n)){this._expand(n);}else{this.sel=n.addr;this.trg=n.addr;this._fetch(n.addr);}
ecma.dom.stopEvent(event);},_omover:function(event,n){ecma.dom.addClassNames(this._e(n.addr,'dt'),'hl');},_omout:function(event,n){ecma.dom.removeClassNames(this._e(n.addr,'dt'),'hl');},_toggle:function(event,n){var tgl=this._e(n.addr,'tgl');if(ecma.dom.hasClassName(tgl,'empty')||!this._canexp(n)){return this._osel(event,n);}
if(this._isexp(n.addr)){this._collapse(n);}else{this._expand(n);}
ecma.dom.stopEvent(event);},_new:function(n,nextsib){var dl=this._new_dl(n.addr);var elems=[this._new_dt(n),this._new_dd(n,dl)];if(nextsib){ecma.dom.insertChildrenBefore(nextsib,elems);}else{var pe=this._p(n.addr,'dl');if(!pe)throw'Cannot obtain parent element';ecma.dom.appendChildren(pe,elems);}
var ui=this._ui(n.addr);if(this._canexp(n)){ecma.dom.addClassNames(ui.tgl,'canexp');}else{ecma.dom.removeClassNames(ui.tgl,'canexp','isexp')}
ecma.dom.setAttribute(ui.lbl,'innerHTML',this._formatName(n));this._update(n,ui);return dl;},_update:function(n,ui){if(!ui)ui=this._ui(n.addr);var dtlItems=this.opts.formatDetail(n);if(dtlItems&&dtlItems.length>0){var list=[];for(var i=dtlItems.length-1;i>=0;i--){list.push(ecma.dom.createElement('li',{'class':'li'+(i+1),innerHTML:dtlItems[i]}));}
ecma.dom.replaceChildren(this._e(n.addr,'dtl'),list);}
this._vis(n);},_new_dt:function(n){var onDblClick=this._autoExpand(n)?undefined:[this._toggle,this,[n]];return ecma.dom.createElements('dt',{id:this._eid(n.addr,'dt'),onClick:[this._osel,this,[n]],onDblClick:onDblClick,onMouseOver:[this._omover,this,[n]],onMouseOut:[this._omout,this,[n]],onSelectStart:function(event){ecma.dom.stopEvent(event);},onMouseDown:function(event){ecma.dom.stopEvent(event);}},['ul',{id:this._eid(n.addr,'dtl')},'div',{id:this._eid(n.addr,'tgl'),onClick:[this._toggle,this,[n]],'class':'tgl'},'img',{id:this._eid(n.addr,'ico'),title:n.addr,onClick:[this._osel,this,[n]],'class':'ico',src:n.icon},'a',{id:this._eid(n.addr,'lbl'),'class':'name',style:{cursor:'default'}}]);},_new_dd:function(n,dl){return ecma.dom.createElements('dd',{id:this._eid(n.addr,'dd')},[dl]);},_new_dl:function(a){if(!ecma.util.defined(a))a='';return ecma.dom.createElement('dl',{id:this._eid(a,'dl'),'class':'nlist'});},_defa:function(a){if(ecma.util.defined(a)){if(a.indexOf(this.ra)!=0)
throw'Address outside of list root: '+a;}else{a=this.ra;}
return a;},_canexp:function(n){return this._getbopt('canExpand',n);},_isexp:function(a){var tgl=this._e(a,'tgl');if(!tgl)return;return ecma.dom.hasClassName(tgl,'isexp')||ecma.dom.hasClassName(tgl,'empty')?true:ecma.dom.hasClassName(tgl,'canexp')?false:true;},_etoa:function(e){if(!e)return;var id=e.id;var a=id.substr(this.id.length);return a.substr(0,a.indexOf('?'));},_eid:function(a,tag){return this.id+a+'?'+tag;},_pid:function(a,tag){if(a==this.ra)return this._eid('',tag);return this._eid(ecma.data.addr_parent(a),tag);},_e:function(a,tag){return ecma.dom.getElement(this._eid(a,tag));},_p:function(a,tag){return ecma.dom.getElement(this._pid(a,tag));},_pn:function(a){var pa=ecma.data.addr_parent(a);if(pa.indexOf(this.ra)!=0)return undefined;if(pa==a)return undefined;return this.dm.get(pa);},_pui:function(a){if(a!=this.ra&&a.indexOf(this.ra)==0){return this._ui(ecma.data.addr_parent(a));}},_ui:function(a){return{dt:this._e(a,'dt'),tgl:this._e(a,'tgl'),ico:this._e(a,'ico'),lbl:this._e(a,'lbl'),dd:this._e(a,'dd'),dl:this._e(a,'dl')};}};});ECMAScript.Extend('lsn',function(ecma){var _globalMask=undefined;var _defaultStyles={'opacity':.75,'background-color':'white'};var _requiredStyles={'position':'absolute','top':0,'left':0,'width':0,'height':0};this.Mask=function(optStyle){this.showCount=0;this.style=ecma.util.overlay({},_defaultStyles,optStyle,_requiredStyles);this.ui=ecma.dom.createElement('div',{'style':this.style});if(ecma.dom.isIE){this.ui.appendChild(ecma.dom.createElement('iframe',{'width':0,'height':0,'frameborder':0,'src':'about:blank','style':{'width':0,'height':0,'visibility':'hidden'}}));}
var body=ecma.dom.getBody();this.ce=ecma.dom.browser.isIE?body:body.parentNode||body;};this.Mask.prototype={show:function(optStyle){this.showCount++;if(this.showCount>1)return;var style=ecma.util.overlay(this.style,optStyle);var opacity=undefined;if(style){for(var k in style){if(k=='opacity'){opacity=style[k];continue;}
ecma.dom.setStyle(this.ui,k,style[k]);}}
if(ecma.util.defined(opacity))ecma.dom.setOpacity(this.ui,opacity);this.ce.appendChild(this.ui);this.t=ecma.dom.getTop(this.ui);this.l=ecma.dom.getLeft(this.ui);this.resize();this.resizeEvent=new ecma.dom.EventListener(window,'resize',this.resize,this);return this;},hide:function(){this.showCount--;if(this.showCount<0)this.showCount=0;if(this.showCount)return;try{this.ce.removeChild(this.ui);this.resizeEvent.remove();}catch(ex){}
return this;},resize:function(){var c=ecma.dom.canvas.getPosition();var w=c.windowX<c.pageX?c.pageX:c.windowX;var h=c.windowY<c.pageY?c.pageY:c.windowY;w-=this.l;w-=this.t;ecma.dom.setStyle(this.ui,'width',w+"px");ecma.dom.setStyle(this.ui,'height',h+"px");}};this.showMask=function(style){if(!_globalMask)_globalMask=new ecma.lsn.Mask();return _globalMask.show(style);};this.hideMask=function(){if(_globalMask)return _globalMask.hide();};});ECMAScript.Extend('lsn',function(ecma){this.setMoveTarget=function(event,elem){return new ecma.lsn.Move(event,elem);},this.Move=function(event,elem){this.elem=ecma.dom.getElement(elem);this.listenOn=ecma.dom.browser.isIE?ecma.document:ecma.window;if(!this.elem)return;this.mmEvent=new ecma.dom.EventListener(this.listenOn,'mousemove',this.onMouseMove,this);this.muEvent=new ecma.dom.EventListener(this.listenOn,'mouseup',this.onMouseUp,this);var vp=ecma.dom.getViewportPosition();ecma.dom.makePositioned(elem);var pointer=ecma.dom.getEventPointer(event);this.min_x=vp['left'];this.min_y=vp['top'];this.abs_x=ecma.dom.getLeft(this.elem);this.abs_y=ecma.dom.getTop(this.elem);this.orig_x=ecma.util.asInt(ecma.dom.getStyle(this.elem,'left'));this.orig_y=ecma.util.asInt(ecma.dom.getStyle(this.elem,'top'));this.orig_z=ecma.dom.getStyle(this.elem,'z-index');this.orig_mx=pointer.x;this.orig_my=pointer.y;this.max_x=vp['left']+vp['width']-ecma.dom.getWidth(this.elem);this.max_y=vp['top']+vp['height']-ecma.dom.getHeight(this.elem);ecma.dom.setStyle(this.elem,'left',this.orig_x.toString(10)+'px');ecma.dom.setStyle(this.elem,'top',this.orig_y.toString(10)+'px');ecma.dom.setStyle(this.elem,'z-index','199');ecma.dom.stopEvent(event);};this.Move.prototype={onMouseUp:function(event){ecma.dom.setStyle(this.elem,'z-index',this.orig_z);this.mmEvent.remove();this.muEvent.remove();},onMouseMove:function(event){var pointer=ecma.dom.getEventPointer(event);var delta_x=pointer.x-this.orig_mx;var delta_y=pointer.y-this.orig_my;var new_x=this.orig_x+delta_x;var new_y=this.orig_y+delta_y;if(this.abs_x+delta_x>=this.max_x)new_x=this.max_x;if(this.abs_y+delta_y>=this.max_y)new_y=this.max_y;if(this.abs_x+delta_x<this.min_x)new_x=this.min_x;if(this.abs_y+delta_y<this.min_y)new_y=this.min_y;if(new_x!=null)
ecma.dom.setStyle(this.elem,'left',(new_x).toString(10)+'px');if(new_y!=null)
ecma.dom.setStyle(this.elem,'top',(new_y).toString(10)+'px');ecma.dom.stopEvent(event);}};});ECMAScript.Extend('lsn',function(ecma){var _css=null;this.initDialogStyles=function(){if(_css)return;_css=new ecma.dom.StyleSheet();_css.createRule('.dlghidden',{'visibility':'hidden','z-index':'-1','position':'absolute','left':'-1000em'});};this.includeHead=function(){ecma.lsn.includeHeadCSS.apply(this,arguments);ecma.lsn.includeHeadJS.apply(this,arguments);};this.includeHeadCSS=function(head,id,caller){if(head){var links=head.get('links/css');if(links){links.iterate(function(k,v){ecma.dom.include.style({'href':v});});}
var text=head.get('css');if(text){ecma.dom.include.style({'text':text});}}};this.includeHeadJS=function(head,id,caller,cb){if(head){var hasLoaded=false;var links=head.get('links/js');if(links){var list=links.values();var includeNext;includeNext=function(){if(list.length){var uri=list.shift();ecma.dom.include.script({'src':uri},includeNext);}else{hasLoaded=true;}}
includeNext();}else{hasLoaded=true;}
var text=head.get('js');if(text){ecma.dom.include.script({'text':text});}
var events=head.get('events/js');if(events){events.iterate(function(target,events){events.iterate(function(idx,kvpair){var evtFunc=ecma.lang.Callback(new Function(kvpair.get('value')),caller);if(target=='dialog'||target=='widget'){if(caller){caller.includeEvent(kvpair.get('key'),evtFunc);}}else{ecma.dom.addEventListener(eval(target),kvpair.get('key'),evtFunc);}});});}
if(cb){ecma.dom.waitUntil(cb,function(){return hasLoaded;},10,caller);}}else{if(cb)cb.apply(caller);}};this.Widget=function(uri,options){ecma.lsn.initDialogStyles();if(!ecma.http.isSameOrigin(uri))throw"SOP Violation";if(!this.id)this.id=ecma.util.randomId('widget_');this.request=new ecma.lsn.Request(uri,{'onSuccess':ecma.lang.Callback(this._onSuccess,this),'onInternalServerError':ecma.lang.Callback(this._onFailure,this)});this.container=undefined;this.handleKeypress={};this.refetch=true;this.events={};this.includeEvents={};this.props={};this.jsLoaded=false;this.hidden=false;for(var k in options){this.setOption(k,options[k]);}
this.reset();};this.Widget.prototype={reset:function(){this.nodes=null;this.values={};this.btn_events=[];this.includeEvents={};this._stopEvent={};this._eventName=[];this.hasLoaded=false;},setOption:function(key,value){if(key.match(/^on[A-Z]/)){this.addEvent(key,value);}else{this[key]=value;}},addEvent:function(name,func){name=name.replace(/^on/,'');name=name.toLowerCase();if(!this.events[name])this.events[name]=new Array();this.events[name].push(func);},includeEvent:function(name,func){name=name.replace(/^on/,'');name=name.toLowerCase();if(!this.includeEvents[name])this.includeEvents[name]=new Array();this.includeEvents[name].push(func);},stopEvent:function(){if(!this._eventName.length)return;var name=this._eventName[this._eventName.length-1];this._stopEvent[name]=true;},_isStopped:function(name){return this._stopEvent[name];},_beginEvent:function(name){this._eventName.push(name);},_endEvent:function(name){delete this._stopEvent[name];this._eventName.pop();},doEvent:function(name){this._beginEvent(name);if(this._isStopped(name))return this._endEvent(name);if(this.includeEvents[name]){for(var i=0;i<this.includeEvents[name].length;i++){this.includeEvents[name][i].apply(this);if(this._isStopped(name))return this._endEvent(name);}}
if(this.events[name]){for(var i=0;i<this.events[name].length;i++){var cb=this.events[name][i];ecma.lang.callback(cb,this);if(this._isStopped(name))return this._endEvent(name);}}
if(name=='init'){ecma.dom.waitUntil(this._onInit,this._jsLoaded,10,this,['ready']);}
if(name=='ok'||name=='cancel'){this.hide();}
if(name=='hide'){this.onHide();}
if(name=='load'){this.hasLoaded=true;}
this._endEvent(name);},show:function(params){this.params=params?params:{};this.beforeShow();if(this.nodes){if(this.refetch){this.destroy();this.request.submit();}else{this._enableUI();this._appendNodes();this.doEvent('init');}}else{this.request.submit();}},getElementById:function(id){var elem=null;for(var i=0,node;node=this.nodes[i];i++){elem=ecma.dom.getDescendantById(node,id);if(elem)break;}
return elem;},beforeShow:function(){},_onFailure:function(xhr){this.onHide();},_onSuccess:function(r){this.doc=r.responseHash;var tmpDiv=ecma.dom.createElement('div',{'innerHTML':this.doc.get('body')});this.nodes=ecma.util.args(tmpDiv.childNodes);this.nodes.push(ecma.dom.createElement('noscript',{id:this.id+'_dom_ready'}));this._appendNodes();this._includeRes();this.doEvent('init');},_appendNodes:function(){var ce=ecma.dom.getElement(this.container||ecma.dom.getBody());for(var i=0;i<this.nodes.length;i++){var node=this.nodes[i];if(!node.style){this.nodes.splice(i--,1);continue;}
if(this.zIndex){ecma.dom.setStyle(node,'z-index',this.zIndex);}
ce.appendChild(node);}
if(this.nodes.length==1){throw'No element nodes found';}},_includeRes:function(){ecma.lsn.includeHeadCSS(this.doc.get('head'),this.id,this);ecma.dom.waitUntil(this._includeJS,this._domLoaded,10,this);},_includeJS:function(){this.jsLoaded=false;ecma.lsn.includeHeadJS(this.doc.get('head'),this.id,this,function(){this.jsLoaded=true;});},_domLoaded:function(){return ecma.dom.getElement(this.id+'_dom_ready')?true:false;},_jsLoaded:function(){return this.jsLoaded;},_onInit:function(){if(!this.hasLoaded)this.doEvent('load');this.doEvent('show');this.hidden=false;this.doEvent('ready');},_removeUI:function(){var trash=ecma.dom.createElement('div');if(this.nodes){for(var i=0;i<this.nodes.length;i++){ecma.dom.removeElement(this.nodes[i]);}}},_disableUI:function(){if(this.nodes){for(var i=0;i<this.nodes.length;i++){ecma.dom.addClassName(this.nodes[i],'dlghidden');}}},_enableUI:function(){if(this.nodes){for(var i=0;i<this.nodes.length;i++){ecma.dom.removeClassName(this.nodes[i],'dlghidden');}}},hide:function(){if(this.hidden)return;this.doEvent('hide');this._disableUI();this.hidden=true;},onHide:function(){},destroy:function(){this.hide();this._removeUI();this.doEvent('destroy');this.reset();}};});ECMAScript.Extend('lsn',function(ecma){this.dlg={};var _zIndex=102;var _dlgCount=0;var baseClass=ecma.lsn.Widget;var proto=ecma.lang.Methods(baseClass);this.Dialog=function(uri,userOpts){this.id=ecma.util.randomId('dlg_');var opts={modal:true,modalOpacity:.50};ecma.util.overlay(opts,userOpts);baseClass.apply(this,[uri,opts]);this.mask=null;};this.Dialog.prototype=proto;proto.beforeShow=function(){_dlgCount++;this.zIndex=_zIndex+(2*_dlgCount);if(this.modal){this.mask=new ecma.lsn.Mask();this.mask.show({'opacity':this.modalOpacity,'z-index':this.zIndex-1});}};proto.onHide=function(){if(this.modal){this.mask.hide();this.mask=null;}
_dlgCount--;};});ECMAScript.Extend('lsn',function(ecma){this.PageLayout=function(opts){ecma.util.overlay(this,opts);ecma.dom.addEventListener(ecma.window,'load',this.load,this);ecma.dom.addEventListener(ecma.window,'resize',this.resize,this);ecma.dom.addEventListener(ecma.window,'unload',this.unload,this);};this.PageLayout.prototype={load:function(event){this.resize(event);},resize:function(event){},unload:function(event){}};});ECMAScript.Extend('lsn',function(ecma){this.DragHandle=function(elem,opts){this.opts={'threshold':0,'onMouseDown':function(event,dh){event.stop()},'onMouseUp':function(event,dh){event.stop()},'onMouseMove':function(event,dh){event.stop()}};ecma.util.overlay(this.opts,opts);this.elem=ecma.dom.getElement(elem);if(!this.elem)return;this.listenOn=ecma.dom.browser.isIE?ecma.document:ecma.window;ecma.dom.addEventListener(this.elem,'mousedown',this.onMouseDown,this);this.reset();this.mmEvent=null;this.muEvent=null;};this.DragHandle.prototype={reset:function(){this.orig_mx=0;this.orig_my=0;this.delta_x=0;this.delta_y=0;this.dragging=false;},onMouseDown:function(event){this.reset();var pointer=ecma.dom.getEventPointer(event);this.orig_mx=pointer.x;this.orig_my=pointer.y;this.mmEvent=new ecma.dom.EventListener(this.listenOn,'mousemove',this.onMouseMove,this);this.muEvent=new ecma.dom.EventListener(this.listenOn,'mouseup',this.onMouseUp,this);ecma.lang.callback(this.opts.onMouseDown,this,[event,this]);},onMouseUp:function(event){this.mmEvent.remove();this.muEvent.remove();this.dragging=false;ecma.lang.callback(this.opts.onMouseUp,this,[event,this]);},onMouseMove:function(event){var pointer=ecma.dom.getEventPointer(event);this.delta_x=pointer.x-this.orig_mx;this.delta_y=pointer.y-this.orig_my;if(!this.dragging&&Math.abs(this.delta_x)<this.opts.threshold&&Math.abs(this.delta_y)<this.opts.threshold){return}
this.dragging=true;ecma.lang.callback(this.opts.onMouseMove,this,[event,this]);}};});ECMAScript.Extend('lsn',function(ecma){_impl={};this.ContentController=function(){this.impl=ecma.dom.browser.isIE?new _impl.IE():ecma.dom.browser.isGecko?new _impl.Gecko():new _impl.Gecko();if(!this.impl)throw'no ContentController implementation for this browser';};this.ContentController.prototype.attach=function(elem){elem=ecma.dom.getElement(elem);return this.impl.attach.apply(this.impl,[elem]);};this.ContentController.prototype.detach=function(){return this.impl.detach.apply(this.impl,[]);};this.ContentController.prototype.insertHTML=function(){return this.impl.insertHTML.apply(this.impl,arguments);};this.ContentController.prototype.getFocusElement=function(){return this.impl.getFocusElement.apply(this.impl,arguments);};this.ContentController.prototype.insertElement=function(){return this.impl.insertElement.apply(this.impl,arguments);};this.ContentController.prototype.selectElement=function(){return this.impl.selectElement.apply(this.impl,arguments);};this.ContentController.prototype.focusBefore=function(){return this.impl.focusBefore.apply(this.impl,arguments);};this.ContentController.prototype.focusAfter=function(){return this.impl.focusAfter.apply(this.impl,arguments);};this.ContentController.prototype.exec=function(){return this.impl.exec.apply(this.impl,arguments);};this.ContentController.prototype.toggle=function(tagName){return this.impl.toggle.apply(this.impl,arguments);};_impl.Gecko=function(){};_impl.Gecko.prototype={attach:function(elem){this.target=elem;this.exec('useCSS',true);},detach:function(){this.target=undefined;},getFocusElement:function(){var sel=this.getSelection();var range=sel.getRangeAt(0);var elem=range.commonAncestorContainer;while(elem&&elem.nodeType!=Node.ELEMENT_NODE){elem=elem.parentNode;}
return elem;},insertElement:function(elem){var sel=this.getSelection();if(false==sel.isCollapsed){sel.deleteFromDocument();sel=this.getSelection();}
if(sel.isCollapsed){var nFocus=sel.focusNode;var focusOffset=sel.focusOffset;switch(nFocus.nodeType){case Node.ELEMENT_NODE:var nCurr=focusOffset>0?nFocus.childNodes[focusOffset-1]:nFocus;if(nCurr===this.target){if(nCurr.childNodes.length>0){nCurr.insertBefore(elem,nCurr.childNodes[0]);}else{nCurr.appendChild(elem);}}else{ecma.dom.insertChildrenAfter(nCurr,[elem]);}
break;case Node.TEXT_NODE:var a=nFocus.nodeValue.substr(0,focusOffset);var b=nFocus.nodeValue.substr(focusOffset);var nA=ecma.dom.createElement('#text',{'nodeValue':a});var nB=ecma.dom.createElement('#text',{'nodeValue':b});ecma.dom.insertChildrenBefore(nFocus,[nA,elem,nB]);nFocus.parentNode.removeChild(nFocus);break;default:throw'no implementation for selected nodeType';}
this.focusAfter(elem);}},selectElement:function(elem){var sel=this.getSelection();sel.removeAllRanges();var range=ecma.document.createRange();range.selectNode(elem);sel.addRange(range);return sel;},focusBefore:function(elem){sel=this.selectElement(elem);sel.collapseToStart();},focusAfter:function(elem){sel=this.selectElement(elem);sel.collapseToEnd();},insertHTML:function(html){this.exec('insertHTML',html);},exec:function(cmd,args){ecma.document.execCommand(cmd,false,args);},toggle:function(tagName){},getSelection:function(){var sel=ecma.window.getSelection();if(!sel.anchorNode)throw'target does not have focus';return sel;},setSelection:function(){}};_impl.IE=function(){};_impl.IE.prototype={attach:function(elem){this.target=elem;},detach:function(){this.target=undefined;},getFocusElement:function(){var sel=this.getSelection();var range=sel.createRange();return sel.type=='Control'?range.item(0):range.parentElement();},insertElement:function(elem){var sel=this.getSelection();var tmp=this._insertTemp();this.replaceElement(tmp,elem);},replaceElement:function(eOld,eNew){eOld.appendChild(eNew);eOld.removeNode();},_insertTemp:function(){var id=ecma.util.randomId();var html="<span id='"+id+"'></span>";this.getRange().pasteHTML(html);var elem=ecma.dom.getElement(id);return elem;},selectElement:function(elem){var range=ecma.dom.getBody().createControlRange();range.addElement(elem);range.select();},focusBefore:function(elem){this.selectElement(elem);},focusAfter:function(elem){this.selectElement(elem);},insertHTML:function(html){this.getRange().pasteHTML(html);},exec:function(cmd,args){ecma.document.execCommand(cmd,args?false:true,args);},toggle:function(tagName){var sel=ecma.document.selection;var ranges=sel.createRangeCollection();for(var i=0;i<ranges.length;i++){var textRange=ranges.item(i);var html=textRange.htmlText;if(html){var re=new RegExp('\\s*<'+tagName+'>');if(html.match(re,'g')){}else{}
textRange.pasteHTML(html);}}},getSelection:function(){var sel=ecma.document.selection;return sel;},getRange:function(){return this.getSelection().createRange();}};});ECMAScript.Extend('lsn',function(ecma){this.ComboBox=function(){this.ctrl=ecma.dom.createElement('input');this.toggle=ecma.dom.createElement('img',{'alt':'[...]','src':'/res/images/dropdown.png','onClick':[this.onToggle,this],'style':{'font-size':'8pt','position':'relative','left':'-19px','width':'13px','height':'7px','cursor':'pointer'}});};var proto=this.ComboBox.prototype={};proto.attach=function(elem){var ctrl=ecma.dom.getElement(elem);ecma.dom.insertAfter(this.toggle,ctrl);var box=this.getElement();ecma.dom.setStyle(box,'top',ecma.dom.getBottom(ctrl)+'px');ecma.dom.setStyle(box,'left',ecma.dom.getLeft(ctrl)+'px');ecma.dom.setStyle(box,'width',(ecma.dom.getWidth(ctrl))+'px');this.ctrl=ctrl;};proto.show=function(){ecma.dom.getBody().appendChild(this.ui.box);ecma.dom.setStyle(this.ui.box,'visibility','visible');ecma.dom.setAttribute(this.ctrl,'disabled','disabled');this.windowClickEvent=new ecma.dom.EventListener(ecma.window,'click',this.onWindowClick,this,null,true);this.isVisible=true;};proto.hide=function(){ecma.dom.removeAttribute(this.ctrl,'disabled','disabled');ecma.dom.setStyle(this.ui.box,'visibility','hidden');ecma.dom.removeElement(this.ui.box);if(this.windowClickEvent)this.windowClickEvent.remove();this.isVisible=false;};proto.onWindowClick=function(event){var target=ecma.dom.getEventTarget(event);if(ecma.dom.isChildOf(target,this.getElement()))return;ecma.dom.stopEvent(event);this.hide();};proto.onToggle=function(event){ecma.dom.stopEvent(event);if(this.isVisible){this.hide();}else{this.show();}};});ECMAScript.Extend('lsn',function(ecma){var CActionDispatcher=ecma.action.ActionDispatcher;var proto=ecma.lang.createMethods(CActionDispatcher);this.InputListener=function(elem){CActionDispatcher.apply(this);this.elem=ecma.dom.getElement(elem);this.setValue();this.kpevt=new ecma.dom.EventListener(elem,'keypress',this.onKeyPress,this);this.checkInterval=75;this.checkTimeout=10*this.checkInterval;this.checkCount=0;};this.InputListener.prototype=proto;proto.setValue=function(){this.currentValue=ecma.dom.getValue(this.elem);};proto.onKeyPress=function(){if(this.intervalId)return;this.intervalId=ecma.dom.setInterval(this.checkValue,this.checkInterval,this);};proto.checkValue=function(){var value=ecma.dom.getValue(this.elem);if(this.currentValue!=value){this.clearInterval();var prevValue=this.currentValue;this.setValue();this.dispatchAction('change',this.currentValue,prevValue);}else{this.checkCount++;if((this.checkInterval*this.checkCount)>this.checkTimeout){this.clearInterval();}}};proto.clearInterval=function(){ecma.dom.clearInterval(this.intervalId);this.intervalId=null;this.checkCount=0;};proto.destroy=function(){this.clearInterval();this.kpevt.remove();};});ECMAScript.Extend('dom',function(ecma){var CActionDispatcher=ecma.action.ActionDispatcher;var proto=ecma.lang.createMethods(CActionDispatcher);this.LocationListener=function(){CActionDispatcher.apply(this);this.checkInterval=75;this.setLocation();this.intervalId=ecma.dom.setInterval(this.checkLocation,this.checkInterval,this);};this.LocationListener.prototype=proto;proto.setLocation=function(){this.currentHref=ecma.document.location.href;this.currentLocation=new ecma.http.Location();};proto.checkLocation=function(){var href=ecma.document.location.href;if(this.currentHref!=href){var prevLocation=this.currentLocation;this.setLocation();this.dispatchAction('change',this.currentLocation,prevLocation);}};proto.destroy=function(){ecma.dom.clearInterval(this.intervalId);};});ECMAScript.Extend('dom',function(ecma){var proto={};this.KeyListener=function(elem,key,func,scope,args){this.elem=ecma.dom.getElement(elem);this.key=key;this.cb=ecma.lang.createCallbackArray(func,scope,args);this.kpevt=new ecma.dom.EventListener(elem,'keypress',this.onKeyPress,this);};this.KeyListener.prototype=proto;proto.onKeyPress=function(event){var seq=this.getSequence(event);var match=false;if(typeof(this.key)=='function'){match=ecma.lang.callback(this.key,null,[seq]);}else{match=seq.numeric==this.key||seq.ascii==this.key;}
if(match)ecma.lang.callback(this.cb,null,[event]);};proto.getSequence=function(event){var char_code=this.getCharCode(event);var ascii_code=String.fromCharCode(char_code).toLowerCase();var prefix=event.ctrlKey?"ctrl+":"";if(event.altKey)prefix+="alt+";if(event.shiftKey)prefix+="shift+";var seq={'ascii':prefix,'numeric':prefix+char_code,'ismod':false};var is_special=true;if(ecma.dom.browser.isGecko){is_special=event.keyCode&&!event.charCode;}
if(is_special){switch(char_code){case 8:seq.ascii+='backspace';break;case 9:seq.ascii+='tab';break;case 13:seq.ascii+='enter';break;case 16:seq.ascii='shift';break;case 17:seq.ascii='ctrl';break;case 18:seq.ascii='alt';break;case 27:seq.ascii+='esc';break;case 37:seq.ascii+='left';break;case 38:seq.ascii+='up';break;case 39:seq.ascii+='right';break;case 40:seq.ascii+='down';break;case 46:seq.ascii+='delete';break;case 36:seq.ascii+='home';break;case 35:seq.ascii+='end';break;case 33:seq.ascii+='pageup';break;case 34:seq.ascii+='pagedown';break;case 45:seq.ascii+='insert';break;default:seq.ascii+=ascii_code;}}else{seq.ascii+=ascii_code;}
seq.ismod='shift'==seq.ascii||'ctrl'==seq.ascii||'alt'==seq.ascii;return seq;};proto.getCharCode=function(event){return event.which?event.which:event.keyCode?event.keyCode:event.charCode?event.charCode:0;};proto.destroy=function(){this.kpevt.remove();};});ECMAScript.Extend('lsn.auth',function(ecma){var _basic_auth_token=null;this.setAuthToken=function(tk){_basic_auth_token=tk;};this.basic=function(un,pw){var h1=ecma.crypt.hex_sha1(pw);var h2=ecma.crypt.hex_sha1(h1+':'+_basic_auth_token);return{'un':un,'h2':h2};};});ECMAScript.Extend('lsn.ui',function(ecma){var UI_STATE_DEFAULT=1;var UI_STATE_AUTHENTICATING=2;var UI_STATE_AUTHENTICATED=3;var UI_STATE_FAILED=4;var proto={};this.LoginDialog=function(dlgUri,loginUri){this.ui={};this.dlgUri=dlgUri||'/res/login/login.dlg';this.loginUri=loginUri||'/res/login/module.pm/login';this.dlg=new ecma.lsn.Dialog(this.dlgUri,{refetch:false});this.dlg.addEvent('load',[this.onLoad,this]);this.dlg.addEvent('show',[this.onShow,this]);this.dlg.addEvent('ok',[this.onOk,this]);this.dlg.addEvent('cancel',[this.onCancel,this]);this.dlg.addEvent('destroy',[this.onDestroy,this]);this.req=new ecma.lsn.Request(this.loginUri);this.req.addEventListener('success',this.onSuccess,this);this.req.addEventListener('failure',this.onFailure,this);};this.LoginDialog.prototype=proto;proto.show=function(params){this.dlg.show(params);};proto.hide=function(){this.dlg.hide();};proto.onLoad=function(){this.ui.un=this.dlg.getElementById('un');this.ui.pw=this.dlg.getElementById('pw');this.ui.msg=this.dlg.getElementById('msg');this.ui.btnbar=this.dlg.getElementById('btnbar');this.ui.btnOk=this.dlg.getElementById('btn_ok');this.ui.btnCancel=this.dlg.getElementById('btn_cancel');this.ui.kbEnter=new ecma.dom.KeyListener(this.ui.pw,'enter',this.onOk,this);};proto.enableButtons=function(){ecma.dom.removeAttribute(this.ui.un,'disabled','disabled');ecma.dom.removeAttribute(this.ui.pw,'disabled','disabled');ecma.dom.removeAttribute(this.ui.btnOk,'disabled','disabled');ecma.dom.removeAttribute(this.ui.btnCancel,'disabled','disabled');};proto.disableButtons=function(){ecma.dom.setAttribute(this.ui.un,'disabled','disabled');ecma.dom.setAttribute(this.ui.pw,'disabled','disabled');ecma.dom.setAttribute(this.ui.btnOk,'disabled','disabled');ecma.dom.setAttribute(this.ui.btnCancel,'disabled','disabled');};proto.updateUI=function(state){if(state==UI_STATE_DEFAULT){this.enableButtons();ecma.dom.setValue(this.ui.msg,'');ecma.dom.setClassName(this.ui.msg,'authenticating');if(this.ui.cont){ecma.dom.removeElement(this.ui.cont);delete this.ui.cont;this.ui.btnbar.appendChild(this.ui.btnCancel);this.ui.btnbar.appendChild(this.ui.btnOk);}}else if(state==UI_STATE_AUTHENTICATING){this.disableButtons();ecma.dom.setValue(this.ui.msg,'Authenticating...');}else if(state==UI_STATE_FAILED){this.enableButtons();ecma.dom.setValue(this.ui.msg,'Login incorrect');ecma.dom.setClassName(this.ui.msg,'failed');}else if(state==UI_STATE_AUTHENTICATED){ecma.dom.setClassName(this.ui.msg,'authenticated');ecma.dom.setValue(this.ui.msg,'Success');}else{throw'Unknown ui state: '+state;}};proto.onShow=function(){ecma.dom.setValue(this.ui.un,'');ecma.dom.setValue(this.ui.pw,'');ecma.dom.setValue(this.ui.msg,'');this.updateUI(UI_STATE_DEFAULT);this.ui.un.focus();};proto.onOk=function(){this.dlg.stopEvent();this.updateUI(UI_STATE_AUTHENTICATING);var un=ecma.dom.getValue(this.ui.un);var pw=ecma.dom.getValue(this.ui.pw);this.req.submit(ecma.lsn.auth.basic(un,pw));};proto.onCancel=function(){this.goNext(this.dlg.params.onCancel,this.dlg.params.onCancelUri);};proto.onDestroy=function(){this.ui.kbEnter.destroy();};proto.onSuccess=function(){this.updateUI(UI_STATE_AUTHENTICATED);this.goNext(this.dlg.params.onSuccess,this.dlg.params.onSuccessUri);};proto.goNext=function(cb,uri){if(cb){this.hide();ecma.lang.callback(cb,this.dlg);}else if(uri){var loc=new ecma.http.Location(uri);ecma.lang.assert(loc.isSameOrigin());if(false&&ecma.dom.browser.isIE){this.ui.cont=ecma.dom.createElement('a',{'href':loc.getUri(),'innerHTML':'Continue'});ecma.dom.removeElement(this.ui.btnCancel);ecma.dom.removeElement(this.ui.btnOk);this.ui.btnbar.appendChild(this.ui.cont);this.ui.cont.focus();}else{if(ecma.document.location.href==loc.getUri()){ecma.document.location.reload();}else{ecma.document.location.replace(loc.getUri());}}}else{this.hide();}};proto.onFailure=function(){this.updateUI(UI_STATE_FAILED);ecma.dom.setValue(this.ui.pw,'');this.ui.pw.focus();};});ECMAScript.Extend('lsn.ui',function(ecma){var CActionDispatcher=ecma.action.ActionDispatcher;var proto=ecma.lang.createMethods(CActionDispatcher);this.View=function(){CActionDispatcher.apply(this);this.ui=new Object();};this.View.prototype=proto;proto.createUI=function(rootElem){var nlist=rootElem.getElementsByClassName('ui');for(var i=0,node;node=nlist[i];i++){if(!node.id)continue;this.ui[node.id]=node;}
return this.ui;};proto.updateUI=function(){};proto.destroyUI=function(){};});js=new ECMAScript.Class(window,document);