function toggle_block(block, icon) {
        if (document.getElementById)
        {
                if (document.getElementById(block).style.display == 'block')
                {
                        document.getElementById(block).style.display = 'none';
                        icon.src = 'images/plus.gif'; 
                        addCookie(block, true);                   
                }
                else
                {
                        document.getElementById(block).style.display = 'block';
                        icon.src = 'images/minus.gif';
                        removeCookie(block);                          
                }
        }
        else if (document.all)
        {
                if (document.all[block].style.display == 'block')
                {
                        document.all[block].style.display = 'none';
                        icon.src = 'images/plus.gif';
                        addCookie(block, true);
                }
                else
                {
                        document.all[block].style.display = 'block';
                        icon.src = 'images/minus.gif';
                        removeCookie(block);
                }
        }
}

function addCookie(szName,szValue) {
var dtExpires = new Date();
var dtExpiryDate = "";

dtExpires.setTime(dtExpires.getTime() + (1000 * 86400 * 365));
dtExpiryDate = dtExpires.toGMTString();
document.cookie = szName + "=" + szValue + "; expires=" + dtExpiryDate;
}

function findCookie(szName) {
var i = 0;
var nStartPosition = 0;
var nEndPosition = 0; 
var szCookieString = document.cookie; 

while(i <= szCookieString.length) {
nStartPosition = i;
nEndPosition = nStartPosition + szName.length;
if(szCookieString.substring(nStartPosition,nEndPosition) == szName) {
nStartPosition = nEndPosition + 1;
nEndPosition = document.cookie.indexOf(";",nStartPosition);
if(nEndPosition < nStartPosition) nEndPosition = document.cookie.length;
return document.cookie.substring(nStartPosition,nEndPosition); 
break; 
}
i++; 
}
return "";
}

function removeCookie(szName) {
var dtExpires = new Date();

dtExpires.setTime(dtExpires.getTime() - 1);
var szValue = findCookie(szName);
document.cookie = szName + "=" + szValue + "; expires=" + dtExpires.toGMTString();
}

function pm(name) {
var txtarea = document.getElementById("message");
text = '[b]' + name + '[/b] писал:' + '\r\n';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
return 0;
}

function pm2(name) {
var txtarea = document.getElementById("message");
text = '[b]' + name + '[/b],' + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
return 0;
}

var copy_txt = '';
function copy() {
    if (document.getSelection) copy_txt = document.getSelection();
    else if (document.selection) copy_txt = document.selection.createRange().text;
    else return;
}

function ins_in (tex_to) {
    var txtarea = document.getElementById("message");
    if (txtarea.createTextRange && txtarea.caretPos) {
        var caretPos = txtarea.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? tex_to + ' ' : tex_to;
  } else txtarea.value += tex_to;
    copy_txt = '';
}

function ins_to(by_who) {
    pm(by_who);
    if (copy_txt) {
    ins_in ("[quote]" + copy_txt + "[/quote]" + "\r\n");
    } else return;
}
