var RFT={init:function(){RFT.layout=document.id("rft-layout");RFT.wrapper=document.getElement(".rft-wrapper");RFT.settings=document.id("rft-settings");
RFT.data=document.id("rft-data");RFT.importButton=document.id("import-button");RFT.visible=false;(6).times(function(a){var b=document.id("jform_params_data_col"+(a+1)+"-lbl");
if(b){(b.getParent("li")||b.getParent(".control-group")).dispose();}});RFT.reposition();RFT.attachEvents();RFT.layout.inject(document.body).setStyles({display:"block",top:-1000,left:-1000});
Tabs.init();RFT.importButton.addEvent("click",function(b){var a=document.id("templates").get("value");if(a=="_select_"||!a.length){return;}RFT.importTemplate(a);
});},attachEvents:function(){RFT.settings.addEvent("click",RFT.toggle);window.addEvent("resize",RFT.reposition);},toggle:function(){if(RFT.settings.hasClass("active")){RFT.visible=false;
RFT.layout.style.top="-1000px";RFT.settings.removeClass("active");window.removeEvent("scroll",RFT.reposition);}else{RFT.visible=true;RFT.reposition();RFT.settings.addClass("active");
window.addEvent("scroll",RFT.reposition);}},reposition:function(){if(!RFT.visible){return;}var a;if(document.getElement(".control-group")){RFT.layout.setStyle("padding-bottom",50);
a=RFT.wrapper.getPosition(),size={wrapper:RFT.wrapper.getSize(),button:RFT.settings.getSize(),panel:RFT.layout.getSize()};RFT.layout.setStyles({left:a.x-1,top:a.y+size.button.y-1});
}else{a=RFT.settings.getPosition(),size={button:RFT.settings.getSize(),panel:RFT.layout.getSize()};RFT.layout.setStyles({left:a.x-size.panel.x+size.button.x-1,top:a.y+size.button.y-1});
}},store:function(){var a=RFT.data.getElements("textarea").setStyle("display","none").set("value","");Panels.wrappers.each(function(d,c){var e=d.getElements(".row"),b="";
e.each(function(q,k){var m=q.getElements("input");var f=m.get("name"),n=m.get("value"),i=m.get("rel");var o={},g={};m.each(function(j,r){o[f[r]?f[r]:"_text"]=n[r]||"";
g[f[r]?f[r]:"_text"]=i[r]||"";});var h=o["class"].split(" "),p,l=[];if(h.length<=1){p=o["class"];l=[];}else{p=h[0];l=h.slice(1);}b+=p+"::"+(o.style?o.style+"|":"")+o._text+"\n";
if(o.sub!=g.sub){b+=p+"-sub::"+o.sub+"\n";}if(o.link!=g.link){b+=p+"-link::"+o.link+"\n";}if(l.join(" ").clean().trim().length){b+=p+"-classes::"+l.join(" ").clean().trim()+"\n";
}});a[c].set("value",b);});},clean:function(){(Tabs.removers.length).times(function(d){d=Tabs.removers.length-1;if(!d){return;}var b=Tabs.removers[d];var c=Tabs.removers.indexOf(b),f=false;
var e=Tabs.wrappers[c]||null;if(!e||Tabs.wrappers.length==1){return;}if(Tabs.wrappers[c].hasClass("active")){f=true;}Tabs.wrappers[c].dispose();Panels.wrappers[c].dispose();
Tabs.wrappers.erase(Tabs.wrappers[c]);Tabs.buttons.erase(Tabs.buttons[c]);Tabs.removers.erase(Tabs.removers[c]);Panels.wrappers.erase(Panels.wrappers[c]);
if(Tabs.wrappers.length<6){Tabs.plus.setStyle("display","block");}if(f){Tabs.tabClick(null,0);}Panels.refreshPanels();});Panels.rows=Panels.rows.slice(0,1);
var a=$$(Panels.actionButtons.flatten()).filter(function(b){return b.hasClass("remove");});a=$$(a.slice(1,a.length));a.fireEvent("click");Panels.actionButtons=Panels.actionButtons.slice(0,5);
Panels.rows[0].getElements("input[type=text]").forEach(function(b){b.set("value",b.get("rel"));});document.id("no_of_rows").set("text",Tabs.wrappers.length);
document.id("no_of_columns").set("text",Panels.rows.length);},parse:function(d){var b=d;var a=b.split("---"),c=[],e={};if(!a.length){return;}a=a.slice(0,6);
a.each(function(h,g){h=h.replace(/\n{1,}/g,"\n");var f=h.split("\n");if(f.length){f=f.erase("");e={};f.each(function(i,k){var m=i.split("::");e[m[0]]={value:m[1]};
var l=m[1].split("|");if(l[1]){e[m[0]]={value:l[1],style:l[0]};}["-sub","-link","-classes"].each(function(o){var j=o.replace("-","");var n=m[0].replace(o,"");
if(e[n]&&n!=m[0]){e[n][j]=m[1];delete e[m[0]];}});});c.push(e);}});return c;},importTemplate:function(c){RFT.clean();var a=RFT.parse(c),b=0;a.each(function(e,g){if(g>0){Tabs.plus.fireEvent("click");
}var f=0;for(var h in e){if(f>0){Panels.addRow(Panels.wrappers[g]);}var d=Panels.rows[b].getElements("input[type=text]");d[0].set("value",e[h]["value"]);
d[1].set("value",h+(e[h]["classes"]?" "+e[h]["classes"]:""));if(e[h]["sub"]){d[2].set("value",e[h]["sub"]);}if(e[h]["link"]){d[3].set("value",e[h]["link"]);
}if(e[h]["style"]){d[4].set("value",e[h]["style"]);}f++;b++;}});Tabs.tabClick(null,0);RFT.store();}};var Tabs={init:function(){Tabs.element=document.id("tabs");
Tabs.wrappers=$$(Tabs.element.getElements(".tab").flatten());Tabs.buttons=$$(Tabs.wrappers.getElements(".inner-tab").flatten());Tabs.removers=$$(Tabs.wrappers.getElements(".remove-column").flatten()).setStyle("opacity",0);
Tabs.plus=Tabs.element.getElement(".add-tab");Tabs.removers.set("tween",{duration:200});Tabs.actions();Panels.init();},actions:function(a){(a?Tabs.wrappers[a]:Tabs.wrappers).addEvents({mouseenter:Tabs.showRemover,mouseleave:Tabs.hideRemover});
(a?Tabs.buttons[a]:Tabs.buttons).addEvent("click",Tabs.tabClick);(a?Tabs.removers[a]:Tabs.removers).addEvent("click",Tabs.remove);if(!a){Tabs.plus.addEvent("click",Tabs.addNew);
}},addNew:function(){var b=Tabs.wrappers[0].clone(true,true);var a=Tabs.wrappers.length;b.set("class","tab tab-"+(a+1)).inject(this,"before");b.getElement(".column-title").set("text","COL "+(a+1));
Tabs.wrappers.push(b);Tabs.buttons.push(b.getElement(".inner-tab"));Tabs.removers.push(b.getElement(".remove-column"));Panels.addPanel(a);if(Tabs.wrappers.length>=6){Tabs.plus.setStyle("display","none");
}Tabs.actions(a);Tabs.tabClick(null,a);},showRemover:function(){var a=Tabs.wrappers.indexOf(this);var b=Tabs.removers[a]||null;if(b&&Tabs.wrappers.length>1){b.fade("in");
}},hideRemover:function(){var a=Tabs.wrappers.indexOf(this);var b=Tabs.removers[a]||null;if(b&&Tabs.wrappers.length>1){b.fade("out");}},tabClick:function(c,a){a=(a!=null)?a:Tabs.buttons.indexOf(this);
var b=Tabs.wrappers[a]||null;if(!b){return;}Tabs.wrappers.removeClass("active");b.addClass("active");Panels.switchPanel(a);RFT.reposition();},remove:function(){var a=Tabs.removers.indexOf(this),c=false;
var b=Tabs.wrappers[a]||null;if(!b||Tabs.wrappers.length==1){return;}if(Tabs.wrappers[a].hasClass("active")){c=true;}Tabs.wrappers[a].dispose();Panels.wrappers[a].dispose();
Tabs.wrappers.erase(Tabs.wrappers[a]);Tabs.buttons.erase(Tabs.buttons[a]);Tabs.removers.erase(Tabs.removers[a]);Panels.wrappers.erase(Panels.wrappers[a]);
if(Tabs.wrappers.length<6){Tabs.plus.setStyle("display","block");}if(c){Tabs.tabClick(null,0);}Panels.refreshPanels();}};var Panels={init:function(){Panels.wrappers=$$("#panels .panel");
Panels.rows=$$("#panels .panel .row");Panels.actionButtons=$$(Panels.rows.getElements(".row-action"));Panels.actions();Panels.refreshPanels();},switchPanel:function(a){Panels.wrappers.removeClass("active");
Panels.wrappers[a].addClass("active");},actions:function(a){(a?Panels.actionButtons[a]:Panels.actionButtons).addEvent("click",function(){if(this.hasClass("action-button")){var d=this.className;
d=d.trim().clean().split(" ");var b=(d.getLast()=="active")?d[d.length-2]:d.getLast();var c=this.getParent().getElement(".action-"+b);if(this.hasClass("active")){this.removeClass("active");
c.setStyle("display","none");}else{this.addClass("active");c.setStyle("display","block");}}else{if(this.hasClass("add")){Panels.addRow(this.getParent(),"after");
}else{if(this.getParent()&&!this.getParent().getSiblings().length){return;}var f=this.getParent();if(f){var e=f.getElements(".row-action");e.each(Panels.actionButtons.erase);
Panels.rows.erase(f);f.dispose();Panels.refreshRows();}}}RFT.reposition();});if(a&&Panels.rows[a]){$$($$(Panels.rows[a]).getElements("input[type=text]")).addEvent("keyup",RFT.store);
}else{$$($$(Panels.rows).getElements("input[type=text]")).addEvent("keyup",RFT.store);}},addPanel:function(){var a=Panels.wrappers[0].clone(false,true);
var c=Panels.wrappers.length;a.set("class","panel panel-"+(c+1)).inject(Panels.wrappers.getLast(),"after");var b=Panels.addRow(a);Panels.wrappers.push(a);
Panels.refreshPanels();},addRow:function(b,a){var c=Panels.rows[0].clone(true,true).inject(b,a||"inside");var f=c.getElements(".row-action");var e=b.hasClass("row")?b.className.match(/\d/)[0].toInt()+1:"1";
c.getElement("input").set("value","Row "+e);var d=c.getElements(".action-input");d.each(function(g){if(g.getParent().hasClass("action-class")){g.set("value","row-"+e);
}else{g.set("value",g.get("rel"));}});Panels.rows.push(c);f.each(function(g){Panels.actionButtons.push(g);Panels.actions(Panels.actionButtons.length-1);
if(g.hasClass("active")){g.fireEvent("click");}});Panels.refreshRows();},refreshPanels:function(){var a=0;Tabs.wrappers.each(function(c,b){c.getElement(".column-title").set("text","COL "+(b+1));
});Panels.wrappers.each(function(b,d){var e=b.hasClass("active");b.set("class","panel panel-"+(d+1));if(e){b.addClass("active");}var c=b.getChildren();
a=Math.max(a,c.length);c.each(function(l,h){l.set("class","row row-"+(h+1));l.getElement(".row-title").set("text","ROW "+(h+1));var k=l.getElement("input");
var i=k.get("value");if(i.match(/Row\s\d/)){k.set("value","Row "+(h+1));}var f=l.getElement(".action-class input");var g=f.get("value");if(g.match(/row\-\d/)){f.set("value","row-"+(h+1));
}});});document.id("no_of_rows").set("text",a);document.id("no_of_columns").set("text",Tabs.wrappers.length);RFT.store();},refreshRows:function(){Panels.refreshPanels();
}};window.addEvent("domready",RFT.init);