  function showloginform()
   {
    document.getElementById('loginform').style.display = 'block';
    document.getElementById('screen').style.display = 'block';
   }

  function hideloginform()
   {
    document.getElementById('loginform').style.display = 'none';
    document.getElementById('screen').style.display = 'none';
   }


  function auth(){
    logi = document.pbc_auth.login.value;
    passw = document.pbc_auth.password.value;

    if(document.pbc_auth.remember.checked == 1){
      var to = 5*365*24*60*60*1000;
      var expDate = new Date();
      expDate.setTime(expDate.getTime() + to);
      document.cookie = "pbc_login = " + logi + "; path=/;";
      document.cookie = "pbc_pass = " + passw + "; path=/;";
      document.cookie = "pbc_reme = 1; path=/;";
    }else{

      document.cookie = "pbc_login = " + logi + "; path=/;";
      document.cookie = "pbc_pass = " + passw + "; path=/;";
    }

    location.reload();
    return false;
  }

  function logout(){

    document.cookie = "pbc_login = x; path=/";
    document.cookie = "pbc_pass = x; path=/";
    document.cookie = "pbc_auth = x; path=/";
    
    location.reload();
  }

  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 rateit(url){
    var width = 340;
    var height = 140;
    var top = screen.availHeight/2 - height/2;
    var left = screen.availWidth/2 - width/2;

    window.open(url,'_rateit', config='toolbar=no,location=no,resizable=no,menubar=no,scrollbars=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height)
  }


  function rateview(url){
    var width = 540;
    var height = 340;
    var top = screen.availHeight/2 - height/2;
    var left = screen.availWidth/2 - width/2;

    window.open(url,'_rateview', config='toolbar=no,location=no,resizable=no,menubar=no,scrollbars=yes,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height)
  }


  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 text_bold() {enter.text.focus(); var rng=document.selection.createRange(); rng.text='[b]'+rng.text+'[/b]';}
  function text_italic() {enter.text.focus(); var rng=document.selection.createRange(); rng.text='[i]'+rng.text+'[/i]';}
  function text_underline() {enter.text.focus(); var rng=document.selection.createRange(); rng.text='[u]'+rng.text+'[/u]';}
  function text_ul() {enter.text.focus(); var rng=document.selection.createRange(); rng.text='[ul]'+rng.text+'[/ul]';}
  function text_big() {enter.text.focus(); var rng=document.selection.createRange(); rng.text='[big]'+rng.text+'[/big]';}
  function text_small() {enter.text.focus(); var rng=document.selection.createRange(); rng.text='[small]'+rng.text+'[/small]';}
  function text_img() {enter.text.focus(); var rng=document.selection.createRange(); rng.text='[img]'+rng.text+'[/img]';}






  function text_bold() {
    if(document.selection){
	enter.text.focus(); var rng=document.selection.createRange(); rng.text='[b]'+rng.text+'[/b]';
    }else{
	s=enter.text.value.substring(enter.text.selectionStart,enter.text.selectionEnd);
        enter.text.value = enter.text.value.substr(0,enter.text.selectionStart)+'[b]'+s+'[/b]'+enter.text.value.substr(enter.text.selectionEnd,enter.text.value.length);
     enter.text.setSelectionRange(enter.text.selectionEnd,enter.text.selectionEnd);
    }
  }

  function text_italic() {
    if(document.selection){
	enter.text.focus(); var rng=document.selection.createRange(); rng.text='[i]'+rng.text+'[/i]';
    }else{
	s=enter.text.value.substring(enter.text.selectionStart,enter.text.selectionEnd);
        enter.text.value = enter.text.value.substr(0,enter.text.selectionStart)+'[i]'+s+'[/i]'+enter.text.value.substr(enter.text.selectionEnd,enter.text.value.length);
     enter.text.setSelectionRange(enter.text.selectionEnd,enter.text.selectionEnd);
    }
  }

  function text_underline() {
    if(document.selection){
	enter.text.focus(); var rng=document.selection.createRange(); rng.text='[u]'+rng.text+'[/u]';
    }else{
	s=enter.text.value.substring(enter.text.selectionStart,enter.text.selectionEnd);
        enter.text.value = enter.text.value.substr(0,enter.text.selectionStart)+'[u]'+s+'[/u]'+enter.text.value.substr(enter.text.selectionEnd,enter.text.value.length);
     enter.text.setSelectionRange(enter.text.selectionEnd,enter.text.selectionEnd);
    }
  }

  function text_ul() {
    if(document.selection){
	enter.text.focus(); var rng=document.selection.createRange(); rng.text='[ul]'+rng.text+'[/ul]';
    }else{
	s=enter.text.value.substring(enter.text.selectionStart,enter.text.selectionEnd);
        enter.text.value = enter.text.value.substr(0,enter.text.selectionStart)+'[ul]'+s+'[/ul]'+enter.text.value.substr(enter.text.selectionEnd,enter.text.value.length);
     enter.text.setSelectionRange(enter.text.selectionEnd,enter.text.selectionEnd);
    }
  }

  function text_big() {
    if(document.selection){
	enter.text.focus(); var rng=document.selection.createRange(); rng.text='[big]'+rng.text+'[/big]';
    }else{
	s=enter.text.value.substring(enter.text.selectionStart,enter.text.selectionEnd);
        enter.text.value = enter.text.value.substr(0,enter.text.selectionStart)+'[big]'+s+'[/big]'+enter.text.value.substr(enter.text.selectionEnd,enter.text.value.length);
     enter.text.setSelectionRange(enter.text.selectionEnd,enter.text.selectionEnd);
    }
  }

  function text_small() {
    if(document.selection){
	enter.text.focus(); var rng=document.selection.createRange(); rng.text='[small]'+rng.text+'[/small]';
    }else{
	s=enter.text.value.substring(enter.text.selectionStart,enter.text.selectionEnd);
        enter.text.value = enter.text.value.substr(0,enter.text.selectionStart)+'[small]'+s+'[/small]'+enter.text.value.substr(enter.text.selectionEnd,enter.text.value.length);
     enter.text.setSelectionRange(enter.text.selectionEnd,enter.text.selectionEnd);
    }
  }

  function text_img() {
    if(document.selection){
	enter.text.focus(); var rng=document.selection.createRange(); rng.text='[img]'+rng.text+'[/img]';
    }else{
	s=enter.text.value.substring(enter.text.selectionStart,enter.text.selectionEnd);
        enter.text.value = enter.text.value.substr(0,enter.text.selectionStart)+'[img]'+s+'[/img]'+enter.text.value.substr(enter.text.selectionEnd,enter.text.value.length);
     enter.text.setSelectionRange(enter.text.selectionEnd,enter.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 getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}



function assist(t,id) {
	// (1) создать объект для запроса к серверу
	var req = getXmlHttp()  
       
        // (2)
	// span рядом с кнопкой
	// в нем будем отображать ход выполнения
	if(t == 'f'){
	  var statusElemName = 'assistf';
        }else{
	 if(t == 'p'){
	  var statusElemName = 'assistp';
	 }
	}
	var statusElem = document.getElementById(statusElemName) 
	
	req.onreadystatechange = function() {  
        // onreadystatechange активируется при получении ответа сервера

		if (req.readyState == 4) { 
            // если запрос закончил выполняться
			if(req.status == 200) { 
                 // если статус 200 (ОК) - выдать ответ пользователю
				//alert("Ответ сервера: "+req.responseText);
			       if(req.responseText != ''){
				statusElem.innerHTML = req.responseText // показать статус (Not Found, ОК..)
			       }	
			}
			// тут можно добавить else с обработкой ошибок запроса
		}

	}

       // (3) задать адрес подключения
	req.open('GET', '/assist/' + t + '/' + id, true);

	// объект запроса подготовлен: указан адрес и создана функция onreadystatechange
	// для обработки ответа сервера
	 
        // (4)
	req.send(null);  // отослать запрос
  
        // (5)
	//statusElem.innerHTML = 'Ожидаю ответа сервера...' 
}
