// JavaScript Document
function checkWholeForm() {
    var why = "";
	why += checkEmail(document.theForm.email.value);
	why += checkFirstname (document.theForm.firstname.value);
	why += checkLastname(document.theForm.lastname.value);
	why += checkPassword(document.theForm.password.value);
    why += checkLocation(document.theForm.location.value);
    why += checkPhone(document.theForm.mobile.value);
	why += checkPasswords(document.theForm.password.value, document.theForm.password2.value);
	  if (why != "") {
       alert("Please note the following errors\n" + why);
       return false;
    }
document.theForm.submit();
return true;
}
function checkFirstname(strng) {
var error="";
if (strng == "") {
   error = "Enter first name.\n";
}

    var illegalChars = /\W /; // allow letters, numbers, and underscores
    if ((strng.length < 1) || (strng.length > 50)) {
       error = "Invalid First Name.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "Invalid First Name.\n";
    } 
return error;
}  
function checkLastname(strng) {
var error="";
if (strng == "") {
   error = "Enter Last Name.\n";
}


    var illegalChars = /\W /; // allow letters, numbers, and underscores
    if ((strng.length < 1) || (strng.length > 50)) {
       error = "Invalid Last Name.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "Invalid Last Name.\n";
    } 
return error;
}  

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "Invalid Email Address.\n";
       }
    }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "Enter a phone Number.\n";

}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "Invalid Phone Number.\n";
	   }
    if (stripped.length < 8) {
	error = "Please Enter code and Number e.g 014713456.\n";
    } 
return error;
}



// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 20)) {
       error = "password should be at least 6 characters. .\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}  
function checkPasswords (strng, strngs) {
var error = "";
if (strng != strngs) {
   error = "Your Passwords do not match.\n";
	}
return error;
}
function checkceremstart(hh, mm) {
var error = "";
    if (hh == "HH" || mm == "MM") {
    error = "Invalid Ceremony Start time.\n";
	document.getElementById("starttime").innerHTML ="Ceremony Start Time*";
   document.getElementById("starttime").style.color = "#ff0000";
    }    
return error;
}    
function checkCordinator(strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a coordinator.\n";
   document.getElementById("coordinator").innerHTML ="Coordinator Name*";
   document.getElementById("coordinator").style.color = "#ff0000";
}


    var illegalChars = /\W /; // allow letters, numbers, and underscores
    if ((strng.length < 1) || (strng.length > 100)) {
       error = "The coordinator's name name is the wrong length.\n";
	   document.getElementById("coordinator").innerHTML ="Coordinator Name*";
   		document.getElementById("coordinator").style.color = "#ff0000";
    }
    else if (illegalChars.test(strng)) {
    error = "The coordinator's name name is the wrong length.\n";
	document.getElementById("coordinator").innerHTML ="Coordinator Name*";
   document.getElementById("coordinator").style.color = "#ff0000";
    } 
return error;
}  
function checkVideo(strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a Videographer.\n";
   document.getElementById("videographer").innerHTML ="Videographer Name*";
   document.getElementById("videographer").style.color = "#ff0000";
}


    var illegalChars = /\W /; // allow letters, numbers, and underscores
    if ((strng.length < 1) || (strng.length > 80)) {
       error = "The Videographer's name is the wrong length.\n";
	   document.getElementById("videographer").innerHTML ="Videographer Name*";
   		document.getElementById("videographer").style.color = "#ff0000";
    }
    else if (illegalChars.test(strng)) {
    error = "The Videographer's name contains illegal characters.\n";
	document.getElementById("videographer").innerHTML ="Videographer Name*";
   document.getElementById("videographer").style.color = "#ff0000";
    } 
return error;
}  
function checkMinister(strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a Minister.\n";
   document.getElementById("minister").innerHTML ="Minister's Name*";
   document.getElementById("minister").style.color = "#ff0000";
}


    var illegalChars = /\W /; // allow letters, numbers, and underscores
    if ((strng.length < 1) || (strng.length > 50)) {
       error = "Invalid Minister's Name.\n";
	   document.getElementById("minister").innerHTML ="Minister's Name*";
   document.getElementById("minister").style.color = "#ff0000";
    }
    else if (illegalChars.test(strng)) {
    error = "Invalid Minister's Name.\n";
	document.getElementById("minister").innerHTML ="Minister's Name*";
   document.getElementById("minister").style.color = "#ff0000";
    } 
return error;
}  
function checkCaterer(strng) {
var error = "";
if (strng == "") {
   error = "Invalid Caterer's Name.\n";
   document.getElementById("caterer").innerHTML ="Caterer's Name*";
   document.getElementById("caterer").style.color = "#ff0000";
}


    var illegalChars = /\W /; // allow letters, numbers, and underscores
    if ((strng.length < 1) || (strng.length > 50)) {
       error = "Invalid Caterer's Name.\n";
	   document.getElementById("caterer").innerHTML ="Caterer's Name*";
   document.getElementById("caterer").style.color = "#ff0000";
    }
    else if (illegalChars.test(strng)) {
    error = "Invalid Caterer's Name.\n";
	document.getElementById("caterer").innerHTML ="Caterer's Name*";
   document.getElementById("caterer").style.color = "#ff0000";
    } 
return error;
}   
function checkMusicians (strng) {
var error = "";
if (strng == "") {
   error = "Invalid Musician.\n";
   document.getElementById("musicians").innerHTML ="Musician's Name*";
   document.getElementById("musicians").style.color = "#ff0000";
}


    var illegalChars = /\W /; // allow letters, numbers, and underscores
    if (illegalChars.test(strng)) {
    error = "Invalid Musician.\n";
	document.getElementById("musicians").innerHTML ="Musician's Name*";
   document.getElementById("musicians").style.color = "#ff0000";
    } 
return error;
} 
function checkHair (strng) {
var error = "";
if (strng == "") {
   error = "Invalid value for hair / Make Up.\n";
   document.getElementById("hair").innerHTML ="Hair/Makeup Name*";
   document.getElementById("hair").style.color = "#ff0000";
}


    var illegalChars = /\W /; // allow letters, numbers, and underscores
    if (illegalChars.test(strng)) {
    error = "Invalid value for hair / Make Up.\n";
	document.getElementById("hair").innerHTML ="Hair/Makeup Name*";
   document.getElementById("hair").style.color = "#ff0000";
    } 
return error;
}