var SendChaturl = "sendChatData.php";
var LastSendStamp = 0;
var LastMessage = "";
function get_unixtime() {
var newDateObj = new Date();
var humDate = new Date(
Date.UTC(newDateObj.getFullYear(), (newDateObj.getMonth()-1),
newDateObj.getDate(), newDateObj.getHours(),
newDateObj.getMinutes(), newDateObj.getSeconds()));
return (humDate.getTime()/1000.0);
}
function show_smile_info (ev) {
if(window.event && window.event.button > 1) return;
var el = document.getElementById('smile_operations');
if (!el) return;
if(ev){
_ev = ev;
}
if (document.all) _ev = window.event;
var x = document.documentElement.scrollLeft + document.body.scrollLeft;
if (_ev) { x += _ev.clientX;}
if (document.body.clientWidth > el.clientWidth * 1.5) {
x -= document.body.clientWidth - _ev.clientX < el.clientWidth + 10 ? el.clientWidth - 5 : 0;
if (x < 0) x += el.clientWidth / 2;
} else if (document.body.clientWidth >= el.clientWidth) {
if (x - el.clientWidth < 0) x = 1;
else if (x + el.clientWidth > document.body.clientWidth) x -= el.clientWidth;
} else {
x = 1;
}
el.style.left = x + "px";
el.style.top = "0px";
if (el.style.display != "block") el.style.display = "block";
}
function hide_smile_info () {
setTimeout('process_hide_smile_info()',500);
}
function process_hide_smile_info()
{
var el = document.getElementById('smile_operations');
var smile1 = document.getElementById('smile1');
var smile2 = document.getElementById('smile2');
var smile3 = document.getElementById('smile3');
if(
smile1.getAttribute('selected') == null
&& smile2.getAttribute('selected') == null
&& smile3.getAttribute('selected') == null
){
if (el) el.style.display = 'none';
}
}
function make_bold(obj)
{
obj.style.color = '#FF0000';
obj.setAttribute('selected','1');
}
function remove_bold(obj)
{
obj.style.color = '#000000';
obj.removeAttribute('selected');
}
function clear_chat()
{
parent.frames['chat_frame'].document.getElementById(parent.frames['chat_frame'].chan).innerHTML = '';
}
function logout()
{
if(confirm('Действительно выходим?'))
top.location = '/logout/';
}
function SetCookie(name, value, days){
var today = new Date();
expires = new Date(today.getTime() + days*24*60*60*1000);
document.cookie = name + "=" + escape(value) +"; expires=" + expires.toGMTString();
}
function open_smilebar(barnum)
{
//document.getElementById('smile_operations').style.display = 'none';
if(barnum != 'vip')
{
open('/ajax/chat/smilebar' + barnum + '.php','smilebar'+barnum,'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,channelmode=no,directories=no,resizable=no,width=420,height=470');
}
else{
open('/ajax/chat/smilebarvip.php','smilebarvip','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,channelmode=no,directories=no,resizable=no,width=470,height=550');
}
return false;
}
function set_chat_order()
{
var el = parent.frames['chat_frame'].document.getElementById('chat_order');
hide_info();
switch(el.value)
{
case '1':
SetCookie('chat_order', 2, 2);
document.getElementById('chat_order').innerHTML = '';
el.value = '2';
break;
case '2':
SetCookie('chat_order', 3, 2);
document.getElementById('chat_order').innerHTML = '';
el.value = '3';
break;
case '3':
SetCookie('chat_order', 4, 2);
document.getElementById('chat_order').innerHTML = '';
el.value = '4';
break;
case '4':
SetCookie('chat_order', 0, -1);
document.getElementById('chat_order').innerHTML = '';
el.value = '1';
break;
}
}
function add_private(login)
{
el = document.getElementById('chatbarText');
var chat_text = el.value;
el.value = '!' + login + '! ' + chat_text;
el.focus();
try{
var rng = el.createTextRange();
rng.text = rng.text + '';
}
catch(e){}
}
function save_keep_tellto()
{
if(document.getElementById('keep_tellto').checked)
{
SetCookie('keep_tellto', 1, 7);
}
else{
SetCookie('keep_tellto', 0, -1);
}
}
//stores a new comment on the server
var b=0;
function sendComment() {
var now = get_unixtime();
if(now - LastSendStamp <= 2)
{
return false;
}
LastSendStamp = now;
if (b==1) return;
var ch=parent.frames['chat_frame'].chan;
if (ch=="main") ch=parent.frames['chat_frame'].old_main_chat;
LastMessage = document.forms['chatForm'].elements['chatbarText'].value;
b=1;
$('#loading').show();
$.ajax({
type:'POST',
dataType: 'text',
url: SendChaturl,
data: {
c:document.forms['chatForm'].elements['chatbarText'].value,
chan:ch
},
success: function(x){
b=0;
if(x!='false'){
var private_regexp = new RegExp("^(!(.*?)! ?)+","g");
var tellto_regexp = new RegExp("^(>(.*?)> ?)+","g");
if(document.getElementById('keep_tellto').checked)
{
var check = private_regexp.exec(document.forms['chatForm'].elements['chatbarText'].value);
var check_tellto =tellto_regexp.exec(document.forms['chatForm'].elements['chatbarText'].value);
if(check != null && check[0] != '' && check[0] != '%2B%')
{
document.forms['chatForm'].elements['chatbarText'].value = check[0];
}else{
if(check_tellto != null && check_tellto[0] != '' && check_tellto[0] != '%2B')
{
document.forms['chatForm'].elements['chatbarText'].value = check_tellto[0];
}else{
document.forms['chatForm'].elements['chatbarText'].value = '';
}
}
}else{
document.forms['chatForm'].elements['chatbarText'].value='';
}
$('#loading').hide();
}else{
sendComment();
}
document.forms['chatForm'].elements['chatbarText'].focus();
}
});
}
function sendComment_old() {
var now = get_unixtime();
if(now - LastSendStamp <= 2)
{
return false;
}
LastSendStamp = now;
var currentChatText = document.forms['chatForm'].elements['chatbarText'].value;
LastMessage = currentChatText;
var private_regexp = new RegExp("^(!(.*?)! ?)+","g");
var tellto_regexp = new RegExp("^(>(.*?)> ?)+","g");
if (currentChatText != '' & (httpSendChat.readyState == 4 || httpSendChat.readyState == 0)) {
currentName = document.forms['chatForm'].elements['name'].value;
while(currentChatText.indexOf("+")!=-1) currentChatText = currentChatText.replace("+", "%2B");
while(currentChatText.indexOf("&")!=-1) currentChatText = currentChatText.replace("&", "#amp#");
var param = 'n='+ currentName+'&c='+ currentChatText;
httpSendChat.open("POST", SendChaturl, true);
httpSendChat.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
httpSendChat.onreadystatechange = handlehHttpSendChat;
httpSendChat.send(param);
if(document.getElementById('keep_tellto').checked)
{
var check = private_regexp.exec(currentChatText);
var check_tellto =tellto_regexp.exec(currentChatText);
//alert(check); alert(check_tellto);
if(check != null && check[0] != '' && check[0] != '%2B%')
{
document.forms['chatForm'].elements['chatbarText'].value = check[0];
}
else{
if(check_tellto != null && check_tellto[0] != '' && check_tellto[0] != '%2B')
{
document.forms['chatForm'].elements['chatbarText'].value = check_tellto[0];
}
else{
document.forms['chatForm'].elements['chatbarText'].value = '';
}
}
}
else{
document.forms['chatForm'].elements['chatbarText'].value = '';
}
} else {
//setTimeout('sendComment();',1000);
}
document.forms['chatForm'].elements['chatbarText'].focus();
try{
el = document.forms['chatForm'].elements['chatbarText'];
var rng = el.createTextRange();
rng.text = rng.text + '';
}
catch(e){}
}
//deals with the servers' reply to sending a comment
function handlehHttpSendChat() {
if (httpSendChat.readyState == 4) {
//receiveChatText(); //refreshes the chat after a new comment has been added (this makes it more responsive)
}
}
//does celver things to the input and submit
function checkStatus(focusState) {
currentChatText = document.forms['chatForm'].elements['chatbarText'];
/*oSubmit = document.forms['chatForm'].elements['submit'];
if (currentChatText.value != '' || focusState == 'active') {
oSubmit.disabled = false;
} else {
oSubmit.disabled = true;
}*/
}
//autoasigns a random name to a new user
function checkName() {
return true;
}
//initiates the XMLHttpRequest object
//as found here: http://www.webpasties.com/xmlHttpRequest
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
function validate_chat(ev){
var ev = window.event ? window.event : ev;
if(ev.keyCode == 13){
sendComment();
return false;
}
if(ev.keyCode == 38){
var tmp = LastMessage;
LastMessage = document.forms['chatForm'].elements['chatbarText'].value;
document.forms['chatForm'].elements['chatbarText'].value=tmp;
}
}
// initiates the two objects for sending and receiving data
var httpSendChat = getHTTPObject();