// JavaScript Document
// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('email address is mandatory');
   return false;
}
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('email address contains invalid characters');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('email address must contain an @');
   return false;
}
if (atPos == 0) {
   if (db) alert('email address must not start with @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('email address must contain only one @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('email address must contain a period in the domain name');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('period must not immediately follow @ in email address');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('period must not immediately precede @ in email address');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('two periods must not be adjacent in email address');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('invalid primary domain in email address');
   return false;
}
return true;
}

//HEAD
/*<script type="text/javascript" src="email.js">
</script> 

if (!validateEmail(emailfield,1,0)) {
  alert('email address is invalid or was not entered');
  return false;} */



function validate(earliestyear, latestyear, campmonth, campday) {
var valid=true;
    if (document.appform.firstname.value == "") {
	   		alert("Please provide the applicant's first name.");
			document.appform.firstname.focus();
         	document.appform.firstname.select();
			valid=false;
       	}
	else if (document.appform.lastname.value == "") {
	   		alert("Please provide the applicant's last name.");
			document.appform.lastname.focus();
         	document.appform.lastname.select();
			valid=false;
       	}
	else if (document.appform.lastname.value == "") {
	   		alert("Please provide the applicant's last name.");
			document.appform.lastname.focus();
         	document.appform.lastname.select();
			valid=false;
       	}
	else if (document.appform.year.value == "0" || document.appform.month.value == "0" || document.appform.day.value == "0") {
			alert("Please enter the applicant's date of birth.");
			valid=false;
		}
	else if (document.appform.year.value == earliestyear && (parseInt(document.appform.month.value) < parseInt(campmonth) || document.appform.month.value == campmonth && parseInt(document.appform.day.value) < parseInt(campday))) {
		/*if() {
			alert("The applicant must be between the ages of 12 and 15 on the first day of camp.\n Please double check your birthdate to confirm that you have met the age requirement.");
			valid=false;
		}
		else if() {
			alert("The applicant must be between the ages of 12 and 15 on the first day of camp.\n Please double check your birthdate to confirm that you have met the age requirement.");
			valid=false;
		}*/
			alert("The applicant must be between the ages of 12 and 15 on the first day of camp.\n Please double check your birthdate to confirm that you have met the age requirement.");
			valid=false;
	}
	else if (document.appform.year.value == latestyear && (parseInt(document.appform.month.value) > parseInt(campmonth) || document.appform.month.value == campmonth && parseInt(document.appform.day.value) > parseInt(campday))) {
		/*if() {
			alert("The applicant must be between the ages of 12 and 15 on the first day of camp.\n Please double check your birthdate to confirm that you have met the age requirement.");
			valid=false;
		}
		else if() {
			alert("The applicant must be between the ages of 12 and 15 on the first day of camp.\n Please double check your birthdate to confirm that you have met the age requirement.");
			valid=false;
			
		}*/
alert("The applicant must be between the ages of 12 and 15 on the first day of camp.\n Please double check your birthdate to confirm that you have met the age requirement.");
			valid=false;
	}
	else if(document.appform.address.value.length < 3) {
			alert("Please provide the applicant's mailing address.");
			document.appform.address.focus();
         	document.appform.address.select();
			valid=false;
	}
	else if(document.appform.city.value == "") {
			alert("Please provide the applicant's city of residence.");
			document.appform.city.focus();
         	document.appform.city.select();
			valid=false;
	}
	else if(document.appform.state.value != "PA") {
			alert("You MUST be a resident of Armstrong County, Pennsylvania in order to attend Camp Cadet-Armstrong County.");
			document.appform.state.focus();
         	document.appform.state.select();
			valid=false;
	}
	else if(document.appform.zip.value.length != 5 || isNaN(document.appform.zip.value)) {
			alert("Please provide the correct zipcode for the applicant's mailing address.");
			document.appform.zip.focus();
         	document.appform.zip.select();
			valid=false;
	}
	else if(document.appform.township.value == "") {
			alert("Please provide the applicant's township or borough of residence.");
			document.appform.township.focus();
         	document.appform.township.select();
			valid=false;
	}	
else if (document.appform.phone_ac.value == "" || document.appform.phone_ac.value.length !=3) {
	   		alert("Please provide your area code.");
			document.appform.phone_ac.focus();
			document.appform.phone_ac.select();
			valid=false;
		}
	else if (isNaN(parseInt(document.appform.phone_ac.value))) {
   			alert("The area code contains invalid characters.");
			document.appform.phone_ac.focus();
			document.appform.phone_ac.select();
			valid=false;
			}
	else if (document.appform.phone_ex.value == "" || document.appform.phone_ex.value.length !=3) {
	   		alert("Please provide a correct phone number.");
			document.appform.phone_ex.focus();
			document.appform.phone_ex.select();
			valid=false;
		}
	else if (isNaN(parseInt(document.appform.phone_ex.value))) {
   			alert("The phone number contains invalid characters.");
			document.appform.phone_ex.focus();
			document.appform.phone_ex.select();
			valid=false;
			}
	else if (document.appform.phone_num.value == "" || document.appform.phone_num.value.length !=4) {
	   		alert("Please provide a correct phone number.");
			document.appform.phone_num.focus();
			document.appform.phone_num.select();
			valid=false;
		}
	else if (isNaN(parseInt(document.appform.phone_num.value))) {
   			alert("The phone number contains invalid characters.");
			document.appform.phone_num.focus();
			document.appform.phone_num.select();
			valid=false;
			}
	else if (document.appform.email.value != "" && !validateEmail(document.appform.email.value,1,0)) {
  		alert("Please provide a valid email address.");
			document.appform.email.focus();
			document.appform.email.select();
			valid=false;
			} 
	else if(document.appform.parent1.value.length < 4 && document.appform.parent2.value.length < 4) {
 		alert("Please provide the name of AT LEAST ONE parent or guardian.");
			document.appform.parent1.focus();
			document.appform.parent1.select();
			valid=false;
			}
	else if(document.appform.same.checked != false) {
		if(document.appform.paddress.value.length < 3) {
			alert("Please provide the parent's or guardian's mailing address.");
			document.appform.paddress.focus();
         	document.appform.paddress.select();
			valid=false;
		}
		else if(document.appform.pcity.value == "") {
			alert("Please provide the the parent's or guardian's city of residence.");
			document.appform.pcity.focus();
         	document.appform.pcity.select();
			valid=false;
		}
		else if(document.appform.pstate.value == "") {
			alert("Please provide the the parent's or guardian's state of residence.");
			document.appform.pstate.focus();
         	document.appform.pstate.select();
			valid=false;
		}
		else if(document.appform.pzip.value.length != 5 || isNaN(document.appform.pzip.value)) {
			alert("Please provide the correct zipcode for the parent's or guardian's mailing address.");
			document.appform.pzip.focus();
         	document.appform.pzip.select();
			valid=false;
		}
		else if (document.appform.pphone_ac.value == "" || document.appform.pphone_ac.value.length !=3) {
	   		alert("Please provide the parent's or guardian's area code.");
			document.appform.pphone_ac.focus();
			document.appform.pphone_ac.select();
			valid=false;
		}
		else if (isNaN(parseInt(document.appform.pphone_ac.value))) {
   			alert("The parent's or guardian's area code contains invalid characters.");
			document.appform.pphone_ac.focus();
			document.appform.pphone_ac.select();
			valid=false;
			}
		else if (document.appform.pphone_ex.value == "" || document.appform.pphone_ex.value.length !=3) {
	   		alert("Please provide the parent's or guardian's phone number.");
			document.appform.pphone_ex.focus();
			document.appform.pphone_ex.select();
			valid=false;
		}
			else if (isNaN(parseInt(document.appform.pphone_ex.value))) {
   			alert("The parent's or guardian's phone number contains invalid characters.");
			document.appform.pphone_ex.focus();
			document.appform.pphone_ex.select();
			valid=false;
			}
		else if (document.appform.pphone_num.value == "" || document.appform.pphone_num.value.length !=4) {
	   		alert("Please provide the parent's or guardian's phone number.");
			document.appform.pphone_num.focus();
			document.appform.pphone_num.select();
			valid=false;
		}
		else if (isNaN(parseInt(document.appform.pphone_num.value))) {
   			alert("The the parent's or guardian's phone number contains invalid characters.");
			document.appform.pphone_num.focus();
			document.appform.pphone_num.select();
			valid=false;
			}
	}
	else if (document.appform.pemail.value != "" && !validateEmail(document.appform.pemail.value,1,0)) {
  		alert("Please provide a valid parent or guardian email address.");
			document.appform.pemail.focus();
			document.appform.pemail.select();
			valid=false;
			}
	   	
			return valid;
		
     }

function adjustContact(form, value) {
if(form.same.checked != true) {
var ta = document.getElementById("dim"); 
ta.style.color = "#cccccc";
//form.currentMemberH.value = "yes";
form.paddress.disabled = true;
form.pcity.disabled = true;
form.pstate.disabled = true;
form.pzip.disabled = true;
form.pphone_ac.disabled = true;
form.pphone_ex.disabled = true;
form.pphone_num.disabled = true;
}
else {
var ta = document.getElementById("dim"); 
ta.style.color = "#000000";
//form.currentMemberH.value = "no";
form.paddress.disabled = false;
form.pcity.disabled = false;
form.pstate.disabled = false;
form.pzip.disabled = false;
form.pphone_ac.disabled = false;
form.pphone_ex.disabled = false;
form.pphone_num.disabled = false;
form.paddress.focus();
}
}

