/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE
 * file distributed with this work for additional information regarding copyright ownership.  The ASF licenses this
 * file to You 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.
 */
forms_submitForm=function(){if(dojo){dojo.debug("DEPRECATED: forms_submitForm(), use cocoon.forms.submitForm(element[, name, params]) instead")}var B=document.getElementById("_cforms_default_form_");if(!B){for(var A=0;A<document.forms.length;A++){if(document.forms[A].getAttribute("dojoWidgetId")!=""){B=document.forms[A];B.setAttribute("id","_cforms_default_form_")}if(B){break}}}if(!B){B=document.forms[0]}cocoon.forms.submitForm.apply(cocoon.forms,[B])};forms_getForm=function(A){if(dojo){dojo.debug("DEPRECATED: forms_getForm(element), use cocoon.forms.getForm(element) instead")}cocoon.forms.getForm.apply(cocoon.forms,arguments)};forms_onsubmit=function(){if(dojo){dojo.debug("DEPRECATED: forms_onsubmit(), use cocoon.forms.callOnSubmitHandlers(form) instead")}var A=document.getElementById("_cforms_default_form_");cocoon.forms.callOnSubmitHandlers.apply(cocoon.forms,[A])};forms_onload=function(){if(dojo){dojo.debug("DEPRECATED: forms_onload(), use cocoon.forms.callOnLoadHandlers() instead")}cocoon.forms.callOnLoadHandlers.apply(cocoon.forms,arguments)};var forms_onloadHandlers=new Array();forms_onloadHandlers.push=function(A){if(dojo){dojo.debug("DEPRECATED: forms_onloadHandlers.push(handler), use cocoon.forms.addOnLoadHandler(handler) instead")}cocoon.forms.addOnLoadHandler.apply(cocoon.forms,arguments)};var forms_onsubmitHandlers=new Array();forms_onsubmitHandlers.push=function(B){if(dojo){dojo.debug("DEPRECATED: forms_onsubmitHandlers.push(handler), use cocoon.forms.addOnSubmitHandler(form, handler) instead")}var C=document.getElementById("_cforms_default_form_");if(!C){for(var A=0;A<document.forms.length;A++){if(document.forms[A].getAttribute("dojoWidgetId")!=""){C=document.forms[A];C.setAttribute("id","_cforms_default_form_")}if(C){break}}}if(!C){C=document.forms[0];if(C){C.setAttribute("id","_cforms_default_form_")}}cocoon.forms.addOnSubmitHandler.apply(cocoon.forms,[C,B])};function forms_moveInBody(A){A.parentNode.removeChild(A);document.body.appendChild(A)}function forms_createOptionTransfer(C,B){var A=new OptionTransfer(C+".unselected",C);A.setAutoSort(true);A.forms_id=C+":input";A.forms_onload=function(){var D=cocoon.forms.getForm(document.getElementById(this.forms_id));this.init(D);sortSelect(this.left);sortSelect(this.right)};A.submitOnChange=B;A.forms_transferLeft=function(){this.transferLeft();if(this.submitOnChange){cocoon.forms.submitForm(document.getElementById(this.forms_id))}};A.forms_transferRight=function(){this.transferRight();if(this.submitOnChange){cocoon.forms.submitForm(document.getElementById(this.forms_id))}};A.forms_transferAllLeft=function(){this.transferAllLeft();if(this.submitOnChange){cocoon.forms.submitForm(document.getElementById(this.forms_id))}};A.forms_transferAllRight=function(){this.transferAllRight();if(this.submitOnChange){cocoon.forms.submitForm(document.getElementById(this.forms_id))}};cocoon.forms.addOnLoadHandler(A);A.forms_onsubmit=function(){selectAllOptions(this.right)};cocoon.forms.addOnSubmitHandler(document.getElementById(C),A);return A}function forms_showTab(tabgroup,idx,length,state){if(state.length>0){document.getElementById(state).value=idx}for(var i=0;i<length;i++){var tab=document.getElementById(tabgroup+"_tab_"+i);if(tab!=null){tab.className=(i==idx)?"forms-tab forms-activeTab":"forms-tab"}var tabitems=document.getElementById(tabgroup+"_items_"+i);if(tabitems!=null){tabitems.style.display=(i==idx)?"":"none";if(i==idx&&window.onTabShownHandlers!=null&&window.onTabShownHandlers[tabgroup]!=null){var onShowHandler=window.onTabShownHandlers[tabgroup][tabgroup+"_items_"+i];if(onShowHandler!=null){eval(onShowHandler)}}}}}if(dojo){dojo.provide("cocoon.forms");dojo.provide("cocoon.forms.common")}else{cocoon=cocoon||{};cocoon.forms=cocoon.forms||{}}cocoon.forms.getForm=function(A){while(A!=null&&A.tagName!=null&&A.tagName.toLowerCase()!="form"){A=A.parentNode}return A};cocoon.forms.submitForm=function(B,A,E){var D=this.getForm(B);if(D==null){alert("Cannot find form for "+B);return }if(!A){A=B.name}var C=D.getAttribute("dojoWidgetId");if(C){dojo.widget.byId(C).submit(A,E)}else{if(!D.onsubmit||D.onsubmit()!=false){cocoon.forms.fullPageSubmit(D,A,E)}}};cocoon.forms.fullPageSubmit=function(C,B,E){E.forms_submit_id=B;if(cocoon.forms.callOnSubmitHandlers(C)){for(var D in E){var A=C[D]||document.createElement("input");A.setAttribute("type","hidden");A.setAttribute("name",D);A.setAttribute("value",E[D]);if(!C[D]){C.appendChild(A)}}C.submit()}};cocoon.forms.onLoadHandlers=new Array();cocoon.forms.addOnLoadHandler=function(A){if(A&&typeof (A.forms_onload)=="function"){cocoon.forms.onLoadHandlers.push(A)}};cocoon.forms.callOnLoadHandlers=function(){for(var A=0;A<cocoon.forms.onLoadHandlers.length;A++){cocoon.forms.onLoadHandlers[A].forms_onload()}cocoon.forms.onLoadHandlers=new Array()};cocoon.forms.onSubmitHandlers={};cocoon.forms.addOnSubmitHandler=function(A,B){if(B&&typeof (B.forms_onsubmit)=="function"){var C=this.getForm(A);if(C){var D=C.getAttribute("id");if(D){if(!cocoon.forms.onSubmitHandlers[D]){cocoon.forms.onSubmitHandlers[D]=new Array()}cocoon.forms.onSubmitHandlers[D].push(B)}else{if(dojo){dojo.debug("WARNING: SubmitHandler not added. There is no id attribute on your form.")}}}}};cocoon.forms.callOnSubmitHandlers=function(B){var C=B.getAttribute("id");if(cocoon.forms.onSubmitHandlers==null){return false}if(cocoon.forms.onSubmitHandlers[C]==null){return true}for(var A=0;A<cocoon.forms.onSubmitHandlers[C].length;A++){if(cocoon.forms.onSubmitHandlers[C][A].forms_onsubmit()==false){return false}}cocoon.forms.onSubmitHandlers[C]=null;return true};dojo.provide("cocoon.forms.manifest");(function(){var B={html:{cformsdraganddroprepeater:"cocoon.forms.CFormsDragAndDropRepeater",cformsform:"cocoon.forms.CFormsForm",simpleform:"cocoon.forms.SimpleForm",ajaxform:"cocoon.forms.AjaxForm",cformsrepeater:"cocoon.forms.CFormsRepeater",cformssuggest:"cocoon.forms.CFormsSuggest",dropdowndatetimepicker:"cocoon.forms.DropdownDateTimePicker",infopopup:"cocoon.forms.InfoPopup",multivalueeditor:"cocoon.forms.MultiValueEditor",multivalueeditorwithsuggestion:"cocoon.forms.MultiValueEditorWithSuggestion"},svg:{},vml:{}};function A(C,D){if(!D){D="html"}if(!B[D]){return null}return B[D][C]}dojo.registerModulePath("cocoon.ajax","../ajax/js");dojo.registerModulePath("cocoon.forms","../forms/js");dojo.registerNamespace("forms","cocoon.forms",A)})();dojo.provide("cocoon.ajax.insertion");dojo.require("dojo.dom");cocoon.ajax.insertion={};dojo.lang.mixin(cocoon.ajax.insertion,{before:function(A,B){return cocoon.ajax.insertionHelper.insert(A,B,function(C,D){C.parentNode.insertBefore(D,C)})},after:function(A,B){return cocoon.ajax.insertionHelper.insert(A,B,function(C,D){if(C.nextSibling){C.parentNode.insertBefore(D,C.nextSibling)}else{C.parentNode.appendChild(D)}})},top:function(A,B){return cocoon.ajax.insertionHelper.insert(A,B,function(C,D){if(C.firstChild){C.insertBefore(D,C.firstChild)}else{C.appendChild(D)}})},bottom:function(A,B){return cocoon.ajax.insertionHelper.insert(A,B,function(C,D){C.appendChild(D)})},inside:function(A,B){return cocoon.ajax.insertionHelper.insert(A,B,function(C,E){while(C.hasChildNodes()){var D=C.firstChild;if(D.nodeType==dojo.dom.ELEMENT_NODE){cocoon.ajax.insertionHelper.destroy(D)}C.removeChild(D)}C.appendChild(E)})},replace:function(A,B){return cocoon.ajax.insertionHelper.insert(A,B,function(C,D){C.parentNode.replaceChild(D,C);cocoon.ajax.insertionHelper.destroy(C)})}});cocoon.ajax.insertionHelper={};dojo.lang.mixin(cocoon.ajax.insertionHelper,{importNode:function(B,M){if(B.xml||dojo.lang.isString(B)){var L=dojo.lang.isString(B)?B:B.xml;var A=M.createElement("DIV");var N="(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)";var I=L.replace(new RegExp(N,"img"),"");var O="(<textarea[^<]*)/>";var C=I.match(O);var K=I.replace(new RegExp(O,"img"),"$1></textarea>");A.innerHTML=K;var J=new RegExp(N,"img");var H=new RegExp(N,"im");var E=L.match(J);var D=new Array();if(E){for(var G=0;G<E.length;G++){D.push(E[G].match(H)[1])}}return{element:dojo.dom.getFirstChildElement(A),scripts:D}}else{var D=new Array();var F=this._importDomNode(B,M,D);return{element:F,scripts:D}}},_importDomNode:function(B,J,C){switch(B.nodeType){case dojo.dom.ELEMENT_NODE:if(B.nodeName.toLowerCase()=="script"){C.push(B.firstChild&&B.firstChild.nodeValue);return }var E=J.createElement(B.nodeName);var H=B.attributes;for(var F=0;F<H.length;F++){var G=H[F];E.setAttribute(G.nodeName,G.nodeValue)}var A=B.childNodes;for(var D=0;D<A.length;D++){var I=this._importDomNode(A[D],J,C);if(I){E.appendChild(I)}}return E;break;case dojo.dom.TEXT_NODE:return J.createTextNode(B.nodeValue);break;case dojo.dom.CDATA_SECTION_NODE:return J.createTextNode(B.nodeValue);break}},_runScripts:function(imported){for(var i=0;i<imported.scripts.length;i++){eval(imported.scripts[i])}},insert:function(A,D,C){A=dojo.byId(A,D);var B=this.importNode(D,A.ownerDocument);C(A,B.element);this._runScripts(B);return this.parseDojoWidgets(B.element)},destroy:function(C){var D=dojo.widget.byNode(C);if(D){D.destroy(true,true)}else{var B=C.childNodes;for(var A=0;A<B.length;A++){var E=B[A];if(E.nodeType==dojo.dom.ELEMENT_NODE){this.destroy(E)}}}},parseDojoWidgets:function(B){var A=this.findParentWidget(B);var E=new dojo.xml.Parse();var D=document.createElement("DIV");B.parentNode.replaceChild(D,B);D.appendChild(B);var C=E.parseElement(D,null,true);dojo.widget.getParser().createComponents(C,A);B=D.firstChild;D.parentNode.replaceChild(B,D);A&&A.onResized();return B},findParentWidget:function(A){var B=A.parentNode;var C;while(B&&!C){var C=dojo.widget.byNode(B);if(C){return C}B=B.parentNode}}});dojo.provide("cocoon.ajax");dojo.provide("cocoon.ajax.common");dojo.require("cocoon.ajax.insertion");dojo.require("dojo.lfx.html");dojo.lang.mixin(cocoon.ajax,{update:function(A,D,C){if(dojo.lang.isString(D)){var B=D.split("#");if(B.length==2){C=B[0];D=dojo.byId(B[1])}else{D=dojo.byId(D)}}if(dojo.lang.isString(C)){C=cocoon.ajax.insertion[C]}C=C||cocoon.ajax.insertion.inside;dojo.io.bind({url:A,load:function(F,G,E){C(D,G)},mimetype:"text/plain"})},periodicalUpdate:function(B,A,D,C){dojo.require("dojo.lang.timing.Timer");var E=new dojo.lang.timing.Timer(B);E.onTick=function(){cocoon.ajax.update(A,D,C)};E.onStart=E.onTick;E.start();return E},effects:{highlight:{yellow:function(A){dojo.lfx.html.highlight(A,[240,238,133],1000).play(0)},blue:function(A){dojo.lfx.html.highlight(A,[141,133,252],1000).play(0)},red:function(A){dojo.lfx.html.highlight(A,[220,133,133],1000).play(0)},green:function(A){dojo.lfx.html.highlight(A,[159,223,133],1000).play(0)},grey:function(A){dojo.lfx.html.highlight(A,[128,128,128],1000).play(0)},purple:function(A){dojo.lfx.html.highlight(A,[197,133,220],1000).play(0)},orange:function(A){dojo.lfx.html.highlight(A,[252,202,133],1000).play(0)}},blink:function(B){var A=dojo.html.getOpacity(B);dojo.html.setOpacity(B,0.2);setTimeout(function(){dojo.html.setOpacity(B,A)},600)}}});dojo.provide("cocoon.ajax.BUHandler");dojo.require("dojo.dom");dojo.require("cocoon.ajax.common");dojo.require("cocoon.ajax.insertion");cocoon.ajax.BUHandler=function(){};cocoon.ajax.BUHandler.highlight=null;dojo.lang.extend(cocoon.ajax.BUHandler,{processResponse:function(G){var F=G.documentElement;var A=[];if(F.nodeName.toLowerCase()=="bu:document"){A=F.childNodes;dojo.debug("got response using: XMLHTTPTransport")}else{F=dojo.byId("browser-update",G);if(F){A=F.childNodes;dojo.debug("got response using: IframeTransport")}else{this.handleError("No response data found",G)}}for(var B=0;B<A.length;B++){var E=A[B];if(E.nodeType==dojo.dom.ELEMENT_NODE){var C=E.nodeName.replace(/.*:/,"").toLowerCase();if(C=="textarea"){C=E.getAttribute("name")}var D=this.handlers[C];if(D){D(E)}else{this.handleError("No handler found for element "+C,G)}}}},handleError:function(C,B){if(confirm(C+"\nShow server response?")){var A=window.open(undefined,"Cocoon Error","location=no,resizable=yes,scrollbars=yes");if(A==undefined){alert("You must allow popups from this server to display the response.")}else{var D=A.document;if(B.responseText){D.open();D.write(B.responseText);D.close()}else{if(B.childNodes){dojo.dom.copyChildren(D,B)}}}}},handlers:{replace:function(B){var E=B.getAttribute("id");if(!E){alert("no id found on update element");return }var C=dojo.dom.getFirstChildElement(B);if(!C&&B.nodeName.toLowerCase()=="textarea"){C=dojo.dom.createDocumentFromText(B.value).documentElement}var A=document.getElementById(E);if(!A){alert("no element '"+E+"' in source document");return }var D=cocoon.ajax.insertion.replace(A,C);if(typeof (cocoon.ajax.BUHandler.highlight)=="function"){cocoon.ajax.BUHandler.highlight(D)}}}});dojo.provide("cocoon.forms.SimpleForm");dojo.require("dojo.event");dojo.require("dojo.widget.DomWidget");dojo.require("cocoon.forms.common");dojo.widget.defineWidget("cocoon.forms.SimpleForm",dojo.widget.DomWidget,{ns:"forms",widgetType:"SimpleForm",isContainer:true,preventClobber:true,fillInTemplate:function(A,B){this.id=this.domNode.getAttribute("id");if(!this.id){dojo.debug("WARNING: IDs on forms are now required, this form may not work properly.")}this.domNode.setAttribute("dojoWidgetId",this.widgetId);dojo.event.connect("around",this.domNode,"onsubmit",this,"_browserSubmit");dojo.event.connect(this.domNode,"onclick",this,"_grabClickTarget")},_grabClickTarget:function(A){this.lastClickTarget=dojo.html.getEventTarget(A)},_browserSubmit:function(A){if(A.proceed()==false){return false}this.submit(this.lastClickTarget&&this.lastClickTarget.name);return false},submit:function(A,B){dojo.debug("SimpleForm.submit");if(!B){B={}}cocoon.forms.fullPageSubmit(this.domNode,A,B);if(this.domNode[A]){this.domNode[A].disabled=true}}});dojo.provide("cocoon.forms.AjaxForm");dojo.require("cocoon.forms.SimpleForm");dojo.require("cocoon.ajax.BUHandler");dojo.widget.defineWidget("cocoon.forms.AjaxForm",cocoon.forms.SimpleForm,{widgetType:"AjaxForm",submit:function(B,E){var D=this.domNode;var A="text/xml";if(!E){E={}}document.body.style.cursor="wait";var C=D.getAttribute("ajax-action").replace(/&amp;/g,"&");if(!C){C=D.action}if(C==""){C=document.location}E.forms_submit_id=B;E["cocoon-ajax"]=true;if(dojo.io.formHasFile(D)){dojo.require("dojo.io.IframeIO");A="text/html"}dojo.io.bind({url:C,handle:dojo.lang.hitch(this,function(F,G){this._handleBrowserUpdate(this,B,F,G)}),method:"post",mimetype:A,content:E,formNode:D,sendTransport:true});if(D[B]){D[B].disabled=true}},_handleBrowserUpdate:function(D,A,B,C){document.body.style.cursor="auto";if(this.domNode[A]){this.domNode[A].disabled=false}var E=new cocoon.ajax.BUHandler();if(B=="load"){if(!C){cocoon.ajax.BUHandler.handleError("No xml answer",C);return }E.handlers["continue"]=function(){D._continue()};E.processResponse(C)}else{if(B=="error"){E.handleError("Request failed",C)}else{dojo.debug("WARNING: dojo.io.bind returned an unhandled state : "+B)}}},_continue:function(){var C=this.domNode;if(C.method.toLowerCase()=="post"){var D=document.createElement("div");var B="<form method='POST'><input type='hidden' name='cocoon-ajax-continue' value='true'/>";if(C.elements["continuation-id"]){B+="<input type='hidden' name='continuation-id' value='"+C.elements["continuation-id"].value+"'/>"}B+="</form>";D.innerHTML=B;document.body.appendChild(D);D.firstChild.setAttribute("action",C.action);D.firstChild.submit()}else{var A="?cocoon-ajax-continue=true";if(C.elements["continuation-id"]){A+="&continuation-id="+C.elements["continuation-id"].value}window.location.href=C.action+A}}});dojo.io.checkChildrenForFile=function(B){var C=false;var A=B.getElementsByTagName("input");dojo.lang.forEach(A,function(D){if(C){return }if(D.getAttribute("type")=="file"&&!D.disabled&&D.value){C=true}});return C};

