/**
 * 此版本为单文件版
 * lrcc@163.com
 * @author CHX
 * @version 0.1
 */
var jatX=function(){var _version="";var _ui={};var _widgets={};var _utilities={};var _cache_elements=[];function _$(v,w){w=w||window;var _el;if(typeof v=="string"){if(/^<([\w-]+)>$/.test(v)){var _tagName=RegExp.$1;if(/input\-(text|button|radio|checkbox|hidden|image|reset|submit|file|password)(\-\w+)?/i.test(_tagName)){if(window.ActiveXObject){var _sName=RegExp.$2?" name=\""+RegExp.$2.substring(1)+"\"":" name=\"_jx_"+RegExp.$1+"\"";_el=w.document.createElement("<input type=\""+RegExp.$1+"\""+_sName+">");}else{_el=w.document.createElement("input");_el.type=RegExp.$1;_el.name=RegExp.$2?RegExp.$2.substring(1):"_jx_"+RegExp.$1;}}else if(/(textarea|select)(\-\w+)?/i.test(_tagName)){if(window.ActiveXObject){var _sName=RegExp.$2?" name=\""+RegExp.$2.substring(1)+"\"":" name=\"_jx_"+RegExp.$1+"\"";_el=w.document.createElement("<"+RegExp.$1+_sName+">");}else{_el=w.document.createElement(RegExp.$1);_el.name=RegExp.$2?RegExp.$2.substring(1):"_jx_"+RegExp.$1;}}else{_el=w.document.createElement(_tagName);}}else{_el=w.document.getElementById(v);if(!_el)return null;if(_el.id!=v){_el=null;var _allID=document.all[v];for(var i=0;i<_allID.length;i++){if(_allID[i].id==v){_el=_allID[i];break;}}}}}else{_el=v;}return _el;}function _augment(o,oExt,bOverride,fFilter){if(!oExt)return;for(var p in oExt){if(bOverride||!(p in o)){if(typeof fFilter=="function"){if(fFilter.call(oExt,p)){o[p]=oExt[p];}}else{o[p]=oExt[p];}}}if(bOverride&&typeof oExt.toString=="function"&&oExt.toString!=o.toString){o.toString=oExt.toString;}return this;}function _instanceOf(fClass){var _super=this;do{if(_super===fClass)return true;_super=_super.prototype.$super;}while(typeof _super=="function");return false;}function _class(oClass){var _construct=oClass.__init||{};var _use=oClass.__use||[];delete oClass.__init;delete oClass.__use;_construct.prototype.Super=[];if(_use instanceof Function){_augment(_construct.prototype,_use.prototype);_construct.prototype.Super.push(_use);}else if(_use instanceof Array){_use.forEach(function(v,i){if(typeof v=="function"){_augment(_construct.prototype,v.prototype);_construct.prototype.Super.push(v);}else if(typeof v=="object"&&"$class"in v&&typeof v.$class=="function"){_augment(_construct.prototype,v.$class.prototype,true,v.filter);_construct.prototype.Super.push(v.$class);}});}else if(_use instanceof Object&&"$class"in _use&&typeof _use.$class=="function"){_augment(_construct.prototype,_use.$class.prototype);_construct.prototype.Super.push(_use.$class);}_augment(_construct.prototype,oClass,true);_construct.prototype.constructor=_construct;return _construct;}function _baseClass(){}_augment(_baseClass.prototype,{fireEvent:function(name,opt){if(typeof this._propEx!="object"||!this._propEx)this._propEx={};if(typeof this._propEx[name]=="function"){this._propEx[name].apply(this,opt);return true;}return false;},attach:function(o){if(typeof this._propEx!="object"||!this._propEx)this._propEx={};if(typeof o=="object"){_augment(this._propEx,o,false);}return this;},$interface:function(o){if(this._interface instanceof Array){for(var i=0;i<this._interface.length;i++){if(!this._interface[i]in o){new Error("所有的接口方法都须要实现: "+this._interface[i]);}}}if(typeof o=="object"){this._interface=o;}else{}return this;}});function _element(v,w){var _el=_$(v,w);if(_el instanceof jatX.Element||_el instanceof jatX.Table)return _el;var _isCached=_cache_elements.some(function(v){if(v.$value()===_el){_el=v;return true;}});if(_isCached)return _el;if(_el){if(_el.tagName=="TABLE"){_el=new jatX.Table(_el);}else{_el=new jatX.Element(_el);}_cache_elements.push(_el);}return _el;}return{getVersion:function(){return _version;},$E:_element,$:_$,augment:_augment,Class:_class,baseClass:_baseClass,methods:function(fClass,oProto,bOverride){_augment(fClass.prototype,oProto,bOverride);},UI:_ui,widg:_widgets,util:_utilities,window:{}};}();

jatX.augment(Function.prototype,{delay:function(n,thisObj,args){var me=this;var f=function(){me.apply(thisObj||window,args);};window.setTimeout(f,n);},bind:function(){var t=this;var arg=arguments;return function(){var arg1=Array.prototype.slice.call(arguments);t.apply(this,arg1.concat(Array.prototype.slice.call(arg)));};}});jatX.augment(String.prototype,{trim:function(){return this;},encodeURL:function(){var s="";for(var i=0;i<this.length;i++){s+="%"+this.charCodeAt(i).toString(16);}return s;},decodeURL:function(){return decodeURIComponent(this.toString());}});jatX.augment(Array.prototype,{forEach:function(fCallback,thisObj){thisObj=typeof thisObj=="object"?thisObj:this;for(var i=0;i<this.length;i++){fCallback.call(thisObj,this[i],i,this);}return this;},filter:function(fCallback,thisObj){var _a=[];thisObj=typeof thisObj=="object"?thisObj:this;for(var i=0;i<this.length;i++){if(fCallback.call(thisObj,this[i],i,this))_a.push(this[i]);;}return _a;},every:function(fCallback,thisObj){},some:function(fCallback,thisObj){for(var i=0;i<this.length;i++){if(fCallback.call(thisObj||this,this[i],i,this)===true)return true;}return false;},map:function(fCallback,thisObj){},shuffle:function(){}});if(typeof console=="undefined"){console={log:function(v){return;var el=jatX.$("bug");var s="";if(typeof v=="object"){if(!v){s="";}else{s="<ul>";for(var p in v){var vv=v[p]||"";s+="<li>"+p+" : "+vv+"</li>";}s+="</ul>";}}else{s=s?v.toString():"";}el.innerHTML=s;}};}

jatX.Element=jatX.Class({__init:function(el){this._element=el;if(!this.valid())throw new Error("Invalid HTML element!");this.tagName=this._element.tagName;},valid:function(v){var v=v||this._element||this;if(!v)return false;if(typeof v=="object"){if(/object|function/i.test(typeof HTMLElement)&&v instanceof HTMLElement){return true;}else{if(!(v instanceof Object)&&v.nodeType&&v.nodeType==1)return true;return false;}}return false;},$value:function(){return this._element;},hasClass:function(sClass){if(typeof sClass!="string"||!sClass)return false;return new RegExp("(?:^|\\s+)"+sClass+"(?:\\s+|$)").test(this._element.className);},delClass:function(sClass){if(!sClass){this._element.className="";return this;}var a=this._element.className.split(/\s+/ig);a=a.filter(function(v){return sClass!=v;});this._element.className=a.join(" ");return this;},addClass:function(sClass){if(!this.hasClass(sClass)){this._element.className=this._element.className?this._element.className+" "+sClass:sClass;}return this;},className:function(sClass){if(typeof sClass=="string"&&sClass)this._element.className=sClass;return this;},setStyle:function(oStyle){var styleName;for(var stl in oStyle){if(typeof oStyle[stl]!="string"&&typeof oStyle[stl]!="number")continue;if(stl=="float"){styleName=this._element.currentStyle?"styleFloat":"cssFloat";}else{styleName=stl;}this._element.style[styleName]=oStyle[stl].toString();}return this;},getStyle:function(sName){var val=this._element.style[sName];if(!val){if(document.defaultView&&document.defaultView.getComputedStyle){val=document.defaultView.getComputedStyle(this._element,null).getPropertyValue(sName);}else if(this._element.currentStyle){sName=sName.replace(/\-([a-z])/ig,function($$,$1){return $1.toUpperCase();});val=this._element.currentStyle[sName];}else{val="";}}return val;},getInnerSize:function(){return{width:this._element.clientWidth,height:this._element.clientHeight};},getOffsetSize:function(){return{width:this._element.offsetWidth,height:this._element.offsetHeight};},getSize:function(){var _width=/^(\d+)(?:px)?$/i.test(this.getStyle("width"))?parseInt(RegExp.$1):0;var _height=/^(\d+)(?:px)?$/i.test(this.getStyle("height"))?parseInt(RegExp.$1):0;return{width:_width,height:_height};},setSize:function(oSize){if(typeof oSize.width=="number")this._element.style.width=Math.max(oSize.width,0)+"px";if(typeof oSize.height=="number")this._element.style.height=Math.max(oSize.height,0)+"px";return this;},getPosition:function(){var offTop=this._element.offsetTop;var offLeft=this._element.offsetLeft;var el=this._element;while(el=el.offsetParent){if(el.style.position=="absolute"||el.style.postion=="relative"||(el.style.overflow!="visible"&&el.style.overflow!="")){break;}offTop+=el.offsetTop;offLeft+=el.offsetLeft;}return{top:offTop,left:offLeft};},setPosition:function(oPos){if(!oPos)return;var x=oPos.left;var y=oPos.top;var z=oPos.z;var right=oPos.right;var bottom=oPos.bottom;if(typeof y=="number")this._element.style.top=y+"px";if(typeof x=="number")this._element.style.left=x+"px";if(typeof bottom=="number")this._element.style.bottom=bottom+"px";if(typeof right=="number")this._element.style.right=right+"px";if(typeof z=="number")this._element.style.zIndex=z;return this;},appendTo:function(elParent){if(elParent instanceof this.constructor)elParent._element.appendChild(this._element);else elParent.appendChild(this._element);return this;},appendChild:function(){for(var i=0;i<arguments.length;i++){this._element.appendChild(!this.valid(arguments[i])?arguments[i]._element:arguments[i]);}return this;},show:function(display){if(typeof display=="string"){this._element.style.display=display;return this;}var s=this._element.style;var b="block";var c={P:b,DIV:b,FORM:b,H1:b,H2:b,H3:b,H4:b,OL:b,UL:b,FIELDSET:b,TD:"table-cell",TH:"table-cell",LI:"list-item",TABLE:"table",THEAD:"table-header-group",TBODY:"table-row-group",TFOOT:"table-footer-group",TR:"table-row",COL:"table-column",COLGROUP:"table-column-group",CAPTION:"table-caption",DL:b,DT:b,DD:b};try{if(typeof c[this.tagName]=="string"){s.display=c[this.tagName];}else{s.display="inline";}}catch(e){s.display="block";}return this;},hide:function(){this._element.style.display="none";return this;},setVisible:function(bVisi){sVisi=bVisi?"visible":"hidden";this.setStyle({visibility:sVisi});return this;},parent:function(){var ct=this.constructor;return new ct(this._element.parentNode);},attribute:function(arg){if(typeof arg=="string")return this._element.getAttribute(arg);for(var p in arg){if(typeof arg[p]=="string")this._element.setAttribute(p,arg[p]);}return this;},property:function(arg){if(typeof arg=="string")return this._element[arg];for(var p in arg){this._element[p]=arg[p];}return this;},text:function(s){if(typeof s=="string"){if(typeof this._element.innerText!="undefined"){this._element.innerText=s;}else{this._element.textContent=s;}}var t=this._element.innerText||this._element.textContent;if(typeof t!="string")t="";return t;},html:function(s){if(typeof s=="string"){this._element.innerHTML=s;return this;}else{return this._element.innerHTML;}},replaceWith:function(el){if(!this.valid(el))throw new Error('invalid node');if(this._element.parentNode.replaceChild(el,this._element)){this._element=el;};return this;},die:function(){this._element.parentNode.removeChild(this._element);},scrollIntoView:function(){try{this._element.scrollIntoView();}catch(e){};return this;},addEvent:function(sName,fCallback,thisObj){jatX.event.bind(this._element,sName,fCallback,thisObj);return this;},delEvent:function(sName,fCallback){jatX.event.unbind(this._element,sName,fCallback);return this;}});

jatX.Table=jatX.Class({__use:{$class:jatX.Element,filter:function(p){return /^(instanceOf|addClass|className|valid|appendTo|attribute|property|parent|getPosition|setPosition|getSize|setSize)$/.test(p);}},__init:function(el){this._element=el;},$value:function(){return this._element;},insertRow:function(idx){return this._element.insertRow(idx);},addRow:function(iPos,iCells,sValue){iCells=(typeof iCells=="number"&&iCells)>0?Math.round(iCells):1;var _a=[];var r=this._element.insertRow(iPos);for(var i=0;i<iCells;i++){var c=r.insertCell(i);_a.push(c);if(sValue)c.innerHTML=sValue.replace(/%i/,i);}return _a;},removeRow:function(iPos){this._element.deleteRow(iPos);}});

jatX.event=function(){var _isReady=false;var _pool_domready=[];var _event_namespace="_jx_events";function _domready(fCallback){if(_isReady){fCallback();return;}_pool_domready.push(fCallback);}function _checkDOMReady(){return(document&&document.getElementsByTagName&&document.getElementById&&document.body);}function _fireDOMReady(){_isReady=true;while(_pool_domready.length>0){_pool_domready.shift()();}}(function(){(_checkDOMReady())?_fireDOMReady():setTimeout(arguments.callee,100);})();var _pool_bind=[];function handleEvent(event){var e=new jatX.Event(event);var _el=this===window?jatX.window:this;_el[_event_namespace][e.type].forEach(function(v,i){var _this=this;v.fn.call(v.obj||_this,e);},this);}function _bindDOM0(el,sType,fCallback,thisObj){var _name="on"+sType;var _el=(window===el)?jatX.window:el;if(!_el[_event_namespace])_el[_event_namespace]={};if(!_el[_event_namespace][sType]){_el[_event_namespace][sType]=[];if((el)[_name])_el[_event_namespace][sType].push({fn:el[_name],obj:null});if(el[_name]!=handleEvent)el[_name]=handleEvent;}_el[_event_namespace][sType].push({fn:fCallback,obj:thisObj});if(!_pool_bind.some(function(v){return v===el;}))_pool_bind.push(el);}function _unbindDOM0(el,sType,fCallback){var _el=(window===el)?jatX.window:el;if(el){if(typeof sType=="string"){if(typeof fCallback=="function"){_el[_event_namespace][sType]=_el[_event_namespace][sType].filter(function(v,i){return v.fn!==fCallback;});}else{delete _el[_event_namespace][sType];el["on"+sType]=null;}}else{for(var p in _el[_event_namespace]){el["on"+p]=null;}_el[_event_namespace]=null;}}else{while(_pool_bind.length>0){_unbind(_pool_bind.pop());}}}function _bind(el,eventName,eh,thisObj){switch(eventName){case"drag":_bindDrag(el,eh,thisObj);break;case"mouseenter":_bindMouseEnter(el,eh,thisObj);break;case"mouseleave":_bindMouseLeave(el,eh,thisObj);break;default:_bindDOM0(el,eventName,eh,thisObj);}}function _unbind(el,eventName,eh){switch(eventName){case"drag":_unbindDrag(el,eh);break;case"mouseenter":_unbindMouseEnter(el,eh);break;case"mouseleave":_unbindMouseLeave(el,eh);break;default:_unbindDOM0(el,eventName,eh);}}function _bindDrag(el,eh,thisObj){var _hl=("handleEvent"in eh)?eh.handleEvent:(typeof eh=="function")?eh:null;if(!_hl)throw new Error("Invalid drag event handler.");if(!el[_event_namespace])el[_event_namespace]={};if(!el[_event_namespace].jxDrag)el[_event_namespace].jxDrag=[];el[_event_namespace].jxDrag.push({fn:_hl,before:eh.before||null,after:eh.after||null,obj:thisObj});_bindDOM0(el,"mousedown",_initDrag);}function _initDrag(event){event.stop();this[_event_namespace].jxDrag.forEach(function(v,i){if(typeof v.before=="function"){v.before.call(v.obj||this,event);}},this);if(this.setCapture)this.setCapture();_bindDOM0(document,"mousemove",_drag,this);_bindDOM0(document,"mouseup",_drop,this);}function _drag(event){this[_event_namespace].jxDrag.forEach(function(v,i){v.fn.call(v.obj||this,event);},this);}function _drop(event){this[_event_namespace].jxDrag.forEach(function(v,i){if(typeof v.after=="function"){v.after.call(v.obj||this,event);}},this);if(this.releaseCapture)this.releaseCapture();_unbindDOM0(document,"mousemove",_drag);_unbindDOM0(document,"mouseup",_drop);}function _unbindDrag(el,eh){var _hl=eh.handleEvent||eh||null;if(eh){el[_event_namespace].jxDrag=el[_event_namespace].jxDrag.filter(function(v){return v.fn!==_hl||v.before!=(eh.before||null)||v.after!=(eh.after||null);});}else{el[_event_namespace]=null;}if(!el[_event_namespace].jxDrag||el[_event_namespace].jxDrag.length==0)_unbindDOM0(el,"mousedown",_initDrag);}function _bindMouseEnter(el,eventHandler,thisObj){}function _bindMouseLeave(el,eventHandler,thisObj){}function _unbindMouseEnter(el,eventHandler){}function _unbindMouseLeave(el,eventHandler){}_bindDOM0(window,"unload",_unbindDOM0);return{domready:_domready,bind:_bind,unbind:_unbind};}();jatX.ready=jatX.event.domready;

jatX.Event=jatX.Class({__init:function(e){e=this._event=e||window.event;this.target=e.target||e.srcElement;this.position=this.getPosition();this.key=this.getKey();this.button=this.getButton();this.type=this._event.type;},$value:function(){return this._event;},getPosition:function(){var _this=this;return{left:_this._event.clientX,top:_this._event.clientY};},getButton:function(){var _this=this;var eW=this._event.which;var eB=this._event.button;function _getMouseWheel(){return _this._event.wheelDelta==0||_this._event.detail==1?0:_this._event.wheelDelta<0||_this._event.detail>0?1:-1;}return{delta:_getMouseWheel(),left:eW?eB==0:!!(eB&1),middle:eW?eB==1:!!(eB&4),right:eW?eB==2:!!(eB&2)};},getKey:function(){var e=this._event;var k=e.keyCode||e.charCode;return{code:k,alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey,shift:e.shiftKey,up:(k==38),down:(k==40),left:(k==37),right:(k==39),enter:(k==13),esc:(k==27)};},stop:function(sType){var _event=this._event;if(typeof sType=="undefined"||!sType)sType="";sType=sType.toString().toLowerCase();switch(sType){case"default","1":_event.preventDefault?_event.preventDefault():_event.returnValue=false;break;case"bubble","propagation","2":_event.stopPropagation?_event.stopPropagation():_event.cancelBubble=true;break;default:_event.preventDefault?_event.preventDefault():_event.returnValue=false;_event.stopPropagation?_event.stopPropagation():_event.cancelBubble=true;}return this;}});

jatX.util.Drag=jatX.Class({__use:jatX.baseClass,__init:function(target,dragBox,opt){if(typeof target=="string")target=jatX.$(target);if(typeof dragBox=="string")dragBox=jatX.$(dragBox);if(!target)throw new Error("No target element specified");this.options=opt||{};this.target=jatX.$E(target);this.dragBox=dragBox?jatX.$E(dragBox):this.target;jatX.event.bind(this.target.$value(),"drag",this,this);},_offset:{top:0,left:0},handleEvent:function(e){if(this.disabled)return;var _this=this;var _top=e.position.top-this._offset.top;var _left=e.position.left-this._offset.left;var oPosition=(typeof this.options.adjust=="function")?this.options.adjust.call(this,_left,_top):{left:_left,top:_top};this.fireEvent("onBeforeDrag",[e,oPosition]);if(oPosition&&!this.stopped)this.dragBox.setPosition(oPosition);this.fireEvent("onDrag",[e,oPosition]);},before:function(e){var _p=this.dragBox.getPosition();this._offset.left=e.position.left-_p.left;this._offset.top=e.position.top-_p.top;this.fireEvent("onStart",[e,_p]);},after:function(e){this.fireEvent("onEnd",[e,this.dragBox.getPosition()]);},stop:function(){this.stopped=true;},start:function(){this.stopped=false;},disable:function(){this.disabled=true;},enable:function(){this.disabled=false;}});

jatX.UI.Window=jatX.Class({__use:jatX.baseClass,__init:function(opt){this.options=opt||{};var _this=this;this.minWidth=this.options.minWidth||200;this.minHeight=this.options.minHeight||80;this._create();this._bindStyles();this._bindEvents();this.collapsed=false;this._capWidthOffset=this.icon.getSize().width+this.buttonArea.getSize().width+4;this.setSize(this.options.width||this.minWidth,this.options.height||this.minHeight);},_style:{window:"jx_window",corner_top_left:"jx_window_bg_corner_top_left",corner_top_right:"jx_window_bg_corner_top_right",corner_bottom_left:"jx_window_bg_corner_bottom_left",corner_bottom_right:"jx_window_bg_corner_bottom_right",border_top:"jx_window_bg_border_top",border_bottom:"jx_window_bg_border_bottom",border_left:"jx_window_bg_border_left",border_right:"jx_window_bg_border_right",title_border_left:"jx_window_title_border_left",title_border_right:"jx_window_title_border_right",caption:"jx_window_caption",icon:"jx_window_icon",btn_close:"jx_window_btn_close",btn_min:"jx_window_btn_min",button_area:"jx_window_btn_area",title:"jx_window_title",body:"jx_window_body"},_create:function(){this.box=jatX.$E("<table>");this.title=jatX.$E("<div>");this.body=jatX.$E(this.options.body||"<div>");this.caption=jatX.$E("<span>");this.btnClose=jatX.$E("<li>");this.icon=jatX.$E("<span>");this.buttonArea=jatX.$E("<ul>");this.box.attribute({border:"0",cellPadding:"0",cellSpacing:"0"});var _bottom=this.box.addRow(0,3,"");var _middle=this.box.addRow(0,3,"");var _title=this.box.addRow(0,3,"");var _top=this.box.addRow(0,3,"");this.corners=[_top[0],_top[2],_bottom[2],_bottom[0]];this.borders=[_top[1],_middle[2],_bottom[1],_middle[0]];this.titleBorders=[_title[0],_title[2]];var _body=_middle[1];var _head=_title[1];this.title.appendTo(_head).appendChild(this.icon,this.caption,this.buttonArea);this.body.appendTo(_body);if(this.options.content)this.body.html(this.options.content);this.icon.className(this._style.icon);this.caption.className(this._style.caption).html(this.options.subject||"");this.buttonArea.appendChild(this.btnClose);this.box.appendTo(document.body);},_bindStyles:function(){this.box.className(this._style.window);this.corners[0].className=this._style.corner_top_left;this.corners[1].className=this._style.corner_top_right;this.corners[2].className=this._style.corner_bottom_right;this.corners[3].className=this._style.corner_bottom_left;this.borders[0].className=this._style.border_top;this.borders[1].className=this._style.border_right;this.borders[2].className=this._style.border_bottom;this.borders[3].className=this._style.border_left;this.titleBorders[0].className=this._style.title_border_left;this.titleBorders[1].className=this._style.title_border_right;this.title.className(this._style.title);this.body.className(this._style.body);this.icon.className(this._style.icon);this.caption.className(this._style.caption);this.buttonArea.className(this._style.button_area);this.btnClose.className(this._style.btn_close);},_bindEvents:function(){var _this=this;this.btnClose.addEvent("click",this.hide,this);new jatX.util.Drag(this.title,this.box);new jatX.util.Drag(this.borders[0],this.box,{adjust:function(left,top){var h=Math.max(this.tmpOffset-top,_this.minHeight,0);(h!=this.tmpOffset-top)?top=null:_this.body.$value().style.height=h+"px";return{left:null,top:top};}}).attach({onStart:function(e,p){this.tmpOffset=p.top+parseInt(_this.body.getStyle("height"));},onDrag:function(){_this.fireEvent("onResize");}});new jatX.util.Drag(this.borders[1],null,{adjust:function(left,top){return null;}}).attach({onStart:function(e,p){this.tmpOffset=e.position.left-parseInt(_this.body.getStyle("width"));},onDrag:function(e,p){var width=Math.max(e.position.left-this.tmpOffset,_this.minWidth,0);_this.setSize(width,null);}});new jatX.util.Drag(this.borders[2],null,{adjust:function(left,top){return null;}}).attach({onStart:function(e,p){this.tmpOffset=e.position.top-parseInt(_this.body.getStyle("height"));},onDrag:function(e,p){_this.body.$value().style.height=Math.max(e.position.top-this.tmpOffset,_this.minHeight,0)+"px";}});new jatX.util.Drag(this.borders[3],this.box,{adjust:function(left,top){var w=Math.max(this.tmpOffset-left,_this.minWidth,0);(w!=this.tmpOffset-left)?left=null:_this.setSize(w,null);return{left:left,top:null};}}).attach({onStart:function(e,p){this.tmpOffset=p.left+parseInt(_this.body.getStyle("width"));},onDrag:function(){_this.fireEvent("onResize");}});new jatX.util.Drag(this.corners[2],this.body,{adjust:function(left,top){return null;}}).attach({onStart:function(e,p){this.tmpOffsetLeft=e.position.left-parseInt(_this.body.getStyle("width"));this.tmpOffsetTop=e.position.top-parseInt(_this.body.getStyle("height"));},onBeforeDrag:function(e,p){var w=Math.max(e.position.left-this.tmpOffsetLeft,_this.minWidth,0);var h=Math.max(e.position.top-this.tmpOffsetTop,_this.minHeight,0);_this.setSize(w,h);}});},show:function(){this.box.show();},hide:function(){this.box.hide();},setPosition:function(x,y){this.box.setPosition({left:x,top:y});},decorate:function(el){this.body.replaceWith(el);var siz=this.body.getSize();this.setSize(siz.width,siz.height);},setSize:function(width,height){this.title.setSize({width:width});this.body.setSize({width:width,height:height});this.caption.setSize({width:width-this._capWidthOffset});},resizeTo:function(width,height){},collapse:function(){this.body.hide();this.collapsed=true;},expand:function(){this.body.show();this.collapsed=false;},setSubject:function(s){this.caption.text(s);},setContent:function(s){this.body.html(s);}});

jatX.util.Parser=jatX.Class({version:"0.1",__init:function(opt){this.style={cmd_box:"jx_debug_cmd_box",lang_type:"jx_debug_lang_type",lang_null:"jx_debug_lang_null",lang_nan:"jx_debug_lang_nan",lang_finite:"jx_debug_lang_finite",lang_array:"jx_debug_lang_array",lang_function:"jx_debug_lang_function",lang_number:"jx_debug_lang_number",lang_object:"jx_debug_lang_object",lang_boolean:"jx_debug_lang_boolean",lang_string:"jx_debug_lang_string",lang_undefined:"jx_debug_lang_undefined",lang_html:"jx_debug_lang_html",lang_err_message:"jx_debug_lang_err_message",lang_err_line:"jx_debug_lang_err_line",lang_err_file:"jx_debug_lang_err_file",lang_err_name:"jx_debug_lang_err_name"};this.cmd_history=[];this.currentCmdIndex=0;var owner=this;this._debugObj={$:jatX.$,log:function(s){owner.log(s);},list:function(o){owner.list(o);},clear:function(){owner.clear();},version:owner.version};this._parseDepth=0;this._parseMaxDepth=2;this.$box=jatX.$E("<div>");this.$logArea=jatX.$E("<ol>");this.$cmd_box=jatX.$E("<input-text>");this.window=new jatX.UI.Window({subject:"Javascript Console",body:this.$box});this.$logArea.appendTo(this.$box);this.window.setSize(550,140);this.$cmd_box.appendTo(jatX.$E("<div>").appendTo(this.window.body.parent()).className(this.style.cmd_box));this._bindEvents();},_bindEvents:function(){this.$cmd_box.addEvent("keydown",this._run,this);this.$cmd_box.addEvent("keydown",this.viewHistory,this);},_run:function(e,c){if(e.key.enter){e.stop();c=c||this.$cmd_box._element.value;if(c!=this.cmd_history[this.cmd_history.length-1]){this.cmd_history.push(c);this.currentCmdIndex=this.cmd_history.length;}this.$cmd_box._element.value="";this._logCmd(c);try{var f=function(){var e,f;return eval(c);};var res=f.call(this._debugObj);if(typeof res!="undefined"){this.log(res);}}catch(e){this._logErr(e);}}},_logErr:function(oErr){var name=oErr.name||"";var message=oErr.message||oErr.description||"";var lineNumber=oErr.lineNumber||0;var fileName=oErr.fileName||"";this._log(this._decoratVar("err_name",name+":")+this._decoratVar("err_message",message)+this._decoratVar("err_line",lineNumber)+this._decoratVar("err_file",fileName),"err");this._parseDepth=0;},_logCmd:function(s){this._log(">>> "+s,"cmd");this._parseDepth=0;},_log:function(s,type){var el=jatX.$E("<li>");this.$logArea.appendChild(el.html(s));if(type&&typeof type=="string"){el.className(type);}el.scrollIntoView();},_HtmlEncode:function(s){return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\r?\n/g,"<br />");},_decoratVar:function(varType,sLiteral){return"<span class=\""+this.style["lang_"+varType]+"\">"+sLiteral+"</span>";},parse:function(v,b,l){var _literal="";var _varName="";l=l||0;var _varType=typeof v;switch(_varType){case"object":this._parseDepth++;if(v===null){_literal="null";_varName="null";}else if(v instanceof Array){var _a=[];if(this._parseDepth<this._parseMaxDepth){f:for(var i=0;i<v.length;i++){if(l>i){_a.push(this.parse(v[i],true,l));}else{_a.push("...");break f;}}this._parseDepth--;}else{_a.push("...");}_literal="["+_a.join(", ")+"]"+(!b?" length="+v.length:"");}else if(jatX.Element.prototype.valid(v)){_literal="HTMLElement["+v.tagName+"]";_varName="html";}else{var _ao=[];var _i=0;if(this._parseDepth<this._parseMaxDepth){for(var p in v){if(l>_i++){_ao.push(p+": "+this.parse(v[p],true,l));}if(_i==l){_ao.push("...");break;}}this._parseDepth--;}else{_ao.push("...");}_literal="{"+_ao.join(", ")+"}";}_varName=v?v instanceof Array?"array":"object":"null";break;case"number":_literal=v.toString();_varName=isNaN(v)?"nan":!isFinite(v)?"finite":"number";break;case"function":_literal="function";_varName="function";break;case"string":_literal=this._HtmlEncode(v.toString());_varName="string";break;case"boolean":_literal=v?"true":"false";_varName="boolean";break;default:_literal="undefined";_varName="undefined";}return this._decoratVar(_varName,_literal)+(b?"":" "+this._decoratVar("type",Object.prototype.toString.apply(v)));},list:function(o){for(var p in o){this._log(p+": "+this.parse(o[p],false,1));this._parseDepth=0;}},viewHistory:function(e){if(e.key.up&&this.currentCmdIndex>0){this.$cmd_box._element.value=this.cmd_history[--this.currentCmdIndex];}if(e.key.down&&this.currentCmdIndex<this.cmd_history.length-1){this.$cmd_box._element.value=this.cmd_history[++this.currentCmdIndex];}},clear:function(){this.$logArea.html("");},log:function(){var v=[];if(this._parseDepth>0)return;for(var i=0;i<arguments.length;i++){v.push(this.parse(arguments[i],false,5));this._parseDepth=0;}this._log(v.join(", "));}});
