////////////////////////////////////////////////////////////////////////////
////////////////////////This function tells who's online////////////////////
////////////////////////////////////////////////////////////////////////////

var oldContentx="";
function getMembers(chat_id){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = 'members_online_incl.php?chat_id=' + chat_id; //This is the path to the file we just finished making *
    xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to receive data
                var content = xmlhttp.responseText; //The content data which has been retrieved ***
                if( content ){ //Make sure there is something in the content variable
                      if(content!=oldContentx){
					  	document.getElementById('membersOnlineDiv').innerHTML = content; //Change the inner content of your div to the newly retrieved content ****
					}
					  oldContentx=content;
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
		window.setTimeout("getMembers()", 5000);
		
}



////////////////////////////////////////////////////////////////////////////
////////////////////////This function tells who's in the room///////////////
////////////////////////////////////////////////////////////////////////////

var oldContenty="";
function getRoomMembers(chat_id){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = "members_in_room.php?chat_id=" + escape(chat_id) + "&"; //This is the path to the file we just finished making *
    xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to receive data
                var contenty = xmlhttp.responseText; //The content data which has been retrieved ***
                if( contenty ){ //Make sure there is something in the content variable
                      if(contenty!=oldContenty){
					  	document.getElementById('membersInRoomDiv').innerHTML = contenty; //Change the inner content of your div to the newly retrieved content ****
					}
					  oldContenty=contenty;
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
		window.setTimeout("getRoomMembers(" + chat_id + ")", 5000);
		
}


////////////////////////////////////////////////////////////////////////////
////////////////////////This function refreshes the chat////////////////////
////////////////////////////////////////////////////////////////////////////

var x=0;
function flagScrollbar(){
	
	x=1;

}

var oldContentz="";
function refreshChat(chat_id){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = "refresh_chat.php?chat_id=" + escape(chat_id) + "&"; //This is the path to the file we just finished making *
    xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to receive data
                var contentz = xmlhttp.responseText; //The content data which has been retrieved ***
                if( contentz ){ //Make sure there is something in the content variable
                    if(contentz!=oldContentz){
					  	document.getElementById('chat').innerHTML = contentz; //Change the inner content of your div to the newly retrieved content ****
						x=0;
					}
					if(x!=1){
						document.getElementById('chat').scrollTop=document.getElementById('chat').scrollHeight;		
					}
					  oldContentz=contentz;
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
		window.setTimeout("refreshChat(" + chat_id + ")", 1000);
		
}




////////////////////////////////////////////////////////////////////////////
////////////////////////This function gets all the current chats////////////
////////////////////////////////////////////////////////////////////////////

var oldContenty="";
function getChats(){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = "includes/members_in_room2.php"; //This is the path to the file we just finished making *
    xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to receive data
                var contenty = xmlhttp.responseText; //The content data which has been retrieved ***
                if( contenty ){ //Make sure there is something in the content variable
                      if(contenty!=oldContenty){
					  	document.getElementById('allChats').innerHTML = contenty; //Change the inner content of your div to the newly retrieved content ****
					}
					  oldContenty=contenty;
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
		window.setTimeout("getChats()", 5000);
		
}


////////////////////////////////////////////////////////////////////////////
////////////////////////This function gets all the current chats////////////
////////////////////////////////////////////////////////////////////////////

var oldContenty="";
function totalMembers(){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = "includes/total_members_online.php"; //This is the path to the file we just finished making *
    xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) { //Check if it is ready to receive data
                var contenty = xmlhttp.responseText; //The content data which has been retrieved ***
                if( contenty ){ //Make sure there is something in the content variable
                      if(contenty!=oldContenty){
					  	document.getElementById('totalMembers').innerHTML = contenty; //Change the inner content of your div to the newly retrieved content ****
					}
					  oldContenty=contenty;
                }
        }
        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
		window.setTimeout("totalMembers()", 5000);
		
}

////////////////////////////////////////////////////////////////////////////
////////////////////////This function logs the user out of the chat room////
////////////////////////////////////////////////////////////////////////////


function logOutChat(member_id, chat_id){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = "chat_logout.php?member_id=" + member_id +"&chat_id=" + chat_id; //This is the path to the file we just finished making *
    xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {

        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
		
}




function addToChat(member_id, chat_id, bodyText){
var xmlhttp=false; //Clear our fetching variable
        try {
                xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
        } catch (e) {
                try {
                        xmlhttp = new
                        ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
            } catch (E) {
                xmlhttp = false;
                        }
        }
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                xmlhttp = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
        }
        var file = "chat_add_text.php?member_id=" + member_id +"&chat_id=" + chat_id +"&bodyText=" + escape(bodyText); //This is the path to the file we just finished making *
    xmlhttp.open('GET', file, true); //Open the file through GET, and add the page we want to retrieve as a GET variable **
    xmlhttp.onreadystatechange=function() {

        }
        xmlhttp.send(null) //Nullify the XMLHttpRequest
		
}

