window.onload = function () {
	da_cal  = new Epoch('epoch_popup','popup',document.getElementById('DateAvailable'));
	ww_cal  = new Epoch('epoch_popup','popup',document.getElementById('WorkedWhen'));
};

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 = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}

function isEmpty(name, strng) {
var error = "";
  if ((strng.value == "undefined") || (strng.length == 0)) {
     error = "The mandatory field '" + name + "' has not been filled in.\n"
  }
return error;	  
}

function isUnselected(name, obj)
{
   var error = "";
   var len = obj.length;
   var chosen = "";

   for (i = 0; i < len; i++) 
   {
      if (obj[i].checked) 
         chosen = obj[i].value
   }

   if (chosen == "")
      error = "The mandatory field '" + name + "' has not been filled in.\n"

   return error;	  
}

function checkEmploymentForm(theForm) 
{
    var why = "";

    why += isEmpty("Last Name", theForm.Lastname.value);
    why += isEmpty("First Name", theForm.Firstname.value);
    why += checkPhone(theForm.PrimaryPhone.value);
    why += isEmpty("Address", theForm.AddressStreet.value);
    why += isEmpty("City", theForm.AddressCity.value);
    why += isEmpty("Postal Code", theForm.AddressPostal.value);
    
    why += isEmpty("Date Available",theForm.DateAvailable.value);
    why += isUnselected("Legal to work in Canada?",theForm.LegalToWork);
    why += isUnselected("Worked for this company?",theForm.WorkedBefore);

    if (theForm.WorkedBefore[0].checked)
        why += isEmpty("When did you work for this company?",theForm.WorkedWhen.value);

    why += isUnselected("CriminalOffense", theForm.CriminalOffense);

    if (theForm.CriminalOffense[0].checked)
        why += isEmpty("Please explain about your Criminal Offense.",theForm.CriminalExplanation.value);

    if (why != "") {
       alert(why);
       return false;
    }
    return true;
}