loadStdInfo=function(f,id){
	var iwin;
	if(!iwin){
		var iwin=new DE_win('std-info-win',{modal:true,className:"dx-light"});
		iwin.body.set("load",{});
		
	}
	var ref="/special/pricelist.php?ARG1="+f.amount.value+"-"+f.period.value;
	if(id){
		ref+='&did='+id
	}
	iwin.body.load(ref);
	iwin.open();
}

var DE_wins={};
var DE_win=new Class({
	initialize:function(id,options){
		this.options=$extend({
			duration:300,
			onOpen:$empty,
			onClose:$empty,
			create:false,
			className:'dx',
			open:false,
			modal:false,
			draggable:true,
			pos:'auto'// auto|fixed|cookies|'rt'//rt,lt,rb,lb
		},options||{});
		DE_wins[id]=this;		
		this.parent=null;
		this.el=$(id);
		if(!this.el){
			this.el=new Element('div',{'id':id,'class':this.options.className})
			var h='<div class="dx-head"><div class="dx-close"></div><h3></h3></div>';
			h+='<div class="dx-body"><div class="dx-cont"></div></div>';
			h+='<div class="dx-foot"><div></div></div>';
			this.el.set('html',h).inject(document.body);
		}
		this.body=this.el.getElement('.dx-cont');
		this.el.setStyle('opacity',0);
		var header=this.el.firstChild;
	
		if(this.options.draggable){
			header.style.cursor='move';
			new Drag(this.el,{
				handle:header,
				onBeforeStart:this.setPriority.bind(this)
			});
		}

		this.id=id;
		this.op=0
		var op=function(){
			if(this.op==1){
				this.op=2;
				this.options.onOpen();
			}else{
				this.op=0;
			}
		}.bind(this);

		if(this.options.duration>0){
			this.fx=new Fx.Morph(this.el,{
				onComplete:op,
				duration:this.options.duration
			});
		}

		var hide=this.close.bind(this, false);
		this.el.getElement('.dx-close').addEvent('click',hide);
		if(this.options.open)this.open();
	},
	setPriority:function(){
		for(id in DE_wins){
			DE_wins[id].el.setStyle('z-index', this.id==id?11:10)
		}
	},
	isOpened:function(){
		return this.op>0;
	},

	MLayer:function(state){
		var el=$('DE-modal-layer');
		if(!el){
			el=new Element('div',{'id':'DE-modal-layer','opacity':0.8});
			el.addEvent('click',this.close.bind(this, false));
			el.inject(document.body);
		}
		el.style.display=state?'block':'none';
	},
	close:function(){
		if(this.op!=2)return;
		if(this.options.modal){
			this.MLayer(0);
		}
		var close=function(){
			this.el.setStyle('left',-300);
			this.options.onClose();
		}.bind(this)

		if(this.options.duration==0){
			close();
			return false;
		}
		this.fx.start({opacity:[1,0]}).chain(close);
		return false;
	},
	open:function(opener){
		if(this.needReposition()){
			this.setPosition();
		}
		if(this.op!=0)return false;
		if(this.options.modal){
			this.MLayer(1);
		}
		this.op=1;
//		if(this.options.pos=='auto'){
			if(opener&&opener.el){
				this.setPosByEl(opener.el);
				this.parent=opener;
			}else if(opener){
				this.setPosByEl(opener);
			}else{
				this.setPosition();
			}
//		}
		this.fx.start({'opacity':[0,1]});
		return true;
	},
	setPosByEl:function(el){
		var x=null,y=null,c=el.getCoordinates();
		switch(this.options.pos){
			case 'rt':
				x=c.right+2;
				y=c.top;
			break;
			case 'lt':
				x=c.left+2;
				y=c.top+2;
			break;
			case 'rb':
				x=c.right+2;
				y=c.bottom+2;
			break;
			case 'lb':
			default:
				x=c.left;
				y=c.bottom+2;
			break;
			case 'auto':
		}
		this.setPosition(x,y);
	},
	setHeader:function(htm){
		return this.el.getElement('.dx-head h3').set('html',htm);
	},
	setContent:function(htm){
		return this.body.set('html',htm);
	},
	injectContent:function(el){
		return el.inject(this.body);
	},
	needReposition:function(){
		var c=getSize();
		var ws=getScroll();
		var cc=this.el.getSize();
		x=c.x/2-cc.x/2+ws.x;
		if(x<0)x=0;
		y=c.y/2-cc.y/2;

//jei palindes del scrolo
		if(y<ws.y)return true;
		if(x+cc.x>c.x)return true;
		return false;
	},
	setPosition:function(x,y){
		var c=getSize();
		var ws=getScroll();
		var cc=this.el.getSize();
		if(x==null)x=c.x/2-cc.x/2+ws.x;
		if(x<0)x=0;
		if(y==null)y=c.y/2-cc.y/2;
//jei palindes del scrolo
		if(y<ws.y)y=ws.y;
		if(y<0)y=0;
		if(x+cc.x>c.x)x=c.x-cc.x+ws.x;//uzhlenda deshinej
		this.el.setStyles({
			left:x+'px',
			top:y+'px'
		});
	}
});

