function checkData()
{
var correct = true
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (document.Validate.student_firstname.value == "") {correct = false; alert("Please enter your first name.")}
if (document.Validate.student_lastname.value == "") {correct = false; alert("Please enter your last name.")}
if (document.Validate.student_email.value == "") {correct = false; alert("Please enter your Email.")}
else
{
	var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(document.Validate.student_email.value))){ correct = false; alert("Please enter a valid email address.");	 }
  else if(document.Validate.student_email.value.match(illegalChars)){ correct = false; alert("The email address contains illegal characters.");}  
  else
	{
		if (document.Validate.student_email2.value == "") {correct = false; alert("Please verify your Email.")}
		else if (document.Validate.student_email2.value != document.Validate.student_email.value) {correct = false; alert("Emails do not match.")}
	}
}

if (document.Validate.student_password.value == "") {correct = false; alert("Please enter your Password.")}
else
{
	if (document.Validate.student_password.value.length < 6) {correct = false; alert("Password needs to be six characters or more.")}
  else if(document.Validate.student_password.value.match(illegalChars)){ correct = false; alert("Password contains illegal characters.");}  
  else
	{
		if (document.Validate.student_password.value == "") {correct = false; alert("Please verify your Password.")}
		else if (document.Validate.student_password2.value != document.Validate.student_password.value) {correct = false; alert("Passwords do not match.")}
	}
}	

var selection = document.Validate.is_employee.selectedIndex;
if (document.Validate.is_employee.options[selection].value == "Yes")
{
	if (document.Validate.location_employee_id.value == "") {correct = false; alert("Please indicate the name of the center which you work at.")}
	if (document.Validate.employee_code.value == "") {correct = false; alert("Please enter center code.")}
	else if(document.Validate.employee_code.value.match(illegalChars)){ correct = false; alert("Center code contains illegal characters.");}  
	
	var radio_choice = false;
	for (counter = 0; counter < document.Validate.division_employee.length; counter++)
	{
		
		if (Validate.division_employee[counter].checked)
		radio_choice = true; 
	}
	if (!radio_choice)
	{
		correct = false; alert("Please choose the division.")
	}
	
}

if (correct){}
return correct
}

function checkData_admin(mode)
{
var mode = mode	
var correct = true
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (document.Validate.student_firstname.value == "") {correct = false; alert("Please enter your first name.")}
if (document.Validate.student_lastname.value == "") {correct = false; alert("Please enter your last name.")}
if (document.Validate.student_email.value == "") {correct = false; alert("Please enter your Email.")}
else
{
	var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(document.Validate.student_email.value))){ correct = false; alert("Please enter a valid email address.");	 }
  else if(document.Validate.student_email.value.match(illegalChars)){ correct = false; alert("The email address contains illegal characters.");}  
}

if( mode == 'add')
{
	if (document.Validate.student_password.value == "") {correct = false; alert("Please enter your Password.")}
	else
	{
		if (document.Validate.student_password.value.length < 6) {correct = false; alert("Password needs to be six characters or more.")}
	  else if(document.Validate.student_password.value.match(illegalChars)){ correct = false; alert("Password contains illegal characters.");}  
	}	
}
else if( mode == 'edit')
{
	if (document.Validate.student_password.value != "")
	if (document.Validate.student_password.value.length < 6) {correct = false; alert("Password needs to be six characters or more.")}
	else if(document.Validate.student_password.value.match(illegalChars)){ correct = false; alert("Password contains illegal characters.");}  
	
}	

if( mode == 'add')
{		
var selection = document.Validate.is_employee.selectedIndex;
if (document.Validate.is_employee.options[selection].value == "Yes")
{
	if (document.Validate.location_employee_id.value == "") {correct = false; alert("Please indicate the name of the center which you work at.")}
	var radio_choice = false;
	for (counter = 0; counter < document.Validate.division_employee.length; counter++)
	{
		
		if (Validate.division_employee[counter].checked)
		radio_choice = true; 
	}
	if (!radio_choice)
	{
		correct = false; alert("Please choose the division.")
	}
}
}
if (correct){}
return correct
}

function checkData_subject()
{
var correct = true
if (document.Validate.subject_name.value == "") {correct = false; alert("Please enter subject name.")}
//if (document.Validate.subject_description.value == "") {correct = false; alert("Please enter subject description.")}
if (document.Validate.subject_perequisites.value == "") {correct = false; alert("Please enter subject perequisites.")}

var selection = document.Validate.department_id.selectedIndex;
if (document.Validate.department_id.options[selection].value == "")
{
	correct = false; alert("Please choose Area of Interest.");
}
if (document.Validate.subject_credit_hours.value == "") {correct = false; alert("Please enter subject credit hours.")}
if (document.Validate.state_approved.value == "") {correct = false; alert("Please enter DECAL approved hours.")}
if (document.Validate.subject_ceus.value == "") {correct = false; alert("Please enter CEUS.")}
if (document.Validate.subject_college_credit.value == "") {correct = false; alert("Please enter college credit recommendation.")}

/*
var selection = document.Validate.state_approved.selectedIndex;
if (document.Validate.state_approved.options[selection].value == "")
{
	correct = false; alert("Please indicate if this subject is state-approved.");
}
if (document.Validate.subject_max.value == "") {correct = false; alert("Please enter the max number of trainees that may enroll.")}

var selection = document.Validate.subject_status.selectedIndex;
if (document.Validate.subject_status.options[selection].value == "")
{
	correct = false; alert("Please choose status.");
}
*/
if (document.Validate.subject_cost.value == "") {correct = false; alert("Please enter the cost.")}
if (correct){}
return correct
}


function checkData_class()
{
var correct = true

var selection = document.Validate.subject_id.selectedIndex;
if (document.Validate.subject_id.options[selection].value == "")
{
	correct = false; alert("Please choose a subject.");
}
var selection = document.Validate.instructor_id.selectedIndex;
if (document.Validate.instructor_id.options[selection].value == "")
{
	correct = false; alert("Please choose an instructor.");
}
var selection = document.Validate.location_id.selectedIndex;
if (document.Validate.location_id.options[selection].value == "")
{
	correct = false; alert("Please choose a lcoation.");
}

if (document.Validate.class_max.value == "") {correct = false; alert("Please enter max capacity.")}
/*
var selection = document.Validate.class_status.selectedIndex;
if (document.Validate.class_status.options[selection].value == "")
{
	correct = false; alert("Please choose status.");
}
*/
var selection_month = document.Validate.Month.selectedIndex;
var selection_day = document.Validate.Day.selectedIndex;
var selection_year = document.Validate.Year.selectedIndex;
var selection_hour = document.Validate.Hour.selectedIndex;
var selection_minute = document.Validate.Minute.selectedIndex;
var msg = "Please choose the following for Class Time:\n\n"; 
var ale = false;
if (document.Validate.Month.options[selection_month].value == "")
{
	msg += " Month\n"; ale = true;
}
if (document.Validate.Day.options[selection_day].value == "")
{
	msg += " Day\n"; ale = true;
}
if (document.Validate.Year.options[selection_year].value == "")
{
	msg += " Year\n"; ale = true;
}
if (document.Validate.Hour.options[selection_hour].value == "")
{
	msg += " Hour\n"; ale = true;
}
if (document.Validate.Minute.options[selection_minute].value == "")
{
	msg += " Minute\n"; ale = true;
}
if( ale == true  )
{ 
	alert(msg)
  correct = false; 
}


var selection_hour = document.Validate.h_e.selectedIndex;
var selection_minute = document.Validate.m_e.selectedIndex;
var msg = "Please choose the following for Class End Time:\n\n"; 
var ale = false;
if (document.Validate.h_e.options[selection_hour].value == "")
{
	msg += " Hour\n"; ale = true;
}
if (document.Validate.m_e.options[selection_minute].value == "")
{
	msg += " Minute\n"; ale = true;
}
if( ale == true  )
{ 
	alert(msg)
  correct = false; 
}

if (correct){}
return correct
}

function location_code_show() {
location_combo.style.display='block';
}

function location_code_hide() {
location_combo.style.display='none';
}

function location_code(){
	
	var selection = document.Validate.is_employee.selectedIndex;
	if (document.Validate.is_employee.options[selection].value == "Yes")
	{
   location_code_show(); 
  }
	else
	{
   location_code_hide(); 
  }
}


function checkData_billing()
{
var correct = true
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (document.Validate.student_firstname.value == "") {correct = false; alert("Please enter your first name.")}
if (document.Validate.student_lastname.value == "") {correct = false; alert("Please enter your last name.")}
if (document.Validate.student_address.value == "") {correct = false; alert("Please enter your address.")}
if (document.Validate.student_city.value == "") {correct = false; alert("Please enter your city.")}
if (document.Validate.student_zip.value == "") {correct = false; alert("Please enter your zip.")}

	var cctype_selection = document.Validate.student_cctype.selectedIndex;
  if( checkCreditCard (document.Validate.student_ccnum.value,document.Validate.student_cctype.options[cctype_selection].value)) {
  	//do nothing
  } 
  else 
  {
  	alert (ccErrors[ccErrorNo]);
  	correct = false;	
  }



if (correct){}
return correct
}


var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {

     
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  
  cards [1] = {name: "MasterCard", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
	cards [2] = {name: "Visa", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};               
  cards [3] = {name: "AmEx", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};

	cards [4] = {name: "DinersClub", 
               length: "14,", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
	cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "Enroute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
               
  cards [8] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
               
  // Establish card type
  cardType = cardname;
  
  /*var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  */
  // If card type not found, report an error
  if (cardType == '') {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
  
  // Check that the number is numeric, although we do permit a space to occur  
  // every four digits. 
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}