var sml_img = { }; Element.prototype.remove = function() { this.parentElement.removeChild(this); }; NodeList.prototype.remove = HTMLCollection.prototype.remove = function() { for(var i = 0, len = this.length; i < len; i++) { if(this[i] && this[i].parentElement) { this[i].parentElement.removeChild(this[i]); } } }; var chat = { key:'', room:'', count:0, time:0, t:null, //timer t2:null, //timer 2 t_all:{}, //time molch r:0, g:0, rtime:37, ct:{ '-1':0, '1':15, '2':30, '3':60, '4':300}, saveData:null, msg_id:0, nrg:0, nozpros:0, newmsg:0, sound:0, translit:0, filter:0, globalMsg:0, ignoreList:{x:0,nms:[]}, citySys:0, inObj:null, ignore:function(login) { if(this.ignoreList[login]!=undefined) { if($('#ignr_alu').attr('id')!=undefined) { $('#ignr_u_'+this.ignoreList[login]).remove(); } delete this.ignoreList.nms[this.ignoreList[login]]; delete this.ignoreList[login]; //msg }else{ this.ignoreList.x++; this.ignoreList[login] = this.ignoreList.x; this.ignoreList.nms[this.ignoreList.x] = login; if($('#ignr_alu').attr('id')!=undefined) { $('#ignr_alu').html($('#ignr_alu').html()+'
    '+login+'   Clear  
'); } //msg } }, getRandom:function(a, b){ return a + ( (b-a) * Math.random() ); }, ignorUn:function(x) { $('#ignr_u_'+x).remove(); this.ignore(this.ignoreList.nms[x]); }, ignorListOpen:function() { var date = '',i = 0; var j = 1; while(j<=this.ignoreList.x) { if(this.ignoreList[this.ignoreList.nms[j]]!=undefined) { date += '
    '+this.ignoreList.nms[j]+'   Clear  
'; } j++; } win.add('ignorListWin','Список игнорируемых','
'+date+'
',{},0,1,'min-width:200px;'); delete date; }, addSmile:function(id) { $('#textmsg').val($('#textmsg').val()+' :'+id+': '); $('#textmsg').focus(); }, lookSmiles:function() { if($('#chbtn8').attr('class')=='getInstance cp chatBtn8_1') { $('#ttSmiles').css('display',''); $('#chbtn8').attr('class','getInstance cp chatBtn8_2'); }else{ $('#ttSmiles').css('display','none'); $('#chbtn8').attr('class','getInstance cp chatBtn8_1'); } }, filterMsg:function() { if($('#chbtn1').attr('class')=='getInstance cp chatBtn1_1') { $('#chbtn1').attr('class','getInstance cp chatBtn1_2'); this.filter = 1; }else{ $('#chbtn1').attr('class','getInstance cp chatBtn1_1'); this.filter = 0; } }, systemMsg:function() { if($('#chbtn4').attr('class')=='getInstance cp chatBtn4_1') { $('#chbtn4').attr('class','getInstance cp chatBtn4_2'); this.citySys = 1; $.cookie('citySys',1); }else{ $('#chbtn4').attr('class','getInstance cp chatBtn4_1'); this.citySys = 0; $.cookie('citySys',0); } }, soundChat:function() { if($('#chbtn7').attr('class')=='getInstance cp chatBtn7_1') { $('#chbtn7').attr('class','getInstance cp chatBtn7_2'); this.sound = 1; }else if($('#chbtn7').attr('class')=='getInstance cp chatBtn7_2'){ $('#chbtn7').attr('class','getInstance cp chatBtn7_3'); this.sound = 2; }else{ $('#chbtn7').attr('class','getInstance cp chatBtn7_1'); this.sound = 0; } }, translitChat:function() { if($('#chbtn6').attr('class')=='getInstance cp chatBtn6_1') { $('#chbtn6').attr('class','getInstance cp chatBtn6_2'); this.translit = 1; }else{ $('#chbtn6').attr('class','getInstance cp chatBtn6_1'); this.translit = 0; } },subValSend:'', subSend:function() { if($('#textmsg').val()!='') { if($('#textmsg').val()!=this.subValSend) { if(this.nozpros == 0) { this.trmb(); $.post('online.php?r'+c.rnd+'&cas'+((new Date().getTime()) + Math.random()),{ msg:$('#textmsg').val(),key:this.key,mid:this.msg_id,rndo:c.rnd}, function(data){ chat.clearText(); chat.fc(); chat.genchatData(data,1); }); this.subValSend = $('#textmsg').val(); this.nozpros=1; setTimeout('chat.subValSend="";chat.nozpros=0;',1000); } else { console.log('nozpros != 0'); } } else { console.log('No text input = ""'); } } else { console.log('No text input'); } }, addto:function(login, type2) { var loginaddT = login; var s = ''; if($('#'+$(this.inObj).attr('id')).attr('id') == undefined) { $('#textmsg').focus(); s = $('#textmsg').val(); } else { $(this.inObj).focus(); } var reg555 = new RegExp("private\\s*\\[(.*?)\\]",""); var reg551 = new RegExp("to\\s*\\[(.*?)\\]",""); var test1 = s.match(reg555); if(s.match(reg555) == null) { type = "to"; } else if(s.match(reg551) == null) { type = "private"; } var type3 = 'to'; var reg2 = new RegExp(""+type+"(\\s*)\\[(.*?)\\]",""); var cs = s.replace(reg2,""+type+"$1[,$2,]"); var slogin = login.replace(/([\^.*{}$%?\[\]+|\/\(\)])/g,"\\$1"); var reg = new RegExp(""+type+"\\s*\\[.*,\\s*"+slogin+"\\s*,.*\\]",""); var result = ''; var reg3 = new RegExp(""+type+"\\s*\\[(.*?)\\]",""); while(res = s.match(reg3)) { result += res[1]+','; s = s.replace(reg3,''); } result = result.replace(/,$/,''); var prar = result.split(','); for(i = 0; i < prar.length; i++) { prar[i] = prar[i].replace(/^\s+/,''); prar[i] = prar[i].replace(/\s+$/,''); } var str = prar.join(', '); if(str) login += ', '; space = ''; if (!s.match(/^\s+/)) space = ' '; var prob = ''; if($('#'+$(this.inObj).attr('id')).attr('id') == undefined && (this.inObj == null || $('#main').contents().find('#'+this.inObj.id).attr('id') == undefined)) { if (!cs.match(reg)) { if(type2=='to') { if(test1!=null) { type2 = 'private'; } } s = type2+' ['+prob+''+login+str+''+prob+']'+space+s; } else { if(type3 == 'to') { type3 = "private"; } s = type3+' ['+prob+''+str+''+prob+']'+space+s; } } else { s = login+str; } if(this.inObj != null && $('#main').contents().find('#'+this.inObj.id).attr('id') != undefined) { $('#main').contents().find('#'+this.inObj.id).val(s); } else if($('#'+$(this.inObj).attr('id')).attr('id') == undefined) { $('#textmsg').val(s); } else { $(this.inObj).val(s); } }, clearText:function() { $('#textmsg').val(''); }, reflesh:function() { this.time = 0; this.testTimer(true); }, reMoney:function() { $('#moneyGM').html(top.c.money+' кр.'); }, btl:0 , testTimer:function(n) { clearTimeout(this.t); /*if(top.c.money < 100) { $('#moneyGM').height('50px'); }else if(top.c.money < 1000) { $('#moneyGM').height('70px'); }else{ $('#moneyGM').height('100px'); }*/ if($.cookie('btl') != this.btl) { if($.cookie('btl') > 0) { this.sendSound(2); if(top.frames['main'].smnpty != undefined) { }else{ top.frames['main'].location.href="main.php"; } } this.btl = $.cookie('btl'); } if(this.rtime!=this.ct[$.cookie('chatCfg0')] && this.ct[$.cookie('chatCfg0')]!=undefined) { this.rtime = this.ct[$.cookie('chatCfg0')]; if(this.time>this.rtime) { this.time = this.rtime; } } if(this.rtime>=10 || this.r==0) { if(this.time < 1) { var aot = { 0:0, 1:1, 2:0 }; if($('#chcf10').attr('checked')==true) { aot[2] = 1; } if($('#autoRefOnline').attr('checked')==true || this.r==0 || n!=false) { aot[0] = 1; } //alert('chat.reflesh.undefined()'); if(this.nozpros == 0) { $.getJSON('online.php?r'+c.rnd+'&cas'+((new Date().getTime()) + Math.random()), { key:this.key, mid:this.msg_id, r1:aot[0], r2:aot[1], r3:aot[2], rndo:c.rnd }, function(data){ if(data.rnd!=null){ if(data.telegram > 0){ $('#mini_sms').show(); }else{ $('#mini_sms').hide(); } chat.genchatData(data); if(data.key!=undefined){ chat.saveData=data; } this.g++; c.rnd = data.rnd; } }); this.nozpros=1; setTimeout('chat.nozpros=0;',1000); } this.time = this.rtime; this.r++; }else{ this.time--; } this.t = setTimeout('chat.testTimer(false);clearTimeout(this.t);',1000); } },mlch:{}, fc:function() { $('#textmsg').focus(); }, timeOut:function(v) { msPerDay = ''; dt = new Date(); dt.setTime((v-c.time)*1000); m1 = dt.getUTCMonth(); d1 = dt.getUTCDay(); h1 = dt.getUTCHours(); min1 = dt.getUTCMinutes(); sec = dt.getUTCSeconds(); if(m1>0) { msPerDay = m1+' мес. '; } if(d1>0 && Math.floor((v-c.time)/(60*60*24)) == d1) { msPerDay = d1+' д. '; } if(h1>0) { msPerDay += h1+' ч. '; } if(min1>0) { msPerDay += min1+' мин. '; } if(sec>0 && msPerDay != '') { msPerDay += sec+' сек. '; } if(msPerDay == '') { msPerDay = 'меньше минуты.'; } delete m1; delete d1; delete h1; delete min1; delete sec; return msPerDay; }, deleteMessage:function(id,fc) { //$('#msg_'+id).hide('slow'); setTimeout("$('#msg_'+id).remove();",1000); if(fc == 1) { top.msgdeleted(id); }else{ $('#msg_'+id).remove(); $('#msg_'+id+'_sys').remove(); if(top.c.admin>0) { $.post('online.php?jack='+c.rnd+'&cas'+((new Date().getTime()) + Math.random()),{delMsg:id}); } } }, clear:function() { if($('#textmsg').val()=='') { if(confirm('Очистить окно чата?')) { if(top.cb_date[top.cb_select] == 4 || top.cb_date[top.cb_select] == 5) { $('#canal'+top.cb_date[top.cb_select]).html(''); $('#textmsg').focus(); } } }else{ $('#textmsg').val(''); } }, scrollNow:function(id) { }, msgcount:0, sendMsg:function(data) { var msg_see = 1; if(!data) { console.log('No data [0]'); } else { console.log(data); } if(data[0]=='new') { data[0] = 'new_msg_'+this.newmsg; this.newmsg++; } if(data[2] == 'delete') { this.deleteMessage(data[0]); }else if(data['d']>0) { this.deleteMessage(data['d']); }else if(data['s']>0) { this.deleteMessage(data['s']); }else if(data[0]!=undefined && document.getElementById('msg_'+data[0]) == undefined) { var msg = ''; if(data[0]!=0) { if(data[3]!='') { msg += '['+data[3]+']'; } if(data[4]!='') { var forYou = 0; //тот кто писал //кому написали, разбор массива if(data[4]!='') { var to = '',to2 = '',arr = data[4].split(','),i = 0,vl = ''; //тем кому писали while(i!=-1) { if(arr[i]!=undefined) { vl = this.trim(arr[i]); if(vl.toLowerCase() == c.login.toLowerCase()) { forYou++; } if(vl.toLowerCase() == c.login.toLowerCase()) { vl = this.trim(data[3]); } if(i>0) { to += ', '; to2 += ', '; } if(data[3]!='') { to += ''+this.trim(arr[i])+''; if(this.trim(arr[i].toLowerCase()) != c.login.toLowerCase()) { to2 += this.trim(arr[i]); }else{ if(data[2]==2) { to2 += this.trim(arr[i]); }else{ to2 += this.trim(vl); } } } }else{ i = -2; } i++; } } if(data[2]==6) { //личная системка, внимание msg += ' Внимание! '; }else if(data[2]==2) { if(forYou>0) { msg += ' to ['+to2+']'; }else{ msg += ' to ['+to2+']'; } }else if(data[2]==3) { if(this.trim(data[3].toLowerCase()) == c.login.toLowerCase()) { forYou++; } if(data[3]!='') { if(data[4]=='klan' && data[2]==3) { msg += ' private [klan]'; }else if(data[4]=='paladins' && data[2]==3) { msg += ' private [paladins]'; }else if(data[4]=='tarmans' && data[2]==3) { msg += ' private [tarmans]'; }else{ msg += ' private [ '+to+' ]'; } } } } msg += ' '; } else { console.log('No data'); } data[5] = this.replaceAll(data[5],"[s1;]",'"'); data[5] = this.replaceAll(data[5],"[s2;]",'\''); data[5] = this.replaceAll(data[5],"[s3;]",'<'); data[5] = this.replaceAll(data[5],"[s4;]",'>'); if(data[6]!='Black' && data[6]!='') { msg += ''+data[5]+''; }else{ msg += data[5]; } if(data[1]>0) { var td = new Date((parseInt(data[1]))*1000); td = [td,null,null,null]; td[1] = td[0].getHours(); td[2] = td[0].getMinutes(); td[3] = td[0].getSeconds(); td[4] = td[0].getDay(); td[5] = td[0].getMonth(); td[6] = td[0].getYear(); var j = 1;while(j<6){if(td[j]<10){td[j]='0'+td[j];}j++;} var cls = ''; if(forYou>0) { cls = 'date2'; }else{ cls = 'date'; } var msg22 = ' 0) { msg22 += 'oncontextmenu="chat.deleteMessage('+data[0]+');return false;" '; }else{ msg22 += 'oncontextmenu="chat.deleteMessage('+data[0]+',1);return false;" '; } if( data[8] == 2 ) { //msg22 += 'class="'+cls+'">'+td[4]+'.'+td[5]+'.'+(td[6]+1900)+' '+td[1]+':'+td[2]+' '; msg22 += 'class="'+cls+'">'+data[14]+' '; }else{ //msg22 += 'class="'+cls+'">'+td[1]+':'+td[2]+' '; msg22 += 'class="'+cls+'">'+data[13]+' '; } msg = msg22+msg; } this.msgcount++; msg = ''+msg+'
'; if(forYou > 0 && this.sound > 0 && this.trim(data[3].toLowerCase()) != c.login.toLowerCase()) { this.sendSound(1); } if(msg_see == 1) { if(this.trim(data[3].toLowerCase()) == c.login.toLowerCase() || forYou == 1 || this.filter == 0) { if( data[9] > 0 ) { this.sendSound(data[9]); } $('#chat').find('#mes').html(msg ); //обычное сообщение console.log(msg); } else { console.log('N errors'); } } else { console.log('Msg see = '+msg_see+''); } this.scrollNow(this.msgcount); delete forYou; delete cls; delete msg_see; delete msg; delete arr; } else { console.log('UNNAMED ERROR'); } }, testKey:function(m,v) { var i = 0, r = v; v = false; while(i!=-1) { if(m[i]!=undefined) { if(m[i]==r) { v = i; i = -2; } }else{ i = -2; } i++; } delete r,m; return v; }, isNumber:function(s) { s = !isNaN(s); return s; }, testSmile:function(txt) { txr = txt.split(':'); var i = 1, j = 0, smid = 0; while(i <= txr.length) { if( txr[i] != undefined) { smid = this.testKey(top.sml,txr[i]); imsml = txr[i].split('-'); if(((smid != false || smid == 0) && this.isNumber(txr[i]) != true) || (imsml != undefined && imsml[0] == '%usersmile%')) { if(j < 3 && this.isNumber(top.sml[smid]) != true && (top.sml[smid] != undefined || imsml[0] == '%usersmile%')) { if(imsml[0] == '%usersmile%') { //txt = txt.replace("\:%usersmile%-"+imsml[1]+"\:",''); txt = txt.replace("\:%usersmile%-"+imsml[1]+"\:",''); }else{ txt = txt.replace("\:"+txr[i]+"\:",''); } j++; } } } i++; } //} return txt; }, trmb:function() { if(this.translit==1) { $('#textmsg').val(this.convert2($('#textmsg').val())); } }, replaceAll:function(t,v,s) { return t.split(v).join(s); }, convert2:function(txt) { var trn = []; trn = txt.split(' '); for(var i=0;i=0) str = str.replace(this.map_en[i],this.map_ru[i]); newstr += str; return newstr; }, sendSound:function(s) { var svolm = 100; if(this.sound == 0) { svolm = 0; }else if(this.sound == 1) { svolm = 25; }else if(this.sound == 2) { svolm = 100; } var M$ = navigator.appName.indexOf("Microsoft")!=-1; if(!M$ && this.getSwf('Sound').SetVariable == undefined) { document.getElementById('Sound2').SetVariable("Volume",svolm); document.getElementById('Sound2').SetVariable("Sndplay",s); }else{ window.document["Sound"].SetVariable("Volume", svolm); window.document["Sound"].SetVariable("Sndplay", s); } }, getSwf:function(val) { var M$ = navigator.appName.indexOf("Microsoft")!=-1; return (M$ ? window : document)[val] }, trim:function(s) { return this.rtrim(this.ltrim(s)); }, ltrim:function(s) { return s.replace(/^\s+/, ''); }, rtrim:function(s) { return s.replace(/\s+$/, ''); }, multiaddto:function(users,tp) { var arr = users.split(','); var i = arr.length; while(i>=0) { if(arr[i]!=undefined) { this.addto(arr[i],tp); } i--; } }, osize:function(obj) { var size = 0, key; for (key in obj) { if (obj.hasOwnProperty(key)) size++; } return size; }, genchatData:function(data,prs) { if(prs == 1) { data = $.parseJSON(data); } if(data == null && this.saveData!=null) { data = this.saveData; data.js = ''; data.rn = undefined; data.key = undefined; } //Получаем сообщение if(data.msg!=undefined) { var ms = $.parseJSON(data.msg); if(ms['ld']>this.msg_id) { this.msg_id = ms['ld']; } var i = 0; //while(i <= this.osize(ms.length)+10) while(i <= ms['id']) { if(ms['m'+i]!=undefined) { this.sendMsg(ms['m'+i]); } i++; } } //Если есть JS if(data.js!='') { eval(data.js); } if(data.rnd!=undefined){ c.rnd = data.rnd; } if(data.key!=undefined){ this.key = data.key; } } };