window.onload = function () {
	dp_cal  = new Epoch('epoch_popup','popup',document.getElementById('MoveDate'));
};

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.length == 0) {
     error = "The mandatory field '" + name + "' has not been filled in.\n"
  }
return error;	  
}

function checkEstimateForm(theForm) 
{
    var why = "";
    why += isEmpty("First Name", theForm.Firstname.value);
    why += isEmpty("Last Name", theForm.Lastname.value);
    why += checkEmail(theForm.Email.value);
    why += checkPhone(theForm.PrimaryPhone.value);
    why += isEmpty("Move Date", theForm.MoveDate.value);
    why += isEmpty("Household Type", theForm.Household.options[theForm.Household.selectedIndex].text);
    why += isEmpty("Number of Rooms", theForm.Rooms.value);
    why += isEmpty("Pick Up Street Number", theForm.PUStreetNumber.value);
    why += isEmpty("Pick Up Street Name", theForm.PUStreetname.value);
    why += isEmpty("Pick Up Municipality", theForm.PUCity.value);
    why += isEmpty("Pick Up Postal Code", theForm.PUPostalCode.value);
    why += isEmpty("Destination Street Number", theForm.DStreetNumber.value);
    why += isEmpty("Destination Street Name", theForm.DStreetname.value);
    why += isEmpty("Destination Municipality", theForm.DCity.value);
    why += isEmpty("Destination Postal Code", theForm.DPostalCode.value);

    if (why != "") {
       alert(why);
       return false;
    }
    return true;
}