function setOnlineMark(http_host, port_id, url) {
        var req = new XMLHttpRequest();
        if (req) {
                req.onreadystatechange = function() {
                        if (req.readyState == 4 ) { //for local
                                var result = eval('(' + req.responseText + ')');
                                var success = result.success;
                                var room_id = result.room_id;
                                var chatter = result.chatter;
                                ///////////////////////////////////
				// DEAL WITH CHAT
				//
				///////////////////////////////////
                                if (room_id > 0 &&
                                	chatter.length > 0) {                                	
                                	
					//var answer = confirm("Accept Chat Invitation from \"" + chatter + "\"?")        					
					//if (answer){
					//	//alert("chat it up!")
					//	//window.open('http://<?php print $_SERVER["HTTP_HOST"]; ?>/new/s3/s3UserChatAccept.php?rid=' + room_id + '&pid2=' + port_id, 'w_chat','menubar=no,width=602,height=414,toolbar=no,location=no');
					//	//var newWin = window.open ('titlepage.html', 'newwindow', config='height=100,width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no')
					//	//if (newWin && newWin.top) {
					//	//	// popup has opened
					//	//	alert('open');
					//	//} else {
					//	//	alert('blocked');
					//	//	// popup has been blocked
					//	//}
					//	creatediv("yo", "hello", 300, 300, 300, 300);
					//} else {
					//	alert("You are a hider!")
					//}					
					var s_div_html = '<table align="left" height="20" width="770" cellspacing="0" cellpadding="0" border="0" style="background: #ffcc00; border: solid 1px #333; font: 11px verdana;">';
					s_div_html += '<tr><td align="left" width="400" style="padding-left: 10px;">';
					s_div_html += 'Would you like to accept a chat invitation from ' + chatter + '?</td><td width="40"></td><td align="left"><input type="button" onclick="window.open(\'http://' + http_host + '/new/s3/s3UserChatAccept.php?rid=' + room_id + '&u=' + chatter + '\', \'chat_' + room_id + '\',\'scrollbars=no,resizeable=no,menubar=no,width=602,height=440,toolbar=no,location=no\'); chatAccept(' + room_id + ', ' + port_id + ', \'' + http_host + '\', 1);" value="ACCEPT" style="border: solid 1px #333; width: 100px;">&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" onclick="chatAccept(' + room_id + ', ' + port_id + ', \'' + http_host + '\', 0);" value="DENY" style="border: solid 1px #333; width: 100px;"></td></tr></table>';
					if (!document.getElementById("invite_" + room_id)) {						
						creatediv("invite_" + room_id, s_div_html, 770, 20, 120, 0);
						alert("You have received a chat invitation from: " + chatter + ".\nTo accept, please press the ACCEPT button on the top of your screen.");
						window.focus();
					}
                                }
                                ///////////////////////////////////
				///////////////////////////////////
                        }
                }

                var parameters = 'port_id=' + port_id + '&url=' + escape(url);
                req.open('POST', 'http://' + http_host + '/new/s3/ws/online.php', true);
                req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                req.setRequestHeader("Content-length", parameters.length);
                req.setRequestHeader("Connection", "close");
                req.send(parameters);
        }
        setTimeout(function() {
		setOnlineMark(http_host, port_id, url);
	//}, 60000);
	}, 6000);
	
}

function chatAccept(room_id, port_id, http_host, i_accept) {
	var req = new XMLHttpRequest();
        if (req) {
                req.onreadystatechange = function() {
                        if (req.readyState == 4 ) { //for local
                                var result = eval('(' + req.responseText + ')');
                                var success = result.success;
                                ///////////////////////////////////
				// DEAL WITH ACCEPT RETURN
				//
				///////////////////////////////////

                                ///////////////////////////////////
				///////////////////////////////////
                        }
                }

                var parameters = 'room_id=' + room_id + '&port_id=' + port_id;
                req.open('POST', 'http://' + http_host + '/new/s3/ws/chatAccept.php', true);
                req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                req.setRequestHeader("Content-length", parameters.length);
                req.setRequestHeader("Connection", "close");
                req.send(parameters);
        }
        
	document.getElementById("invite_" + room_id).style.visibility = 'hidden';
	//if (i_accept == 1) {
	//	window.open('http://' + http_host + '/new/s3/s3UserChatAccept.php?rid=' + room_id, 'w_chat','menubar=no,width=602,height=414,toolbar=no,location=no');
	//}
}
	

function creatediv(id, html, i_width, i_height, i_left, i_top) {
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', id);
	newdiv.style.width = i_width;
	newdiv.style.height = i_height;
	newdiv.style.left = i_left;
	newdiv.style.top = i_top;
	newdiv.style.position = "absolute";   	
	newdiv.style.background = "#fff";
	newdiv.style.border = "0px solid #333";
	newdiv.innerHTML = html;	
	document.body.appendChild(newdiv);
} 