
function copyInfo() {
	var theForm = document.forms.subscribeForm;
	if(theForm.sameAsShipping.checked == true) {
		theForm.bill_street1.value = theForm.ship_street1.value;
		theForm.bill_street2.value = theForm.ship_street2.value;
		theForm.bill_firstname.value = theForm.ship_firstname.value;
		theForm.bill_lastname.value = theForm.ship_lastname.value;
		theForm.bill_city.value = theForm.ship_city.value;
		theForm.bill_state.value = theForm.ship_state.value;
		theForm.bill_zip.value = theForm.ship_zip.value;
		theForm.bill_country.value = theForm.ship_country.value;
	}
}

/* Validate login */
function Validate(theForm){
    var why = "";
    	if (theForm.login_email != null) 
		    why += checkEmail(theForm.login_email.value);	    
    	if (theForm.login_password != null) 	    
		    why += checkPassword(theForm.login_password.value);
    
        if (why != "") {
    	  alert(why);
	       return false;
	    }
	return true; 
}

/* Validate password reset */
function validatePWReset(theForm) {
    var why = "";
    		why += checkEmpty(theForm.special_code.value, "special code", false);
		    why += checkEmail(theForm.login_email.value);
		    why += checkPassword(theForm.reset_password.value);
		    why += checkPasswordConfirm(theForm.reset_password.value, theForm.reset_password_confirm.value);

    if (why != "") {
       alert(why);
       return false;
    }
	theForm.submit();
return true;
}

/* Validate registration */
function validateRegistration(theForm) {
    var why = "";
		    why += checkEmpty(theForm.register_first_name.value, "first name", false);
		    why += checkEmpty(theForm.register_last_name.value, "last name", false);

			why += checkEmail(theForm.register_email.value);
		    why += checkConfirmEmail(theForm.register_email_confirm.value, theForm.register_email.value);
		    why += checkPassword(theForm.register_password.value);
		    why += checkPasswordConfirm(theForm.register_password_confirm.value, theForm.register_password.value);

			why += checkSubscriptionNumber(theForm.register_subscription_number);

    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

/* Validate free issue registration */
function validateFreeIssueRegistration(theForm) {
    var why = "";
		    why += checkEmpty(theForm.first_name.value, "first name", false);
		    why += checkEmpty(theForm.last_name.value, "last name", false);

			why += checkEmail(theForm.email.value);
		    why += checkConfirmEmail(theForm.conf_email.value, theForm.email.value);

			why += validateAddress(theForm);

    if (why != "") {
       alert(why);
       return false;
    }
	theForm.submit();
return true;
}

/* Validate GIVE THE GIFT OF COMMENTARY  subscribe_edgift.cfm */
function validateSubscribeEdGift(theForm) {
    var why = "";
	why += validateShipAddress(theForm);
	why += validateBillAddress(theForm);

	why += checkEmail(theForm.bill_email.value);
    why += checkConfirmEmail(theForm.bill_email2.value, theForm.bill_email.value);

	why += validateCreditCard(theForm);

    if (why != "") {
       alert(why);
       return false;
    }	
	return true;
}

/* Validate GIVE THE GIFT THAT LASTS ALL YEAR!  subscribe_gift.cfm */
function validateSubscribeGift(theForm) {
    var why = "";

	if(theForm.subscription.value == 1)
	{
		why += checkEmail(theForm.ship_email.value);
    	why += checkConfirmEmail(theForm.ship_email2.value, theForm.ship_email.value);
	}
	why += validateShipAddress(theForm);

	why += checkEmail(theForm.bill_email.value);
    why += checkConfirmEmail(theForm.bill_email2.value, theForm.bill_email.value);
	why += validateBillAddress(theForm);

	why += validateCreditCard(theForm);

    if (why != "") {
       alert(why);
       return false;
    }	
		theForm.submit();
	return true;
}

/* Validate GIVE THE GIFT THAT LASTS ALL YEAR!  subscribe_gift.cfm */
function validateBackIssue(theForm) {
    var why = "";

	if(theForm.type.value=='print')
		why += validateShipAddress(theForm);

	why += checkEmail(theForm.email.value);
    why += checkConfirmEmail(theForm.email2.value, theForm.email.value);
	why += validateBillAddress(theForm);

	why += validateCreditCard(theForm);

    if (why != "") {
       alert(why);
       return false;
    }	
	
	theForm.submit();
	return true;
}

/* Validate Donate  donate.cfm */
function validateDonate(theForm) {
    var why = "";

    why += checkEmpty(theForm.firstName.value, "first name", false);
    why += checkEmpty(theForm.lastName.value, "first name", false);
	why += checkEmail(theForm.email.value);
	if (typeof(theForm.emailConfirm)!='undefined') {
    	why += checkConfirmEmail(theForm.emailConfirm.value, theForm.email.value);
    }
    if(theForm.honor.checked)
	{
	if (theForm.cardOrEmail[0].checked) {
		why += checkEmpty(theForm.honnor_street_1.value, "Notification Street Address", false);
		why += checkEmpty(theForm.honnor_country.value, "Notification Country", false);
		why += checkEmpty(theForm.honnor_city.value, "Notification City", false);
		why += validateZip(theForm.honnor_zip.value, theForm.honnor_country.value);
		why += validateState(theForm.honnor_state.value, theForm.honnor_country.value);
    }
    else {
		why += checkEmail_cust(theForm.honnor_email.value, 'Please enter a valid notification e-mail address.');
    	why += checkConfirmEmail_cust(theForm.honnor_email_confirm.value, theForm.honnor_email.value, 'Please confirm your notification e-mail address.', 'Your notification e-mail addresses must match!');
    }
	}
	why += validateBillAddress(theForm);

	why += validateCreditCard(theForm);

    if (why != "") {
       alert(why);
       return false;
    }	
	theForm.submit();
	return true;
}

/* Validate Donate  donate.cfm */
function validateDonate07(theForm) {
    var why = "";

    why += checkEmpty(theForm.firstName.value, "first name", false);
    why += checkEmpty(theForm.lastName.value, "first name", false);
	why += checkEmail(theForm.email.value);
	if (typeof(theForm.emailConfirm)!='undefined') {
    	why += checkConfirmEmail(theForm.emailConfirm.value, theForm.email.value);
    }
   
	why += validateBillAddress(theForm);

	why += validateCreditCard(theForm);

    if (why != "") {
       alert(why);
       return false;
    }	
	theForm.submit();
	return true;
}


/* Validate CHANGE YOUR ADDRESS  updateaddresses.cfm */
function validateChangeAddress(theForm) {
    var why = "";

    why += checkEmpty(theForm.ship_firstname.value, "first name", false);
    why += checkEmpty(theForm.ship_lastname.value, "last name", false);
	why += validateShipAddress(theForm);

    why += checkEmpty(theForm.bill_firstname.value, "billing first name", false);
    why += checkEmpty(theForm.bill_lastname.value, "billing last name", false);
	why += validateBillAddress(theForm);

    if (why != "") {
       alert(why);
       return false;
    }	
		theForm.submit();
	return true;
}

/* Validate registration */
function validateNewRegistration(theForm) {
    var error = "";
		    error += checkEmpty(theForm.register_first_name.value, "first name", false);
		    error += checkEmpty(theForm.register_last_name.value, "last name", false);

			error += checkEmail(theForm.register_email.value);
		    error += checkConfirmEmail(theForm.register_email_confirm.value, theForm.register_email.value);
		    error += checkPassword(theForm.register_password.value);
		    error += checkPasswordConfirm(theForm.register_password_confirm.value, theForm.register_password_confirm.value);

		

  
return error;
}

/* Validate profile */
function validateProfile(theForm) {
    var why = "";
		    why += checkEmpty(theForm.first_name.value, "first name", false);
		    why += checkEmpty(theForm.last_name.value, "last name", false);
		    why += checkEmail(theForm.login_email.value);
		    why += checkPassword(theForm.login_password.value);
		    why += checkPasswordConfirm(theForm.login_password.value, theForm.login_password_confirm.value);

    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

/* Validate profile New */
function validateProfileNew(theForm) {
    var why = "";
		    why += checkEmpty(theForm.first_name.value, "first name", false);
		    why += checkEmpty(theForm.last_name.value, "last name", false);

			why += checkEmail(theForm.email1.value);
		    why += checkConfirmEmail(theForm.confirmemail1.value, theForm.email1.value);

		    why += checkPassword(theForm.login_password.value);
		    why += checkPasswordConfirm(theForm.login_password.value, theForm.login_password_confirm.value);

    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

/* Validate credit card profile */
function validateCreditCardProfile(theForm) {
    var why = "";
    why += validateCreditCard(theForm);

    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

/*
selected radio button
*/

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

/* Validate buy subscription*/

function validateSubscription(theForm){
	
    var why = "";
	if (theForm.logged.value == 0)
	{	why += validateNewRegistration(theForm);}
	why += validateBillAddress(theForm);

		if (theForm.subscription1.checked == false)
	{	why += validateShipAddress(theForm);}
	

	
	
	
	
	
	why += validateCreditCard(theForm);
    if (why != "") {
       alert(why);
       return false;
    }	
	theForm.submit();
return true;
}

/* Validate donation */

function validateDonation(theForm) {
    var why = "";
//		    why += checkEmail(theForm.login-email.value);
			why += checkAmount(theForm.selectamount.checked, theForm.otheramountvalue.value);
			why += validateCreditCard(theForm);
			why += validateBillAddress(theForm);
//		    why += checkConfirmEmail(theForm.register_email_confirm.value, theForm.register_email.value);

	if (why != "") {
		alert(why);
		return false;
	}
return true;
}


/* Validate Gift Certificate Purchase */

function validateGiftSubscription(theForm) {
    var why = "";
		    why += checkEmpty(theForm.first_name.value, "first name", true);
		    why += checkEmpty(theForm.last_name.value, "last name", true);
		    why += checkEmail(theForm.email.value);
			why += validateCreditCard(theForm);
			why += validateBillAddress(theForm);
			why += validateSubscriptionChoice(theForm);
			if(theForm.productHandle[0].checked || theForm.productHandle[3].checked) {
				why += validateShipAddress(theForm);
			}
	if (why != "") {
		alert(why);
		return false;
	}
return true;
}




/* Validate Educational Subscription */
//TODO
function validateEducationalForm(theForm) {
    var why = "";
		    why += checkEmpty(theForm.first_name.value, "first name", false);
		    why += checkEmpty(theForm.last_name.value, "last name", false);
		    why += checkPassword(theForm.password.value);
		    why += checkPasswordConfirm(theForm.password.value, theForm.password2.value);		    
		    why += checkEmail(theForm.email.value);
		    why += checkConfirmEmail(theForm.email.value, theForm.conf_email.value);
			why += validateAddress(theForm);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}


/* validate email friend form */
function validateEmailFriend(theForm){
	var why = "";
	why += checkEmail(theForm.from_address.value);
			
	var recipients = theForm.recipients.value.split(",");
	for (i=0;i<recipients.length;i++ )
	{
		why += checkEmail(recipients[i]);
	}

	if (why != "") {
       alert(why);
       return false;
    }
	return true;
}


/* validate email editor form */
function validateEmailEditor(theForm){
	var why = "";
	why += checkEmpty(theForm.name.value, "Name", false);
	why += checkEmail(theForm.email.value);
	why += checkEmpty(theForm.content.value, "Content", false);
	
			
	

	if (why != "") {
       alert(why);
       return false;
    }
	return true;
}

/* Validate article purchase page*/
//TODO
function validateArticlePurchase(theForm) {
    var why = "";
	why += validateBillAddress(theForm);
	why += validateCreditCard(theForm);
    if (why != "") {
       alert(why);
       return false;
    }	
	theForm.submit();
	return true;
}


function validateSubscriptionChoice(theForm){
    var error = "";
	if (theForm.subscribe_option_online_intl.checked || theForm.subscribe_option_online.checked )
		return "";
	
	var country = theForm.ship_country.value;
		if (country=="US")
		{
			if (!theForm.subscribe_option_print.checked)
			{
				return "For US shipping addresses, please select a US Print Subscription";
			}
		}
		else if (country == "CA" || country == "MX")
		{
			if (!theForm.subscribe_option_print_intl_nafta.checked)
			{
				return "For shipping addresses in Canada or Mexico, please select a Canada/Mexico Print Subscription";
			}
		}
		else if (!theForm.subscribe_option_print_intl.checked)
			return "For international shipping addresses, please select an international print subscription";

	return error;

}

function validateAddress(form) {
	var error = "";
	error += checkEmpty(form.street1.value, "Street Address", false);
	error += checkEmpty(form.country.value, "Country", false);
	error += checkEmpty(form.city.value, "City", false);
	error += validateZip(form.zip.value, form.country.value);
	error += validateState(form.state.value, form.country.value);
	return error;
}

function validateBillAddress(form) {
	var error = "";
	error += checkEmpty(form.bill_firstname.value, "Billing First Name", false);
	error += checkEmpty(form.bill_lastname.value, "Billing Last Name", false);
	error += checkEmpty(form.bill_street1.value, "Billing Street Address", false);
	error += checkEmpty(form.bill_country.value, "Country", false);
	error += checkEmpty(form.bill_city.value, "City", false);
	error += validateZip(form.bill_zip.value, form.bill_country.value);
	error += validateState(form.bill_state.value, form.bill_country.value);
	return error;
}

function validateShipAddress(form) {
	var error = "";
	error += checkEmpty(form.ship_firstname.value, "Shiping First Name", false);
	error += checkEmpty(form.ship_lastname.value, "Shiping Last Name", false);	
	error += checkEmpty(form.ship_street1.value, "Street 1", false);
	error += checkEmpty(form.ship_country.value, "Country", false);
	error += checkEmpty(form.ship_city.value, "City", false);
	error += validateZip(form.ship_zip.value, form.ship_country.value);
	error += validateState(form.ship_state.value, form.ship_country.value);
	return error;
}

function validateGiftAddress(form) {
	var error = "";
	error += checkEmpty(form.gift_street1.value, "Street 1", false);
	error += checkEmpty(form.gift_country.value, "Country", false);
	error += validateZip(form.gift_zip.value, form.gift_country.value);
	error += validateState(form.gift_state.value, form.gift_country.value);
	return error;
}

function validateAddress(form) {
	var error = "";
	error += checkEmpty(form.street1.value, "Street 1", false);
	error += checkEmpty(form.country.value, "Country", false);
	error += checkEmpty(form.city.value, "City", false);
	error += validateZip(form.zip.value, form.country.value);
	error += validateState(form.state_province.value, form.country.value);
	return error;
}


function validateCreditCard(form){
	var error = "";
	error += checkEmpty(form.name_on_card.value, "Name on the Credit Card", false);
	error += checkEmpty(form.card_expiration_month.value, "Expiration Month", false);
	error += checkEmpty(form.card_expiration_year.value, "Expiration Year", false);
	error += checkEmpty(form.card_type.value, "Card Type", false);
	error += checkEmpty(form.card_number.value, "Credit Card Number", false);
	error += checkValidCCDate(form.card_expiration_month.selectedIndex, form.card_expiration_year.value);
	
	return error;
}

function checkValidCCDate(month, year){
	var error = "";
	var today = new Date();
	month--; // convert to months 0 - 11
	if((today.getMonth() > month) && (today.getFullYear() >= year)){
		error = "Credit Card Expiration Date in the past";
	}
	return error;
}


function checkAmount(check, amt){
	var error = "";
	var digitfilter = /\d+/;
	if (check) {
		if (!(digitfilter.test(amt))){
			error = "You have invalid characters in your amount field, please enter in only digits and decimal values";
		}
		else if (amt < 1)
		{
			error = "The minimum donation amount is $1, please fill in a valid amount";
		}
	}
	return error;
}

function validateZip(zip, country) {
	var error="";
	var zipFilter = /\d+/;
	if (country == "CA" || country == "US")
	{
		if (zip.length < 5)
		{
			error = "Illegal zip/postal code.\n";
		}
		else if (zip.length > 10){
			error = "Illegal zip/postal code. \n";
		}
	}
	return error;
}

function validateState(state, country) {
	var error="";
	var zipFilter = /\d+/;
	if (country == "CA" || country == "US")
	{
		if (state.length < 1)
		{
			error = "State/Province is required for the US and Canada.\n";
		}
	}
	return error;
}



function checkEmail (strng) {
var error="";
	if (strng == "") {
	   error = "Please enter a valid e-mail address.\n";
	}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid e-mail address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "Please enter a valid e-mail address.\n";
       }
    }
return error;    
}


function checkConfirmEmail (strng, strng2) {
var error="";
	if (strng == "") {
	   error = "Please confirm your e-mail address.\n";
	}
    if (strng != strng2) {
	   error = "Your e-mail addresses must match!\n";
    }
return error;    
}

function checkEmail_cust (strng, message) {
var error="";
	if (message == "") {
		message = "Please enter a valid e-mail address.";
	}

	if (strng == "") {
	   error = message + "\n";
	}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = message + "\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = message + "\n";
       }
    }
return error;    
}


function checkConfirmEmail_cust (strng, strng2, message, message2) {
var error="";
	if (message == "") {
		message = "Please confirm your e-mail address.";
	}
	if (message2 == "") {
		message2 = "Your e-mail addresses must match!";
	}


	if (strng == "") {
	   error = message + "\n";
	}
    if (strng != strng2) {
	   error = message2 + "\n";
    }
return error;    
}

// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
	return error;
}


function checkSubscriptionNumber(strng){
	var error = "";
	if (strng.length > 0)
	{		
		if (strng.length != 16 || strng.length != 18) 
		{
			error = "Your subscription number must be 16 or 18 digits exactly";
		}
	}
	return error;
}



// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
	if (strng.length ==0 ) {
       error = "Please enter in a password.\n";
    }    
    else if ((strng.length < 5) || (strng.length > 20)) {
       error = "The password must be between 5-20 characters long.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    



function checkPasswordConfirm (passwd1, passwd2) {
var error = "";
if (passwd1== "") {
   error = "Please verify your password\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
	if (passwd1.length ==0 ) {
       error = "Please verify your password.\n";
    }    
    else if (passwd1 != passwd2) {
       error = "Your passwords must match\n";
    }
return error;    
}    



// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
	if (strng == "") {
	   error = "You didn't enter a username.\n";
	}
    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
return error;
}       

//Check Bill

function checkEmpty(strng, name, gift) {
var error = "";
  if (strng.length == 0) {
	 if (gift)
	 {
		error = "Please fill in the recipient's "+ name+".\n"
	 } else {
	     error = "Please fill in your "+ name+".\n"
	 }
  }
return error;	  
}




// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;	  
}

function checkEqual(string1, string2, msg) {
	if (string1 != string2)
	{
		return msg;
	}
}




// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}    



// javascript regular expressions for pattern checking
// must have a 4.0 browser
// expect a global ns4/ie4, otherwise, don't call these functions
// and let the server handle the type checking

// types array, no need to create anew each time
// add as many as you need
// currently, types can be function pointers that take one argument
// or re's

var focus = true;

var types = new Array();
types["w"] = /\w/;	//word
types["w1"] = /\w+/;	//word
types["d"] = /^\d*$/;
types["d1"] = /^\d+$/;
types["file"] = /\w/;
types["date"] = _is_date;
types["null_date"] = _is_null_date;
types["email"] = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
types["state"] = _is_state;
types["password"] = _check_password;
types["password_verify"] = _check_password_verify;
//separate match from password_verify if the need arises
types["match"] = _check_password_verify;
types["ccard_type"] = _check_credit_card_type;
types["ccard"] = _check_credit_card_num;
types["phone"] = /^([0-9\-\(\)])+$/;
types["and"] = _all_or_nothing;
types["or"] = _any;

function TypeChecker () {
    this.check_value = _check_value;
    this.check_form = _check_form;
}

function _all_or_nothing(vals) {
		var countTruth = 0;
		var countFalse = 0;
		for (i=0;i<vals.length;i++) {
			if (vals[i] != '') {
				countTruth++;
			} else {
				countFalse++;
			}
		}
		return ((countTruth==0) || (countFalse==0));
}

function _any(vals) {
		var toReturn = (vals[0]!='');
		for (i=0;i<vals.length;i++) {
			toReturn = toReturn || (vals[i]!='');
		}
		return toReturn;
}

function _check_password(val) {
	return (val.length > 4);
}

function _check_credit_card_type(vals) {
	//expects vals to be array of 2, first element is card type, 2nd element is ccard num
	var cardType=vals[0].toString();
	var cardNumber=vals[1].toString();
  
  var isValid = false;
  var ccCheckRegExp = /[^\d ]/;
  isValid = !ccCheckRegExp.test(cardNumber);

  if (isValid)
  {
    var cardNumbersOnly = cardNumber.replace(/ /g,"");
    var cardNumberLength = cardNumbersOnly.length;
    var lengthIsValid = false;
    var prefixIsValid = false;
    var prefixRegExp;

    switch(cardType)
    {
      case "Mastercard":
        lengthIsValid = (cardNumberLength == 16);
        prefixRegExp = /^5[1-5]/;
        break;

      case "Visa":
        lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
        prefixRegExp = /^4/;
        break;

      case "AmericanExpress":
        lengthIsValid = (cardNumberLength == 15);
        prefixRegExp = /^3(4|7)/;
        break;

      default:
        prefixRegExp = /^$/;
    }

    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
    isValid = prefixIsValid && lengthIsValid;
  }

  return isValid;
}

function _check_credit_card_num(val) {

		var cardNumber = val;
		
		var cardNumbersOnly = cardNumber.replace(/ /g,"");
    var cardNumberLength = cardNumbersOnly.length;
	
    var numberProduct;
    var numberProductDigitIndex;
    var checkSumTotal = 0;

    for (digitCounter = cardNumberLength - 1; 
      digitCounter >= 0; 
      digitCounter--)
    {
      checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
      digitCounter--;
      numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
      for (var productDigitCounter = 0;
        productDigitCounter < numberProduct.length; 
        productDigitCounter++)
      {
        checkSumTotal += 
          parseInt(numberProduct.charAt(productDigitCounter));
      }
    }

    return(checkSumTotal % 10 == 0);

}

function _check_password_verify(vals) {
x=vals[0].toString();
y=vals[1].toString();
	if (x == y) {
		return(true);
	} else { 
		return(false);
	}
}

function _is_state(val){
	return (val.length == 2);
}

function _is_date (val) {
    return Date.parse(val);
}

function _is_null_date (val) {
    if (val == "") {
	return true;
    } else {
	return Date.parse(val);
    }
}

function _check_value (vals, typ) {
	if (vals.length > 1) {
		return types[typ](vals);
	} else {
		var qq = new String(val);
		switch (typeof(types[typ])) {
	    case "undefined":
		return false;
	    case "object":
		return qq.match(types[typ]);
	    case "function":
		return types[typ](qq);
	    default:
		return false;
    }
	}
}


// this function expects to be passed
// an array of arrays of field names and expected types
// it will alert use and return true/false
// so the form knows whether or not to submit
// each sub array is in the form: new Array("field_name", "field_type", "error message"[, boolean ignore_empty_value]);
function _check_form (frm, fields) {
    var i, val, field, j;
    for(i=0; i<fields.length; i++) {
	val = "";
	
	strFieldnames = fields[i][0];
	fieldnames = strFieldnames.split("|");

	vals = new Array();
	
	has_val=0;
	for(m=0; m<fieldnames.length; m++) {
		//aryField[m] = frm[fieldnames[m]];
		vals[m] = new String(_get_val(frm[fieldnames[m]]));
		if(vals[m].length>0)
			has_val=1;
	}	
	if(fields[i][3] && !has_val) //skip if we are accepting empty values for this field
		continue;	

	if (! this.check_value(vals, fields[i][1])) {
	    alert(fields[i][2]);
	    if (focus) { frm[fieldnames[0]].focus() }
	    return false;
	}
    }
    return true;
}


function _get_val(field) {
    // first we catch radio buttons
	if (!field.type) {  // it's a radio or checkbox group
	    if (field.length > 0) {
			if (field[0].type.match(/radio/i)) {
				focus = false;
				val = ""; // was val = null;
				for(j=0; j<field.length; j++) {
					if (field[j].checked) {
						val = field[j].value;
					}
				}
			}
	    }
	} else if (field.type.match(/select/i)) {
	    val = new String(field.options[field.selectedIndex].value);
	} else if ((field.type.match(/text/)) || (field.type.match(/password/))) {
	    val = new String(field.value);
	} else if (field.type.match(/file/)) {
	    val = new String(field.value);
	} else if (field.type.match(/radio/)) {
	    val = new String(field.value);
		//alert(val);
	} else if (field.type.match(/checkbox/)) { 
         val = ""; 
          if (field.checked) {
               val = new String(field.value);
          }
	}
	return val;
	
}