  function auth(){
    logi = document.pbcf_auth.login.value;
    passw = document.pbcf_auth.pass.value;
    setcookie(logi,passw,'norem');
    refresh();
    return false;
  }


  function avatar_upload(){
    var width = 340;
    var height = 140;
    var top = screen.availHeight/2 - height/2;
    var left = screen.availWidth/2 - width/2;

    window.open('/avatar_upload','_upload', config='toolbar=no,location=no,resizable=no,menubar=no,scrollbars=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height)
  }


  function file_upload(){
    var width = 340;
    var height = 140;
    var top = screen.availHeight/2 - height/2;
    var left = screen.availWidth/2 - width/2;

    window.open('/file_upload','_upload', config='toolbar=no,location=no,resizable=no,menubar=no,scrollbars=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height)
  }

  function file_delete(fileid,uid){
    var width = 340;
    var height = 140;
    var top = screen.availHeight/2 - height/2;
    var left = screen.availWidth/2 - width/2;

    window.open('/file_delete/' + fileid + '/' + uid,'_delete', config='toolbar=no,location=no,resizable=no,menubar=no,scrollbars=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height)
  }


  function open_remind(){
    var width = 340;
    var height = 140;
    var top = screen.availHeight/2 - height/2;
    var left = screen.availWidth/2 - width/2;

    window.open('/remind','_remind', config='toolbar=no,location=no,resizable=no,menubar=no,scrollbars=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height)
  }


  function show(id){

   var i = id.replace('d','i');

   document.images[i].style.cursor = 'hand';

   var left = window.event.clientX;
   var top = window.event.clientY;
   
   if(navigator.appName == 'Microsoft Internet Explorer'){
    var width = document.body.clientWidth;
   }else{
    var width = window.innerWidth;
   }

   if((width-document.all[id].clientWidth-10-left)<0){
    left=left+(width-document.all[id].clientWidth-10-left);
   }
   document.all[id].style.Top = top;
   document.all[id].style.posLeft = left - 10;
   document.all[id].style.visibility = 'visible';

  }

  function hide(id){
   document.all[id].style.visibility = 'hidden';
  }



  function showtip(){


      var oCanvas = document.
          getElementsByTagName((document.compatMode && 
              document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];

      var left = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
      var top = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
   

   document.all['answer_tip'].style.posTop = top;
   document.all['answer_tip'].style.posLeft = left - 10;
   document.all['answer_tip'].style.visibility = 'visible';

  }

  function hidetip(){
   document.all['answer_tip'].style.visibility = 'hidden';
  }


function answer(login,mod){

 selection=false;
 selection = document.selection.createRange().text;
 document.pbcf_comm.m_text.focus();

 if(selection){
   selection = '>> ' + selection;
   comm=selection.replace('\n','\n>> ');
   comm='((' + mod + ' ' + login + ')):\n' + comm + '\n';
  }else{
   comm='((' + mod + ' ' + login + ')),\n';
  }
 document.pbcf_comm.m_text.value = document.pbcf_comm.m_text.value + comm;

 document.selection.createRange().text = '';

}


function delete_message(m_id){
  if(confirm('Сохранить сообщение на сервере?')){
     location.href="/delete/message/" + m_id + "/store";
    }else{
      if(confirm('Сообщение нельзя будет восстановить. Удалить?')){
        location.href="/delete/message/" + m_id;
      }
  }
}



   var lastDiv;
    lastDiv = 's';

    function comment(tree) {
        if (! document.getElementById) return false;

        var qr_div = document.getElementById('s');
        var cur_div = document.getElementById(tree);

        if (lastDiv == 's') {
            qr_div.style.display = 'inline';

            // only one swap
            swapnodes(qr_div, cur_div);
        } else if (lastDiv != tree) {
              var last_div = document.getElementById(lastDiv);

              // Two swaps
              swapnodes(last_div, cur_div);
              swapnodes(qr_div, last_div);
        }

        lastDiv = tree;

        // So it doesn't follow the link
        return false;
    }

    function swapnodes (orig, to_swap) {
        var parent_node = orig.parentNode;
        var next_sibling = orig.nextSibling;
        to_swap.parentNode.replaceChild(orig, to_swap);
        parent_node.insertBefore(to_swap, next_sibling);
        return true;
    }
