function isavalidemail(inputValue) {

    var foundAt = false
    var foundDot = false
	
    for (var i=0; i<=inputValue.length; i++) {
      if (inputValue.charAt(i) == "@" ) {
          foundAt = true
      }
      else if (inputValue.charAt(i) == ".") {
          foundDot = true
      }
    }
	
    if (foundAt && foundDot) {
        return true
    }
    else {
        return false
    }
}

function exists(inputValue) {

    var aCharExists = false

    for (var i=0; i<=inputValue.length; i++) {
      if (inputValue.charAt(i) != " " && inputValue.charAt(i) != "") {
          aCharExists = true
          break
      }
    }

    return aCharExists
}

function isavalidphonenumber(inputValue) {
	
    var stripped = inputValue.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
   return false;
}

if (!(stripped.length == 10 || (stripped.length == 11 && stripped[0] == '1'))) {
	return false;
}
return true;
}

function validateform(){
	
	var name = exists(document.form2.Name.value);
	var phone = exists(document.form2.Phone.value);
	var email = exists(document.form2.Email.value);
	
	var validphone = false;
	var validemail = false;
	if(phone) validphone = isavalidphonenumber(document.form2.Phone.value);
	if(email) validemail = isavalidemail(document.form2.Email.value);
	
	if(name && validphone && validemail){ 
	alert("Thanks for your interest! We'll contact you shortly about your project!");
	return true;
	}
	
	var badname = "-No name.\n";
	var nophone = "-No telephone number.\n";
	var noemail = "-No email address.\n";
	var invalidphone = "-Telephone invalid. Please make sure that your telephone number has only 10 or 11 digits - no more, no less. Any combination of parentheses, dashes, or spaces may be used. Also, if you entered an 11 digit telephone number make sure it begins with \"1\".\n";
	var invalidemail = "-Invalid Email. Please enter a valid email address.\n";
	var alertline = "The following problems were encountered with your submission:\n\n";
	
	if(!name) alertline += badname;
	if(!email) alertline += noemail;
	else if(!validemail) alertline += invalidemail;
	if(!phone) alertline += nophone;
	else if(!validphone) alertline += invalidphone;
	alertline += "\nPlease make corrections and submit again. Thank you.";
	
	alert(alertline);
	
	return false;
	
}