var tabEdit=Class.create();tabEdit.prototype=Object.extend(new freezeClass,{handleClass:"tabMove",draggableClass:"draggable",toggleSelector:".tabToggle",saveURL:"ajax.php",tabs:$A(),changed:false,listElem:null,saveElems:[],addFormElem:null,editFormElem:null,popElems:[],activityElems:[],editing:false,registered:false,defaultTab:null,currentEdit:null,state:null,initialize:function(){this.attach.root=this;this._pvt.root=this;},attach:{root:null,list:function(_1){_1=$(_1);if(!_1){throw "Argument must be a valid DOM node";}if(this.root.listElem){throw "A list element has already been attached to this instance";}this.root.listElem=_1;},toggle:function(_2){_2=$(_2);if(!_2){throw "Argument must be a valid DOM node";}_2.observe("click",this.root.toggle.bind(this.root));},add:function(_3){_3=$(_3);if(!_3){throw "Argument must be a valid DOM node";}_3.observe("click",this.root.addForm.bind(this.root));},save:function(_4){_4=$(_4);if(!_4){throw "Argument must be a valid DOM node";}if(this.root.changed){_4.show();}else{_4.hide();}_4.observe("click",this.root.save.bind(this.root));this.root.saveElems.push(_4);},addForm:function(_5){if(this.root.addFormElem){throw "An 'Add Form' element has already been attached to this instance";}_5=$(_5);if(!_5){throw "Argument must be a valid DOM node";}_5.hide();this.root.addFormElem=_5;_5.getElementsBySelector("form").each(function(_6){Event.observe(_6,"submit",this.submitAddForm.bind(this));}.bind(this.root));_5.getElementsBySelector("input").each(function(_7){$(_7).defaultValue=$(_7).value;});},editForm:function(_8){if(this.root.editFormElem){throw "An 'Edit Form' element has already been attached";}_8=$(_8);if(!_8){throw "Argument must be a valid DOM node";}_8.hide();this.root.editFormElem=_8;_8.getElementsBySelector("form").each(function(_9){Event.observe(_9,"submit",this.submitEdit.bind(this));}.bind(this.root));_8.getElementsBySelector("input").each(function(_a){$(_a).defaultValue=$(_a).value;});},pop:function(_b){_b=$(_b);if(!_b){throw "Argument must be a valid DOM node";}this.root.popElems=$A(this.root.popElems).without(_b);this.root.popElems.push(_b);_b.hide();},activity:function(_c){_c=$(_c);if(!_c){throw "Argument must be a valid DOM node";}this.root.activityElems=$A(this.root.activityElems).without(_c);this.root.activityElems.push(_c);_c.hide();},defaultTab:function(_d){this.root.defaultTab=_d.dup();}},register:function(){if(!this.listElem){throw "No list element has been registered with this instance";}this.registered=true;this.state=this.toQueryParams();return;},add:function(_e){if(this.frozen()){return;}this.tabs=$A(this.tabs);this.tabs.push(_e);_e.editorInstance=this;$(this.listElem).appendChild(_e.makeDOM());if(this.registered){if(this.editing){_e.show();this.remake();}else{_e.hide();}this.markChanged();}else{_e.hide();}_e.added();},create:function(_f){if(!this.defaultTab){throw "No default tab object has been attached to this instance";}var _10=this.defaultTab.dup();_10.set(_f);this.add(_10);},toggle:function(){if(!this.listElem){throw "No list element has been registered with this instance";}if(this.frozen()){return;}return this.editing?this.stop():this.start();},start:function(_11){if(!this.listElem){throw "No list element has been registered with this instance";}if(this.editing&&!_11){return true;}if(this.frozen()){return;}this.editing=true;$A(this.tabs).invoke("show");$$(this.toggleSelector).invoke("show");this._pvt.makeSortable();return true;},stop:function(_12){if(!this.listElem){throw "No list element has been registered with this instance";}if(!this.editing&&!_12){return true;}this.editing=false;$A(this.tabs).invoke("hide");$$(this.toggleSelector).invoke("hide");this.hideAddForm();this.hideEditForm();return true;},remake:function(){this._pvt.unmakeSortable();this.start(true);},addForm:function(){if(!this.addFormElem){throw "No list element has been registered with this instance";}if(this.frozen()){return;}this.addFormElem.toggle();this.hideEditForm();this.hidePop();return true;},submitAddForm:function(_13){if(_13){Event.stop(_13);}if(!this.addFormElem){throw "No list element has been registered with this instance";}if(this.frozen()){return;}var _14=this.addFormElem.getElementsBySelector("input").inject($H(),function(_15,_16){_16=$(_16);if(!_16.name||!_16.value||_16.type=="submit"){return _15;}_15[_16.name]=$F(_16);return _15;});this.hideAddForm();this.resetAdd();this.create(_14);return false;},resetAdd:function(){if(!this.addFormElem){throw "No list element has been registered with this instance";}this.addFormElem.getElementsBySelector("input").each(function(_17){_17=$(_17);if(_17.type=="submit"){return;}_17.value=_17.defaultValue;});},hideAddForm:function(){if(!this.addFormElem){return;}this.addFormElem.hide();resizeTopFrame();},editForm:function(tab){if(!this.editFormElem){throw "No 'Edit Form' element has been attached to this instance";}if(this.frozen()){return;}if(!$A(this.tabs).include(tab)){throw "Tab is not registered with this editor";}this.hideAddForm();if(this.editFormElem.visible()&&this.currentEdit==tab){return this.hideEditForm();}else{this.editFormElem.show();}this.currentEdit=tab;$(this.editFormElem).getElementsBySelector("input").each(function(_19){_19=$(_19);if(!_19||!_19.name){return;}var _1a=this.currentEdit.settings[_19.name];if(_19.type=="checkbox"){if(_19.value==_1a){_19.checked=true;}else{_19.checked=false;}}else{if(!this.currentEdit.settings[_19.name]){_19.value="";}else{_19.value=this.currentEdit.settings[_19.name];}}}.bind(this));resizeTopFrame();},submitEdit:function(_1b){if(!this.editFormElem){throw "No 'Edit Form' element has been attached to this instance";}if(!this.currentEdit){throw "No tab is currently being edited";}if(_1b){Event.stop(_1b);}if(this.frozen()){return;}var _1c=this.editFormElem.getElementsBySelector("input").inject($H(),function(_1d,_1e){_1e=$(_1e);if(!_1e.name||_1e.type=="submit"){return _1d;}_1d[_1e.name]=$F(_1e);return _1d;});this.currentEdit.set(_1c);this.remake();this.hideEditForm();this.markChanged();return false;},hideEditForm:function(){if(!this.editFormElem){return;}this.currentEdit=null;this.editFormElem.hide();resizeTopFrame();},remove:function(tab){if(this.frozen()){return;}if(!confirm("Are you sure you want to delete this tab?")){return;}if(this.currentEdit==tab){this.hideEditForm();}this.tabs=$A(this.tabs).without(tab);tab.getDOM().remove();this.remake();this.markChanged();},pop:function(tab,_21){this.hidePop();this.popElems=$A(this.popElems);if(!$A(this.tabs).include(tab)){throw "Tab is not registered with this editor";}var _22=new Template(_21,{onEmpty:function(){return "<i>None</i>";}});var _23=_22.evaluate(tab.settings);if(_22.evaluate($H())==_23){return this.popElems;}this.popElems.each(function(_24,_25){_25=$(_25);_25.update(_24);_25.show();}.bind(this,_23));resizeTopFrame();return this.popElems;},hidePop:function(){this.popElems=$A(this.popElems);this.popElems.invoke("hide");resizeTopFrame();return this.popElems;},updateTabList:function(){this.tabs=$A(this.tabs).sort(function(a,b){return $(a.getDOM()).relativeDOM(b.getDOM());});this.markChanged();},getTabPosition:function(tab){this.tabs=$A(this.tabs);if(!this.tabs.include(tab)){throw "Tab is not attached to this instance";}return this.tabs.indexOf(tab);},toQueryParams:function(){return $A(this.tabs).collect(function(tab){return tab.toQueryParams();}).compact().join("&");},save:function(){this.markChanged();if(!this.changed||this.frozen()){return;}if(!this.saveURL){throw "No save URL has been set";}this.freeze();this.stop();$A(this.saveElems).invoke("hide");$(this.activityElems).invoke("show");new Ajax.Request(this.saveURL,{parameters:this.toQueryParams(),method:"post",onFailure:function(){$(this.activityElems).invoke("hide");alert("An error occured while saving your results. Please try again.");this.unfreeze();this.changed=false;this.markChanged();}.bind(this),onSuccess:function(_2a){$(this.activityElems).invoke("hide");this.unfreeze();this.changed=false;this.state=this.toQueryParams();}.bind(this)});},markChanged:function(){if(this.frozen()){return;}if(this.state==this.toQueryParams()){$A(this.saveElems).invoke("hide");this.changed=false;}else{if(!this.changed){this.changed=true;$A(this.saveElems).invoke("show");$A(this.saveElems).each(function(_2b){new Effect.Pulsate(_2b,{duration:2,pulses:4,queue:"parallel"});});}}},_pvt:{root:null,makeSortable:function(){if(!this.root.listElem){throw "No list element has been registered with this instance";}if(this.root.frozen()){return;}Sortable.create(this.root.listElem,{constraint:"horizontal",only:this.root.draggableClass,handle:this.root.handleClass,onUpdate:this.root.updateTabList.bind(this.root)});},unmakeSortable:function(){if(!this.root.listElem){throw "No list element has been registered with this instance";}Sortable.destroy(this.root.listElem);}}});var tabDOM=Class.create();tabDOM.prototype=Object.extend(new quickDOM,{editorInstance:null,template:"<a href='#{URL}'>#{title}</a>",domTag:"li",hidden:true,toggleSelector:".tabToggle",editSelector:".tabEdit",deleteSelector:".tabDelete",popSelector:".tabPop",popTemplate:"<b>Username:</b> #{uname}, <b>Password Hint:</b> #{passHint}",postUpdate:function(){var dom=$(this.getDOM());dom.getElementsBySelector(this.editSelector).invoke("observe","click",this.edit.bind(this));dom.getElementsBySelector(this.deleteSelector).invoke("observe","click",this.remove.bind(this));dom.getElementsBySelector(this.popSelector).invoke("observe","click",this.pop.bind(this));},show:function(){this.getDOM().getElementsBySelector(this.toggleSelector,this.editSelector,this.deleteSelector).invoke("show");},hide:function(){this.getDOM().getElementsBySelector(this.toggleSelector,this.editSelector,this.deleteSelector).invoke("hide");},added:function(){},getPosition:function(){if(!this.editorInstance){throw "This tab is not attached to an editor instance";}return this.editorInstance.getTabPosition(this);},toQueryParams:function(){return $H(this.settings).collect(function(_2d){if(_2d.key&&_2d.value){return "tab["+this.getPosition()+"]["+encodeURIComponent(_2d.key)+"]="+encodeURIComponent(_2d.value);}else{return null;}}.bind(this)).compact().join("&");},remove:function(){if(!this.editorInstance){throw "This tab is not attached to an editor instance";}this.editorInstance.remove(this);},edit:function(){if(!this.editorInstance){throw "This tab is not attached to an editor instance";}this.editorInstance.editForm(this);},pop:function(_2e){if(!this.editorInstance){throw "This tab is not attached to an editor instance";}this.editorInstance.pop(this);}});var tabPop=Class.create();tabPop.prototype=Object.extend(new tabDOM,{popupPopTemplate:"<b>Username:</b> #{uname}, <b>Password Hint:</b> #{passHint}, <a href='#{URL}' target='_BLANK'>Click Here to Open a New Window</a>",pop:function(_2f){if(!this.editorInstance){throw "This tab is not attached to an editor instance";}if(this.settings.popup=="T"){Event.stop(_2f);this.editorInstance.pop(this,this.popupPopTemplate).each(function(_30){_30.getElementsBySelector("a").invoke("observe","click",this.hidePop.bind(this));}.bind(this.editorInstance));return false;}else{this.editorInstance.pop(this,this.popTemplate);return true;}}});