2026-03-20 10:48:09 +01:00

310 lines
11 KiB
JavaScript

var URLsuffix = '/process/ajaxreq.jsp';
//var URLsuffix = '/FabkovaChata/process/ajaxreq.jsp';
var ajaxHttp = getAjaxLibrary();
function getAjaxLibrary() {
var activexmodes = [ "Msxml2.XMLHTTP", "Microsoft.XMLHTTP" ] // activeX
// versions
// to check
// for in IE
if (window.ActiveXObject) { // Test for support for ActiveXObject in IE
// first (as XMLHttpRequest in IE7 is broken)
for ( var i = 0; i < activexmodes.length; i++) {
try {
return new ActiveXObject(activexmodes[i])
} catch (e) {
// suppress error
}
}
} else if (window.XMLHttpRequest) // if Mozilla, Safari etc
return new XMLHttpRequest()
else
return false
}
/*******************************************************************************
* F U N C T I O N S
******************************************************************************/
function getHost() {
var url = ""+window.location;
var prot = url.split('//')[0];
var urlparts = url.split('//')[1].split('/');
return urlparts[0];
}
function getProt() {
var url = ""+window.location;
return url.split('//')[0];
}
function ajaxSendRequest(data, onReadyStateChange)
{
var URL = getProt()+'//'+getHost()+URLsuffix;
//if (ajaxHttp.overrideMimeType)
//ajaxHttp.overrideMimeType('text/xml')
ajaxHttp.open("POST", URL , true);
ajaxHttp.onreadystatechange = onReadyStateChange;
ajaxHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajaxHttp.send(data);
}
function ajaxResponseReady()
{
if (ajaxHttp.readyState == 4) {
/* received */
if (ajaxHttp.status == 200 || window.location.href.indexOf("http")==-1) {
/* response is ok */
return true;
} else {
return false;
}
}
return false;
}
function ajaxGetXmlResponse() {
if (ajaxHttp.responseXML && ajaxHttp.responseXML.parseError && (ajaxHttp.responseXML.parseError.errorCode !=0)) {
ajaxGetXmlError(true);
return null;
} else {
return ajaxHttp.responseXML;
}
}
function ajaxGetXmlError(withalert) {
if (ajaxHttp.responseXML.parseError.errorCode !=0 ) {
line = ajaxHttp.responseXML.parseError.line;
pos = ajaxHttp.responseXML.parseError.linepos;
error = ajaxHttp.responseXML.parseError.reason;
error = error + "Contact the support ! and send the following informations: error is line " + line + " position " + pos;
error = error + " >>" + ajaxHttp.responseXML.parseError.srcText.substring(pos);
error = error + "GLOBAL:" + ajaxHttp.responseText;
if (withalert)
alert(error);
return error;
} else {
return "";
}
}
function convertLinks(text)
{
var myArray = text.split(" ");
for (var i = 0 ; i < myArray.length ; i++) {
var part = myArray[i];
if (part.indexOf("http://")==0) {
text = text.replace(part, '<a href="' + part + '">' + part + '</a>');
}
}
return text;
}
/*******************************************************************************
* ajax call functions
*/
function AX_voting(id, yes_no)
{
var data = 'ajaxMethod=ajaxVoting_'+yes_no +'&universalId='+id;
ajaxSendRequest(data, AX_votingResponse);
}
function AX_chat_voting(id, yes_no)
{
var data = 'ajaxMethod=ajaxChatVoting_'+yes_no +'&universalId='+id;
ajaxSendRequest(data, AX_chatVotingResponse);
}
function AX_sendChatMessage(text, chatid)
{
var data = 'ajaxMethod=chat_text_' + text +'&universalId='+chatid;
ajaxSendRequest(data, AX_asynchUpdateResponse);
}
function AX_asynchUpdate()
{
var data = 'ajaxMethod=asynchUpdate';
ajaxSendRequest(data, AX_asynchUpdateResponse);
}
function AX_asynchUpdateChat()
{
var data = 'ajaxMethod=asynchUpdateChat';
ajaxSendRequest(data, AX_asynchUpdateResponse);
}
function AX_firstUpdateChat()
{
var data = 'ajaxMethod=firstUpdateChat';
ajaxSendRequest(data, AX_asynchUpdateResponse);
}
/*******************************************************************************
* response functions
*/
function AX_votingResponse()
{
if (ajaxResponseReady()) {
if (ajaxHttp.responseText.indexOf('invalid') == -1) {
var xmlDocument = ajaxGetXmlResponse();
var id = xmlDocument.getElementsByTagName("id")[0].firstChild.data;
var yes = xmlDocument.getElementsByTagName("yes")[0].firstChild.data;
var no = xmlDocument.getElementsByTagName("no")[0].firstChild.data;
document.getElementById('yes' + id).innerHTML = yes;
document.getElementById('no' + id).innerHTML = no;
}
}
}
function AX_chatVotingResponse()
{
if (ajaxResponseReady()) {
if (ajaxHttp.responseText.indexOf('invalid') == -1) {
var xmlDocument = ajaxGetXmlResponse();
var id = xmlDocument.getElementsByTagName("id")[0].firstChild.data;
var thumbup = xmlDocument.getElementsByTagName("thumbup")[0].firstChild;
var thumbdown = xmlDocument.getElementsByTagName("thumbdown")[0].firstChild;
var yesVotes = 0;
var noVotes = 0;
var yesNames = '';
var noNames = '';
if (thumbup!==null && thumbup.data!==null) {
yesNames = thumbup.data;
yesVotes = yesNames.split(',').length;
}
if (thumbdown!==null && thumbdown.data!==null) {
noNames = thumbdown.data;
noVotes = noNames.split(',').length;
}
document.getElementById('yes' + id).innerHTML = yesVotes;
document.getElementById('no' + id).innerHTML = noVotes;
document.getElementById('yes' + id).title = yesNames;
document.getElementById('no' + id).title = noNames;
}
}
}
function AX_asynchUpdateResponse()
{
if (ajaxResponseReady()) {
if (ajaxHttp.responseText.indexOf('invalid') == -1) {
var xmlDocument = ajaxGetXmlResponse();
var userNames = xmlDocument.getElementsByTagName("userName");
var userIds = xmlDocument.getElementsByTagName("userId");
var inactives = xmlDocument.getElementsByTagName("inactive");
var inChat = xmlDocument.getElementsByTagName("inChat");
var resStr = "";
for (var i=0; i <= (userNames.length-1); i++)
{
if (inChat[i].firstChild.data=='true')
resStr = resStr + "<a href='newpm.jsp?uid=" + userIds[i].firstChild.data + "'>" + userNames[i].firstChild.data + " [Chat] (" + inactives[i].firstChild.data + ")</a>, ";
else
resStr = resStr + "<a href='newpm.jsp?uid=" + userIds[i].firstChild.data + "'>" + userNames[i].firstChild.data + " (" + inactives[i].firstChild.data + ")</a>, ";
}
document.getElementById('userCount').innerHTML = ""+userNames.length;
document.getElementById('userList').innerHTML = resStr.substring(0, resStr.length-2);
var fromNames = xmlDocument.getElementsByTagName("fromName");
var chatIds = xmlDocument.getElementsByTagName("chatId");
var newMess = xmlDocument.getElementsByTagName("newMess");
var times = xmlDocument.getElementsByTagName("time");
var texts = xmlDocument.getElementsByTagName("text");
var thumbup = xmlDocument.getElementsByTagName("thumbup");
var thumbdown = xmlDocument.getElementsByTagName("thumbdown");
var resStr = "";
var chatNode = document.getElementById('main_chat');
var newdiv = '';
for (var i=0; i <= (chatIds.length-1); i++)
{
var divIdName = 'chatId_'+chatIds[i].firstChild.data;
var color = 'color:#FF0000';
if (newMess[i].firstChild.data=='1')
color = 'color:#FF0000';
else if (newMess[i].firstChild.data=='2')
color = 'color:#0000FF';
else
color = 'color:#000000';
/*
var yesVotes = 0;
var noVotes = 0;
var yesNames = ' ';
var noNames = ' ';
if (thumbup[i].firstChild!==null) {
yesNames = thumbup[i].firstChild.data;
yesVotes = yesNames.split(',').length;
}
if (thumbdown[i].firstChild!==null) {
noNames = thumbdown[i].firstChild.data;
noVotes = noNames.split(',').length;
}
var chatVotingLine = ' <span class=\"voting-buttons\"><a title=\"'+yesNames+'\" id=\"yes'+chatIds[i].firstChild.data+'\" class=\"voting_yes\" href="javascript:AX_chat_voting('+chatIds[i].firstChild.data+',\'yes\')">'+yesVotes+'</a><a title=\"'+noNames+'\" id=\"no'+chatIds[i].firstChild.data+'\" class=\"voting_no\" href=\"javascript:AX_chat_voting('+chatIds[i].firstChild.data+',\'no\')">'+noVotes+'</a></span>';
*/
var chatVotingLine = '';
newdiv += '<div id=\"'+divIdName+'\" style=\"'+color+'\">['+times[i].firstChild.data+chatVotingLine+'] - '+fromNames[i].firstChild.data+': '+convertLinks(texts[i].firstChild.data)+'</div>';
}
if (chatIds.length>0)
chatNode.innerHTML = newdiv;
var newTitle = '';
var fids = xmlDocument.getElementsByTagName("forumId");
var messCounts = xmlDocument.getElementsByTagName("messageCount");
if (messCounts.length>0 || document.title.indexOf('(1+)')>-1) {
newTitle += '(1+)';
}
var newChatMessages = xmlDocument.getElementsByTagName("newChatMessages");
if (newChatMessages.length>0 || document.title.indexOf('(CHAT+)')>-1) {
newTitle += '(CHAT+)';
}
var newPMs = xmlDocument.getElementsByTagName("newPMCount");
if (newPMs.length>0) {
document.getElementById('newPM').innerHTML = "<STRONG><a href='private.jsp'><img src='images/pm.gif'/> You have unread Private Message</STRONG>";
if (document.title.indexOf('(PM+)')<0) {
newTitle += '(PM+)';
}
}
if (newTitle.length!='') {
document.title = newTitle + " kAmMa's Forum";
}
var resStr = '';
for (var i=0; i <= (fids.length-1); i++)
{
resStr = " "+messCounts[i].firstChild.data+" new message(s)";
if (document.getElementById('newCount'+fids[i].firstChild.data)!=null) {
document.getElementById('newCount'+fids[i].firstChild.data).innerHTML = resStr;
}
}
var playNotification = xmlDocument.getElementsByTagName("playNotification");
if (playNotification.length>0 && playNotification[0].firstChild.data=='1' && document.getElementById('soundon')!=null) {
var embed=document.createElement('object');
embed.setAttribute('type','audio/wav');
embed.setAttribute('data', 'notif.wav');
embed.setAttribute('autostart', true);
document.getElementsByTagName('body')[0].appendChild(embed);
}
}
}
}
/*
* END of response functions
*/