var Tapestry={FORM_VALIDATE_EVENT:"tapestry:formvalidate",FORM_PREPARE_FOR_SUBMIT_EVENT:"tapestry:formprepareforsubmit",FORM_PROCESS_SUBMIT_EVENT:"tapestry:formprocesssubmit",FIELD_FORMAT_EVENT:"tapestry:fieldformat",FIELD_VALIDATE_EVENT:"tapestry:fieldvalidate",FOCUS_CHANGE_EVENT:"tapestry:focuschange",DEBUG_ENABLED:false,CONSOLE_DURATION:10,onDOMLoaded:function(A){document.observe("dom:loaded",A)},onDomLoadedCallback:function(){Tapestry.ScriptManager.initialize();$$(".t-invisible").each(function(A){A.hide();A.removeClassName("t-invisible")});$$("INPUT","SELECT","TEXTAREA").each(function(B){var A=$T(B);if(!A.observingFocusChange){B.observe("focus",function(){if(B!=Tapestry.currentFocusField){document.fire(Tapestry.FOCUS_CHANGE_EVENT,B);Tapestry.currentFocusField=B}});A.observingFocusChange=true}});$$("INPUT[type=submit]").each(function(B){var A=$T(B);if(!A.trackingClicks){B.observe("click",function(){$T(B.form).lastSubmit=B});A.trackingClicks=true}})},init:function(A){$H(A).each(function(D){var B=D.key;var C=Tapestry.Initializer[B];if(C==undefined){Tapestry.error("Function Tapestry.Initializer.#{name}() does not exist.",{name:B});return }D.value.each(function(E){if(!Object.isArray(E)){E=[E]}C.apply(this,E)})})},error:function(B,A){Tapestry.updateConsole("t-err",B,A)},warn:function(B,A){Tapestry.updateConsole("t-warn",B,A)},debug:function(B,A){if(Tapestry.DEBUG_ENABLED){Tapestry.updateConsole("t-debug",B,A)}},updateConsole:function(A,C,B){if(B!=undefined){C=C.interpolate(B)}if(Tapestry.console==undefined){Tapestry.console=Tapestry.createConsole("t-console")}Tapestry.writeToConsole(Tapestry.console,A,C)},createConsole:function(C){var A=$$("BODY").first();var B=new Element("div",{"class":C});A.insert({top:B});return B},writeToConsole:function(A,C,D,F){var E=new Element("div",{"class":C}).update(D).hide();A.insert({top:E});new Effect.Appear(E,{duration:0.25});var B=new Effect.Fade(E,{delay:Tapestry.CONSOLE_DURATION,afterFinish:function(){E.remove()}});E.observe("click",function(){B.cancel();E.remove()})},updateAjaxConsole:function(A,C,B){if(Tapestry.ajaxConsole==undefined){Tapestry.ajaxConsole=Tapestry.createConsole("t-ajax-console")}if(B!=undefined){C=C.interpolate(B)}Tapestry.writeToConsole(Tapestry.ajaxConsole,A,C)},loadScriptsInReply:function(reply,callback){var redirectURL=reply.redirectURL;if(redirectURL){window.location.pathname=redirectURL;return }Tapestry.ScriptManager.addStylesheets(reply.stylesheets);Tapestry.ScriptManager.addScripts(reply.scripts,function(){callback.call(this);if(reply.script){eval(reply.script)}Tapestry.onDomLoadedCallback()})},ajaxFailureHandler:function(A){var B=A.getHeader("X-Tapestry-ErrorMessage");Tapestry.ajaxError("Communication with the server failed: "+B);Tapestry.debug("Ajax failure: Status #{status} for #{request.url}: "+B,A)},ajaxError:function(B,A){Tapestry.updateAjaxConsole("t-err",B,A)},ajaxRequest:function(B,A){return new Ajax.Request(B,{onSuccess:function(C,D){if(!C.request.success()){Tapestry.ajaxError("Server request was unsuccesful. There may be a problem accessing the server.");return }try{A.call(this,C,D)}catch(E){Tapestry.ajaxError("Client exception processing response: "+E)}},onException:Tapestry.ajaxFailureHandler,onFailure:Tapestry.ajaxFailureHandler})},findZoneManager:function(D){var B=$T(D).zoneId;var A=$(B);if(!A){Tapestry.ajaxError("Unable to locate Ajax Zone '#{id}' for dynamic update.",{id:B});return null}var C=$T(A).zoneManager;if(!C){Tapestry.ajaxError("Ajax Zone '#{id}' does not have an associated Tapestry.ZoneManager object.",{id:B});return null}return C},rebuildURL:function(C){if(C.match(/^https?:/)){return C}if(C.startsWith("/")){var A=window.location;return A.protocol+"//"+A.host+C}var B=this.stripToLastSlash(window.location.href);while(true){if(C.startsWith("../")){B=this.stripToLastSlash(B.substr(0,B.length-1));C=C.substring(3);continue}if(C.startsWith("./")){C=C.substr(2);continue}return B+C}},stripToLastSlash:function(A){var B=A.lastIndexOf("/");return A.substring(0,B+1)}};Element.addMethods({isDeepVisible:function(A){var B=$(A);while(true){if(!B.visible()){return false}if(B.tagName=="FORM"){break}B=$(B.parentNode)}return true}});Element.addMethods("FORM",{getFormEventManager:function(C){C=$(C);var B=$T(C);var A=B.formEventManager;if(A==undefined){A=new Tapestry.FormEventManager(C);B.formEventManager=A}return A},sendAjaxRequest:function(D,C,B){D=$(D);B=Object.clone(B||{});B.onFailure|=Tapestry.ajaxFailureHandler;var E=D.getElements().reject(function(G){return G.tagName=="INPUT"&&G.type=="submit"});var F=Form.serializeElements(E,true);var A=$T(D).lastSubmit;if(A&&A.name){F[A.name]=$F(A)}Object.extend(F,B.parameters);B.parameters=F;return new Ajax.Request(C,B)}});Element.addMethods(["INPUT","SELECT","TEXTAREA"],{getFieldEventManager:function(C){C=$(C);var B=$T(C);var A=B.fieldEventManager;if(A==undefined){A=new Tapestry.FieldEventManager(C);B.fieldEventManager=A}return A},showValidationMessage:function(A,B){A=$(A);$T(A).validationError=true;$T(A.form).validationError=true;A.getFieldEventManager().showValidationMessage(B);return A},removeDecorations:function(A){$(A).getFieldEventManager().removeDecorations();return A},addValidatorAsObserver:function(C,A,B){C.observe(A,function(E){try{B.call(this,$F(C))}catch(D){C.showValidationMessage(D)}});return C},addValidator:function(B,A){return B.addValidatorAsObserver(Tapestry.FIELD_VALIDATE_EVENT,A)},addFormatValidator:function(B,A){return B.addValidatorAsObserver(Tapestry.FIELD_FORMAT_EVENT,A)}});Tapestry.Initializer={ajaxFormLoop:function(A){var B=$(A.rowInjector);$(A.addRowTriggers).each(function(C){$(C).observe("click",function(D){$(B).trigger();Event.stop(D)})})},formLoopRemoveLink:function(A){var B=$(A.link);var C=A.fragment;B.observe("click",function(E){Event.stop(E);var D=function(I){var F=$(C);var G=$T(F).formFragment;if(G!=undefined){G.hideAndRemove()}else{var H=Tapestry.ElementEffect.fade(F);H.options.afterFinish=function(){F.remove()}}};Tapestry.ajaxRequest(A.url,D)})},linkZone:function(C,A,B){C=$(C);$T(C).zoneId=A;if(C.tagName=="FORM"){C.getFormEventManager().preventSubmission=true;C.observe(Tapestry.FORM_PROCESS_SUBMIT_EVENT,function(){var D=Tapestry.findZoneManager(C);if(!D){return }var E=function(F){D.processReply(F.responseJSON)};C.sendAjaxRequest(B,{onSuccess:E})});return }C.observe("click",function(E){Event.stop(E);var D=Tapestry.findZoneManager(C);if(!D){return }D.updateFromURL(B)})},validate:function(A,B){A=$(A);$(A.form).getFormEventManager();$(A).getFieldEventManager();B.each(function(C){var D=C[0];var E=C[1];var F=C[2];var G=Tapestry.Validator[D];if(G==undefined){Tapestry.error("Function Tapestry.Validator.#{name}() does not exist for field '#{fieldName}'.",{name:D,fieldName:A.id});return }G.call(this,A,E,F)})},zone:function(A){new Tapestry.ZoneManager(A)},formFragment:function(A){new Tapestry.FormFragment(A)},formInjector:function(A){new Tapestry.FormInjector(A)},linkTriggerToFormFragment:function(A,B){A=$(A);if(A.type=="radio"){$(A.form).observe("click",function(){$T(B).formFragment.setVisible(A.checked)});return }A.observe("click",function(){$T(B).formFragment.setVisible(A.checked)})}};if(window.console&&!Prototype.Browser.WebKit){var createlog=function(A){return function(C,B){if(B!=undefined){C=C.interpolate(B)}A.call(this,C)}};Tapestry.error=createlog(window.console.error);Tapestry.warn=createlog(window.console.warn);Tapestry.debug=createlog(window.console.debug)}Tapestry.Validator={INT_REGEXP:/^(\+|-)?\d+$/,FLOAT_REGEXP:/^(\+|-)?((\.\d+)|(\d+(\.\d*)?))$/,required:function(B,A){B.addFormatValidator(function(C){if(C.strip()==""){throw A}})},integernumber:function(B,A){B.addFormatValidator(function(C){if(C!=""&&!C.match(Tapestry.Validator.INT_REGEXP)){throw A}})},decimalnumber:function(B,A){B.addFormatValidator(function(C){if(C!=""&&!C.match(Tapestry.Validator.FLOAT_REGEXP)){throw A}})},minlength:function(C,B,A){C.addValidator(function(D){if(D.length<A){throw B}})},maxlength:function(C,B,A){C.addValidator(function(D){if(D.length>A){throw B}})},min:function(C,A,B){C.addValidator(function(D){if(D<B){throw A}})},max:function(C,A,B){C.addValidator(function(D){if(D>B){throw A}})},regexp:function(D,A,C){var B=new RegExp(C);D.addValidator(function(E){if(!B.test(E)){throw A}})}};Tapestry.ErrorPopup=Class.create({BUBBLE_VERT_OFFSET:-34,BUBBLE_HORIZONTAL_OFFSET:-20,BUBBLE_WIDTH:"auto",BUBBLE_HEIGHT:"39px",initialize:function(B){this.field=$(B);this.innerSpan=new Element("span");this.outerDiv=$(new Element("div",{id:this.field.id+":errorpopup","class":"t-error-popup"})).update(this.innerSpan).hide();var A=$$("BODY").first();A.insert({bottom:this.outerDiv});this.outerDiv.absolutize();this.outerDiv.observe("click",function(C){this.ignoreNextFocus=true;this.stopAnimation();this.outerDiv.hide();this.field.activate();Event.stop(C)}.bindAsEventListener(this));this.queue={position:"end",scope:this.field.id};Event.observe(window,"resize",this.repositionBubble.bind(this));document.observe(Tapestry.FOCUS_CHANGE_EVENT,function(C){if(this.ignoreNextFocus){this.ignoreNextFocus=false;return }if(C.memo==this.field){this.fadeIn();return }this.fadeOut()}.bind(this))},showMessage:function(A){this.stopAnimation();this.innerSpan.update(A);this.hasMessage=true;this.fadeIn()},repositionBubble:function(){var A=this.field.cumulativeOffset();this.outerDiv.setStyle({top:(A[1]+this.BUBBLE_VERT_OFFSET)+"px",left:(A[0]+this.BUBBLE_HORIZONTAL_OFFSET)+"px",width:this.BUBBLE_WIDTH,height:this.BUBBLE_HEIGHT})},fadeIn:function(){if(!this.hasMessage){return }this.repositionBubble();if(this.animation){return }this.animation=new Effect.Appear(this.outerDiv,{queue:this.queue,afterFinish:function(){this.animation=null;if(this.field!=Tapestry.currentFocusField){this.fadeOut()}}.bind(this)})},stopAnimation:function(){if(this.animation){this.animation.cancel()}this.animation=null},fadeOut:function(){if(this.animation){return }this.animation=new Effect.Fade(this.outerDiv,{queue:this.queue,afterFinish:function(){this.animation=null}.bind(this)})},hide:function(){this.hasMessage=false;this.stopAnimation();this.outerDiv.hide()}});Tapestry.FormEventManager=Class.create({initialize:function(A){this.form=$(A);this.form.onsubmit=this.handleSubmit.bindAsEventListener(this)},handleSubmit:function(C){var A=$T(this.form);A.validationError=false;var B=null;this.form.getElements().each(function(F){var E=$T(F).fieldEventManager;if(E!=undefined){var D=E.validateInput();if(D&&!B){B=F}}});this.form.fire(Tapestry.FORM_VALIDATE_EVENT,this.form);if(A.validationError){Event.stop(C);if(B){B.activate()}A.lastSubmit=null;return false}this.form.fire(Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT,this.form);if(this.preventSubmission){Event.stop(C);this.form.fire(Tapestry.FORM_PROCESS_SUBMIT_EVENT);return false}return true}});Tapestry.FieldEventManager=Class.create({initialize:function(A){this.field=$(A);var B=this.field.id;this.label=$(B+":label");this.icon=$(B+":icon");document.observe(Tapestry.FOCUS_CHANGE_EVENT,function(C){if(Tapestry.currentFocusField==this.field&&this.field.form==C.memo.form){this.validateInput()}}.bindAsEventListener(this))},removeDecorations:function(){this.field.removeClassName("t-error");if(this.label){this.label.removeClassName("t-error")}if(this.icon){this.icon.hide()}if(this.errorPopup){this.errorPopup.hide()}},showValidationMessage:function(A){this.field.addClassName("t-error");if(this.label){this.label.addClassName("t-error")}if(this.icon){if(!this.icon.visible()){new Effect.Appear(this.icon)}}if(this.errorPopup==undefined){this.errorPopup=new Tapestry.ErrorPopup(this.field)}this.errorPopup.showMessage(A)},validateInput:function(){if(this.field.disabled){return }if(!this.field.isDeepVisible()){return }var A=$T(this.field);A.validationError=false;this.field.fire(Tapestry.FIELD_FORMAT_EVENT,this.field);if(!A.validationError){var B=$F(this.field);if(B!=""){this.field.fire(Tapestry.FIELD_VALIDATE_EVENT,this.field)}}if(!A.validationError){this.field.removeDecorations()}return A.validationError}});Tapestry.ElementEffect={show:function(A){return new Effect.Appear(A)},highlight:function(A){return new Effect.Highlight(A)},slidedown:function(A){return new Effect.SlideDown(A)},slideup:function(A){return new Effect.SlideUp(A)},fade:function(A){return new Effect.Fade(A)}};Tapestry.ZoneManager=Class.create({initialize:function(A){if(Object.isString(A)){A={element:A}}this.element=$(A.element);this.showFunc=Tapestry.ElementEffect[A.show]||Tapestry.ElementEffect.show;this.updateFunc=Tapestry.ElementEffect[A.update]||Tapestry.ElementEffect.highlight;$T(this.element).zoneManager=this;var B=this.element.select(".t-zone-update");this.updateElement=B.first()||this.element},show:function(B){this.updateElement.update(B);var A=this.element.visible()?this.updateFunc:this.showFunc;A.call(this,this.element)},processReply:function(A){Tapestry.loadScriptsInReply(A,function(){this.show(A.content)}.bind(this))},updateFromURL:function(A){var B=function(C){this.processReply(C.responseJSON)}.bind(this);Tapestry.ajaxRequest(A,B)}});Tapestry.FormFragment=Class.create({initialize:function(A){if(Object.isString(A)){A={element:A}}this.element=$(A.element);$T(this.element).formFragment=this;this.hidden=$(A.element+":hidden");this.showFunc=Tapestry.ElementEffect[A.show]||Tapestry.ElementEffect.slidedown;this.hideFunc=Tapestry.ElementEffect[A.hide]||Tapestry.ElementEffect.slideup;var B=$(this.hidden.form);B.getFormEventManager();$(B).observe(Tapestry.FORM_PREPARE_FOR_SUBMIT_EVENT,function(){if(!this.element.isDeepVisible()){this.hidden.value=""}}.bind(this))},hide:function(){if(this.element.visible()){this.hideFunc(this.element)}},hideAndRemove:function(){var A=this.hideFunc(this.element);A.options.afterFinish=function(){this.element.remove()}.bind(this)},show:function(){if(!this.element.visible()){this.showFunc(this.element)}},toggle:function(){this.setVisible(!this.element.visible())},setVisible:function(A){if(A){this.show();return }this.hide()}});Tapestry.FormInjector=Class.create({initialize:function(A){this.element=$(A.element);this.url=A.url;this.below=A.below;this.showFunc=Tapestry.ElementEffect[A.show]||Tapestry.ElementEffect.highlight;this.element.trigger=function(){var B=function(F){var C=F.responseJSON;var E=new Element(this.element.tagName,{"class":this.element.className});var D={};D[this.below?"after":"before"]=E;Tapestry.loadScriptsInReply(C,function(){this.element.insert(D);E.update(C.content);E.id=C.elementId;this.showFunc(E)}.bind(this))}.bind(this);Tapestry.ajaxRequest(this.url,B);return false}.bind(this)}});Tapestry.ScriptLoadMonitor=Class.create({initialize:function(A,C){this.callback=C;this.loaded=0;this.toload=A.length;var B=this;A.each(function(E){if(Prototype.Browser.IE){var D=false;E.onreadystatechange=function(){if(!D&&(this.readyState=="loaded"||this.readyState=="complete")){D=true;B.loadComplete(E)}}}else{E.onload=B.loadComplete.bindAsEventListener(B,E)}});if(this.toload==0){this.callback.call(this)}},loadComplete:function(){this.loaded++;if(this.loaded==this.toload){this.callback.call(this)}}});Tapestry.ScriptManager={initialize:function(){this.emulated=false;if(!document.scripts){this.emulated=true;document.scripts=new Array();$$("script").each(function(A){document.scripts.push(A)})}},contains:function(B,C,A){return $A(B).any(function(E){var F=E[C];if(F.blank()){return false}var D=Prototype.Browser.IE?Tapestry.rebuildURL(F):F;return D==A});return false},addScripts:function(A,E){var C=new Array();if(A){var D=this.emulated;var B=$$("head").first();A.each(function(H){var G=Tapestry.rebuildURL(H);if(Tapestry.ScriptManager.contains(document.scripts,"src",G)){return }var F=new Element("script",{src:G,type:"text/javascript"});B.insert({bottom:F});C.push(F);if(D){document.scripts.push(F)}})}new Tapestry.ScriptLoadMonitor(C,E)},addStylesheets:function(B){if(!B){return }var A=$$("head").first();$(B).each(function(E){var D=Tapestry.rebuildURL(E.href);if(Tapestry.ScriptManager.contains(document.styleSheets,"href",D)){return }var C=new Element("link",{type:"text/css",rel:"stylesheet",href:D});if(E.media!=undefined){C.writeAttribute("media",E.media)}A.insert({bottom:C})})}};function $T(B){var C=$(B);var A=C._tapestry;if(!A){A={};C._tapestry=A}return A}Tapestry.onDOMLoaded(Tapestry.onDomLoadedCallback);