calcWindow = null;
calcTitle = '';
calcContent = '';
calcPrice = 0;

function showContactForm( subject, lang ){
	
	myWidth = getVisibleHeight(0);
	myHeight = getVisibleHeight(1);
	
	visibleWidth = (myWidth-650)/2;
	visibleHeight = (myHeight-480)/2+document.documentElement.scrollTop;
	calcTitle = calcTitleContact;
	calcContent = '<iframe src="'+host_url+'/www/form.php?subject='+subject+'&l='+lang+'" class="noborder" frameborder="0" scrolling="no" />';
	
	if(calcWindow){ 
		calcWindow.setPosition( visibleHeight, visibleWidth );
		calcWindow.show();
	}
	else{
		calcWindow = new mWindow( calcTitle, visibleHeight, visibleWidth ,650, 480 );
		calcWindow.setContent( calcContent );		
		calcWindow.show();
	}
}

function showInformForm( url, lang ){
	
	myWidth = getVisibleHeight(0);
	myHeight = getVisibleHeight(1);
	
	visibleWidth = (myWidth-650)/2;
	visibleHeight = (myHeight-480)/2+document.documentElement.scrollTop;
	calcTitle = calcTitleInform;
	calcContent = '<iframe src="'+host_url+'/www/inform.php?url='+url+'&l='+lang+'" class="noborder" frameborder="0" scrolling="no" />';
	
	if(calcWindow){ 
		calcWindow.setPosition( visibleHeight, visibleWidth );
		calcWindow.show();
	}
	else{
		calcWindow = new mWindow( calcTitle, visibleHeight, visibleWidth ,650, 480 );
		calcWindow.setContent( calcContent );		
		calcWindow.show();
	}
}

function showOrderForm(lang){

	myWidth = getVisibleHeight(0);
	myHeight = getVisibleHeight(1);
	

	visibleWidth = (myWidth-650)/2;
	visibleHeight = (myHeight-480)/2+document.documentElement.scrollTop;
	calcTitle = 'Przewodnik Katolicki - prenumerata';
	calcContent = '<iframe src="'+host_url+'/www/order.php?l='+lang+'" class="noborder" frameborder="0" scrolling="no" />';

	if(calcWindow){
		calcWindow.setPosition( visibleHeight, visibleWidth );
		calcWindow.show();
	}
	else{
		calcWindow = new mWindow( calcTitle, visibleHeight, visibleWidth ,650, 480 );
		calcWindow.setContent( calcContent );
		calcWindow.show();
	}
}

function getVisibleHeight(Mode) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if(Mode==0) return myWidth;
  if(Mode==1) return myHeight;
}


lastzIndex = 1000;
var mWindow = new Class({
initialize: function(titleText,t,l,w,h){
	this.container = new Element('div');
	this.container.className = 'window';	
	
    this.eventPosition = this.position.bind(this);
	if( !$('lbOverlay') ) this.overlay = new Element('div', {'id': 'lbOverlay'}).injectInside(document.body);
	else this.overlay = $('lbOverlay');
			
	this.containerContent = new Element('div');		
	this.containerContent.className = 'windowLayer';
	this.container.adopt(this.containerContent);
	this.frameContainer = new Element('div');	
	this.frameContainer.className = 'windowFrameContainer';	
	this.frameContent = new Element('iframe');	
	this.frameContent.className = 'windowFrameContent';	
	this.frameContainer.adopt(this.frameContent);	
	this.containerContent.adopt(this.frameContainer);
		
	if(t){
		this.container.setStyle("top",t);
	}
	if(l){
		this.container.setStyle("left",l);
	}
	if(w){
		this.container.setStyle("width",w);
		this.containerContent.setStyle("width",w);
	}
	else{
		this.container.setStyle("width",200);
		this.containerContent.setStyle("width",200);
	}
	if(h){
		this.container.setStyle("height",h);
		this.containerContent.setStyle("height",h);
	}
			
	// Defining title bar
	this.titleButtons = new Element('span');
	this.closeButton = new Element('img',{src: calcTemplate+'close.gif', style: 'margin-top: 2px;margin-right: 2px;'});
	this.closeButton.setStyle('cursor','default');
	this.closeButton.addEvent('click', this.close.bind(this));
	this.slideButton =  new Element('img',{src: calcTemplate+'slide.gif', style: 'margin-top: 2px;margin-right: 2px;'});
	this.slideButton.setStyle('cursor','default');
	this.slideButton.addEvent('click', this.slide.bind(this));
	this.slideButton.inject(this.titleButtons);
	this.closeButton.inject(this.titleButtons);
	this.title = new Element('div');
	this.title.className = 'windowTitle';

	this.titleButtons.inject(this.title);
	this.titleButtons.setStyle("float","right");
	this.title.appendText(titleText);
	this.container.adopt(this.title);
	new Drag.Move(this.container,{
		handle: this.title
	});
	
	// Defining content block
	this.content = new Element('div');	
	this.content.className = 'windowContent';
	this.container.adopt(this.content);
		
	// Defining status bar
	this.statusBar = new Element('div');	
	this.statusBar.className = 'windowStatus';
	
	/*
	this.resizeButton = new Element('img',{src: calcTemplate+'resize.gif', style: 'margin-bottom: 2px;margin-right: 2px;'});
	this.resizeButton.setStyle('cursor','se-resize');
	this.resizeButton.setStyle("float","right");
	
	this.statusBar.adopt(this.resizeButton);
	this.container.makeResizable({
		handle: this.resizeButton,
		limit:{
			        x:[100, 800],
			        y:[50, 600]
			    }							
		
		});
	*/
	this.container.adopt(this.statusBar);
	this.fx = new Fx.Style(this.container, 'opacity', {duration: 250, wait: false}).set(0);	
	
    this.fxOv = this.overlay.effect('opacity', {duration: 500}).hide();
	
	this.container.addEvent('mousedown',this.bringToTop.bind(this));
	this.title.addEvent('mousedown',this.bringToTop.bind(this));
	this.container.inject($(document.body));
},

setContent: function(content){
		this.content.setHTML(content);
},
slide: function(){
		if(this.content.getStyle('display')=='block'){
			this.content.setStyle('display','none');
			this.containerContent.setStyle('display','none');
		}
		else{
			this.content.setStyle('display','block');
			this.containerContent.setStyle('display','block');
		}
},
close: function(){
	this.fx.start(0);
	this.fxOv.start(0);
	this.setup(false);
	//this.container.setStyle('display','none');
},
show: function(){
	this.container.setStyle('display','block');
	this.fx.start(1);
	this.fxOv.start(0.8);
	
    this.position();
	this.setup(true);
		
	if(this.content.getStyle('display')!='block') this.slide();
},
position: function(){
    this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
},
setPosition: function(t, l){
	if(t)
		this.container.setStyle("top",t);
	if(l)
		this.container.setStyle("left",l);
},
setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
},
bringToTop: function(){
	lastzIndex++;
	this.container.setStyle('z-index',lastzIndex);
}

});
