			var sendReq = getXmlHttpRequestObject();
			var receiveReq = getXmlHttpRequestObject();
			var lastMessage = 0;
			var mTimer;
			var lastUpdateTime;
			//Function for initializating the page.
			function startChat() {
				//Set the focus to the Message Box.
                if (document.getElementById('txt_message')) {
                    document.getElementById('txt_message').focus();
                }
				//Start Recieving Messages.
				getChatText();
			}		
			//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: Incompatible browser, consider upgrading your browser.';
                    alert('no xmlhttp');
				}
			}
			
			//Gets the current messages from the server
			function getChatText() {
				if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
					receiveReq.open("GET", 'getChat.php?last=' + lastMessage, true);
					receiveReq.onreadystatechange = handleReceiveChat; 
					receiveReq.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;
				}
				if (sendReq.readyState == 4 || sendReq.readyState == 0) {
					sendReq.open("POST", 'getChat.php?last=' + lastMessage, true);
					sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
					sendReq.onreadystatechange = handleSendChat; 
					var param = 'message=' + encodeURIComponent(document.getElementById('txt_message').value);
					sendReq.send(param);
					document.getElementById('txt_message').value = '';
				}							
			}
			//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.
				clearInterval(mTimer);
				getChatText();
			}
			function getLocalTimeString(ts) {
				var offset    = new Date().getTimezoneOffset() * 60000;
                var localTime = new Date(ts) - offset;
                var lt        = new Date(localTime);
                //var ltstring  = lt.getFullYear() + '/';
                var ltstring  = (lt.getMonth() < 11 ? '0' : '') + (lt.getMonth() + 1) + '/';
                ltstring     += (lt.getDate() < 10 ? '0' : '') + lt.getDate() + '@';
                ltstring     += ((lt.getHours() % 12 || 12) < 10 ? '0' : '') + (lt.getHours() % 12 || 12) + ':';
                ltstring     += (lt.getMinutes() < 10 ? '0' : '') + lt.getMinutes() + ':';
                //ltstring     += (lt.getSeconds() < 10 ? '0' : '') + lt.getSeconds() + ' ';
                ltstring     += (lt.getSeconds() < 10 ? '0' : '') + lt.getSeconds();
                //ltstring     += (lt.getHours() < 12 ? 'AM' : 'PM') + ' ';
                ltstring     += (lt.getHours() < 12 ? 'AM' : 'PM');
                //ltstring     += 'GMT' + (lt.getTimezoneOffset() < 0 ? '+' : '') + (-lt.getTimezoneOffset() / 60);
                return ltstring;
			}
			function handleReceiveChat() {
				if (receiveReq.readyState == 4) {
					//Get a reference to our chat container div for easy access
					var chat_div = document.getElementById('div_chat');
					//Get the AJAX response and run the JavaScript evaluation function
					//on it to turn it into a useable object.  Notice since we are passing
					//in the JSON value as a string we need to wrap it in parentheses
					var response = eval("(" + receiveReq.responseText + ")");
					if (response.msg.length > 0) {
						//lastUpdateTime = new Date(response.msg[i].time) - new Date().getTimeZoneOffset();
						document.getElementById('p_status').innerHTML = 'Status: Updating';
					}
					for (i = 0; i < response.msg.length; i++) {
						chat_div.innerHTML += '<font class="chat_time">' + getLocalTimeString(response.msg[i].time) + '</font>&nbsp;&nbsp;&nbsp;';
                        if (response.msg[i].text == 'System Normal') {
                            chat_div.innerHTML += '<font class="chat_time">' + response.msg[i].text + '</font><br />';
                        }
                        else {
						    chat_div.innerHTML += response.msg[i].text + '<br />';
                        }
						chat_div.scrollTop = chat_div.scrollHeight;
						lastMessage = response.msg[i].id;
					}
					mTimer = setTimeout('getChatText();',1500); //Refresh our chat in 2 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() {
				document.getElementById('txt_message').value = '';
				document.getElementById('div_chat').innerHTML = '';
				//if (sendReq.readyState == 4 || sendReq.readyState == 0) {
					//sendReq.open("POST", 'getChat.php?chat=1&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();
			//}	
