// JavaScript Document
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,"Please enter a valid e-mail address.")==false)
  {email.focus();return false}
  if (validate_required(first_name,"Please enter a first name.")==false)
  {first_name.focus();return false}
  if (validate_required(last_name,"Please enter a last name.")==false)
  {last_name.focus();return false}

if (validate_required(birthdate,"Please enter a Birth Date.")==false)
  {birthdate.focus();return false}

if ( !isDate(birthdate.value) )
{
alert('Please enter a valid Birth Date in the format of mm/dd/yyyy');
return false;
}

}
}

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false}
else {return true}
}
}

function isDate(txtDate) {   
var objDate,  // date object initialized from the txtDate string   
mSeconds, // txtDate in milliseconds   
day,      // day   
month,    // month   
year;     // year   
// date length should be 10 characters (no more no less)   
if (txtDate.length !== 10) {   
return false;   
}   
// third and sixth character should be '/'   
if (txtDate.substring(2, 3) !== '/' || txtDate.substring(5, 6) !== '/') {   
return false;   
}   
// extract month, day and year from the txtDate (expected format is mm/dd/yyyy)   
// subtraction will cast variables to integer implicitly   
month = txtDate.substring(0, 2) - 1; // because months in JS start from 0   
day = txtDate.substring(3, 5) - 0;   
year = txtDate.substring(6, 10) - 0;   
// test year range   
if (year < 1000 || year > 3000) {   
return false;   
}   
// convert txtDate to milliseconds   
mSeconds = (new Date(year, month, day)).getTime();   
// initialize Date() object from calculated milliseconds   
objDate = new Date();   
objDate.setTime(mSeconds);   
// compare input date and parts from Date() object   
// if difference exists then date isn't valid   
if (objDate.getFullYear() !== year ||   
objDate.getMonth() !== month ||   
objDate.getDate() !== day) {   
return false;   
}   
// otherwise return true   
return true;   
}  

