function parseName() {  
  var newName = "";
  var obj = document.final_payment.p_name.value;
  for (i=0; i < obj.length; i++) {
      if (i == 0) {
         newName += obj.substring(i,i+1).toUpperCase();
      } else if (obj.substring(i,i+1) == " ") {
         i ++; newName += " " + obj.substring(i,i+1).toUpperCase();
      } else if (obj.substring(i,i+1) == "-") {
         i ++; newName += "-" + obj.substring(i,i+1).toUpperCase();
      } else {
         newName += obj.substring(i,i+1).toLowerCase();
      }
  }
  document.final_payment.p_name.value = newName;  
}

function validate() {
 if (document.final_payment.p_name.value    != "" &&
     document.final_payment.p_phone.value   != "" &&
     document.final_payment.p_address.value != "") {

     // Email address ok?
     if (document.final_payment.p_email.value != "") {    
        if (document.final_payment.p_email.value.indexOf("@") == -1 ||
            document.final_payment.p_email.value.indexOf(".") == -1) {
           alert("Please enter a valid email address.");
           return(false);
        }
     }

     // Country selected?
     if (document.final_payment.p_country.selectedIndex == 0) {    
        alert("Please select your Country.");
        return(false);
     }

     // Terms & Conditions accepted?
     if (!document.final_payment.tc.checked) {
        alert("Please tick that you accept our Terms & Conditions before continuing, thank you.");
        return(false);
     }
     return(confirm("Please check that you have chosen to pay your final fee for the correct course on the correct dates.\n\nClick OK to proceed."));
 } else {
     alert("Please complete all fields. Thank you.");
     return(false);
 }
}

