//<script language="JavaScript">
 //---------------------------------------------------------------
 // Чат...
 //---------------------------------------------------------------
 function chat_class(){
   this.rt=new Array();
     this.rt[0]=10000;
     this.rt[1]=3000;
   this.time=this.rt[0];
   this.status=-1;
   this.ls=0;
   this.show_smiles=false;
   
   this.switch_chat=function(){
     if (guest) return false;
     if(this.status!=1){
       this.status=1;
       if(info!='chat'){       
         show_wait();
         info='chat';
         this.data.send_action('get_chat_table');
        }
      }
     else{
       this.status=0;
      }
     show_hide('info',this.status);
     show_hide('curtain',this.status);
     this.data.set_perm_data('status',this.status);
     this.time=this.rt[this.status];
     return false;
    }   
   
   this.switch_smiles=function(show){
     obj=document.getElementById('smile_table'); 
     var len=obj.rows.length-1;
     for (row_id in obj.rows){
       if(row_id<len){
         obj.rows[row_id].style.display=(show)?'':'none';
        }
      }
    }
    
   this.send_chat_messages=function(){
     this.time=this.rt[1];
     this.data.set_data('text',document.getElementById('chat_input').value);
     document.getElementById('chat_input').value='';
     this.data.send_action('send_message');
     document.getElementById('chat_input').focus();
    }
   
   this.show_chat_messages=function(text,ls){
     //~ rt=(status==1)?rt1:rt0;
     this.data.set_perm_data('ls',ls);
     into_add('chat_messages_small',str_replace('<img','<img height="12"',text));
     document.getElementById('chat_messages_small').scrollTop=100000;
     if (guest || info!='chat') return false;
     into_add('chat_messages',text);
     document.getElementById('chat_messages').scrollTop=100000;
    }
   
   this.chat_insert=function(ibTag, ibClsTag, isSingle){
     if (guest) return false;
     var isClose = false;
     var obj_ta = document.getElementById('chat_input');
     
     //----------------------------------------
     // It's IE!
     //----------------------------------------
     
     if ( (ua_vers >= 4) && is_ie && is_win){
       if (obj_ta.isTextEdit){
         obj_ta.focus();
         var sel = document.selection;
         var rng = sel.createRange();
         rng.colapse;
         if((sel.type == "Text" || sel.type == "None") && rng != null){
           if(ibClsTag != "" && rng.text.length > 0)
             ibTag += rng.text + ibClsTag;
           else if(isSingle)
             isClose = true;
           rng.text = ibTag;
          }
        }
       else{
         if(isSingle){
           isClose = true;
          }
         obj_ta.value += ibTag;
        }
      }
     else if ( obj_ta.selectionEnd ){
        // It's MOZZY!
       var ss = obj_ta.selectionStart;
       var st = obj_ta.scrollTop;
       var es = obj_ta.selectionEnd;
       if (es <= 2){
         es = obj_ta.textLength;
        }
       var start  = (obj_ta.value).substring(0, ss);
       var middle = (obj_ta.value).substring(ss, es);
       var end    = (obj_ta.value).substring(es, obj_ta.textLength);
       // text range?
       if (obj_ta.selectionEnd - obj_ta.selectionStart > 0){
         middle = ibTag + middle + ibClsTag;
        }
       else{
         middle = ibTag + middle;
         if (isSingle){
           isClose = true;
          }
        }
       obj_ta.value = start + middle + end;
       var cpos = ss + (middle.length);
       obj_ta.selectionStart = cpos;
       obj_ta.selectionEnd   = cpos;
       obj_ta.scrollTop      = st;
      }
     else{
       // It's CRAPPY!
       if (isSingle){
         isClose = true;
        }
       obj_ta.value += ibTag;
      }
     obj_ta.focus();
     //return isClose;
    }
   
   this.key_handler=function(evt){
     this.time=this.rt[1];
     var key_number = evt.keyCode;
     var key_ctrl = evt.ctrlKey;
     if (key_ctrl && key_number==13){
       this.send_chat_messages();
       return false;
      }
    }
   
   this.timeout_handler=function(){
     if((this.status==0 && this.time<60000) || (this.status==1 && this.time<10000))this.time+=500;
     this.data.doload();
    }
    
    // Конструктор 
    //~ show_hide('top_chat',1);
    document.getElementById('top_chat').style.display='';
    this.data=new data_class('chat');
    this.data.set_perm_data('ls',0);
    this.data.set_perm_data('status',this.status);
    this.data.set_handler('chat.timeout_handler();',this.time);
    this.data.doload();
  }
//</script>
