/*
 * Copyright 2004-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
dojo.declare("Spring.DefaultEquals",null,{equals:function(_1){if(_1.declaredClass&&_1.declaredClass==this.declaredClass){return true;}else{return false;}}});dojo.declare("Spring.ElementDecoration",[Spring.AbstractElementDecoration,Spring.DefaultEquals],{constructor:function(_2){this.copyFields=new Array("name","value","type","checked","selected","readOnly","disabled","alt","maxLength","class","title");dojo.mixin(this,_2);if(this.widgetModule==""){this.widgetModule=this.widgetType;}},apply:function(){if(dijit.byId(this.elementId)){dijit.byId(this.elementId).destroyRecursive(false);}var _3=dojo.byId(this.elementId);if(!_3){console.error("Could not apply "+this.widgetType+" decoration.  Element with id '"+this.elementId+"' not found in the DOM.");}else{for(var _4 in this.copyFields){_4=this.copyFields[_4];if(!this.widgetAttrs[_4]&&_3[_4]&&(typeof _3[_4]!="number"||(typeof _3[_4]=="number"&&_3[_4]>=0))){this.widgetAttrs[_4]=_3[_4];}}if(_3["style"]&&_3["style"].cssText){this.widgetAttrs["style"]=_3["style"].cssText;}dojo.require(this.widgetModule);var _5=dojo.eval(this.widgetType);this.widget=new _5(this.widgetAttrs,_3);this.widget.startup();}return this;},validate:function(){if(!this.widget.isValid){return true;}var _6=this.widget.isValid(false);if(!_6){this.widget.state="Error";this.widget._setStateClass();}return _6;}});dojo.declare("Spring.ValidateAllDecoration",[Spring.AbstractValidateAllDecoration,Spring.DefaultEquals],{constructor:function(_7){this.originalHandler=null;this.connection=null;dojo.mixin(this,_7);},apply:function(){var _8=dojo.byId(this.elementId);this.originalHandler=_8[this.event];var _9=this;_8[this.event]=function(_a){_9.handleEvent(_a,_9);};return this;},cleanup:function(){dojo.disconnect(this.connection);},handleEvent:function(_b,_c){if(!Spring.validateAll()){dojo.stopEvent(_b);}else{if(dojo.isFunction(_c.originalHandler)){var _d=_c.originalHandler(_b);if(_d==false){dojo.stopEvent(_b);}}}}});dojo.declare("Spring.AjaxEventDecoration",[Spring.AbstractAjaxEventDecoration,Spring.DefaultEquals],{constructor:function(_e){this.connection=null;dojo.mixin(this,_e);},apply:function(){this.connection=dojo.connect(dojo.byId(this.elementId),this.event,this,"submit");return this;},cleanup:function(){dojo.disconnect(this.connection);},submit:function(_f){if(this.sourceId==""){this.sourceId=this.elementId;}if(this.formId==""){Spring.remoting.getLinkedResource(this.sourceId,this.params,this.popup);}else{Spring.remoting.submitForm(this.sourceId,this.formId,this.params);}dojo.stopEvent(_f);}});dojo.declare("Spring.RemotingHandler",Spring.AbstractRemotingHandler,{constructor:function(){},submitForm:function(_10,_11,_12){var _13=new Object();for(var key in _12){_13[key]=_12[key];}var _15=dojo.byId(_10);if(_15!=null){if(_15.value!=undefined&&_15.type&&("button,submit,reset").indexOf(_15.type)<0){_13[_10]=_15.value;}else{if(_15.name!=undefined){_13[_15.name]=_15.name;}else{_13[_10]=_10;}}}if(!_13["ajaxSource"]){_13["ajaxSource"]=_10;}dojo.xhrPost({content:_13,form:_11,handleAs:"text",headers:{"Accept":"text/html;type=ajax"},load:this.handleResponse,error:this.handleError});},getLinkedResource:function(_16,_17,_18){this.getResource(dojo.byId(_16).href,_17,_18);},getResource:function(_19,_1a,_1b){dojo.xhrGet({url:_19,content:_1a,handleAs:"text",headers:{"Accept":"text/html;type=ajax"},load:this.handleResponse,error:this.handleError,modal:_1b});},handleResponse:function(_1c,_1d){var _1e=_1d.xhr.getResponseHeader("Spring-Redirect-URL");var _1f=_1d.xhr.getResponseHeader("Spring-Modal-View");var _20=((dojo.isString(_1f)&&_1f.length>0)||_1d.args.modal);if(dojo.isString(_1e)&&_1e.length>0){if(_20){Spring.remoting.renderURLToModalDialog(_1e,_1d);return _1c;}else{if(_1e.indexOf("/")>=0){window.location=window.location.protocol+"//"+window.location.host+_1e;}else{var _21=window.location.protocol+"//"+window.location.host+window.location.pathname;var _22=_21.lastIndexOf("/");_21=_21.substr(0,_22+1)+_1e;if(_21==window.location){Spring.remoting.getResource(_21,_1d.args.content,false);}else{window.location=_21;}}return _1c;}}var _23="(?:<script(.|[\n|\r])*?>)((\n|\r|.)*?)(?:</script>)";var _24=[];var _25=new RegExp(_23,"img");var _26=new RegExp(_23,"im");var _27=_1c.match(_25);if(_27!=null){for(var i=0;i<_27.length;i++){var _29=(_27[i].match(_26)||["","",""])[2];_29=_29.replace(/<!--/mg,"").replace(/\/\/-->/mg,"").replace(/<!\[CDATA\[(\/\/>)*/mg,"").replace(/(<!)*\]\]>/mg,"");_24.push(_29);}}_1c=_1c.replace(_25,"");var _2a=dojo.doc.createElement("span");_2a.id="ajaxResponse";_2a.style.visibility="hidden";document.body.appendChild(_2a);_2a.innerHTML=_1c;var _2b=new dojo.NodeList(_2a);var _2c=_2b.query("#ajaxResponse > *").orphan();_2b.orphan();if(_20){Spring.remoting.renderNodeListToModalDialog(_2c);}else{_2c.forEach(function(_2d){if(_2d.id!=null&&_2d.id!=""){var _2e=dojo.byId(_2d.id);if(!_2e){console.error("An existing DOM elment with id '"+_2d.id+"' could not be found for replacement.");}else{_2e.parentNode.replaceChild(_2d,_2e);}}});}dojo.forEach(_24,function(_2f){dojo.eval(_2f);});return _1c;},handleError:function(_30,_31){dojo.require("dijit.Dialog");console.error("HTTP status code: ",_31.xhr.status);if(Spring.debug&&_31.xhr.status!=200){var _32=new dijit.Dialog({});dojo.connect(_32,"hide",_32,function(){this.destroyRecursive(false);});_32.domNode.style.width="80%";_32.domNode.style.height="80%";_32.domNode.style.textAlign="left";_32.setContent(_30.responseText);_32.show();}return _30;},renderURLToModalDialog:function(url,_34){url=url+"&"+dojo.objectToQuery(_34.args.content);Spring.remoting.getResource(url,{},true);},renderNodeListToModalDialog:function(_35){dojo.require("dijit.Dialog");var _36=new dijit.Dialog({});_36.setContent(_35);dojo.connect(_36,"hide",_36,function(){this.destroyRecursive(false);});_36.show();}});dojo.declare("Spring.CommandLinkDecoration",[Spring.AbstractCommandLinkDecoration,Spring.DefaultEquals],{constructor:function(_37){dojo.mixin(this,_37);},apply:function(){var _38=dojo.byId(this.elementId);if(!dojo.hasClass(_38,"progressiveLink")){var _39=new dojo.NodeList(_38);_39.addContent(this.linkHtml,"after").orphan("*");_38=dojo.byId(this.elementId);}_38.submitFormFromLink=this.submitFormFromLink;return this;},submitFormFromLink:function(_3a,_3b,_3c){var _3d=[];var _3e=dojo.byId(_3a);var _3f=document.createElement("input");_3f.name=_3b;_3f.value="submitted";_3d.push(_3f);dojo.forEach(_3c,function(_40){var _41=document.createElement("input");_41.name=_40.name;_41.value=_40.value;_3d.push(_41);});dojo.forEach(_3d,function(_42){dojo.addClass(_42,"SpringLinkInput");dojo.place(_42,_3e,"last");});if((_3e.onsubmit?!_3e.onsubmit():false)||!_3e.submit()){dojo.forEach(_3d,function(_43){_3e.removeChild(_43);});}}});dojo.addOnLoad(Spring.initialize);
