//need to move these to above the include for this file
//var chatroomid = 1;
//var setChatName = '';
//var setChatUserId = 0;

var chatRefreshRate = 4500; //default refresh rate for chat updating (4.5 seconds)
var secondsSinceMessageSent = 0; //This holds the time since a message was sent by a user in the chat.

function setGameSpace(space,code) {
var temp = document.getElementById(space);
var temp2 = code;
//if (temp.innerHTML != temp2) {
//temp.innerHTML = temp2;
if (document.getElementById('setGameSpaceTemp')) {
document.getElementById('setGameSpaceTemp').innerHTML = code;
if (document.getElementById(space).innerHTML != document.getElementById('setGameSpaceTemp').innerHTML) {
document.getElementById(space).innerHTML = code;
}
}//if document.getElementById('setGameSpaceTemp') exists
}



function updateChatRefreshRateBasedOnUserCount(value) {
if (value <= 30) { chatRefreshRate = 5000 + value*10; }
else if (value <= 60) { chatRefreshRate = 6400 + value*10; }
else if (value <= 90) { chatRefreshRate = 7500 + value*10; }
else { chatRefreshRate = 9900 + value*10; }
//if (secondsSinceMessageSent >= 60) { chatRefreshRate = chatRefreshRate + 10000; } //increases refresh rate by 10 seconds if they have not sent a message in 60 seconds minutes
//if (secondsSinceMessageSent >= 400) { chatRefreshRate = chatRefreshRate + 20000; } //increases refresh rate by 55 seconds if they have not sent a message in 200 seconds minutes
if (chatRefreshRate > 61000) { chatRefreshRate = 41000; }
var temp = (Math.round((chatRefreshRate/1000)*10)/10) + ' Seconds/Update**';
if (document.getElementById('refreshRate')) { document.getElementById('refreshRate').innerHTML = temp; }//if it exists
}//function updateChatRefreshRatebasedOnUserCount



var setChatBoxHeight = 198;
var setChatBoxWidth = 568;
			var sendReq = getXmlHttpRequestObject();
			var receiveReq = getXmlHttpRequestObject();
			var receiveReqOnline = getXmlHttpRequestObject();
			// var receiveReqCapture = getXmlHttpRequestObject();
			var lastMessage = 0;
			var lastNewMessage = 0;
			var lastMessageOnline = 0;
			var mTimerOnlineMod = 1;
			var mTimer;
			var mTimerOnline;
var remoteUser = '';
var lastMessagePrivate = 0;
var previousRemoteUser = '';
var temp;
var temp2;
var temp3;
var temp4;
			var mTimerChatLastReload;
			var mTimerChatLastReloadSecondsPassing = 62;
                        var mTimerChatLastReloadSeconds = 62; //if it has been more than 62 seconds we should force a refresh
function decLastChatReloadUpdateSeconds() {
	clearTimeout(mTimerChatLastReload);
//document.getElementById('chatUpdateButton').value = 'Refresh (' + mTimerChatLastReloadSecondsPassing + ')';
if (mTimerChatLastReloadSecondsPassing > 0) {
mTimerChatLastReloadSecondsPassing--;
document.getElementById('chatUpdateButton').value = 'Refresh';
} else { //we probably need to start the chat again
document.getElementById('chatUpdateButton').value = 'Refresh (' + mTimerChatLastReloadSecondsPassing + ')';
mTimerChatLastReloadSecondsPassing--;
				clearTimeout(mTimer);
getChatText();
}//else start chat
secondsSinceMessageSent++; //Increases time since last message was sent every second
mTimerChatLastReload = setTimeout('decLastChatReloadUpdateSeconds();',1000); //refresh our function in 1 seconds
}//function


function setRemoteUser(RemoteU)
{
remoteUser = RemoteU;
if (RemoteU == '') { temp3 = 'chatTaskBarMain'; } else { temp3 = 'chatTaskBar' + remoteUser; }
document.getElementById(temp3).style.background='#cccccc';
document.getElementById(temp3).style.display='';

if (RemoteU != '') {
temp4 = 'HidechatTaskBar' + RemoteU;
document.getElementById(temp4).style.display='';
}
if (previousRemoteUser == '') { temp4 = 'div_chat'; } else { temp4 = 'chatWindow' + previousRemoteUser; }
document.getElementById(temp4).style.display='none';
if (RemoteU == '') { temp2 = 'div_chat'; } else { temp2 = 'chatWindow' + RemoteU; }
document.getElementById(temp2).style.display='block';
chatWindowTemp = document.getElementById(temp2);

chatWindowTemp.scrollTop = chatWindowTemp.scrollHeight;
previousRemoteUser = RemoteU;
document.forms['frmmain']. elements['txt_message'].focus();
}

function hideRemoteUser(RemoteU) {
if (RemoteU == '') { temp2 = 'div_chat'; } else { temp2 = 'chatWindow' + RemoteU; }
document.getElementById(temp2).style.display='none';
temp4 = 'chatTaskBar' + RemoteU;
document.getElementById(temp4).style.display='none';

temp4 = 'HidechatTaskBar' + RemoteU;
document.getElementById(temp4).style.display='none';
if (previousRemoteUser == '') { temp4 = 'div_chat'; } else { temp4 = 'chatWindow' + previousRemoteUser; }
document.getElementById(temp4).style.display='block';
chatWindowTemp = document.getElementById(temp4);
chatWindowTemp.scrollTop = chatWindowTemp.scrollHeight;
}



function startPrivate(userName)
{
var temp = 'chatWindow' + userName;
var chatWindowS = document.getElementById(temp);
if (chatWindowS == null) { 
document.getElementById('chatTaskBar').innerHTML += ' <a href="javascript:setRemoteUser(\'' + userName + '\');" class="textSmall" style="" id="chatTaskBar' + userName + '">' + userName + '</a><a href="javascript:hideRemoteUser(\'' + userName + '\');" class="textSmall" style="" id="HidechatTaskBar' + userName + '">X</a>';
document.getElementById('chatWindow').innerHTML += '<div id="chatWindow' + userName + '" style="height: ' + setChatBoxHeight + 'px; width: ' + setChatBoxWidth + '; overflow: auto; display: none;"></div>';
var chatWindowS = document.getElementById(temp);
}
setRemoteUser(userName);
}


//Chat Game Functions and Vars
var userNameOfPlayer = setChatName;
var playWindowOpen = 0;
function setPlayWindowOpen (temp) { playWindowOpen = temp; }
function returnBodyCodes()
{
var theBodyCodes = '';
if (document.getElementById('chatGameBodyType').value == 'M1') { theBodyCodes += 'body_60_150,cock_60_150,'; } else if (document.getElementById('chatGameBodyType').value == 'F1') { theBodyCodes += 'body_60_150,boobs_60_150,'; } else { theBodyCodes += ',,'; }
if (document.getElementById('chatGameBodySocks').value == 'socks') { theBodyCodes += 'socks_60_150,'; } else if (document.getElementById('chatGameBodySocks').value == 'noSocks') { theBodyCodes += ','; } else { theBodyCodes += ','; }
if (document.getElementById('chatGameBodyUnderwear').value == 'boxers') { theBodyCodes += 'boxers_60_150,'; } else if (document.getElementById('chatGameBodyUnderwear').value == 'panty') { theBodyCodes += 'panty_60_150,'; } else if (document.getElementById('chatGameBodyUnderwear').value == 'panty2') { theBodyCodes += 'panty2_60_150,'; } else { theBodyCodes += ','; }
if (document.getElementById('chatGameBodyBra').value == 'bra') { theBodyCodes += 'bra_60_150,'; } else if (document.getElementById('chatGameBodyBra').value == 'bra2') { theBodyCodes += 'bra2_60_150,'; } else { theBodyCodes += ','; }
if (document.getElementById('chatGameBodyUnderShirt').value == 'underShirt') { theBodyCodes += 'underShirt_60_150,'; } else { theBodyCodes += ','; }
if (document.getElementById('chatGameBodyPants').value == 'pants') { theBodyCodes += 'pants_60_150,'; } else if (document.getElementById('chatGameBodyPants').value == 'skirt') { theBodyCodes += 'skirt_60_150,'; } else if (document.getElementById('chatGameBodyPants').value == 'shorts') { theBodyCodes += 'shorts_60_150,'; } else { theBodyCodes += ','; }
if (document.getElementById('chatGameBodyShirt').value == 'shirt1') { theBodyCodes += 'shirt1_60_150,'; } else if (document.getElementById('chatGameBodyShirt').value == 'shirt2') { theBodyCodes += 'shirt2_60_150,'; } else { theBodyCodes += ','; }
if (document.getElementById('chatGameBodyHair').value == 'hair1') { theBodyCodes += 'hair1_60_150,'; } else if (document.getElementById('chatGameBodyHair').value == 'hair2') { theBodyCodes += 'hair2_60_150,'; } else if (document.getElementById('chatGameBodyHair').value == 'hair3') { theBodyCodes += 'hair3_60_150,'; } else if (document.getElementById('chatGameBodyHair').value == 'hair4') { theBodyCodes += 'hair4_60_150,'; } else { theBodyCodes += ','; }

return theBodyCodes;
}
function bodyCodesToHTML(bodyCodes) {
var bodyCodeGood = 0;
var brokenstring = bodyCodes.split(','); 
var bodyCodeHTML = '<div style="position: relative; width: 60px; height: 150px;">';
for (var i=0; i<brokenstring.length; i++) {
var brokenstring2 = brokenstring[i].split('_');
if (brokenstring2[0] != '' && brokenstring2[1] != '') { bodyCodeGood = 1; bodyCodeHTML += '<div style="position: absolute; top: 0px; left: 0px;"><img src="images/chatGame/' + brokenstring2[0] + '_' + brokenstring2[1] + '_' + brokenstring2[2] + '.png"></div>'; }
}//for loop
bodyCodeHTML += '</div>';
if (bodyCodeGood == 1) { return bodyCodeHTML; } else { return null; }
}

//End Chat Game Functions and Vars



function stopChat() {
				clearTimeout(mTimer);
	clearTimeout(mTimerChatLastReload);
}//closes chat connection
			//Function for initializating the page.
			function startChat() {
				//Set the focus to the Message Box.
				document.getElementById('txt_message').focus();
				//Start Recieving Messages.

				getChatText();
				//getChatTextOnline();
                                decLastChatReloadUpdateSeconds();
			}		
			//Gets the browser specific XmlHttpRequest Object
			function getXmlHttpRequestObject() {
				if (window.XMLHttpRequest) {
					return new XMLHttpRequest();
				} else if(window.ActiveXObject) {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} else {
					document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.  Upgrade your freaking browser!';
				}
			}

			//Gets the current messages from the server
			function getChatText() {
				clearTimeout(mTimer);
				if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
					receiveReq.open("GET", 'getChat.php?chat=' + chatroomid + '&name='+ setChatName + '&chatuserid=' + setChatUserId + '&last=' + lastMessage + '&bodyCodes=' + returnBodyCodes(), true);
					receiveReq.onreadystatechange = handleReceiveChat; 
					receiveReq.send(null);
mTimerChatLastReloadSecondsPassing = 62;
				}			
			}
			//Gets the current USERS ONLINE from the server
			function getChatTextOnline() {
				if (receiveReqOnline.readyState == 4 || receiveReqOnline.readyState == 0) {
					receiveReqOnline.open("GET", 'getChatonline.php?chat=' + chatroomid+ '&chatname='+ setChatName + '&chatuserid=' + setChatUserId + '&last=0', true);
					receiveReqOnline.onreadystatechange = handleReceiveChatOnline; 
					receiveReqOnline.send(null);
				}			
			}
			//Add a message to the chat server.
			function sendChatText() {
				if(document.getElementById('txt_message').value == '') {
					alert("You have not entered a message");
					return;
				}
secondsSinceMessageSent = 0; //resets the timer since they are sending a message
//Split the message in to an array and search for Client Side commands
var longstring = document.getElementById('txt_message').value;
var brokenstring=longstring.split(' ');
if (brokenstring[0] == '/nick') { setChatUserName(brokenstring[1]); document.getElementById('txt_message').value = '';
					var chat_div = document.getElementById('div_chat');
						chat_div.innerHTML += '<i><b>Username changed to ' + brokenstring[1] + '</b></i><br />';
						chat_div.scrollTop = chat_div.scrollHeight;
} else if ((brokenstring[0] == '/msg' || brokenstring[0] == '/message') && brokenstring[1]) {
				startPrivate(brokenstring[1]);

 } else {

				if (sendReq.readyState == 4 || sendReq.readyState == 0) {
					sendReq.open("POST", 'getChat.php?chat=' + chatroomid+ '&name='+ setChatName + '&chatuserid=' + setChatUserId + '&last=' + lastMessage, true);
					sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					sendReq.onreadystatechange = handleSendChat; 
var tempReplace = document.getElementById('txt_message').value;
tempReplace = tempReplace.replace(/</gi, "&lt;");
tempReplace = tempReplace.replace(/>/gi, "&gt;");
tempReplace = tempReplace.replace(/&/gi, "-----ampersand-----");

					var param = 'message=' + tempReplace;
					param += '&name='+ setChatName + '&chatuserid=' + setChatUserId;
					param += '&RemoteUsers=' + remoteUser;
					param += '&chat=' + chatroomid;
					sendReq.send(param);
					document.getElementById('txt_message').value = '';
				}							
}//else there is not a client side command.
			}
			function sendChatTextStickName() {
				if(document.getElementById('stickName').value == '') {
					alert("You have not entered a UserName");
					return;
				}
				if (sendReq.readyState == 4 || sendReq.readyState == 0) {
					sendReq.open("POST", 'getChat.php?chat=' + chatroomid + '&last=' + lastMessage, true);
					sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					sendReq.onreadystatechange = handleSendChat; 
					var param = 'message=/stickam+' + document.getElementById('stickName').value;
					param += '&name='+ setChatName + '&chatuserid=' + setChatUserId;
					param += '&RemoteUsers=' + remoteUser;
					param += '&chat=' + chatroomid;
					sendReq.send(param);
					document.getElementById('stickName').value = '';
				}							
			}
			function sendChatTextButton(tempV) {
				if (sendReq.readyState == 4 || sendReq.readyState == 0) {
					sendReq.open("POST", 'getChat.php?chat=' + chatroomid + '&name='+ setChatName + '&last=' + lastMessage, true);
					sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					sendReq.onreadystatechange = handleSendChat; 
					var param = 'message=' + tempV;
					param += '&name='+ setChatName + '&chatuserid=' + setChatUserId;
					param += '&RemoteUsers=' + remoteUser;
					param += '&chat=' + chatroomid;
					sendReq.send(param);
				}							
			}
			//When our message has been sent, update our page.
			function handleSendChat() {
				//Clear out the existing timer so we don't have 
				//multiple timer instances running.
				clearTimeout(mTimer);
				getChatText();
			}
			//Function for handling the return of chat text
			function handleReceiveChat() {
				if (receiveReq.readyState == 4) {
					var chat_div = document.getElementById('div_chat');
					if (document.getElementById('div_stickNames') != null) { var chat_divStick = document.getElementById('div_stickNames'); }
					var xmldoc = receiveReq.responseXML;
					var message_nodes = xmldoc.getElementsByTagName("message"); 
					var n_messages = message_nodes.length
					for (i = 0; i < n_messages; i++) {
						var user_node = message_nodes[i].getElementsByTagName("user");
						var text_node = message_nodes[i].getElementsByTagName("text");
						var time_node = message_nodes[i].getElementsByTagName("time");
						var stick_node = message_nodes[i].getElementsByTagName("stick");
						chat_div.innerHTML += '<b>' + user_node[0].firstChild.nodeValue + '</b>&nbsp;';
						chat_div.innerHTML += '<font class="chat_time">' + time_node[0].firstChild.nodeValue + '</font>&nbsp;-&nbsp;';
						chat_div.innerHTML += replaceURLWithHTMLLinks(text_node[0].firstChild.nodeValue) + '<br />';
						chat_div.scrollTop = chat_div.scrollHeight;
if (message_nodes[i].getElementsByTagName("stick") != null && document.getElementById('div_stickNames') != null) {
if (stick_node[0].firstChild.nodeValue != '0') {
						chat_divStick.innerHTML += stick_node[0].firstChild.nodeValue;
						chat_divStick.scrollTop = chat_divStick.scrollHeight;
}
}
						lastMessage = (message_nodes[i].getAttribute('id'));
				if (remoteUser != '') { document.getElementById('chatTaskBarMain').style.background='red'; }
					}
					//var chat_div = document.getElementById('div_chat');
					var private_nodes = xmldoc.getElementsByTagName("private"); 
					var p_messages = private_nodes.length
					for (i = 0; i < p_messages; i++) {
						var user_node = private_nodes[i].getElementsByTagName("user");
						var text_node = private_nodes[i].getElementsByTagName("text");
						var time_node = private_nodes[i].getElementsByTagName("time");
						var remoteUser_node = private_nodes[i].getElementsByTagName("remoteUser");
var temp = 'chatWindow' + remoteUser_node[0].firstChild.nodeValue;
var chatWindowS = document.getElementById(temp);
if (chatWindowS == null) { 
document.getElementById('chatTaskBar').innerHTML += ' <a href="javascript:setRemoteUser(\'' + remoteUser_node[0].firstChild.nodeValue + '\');" class="textSmall" style="" id="chatTaskBar' + remoteUser_node[0].firstChild.nodeValue + '">' + remoteUser_node[0].firstChild.nodeValue + '</a><a href="javascript:hideRemoteUser(\'' + remoteUser_node[0].firstChild.nodeValue + '\');" class="textSmall" style="" id="HidechatTaskBar' + remoteUser_node[0].firstChild.nodeValue + '">X</a>';
document.getElementById('chatWindow').innerHTML += '<div id="chatWindow' + remoteUser_node[0].firstChild.nodeValue + '" style="height: ' + setChatBoxHeight + 'px; width: ' + setChatBoxWidth + 'px; overflow: auto; display: none;"></div>';
var chatWindowS = document.getElementById(temp);
}
						chatWindowS.innerHTML += '<b>' + user_node[0].firstChild.nodeValue + '</b>&nbsp;';
						chatWindowS.innerHTML += '<font class="chat_time">' + time_node[0].firstChild.nodeValue + '</font>&nbsp;-&nbsp;';
						chatWindowS.innerHTML += replaceURLWithHTMLLinks(text_node[0].firstChild.nodeValue) + '<br />';
						chatWindowS.scrollTop = chatWindowS.scrollHeight;
						lastMessagePrivate = (private_nodes[i].getAttribute('id'));
temp2 = 'chatTaskBar' + remoteUser_node[0].firstChild.nodeValue;
				if (remoteUser != remoteUser_node[0].firstChild.nodeValue) { document.getElementById(temp2).style.background='red'; document.getElementById(temp2).style.display=''; 
                                     temp2 = 'HidechatTaskBar' + remoteUser_node[0].firstChild.nodeValue;
                                     document.getElementById(temp2).style.display='';
                                }

if (lastMessagePrivate > lastMessage) { lastMessage = lastMessagePrivate; }
					}

					if (lastMessage > lastNewMessage) {
						lastNewMessage = lastMessage;
						//make innerhtml somewhere the sound byte if sounds are checked
						if (document.getElementById('soundsOnOffJS').value == 1) {
							document.getElementById('div_chat_events').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0" id="Movie1" width="1" height="1"><param name="movie" value="flash/Ting.swf"><param name="quality" value="high"><param name="bgcolor" value="#CC0000"><embed name="Movie1" src="flash/Ting.swf" quality="high" bgcolor="#CC0000" width="1" height="1" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>';
						}
						else if (document.getElementById('soundsOnOffJS').value == 2) {
							document.getElementById('div_chat_events').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0" id="Movie1" width="1" height="1"><param name="movie" value="flash/Ting2.swf"><param name="quality" value="high"><param name="bgcolor" value="#CC0000"><embed name="Movie1" src="flash/Ting2.swf" quality="high" bgcolor="#CC0000" width="1" height="1" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>';
						}
						else if (document.getElementById('soundsOnOffJS').value == 3) {
							document.getElementById('div_chat_events').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0" id="Movie1" width="1" height="1"><param name="movie" value="flash/Ting3.swf"><param name="quality" value="high"><param name="bgcolor" value="#CC0000"><embed name="Movie1" src="flash/Ting3.swf" quality="high" bgcolor="#CC0000" width="1" height="1" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>';
						} else {
							//do nothing
						}
					
		
					}


                                        var chat_divonline = document.getElementById('div_chatonline');
					var xmldoconline = receiveReq.responseXML;
					var message_nodesonline = xmldoconline.getElementsByTagName("onlineUser"); 
					var n_messagesonline = message_nodesonline.length
var tempDCO = '<div>' + n_messagesonline + ' Users</div>';
var tempCGPA = '';
updateChatRefreshRateBasedOnUserCount(n_messagesonline); //Updates the chat refresh rate based on the amount of users in the chat.
					for (i = 0; i < n_messagesonline; i++) {
						var user_nodeonline = message_nodesonline[i].getElementsByTagName("user");
						var text_nodeonline = message_nodesonline[i].getElementsByTagName("text");
						var time_nodeonline = message_nodesonline[i].getElementsByTagName("time");
						var profile_nodeonline = message_nodesonline[i].getElementsByTagName("profile");
						var bodyCodes_nodeonline = message_nodesonline[i].getElementsByTagName("bodyCodes");
						var userPoints_nodeonline = message_nodesonline[i].getElementsByTagName("userPoints");
						tempDCO += '<div><table width="98%" cellpadding="0" cellspacing="0" border="0"><tr><td width="16">';
						if (text_nodeonline[0].firstChild.nodeValue == 1) { 

//Split the profile in to an array and search for moderator or admin status
var longstring1 = profile_nodeonline[0].firstChild.nodeValue;
var brokenstring1=longstring1.split('<b>');
if (brokenstring1[1]) {
var longstring2 = brokenstring1[1];
var brokenstring2=longstring2.split('</b>');
if (brokenstring2) {
if (brokenstring2[0] == 'Admin') { tempDCO += '<img src="http://www.360pal.com/images/fam/award_star_gold_1.png" width="16" height="16" align="left" title="Admin - Available">'; }
else if (brokenstring2[0] == 'Moderator') { tempDCO += '<img src="http://www.360pal.com/images/fam/award_star_gold_2.png" width="16" height="16" align="left" title="Moderator - Available">'; }
else if (brokenstring2[0] == 'Kicked') { tempDCO += '<img src="http://www.360pal.com/images/fam/cancel.png" width="16" height="16" align="left" title="Kicked - they cannot see the chat">'; }
else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_online.png" width="16" height="16" align="left" title="Available">'; }
} else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_online.png" width="16" height="16" align="left" title="Available">'; }
} else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_online.png" width="16" height="16" align="left" title="Available">'; }

//tempDCO += '<img src="http://www.360pal.com/images/fam/status_online.png" width="16" height="16" align="left" title="Available">';
 }
						else if (text_nodeonline[0].firstChild.nodeValue == 2) { 
//Split the profile in to an array and search for moderator or admin status
var longstring1 = profile_nodeonline[0].firstChild.nodeValue;
var brokenstring1=longstring1.split('<b>');
if (brokenstring1[1]) {
var longstring2 = brokenstring1[1];
var brokenstring2=longstring2.split('</b>');
if (brokenstring2) {
if (brokenstring2[0] == 'Admin') { tempDCO += '<img src="http://www.360pal.com/images/fam/award_star_bronze_1.png" width="16" height="16" align="left" title="Admin - Away">'; }
else if (brokenstring2[0] == 'Moderator') { tempDCO += '<img src="http://www.360pal.com/images/fam/award_star_bronze_2.png" width="16" height="16" align="left" title="Moderator - Away">'; }
else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_away.png" width="16" height="16" align="left" title="Away">'; }
} else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_away.png" width="16" height="16" align="left" title="Away">'; }
} else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_away.png" width="16" height="16" align="left" title="Away">'; }

//tempDCO += '<img src="http://www.360pal.com/images/fam/status_away.png" width="16" height="16" align="left" title="Away">'; 
}
						else if (text_nodeonline[0].firstChild.nodeValue == 3) { 

//Split the profile in to an array and search for moderator or admin status
var longstring1 = profile_nodeonline[0].firstChild.nodeValue;
var brokenstring1=longstring1.split('<b>');
if (brokenstring1[1]) {
var longstring2 = brokenstring1[1];
var brokenstring2=longstring2.split('</b>');
if (brokenstring2) {
if (brokenstring2[0] == 'Admin') { tempDCO += '<img src="http://www.360pal.com/images/fam/award_star_silver_1.png" width="16" height="16" align="left" title="Admin - Offline">'; }
else if (brokenstring2[0] == 'Moderator') { tempDCO += '<img src="http://www.360pal.com/images/fam/award_star_silver_2.png" width="16" height="16" align="left" title="Moderator - Offline">'; }
else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_offline.png" width="16" height="16" align="left" title="Offline">'; }
} else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_offline.png" width="16" height="16" align="left" title="Offline">'; }
} else { tempDCO += '<img src="http://www.360pal.com/images/fam/status_offline.png" width="16" height="16" align="left" title="Offline">'; }
//tempDCO += '<img src="http://www.360pal.com/images/fam/status_offline.png" width="16" height="16" align="left" title="Offline">'; 
}
						else if (text_nodeonline[0].firstChild.nodeValue == 4) { tempDCO += '<img src="http://www.360pal.com/images/fam/joystick.png" width="16" height="16" align="left" title="Playing">'; }

						tempDCO += '</td><td style="overflow: hidden;">';
var tempName = user_nodeonline[0].firstChild.nodeValue;
var tempNameLastCharIndex = tempName.length - 1;
if (tempName.charAt(tempNameLastCharIndex) != '*') {
						tempDCO += '<a href="http://truthordarepal.com/user.php?username=' + user_nodeonline[0].firstChild.nodeValue + '" target="_blank">';
}//if not a guest
						tempDCO += '<span ONMOUSEOVER="popupProfile(\'' + profile_nodeonline[0].firstChild.nodeValue + '<br />' + userPoints_nodeonline[0].firstChild.nodeValue + ' Points';
						if (text_nodeonline[0].firstChild.nodeValue == 2) { tempDCO += '<br /><b>Away from Chat</b>'; }
						tempDCO += '\',\'ffffff\')"; ONMOUSEOUT="kill()"><b>' + user_nodeonline[0].firstChild.nodeValue + '</b></span>';
if (tempName.charAt(tempNameLastCharIndex) != '*') {
						tempDCO += '</a>';
}//if not a guest
						tempDCO += '</td><td align="right"><a href="javascript:sendChatTextButton(\'/givePoints ' + user_nodeonline[0].firstChild.nodeValue + '\');"><img src="http://www.360pal.com/images/fam/coins_add.png" border="0" alt="Give User a Point" title="Give this user a Point" /></a><a href="javascript:startPrivate(\'' + user_nodeonline[0].firstChild.nodeValue + '\');"><img src="http://www.360pal.com/images/fam/comment_add.png" border="0" alt="Instant Message this User" title="Instant Message this User" /></a></td></tr></table></div>';
						//chat_divonline.scrollTop = chat_divonline.scrollHeight;
						lastMessageOnline = (message_nodesonline[i].getAttribute('id'));

if (text_nodeonline[0].firstChild.nodeValue == 4) {
//Player Building
if (tempCGPA == '') { tempCGPA = '<table><tr>'; }
tempCGPA += '<td>' + bodyCodesToHTML(bodyCodes_nodeonline[0].firstChild.nodeValue) + '<div style="width: 60px; text-align: center; font-size: 8pt;">'+ user_nodeonline[0].firstChild.nodeValue + '</div><div style="width: 60px; text-align: center; font-size: 7pt;">'+ userPoints_nodeonline[0].firstChild.nodeValue + ' <img src="http://www.360pal.com/images/fam/coins.png" width="7" height="7" border="0" alt="Points" title="Points"></div></td>';
//End PLayer Building
}//end if user is playing
					} //for loop
//Update chatGame if not blank
if (tempCGPA != '') { tempCGPA += '</tr></table>'; } else { tempCGPA = 'No one is playing'; } setGameSpace('chatGamePlayerArea',tempCGPA);

//take the temporary holder and use setGameSpace(space,code) to update the div_chatonline field
setGameSpace('div_chatonline',tempDCO);



					mTimer = setTimeout('getChatText();',chatRefreshRate); //Refresh our chat in chatRefreshRate milli seconds
mTimerOnlineMod++;

				}
			}
			//Function for handling the return of chat USERS ONLINE text
			function handleReceiveChatOnline() {
				if (receiveReqOnline.readyState == 4) {
					//document.getElementById('div_chatonline').innerHTML = '';
                                        var chat_divonline = document.getElementById('div_chatonline');
					var xmldoconline = receiveReqOnline.responseXML;

					var message_nodesonline = xmldoconline.getElementsByTagName("message"); 
					var n_messagesonline = message_nodesonline.length
var tempDCO = '';
					for (i = 0; i < n_messagesonline; i++) {
						var user_nodeonline = message_nodesonline[i].getElementsByTagName("user");
						var text_nodeonline = message_nodesonline[i].getElementsByTagName("text");
						var time_nodeonline = message_nodesonline[i].getElementsByTagName("time");
						var profile_nodeonline = message_nodesonline[i].getElementsByTagName("profile");
//						if (text_nodeonline[0].firstChild.nodeValue == 1) { chat_divonline.innerHTML += '<img src="images/chat/userstatus_' + text_nodeonline[0].firstChild.nodeValue + '.gif" width="7" height="7" align="left" title="Available">'; }

//						else if (text_nodeonline[0].firstChild.nodeValue == 2) { chat_divonline.innerHTML += '<img src="images/chat/userstatus_' + text_nodeonline[0].firstChild.nodeValue + '.gif" width="7" height="7" align="left" title="Away">'; }
//						else if (text_nodeonline[0].firstChild.nodeValue == 3) { chat_divonline.innerHTML += '<img src="images/chat/userstatus_' + text_nodeonline[0].firstChild.nodeValue + '.gif" width="7" height="7" align="left" title="Offline">'; }
//						else if (text_nodeonline[0].firstChild.nodeValue == 4) { chat_divonline.innerHTML += '<img src="images/chat/userstatus_' + text_nodeonline[0].firstChild.nodeValue + '.gif" width="7" height="7" align="left" title="Playing">'; }

//						chat_divonline.innerHTML += '<a href="http://truthordarepal.com?' + user_nodeonline[0].firstChild.nodeValue + '" target="_blank" ONMOUSEOVER="popupProfile(\'' + profile_nodeonline[0].firstChild.nodeValue + '\',\'ffffff\')"; ONMOUSEOUT="kill()"><b>' + user_nodeonline[0].firstChild.nodeValue + '</b></a><a href="javascript:startPrivate(\'' + user_nodeonline[0].firstChild.nodeValue + '\');">(PM)</a><br>';
						// chat_divonline.innerHTML += '<font class="chat_time">' + time_nodeonline[0].firstChild.nodeValue + '</font>&nbsp;-&nbsp;';
//						// chat_divonline.innerHTML += text_nodeonline[0].firstChild.nodeValue + '<br>';
//						chat_divonline.scrollTop = chat_divonline.scrollHeight;
//						lastMessageOnline = (message_nodesonline[i].getAttribute('id'));
						if (text_nodeonline[0].firstChild.nodeValue == 1) { tempDCO += '<img src="images/chat/userstatus_' + text_nodeonline[0].firstChild.nodeValue + '.gif" width="7" height="7" align="left" title="Available">'; }
						else if (text_nodeonline[0].firstChild.nodeValue == 2) { tempDCO += '<img src="images/chat/userstatus_' + text_nodeonline[0].firstChild.nodeValue + '.gif" width="7" height="7" align="left" title="Away">'; }
						else if (text_nodeonline[0].firstChild.nodeValue == 3) { tempDCO += '<img src="images/chat/userstatus_' + text_nodeonline[0].firstChild.nodeValue + '.gif" width="7" height="7" align="left" title="Offline">'; }
						else if (text_nodeonline[0].firstChild.nodeValue == 4) { tempDCO += '<img src="images/chat/userstatus_' + text_nodeonline[0].firstChild.nodeValue + '.gif" width="7" height="7" align="left" title="Playing">'; }

						tempDCO += '<a href="http://www.360pal.com/user.php?username=' + user_nodeonline[0].firstChild.nodeValue + '" target="_blank" ONMOUSEOVER="popupProfile(\'' + profile_nodeonline[0].firstChild.nodeValue + '\',\'ffffff\')"; ONMOUSEOUT="kill()"><b>' + user_nodeonline[0].firstChild.nodeValue + '</b></a><a href="javascript:startPrivate(\'' + user_nodeonline[0].firstChild.nodeValue + '\');">(PM)</a><br>';
						// chat_divonline.innerHTML += '<font class="chat_time">' + time_nodeonline[0].firstChild.nodeValue + '</font>&nbsp;-&nbsp;';
						// chat_divonline.innerHTML += text_nodeonline[0].firstChild.nodeValue + '<br>';
						chat_divonline.scrollTop = chat_divonline.scrollHeight;
						lastMessageOnline = (message_nodesonline[i].getAttribute('id'));
					}
//take the temporary holder and use setGameSpace(space,code) to update the div_chatonline field
setGameSpace('div_chatonline',tempDCO);
					//mTimerOnline = setTimeout('getChatTextOnline();',9500); //Refresh our chat user list in 9.5 seconds
				}
			}
			//This functions handles when the user presses enter.  Instead of submitting the form, we
			//send a new message to the server and return false.
			function blockSubmit() {
				sendChatText();
				return false;
			}
			//This cleans out the database so we can start a new chat session.

			function resetChat() {
				if (sendReq.readyState == 4 || sendReq.readyState == 0) {
					sendReq.open("POST", 'getChat.php?chat=' + chatroomid + '&last=' + lastMessage, true);
					sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					sendReq.onreadystatechange = handleResetChat; 
					var param = 'action=reset';
					sendReq.send(param);
					document.getElementById('txt_message').value = '';
				}							
			}
			//This function handles the response after the page has been refreshed.
			function handleResetChat() {
				document.getElementById('div_chat').innerHTML = '';
				getChatText();
			}	



function replaceURLWithHTMLLinks(text) {
  var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  return text.replace(exp,"<a href='$1' target='_blank'>$1</a>"); 
}

