/** * AjaxUtil.js 2005/11/12 * * Author lauri.lehtinen@finaldimension.net * Version 2006.08.12 */ function makeRequest(url, requestType) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); // See note below about this line } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { return false; } if (requestType == "ONLINE_STATUS") { http_request.onreadystatechange = updateOnlineStatus; } else if (requestType == "FD_FACES") { //alert("FD_FACES"); //http_request.onreadystatechange = null; } else { http_request.onreadystatechange = requestType; } http_request.open('GET', url, true); http_request.send(null); } function ajaxGet(url, callback) { if (url.indexOf('finaldimension.net') == -1) { var host = (document.URL.toString().indexOf('www.') > -1) ? 'http://www.finaldimension.net' : 'http://finaldimension.net'; url = host + url; } var httpRequest = getHttpRequest(); if (callback != null) { httpRequest.onreadystatechange = callback; } httpRequest.open('GET', url, true); try { httpRequest.overrideMimeType('text/xml'); } catch (ex) {} httpRequest.send(null); } function ajaxPost(url, data, callback) { var httpRequest = getHttpRequest(); if (callback != null) { httpRequest.onreadystatechange = callback; } httpRequest.open('POST', url, true); httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1"); httpRequest.send(data); } function getHttpRequest() { httpRequest = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... httpRequest = new XMLHttpRequest(); if (httpRequest.overrideMimeType) { httpRequest.overrideMimeType('text/plain'); // See note below about this line } } else if (window.ActiveXObject) { // IE try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!httpRequest) { return false; } else { return httpRequest; } } function unfmt(str) { str = str.replace("å", "?"); str = str.replace("ä", "?"); str = str.replace("ö", "?"); return str; } function deleteMessage(msgId) { var rows = document.getElementsByTagName('tr'); var lastId = ''; for (i = 0; i < rows.length; i++) { if (rows[i].getAttribute('name') != 'message_row') { continue; } lastId = rows[i].getAttribute('id'); } var row = document.getElementById(msgId); if (row) { row.parentNode.removeChild(row); } var host = (document.URL.toString().indexOf('www.') > -1) ? 'www.finaldimension.net' : 'finaldimension.net'; var url = 'http://' + host + '/ajax/delete_message_ajax.php?' + 'id=' + msgId + '&lastId=' + lastId; ajaxGet(url, updateOnlineMessages); var rows = getElementsByName_iefix('tr', 'message_row'); for (i = 0; i < rows.length; i++) { rows[i].style.backgroundColor = (i % 2 == 0) ? '#e3edf9' : '#c4dffd'; } } function getElementsByName_iefix(tag, name) { var elem = document.getElementsByTagName(tag); var arr = new Array(); for(i = 0,iarr = 0; i < elem.length; i++) { att = elem[i].getAttribute("name"); if(att == name) { arr[iarr] = elem[i]; iarr++; } } return arr; } function updateOnlineMessages() { if (httpRequest.readyState < 4 || httpRequest.status != 200) return; if (httpRequest.responseText == 'error') return; var resp = unescape(httpRequest.responseText); if (!window.event) { // doesn't work with IE document.getElementById('message_table').innerHTML += resp; } window.scrollTo(0, 2000); } function updateOnlineStatus() { if (http_request.readyState < 4 || http_request.status != 200) return; //alert(http_request.responseText); _xmlDoc = http_request.responseXML; //alert(_xmlDoc); _onlineStatus = _xmlDoc.getElementsByTagName("onlineStatus").item(0); //alert(_onlineStatus); // used to exclude the user him/herself from the online msg recipient list _selfNick = unescape(_onlineStatus.attributes[1].value); if (_selfNick != "") { // _selfNick == "" if user is not logged in // online messages _unreadOnlineMsgs = _onlineStatus.attributes[3].value; var currentTitle = document.title; if ((index = currentTitle.indexOf(') ')) > 0) { currentTitle = currentTitle.substr(index + 2); } if (_unreadOnlineMsgs > 0) { document.title = '(' + _unreadOnlineMsgs + ') ' + currentTitle; } else { document.title = currentTitle; } if (_unreadOnlineMsgs < 1) { _unreadOnlineMsgsText = 'No new messages'; } else { _unreadOnlineMsgsText = 'You have {0} new message(s)'.replace('{0}', _unreadOnlineMsgs); } } // hits _hits = _onlineStatus.attributes[2].value + ' hits'; _hitsToday = _onlineStatus.attributes[4].value; _hitsThisWeek = _onlineStatus.attributes[5].value; _hitsThisMonth = _onlineStatus.attributes[6].value; _hitsThisYear = _onlineStatus.attributes[7].value; // member count & hyperlinked nicks _onlineUserCount = _onlineStatus.attributes[0].value; _members = _xmlDoc.getElementsByTagName("onlineUser"); _select = document.getElementById("onlineMsgReceivers"); // update online user count _onlineUserCountHTML = ""; if (_onlineUserCount == 0) { _onlineUserCountHTML = 'No users online'; } else if (_onlineUserCount == 1) { _onlineUserCountHTML = '1 user online'; } else { _onlineUserCountHTML = '{0} users online'.replace('{0}', _onlineUserCount); } _onlineUserCountSpan = document.getElementById("onlineUserCount"); _onlineUserCountSpan.innerHTML = _onlineUserCountHTML; // create new online users
';
}
if (_don >= 20) {
_a.innerHTML = '' + _a.innerHTML + '';
}
_acronym.appendChild(_a);
_onlineUsers.appendChild(_acronym);
} else {
_acronym.appendChild(document.createTextNode(_nick));
_a.appendChild(_acronym);
if (_don >= 10) {
_a.innerHTML += '
';
}
if (_don >= 20) {
_a.innerHTML = '' + _a.innerHTML + '';
}
_onlineUsers.appendChild(_a);
}*/
_a.onmouseover = function() { mpOn(this); };
_a.onmouseout = function() { mpOff(); };
_a.onclick = function() { removeMpNow(); };
_a.appendChild(document.createTextNode(_nick));
if (_don >= 10) {
_a.innerHTML += '
';
}
if (_don >= 20) {
_a.innerHTML = '' + _a.innerHTML + '';
}
_onlineUsers.appendChild(_a);
if (i < _members.length - 1) {
// separate user names with comma
_onlineUsers.appendChild(document.createTextNode(", "));
}
if (false) { // never do this
_option = document.createElement("option");
_option.value = _nick;
_option.appendChild(document.createTextNode(_nick));
_select.appendChild(_option);
}
}
// replace old one with new one
_oldOnlineUsers = document.getElementById("onlineUsers");
_oldParent = _oldOnlineUsers.parentNode;
_oldParent.replaceChild(_onlineUsers, _oldOnlineUsers);
//if (_selfNick == "nmd") alert(_onlineMembers.innerHTML);
document.getElementById("hits").innerHTML = _hits
document.getElementById("hitsToday").innerHTML = _hitsToday;
document.getElementById("hitsThisWeek").innerHTML = _hitsThisWeek;
document.getElementById("hitsThisMonth").innerHTML = _hitsThisMonth;
document.getElementById("hitsThisYear").innerHTML = _hitsThisYear;
if (_selfNick != "") { // _selfNick == "" if user is not logged in
document.getElementById("unreadOnlineMessages").innerHTML =
_unreadOnlineMsgsText;
}
}