var CtrlPress = false;

totrefcount=0;

function AddTo(login){

        if ((CtrlPress) && (top.frames['chat'].window.document.all.silence.style.display=='')) {
                        top.frames['chat'].window.document.F2.nick.focus();
                        top.frames['chat'].document.forms[0].nick.value = ''+login+'';
                          } 
else { if (login.length>25) return true;
                        top.frames['bottom'].window.document.F1.text.focus();
                        top.frames['bottom'].document.forms[0].text.value = 'to ['+login+'] '+top.frames['bottom'].document.forms[0].text.value;
                             
        }
}
function AddToPrivate(login, nolookCtrl){
        if (CtrlPress && !nolookCtrl) {
                while (login.indexOf('+')>=0) login = login.replace('+', '%2B');
                while (login.indexOf('#')>=0) login = login.replace('#', '%23');
                while (login.indexOf('?')>=0) login = login.replace('?', '%3F');
                window.open('http://capitalcity.combats.ru/inf.pl?login='+login, '_blank')
        } else {
                top.frames['bottom'].window.document.F1.text.focus();
                top.frames['bottom'].document.forms[0].text.value = 'private ['+login+'] ' + top.frames['bottom'].document.forms[0].text.value;
        }
}
function setCookie(name, value) {document.cookie=name+"="+escape(value)+"; path=/";}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0){
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
                offset += search.length
                end = document.cookie.indexOf(";", offset)
                if (end == -1) end = document.cookie.length
                return unescape(document.cookie.substring(offset, end))
        }
}}

var rnd = Math.random();

//-- Обновление чата
var ChatTimerID = -1;           // id таймера для чата
var ChatDelay = 15;             // через сколько сек. рефрешить чат
var ChatNormDelay = 15;         // через сколько сек. рефрешить чат при нормальном обновлении
var ChatSlowDelay = 60;         // через сколько сек. рефрешить чат при медленном обновлении
var ChatOm = false;             // фильтр сообщений в чате
var ChatSound = true;           // звук приватных сообщений в чате
var ChatSlow = false;           // обновление чата раз в минуту
var ChatTranslit = false;       // преобразование транслита
var lid = 0;                    // номер последнего сообщения в чате
function RefreshChat()
{       var s = '';
        if (ChatOm) { s=s+'&om=1'; }
        if (ChatSound) { s=s+'&soun=1'; }
        if (ChatTimerID>=0) { clearTimeout(ChatTimerID); }
        ChatTimerID = setTimeout('RefreshChat()', ChatDelay*1000);
        top.frames['refreshed'].location='chat/ch.php?show='+Math.random()+s;
}
// останавливает обновление чата
function StopRefreshChat(){
        if (ChatTimerID>=0) {clearTimeout(ChatTimerID); }
        ChatTimerID = -1;
}
// сбрасывает таймер счетчика
function NextRefreshChat(){
        if (ChatTimerID>=0) {clearTimeout(ChatTimerID); }
        ChatTimerID = setTimeout('RefreshChat()', ChatDelay*1000);
}
// Прокрутка текста чата вниз
function srld(){top.frames['chat'].window.scrollBy(0, 65000);}

// Установка lid
function slid(newlid)
{       var o = top.frames['bottom'].F1;
        if (o) {lid=newlid;o.lid.value=newlid;}
}

// Перезагружаем список online, делаем это не сразу, а с паузой
var OnlineDelay = 12;           // пауза в сек. перед релоудом списка online
var OnlineTimerOn = -1;         // id таймера
var OnlineOldPosition = 0;      // Позиция списка перед релоудом
var OnlineStop = true;          // ручное обновление чата
function rld(now) {
        if (OnlineTimerOn < 0 || now) {
                var tm = now ? 2000 : OnlineDelay*1000;
                OnlineTimerOn = setTimeout('onlineReload('+now+')', tm);
        }
}
function onlineReload(now) {
        if (OnlineTimerOn >= 0) clearTimeout(OnlineTimerOn);
        OnlineTimerOn = -1;
        if (! OnlineStop || now) { top.frames['online'].navigate('chat/list.php?online='+Math.round(Math.random()*100000));  }
}

//-- Очистка чата
var ChatClearTimerID = -1;      // id таймера для чата
var ChatClearDelay = 900;       // через сколько сек. чистим чат
var ChatClearSize = 32000;      // Сколько байт оставляем после чистки
function RefreshClearChat(){
        if (ChatClearTimerID>=0) { clearTimeout(ChatClearTimerID); }
        ChatClearTimerID = setTimeout('RefreshClearChat()', ChatClearDelay*1000);
        var s = top.frames['chat'].document.all("mes").innerHTML;
        if (s.length > ChatClearSize) { // Надо чистить
                var j = s.lastIndexOf('<BR>', s.length-ChatClearSize);
                top.frames['chat'].document.all("mes").innerHTML = s.substring(j, s.length);
        }
}

//-- Прочие функции
var oldlocation = '';
function cht(nm){
        if (oldlocation == '') {
                oldlocation = top.frames['main'].location.href;
                var i = oldlocation.indexOf('?', 0);
                if (i>0) { oldlocation=oldlocation.substring(0, i) }
        }
        top.frames['main'].navigate(nm);
}
function returned(){
        if (oldlocation != '') { top.frames['main'].navigate(oldlocation+'?tmp='+Math.random()); oldlocation=''; }
        else { top.frames['main'].navigate('/main.php?tmp='+Math.random()) }
}
function myscroll(){
        OnlineOldPosition = top.frames['online'].document.body.scrollTop;
}
function CLR1(){
        top.frames["bottom"].document.F1.text.value='';
        top.frames["bottom"].document.F1.text.focus();
}
function CLR2(){
        top.frames['chat'].document.all("mes").innerHTML='';
        top.frames['chat'].document.all("oMenu").style.top="0px";
}
function strt(){// Начинаем
        ChatTimerID = setTimeout('RefreshChat()', 1000);
        OnlineTimerOn = setTimeout('onlineReload(true)', 2*1000);
        ChatClearTimerID = setTimeout('RefreshClearChat()', ChatClearDelay*1000);
}
var user = getCookie("c_name");

if (user == undefined)
{
document.write(
'<frameset rows="100%, *, 0, 0" FRAMEBORDER="0" BORDER="0" FRAMESPACING="1">'+
'<frame name="main" src="main.php?'+Math.random()+'">'+
'</frameset>'
);
}
else
{
document.write(
'<frameset rows="70%, *, 20, 0" FRAMEBORDER="0" BORDER="0" FRAMESPACING="1">'+
'<frame name="main" src="main.php?'+Math.random()+'">'+
'<frameset cols="*,200">'+
'<frame name="chat" src="chat/chat.php?'+Math.random()+'" scrolling=YES FRAMEBORDER="0" BORDER="0" FRAMESPACING="0" MARGINWIDTH="3" MARGINHEIGHT="3">'+
'<frame name="online" src="chat/list.php?'+Math.random()+'" scrolling=YES FRAMEBORDER=0 BORDER=0 FRAMESPACING=0 MARGINWIDTH=3 MARGINHEIGHT=0>'+
'</frameset>'+
'<frame name="bottom" scrolling="no" noresize src="chat/input.php?'+Math.random()+'">'+
'<frame name="refreshed" target="_top" scrolling="no" noresize src="chat/ch.php?'+Math.random()+'&first=yes">'+
'</frameset>');
}
