function valid_c(frm) 
{
       var filledIn = false;

       // Use the length property to iterate through each Checkbox
       // to determine if a selection has been made
       for (var counter=0; counter<frm.elements['courses[]'].length; counter++)
           if (frm.elements['courses[]'][counter].checked == true)
               filledIn = true;

       if (filledIn == false)
       {
           alert('You must select at least one course');
           return false;
       }

       return true;
}

function valid_p(frm) 
{
       var filledIn = false;

       // Use the length property to iterate through each Checkbox
       // to determine if a selection has been made
       for (var counter=0; counter<frm.elements['packages[]'].length; counter++)
           if (frm.elements['packages[]'][counter].checked == true)
               filledIn = true;

       if (filledIn == false)
       {
           alert('You must select at least one package');
           return false;
       }

       return true;
}

/*
   This function returns true if the email address entered
   has the correct format x@y.z.... else it returns false.
   It's not perfect but it covers many cases.  
*/
function isValidEmailAddress(emailAddress)
{

   /* Check for empty address or invalid characters */

   if (emailAddress == "" || hasInvalidChar(emailAddress))
   {
      return false;
   }

   /* check for presence of the @ character */

   var atPos = emailAddress.indexOf("@", 1)
   if (atPos == -1)
   {
      return false;
   }
   
   /* Check that there are no more @ characters */

   if (emailAddress.indexOf("@", atPos + 1) > -1)
   {
      return false;
   }

   /* Check for the presence of a dot somewhere after @ */

   var dotPos = emailAddress.indexOf(".", atPos + 1);
   if (dotPos == -1)
   {
      return false;
   }

   /* Check for presence of two or more characters after last dot */

   var lastDotPos = emailAddress.lastIndexOf(".");
   if (lastDotPos + 3 >  emailAddress.length)
   {
      return false;
   }
   return true;
}

/*
   Return true if the given email address has an invalid character
   in it, else return false.
*/
function hasInvalidChar(emailAddress)
{
   var invalidChars = "/;:,"; // this list is not complete

   for (var k = 0; k < invalidChars.length; k++)
   {
      var ch = invalidChars.charAt(k);
      if (emailAddress.indexOf(ch) > -1)
      {
         return true;
      }
   }
   return false;
}
