﻿var web_txt=new Array();
var box_cnt=0,boxes=new Array(),shown_cnt=0;
var MessageBox=new Class({
	initialize:function(content){
		this.box=new Element('div',{'class':'message_box','events':{'click':this.hide.bind(this)}}).inject(document.body);
		var s=this.box.getSize();
		this.shown=0;
		this.h=s.y;
		this.w=s.x;	
		this.box.set({'styles':{'right':0,'bottom':-this.h},'html':content});
		this.showBox=new Fx.Morph(this.box,{duration:500,transition:Fx.Transitions.Quad.easeOut});
		box_cnt++;
		this.cnt=box_cnt;
		boxes[box_cnt]=this;
	},	
	show:function(){
		if(this.shown==0){
			this.box.setStyle('right',(shown_cnt*this.w));
			this.showBox.start({'bottom':0});
			this.shown=1;
			shown_cnt++;
		}
	},
	hide:function(){
		this.showBox.start({'bottom':-this.h});
		this.shown=0;
		this.cnt=0;
		shown_cnt--;		
		var s_c=0;		
		for(c=1;c<=box_cnt;c++){
			if(boxes[c].shown==1){
				boxes[c].showBox.start({'right':(s_c*this.w)});
				s_c++;
			}					
		}
	},
	setcontent:function(content){
		this.box.innerHTML=content;	
	}
});


var ShaddowBox=new Class({
	initialize:function(content){
		this.shown=0;
		this.alpha=new Element('div',{'id':'alpha'}).inject(document.body);
		this.box_holder=new Element('div',{'id':'shaddowbox_holder'}).inject(document.body);
		this.box=new Element('div',{'id':'shaddowbox'}).inject(this.box_holder);
		var b_r=new Element('div',{'class':'shaddowbox_r'});
		this.box_body=new Element('div',{'class':'shaddowbox_body'}).inject(b_r);
		this.box_content=$(content);
		this.box_content.setStyles({
   			opacity:0,
    		display:'block'
		});
		this.box_body.grab(this.box_content);
		this.box.adopt([new Element('div',{'class':'shaddowbox_t'}),new Element('div',{'class':'shaddowbox_tr'}),b_r,new Element('div',{'class':'shaddowbox_bl'}),new Element('div',{'class':'shaddowbox_b'}),new Element('div',{'class':'shaddowbox_br'})]);
		this.showBox=new Fx.Tween(this.box_holder,{duration:700,transition:Fx.Transitions.Quad.easeIn});
		this.showBox.onComplete=function(){
			if(this.shown==0){
				this.box_content.set('opacity',0);
				this.alpha.setStyle('display','none');
				$$('html').setStyle('overflow','auto');
				
			}
			else{
				this.box_content.tween('opacity',1);	
			}
		}.bind(this);
	},
	show:function(){
		if(this.shown==0){
			$$('html').setStyle('overflow','hidden');
			this.alpha.setStyles({
				display:'block',
				height:window.getScrollSize().y,
				opacity:.5
			});
			this.shown=1;
			this.showBox.start('top',window.getScroll().y);
		}
	},
	hide:function(){
		if(this.shown==1){
			this.shown=0;
			s=this.box.getCoordinates();
			this.showBox.start('top',-(s.height+s.top));
		}
	}
});



window.addEvent('domready',function(){
	menu_onload();
	$$('a[rel=_blank]').setProperty('target','_blank');
	
	if($('set_sorting')){
		var form=$('set_sorting')
		var els=form.getElements('input[name=page]');
		var l=new URI(location.href);
		els.addEvents({
			'keydown':function(event){
				eCode=event.code;
				return ((eCode>=48&&eCode<=57)||eCode==37||eCode==39||eCode==8||eCode==46);
			},
			'keyup':function(event){
				max_val=$('page_cnt').value;
				if(this.value.toInt()>max_val.toInt())
					this.value=max_val;
				if(this.value.toInt()==0)
					this.value=1;
				if(event.code==13){
					l.setData({page:(this.value-1),per_page:''},true);
					var q=l.get('query').cleanQueryString();
					l.set('query',q);
					l.go();
				}
			},
			'blur':function(){
				if(this.value==''||this.value==0)
					this.value=$('page_nr').value;
				l.setData({page:(this.value-1),per_page:''},true);
				var q=l.get('query').cleanQueryString();
				l.set('query',q);
				l.go();
			}
		});
		if($('per_page')){
			$('per_page').addEvents({
				'keydown':function(event){
					eCode=event.code;
					return ((eCode>=48&&eCode<=57)||eCode==37||eCode==39||eCode==8||eCode==46);
				},
				'keyup':function(event){
					max_val=$('record_cnt').value;
					if(this.value.toInt()>max_val.toInt())
						this.value=max_val;
					if(this.value.toInt()==0)
						this.value=1;
					if(event.code==13){
						l.setData({per_page:this.value,page:''},true);
						var q=l.get('query').cleanQueryString();
						l.set('query',q);
						l.go();
					}
				},
				'blur':function(){
					if(this.value==''||this.value==0)
						this.value=10;
					max_val=$('record_cnt').value;
					if(this.value.toInt()>max_val.toInt())
						this.value=max_val;
					l.setData({per_page:this.value,page:''},true);
					var q=l.get('query').cleanQueryString();
					l.set('query',q);
					l.go();
				}
			});
		}
	}
});