// Michael DelGaudio.com
// Contact - Validation
// -------------------------
// When the page loads, set the contact email
// this keeps it of the hand of dirty spam crawlers
// -------------------------
function setContactEmail(){
 	var toEmail = document.getElementById("ToEmail");
	var domain = "michaeldelgaudio.com";
	var receipent = "michael"
	var emailString = receipent+"@"+domain;
	toEmail.value = emailString;
	// populate the display
	var emailDisplay = document.getElementById("emailDisplay");
	emailDisplay.innerHTML = emailString;
}
// -------------------------
// Validation for the for email fields
// -------------------------
function validateAndSend(){
	var okToSubmit = true;
	// email validation
	var elm = document.getElementById("Email");
	var strng = elm.value;
	// see if its empty
	if (strng == "") {
		alert("Please enter an email address.");
		okToSubmit = false;
		elm.focus();
		return;
	}
	// check for valid email format
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
    	alert("Please enter a valid email address.");
		okToSubmit = false;
		elm.focus();
		return;
    }
	// message validation
	var msg = document.getElementById("ToComments");
	var msgStrng = msg.value;
	// see if its empty
	if (msgStrng == "") {
		alert("Pleaese enter a message.");
		okToSubmit = false;
		msg.focus();
		return;
	}
	// if we're all good let's go!
	if (okToSubmit) document.getElementById("mailHandler").submit()
}
