//
// NOTE:
// Chat will ONLY work if there is no errors with the user tracking.
//
// offline > 0 - online / 1 - offline
// public_display > 0 - no / 1 - yes
// public_display_users > 0 - no / 1 - yes
// public_error_count > 0
// public_reset > 0 - no / 1 - yes
// public_last_update >
// public_msg_count > 0
//
var chat_settings = {
offline: 0,
public_display: 0,
public_display_users: 0,
public_error_count: 0,
public_reset: 0,
public_last_update: '1328695996',
public_msg_count: 0
};
function chat_apply_value(n,v) {
chat_settings[n] = v;
}
function chat_get_value(n) {
return chat_settings[n];
}
var Chat_Console = new Class({
Implements: [Options, Events],
options: {
},
initialize: function (options) { },
Toggle_Public: function () {
if (tracking_settings.error_msg == "") {
chat_settings.public_display = (chat_settings.public_display == 1 ? 0 : 1);
chat_settings.public_reset = (chat_settings.public_display == 1 ? 1 : 0);
// Closing the window? Close & clear the user list..
// ----------------------------
if (chat_settings.public_display == 0) {
if ($('chat_public_display_users')) {
Utility.display($('chat_public_display_users'),0);
$('chat_public_display').style.visibility = "visible";
$('chat_public_display').display = "block";
$('chat_public_display_users').innerHTML = "";
}
chat_settings.public_display_users = 0;
}
// Window
// ----------------------------
if (!$('chat_public_window')) {
var win = PageX.Item('div',{ 'id': 'chat_public_window', 'html': '' },document.body,1);
win.style.zIndex = "1110";
win.style.position = "fixed";
win.style.visibility = (chat_settings.public_display == 1 ? "visible" : "hidden");
win.style.display = (chat_settings.public_display == 1 ? "inline" : "none");
win.style.bottom = "25px";
win.style.right = "6px";
win.style.borderStyle = "solid";
win.style.borderWidth = "1px 0px 0px 1px";
win.style.borderColor = "#DDDDDD";
win.style.backgroundColor = "#FAFAFA";
win.style.width = "320px";
win.style.height = "360px";
var html = '
Public Chat
'
+''
+''
+''
+'
'
+' '
+' | User List | '
+'  | '
+'
'
+'
'
+'
'
+'
'
+'
'
+'';
win.innerHTML = html;
} else {
var win = $('chat_public_window');
win.style.visibility = (chat_settings.public_display == 1 ? "visible" : "hidden");
win.style.display = (chat_settings.public_display == 1 ? "inline" : "none");
}
// Update # of online users
this.Public_Online_Users();
// Get most recent messages
this.Public_Recent_Messages();
}
},
Public_Online_Users: function () {
var span = $('chat_public_display_online_users');
if (span && chat_settings.public_display == 1 && chat_settings.offline != 1) {
var update = new Request({
method: 'get',
url: 'http://www.pictoucounty.ca/x/chat/online_users.php?x=1',
onSuccess: function(html) {
var resp = html.split("|");
if (resp[0] == "error") {
span.innerHTML = '?';
} else if (resp[0] == "count") {
span.innerHTML = resp[1];
} else {
span.innerHTML = '?';
}
window.setTimeout('Chat.Public_Online_Users()',10000);
},
onFailure: function(xhr) {
span.innerHTML = '?';
}
});
update.send();
}
},
Public_Recent_Messages: function () {
var body = $('chat_public_display');
var url = "";
if (chat_settings.public_msg_count > 400) {
chat_settings.public_reset = 1;
}
if (chat_settings.public_reset == 1) {
url = "reset";
chat_settings.public_reset = 0;
} else {
url = chat_settings.public_last_update;
}
if (body && chat_settings.public_display == 1 && chat_settings.offline != 1) {
var update = new Request({
method: 'get',
url: 'http://www.pictoucounty.ca/x/chat/public_recent_messages.php?x='+url,
onSuccess: function(html) {
var resp = html.split("|");
var add = "";
var ec = chat_get_value('public_error_count');
var mc = chat_get_value('public_msg_count');
if (resp[0] == "error") {
if (chat_get_value('public_error_count') >= 4) {
body.innerHTML = body.innerHTML + 'Please try refreshing the page...
';
} else {
body.innerHTML = body.innerHTML + 'Opps! Unable to receive the chat messages at this time.
'
+ 'Try again?
'
+ 'Trying again...';
chat_apply_value('public_error_count',ec+1);
}
body.innerHTML = body.innerHTML + '
'
+ '
';
} else if (resp[0] == "result") {
chat_apply_value('public_last_update',resp[1]);
if (resp[2] == "reset") {
body.innerHTML = "";
chat_apply_value('public_reset',0);
chat_apply_value('public_msg_count',resp[3]);
} else {
chat_apply_value('public_msg_count',mc+resp[3]);
}
body.innerHTML = body.innerHTML + resp[4];
} else {
if (chat_get_value('public_error_count') >= 4) {
body.innerHTML = body.innerHTML + 'Please try refreshing the page...
';
} else {
body.innerHTML = body.innerHTML + 'Opps! Unable to receive the chat messages at this time.
'
+ 'Try again?
'
+ 'Trying again...';
chat_apply_value('public_error_count',ec+1);
}
body.innerHTML = body.innerHTML + '
'
+ '
';
}
body.scrollTop = body.scrollHeight;
window.setTimeout('Chat.Public_Recent_Messages()',1500);
},
onFailure: function(xhr) {
body.innerHTML = body.innerHTML + 'Error! Please try refreshing the page...
'
+ '
'
+ '
';
chat_apply_value('public_error_count',5);
}
});
update.send();
}
},
Public_Message_KeyDown: function (event) {
var body = $('chat_public_display');
if (body && chat_settings.public_display == 1 && chat_settings.offline != 1) {
if (!(event.keycode == 16 || event.shiftKey) && event.keyCode == 13) {
if ($('chat_public_display_msg')) {
this.Public_Send_Message($('chat_public_display_msg').value);
}
}
}
},
Public_Send_Message: function (msg) {
var body = $('chat_public_display');
if (body && chat_settings.public_display == 1 && chat_settings.offline != 1) {
if (msg != "") {
$('chat_public_display_msg').value = "";
alert("We're sorry, but this feature is presently unavailable!");
/*
var post_msg = new Request({
method: 'post',
url: 'http://www.pictoucounty.ca/x/chat/public_send_message.php',
data: 'msg='+msg,
onSuccess: function(response) {
var ec = chat_get_value('public_error_count');
$('chat_public_display_msg').value = "";
if (response.length == 0) {
alert('Opps.. Your message may not have sent properly!');
} else {
// parse the response
var r = response.split("|");
if (r[0] == "success") {
Chat.Public_Recent_Messages();
Utility.display($('chat_public_display_users'),0);
$('chat_public_display').style.visibility = "visible";
$('chat_public_display').style.display = "block";
chat_apply_value('public_display_users',0);
} else {
alert('Opps.. Your message could not be posted! - '+response);
}
}
},
onFailure: function(xhr) {
$('chat_public_display_msg').value = "";
alert('Opps.. Unable to post your message! - '+xhr.status+': '+xhr.statusText);
}
});
post_msg.send();
*/
}
}
},
Public_View_Users: function () {
var body = $('chat_public_display');
var users = $('chat_public_display_users');
var userlist = $('chat_public_display_users_list');
if (body && users && userlist && chat_settings.public_display == 1 && chat_settings.offline != 1) {
chat_settings.public_display_users = (chat_settings.public_display_users == 1 ? 0 : 1);
switch (chat_settings.public_display_users) {
case 1:
users.style.visibility = "visible";
users.style.display = "block";
Utility.display(body,0);
var update = new Request({
method: 'get',
url: 'http://www.pictoucounty.ca/x/chat/online_users.php?x=2',
onSuccess: function(html) {
var resp = html.split("|");
var userlist = $('chat_public_display_users_list');
if (resp[0] == "error") {
userlist.innerHTML = 'Error:
'+resp[1]+'';
} else if (resp[0] == "list") {
userlist.innerHTML = resp[1];
} else {
userlist.innerHTML = 'Error:
Unable to retrieve user list!';
}
},
onFailure: function(xhr) {
userlist.innerHTML = 'Error:
Failed to retrieve user list!';
}
});
update.send();
break;
default:
Utility.display(users,0);
body.style.visibility = "visible";
body.style.display = "block";
userlist.innerHTML = "";
}
}
}
});
var Chat = new Chat_Console();