Anyone familiar with the Omelge chat script? (alteration)

Discussion in 'JavaScript' started by MoonPie00, Apr 14, 2010.

  1. #1
    I want to alter the script in a way where there are 2 different kinds of users that get matched up in pairs, and so that it is not entirely random. In other words, instead of just click on "Start Chat", there would be a start chat as user A, or Start chat as user B. Where by user A and B would get paired up to chat, instead of AA or BB.

    Here is the java code for the start chat button and random chat

    
    
    function startChat()
                    {
                    xmlHttp2 = GetXmlHttpObject();
    
                    if (xmlHttp2 == null)
                        {
                        alert("Browser does not support HTTP Request");
                        return;
                        }
    
                    var url = "startChat.php";
                    xmlHttp2.open("POST", url, true);
                    xmlHttp2.onreadystatechange = stateChanged2;
                    xmlHttp2.send(null);
                    }
    
                function stateChanged2()
                    {
                    if (xmlHttp2.readyState == 4 || xmlHttp2.readyState == "complete")
                        {
                        userId = trim(xmlHttp2.responseText);
    
                        document.getElementById("chatbox").style.display = 'block';
                        document.getElementById("sendbtn").disabled = true;
                        document.getElementById("chatmsg").disabled = true;
                        document.getElementById("disconnectbtn").disabled = true;
    
                        document.getElementById("intro").style.display = 'none';
                        document.getElementById("sayHi").style.display = 'none';
    
                        if (document.getElementById("chatDisconnected") != undefined)
                            document.getElementById("chatDisconnected").style.display = 'none';
    
                        if (document.getElementById("startNew") != undefined)
                            document.getElementById("startNew").style.display = 'none';
    
                        randomChat();
                        }
                    }
    
    
    Code (markup):
    
    function listenToReceive()
                    {
                    xmlHttp5 = GetXmlHttpObject();
    
                    if (xmlHttp5 == null)
                        {
                        alert("Browser does not support HTTP Request");
                        return;
                        }
    
                    var url = "listenToReceive.php?userId=" + userId;
                    xmlHttp5.open("POST", url, true);
                    xmlHttp5.onreadystatechange = stateChanged5;
                    xmlHttp5.send(null);
                    }
    
                function stateChanged5()
                    {
                    if (xmlHttp5.readyState == 4 || xmlHttp5.readyState == "complete")
                        {
                        var msg = xmlHttp5.responseText;
    
                        if (trim(msg) == "||--noResult--||")
                            {
                            // other party is disconnected//
                            document.getElementById("sendbtn").disabled = true;
                            document.getElementById("chatmsg").disabled = true;
                            document.getElementById("disconnectbtn").disabled = true;
                            document.getElementById("sayHi").style.display = 'none';
                            document.getElementById("chatDisconnected").style.display = 'block';
                            document.getElementById("logbox").innerHTML
                                += "<div id='startNew' class='logitem'><div><input value='Start New Chat' onclick='startNewChat();' type='button'></div></div>";
                            document.getElementById("logbox").scrollTop = document.getElementById("logbox").scrollHeight;
                            leaveChat();
    
                            return;
                            }
    
                        else if (trim(msg) != "" && msg != undefined)
                            {
                            // Message received //
                            document.getElementById("logbox").innerHTML
                                += "<div class='logitem'><div class='strangermsg'><span class='msgsource'>Friend:</span>"
                                       + msg + "</div></div>";
                            document.getElementById("logbox").scrollTop = document.getElementById("logbox").scrollHeight;
    
                            playTitleFlag = true;
                            playTitle();
                            }
    
                        window.setTimeout("listenToReceive();", 2000);
                        }
                    }
    
    
    Code (markup):

     
    MoonPie00, Apr 14, 2010 IP