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

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

	updateUserStatus = function(user_id)
	{
		var url = _php_status_update_url;

		var pars = null;

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

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

		new Ajax.Request(url+ '&action=json&id='+user_id, {
			method: 'get',
		  	onSuccess: function(response) {
		  		var data = response.responseText.evalJSON();

		  		if (typeof data.user_id != 'undefined' && typeof data.status != 'undefined') {
		  			$$('div[rel=user_stars_'+user_id+']').each(function(el){
						el.className='stars_'+data.status;
					});
				}

		  		if (typeof data.user_id != 'undefined' && typeof data.status_name != 'undefined') {
		  			$$('div[rel=user_status_'+user_id+']').each(function(el){
						el.innerHTML = data.status_name;
					});
				}
		  	}
		});



	}

	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);
        
        function setUserInfo() {
            if (typeof Cookie.get(_info_name) == 'string') {
                    var userInfo = Cookie.get(_info_name).split(':');

                    if (userInfo.length) {
                            //Посетитель не залогинен
                            if (userInfo[1] == -1) {
                                    document.getElementById('login_user_false').style.display = 'block';
                                    document.getElementById('login_user_true').style.display = 'none';
                                    try { //На главной нет этого элемента
                                        document.getElementById('login_container').style.width = '280px';
                                    } catch (e) {/**/}
                            } else {                                                            
                                    if (userInfo.length > 1 && userInfo[1] == 0)
                                            document.getElementById('login_mail_enabled').style.display = '';
                                    document.getElementById('login_user_false').style.display = 'none';
                                    document.getElementById('login_user_true').style.display = '';
                                    document.getElementById('login_user_lnk').setAttribute('title', decodeURIComponent(userInfo[0]).replace('+', ' '));
                                    document.getElementById('login_user_lnk').innerHTML = decodeURIComponent(userInfo[0]).split('+')[0];
                                    try { //На главной нет этого элемента
                                        document.getElementById('login_container').style.width = '345px';
                                    } catch (e) {/**/}
                            }
                    }
            } else {                    
                    new Ajax.Request(_info_url, {
                            onSuccess: function(transport) {
                                    var data = transport.responseText.evalJSON();
                                    if (typeof data.nameShort != 'undefined') {                                            
                                            if (data.isOpenid == -1) { //Посетитель не залогинен
                                                    document.getElementById('login_user_false').style.display = 'block';
                                                    document.getElementById('login_user_true').style.display = 'none';
                                                    try { //На главной нет этого элемента
                                                        document.getElementById('login_container').style.width = '280px';
                                                    } catch (e) {/**/}
                                            } else {
                                                    if (data.isOpenid == 0)
                                                    document.getElementById('login_mail_enabled').style.display = '';
                                                    document.getElementById('login_user_false').style.display = 'none';
                                                    document.getElementById('login_user_true').style.display = '';
                                                    document.getElementById('login_user_lnk').innerHTML = decodeURIComponent(data.nameFull).split('+')[0];
                                                    document.getElementById('login_user_lnk').setAttribute('title', decodeURIComponent(data.nameShort).replace('+', ' '));
                                                    try { //На главной нет этого элемента
                                                        document.getElementById('login_container').style.width = '345px';
                                                    } catch (e) {/**/}
                                            }
                                            Cookie.set(_info_name, data.nameShort+':'+data.isOpenid, 0, '/', _info_domain, false);
                                    }
                            }
                    }
                    );
            }
        }
