/******************************************************************************
*	+--------------------------------------------------------------------------
*	|   STRCHAT - AJAX CHAT FOR INVISION POWER BOARD 2.1.x
*	|   =============================================
*	|   by sdx aka EasyBot on IBR ;)
*	|	icq: 555-391
*	|   (c) 2006 STHost
*	|   http://www.sthost.ru
*	|	http://nnm.cc
*	|   =============================================
*	|   Web: http://www.sthost.ru
*	|   Web: http://www.nnm.cc
*	+--------------------------------------------------------------------------
******************************************************************************/
var timeout = null;
var canl=false;
globcanl = false;
var div_scroll2;
privat = false;
tLoad =null;
tUser = null;
var strchat_loaded   = 0;
var strchat_call_loaded = 0;
var sarray = new Array();
var banned = null;
var scroll_status = '>>';

var scroll_timer = null;
var userlist = new Array();

var counter_log_1 = 0;
var counter_log_2 = 0;
var counter_log_3 = 0;
var counter_log_4 = 0;
var counter_log_5 = 0;
var counter_log_6 = 0;

var user_active_name = '';

function init_chat()
{
        On_Load();
        Resize();
        Do_Load();
        Init_Users();
        timerStart(refresh);
        refresh_clock();
        my_setcookie( 'strchat_curr_status', '0', 0 );
        start_stopscroll();
}

function Resize()
{
            document.getElementById('outputList_').style.height=document.body.clientHeight-201-koff+'px';
            document.getElementById('strchat_table').style.height=document.body.clientHeight-koff+'px';
            document.getElementById('smileList_').style.height=document.body.clientHeight-koff-176+'px';
            document.getElementById('onlineList_').style.height=document.body.clientHeight-koff-201+'px';
}

function Init_Users()
{
			var ulist = '<span style="color:#5D5D5D"><b><a href="javascript:void(0);" onclick="change_say_private();" id="say_private">Ñêàçàòü:</a></b> </span> <a href="javascript:void(0);" id="say_all" onclick="user_over(\'all\');" style="border:#808080 dotted 1px;background-color:#FFEECE;">Âñåì</a> ';
			var nlist = '<span style="color:#5D5D5D"> | <b>Íèêè:</b> </span> <span id="nicks_place"></span>';
			document.getElementById('UserList_').innerHTML=ulist+nlist;
			setTimeout(get_userlist_names, 4000);
}

function aaalert()
{
	cookl = new Array();
	userl = new Array();
	cleann = new Array();
	add   = 1;
	dat = '';

	//-----------------------------------
	// Get any saved info
	//-----------------------------------

	if ( tmp = my_getcookie('strchat_users_list') )
	{
		cookl = tmp.split(",");
	}
	if ( tmp2 = userlist['list'] )
	{
		userl = tmp2.split(",");
	}

    dat = 'userlist: ' + userlist['list'] + '<br>';
    dat += 'cookies: ' + tmp + '<br>';
    find = '<br> find: '
	//-----------------------------------
	// Remove bit if exists
	//-----------------------------------
	for( i = 0 ; i < userl.length; i++ )
	{
		if ( userl[i] != "" )
		{
			for( j = 0 ; j < cookl.length; j++ )
			{
				dat += 'ul: ' + userl[i] + ' | cl: ' + cookl[j] + '<br>'
				if ( userl[i] == cookl[j] )
				{
					 find += cookl[j] + ', '
					 cleann[cleann.length] = cookl[i];
				}
			}
		}
	}
	document.getElementById('outputList_').innerHTML=dat+find+'<br><br> Listed: ' + cleann.join(',');
	//dump_nick_place(clean.join(','));
}

function change_say_private()
{
	data = my_getbyid("say_private");
	stat = my_getcookie( 'strchat_curr_status' );
	uactive = my_getcookie( 'strchat_user_active' );
	if ( stat > 0 )
	{
		my_setcookie( 'strchat_curr_status', '0', 0 );
		data.innerHTML = 'Ñêàçàòü:';
	}
	else
	{
		if( uactive != 'all' ) {
			my_setcookie( 'strchat_curr_status', '1', 0 );
			data.innerHTML = 'Ïðèâàò:';
		}
	}
}

function user_over(id)
{
	var ids = my_getcookie( 'strchat_users_list' );
	saved = new Array();
	if ( ids )
	{
		saved = ids.split(",");
	}

	//alert(saved.length);

	for( i = 0 ; i < saved.length; i++ )
	{
		user = my_getbyid('user_'+saved[i]);
		user.style.border = "0px";
		user.style.background = "transparent";
	}
	for( i = 0 ; i < saved.length; i++ )
	{
		if(id == 'all')
		{
			user = my_getbyid('say_all');
			user.style.border = "#808080 dotted 1px";
			user.style.background = "#FFEECE";
			my_setcookie( 'strchat_user_active', 'all', 0 );
			stat = my_getcookie( 'strchat_curr_status' );
			if ( stat > 0 ) {
			change_say_private();
			}
		}
		else
		{
			if( saved[i] == id ) {
				user = my_getbyid('say_all');
				user.style.border = "0px";
				user.style.background = "transparent";
				user2 = my_getbyid('user_'+saved[i]);
				if (user2) {
					user2.style.border = "#808080 dotted 1px";
					user2.style.background = "#FFEECE";
				}
				my_setcookie( 'strchat_user_active', id, 0 );
				user_active_name = userlist[id]['name'];
			}
		}
	}
}

function get_select_name()
{
	var ids = my_getcookie( 'strchat_users_list' );
	var idu = my_getcookie( 'strchat_user_active' );
	saved = new Array();
	if ( ids )
	{
		saved = ids.split(",");
	}

	for( i = 0 ; i < saved.length; i++ )
	{
		if( saved[i] == idu ) {
			return userlist[idu]['name'];
		}
	}
}


function dump_nick_place(ids)
{
	var dump = '';
	saved = new Array();
	var found = 0;
	var cid = my_getcookie( 'strchat_user_active' );
	if ( !ids )
	{
		document.getElementById('nicks_place').innerHTML="Ïîëüçîâàòåëåé íåò...";
	}
	else
	{
		saved = ids.split(",");

		for( i = 0 ; i < saved.length; i++ )
		{
			found = 1;
	  		dump += '<a href="javascript:void(0);" ondblclick="add_user_to_bottom(\''+saved[i]+'\');clear_inp();" onclick="user_over(\''+saved[i]+'\');addin(userlist['+saved[i]+'][\'name\']+\': \');"><span id="user_'+saved[i]+'">'+userlist[saved[i]]['pr'] + userlist[saved[i]]['name'] + userlist[saved[i]]['sf'] + '</span></a> ';
		}

		if(found != 1) {
			document.getElementById('nicks_place').innerHTML="Ïîëüçîâàòåëåé íåò...";
		}

		document.getElementById('nicks_place').innerHTML=dump.replace(/undefined/, '');
		user_over(cid);
	}
}

function get_userlist_names()
{
	var ids = my_getcookie( 'strchat_users_list' );
	if(!ids || ids == 'null')
	{
		document.getElementById('nicks_place').innerHTML="Ïîëüçîâàòåëåé íåò...";
	}
	else
	{
    	dump_nick_place(ids);
 	}
}

function add_user_to_bottom(id)
{
	cookl = new Array();
	userl = new Array();
	clean = new Array();
	add   = 1;
    color_all = 0;

	//-----------------------------------
	// Get any saved info
	//-----------------------------------

	if ( tmp = my_getcookie('strchat_users_list') )
	{
		cookl = tmp.split(",");
	}
	if ( tmp2 = userlist['list'] )
	{
		userl = tmp2.split(",");
	}
	var cid = my_getcookie( 'strchat_user_active' );


	//-----------------------------------
	// Remove bit if exists
	//-----------------------------------

	for( i = 0 ; i < cookl.length; i++ )
	{
		if ( cookl[i] != "" )
		{
			if ( cookl[i] == id )
			{
				if( cookl[i] == cid )
				{
					color_all = '1';
				}
				add = 0;
			}
			else
			{
				for( j = 0 ; j < userl.length; j++ )
				{
					if( cookl[i] == userl[j] )
					{
						clean[clean.length] = cookl[i];
					}
				}
			}
		}
	}

	//-----------------------------------
	// Add?
	//-----------------------------------
		if ( add )
		{
			clean[ clean.length ] = id;
		}

	my_setcookie( 'strchat_users_list', clean.join(','), 0 );
	if( color_all )
	{
		user_over('all');
	}
	dump_nick_place(clean.join(','));

	return false;
}

function add_user_to_list_ids(id)
{
	saved = new Array();
	clean = new Array();
	add   = 1;

	//-----------------------------------
	// Get any saved info
	//-----------------------------------

	if ( tmp = userlist['list'] )
	{
		saved = tmp.split(",");
	}

	//-----------------------------------
	// Remove bit if exists
	//-----------------------------------

	for( i = 0 ; i < saved.length; i++ )
	{
		if ( saved[i] != "" )
		{
			if ( saved[i] == id )
			{
				add = 1;
			}
			else
			{
				clean[clean.length] = saved[i];
			}
		}
	}

	//-----------------------------------
	// Add?
	//-----------------------------------
		if ( add )
		{
			clean[ clean.length ] = id;
		}
	//my_setcookie( 'ulist', clean.join(','), 0 );
	userlist['list'] = clean.join(',');
}


function Do_Load(viewer)
{
	if(!globcanl)
	{
		if(!canl)
		{
			canl = true;
			var req = new JsHttpRequest();
			req.onreadystatechange = function() {
			if (req.readyState == 4) {
						if(req.responseJS)
						{
							if(viewer == '1') {
					        	insertO = document.getElementById("outputList_");
					        	insertO.innerHTML = '';
    						}
					        try {
					        	eval(req.responseJS);
					        }
					        catch(e) {
					        	window.alert(e);
					        }
						}
						infoadd('load',2);
						canl = false;
				}
			}

			infoadd('load',1);
            if(viewer == '1') {
            	lastID = '-1';
            }
	        if(viewer == null) var viewer = '0';
			req.caching = false;
			req.open('POST', GetChaturl + "&viewer=" + viewer, true);
			req.send({ last_id: lastID });
	  	}
	}
}

function On_Load()
{
	if(!globcanl)
	{
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
		if (req.readyState == 4) {
				infoadd('online',2);
			if (req.responseJS && req.responseJS.length>0) {
				var buffer = '';
				userlist['list'] = '';
				for(var i=0;i<req.responseJS.length;i++) {
					var name= (req.responseJS[i].n||'');
					var uid= (req.responseJS[i].ui||'');
					var pr= (req.responseJS[i].pr||'');
					var sf= (req.responseJS[i].sf||'');
					var h1= (req.responseJS[i].h1||'');
					var h2= (req.responseJS[i].h2||'');
					var h3= (req.responseJS[i].h3||'');

					var moder = '';
					var ddi = '';
		   				add_user_to_list_ids(uid);
					userlist[uid] = new Array();
					userlist[uid]['id'] = uid;
					userlist[uid]['name'] = name;
					userlist[uid]['pr'] = pr;
					userlist[uid]['sf'] = sf;
					userlist[uid]['h1'] = h1;
					userlist[uid]['h2'] = h2;
					userlist[uid]['h3'] = h3;

					if (gradient_activate > 0) {
						var gname = gradient(h1,h2,h3,name);
					}
					else {
						var gname = name;
					}

					if(req.responseJS[i].k == '1'){
					  moder = '&nbsp;<span onmouseover="ShowTip(3);" onmouseout="HideTip(3);" style="cursor:help;">*</span>';
					}

					if(req.responseJS[i].m){
					  moder += '&nbsp;<span onmouseover="ShowTip(2);" onmouseout="HideTip(2);" style="cursor:help;">#</span>';
					}

					if(req.responseJS[i].dd){
					  ddi += '&nbsp;' + req.responseJS[i].dd;
					}



					if(req.responseJS[i].aw){
					  ddi += '&nbsp;<span style="color:#808080">( ' + req.responseJS[i].aw + ' )</span>';
					}
			  		buffer += '<div><a  href="index.php?showuser=' + uid + '" target="_blank" title="' + lang_profile + '" style="cursor:hand;"><img src="' + ipb_var_image_url + '/profile_msn.gif"></a>&nbsp;';
					if(viewer != '1') {
					  buffer += "<a href=\"javascript:void(0);\" onclick=javascript:add_user_to_bottom('"+uid+"') style='cursor:hand;'>"+ pr + gname + sf +'</a>'+moder+ddi;
					}
				  	else {
					  if(s_mod_chat == '1')
					  {
					  	buffer += "<a href=\"javascript:void(0);\" onclick=javascript:addin('"+name+"') style='cursor:hand;'>"+ pr + gname + sf +'</a>'+moder+ddi;
					  }
					  else
					  {
					  buffer += pr + gname + sf +moder+ddi;
					  }
			  		}
			  		buffer +='</div>';
				}
				if(viewer != '1') {
			  		buffer += '<br><br><div align="center"><input class="button" type="button" value="áàí ëèñò" style="width: 90px;height:18px;padding:0px;" onClick="see_ban_list();"></div>';
			 	}
			  	document.getElementById('onlineList_').innerHTML=buffer;
			}
			if (req.responseText) {
			  try {
			  	eval(req.responseText);
			  }
			  catch(e) {
			  	window.alert(e);
			  }
			  //banned = req.responseText;
			}
		}
	}
 	//if(!viewer) {
  		infoadd('online',1);
    //}
    var onc_u = '0';
    if(invizible) onc_u = '1';
    req.open(null, OnlChaturl + "&viewer=" + viewer, true);
    req.send({ 'in': onc_u , last_id: lastID})
    }
}


function Do_Send()
{
	if(!globcanl)
	{
        var not_send = '0';
        var cct = my_getbyid('mess');
        var priv = my_getcookie( 'strchat_curr_status' );
        var select_user = my_getcookie( 'strchat_user_active' );
        var select_name = user_active_name;
        var is_private = '0';
        var select_private = '0';
        var is_say = '0';
        var select_say = '0';
        currentChatText = cct.value;

        if(!select_name)
        {
        	select_name = get_select_name()
        }

        if (currentChatText != '')
        {
              sarray[3] = sarray[2];
              sarray[2] = sarray[1];
              sarray[1] = currentChatText;
              if(sarray[1] == sarray[2] && sarray[2] == sarray[3])
              {
              	alert( error_flood )
              	return false;
              }
              if(priv > 0)
              {
              		is_private = '1';
              }
              else
              {
              		is_say = '1';
              }
              if( not_send == '0' )
              {

			var req = new JsHttpRequest();
			req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.responseJS) {
					        try {
					        	eval(req.responseJS);
					        }
					        catch(e) {
					        	window.alert(e);
					        }
					}
				infoadd('send',2);
				}
			}
	                infoadd('send',1);
			req.caching = false;
			req.open(null, SendChaturl + "&viewer=" + viewer , true);
			req.send({ Post: currentChatText, private: is_private, say: is_say, s_user: select_user, s_name: select_name, last_id_s: lastID });


              	cct.value = '';
              	cct.focus();
              }
              else
              {
              	cct.value = '';
              	cct.focus();
              }
        }
        else {
        	//alert("Ââåäòå òåêñò");
        }
        return false;
   }
}


function Do_Send_file() {
	if(!globcanl)
	{
	var ffile = my_getbyid('up_file');
    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
        	//if(!viewer)
			//{
				infoadd('send',2);
			//}
			            if (req.responseJS) {
							if(req.responseJS)
							{
							eval(req.responseJS);
							}
						}
						//Do_Load(viewer);
		}
    }
    //if(!viewer)
    //{
    	infoadd('send',1);
    //}
    req.open(null, SendChaturl+'&upload=true', true);
    req.send( { 'file': ffile } );
    }
}




function see_ban_list()
{
	//ShowTip('banned');
	//var ban_c = (document.getElementById) ? document.getElementById('ban_content') : eval("document.all['ban_content']");
	banned_drag = my_getbyid("strchat-banned-drag");
	banned_main = my_getbyid("get-banned-strchat");
	banned_main.style.position = 'absolute';
	banned_main.style.display  = 'block';
	banned_main.style.zIndex   = 99;
	banned_main.style.left = '100px';
	banned_main.style.top  = '100px';
	Drag.init( banned_drag, banned_main );
	ban_c = my_getbyid('str-banned-content');
	ban_c.innerHTML = banned;
}

function strchat_banned_hide()
{
        document.getElementById("get-banned-strchat").style.display="none";
}


function get_info()
{
	var cct = my_getbyid('need_1');
	var cct2 = my_getbyid('need_2');
	var cct3 = my_getbyid('onlineList_');
	var w = document.body.clientHeight;
	var h3 = document.body.clientHeight;
	var c = h3 - cct.offsetHeight + cct2.offsetHeight
	inp2('width: ' + cct3.offsetWidth + '<br>');
}



function inp(id,date,type,name,uname,uid,msg)
{
  if(lastID<id)
  {
    var html;
    var onc_t = '';
    var viev_ = viewer;

    if (gradient_activate > 0) {
	    if(userlist[uid]) {
		    if (userlist[uid]['h1'] && userlist[uid]['h2'] && userlist[uid]['h3'] && name) {
		    	var cname = gradient(userlist[uid]['h1'],userlist[uid]['h2'],userlist[uid]['h3'],name);
		    }
		}
		else {
			var cname = name;
		}
	}
    else {
    	var cname = name;
    }

        if(viev_ == '0')
        {
              onc_t = "<a href='javascript:void(0);' onclick=\"add_user_to_bottom('" + uid + "');\"><b>" + cname + "</b></a>";
        }
        else
        {
              	//div_scroll1.scrollDown();
				//div_scroll1.stopScroll();

              if(s_mod_chat == '1')
              {
                  onc_t = "<a href='javascript:void(0);' onclick=\"add_user_to_bottom('" + uid + "');\"><b>" + name + "</b></a>";
              }
              else
              {
                 onc_t = "<b>" + cname + ":</b>";
              }
        }
    if(type == "0")
          html = "<div style='margin-left: 5px;'><i>" + date + "</i> " + onc_t + " " + msg + "</div>";
    else if(type == "1")
    {
          html = "<div style='margin-left: 5px;'><i>" + date + "</i> " + onc_t + " " + msg + "</div>";
    }
    else if(type == "2")
    {
          html = "<div style='margin-left: 5px;' class='darkrow3_'><i>" + date + "</i> " + onc_t + " " + msg + "</div>";
    }
    else if(type == "3")
          html = "<div style='margin-left: 5px;'><i>" + date + "</i> &nbsp;&nbsp;&nbsp;&nbsp; " + msg + "</div>";
    else if(type == "4")
          html = "<div style='margin-left: 5px;' class='darkrow3_'><i>" + date + "</i> " + onc_t + " " + msg + "</div>";
    else if(type == "5")
          html = "<div style='margin-left: 5px;'><i>" + date + "</i> " + onc_t + " " + msg + "</div>";
    else if(type == "6")
          html = "<div style='width:100%;'><div style='margin-left: 5px;'><i>" + date + "</i> " + onc_t + "</div><div style='text-align:center;'>" + msg + "</div></div>";
    else if(type == "7")
          html = "<div style='width:100%;'>" + msg + "</div>";
    else if(type == "ign")
          html = "";
    else
          html = "<div style='margin-left: 5px;'><i>" + date + " " + cname +"</i> <b>&nbsp;&nbsp;&nbsp;&nbsp; " + msg + "</b></div>";
      if(id!='bot')
      lastID = id;
    insertO = document.getElementById("outputList_");
    onetxt=insertO.innerHTML;
    newtxt=html;
    insertO.innerHTML=onetxt+newtxt;



  }
}
function inp2(msg)
{
	var html;
	html = msg;
	insertO = document.getElementById("outputList_");
	onetxt=insertO.innerHTML;
    newtxt=html;
    insertO.innerHTML=onetxt+newtxt;
}

function inp3(msg)
{
	var html;
	html = msg;
	insertO = document.getElementById("plugins_container");
    newtxt=html;
    insertO.innerHTML=newtxt;
}

function added_notice(notice_text,id)
{
	if(lastID<id) {
	lastID = id;
	html = "<div style='width:100%;'>" + notice_text + "</div>";
    insertO = document.getElementById("outputList_");
    onetxt=insertO.innerHTML;
    newtxt=html;
    insertO.innerHTML=onetxt+newtxt;
	}
}


function set_sending_command(txt)
{
	addin(txt,1);
	Do_Send();
	return false;
}

function clear_inp()
{	document.forms['chatForm'].elements['mess'].value = '';
	document.forms['chatForm'].elements['mess'].focus();
}

function addin(text,type)
{
        if(type)
        	document.forms['chatForm'].elements['mess'].value = text;
        else
        	document.forms['chatForm'].elements['mess'].value = text + document.forms['chatForm'].elements['mess'].value;
        document.forms['chatForm'].elements['mess'].focus();
}

function add_smile(text)
{	document.forms['chatForm'].elements['mess'].value = document.forms['chatForm'].elements['mess'].value + text;
	document.forms['chatForm'].elements['mess'].focus();
}


function infoadd(param,c)
{
        var dat = null;

        if( param != 'update' )
        {

	        if(counter_log_1 == 99 || counter_log_2 == 99)
	        {
	        	counter_log_1 = counter_log_1 - 50;
	        	counter_log_2 = counter_log_2 - 50;
	        }

	        if(counter_log_3 == 99 || counter_log_4 == 99)
	        {
	        	counter_log_3 = counter_log_3 - 50;
	        	counter_log_4 = counter_log_4 - 50;
	        }

	        if(counter_log_5 == 99 || counter_log_6 == 99)
	        {
	        	counter_log_5 = counter_log_5 - 50;
	        	counter_log_6 = counter_log_6 - 50;
	        }

	        if( param == 'load' )
	        {
	        	if( c == '1' ) {
	        	counter_log_1++;
	        	}
	        	if( c == '2' ) {
	        	counter_log_2++;
	        	}
	        }
	        if( param == 'send' )
	        {
	        	if( c == '1' ) {
	        	counter_log_3++;
	        	}
	        	if( c == '2' ) {
	        	counter_log_4++;
	        	}
	        }
	        if( param == 'online' )
	        {
	        	if( c == '1' ) {
	        	counter_log_5++;
	        	}
	        	if( c == '2' ) {
	        	counter_log_6++;
	        	}
	        }
	        dat = "<span style='font-size:11px;'>Load: <span style='color:green;'>" + counter_log_1 + "</span>:<span style='color:red;'>" + counter_log_2 + "</span> Send: <span style='color:green;'>" + counter_log_3 + "</span>:<span style='color:red;'>" + counter_log_4 + "</span> On: <span style='color:green;'>" + counter_log_5 + "</span>:<span style='color:red;'>" + counter_log_6 + "</span></span>";

		}
		else {
			dat = b_5_3;
		}

		if(viewer != '1') {
			var idiv = my_getbyid('infoc');
        	idiv.innerHTML  =  dat;
        }
}

function addname(name)
{
        addin(""+ name + ": ");
        return false;//
}

function _stop_scroll()
{
	div_scroll1.stopScroll();
}

function _start_scroll(stop)
{
	div_scroll1.scrollDown();
	div_scroll1.stopScroll();
}

function start_scroll()
{
        if (scroll_timer==null) scroll_timer = setInterval('_start_scroll();',20)
}

function stop_scroll()
{
        if (scroll_timer!=null) {clearInterval(scroll_timer); scroll_timer = null;}
        _stop_scroll();
}

function start_stopscroll()
{
	var scdat = my_getbyid('conf_scroll');
	if( scdat.value == '>>' ) {
		start_scroll();
		scdat.value = '||';
		scdat.title = b_1_1;
		//div_scroll1.scrollDown();
	}
	else {
		stop_scroll();
		scdat.value = '>>';
		scdat.title = b_1_2;
	}
}

function msgdecode()
{
	var strTable1="qwertyuiop[]asdfghjklzxcvbnm,.QWERTYUIOP{}ASDFGHJKL:ZXCVBNM<>éöóêåíãøùçõúôûâàïðîëäÿ÷ñìèòüáþÉÖÓÊÅÍÃØÙÇÕÚÔÛÂÀÏÐÎËÄÆß×ÑÌÈÒÜÁÞ'\";ýÝæ";
	var strTable2="éöóêåíãøùçõúôûâàïðîëäÿ÷ñìèòüáþÉÖÓÊÅÍÃØÙÇÕÚÔÛÂÀÏÐÎËÄÆß×ÑÌÈÒÜÁÞqwertyuiop[]asdfghjklzxcvbnm,.QWERTYUIOP{}ASDFGHJKL:ZXCVBNM<>ýÝæ'\";";
	var strRet = "";
	var getm = my_getbyid('mess');
	var strSrc = getm.value;
	var cTmp, nTmp;
	for (var i=0 ; i < strSrc.length ; i++)
	{
		cTmp = strSrc.charAt(i);
		nTmp = strTable1.indexOf(cTmp);
		if (nTmp >= 0) cTmp = strTable2.charAt(nTmp);
		strRet += cTmp;
	}
	getm.value = strRet;
	getm.focus();
}


function onc(viewer)
{
        // Ïîäãîòâàëèâàåì îáúåêò.
        if(!viewer)
        {
                infoadd(i_onload);
        }
        var onc_u = '0';
        if(invizible) onc_u = '1';
        req3.open('POST', OnlChaturl , true);
        // Ïîñûëàåì.
                req3.send({'in': onc_u});
        return false;
}



function timerReStart(refresh)
{
        timerStop();
        counter_log_1 = 0;
        counter_log_2 = 0;
        counter_log_3 = 0;
        counter_log_4 = 0;
        counter_log_5 = 0;
        counter_log_6 = 0;
        //doLoad();
        infoadd('update');
        canl = false;
        timerStart(refresh);
}

function timerStart(refresh,viewer)
{
        if (tLoad==null) tLoad = setInterval('Do_Load('+ viewer +');',refresh*1000)
        if (tUser==null) tUser = setInterval('On_Load('+ viewer +');',refresh*1000*5)
}

function timerStop()
{
        if (tLoad!=null) {clearInterval(tLoad); tLoad = null;}
        if (tUser!=null) {clearInterval(tUser); tUser = null;}
}

function scr()
{
        var o_list = document.getElementById('outputList_');
        var scrollarea = o_list.scrollHeight - o_list.offsetHeight;
        var scroll = true;
        var sss;
        if(scrollarea > 0 && (scrollarea - o_list.scrollTop) > 5) scroll = false;
        sss = scrollarea;
        scrollarea = o_list.scrollHeight - o_list.offsetHeight;
        if(scroll){
                   o_list.scrollTop=o_list.scrollHeight - o_list.offsetHeight;
        }
}


function doOnKeyDown(e) {
        var event = null;
        if(e) {
                event = e;
        } else {
                event = window.event;
        }
        if (event.keyCode==13) {
                   onClickSend();
                event.preventDefault ?
        event.preventDefault() :
        event.returnValue = false;
        }
}

function debug(text) {
        var d = document.getElementById('debug');
        d.innerHTML += text+'</br>';
}

function associateEventWithObject(_obj, _method, _param) {
        return function(e)
        {
                return _obj[_method](new MouseEvent(e), this, _param);
        };
}

function isClass(_elem, _className) {
        return _elem && _elem.className &&
                new RegExp('\\b'+_className+'\\b').test(_elem.className);
}

function addClass(_elem, _className) {
        modifyClass(_elem, _className, function(_elem, _className)
                {
                        if (_elem.className && !/^\s*$/.test(_elem.className))
                        // element className field is set to non-empty string,
                        // so we're going to add one to class to element
                        {
                                if (!isClass(_elem, _className))
                                        _elem.className=_elem.className+" "+_className;
                        }
                        else
                                _elem.className=_className;
                }
        );
}

function delClass(_node, _className) {
        if (_node && (_node.className!=undefined))
        {
                _node.className=_node.className.replace(" "+_className, "");
                _node.className=_node.className.replace(_className, "");
        }
}

function modifyClass(_elem, _className, _func) {
        if (_elem.length)
                for (var i=0; i<_elem.length; i++)
                        _func(_elem[i], _className);
        else
                _func(_elem, _className);
}

function trim(x) {
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

function clickSend() {
        onClickSend();
        var m = document.getElementById('mess');
        m.focus();
}

function emoticon(code,param1,param1)
{
        addin(' ' + code + ' ');
}

function emo_pop()
{
                window.open("index.php?act=legends&amp;CODE=emoticons&amp;s=","Legends","width=250,height=500,resizable=yes,scrollbars=yes");
        return false;//
}

function strchat_hide()
{
        document.getElementById("get-strchat").style.display="none";
        timerStop();
}

function call_strchat()
{
        var not_loaded_yet = 0;

        if ( use_enhanced_js )
        {
                try
                {
                        xml_strchat_init();
                        not_loaded_yet = 1;
                }
                catch( e )
                {
                        alert(e);
                        not_loaded_yet = 0;
                }
        }

        if ( ! not_loaded_yet )
        {
                ipb_var_base_url = ipb_var_base_url.replace( '&amp;', '&' );
                //window.open( ipb_var_base_url + 'automodule=strchat&CODE=pre','STRChat','width=600,height=300,resizable=yes,scrollbars=yes');
        }
        else
        {
                timerStart(refresh,true);
        }

}

function xml_strchat_init()
{
        strchat_main     = document.getElementById( 'get-strchat' );
        strchat_drag            = document.getElementById( 'strchat-drag' );
        strchat_bookmark = document.getElementById( 'strchat-bookmark' );

        strchat_main.style.position = 'absolute';
        strchat_main.style.display  = 'block';
        strchat_main.style.zIndex   = 99;

         //----------------------------------
         // Not loaded? INIT
         //----------------------------------

         if ( ! strchat_loaded )
         {
                 //----------------------------------
                 // Figure width and height
                 //----------------------------------

                 var my_width  = 0;
                 var my_height = 0;

                 if ( typeof( window.innerWidth ) == 'number' )
                 {
                         //----------------------------------
                         // Non IE
                         //----------------------------------

                         my_width  = window.innerWidth;
                         my_height = window.innerHeight;
                 }
                 else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
                {
                        //----------------------------------
                        // IE 6+
                        //----------------------------------

                        my_width  = document.documentElement.clientWidth;
                        my_height = document.documentElement.clientHeight;
                }
                else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
                {
                        //----------------------------------
                        // Old IE
                        //----------------------------------

                        my_width  = document.body.clientWidth;
                        my_height = document.body.clientHeight;
                }

                //----------------------------------
                // Get div height && width
                //----------------------------------

                var divheight = parseInt( strchat_main.style.Height );
                var divwidth  = parseInt( strchat_main.style.Width );

                divheight = divheight ? divheight : 400;
                divwidth  = divwidth  ? divwidth  : 400;

                //----------------------------------
                // Got it stored in a cookie?
                //----------------------------------

                var divxy = my_getcookie( 'ipb-strchat-div' );
                var co_ords;

                if ( divxy && divxy != null )
                {
                        co_ords = divxy.split( ',' );

                        //----------------------------------
                        // Got co-ords?
                        //----------------------------------

                        if ( co_ords.length )
                        {
                                var final_width  = co_ords[0];
                                var final_height = co_ords[1];

                                if ( co_ords[0] > my_width )
                                {
                                        //----------------------------------
                                        // Keep it on screen
                                        //----------------------------------

                                        final_width = my_width - divwidth;
                                }

                                if ( co_ords[1] > my_height )
                                {
                                        //----------------------------------
                                        // Keep it on screen
                                        //----------------------------------

                                        final_height = my_height - divheight;
                                }

                                strchat_main.style.left = final_width  + 'px';
                                strchat_main.style.top  = final_height + 'px';
                        }
                }
                else
                {
                        //----------------------------------
                        // Reposition DIV roughly centered
                        //----------------------------------

                        strchat_main.style.left = my_width  / 2  - (divwidth / 2)  + 'px';
                        strchat_main.style.top  = my_height / 2 - (divheight / 2 ) + 'px';
                }

                Drag.cookiename = 'ipb-strchat-div';
                Drag.init( strchat_drag, strchat_main );

                strchat_loaded = 1;
                Do_Load(true);
                On_Load(true);
        }
}

function strchat_admin_hide()
{
        document.getElementById("get-admin-strchat").style.display="none";
}

function open_admin_menu()
{
	load_admin_panel();
}

function strchat_plugins_hide()
{
        document.getElementById("get-plugins-strchat").style.display="none";
}

function open_plugins_menu()
{
	load_plugins_panel();
}



function strchat_call_hide()
{
        document.getElementById("get-call-strchat").style.display="none";
}

function call_strchat_call()
{
        var not_loaded_yet = 0;

        if ( use_enhanced_js )
        {
                try
                {
                        xml_strchat_call_init();
                        not_loaded_yet = 1;
                }
                catch( e )
                {
                        alert(e);
                        not_loaded_yet = 0;
                }
        }

        if ( ! not_loaded_yet )
        {
                addin('!call ');
        }
}

function xml_strchat_call_init()
{
        strchat_call_main     = document.getElementById( 'get-call-strchat' );
        strchat_call_drag            = document.getElementById( 'strchat-call-drag' );
        strchat_call_bookmark = document.getElementById( 'strchat-call-bookmark' );

        strchat_call_main.style.position = 'absolute';
        strchat_call_main.style.display  = 'block';
        strchat_call_main.style.zIndex   = 99;

         //----------------------------------
         // Not loaded? INIT
         //----------------------------------

         if ( ! strchat_call_loaded )
         {
                 //----------------------------------
                 // Figure width and height
                 //----------------------------------

                 var my_width  = 0;
                 var my_height = 0;

                 if ( typeof( window.innerWidth ) == 'number' )
                 {
                         //----------------------------------
                         // Non IE
                         //----------------------------------

                         my_width  = window.innerWidth;
                         my_height = window.innerHeight;
                 }
                 else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
                {
                        //----------------------------------
                        // IE 6+
                        //----------------------------------

                        my_width  = document.documentElement.clientWidth;
                        my_height = document.documentElement.clientHeight;
                }
                else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
                {
                        //----------------------------------
                        // Old IE
                        //----------------------------------

                        my_width  = document.body.clientWidth;
                        my_height = document.body.clientHeight;
                }

                //----------------------------------
                // Get div height && width
                //----------------------------------

                var divheight = parseInt( strchat_call_main.style.Height );
                var divwidth  = parseInt( strchat_call_main.style.Width );

                divheight = divheight ? divheight : 400;
                divwidth  = divwidth  ? divwidth  : 400;

                //----------------------------------
                // Got it stored in a cookie?
                //----------------------------------

                var divxy = my_getcookie( 'ipb-strchat-call-div' );
                var co_ords;

                if ( divxy && divxy != null )
                {
                        co_ords = divxy.split( ',' );

                        //----------------------------------
                        // Got co-ords?
                        //----------------------------------

                        if ( co_ords.length )
                        {
                                var final_width  = co_ords[0];
                                var final_height = co_ords[1];

                                if ( co_ords[0] > my_width )
                                {
                                        //----------------------------------
                                        // Keep it on screen
                                        //----------------------------------

                                        final_width = my_width - divwidth;
                                }

                                if ( co_ords[1] > my_height )
                                {
                                        //----------------------------------
                                        // Keep it on screen
                                        //----------------------------------

                                        final_height = my_height - divheight;
                                }

                                strchat_call_main.style.left = final_width  + 'px';
                                strchat_call_main.style.top  = final_height + 'px';
                        }
                }
                else
                {
                        //----------------------------------
                        // Reposition DIV roughly centered
                        //----------------------------------

                        strchat_call_main.style.left = my_width  / 2  - (divwidth / 2)  + 'px';
                        strchat_call_main.style.top  = my_height / 2 - (divheight / 2 ) + 'px';
                }

                Drag.cookiename = 'ipb-strchat-call-div';
                Drag.init( strchat_call_drag, strchat_call_main );

                strchat_call_loaded = 1;
        }
}



// gives up and down scroll buttons to images, spans, ... named up_name, down_name, respectively.
// will keep the default scroll_box's style overflow if it encounters errors (so make overflow: auto;)

// usage: put this after the scrollbox div:  var div_scroll1 = new TextScroll('div_scroll1', 'scroll_box');
function TextScroll(scrollname, div_name, up_name, down_name)
{
    this.div_name = div_name;
    this.name = scrollname;
    this.scrollCursor = 1;
    this.speed = 10;
    this.timeoutID = 1;
    this.div_obj = null;
    this.up_name = up_name;
    this.dn_name = down_name;

	{
        if (document.getElementById) {
            div_obj = document.getElementById(this.div_name);
            if (div_obj) {
                this.div_obj = div_obj;
                this.div_obj.style.overflow = 'auto';
            }
            div_up_obj = document.getElementById(this.up_name);
            div_dn_obj = document.getElementById(this.dn_name);
            if (div_up_obj && div_dn_obj) {
                div_up_obj.setAttribute("onmouseover", scrollname + ".scrollUp();")
                div_up_obj.setAttribute("onmouseout", scrollname + ".stopScroll();")

                div_dn_obj.setAttribute("onmouseover", scrollname + ".scrollDown();")
                div_dn_obj.setAttribute("onmouseout", scrollname + ".stopScroll();")



            }
        }
    }

this.stopScroll = function() {
        clearTimeout(this.timeoutID);
    }

this.scrollUp = function() {
        if (this.div_obj) {
            this.scrollCursor = (this.scrollCursor - this.speed) < 0 ? 0 : this.scrollCursor - this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollUp()", 60);
        }
    }

this.scrollDown = function() {
        if (this.div_obj) {
            this.scrollCursor += this.speed;
            this.div_obj.scrollTop = this.scrollCursor;
            this.timeoutID = setTimeout(this.name + ".scrollDown()", 60);
        }
    }

this.resetScroll = function() {
        if (this.div_obj) {
            this.div_obj.scrollTop = 0;
            this.scrollCursor = 0;
        }
    }
}



function ShowTip(fArg,glob)
{
	var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");
	if (tooltipOBJ != null) {
		if (glob)
		{
			var help_glob = (document.getElementById) ? document.getElementById('help_content') : eval("document.all['help_content']");
			var help_1 = (document.getElementById) ? document.getElementById('help_1') : eval("document.all['help_1']");
			var help_nav = (document.getElementById) ? document.getElementById('help_nav') : eval("document.all['help_nav']");
			var new_help = tooltipOBJ.innerHTML;
			//help_nav.style.display = "block";
			if(fArg == '1')
				var new_help_ = help_1.innerHTML;
			else
				var new_help_ = new_help.replace(/<!--nav-->/, help_nav.innerHTML);
			help_glob.innerHTML=new_help_;
			//help_glob.style.visibility = "visible";
		}
		var tooltipLft = (document.body.offsetWidth?document.body.offsetWidth:document.body.style.pixelWidth) - (tooltipOBJ.offsetWidth?tooltipOBJ.offsetWidth:(tooltipOBJ.style.pixelWidth?tooltipOBJ.style.pixelWidth:380)) - 30;
		var tooltipTop = 10;
		if (navigator.appName == 'Netscape') {
			tooltipTop = (document.body.scrollTop>=0?document.body.scrollTop+10:event.clientY+10);
 			tooltipOBJ.style.top = tooltipTop+"px";
			tooltipOBJ.style.left = tooltipLft+"px";
		}
		else {
			tooltipTop = (document.body.scrollTop>=0?document.body.scrollTop+10:event.clientY+10);
			tooltipTop = (document.body.scrollTop>=0?document.body.scrollTop+10:event.clientY+10);
			if ((event.clientX > tooltipLft) && (event.clientY < (tooltipOBJ.scrollHeight?tooltipOBJ.scrollHeight:tooltipOBJ.style.pixelHeight) + 10)) {
				tooltipTop = (document.body.scrollTop?document.body.scrollTop:document.body.offsetTop) + event.clientY + 20;
			}
			tooltipOBJ.style.left = tooltipLft;
			tooltipOBJ.style.top = tooltipTop;
		}
		if (glob && fArg == '1') {
		tooltipOBJ.style.visibility = "visible"; }
		if (!glob) {
		tooltipOBJ.style.visibility = "visible"; }
	}
}
function HideTip(fArg)
{
	var tooltipOBJ = (document.getElementById) ? document.getElementById('tt' + fArg) : eval("document.all['tt" + fArg + "']");
	if (tooltipOBJ != null) {
		tooltipOBJ.style.visibility = "hidden";
	}
}


function get_clock() {

var mydate=new Date()

var year=mydate.getFullYear();var month=mydate.getMonth();var day=mydate.getDate();
if (day < 10) {daym="0"+day;}
month++;
if (month < 10) {month="0"+month;}

var hours=mydate.getHours();var minutes=mydate.getMinutes();var seconds=mydate.getSeconds();

if (hours<=23) {hours=""+hours;}
if (minutes<=9) {minutes="0"+minutes;}
if (seconds<=9) {seconds="0"+seconds;}

var cdate= day + "." + month + "." + year + " " + hours + ":" + minutes + ":" + seconds;

if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate

}


function refresh_clock() {
if (document.all||document.getElementById)
setInterval("get_clock()",1000)
}


// (c) august chat

function Hex ( B )
{
var Chars = "0123456789abcdef";
return Chars.charAt (B >> 4) + Chars.charAt (B & 0x0F)
}


function gradient ( C1, C2, C3, Str )
{
	function l ( Str )
	{
		while (re = /[^]+/.test (Str))
			Str = Str.replace (/[^]+/g, "");
			return Str.replace (/<[^>]+>?/g, "").replace (/&([a-z]{2,}\d*|#\d+|#x[\da-f]{2});/gi, " ").length
	}

	function c ( R, G, B, Str )
	{
		return "<font color=#" + Hex (R) + Hex (G) + Hex (B) + ">" + Str + "</font>"
	}

	function g ( C1, C2, l, s )
	{
		C1 = parseInt ("0x0" + C1.substr (1))
		C2 = parseInt ("0x0" + C2.substr (1))
		var R1 = C1 >> 16, G1 = (C1 >> 8) & 0xFF, B1 = C1 & 0xFF
		var R2 = C2 >> 16, G2 = (C2 >> 8) & 0xFF, B2 = C2 & 0xFF
		var Res = ""
		var d = l - s
		R2 -= R1; G2 -= G1; B2 -= B1
		for (var i = 0; iS < Str.length;) {
			if (Str.charAt (iS) == '<') {
				for (var t = 0; iS < Str.length; iS++) {
					Res += Str.charAt (iS)
					if (Str.charAt (iS) == '') t++
					else if (Str.charAt (iS) == '') t--
					else if (Str.charAt (iS) == '>' && !t) break
				}
				iS++
			} else if (i != l) {
				var S = (Str.charAt (iS) == '&' && /^(&([a-z]{2,}\d*|#\d+|#x[\da-f]{2});)/i.test (Str.substr (iS))) ? RegExp.$1 : Str.charAt (iS)
				Res += d ? c (R1 + i * R2 / d, G1 + i * G2 / d, B1 + i * B2 / d, S) : c (R1, G1, B1, S)
				iS += S.length
				i++
			} else
				break
		}
		return Res
	}
	Str = Str.replace (/^\s+|\s+$/g, "")
	var iS = 0
	var Len = l (Str)
	return C2 ? g (C1, C2, Math.floor (Len / 2), 0) + g (C2, C3, Math.round (Len / 2), 1) : g (C1, C3, Len, 1)
}


function s(obj)
{
    document.body.innerHTML+='<SPAN ID="objectInfo"></SPAN>';
    var val,c,c1="#000000",c2="#333333",res="";
    for (var i in obj)
    {
        //if (/^on/.test(i)) continue; óáðàòü ìåòîäû EVENTà
        if (c == c1) c = c2; else c = c1;
        res += '<tr><td bgcolor='+c+'>'+"obj"+'.'+i+'</td><td bgcolor='+((c==c1)?c2:c1)+'>&nbsp;'+obj[i]+'</td></tr>';
    }
    objectInfo.innerHTML='<table cellspacing=0 border=1 bordercolor=#aaaaaa style="color: yellow">'+res+'</table>';
}


function clickPic(el, url){
  if(!strNew){
    window.open(el.parentNode.parentNode.getElementsByTagName('a')[0].href);
  }else{
    window.open(url);
  }
}