var payment_details = {};
var order_details = {};
var need_to_stand = false;
var force_fire_events = false;
var splash = {};
var shadow = '';
var CONTENT_HEIGHT = 515;
//---------------------in_array--------------------------------------------------------------------*/
	var in_array = function(arr, v){
		for (var j = 0; j < arr.length; j++){
			if (v == arr[j]){return true};
		}
		return false;
	}
//---------------------page------------------------------------------------------------------------*/
	var page = new function(){
		this.print = function(html){
			win = window.open(document.location);
			win.document.write('');
			if (!html){
				var print_version = new Element('div');
				var content = document.getElement('.content').clone();
				content.inject(print_version);
				try{
					content.getElements('.hidden').each(function(c){
						c.dispose();
					});
					content.getElements('.submenu').each(function(c){
						c.dispose();
					});
					content.getElement('.path').dispose();
					content.getElement('.right_col').dispose();
				}
				catch(e){};
				content.getElements('a').each(function(a){
					a.setProperty('href', '#').setProperty('onclick', 'return false');
				});
				win.document.write(print_version.get('html'));
				win.document.write('<style type="text/css">img{border:0px;}*{cursor:default;color:black}.fl{float:left}.fr{float:right}</style>');
			}
			else{
				win.document.write(html);
			}
			win.document.close();
			return false;
		}
		this.refresh = function(s){
			document.location = document.location.pathname + (s !== false ? document.location.search : '');
		}
		this.remove_param = function(param){
			var loc = document.location.pathname;
			var params = document.location.search.substr(1).split('&');
			for (var i = 0; i < params.length; i++){
				if (params[i].substr(0, param.length + 1) == param + '=' || params[i] == ''){
					delete params[i];
				}
			}
			params = params.clean();
			return loc + (params.length ? '?' + params.join('&') : '');
		}
		this.add_param = function(param, value, url){
			var loc = document.location.pathname;
			var params = document.location.search.substr(1);
			if (url){
				loc = url.split('?')[0];
				params = url.split('?')[1] || '';
			}
			params = this.decode_params(params);
			params[param] = value ? value : '';
			return loc + (params ? '?' + this.encode_params(params) : '');
		}
		this.goto = function(url){
			document.location = url;
		}
		this.encode_params = function(params){
			params = params || {};
			var str = [];
			for (var i in params){
				str[str.length] = i + '=' + params[i];
			}
			return str.join('&');
		}
		this.decode_params = function(params){
			params = params || document.location.search.substr(1);
			params = params.split('&');
			arr = {};
			for (var i = 0; i < params.length; i++){
				if (params[i] != ''){
					arr[params[i].split('=')[0]] = params[i].split('=')[1];
				}
			}
			return arr;
		}
	}
//---------------------cut-------------------------------------------------------------------------*/
	var cut = function(str, len, d){
		d = d || '..';
		return (str.length > len ? str.substring(0, Math.floor(len/2)) + d + str.substring(str.length - Math.ceil(len/2)) : str);
	}
//---------------------format----------------------------------------------------------------------*/
	var format = function(str){
		str = str.toString().replace(/\s/g, '').replace('.', ',');
		var tmp = str.split(',');
		if (!tmp[1]){
			tmp[1] = '00';
		}
		else if (tmp[1].length < 2){
			tmp[1] += '0';
		}
		for (var i = tmp[0].length-1; i >=0; i--){
			tmp[0] = tmp[0].substring(0, i-2) + ' ' + tmp[0].substring(i-2);
			i = i-2;
		}
		return tmp.join().trim();
	}
//---------------------check_keyboard--------------------------------------------------------------*/
	var keyboard = {
		'capslock':{
			'title':'включен Caps Lock',
			'value':false
		},
		'russian':{
			'title':'выбрана русская раскладка клавиатуры',
			'value':false
		}
	}
	var keyboard_notice = {
		'show': function(params){
					var div = $('notice') || new Element('div', {'class': 'notice', 'id': 'notice'});
					var m = ['Внимание'];
					for (var i = 0; i < params.length; i++){
						if (keyboard[params[i]].value){
							m[m.length] = keyboard[params[i]].title;
						}
					}
					if (m.length > 1){
						div.set('html', '<span>' + m.join(', ') + '</span>');
						div.inject(document.body).removeClass('hidden');
					}
					else{
						keyboard_notice.hide();
					}
		},
		'hide': function(){
					var div = $('notice');
					if ($chk(div)){
						div.addClass('hidden');
					}
		}
	}
	document.addEvent('keypress', function(e){
		if (e.control){
			return;
		}
		else if (e.code >= 97 && e.code <= 122){
			keyboard.capslock.value = e.shift ? true : false;
			keyboard.russian.value = false;
		}
		else if (e.code >= 65 && e.code <= 90){
			keyboard.capslock.value = e.shift ? false : true;
			keyboard.russian.value = false;
		}
		else if ((e.code >= 1072 && e.code <= 1103) || e.code == 1105){
			keyboard.capslock.value = e.shift ? true : false;
			keyboard.russian.value = true;
		}
		else if ((e.code >= 1040 && e.code <= 1071) || e.code == 1125){
			keyboard.capslock.value = e.shift ? false : true;
			keyboard.russian.value = true;
		}
	}).addEvent('keydown', function(e){
		if (e.code == 20){
			keyboard.capslock.value = !keyboard.capslock.value;
			var div = $('notice');
			if ($chk(div)){
				keyboard_notice.show(['capslock', 'russian']);
			}
		}
	});
	window.addEvent('blur', function(e){
		keyboard.capslock.value = false;
		keyboard.russian.value = false;
	});
//---------------------case_number-----------------------------------------------------------------*/
	var case_number = function(n, first, second, last){
        var x = n % 100;
        if ((x % 10 == 1) && x != 11){
            return first || 1;
		}
        else if ((2 <= (x % 10) && (x % 10) <= 4) && (x / 10 != 1)){
            return second || 2;
		}
        else{
            return last || 3;
		}
    }
//---------------------get_key---------------------------------------------------------------------*/
	var get_key = function(e){
		var code = [e.event.charCode, e.event.which, e.event.keyCode];
		var key = code[0];
		if (code[0] == 0){
			key = '';
		}
		else if (typeof code[0] == 'undefined'){
			if (code[1] == '0'){
				key = '';
			}
			else{
				key = code[2];
			}
		}
		if (key == '144' || key == '145' || key < '32'){
			key = '';
		}
		return (!key) ? '' : String.fromCharCode(key);
	}
//---------------------filter_keys-----------------------------------------------------------------*/
	var filter_keys = function(_blur){
		var inputs = $$('.only_granted_symbols').filter(function(input){return !input.hasClass('activated')});
		inputs.each(function(input){
			input.addClass('activated');
			var re = '';
			if (input.get('name') == 'domain'){
				if (input.hasClass('dot')){
					re = /[^a-z0-9\-\.]/gi;
				}
				else{
					re = /[^a-z0-9\-]/gi;
				}
				input.addEvent('keypress', function(e){
					keyboard_notice.show(['russian']);
					var key = get_key(e);
					if (key){
						if (key.replace(re, '') == ''){
							e.stop();
							document.fireEvent('keypress', e);
						}
					}
				}).addEvent('blur', function(e){
					keyboard_notice.hide();
					var t = input.get('value');
					var punycode = t.substring(0,4) == 'xn--' ? true : false;
					if (punycode){
						t = t.replace('xn--', '');
					}
					t = t.replace(/\.{2,}/g, ".").replace(/\-{2,}/g, "-");
					if (t[t.length-1] == '.' || t[t.length-1] == '-'){
						t = t.substring(0, t.length-1);
					}
					if (t[0] == '.' || t[0] == '-'){
						t = t.substr(1);
					}
					t = t.replace(re, '');
					if (punycode){
						t = 'xn--' + t;
					}
					input.set('value', t);
				}).addEvent('focus', function(){
					keyboard_notice.show(['russian']);
				});
			}
			else if (input.get('name') == 'number'){
				re = /[^0-9\.\,]/g;
				input.addEvent('keypress', function(e){
					var key = get_key(e);
					if (key){
						if (key.replace(re, "") == ''){
							e.stop();
							document.fireEvent('keypress', e);
						}
					}
				}).addEvent('blur', function(e){
					var t = input.get('value');
					t = t.replace(/,/g, ".").replace(/\.{2,}/g, ".");
					if (t[t.length-1] == '.'){
						t = t.substring(0, t.length-1);
					}
					if (t[0] == '.'){
						t = '0' + t;
					}
					t = t.replace(re, '');
					input.set('value', t);
				});
			}
			else if (input.get('name') == 'integer'){
				re = /[^0-9]/g;
				input.addEvent('keypress', function(e){
					var key = get_key(e);
					if (key){
						if (key.replace(re, "") == ''){
							e.stop();
							document.fireEvent('keypress', e);
						}
					}
				}).addEvent('blur', function(e){
					var t = input.get('value');
					t = t.replace(re, '');
					input.set('value', t);
				});
			}
			if (_blur !== false){
				input.fireEvent('blur');
			}
		});
	}
//---------------------allow_tab_inject------------------------------------------------------------*/
	var allow_tab_inject = function(inp){
		inp.addEvent('keydown', function(e){
			if (e.code == 9){
				e.stop();
				inp.insertAtCursor('	', false);
			}
		}).addEvent('keypress', function(e){
			if (e.code == 9){
				e.stop();
			}
		});
	}
//---------------------pattern---------------------------------------------------------------------*/
	var pattern = function(str, array_in){
		for (var i = 0; i < array_in.length; i++){
			var re = new RegExp('\\$' + (i+1), 'g');
			str = str.replace(re, array_in[i]);
		}
		return str;
	}
//---------------------blinked---------------------------------------------------------------------*/
	var blinked = function(el, num, t){
		if (!t){
			var t = 300;
		}
		if (!num){
			var num = 5;
		}
		for (var i = 0; i < num*2; i++){
			setTimeout(
				function(){el.toggleClass('hot')},
				i*t
			);
		}
	}
//---------------------ajax_counter----------------------------------------------------------------*/
	var ajax_counter = 0;
	var show_loading = function(i){
		if (i > 0){
			i = Math.max(++ajax_counter, 1);
		}
		else{
			i = Math.max(--ajax_counter, 0);
		}
		if (i > 0){
			document.fireEvent('scroll');
			loading.removeClass('hidden');
		}
		else if (i < 1){
			loading.addClass('hidden');
		}
	}
	var loading = new Element('div', {
		'id': 'loading',
		'text': load_text,
		'class': 'loading hidden'
	});
	var Ajax = function(data, options){
		show_loading(1);
		var f = function(func_name){
			var func = options[func_name];
			options[func_name] = function(){
				if (func){
					func();
				}
				show_loading(0);
			}
		}
		f('onComplete');
		f('onCancel');
		options['data'] = data;
		if (!options['method']){
			options['method'] = 'post';
		}
		if (!options['onFailure']){
			options['onFailure'] = function(){
				if (this.status/100 >= 3){
					Message(
						'Ошибка',
						'К сожалению, cервер не отвечает или недоступен в данный момент.<br/>Пожалуйста, повторите действие через несколько минут.<br/>Если ошибка повторяется, обратитесь в техническую поддержку.',
						'Alert',
						0,
						425
					);
				}
				else{
					Message(
						'Ошибка',
						'К сожалению, произошла неизвестная ошибка.<br/>Повторить запрос еше раз?',
						'Confirm',
						function(){
							this.send(this.options.data);
						}.bind(this),
						320
					);
				}
			}
		}
		var r = new Request.JSON(options);
		r.send(data);
		return r;
	}
//---------------------messageboxs-----------------------------------------------------------------*/
	var Message = function(t, m, id, func, w, dont_close, ok_button_text){
		ok_button_text = ok_button_text ? ok_button_text : (id == 'Confirm' ? 'Да' : 'Ок');
		var ok = $(id).getElement('.ok');
		var title = $(id).getElement('.title');
		var box = $(id).getElement('.box');
		if ($chk(ok)){
			ok.removeEvents().set('value', ok_button_text);
			fix_button_width(ok, 1);
			ok.getParent().removeClass('sdisabled');
			ok.addEvent('click', function(e){
				if ($chk(e)){e.stop()};
				if (ok.getParent().hasClass('sdisabled')){return};
				if (func){
					func();
				}
				if (!dont_close){
					shadow.fireEvent('click');
				}
			});
		}
		if (t){
			title.set('html', t);
		}
		if (m){
			box.set('html', m);
		}
		if (w){
			$(id).setStyle('width', w + 'px');
		}
		else{
			$(id).setStyle('width', '250px');
		}
		if ($defined(splash.show)){
			splash.show(id);
		}
		else{
			setTimeout(function(){Message(t, m, id, func, w)}, 1000);
		}
		if ($chk(ok)){
			ok.focus();
		}
	}
//---------------------login_or_die----------------------------------------------------------------*/
	var login_or_die = function(){
		need_to_stand = true;
		force_fire_events = true;
		splash.show('login_or_reg');
	}
//---------------------change_agreement------------------------------------------------------------*/
	var change_agreement = function(){
		var change_agreement = $('change_agreement');
		if ($chk(change_agreement)){
			change_agreement.getElements('a').each(function(a){
				a.removeEvents().addEvent('click', function(e){
					if ($chk(e)){e.stop()};
					page.goto(page.add_param('agreement', a.get('id'), page.remove_param('agreement')));
				});
			});
			splash.show('change_agreement');
		}
	}
//---------------------sort_table------------------------------------------------------------------*/
	var sort_table = function(field){
		page.goto(page.add_param('sort', field, page.remove_param('sort')));
		return false;
	}
//---------------------fill_address----------------------------------------------------------------*/
	var fill_address = function(level){
		var result = '';
		address[level]['other'].sort();
		for (var i = 0; i < address[level]['first'].length; i++){
			result += '<a href="#">' + address[level]['first'][i] + '</a>';
		}
		for (var i = 0; i < address[level]['other'].length; i++){
			result += '<a href="#">' + address[level]['other'][i] + '</a>';
		}
		return result;
	}
//---------------------write_multiline_string------------------------------------------------------*/
	var write_multiline_string = function(id){
		var re = /\n/g;
		var str = $(id).get('html');
		$(id).set('html', str.replace(re, '<br/>')).setStyle('white-space', 'normal').removeClass('hidden').set('id', 'fake');
	}
//---------------------init_fileinput--------------------------------------------------------------*/
	var init_fileinput = function(c){
		var inp = c.getElement('input[type=text]');
		var button = c.getElement('input[type=button]');
		var file = c.getElement('input[type=file]');
		var timer = null;
		var rw = function(){
			var v1 = file.get('value').replace(/\\/g, '/').split('/');
			var v2 = inp.get('value');
			if (v1 && v1[v1.length-1] != v2){
				inp.set('value', v1[v1.length-1]);
				clearInterval(timer);
			}
		}
		file.addEvent('click', function(e){
			timer = setInterval(rw, 50);
		});
	}
//---------------------init_selects----------------------------------------------------------------*/
	var init_selects = function(){
		var conts = $$('.select').filter(function(div){return !div.hasClass('activated')});
		conts.each(function(div){
			div.addClass('activated');
			var timer = null;
			var inp = div.getElement('input[type=text]');
			if (!inp.getProperty('selectedIndex')){
				inp.setProperty('selectedIndex', 0);
			}
			var hid = div.getElement('input[type=hidden]');
			var sel = div.getElement('select');
			var list = div.getElement('.list');
			if (inp.get('readonly')){
				inp.addClass('origin');
			}
			list.links = list.getElements('a');
			if (list.links.length == 0){
				return;
			}
			list.center = list.getElement('.center');
			var filter_c = function(inp, list){
				if (!inp.getProperty('readonly')){
					var v = inp.get('value').toLowerCase();
					var count = 0;
					var _link = null;
					list.links.each(function(a){
						if (v != ''){
							var t = a.get('text').toLowerCase();
							//if (t.indexOf(v) != -1){
							if (t.substring(0, v.length) == v){
								a.setStyle('display', 'block');
								_link = a;
								count++;
							}
							else{
								a.setStyle('display', 'none');
							}
						}
						else{
							count++;
							a.setStyle('display', 'block');
						}
					});
					list.scrollTop = 0;
					if (count == 0){
						list.center.getLast().removeClass('hidden');
					}
					else{
						list.center.getLast().addClass('hidden');
					}
				}
			}
			var pos_list = function(){
				if (!div.hasClass('progressive')){return};
				if (Browser.Engine.trident){
					inp.setStyles({
						'width': '0px',
						'margin-right': inp.getProperty('width')
					});
				}
				var h = list.center.getHeight();
				var h2 = list.getHeight();
				var lc = list.links.length;
				var si = inp.getProperty('selectedIndex');
				var d = h/lc*si + (h2-h)/2 - 5;
				list.setStyle('margin-top', 0);
				list.setStyle('margin-top', Math.max(-d, -list.getTop()));
			}
			var select_point = function(el){
				var current = 0;
				list.links.each(function(a, i){
					if (a.hasClass('current')){
						current = i;
						a.removeClass('current');
					}
				});
				if (typeof el == 'object'){
					el.addClass('current');
				}
				else{
					if (el == 'next'){
						current++;
						while (current < list.links.length && list.links[current].style.display == 'none'){
							current++;
						}
					}
					else if (el == 'prev'){
						current--;
						while (current > 0 && list.links[current].style.display == 'none'){
							current--;
						}
					}
					else if (el == 'first'){
						current = 0;
						while (current < list.links.length && list.links[current].style.display == 'none'){
							current++;
						}
					}
					else if (el == 'current'){
						current = inp.getProperty('selectedIndex');
						while (current < list.links.length && list.links[current].style.display == 'none'){
							current++;
						}
					}
					if (current < 0){
						current = 0;
					}
					else if (current > list.links.length - 1){
						current = list.links.length - 1;
					}
					if (list.links[current].style.display == 'none'){
						var tmp = list.links.filter(function(a){return a.style.display != 'none'})[0];
						if ($chk(tmp)){
							tmp.addClass('current');
						}
					}
					else{
						list.links[current].addClass('current');
					}
				}
			}
			var write_value = function(){
				var point = list.getElement('.current');
				if ($chk(point)){
					point.fireEvent('mousedown');
					inp.fireEvent('blur');
				}
			}
			inp.setProperty('width', Math.max(parseInt(inp.getStyle('width')), parseInt(inp.style.width || 1), parseInt(inp.getProperty('width') || 1)));
			inp.addEvent('focus', function(e){
				filter_c(inp, list);
				select_point('current');
				if ($chk(e)){
					list.setStyle('width', parseInt(inp.getStyle('width')) + 22 + 'px');
					list.removeClass('hidden');
					pos_list();
					inp.setProperty('dx', window.getScroll().x);
					inp.setProperty('dy', window.getScroll().y);
				}
			}).addEvent('blur', function(){
				inp.setStyles({
					'width': inp.getProperty('width'),
					'margin-right': '0px'
				});
				list.addClass('hidden');
				if (inp.getTop() < window.getScroll().y){
					$(document.body).scrollTo(inp.getProperty('dx'), inp.getProperty('dy'));
				}
			}).addEvent('click', function(e){
				if ($chk(e)){e.stop()};
				list.removeClass('hidden');
			}).addEvent('keydown', function(e){
				list.removeClass('hidden');
				if (e.code == 40){
					select_point('next');
				}
				else if (e.code == 38){
					select_point('prev');
				}
				else if (e.code == 13){
					write_value();
				}
			}).addEvent('keyup', function(e){
				clearTimeout(timer);
				timer = setTimeout(
					function(){
						if ($chk(e) && (e.code == 40 || e.code == 38 || e.code == 13)){
							return;
						}
						inp.fireEvent('focus');
					},
					50
				)
			}).fireEvent('blur');
			div.setStyle('width', parseInt(inp.getProperty('width')) + 24 + 'px');
			list.links.each(function(a, i){
				a.setProperty('number', i).addEvent('mousedown', function(e){
					var changed = false;
					if (inp.get('value') != a.get('text')){
						changed = true;
					}
					inp.set('value', a.get('text').trim());
					inp.setProperty('selectedIndex', a.getProperty('number'));
					inp.fireEvent('keyup');
					if (a.getProperty('v') && $chk(hid)){
						hid.set('value', a.getProperty('v'));
					}
					if (changed && typeof inp.onChange == 'function'){
						inp.onChange();
					}
					if (changed && $chk(hid) && typeof hid.onChange == 'function'){
						hid.onChange();
					}
				}).addEvent('mouseenter', function(){
					select_point(a);
				}).addEvent('click', function(e){
					if ($chk(e)){e.stop()};
				});
				if (a.get('text') == inp.get('value')){
					inp.setProperty('selectedIndex', i);
				}
			});
			(new Element('span', {'class':'hidden', 'text':'Нет вариантов'})).inject(list.center);
		});
	}
//---------------------init_sliders----------------------------------------------------------------*/
	var init_sliders = function(){
		var conts = $$('.slider').filter(function(div){return !div.hasClass('activated')});
		conts.each(function(div){
			div.addClass('activated');
			div.inp = div.getElement('input[type=text]');
			var w = parseInt(div.inp.style.width);
			div.setStyle('width', w + 24 + 'px');
			div.steps = parseInt(div.getProperty('steps') || 10);
			div.variants = [{'title': 'Выберите значение'}];
			for (var i = 1; i <= div.steps; i++){
				div.variants[i] = {'title': '---'};
			}
			div.cur_point = 0;
			div.inp.set('value', div.variants[0].title);
			div.panel = div.getElement('div.textblock');
			div.slide = div.panel.getElement('div.slide');
			div.slide.half = 10;
			div.panel.setStyle('width', w + 22 + 'px');
			div.panel.pad = 0;
			div.offset = {};
			div.offset.min = div.slide.half;
			div.offset.max = w + 2 - div.slide.half - div.panel.pad;
			div.setSlide = function(step){
				div.slide.setStyle('left', step * (div.slideobj.options.grid.x || div.slideobj.options.grid) + div.slide.half + 'px');
				div.cur_point = step;
			}
			div.slideobj = new Drag(div.slide, {
				limit: {x: [div.offset.min, div.offset.max], y: [0, 0]},
				grid: Math.floor(div.offset.max / div.steps),
				onDrag: function(){
					var x = parseInt(div.slide.style.left);
					var step = Math.round((x - div.offset.min) / this.options.grid.x);
					if (step != div.cur_point){
						div.cur_point = step;
						div.inp.set('value', div.variants[step].title);
						if (typeof div.onMove == 'function'){
							div.onMove(step);
						}
					}
				}
			});
			div.panel.addEvent('mousedown', function(e){
				var y = e.client.y + document.getScrollTop() - div.panel.getTop();
				if (y < 30){
					setTimeout(function(){div.inp.focus()}, 1);
					return;
				}
				div.inp.blur();
				var x = e.client.x + document.getScrollLeft() - div.panel.getLeft();
				div.slide.setStyle('left', x - div.panel.pad + 'px');
				div.slideobj.element.fireEvent('mousedown', e);
				div.slideobj.drag(e);
			});
			div.inp.addEvent('keydown', function(e){
				if ($chk(e) && (e.code == 37 || e.code == 39)){
					e.stop();
					var step = 0;
					if (e.code == 37){
						step = Math.max(div.cur_point - 1, 0);
					}
					else{
						step = Math.min(div.cur_point + 1, div.steps);
					}
					if (step != div.cur_point){
						div.inp.set('value', div.variants[step].title);
						if (typeof div.onMove == 'function'){
							div.onMove(step);
						}
					}
					div.setSlide(step);
				}
			});
		});
	}
//---------------------init_checkboxes-------------------------------------------------------------*/
	var init_checkboxes = function(){
		var conts = $$('.checkbox').filter(function(div){return !div.hasClass('activated')});
		conts.each(function(div){
			div.addClass('activated');
			div.inp = div.getElement('input[type=checkbox]');
			div.inp.addEvent('click', function(e){
				if ($chk(e)){
					if (this.getParent().hasClass('readonly')){
						e.stop();
						return;
					}
				}
				if (this.getProperty('checked')){
					this.getParent().addClass('checkbox_on');
				}
				else{
					this.getParent().removeClass('checkbox_on');
				}
			}).fireEvent('click');
		});
	}
//---------------------fix_button_width------------------------------------------------------------*/
	var fix_button_width = function(butn, force){
		var div = document.getElement('.tmpbutton');
		if (div){
			var c = parseInt(butn.style.width || 0);
			if (force || c < 10){
				div.set('text', butn.get('value'));
				c = div.getWidth();
				if (butn.hasClass('private')){
					c += 7;
				}
			}
			butn.setStyle('width', c + 'px');
			butn.getParent().setStyle('width', c + 'px');
		}
	}
//---------------------decorate_links--------------------------------------------------------------*/
	decorate_links = function(){
		var _links = $$('a').filter(function(a){return !a.hasClass('activated')});
		_links.each(function(_a){
			_a.addClass('activated').addEvent('mouseenter', function(){
				this.addClass('selected');
			}).addEvent('mouseleave', function(){
				this.removeClass('selected');
			});
		});
	}
//---------------------md5-------------------------------------------------------------------------*/
	var md5 = function(s){
		this.rstr_md5 = function(s){
			return this.binl2rstr(this.binl_md5(this.rstr2binl(s), s.length * 8));
		}
		this.rstr2hex = function(input){
			var hex_tab = '0123456789abcdef';
			var output = '';
			var x;
			for(var i = 0; i < input.length; i++){
				x = input.charCodeAt(i);
				output += hex_tab.charAt((x >>> 4) & 0x0F) +  hex_tab.charAt( x		& 0x0F);
			}
			return output;
		}
		this.str2rstr_utf8 = function(input){
			var output = "";
			var i = -1;
			var x, y;
			while(++i < input.length){
				x = input.charCodeAt(i);
				y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
				if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF){
					x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
					i++;
				}
				if(x <= 0x7F){
					output += String.fromCharCode(x);
				}
				else if(x <= 0x7FF){
					output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), 0x80 | ( x		 & 0x3F));
				}
				else if(x <= 0xFFFF){
					output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 0x80 | ((x >>> 6 ) & 0x3F), 0x80 | ( x		 & 0x3F));
				}
				else if(x <= 0x1FFFFF){
					output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 0x80 | ((x >>> 12) & 0x3F), 0x80 | ((x >>> 6 ) & 0x3F), 0x80 | ( x		 & 0x3F));
				}
			}
			return output;
		}
		this.rstr2binl = function(input){
			var output = Array(input.length >> 2);
			for(var i = 0; i < output.length; i++){
				output[i] = 0;
			}
			for(var i = 0; i < input.length * 8; i += 8){
				output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
			}
			return output;
		}
		this.binl2rstr = function(input){
			var output = "";
			for(var i = 0; i < input.length * 32; i += 8){
				output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
			}
			return output;
		}
		this.binl_md5 = function(x, len){
			x[len >> 5] |= 0x80 << ((len) % 32);
			x[(((len + 64) >>> 9) << 4) + 14] = len;
			var a =  1732584193;
			var b = -271733879;
			var c = -1732584194;
			var d =  271733878;
			for(var i = 0; i < x.length; i += 16){
				var olda = a;
				var oldb = b;
				var oldc = c;
				var oldd = d;
				a = this.md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
				d = this.md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
				c = this.md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
				b = this.md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
				a = this.md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
				d = this.md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
				c = this.md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
				b = this.md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
				a = this.md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
				d = this.md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
				c = this.md5_ff(c, d, a, b, x[i+10], 17, -42063);
				b = this.md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
				a = this.md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
				d = this.md5_ff(d, a, b, c, x[i+13], 12, -40341101);
				c = this.md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
				b = this.md5_ff(b, c, d, a, x[i+15], 22,  1236535329);
				a = this.md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
				d = this.md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
				c = this.md5_gg(c, d, a, b, x[i+11], 14,  643717713);
				b = this.md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
				a = this.md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
				d = this.md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
				c = this.md5_gg(c, d, a, b, x[i+15], 14, -660478335);
				b = this.md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
				a = this.md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
				d = this.md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
				c = this.md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
				b = this.md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
				a = this.md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
				d = this.md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
				c = this.md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
				b = this.md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
				a = this.md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
				d = this.md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
				c = this.md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
				b = this.md5_hh(b, c, d, a, x[i+14], 23, -35309556);
				a = this.md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
				d = this.md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
				c = this.md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
				b = this.md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
				a = this.md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
				d = this.md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
				c = this.md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
				b = this.md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
				a = this.md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
				d = this.md5_hh(d, a, b, c, x[i+12], 11, -421815835);
				c = this.md5_hh(c, d, a, b, x[i+15], 16,  530742520);
				b = this.md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
				a = this.md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
				d = this.md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
				c = this.md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
				b = this.md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
				a = this.md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
				d = this.md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
				c = this.md5_ii(c, d, a, b, x[i+10], 15, -1051523);
				b = this.md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
				a = this.md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
				d = this.md5_ii(d, a, b, c, x[i+15], 10, -30611744);
				c = this.md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
				b = this.md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
				a = this.md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
				d = this.md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
				c = this.md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
				b = this.md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
				a = this.safe_add(a, olda);
				b = this.safe_add(b, oldb);
				c = this.safe_add(c, oldc);
				d = this.safe_add(d, oldd);
			}
			return Array(a, b, c, d);
		}
		this.md5_cmn = function(q, a, b, x, s, t){
			return this.safe_add(this.bit_rol(this.safe_add(this.safe_add(a, q), this.safe_add(x, t)), s),b);
		}
		this.md5_ff = function(a, b, c, d, x, s, t){
			return this.md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
		}
		this.md5_gg = function(a, b, c, d, x, s, t){
			return this.md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
		}
		this.md5_hh = function(a, b, c, d, x, s, t){
			return this.md5_cmn(b ^ c ^ d, a, b, x, s, t);
		}
		this.md5_ii = function(a, b, c, d, x, s, t){
			return this.md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
		}
		this.safe_add = function(x, y){
			var lsw = (x & 0xFFFF) + (y & 0xFFFF);
			var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
			return (msw << 16) | (lsw & 0xFFFF);
		}
		this.bit_rol = function(num, cnt){
			return (num << cnt) | (num >>> (32 - cnt));
		}
		return this.rstr2hex(this.rstr_md5(this.str2rstr_utf8(s)));
	}
//-------------------------------------------------------------------------------------------------*/

window.addEvent('domready', function(){
//---------------------input[type=passord]---------------------------------------------------------*/
	$$('input[type=password]').each(function(inp){
		inp.addEvent('focus', function(){
			keyboard_notice.show(['capslock', 'russian']);
		}).addEvent('blur', function(){
			keyboard_notice.hide();
		}).addEvent('keypress', function(){
			keyboard_notice.show(['capslock', 'russian']);
		});
	});
//---------------------loading---------------------------------------------------------------------*/
	var tmp = $$('.splashes')[0];
	if ($chk(tmp)){
		loading.inject(tmp);
	}
//---------------------a.text-decoration-----------------------------------------------------------*/
	decorate_links();
//---------------------shadow----------------------------------------------------------------------*/
	shadow = $('shadow');
	if ($chk(shadow)){
		splash.show = function(name){
			shadow.fireEvent('click');
			var arr = name.split("|");
			name = arr[0];
			if (!$chk($(name))){
				return;
			}
			t = arr[1];
			if (t){
				setTimeout(function(){
					shadow.fireEvent('click');
				}, t*1000);
			}
			shadow.removeClass('hidden');
			$(name).removeClass('hidden');
			if (Browser.Engine.trident && Browser.Engine.version < 5){
				$$('select').each(function(sel){
					sel.addClass('tmp_hidden');
				});
			}
			if (name == 'auth'){
				need_to_stand = false;
			}
			var box = $(name).getElement('.box');
			if ($chk(box)){
				var h = box.getStyle('max-height') || 333;
				if (box.getHeight() > h){
					box.setStyle('height', h + 'px');
				}
			}
			window.fireEvent('resize');
		};
		shadow.addEvent('click', function(e){
			if ($chk(e)){e.stop()};
			$$('.splash').each(function(splash){
				splash.addClass('hidden');
			});
			this.addClass('hidden');
			if (Browser.Engine.trident && Browser.Engine.version < 5){
				$$('select').each(function(sel){
					sel.removeClass('tmp_hidden');
				});
			}
		});
		document.addEvent('keydown', function(e){
			if (e.code == 27){
				shadow.fireEvent('click');
			}
		});
		$$('.splash').each(function(el){
			el.getElement('.cross').addEvent('mouseover', function(){
				this.addClass('cross_selected');
			}).addEvent('mouseout', function(){
				this.removeClass('cross_selected');
			}).addEvent('click', function(){
				shadow.fireEvent('click');
			});
			if ($chk(el.getElement('.cancel'))){
				el.getElement('.cancel').addEvent('click', function(){
					shadow.fireEvent('click');
				});
			}
		});
		window.addEvent('resize', function(e){
			var _screen = document.getSize();
			var set_centered = function(div){
				var c = div.getSize();
				div.setStyles({
					'left'	: ((c.x < _screen.x) ? (_screen.x - c.x)/2 : 0) + 'px',
					'top'	: ((c.y < _screen.y) ? (_screen.y - c.y)/2 : 0) + 'px'
				});
			}
			$$('.splash').each(set_centered);
		});
		var dialogs = $$('.dialog');
		dialogs.each(function(a){
			a.t = a.get('title');
			a.removeProperty('title');
			a.addEvent('click', function(e){
				if ($chk(e)){e.stop()};
				splash.show(a.t);
			});
		});
	}
//---------------------exit------------------------------------------------------------------------*/
	if ($chk($$('.quit'))){
		$$('.quit').addEvent('click', function(e){
			if ($chk(e)){e.stop()};
			new Ajax('{"quit":"1"}', {
				url: '/auth.x',
				onSuccess: function(response){
					page.goto('/');
				}
			});
		});
	}
//---------------------buttons---------------------------------------------------------------------*/
	var buttons = $$('div.button');
	buttons.each(function(b){
		b.addEvent('click', function(e){
			if (b.getFirst().get('type') != 'submit'){
				if ($chk(e)){e.stop()};
				b.getFirst().fireEvent('click');
			}
		});
		fix_button_width(b.getFirst());
	});
//---------------------inputs type=file------------------------------------------------------------*/
	var ifiles = $$('div.file');
	ifiles.each(function(c){
		init_fileinput(c);
	});
//---------------------table.price-----------------------------------------------------------------*/
	$$('table.price').each(function(table){
		var tr = {};
		if (table.getElement('thead')){
			tr.head = table.getElement('thead').getFirst();
			tr.head.els = $H(tr.head.childNodes).filter(function(el){return (el.nodeType == 1)}).getValues();
			tr.head.els.each(function(td, i){
				if (i == 0){
					$(td).addClass('first');
				}
				else if (i == 1){
					$(td).addClass('second');
				}
				else if (i == tr.head.els.length-1){
					$(td).addClass('last');
				}
				else{
					$(td).addClass('with_border')
				}
			});
		}
		tr.body = table.getElements('tbody tr');
		tr.body.each(function(tr, i){
			if (i % 2 != 0){
				tr.addClass('r2');
			}
			tr.getFirst().addClass('first');
			tr.getLast().addClass('last');
		});
		if (table.getElement('tfoot')){
			tr.foot = table.getElement('tfoot').getLast();
			tr.foot.getFirst().addClass('first');
			tr.foot.getLast().addClass('last');
			table.getElement('tfoot').removeClass('hidden');
		}
		else{
			if (tr.body.length % 2 != 0){
				table.addClass('footless');
			}
		}
		var corners = table.getElements('.first, .last');
		corners.each(function(td){
			if (!td.getFirst()){
				var div = new Element('div', {'class':'corner'});
				div.inject(td, 'top');
			}
		});
	});
//---------------------only_granted_simbols--------------------------------------------------------*/
	filter_keys();
//---------------------input.check_all-------------------------------------------------------------*/
	var c_all = $$('input.check_all');
	c_all.each(function(input){
		var name = input.get('name');
		var t_inputs = $$('input[name=' + name + ']').filter(function(input){return !input.hasClass('check_all')});;
		t_inputs.each(function(inp){
			inp.addEvent('click', function(e){
				if ($chk(e)){
					input.setProperty('checked', 'checked').fireEvent('click');
					t_inputs.each(function(el){
						if (!el.get('checked')){
							input.removeProperty('checked').fireEvent('click');
						}
					});
				}
			});
			inp.setStyle('cursor', 'pointer');
		});
		input.addEvent('click', function(e){
			if ($chk(e)){
				if (input.get('checked')){
					t_inputs.each(function(inp){
						inp.setProperty('checked', 'checked').fireEvent('click');
					});
				}
				else{
					t_inputs.each(function(inp){
						inp.removeProperty('checked').fireEvent('click');
					});
				}
			}
		});
		input.setStyle('cursor', 'pointer');
	});
//---------------------change=keyup----------------------------------------------------------------*/
	$$('input').each(function(input){
		input.setProperty('autocomplete','off');
		if (Browser.Engine.gecko || Browser.Engine.webkit || Browser.Engine.presto){
			input.addEventListener('input', function(){
					input.fireEvent('keyup');
				},
				false
			);
			input.addEventListener('dragdrop', function(){
					input.fireEvent('keyup');
				},
				false
			);
		} 
		else if (Browser.Engine.trident){
			input.attachEvent('onpaste', function(){
					setTimeout(
						function(){input.fireEvent('keyup')},
						50
					)
				},
				false
			);
		}
		else{
			input.addEventListener('DOMCharacterDataModified', function(){
					input.fireEvent('keyup');
				},
				false
			);
		}
	});
//---------------------cabinet_menu----------------------------------------------------------------*/
	$$('div.droppable').each(function(div){
		var c_menu = div.getFirst();
		div.addEvent('mouseenter', function(e){
			c_menu.removeClass('hidden');
			div.getElement('div.arrow').addClass('arrow_top').getNext().setStyle('visibility', 'hidden');
		});
		c_menu.addEvent('mouseleave', function(){
			c_menu.addClass('hidden');
			div.getElement('div.arrow').removeClass('arrow_top').getNext().setStyle('visibility', 'visible');
		});
	});
//-------------------------------------------------------------------------------------------------*/
	init_checkboxes();
	window.fireEvent('resize');
}).addEvent('load', function(){
	if (Browser.Engine.trident && !document.body.filters){
		shadow.setStyle('background-color', 'transparent');
	}
}).addEvent('resize', function(){
	var tmp = document.getElement('div.content');
	if ($chk(tmp) && !tmp.hasClass('unresizable')){
		tmp.setStyle('min-height', Math.max(document.getHeight()-220, CONTENT_HEIGHT) + 'px');
	}
});