var Panel=new Class({initialize:function(c,b){this.keep=false;this.panel=c;if(b){try{this.panel.style.left=b.getCoordinates().left}catch(a){}}},show:function(){this.panel.style.display="block"},hide:function(){this.panel.style.display="none"},isShown:function(){var a=this.panel.style.display;return a=="block"},click:function(){this.keep=true},toggle:function(){if(this.panel){if(!this.isShown()){this.show();this.showHideAction();this.showAction();this.keep=true;document.onclick=this.close.create({event:true,bind:this});document.onkeydown=this.escape.create({event:true,bind:this});this.panel.onclick=this.click.create({event:true,bind:this})}else{this.hide();this.showHideAction();this.hideAction()}return false}else{return true}},close:function(a){if(this.keep){this.keep=false;return}if(!this.panel){return}this.hide();document.onclick=null;document.onkeydown=null},escape:function(b){if(window.event){b=window.event}var a=b.keyCode?b.keyCode:b.which?b.which:null;if(a==27){if(!this.panel){return}this.hide();document.onclick=null;document.onkeydown=null}},click:function(a){this.keep=true},showHideAction:function(){},showAction:function(){},hideAction:function(){}});var LoginPanel=new Class({Extends:Panel,initialize:function(){this.parent($("LoginPanel"));this.nameField=$("id_username");this.pwdField=$("id_password")},setUser:function(a){if(!this.isShown()){this.show();this.nameField.value=a;this.pwdField.value="";this.pwdField.focus()}},showAction:function(){this.nameField.focus()}});var LangPanel=new Class({Extends:Panel,initialize:function(){this.parent($("LangPanel"))}});var PaymentPanel=new Class({Extends:Panel,initialize:function(){this.parent($("PaymentPanel"));this.submitButton=$("payment_submit");this.addCreditsLink=$("link_addcredits");try{this.panel.style.left=this.addCreditsLink.getCoordinates().left}catch(a){}},enableSubmit:function(){if(this.submitButton.disabled==true){this.submitButton.disabled=false}},showHideAction:function(){this.enableSubmit()}});var FeedbackPanel=new Class({Extends:Panel,initialize:function(){this.parent($("FeedBackPanel"));this.feedbackLink=$("link_feedback")},align:function(){try{this.panel.style.right=(1-(this.feedbackLink.getCoordinates().right/document.getCoordinates().width))*100+"%"}catch(a){this.style.left="30%"}},showHideAction:function(){this.align()}});var verifyState={phoneInputEnabled:true,showVerifyButton:true,showChangeButton:false,showInProgress:false,showSuccess:false,showSecret:false,clearSecretCode:false};var inProgressState={phoneInputEnabled:false,showVerifyButton:false,showChangeButton:true,showInProgress:true,showSuccess:false,showSecret:false,clearSecretCode:false};var secretState={phoneInputEnabled:false,showVerifyButton:false,showChangeButton:true,showInProgress:false,showSuccess:false,showSecret:true,clearSecretCode:true};var successState={phoneInputEnabled:false,showVerifyButton:false,showChangeButton:true,showInProgress:false,showSuccess:true,showSecret:false,clearSecretCode:false};var CliPanel=new Class({Extends:Panel,initialize:function(){this.parent($("CliPanel"));this.linkCli=$("link_cli");try{this.panel.style.left=this.linkCli.getCoordinates().left}catch(a){}},showHideAction:function(){var a=Cookie.read("verify_inprogress");if(a){this.drawControls(secretState);$("verify_phone_input").value=a}else{if($("success_div").style.display!="none"){this.drawControls(successState)}else{this.drawControls(verifyState)}}},drawControls:function(b,a){$("verify_phone_input").disabled=!b.phoneInputEnabled;$("verify_phone_button").style.display=b.showVerifyButton?"block":"none";$("change_phone_button").style.display=b.showChangeButton?"block":"none";$("ajaxload").style.display=b.showInProgress?"block":"none";$("success_div").style.display=b.showSuccess?"block":"none";$("error_div").style.display=a?"block":"none";if(a){$("error_div").innerHTML=a}$("secret_div").style.display=b.showSecret?"block":"none";if(b.clearSecretCode){$("secret_code_input").value=""}},verifyCancel:function(){Cookie.dispose("verify_inprogress");new Request({method:"GET",url:"/drop_phone/"}).send();this.drawControls(verifyState)},verifyPhone:function(){var a=this;new Request({method:"POST",url:"/verify_phone/"+$("verify_phone_input").value+"/",onRequest:function(){a.drawControls(inProgressState)},onSuccess:function(b){switch(b){case"OK":Cookie.write("verify_inprogress",$("verify_phone_input").value);a.drawControls(secretState);break;case"INPROGRESS":Cookie.dispose("verify_inprogress");a.drawControls(successState);break;default:a.drawControls(verifyState,gettext("error"))}},onFailure:function(){a.drawControls(verifyState,gettext("error"))}}).send()},submitPhone:function(){var a=this;new Request({method:"POST",url:"/submit_phone/"+$("verify_phone_input").value+"/"+$("secret_code_input").value+"/",onSuccess:function(b){if(b){if(b=="OK"){Cookie.dispose("verify_inprogress");a.drawControls(successState)}}else{a.drawControls(secretState,gettext("incorrect_code"))}}}).send()}});var PrefsPanel=new Class({Extends:Panel,initialize:function(){this.parent($("PrefsPanel"),$("link_prefs"))},saveAlias:function(){new Request({method:"POST",url:"/savealias/",data:"username="+$("alias_input").value,onRequest:function(){$("alias_ajaxload").style.display="block"},onSuccess:function(a){$("alias_ajaxload").style.display="none";switch(a){case"OK":$("alias_successdiv").style.display="block";$("alias_input").disabled="true";$("save_alias_button").disabled="true";$("alias_errordiv").style.display="none";break;case"FAIL":$("alias_successdiv").style.display="none";$("alias_errordiv").style.display="block";break;default:$("alias_successdiv").style.display="none";$("alias_errordiv").style.display="block"}},onFailure:function(){$("alias_ajaxload").style.display="none";$("alias_successdiv").style.display="none";$("alias_errordiv").style.display="block"}}).send()}});var SettingsPanel=new Class({Extends:Panel,initialize:function(){this.parent($("SettingsPanel"),$("linkSettings"))},fillDropDownList:function(e,b,d){var a=0;for(var c=0;c<b.length;c++){if(b[c]==d){a=c}e.add(new Element("option",{html:b[c]}),null)}e.selectedIndex=a},populate:function(){var a=$("TalkPadAdapter");if(!a){return}var g=a.getAttribute("playback_devices");var e=a.getAttribute("capture_devices");if(!g||!e){return}var c=g.split("|");c.unshift("default");var f=$("PlaybackDevice");this.fillDropDownList(f,c,a.getAttribute("playback_device"));f.addEvent("change",function(){if(softPhone){softPhone.setPlaybackDevice(f.options[f.selectedIndex].value)}});var b=e.split("|");b.unshift("default");var d=$("CaptureDevice");this.fillDropDownList(d,b,a.getAttribute("capture_device"));d.addEvent("change",function(){if(softPhone){softPhone.setCaptureDevice(d.options[d.selectedIndex].value)}})},showAction:function(){if(this.populate){try{this.populate()}catch(a){alert(a)}this.populate=null}}});var SignupForm=new Class({initialize:function(){this.signupComment=$("signupComment");this.signupInput=$("signupInput");this.signupSpinner=$("signupSpinner");this.signupButton=$("signupButton");this.sInputDiv=$("sInputDiv");this.sCommentDiv=$("sCommentDiv");this.normalState={showComment:true,showInput:true,showButton:true,showSpinner:false,signupButtonDisabled:false};this.spinnerState={showComment:false,showInput:false,showButton:true,showSpinner:true,sInputDiv:false,sCommentDiv:false,signupButtonDisabled:true};this.verifyState={showComment:false,showInput:false,showButton:true,showSpinner:false,sInputDiv:true,sCommentDiv:true,signupButtonDisabled:false,signupButtonText:"Login"}},drawControls:function(a){this.signupComment.style.display=a.showComment?"block":"none";this.signupInput.style.display=a.showInput?"block":"none";this.signupSpinner.style.display=a.showSpinner?"block":"none";this.sInputDiv.style.display=a.sInputDiv?"block":"none";this.sCommentDiv.style.display=a.sCommentDiv?"block":"none";this.signupButton.disabled=a.signupButtonDisabled},verify:function(){var b=this;var a=$("phoneRegInput").value;new Request({method:"POST",url:"/signup/",data:"phone="+a,onRequest:function(){b.drawControls(b.spinnerState)},onSuccess:function(c){if(c){b.drawControls(b.normalState);$("id_username").value=c;loginPanel.toggle();$("id_password").focus()}else{b.drawControls(b.normalState)}}}).send()}});var loginPanel=null;var langPanel=null;var cliPanel=null;var prefsPanel=null;var paymentPanel=null;var feedbackPanel=null;var signupForm=null;var settingsPanel=null;window.addEvent("domready",function(){loginPanel=new LoginPanel();langPanel=new LangPanel();cliPanel=new CliPanel();prefsPanel=new PrefsPanel();paymentPanel=new PaymentPanel();feedbackPanel=new FeedbackPanel();signupForm=new SignupForm();settingsPanel=new SettingsPanel()});

