  function auth(){
    logi = document.pbcf_auth.login.value;
    passw = document.pbcf_auth.pass.value;
    setcookie(logi,passw,'norem');
    refresh();
    return false;
  }


  function logout(){
    document.cookie = "pbc_login =; path=/";
    document.cookie = "pbc_pass =; path=/";
    refresh();
  }


  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 = 'pointer';

     obj=document.getElementById(id);

	  Event = id;

	if(typeof window.event == "undefined"){
	  var left = Event.pageX+window.pageXOffset;
	  var top = Event.pageY+window.pageYOffset;
	}
	else{
	   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-obj.clientWidth-10-left)<0){
    left=left+(width-obj.clientWidth-10-left);
   }


   obj.style.Top = top;
   obj.style.posLeft = left - 10;
   obj.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;

	if(document.selection){
	 selection = document.selection.createRange().text;
	 document.pbcf_comm.m_text.focus();


	 if(selection){
	   selection = '>> ' + selection;
	   comm=selection.replace('\n','\n>> ');
	   comm='\n((' + mod + ' ' + login + ')):\n' + comm + '\n\n';
	  }else{
	   comm='\n((' + mod + ' ' + login + ')),\n\n';
	  }
	 document.pbcf_comm.m_text.value = document.pbcf_comm.m_text.value + comm;
	
	 document.selection.createRange().text = '';

	}else if(window.getSelection){

	 selection = window.getSelection();
	 ss=selection.toString();
         s=selection.getRangeAt(0);
	 selection.removeAllRanges();
	 comm='';

	 if(ss != ''){
	   s = '>> ' + s;
	   comm=s.replace('\n','\n>> ');
	   comm='\n((' + mod + ' ' + login + ')):\n' + comm + '\n\n';
	  }else{
	   comm='\n((' + mod + ' ' + login + ')),\n\n';
	  }

	document.getElementById('m_text').value = document.getElementById('m_text').value + comm;

        }else{
	   comm='\n((' + mod + ' ' + login + ')),\n\n';
 	   document.getElementById('m_text').value = document.getElementById('m_text').value + comm;
        }

}


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;
    }


  function text_bold() {
    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text='[b]'+rng.text+'[/b]';
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart)+'[b]'+s+'[/b]'+pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }

  function text_italic() {
    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text='[i]'+rng.text+'[/i]';
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart)+'[i]'+s+'[/i]'+pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }

  function text_underline() {
    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text='[u]'+rng.text+'[/u]';
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart)+'[u]'+s+'[/u]'+pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }

  function text_ul() {
    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text='[ul]'+rng.text+'[/ul]';
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart)+'[ul]'+s+'[/ul]'+pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }

  function text_big() {
    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text='[big]'+rng.text+'[/big]';
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart)+'[big]'+s+'[/big]'+pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }

  function text_small() {
    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text='[small]'+rng.text+'[/small]';
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart)+'[small]'+s+'[/small]'+pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }

  function text_img() {
    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text='[img]'+rng.text+'[/img]';
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart)+'[img]'+s+'[/img]'+pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }

  function text_url() {
    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text='[url='+rng.text+']текст ссылки[/url]';
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart)+'[url='+s+']текст ссылки[/url]'+pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }


  function as_text_bold() {pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[b]'+rng.text+'[/b]';}
  function as_text_italic() {pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[i]'+rng.text+'[/i]';}
  function as_text_underline() {pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[u]'+rng.text+'[/u]';}
  function as_text_ul() {pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[ul]'+rng.text+'[/ul]';}
  function as_text_big() {pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[big]'+rng.text+'[/big]';}
  function as_text_small() {pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[small]'+rng.text+'[/small]';}
  function as_text_img() {pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[img]'+rng.text+'[/img]';}



  function as_text_bold() {
    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[b]'+rng.text+'[/b]';
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart)+'[b]'+s+'[/b]'+pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }

  function as_text_italic() {
    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[i]'+rng.text+'[/i]';
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart)+'[i]'+s+'[/i]'+pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }

  function as_text_underline() {
    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[u]'+rng.text+'[/u]';
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart)+'[u]'+s+'[/u]'+pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }

  function as_text_ul() {
    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[ul]'+rng.text+'[/ul]';
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart)+'[ul]'+s+'[/ul]'+pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }

  function as_text_big() {
    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[big]'+rng.text+'[/big]';
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart)+'[big]'+s+'[/big]'+pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }

  function as_text_small() {
    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[small]'+rng.text+'[/small]';
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart)+'[small]'+s+'[/small]'+pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }

  function as_text_img() {
    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[img]'+rng.text+'[/img]';
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart)+'[img]'+s+'[/img]'+pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }

  function as_text_url() {
    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text='[url='+rng.text+']текст ссылки[/url]';
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart)+'[url='+s+']текст ссылки[/url]'+pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }



  function text_smile(id) {
	var smile_string = ' :smile' + id + ': ';

    if(document.selection){
	pbcf_comm.m_text.focus(); var rng=document.selection.createRange(); rng.text=rng.text+ smile_string;
    }else{
	s=pbcf_comm.m_text.value.substring(pbcf_comm.m_text.selectionStart,pbcf_comm.m_text.selectionEnd);
        pbcf_comm.m_text.value = pbcf_comm.m_text.value.substr(0,pbcf_comm.m_text.selectionStart) +s+ smile_string +pbcf_comm.m_text.value.substr(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.value.length);
     pbcf_comm.m_text.setSelectionRange(pbcf_comm.m_text.selectionEnd,pbcf_comm.m_text.selectionEnd);
    }
  }



  function as_text_smile(id) {
	var smile_string = ' :smile' + id + ': ';

    if(document.selection){
	pbcf_add_subj.s_text.focus(); var rng=document.selection.createRange(); rng.text=rng.text+ smile_string;
    }else{
	s=pbcf_add_subj.s_text.value.substring(pbcf_add_subj.s_text.selectionStart,pbcf_add_subj.s_text.selectionEnd);
        pbcf_add_subj.s_text.value = pbcf_add_subj.s_text.value.substr(0,pbcf_add_subj.s_text.selectionStart) +s+ smile_string +pbcf_add_subj.s_text.value.substr(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.value.length);
     pbcf_add_subj.s_text.setSelectionRange(pbcf_add_subj.s_text.selectionEnd,pbcf_add_subj.s_text.selectionEnd);
    }
  }


  var smiles_panel = false;

  function show_smiles(){

	var forsmiles = document.getElementById('forsmiles');
	var smilesfull = document.getElementById('smilesfull');

	if(smiles_panel == false){
	  forsmiles.innerHTML = smilesfull.innerHTML;
	  smiles_panel = true;
        }else{
	  forsmiles.innerHTML = '';
	  smiles_panel = false;
        }

  }
