/*
 * @require jade/compat/Object.js
 * @require jade/HTMLUtils.js
 */
jade.compat.Widget=function(a,b){if(a&&!(a instanceof jade.compat.Widget))throw Error("Owner must be an instance of jade.compat.Widget");this.createRootElement();this.init();jade.compat.Object.call(this,a,b);this.addStyleId()};
jade.inherit(jade.compat.Widget,jade.compat.Object);jade.compat.Widget.prototype.rootElement=null;jade.compat.Widget.prototype.x=0;jade.compat.Widget.prototype.y=0;jade.compat.Widget.prototype.realX=0;jade.compat.Widget.prototype.realY=0;jade.compat.Widget.prototype.width=0;jade.compat.Widget.prototype.height=0;jade.compat.Widget.prototype.background=null;jade.compat.Widget.prototype.opacity=1;jade.compat.Widget.prototype.alignment=jade.ALIGN_NORTHWEST;jade.compat.Widget.prototype.mouseInWidget=!1;
jade.compat.Widget.prototype.form=null;jade.compat.Widget.prototype.mouseCapturing=!1;jade.compat.Widget.prototype.nextZIndex=1;jade.compat.Widget.prototype.enabled=!0;jade.compat.Widget.prototype.autoDrag=!1;jade.compat.Widget.prototype.scrollable=!1;jade.compat.Widget.prototype.assimilatedElementId=null;jade.compat.Widget.prototype.assimilatedElement=null;jade.compat.Widget.prototype.needExternalContent=!1;jade.compat.Widget.prototype.visible=!0;jade.compat.Widget.prototype.invalid=!1;
jade.compat.Widget.prototype.cursor="auto";jade.compat.Widget.prototype.createRootElement=function(){var a;this.rootElement=document.createElement("div");this.rootElement.ondragstart=function(){return!1};
this.rootElement.ondrag=function(){return!1};
this.rootElement.ondragend=function(){return!1};
a=this.rootElement.style;a.position="absolute";a.left=0;a.top=0;a.overflow="hidden";this.createElements(this.rootElement)};
jade.compat.Widget.prototype.addStyleId=function(){if(!this.rootElement.id)this.rootElement.id=this.getName()};
jade.compat.Widget.prototype.init=function(){};
jade.compat.Widget.prototype.createElements=function(a){};
jade.compat.Widget.prototype.setX=function(a){a=parseInt(a);if(this.x!=a)this.x=a,this.reposition()};
jade.compat.Widget.prototype.setY=function(a){a=parseInt(a);if(this.y!=a)this.y=a,this.reposition()};
jade.compat.Widget.prototype.setPosition=function(a,b){a=parseInt(a);b=parseInt(b);if(this.x!=a||this.y!=b)this.x=a,this.y=b,this.reposition()};
jade.compat.Widget.prototype.getPosition=function(){return{x:this.x,y:this.y}};
jade.compat.Widget.prototype.getX=function(){return this.x};
jade.compat.Widget.prototype.getY=function(){return this.y};
jade.compat.Widget.prototype.getWidth=function(){return this.width};
jade.compat.Widget.prototype.getHeight=function(){return this.height};
jade.compat.Widget.prototype.setWidth=function(a){a=parseInt(a);a<0&&(a=0);if(this.width!=a)this.width=a,this.resize()};
jade.compat.Widget.prototype.setHeight=function(a){a=parseInt(a);a<0&&(a=0);if(this.height!=a)this.height=a,this.resize()};
jade.compat.Widget.prototype.setSize=function(a,b){a=parseInt(a);b=parseInt(b);a<0&&(a=0);b<0&&(b=0);if(this.width!=a||this.height!=b)this.width=a,this.height=b,this.resize()};
jade.compat.Widget.prototype.getSize=function(){return{width:this.width,height:this.height}};
jade.compat.Widget.prototype.setAlignment=function(a){if(this.alignment!=a)this.alignment=a,this.reposition()};
jade.compat.Widget.prototype.getAlignment=function(){return this.alignment};
jade.compat.Widget.prototype.setMouseCapturing=function(a){this.mouseCapturing=a};
jade.compat.Widget.prototype.getMouseCapturing=function(){return this.mouseCapturing};
jade.compat.Widget.prototype.setGeometry=function(a,b,c,d,e){a=parseInt(a);b=parseInt(b);c=parseInt(c);d=parseInt(d);e=parseInt(e);c<0&&(c=0);d<0&&(d=0);if(this.x!=a||this.y!=b||this.alignment!=e)this.x=a,this.y=b,this.alignment=e,this.reposition();if(this.width!=c||this.height!=d)this.width=c,this.height=d,this.resize()};
jade.compat.Widget.prototype.getRealX=function(){return this.realX};
jade.compat.Widget.prototype.getRealY=function(){return this.realY};
jade.compat.Widget.prototype.reposition=function(){var a,b,c,d,e,f,g,h;e=this.alignment;c=this.width;d=this.height;a=this.x;b=this.y;if(e!=jade.ALIGN_NORTHWEST&&this.parent){g=this.parent.getWidth();h=this.parent.getHeight();if(e==jade.ALIGN_NORTH||e==jade.ALIGN_SOUTH||e==jade.ALIGN_CENTER)a+=g-c>>1;else if(e==jade.ALIGN_NORTHEAST||e==jade.ALIGN_EAST||e==jade.ALIGN_SOUTHEAST)a=g-c-a;if(e==jade.ALIGN_WEST||e==jade.ALIGN_EAST||e==jade.ALIGN_CENTER)b+=h-d>>1;else if(e==jade.ALIGN_SOUTHWEST||e==jade.ALIGN_SOUTH||
e==jade.ALIGN_SOUTHEAST)b=h-d-b}else a=this.x,b=this.y;f=this.rootElement;this.realX=a;this.realY=b;f.style.left=a+"px";f.style.top=b+"px";this.sendSignal("reposition",this.realX,this.realY);this.sendSignal("geometry",this.realX,this.realY,this.width,this.height)};
jade.compat.Widget.prototype.resize=function(){var a,b,c,d,e;e=this.rootElement;e.style.width=this.width+"px";e.style.height=this.height+"px";this.background instanceof jade.compat.Widget&&this.background.setSize(this.width,this.height);this.alignment!=jade.ALIGN_NORTHWEST&&this.reposition();if(!this.isLayouter()){a=this.getChildren();for(b=0,c=a.length;b<c;b++)d=a[b],d.getAlignment()!=jade.ALIGN_NORTHWEST&&d.reposition()}this.invalidate();this.sendSignal("resize",this.width,this.height);this.sendSignal("geometry",
this.realX,this.realY,this.width,this.height)};
jade.compat.Widget.prototype.invalidate=function(){if(!this.invalid)this.invalid=!0,jade.Schedular.schedule(1,this.repaint,this)};
jade.compat.Widget.prototype.repaint=function(){this.invalid=!1;this.paint()};
jade.compat.Widget.prototype.paint=function(){};
jade.compat.Widget.prototype.setBackground=function(a){if(a!=this.background)this.background instanceof jade.compat.Widget&&this.rootElement.removeChild(this.background.getRootElement()),a instanceof jade.compat.Widget?(this.rootElement.firstChild?this.rootElement.insertBefore(a.getRootElement(),this.rootElement.firstChild):this.rootElement.appendChild(a.getRootElement()),a.setSize(this.width,this.height)):this.rootElement.style.backgroundColor=a?a:"transparent",this.background=a};
jade.compat.Widget.prototype.getBackground=function(){return this.background};
jade.compat.Widget.prototype.setOpacity=function(a){this.opacity=a;this.rootElement.style.opacity=a;this.rootElement.style.filter="alpha(opacity="+Math.round(a*100)+")"};
jade.compat.Widget.prototype.getOpacity=function(){return this.opacity};
jade.compat.Widget.prototype.getRootElement=function(){return this.rootElement};
jade.compat.Widget.prototype.getInsertionPoint=function(){return null};
jade.compat.Widget.prototype.insertChild=function(a){var b;jade.compat.Object.prototype.insertChild.call(this,a);(b=this.getInsertionPoint())?this.rootElement.insertBefore(a.getRootElement(),b):this.rootElement.appendChild(a.getRootElement());a.getRootElement().style.zIndex=this.getNextZIndex();this.isLayouter()&&this.invalidate()};
jade.compat.Widget.prototype.getNextZIndex=function(){return this.nextZIndex++};
jade.compat.Widget.prototype.removeChild=function(a){a.releaseMouse();if(!jade.compat.Object.prototype.removeChild.call(this,a))return!1;this.rootElement.removeChild(a.getRootElement());this.isLayouter()&&this.invalidate();return!0};
jade.compat.Widget.prototype.clear=function(){var a,b;for(a=0,b=this.children.length;a<b;a++)this.rootElement.removeChild(this.children[a].getRootElement());jade.compat.Object.prototype.clear.call(this);this.isLayouter()&&this.invalidate()};
jade.compat.Widget.prototype.bringChildToFront=function(a){var b;jade.compat.Object.prototype.bringChildToFront.call(this,a);(b=this.getInsertionPoint())?this.rootElement.insertBefore(a.getRootElement(),b):this.rootElement.appendChild(a.getRootElement());this.isLayouter()&&this.invalidate();this.fixZIndexes()};
jade.compat.Widget.prototype.sendChildToBack=function(a){jade.compat.Object.prototype.sendChildToBack.call(this,a);var b=this.rootElement.firstChild;b||(b=this.getInsertionPoint());b?this.rootElement.insertBefore(a.getRootElement(),b):this.rootElement.appendChild(a.getRootElement());this.isLayouter()&&this.invalidate();this.fixZIndexes()};
jade.compat.Widget.prototype.fixZIndexes=function(){var a,b,c,d;c=this.getChildren();for(a=0,b=c.length;a<b;a++)d=c[a].getRootElement(),d.style.zIndex=a+1;this.nextZIndex=a};
jade.compat.Widget.prototype.mouseMove=function(a,b){var c,d,e,f,g;this.mouseInWidget||this.mouseEnter(a,b);c=this.getChildGeometries();for(e=c.length-1;e>=0;e--)if(d=c[e],f=a-d.x,g=b-d.y,f>=0&&g>=0&&f<=d.width&&g<=d.height){if(d.child.mouseMove(f,g),d.child.getMouseCapturing())break}else d.child.isMouseInWidget()&&d.child.mouseLeave();this.sendSignal("mouseMove",a,b)};
jade.compat.Widget.prototype.mouseEnter=function(a,b){this.mouseInWidget=!0;this.sendSignal("mouseEnter",a,b)};
jade.compat.Widget.prototype.mouseDown=function(a,b,c){var d,e,f,g,h;if(this.autoDrag)this.startDrag(a,b);else{if(!this.mouseCapturing){d=this.getChildGeometries();for(f=d.length-1;f>=0;f--)if(e=d[f],g=a-e.x,h=b-e.y,g>=0&&h>=0&&g<=e.width&&h<=e.height&&(e.child.mouseDown(g,h,c),e.child.getMouseCapturing()))break}this.sendSignal("mouseDown",a,b,c);this.mouseCapturing&&this.captureMouse()}};
jade.compat.Widget.prototype.captureMouse=function(){jade.compat.Application.getInstance().captureMouse(this)};
jade.compat.Widget.prototype.releaseMouse=function(){this.isMouseCaptured()&&jade.compat.Application.getInstance().releaseMouse()};
jade.compat.Widget.prototype.isMouseCaptured=function(){return jade.compat.Application.getInstance().isMouseCaptured(this)};
jade.compat.Widget.prototype.mouseUp=function(a,b){var c,d,e,f,g;c=this.getChildGeometries();for(e=c.length-1;e>=0;e--)if(d=c[e],f=a-d.x,g=b-d.y,f>=0&&g>=0&&f<=d.width&&g<=d.height&&(d.child.mouseUp(f,g),d.child.getMouseCapturing()))break;this.sendSignal("mouseUp",a,b)};
jade.compat.Widget.prototype.getChildGeometries=function(){var a,b,c,d,e,f;e=[];a=this.getChildren();for(c=0,d=a.length;c<d;c++)b=a[c],f={},f.child=b,f.x=b.getRealX(),f.y=b.getRealY(),f.width=b.getWidth(),f.height=b.getHeight(),e.push(f);return e};
jade.compat.Widget.prototype.click=function(a,b){var c,d,e,f,g;c=this.getChildGeometries();for(e=c.length-1;e>=0;e--)if(d=c[e],f=a-d.x,g=b-d.y,f>=0&&g>=0&&f<=d.width&&g<=d.height&&(d.child.click(f,g),d.child.getMouseCapturing()))break;this.sendSignal("click",a,b)};
jade.compat.Widget.prototype.mouseWheel=function(a,b,c){var d,e,f,g,h;d=this.getChildGeometries();for(f=d.length-1;f>=0;f--)if(e=d[f],g=a-e.x,h=b-e.y,g>=0&&h>=0&&g<=e.width&&h<=e.height&&(e.child.mouseWheel(g,h,c),e.child.getMouseCapturing()))break;this.sendSignal("mouseWheel",a,b,c)};
jade.compat.Widget.prototype.dblClick=function(a,b){var c,d,e,f,g;c=this.getChildGeometries();for(e=c.length-1;e>=0;e--)if(d=c[e],f=a-d.x,g=b-d.y,f>=0&&g>=0&&f<=d.width&&g<=d.height&&(d.child.dblClick(f,g),d.child.getMouseCapturing()))break;this.sendSignal("dblClick",a,b)};
jade.compat.Widget.prototype.mouseLeave=function(){var a,b,c;a=this.getChildren();for(b=0,c=a.length;b<c;b++)a[b].isMouseInWidget()&&a[b].mouseLeave();this.mouseInWidget=!1;this.sendSignal("mouseLeave")};
jade.compat.Widget.prototype.isLayouter=function(){return!1};
jade.compat.Widget.prototype.getPagePosition=function(){var a,b;a={};a.x=this.realX;a.y=this.realY;if(this.form)b=this.form.getPagePosition();else{if(!this.parent)throw Error("Unable to get page position from invisible widget");b=this.parent.getPagePosition()}a.x+=b.x;a.y+=b.y;return a};
jade.compat.Widget.prototype.enable=function(){this.enabled=!0;this.sendSignal("changeEnabled",!0)};
jade.compat.Widget.prototype.disable=function(){this.enabled=!1;this.sendSignal("changeEnabled",!1)};
jade.compat.Widget.prototype.isEnabled=function(){return this.enabled};
jade.compat.Widget.prototype.isMouseInWidget=function(){return this.mouseInWidget};
jade.compat.Widget.prototype.setAutoDrag=function(a){this.autoDrag=a};
jade.compat.Widget.prototype.getAutoDrag=function(){return this.autoDrag};
jade.compat.Widget.prototype.startDrag=function(a,b){jade.compat.application.startDrag(this);this.sendSignal("dragStart",a,b)};
jade.compat.Widget.prototype.endDrag=function(){this.sendSignal("dragEnd");jade.compat.application.endDrag(this)};
jade.compat.Widget.prototype.dragOver=function(a,b,c){var d,e,f,g,h,i;this.mouseInWidget||this.mouseEnter(a,b);d=this.getChildren();for(f=0,g=d.length;f<g;f++)e=d[f],h=a-e.getRealX(),i=b-e.getRealY(),h>=0&&i>=0&&h<=e.getWidth()&&i<=e.getHeight()?e.dragOver(h,i):e.isMouseInWidget()&&e.mouseLeave();this.sendSignal("dragOver",a,b,c)};
jade.compat.Widget.prototype.dragDrop=function(a,b,c){var d,e,f,g,h,i;d=this.getChildren();for(f=0,g=d.length;f<g;f++)e=d[f],h=a-e.getRealX(),i=b-e.getRealY(),h>=0&&i>=0&&h<=e.getWidth()&&i<=e.getHeight()&&e.dragDrop(h,i,c);this.sendSignal("dragDrop",a,b,c)};
jade.compat.Widget.prototype.setCursor=function(a){if(a!=this.cursor)this.cursor=this.getRootElement().style.cursor=a};
jade.compat.Widget.prototype.getCursor=function(){return this.cursor};
jade.compat.Widget.prototype.setScrollable=function(a){this.scrollable=a;this.getRootElement().style.overflow=a?"auto":"hidden"};
jade.compat.Widget.prototype.getScrollable=function(){return this.scrollable};
jade.compat.Widget.prototype.checkInnerSize=function(){return{width:this.rootElement.clientWidth?this.rootElement.clientWidth:this.width,height:this.rootElement.clientHeight?this.rootElement.clientHeight:this.height}};
jade.compat.Widget.prototype.assimilateElement=function(a){var b;this.assimilatedElementId=a;b=jade.compat.Application.getInstance();if(b.isLoaded()){this.assimilatedElement=document.getElementById(this.assimilatedElementId);if(!this.assimilatedElement)throw Error("No source element with id  "+this.assimilatedElementId+" for assimilation found");if(!this.rootElement)throw Error("Not root element for assimilation found");this.assimilatedElement.parentNode.removeChild(this.assimilatedElement);this.rootElement.appendChild(this.assimilatedElement);
this.assimilatedElement.style.display="block"}else b.isConnected("load",this.handleAssimilateElementOnLoad,this)||b.connect("load",this.handleAssimilateElementOnLoad,this)};
jade.compat.Widget.prototype.handleAssimilateElementOnLoad=function(){this.assimilateElement(this.assimilatedElementId)};
jade.compat.Widget.prototype.getNeedExternalContent=function(){return this.needExternalContent};
jade.compat.Widget.prototype.setNeedExternalContent=function(a){(this.needExternalContent=a)&&(jade.compat.application.isLoaded()?this.sendNeedExternalContentSignal():jade.compat.application.isConnected("load",this.sendNeedExternalContentSignal,this)||jade.compat.application.connect("load",this.sendNeedExternalContentSignal,this))};
jade.compat.Widget.prototype.sendNeedExternalContentSignal=function(){var a;this.rootElement.childNodes.length&&(a=this.rootElement.removeChild(this.rootElement.childNodes[0]));this.sendSignal("needExternalContent",this.rootElement,a)};
jade.compat.Widget.prototype.setVisibility=function(a){if(this.visible!=a)this.visible=a,this.getRootElement().style.visibility=a?"visible":"hidden",this.sendSignal("changeVisibility",a)};
jade.compat.Widget.prototype.getVisibility=function(){return this.visible};
jade.compat.Widget.prototype.busy=function(){jade.compat.Object.prototype.busy.call(this);this.busyCounter==1&&(jade.HTMLUtils.addClassName(this.getRootElement(),"busy"),this.invalidate())};
jade.compat.Widget.prototype.ready=function(){jade.compat.Object.prototype.ready.call(this);this.busyCounter||(jade.HTMLUtils.removeClassName(this.getRootElement(),"busy"),this.invalidate())};
jade.compat.Widget.prototype.setFullSize=function(a){var b;b=this.getParent();if(!this.parent)throw Error("Unable to set full size mode for an invisible widget");a?(this.parent.connect("resize",this.handleParentResize,this,!0),this.parent.resize()):this.parent.disconnect("resize",this.reposition,this)};
jade.compat.Widget.prototype.handleParentResize=function(a,b,c){this.setSize(b,c)};
jade.compat.Widget.prototype.setBackgroundColor=function(a){jade.Log.debug("!!!setBackgroundColor() is deprecated!!!");this.backgroundColor=a;this.rootElement.style.backgroundColor=a};
jade.compat.Widget.prototype.getBackgroundColor=function(){jade.Log.debug("!!!getBackgroundColor() is deprecated!!!");return this.backgroundColor};
jade.compat.Widget.prototype.setBackgroundImage=function(a){jade.Log.debug("!!!setBackgroundImage() is deprecated!!!");this.backgroundImage=a;this.rootElement.style.backgroundImage="url("+a+")"};
jade.compat.Widget.prototype.getBackgroundImage=function(){jade.Log.debug("!!!getBackgroundImage() is deprecated!!!");return this.backgroundImage};
jade.compat.Widget.prototype.getForm=function(){return this.form};
