// This document holds all of the JavaScript necessary for validating our registration forms. 

function validEmail (email1) {
invalidChars = " /:,;"
if (email1 == "") {
return false
}

for (i=0; i<invalidChars.length; i++) {
	badChar = invalidChars.charAt(i)
if (email1.indexOf(badChar,0) != -1) {
	return false
		}
	}

	atPos = email1.indexOf("@",1)
if (atPos == -1) {
return false
}

if(email1.indexOf("@",atPos+1) != -1) {
return false
}

periodPos = email1.indexOf(".",atPos)
if (periodPos == -1) {
return false
}

if (periodPos+3 > email1.length) {
return false
}


return true
}

function matchEmails(email, confirmEmail) {
	if (email.value != confirmEmail.value) {
		alert("The email addresses you entered do not match. Please correct.");
		confirmEmail.focus();
		confirmEmail.select();
		return false;
	}
	return true;
}

<!---function checkLecture() {
	alert("current field is " + lecture);
	alert("field length is " + lecture.length);
	// Loop through all lecture-related checkboxes on the page
	for (i=0; i<document.lecture_register.lecture.length; i++) {
		if (document.lecture_register.lecture[i].checked==true) {
			return true;				
		}
	}
	return false;
}--->

function clearLectures(lectures, radiobutton) {
	for (i=0; i<lectures.length; i++) {
		if (lectures[i].checked==true) {
			lectures[i].click();
		}
	}
	radiobutton[1].checked=true;
	return true;
}

function submitIt(form) {
/*
if (!checkLecture() {
	alert("Please select at least one event.")
	// form.lecture.focus()
	// form.purchase_influence.select()
	return false
}
*/
if (form.visitor_first_name.value=="") {
	alert("Please enter your first name.")
	form.visitor_first_name.focus()
	form.visitor_first_name.select()
	return false
}
if (form.visitor_last_name.value=="") {
	alert("Please enter your last name.")
	form.visitor_last_name.focus()
	form.visitor_last_name.select()
	return false
}
if (form.company.value=="") {
	alert("Please enter your company name.")
	form.company.focus()
	form.company.select()
	return false
}
if (form.title.value=="") {
	alert("Please enter your title.")
	form.title.focus()
	form.title.select()
	return false
}
if (form.department.value=="") {
	alert("Please enter your division or department.")
	form.department.focus()
	form.department.select()
	return false
}
if (form.job_type.value=="") {
	alert("Please select your job type.")
	form.job_type.focus()
	// form.job_type.select()
	return false
}
if (form.address1.value=="") {
	alert("Please enter your street address.")
	form.address1.focus()
	form.address1.select()
	return false
}
if (form.zip.value=="") {
	alert("Please enter your zip code.")
	form.zip.focus()
	form.zip.select()
	return false
}
if (form.phone.value=="") {
	alert("Please enter your phone number.")
	form.phone.focus()
	form.phone.select()
	return false
}
if (!validEmail(form.email.value)) {
	alert("Please enter a valid email address.")
	form.email.focus()
	form.email.select()
	return false
}
if (form.ConfirmEmail.value=="") {
	alert("Please type your email address a second time for verification.")
	form.ConfirmEmail.focus()
	form.ConfirmEmail.select()
	return false
}
if (!matchEmails(form.email, form.ConfirmEmail)) {
	alert("Your email addresses do not match. Please correct.")
	form.ConfirmEmail.focus()
	form.ConfirmEmail.select()
	return false
}
return true
}

if (form.job_type.value=="") {
	alert("Please select your job type.")
	form.job_type.focus()
	// form.job_type.select()
	return false
}