// Simple check for valid Email address in string

function valid_email(email_address) {
 if (email_address.length < 7) {return false};
  at_location = email_address.indexOf("@");
  dot_location = email_address.lastIndexOf(".");
  space_location = email_address.lastIndexOf(" ");
 if (at_location == -1 || space_location > 0 || dot_location == -1 || at_location > dot_location ) {return false};
 if (at_location == 0) {return false};
 if (dot_location - at_location < 3 ) {return false};
 if (email_address.length - dot_location < 3) {return false};
 return true
}

//Check for empty or only non visible characters in string

function its_not_visible(string_value) {
 var not_visible = " \n\r\t"

 for (var counter = 0; counter < string_value.length; counter++)
{  current_char = string_value.charAt(counter)
  if (not_visible.indexOf(current_char) == -1) {
   return false
  }
 }
 return true
}

//Submit handler can be extended to many more fields

function submit_handler2() {

	if (document.ride.name.value.length < 1 || document.ride.name.value == "Your name") {
		alert('Name is required, please correct and resubmit');
		document.ride.name.focus() ;
		return false
	};

	if (document.ride.phone.value.length < 1 || document.ride.phone.value == "Phone number") {
		alert('Telephone Number is required, please correct and resubmit');
		document.ride.phone.focus() ;
		return false
	};
	
	if( valid_email(document.ride.email.value) ) {
		return true
	}
	else {
		alert('Please enter a valid email address so I can reply \n Hint: Check for leading or trailing spaces');
		document.ride.email.focus() ;
		return false
	}
}



