// array with usersvar update1chat_users = new Array();// last message id that has been displayedvar update1chat_last_msgid = fetch_cookie('update1chat_last_msgid');update1chat_last_msgid = parseInt(update1chat_last_msgid) > 0 ? parseInt(update1chat_last_msgid) : 0;// whether can update the text "...has entered..."// when array with users is being re-created, we should stop text updatevar update1chat_can_text = true;// ajax instancevar ajax_update1chat = create_request_object();// functionsfunction update_anytime_chat(){	ajax_update1chat.open('get', gvar.sub_dir +'/ajax/update_anytime_chat.php');	ajax_update1chat.onreadystatechange = update_anytime_chat_response;	ajax_update1chat.send(null);	// run itself every 3 seconds = refresh anytime chatter regularly	// oops, not anymore...    //setTimeout('update_anytime_chat()', 3000);}function update_anytime_chat_response(){	if (ajax_update1chat.readyState == 4) {		var response = ajax_update1chat.responseText;		var str_response = String(response);		// compare against []		if (str_response.length <= 2) {			return false;		}		var users = JSON.parse(response);		// add users (if any)		if (users.length) {			var cu;			// set flag to "stop text update". reason: these functions might be run simultaneously			update1chat_can_text = false;						// process objects			for (var ic = 0; ic < users.length; ic++) {				// check				if (typeof(users[ic].user_id) == 'undefined' || typeof(users[ic].username) == 'undefined' || typeof(users[ic].user_img) == 'undefined' || typeof(users[ic].channel) == 'undefined' || typeof(users[ic].msg_id) == 'undefined' || typeof(users[ic].msg_date) == 'undefined') {					continue;				}				// remove this user from the global users array				for (var j = 0; j < update1chat_users.length; j++) {					// ...so, the last entered user has the maximum array offset					if (update1chat_users[j]['user_id'] == users[ic].user_id) {						// found it. remove 1 element						update1chat_users.splice(j, 1);					}				}				// next available offset				cu = update1chat_users.length;				update1chat_users[cu] = new Array();				// fill-in global users array				update1chat_users[cu]['user_id'] = users[ic].user_id;				update1chat_users[cu]['username'] = users[ic].username;				update1chat_users[cu]['user_img'] = users[ic].user_img;				update1chat_users[cu]['channel'] = users[ic].channel;				update1chat_users[cu]['msg_id'] = users[ic].msg_id;				update1chat_users[cu]['msg_date'] = users[ic].msg_date;			}						// have to sort it			update1chat_users = sort_2d_array(update1chat_users, 'msg_id', 'desc');						// users array re-created. set flag back to "can update text"			update1chat_can_text = true;						// run update text			update_anytime_chat_text();		}	}}function update_anytime_chat_text(){	// check whether users array is in process of re-creating	// if so, wait for the function above to call us	if (!update1chat_can_text) {		return true;	}	// check div for existence	if (!document.getElementById) {		return false;	}	var div_id = document.getElementById('update_anytime_chat');	if (!div_id) {		return false;	}	// look for the first user that we could display	// begin looking from the last one, as first user is the latest entered	for (var ic = update1chat_users.length - 1; ic >= 0; ic--) {		// we should not display the same user twice, so only display who has entered after(!) latest displayed user		if (parseInt(update1chat_users[ic]['msg_id']) > update1chat_last_msgid) {			// retrieve data from the global users array			var username = update1chat_users[ic]['username'];			var user_img = String(update1chat_users[ic]['user_img']);			// update message			var msg = (user_img.length > 1 ? ''+				'<div class="ua_chat_image_wrapper"><div class="ua_chat_img_div"><img src="'+ user_img +'" class="ua_chat_image" /></div></div>' : '') +				'<div style="cursor:pointer;" onclick="document.location=\'./chat.php?room=1\'"><div class="ua_chat_bg_left"></div>'+				'<div class="ua_chat_bg">Join <span class="ua_chat_username">'+ username +'</span> in Anytime Chat</div>'+				'<div class="ua_chat_bg_right"></div><div class="clear_both"></div></div>';			div_id.innerHTML = msg;						// re-set global last_msgid			update1chat_last_msgid = parseInt(update1chat_users[ic]['msg_id']);			// and save it in cookies, so if user clicks another page, session is not loosed			set_cookie('update1chat_last_msgid', update1chat_last_msgid, false, false, false);						// run again if there are more persons to display 			if (ic > 0) {				// ...so we attempt to show them all before next ajax call				setTimeout('update_anytime_chat_text()', 4000);			}						// stop loop right now			return true;		}	}		// the winner is not found	return false;}//update in: 4 secondssetTimeout('update_anytime_chat()', 4000);//...64 secondssetTimeout('update_anytime_chat()', 64000);//...124 secondssetTimeout('update_anytime_chat()', 124000);//...184 secondssetTimeout('update_anytime_chat()', 184000);