
var TabDialogForm=Class.create({initialize:function(dialog){this.form=null;this.dialog=dialog;this.callbacks=new Hash();},bind:function(){this.controlEnterKey();},controlEnterKey:function(){this.form.onkeypress=this.checkEnterKey.bindAsEventListener(this);},checkEnterKey:function(event){if(event.keyCode==13){this.OkBtnClicked();Event.stop(event);return false;}else{return true;}},hide:function(){this.form.hide();},show:function(){this.form.show();},setCallbacks:function(callbacks){var hash=this.callbacks;Object.keys(callbacks).each(function(key){hash.set(key,callbacks[key])})}});var LoginForm=Class.create(TabDialogForm,{initialize:function($super,dialog){$super(dialog);this.nicknameInput=null;this.passwordInput=null;this.nicknameFieldBg=null;this.passwordFieldBg=null;this.forgotPasswordBtn=null;},loaded:function(isLoaded){if(isLoaded){this.form=$('tabDialog_loginForm');this.nicknameInput=$('tabDialog_loginForm_nickname');this.passwordInput=$('tabDialog_loginForm_password');this.nicknameFieldBg=$$('#tabDialog_loginForm_campoNickname .tabDialog_campoSfondo')[0];this.passwordFieldBg=$$('#tabDialog_loginForm_campoPassword .tabDialog_campoSfondo')[0];this.OKBtn=$('tabDialog_LoginForm_OkBtn');this.cancelBtn=$('tabDialog_LoginForm_cancelBtn');this.forgotPasswordBtn=$$('#tabDialog_loginForm_passwordDimenticata a')[0];}},bind:function($super){$super();this.OKBtn.onclick=this.OkBtnClicked.bindAsEventListener(this);this.cancelBtn.onclick=this.cancelBtnClicked.bindAsEventListener(this);this.forgotPasswordBtn.onclick=this.forgotPasswordBtnClicked.bindAsEventListener(this);if((arguments.length>0)&&(arguments[1].callbacks!=null)){this.setCallbacks(arguments[1].callbacks);}},OkBtnClicked:function(){if(this.callbacks.get('loginConfirmed')!=null){this.callbacks.get('loginConfirmed')({parameters:this.form.serialize()});}else{new Ajax.Request('/user/login',{asynchronous:true,evalScripts:true,parameters:this.form.serialize(),requestHeaders:{Accept:'text/x-json'},onComplete:this.checkLoginResponse.bindAsEventListener(this)})}},cancelBtnClicked:function(){if(this.callbacks.get('loginCancelled')!=null){this.callbacks.get('loginCancelled')();}else{pageTabs.cancelLoginForm();}},hide:function($super){$super();this.nicknameFieldBg.setStyle({position:'absolute'});this.passwordFieldBg.setStyle({position:'absolute'});},show:function($super){this.cleanFields();this.nicknameFieldBg.setStyle({position:'relative'});this.passwordFieldBg.setStyle({position:'relative'});if((arguments.length>1)&&(arguments[1].callbacks!=null)){this.setCallbacks(arguments[1].callbacks);}
$super();},cleanFields:function(){this.nicknameInput.value="";this.passwordInput.value="";},forgotPasswordBtnClicked:function(){this.callbacks.get('passwordForgotten')();},checkLoginResponse:function(request){if(this.callbacks.get('checkLoginResponse')!=null){this.callbacks.get('checkLoginResponse')(request);}else{pageTabs.checkLoginResponse();}}});var PasswordForgottenForm=Class.create(TabDialogForm,{initialize:function($super,dialog,loginForm){$super(dialog);this.loginForm=loginForm;this.nicknameInput=null;this.parentEmailInput=null;this.nicknameFieldBg=null;this.parentEmailFieldBg=null;this.OKBtn=null;this.cancelBtn=null;},loaded:function(isLoaded){if(isLoaded){this.form=$('tabDialog_passwordForgottenForm');this.nicknameInput=$('tabDialog_passwordForgottenForm_nickname');this.parentEmailInput=$('tabDialog_passwordForgottenForm_parentEmail');this.nicknameFieldBg=$$('#tabDialog_passwordForgottenForm_campoNickname .tabDialog_campoSfondo')[0];this.parentEmailFieldBg=$$('#tabDialog_passwordForgottenForm_campoParentEmail .tabDialog_campoSfondo')[0];this.OKBtn=$('passwordForgottenForm_OKBtn');this.cancelBtn=$('passwordForgottenForm_cancelBtn');}},bind:function($super){$super();this.OKBtn.onclick=this.OkBtnClicked.bindAsEventListener(this);this.cancelBtn.onclick=this.cancelBtnClicked.bindAsEventListener(this);},hide:function($super){if(this.nicknameFieldBg){this.nicknameFieldBg.setStyle({position:'absolute'})};if(this.parentEmailFieldBg){this.parentEmailFieldBg.setStyle({position:'absolute'})};$super();},show:function($super){this.cleanFields();if(this.nicknameFieldBg){this.nicknameFieldBg.setStyle({position:'relative'})};if(this.parentEmailFieldBg){this.parentEmailFieldBg.setStyle({position:'relative'})};$super();},cleanFields:function(){this.nicknameInput.value="";this.parentEmailInput.value="";},OkBtnClicked:function(){var nickname=this.nicknameInput.getValue();var parent_email=this.parentEmailInput.getValue();if((nickname!='')&&(parent_email!='')){this.dialog.startSpinner(i18n.stringLocale('invio_richiesta_in_corso','dialog'));var objectToPost={'nickname':nickname,'parent_email':parent_email}
var options={JSON:true,evalJS:true,onComplete:this.checkForgotPasswordRequest.bindAsEventListener(this)};this.dialog.sendRequest('/user/forgot_password/',objectToPost,options);}else{this.dialog.displayMessage({title:'warning',description:i18n.stringLocale('inserisci_nick_e_p_mail','dialog'),actions:'1button',actionOK:this.dialog.showPasswordForgottenForm.bindAsEventListener(this.dialog)})}},checkForgotPasswordRequest:function(request){if(request.status=='200'){response=request.responseJSON;if(response.status.action_result=='OK'){this.dialog.displayMessage({title:'good',description:i18n.stringLocale('mail_inviata_a_genitori_reset_p','dialog')+"<br><br>"+i18n.stringLocale('corri_da_mama_e_papa','dialog'),actionOK:this.dialog.hideDialog.bindAsEventListener(this.dialog),size:'small'})}else{this.dialog.displayMessage({title:'warning',description:response.status.message,actions:'1button',actionOK:this.dialog.showPasswordForgottenForm.bindAsEventListener(this.dialog)})}}else{this.dialog.displayMessage({title:'warning',description:i18n.stringLocale('problema_server_prova_1_minuto','dialog'),actionOK:window.location.reload(true),size:'small'})}
this.dialog.stopSpinner();},cancelBtnClicked:function(){this.loginForm.cancelBtnClicked();if(typeof(pageTabs.cancelLoginForm)!='undefined'){pageTabs.cancelLoginForm();}}});var AddFriendForm=Class.create(TabDialogForm,{initialize:function($super,dialog){$super(dialog);this.magicSpellInput=null;this.OKBtn=null;this.cancelBtn=null;this.onComplete=null;this.targetNickname=null;},loaded:function(isLoaded){if(isLoaded){this.form=$('tabDialog_addFriendForm');this.magicSpellInput=$('tabDialog_addFriendForm_magicSpell');this.magicSpellFieldBg=$('#tabDialog_addFriendForm_magicSpellField .tabDialog_campoSfondo');this.OKBtn=$('addFriend_OKBtn');this.cancelBtn=$('addFriend_CancelBtn');}},bind:function($super){$super();this.OKBtn.onclick=this.OkBtnClicked.bindAsEventListener(this);this.cancelBtn.onclick=this.cancelBtnClicked.bindAsEventListener(this);},hide:function($super){if(this.magicSpellFieldBg){this.magicSpellFieldBg.setStyle({position:'absolute'})};$super();},show:function($super,options,additionalOptions){if((typeof additionalOptions!='undefined')&&(additionalOptions!=null)){if((typeof additionalOptions.friendNickname!='undefined')&&(additionalOptions.friendNickname!=null)){this.targetNickname=additionalOptions.friendNickname;}
if((typeof additionalOptions.callbackToContinue!='undefined')&&(additionalOptions.callbackToContinue!=null)){this.onComplete=additionalOptions.callbackToContinue;}}
this.dialog.displayTitle('warning');this.dialog.setDescription(i18n.stringLocale('enter_magic_spell_1','dialog')+this.targetNickname+i18n.stringLocale('enter_magic_spell_2','dialog')+this.targetNickname);this.cleanFields();if(this.magicSpellFieldBg){this.magicSpellFieldBg.setStyle({position:'relative'})};$super();},cleanFields:function(){this.magicSpellInput.value="";},OkBtnClicked:function(){var magicSpell=this.magicSpellInput.value;if(magicSpell!=''){this.dialog.startSpinner(i18n.stringLocale('invio_richiesta_in_corso','dialog'));var objectToPost={'nickname':this.targetNickname,'magic_spell':magicSpell}
var options={JSON:true,evalJS:true,onComplete:this.checkAddFriendResponse.bindAsEventListener(this)};this.dialog.sendRequest('/friendship/add_friend/',objectToPost,options);}else{this.dialog.displayMessage({title:'warning',description:i18n.stringLocale('magic_spell_not_entered','dialog'),actions:'1button',actionOK:this.dialog.showAddFriendForm.bindAsEventListener(this.dialog)})}},cancelBtnClicked:function(){this.dialog.hideDialog();if(this.onComplete!=null){this.onComplete()}},checkAddFriendResponse:function(request){if(request.status=='200'){response=request.responseJSON;if(response.status.action_result=='OK'){this.dialog.displayMessage({title:'good',description:response.status.message,actions:'1button',size:'small',actionOK:this.checkForActionsToPerform.bindAsEventListener(this)})}else{actions=null;actionOK=null;actionCancel=null;switch(response.status.action_to_perform){case'logout!':actions='1button';actionOK=this.forceRefresh.bindAsEventListener(this);break;case'tryAgain':actions='2buttons';actionOK=this.dialog.showAddFriendForm.bindAsEventListener(this.dialog);actionCancel=this.checkForActionsToPerform.bind(this);break;default:actions='1button';actionOK=this.dialog.hideDialog.bindAsEventListener(this.dialog);}
this.dialog.displayMessage({title:'warning',description:response.status.message,actions:actions,actionOK:actionOK,actionCancel:actionCancel})}}else{this.dialog.displayMessage({title:'warning',description:i18n.stringLocale('problema_server_prova_1_minuto','dialog'),actions:'1button',actionOK:window.location.reload(true)})}
this.dialog.stopSpinner();},checkForActionsToPerform:function(){this.dialog.hideDialog();if(this.onComplete!=null){this.onComplete()}},forceRefresh:function(){if(window.pageTabs!=undefined){pageTabs.forceRefresh();}else{window.location.reload(true);}}});var TabDialog=Class.create({initialize:function(){this.dialog=null;this.title=null;this.titleImg=null;this.description=null;this.loginForm=new LoginForm(this);this.passwordForgottenForm=new PasswordForgottenForm(this,this.loginForm);this.addFriendForm=new AddFriendForm(this);this.actionsTab=null;this.actionsImgOK=null;this.actionsImcCancel=null;this.actionsImgOKMiddle=null;this.actionsType='1button';this.closeBtn=null;this.spinner=null;this.spinnerText=null;this.spinnerUp=null;this.size='big';this.actions=new Hash();this.communicator=new Communicator();},loaded:function(isLoaded){if(isLoaded){this.dialog=$('tabDialog');this.titleStamp=$('tabDialog_stamp').select('img')[0];this.title=$$('.tabDialog_titolo')[0];this.titleImg=this.title.select('img')[0];this.description=$('tabDialog_descrizione');this.loginForm.loaded(isLoaded);this.passwordForgottenForm.loaded(isLoaded);this.addFriendForm.loaded(isLoaded);this.actionsTab=$('tabDialog_azioni');this.actionsImgOK=$('tabDialog_azioni_imgOK');this.actionsImcCancel=$('tabDialog_azioni_imgCancel');this.actionsImgOKMiddle=$('tabDialog_azioni_imgOK_middle');this.closeBtn=$('tabDialog_closeBnt').down('img');this.spinner=$('tabDialog_spinner');this.spinnerText=$('tabDialog_spinner_innertext');this.spinnerUp=$('tabDialog_spinner_up')
this.setSize({size:'big'});this.hideInputForms();this.bindTabDialog();}},bindTabDialog:function(){this.loginForm.bind({callbacks:{passwordForgotten:this.passwordForgotten.bindAsEventListener(this)}});this.passwordForgottenForm.bind();this.addFriendForm.bind();this.bindActions();},isVisible:function(){return(this.dialog!=null&&this.dialog.visible()&&this.dialog.getStyle('opacity')==1)},setSize:function(options){if(options.size=="small"){this.size='small';this.dialog.hasClassName('tabDialog_big')?this.dialog.removeClassName('tabDialog_big'):null;this.dialog.hasClassName('tabDialog_small')?null:this.dialog.addClassName('tabDialog_small');this.closeBtn.show();}else{this.size='big';this.dialog.hasClassName('tabDialog_small')?this.dialog.removeClassName('tabDialog_small'):null;this.dialog.hasClassName('tabDialog_big')?null:this.dialog.addClassName('tabDialog_big');this.closeBtn.hide();}},showLoginForm:function(options){options=options||{};this.setSize({size:'big'});this.hideInputForms();this.displayTitle('enter');this.setDescription(options.message!=null?options.message:i18n.stringLocale('inserisci_usr_e_pwd_per_accedere_tua_pagina','dialog'));this.loginForm.show(options);this.hideActions();this.showDialog(options);},displayTitle:function(titleToDisplay){var titleStampSrc=null;var titleStampAlt=null;var titleClassName=null;var titleImgSrc=null;var titleImgAlt=null;switch(titleToDisplay){case'enter':titleStampSrc=this.size=='small'?"/images/mypage/dialog/stamp/entra_esci_bollo_s.png":"/images/mypage/dialog/stamp/entra_esci_bollo_b.png";titleStampAlt=i18n.stringLocale('entra','dialog');titleClassName='title_enter';titleImgSrc=this.size=='small'?"/images/mypage/dialog/title/entra_s.png":"/images/mypage/dialog/title/entra_b.png"
titleImgAlt=titleStampAlt;break;case'exit':titleStampSrc=this.size=='small'?"/images/mypage/dialog/stamp/entra_esci_bollo_s.png":"/images/mypage/dialog/stamp/entra_esci_bollo_b.png";titleStampAlt=i18n.stringLocale('esci','dialog');titleClassName='title_exit';titleImgSrc=this.size=='small'?"/images/mypage/dialog/title/esci_s.png":"/images/mypage/dialog/title/esci_b.png"
titleImgAlt=titleStampAlt;break;case'warning':titleStampSrc=this.size=='small'?"/images/mypage/dialog/stamp/attenzione_bollo_s.png":"/images/mypage/dialog/stamp/attenzione_bollo_b.png";titleStampAlt=i18n.stringLocale('attenzione','dialog');titleClassName='title_warning';titleImgSrc=this.size=='small'?"/images/mypage/dialog/title/attenzione_s.png":"/images/mypage/dialog/title/attenzione_b.png"
titleImgAlt=titleStampAlt;break;case'good':titleStampSrc=this.size=='small'?"/images/mypage/dialog/stamp/bravo_bollo_s.png":"/images/mypage/dialog/stamp/bravo_bollo_b.png";titleStampAlt=i18n.stringLocale('bravo','dialog');titleClassName='title_good';titleImgSrc=this.size=='small'?"/images/mypage/dialog/title/bravo_s.png":"/images/mypage/dialog/title/bravo_b.png"
titleImgAlt=titleStampAlt;break;case'halt':titleStampSrc=this.size=='small'?"/images/mypage/dialog/stamp/divieto_bollo_s.png":"/images/mypage/dialog/stamp/divieto_bollo_b.png";titleStampAlt='Ops';titleClassName='title_ooops';titleImgSrc=this.size=='small'?"/images/mypage/dialog/title/ops_s.png":"/images/mypage/dialog/title/ops_b.png"
titleImgAlt='Ops';break;case'benvenuto':this.titleImg.writeAttribute('src',i18n.imageLocale("/images/mypage/dialog/benvenuto_it.png"));this.titleImg.writeAttribute('alt','Benvenuto');break;}
this.titleStamp.writeAttribute('src',titleStampSrc);this.titleStamp.writeAttribute('alt',titleStampAlt);titleClassName=='title_enter'?(this.title.hasClassName('title_enter')?null:this.title.addClassName('title_enter')):(this.title.hasClassName('title_enter')?this.title.removeClassName('title_enter'):null);titleClassName=='title_exit'?(this.title.hasClassName('title_exit')?null:this.title.addClassName('title_exit')):(this.title.hasClassName('title_exit')?this.title.removeClassName('title_exit'):null);titleClassName=='title_warning'?(this.title.hasClassName('title_warning')?null:this.title.addClassName('title_warning')):(this.title.hasClassName('title_warning')?this.title.removeClassName('title_warning'):null);titleClassName=='title_good'?(this.title.hasClassName('title_good')?null:this.title.addClassName('title_good')):(this.title.hasClassName('title_good')?this.title.removeClassName('title_good'):null);titleClassName=='title_ooops'?(this.title.hasClassName('title_ooops')?null:this.title.addClassName('title_ooops')):(this.title.hasClassName('title_ooops')?this.title.removeClassName('title_ooops'):null);this.titleImg.writeAttribute('src',i18n.imageLocale(titleImgSrc));this.titleImg.writeAttribute('alt',titleImgAlt);},setDescription:function(description){this.description.update('<p>'+description.toUpperCase()+'</p>');},getZIndex:function(){return parseInt(Element.getStyle(this.dialog,'z-index')||0);},setZIndex:function(currentZIndex){if(currentZIndex>this.getZIndex()){this.dialog.setStyle({zIndex:currentZIndex});}},showActions:function(type){typeof(type)=='undefined'?this.actionsType='1button':this.actionsType=type
switch(this.actionsType){case'1button':this.actionsImgOK.hide();this.actionsImcCancel.hide();this.actionsImgOKMiddle.show();break;case'2buttons':this.actionsImgOK.show();this.actionsImcCancel.show();this.actionsImgOKMiddle.hide();break;default:this.actionsImgOK.hide();this.actionsImcCancel.hide();this.actionsImgOKMiddle.hide();}
this.hideInputForms();this.actionsTab.show();},hideActions:function(){this.actionsTab.hide();},bindActions:function(){this.actionsImgOK.onclick=this.actionOKClicked.bindAsEventListener(this);this.actionsImcCancel.onclick=this.actionCancelClicked.bindAsEventListener(this);this.actionsImgOKMiddle.onclick=this.actionOKMiddleClicked.bindAsEventListener(this);if(this.closeBtn!=null){this.closeBtn.onclick=this.closeBtnClicked.bindAsEventListener(this);}},setActionOK:function(action){if(this.actionsType=='1button'){this.actions.set('OKMiddle',action);}else{this.actions.set('OK',action);}},setActionCancel:function(action){this.actions.set('Cancel',action);},setActionClose:function(action){this.actions.set('Close',action);},showDialog:function(options){if(!this.isVisible()){var zIndex=options!=null&&options.zIndex!=null?options.zIndex:(typeof(pageTabs.getCurrentZIndex)!='undefined'?pageTabs.getCurrentZIndex(true):null);if(zIndex!=null){this.setZIndex(zIndex)}
var dialogMaskHeight=options!=null&&options.dialogMaskHeight!=null?options.dialogMaskHeight:(typeof(pageTabs.getDialogMaskHeight)!='undefined'?pageTabs.getDialogMaskHeight():null);if(dialogMaskHeight!=null){this.dialog.style.heigtht=dialogMaskHeight+'px'}
this.dialog.setOpacity(0);this.dialog.show();new Effect.Opacity(this.dialog,{duration:0.3,from:0,to:1});}
this.stopSpinner();},setDefaultDialog:function(){this.hideInputForms();this.loginForm.show();},hideDialog:function(){if(this.isVisible()){new Effect.Opacity('tabDialog',{duration:0.3,from:1,to:0,afterFinish:function(effect){$('tabDialog').hide()}});}},actionOKClicked:function(){this.actions.get('OK')!=null?this.actions.get('OK')():this.hideDialog();},actionOKMiddleClicked:function(){this.actions.get('OKMiddle')!=null?this.actions.get('OKMiddle')():this.hideDialog();},actionCancelClicked:function(){this.actions.get('Cancel')!=null?this.actions.get('Cancel')():this.hideDialog();},closeBtnClicked:function(){this.actions.get('Close')!=null?this.actions.get('Close')():this.hideDialog();},showPasswordForgottenForm:function(){this.hideInputForms();this.hideActions();this.displayTitle('enter');this.setDescription(i18n.stringLocale('messaggio_pwd_dimenticata','dialog'))
this.passwordForgottenForm.show();},passwordForgotten:function(){this.showPasswordForgottenForm();},hideInputForms:function(){this.loginForm.hide();this.passwordForgottenForm.hide();this.addFriendForm.hide();},showAddFriendForm:function(options,additionalOptions){options=options||{}
this.hideInputForms()
this.hideActions();this.setSize({size:'big'});this.addFriendForm.show(options,additionalOptions)
this.showDialog(options)},startSpinner:function(message){if(message){this.spinnerText.innerHTML=message}
this.spinner.show();},stopSpinner:function(){this.spinner.hide();},sendRequest:function(url,objectToPost,options){this.communicator.sendRequest(url,objectToPost,options);},displayMessage:function(){if(arguments.length>0&&arguments[0].size!=null){this.setSize({size:arguments[0].size})}else{this.setSize({size:'big'})}
if(arguments.length>0){if(arguments[0].title!=null){this.displayTitle(arguments[0].title)}
if(arguments[0].description!=null){this.setDescription(arguments[0].description)}
if(arguments[0].size&&arguments[0].size=='small'){this.showActions('closeBtn');if(arguments[0].actionOK!=null){this.setActionClose(arguments[0].actionOK)}}else{if(arguments[0].actions!=null){this.showActions(arguments[0].actions)}
if(arguments[0].actionOK!=null){this.setActionOK(arguments[0].actionOK)}
if(arguments[0].actionCancel!=null){this.setActionCancel(arguments[0].actionCancel)}}}
this.hideInputForms();},waitAndRedirect:function(options){this.spinnerUp.show();this.setDescription(options.message);this.hideInputForms();this.hideActions();this.showDialog();setTimeout(this.redirectAfterWait.bindAsEventListener(this,{url:options.url,showDialogAvvisiAtStartup:options.showDialogAvvisiAtStartup}),options.timeout);},redirectAfterWait:function(){var url="/page/back_to_homepage";if(arguments[1].url!=null){url=arguments[1].url;}else{url=arguments[1].showDialogAvvisiAtStartup==true?"/page/back_to_homepage?show_dialog_avvisi=true":"/page/back_to_homepage"}
location.href=url;}});var Action=Class.create({initialize:function(action,parameters){this.action=action;this.parameters=parameters;}});var ActionCfg=Class.create({initialize:function(action,parameters,executeOnce,asynchronous){this.action=action;this.parameters=parameters;this.executeOnce=executeOnce!=null?executeOnce:false;this.asynchronous=asynchronous!=null?asynchronous:false;},perform:function(callbackToContinue){this.action({parameters:this.parameters,callbackToContinue:callbackToContinue});},isSingleExecution:function(){return this.executeOnce;},isAsynchronous:function(){return this.asynchronous;}})
var ActionsToPerform=Class.create({initialize:function(){this.actions=new Hash();},addAction:function(){if((arguments.length>0)&&(arguments[0].event!=null)&&(arguments[0].when!=null)&&(arguments[0].action!=null)){if(this.actions.get(arguments[0].event)==null){this.actions.set(arguments[0].event,new Hash());}
var eventHash=this.actions.get(arguments[0].event);eventHash.set(arguments[0].when,arguments[0].action);}},removeAction:function(){if((arguments.length>0)&&(arguments[0].event!=null)&&(arguments[0].when!=null)){if(this.actions.get(arguments[0].event)!=null){var eventHash=this.actions.get(arguments[0].event);eventHash.set(arguments[0].when,null);}}},getAction:function(){if((arguments.length>0)&&(arguments[0].event!=null)&&(arguments[0].when!=null)){var eventHash=this.actions.get(arguments[0].event)
if(eventHash!=null){return eventHash.get(arguments[0].when);}else{return null;}}},eventHappen:function(){if((arguments.length>0)&&(arguments[0].event!=null)&&(arguments[0].when!=null)){var event=arguments[0].event;var when=arguments[0].when;var actionToPerform=this.getAction({event:event,when:when})
if(actionToPerform!=null){if(actionToPerform.isAsynchronous()){actionToPerform.perform(arguments[0].callbackToContinue);}else{actionToPerform.perform();arguments[0].callbackToContinue();}
if(actionToPerform.isSingleExecution()){this.removeAction({event:event,when:when});}}else{arguments[0].callbackToContinue();}}},eventCancelled:function(){if((arguments.length>0)&&(arguments[0].event!=null)){var event=arguments[0].event;var actionToPerform=this.getAction({event:event,when:'after'})
if(actionToPerform!=null&&actionToPerform.isSingleExecution()){this.removeAction({event:event,when:'after'});}}}})
var EventCallback=Class.create({initialize:function(options){this.callback=options.callback;this.callbackParams=options.callbackParams;this.executeOnce=options.executeOnce!=null?options.executeOnce:true;this.asynchronous=options.asynchronous!=null?options.asynchronous:false;this.blocksQueue=options.blocksQueue!=null?options.blocksQueue:false;},perform:function(options){this.callback({parameters:this.callbackParams,callbackToContinue:options.callbackToContinue});},isSingleExecution:function(){return this.executeOnce;},isAsynchronous:function(){return this.asynchronous;},isBlockingQueue:function(){return this.blocksQueue;}})
var EventInCourse=Class.create({initialize:function(options){this.event=options.event;this.when=options.when;this.callbackToContinueEvent=options.callbackToContinueEvent;this.pendingCallbacks=0;},addPendingCallback:function(){this.pendingCallbacks++;},removePendingCallback:function(){this.pendingCallbacks--;},canEventContinue:function(){return this.pendingCallbacks==0;}})
var EventQueueDispatcher=Class.create({initialize:function(){this.callbacks=new Hash();this.eventsInCourse=new Hash();},addCallback:function(options){if(this.callbacks.get(options.event)==null){this.callbacks.set(options.event,new Hash())}
var eventHash=this.callbacks.get(options.event);if(eventHash.get(options.when)==null){eventHash.set(options.when,new Hash({queue:new Array(),callbackToExecuteIndex:0}));}
var callbacksQueue=eventHash.get(options.when).get('queue');if(options.placeFirst!=null&&options.placeFirst==true){callbacksQueue.unshift(options.callback)}else{callbacksQueue.push(options.callback)}},eventHappen:function(options){this.eventsInCourse.set(options.event,new EventInCourse({event:options.event,when:options.when,callbackToContinueEvent:options.callbackToContinueEvent}))
var eventHash=this.callbacks.get(options.event);if(eventHash!=null){var callbacksQueue=eventHash.get(options.when);if(callbacksQueue!=null){callbacksQueue.set('callbackToExecuteIndex',0);}}
this.checkQueue({event:options.event,when:options.when});},eventCancelled:function(options){var eventHash=this.callbacks.get(options.event);if(eventHash!=null){var callbacksQueue=eventHash.get('before');if(callbacksQueue!=null){this.clearQueueFromSingleExecutionCallbacks({event:options.event,when:'before'})}
callbacksQueue=eventHash.get('after');if(callbacksQueue!=null){this.clearQueueFromSingleExecutionCallbacks({event:options.event,when:'after'})}}
this.eventsInCourse.unset(options.event);},clearQueueFromSingleExecutionCallbacks:function(options){var callbacksQueue=this.callbacks.get(options.event).get(options.when);var queue=callbacksQueue.get('queue');for(var i=0;i<queue.size();i++){var callback=queue[i];if(callback.isSingleExecution()){queue[i]=null;callbacksQueue.set('queue',queue.compact());}}
callbacksQueue.set('callbackToExecuteIndex',0);},checkQueue:function(options){var eventInCourse=this.eventsInCourse.get(options.event);var eventHash=this.callbacks.get(options.event);if(eventHash!=null){var callbacksQueue=eventHash.get(options.when);if(callbacksQueue!=null&&callbacksQueue.get('queue').size()>0){var queue=callbacksQueue.get('queue');var callbackToExecute=queue[callbacksQueue.get('callbackToExecuteIndex')];if(callbackToExecute!=null){if(callbackToExecute.isSingleExecution()){queue[callbacksQueue.get('callbackToExecuteIndex')]=null;callbacksQueue.set('queue',queue.compact());}else{callbacksQueue.set('callbackToExecuteIndex',callbacksQueue.get('callbackToExecuteIndex')+1);}
if(callbackToExecute.isBlockingQueue()){if(callbackToExecute.isAsynchronous()){eventInCourse.addPendingCallback();callbackToExecute.perform({callbackToContinue:this.callbackExecuted.bind(this,{event:options.event,when:options.when,wasAsynch:true})});}else{callbackToExecute.perform({callbackToContinue:this.callbackExecuted.bind(this,{event:options.event,when:options.when,wasAsynch:false})});}}else{if(callbackToExecute.isAsynchronous()){eventInCourse.addPendingCallback();callbackToExecute.perform({callbackToContinue:this.callbackExecuted.bind(this,{event:options.event,when:options.when,wasAsynch:true})});}else{callbackToExecute.perform({callBackToContinue:null});}
this.checkQueue({event:options.event,when:options.when});}}else{this.continueEvent({event:options.event,when:options.when});}}else{this.continueEvent({event:options.event,when:options.when});}}else{this.continueEvent({event:options.event,when:options.when});}},callbackExecuted:function(options){var eventInCourse=this.eventsInCourse.get(options.event)
if(eventInCourse!=null&&options.wasAsynch==true){eventInCourse.removePendingCallback();}
this.checkQueue({event:options.event,when:options.when});this.continueEvent({event:options.event,when:options.when});},continueEvent:function(options){var eventToContinue=this.eventsInCourse.get(options.event);if(eventToContinue!=null&&eventToContinue.canEventContinue()){this.eventsInCourse.unset(options.event);if(eventToContinue.callbackToContinueEvent1=!null){eventToContinue.callbackToContinueEvent();}}},stopDispatching:function(options){var eventHash=this.callbacks.get(options.event);if(eventHash!=null){var callbacksQueue=eventHash.get(options.when);if(callbacksQueue!=null){callbacksQueue.set('callbackToExecuteIndex',callbacksQueue.get('queue').size());}}
this.eventsInCourse.unset(options.event);}})
var User=Class.create({initialize:function(){this.id=0;this.nickname="";this.enabled=false;this.registered=false;this.logged_in=false;this.gender=null;this.birthday=function(){this.day=null;this.month=null;this.year=null;}
this.new_notifications_count=0;this.media_download=false;this.write_text=false;this.friendship_p_auth=false;this.can_have_friends=false;this.friends=new Array();this.lang=null;this.keep_contents_on_notification=false;this.keep_contents_on_paste=false;this.page=function(){this.id=0;this.tabs=new Array();}
this.newFriendsCount=0;this.avatarUrl="";this.hasDialogAvvisi=false;},setUserInfoFromServerData:function(responseFromServer,new_notifications_count){this.id=responseFromServer.id;this.nickname=responseFromServer.nickname;this.enabled=responseFromServer.enabled;this.registered=responseFromServer.registered;this.logged_in=responseFromServer.logged_in;this.gender=responseFromServer.gender;if(responseFromServer.birthday!=null){this.birthday.day=responseFromServer.birthday.day;this.birthday.month=responseFromServer.birthday.month;this.birthday.year=responseFromServer.birthday.year;}
this.new_notifications_count=new_notifications_count!=null?new_notifications_count:responseFromServer.new_notifications_count;this.media_download=responseFromServer.media_download
this.write_text=responseFromServer.write_text;this.friendship_p_auth=responseFromServer.friendship_p_auth;this.can_have_friends=responseFromServer.can_have_friends;this.friends=responseFromServer.friends;this.is_famous_friend=responseFromServer.is_famous_friend;this.can_require_friendship=responseFromServer.can_require_friendship;this.lang=responseFromServer.lang
this.keep_contents_on_notification=responseFromServer.keep_contents_on_notification;this.keep_contents_on_paste=responseFromServer.keep_contents_on_paste;if(typeof responseFromServer.page!='undefined'){this.page.id=responseFromServer.page.id;this.page.tabs=responseFromServer.page.tabs;}
this.newFriendsCount=typeof responseFromServer.new_friends_count!='undefined'?responseFromServer.new_friends_count:null;this.avatarUrl=responseFromServer.avatar_url;this.hasDialogAvvisi=responseFromServer.has_dialog_avvisi==true?true:false},equalsTo:function(otherUser){return typeof(otherUser.id)!='undefined'&&this.id==otherUser.id?true:false;},getId:function(){return this.id;},isLoggedIn:function(){return this.logged_in;},isRegistered:function(){return this.registered;},canDownloadMedia:function(){return this.media_download;},canWriteText:function(){return this.write_text;},getYourPageId:function(){return this.page.id;},setNewNotificationsCount:function(notifications_count){this.new_notifications_count=notifications_count;},getNewNotificationsCount:function(){return this.new_notifications_count;},canHaveFriends:function(){return this.can_have_friends;},canRequireFriendship:function(){return this.can_require_friendship;},getLang:function(){return this.lang;},getLanguage:function(){return this.getLang();},getGender:function(){return this.gender;},keepContentsOnNotification:function(){return this.keep_contents_on_notification;},keepContentsOnPaste:function(){return this.keep_contents_on_paste;},isFamousFriend:function(){return this.is_famous_friend;},isFriendWith:function(friend){return this.isFriendWithById(friend.id)},isFriendWithById:function(friendId){var areFriends=false;this.friends.each(function(user_friend){if(user_friend.id==friendId){if(user_friend.has_blocked==true){areFriends="friend_has_blocked"}else if(user_friend.is_blocked==true){areFriends="friend_is_blocked"}else{areFriends=true}
throw $break;}})
return areFriends;},getNewFriendsCount:function(){return this.newFriendsCount;}});MPSound={play:function(sound_url){Sound.play(sound_url);},enable:function(sound_url){Sound.enable(sound_url);},disable:function(sound_url){Sound.disable(sound_url);},stop:function(sound_url){Sound.enable();Sound.play('',{replace:true});}};var MPConfiguration=Class.create({initialize:function(){this.flashMediaPath=null;},setFlashMediaPath:function(path){this.flashMediaPath=path;},getFlashMediaPath:function(){return this.flashMediaPath!=null?this.flashMediaPath:'';},setVideoMediaPath:function(path){this.videoMediaPath=path;},getVideoMediaPath:function(){return this.videoMediaPath!=null?this.videoMediaPath:'';},setDownloadMediaPath:function(path){this.downloadMediaPath=path;},getDownloadMediaPath:function(){return this.downloadMediaPath!=null?this.downloadMediaPath:'';}})
var I18N=Class.create({initialize:function(){this.confs=null;},setConfiguration:function(confs){this.confs=confs;},stringLocale:function(stringName,contest,params)
{var lang=typeof(pageTabs)!='undefined'?pageTabs.getUserLang():'it';var string="";if(contest!=null&&this.confs[contest]!=null){string=this.confs[contest][stringName][lang]!=null?this.confs[contest][stringName][lang]:this.confs[contest][stringName]['it'];}else{string=this.confs[stringName][lang]!=null?this.confs[stringName][lang]:this.confs[stringName]['it'];}
if((typeof arguments[2]!='undefined')&&(string.split("%s").length>1)){params=typeof params!='object'?[params]:params;var tokens=string.split("%s");string="";for(var i=0;i<tokens.length;i++){string+=tokens[i];if(params[i]!=null&&i!=tokens.length-1){string+=params[i];}}}
return string},imageLocale:function(source,lang){language=typeof(lang)!='undefined'?lang:(pageTabs.getUserLang()||'it');filename=source.split('/').last()
ext=filename.split('.').last()
name_s=filename.split('.').first()
basePath=source.split(filename).first()
name_e=name_s.indexOf('_it')>0?name_s.sub('_it','_'+language):(name_s+'_'+language)
basePath=basePath.indexOf('/it/')>0?basePath.sub('/it/','/'+language+'/'):basePath+language+'/'
return basePath+name_e+(ext!=name_s?('.'+ext):"");},mediaLocale:function(source,lang){return this.imageLocale(source,lang);}})
var DialogAvvisi=Class.create({initialize:function(options){this.userManager=options.userManager;this.user=options.user
this.mainDiv=null;this.statusInfoContent=null;this.statusInfoEmailParentsBtn=null;this.statusInfoEmailFeedback=null;this.notificationsEmailParentsBtn=null;this.parentEmailField=null;this.parentEmailFieldInitialValue=null;this.parentEmailBtn=null;this.parentEmailNokFeedback=null;this.closeDialogBtn=null;this.goToYourPageLink=null;this.userId=(options!=null&&options.userId!=null)?options.userId:null;this.dialogLanguage=null;this.load({showAfterLoad:options.show,callbackToContinue:options.callbackToContinue,userId:options.userId})},load:function(options){var userId=(this.userId!=null)?this.userId:this.user.getId();new Ajax.Request('/user/load_dialog_avvisi/'+userId,{asynchronous:true,evalScripts:true,onComplete:this.hasLoaded.bindAsEventListener(this,{showAfterLoad:options.showAfterLoad,callbackToContinue:options.callbackToContinue})});},reload:function(options){var userId=(this.userId!=null)?this.userId:this.user.getId();this.dialogLanguage=options.language;new Ajax.Request("/user/load_dialog_avvisi?id="+userId+"&lang="+options.language+"&display=true",{asynchronous:true,evalScripts:true,onComplete:this.hasLoaded.bindAsEventListener(this,{showAfterLoad:options.showAfterLoad,callbackToContinue:options.callbackToContinue})});},hasLoaded:function(){this.bind();var showAfterLoad=arguments[1].showAfterLoad;if(showAfterLoad){this.show();}
if(arguments[1].callbackToContinue!=null&&arguments[1].callbackToContinue){arguments[1].callbackToContinue()};},bind:function(){this.mainDiv=$("dialogAvvisi");this.statusInfoContent=$("dialogAvvisi_statusInfo_content");this.statusInfoEmailParentsBtn=$("dialogAvvisi_statusInfo_emailParentsBtn");this.statusInfoEmailFeedback=$("dialogAvvisi_statusInfo_emailFeedback");this.notificationsEmailParentsBtn=$('dialogAvvisi_notifications_emailParentsBtn');this.parentEmailField=$('dialogAvvisi_parentEmailForm_Field');this.parentEmailBtn=$('dialogAvvisi_parentEmailForm_Link');this.parentEmailNokFeedback=$('dialogAvvisi_parentEmailForm_NokFeedback');this.closeDialogBtn=$("dialogAvvisi_closeBtn");this.goToYourPageLink=$('dialogAvvisi_profileSummary_goToYourPage_link');if(this.statusInfoEmailParentsBtn){this.statusInfoEmailParentsBtn.onclick=this.statusInfoEmailParentsBtnClicked.bindAsEventListener(this);}
if(this.notificationsEmailParentsBtn){this.notificationsEmailParentsBtn.onclick=this.notificationsEmailParentsBtnClicked.bindAsEventListener(this);}
if(this.parentEmailField){this.parentEmailFieldInitialValue=this.parentEmailField.value.strip();this.parentEmailField.onfocus=this.parentEmailFieldFocusedOn.bindAsEventListener(this);this.parentEmailBtn.onclick=this.parentEmailBtnClicked.bindAsEventListener(this);}
if(this.closeDialogBtn){this.closeDialogBtn.onclick=this.closeDialogBtnClicked.bindAsEventListener(this);}
if(this.goToYourPageLink){this.goToYourPageLink.onclick=this.goToYourPageLinkClicked.bindAsEventListener(this);}},hide:function(){this.mainDiv.hide();},show:function(){this.mainDiv.show();},statusInfoEmailParentsBtnClicked:function(){this.emailParents();},notificationsEmailParentsBtnClicked:function(){this.emailParents();},emailParents:function(){var userId=(this.userId!=null)?this.userId:this.user.getId();var objectToPost={'user_id':userId};if(this.dialogLanguage!=null){objectToPost.language=this.dialogLanguage;}
var options={JSON:true,evalJS:true,onComplete:this.checkEmailParentsResponse.bindAsEventListener(this)};this.userManager.communicator.sendRequest('/user/email_parents/',objectToPost,options);},checkEmailParentsResponse:function(request){if(this.userManager.communicator.checkResponseFromServer({request:request,refreshOnLogout:true,tabDialog:this.userManager.tabDialog})){this.statusInfoContent.hide();this.statusInfoEmailFeedback.show();}},parentEmailFieldFocusedOn:function(){if(this.parentEmailField.value.strip()==this.parentEmailFieldInitialValue){this.parentEmailField.value="";}
this.parentEmailNokFeedback.hide();},parentEmailBtnClicked:function(){this.changeParentEmail();},changeParentEmail:function(){var email=this.parentEmailField.value;if(email.strip().length>0){if(checkEmailPattern({email:email})){var userId=(this.userId!=null)?this.userId:this.user.getId();var objectToPost={parent_email:email,user_id:userId};var options={JSON:true,evalJS:true,onComplete:this.checkChangeParentEmailResponse.bindAsEventListener(this)};this.userManager.communicator.sendRequest('/user/change_parent_email/',objectToPost,options);}else{this.parentEmailNokFeedback.show();}}},checkChangeParentEmailResponse:function(request){if(this.userManager.communicator.checkResponseFromServer({request:request,refreshOnLogout:true,tabDialog:this.userManager.tabDialog,callbackOnApplicationError:this.showChangePMailServerNokFeedback.bind(this)})){this.statusInfoContent.hide();this.statusInfoEmailFeedback.show();}else{this.showChangePMailServerNokFeedback();}},showChangePMailServerNokFeedback:function(){this.userManager.tabDialog.hideDialog();this.parentEmailNokFeedback.show();},closeDialogBtnClicked:function(){this.hide();},goToYourPageLinkClicked:function(){location.href="/page/back_to_homepage";}})
var MyPageHeaderConf=Class.create({initialize:function(myPageHeaderBehaviour,myPageHeaderBehaviourAvoidFamous){this.myPageHeaderBehaviour=myPageHeaderBehaviour;this.myPageHeaderBehaviourAvoidFamous=myPageHeaderBehaviourAvoidFamous;},isElementVisible:function(){var element=arguments[0].element;var page=arguments[0].page;var user=arguments[0].user;var pageOwner=arguments[0].pageOwner;if(user.isFamousFriend()&&this.myPageHeaderBehaviourAvoidFamous.indexOf(element)!=-1){return false}
var elementObj=this.myPageHeaderBehaviour[element];if(typeof elementObj[page]=='undefined'){return false}
if(elementObj[page]==true){return true}
var pageObj=elementObj[page];if(user.isRegistered()){if(typeof(pageObj['user_registered'])!='undefined'){if(pageObj['user_registered']==true){return true}
var userObj=pageObj['user_registered'];if((typeof userObj['user_page']!='undefined')||(typeof userObj['not_user_page']!='undefined')){if(typeof userObj['user_page']!='undefined'){return(user.id==pageOwner.id)?true:false;}else{return(user.id!=pageOwner.id)?true:false;}}else{if(user.isLoggedIn()){if(typeof userObj['user_logged']!='undefined'){if(userObj['user_logged']==true){return true}
var userPageObj=userObj['user_logged'];if((typeof userPageObj['user_page']!='undefined')||(typeof userPageObj['not_user_page']!='undefined')){if(typeof userPageObj['user_page']!='undefined'){return(user.id==pageOwner.id)?true:false;}else{return(user.id!=pageOwner.id)?true:false;}}else{return false}}else{return false;}}else{if(typeof userObj['user_not_logged']!='undefined'){if(userObj['user_not_logged']==true){return true}
var userPageObj=userObj['user_not_logged'];if((typeof userPageObj['user_page']!='undefined')||(typeof userPageObj['not_user_page']!='undefined')){if(typeof userPageObj['user_page']!='undefined'){return(user.id==pageOwner.id)?true:false;}else{return(user.id!=pageOwner.id)?true:false;}}else{return false}}else{return false;}}}}else{return false;}}else{if(typeof pageObj['user_not_registered']!='undefined'){if(pageObj['user_not_registered']==true){return true}
var userObj=pageObj['user_not_registered'];if((typeof userObj['user_page']!='undefined')||(typeof userObj['not_user_page']!='undefined')){if(typeof userObj['user_page']!='undefined'){return(user.id==pageOwner.id)?true:false;}else{return(user.id!=pageOwner.id)?true:false;}}else{return false}}else{return false;}}}})
var Header=Class.create({initialize:function(header,pageName){this.header=header;this.pageName=pageName;this.myPageHeaderConf=null;},update:function(){if((typeof(arguments[0].myPageHeaderConf)!='undefined')&&(arguments[0].myPageHeaderConf!=null)){this.myPageHeaderConf=arguments[0].myPageHeaderConf;}}})
var UpperHeader=Class.create(Header,{initialize:function($super,header,pageName){$super(header,pageName);this.container=$('upper_header');this.staticHPLink=$('homeStLink');this.starPagesLink=$('starPagesLink');this.loginLink=$('loginLink');this.logoutLink=$('logoutLink');this.registerLink=$('registerLink');this.writeToMyPageLink=$('writeToMyPageLink');this.languageBox=$$('#upper_header #language_box')[0];this.bind();},bind:function(){this.staticHPLink.onclick=this.staticHPLinkClicked.bindAsEventListener(this);if(this.startPagesLink)this.starPagesLink.onclick=this.starPagesLinkClicked.bindAsEventListener(this);this.loginLink.onclick=this.loginLinkClicked.bindAsEventListener(this);this.logoutLink.onclick=this.logoutLinkClicked.bindAsEventListener(this);this.registerLink.onclick=this.registerLinkClicked.bindAsEventListener(this);this.writeToMyPageLink.onclick=this.writeToMyPageLinkClicked.bindAsEventListener(this);},staticHPLinkClicked:function(){this.header.staticHPLinkClicked();},starPagesLinkClicked:function(){this.header.starPagesLinkClicked();},loginLinkClicked:function(){this.header.loginLinkClicked();},logoutLinkClicked:function(){this.header.logoutLinkClicked();},registerLinkClicked:function(){this.header.registerLinkClicked();},writeToMyPageLinkClicked:function(){this.header.writeToMyPageLinkClicked();},update:function($super){$super(arguments[1]);var user=arguments[1].user;var pageOwner=arguments[1].pageOwner;if(this.myPageHeaderConf.isElementVisible({element:'language_box',page:this.pageName,user:user,pageOwner:pageOwner})){this.languageBox.style.display='block';}else{this.languageBox.style.display='none';}
if(user.isLoggedIn()){this.loginLink.style.display='none';this.logoutLink.style.display='inline';this.registerLink.style.display='none';}else{this.loginLink.style.display='inline';this.logoutLink.style.display='none';this.registerLink.style.display='inline';}}})
var LowerHeader=Class.create(Header,{initialize:function($super,header,pageName){$super(header,pageName);this.container=$('header_mypage');this.profileLink=$('profiloLink');this.passaparolaLink=$('passaparolaLink');this.friendsLink=$('amiciLink');this.awardsSupporterLink=$('awardsSupporterLink');this.passaparolaNotifications=$('passaparolaNotifiche');this.friendsNotifications=$('amiciNotifiche');this.accountLink=$('accountLink');this.pageOfMarker=$('pageOfMarker');this.headerAvatar=$('header_avatar');this.becomeFriendLink=$('becomeFriendLink');this.youAreFriendAd=$('youAreFriendAd');this.addFanLink=$('addFanLink');this.youAreFanAd=$('youAreFanAd');this.homePageLink=$('homePageLink');this.closePageLink=$('closePageLink');this.bind();},bind:function(){this.profileLink.onclick=this.profileLinkClicked.bindAsEventListener(this);this.accountLink.onclick=this.accountLinkClicked.bindAsEventListener(this);if(this.passaparolaLink!=null)
this.passaparolaLink.onclick=this.passaparolaLinkClicked.bindAsEventListener(this);if(this.friendsLink!=null)
this.friendsLink.onclick=this.friendsLinkClicked.bindAsEventListener(this);if(this.awardsSupporterLink!=null)
this.awardsSupporterLink.onclick=this.awardsSupporterLinkClicked.bindAsEventListener(this);this.homePageLink.onclick=this.homePageLinkClicked.bindAsEventListener(this);if(this.closePageLink!=null)
this.closePageLink.onclick=this.closePageLinkClicked.bindAsEventListener(this);this.becomeFriendLink.onclick=this.becomeFriendLinkClicked.bindAsEventListener(this);this.addFanLink.onclick=this.addFanLinkClicked.bindAsEventListener(this);},profileLinkClicked:function(){this.header.profileLinkClicked();},accountLinkClicked:function(){this.header.accountLinkClicked();},passaparolaLinkClicked:function(){this.header.passaparolaLinkClicked();},friendsLinkClicked:function(){this.header.friendsLinkClicked();},awardsSupporterLinkClicked:function(){this.header.awardsSupporterLinkClicked();},homePageLinkClicked:function(){this.header.homePageLinkClicked();},closePageLinkClicked:function(){this.header.closePageLinkClicked();},becomeFriendLinkClicked:function(){this.header.becomeFriendLinkClicked();},addFanLinkClicked:function(){this.header.addFanLinkClicked();},update:function($super){$super(arguments[1]);var user=arguments[1].user;var pageOwner=arguments[1].pageOwner;var profileLinkVisible=this.myPageHeaderConf.isElementVisible({element:'profile_page_link',page:this.pageName,user:user,pageOwner:pageOwner});var passaparolaLinkVisible=this.myPageHeaderConf.isElementVisible({element:'word_of_mouth_link',page:this.pageName,user:user,pageOwner:pageOwner});var friendsLinkVisible=this.myPageHeaderConf.isElementVisible({element:'friendship_page_link',page:this.pageName,user:user,pageOwner:pageOwner});var awardsSupporterLinkVisible=this.myPageHeaderConf.isElementVisible({element:'awards_supporter_link',page:this.pageName,user:user,pageOwner:pageOwner})
var homePageLinkVisible=this.myPageHeaderConf.isElementVisible({element:'go_to_my_page_link',page:this.pageName,user:user,pageOwner:pageOwner});if(profileLinkVisible){this.profileLink.style.display=user.isFamousFriend()?'none':'block';this.accountLink.style.display=user.isFamousFriend()?'block':'none';}else{this.profileLink.style.display='none';this.accountLink.style.display='none';}
if(this.passaparolaLink!=null)
this.passaparolaLink.style.display=passaparolaLinkVisible?'block':'none';if(this.passaparolaNotifications!=null){if(passaparolaLinkVisible){var newNotificationsCount=user.getNewNotificationsCount()
if(newNotificationsCount>0){this.passaparolaNotifications.innerHTML=newNotificationsCount;this.passaparolaNotifications.style.display='block';}else{this.passaparolaNotifications.style.display='none';}}else{this.passaparolaNotifications.style.display='none';}}
if(this.friendsLink!=null)
this.friendsLink.style.display=friendsLinkVisible?'block':'none';if(this.friendsNotifications!=null){if(friendsLinkVisible){var newFriendsCount=user.getNewFriendsCount();if(newFriendsCount>0){this.friendsNotifications.innerHTML=newFriendsCount;this.friendsNotifications.style.display='block';}else{this.friendsNotifications.style.display='none';}}else{this.friendsNotifications.style.display='none';}}
if(this.awardsSupporterLink!=null)
this.awardsSupporterLink.style.display=awardsSupporterLinkVisible?'block':'none';if(homePageLinkVisible){this.homePageLink.style.display='inline';}else{this.homePageLink.hide();}
var pageOfMarkerVisible=this.myPageHeaderConf.isElementVisible({element:'page_of_marker',page:this.pageName,user:pageOwner,pageOwner:pageOwner});var avatarVisible=this.myPageHeaderConf.isElementVisible({element:'avatar',page:this.pageName,user:pageOwner,pageOwner:pageOwner});var becomeFriendLinkVisible=this.myPageHeaderConf.isElementVisible({element:'become_friend',page:this.pageName,user:user,pageOwner:pageOwner});var nicknameDimension=getStringDimension({string:pageOwner.nickname,maxDim:11});this.showPageOfMarker(pageOwner,pageOfMarkerVisible);if(becomeFriendLinkVisible){if(user.isFriendWith(pageOwner)!=false){if(user.isFamousFriend()){this.youAreFriendAd.style.display='none';this.youAreFanAd.style.display='none';}else{if(!pageOwner.isFamousFriend()){this.youAreFriendAd.style.display='block';this.youAreFriendAd.setStyle('left:'+(nicknameDimension+174)+'px');this.youAreFanAd.style.display='none';}else{this.youAreFriendAd.style.display='none';this.youAreFanAd.style.display='block';this.youAreFanAd.setStyle('left:'+(nicknameDimension+174)+'px');}}
this.becomeFriendLink.style.display='none';this.addFanLink.style.display='none';}else{if((user.id!=pageOwner.id)){if(!pageOwner.isFamousFriend()){this.becomeFriendLink.style.display='block';this.addFanLink.style.display='none';this.becomeFriendLink.setStyle('left:'+(nicknameDimension+174)+'px');}else{this.becomeFriendLink.style.display='none';this.addFanLink.style.display='block';this.addFanLink.setStyle('left:'+(nicknameDimension+174)+'px');}}else{this.becomeFriendLink.style.display='none';this.addFanLink.style.display='none';}
this.youAreFriendAd.style.display='none';this.youAreFanAd.style.display='none';}}else{this.becomeFriendLink.style.display='none';this.addFanLink.style.display='none';this.youAreFriendAd.style.display='none';this.youAreFanAd.style.display='none';}
if(avatarVisible){if(pageOwner.avatarUrl!=null&&pageOwner.avatarUrl.strip().length>0){this.headerAvatar.select('img')[0].writeAttribute('src',pageOwner.avatarUrl);}
this.headerAvatar.setStyle('left:'+(nicknameDimension+96)+'px');}else{this.headerAvatar.hide();}},showPageOfMarker:function(pageOwner,show){if(show){var hasReqestedVersion=DetectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision);if(hasReqestedVersion){if(!pageOwner.isFamousFriend()){stringa=AC_FL_RunContent("src","/flash/mypage/pageOfMarker","width","256","height","19","align","middle","quality","high","wmode","transparent","menu","false","flashvars","nomeutente="+pageOwner.nickname,"allowScriptAccess","sameDomain","type","application/x-shockwave-flash",'codebase','http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',"pluginspage","http://www.adobe.com/go/getflashplayer");}else{stringa=AC_FL_RunContent("src","/flash/mypage/pageOfMarker_superuser","width","435","height","19","align","middle","quality","high","wmode","transparent","menu","false","flashvars","nomeutente="+pageOwner.nickname,"allowScriptAccess","sameDomain","type","application/x-shockwave-flash",'codebase','http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',"pluginspage","http://www.adobe.com/go/getflashplayer");}}else{var stringa='<img src="/images/mypage/page_of_marker.gif" alt="mypage.it/" /><span>'+pageOwner.nickname+'</span>';}
this.pageOfMarker.update(stringa);this.pageOfMarker.show();}else{this.pageOfMarker.hide();}},updateNewFriendshipItemsCounter:function(newValue){if(this.friendsNotifications){this.friendsNotifications.style.display=newValue>0?'block':'none'
this.friendsNotifications.innerHTML=newValue;}}})
var HeaderMyPage=Class.create({initialize:function(userManager,pageName){this.userManager=userManager;this.pageNmae=pageName;this.upperHeader=new UpperHeader(this,pageName);this.lowerHeader=new LowerHeader(this,pageName);this.actionToPerform=null;},staticHPLinkClicked:function(){this.userManager.staticHPLinkClicked();},starPagesLinkClicked:function(){this.userManager.starPagesLinkClicked();},loginLinkClicked:function(){this.userManager.loginLinkClicked();},logoutLinkClicked:function(){this.userManager.logoutLinkClicked();},registerLinkClicked:function(){this.userManager.registerLinkClicked();},writeToMyPageLinkClicked:function(){this.userManager.writeToMyPageLinkClicked();},profileLinkClicked:function(){this.userManager.profileLinkClicked();},accountLinkClicked:function(){this.userManager.accountLinkClicked();},passaparolaLinkClicked:function(){this.userManager.passaparolaLinkClicked();},friendsLinkClicked:function(){this.userManager.friendsLinkClicked();},awardsSupporterLinkClicked:function(){this.userManager.awardsSupporterLinkClicked();},homePageLinkClicked:function(){this.userManager.homePageLinkClicked();},closePageLinkClicked:function(){this.userManager.closePageLinkClicked();},becomeFriendLinkClicked:function(){this.userManager.becomeFriendLinkClicked();},addFanLinkClicked:function(){this.userManager.addFanLinkClicked();},update:function(){var headerConf=(typeof(arguments[0].myPageHeaderBehaviour)!='undefined'&&(arguments[0].myPageHeaderBehaviour!=null))?new MyPageHeaderConf(arguments[0].myPageHeaderBehaviour,arguments[0].myPageHeaderBehaviourAvoidFamous):null;this.upperHeader.update({user:arguments[0].user,pageOwner:arguments[0].pageOwner,myPageHeaderConf:headerConf})
this.lowerHeader.update({user:arguments[0].user,pageOwner:arguments[0].pageOwner,myPageHeaderConf:headerConf})},updateNewFriendshipItemsCounter:function(newValue){this.lowerHeader.updateNewFriendshipItemsCounter(newValue);}})
var UserManager=Class.create({initialize:function(options){this.pageTabs=options!=null&&options.pageTabs?options.pageTabs:arguments[0];this.user=options!=null&&options.user?options.user:arguments[1];this.pageOwner=options!=null&&options.pageOwner?options.pageOwner:arguments[2];this.tabDialog=options!=null&&options.tabDialog?options.tabDialog:arguments[3];this.pageName=options!=null&&options.pageName?options.pageName:arguments[4];this.communicator=options!=null&&options.communicator?options.communicator:arguments[5];var hasHeader=options!=null&&options.has_header?options.has_header:arguments[6];this.pageIsPrivate=options!=null&&options.pageIsPrivate?options.pageIsPrivate:null;this.pageAvailableToFamousUser=options!=null&&options.pageAvailableToFamousUser?options.pageAvailableToFamousUser:null
this.headerMyPage=hasHeader?new HeaderMyPage(this,this.pageName):null;this.pageToRefreshAtLogin=options!=null&&options.pageToRefreshAtLogin?options.pageToRefreshAtLogin:false;this.pageToRefreshAtLogout=options!=null&&options.pageToRefreshAtLogout?options.pageToRefreshAtLogout:this.pageToRefreshAtLogin;this.dialogAvvisi=null;this.actionsToPerform=new ActionsToPerform();this.eventQueueDispatcher=new EventQueueDispatcher();this.refreshPageAfterLogin=false;this.loginParameters=null;this.skipShowDialogAvvisi=false;this.start();},start:function(){this.checkUserInPage();this.subscribeAction({event:'login',when:'after',callback:new EventCallback({callback:this.showDialogAvvisi.bindAsEventListener(this),callbackParams:null,executeOnce:false,asynchronous:false,blocksQueue:false})})},showDialogAvvisi:function(options){var forceShow=options!=null&&options.force?options.force:false;var userId=options!=null&&options.userId?options.userId:null;if(this.user.hasDialogAvvisi&&(forceShow||(this.user.isLoggedIn()&&!this.skipShowDialogAvvisi))){var callbackToContinue=options!=null&&typeof options.callbackToContinue!='undefined'?options.callbackToContinue:null;this.dialogAvvisi=new DialogAvvisi({userManager:this,user:this.user,show:true,callbackToContinue:callbackToContinue,userId:userId});this.tabDialog.hideDialog();}},reloadDialogAvvisi:function(options){if(options!=null&&options.language!=null){this.dialogAvvisi.reload({language:options.language})}},subscribeAction:function(){this.eventQueueDispatcher.addCallback(arguments[0]);},checkSubscribeArguments:function(){if((arguments.length==0)||(arguments[0].event==null)||(['login','logout'].indexOf(arguments[0].event)==-1)||(arguments[0].when==null)||(['before','after'].indexOf(arguments[0].when)==-1)||(arguments[0].action==null)){return false;}else{return true;}},userCanAccessPage:function(){var pageIsPrivate=this.pageIsPrivate!=null?this.pageIsPrivate:["pass_the_word","pass_the_word_index","user_profile","friendship_page"].indexOf(this.pageName)!=-1
if(pageIsPrivate){if(this.user.isLoggedIn()){if(this.user.isFamousFriend()){var pageAvailableToFamousUser=this.pageAvailableToFamousUser!=null?this.pageAvailableToFamousUser:["pass_the_word","pass_the_word_index","friendship_page"].indexOf(this.pageName)!=-1
if(pageAvailableToFamousUser){return false;}else{return true;}}else{return true;}}else{return false;}}else{return true;}},checkUserInPage:function(){if(!this.userCanAccessPage()){location.href="/page/back_to_homepage";}},checkAlertForUser:function(){if(this.userCanAccessPage()){if(this.user.getId()!=this.pageOwner.getId()){if(!this.pageOwner.isFamousFriend()){if(this.user.isFamousFriend()){this.displayAlertForNotFriendUser({userIsFamous:true});}else{if(!this.user.isFriendWith(this.pageOwner)){this.displayAlertForNotFriendUser({userIsFamous:false});}}}}}},displayAlertForNotFriendUser:function(){var userIsFamous=typeof arguments[0]!='undefined'&&typeof arguments[0].userIsFamous!='undefined'?arguments[0].userIsFamous:false;var description=userIsFamous?message=i18n.stringLocale('not_friend_content_hidden','dialog',[this.pageOwner.nickname]):message=i18n.stringLocale('not_friend_content_hidden','dialog',[this.pageOwner.nickname])
this.tabDialog.displayMessage({title:'halt',description:description,actionOK:this.tabDialog.hideDialog.bind(this.tabDialog),size:'small'})
this.tabDialog.showDialog();},staticHPLinkClicked:function(){location.href='/';},starPagesLinkClicked:function(){null;},loginLinkClicked:function(){var redirectToHomepage=((this.pageName=='static_homepage'||this.pageName=='static_page')?false:true)
this.startLogin({redirectToHomepage:redirectToHomepage});},startLogin:function(options){if(options!=null&&options.skipShowDialogAvvisi==true){this.skipShowDialogAvvisi=true}
var redirectToHomepage=((typeof(arguments[0])!='undefined')&&(typeof(arguments[0].redirectToHomepage)!='undefined')&&(arguments[0].redirectToHomepage!=null))?arguments[0].redirectToHomepage:true;this.tabDialog.showLoginForm({callbacks:{loginConfirmed:this.loginConfirmed.bind(this,{redirectToHomepage:redirectToHomepage}),loginCancelled:this.loginCancelled.bindAsEventListener(this)},message:typeof arguments[0]!='undefined'?arguments[0].message:null});},loginConfirmed:function(){this.loginParameters=arguments[1].parameters;var redirectToHomepage=((typeof(arguments[0])!='undefined')&&(typeof(arguments[0].redirectToHomepage)!='undefined')&&(arguments[0].redirectToHomepage!=null))?arguments[0].redirectToHomepage:true;this.eventQueueDispatcher.eventHappen({event:'login',when:'before',callbackToContinueEvent:this.sendLoginRequest.bind(this,{redirectToHomepage:redirectToHomepage})});},loginCancelled:function(){this.eventQueueDispatcher.eventCancelled({event:'login'});this.tabDialog.hideDialog();},sendLoginRequest:function(){var redirectToHomepage=((typeof(arguments[0])!='undefined')&&(typeof(arguments[0].redirectToHomepage)!='undefined')&&(arguments[0].redirectToHomepage!=null))?arguments[0].redirectToHomepage:true;new Ajax.Request('/user/login',{asynchronous:true,evalScripts:true,parameters:this.loginParameters,requestHeaders:{Accept:'text/x-json'},onComplete:this.checkLoginResponse.bindAsEventListener(this,{redirectToHomepage:redirectToHomepage})})},checkLoginResponse:function(request){var redirectToHomepage=((typeof(arguments[1])!='undefined')&&(typeof(arguments[1].redirectToHomepage)!='undefined')&&(arguments[1].redirectToHomepage!=null))?arguments[1].redirectToHomepage:true;if(this.communicator.checkResponseFromServer({request:request,refreshOnLogout:true,tabDialog:this.tabDialog,redirectToHomepageOnLogin:redirectToHomepage})){var currentUserLang=this.user.getLang();this.user.setUserInfoFromServerData(request.responseJSON.content);this.refreshPageAfterLogin=(this.user.getLang()!=currentUserLang)||(this.pageToRefreshAtLogin);if((redirectToHomepage&&(this.user.id!=this.pageOwner.id))||this.refreshPageAfterLogin){this.skipShowDialogAvvisi=true}
this.eventQueueDispatcher.eventHappen({event:'login',when:'after',callbackToContinueEvent:this.completeLogin.bind(this,{redirectToHomepage:redirectToHomepage})});}},completeLogin:function(){var redirectToHomepage=((typeof(arguments[0])!='undefined')&&(typeof(arguments[0].redirectToHomepage)!='undefined')&&(arguments[0].redirectToHomepage!=null))?arguments[0].redirectToHomepage:true;if((redirectToHomepage)&&(this.user.id!=this.pageOwner.id)){this.tabDialog.waitAndRedirect({message:i18n.stringLocale('stai_andando_tua_pagina','dialog'),url:null,timeout:2000,showDialogAvvisiAtStartup:true});}else{if(this.refreshPageAfterLogin){this.pageTabs.forceRefresh({showDialogAvvisiAtStartup:true});}else{this.updateHeader();this.pageTabs.applyLoginToPage();}}
this.refreshPageAfterLogin=false;},logoutLinkClicked:function(){this.tabDialog.displayMessage({title:'exit',description:i18n.stringLocale('msg_uscita_1','dialog')+"</p><p>"+i18n.stringLocale('msg_uscita_2','dialog')+"</p><p>"+i18n.stringLocale('msg_uscita_3','dialog'),actions:'2buttons',actionOK:this.logoutConfirmed.bindAsEventListener(this),actionCancel:this.cancelLogout.bindAsEventListener(this)})
this.tabDialog.showDialog();},logoutConfirmed:function(){this.eventQueueDispatcher.eventHappen({event:'logout',when:'before',callbackToContinueEvent:this.startLogout.bind(this)});},cancelLogout:function(){this.eventQueueDispatcher.eventCancelled({event:'logout'});this.tabDialog.hideDialog();},startLogout:function(){new Ajax.Request('/user/logout',{asynchronous:true,evalScripts:true,onComplete:this.checkLogoutResponse.bindAsEventListener(this)});},checkLogoutResponse:function(request){var responseCheck=this.communicator.checkResponseFromServer({request:request,refreshOnLogout:true,tabDialog:this.tabDialog,forceRefreshCallback:this.forceRefresh.bind(this),forceLogoutCallback:this.forceLogout.bind(this),startLoginCallback:this.startLogin.bind(this)});if(responseCheck){if(request.responseJSON!=null&&typeof request.responseJSON.content!='undefined'&&request.responseJSON.content!=null){this.pageTabs.user.setUserInfoFromServerData(request.responseJSON.content);this.eventQueueDispatcher.eventHappen({event:'logout',when:'after',callbackToContinueEvent:this.completeLogout.bind(this)});}else{window.location.reload(true);}}},completeLogout:function(){this.tabDialog.hideDialog();if(!this.userCanAccessPage()){location.href="/page/back_to_homepage";}else{if(this.pageToRefreshAtLogout){this.pageTabs.forceRefresh()}else if(typeof(this.pageTabs.applyLogoutToPage)!='undefined'){this.pageTabs.applyLogoutToPage();}};this.updateHeader();},registerLinkClicked:function(){this.registerUser();},registerUser:function(){var url="/user/register/";switch(this.pageName){case'static_homepage':url="/user/register?from=static"
break;case'page':url="/user/register"
break;}
location.href=url;},writeToMyPageLinkClicked:function(){this.writeToMyPage();},writeToMyPage:function(){var userLang=this.user.getLang()||'it'
window.open('http://parental.mypage.it/'+userLang+'/support.php','support','height=600, width=550, left=20, top=20, resizable=yes, scrollbars=yes, menubar=yes, toolbar=yes, directories=yes, location=no, status=yes');},forceLogout:function(){this.user.logged_in=false;this.completeLogout();},forceRefresh:function(){if(typeof pageTabs.forceRefresh!='undefined'){pageTabs.forceRefresh();}else{window.location.reload(true);}},checkUserStatusAtStartUp:function(myPageHeaderBehaviour,myPageHeaderBehaviourAvoidFamous){this.updateHeader(myPageHeaderBehaviour,myPageHeaderBehaviourAvoidFamous);if(this.user.isLoggedIn()){if(typeof(this.pageTabs.applyLoginToPage)!='undefined'){this.pageTabs.applyLoginToPage({atStartup:true});}}},profileLinkClicked:function(){if(this.pageName!='user_profile'){location.href='/user/profile/'+this.user.id;}},accountLinkClicked:function(){if(this.pageName!='user_profile'){location.href='/user/profile/'+this.user.id;}},passaparolaLinkClicked:function(){if((this.pageName!='pass_the_word_index')&&(this.pageName!='pass_the_word')){location.href="/word_of_mouth/index/?page=1";}},friendsLinkClicked:function(){if(this.pageName!='friendship_page'){location.href="/friends";}},awardsSupporterLinkClicked:function(){if(this.pageName!='awards_supporter_personal_page'){location.href="/supporter"}},homePageLinkClicked:function(){location.href='/'+this.user.nickname;},closePageLinkClicked:function(){this.homePageLinkClicked();},becomeFriendLinkClicked:function(){this.becomeFriendSecond();},addFanLinkClicked:function(){this.becomeFriendSecond();},becomeFriendSecond:function(){var callbackToContinue=typeof arguments[0]!='undefined'&&typeof arguments[0].callbackToContinue!='undefined'?arguments[0].callbackToContinue:null;if(this.user.isRegistered()){if(this.user.isLoggedIn()){if(this.user.canRequireFriendship()!=false){if(this.user.canRequireFriendship()==true||(this.user.canRequireFriendship()=='only_famous_friends'&&this.pageOwner.isFamousFriend())){if((this.pageOwner.isRegistered())&&(this.pageOwner.nickname!=this.user.nickname)&&(!this.pageOwner.canHaveFriends())){this.sendMailToParent({caller:this.user,receiver:this.pageOwner,callerIsBlocked:false});message=i18n.stringLocale('amico_controllato_1','dialog')+this.pageOwner.nickname+i18n.stringLocale('amico_controllato_2','dialog');this.tabDialog.displayMessage({title:'halt',description:message,actionOK:this.addFriendRequestFailed.bind(this,{callbackToContinue:callbackToContinue}),size:'small'})
this.tabDialog.showDialog();}else{var addingFriendNickname=this.pageOwner.nickname;this.startFriendshipRequest({friendNickname:addingFriendNickname,callbackToContinue:callbackToContinue})}}else{this.sendMailToParent({caller:this.user,receiver:this.pageOwner,callerIsBlocked:true});message=i18n.stringLocale('user_controllato','dialog')
this.tabDialog.displayMessage({title:'halt',description:message,actionOK:this.addFriendRequestFailed.bind(this,{callbackToContinue:callbackToContinue}),size:'small'})
this.tabDialog.showDialog();}}else{this.sendMailToParent({caller:this.user,receiver:this.pageOwner,callerIsBlocked:true});message=i18n.stringLocale('cannot_ask_friendship','dialog')
this.tabDialog.displayMessage({title:'halt',description:message,actionOK:this.addFriendRequestFailed.bind(this,{callbackToContinue:callbackToContinue}),size:'small'})
this.tabDialog.showDialog();}}else{this.subscribeAction({event:'login',when:'after',placeFirst:true,callback:new EventCallback({callback:this.becomeFriendSecond.bindAsEventListener(this),callbackParams:null,executeOnce:true,asynchronous:false,blocksQueue:true})})
message=i18n.stringLocale('friendship_checker_login','dialog');this.tabDialog.displayMessage({title:'halt',description:message,actions:'2buttons',actionOK:this.startLogin.bind(this,{redirectToHomepage:false}),actionCancel:this.tabDialog.hideDialog.bindAsEventListener(this.tabDialog)})
this.tabDialog.showDialog();}}else{message=i18n.stringLocale('friendship_checker_register','dialog');this.tabDialog.displayMessage({title:'halt',description:message,actions:'1button',actionOK:this.registerUser.bindAsEventListener(this),actionCancel:this.tabDialog.hideDialog.bindAsEventListener(this.tabDialog)})
this.tabDialog.showDialog();}},startFriendshipRequest:function(){var callbackToContinue=typeof arguments[0]!='undefined'&&typeof arguments[0].callbackToContinue!='undefined'?arguments[0].callbackToContinue:null;this.addingFriendNickname=arguments[0].friendNickname;var objectToPost={'nickname':this.addingFriendNickname};var options={JSON:true,evalJS:true,onComplete:this.checkAddFriendResponse.bindAsEventListener(this,{callbackToContinue:callbackToContinue})};this.communicator.sendRequest('/friendship/add_friend/',objectToPost,options);},checkAddFriendResponse:function(request){var callbackToContinue=arguments[1].callbackToContinue;var title='warning';var size='big';if(this.communicator.checkResponseFromServer({request:request,refreshOnLogout:true,tabDialog:this.tabDialog,callbackOnApplicationError:this.addFriendRequestFailed.bind(this,{callbackToContinue:callbackToContinue})})){var response=request.responseJSON;if(response.status.action_to_perform=='insertMagicSpell'){this.tabDialog.showAddFriendForm({},{friendNickname:this.addingFriendNickname,callbackToContinue:callbackToContinue});}else{if(response.status.action_result=='OK'){title='good';size='small';actionOK=this.addFriendRequestCompleted.bind(this,{response:response,callbackToContinue:callbackToContinue});}else{actionOK=this.addFriendRequestFailed.bind(this,{callbackToContinue:callbackToContinue});}
this.tabDialog.displayMessage({title:title,description:response.status.message,actions:'1button',actionOK:actionOK,size:size})
this.tabDialog.showDialog();}}},addFriendRequestCompleted:function(){this.tabDialog.hideDialog();if(typeof arguments[0]!='undefined'&&typeof arguments[0].response!='undefined'&&typeof arguments[0].response.content!='undefined'&&arguments[0].response.content!=null){this.user.setUserInfoFromServerData(arguments[0].response.content);}
this.updateHeader();if(typeof arguments[0]!='undefined'&&typeof arguments[0].callbackToContinue!='undefined'&&arguments[0].callbackToContinue!=null){arguments[0].callbackToContinue();}},addFriendRequestFailed:function(){this.tabDialog.hideDialog();if(typeof arguments[0]!='undefined'&&typeof arguments[0].callbackToContinue!='undefined'&&arguments[0].callbackToContinue!=null){arguments[0].callbackToContinue();}},reloadUserInfo:function(){var includePageOwner=typeof arguments[0]!='undefined'&&arguments[0].includePageOwner!=null?arguments[0].includePageOwner:false
var objectToPost=includePageOwner?this.pageOwner.getId():null;var options={JSON:false,evalJS:false,requestHeaders:{Accept:'text/x-json'},onComplete:this.checkReloadUserInfoResponse.bindAsEventListener(this)};this.communicator.sendRequest('/user/reload_user_info/',objectToPost,options);},checkReloadUserInfoResponse:function(request){if(this.communicator.checkResponseFromServer({request:request,refreshOnLogout:true,tabDialog:this.tabDialog})){var content=request.responseJSON.content;this.user.setUserInfoFromServerData(content.user);this.pageOwner.setUserInfoFromServerData(content.page_owner);this.updateHeader();}},updateHeader:function(myPageHeaderBehaviour,myPageHeaderBehaviourAvoidFamous){if(this.headerMyPage!=null){this.headerMyPage.update({user:this.user,pageOwner:this.pageOwner,myPageHeaderBehaviour:myPageHeaderBehaviour,myPageHeaderBehaviourAvoidFamous:myPageHeaderBehaviourAvoidFamous});}},updateNewFriendshipItemsCounter:function(newValue){this.headerMyPage.updateNewFriendshipItemsCounter(newValue);},sendMailToParent:function(){var caller=arguments[0].caller;var receiver=arguments[0].receiver;var callerIsBlocked=arguments[0].callerIsBlocked;var objectToPost={caller_id:caller.getId(),receiver_id:receiver.getId(),caller_is_blocked:callerIsBlocked}
var options={JSON:true,evalJS:false};this.communicator.sendRequest('/friendship/send_mail_to_parent_for_friendship/',objectToPost,options);},pageOwnerIsFriendWithUser:function(){var friendship=this.pageOwner.isFriendWith(this.user);if(friendship!=false){if(this.user.isFamousFriend()){return'userIsFamous';}else{return friendship;}}else{return friendship;}},userIsFriendWithOtherById:function(otherId){var friendship=this.user.isFriendWithById(otherId);if(friendship!=false){if(this.user.isFamousFriend()){return'userIsFamous';}else{return friendship;}}else{return friendship;}},goToPage:function(options){var options=options.parameters!=null?options.parameters:options
if(this.user.isLoggedIn()){if(options.page=='friends'){location.href="/friends";}else if(options.page=='profile'){switch(options.tab){case('avatar'):location.href="/user/profile?tab=avatar";break;case('magic_spell'):location.href="/user/profile?tab=magic_spell";break;default:location.href="/user/profile?tab=account";}}}else{this.subscribeAction({event:'login',when:'after',callback:new EventCallback({callback:this.goToPage.bindAsEventListener(this),callbackParams:options,executeOnce:true,asynchronous:false,blocksQueue:true})})
this.startLogin({redirectToHomepage:false})}}})
var FlashPreloader=Class.create({initialize:function(options){this.idDivContainer=options.idDivContainer;this.browser=options.browser!=null?options.browser:BrowserDetect.browser;this.movieFlash=null;this.objectFlash=null;this.intervalId=null;this.divContainer=null;this.spinnerBuilded=0;this.topForPreloaderImage=options.topForPreloaderImage
this.leftForPreloaderImage=options.leftForPreloaderImage
this.imageForSpinner=options.imageForSpinner},getContainerFlashObject:function(){this.divContainer=$(''+this.idDivContainer+'')},buildContainerSpinner:function(){if(!this.spinnerBuilded){this.divContainer.parentNode.insert({bottom:'<div id=\"spinner_for_preload\" style=\"display:block; position:absolute; top:'+this.topForPreloaderImage+'px; left:'+this.leftForPreloaderImage+'px;width:100px;height:40px;\" >'+'<img src=\"/images/'+this.imageForSpinner+'.gif\"/ style=\"float:left;\">'+'<span id=\"percent_loaded\" style=\"position: relative; text-align: center; width: 250px; height: 30px;left:10px;top:5px;\"></span></div>'})
this.spinnerBuilded=1}else{$('spinner_for_preload').style.display=""
$('spinner_for_preload').update('<img src=\"/images/'+this.imageForSpinner+'.gif\"/ style=\"float:left;\">'+'<span id=\"percent_loaded\" style=\"position: relative; text-align: center; width: 250px; height: 30px;left:10px;top:5px;\"></span>')}},getFlashName:function(){this.movieFlash=this.divContainer.down().src},getMovieFlashIstance:function(){if(this.browser=="Firefox"||this.browser=="Safari"){i=0
while(window.document.plugins[i]!=null){if(this.movieFlash==window.document.plugins[i].src){this.objectFlash=window.document.plugins[i]
break;}else
i++;}}else{if(this.divContainer)
this.objectFlash=this.divContainer.down('OBJECT').object}
return this.objectFlash;},hideObjectFlash:function(){this.divContainer.style.visibility="hidden"},stopPreloader:function(){if(this.intervalId){this.intervalId.stop();this.intervalId=null}},getFlash:function(){this.getContainerFlashObject()
this.getFlashName();return this.getMovieFlashIstance();},initPreloader:function(){this.getContainerFlashObject()
this.getFlashName();this.hideObjectFlash();return this.getMovieFlashIstance();},startPreloader:function(){this.intervalId=new PeriodicalExecuter(this.checkFlashLoading.bindAsEventListener(this),1);},checkFlashLoading:function(){if(this.objectFlash.PercentLoaded()==100){$('spinner_for_preload').style.display="none"
this.divContainer.style.visibility=""
if(this.intervalId)
this.stopPreloader()}else{$('percent_loaded').innerHTML=this.objectFlash.PercentLoaded()+" %"}}})
var mpConfig=new MPConfiguration();var i18n=new I18N();