/*
	ReaderViews javascript
*/


/* begin moving to name-spaced method javascript style */

	// declarations
	rv							= {};
	rv.setupIndexPage			= null;
	rv.setupNewsletter			= null;
	rv.setupShowMoreOrLess		= null;


	// implementation

	rv.setupIndexPage = function () 
	{
		rv.setupShowMoreOrLess();
	}

	rv.setupNewsletter = function () 
	{
		rv.setupShowMoreOrLess();
	}

		rv.setupShowMoreOrLess = function () 
		{
			$('.readMoreWrapper')	.hide();
			$('.readMoreLink')		.click(function(event) {
				event.stopPropagation();
				event.preventDefault();
				var currentLink			= $(event.target);
				var currentLinkText		= $(currentLink).text();
				(currentLinkText == "Read more...") ? currentLink.text('Close...') : currentLink.text('Read more...');
				var currentContainer	= $(event.target).parent().next('.readMoreWrapper');
				$(currentContainer)		.slideToggle('slow');
			});

			$('.closeReadMoreLink').bind('click', function(event) {
				event.stopPropagation();
				event.preventDefault();
				$('#theReadMoreLink').text('Read more...')
				$('html,body').animate({ scrollTop: 0 }, "slow", function(){ $(event.target).closest('.readMoreWrapper').slideUp('slow'); });
			});

		}
	
	


// validation functions and data

	// globally available regular expressions used for validating user input

	var gRegExNonBlankValidator 		 	= /\w/																					; // must contain at least 1 word character
	var gRegExThreeDigitsValidator	 		= /^[0-9][0-9][0-9]$/																	; // used for phone number validation
	var gRegExFourDigitsValidator		 	= /^[0-9][0-9][0-9][0-9]$/																; // used for phone number validation
	var gRegExNumbersOnlyValidator		 	= /^[0-9]+$/																			; // any number of numbers only
	var gRegExOneFieldPhoneNumberValidator	= /^\(?[\d]{3}\)?[ .\/_\-]?[\d]{3}[ .\/_\-]?[\d]{4}/									; // 3 part phone number in one field.
	var gRegExUSStateValidator 				= /^[A-Za-z][A-Za-z]$/																	; // 2 characters, assumes it will be a valid us state, for now.
	var gUSStateCodes						= "AL|AK|AS|AZ|AR|CA|CO|CT|DE|DC|FM|FL|GA|GU|HI|ID|IL|IN|IA|KS|KY|LA|ME|MH|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|MP|OH|OK|OR|PW|PA|PR|RI|SC|SD|TN|TX|UT|VT|VI|VA|WA|WV|WI|WY|AE|AA|AE|AE|AP" ;
	var gRegExSingleUSZipValidator 			= /^[\d]{5}$/																			; // US ZipCode, 5 digits and 5 digits only
	var gRegExSingleCanPostalCodeValidator 	= /^[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ] ?[0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]$/	; // Can postal code: CharDigitChar DigitCharDigit separated by one optional space ex: T3M 2K7. Validator assumes that the field has been UPPERCASE'd
	var gRegExEmailValidator				= /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ ;


	// uppercaseThisField
	function uppercaseThisField(someField) {
		var upperCasedValue = $(someField).val().toUpperCase();
		$(someField).val(upperCasedValue);
	}
	
	// nonBlankValidator
	function nonBlankValidator(currentTextField) {
	
		var currentFieldIsValid	= false;
	
		currentFieldIsValid		= gRegExNonBlankValidator.test($(currentTextField).val());
	
		if (currentFieldIsValid) {
			$(currentTextField).removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$(currentTextField).addClass('notValidHighlight').next('img').fadeIn('fast');
			return false;
		}
	}


	// emailValidator
	function emailValidator(currentTextField) {
	
		var currentFieldIsValid	= false;
	
		currentFieldIsValid		= gRegExEmailValidator.test($(currentTextField).val());
	
		if (currentFieldIsValid) {
			$(currentTextField).removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$(currentTextField).addClass('notValidHighlight').next('img').fadeIn('fast');
			return false;
		}
	}


	// oneFieldPhoneValidator
	function oneFieldPhoneValidator(currentTextField) {
	
		var currentFieldIsValid	= false;
	
		currentFieldIsValid		= gRegExOneFieldPhoneNumberValidator.test($(currentTextField).val());
	
		if (currentFieldIsValid) {
			$(currentTextField).removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$(currentTextField).addClass('notValidHighlight').next('img').fadeIn('fast');
			return false;
		}
	}


	// usStateValidator
	function usStateValidator(currentTextField) {
	
		var currentFieldLengthIsValid	= false;
		var currentFieldIsValid			= false;
		var currentFieldValue			= $(currentTextField).val().toUpperCase();
	
		currentFieldLengthIsValid		= gRegExUSStateValidator.test(currentFieldValue);
		currentFieldIsValid				= gUSStateCodes.indexOf(currentFieldValue) != -1 ;
	
		if (currentFieldLengthIsValid && currentFieldIsValid) {
			$(currentTextField).removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$(currentTextField).addClass('notValidHighlight').next('img').fadeIn('fast');
			return false;
		}
	}


	// singleUSorCAPostalCode
	function singleUSorCAPostalCode(currentTextField) {
	
		var currentFieldIsValid	= false;
		var currentFieldValue	= $(currentTextField).val().toUpperCase();
	
		currentFieldIsValid		= ( gRegExSingleUSZipValidator.test(currentFieldValue) || gRegExSingleCanPostalCodeValidator.test(currentFieldValue) );
	
		if (currentFieldIsValid) {
			$(currentTextField).removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$(currentTextField).addClass('notValidHighlight').next('img').fadeIn('fast');
			return false;
		}
	}


	// some radio is checked
	function radioGroupisValid(someRadioButton) {
		var currentGroupIsValid		= false;
		var currentRadioGroupName	= $(someRadioButton).attr('name');
		var currentRadioButton		= $("input[name=" + currentRadioGroupName + "]:checked");
		var lastRadioButtoninGroup	= $("input[name=" + currentRadioGroupName + "]:last");
	
		currentGroupIsValid			= $(currentRadioButton).length;
	
		if (currentGroupIsValid) {
			$(lastRadioButtoninGroup).nextAll('img').fadeOut('slow');
			return true;
		} else {
			$(lastRadioButtoninGroup).nextAll('img').fadeIn('fast');
			return false;
		}
	
	}


	// numbersOnlyValidator
	function numbersOnlyValidator(currentTextField) {
	
		var currentFieldIsValid	= false;
		var currentFieldValue	= $(currentTextField).val();
	
		currentFieldIsValid		= ( gRegExNumbersOnlyValidator.test(currentFieldValue) );
	
		if (currentFieldIsValid) {
			$(currentTextField).removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$(currentTextField).addClass('notValidHighlight').next('img').fadeIn('fast');
			return false;
		}
	}


	// selectValidator
	function selectValidator(currentSelect) {

		var curentSelectValue		= $(currentSelect).val();
		var currentSelectIsValid	= curentSelectValue !== "";
	
		if (currentSelectIsValid) {
			$(currentSelect).removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$(currentSelect).addClass('notValidHighlight').next('img').fadeIn('fast');
			return false;
		}
	}


	// selectMultipleValidator
	function selectMultipleValidator(currentSelect) {

		var curentSelectValue		= $(currentSelect).val();
		var currentSelectIsValid	= curentSelectValue !== null;
	
		if (currentSelectIsValid) {
			$(currentSelect).removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$(currentSelect).addClass('notValidHighlight').next('img').fadeIn('fast');
			return false;
		}
	}


	// checkbox 'group'
	function validateIAmThe() {
		var IamTheIsValid = $('div.IAmThe [type=checkbox]:checked').length;
		if (IamTheIsValid) {
			$('img#IamThe').fadeOut('fast');
		} else {
			$('img#IamThe').fadeIn('fast');
		}
		return IamTheIsValid;
	}

	// used on the additional services page
	function calculateServicesCost() {
		var currentTotal = 0; 
		$('table.servicesAndCosts [type=checkbox]:checked').each(function() {
			var currentCost = $(this).parent('td').find('span').text();
			currentCost = parseInt(currentCost);
			currentTotal += currentCost;
		});
		$('td#servicesTotal').text("$" + currentTotal);
	}

	
	// special case for the nospam field
	function nospamValidator() {
		usersInput = $('input[name=zsr74]').val().toLowerCase();
		if (usersInput == "nospam") {
			$('input[name=zsr74]').removeClass('notValidHighlight').next('img').fadeOut('slow') ;
			return true;
		} else {
			$('input[name=zsr74]').addClass('notValidHighlight').next('img').fadeIn('fast') ;
			return false;
		}
	}





/* ============================================================
	the original, stand-lone submission page. New reviews only. 
   ============================================================ */


	function setupTheSubmitForAReviewPage() {
	
		$('div#contactform img').hide();
	
		$('input[name=Contact0FirstName]')							.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0LastName]')							.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0Email]')								.bind('keyup blur', 	function(){emailValidator			(this);});
		$('input[name=Contact0Phone1]')								.bind('keyup blur', 	function(){oneFieldPhoneValidator	(this);});
		$('input[name=Contact0StreetAddress1]')						.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0City]')								.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0State]')								.bind('keyup blur', 	function(){usStateValidator			(this);});
		$('input[name=Contact0State]')								.bind('blur',			function(){uppercaseThisField		(this);});
		$('input[name=Contact0PostalCode]')							.bind('keyup blur', 	function(){singleUSorCAPostalCode	(this);});
		$('input[name=Contact0PostalCode]')							.bind('blur', 			function(){uppercaseThisField		(this);});
		$('input[name=Contact0_Iamthe]')							.bind('click',			function(){radioGroupisValid		(this);});
	
		$('input[name=Contact0_TitleofSubmission0]')				.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_AuthorsName0]')						.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_CopyrightDate]')						.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_ISBN0]')								.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_PagesorCDs]')						.bind('keyup blur', 	function(){numbersOnlyValidator		(this);});
		$('select[name=Contact0_TypeofFormat]')						.bind('change focus', 	function(){selectValidator			(this);});
		$('textarea[name=Contact0_PublishersNameAddress0]')			.bind('keyup blur',		function(){nonBlankValidator		(this);});
		$('input[name=Contact0_Category1]')							.bind('click',			function(){radioGroupisValid		(this);});
	
		$('input[name=Contact0_PrimaryGenreonlyoneplease0]')		.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('select[name=Contact0_AdditionalGenreCheckallthatapply]')	.bind('change focus', 	function(){selectMultipleValidator	(this);});
		$('input[name=Contact0_AmazonListing1]')					.bind('click',			function(){radioGroupisValid		(this);});
	
		$('textarea[name=Contact0_DetailedSynopsis]')				.bind('keyup blur',		function(){nonBlankValidator		(this);});
		$('select[name=Contact0_TypeofPackageRequesting]')			.bind('change focus', 	function(){selectValidator			(this);});
		$('input[name=Contact0_WebsiteforAuthor]')					.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_EnterthisbookinLiteraryAwards]')		.bind('click',			function(){radioGroupisValid		(this);});
	
	}


	function validateTheReviewSubmission(theForm) {
	
		var incompleteFieldMessages		= "";
	
		var FirstNameIsValid			= nonBlankValidator 		($('input[name=Contact0FirstName]')							.get(0));
		var LastNameIsValid				= nonBlankValidator 		($('input[name=Contact0LastName]')							.get(0));
		var EmailIsValid				= emailValidator    		($('input[name=Contact0Email]')								.get(0));
		var PhoneIsValid				= oneFieldPhoneValidator    ($('input[name=Contact0Phone1]')							.get(0));
		var StreetAddressIsValid		= nonBlankValidator 		($('input[name=Contact0StreetAddress1]')					.get(0));
		var CityIsValid					= nonBlankValidator 		($('input[name=Contact0City]')								.get(0));
		var StateIsValid				= usStateValidator 			($('input[name=Contact0State]')								.get(0));
		var PostalCodeIsValid			= singleUSorCAPostalCode 	($('input[name=Contact0PostalCode]')						.get(0));
		var IamTheIsValid				= radioGroupisValid 		($('input[name=Contact0_Iamthe]')							.get(0));
	
		var TitleIsValid				= nonBlankValidator 		($('input[name=Contact0_TitleofSubmission0]')				.get(0));
		var AuthorsNameIsValid			= nonBlankValidator 		($('input[name=Contact0_AuthorsName0]')						.get(0));
		var CopyrightDateIsValid		= nonBlankValidator 		($('input[name=Contact0_CopyrightDate]')					.get(0));
		var ISBNIsValid					= nonBlankValidator 		($('input[name=Contact0_ISBN0]')							.get(0));
		var numberOfPagesIsValid		= numbersOnlyValidator 		($('input[name=Contact0_PagesorCDs]')						.get(0));
		var typeOfFormatIsValid			= nonBlankValidator 		($('select[name=Contact0_TypeofFormat]')					.get(0));
		var PublishersAddressIsValid	= nonBlankValidator 		($('textarea[name=Contact0_PublishersNameAddress0]')		.get(0));
		var categoryIsValid				= radioGroupisValid 		($('input[name=Contact0_Category1]')						.get(0));
	
		var primaryGenreIsValid			= nonBlankValidator 		($('input[name=Contact0_PrimaryGenreonlyoneplease0]')		.get(0));
		var additionalGenreIsValid		= selectMultipleValidator 	($('select[name=Contact0_AdditionalGenreCheckallthatapply]').get(0));
		var amazonListingIsValid		= radioGroupisValid 		($('input[name=Contact0_AmazonListing1]')					.get(0));
	
		var synopsisIsValid				= nonBlankValidator 		($('textarea[name=Contact0_DetailedSynopsis]')				.get(0));
		var typeOfPackageIsValid		= nonBlankValidator 		($('select[name=Contact0_TypeofPackageRequesting]')			.get(0));
		var websiteForAuthorIsValid		= nonBlankValidator 		($('input[name=Contact0_WebsiteforAuthor]')					.get(0));
		var EnterLiteraryIsValid		= radioGroupisValid 		($('input[name=Contact0_EnterthisbookinLiteraryAwards]')	.get(0));
	
		if (!FirstNameIsValid)			{ incompleteFieldMessages += "First Name\n";								}
		if (!LastNameIsValid)			{ incompleteFieldMessages += "Last Name\n";									}
		if (!EmailIsValid)				{ incompleteFieldMessages += "Email\n";										}
		if (!PhoneIsValid)				{ incompleteFieldMessages += "Phone (with area code)\n";					}
		if (!StreetAddressIsValid)		{ incompleteFieldMessages += "Street Address 1\n";							}
		if (!CityIsValid)				{ incompleteFieldMessages += "City\n";										}
		if (!StateIsValid)				{ incompleteFieldMessages += "State\n";										}
		if (!PostalCodeIsValid)			{ incompleteFieldMessages += "Zip/Postal code\n";							}
		if (!IamTheIsValid)				{ incompleteFieldMessages += "I am the Author, Publisher or Publicist\n";	}
		
		if (!TitleIsValid)				{ incompleteFieldMessages += "Title of Submission\n";						}
		if (!AuthorsNameIsValid)		{ incompleteFieldMessages += "Author's Name\n";								}
		if (!CopyrightDateIsValid)		{ incompleteFieldMessages += "Copyright Date\n";							}
		if (!ISBNIsValid)				{ incompleteFieldMessages += "ISBN\n";										}
		if (!numberOfPagesIsValid)		{ incompleteFieldMessages += "Number of Pages\n"; 							}
		if (!typeOfFormatIsValid)		{ incompleteFieldMessages += "Type of Format\n"; 							}
	
		if (!PublishersAddressIsValid)	{ incompleteFieldMessages += "Publisher's Name\/Address\n"; 				}
		if (!categoryIsValid)			{ incompleteFieldMessages += "Category\n"; 									}
	
		if (!primaryGenreIsValid)		{ incompleteFieldMessages += "Primary Genre\n"; 							}
		if (!additionalGenreIsValid)	{ incompleteFieldMessages += "Additional Genres\n"; 						}
		if (!amazonListingIsValid)		{ incompleteFieldMessages += "Amazon Listing\n"; 							}
	
		if (!synopsisIsValid)			{ incompleteFieldMessages += "Synopsis\n"; 									}
		if (!typeOfPackageIsValid)		{ incompleteFieldMessages += "Type of Package\n"; 							}
		if (!websiteForAuthorIsValid)	{ incompleteFieldMessages += "Website for Author\n"; 						}
		if (!EnterLiteraryIsValid)		{ incompleteFieldMessages += "Enter Literary Awards Program\n"; 			}
	
		if (incompleteFieldMessages == "") {
			$('input#Submit').attr({disabled: 'disabled', value:'Submitting...'});
			return true;
		} else {
			var message = "We need more information. \nPlease complete the following:\n\n" ;
				message += incompleteFieldMessages ;
			alert(message);
			return false;
		}
	}





/* ============================================================
	Three page submission system 2010.11
   ============================================================ */


	function showNewSubmissionPage() {
		window.location.href = "submissionform-newSubmission.html";
	}

	function showAddOnServicesPage() {
		window.location.href = "submissionform-additionalServices.html";
	}



	/* the choose... page */

	function setupChooseSubmission() {
		$('input#newSubmission').bind('click', function(){ showNewSubmissionPage()	});
		$('input#addonServices').bind('click', function(){ showAddOnServicesPage() 	});
	}



	/* New submission page */

	function setupNewSubmissionPage() {
	
		$('div#contactform img.validationImgInTD')					.hide();
		$('input#newSubmission')									.bind('click', function(){ showNewSubmissionPage()	});
		$('input#addonServices')									.bind('click', function(){ showAddOnServicesPage() 	});

		$('input[name=Contact0FirstName]')							.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0LastName]')							.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0Email]')								.bind('keyup blur', 	function(){emailValidator			(this);});
		$('input[name=Contact0Phone1]')								.bind('keyup blur', 	function(){oneFieldPhoneValidator	(this);});
		$('input[name=Contact0StreetAddress1]')						.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0City]')								.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0State]')								.bind('keyup blur', 	function(){usStateValidator			(this);});
		$('input[name=Contact0State]')								.bind('blur',			function(){uppercaseThisField		(this);});
		$('input[name=Contact0PostalCode]')							.bind('keyup blur', 	function(){singleUSorCAPostalCode	(this);});
		$('input[name=Contact0PostalCode]')							.bind('blur', 			function(){uppercaseThisField		(this);});
		$('input[name=Contact0_Iamthe]')							.bind('click',			function(){radioGroupisValid		(this);});

		$('input[name=Contact0_TitleofSubmission0]')				.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_AuthorsName0]')						.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_CopyrightDate]')						.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_ISBN0]')								.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_PagesorCDs]')						.bind('keyup blur', 	function(){numbersOnlyValidator		(this);});
		$('select[name=Contact0_TypeofFormat]')						.bind('change focus', 	function(){selectValidator			(this);});
		$('textarea[name=Contact0_PublishersNameAddress0]')			.bind('keyup blur',		function(){nonBlankValidator		(this);});
		$('input[name=Contact0_Category1]')							.bind('click',			function(){radioGroupisValid		(this);});

		$('input[name=Contact0_PrimaryGenreonlyoneplease0]')		.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('select[name=Contact0_AdditionalGenreCheckallthatapply]')	.bind('change focus', 	function(){selectMultipleValidator	(this);});
		$('input[name=Contact0_AmazonListing1]')					.bind('click',			function(){radioGroupisValid		(this);});
	
		$('textarea[name=Contact0_DetailedSynopsis]')				.bind('keyup blur',		function(){nonBlankValidator		(this);});
		$('select[name=Contact0_TypeofPackageRequesting]')			.bind('change focus', 	function(){selectValidator			(this);});
		$('input[name=Contact0_WebsiteforAuthor]')					.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0_EnterthisbookinLiteraryAwards]')		.bind('click',			function(){radioGroupisValid		(this);});

		$('input[name=zsr74]')										.bind('keyup blur', 	function(){nospamValidator			()    ;});

	}


	function validateNewSubmissionPage() {

		var incompleteFieldMessages		= "";
	
		var FirstNameIsValid			= nonBlankValidator 		($('input[name=Contact0FirstName]')							.get(0));
		var LastNameIsValid				= nonBlankValidator 		($('input[name=Contact0LastName]')							.get(0));
		var EmailIsValid				= emailValidator    		($('input[name=Contact0Email]')								.get(0));
		var PhoneIsValid				= oneFieldPhoneValidator    ($('input[name=Contact0Phone1]')							.get(0));
		var StreetAddressIsValid		= nonBlankValidator 		($('input[name=Contact0StreetAddress1]')					.get(0));
		var CityIsValid					= nonBlankValidator 		($('input[name=Contact0City]')								.get(0));
		var StateIsValid				= usStateValidator 			($('input[name=Contact0State]')								.get(0));
		var PostalCodeIsValid			= singleUSorCAPostalCode 	($('input[name=Contact0PostalCode]')						.get(0));
		var IamTheIsValid				= radioGroupisValid 		($('input[name=Contact0_Iamthe]')							.get(0));
	
		var TitleIsValid				= nonBlankValidator 		($('input[name=Contact0_TitleofSubmission0]')				.get(0));
		var AuthorsNameIsValid			= nonBlankValidator 		($('input[name=Contact0_AuthorsName0]')						.get(0));
		var CopyrightDateIsValid		= nonBlankValidator 		($('input[name=Contact0_CopyrightDate]')					.get(0));
		var ISBNIsValid					= nonBlankValidator 		($('input[name=Contact0_ISBN0]')							.get(0));
		var numberOfPagesIsValid		= numbersOnlyValidator 		($('input[name=Contact0_PagesorCDs]')						.get(0));
		var typeOfFormatIsValid			= nonBlankValidator 		($('select[name=Contact0_TypeofFormat]')					.get(0));
		var PublishersAddressIsValid	= nonBlankValidator 		($('textarea[name=Contact0_PublishersNameAddress0]')		.get(0));
		var categoryIsValid				= radioGroupisValid 		($('input[name=Contact0_Category1]')						.get(0));
	
		var primaryGenreIsValid			= nonBlankValidator 		($('input[name=Contact0_PrimaryGenreonlyoneplease0]')		.get(0));
		var additionalGenreIsValid		= selectMultipleValidator 	($('select[name=Contact0_AdditionalGenreCheckallthatapply]').get(0));
		var amazonListingIsValid		= radioGroupisValid 		($('input[name=Contact0_AmazonListing1]')					.get(0));
	
		var synopsisIsValid				= nonBlankValidator 		($('textarea[name=Contact0_DetailedSynopsis]')				.get(0));
		var typeOfPackageIsValid		= nonBlankValidator 		($('select[name=Contact0_TypeofPackageRequesting]')			.get(0));
		var websiteForAuthorIsValid		= nonBlankValidator 		($('input[name=Contact0_WebsiteforAuthor]')					.get(0));
		var EnterLiteraryIsValid		= radioGroupisValid 		($('input[name=Contact0_EnterthisbookinLiteraryAwards]')	.get(0));

		var zsr74IsValid				= nospamValidator	 		();

		if (!FirstNameIsValid)			{ incompleteFieldMessages += "First Name\n";								}
		if (!LastNameIsValid)			{ incompleteFieldMessages += "Last Name\n";									}
		if (!EmailIsValid)				{ incompleteFieldMessages += "Email\n";										}
		if (!PhoneIsValid)				{ incompleteFieldMessages += "Phone (with area code)\n";					}
		if (!StreetAddressIsValid)		{ incompleteFieldMessages += "Street Address 1\n";							}
		if (!CityIsValid)				{ incompleteFieldMessages += "City\n";										}
		if (!StateIsValid)				{ incompleteFieldMessages += "State\n";										}
		if (!PostalCodeIsValid)			{ incompleteFieldMessages += "Zip/Postal code\n";							}
		if (!IamTheIsValid)				{ incompleteFieldMessages += "I am the Author, Publisher or Publicist\n";	}
		
		if (!TitleIsValid)				{ incompleteFieldMessages += "Title of Submission\n";						}
		if (!AuthorsNameIsValid)		{ incompleteFieldMessages += "Author's Name\n";								}
		if (!CopyrightDateIsValid)		{ incompleteFieldMessages += "Copyright Date\n";							}
		if (!ISBNIsValid)				{ incompleteFieldMessages += "ISBN\n";										}
		if (!numberOfPagesIsValid)		{ incompleteFieldMessages += "Number of Pages\n"; 							}
		if (!typeOfFormatIsValid)		{ incompleteFieldMessages += "Type of Format\n"; 							}
	
		if (!PublishersAddressIsValid)	{ incompleteFieldMessages += "Publisher's Name\/Address\n"; 				}
		if (!categoryIsValid)			{ incompleteFieldMessages += "Category\n"; 									}
	
		if (!primaryGenreIsValid)		{ incompleteFieldMessages += "Primary Genre\n"; 							}
		if (!additionalGenreIsValid)	{ incompleteFieldMessages += "Additional Genres\n"; 						}
		if (!amazonListingIsValid)		{ incompleteFieldMessages += "Amazon Listing\n"; 							}
	
		if (!synopsisIsValid)			{ incompleteFieldMessages += "Synopsis\n"; 									}
		if (!typeOfPackageIsValid)		{ incompleteFieldMessages += "Type of Package\n"; 							}
		if (!websiteForAuthorIsValid)	{ incompleteFieldMessages += "Website for Author\n"; 						}
		if (!EnterLiteraryIsValid)		{ incompleteFieldMessages += "Enter Literary Awards Program\n"; 			}

		if (!zsr74IsValid)				{ incompleteFieldMessages += "Spam control\n";								}

		if (incompleteFieldMessages == "") {
			$('input#Submit').attr({disabled: 'disabled', value:'Submitting...'});
			return true;
		} else {
			var message = "We need more information. \nPlease complete the following:\n\n" ;
				message += incompleteFieldMessages ;
			alert(message);
			return false;
		}

	}



	/* Additional services page */

	function setupAdditionalServicesPage() {

		$('div#contactform img.validationImgInTD').hide();
		
		$('input#newSubmission')	.bind('click', function(){ showNewSubmissionPage()	});
		$('input#addonServices')	.bind('click', function(){ showAddOnServicesPage() 	});

		$('td.alignRight input')	.css({float:'left'})
		
		$('.calculateCost')			.bind('click', function(){calculateServicesCost()				});

		$('input[name=Contact0FirstName]')									.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0LastName]')									.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('input[name=Contact0Email]')										.bind('keyup blur', 	function(){emailValidator			(this);});
		$('input[name=Contact0Phone1]')										.bind('keyup blur', 	function(){oneFieldPhoneValidator	(this);});

		$('textarea[name=Contact0_TitleofSubmission]')						.bind('keyup blur', 	function(){nonBlankValidator		(this);});
		$('textarea[name=Contact0_ISBN]')									.bind('keyup blur', 	function(){nonBlankValidator		(this);});

		$('input[name=zsr74]')												.bind('keyup blur', 	function(){nospamValidator			()    ;});

		// if the page happens to (re)load with something checked...
		calculateServicesCost();
	}


	function validateAdditionalServicesPage() {

		var thisIsANewSubmission				= ( $("[name='New submisson or Addon']:checked").val() == "making a new submission" );
		var thisIsAnAddtionalServicesRequest	= ( $("[name='New submisson or Addon']:checked").val() == "requesting addon services" );

		var incompleteFieldMessages	= "";

		// check all the fields

		var FirstNameIsValid			= nonBlankValidator 		($('input[name=Contact0FirstName]')									.get(0));
		var LastNameIsValid				= nonBlankValidator 		($('input[name=Contact0LastName]')									.get(0));
		var EmailIsValid				= emailValidator    		($('input[name=Contact0Email]')										.get(0));
		var PhoneIsValid				= oneFieldPhoneValidator    ($('input[name=Contact0Phone1]')									.get(0));

		var TitleIsValid				= nonBlankValidator 		($('textarea[name=Contact0_TitleofSubmission]')						.get(0));
		var ISBNIsValid					= nonBlankValidator 		($('textarea[name=Contact0_ISBN]')									.get(0));

		var zsr74IsValid				= nospamValidator	 		();

		if (!FirstNameIsValid)			{ incompleteFieldMessages += "First Name\n";								}
		if (!LastNameIsValid)			{ incompleteFieldMessages += "Last Name\n";									}
		if (!EmailIsValid)				{ incompleteFieldMessages += "Email\n";										}
		if (!PhoneIsValid)				{ incompleteFieldMessages += "Phone (with area code)\n";					}
		if (!TitleIsValid)				{ incompleteFieldMessages += "Title of Submission\n";						}
		if (!zsr74IsValid)				{ incompleteFieldMessages += "Spam control\n";								}

		if (incompleteFieldMessages == "") {
			$('input#Submit').attr({disabled: 'disabled', value:'Submitting...'});
			return true;
		} else {
			var message = "We need more information. \nPlease complete the following:\n\n" ;
				message += incompleteFieldMessages ;
			alert(message);
			return false;
		}

	}




