var submitexpected=false;var SUPPORTED_LANGUAGES={en:"English",es:"Español",de:"Deutsch",nl:"Nederlands",pt_br:"Portuguese (Brazil)",ja:"日本語",he:"עברית"};function revertscreen(){$("first").enable();$("last").enable();$("password").enable();$("btn_login").enable();$("location").enable();$("grid").enable();$("lang").enable();$(document.body).removeClassName("loggingin");try{window.parent.document.getElementById("frameset").rows="*,80";var A=window.parent.document.getElementById("loginpage");if(A&&A.parentNode){A.parentNode.insertBefore(A,window.parent.document.getElementById("loginform"))}}catch(B){}}function dolanguage(){$("label_first").innerHTML=_("Login.First");$("label_last").innerHTML=_("Login.Last");$("label_pass").innerHTML=_("Login.Password");$("label_grid").innerHTML=_("Login.Grid");$("label_lang").innerHTML=_("Login.Language");$("btn_login").value=_("Login.LogIn");if($("label_sound")){$("label_sound").innerHTML=_("Login.EnableSound")}if($("location")){$("label_loginlocation").innerHTML=_("Login.Location");$("location").options[0].text=_("Login.Home");$("location").options[1].text=_("Login.LastPlace");$("location").options[2].text=_("Login.ArbitraryPlace")}Ext.MessageBox.buttonText={yes:_("Widgets.Yes"),no:_("Widgets.No"),ok:_("Widgets.OK"),cancel:_("Widgets.Cancel")};if(_("Language.Direction")=="rtl"&&!Prototype.Browser.IE){$(document.getElementsByTagName("body")[0]).removeClassName("ltr");$(document.getElementsByTagName("body")[0]).addClassName("rtl")}else{$(document.getElementsByTagName("body")[0]).removeClassName("rtl");$(document.getElementsByTagName("body")[0]).addClassName("ltr")}}var query=location.search.toQueryParams();if(!window.parent.document.getElementsByTagName("frameset").length&&!(query.noframes==true||query.noframes=="true"||query.noframes==undefined)){location.replace("index.html")}function domemorycheck(){var A=false;A=A||(window.opera&&opera.wiiremote);A=A||!!navigator.userAgent.match(/Apple.*Mobile.*Safari/);if(A){$("background").parentNode.removeChild($("background"));$(document.body).addClassName("lowmem")}}function initui(){AjaxLife.Debug("login: Switching visible screen.");$("loginscreen").hide();domemorycheck();$("uiscreen").show();var B=AjaxLife.Widgets.Modal.wait(_("Login.LoadingSession"));var A=new Ext.data.Connection({timeout:30000});A.request({url:"details.kat",method:"POST",params:{sid:gSessionID},callback:function(D,G,C){C=C.responseText;AjaxLife.Debug("login: sessiondata: "+C);B.hide();B=false;if(!G){AjaxLife.Widgets.Modal.alert(_("Login.SessionLoadFailed"));return }var F=Ext.util.JSON.decode(C);gRegionCoords=F.RegionCoords;gRegion=F.Region;gPosition=F.Position;gMOTD=F.MOTD;gUserName=F.UserName;gAgentID=F.AgentID;gInventoryRoot=F.InventoryRoot;AjaxLife.Debug("login: Extracted session data.");gLanguageCode=$("lang").getValue();AjaxLife.Debug("login: Checking for login screen frame...");if(window.parent&&window.parent.document&&window.parent.document.getElementById){var E=window.parent.document.getElementById("loginpage");if(E&&E.parentNode){AjaxLife.Debug("login: Removing login screen...");E.parentNode.removeChild(E)}}$(document.body).addClassName("loggedin").removeClassName("loggingin");AjaxLife.Debug("login: Running AjaxLife init...");AjaxLife.Startup()}})}function handlelogin(){$("first").disable();$("last").disable();$("password").disable();$("btn_login").disable();$("location").disable();$("grid").disable();$("lang").disable();if(window.parent&&window.parent.document&&window.parent.document.getElementById){var A=window.parent.document.getElementById("loginpage");if(A&&A.parentNode){A.parentNode.appendChild(A);window.parent.document.getElementById("frameset").rows="*,0"}}$(document.body).addClassName("loggingin");setTimeout(function(){if(!$("grid").getValue().endsWith("(Linden Lab)")){if(!confirm("You are about to send data to a login server that is NOT owned by Linden Lab.\nThe login info will be passed on UNENCRYPTED.\n\nDO NOT USE your Second Life account to log into this grid.\nIf you are using an account specifically for "+$("grid").getValue()+", it is safe to proceed.\nDo you wish to continue?")){revertscreen();return false}}var B=AjaxLife.Widgets.Modal.wait(_("Login.Encrypting"));var D=Encrypt();AjaxLife.Debug("login: Encrypted login: "+D);B.updateText(_("Login.LoggingIn"));var C=new Ext.data.Connection({timeout:120000});C.request({url:"connect.kat",method:"POST",params:{logindata:D,grid:$("grid").getValue(),location:$("location").getValue(),sim:$("loginsim").value,session:gSessionID},callback:function(F,H,E){AjaxLife.Debug("login: Received login response: "+E.responseText);B.hide();B=false;if(H){try{var E=Ext.util.JSON.decode(E.responseText);if(E.success){initui()}else{AjaxLife.Debug("login: Login failure: "+E.message);AjaxLife.Widgets.Modal.alert(_("Login.Error"),E.message.escapeHTML(),revertscreen)}}catch(G){AjaxLife.Widgets.Modal.alert("Server Error","A C# Exception was caught:<pre>"+E.responseText.escapeHTML()+"</pre>",revertscreen)}}else{AjaxLife.Widgets.Modal.alert(_("Login.Error"),_("Login.SomethingWrong"),revertscreen)}}});AjaxLife.Debug("login: Made login request.")},100)}function base64encode(I){var A="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var G=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);var D,F,H;var E,C,B;H=I.length;F=0;D="";while(F<H){E=I.charCodeAt(F++)&255;if(F==H){D+=A.charAt(E>>2);D+=A.charAt((E&3)<<4);D+="==";break}C=I.charCodeAt(F++);if(F==H){D+=A.charAt(E>>2);D+=A.charAt(((E&3)<<4)|((C&240)>>4));D+=A.charAt((C&15)<<2);D+="=";break}B=I.charCodeAt(F++);D+=A.charAt(E>>2);D+=A.charAt(((E&3)<<4)|((C&240)>>4));D+=A.charAt(((C&15)<<2)|((B&192)>>6));D+=A.charAt(B&63)}return D}function Encrypt(){setMaxDigits(131);key=new RSAKeyPair(RSA_EXPONENT,"",RSA_MODULUS);encrypted=encryptedString(key,CHALLENGE+"\\"+base64encode(Ext.get("first").dom.value)+"\\"+base64encode(Ext.get("last").dom.value)+"\\$1$"+md5(Ext.get("password").dom.value)+"\\"+AjaxLife.Signature);return encrypted}Ext.onReady(function(){Ext.get("btn_login").on("click",handlelogin);var B=function(G){if(G.keyCode==13||G.which==13){handlelogin()}};Ext.get("first").addListener("keyup",B);Ext.get("last").addListener("keyup",B);Ext.get("password").addListener("keyup",B);$("form_login").onsubmit=function(G){if(G&&G.preventDefault){G.preventDefault()}else{if(window.event&&window.event.returnValue){window.eventReturnValue=false}}handlelogin();return false};if($("lang")){var A=[];var F=navigator.language?navigator.language:navigator.browserLanguage;try{if(!F||!F.gsub){F="en"}else{F=F.gsub("-","_")}if(!SUPPORTED_LANGUAGES[F]){if(!SUPPORTED_LANGUAGES[F.substr(0,2)]){F="en"}else{F=F.substr(0,2)}}}catch(E){F="en"}$("lang").childElements().invoke("remove");for(var D in SUPPORTED_LANGUAGES){var C=document.createElement("option");C.appendChild(document.createTextNode(SUPPORTED_LANGUAGES[D]));C.value=D;if(D==F){C.selected="selected"}$("lang").appendChild(C)}gLanguageCode=$("lang").getValue();$("lang").onchange=function(){gLanguageCode=$("lang").getValue();dolanguage()};dolanguage()}if($("location")){$("location").onchange=function(){if($("location").getValue()=="arbitrary"){$("loginsim").show().activate()}else{$("loginsim").hide()}};Ext.get("loginsim").addListener("keyup",B);$("loginsim").onkeyup=function(){$("location").options[2].text=$("loginsim").value.blank()?_("Login.ArbitraryPlace"):$("loginsim").value}}if($("enablesound")){$("enablesound").onchange=function(){if($("enablesound").checked){AjaxLife.Sound.Enable()}else{AjaxLife.Sound.Disable()}}}$("first").activate()})