var message 
var fieldtofocus 
var passed

// Master function that checks all the pieces 
function isMailReady() {
	passed = true;  
	fieldtofocus = ""   ;
	message ="Please review the following required fields: \n";
	
// Checking for required fields ...
	if (document.Contact.Name.value == "") {
		message += "- - Your name \n"; 
		passed = false;
		if (fieldtofocus == "")  {fieldtofocus = document.Contact.Name};
	}
	
	if (document.Contact.Addr1.value =="")  {
		message += "- - Address \n"; 
		passed = false;
		if (fieldtofocus == "")  {fieldtofocus = document.Contact.Addr1};
	}
					
	if (document.Contact.City.value == "") {
		message += "- - City \n";
		passed = false;
		if (fieldtofocus == "")  {fieldtofocus = document.Contact.City};
	}
	
	if (document.Contact.State.value == "") {
		message += "- - State \n";
		passed = false;
		if (fieldtofocus == "")  {fieldtofocus = document.Contact.State};
	}
	
	if (document.Contact.Zip.value == "") {
		message += "- - Zip code \n";
		passed = false;
		if (fieldtofocus == "")  {fieldtofocus = document.Contact.Zip};
	}
	
	if (document.Contact.Email.value != "") {
		var element = document.Contact.Email;
		var result = isEmail(element);
		if (result)  {
			passed = false;
			if (fieldtofocus == "")  {fieldtofocus = document.Contact.Email};
		}
	}
	
	if (document.Contact.Phone.value == "") {
		message += "- - Phone number \n";
		passed = false;
		if (fieldtofocus == "")  {fieldtofocus = document.Contact.Phone};
	}
	
	//var element = document.Contact.Email;
	//if (element.value != "")   {
		//var result = isEmail(element);
		//if (result)  {
			//passed = false;
		//if (fieldtofocus == "")  {fieldtofocus = document.Contact.Email};
		//}
	//}
	
	// end of information checking
	
	if (passed == true)  {
		document.Contact.submit();
		return (true);
	}
	if (passed == false)  {
		fixFieldInfo();
		return (false);
	}
}

function fixFieldInfo() {
	alert(message);
	fieldtofocus.focus();
}
	
// Do some validation on the Email side of things
function isEmail(element)  {
	var inputStr = element.value;
	if (inputStr.length < 9)  {
		message += "- - Email should be at least 9 characters \n";
		return true;
	}	
	var charA = inputStr.indexOf("@");
	if (charA == -1)  {
		message += "- - Email did not find the @ character \n";
		return true;
	}
	if (charA < 2 )  {
		message += "- - Email expected at least 2 characters before the @ character \n";
		return true;
	}
	var charP = inputStr.lastIndexOf(".");
	if (charP == -1)  {
		message += "- - Email expected to find the . character \n";
		return true;
	}
	if (charP != inputStr.length - 3 && charP != inputStr.length - 4)  {
		message += "- - Email ending . character not in correct position \n";
		return true;
	}
	if (charP < charA + 3)  {
		message += "- - Email should have at least 2 characters between the @ and . characters \n";
		return true;
	}
	return false;
}

