	
	var sendReq = getXmlHttpRequestObject();
	var receiveReq = getXmlHttpRequestObject();
			var lastMessage = 0;
			var mTimer;
			
			var xmldata;
			
			//store data from flex
			
			function savexml(data)
			{
				//alert("calling javascript");
				xmldata=data;
				//alert("xmlis"+xmldata);
				sendChatText();
			}
			
			
			
			//Function for initializating the page.
			function startChat() {

				alert("app started");
				//Set the focus to the Message Box.
				//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");
				} 
			}
			
			//Gets the current messages from the server
			function getChatText() {
				if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
  				{

					
					receiveReq.open("GET", 'getChat.php?chat=1&last=' + lastMessage, true);
					receiveReq.onreadystatechange = handleReceiveChat; 
					receiveReq.send(null);
				}			
			}


			//Add a message to the chat server.
			function sendChatText()
				 {
				
				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 = handleSendChat; 
				
					var param = 'message=' + xmldata;
				
					param += '&name=bala';
					param += '&chat=1';
					sendReq.send(param);
					//alert("sent message="+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.
				clearInterval(mTimer);
			      getChatText();
			}


			//Function for handling the return of chat text
			function handleReceiveChat() {
			
				if (receiveReq.readyState == 4) {
				
					var xmldoc = receiveReq.responseXML;
					var message_nodes = xmldoc.getElementsByTagName("message"); 
					var n_messages = message_nodes.length;
							
					  for (i = 0; i < n_messages; i++) 
					   {
						
						var text_node = message_nodes[i].getElementsByTagName("text");
						//alert("From server="+text_node[0].firstChild.nodeValue);
						lastMessage = (message_nodes[i].getAttribute('id'));
					//	collpaint.rectinjs(text_node[0].firstChild.nodeValue);	
					collpaint.rectinjs(text_node[0].firstChild.nodeValue);			
					   }
					
					mTimer = setTimeout('getChatText();',800); //Refresh our chat in 2 seconds
				}
			}
			
		/*	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=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();
			}	*/
	