// validates form input
function validateme(){
	var f = document.refform;
	var alert_msg = "Please correct the following invalid values:\n\n";
	var missing = '';
	// check Student Info first
	if (document.getElementById('student_email_address').value == ''){
		missing = missing + "\tYour Email Address - must be a valid address (ie: user@domain.com)\n\n";
	}else{
		if(echeck(document.getElementById('student_email_address').value) == false){
			missing = missing + "\tYour Email Address - must be a valid address (ie: user@domain.com)\n\n";
		}
	}

	// Now check Prospect Info
	if(document.getElementById('prospect_first_name').value.length < 2){
		missing = missing + "\tProspect First Name - must be at least 2 characters.\n";
	}else if(document.getElementById('prospect_first_name').value.length > 75){
		missing = missing + "\tProspect First Name - must be at most 75 characters.\n";
	}
	if(document.getElementById('prospect_last_name').value.length < 2){
		missing = missing + "\tProspect Last Name - must be at least 2 characters.\n";
	}else if(document.getElementById('prospect_last_name').value.length > 75){
		missing = missing + "\tProspect Last Name - must be at most 75 characters.\n";
	}
	if (document.getElementById('prospect_email_address').value == ''){
		missing = missing + "\tProspect Email Address - must be a valid address (ie: user@domain.com).\n";
	}else{
		if(echeck(document.getElementById('prospect_email_address').value) == false){
			missing = missing + "\tProspect Email Address - must be a valid address (ie: user@domain.com).\n";
		}
	}
	if (document.getElementById('prospect_phone_1').value.length < 10){
		missing = missing + "\tProspect Phone Number 1 - must include at least one phone number (ie: (555) 555-5555).\n";
	}else if(document.getElementById('prospect_phone_1').value.length > 15) {
		missing = missing + "\tProspect Phone Number 1 - must include at least one phone number (ie: (555) 555-5555).\n";
	}
	if(document.getElementById('prospect_state_province').selectedIndex <= 0){
		missing = missing + "\tProspect State/Province - please tell us the where the prospect resides (ie: Florida).\n";
	}
	if(document.getElementById('prospect_areas_of_study').selectedIndex <= 0){
		missing = missing + "\tProspect Areas of Study - please tell us the Areas of Study for the prospect.\n";
	}
	if(document.getElementById('prospect_military').selectedIndex <= 0){
		missing = missing + "\tProspect Military - please tell us if the prospect is in the Military.\n";
	}
	if(document.getElementById('prospect_areas_of_study').selectedIndex <= 0){
		missing = missing + "\tProspect Level - please tell us the study Level for the prospect.\n";
	}
	if(missing != ''){
		alert_msg = alert_msg + missing;
		alert(alert_msg);
		return false;
	}
}

function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var alertflag = 0;
	if (str.indexOf(at)==-1){
		alertflag = 1;
   	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alertflag = 1;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alertflag = 1;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		alertflag = 1;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alertflag = 1;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		alertflag = 1;
	}
	if (str.indexOf(" ")!=-1){
		alertflag = 1;
	}
	if(alertflag == 1){
		return false;
	}
	return true;
}

