//MooTools classes corrected by Fedor Shumov for the not doctypted codes

			var isMSIE = /*@cc_on!@*/false;
			var RuleSortObject = new Class({
			
				options: {
					handles: false,
					onStart: Class.empty,
					onComplete: Class.empty,
					ghost: true,
					snap: 3,
					onDragStart: function(element, ghost){
						ghost.setStyle('opacity', 0.7);
						element.setStyle('opacity', 0.7);
					},
					onDragComplete: function(element, ghost){
						element.setStyle('opacity', 1);
						ghost.remove();
						this.trash.remove();
					}
				},
			
				initialize: function(list, options){
					this.setOptions(options);
					this.list = $(list);
					this.elements = this.list.getChildren();
					this.handles = (this.options.handles) ? $$(this.options.handles) : this.elements;
					this.bound = {
						'start': [],
						'chiki': [],
						'edits': [],
						'moveGhost': this.moveGhost.bindWithEvent(this)
					};
					for (var i = 0, l = this.handles.length; i < l; i++){
						this.bound.start[i] = this.start.bindWithEvent(this, this.elements[i]);
						this.bound.chiki[i] = this.chiki.bindWithEvent(this, this.elements[i].getFirst());
						this.bound.edits[i] = this.edits.bindWithEvent(this, this.elements[i], i);
					}
					this.attach();
					if (this.options.initialize) this.options.initialize.call(this);
					this.bound.move = this.move.bindWithEvent(this);
					this.bound.end = this.end.bind(this);
				},
			
				attach: function(){
					this.handles.each(function(handle, i){
						handle.addEvent('mousedown', this.bound.start[i]);
						handle.getFirst().addEvent('mousedown', this.bound.chiki[i]);
						handle.getFirst().getNext().getNext().getFirst().addEvent('mousedown', this.bound.edits[i]);
					}, this);
				},
			
				detach: function(){
					this.handles.each(function(handle, i){
						handle.removeEvent('mousedown', this.bound.start[i]);
						handle.getFirst().removeEvent('mousedown', this.bound.chiki[i]);
						handle.getFirst().getNext().getNext().getFirst().removeEvent('mousedown', this.bound.edits[i]);
					}, this);
				},

				chiki: function(event, el){
					if (el.hasClass('rule_numafirst')) {
						el.toggleClass('rule_numafirst');
						el.toggleClass('rule_numafirst_check');
						el.getNext().getNext().getNext().getNext().name='deleterow[]';
					} else {
						el.toggleClass('rule_numafirst_check');
						el.toggleClass('rule_numafirst');
						el.getNext().getNext().getNext().getNext().name='ndeleterow[]';
					}
					event.stop();
				},
			
				edits: function(event, stroka, ig){
					setForEdit(stroka.id);
					var maxtop = stroka.getParent().getCoordinates().top + stroka.getParent().getCoordinates().height - 740;
					var curtop = stroka.getCoordinates().top - 250;
					(curtop>maxtop) ? positioning(maxtop) : positioning(curtop);
					showBox('shNewRule');
					event.stop();
				},
			
				start: function(event, el){
					this.active = el;
					this.coordinates = this.list.getCoordinates();
					if (this.options.ghost){
						var position = el.getPosition();
						this.offset = event.page.y - position.y + (isMSIE ? document.body.scrollTop : 0);
						this.trash = new Element('div').inject(document.body);
						this.ghost = el.clone().inject(this.trash).setStyles({
							'position': 'absolute',
							'left': position.x,
							'top': event.page.y - this.offset + (isMSIE ? document.body.scrollTop : 0)
						});
						document.addListener('mousemove', this.bound.moveGhost);
						this.fireEvent('onDragStart', [el, this.ghost]);
					}
					document.addListener('mousemove', this.bound.move);
					document.addListener('mouseup', this.bound.end);
					this.fireEvent('onStart', el);
					event.stop();
				},
			
				moveGhost: function(event){
					var value = event.page.y - this.offset + (isMSIE ? document.body.scrollTop : 0);
					value = value.limit(this.coordinates.top, this.coordinates.bottom - this.ghost.offsetHeight-2);
					this.ghost.setStyle('top', value);
					event.stop();
				},
			
				move: function(event){
					var now = event.page.y + (isMSIE ? document.body.scrollTop : 0);
					this.previous = this.previous || now;
					var up = ((this.previous - now) > 0);
					var prev = this.active.getPrevious();
					var next = this.active.getNext();
					if (prev && up && now < prev.getCoordinates().bottom) {
						prev.className = (prev.getNext().hasClass('rule_tr'))?'rule_tr':'rule_tr_dark';
						this.active.injectBefore(prev);
						prev.getPrevious().className = (prev.hasClass('rule_tr'))?'rule_tr_dark':'rule_tr';
					}
					if (next && !up && now > next.getCoordinates().top) {
						next.className = (next.getPrevious().hasClass('rule_tr'))?'rule_tr':'rule_tr_dark';
						this.active.injectAfter(next);
						next.getNext().className = (next.hasClass('rule_tr'))?'rule_tr_dark':'rule_tr';
					}
					this.previous = now;
				},
			
				serialize: function(converter){
					return this.list.getChildren().map(converter || function(el){
						return this.elements.indexOf(el);
					}, this);
				},
			
				end: function(){
					this.previous = null;
					document.removeListener('mousemove', this.bound.move);
					document.removeListener('mouseup', this.bound.end);
					if (this.options.ghost){
						document.removeListener('mousemove', this.bound.moveGhost);
						this.fireEvent('onDragComplete', [this.active, this.ghost]);
					}
					this.fireEvent('onComplete', this.active);
					this.attach();
				}			
			
			});
			RuleSortObject.implement(new Events, new Options);



			var ActSortObject = new Class({
			
				options: {
					handles: false,
					onStart: Class.empty,
					onComplete: Class.empty,
					ghost: true,
					snap: 3,
					onDragStart: function(element, ghost){
						ghost.setStyle('opacity', 0.7);
						element.setStyle('opacity', 0.7);
					},
					onDragComplete: function(element, ghost){
						element.setStyle('opacity', 1);
						ghost.remove();
						this.trash.remove();
					}
				},
			
				initialize: function(list, options){
					this.setOptions(options);
					this.list = $(list);
					this.elements = this.list.getChildren();
					this.handles = (this.options.handles) ? $$(this.options.handles) : this.elements;
					this.bound = {
						'start': [],
						'chiki': [],
						'moveGhost': this.moveGhost.bindWithEvent(this)
					};
					for (var i = 0, l = this.handles.length; i < l; i++){
						this.bound.start[i] = this.start.bindWithEvent(this, this.elements[i]);
						this.bound.chiki[i] = this.chiki.bindWithEvent(this, this.elements[i].getFirst());
					}
					this.attach();
					if (this.options.initialize) this.options.initialize.call(this);
					this.bound.move = this.move.bindWithEvent(this);
					this.bound.end = this.end.bind(this);
				},
			
				attach: function(){
					this.handles.each(function(handle, i){
						handle.addEvent('mousedown', this.bound.start[i]);
						handle.getFirst().addEvent('mousedown', this.bound.chiki[i]);
					}, this);
				},
			
				detach: function(){
					this.handles.each(function(handle, i){
						handle.removeEvent('mousedown', this.bound.start[i]);
						handle.getFirst().removeEvent('mousedown', this.bound.chiki[i]);
					}, this);
				},
				
				start: function(event, el){
					this.active = el;
					this.coordinates = this.list.getCoordinates();
					if (this.options.ghost){
						var position = el.getPosition();
						this.offset = event.page.y - position.y + (isMSIE ? document.body.scrollTop : 0);
						this.trash = new Element('div').inject(document.body);
						this.ghost = el.clone().inject(this.trash).setStyles({
							'position': 'absolute',
							'left': position.x,
							'top': event.page.y - this.offset + (isMSIE ? document.body.scrollTop : 0)
						});
						document.addListener('mousemove', this.bound.moveGhost);
						this.fireEvent('onDragStart', [el, this.ghost]);
					}
					document.addListener('mousemove', this.bound.move);
					document.addListener('mouseup', this.bound.end);
					this.fireEvent('onStart', el);
					event.stop();
				},
			
				chiki: function(event, el){
					this.chickin = el;
					if (this.chickin.hasClass('rule_numa')) {
						this.chickin.toggleClass('rule_numa');
						this.chickin.toggleClass('rule_numa_check');
					} else {
						this.chickin.toggleClass('rule_numa_check');
						this.chickin.toggleClass('rule_numa');
					}
					event.stop();
				},
			
				moveGhost: function(event){
					var value = event.page.y - this.offset + (isMSIE ? document.body.scrollTop : 0);
					value = value.limit(this.coordinates.top, this.coordinates.bottom - this.ghost.offsetHeight-2);
					this.ghost.setStyle('top', value);
					event.stop();
				},
			
				move: function(event){
					var now = event.page.y + (isMSIE ? document.body.scrollTop : 0);
					this.previous = this.previous || now;
					var up = ((this.previous - now) > 0);
					var prev = this.active.getPrevious();
					var next = this.active.getNext();
					if (prev && up && now < prev.getCoordinates().bottom) {
						prev.className = (prev.getNext().hasClass('rule_tr'))?'rule_tr':'rule_tr_dark';
						this.active.injectBefore(prev);
						prev.getPrevious().className = (prev.hasClass('rule_tr'))?'rule_tr_dark':'rule_tr';
					}
					if (next && !up && now > next.getCoordinates().top) {
						next.className = (next.getPrevious().hasClass('rule_tr'))?'rule_tr':'rule_tr_dark';
						this.active.injectAfter(next);
						next.getNext().className = (next.hasClass('rule_tr'))?'rule_tr_dark':'rule_tr';
					}
					this.previous = now;
				},
			
				serialize: function(converter){
					return this.list.getChildren().map(converter || function(el){
						return this.elements.indexOf(el);
					}, this);
				},
			
				end: function(){
					this.previous = null;
					document.removeListener('mousemove', this.bound.move);
					document.removeListener('mouseup', this.bound.end);
					if (this.options.ghost){
						document.removeListener('mousemove', this.bound.moveGhost);
						this.fireEvent('onDragComplete', [this.active, this.ghost]);
					}
					this.fireEvent('onComplete', this.active);
					this.attach();
				}			
			
			});
			ActSortObject.implement(new Events, new Options);
