jQuery(document).ready(function() {
	
	//if close button is clicked
	jQuery('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		jQuery('#mask').hide();
		jQuery('.window').hide();
	});		
	
	//if mask is clicked
	jQuery('#mask').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
	});			
	
	jQuery('#newsletter_form').submit(function() {
		
		var form = document.forms["newsletter_form"];
					
		form.setAttribute("method", "post");
		form.setAttribute("action", "https://redlink.pl/app/Registration.aspx?id=FFBD72A3-595C-4D9B-B8D7-5D4E1CAE3522");
						
		form.target='formframe';
							
		//window.open('about:blank', 'formresult', 'scrollbars=no,menubar=no,height=250,width=450,resizable=yes,toolbar=no,status=no');
				
		form.submit();
		
		launchWindow('#dialog');
				
	});
});

function launchWindow(id) {
	
	//Get the screen height and width
	var maskHeight = jQuery(document).height();
	var maskWidth = jQuery(window).width();
	
	//Set heigth and width to mask to fill up the whole screen
	jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
	//transition effect		
	jQuery('#mask').fadeIn(1000);	
	jQuery('#mask').fadeTo("slow",0.8);	
	
	//Get the window height and width
	var winH = jQuery(window).height();
	var winW = jQuery(window).width();
	var offset = jQuery(window).scrollTop();
	              
	//Set the popup window to center
	jQuery(id).css('top',  winH/2-jQuery(id).height() + offset);
	jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
	//transition effect
	jQuery(id).fadeIn(2000); 
}
