jQuery.noConflict();

jQuery(document).ready(function() { 
 
    //select all the a tag with name equal to modal
    jQuery('a[title=zapisz]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = jQuery(this).attr('href');
		var parent = jQuery(this).parent().prev().prev();
		
		jQuery('input[name="14"]').val(parent.prev().text());
		jQuery('input[name="15"]').val(parent.text());
		
        //Get the screen height and width
        var maskHeight = jQuery(document).height();
        var maskWidth = jQuery(window).width();
     
        //Set height 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();
        
		if(jQuery('#dialog').height() > winH) {
			winH -= 50;
			jQuery('#dialog').css('height',winH+'px');
			jQuery('#dialog').css('overflow','auto');
		}
		
        //Set the popup window to center
        jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
        jQuery(id).css('left', winW/2-jQuery(id).width()/2);
     
        //transition effect
        jQuery(id).fadeIn(2000);
     
    });
	
	jQuery('a[title=dodaj]').click(function(e) {
        //Cancel the link behavior
        
		if(jQuery('#pre_newsletter_email').val() == '') {
			alert('Proszę podać adres email.');
		}
		else {
			
			var pos_y = 0;
			
			e.preventDefault();
			//Get the A tag
			var id = jQuery(this).attr('href');
			var parent = jQuery(this).parent().prev().prev();
		
			jQuery('#label_mail').text(jQuery('#pre_newsletter_email').val());
			jQuery('#newsletter_email').val(jQuery('#pre_newsletter_email').val());
		
			//Get the screen height and width
			var maskHeight = jQuery(document).height();
			var maskWidth = jQuery(window).width();
     
			//Set height and width to mask to fill up the whole screen
			jQuery('#mask2').css({'width':maskWidth,'height':maskHeight});
         
			//transition effect    
			jQuery('#mask2').fadeIn(1000);   
			jQuery('#mask2').fadeTo("slow",0.8); 
     
			//Get the window height and width
			var winH = jQuery(window).height();
			var winW = jQuery(window).width();
					
			if(jQuery('#dialog2').height() > winH) {
				winH -= 50;
				jQuery('#dialog2').css('height',winH+'px');
				jQuery('#dialog2').css('overflow','auto');
			}
            
			if(jQuery.browser.msie) {
				pos_y = document.documentElement.scrollTop;
			} else {
				pos_y = window.pageYOffset;
			}
			
			//Set the popup window to center
			jQuery(id).css('top',  winH/2-jQuery(id).height()/2 + pos_y);
			jQuery(id).css('left', winW/2-jQuery(id).width()/2);
     
			//transition effect
			jQuery(id).fadeIn(2000);
		}
    });
     
    //if close button is clicked
    jQuery('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        jQuery('#mask, .window').hide();
    });  

	//if close button is clicked
    jQuery('.window2 .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        jQuery('#mask2, .window2').hide();
    }); 	
     
    //if mask is clicked
    jQuery('#mask').click(function () {
        jQuery(this).hide();
        jQuery('.window').hide();
    });  

//if mask is clicked
    jQuery('#mask2').click(function () {
        jQuery(this).hide();
        jQuery('.window').hide();
    });   	
     
});
