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_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 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_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_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function openPopup(win_url,win_name,properties) {
  window.open(win_url,win_name,properties);
}

// Function that calls script to redisplay roster with
// new location id selected
function submit_new_location() {
document.roster.new_location.value = "Y";
document.roster.submit();
}

// Function that calls script to redisplay roster with
// new location id selected
function submit_new_meeting() {
document.roster.new_meeting.value = "Y";
document.roster.submit();
}


// Data entry error checking functions
// A utility function that returns true if a string contains only 
// whitespace characters.
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}
//////////////////////////////////////////////////////////////////////
// This is the function that performs form verification for the 
// Distributor application form. It is invoked from the onsubmit()
// event handler. The handler should return whatever value this
// function returns.

function dist_appl_verify(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var prod_of_interest = "";
    var last_name = /lastname$/;
    var first_name = /firstname$/;
    var address = /address1$/;
    var city = /city$/;
    var state = /state$/;
    var zip = /zip$/;
    var country =/country$/;
    var day_phone =/day_phone$/;
    var password =/password$/;
    var email_field = /email$/;
    var tax_id = /tax_id$/;
    var dist_cat = /dist_cat/;
    var dist_status = /dist_status/;
    var how_sell = /HowSell/;
    var how_many = /HowMany/;
    var how_long = /HowLong/;

// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Put together error messages for fields that are wrong.

//alert("In  dist_appl_verify");
//alert("number of fields is " + f.length);

    for (var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);

	// Don't need to check hidden fields
      if (e.type == "hidden") { continue; }

      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(email_field)
	 if ( result != null)
           empty_fields += "\n          Email";
         var result = e.name.match(password)
	 if ( result != null)
           empty_fields += "\n          Password";
         var result = e.name.match(first_name)
	 if ( result != null)
           empty_fields += "\n          First Name";
         var result = e.name.match(last_name)
	 if ( result != null)
           empty_fields += "\n          Last Name";
         var result = e.name.match(address)
	 if ( result != null)
           empty_fields += "\n          Address";
         var result = e.name.match(city)
	 if ( result != null)
           empty_fields += "\n          City";
         var result = e.name.match(state)
	 if ( result != null)
           empty_fields += "\n          State";
         var result = e.name.match(zip)
	 if ( result != null)
           empty_fields += "\n          Zip";
         var result = e.name.match(country)
	 if ( result != null)
           empty_fields += "\n          Country";
         var result = e.name.match(day_phone)
	 if ( result != null)
           empty_fields += "\n          Day Phone";
         var result = e.name.match(tax_id)
	 if ( result != null)
           empty_fields += "\n          Tax ID/SSN";
         var result = e.name.match(how_sell)
	 if ( result != null)
           empty_fields += "\n          How Will You Sell Nukkles";
         continue;
        } // end if null field

       var result = e.name.match(email_field);
       if ( result != null)  {          // if email field
	 var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	 var result_exp = e.value.match(email_exp);
         if ( ! result_exp ) {
 	   errors += "- The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
           continue;
         } // end !result_exp
       } // end !result 
      } // end if text ....

     //Check that a state has been selected
      if (e.name == "billstate") { 
    	if (e.options[0].selected)  // if "Select State" label selected
      	  errors += "You must select a state.\n\n";
      }

    // Check that a Distributor Status has been selected
      if (e.name == "dist_status") { 
	if (e.options[0].selected)  // if "Specify Distributor Status" label selected
      	  errors += "You must select a Distributor Status.\n\n";
      }

    // Check that a Distributor Category has been selected
      if (e.name == "dist_cat") { 
	if (e.options[0].selected)  // if "Specify Distributor Category" label selected
      	  errors += "You must select a Distributor Category.\n\n";
      }

    // Check that How Long in Business is specified
      if (e.name == "HowLong") { 
	if (e.options[0].selected)  // if "How Long?" label selected
      	  errors += "You must specify how long you've been in business.\n\n";
      }

    // Check that How Many is specified
      if (e.name == "HowMany") { 
	if (e.options[0].selected)  // if "How Many?" label selected
      	  errors += "You must specify how many you expect to sell.\n\n";
      }

    // Check that a password has been entered
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(password)
	 if ( result != null)
           empty_fields += "\n          Password";
       }

  // Check to see that one or more products of interest were selected
       if ( e.name == "int_nukkles" && e.checked )  {
          prod_of_interest = "yes";
       }
       if ( e.name == "int_botfresh" && e.checked )  {
          prod_of_interest = "yes";
       }
       if ( e.name == "int_ajax" && e.checked )  {
          prod_of_interest = "yes";
       }

    } // end for

    if ( prod_of_interest != "yes" ) {
      errors += "You must select one or more Products of Interest.\n\n";
    }

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

//////////////////////////////////////////////////////////////////////
// This is the function that performs form verification to determine
// that all fields for billing and shipping info has been entered
// for a BodyTimeWellness Distributor order. It is invoked
// from the onsubmit() event handler. The handler should return whatever
// value this function returns.
function dist_ship_info_verify(f)
{
    var msg;
    var empty_fields = "";
    var ship_empty_fields = "";
    var errors = "";
    var ship_errors = "";
    var shiptobilladdr = "";
    var bill_last_name = /lastname$/;
    var bill_first_name = /firstname$/;
    var bill_address = /billstreet1$/;
    var bill_city = /billcity$/;
    var bill_state = /billstate$/;
    var bill_zip = /billzip$/;
    var bill_country =/billcountry$/;
    var ship_name = /shipname$/;
    var ship_address = /shipstreet1$/;
    var ship_city = /shipcity$/;
    var ship_state = /shipstate$/;
    var ship_zip = /shipzip$/;
    var ship_country =/shipcountry$/;

// alert("in function dist_ship_info_verify\n");

// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Next, check that an actual month & day or date are selected.
// Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

// alert("var = " + e);

	// Don't need to check hidden fields
      if (e.type == "hidden") { continue; }

      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(bill_first_name)
	 if ( result != null)
           empty_fields += "\n          Billing First Name";
         var result = e.name.match(bill_last_name)
	 if ( result != null)
           empty_fields += "\n          Billing Last Name";
         var result = e.name.match(bill_address)
	 if ( result != null)
           empty_fields += "\n          Billing Address";
         var result = e.name.match(bill_city)
	 if ( result != null)
           empty_fields += "\n          Billing City";
         var result = e.name.match(bill_zip)
	 if ( result != null)
           empty_fields += "\n          Billing Zip";
         var result = e.name.match(bill_country)
	 if ( result != null)
           empty_fields += "\n          Billing Country";
//// shipping info -- won't matter if "shiptobilladdress" box checked
         var result = e.name.match(ship_name)
	 if ( result != null)
           ship_empty_fields += "\n          Shipping Name";
         var result = e.name.match(ship_address)
	 if ( result != null)
           ship_empty_fields += "\n          Shipping Address";
         var result = e.name.match(ship_city)
	 if ( result != null)
          ship_empty_fields += "\n          Shipping City";
         var result = e.name.match(ship_zip)
	 if ( result != null)
           ship_empty_fields += "\n          Shipping Zip";
         var result = e.name.match(ship_country)
	 if ( result != null)
           ship_empty_fields += "\n          Shipping Country";
         continue;
        } // end if null field
      } // end if text

    // Check that a shipping state has been selected
      if (e.name == "shipstate") { 
     	if (e.options[0].selected)  // if "Select State" label selected
      	  ship_errors += "You must select a state for the shipping address.\n\n";
     }

    // See if this is "Ship to Billing Address", and if checked
        if (e.name == "shiptobilladdr" && e.checked) {
          shiptobilladdr = "yes";
        }
    } // end for

    if (shiptobilladdr != "yes") {
      empty_fields += ship_empty_fields;
      errors += ship_errors;
    }
    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors ) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

//////////////////////////////////////////////////////////////////////
// This is the function that performs form verification. It is invoked
// from the onsubmit() event handler. The handler should return whatever
// value this function returns.
function btw_verify(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var last_name = /lastname$/;
    var first_name = /firstname$/;
    var address = /billstreet1$/;
    var city = /billcity$/;
    var state = /billstate$/;
    var zip = /billzip$/;
    var country =/billcountry$/;
    var password =/password$/;
    var email_field = /email$/;
    var cc_num_field = /^ccnum/;
    var dist_cat_field = /dist_cat/;
    var dist_status_field = /dist_status/;
    // non-digit characters which are allowed in credit card numbers
    var creditCardDelimiters = "- "     // space or hyphen

// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Next, check that an actual month & day or date are selected.
// Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);

	// Don't need to check hidden fields
      if (e.type == "hidden") { continue; }

      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(first_name)
	 if ( result != null)
           empty_fields += "\n          First Name";
         var result = e.name.match(last_name)
	 if ( result != null)
           empty_fields += "\n          Last Name";
         var result = e.name.match(address)
	 if ( result != null)
           empty_fields += "\n          Address";
         var result = e.name.match(city)
	 if ( result != null)
           empty_fields += "\n          City";
         var result = e.name.match(zip)
	 if ( result != null)
           empty_fields += "\n          Zip";
         var result = e.name.match(country)
	 if ( result != null)
           empty_fields += "\n          Country";
         var result = e.name.match(email_field)
	 if ( result != null)
           empty_fields += "\n          Email";
         var result = e.name.match(cc_num_field)
	 if ( result != null)
           empty_fields += "\n          Credit Card Number";
         continue;
        } // end if null field
       var result = e.name.match(email_field);
       if ( result != null)  {          // if email field
	 var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	 var result_exp = e.value.match(email_exp);
         if ( ! result_exp ) {
 	   errors += "- The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
           continue;
         } // end !result_exp
       } // end !result 
       var result = e.name.match(cc_num_field);
       if ( result != null)  {          // if credit card number field
         var normalizedCCN = strip_chars(e.value, creditCardDelimiters)
	 var card_type = get_selected_value(f.cctype);
//alert("card = " + card_type + "  number = " + normalizedCCN);
	 if (!isCardMatch(card_type, normalizedCCN)) {
	   errors += "- The Credit Card Number field must contain a valid credit card number\n   (e.g., 9999 9999 9999 9999)\n";
           continue;
	 } // end if valid card number
       } // end if card_number
      } // end if text

    // Check that a state has been selected
    //  if (e.name == "billstate") { 
    //	if (e.options[0].selected)  // if "Select State" label selected
    //  	  errors += "You must select a state.\n\n";
    //  }

    // Check that a Distributor Status has been selected
    //  if (e.name == "dist_status") { 
    // if (e.options[0].selected)  // if "Specify Distributor Status" label selected
    //   errors += "You must select a Distributor Status.\n\n";
    //  }

    // Check that a Distributor Category has been selected
    //  if (e.name == "dist_cat") { 
    //    if (e.options[0].selected)  // if "Specify Distributor Category" label selected
    //      errors += "You must select a Distributor Category.\n\n";
    //  }

    // Check that a password has been entered
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(password)
	 if ( result != null)
           empty_fields += "\n          Password";
       }


    } // end for

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

// This is the function that performs form verification. It is invoked
// from the onsubmit() event handler. The handler should return whatever
// value this function returns.
function verify(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var last_name = /lastname$/;
    var first_name = /firstname$/;
    var address = /billaddress1$/;
    var city = /billcity$/;
    var state = /billstate$/;
    var zip = /billzip$/;
    var country =/billcountry$/;
    var password =/password$/;
    var email_field = /email$/;
    var cc_num_field = /^ccnum/;
    // non-digit characters which are allowed in credit card numbers
    var creditCardDelimiters = "- "     // space or hyphen

// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Next, check that an actual month & day or date are selected.
// Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);

	// Don't need to check hidden fields
      if (e.type == "hidden") { continue; }

      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(first_name)
	 if ( result != null)
           empty_fields += "\n          First Name";
         var result = e.name.match(last_name)
	 if ( result != null)
           empty_fields += "\n          Last Name";
         var result = e.name.match(address)
	 if ( result != null)
           empty_fields += "\n          Address";
         var result = e.name.match(city)
	 if ( result != null)
           empty_fields += "\n          City";
         var result = e.name.match(zip)
	 if ( result != null)
           empty_fields += "\n          Zip";
         var result = e.name.match(country)
	 if ( result != null)
           empty_fields += "\n          Country";
         var result = e.name.match(email_field)
	 if ( result != null)
           empty_fields += "\n          Email";
         var result = e.name.match(cc_num_field)
	 if ( result != null)
           empty_fields += "\n          Credit Card Number";
         continue;
        } // end if null field
       var result = e.name.match(email_field);
       if ( result != null)  {          // if email field
	 var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	 var result_exp = e.value.match(email_exp);
         if ( ! result_exp ) {
 	   errors += "- The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
           continue;
         } // end !result_exp
       } // end !result 
       var result = e.name.match(cc_num_field);
       if ( result != null)  {          // if credit card number field
         var normalizedCCN = strip_chars(e.value, creditCardDelimiters)
	 var card_type = get_selected_value(f.cctype);
//alert("card = " + card_type + "  number = " + normalizedCCN);
	 if (!isCardMatch(card_type, normalizedCCN)) {
	   errors += "- The Credit Card Number field must contain a valid credit card number\n   (e.g., 9999 9999 9999 9999)\n";
           continue;
	 } // end if valid card number
       } // end if card_number
      } // end if text

    // Check that a state has been selected
      if (e.name == "billstate") { 
	if (e.options[0].selected)  // if "Select State" label selected
      	  errors += "You must select a state.\n\n";
      }

    // Check that a location has been selected
      if (e.name == "location") { 
	if (e.options[0].selected)  // if "Location" label selected
      	  errors += "You must select a location.\n\n";
      }

    // Check that a password has been entered
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(password)
	 if ( result != null)
           empty_fields += "\n          Password";
       }


    } // end for

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

//  ******** VERIFY LOGIN ****************

function verify_login(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var password =/credential_1/;
    var email_field = /credential_0/;

// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);
      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(email_field)
	 if ( result != null)
           empty_fields += "\n          Email";
         continue;
        } // end if null field
	var result = e.name.match(email_field);
        if ( result != null)  {          // if email field
	  var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	  var result_exp = e.value.match(email_exp);
          if ( ! result_exp ) {
 	    errors += "- The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n";
            continue;
          } // end !result_exp
        } // end !result 
      } // end if text

      // Check that a password has been entered
      if ((e.value == null) || (e.value == "") || isblank(e.value)) {
        var result = e.name.match(password)
	if ( result != null)
          empty_fields += "\n          Password";
      }
   } // end for

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}


//  ******** VERIFY ROSTER ****************

// This is the function that performs form verification for roster add
// participant. It is invoked from the onsubmit() event handler. 
// The handler should return whatever value this function returns.
function verify_roster(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
    var last_name = /lastname$/;
    var first_name = /firstname$/;
    var gift = /^gift_/;
    var giftselected;

// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);

	// Don't need to check hidden fields
      if (e.type == "hidden") { continue; }

      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(first_name)
	 if ( result != null)
           empty_fields += "\n          First Name";
         var result = e.name.match(last_name)
	 if ( result != null)
           empty_fields += "\n          Last Name";
         continue;
        } // end if null field
      	// Check for gift select
	var result = e.name.match(gift)
	if ( result != null)
	  if (e.value)
	    giftselected = 1;	 
      } // end if text

      // If pay method selected, amount pd must be filled in
      if ( e.type == "radio" && e.checked && e.value != "" ) {
        var pay_method = /^method$/;
	var result = e.name.match(pay_method)
	if (result != null) {  // if pay_method radio
	  var amt_pd = /^amt_pd$/;
          if ((f.amt_pd.value == null) || (f.amt_pd.value == "") || isblank(f.amt_pd.value)) 
            errors+= "Amount paid must be entered, if payment method selected.\n\n";
	} // end if pay_method
      } // end if radio & checked

// Check to see that release is signed & if comm_method-email is checked,
// must have a valid email address

      if ( e.type == "checkbox" ){
        var release = /^release$/;
	var result = e.name.match(release)
	if (result != null){  // if release checkbox
	  if (! e.checked ) 
	    errors+= "- Acceptance of Responsibility must be signed in order to continue this registration.\n\n"; 
        } // end if release
	var comm_method = /^comm_method$/;
	var result = e.name.match(comm_method)
	if (result != null) {  // if comm_method checkbox
	  if ( e.checked ) { 
            var email = /^email$/;
            if ((f.email.value == null) || (f.email.value == "") || isblank(f.email.value)) 
              errors+= "- Email required if registering to receive program materials via email.\n\n"; 
 	    else {  // email entered in field
	      var email_exp = /^[\S]+\@[\S]+\.[\S]+$/;
	      var result_exp = f.email.value.match(email_exp);
              if ( ! result_exp ) {
 	        errors += "- The E-mail field must contain a single valid email address (e.g. yourname@isp.com)\n\n";
              } // end if !result_exp
            } // end else
	  } // end if checked
	} // end if comm_method

	// Check to see that a gift (or "None") was selected
	var nogift = /^gift_None/;
	var result = e.name.match(nogift);
	if (result != null){  // if 'no gift' checkbox
	  if (! e.checked && !giftselected)  {
 	    errors += "- You must select a gift or 'None'.\n\n";
          } // end if !checked
	  // Check to see that both gift & None are not selected
	  else if (e.checked && giftselected) {
 	    errors += "- You cannot select a gift and 'None'.\n\n";
          } // end if checked
        } // end if !null
      } // end if checkbox
   } // end for

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}

//  ******** VERIFY CREDIT CARD ****************

// This is the function that performs form verification. It is invoked
// from the onsubmit() event handler. The handler should return whatever
// value this function returns.
function verify_cc(f)
{

    var msg;
    var empty_fields = "";
    var errors = "";
    var last_name = /lastname$/;
    var first_name = /firstname$/;
    var address = /billstreet1$/;
    var city = /billcity$/;
    var state = /billstate$/;
    var zip = /billzip$/;
    var ccnum = /^ccnumber/;

    // non-digit characters which are allowed in credit card numbers
    var creditCardDelimiters = "- "     // space or hyphen

// Loop through the elements of the form, looking for all 
// text and textarea elements that don't have an "optional" property
// defined. Then, check for fields that are empty and make a list of them.
// Next, check that an actual month & day or date are selected.
// Put together error messages for fields that are wrong.
    for(var i = 0; i < f.length; i++) {
      var e = f.elements[i];

//alert("var = " + e);

	// Don't need to check hidden fields
      if (e.type == "hidden") { continue; }

      if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
        // first check if the field is empty
       if ((e.value == null) || (e.value == "") || isblank(e.value)) {
         var result = e.name.match(first_name)
	 if ( result != null)
           empty_fields += "\n          First Name";
         var result = e.name.match(last_name)
	 if ( result != null)
           empty_fields += "\n          Last Name";
         var result = e.name.match(address)
	 if ( result != null)
           empty_fields += "\n          Address";
         var result = e.name.match(city)
	 if ( result != null)
           empty_fields += "\n          City";
         var result = e.name.match(zip)
	 if ( result != null)
           empty_fields += "\n          Zip";
         var result = e.name.match(ccnum)
	 if ( result != null)
           empty_fields += "\n          Credit Card Number";
         continue;
        } // end if null field
       var result = e.name.match(ccnum);
       if ( result != null)  {          // if credit card number field
         var normalizedCCN = strip_chars(e.value, creditCardDelimiters)
	 var card_type = get_selected_value(f.cctype);
//alert("card = " + card_type + "  number = " + normalizedCCN);
	 if (!isCardMatch(card_type, normalizedCCN)) {
	   errors += "- The Credit Card Number field must contain a valid credit card number\n   (e.g., 9999 9999 9999 9999)\n";
           continue;
	 } // end if valid card number
       } // end if card_number
      } // end if text

    // Check that a state has been selected
      if (e.name == "billstate") { 
	if (e.options[0].selected)  // if "Select State" label selected
      	  errors += "You must select a state.\n\n";
      }

    // Check that a month has been selected
      if (e.name == "ccexpmonth") { 
	if (e.options[0].selected)  // if "Month" label selected
      	  errors += "You must select a expiration month.\n\n";
      }

    // Check that a year has been selected
      if (e.name == "ccexpyear") { 
	if (e.options[0].selected)  // if "Year" label selected
      	  errors += "You must select a expiration year.\n\n";
      }

    } // end for

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) {
      msg += "- The following required field(s) are empty:" 
            + empty_fields + "\n";
     if (errors) msg += "\n";
    }
    msg += errors;
    alert(msg);
    return false;
}



// Removes all characters which appear in string bag from string s.
function strip_chars (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// Get checked value from select menu.
function get_selected_value (select_field)
{   for (var i = 0; i < select_field.length; i++)
    {   if (select_field.options[i].selected) { break }
    }
    return select_field.options[i].value
}

/*  ================================================================
    FUNCTION:  isCardMatch()
 
    INPUT:    cardType - a string representing the credit card type
	      cardNumber - a string representing a credit card number

    RETURNS:  true, if the credit card number is valid for the particular
	      credit card type given in "cardType".
		    
	      false, otherwise
    ================================================================ */
function isCardMatch (cardType, cardNumber)
{

	cardType = cardType.toUpperCase();
	var doesMatch = true;
//alert("card type = " + cardType);
	if ((cardType == "VISA") && (!isVisa(cardNumber)))
		doesMatch = false;
	if ((cardType == "MASTERCARD") && (!isMasterCard(cardNumber)))
		doesMatch = false;
	if ((cardType == "AMEX") && (!isAmericanExpress(cardNumber)))
	        doesMatch = false;
	if ((cardType == "DISCOVER") && (!isDiscover(cardNumber)))
		doesMatch = false;
	return doesMatch;

}  // END FUNCTION CardMatch()

/*  ================================================================
    FUNCTION:  isVisa()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid VISA number.
		    
	      false, otherwise

    Sample number: 4111 1111 1111 1111 (16 digits)
    ================================================================ */
function isVisa(cc)
{
  if (((cc.length == 16) || (cc.length == 13)) &&
      (cc.substring(0,1) == "4"))
    return isCreditCard(cc);
  return false;
}  // END FUNCTION isVisa()

/*  ================================================================
    FUNCTION:  isMasterCard()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid MasterCard
		    number.
		    
	      false, otherwise

    Sample number: 5500 0000 0000 0004 (16 digits)
    ================================================================ */
function isMasterCard(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 16) && (firstdig == "5") &&
      ((seconddig >= "1") && (seconddig <= "5")))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isMasterCard()

/*  ================================================================
    FUNCTION:  isAmericanExpress()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid American
		    Express number.
		    
	      false, otherwise

    Sample number: 340000000000009 (15 digits)
    ================================================================ */
function isAmericanExpress(cc)
{
  firstdig = cc.substring(0,1);
  seconddig = cc.substring(1,2);
  if ((cc.length == 15) && (firstdig == "3") &&
      ((seconddig == "4") || (seconddig == "7")))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isAmericanExpress()


/*  ================================================================
    FUNCTION:  isDiscover()
 
    INPUT:     cc - a string representing a credit card number

    RETURNS:  true, if the credit card number is a valid Discover
		    card number.
		    
	      false, otherwise

    Sample number: 6011000000000004 (16 digits)
    ================================================================ */
function isDiscover(cc)
{
  first4digs = cc.substring(0,4);
  if ((cc.length == 16) && (first4digs == "6011"))
    return isCreditCard(cc);
  return false;

} // END FUNCTION isDiscover()


/*  ================================================================
    FUNCTION:  isCreditCard(st)
 
    INPUT:     st - a string representing a credit card number

    RETURNS:  true, if the credit card number passes the Luhn Mod-10
		    test.
	      false, otherwise
    ================================================================ */

function isCreditCard(st) {
  // Encoding only works on cards with less than 19 digits
  if (st.length > 19)
    return (false);

  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
// Uncomment the following line to help create credit card numbers
// 1. Create a dummy number with a 0 as the last digit
// 2. Examine the sum written out
// 3. Replace the last digit with the difference between the sum and
//    the next multiple of 10.

//  document.writeln("<BR>Sum      = ",sum,"<BR>");
//  alert("Sum      = " + sum);

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

} // END FUNCTION isCreditCard()

