LFM.Dialog=Class.create({});LFM.Dialog.FORM="DIALOG_FORM";LFM.Dialog.STUB="DIALOG_STUB";LFM.Dialog.CUSTOM="DIALOG_CUSTOM";LFM.Dialog._stack=[];LFM.Dialog.hideStack=function(){LFM.Dialog._stack.invoke("hide",true);};LFM.Dialog.getFromStack=function(index){return LFM.Dialog._stack[index];};LFM.Dialog._onDrag=[];LFM.Dialog.registerDragCallback=function(callback){LFM.Dialog._onDrag.push(callback);};LFM.Dialog.DefaultOptions={resource:{type:"",id:"",url:""},type:LFM.Dialog.FORM,classname:"",title:"",content:LFM.String.loadingText,footerContent:"",action:"",confirmText:LFM.String.okText,cancelText:LFM.String.cancelText,showStatus:true,beforeConfirm:null,onConfirm:null,onCancel:null,onClose:null,confirmButton:null,cancelButton:null,overlayForm:null,showDone:true,fadeDone:false,onDone:null,onError:this.failure,width:"400px",maxHeight:"",zIndex:999999,position:"fixed",offset_top:100,modal:false,dismissable:true,showEffect:"Appear",onUpdate:null,contentMethod:"get",formMethod:"post",linkButtonForm:false};LFM.Dialog.prototype={initialize:function(options){Object.extend(this,LFM.Dialog.DefaultOptions);if(options){Object.extend(this,options);}for(k in this.resource){if(!this.resource[k]){delete this.resource[k];}}if(this.content==LFM.String.loadingText){this.type=LFM.Dialog.CUSTOM;}var u_platform=navigator.platform.toLowerCase();var u_agent=navigator.userAgent.toLowerCase();this._use_iframe=u_platform.indexOf("linux")>-1&&u_agent.indexOf("firefox/2")<0;if(u_agent.indexOf("msie 6")>-1){if(this.position=="fixed"){this.ie6_fixed_hack=true;}this.position="absolute";}},hover:false,_watchHoverState:function(){this.overlay.observe("mouseover",function(e){this.hover=true;}.bindAsEventListener(this));this.overlay.observe("mouseout",function(e){this.hover=false;}.bindAsEventListener(this));},_watch_esc:function(e){if(this.dismissable&&e.keyCode==Event.KEY_ESC){if(this.cancelButton){this.cancelButton.addClassName("activeButton");}this.hide();}},_invoke_drag_callbacks:function(draggable){LFM.Dialog._onDrag.each(function(callback){if(Object.isFunction(callback)){callback();}});this.overlay.setStyle({"zIndex":this.zIndex});if(this._use_iframe){this.iframe.setStyle({"zIndex":this.zIndex});}},_reposition_iframe:function(){if(!this._use_iframe){return false;}var offsets=document.viewport.getScrollOffsets();this.iframe.setStyle({"top":offsets.top+"px"});},_bindConfirm:function(){this.confirmButton=$(this.confirmButton);if(this.confirmButton){this.confirmButton.addClassName("dialogButton");this.confirmButton.addClassName("dialogConfirm");if(this.beforeConfirm){this.confirmButton.observe("click",this.beforeConfirm.bindAsEventListener(this));}else{this.confirmButton.observe("click",this.busy.bind(this));}if(this.onConfirm){this.confirmButton.observe("click",this.onConfirm.bindAsEventListener(this,this.resource));}else{if(this.overlayForm&&!this.linkButtonForm){this.confirmButton.observe("click",function(e){e.stop();if(this.overlayForm.action){var params={};if(!this.resource.id){Object.extend(params,this.parameters);Object.extend(params,this.resource);}this.overlayForm.request({parameters:params,onComplete:this.finalHandler.bind(this)});}else{this.hide();}}.bindAsEventListener(this));}}}},_bindCancel:function(){this.cancelButton=$(this.cancelButton);if(this.cancelButton){this.cancelButton.addClassName("dialogButton").addClassName("dialogCancel");this.cancelButton.observe("click",function(e){e.stop();if(this.onCancel){this.onCancel.bind(this)();}else{if(this.parent){this.showParent();}else{this.hide();}}}.bindAsEventListener(this));}},_restack:function(){LFM.Dialog._stack.push(this);},_addClickSource:function(){var clickSource=LFM.Page.Tracker.retrieveTagSource();if(this.overlayForm&&clickSource){this.overlayForm.insert(new Element("input",{"type":"hidden","name":"clickSource","value":clickSource}));}},busy:function(){if(this.status){this.status.className="dialogStatus dialogBusy";}},idle:function(){if(this.status){this.status.className="dialogStatus dialogClose";}},failure:function(){if(this.status){this.status.className="dialogStatus dialogFailure";}},_showOverlay:function(reload){var new_overlay=false;if(!this.overlay){LFM.Dialog.hideStack();this.overlay=new Element("div",{"class":"dialogBox"});this._watchHoverState();this._restack();this.overlay.hide();new_overlay=true;}if(reload||new_overlay){this.overlay.update();this._setupStatus();if(this.title){this.overlayTitle=new Element("h3");this.overlay.insert(this.overlayTitle);this.overlayTitle.update(this.title);}else{this.overlayTitle=null;}this.overlayError=new Element("div");this.overlayError.hide();this.overlay.insert(this.overlayError);this.updateContent(this.content);if(this.type===LFM.Dialog.FORM||this.type===LFM.Dialog.STUB){this.overlayForm=$(this.overlayForm);if(!this.overlayForm){this.overlayForm=new Element("form",{"class":"dialogForm",action:this.action,method:this.formMethod||"post"});}this.overlayForm.update();if(this.resource&&this.resource.type&&this.resource.id){if(!this.res_type_input){this.res_type_input=new Element("input",{"type":"hidden","name":"type"});this.overlayForm.insert(this.res_type_input);}if(!this.res_id_input){this.res_id_input=new Element("input",{"type":"hidden","name":"id"});this.overlayForm.insert(this.res_id_input);}this.res_type_input.writeAttribute("value",this.resource.type);this.res_id_input.writeAttribute("value",this.resource.id);}this.overlayButtons=new Element("div",{"class":"dialogButtons"});if(this.footerContent){this.overlayButtons.insert(this.footerContent);}if(this.action&&this.dismissable){this.formToken=new Element("input",{type:"hidden",name:"formtoken",value:LFM.Session.formtoken});this.overlayForm.insert(this.formToken);if(!this.cancelButton){this.cancelButton=new Element("input",{type:"button","class":"button",value:this.cancelText});this.overlayButtons.insert(this.cancelButton);}}if(!this.confirmButton&&this.dismissable){this.confirmButton=new Element("input",{type:"submit","class":"confirmButton",value:this.confirmText});this.overlayButtons.insert(this.confirmButton);}if(this.type===LFM.Dialog.STUB){if(this.confirmButton){this.overlayForm.insert(this.overlayButtons);}this.overlay.insert(this.overlayContent).insert(this.overlayForm);}else{if(this.type===LFM.Dialog.FORM){this.overlayForm.insert(this.overlayContent);if(this.confirmButton){this.overlayForm.insert(this.overlayButtons);}this.overlay.insert(this.overlayForm);}}}else{if(this.type===LFM.Dialog.CUSTOM){this.overlay.insert(this.overlayContent);this.overlayForm=$(this.overlayForm);}}this._bindConfirm();this._bindCancel();this._bound_watch_esc=this._watch_esc.bindAsEventListener(this);document.observe("keypress",this._bound_watch_esc);if(this.classname){this.overlay.addClassName(this.classname);}this._setupModalBlock();this._setupIframe();$("page").insert(this.overlay);this.overlay.setStyle({"zIndex":this.zIndex,"width":this.width,"position":this.position});this._setupPositioning();this._setupDragging();}if(!reload){LFM.Dialog.hideStack();}if(this._use_iframe){this.iframe.show();this._iframe_repositioning=setInterval(this._reposition_iframe.bind(this),200);}var afterShow=function(){try{if(this.confirmButton&&this.confirmButton.visible()){this.confirmButton.focus();}}catch(err){}};var effectOptions={duration:0.3,afterFinish:function(){setTimeout(afterShow.bind(this),20);}.bind(this)};if(Object.isFunction(this.showEffect)){new Effect.Parallel(this.showEffect.bind(this)(),effectOptions);}else{if(this.showEffect){new Effect[this.showEffect](this.overlay,effectOptions);}else{this.overlay.show();afterShow(this.overlay);}}},_setupPositioning:function(){var scroll_offset=document.viewport.getScrollOffsets();var offset_top=(this.position=="absolute"?scroll_offset.top:0)+this.offset_top+"px";this.overlay.setStyle({"top":offset_top});var relative_container=(this.position=="absolute")?$("page"):document.viewport;var offset_left=(relative_container.getWidth()-this.overlay.getWidth())/2+"px";LFM.info("Dialog positioning ["+this.position+"]: Viewport: "+relative_container.getWidth()+" Overlay width: "+this.overlay.getWidth()+" offset_left: "+offset_left);this.overlay.setStyle({"left":offset_left});if(this.ie6_fixed_hack){var top_expression=this.offset_top+" + document.viewport.getScrollOffsets()['top'] + 'px'";this.overlay.style.setExpression("top",top_expression);}},_setupStatus:function(){if(this.showStatus&&this.dismissable){this.status=new Element("a",{"href":"#"}).observe("click",function(e){e.stop();this.hide();if(this.onClose){this.onClose.bind(this)();}}.bindAsEventListener(this));this.idle();this.overlay.insert(this.status);}},_setupDragging:function(){if(this.draggable){this.draggable.destroy();}if(this.overlayTitle){this.draggable=new Draggable(this.overlay,{handle:this.overlayTitle,starteffect:null,endeffect:null,change:this._invoke_drag_callbacks.bind(this),onEnd:this._invoke_drag_callbacks.bind(this)});}},_setupIframe:function(){if(this._use_iframe&&!this.iframe){this.iframe=new Element("iframe",{frameBorder:"0"}).setStyle({"zIndex":this.zIndex,"position":"absolute","top":0,"left":0,"width":"100%","height":"100%"}).hide();$("page").insert(this.iframe);}},_setupModalBlock:function(){if(this.modal&&!this.modal_block){this.modal_block=new Element("div").setStyle({"position":this.position,"top":0,"left":0,"width":"100%","height":"100%","background":"#333","opacity":"0.5"});$("page").insert(this.modal_block);}},updateContent:function(content){this.content=content;if(this.overlay){if(!this.overlayContent){this.overlayContent=new Element("div",{"class":"dialogContent"});}var oStyles={"maxHeight":this.maxHeight};if(this.ie6_fixed_hack){oStyles["height"]=this.maxHeight;}this.overlayContent.setStyle(oStyles);this.overlayContent.update(content);}if(this.overlay&&this.overlay.visible()&&this.onUpdate){this.onUpdate.bind(this)();}},show:function(){var callback;var url;$A(arguments).each(function(arg){if(typeof arg=="function"){callback=arg;}else{if(typeof arg=="string"){url=arg;}}});this._showOverlay();var params=Object.extend({_dialog:LFM.Dialog._stack.indexOf(this)},this.resource);if(this.parameters){Object.extend(params,this.parameters);}if(url){new Ajax.Request(url,{method:this.contentMethod,parameters:params,onSuccess:function(transport){var response=new LFM.Ajax.Response(transport);if(response.isError()){this.failure();this.content.update(LFM.String.dialogLoadError);}else{this.type=LFM.Dialog.FORM;Object.extend(this,response.toObject());this.resource=response.getResource();this.showEffect=null;this._showOverlay(true);this._addClickSource.bind(this).defer();if(callback){callback.defer(this,response);}}}.bind(this)});}else{if(callback){callback.defer(this);}}},hide:function(instant){this.idle();if(this._use_iframe){clearInterval(this._iframe_repositioning);this.iframe.hide();}$(document).stopObserving("keypress",this._bound_watch_esc);if(this.overlay){if(instant){if(this.modal){this.modal_block.hide();}this.overlay.hide();}else{if(this.modal){new Effect.Fade(this.modal_block,{duration:0.1});}new Effect.Fade(this.overlay,{duration:0.3,afterFinish:function(overlay){if(this.cancelButton){this.cancelButton.removeClassName("activeButton");}}.bind(this)});}}},spawnChild:function(options){var child=new LFM.Dialog(options);child.parent=this;return child;},showParent:function(){this.hide();if(this.parent){this.parent.show();}},finalHandler:function(transport){doneResponse=new LFM.Ajax.Response(transport);if(doneResponse.isError()){if(this.onError){this.onError(doneResponse);this.idle();}else{this.failure();}}else{if(this.showDone){var doneDialog=new LFM.Dialog({resource:doneResponse.getResource(),title:LFM.String.done,content:doneResponse.get("content"),footerContent:doneResponse.get("footerContent"),onConfirm:function(e,resource){e.stop();this.hide();}});doneDialog.show(function(dialog){if(this.onDone){this.onDone(doneResponse);}if(this.fadeDone){doneDialog.hide.bind(doneDialog).delay(2);}}.bind(this));}else{this.hide();if(this.onDone){this.onDone(doneResponse);}}}}};LFM.Dialog.runtests=function(){LFM.Dialog.tests.simple();};LFM.Dialog.tests={simple:function(){var dialog=new LFM.Dialog({resource:{id:2128518,type:4},type:LFM.Dialog.STUB,classname:"fiddlr",title:"Fiddle",content:"Are you sure you'd like to fiddle with this resource?",footerContent:"Extra content",action:"/users/fiddle",confirmText:"Fiddle",onConfirm:function(e,resource){log(e);log(resource);e.stop();alert("Confirmed dialog of class: "+this.classname);alert("You fiddled with a resource of id: "+resource.id+" and type: "+resource.type);this.hide();},cancelText:"Do NOT fiddle",onCancel:function(){alert("Dismissed dialog of class: "+this.classname);this.hide();}});dialog.show();}};LFM.set("AJAXDialog",Class.create({initialize:function(resource,url,options){this.resource=resource;this.url=url;this.options={title:"",classname:"",parameters:null,beforeConfirm:null,showDone:true,onDone:null,onError:null,action:url,fadeDone:false,callback:null};this.position="absolute";if(options){Object.extend(this.options,options);}this.options.resource=this.resource;this.callback=this.options.callback;delete this.options.callback;this.show();},show:function(){this.dialog=new LFM.Dialog(this.options);this.dialog.show(this.url,this.callback);}}));LFM.set("AJAXDialogWrapper",function(url,opts){return function(resource,options){if(!options){options=opts;}else{options=Object.extend(options,opts);}return new LFM.AJAXDialog(resource,url,options);};});LFM.set("Add",LFM.AJAXDialogWrapper("/ajax/dialog/add",{title:LFM.String.addTitle,classname:"add",fadeDone:true,callback:function(dialog,response){if($("tagDialog"+dialog.random)){dialog.addDialogShowTags=$("tagDialog"+dialog.random).visible()?1:0;}},beforeConfirm:function(e){if($("tagDialog"+this.random)){var addDialogShowTags=$("tagDialog"+this.random).visible()?1:0;if(addDialogShowTags!=this.addDialogShowTags){LFM.Ajax.setUserPref("addDialogShowTags",addDialogShowTags);}}}}));LFM.set("RemoveFromLibrary",LFM.AJAXDialogWrapper("/ajax/dialog/removefromlibrary",{title:LFM.String.RemoveFromLibraryTitle,classname:"remove"}));LFM.set("Send",LFM.AJAXDialogWrapper("/ajax/dialog/send",{title:LFM.String.sendTitle,classname:"send",position:"absolute",onError:function(response){this.overlayError.update(response.getErrorMessage());Effect.Appear(this.overlayError);}}));LFM.set("SendShareable",LFM.AJAXDialogWrapper("/ajax/dialog/sendshareable",{title:LFM.String.sendTitle,classname:"send",position:"absolute",onError:function(response){this.overlayError.update(response.getErrorMessage());Effect.Appear(this.overlayError);}}));LFM.set("Tag",LFM.AJAXDialogWrapper("/ajax/dialog/tag",{title:LFM.String.tagTitle,classname:"add",fadeDone:true,position:"absolute",callback:function(dialog,response){if($("tagInput"+dialog.random)){$("tagInput"+dialog.random).focus();}}}));LFM.set("Befriend",LFM.AJAXDialogWrapper("/ajax/dialog/befriend",{title:LFM.String.befriendTitle,classname:"befriend",fadeDone:true}));LFM.set("Playlist",LFM.AJAXDialogWrapper("/ajax/dialog/playlist",{title:LFM.String.playlistTitle,classname:"playlist",fadeDone:true}));LFM.set("Join",LFM.AJAXDialogWrapper("/ajax/dialog/join",{title:LFM.String.joinTitle,fadeDone:true}));LFM.set("Leave",LFM.AJAXDialogWrapper("/ajax/dialog/join",{title:LFM.String.leaveTitle,fadeDone:true}));LFM.set("Membership",LFM.AJAXDialogWrapper("/ajax/dialog/membership",{fadeDone:true}));LFM.set("ImageUpload",LFM.AJAXDialogWrapper("/ajax/dialog/imageupload",{title:LFM.String.uploadImageTitle,classname:"upload",type:LFM.Dialog.CUSTOM}));LFM.set("VideoUpload",LFM.AJAXDialogWrapper("/ajax/dialog/videoupload",{title:LFM.String.uploadVideoTitle,classname:"upload",type:LFM.Dialog.CUSTOM}));LFM.set("Usernote",LFM.AJAXDialogWrapper("/ajax/dialog/usernote",{title:LFM.String.usernoteTitle,classname:"usernote"}));LFM.set("CleanupBio",LFM.AJAXDialogWrapper("/ajax/dialog/cleanupBio",{title:LFM.String.cleanupBioTitle,classname:"cleanupbio"}));LFM.set("SetLocation",LFM.AJAXDialogWrapper("/ajax/dialog/setlocation",{title:LFM.String.setLocationTitle,classname:"setlocation",type:LFM.Dialog.STUB,callback:function(dialog,response){if(dialog.overlay.down("input.text")){dialog.overlay.down("input.text").focus();dialog.overlay.down("input.text").select();}},beforeConfirm:function(e){if(LFM.get("Page","allowReloads")&&LFM.get("Page","reloadLocation")){var newLocation=LFM.get("Page","newLocation");var reloadRoot=LFM.get("Page","reloadURL");if(newLocation&&reloadRoot){reloadURL=reloadRoot+Object.toQueryString({place_id:newLocation.id,place_type:newLocation.type});window.location.href=reloadURL;}else{window.location.reload();}}}}));LFM.set("Flag",LFM.AJAXDialogWrapper("/ajax/dialog/flag",{title:LFM.String.flageventTitle,classname:"flag",fadeDone:true}));LFM.set("ModerationVote",LFM.AJAXDialogWrapper("/ajax/dialog/moderationvote",{classname:"moderationvote",fadeDone:true,onError:function(response){var error=response.getErrorCode();switch(error){case 1:this.overlay.down(".errorChoice").show();break;case 2:var input=this.overlay.down(".customArtistName").down("input");var placeholder=input.getAttribute("placeholder");if(placeholder==$F(input)){this.overlay.down(".errorArtistA").show();}else{this.overlay.down(".errorArtistB").show();}break;case 3:var input=this.overlay.down(".customTrackName").down("input");var placeholder=input.getAttribute("placeholder");if(placeholder==$F(input)){this.overlay.down(".errorTrackA").show();}else{this.overlay.down(".errorTrackB").show();}break;}},beforeConfirm:function(event){this.overlay.select(".errorMessage").invoke("hide");var radio=this.overlay.down("input[value=notcorrect]");if(radio&&radio.checked){$w("Artist Track").each(function(type){var customName=this.overlay.down(".custom"+type+"Name");if(customName&&customName.visible()){customName=customName.down("input");if(customName){var placeholder=customName.getAttribute("placeholder");if(placeholder==$F(customName)){this.overlay.down(".error"+type+"A").show();}}}}.bind(this));}this.busy.bind(this);}}));LFM.set("BuyDialog",LFM.AJAXDialogWrapper("/ajax/dialog/buy",{action:null,classname:"buyDialog"}));LFM.set("MultiBuyDialog",function(resource,options,tracksRoot,limit){var dialog=Class.create(LFM.AJAXDialog,{url:"/ajax/dialog/multibuy",initialize:function(resource,options,tracksRoot,limit){var trackIds=this._getTracks(tracksRoot);this.options={classname:"multiBuyDialog",width:"500px",maxHeight:"350px",parameters:{"limit":limit?limit:15}};if(Prototype.Browser.IE&&Prototype.BrowserFeatures.Version<9){this.options.width="550px";}if(options){options.parameters=options.parameters||{};Object.extend(this.options,options);}this.options.parameters["trackId[]"]=trackIds;this.options.parameters["limit"]=limit||-1;LFM.AJAXDialog.prototype.initialize.apply(this,[resource,this.url,this.options]);},_getTracks:function(tracksRoot){var trackIds;if(!tracksRoot){trackIds=LFM.Page.Extract.trackIds();}else{if(typeof tracksRoot=="string"){trackIds=LFM.Page.Extract.trackIds(tracksRoot);}}return trackIds;}});return new dialog(resource,options,tracksRoot,limit);});LFM.set("setLove",function(value,res,opts){var params=Object.extend({ajax:true,loved:value,formtoken:LFM.Session.formtoken},res);new Ajax.Request("/ajax/library/love",{parameters:params,onSuccess:function(response){var ajaxResponse=new LFM.Ajax.Response(response);if(ajaxResponse.isSuccess()&&typeof opts.onDone=="function"){opts.onDone(ajaxResponse);}else{if(ajaxResponse.isError()&&typeof opts.onError=="function"){opts.onError(ajaxResponse);}}}});});LFM.set("Love",function(res,opts){LFM.setLove(true,res,opts);});LFM.set("Unlove",function(res,opts){LFM.setLove(false,res,opts);});LFM.set("DeprecationDialog",function(deprecationType){var dialog=LFM.AJAXDialogWrapper("/ajax/dialog/deprecation",{title:LFM.String.radioDeprecation,fadeDone:true,modal:true,parameters:{width:"500px",deprecationType:deprecationType},onConfirm:function(e){e.stop();this.hide();}});dialog();});LFM.set("Form",{ResourcePicker:Class.create({initialize:function(options){this.resource={};this.onSelect=null;this.currentTab="music";if(options){Object.extend(this,options);}this.status={};this.focusser=null;this.results={};this.selected={};},selectResource:function(e){e.stop();if(this.resource.id){if(this.onSelect){this.onSelect(this.resource);}else{this.dialog.hide();}}},_createFocusser:function(){if(this.dialog&&!this.focusser){this.focusser=$(document.createElement("textarea"));this.focusser.setStyle({"z-index":0,"position":"absolute","top":0,"left":0,"width":0,"height":0});this.dialog.overlay.insert({before:this.focusser});Event.observe(this.focusser,"keypress",this._watchKeys.bindAsEventListener(this));Event.observe(this.focusser,"blur",function(e){$$("#respickerTypes div.results").invoke("removeClassName","active");}.bindAsEventListener(this));Event.observe(this.focusser,"focus",this._focusKeys.bind(this));}},_watchKeys:function(e){if(this.resultType&&this.selected[this.resultType]){switch(e.keyCode){case Event.KEY_UP:case 63232:e.stop();var prev=this.selected[this.resultType].previous("li");if(prev){this.selectResult(this.resultType,prev);}break;case Event.KEY_DOWN:case 63233:e.stop();var next=this.selected[this.resultType].next("li");if(next){this.selectResult(this.resultType,next);}break;case Event.KEY_RETURN:e.stop();this.selectResource(e);break;default:break;}}},_focusKeys:function(){if(this.focusser&&this.resultType&&this.results[this.resultType]){this.focusser.focus();this.results[this.resultType].addClassName("active");}},show:function(e,reload){if(!this.dialog||reload){this.dialog=new LFM.Dialog({action:true,resource:this.resource,type:LFM.Dialog.STUB,onConfirm:this.selectResource.bindAsEventListener(this)});this.dialog.show("/ajax/dialog/respicker?"+$H({start:this.currentTab}).toQueryString(),function(dialog,response){dialog.confirmButton.disabled=true;$$("#respickerTabs li").each(function(tab){var tabType=tab.id.replace("Tab","");tab.observe("click",this.toggleType.bindAsEventListener(this,tabType));var tabSubmit=$(tabType+"Form").down("input[type=submit]");if(tabSubmit){tabSubmit.observe("click",this.search.bindAsEventListener(this,tabType,true));this.status[tabType]=new LFM.Ajax.StatusHolder(tabSubmit);}}.bind(this));if($("otherTypes")){$("otherTypes").observe("click",this.toggleOther.bindAsEventListener(this));}this._createFocusser();}.bind(this));}else{this.dialog.show();}},_setResultType:function(resultType){this.resultType=resultType;return this.resultType;},toggleType:function(e,tab){$(this.currentTab+"Form").hide();$(tab+"Form").show();$$("#respickerTabs li").invoke("removeClassName","selected");$(tab+"Tab").addClassName("selected");this.currentTab=tab;var formValues=$(tab+"Form").serialize(true);var resultType=this._setResultType(formValues.type);this.selectResult(resultType,this.selected[resultType]);},toggleOther:function(e){var radio=e.element();if(!radio.match("input[type=radio]")||radio.up("li").hasClassName("selected")){return;}$$("#otherTypes li.radioOption").each(function(type){type.removeClassName("selected");var results=type.down("div.results");if(results.visible()){results.hide();}});radio.up("li").addClassName("selected");this.search(e,"other");},_processResults:function(tab,resultType,response){this.results[resultType].update(response);this.selectResult(resultType,this.results[resultType].down("li"));this.results[resultType].select("li").each(function(item){item.observe("click",function(e){this._focusKeys();if(item!=this.selected[resultType]){this.selectResult(resultType,item);}}.bindAsEventListener(this));item.observe("dblclick",this.selectResource.bindAsEventListener(this));}.bind(this));if(tab==this.currentTab){this._focusKeys();}new Effect.Appear(this.results[resultType],{duration:0.4,queue:"end"});this.results[resultType].addClassName("loaded");if(this.status[resultType]){this.status[resultType].idle();}},search:function(e,tab,reload,callback){if(tab!="other"){e.stop();}var formValues=$(tab+"Form").serialize(true);var resultType=this._setResultType(formValues.type);this.results[resultType]=e.element().next("div.results");this.selectResult(resultType,this.selected[resultType]);if(!reload&&this.results[resultType].hasClassName("loaded")){this._focusKeys();new Effect.Appear(this.results[resultType],{duration:0.4,queue:"end"});}else{if(this.status[resultType]){this.status[resultType].busy();}new Ajax.Request("/ajax/search",{parameters:formValues,method:"get",onComplete:function(transport){var response=transport.responseText;if(response=="EMPTY"||response=="ERROR"){if(this.status[resultType]){this.status[resultType].idle();}return;}this._processResults(tab,resultType,response);if(callback){callback();}}.bind(this)});}},selectResult:function(resultType,item){if(this.results[resultType]){this.results[resultType].select("li").invoke("removeClassName","selected");this.selected[resultType]=item;if(item){this.resource=item.getResource();item.addClassName("selected");this.dialog.confirmButton.disabled=false;}}}})});(function(){var Notification=Class.create({initialize:function(){this.dialog=new LFM.Dialog({type:LFM.Dialog.STUB,conent:"",classname:"notificationDialog",offset_top:0,showEffect:function(){return[new Effect.BlindDown(this.overlay,{sync:true}),new Effect.Appear(this.overlay,{sync:true})];},onUpdate:function(){new Effect.Highlight(this.overlay,{startcolor:"#333333",endcolor:"#050505",restorecolor:"#050505"});}});},startTimeout:function(){if(this.timeout){window.clearTimeout(this.timeout);}this.timeout=this.hide.bind(this).delay(10);},hide:function(){if(this.dialog.hover){this.startTimeout();}else{this.dialog.hide();}},send:function(message){this.dialog.updateContent(message);if(!this.dialog.overlay||!this.dialog.overlay.visible()){this.dialog.show();}this.startTimeout();}});LFM.set("Notification",new Notification());})();
