﻿// This method closes the popup
function ClosePopup()
{
	$('#PopupBackground,#InnerPopup').fadeOut("slow");
}

// This method Clears the textbox
function ClearEmailTextbox()
{
    // Use this way due to the Textbox Watermark
    $find('newsletterBID').set_Text("");
}

// Load these on document ready
$(document).ready(function()
{ 
	// For the element with id=button set the following for it's click event
    $('#lbtnNewsletter').click(function(e)
	{
		// Cancel the objects default behavior
		e.preventDefault();
		
		var emailaddress = $("#tbxNewsletter").val();
		if (emailaddress == "Enter Email")
		{
    		alert("An email address is required.");
    	}
    	else
    	{
		    // Get the Popup object
		    var popup = $("#InnerPopup");
            
		    //Get the screen height and width
		    var browserHeight = $(window).height();
		    var browserWidth = $(window).width();

	        // Set the Mask (background) css attributes and then it's fadeIn
		    $('#PopupBackground')
		        .css({'opacity':'0.7','width':browserWidth,'height':$(document).height()})
		        .fadeIn('slow');
    	
		    // Set the Popup windows css attributes and then fadeIn
		    $(popup)
		        .css({'top':browserHeight/2-$(popup).height()/2,'left':browserWidth/2-$(popup).width()/2})
		        .fadeIn('slow');		    
		}
	});
	
	// Handle the click of the close button (X)
	$('#ClosePopup').click(function(e)
	{
		//Cancel the link behavior
		e.preventDefault();
		
		$('#PopupBackground').fadeOut('slow');
		$('#InnerPopup').fadeOut('slow');
	});		
	
	// If user clicks the masks (outside the popup)
	$('#PopupBackground').click(function ()
	{
	    ClosePopup();
        ClearEmailTextbox();
	});
});

