Guest User

Untitled

a guest
Sep 17th, 2013
1,337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updates()
  2. {
  3.     checkSession();
  4.     updateOnlineUsers();
  5.     updateMessages();
  6. }
  7.  
  8. function showLogin()
  9. {
  10.     var insert = "";
  11.     insert += "<br><br><form action='php/login.php' method='POST'><table align='center'>";
  12.     insert += "<tr><td>Username:</td><td><input type='text' name='username'></td></tr>";
  13.     insert += "<tr><td>Password:</td><td><input type='password' name='password'></td></tr>";
  14.     insert += "<tr><td colspan='2' align='center'><input type='submit' value='Login'></td></tr></table></form>";
  15.    
  16.     document.getElementById("formLocation").innerHTML = insert;
  17. }
  18.  
  19. function showRegister()
  20. {
  21.     var insert = "";
  22.    
  23.     insert += "<br><br><table align='center'><form action='php/register.php' method='POST'>";
  24.     insert += "<tr><td>Username:</td><td><input type='text' name='username'></td></tr>";
  25.     insert += "<tr><td>Password:</td><td><input type='password' name='password' id='password'></td></tr>";
  26.     insert += "<tr><td>Confirm Password:</td><td><input type='password' onBlur=\"checkPassword();\" name='passConfirm' id='passConfirm'></td></tr>";
  27.     insert += "<tr><td colspan='2' align='center'><input type='submit' value='Register'></td></tr></table></form>";
  28.    
  29.     document.getElementById("formLocation").innerHTML = insert;
  30. }
  31.  
  32. function checkPassword()
  33. {
  34.     var pass1 = document.getElementById('password').value;
  35.     var pass2 = document.getElementById('passConfirm').value;
  36.    
  37.     if(pass1 == "" || pass2 == "")
  38.     {
  39.         alert("Password can't be blank!");
  40.         return false;
  41.     } else if(pass1 != pass2)
  42.     {
  43.         alert("Passwords don't match!");
  44.         return false;
  45.     }
  46.    
  47.     return true;
  48. }
  49.  
  50. function updateMessages()
  51. {
  52.     var txtFile = new XMLHttpRequest();
  53.     txtFile.open("GET", "../messages.txt", true);
  54.     txtFile.onreadystatechange = function() {
  55.     if (txtFile.readyState === 4) {
  56.         if (txtFile.status === 200) {
  57.             if(txtFile.responseText != "")
  58.             {
  59.                 lines = txtFile.responseText.split("\n"); // Will separate each line into an array
  60.                 output = "";
  61.            
  62.                 for(var i = 0; i < lines.length; i++)
  63.                     output += lines[i] + "<br>";
  64.                
  65.                 document.getElementById("chatBox").innerHTML = output;
  66.                 var textarea = document.getElementById('chatBox');
  67.                 textarea.scrollTop = textarea.scrollHeight;
  68.             } else
  69.                 document.getElementById("chatBox").innerHTML = "No messages!";
  70.         } else
  71.                 document.getElementById("chatBox").innerHTML = "<i>Loading Messages...</i>";
  72.         }  
  73.     }
  74.     txtFile.send(null);
  75.    
  76.     window.setTimeout("updateMessages();", 1000);
  77. }
  78.  
  79. function checkSession()
  80. {
  81.     if (window.XMLHttpRequest)
  82.         xmlhttp=new XMLHttpRequest();
  83.     else
  84.         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  85.    
  86.     xmlhttp.onreadystatechange=function()
  87.     {
  88.         if (xmlhttp.readyState==4 && xmlhttp.status==200)
  89.         {
  90.             if(xmlhttp.responseText == '1')
  91.             {
  92.                 window.location = "index.php";
  93.                 setTimeout("checkSession();", 1500);
  94.             }
  95.         }
  96.     }
  97.    
  98.     xmlhttp.open("GET","php/session_check.php",true);
  99.     xmlhttp.send();
  100. }
  101.  
  102. function updateOnlineUsers()
  103. {
  104.     $(function(){
  105.       $("#usersOnline").load("php/get_online_users.php");
  106.     });
  107.    
  108.     setTimeout("updateOnlineUsers();", 500);
  109. }
  110.  
  111. function sendMessage()
  112. {
  113.     var message = document.getElementById("message").value;
  114.     document.getElementById("message").value = "";
  115.  
  116.     if (window.XMLHttpRequest)
  117.         xmlhttp=new XMLHttpRequest();
  118.     else
  119.         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  120.    
  121.     xmlhttp.open("GET","php/send_message.php?m=" + message,true);
  122.     xmlhttp.send();
  123. }
  124.  
  125. function updateOnlineStatus()
  126. {
  127.     var statusChange = document.getElementById("onlineStatus").value;
  128.    
  129.     if (window.XMLHttpRequest)
  130.         xmlhttp=new XMLHttpRequest();
  131.     else
  132.         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  133.    
  134.     xmlhttp.open("GET","php/update_online_status.php?s=" + statusChange,true);
  135.     xmlhttp.send();
  136. }
Advertisement
Add Comment
Please, Sign In to add comment