	String.prototype.replaceAll = function(search, replace){
 		return this.split(search).join(replace);
	};

function setBan(user_id, ip, action_url)
{
	var url = _php_url;

	var pars = null;

	if (!action_url)
		action_url = url;

	if ($('userBannedForm') != null)
		pars = Form.serialize($('userBannedForm'));

	if (user_id) {
		url += '&type=user&user='+user_id;
		var className = _php_user_ban_label + user_id;
	} else if (ip) {
		url += '&type=ip&ip='+ip;
		var className = _php_ip_ban_label + ip.replaceAll('.', '');
	}

	new Ajax.Updater('facebox_content', action_url, {
	  method: 'get',
	  parameters: pars
	});

	new Ajax.Request(url + '&action=json',
	{
		method: 'get',
	  	onSuccess: function(response) {
	  		var data = response.responseText.evalJSON();
	  		if (typeof data.label_id != 'undefined') {

				$$('a.' + className).each(function(dom){
					dom.innerHTML = '<font style="color:#c31f1b">Забанен'+(user_id ? '' : ' IP')+(typeof data.from_date != 'undefined' ? ' c '+data.from_date : '')+'</font>';
				});
			} else {
				$$('a.' + className).each(function(dom){
					dom.innerHTML = 'Забанить'+(user_id ? '' : ' IP');
				});

				if (typeof data.count_warning != 'undefined') {
					$$('div[id*=warnline_'+user_id+']').each(function(el){
						el.className = 'warn_'+data.count_warning
					});
				}
			}
	  	}
	});
}

warn = function(user_id)
{
	var url = _php_warning_url;
	var className = null;
	var pars = null;

	if ($('form') != null) {
		var pars = Form.serialize($('form'));
	}

	if (user_id) {
		url += '&user='+user_id;
		var className = _php_user_ban_label + user_id;
	}

	new Ajax.Updater('facebox_content', url + '&action=add', {
	  method: 'post',
	  parameters: pars
	});

	new Ajax.Request(url+ '&action=json', {
		method: 'get',
	  	onSuccess: function(response) {
	  		var data = response.responseText.evalJSON();
	  		if (typeof data.user_id != 'undefined' && typeof data.count_warning != 'undefined') {
	  			$$('div[id*=warnline_'+data.user_id+']').each(function(el){
					el.className = 'warn_'+data.count_warning
				});
			}

			if (data.is_banned != undefined && data.is_banned == true) {
				$$('a.' + className).each(function(dom){
					dom.innerHTML = '<font style="color:#c31f1b">Забанен</font>';
				});
			}
	  	}
	});
}