
  function checkEmail (strng) {
    var error="";
    if (strng == "") {
      error = "The following field has not been filled in: Email\n";
	}
    else{
      var emailFilter=/^.+@.+\..{2,3}$/;
      if (!(emailFilter.test(strng))) {
        error = "The email address entered is invalid.\n";
      }
      else {
        //test email for illegal characters
        var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
	    }
      }
	}
  return error;
  }


  // phone number - strip out delimiters and check for 10 digits
  function checkPhone (strng) {
  var error = "";
  if (strng == "") {
     error = "The following field has not been filled in: Phone Number\n";
  }
  else {
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

    if (isNaN(parseInt(stripped))) {
      error = "The phone number contains illegal characters.\n";
	}
    else if (!(stripped.length == 10)) {
      error = "The phone number is the wrong length. Make sure you included an area code.\n";
    }
  }
  return error;
  }

  //Fax function needed as a fax number is not required on all forms
  function checkFax (strng) {
    var error = "";
    if (strng == "") {
      error = "";
    }
    else {
      var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

      if (isNaN(parseInt(stripped))) {
        error = "The fax number contains illegal characters.";
	  }
      else if (!(stripped.length == 10)) {
        error = "The fax number is the wrong length. Make sure you included an area code.\n";
      }
    }
    return error;
  }

  // non-empty textbox
  function isEmpty(strng) {
  var error = "";
    if (strng.length == 0) {
       error = "The following field has not been filled in: "
    }
  return error;
  }
  
  // Year of birth - strip out delimiters and check for 4 digits
  function checkYear(strng) {
  var error = "";
  if (strng == "") {
     error = "The following field has not been filled in: Year of Birth\n";
  }
  else {
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

    if (isNaN(parseInt(stripped))) {
      error = "The year of birth contains illegal characters.\n";
	}
    else if (!(stripped.length == 4)) {
      error = "The year of birth is the wrong length. You must enter a 4 digit year.\n";
    }
  }
  return error;
  }
  
  // AreaID - check for 5 digits
  function checkAreaID(strng) {
  var error = "";
  if (strng == "") {
     error = "The following field has not been filled in: Area ID\n";
  }
  else {
    
    if (isNaN(parseInt(strng))) {
      error = "The Area ID contains illegal characters.\n";
	}
    
  }
  return error;
  }
  
  

  // exactly one radio button is chosen
  function checkRadio(checkvalue) {
  var error = "";
      if (!(checkvalue)) {
         error = "Please check a radio button: ";
      }
  return error;
  }
  
  function checkRadioGroup(radioGroup) {
    var error = "";
    var valid = false;
    
	// if the button group is an array (one button is not an array)
    if (radioGroup[0]) { 
      for (var i=0; i<radioGroup.length; i++) {
        if (radioGroup[i].checked) {
          valid = true
        }
      }
    } else {
	  // if the one button is checked, return zero
      if (radioGroup.checked) {
	    valid = true;
	  }
    }

    if (!(valid)) {
      error = "Please check a radio button: ";
    }
    return error;
  }
  
  //Check for a checkbox selection - terms and conditions
  function checkCheckbox(checkvalue) {
  var error = "";
      if (!(checkvalue.checked)) {
         error = "Please check the Terms & Conditions box. ";
      }
  return error;
  }

  //Check for a checkbox selection - minimum requirements
  function checkCheckbox2(checkvalue) {
  var error = "";
      if (!(checkvalue.checked)) {
         error = "Please agree to the minimum requirements. ";
      }
  return error;
  }
  
  //Check for a checkbox selection - courses
  function checkCourses(course1, course2, course3, course4) {
  var error = "";
      if (!(course1.checked) && !(course2.checked) && !(course3.checked) && !(course4.checked)){
         error = "You have not selected any course(s) to register for. \n";
      }
  return error;
  }
  
  //Check for a checkbox selection - courses on confirm2.asp
  function checkCourses2(course1, course2, course3, course4, course5, course6) {
  var error = "";
      if (!(course1.checked) && !(course2.checked) && !(course3.checked) && !(course4.checked) && !(course5.checked) && !(course6.checked)){
         error = "You have not selected any course(s) to register for. \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: ";
      }
  return error;
  }

  // Check that a Canadian postal code is valid
  function checkPostal(strng) {
    var error = "";
	if (strng == "") {
      error = "The following field has not been filled in: Postal Code\n";
    }
    else if (strng.search) {
      strng = removeSpaces(strng);
	  if (strng.length == 6 && strng.search(/^[a-zA-Z]\d[a-zA-Z]\d[a-zA-Z]\d$/) != -1);
	  else if (strng.length == 7 && strng.search(/^[a-zA-Z]\d[a-zA-Z]-\d[a-zA-Z]\d$/) != -1);
	  else {
        error = "The entered postal code is invalid.\n"
	  }
    }
    return error;
  }
  
  //Check for an expired credit card
  function checkExpired( month, year ) {
    var error = "";
    var now = new Date();
	//alert(month +"----"+year);
    var expiresIn = new Date(year,month);// create an expired on date object with valid thru expiration date
    expiresIn.setMonth(expiresIn.getMonth());// adjust the month, to first day, hour, minute & second of expired month    
    if( now.getTime() > expiresIn.getTime() ){
    error = "Your credit card has expired.\n";
    }
    return error;
  }
  
  // Credit Card Number - check for 4 digits
  function checkCCNumber(strng) {
  var error = "";
  if (strng == "") {
     error = "The following field has not been filled in: Credit Card Number\n";
  }
  else {
    
    if (isNaN(parseInt(strng))) {
      error = "The credit card number contains illegal characters.\n";
	}
    else if (!(strng.length == 4)) {
      error = "The credit card number is the wrong length. All sections must be 4 numbers.\n";
    }
  }
  return error;
  }
  
  //Check for a properly formatted credit card number
  function validateCard(cardNumber, cardType) {
    var error = "";
    if( cardNumber.length == 0 ) {
      error = "Please enter a valid card number.\n";
	  return error;
    }
	
	
    for( var i = 0; i < cardNumber.length; ++i ) {// make sure the number is all digits.. (by design)
      var c = cardNumber.charAt(i);

      if( c < '0' || c > '9' ) {
        var error = "Please enter a valid card number. Use only digits. do not use spaces or hyphens.\n";
		return error;
      }
	  
    }
	
    var length = cardNumber.length;//perform card specific length and prefix tests
	
	if( length != 16 ) {
      error = "The card number you entered is the wrong length.\n";
      return error;
    }
	
    //var prefix = parseInt( cardNumber.substring(0,1));

    //if( prefix != 4 ) {
      //error = "Please enter a valid Visa Card number.\n";
      //return error;
    //}
	
	
    
                                   
  }
  

  

