var expireDate = new Date(); var year = expireDate.getYear(); year = (year < 1900) ? year + 1900 : year; expireDate.setYear(year + 3); function overAgeRequirement(age) { var eighteenDate = new Date(); var eighteenYear = eighteenDate.getFullYear()-18; eighteenDate.setFullYear(eighteenYear); if (age < eighteenDate) {return true;} else {return false;} }; function checkDate() { var age = new Date(); age.setMonth(document.subscribeForm.birthmonth[document.subscribeForm.birthmonth.selectedIndex].value-1); age.setDate(document.subscribeForm.birthday[document.subscribeForm.birthday.selectedIndex].value); age.setYear(document.subscribeForm.birthyear[document.subscribeForm.birthyear.selectedIndex].value); if ((document.subscribeForm.birthday[document.subscribeForm.birthday.selectedIndex].value != 0) && (document.subscribeForm.birthmonth[document.subscribeForm.birthmonth.selectedIndex].value !=0) && (document.subscribeForm.birthyear[document.subscribeForm.birthyear.selectedIndex].value != 0)) { if (overAgeRequirement(age)) { return true; } else { return false; } } }; ///////////////////////////////////////////// // Checks for whitespace /////////////////////////////////////////// function isWS(s) { return ((s == null) || (s.length == 0)); }; function validate() { var errors = ''; var finalerrors = 'The following fields are required:\n\n'; var f = document.subscribeForm; if ((f.birthday[f.birthday.selectedIndex].value == 0) || (f.birthmonth[document.subscribeForm.birthmonth.selectedIndex].value ==0) || (f.birthyear[document.subscribeForm.birthyear.selectedIndex].value == 0)) { errors += ' - Birthday\n'; } else { if(checkDate()){ var sAge = f.birthmonth[f.birthmonth.selectedIndex].value; sAge += "/" + f.birthday[f.birthday.selectedIndex].value; sAge += "/" + f.birthyear[f.birthyear.selectedIndex].value; f.birthdate.value = sAge; } else { alert("Sorry, this registration is not intended for your age group."); return false; } } if (isWS(f.name.value)) errors += ' - Name\n'; if (isWS(f.email.value)) errors += ' - Email\n'; if(f.newsletterCB.checked == true){ f.newsletter.value = "Y"; }else{ f.newsletter.value = "N"; } if(f.champsportsCB.checked == true){ f.champsports.value = "Y"; }else{ f.champsports.value = "N"; } if (errors != '') { finalerrors += errors; alert(finalerrors); return false; } else{ return true; } };