PushButton.DISABLED_OPACITY=0.5;PushButton.IMAGE_POSITION_NONE=0;PushButton.IMAGE_POSITION_LEFT=1;PushButton.IMAGE_POSITION_RIGHT=2;PushButton.IMAGE_POSITION_TOP=3;PushButton.IMAGE_POSITION_BOTTOM=4;PushButton.IMAGE_POSITION_CENTER=5;PushButton.STATE_OFF=0;PushButton.STATE_ON=1;var BUTTON_IMAGE_PATH="../tmb_ui_/gray/Images/";function CreatePushButton(a,b){var c=a;if(a.nodeType!=Node.ELEMENT_NODE){c=document.getElementById(a)}if(!c.loaded){c.loaded=true;c.object=new PushButton(c,b)}return c.object}function PushButton(buttonElement,spec){var _self=this;if(!buttonElement||!spec){return}this.element=buttonElement;var styleElement=buttonElement;if(spec.originalID){styleElement=document.getElementById(spec.originalID);while(buttonElement.firstChild){buttonElement.removeChild(buttonElement.firstChild)}}this._initialWidth=spec.initialWidth||0;this._initialHeight=spec.initialHeight||0;this._leftImageWidth=spec.leftImageWidth||0;this._rightImageWidth=spec.rightImageWidth||0;this._topImageWidth=0;this._bottomImageWidth=0;this._containerLeft=0;this._containerRight=0;this._pressed=false;var imagePrefix=BUTTON_IMAGE_PATH+styleElement.id;this._bgIimageURL=imagePrefix+".png";this._pressedBgImageURL=imagePrefix+"_clicked.png";var style;this._backgroundElement=document.createElement("div");style=this._backgroundElement.style;style.position="absolute";style.top="0px";style.left="0px";style.right="0px";style.bottom="0px";this.element.appendChild(this._backgroundElement);this._backgroundElementPressed=this._backgroundElement.cloneNode(false);style=this._backgroundElementPressed.style;style.visibility="hidden";this.element.appendChild(this._backgroundElementPressed);this._containerElement=this._backgroundElement.cloneNode(false);style=this._containerElement.style;style.textOverflow="inherit";style.whiteSpace="inherit";this.element.appendChild(this._containerElement);this._textElement=document.createElement("span");style=this._textElement.style;style.display="inline";this._containerElement.appendChild(this._textElement);this._imageElement=document.createElement("img");style=this._imageElement.style;style.display="inline";style.verticalAlign="middle";this._containerElement.appendChild(this._imageElement);this._lineBreakElement=document.createElement("br");this._containerElement.appendChild(this._lineBreakElement);this._eventsElement=this._backgroundElement.cloneNode(false);style=this._eventsElement.style;this.element.appendChild(this._eventsElement);this._updateBackgroundImage();var text=spec.text||"";if(window.dashcode&&dashcode.getLocalizedString){text=dashcode.getLocalizedString(text)}this.setText(text);this.setImageURL(spec.customImage||"");this.setPressedImageURL(spec.customImagePressed||"");var imagePosition=(spec.customImagePosition==undefined)||(spec.customImagePosition.length<1)?PushButton.IMAGE_POSITION_NONE:eval(spec.customImagePosition);this.setImagePosition(imagePosition);this.buttonEventHandler=dashcode.CreateTouchButtonEventHandler(this._eventsElement);this.enabled=!spec.disabled;if(this.enabled){try{this.buttonEventHandler.setActionCallback(eval(spec.onclick))}catch(e){}}else{this.buttonEventHandler.eventsEnabled=false}this.buttonEventHandler.highlightCallback=function(pressed){_self._setPressed(pressed)};this.__defineSetter__("onclick",function(onclick){this.buttonEventHandler.setActionCallback(onclick)});this.__defineGetter__("onclick",function(){return this.buttonEventHandler.actionCallback})}PushButton.prototype.setEnabled=function(a){a=!(!a);if(this.enabled==a){return}this.enabled=a;var c=1;var b=document.defaultView.getComputedStyle(this.element,null);if(b){c=+b.getPropertyValue("opacity")}if(a){this.element.style.opacity=c*(1/PushButton.DISABLED_OPACITY);this.buttonEventHandler.eventsEnabled=true;this.element.style.appleDashboardRegion="dashboard-region(control rectangle)"}else{this.element.style.opacity=PushButton.DISABLED_OPACITY*c;this.element.style.appleDashboardRegion="none";this.buttonEventHandler.eventsEnabled=false}};PushButton.prototype.setText=function(a){this._textElement.innerText=a};PushButton.prototype.getText=function(){return this._textElement.innerText};PushButton.prototype.sizeToFit=function(a,b){var c=this._widthRequiredToFit();if(b&&(b<c)){c=parseInt(b)}else{if(a&&(a>c)){c=parseInt(a)}}this.element.style.width=c+"px";this._layoutElements()};PushButton.prototype.setImagePosition=function(a){this._imagePosition=a;this._layoutElements()};PushButton.prototype.getImagePosition=function(){return this._imagePosition};PushButton.prototype.setImageURL=function(b){this._customImageURL=b;this._customImageLoaded=false;if(this._customImageURL){this._customImage=new Image();var a=this;this._customImage.onload=function(){a._customImageLoaded=true;a._setCustomImage()};this._customImage.src=this._customImageURL}else{this._customImage=null;this._setCustomImage()}};PushButton.prototype.getImageURL=function(){return this._customImageURL};PushButton.prototype.setPressedImageURL=function(b){this._customImagePressedURL=b;this._customImagePressedLoaded=false;if(this._customImagePressedURL){this._customImagePressed=new Image();var a=this;this._customImagePressed.onload=function(){a._customImagePressedLoaded=true;a._setCustomImage()};this._customImagePressed.src=this._customImagePressedURL}else{this._customImagePressed=null;this._setCustomImage()}};PushButton.prototype.getPressedImageURL=function(){return this._customImagePressedURL};PushButton.prototype.setState=function(a){this._pressed=(a==PushButton.STATE_ON);if(this._pressed){this._backgroundElement.style.visibility="hidden";this._backgroundElementPressed.style.visibility="visible"}else{this._backgroundElement.style.visibility="visible";this._backgroundElementPressed.style.visibility="hidden"}this._setCustomImage();this._imageElement.offsetLeft};PushButton.prototype.getState=function(){return this._pressed?PushButton.STATE_ON:PushButton.STATE_OFF};PushButton.prototype._setCustomImage=function(){var a=this._imageElement.style;if(this._pressed&&this._customImagePressed&&this._customImagePressedLoaded){this._imageElement.src=this._customImagePressedURL;a.width=this._customImagePressed.width+"px";a.height=this._customImagePressed.height+"px"}else{if(!this._pressed&&this._customImage&&this._customImageLoaded){this._imageElement.src=this._customImageURL;a.width=this._customImage.width+"px";a.height=this._customImage.height+"px"}else{this._imageElement.src=null}}this._layoutElements()};PushButton.prototype._setPressed=function(b){var a=b?PushButton.STATE_ON:PushButton.STATE_OFF;this.setState(a)};PushButton.prototype._updateBackgroundImage=function(){if(!PushButton._webKitVersion){PushButton._webKitVersion=0;var f=RegExp("( AppleWebKit/)([^ ]+)").exec(navigator.userAgent);if(f&&f.length>=3){var b=f[2];var e=RegExp("[^\\.0-9]").exec(b);if(e){b=b.slice(0,e.index)}PushButton._webKitVersion=+b.split(".")[0]}}var a=PushButton._webKitVersion>=523?"repeat stretch":"stretch stretch";var c=""+this._topImageWidth+"px "+this._rightImageWidth+"px "+this._bottomImageWidth+"px "+this._leftImageWidth+"px";this._backgroundElement.style.borderWidth=c;this._backgroundElementPressed.style.borderWidth=c;if(this._leftImageWidth>0||this._rightImageWidth>0){this._backgroundElement.style.webkitBorderImage="url("+this._bgIimageURL+") "+this._topImageWidth+" "+this._rightImageWidth+" "+this._bottomImageWidth+" "+this._leftImageWidth+" "+a;this._backgroundElement.style.backgroundImage="";this._backgroundElementPressed.style.webkitBorderImage="url("+this._pressedBgImageURL+") "+this._topImageWidth+" "+this._rightImageWidth+" "+this._bottomImageWidth+" "+this._leftImageWidth+" "+a;this._backgroundElementPressed.style.backgroundImage=""}else{this._backgroundElement.style.webkitBorderImage="";this._backgroundElement.style.backgroundImage="url("+this._bgIimageURL+")";this._backgroundElement.style.backgroundRepeat="repeat-x";this._backgroundElementPressed.style.webkitBorderImage="";this._backgroundElementPressed.style.backgroundImage="url("+this._pressedBgImageURL+") ";this._backgroundElementPressed.style.backgroundRepeat="repeat-x"}var d=2;this._containerLeft=+this._leftImageWidth+d;this._containerRight=+this._rightImageWidth+d;if(this._containerLeft>this._containerRight){this._containerLeft=Math.ceil((this._containerRight+this._containerLeft)/2)}else{if(this._containerRight>this._containerLeft){this._containerRight=Math.ceil((this._containerRight+this._containerLeft)/2)}}this._containerElement.style.marginLeft=this._containerLeft+"px";this._containerElement.style.marginRight=this._containerRight+"px"};PushButton.prototype._layoutElements=function(){var r=this._imagePosition;if(!this._customImageLoaded&&!this._customImagePressedLoaded){r=PushButton.IMAGE_POSITION_NONE}var j=this._imageElement.style;var e=this._textElement.style;var k=this._containerElement.style;var p=this._lineBreakElement.style;var g=this.element.offsetHeight;if(g<1){g=this._initialHeight}var l=this.element.offsetWidth;if(l<1){l=this._initialWidth}if(r==PushButton.IMAGE_POSITION_NONE){e.position="static";j.display="none";e.display="inline";k.lineHeight=g+"px";k.overflow="hidden";k.marginTop="";p.display="none"}else{var a=this._textElement.offsetHeight;if(a<1){var o=document.defaultView.getComputedStyle(this._textElement,null);if(o){a=parseFloat(o.getPropertyValue("font-size"))}}var h=this._pressed?this._customImagePressed.width:this._customImage.width;var q=this._pressed?this._customImagePressed.height:this._customImage.height;var b=5;var n=5;if(r==PushButton.IMAGE_POSITION_LEFT||r==PushButton.IMAGE_POSITION_RIGHT){e.display="inline";j.display="inline";j.marginTop="";j.marginBottom="";k.marginTop="";k.lineHeight=g+"px";k.overflow="hidden";p.display="none";if(r==PushButton.IMAGE_POSITION_LEFT){this._containerElement.insertBefore(this._imageElement,this._textElement);j.marginLeft="";j.marginRight=b+"px"}else{this._containerElement.insertBefore(this._textElement,this._imageElement);j.marginLeft=b+"px";j.marginRight=""}}else{if(r==PushButton.IMAGE_POSITION_TOP||r==PushButton.IMAGE_POSITION_BOTTOM){e.display="inline";j.display="inline";j.marginLeft="";j.marginRight="";k.lineHeight="";k.overflow="hidden";var f=Math.floor((g-(a+q+n))/2);k.marginTop=Math.max(f,0)+"px";p.display="inline";if(r==PushButton.IMAGE_POSITION_TOP){j.marginTop="";j.marginBottom=n+"px";this._containerElement.insertBefore(this._imageElement,this._textElement);this._containerElement.insertBefore(this._lineBreakElement,this._textElement)}else{j.marginTop=n+"px";j.marginBottom="";this._containerElement.insertBefore(this._textElement,this._imageElement);this._containerElement.insertBefore(this._lineBreakElement,this._imageElement)}}else{e.display="none";j.display="inline";k.lineHeight=g+"px";k.overflow="visible";k.marginTop="";p.display="none";var c=h-(l-this._containerLeft-this._containerRight);var m=(c>0)?-c/2:0;var i=q-g;var d=(i>0)?-i/2:0;j.marginLeft=m+"px";j.marginTop=d+"px";j.marginRight="";j.marginBottom=""}}}};PushButton.prototype._widthRequiredToFit=function(){var c=this._textElement.offsetWidth;var b=0;if(this._imagePosition!=PushButton.IMAGE_POSITION_NONE&&(this._customImageLoaded||this._customImagePressedLoaded)){var a=this._pressed?this._customImagePressed.width:this._customImage.width;switch(this._imagePosition){case PushButton.IMAGE_POSITION_LEFT:case PushButton.IMAGE_POSITION_RIGHT:if(this._imageElement.style.marginLeft){b+=parseInt(this._imageElement.style.marginLeft)}if(this._imageElement.style.marginRight){b+=parseInt(this._imageElement.style.marginRight)}b+=c+a;break;default:if(c>a){b+=c}else{b+=a}break}}else{b+=c}b+=this._containerLeft+this._containerRight;return b};