/*! Fabrik */
var Suboptions=new Class({Implements:[Options],options:{sub_initial_selection:[],defaultMax:0},initialize:function(t,e){this.setOptions(e),this.element=document.id(this.options.id),"null"===typeOf(this.element)&&confirm("oh dear - somethings gone wrong with loading the sub-options, do you want to reload?")&&location.reload(!0),this.watchButtons(),this.watchDefaultCheckboxes(),this.counter=0,this.name=t,Object.each(this.options.sub_values,function(t,e){var n=Object.contains(this.options.sub_initial_selection,t)?"checked='checked'":"";this.addSubElement(t,this.options.sub_labels[e],n)}.bind(this)),0===this.options.sub_values.length&&this.addSubElement("","",!1),Joomla.submitbutton=function(t){if("element.cancel"!==t&&!this.onSave())return!1;Joomla.submitform(t)}.bind(this)},watchDefaultCheckboxes:function(){this.element.addEvent("click:relay(input.sub_initial_selection)",function(e){1===this.options.defaultMax&&this.element.getElements("input.sub_initial_selection").each(function(t){t!==e.target&&(t.checked=!1)})}.bind(this))},watchButtons:function(){this.element.addEvent('click:relay(a[data-button="addSuboption"])',function(t){t.preventDefault(),this.addSubElement()}.bind(this)),this.element.addEvent('click:relay(a[data-button="deleteSuboption"])',function(t,e){t.preventDefault(),1<this.element.getElements("tbody tr").length&&e.getParent("tr").dispose()}.bind(this));this.element.getElements('a[data-button="addSuboption"]')},addOption:function(t){this.addSubElement(),t.stop()},removeSubElement:function(t){var e=t.target.id.replace("sub_delete_","");1<document.id("sub_subElementBody").getElements("li").length&&document.id("sub_content_"+e).dispose(),t.stop()},addJ3SubElement:function(t,e,n){var n=this._chx(t,n),i=this._deleteButton(),t=new Element("tr").adopt([new Element("td",{class:"handle subhandle"}),new Element("td",{width:"30%"}).adopt(this._valueField(t)),new Element("td",{width:"30%"}).adopt(this._labelField(e)),new Element("td",{width:"10%"}).set("html",n),i]),e=this.element.getElement("tbody");e.adopt(t),this.sortable?this.sortable.addItems(t):this.sortable=new Sortables(e,{handle:".subhandle"}),this.counter++},_valueField:function(t){return new Element("input",{class:"form-control-sm inputbox sub_values",type:"text",name:this.name+"[sub_values][]",id:"sub_value_"+this.counter,size:20,value:t,events:{change:function(t){fconsole("need to set this chb boxes value to the value field if selected, or set to blank")}}})},_labelField:function(t){return new Element("input",{class:"form-control-sm inputbox sub_labels",type:"text",name:this.name+"[sub_labels][]",id:"sub_text_"+this.counter,size:20,value:t})},_chx:function(t,e){return'<input class="form-check inputbox sub_initial_selection" type="checkbox" value="'+t+"\" name='"+this.name+"[sub_initial_selection][]' id=\"sub_checked_"+this.counter+'" '+e+" />"},_deleteButton:function(){return new Element("td",{width:"20%"}).set("html",this.options.delButton)},addSubElement:function(t,e,n){return this.addJ3SubElement(t,e,n)},onSave:function(){var n=[],t=document.id("jform_params_dropdown_populate"),e=!1;return(e="null"!==typeOf(t)&&""!==t.get("value")?!0:e)||$$(".sub_values").each(function(t){n.push(t.value)}),$$(".sub_initial_selection").each(function(t,e){t.value=n[e]}),!0}});