////////////////
// NAVIGATION //
////////////////

// BASIC ACTIONS
// Function for performing basic actions
function doNavAction(action) {
	document.masterForm.action="nanotech.jsp";
	document.masterForm.admin_action.value = action;
	document.masterForm.submit();
}

// Function for performing subscriber-only actions
function doSubAction(action) {
	document.masterForm.action="nanotech_subscribers.jsp";
	document.masterForm.admin_action.value = action;
	document.masterForm.submit();
}

// Function to go to content
function gotoContentNano(publicationCode) {
	
	if (publicationCode == 'nanotech') {
		doSubAction('start');	
	} else {
		document.masterForm.action = '/newsletters/' + publicationCode.toLowerCase() + '/index.jsp';
		document.masterForm.admin_action.value = 'start';
	}

	document.masterForm.submit();
}


// FUNCTIONS FOR TOP NAV BAR
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function preloadImages() {
  MM_preloadImages('assets/images/subscribe_over.gif','assets/images/subscriber-login_over.gif','assets/images/newhome_dark.gif','assets/images/newnano_dark.gif','assets/images/newweekly_dark.gif','assets/images/newdaily_dark.gif','assets/images/newjosh_dark.gif','assets/images/newevents_dark.gif','assets/images/newcontact_dark.gif');
}

// FUNCTIONS FOR POP-UP WINDOWS
function showPopUp(name,url,width,height) { 
  window.open(url,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height);
}

function showPopUpScrolling(name,url,width,height) { 
  window.open(url,name,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+width+',height='+height);
}

function checkPopUp() {
  if (getCookie("email_alert")) {
    return false;
  }
  else {
    setCookie("email_alert","1");
    showPopUp('email_alert','http://img-cdn.mediaplex.com/ads/3072/13370/emailcapture.html',300,200);
    return true;
  }
}

// Functions for new site alert
function checkNewSitePopUp() {
  if (getCookie("new_site_alert")) {
    return false;
  }
  else {
    setCookie("new_site_alert","1");
    showPopUp('new_site_alert','new_site_alert.html',400,520);
    return true;
  }
}

function alertRegistration() {
	window.opener.document.location = "http://www.forbesinc.com/newsletters/nanotech/nanotech.jsp?page=register_by_account_number";
	window.close();
}


// COOKIE FUNCTIONS
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function setCookie(name,value) {
  var argv = setCookie.arguments;
  var argc = setCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}


//////////////////
// REGISTRATION //
//////////////////
// Handles form validation for a register action
function nanoRegister() {
	
	// 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) {
		return true;
	} else {
		return false;
	}
}

// Handles form validation for a register return action (i.e. registration attempts 2 to n)
function nanoRegisterReturn() {
	
	// 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) {
		return true;
	} else {
		return false;
	}
}


/////////////////////////
// ACCOUNT MAINTENANCE //
/////////////////////////
function nanoChangePassword() {
	
	// 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) {
		return true;
	} else {
		return false;
	}
}

function nanoChangeEmailAddress() {
	
	// 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) {
		return true;
	} else {
		return false;
	}
}

// Handles form validation for an account lookup action
function nanoAccountLookup() {
	
	// 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) {
		return true;
	} else {
		return false;
	}
}


///////////////
// SUBSCRIBE //
///////////////
// This function validates a subscription form before submitting it
function nanoProcessSubscription() {
		
	// 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) {
		return true;
	} else {
		return false;
	}
}

// This function validates a subscription return form before submitting it
function nanoProcessSubscriptionReturn() {
		
	// 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) {
		return true;
	} else {
		return false;
	}
}
