Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function updates()
- {
- checkSession();
- updateOnlineUsers();
- updateMessages();
- }
- function showLogin()
- {
- var insert = "";
- insert += "<br><br><form action='php/login.php' method='POST'><table align='center'>";
- insert += "<tr><td>Username:</td><td><input type='text' name='username'></td></tr>";
- insert += "<tr><td>Password:</td><td><input type='password' name='password'></td></tr>";
- insert += "<tr><td colspan='2' align='center'><input type='submit' value='Login'></td></tr></table></form>";
- document.getElementById("formLocation").innerHTML = insert;
- }
- function showRegister()
- {
- var insert = "";
- insert += "<br><br><table align='center'><form action='php/register.php' method='POST'>";
- insert += "<tr><td>Username:</td><td><input type='text' name='username'></td></tr>";
- insert += "<tr><td>Password:</td><td><input type='password' name='password' id='password'></td></tr>";
- insert += "<tr><td>Confirm Password:</td><td><input type='password' onBlur=\"checkPassword();\" name='passConfirm' id='passConfirm'></td></tr>";
- insert += "<tr><td colspan='2' align='center'><input type='submit' value='Register'></td></tr></table></form>";
- document.getElementById("formLocation").innerHTML = insert;
- }
- function checkPassword()
- {
- var pass1 = document.getElementById('password').value;
- var pass2 = document.getElementById('passConfirm').value;
- if(pass1 == "" || pass2 == "")
- {
- alert("Password can't be blank!");
- return false;
- } else if(pass1 != pass2)
- {
- alert("Passwords don't match!");
- return false;
- }
- return true;
- }
- function updateMessages()
- {
- var txtFile = new XMLHttpRequest();
- txtFile.open("GET", "../messages.txt", true);
- txtFile.onreadystatechange = function() {
- if (txtFile.readyState === 4) {
- if (txtFile.status === 200) {
- if(txtFile.responseText != "")
- {
- lines = txtFile.responseText.split("\n"); // Will separate each line into an array
- output = "";
- for(var i = 0; i < lines.length; i++)
- output += lines[i] + "<br>";
- document.getElementById("chatBox").innerHTML = output;
- var textarea = document.getElementById('chatBox');
- textarea.scrollTop = textarea.scrollHeight;
- } else
- document.getElementById("chatBox").innerHTML = "No messages!";
- } else
- document.getElementById("chatBox").innerHTML = "<i>Loading Messages...</i>";
- }
- }
- txtFile.send(null);
- window.setTimeout("updateMessages();", 1000);
- }
- function checkSession()
- {
- if (window.XMLHttpRequest)
- xmlhttp=new XMLHttpRequest();
- else
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- if(xmlhttp.responseText == '1')
- {
- window.location = "index.php";
- setTimeout("checkSession();", 1500);
- }
- }
- }
- xmlhttp.open("GET","php/session_check.php",true);
- xmlhttp.send();
- }
- function updateOnlineUsers()
- {
- $(function(){
- $("#usersOnline").load("php/get_online_users.php");
- });
- setTimeout("updateOnlineUsers();", 500);
- }
- function sendMessage()
- {
- var message = document.getElementById("message").value;
- document.getElementById("message").value = "";
- if (window.XMLHttpRequest)
- xmlhttp=new XMLHttpRequest();
- else
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- xmlhttp.open("GET","php/send_message.php?m=" + message,true);
- xmlhttp.send();
- }
- function updateOnlineStatus()
- {
- var statusChange = document.getElementById("onlineStatus").value;
- if (window.XMLHttpRequest)
- xmlhttp=new XMLHttpRequest();
- else
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- xmlhttp.open("GET","php/update_online_status.php?s=" + statusChange,true);
- xmlhttp.send();
- }
Advertisement
Add Comment
Please, Sign In to add comment