// <!--

$("#NLSignUpQuick").ready(function() {

	// functions as variable for reuse
	var emailAddressTextBoxHasFocus = false;
	var showSignUp = function() { emailAddressTextBoxHasFocus = true; $("#NLSignUpQuick div.NLSignUpQuickList").stop(true, true).slideDown(500); }
	var hideSignUp = function() { $("#NLSignUpQuick div.NLSignUpQuickList").stop(true, true).slideUp(500); }
	var showSignUpConditional = function() { if (emailAddressTextBoxHasFocus) { showSignUp.call(null); } }
	var emailAddressTextBoxLostFocus = function() { emailAddressTextBoxHasFocus = false; }

	// control variables for resuse
	var emailAddressTextBox = $("#NLSignUpQuick .emailAddress");
	var submitImageButton = $("#NLSignUpQuick .signupSubmit");

	// Show/Hide List Calls
	emailAddressTextBox.focus(showSignUp);
	emailAddressTextBox.keydown(showSignUp);
	$("#NLSignUpQuick div.NLSignUpQuickRelative").mouseleave(hideSignUp);
	emailAddressTextBox.blur(emailAddressTextBoxLostFocus);
	emailAddressTextBox.mouseover(showSignUpConditional);

	// Set TextBox Prompt
	emailAddressTextBox.focus(function() { if (emailAddressTextBox.attr("OriginalText") == emailAddressTextBox.val()) { emailAddressTextBox.val(''); } });
	emailAddressTextBox.blur(function() { if (jQuery.trim(emailAddressTextBox.val()) == '') { emailAddressTextBox.val(emailAddressTextBox.attr("OriginalText")) } });
	emailAddressTextBox.keypress(function(ev) { return clickControlOnEnter(ev, submitImageButton.attr("id")); });

	// validate the input on click of submit button
	$("#NLSignUpQuick .signupSubmit").click(function() {

		var emailAddress = jQuery.trim(emailAddressTextBox.val());

		// check if email address supplied
		if (emailAddress == jQuery.trim(emailAddressTextBox.attr("OriginalText"))) { alert('Please supply an email address.'); emailAddressTextBox.focus();  return false; };

		// check if valid email address
		if (!isValidEmail(emailAddress, $("#NLSignUpQuick input#NLSignUpQuickEmailValidationRegExp").val())) { alert('Please enter a valid email address.'); return false; };

		// check if newsletter selected
		var selectedItems = $("#NLSignUpQuick ul.NLSignUpQuickUL input[type='checkbox'][checked]");
		if (selectedItems.length == 0) { alert('Please select at least one newsletter.'); return false; };

		// create a CSV of checked items and assign to control
		var items = '';
		for (i = 0; i < selectedItems.length; i++) {
			if (i > 0) { items += ','; }
			items += selectedItems[i].value;
		}
		$("#NLSignUpQuick input#NLSignUpQuickCSV").val(items);
	});

});

// -->
