
function MessageBox(configuration)
{var cmp=this;if(typeof configuration=='undefined'){configuration={};}
this.title=configuration.title||'';this.content=configuration.content||'';this.show=function()
{var setDialogContentAndShow=function()
{var dialogBody=dojo.doc.createElement('div');var textDiv=dojo.doc.createElement('div');textDiv.innerHTML=cmp.content;textDiv.style.maxWidth='400px';dialogBody.appendChild(textDiv);var buttonPane=dojo.doc.createElement('div');buttonPane.style.marginTop='20px';buttonPane.style.textAlign='right';var okButton=new dijit.form.Button({label:"OK",onClick:cmp.hide});buttonPane.appendChild(okButton.domNode);dialogBody.appendChild(buttonPane);cmp._widget.attr('title',cmp.title);cmp._widget.attr('content',dialogBody);cmp._widget.show();};if(typeof cmp._widget=='undefined'){dojo.require("dijit.Dialog");dojo.require("dijit.form.Button");dojo.addOnLoad(function(){cmp._widget=new dijit.Dialog();dojo.body().appendChild(cmp._widget.domNode);cmp._widget.startup();setDialogContentAndShow();});}else{setDialogContentAndShow();}
return cmp;};this.hide=function()
{cmp._widget.hide();return cmp;}}
var MsgBox={};MsgBox._messageBoxObject=null;MsgBox.alert=function(title,content)
{if(MsgBox._messageBoxObject==null){MsgBox._messageBoxObject=new MessageBox();}
MsgBox._messageBoxObject.title=title;MsgBox._messageBoxObject.content=content;MsgBox._messageBoxObject.show();}
function EventEditor()
{var cmp=this;dojo.require("dijit.Dialog");dojo.require("dijit.form.TextBox");this.data={};this._wizardWindow=false;this.editNewForLocation=function(locationId)
{if(!locationId){alert('Missing locationId.');return false;}
var dlg=cmp._getWizardWindow();dlg.addChild(new dijit.form.TextBox({}));dlg.show();};this._getInfoPage=function()
{var titleTextBox=new dijit.form.TextBox({});};this._getWizardWindow=function()
{if(!cmp._wizardWindow){cmp._wizardWindow=new dijit.Dialog({id:"addEventWizard",title:"Event hinzufügen"});}
return this._wizardWindow;}}
var StationEditor={data:{},editor:false,streamEditor:false,init:function(stationData)
{StationEditor.data=stationData;},_getDialog:function()
{if(StationEditor.editor==false){StationEditor.editor=new StationEditorWindow();}
return StationEditor.editor;},edit:function()
{var win=StationEditor._getDialog();win.show(StationEditor.data.id);},create:function()
{var win=StationEditor._getDialog();win.show();},save:function()
{StationEditor.editor.save(function(stationData){location.replace('/webradio/station/d/'+stationData.accesskey);});},_getStreamDialog:function()
{if(StationEditor.streamEditor==false){StationEditor.streamEditor=new StreamEditorWindow();}
return StationEditor.streamEditor;},createStream:function()
{var win=StationEditor._getStreamDialog();win.show(0,StationEditor.data.id);},editStream:function(streamId)
{var win=StationEditor._getStreamDialog();win.show(streamId);},saveStream:function()
{StationEditor.streamEditor.save(function(streamData){});}};function StationEditorWindow()
{this.title='Webradio Sender bearbeiten';var cmp=this;this.show=function(stationId)
{var setDialogContentAndShow=function()
{cmp._widget.attr('title',cmp.title);cmp._widget.attr('href','/webradio/edit?id='+stationId);cmp._widget.show();};if(typeof cmp._widget=='undefined'){dojo.require("dijit.Dialog");dojo.require("dijit.form.Button");dojo.require("dijit.form.ValidationTextBox");dojo.require("dijit.form.SimpleTextarea");dojo.addOnLoad(function(){cmp._widget=new dijit.Dialog({parseOnLoad:true,id:'webradio-edit-station-dialog'});dojo.body().appendChild(cmp._widget.domNode);cmp._widget.startup();setDialogContentAndShow();});}else{setDialogContentAndShow();}};this.save=function(callback)
{var deferred=dojo.xhrPost({url:'/webradio/save-station',form:'webradio-edit-form',handleAs:"text",load:function(data){cmp._widget.hide();if(typeof callback!='undefined'){callback(dojo.fromJson(data));}},error:function(error){dojo.byId("save-element").innerHTML="Beim Speichern ist ein Fehler aufgetreten!";}});dojo.byId('save-element').innerHTML='Sende Daten...';}}
function StreamEditorWindow()
{this.title='Webradio Stream bearbeiten';var cmp=this;this.show=function(streamId,stationId)
{stationId=stationId||0;var setDialogContentAndShow=function()
{cmp._widget.attr('title',cmp.title);cmp._widget.attr('href','/webradio/edit-stream?id='+streamId+'&radioStationId='+stationId);cmp._widget.show();};if(typeof cmp._widget=='undefined'){dojo.require("dijit.Dialog");dojo.require("dijit.form.Button");dojo.require("dijit.form.ValidationTextBox");dojo.require("dijit.form.ComboBox");dojo.addOnLoad(function(){cmp._widget=new dijit.Dialog({parseOnLoad:true,id:'webradio-edit-stream-dialog'});dojo.body().appendChild(cmp._widget.domNode);cmp._widget.startup();setDialogContentAndShow();});}else{setDialogContentAndShow();}};this.save=function(callback)
{var deferred=dojo.xhrPost({url:'/webradio/save-stream',form:'webradio-edit-stream-form',handleAs:"text",load:function(data){cmp._widget.hide();if(typeof callback!='undefined'){callback(dojo.fromJson(data));}},error:function(error){dojo.byId("save-element").innerHTML="Beim Speichern ist ein Fehler aufgetreten!";}});dojo.byId('save-element').innerHTML='Sende Daten...';}}
function MyCityNights()
{var cmp=this;this.auth={currentUser:false,callback:null,setCurrentUser:function(email)
{cmp.auth.currentUser=email;},getCurrentUser:function()
{return cmp.auth.currentUser;},loginDialog:null,login:function(email,password,callback)
{if(typeof callback!='undefined'){cmp.auth.callback=callback;}
if(typeof(email)!='undefined'){content={email:email,password:password};}else{content={};}
dojo.xhrPost({url:"/login/ajax",content:content,load:function(response)
{if(response=='"ok"'){cmp.auth.setCurrentUser(email);cmp.auth._hideLogin();cmp.auth._updateView(email);if(cmp.auth.callback!=null){cmp.auth.callback();cmp.auth.callback=null;}}else{cmp.auth._showLogin(response);}},error:function(response,ioArgs){alert('Fehler '+response);}});},_updateView:function(email)
{var elem=dojo.byId('login-block');html='Angemeldet als: '+email+' [<a href="/login/logout">Abmelden</a>]&nbsp;';html+='<a href="/home">Meine Seite</a>';elem.innerHTML=html;},_showLogin:function(dialogHtml)
{if(cmp.auth.loginDialog==null){dojo.require("dijit.Dialog");dojo.addOnLoad(function(){cmp.auth.loginDialog=new dijit.Dialog({title:"Login",content:dialogHtml});dojo.body().appendChild(cmp.auth.loginDialog.domNode);cmp.auth.loginDialog.startup();cmp.auth.loginDialog.show();});}else{cmp.auth.loginDialog.attr('content',dialogHtml);cmp.auth.loginDialog.show();}},_hideLogin:function()
{if(cmp.auth.loginDialog!=null){cmp.auth.loginDialog.hide();}}}}
