﻿var web_txt=new Array();
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');
				this.box_holder.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.box_holder.setStyle('display','block');
			this.alpha.setStyles({
				display:'block',
				height:window.getScrollSize().y,
				opacity:.5
			});
			this.shown=1;
			s=this.box.getCoordinates();
			s_h=this.box_holder.getCoordinates();
			if(s.height>s_h.height)
				shift_y=10;
			else if((s_h.height-s.height)<50)
				shift_y=(s_h.height-s.height)/2;
			else
				shift_y=50;			
			this.showBox.start('top',window.getScroll().y+shift_y);
		}
	},
	hide:function(){
		if(this.shown==1){
			this.shown=0;
			s=this.box.getCoordinates();
			this.showBox.start('top',-(s.height+s.top));
		}
	}
});

var sorting_init=function(){
	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||(eCode>=96&&eCode<=105));
		},
		'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||(eCode>=96&&eCode<=105));
			},
			'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();
			}
		});
	}	
}

window.addEvent('load',function(){
	menu_onload();
	$$('a[rel=_blank]').setProperty('target','_blank');
	$$('a.button_back').addEvent('click',function(){
		history.go(-1);
		return false;
	});
	if($('print_button'))
		$('print_button').addEvent('click',function(){
			window.print();
			return false;
		});
	$('bookmark').addEvent('click',function(){
		tit='vpl.sk - Všeobecný praktik';
		url='http://www.vpl.sk/';
		if(window.sidebar)
			window.sidebar.addPanel(tit,url,"");
		else if(window.opera&&window.print){
			el=document.createElement('a');
			el.setAttribute('href',url);
			el.setAttribute('title',tit);
			el.setAttribute('rel','sidebar');
			el.click();
		}
		else if(document.all)
			window.external.AddFavorite(url,tit);
		return false;
	});
	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();
				}
			});
		}
	}
});
