///////////////////////////////////
// FUNCTION TO OPEN A NEW WINDOW //
///////////////////////////////////
function newWindow(url, nameOfWindow, attributesOfWindow) {
	nameOfWindow=window.open(url, nameOfWindow, attributesOfWindow);
	nameOfWindow.focus();
}


/////////////////////
// FORM PROCESSING //
/////////////////////

// Function for performing basic actions
function doAction(action) {
	document.masterForm.admin_action.value = action;
	document.masterForm.submit();
}

// Handles form validation for a register action
function register() {
	
	// Perform some checks based on the document type
	var accountErrors = false;
	
	if (document.masterForm.USER_REGISTER_TYPE.value == "name") {
		if (document.masterForm.USER_REGISTER_FULL_NAME.value == "") {
			alert ('Please enter your full name.');
			document.masterForm.USER_REGISTER_FULL_NAME.focus();
			document.masterForm.USER_REGISTER_FULL_NAME.select();
			accountErrors = true;
		} else if (document.masterForm.USER_REGISTER_ADDRESS_1.value == "") {
			alert ('Please enter at least one line for your address.');
			document.masterForm.USER_REGISTER_ADDRESS_1.focus();
			document.masterForm.USER_REGISTER_ADDRESS_1.select();
			accountErrors = true;
		} else if (document.masterForm.USER_REGISTER_CITY.value == "") {
			alert ('Please enter your city.');
			document.masterForm.USER_REGISTER_CITY.focus();
			document.masterForm.USER_REGISTER_CITY.select();
			accountErrors = true;
		} else if (document.masterForm.USER_REGISTER_STATE[document.masterForm.USER_REGISTER_STATE.selectedIndex].value == '') {
			alert ('Please choose your state.');
			gotoAnchor('state');
			accountErrors = true;
		} else if ((document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'United States') && document.masterForm.USER_REGISTER_ZIPCODE.value == '') {
			alert ('Please enter your zip code.');
			document.masterForm.USER_REGISTER_ZIPCODE.focus();
			document.masterForm.USER_REGISTER_ZIPCODE.select();
			accountErrors = true;
		}
	} else {
		if (document.masterForm.USER_REGISTER_ACCOUNT_NUMBER.value.length < 10 || isNaN(document.masterForm.USER_REGISTER_ACCOUNT_NUMBER.value)) {
			alert ('Your account number must be ten digits.');
			document.masterForm.USER_REGISTER_ACCOUNT_NUMBER.focus();
			document.masterForm.USER_REGISTER_ACCOUNT_NUMBER.select();
			accountErrors = true;
		}
	}
	
	// If there are no account errors, proceed
	var userErrors = false;
	
	if (!accountErrors) {
		if (document.masterForm.USER_NAME.value.length < 4 || document.masterForm.USER_NAME.value.length > 30) {
			alert ('Your user name must be 4 to 30 characters long.');
			document.masterForm.USER_NAME.focus();
			document.masterForm.USER_NAME.select();
			userErrors = true;
		} else if (document.masterForm.USER_PASSWORD.value.length < 4 || document.masterForm.USER_PASSWORD.value.length > 30) {
			alert ('Your password must be 4 to 30 characters long.');
			document.masterForm.USER_PASSWORD.focus();
			document.masterForm.USER_PASSWORD.select();
			userErrors = true;
		} else if (document.masterForm.USER_PASSWORD.value != document.masterForm.USER_CONFIRM_PASSWORD.value) {
			alert ('Your passwords do not match. Please try again.');
			document.masterForm.USER_CONFIRM_PASSWORD.focus();
			document.masterForm.USER_CONFIRM_PASSWORD.select();
			userErrors = true;
		} else if (document.masterForm.USER_EMAIL_ADDRESS.value == "" 
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == -1
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(" ") != -1
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == 0
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == (document.masterForm.USER_EMAIL_ADDRESS.value.length - 1)
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") == -1
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") == (document.masterForm.USER_EMAIL_ADDRESS.value.length - 1)
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") + 1 == document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".")
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") + 1 == document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@")) {
			alert ('Please enter a valid email address.');
			document.masterForm.USER_EMAIL_ADDRESS.focus();
			document.masterForm.USER_EMAIL_ADDRESS.select();
			userErrors = true;
		}
	}
	
	if (!accountErrors && !userErrors) {
		doAction('apply_register');
	}
}

// Handles form validation for a register return action (i.e. registration attempts 2 to n)
function registerReturn() {
	
	// Perform some checks based on the document type
	var accountErrors = false;
	
	if (document.masterForm.USER_REGISTER_TYPE.value == "name") {
		if (document.masterForm.USER_REGISTER_FULL_NAME.value == "") {
			alert ('Please enter your full name.');
			document.masterForm.USER_REGISTER_FULL_NAME.focus();
			document.masterForm.USER_REGISTER_FULL_NAME.select();
			accountErrors = true;
		} else if (document.masterForm.USER_REGISTER_ADDRESS_1.value == "") {
			alert ('Please enter at least one line for your address.');
			document.masterForm.USER_REGISTER_ADDRESS_1.focus();
			document.masterForm.USER_REGISTER_ADDRESS_1.select();
			accountErrors = true;
		} else if (document.masterForm.USER_REGISTER_CITY.value == "") {
			alert ('Please enter your city.');
			document.masterForm.USER_REGISTER_CITY.focus();
			document.masterForm.USER_REGISTER_CITY.select();
			accountErrors = true;
		} else if (document.masterForm.USER_REGISTER_STATE[document.masterForm.USER_REGISTER_STATE.selectedIndex].value == '') {
			alert ('Please choose your state.');
			gotoAnchor('state');
			accountErrors = true;
		} else if ((document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'United States') && document.masterForm.USER_REGISTER_ZIPCODE.value == '') {
			alert ('Please enter your zip code.');
			document.masterForm.USER_REGISTER_ZIPCODE.focus();
			document.masterForm.USER_REGISTER_ZIPCODE.select();
			accountErrors = true;
		}
	} else {
		if (document.masterForm.USER_REGISTER_ACCOUNT_NUMBER.value.length < 10 || isNaN(document.masterForm.USER_REGISTER_ACCOUNT_NUMBER.value)) {
			alert ('Your account number must be ten digits.');
			document.masterForm.USER_REGISTER_ACCOUNT_NUMBER.focus();
			document.masterForm.USER_REGISTER_ACCOUNT_NUMBER.select();
			accountErrors = true;
		}
	}
	
	if (!accountErrors) {
		doAction('apply_register_return');
	}
}

// Handles form validation for an account lookup action
function accountLookup() {
	
	// Perform some checks based on the document type
	var accountErrors = false;
	
	if (document.masterForm.USER_ACCOUNT_NUMBER.value.length < 10) {
		alert ('The account number must be ten digits.');
		document.masterForm.USER_ACCOUNT_NUMBER.focus();
		document.masterForm.USER_ACCOUNT_NUMBER.select();
		accountErrors = true;
	}
	
	if (!accountErrors) {
		doAction('apply_account_lookup');
	}
}

// Allows the user to hit enter on the form when doing a general action
function submitEnter(e, action) {
    	var keycode;
	    	
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
    	} else {
    		return true;
    	}
	
    	if (keycode == 13 || keycode == 3) {
      		doAction(action);
      		return false;
    	} else {
     		return true;
     	}
}

// Allows the user to hit enter on the form when doing a register action
function submitRegister(e) {
    	var keycode;
	    	
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
    	} else {
    		return true;
    	}
	
    	if (keycode == 13 || keycode == 3) {
      		register();
      		return false;
    	} else {
     		return true;
     	}
}

// Allows the user to hit enter on the form when doing a register return action
function submitRegisterReturn(e) {
    	var keycode;
	    	
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
    	} else {
    		return true;
    	}
	
    	if (keycode == 13 || keycode == 3) {
      		registerReturn();
      		return false;
    	} else {
     		return true;
     	}
}

// Allows the user to hit enter on the form when doing an account lookup action
function submitAccountLookup(e) {
    	var keycode;
	    	
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
    	} else {
    		return true;
    	}
	
    	if (keycode == 13 || keycode == 3) {
      		accountLookup();
      		return false;
    	} else {
     		return true;
     	}
}

// Checks a change password form
function changePassword() {
	
	// Perform some checks based on the document type
	var passwordErrors = false;
	
	if (document.masterForm.USER_PASSWORD.value == '') {
		alert ('Please enter your current password.');
		document.masterForm.USER_PASSWORD.focus();
		document.masterForm.USER_PASSWORD.select();
		passwordErrors = true;
	} else if (document.masterForm.USER_NEW_PASSWORD.value.length < 4 || document.masterForm.USER_NEW_PASSWORD.value.length > 30) {
		alert ('Your password must be 4 to 30 characters long.');
		document.masterForm.USER_NEW_PASSWORD.focus();
		document.masterForm.USER_NEW_PASSWORD.select();
		passwordErrors = true;
	} else if (document.masterForm.USER_NEW_PASSWORD.value != document.masterForm.USER_CONFIRM_NEW_PASSWORD.value) {
		alert ('Your passwords do not match. Please try again.');
		document.masterForm.USER_CONFIRM_NEW_PASSWORD.focus();
		document.masterForm.USER_CONFIRM_NEW_PASSWORD.select();
		passwordErrors = true;
	}
	
	if (!passwordErrors) {
		doAction('apply_change_password');
	}
}

// Checks a change email address form
function changeEmailAddress() {
	
	// Perform some checks based on the document type
	var emailErrors = false;
	
	if (document.masterForm.USER_EMAIL_ADDRESS.value == "" 
		|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == -1
		|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(" ") != -1
		|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == 0
		|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == (document.masterForm.USER_EMAIL_ADDRESS.value.length - 1)
		|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") == -1
		|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") == (document.masterForm.USER_EMAIL_ADDRESS.value.length - 1)
		|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") + 1 == document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".")
		|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") + 1 == document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@")) {
		alert ('Please enter a valid email address.');
		document.masterForm.USER_EMAIL_ADDRESS.focus();
		document.masterForm.USER_EMAIL_ADDRESS.select();
		emailErrors = true;
	} else if (document.masterForm.USER_EMAIL_ADDRESS.value != document.masterForm.USER_CONFIRM_EMAIL_ADDRESS.value) {
		alert ('The email addresses you entered do not match. Please try again.');
		document.masterForm.USER_CONFIRM_EMAIL_ADDRESS.focus();
		document.masterForm.USER_CONFIRM_EMAIL_ADDRESS.select();
		emailErrors = true;
	}
	
	if (!emailErrors) {
		doAction('apply_change_email_address');
	}
}

//////////////////////
// MESSAGE HANDLING //
//////////////////////

// Checks for a notification message when reloading the registration form
// Displays it and selects the username field if one exists
function checkUserNameMessage(message) {
	
	if (message != '') {
		gotoAnchor('username');
		document.masterForm.USER_NAME.focus();
		document.masterForm.USER_NAME.select();
		alert(message);
	}
}

// Checks for a notification message when reloading the account lookup form
// Displays it and selects the account number field if one exists
function checkAccountLookupMessage(message) {
	
	if (message != '') {
		document.masterForm.USER_ACCOUNT_NUMBER.focus();
		document.masterForm.USER_ACCOUNT_NUMBER.select();
		alert(message);
	}
}

// Checks for a notification message when reloading the change password form
// Displays it and selects the current password field if one exists
function checkChangePasswordMessage(message) {
	
	if (message != '') {
		document.masterForm.USER_PASSWORD.focus();
		document.masterForm.USER_PASSWORD.select();
		alert(message);
	}
}

// Checks for a notification message when reloading the change password form
// Displays it and selects the current password field if one exists
function checkChangeEmailAddressMessage(message) {
	
	if (message != '') {
		document.masterForm.USER_EMAIL_ADDRESS.focus();
		document.masterForm.USER_EMAIL_ADDRESS.select();
		alert(message);
	}
}

////////////////////
// IMAGE HANDLING //
////////////////////

// Creates a new image object
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

// Swaps an image on a mouseover
function changeImage(oldimage, newimage) {
	if (document.images) {
		document[oldimage].src = eval(newimage + ".src");
	}
}


//////////////////
// CSS HANDLING //
//////////////////

// Function for changing the style sheet on a mouse over
function changeLink(newClass,id) {
	document.getElementById(id).className = newClass;
}


/////////////////
// REDIRECTION //
/////////////////

// Sends the user's browser to a new URL
function gotoURL(url) {
	document.location.href=url;
}

// Goes to an anchor on a page
function gotoAnchor(anchorName) {
	if (anchorName != '') {
		window.location = "#" + anchorName;
	}
}

// Directs a logged in user to the start page for their content for a specific newsletter
function gotoContent(publicationCode) {
	
	document.masterForm.action = '/newsletters/' + publicationCode.toLowerCase() + '/index.jsp';
	document.masterForm.admin_action.value = 'start';
	document.masterForm.submit();
}

function doFocus(focus) {
	var stmt = "document.masterForm." + focus + ".focus()";
  	eval(stmt);
}


///////////////
// SUBSCRIBE //
///////////////
// This function validates a subscription form before submitting it
function processSubscription() {
		
	// Perform some checks based on the document type
	var nameAndAddressErrors = false;
	
	if (document.masterForm.USER_REGISTER_FULL_NAME.value == "") {
		alert ('Please enter your full name.');
		document.masterForm.USER_REGISTER_FULL_NAME.focus();
		document.masterForm.USER_REGISTER_FULL_NAME.select();
		nameAndAddressErrors = true;
	} else if (document.masterForm.USER_REGISTER_ADDRESS_1.value == "") {
		alert ('Please enter at least one line for your address.');
		document.masterForm.USER_REGISTER_ADDRESS_1.focus();
		document.masterForm.USER_REGISTER_ADDRESS_1.select();
		nameAndAddressErrors = true;
	} else if (document.masterForm.USER_REGISTER_CITY.value == "") {
		alert ('Please enter your city.');
		document.masterForm.USER_REGISTER_CITY.focus();
		document.masterForm.USER_REGISTER_CITY.select();
		nameAndAddressErrors = true;
	} else if (((document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'United States') || (document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'Canada')) && document.masterForm.USER_REGISTER_STATE[document.masterForm.USER_REGISTER_STATE.selectedIndex].value == '') {
		alert ('Please choose your state.');
		gotoAnchor('state');
		nameAndAddressErrors = true;
	} else if (((document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'United States') || (document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'Canada')) && document.masterForm.USER_REGISTER_ZIPCODE.value == '') {
		alert ('Please enter your zip code.');
		document.masterForm.USER_REGISTER_ZIPCODE.focus();
		document.masterForm.USER_REGISTER_ZIPCODE.select();
		nameAndAddressErrors = true;
	}
	
	// Perform basic format validation for different credit cards
	var ccErrors = false;
	
	// Parse the credit card expiration date for validation
	var ccExpMonthVar = parseFloat(document.masterForm.ccExpMonth.value);
	var ccExpYearVar = parseFloat(document.masterForm.ccExpYear.value);
	
	// Obtain the selected payment type
	var paymentTypeArray = document.masterForm.paymentType;
	var selectedPaymentType = "undefined";

	if (paymentTypeArray) {
  		for (var i = 0; i < paymentTypeArray.length; i++) {
   			if (paymentTypeArray[i].checked) {
	    			selectedPaymentType = paymentTypeArray[i].value;
   			}
   		}
   	}
	
	if (!nameAndAddressErrors) {
		if (selectedPaymentType == 'undefined' || (selectedPaymentType < 1 || selectedPaymentType > 4)) {
			alert ('Please choose a payment type.');
			gotoAnchor('paymentType');
			ccErrors = true;
		} else if (document.masterForm.ccNumber.value.length < 10 || document.masterForm.paymentType.length > 16) {
			alert ('You have entered an invalid credit card number. Please try again.');
			document.masterForm.ccNumber.focus();
			document.masterForm.ccNumber.select();
			ccErrors = true;
		} else if (isNaN(ccExpMonthVar) || document.masterForm.ccExpMonth.value.length != 2) {
			alert ('You have entered an invalid credit card expiration month. Please try again. Note: January should be entered as \'01\'.');
			document.masterForm.ccExpMonth.focus();
			document.masterForm.ccExpMonth.select();
			ccErrors = true;
		} else if (isNaN(ccExpYearVar) || document.masterForm.ccExpYear.value.length != 2) {
			alert ('You have entered an invalid credit card expiration year. Note: 2003 should be entered as \'03\'. Please try again');
			document.masterForm.ccExpYear.focus();
			document.masterForm.ccExpYear.select();
			ccErrors = true;
		}
	}
	
	// If there are no account errors, proceed
	var userErrors = false;
	
	if (!nameAndAddressErrors && !ccErrors) {
		if (document.masterForm.USER_NAME.value.length < 4 || document.masterForm.USER_NAME.value.length > 30) {
			alert ('Your user name must be 4 to 30 characters long.');
			document.masterForm.USER_NAME.focus();
			document.masterForm.USER_NAME.select();
			userErrors = true;
		} else if (document.masterForm.USER_PASSWORD.value.length < 4 || document.masterForm.USER_PASSWORD.value.length > 30) {
			alert ('Your password must be 4 to 30 characters long.');
			document.masterForm.USER_PASSWORD.focus();
			document.masterForm.USER_PASSWORD.select();
			userErrors = true;
		} else if (document.masterForm.USER_PASSWORD.value != document.masterForm.USER_CONFIRM_PASSWORD.value) {
			alert ('Your passwords do not match. Please try again.');
			document.masterForm.USER_CONFIRM_PASSWORD.focus();
			document.masterForm.USER_CONFIRM_PASSWORD.select();
			userErrors = true;
		} else if (document.masterForm.USER_EMAIL_ADDRESS.value == "" 
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == -1
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(" ") != -1
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == 0
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == (document.masterForm.USER_EMAIL_ADDRESS.value.length - 1)
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") == -1
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") == (document.masterForm.USER_EMAIL_ADDRESS.value.length - 1)
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") + 1 == document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".")
				|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") + 1 == document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@")) {
			alert ('Please enter a valid email address.');
			document.masterForm.USER_EMAIL_ADDRESS.focus();
			document.masterForm.USER_EMAIL_ADDRESS.select();
			userErrors = true;
		}
	}
	
	if (!nameAndAddressErrors && !ccErrors && !userErrors) {
		doAction('process_subscription');
	}
}

// This function validates a subscription return form before submitting it
function processSubscriptionReturn() {
		
	// Perform some checks based on the document type
	var nameAndAddressErrors = false;
	
	if (document.masterForm.USER_REGISTER_FULL_NAME.value == "") {
		alert ('Please enter your full name.');
		document.masterForm.USER_REGISTER_FULL_NAME.focus();
		document.masterForm.USER_REGISTER_FULL_NAME.select();
		nameAndAddressErrors = true;
	} else if (document.masterForm.USER_REGISTER_ADDRESS_1.value == "") {
		alert ('Please enter at least one line for your address.');
		document.masterForm.USER_REGISTER_ADDRESS_1.focus();
		document.masterForm.USER_REGISTER_ADDRESS_1.select();
		nameAndAddressErrors = true;
	} else if (document.masterForm.USER_REGISTER_CITY.value == "") {
		alert ('Please enter your city.');
		document.masterForm.USER_REGISTER_CITY.focus();
		document.masterForm.USER_REGISTER_CITY.select();
		nameAndAddressErrors = true;
	} else if (((document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'United States') || (document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'Canada')) && document.masterForm.USER_REGISTER_STATE[document.masterForm.USER_REGISTER_STATE.selectedIndex].value == '') {
		alert ('Please choose your state.');
		gotoAnchor('state');
		nameAndAddressErrors = true;
	} else if (((document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'United States') || (document.masterForm.USER_REGISTER_COUNTRY[document.masterForm.USER_REGISTER_COUNTRY.selectedIndex].value == 'Canada')) && document.masterForm.USER_REGISTER_ZIPCODE.value == '') {
		alert ('Please enter your zip code.');
		document.masterForm.USER_REGISTER_ZIPCODE.focus();
		document.masterForm.USER_REGISTER_ZIPCODE.select();
		nameAndAddressErrors = true;
	}
	
	// Perform basic format validation for different credit cards
	var ccErrors = false;
	
	// Parse the credit card expiration date for validation
	var ccExpMonthVar = parseFloat(document.masterForm.ccExpMonth.value);
	var ccExpYearVar = parseFloat(document.masterForm.ccExpYear.value);
	
	// Obtain the selected payment type
	var paymentTypeArray = document.masterForm.paymentType;
	var selectedPaymentType = "undefined";

	if (paymentTypeArray) {
  		for (var i = 0; i < paymentTypeArray.length; i++) {
   			if (paymentTypeArray[i].checked) {
	    			selectedPaymentType = paymentTypeArray[i].value;
   			}
   		}
   	}
	
	if (!nameAndAddressErrors) {
		if (selectedPaymentType == 'undefined' || (selectedPaymentType < 1 || selectedPaymentType > 4)) {
			alert ('Please choose a payment type.');
			gotoAnchor('paymentType');
			ccErrors = true;
		} else if (document.masterForm.ccNumber.value.length < 10 || document.masterForm.paymentType.length > 16) {
			alert ('You have entered an invalid credit card number. Please try again.');
			document.masterForm.ccNumber.focus();
			document.masterForm.ccNumber.select();
			ccErrors = true;
		} else if (isNaN(ccExpMonthVar) || document.masterForm.ccExpMonth.value.length != 2) {
			alert ('You have entered an invalid credit card expiration month. Please try again. Note: January should be entered as \'01\'.');
			document.masterForm.ccExpMonth.focus();
			document.masterForm.ccExpMonth.select();
			ccErrors = true;
		} else if (isNaN(ccExpYearVar) || document.masterForm.ccExpYear.value.length != 2) {
			alert ('You have entered an invalid credit card expiration year. Note: 2003 should be entered as \'03\'. Please try again');
			document.masterForm.ccExpYear.focus();
			document.masterForm.ccExpYear.select();
			ccErrors = true;
		}
	}
	
	// If there are no account errors, proceed
	var userErrors = false;
	
	if (!nameAndAddressErrors && !ccErrors) {
		if (document.masterForm.USER_EMAIL_ADDRESS.value == "" 
			|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == -1
			|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(" ") != -1
			|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == 0
			|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") == (document.masterForm.USER_EMAIL_ADDRESS.value.length - 1)
			|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") == -1
			|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") == (document.masterForm.USER_EMAIL_ADDRESS.value.length - 1)
			|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@") + 1 == document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".")
			|| document.masterForm.USER_EMAIL_ADDRESS.value.indexOf(".") + 1 == document.masterForm.USER_EMAIL_ADDRESS.value.indexOf("@")) {
			alert ('Please enter a valid email address.');
			document.masterForm.USER_EMAIL_ADDRESS.focus();
			document.masterForm.USER_EMAIL_ADDRESS.select();
			userErrors = true;
		}
	}
	
	if (!nameAndAddressErrors && !ccErrors && !userErrors) {
		doAction('process_subscription_return');
	}
}
