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


	function setCurrent(id, src, type)
	{
		if ($('graph_' + id) == null)
			return void(0);

		$('Today_' + id).hide();
		$('CurToday_' + id).hide();
		$('Week_' + id).hide();
		$('CurWeek_' + id).hide();
		$('Month_' + id).hide();
		$('CurMonth_' + id).hide();

		switch (type){
			case 'Today':
				$('CurToday_' + id).show();
				$('Week_' + id).show();
				$('Month_' + id).show();
			break;
			case 'Week':
				$('CurWeek_' + id).show();
				$('Today_' + id).show();
				$('Month_' + id).show();
			break;
			case 'Month':
				$('CurMonth_' + id).show();
				$('Week_' + id).show();
				$('Today_' + id).show();
			break;
		}

		$('graph_' + id).src = src;

		return void(0);
	}

	function markWork(state)
	{
		$('selectCountry').disabled = state;
		$('selectCity').disabled = state;

		if (state){
			$('selectCity').style.background = '#eee';
			$('selectCountry').style.background = '#eee';
		} else {
			$('selectCity').style.background = '';
			$('selectCountry').style.background = '';
		}
	}


	function getCityList(url, countryId)
	{
		url += '&country=' + countryId;

		markWork(true);

		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(out) {

			array = $$('#selectCity option');
		  	for (var i = 1; i < array.length; i++){
				array[i].remove();
			}

	  		cityList = eval("("+out.responseText+ ")");
			select = $('selectCity');

	  		for (var i = 0; i < cityList.length; i++){
			  	select[i+1] = new Option(cityList[i].name, cityList[i].id);
			}
		  	markWork(false);
		  }
		});
	}

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

		var pars = null;

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

		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('.', '');
		}

		if (subjectField && subjectId) {
			url += '&'+subjectField+'='+subjectId;
			url += '&action=unban';
		}

		new Ajax.Updater('facebox_content', 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');
					});
				}
		  	}
		});
	}

	function checkEditor()
	{
		if (typeof Cookie.get(_ed_name) == 'string') {
			var url = _ed_url + '&t='+Math.random();
			new Ajax.Request(url, {
				onSuccess: function(out) {
					if (out.responseText.isJSON()) {
						var data = out.responseText.evalJSON();
						if (data.status == 'success') {
							eval(data.editor);
						}
					}
				}
			});
		}
	}

	addLoadEvent(checkEditor);
