///////////////////////////////////////// // // Misc // ///////////////////////////////////////// var progressImage; function onLoad() { // adjust page based on where we are being executed iPhoneTest(); // connect to server in 0.5 seconds setTimeout( function() { listener.start( ); }, 500); // username was saved? var userNameToUse = getCookie( "username" ); if ( userNameToUse !== null) { $("loginUsername").value = userNameToUse; } progressImage = new Image(); progressImage.src = "img/animation_in_progress.gif"; var topPx = 0; var leftPx = 0; var delta = 5; // setTimeout( function( ) { // confirmBox( "Attention! This is your captain speaking
Do you know me?", function( answer ) { alert( "answer " + answer ); }); // }, 500 ); } function alertBox( text ) { var alertDiv = $("alertMessageSectionShell"); $("alertMessageText").innerHTML = text; alertDiv.style.display = "block"; alertDiv.style.left = (alertDiv.parentNode.clientWidth - alertDiv.clientWidth - 4)/2 + "px"; alertDiv.style.top = (alertDiv.parentNode.scrollHeight - alertDiv.clientHeight - 4)/2 + "px"; } function confirmBox( text, resultCallback ) { var confirmDiv = $("confirmMessageSectionShell"); $("confirmMessageText").innerHTML = text; confirmDiv.style.display = "block"; confirmDiv.style.left = (confirmDiv.parentNode.clientWidth - confirmDiv.clientWidth - 4)/2 + "px"; confirmDiv.style.top = (confirmDiv.parentNode.scrollHeight - confirmDiv.clientHeight - 4)/2 + "px"; $("confirmNoButton").onclick = function( ) { resultCallback( false ); confirmDiv.style.display = "none"; return false; }; $("confirmYesButton").onclick = function( ) { resultCallback( true ); confirmDiv.style.display = "none"; return false; }; } ///////////////////////////// // function displayInProgress(baseId) { $(baseId + "ResultDiv").className = "sectionContent spinningProgress"; $(baseId + "ResultHeader").style.display = "none"; $(baseId + "ResultMessage").style.display = "none"; $(baseId + "ResultButton").style.display = "none"; displayResultDiv(baseId); } ///////////////////////////// // function setupResultDivAsMessage(baseId, success, message) { $(baseId + "ResultDiv").className = "sectionContent resultAsMessage"; $(baseId + "ResultHeader").style.display = "block"; $(baseId + "ResultMessage").style.display = "block"; $(baseId + "ResultButton").style.display = "block"; var header = $(baseId + "ResultHeader"); if ( success ) { header.className = "resultSuccess"; header.innerHTML = "Success!"; } else { header.className = "resultError"; header.innerHTML = "Oops, something didn't work..."; } $(baseId + "ResultMessage").innerHTML = message; } ///////////////////////////// // function displayResultDiv(baseId) { var resultDiv = $(baseId + "ResultDiv"); var sectionContent = $(baseId + "SectionContent"); // make it same height if ( sectionContent.style.display != "none" ) { resultDiv.style.minHeight = (sectionContent.offsetHeight - 6) + "px"; } // hide content section sectionContent.style.display = "none"; // display message div resultDiv.style.display = "block"; } ///////////////////////////// // function hideResultDiv(baseId) { // hide result div $(baseId + "ResultDiv").style.display = "none"; // show content section $(baseId + "SectionContent").style.display = "block"; } ///////////////////////////// // function proceedToLobby() { window.document.location = "lobby/lobby.do"; } ///////////////////////////////////////// // // REGISTRATION stuff // ///////////////////////////////////////// var username; function submitRegistration() { // check stuff var email = $("formRegEmail").value; var invite = "safari"; username = $("formRegUsername").value; var password = $("formRegPassword").value; var password2 = $("formRegPassword2").value; // all there? if ( !email || !invite || !username || !password || !password2 ) { displayRegistrationMessage(false, "Please fill in all fields." ); return; } // passwords? if ( password != password2 ) { displayRegistrationMessage(false, "'Password' and 'Confirm password' values do not match." ); return; } // email ok? var emailCheck = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // http://www.webreference.com/js/column5/form.html if ( !emailCheck.test(email)) { displayRegistrationMessage(false, "Email address appears to be invalid." ); return; } // long enough? if ( username.length < 3 || username.length > 11 || password.length < 3 || password.length > 11 ) { displayRegistrationMessage(false, "Username and password should be
between 3 and 11 characters long."); return; } // working on it displayInProgress("registration"); // submit stuff setTimeout( function() { new ServerProxy( "http://web1.scramboni.com/Byteclub/login.op" ).send( { operation: "login", action: "register", userName: username, password: password, emailAddress: email, inviteCode: invite } ); }, 100 ); } ///////////////////////////// // function register_Result( args ) { // lucky day? if ( args.errorMessage ) { displayRegistrationMessage(false, args.errorMessage); return; } setCookie( "username", username, new Date ( 2012, 21, 12 ), "/" ); // ask user to click OK displayRegistrationMessage(true, "Your registration has succeeded.
Press OK to login to ByteClub."); // move along setCookie( "username", username, new Date ( 2012, 21, 12 ), "/" ); setTimeout( proceedToLobby, 100 ); return; // OK button should launch a login sequence // $("registrationResultButton").onclick = completeRegistrationSequence; } ///////////////////////////// // function completeRegistrationSequence() { var username = $("formRegUsername").value; var password = $("formRegPassword").value; // working on it displayInProgress("registration"); // submit stuff setTimeout( function() { new ServerProxy( "http://web1.scramboni.com/Byteclub/login.op" ).send( { operation: "login", action: "login", userName: username, password: password } ); }, 100 ); } ///////////////////////////// // function displayRegistrationMessage(success, message) { if ( success ) { $("registrationResultButton").onclick = proceedToLobby; } else { $("registrationResultButton").onclick = hideRegistrationResultDiv; } setupResultDivAsMessage("registration", success, message); displayResultDiv("registration"); } ///////////////////////////// // function hideRegistrationResultDiv() { hideResultDiv("registration"); } ///////////////////////////////////////// // // LOGIN stuff // ///////////////////////////////////////// function submitLogin() { // verify login info username = $("loginUsername").value; var password = $("loginPassword").value; // there? if ( !username || !password ) { displayLoginError( "Username and password are required." ); return; } // long enough? if ( username.length < 3 || username.length > 11 || password.length < 3 || password.length > 11 ) { displayLoginError("Username and password should be
between 3 and 11 characters long."); return; } // working on it displayInProgress("login"); // submit stuff setTimeout( function() { new ServerProxy( "http://web1.scramboni.com/Byteclub/login.op" ).send( { operation: "login", action: "login", userName: username, password: password } ); }, 100 ); } ///////////////////////////// // function login_Result( args ) { if ( ! args.errorMessage ) { // move along setCookie( "username", username, new Date ( 2012, 21, 12 ), "/" ); setTimeout( proceedToLobby, 100 ); return; } // something went wrong displayLoginError( args.errorMessage ); } ///////////////////////////// // function displayLoginError(message) { setupResultDivAsMessage("login", false, message); displayResultDiv("login"); }