/*
* Comet4J JavaScript Client V0.1.0
* Copyright(c) 2011, jinghai.xiao@gamil.com.
* http://code.google.com/p/comet4j/
* This code is licensed under BSD license. Use it as you wish,
* but keep this copyright intact.
*/
var JS={version:'0.0.2'};JS.Runtime=(function(){var ua=navigator.userAgent.toLowerCase(),check=function(r){return r.test(ua);},isOpera=check(/opera/),isFirefox=check(/firefox/),isChrome=check(/chrome/),isWebKit=check(/webkit/),isSafari=!isChrome&&check(/safari/),isSafari2=isSafari&&check(/applewebkit\/4/),isSafari3=isSafari&&check(/version\/3/),isSafari4=isSafari&&check(/version\/4/),isIE=!isOpera&&check(/msie/),isIE7=isIE&&check(/msie 7/),isIE8=isIE&&check(/msie 8/),isIE6=isIE&&!isIE7&&!isIE8,isGecko=!isWebKit&&check(/gecko/),isGecko2=isGecko&&check(/rv:1\.8/),isGecko3=isGecko&&check(/rv:1\.9/),isWindows=check(/windows|win32/),isMac=check(/macintosh|mac os x/),isAir=check(/adobeair/),isLinux=check(/linux/);return{isOpera:isOpera,isFirefox:isFirefox,isChrome:isChrome,isWebKit:isWebKit,isSafari:isSafari,isSafari2:isSafari2,isSafari3:isSafari3,isSafari4:isSafari4,isIE:isIE,isIE7:isIE7,isIE8:isIE8,isIE6:isIE6,isGecko:isGecko,isGecko2:isGecko2,isGecko3:isGecko3,isWindows:isWindows,isMac:isMac,isAir:isAir,isLinux:isLinux};}());JS.isOpera=JS.Runtime.isOpera;JS.isFirefox=JS.Runtime.isFirefox;JS.isChrome=JS.Runtime.isChrome;JS.isWebKit=JS.Runtime.isWebKit;JS.isSafari=JS.Runtime.isSafari;JS.isSafari2=JS.Runtime.isSafari2;JS.isSafari3=JS.Runtime.isSafari3;JS.isSafari4=JS.Runtime.isSafari4;JS.isIE=JS.Runtime.isIE;JS.isIE7=JS.Runtime.isIE7;JS.isIE8=JS.Runtime.isIE8;JS.isIE6=JS.Runtime.isIE6;JS.isGecko=JS.Runtime.isGecko;JS.isGecko2=JS.Runtime.isGecko2;JS.isGecko3=JS.Runtime.isGecko3;JS.isWindows=JS.Runtime.isWindows;JS.isMac=JS.Runtime.isMac;JS.isAir=JS.Runtime.isAir;JS.isLinux=JS.Runtime.isLinux;JS.Syntax={nameSpace:function(){if(arguments.length){var o,d,v;for(var i=0,len=arguments.length;i<len;i++){v=arguments[i];if(!v){continue;}
d=v.split(".");for(var j=0,len=d.length;j<len;j++){if(!d[j]){continue;}
o=window[d[j]]=window[d[j]]||{};}}}
return o;},apply:function(o,c,defaults){if(defaults){JS.Syntax.apply(o,defaults);}
if(o&&c&&typeof c=='object'){for(var p in c){o[p]=c[p];}}
return o;},override:function(origclass,overrides){if(overrides){var p=origclass.prototype;JS.Syntax.apply(p,overrides);if(JS.Runtime.isIE&&overrides.hasOwnProperty('toString')){p.toString=overrides.toString;}}},extend:function(){var io=function(o){for(var m in o){this[m]=o[m];}};var oc=Object.prototype.constructor;return function(sb,sp,overrides){if(JS.Syntax.isObject(sp)){overrides=sp;sp=sb;sb=overrides.constructor!=oc?overrides.constructor:function(){sp.apply(this,arguments);};}
var F=function(){},sbp,spp=sp.prototype;F.prototype=spp;sbp=sb.prototype=new F();sbp.constructor=sb;sb.superclass=spp;if(spp.constructor==oc){spp.constructor=sp;}
sb.override=function(o){JS.Syntax.override(sb,o);};sbp.superclass=sbp.supr=(function(){return spp;});sbp.override=io;JS.Syntax.override(sb,overrides);sb.extend=function(o){return JS.Syntax.extend(sb,o);};return sb;};}(),callBack:function(fn,scope,arg){if(JS.isFunction(fn)){return fn.apply(scope||window,arg||[]);}},isEmpty:function(v,allowBlank){return v===null||v===undefined||((Ext.isArray(v)&&!v.length))||(!allowBlank?v==='':false);},isArray:function(v){return Object.prototype.toString.apply(v)==='[object Array]';},isDate:function(v){return Object.prototype.toString.apply(v)==='[object Date]';},isObject:function(v){return!!v&&Object.prototype.toString.call(v)==='[object Object]';},isPrimitive:function(v){return Ext.isString(v)||Ext.isNumber(v)||Ext.isBoolean(v);},isFunction:function(v){return Object.prototype.toString.apply(v)==='[object Function]';},isNumber:function(v){return typeof v==='number'&&isFinite(v);},isString:function(v){return typeof v==='string';},isBoolean:function(v){return typeof v==='boolean';},isElement:function(v){return!!v&&v.tagName;},isDefined:function(v){return typeof v!=='undefined';},toArray:function(){return JS.isIE?function(a,i,j,res){res=[];for(var x=0,len=a.length;x<len;x++){res.push(a[x]);}
return res.slice(i||0,j||res.length);}:function(a,i,j){return Array.prototype.slice.call(a,i||0,j||a.length);};}()};JS.ns=JS.Syntax.nameSpace;JS.apply=JS.Syntax.apply;JS.override=JS.Syntax.override;JS.extend=JS.Syntax.extend;JS.callBack=JS.Syntax.callBack;JS.isEmpty=JS.Syntax.isEmpty;JS.isArray=JS.Syntax.isArray;JS.isDate=JS.Syntax.isDate;JS.isObject=JS.Syntax.isObject;JS.isPrimitive=JS.Syntax.isPrimitive;JS.isFunction=JS.Syntax.isFunction;JS.isNumber=JS.Syntax.isNumber;JS.isString=JS.Syntax.isString;JS.isBoolean=JS.Syntax.isBoolean;JS.isElement=JS.Syntax.isElement;JS.isDefined=JS.Syntax.isDefined;JS.toArray=JS.Syntax.toArray;JS.DomEvent={on:function(el,name,fun,scope){if(el.addEventListener){el.addEventListener(name,function(){JS.callBack(fun,scope,arguments);},false);}else{el.attachEvent('on'+name,function(){JS.callBack(fun,scope,arguments);});}},un:function(el,name,fun,scope){if(el.removeEventListener){el.removeEventListener(name,fun,false);}else{el.detachEvent('on'+name,fun);}},stop:function(e){e.returnValue=false;if(e.preventDefault){e.preventDefault();}
JS.DomEvent.stopPropagation(e);},stopPropagation:function(e){e.cancelBubble=true;if(e.stopPropagation){e.stopPropagation();}}};JS.on=JS.DomEvent.on;JS.un=JS.DomEvent.un;JS.DelayedTask=function(fn,scope,args){var me=this,id,call=function(){clearInterval(id);id=null;fn.apply(scope,args||[]);};me.delay=function(delay,newFn,newScope,newArgs){me.cancel();fn=newFn||fn;scope=newScope||scope;args=newArgs||args;id=setInterval(call,delay);};me.cancel=function(){if(id){clearInterval(id);id=null;}};};
JS.ns("JS.Observable");JS.Observable=function(o){JS.apply(this,o||JS.toArray(arguments)[0]);if(this.events){this.addEvents(this.events);}
if(this.listeners){this.on(this.listeners);delete this.listeners;}};JS.Observable.prototype={on:function(eventName,fn,scope,o){if(JS.isString(eventName)){this.addListener(eventName,fn,scope,o);}else if(JS.isObject(eventName)){this.addListeners(eventName,scope,o);}},fireEvent:function(){var arg=JS.toArray(arguments),eventName=arg[0].toLowerCase(),e=this.events[eventName];if(e&&!JS.isBoolean(e)){return e.fire.apply(e,arg.slice(1));}},addEvent:function(eventName){if(!JS.isObject(this.events)){this.events={};}
if(this.events[eventName]){return;}
if(JS.isString(eventName)){this.events[eventName.toLowerCase()]=true;}else if(eventName instanceof JS.Event){this.events[eventName.name.toLowerCase()]=eventName;}},addEvents:function(arr){if(JS.isArray(arr)){for(var i=0,len=arr.length;i<len;i++){this.addEvent(arr[i]);}}},addListener:function(eventName,fn,scope,o){eventName=eventName.toLowerCase();var e=this.events[eventName];if(e){if(JS.isBoolean(e)){e=this.events[eventName]=new JS.Event(eventName,this);}
e.addListener(fn,scope,o);}},addListeners:function(obj,scope,o){if(JS.isObject(obj)){for(var p in obj){this.addListener(p,obj[p],scope,o);}}},removeListener:function(eventName,fn,scope){eventName=eventName.toLowerCase();var e=this.events[eventName];if(e&&!JS.isBoolean(e)){e.removeListener(fn,scope);}},clearListeners:function(){var events=this.events,e;for(var p in events){e=events[p];if(!JS.isBoolean(e)){e.clearListeners();}}},clearEvents:function(){var events=this.events;this.clearListeners();for(var p in events){this.removeEvent(p);}},removeEvent:function(eventName){var events=this.events,e;if(events[eventName]){e=events[eventName];if(!JS.isBoolean(e)){e.clearListeners();}
delete events[eventName];}},removeEvents:function(eventName){if(JS.isString(eventName)){this.removeEvent(eventName);}else if(JS.isArray(eventName)&&eventName.length>0){for(var i=0,len=eventName.length;i<len;i++){this.removeEvent(eventName[i]);}}},hasEvent:function(eventName){return this.events[eventName]?true:false;},hasListener:function(eventName,fn,scope){var events=this.events,e=events[eventName];if(!JS.isBoolean(e)){return e.hasListener(fn,scope);}
return false;}