// javascript document

// clear the school not shown field
function clearNotShown() {
	if (document.forms[0].school_not_shown) {
		var a = document.forms[0].school_not_shown.value;
		if (a != "") {
			document.forms[0].school_not_shown.value = "";
		}
	}
}

// if country other than us or association chosen disable cds
function changeCDS(index) {
	var a = document.account.county_code;
	var b = document.account.district_code;
	var c = document.account.school_code;
	var d = document.account.association_id;
	if (index != 0) {
		a.selectedIndex = 0;
		b.selectedIndex = 0;
		c.selectedIndex = 0;
		a.setAttribute("disabled","disabled");
		b.setAttribute("disabled","disabled");
		c.setAttribute("disabled","disabled");
		d.removeAttribute("disabled");
	} else {
		a.removeAttribute("disabled");
	}
}

// dynamically populate district list based on county choice and disable association
function reqDistrict(id) {
	clearNotShown();
	var districtprogressOn = "<img src=\"images/ajax.gif\" alt=\"loading\" width=\"16\" height=\"16\" />";
	var districtprogressOff = "<img src=\"images/transpixel.gif\" alt=\" \" width=\"16\" height=\"16\" />";
	var a = document.forms[0].district_code;
	var b = document.forms[0].school_code;
	if (document.forms[0].association_id) {
		var c = document.forms[0].association_id;
	}
	if (id == 0) {
		a.options.length = 0;
		b.options.length = 0;
		a.options[0] = new Option("Select...","");
		b.options[0] = new Option("Select...","");
		a.setAttribute("disabled","disabled");
		b.setAttribute("disabled","disabled");
		if (c) {
			c.removeAttribute("disabled");
			c.selectedIndex = 0;
		}
		return;
	} else {
		b.options.length = 0;
		b.options[0] = new Option("Select...","");
		b.setAttribute("disabled","disabled");
		if (c) {
			c.setAttribute("disabled","disabled");
		}
	}
	changeContent("districtprogress", districtprogressOn);
	var r = Math.round(Math.random() * 10000000);
	var i = 0;
	var optionscounter = 1;
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status === 200) {
					var dbresults = request.responseText;
					var resultsarray = dbresults.split("\r");
					a.options.length = 0;
					a.options[0] = new Option("Select...","");
					var resultsarraylength = resultsarray.length - 1;
					for (i = 0; i < resultsarraylength; i++) {
						var districtoptions = resultsarray[i].split("|");
						a.options[optionscounter] = new Option(districtoptions[0], districtoptions[1]);
						optionscounter++;
					}
					a.removeAttribute("disabled");
					changeContent("districtprogress", districtprogressOff);
				} else {
					alert("There was a problem retrieving the data:\n" + request.statusText + request.responseText);
				}
			}
		};
		var action_params = "";
		action_params += "?county_code=" + escape(id);
		action_params += "&r=" + escape(r);
		request.open("GET", "qry_district_script.lasso" + action_params, true);
		request.send(null);
	} else {
		alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
	}
}

// dynamically populate school list based on district choice
function reqSchool(id) {
	clearNotShown();
	var schoolprogressOn = "<img src=\"images/ajax.gif\" alt=\"loading\" width=\"16\" height=\"16\" />";
	var schoolprogressOff = "<img src=\"images/transpixel.gif\" alt=\" \" width=\"16\" height=\"16\" />";
	var a = document.forms[0].school_code;
	if (id == 0) {
		a.options.length = 0;
		a.options[0] = new Option("Select...","");
		a.setAttribute("disabled","disabled");
		return;
	}
	changeContent("schoolprogress", schoolprogressOn);
	var r = Math.round(Math.random() * 10000000);
	var i = 0;
	var optionscounter = 1;
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status === 200) {
					var dbresults = request.responseText;
					if (dbresults == "none") {
						a.options.length = 0;
						a.options[0] = new Option("Select...","");
						a.setAttribute("disabled","disabled");
					} else {
						var resultsarray = dbresults.split("\r");
						a.options.length = 0;
						a.options[0] = new Option("Select...","");
						var resultsarraylength = resultsarray.length - 1;
						for (i = 0; i < resultsarraylength; i++) {
							var schooloptions = resultsarray[i].split("|");
							a.options[optionscounter] = new Option(schooloptions[0],schooloptions[1]);
							optionscounter++;
						}
						a.options[optionscounter] = new Option("District Office","0000000");
						optionscounter++;
						a.options[optionscounter] = new Option("School not shown","9999999");
						a.removeAttribute("disabled");
						changeContent("schoolprogress", schoolprogressOff);
					}
				} else {
					alert("There was a problem retrieving the data:\n" + request.statusText + request.responseText);
				}
			}
		};
		var action_params = "";
		action_params += "?district_code=" + escape(id);
		action_params += "&r=" + escape(r);
		request.open("GET", "qry_school_script.lasso" + action_params, true);
		request.send(null);
	} else {
		alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
	}
}

// toggle sample phone number
function togglePrefill(o, e) {
	var a = o.id;
	var eventhandler = e == "f" ? "focus" : "blur";
	var b = document.getElementById(a).value;
	var defaultphone = "9165551234";
	if (eventhandler == "focus") {
		if (b == defaultphone) {
			document.getElementById(a).value = "";
			document.getElementById(a).style.color = "#000000";
		} else if (b !== "" && b != defaultphone) {
			document.getElementById(a).style.color = "#000000";
		}
	}
	if (eventhandler == "blur") {
		if (b === "" || b == defaultphone) {
			document.getElementById(a).value = defaultphone;
			document.getElementById(a).style.color = "#777777";
		}
	}
}

// validate reg form and confirm unique username
function validAccount() {
	var submitbutton = document.account.submitbutton;
	var newaccountprogressOn = "<img src=\"images/ajax.gif\" alt=\"loading\" width=\"16\" height=\"16\" />";
	var newaccountprogressOff = "<img src=\"images/transpixel.gif\" alt=\" \" width=\"16\" height=\"16\" />";
	submitbutton.setAttribute("disabled","disabled");
	changeContent("newaccountprogress", newaccountprogressOn);
	var a = document.account.username.value;
	var b = document.account.password.value;
	var c = document.account.confirm_password.value;
	var d = document.account.security_id.selectedIndex;
	var e = document.account.security_answer.value;
	var f = document.account.name_first.value;
	var g = document.account.name_last.value;
	var h = document.account.position_id.selectedIndex;
	var j = document.account.position_other.value;
	var k = document.account.address_street.value;
	var l = document.account.address_city.value;
	var m = document.account.address_state.value;
	var n = document.account.address_zip.value;
	var o = document.account.phone_work.value;
	var p = document.account.email.value;
	var q = document.account.phone_alternate.value;
	var r = document.account.email_alternate.value;
	var s = document.account.function_id;
	var t = document.account.function_id.length;
	var u = document.account.function_other.value;
	var v = document.account.county_code.selectedIndex;
	var w = document.account.district_code.selectedIndex;
	var x = document.account.school_code.selectedIndex;
	var y = document.account.school_not_shown.value;
	var z = document.account.credential_id.selectedIndex;
	var aa = document.account.grade_teaching.selectedIndex;
	var ab = document.account.classroom_type.length;
	var ac = document.account.lausd_employee_num.value;
	var ad = document.account.association_id.selectedIndex;
	var ae = document.account.association_other.value;
	var af = document.account.reg_self_else.selectedIndex;
	var ag = document.account.created_by.value;
	var ah = document.account.appname;
	var aj = document.account.appversion;
	var ak = document.account.platform;
	var al = document.account.useragent;
	var i = 0;
	var teacher_jobtitle = document.account.position_id[h].value == 37;
	for (i = 0; i < t; i++) {
		var teacher_jobfunction = s[i].checked && s[i].value == 17;
		if (teacher_jobfunction) {
			break;
		}
	}
	var defaultphone = "9165551234";
	var invalidemail;
	var functionchecked;
	var otherfunctionchecked;
	var classroomtypechecked;
	var dialog = "";
	if (a === "" || a.length < 6) {
		dialog += "\n- Username (at least 6 characters)";
	}
	if (b === "") {
		dialog += "\n- Password";
	} else {
		if (b !== c) {
			dialog += "\n- Password confirm does not match password";
		}
	}
	if (d === 0) {
		dialog += "\n- Security question";
	}
	if (e === "") {
		dialog += "\n- Security answer";
	}
	if (f === "") {
		dialog += "\n- First name";
	}
	if (g === "") {
		dialog += "\n- Last name";
	}
	if (h === 0) {
		dialog += "\n- Job title";
	}
	if (document.account.position_id[h].value == "0" && j === "") {
		dialog += "\n- Job title (if other)";
	}
	if (k === "") {
		dialog += "\n- Address";
	}
	if (l === "") {
		dialog += "\n- City";
	}
	if (m === "") {
		dialog += "\n- State";
	}
	if (n === "" || isNaN(n) || n.length !== 5) {
		dialog += "\n- ZIP (5 digits)";
	}
	if (o === defaultphone || isNaN(o) || o.length != 10) {
		dialog += "\n- Work phone (10 digits)";
	}
	if (p === "") {
		dialog += "\n- Work email";
	} else {
		invalidemail = p.indexOf("@") == -1 || p.indexOf(".") == -1;
		if (invalidemail) {
			dialog += "\n- Work email does not appear valid";
		}
	}
	// alternate phone and email are not required, but if we have data we should make sure it's valid
	if (isNaN(q) || q.length != 10) {
		dialog += "\n- Alternate phone (10 digits)";
	}
	if (r !== "") {
		invalidemail = r.indexOf("@") == -1 || r.indexOf(".") == -1;
		if (invalidemail) {
			dialog += "\n- Alternate email does not appear valid";
		}
	}
	for (i = 0; i < t; i++) {
		functionchecked = s[i].checked;
		if (functionchecked) {
			break;
		}
	}
	if (!functionchecked) {
		dialog += "\n- Job function";
	}
	for (i = 0; i < t; i++) {
		otherfunctionchecked = s[i].checked && s[i].value == "0";
	}
	if (otherfunctionchecked && u === "") {
		dialog += "\n- Job function (if other)";
	}
	if (v == 0 && ad == 0) {
		dialog += "\n- County, district, school OR association";
	}
	if (v != 0) {
		if (w == 0) {
			dialog += "\n- District";
		}
		if (x == 0) {
			dialog += "\n- School";
		}
		if (document.account.school_code[x].value == "9999999" && y === "") {
			dialog += "\n- School (if not shown)";
		}
	}
	if (document.account.association_id[ad].value == "0" && ae === "") {
		dialog += "\n- Association (if not shown)";
	}
	// if a teacher, check for credential, grade, and classroom
	if (teacher_jobtitle || teacher_jobfunction) {
		if (z == 0) {
			dialog += "\n- Credential";
		}
		if (aa == 0) {
			dialog += "\n- Teaching grade";
		}
		for (i = 0; i < ab; i++) {
			classroomtypechecked = document.account.classroom_type[i].checked;
			if (classroomtypechecked) {
				break;
			}
		}
		if (!classroomtypechecked) {
			dialog += "\n- Classroom type";
		}
	}
	// don't require lausd employee num, but validate if it's there
	if (ac !== "") {
		if (isNaN(ac) || ac.length != 6) {
			dialog += "\n- LAUSD employee number (6 digits)";
		}
	}
	if (af == 0) {
		dialog += "\n- Self or else account creation";
	}
	if (document.account.reg_self_else[af].value == "No" && ag === "") {
		dialog += "\n- Your name (if creating account for someone else)";
	}
	document.account.appname.value = navigator.appName;
	document.account.appversion.value = navigator.appVersion;
	document.account.platform.value = navigator.platform;
	document.account.useragent.value = navigator.userAgent;
	if (dialog != "") {
		submitbutton.removeAttribute("disabled");
		changeContent("newaccountprogress", newaccountprogressOff);
		alert("Sorry, the following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	var validNewAccount = uniqueUser(a);
	if (!validNewAccount) {
		submitbutton.removeAttribute("disabled");
		changeContent("newaccountprogress", newaccountprogressOff);
		alert("Sorry, that username is already in use. Please choose another.");
		document.forms[0].username.value = "";
		document.forms[0].username.focus();
		return false;
	}
	return true;
}

// validate reg form and confirm unique username
function newAccount() {
	var newaccountprogressOn = "<img src=\"images/ajax.gif\" alt=\"loading\" width=\"16\" height=\"16\" />";
	var newaccountprogressOff = "<img src=\"images/transpixel.gif\" alt=\" \" width=\"16\" height=\"16\" />";
	changeContent("newaccountprogress", newaccountprogressOn);
	var a = document.account.username.value;
	var b = document.account.password.value;
	var c = document.account.confirm_password.value;
	var d = document.account.name_first.value;
	var e = document.account.name_last.value;
	var f = document.account.position_id.selectedIndex;
	var g = document.account.address_street.value;
	var h = document.account.address_city.value;
	var j = document.account.address_state.value;
	var k = document.account.address_zip.value;
	var l = document.account.address_country.selectedIndex;
	var m = document.account.phone_work.value;
	var n = document.account.email.value;
	var o = document.account.function_id.length;
	var p = document.account.county_code.selectedIndex;
	var q = document.account.district_code.selectedIndex;
	var r = document.account.school_code.selectedIndex;
	var s = document.account.association_id.selectedIndex;
	// late add ons
	var t = document.account.ssn.value;
	var u = document.account.ucla_extension.checked;
	var v = document.account.lausd_local_dist.value;
	var w = document.account.lausd_employee_num.value;
	var x = document.account.credential_id.selectedIndex;
	var y = document.account.security_id.selectedIndex;
	var z = document.account.security_answer.value;
	var aa = document.account.school_code.options[r].value;
	var ab = document.account.school_not_shown.value;
	var ac = document.account.reg_self_else.selectedIndex;
	var ad = document.account.created_by.value;
	var ae = document.account.phone_summer.value;
	var af = document.account.email_alternate.value;
	var teacher_jobtitle = document.account.position_id.options[f].value == 37;
	for(var i=0; i<o; i++) {
		var teacher_jobfunction = ((document.account.function_id[i].checked) && (document.account.function_id[i].value == 17));
		if (teacher_jobfunction) {
			break;
		}
	}
	var dialog = "";
	if (a == "" || a.length < 6) {
		dialog += "\n- Username (at least 6 characters)";
	}
	if (b == "") {
		dialog += "\n- Password";
	}
	if (c != b) {
		dialog += "\n- Password confirm doesn't match password";
	}
	if (y == 0) {
		dialog += "\n- Security question";
	}
	if (z == "") {
		dialog += "\n- Security answer";
	}
	if (d == "") {
		dialog += "\n- First name";
	}
	if (e == "") {
		dialog += "\n- Last name";
	}
	if (f == 0) {
		dialog += "\n- Job Title";
	}
	if (g == "") {
		dialog += "\n- Address";
	}
	if (h == "") {
		dialog += "\n- City";
	}
	if (l == 0) { // state and zip if in us
		if (j == "") {
		dialog += "\n- State";
		}
		if (k == "" || isNaN(k) || k.length != 5) {
			dialog += "\n- Zip (5 digits)";
		}
	}
	if (l == 0) { // 10 digit phone if in us
		if (m == "" || isNaN(m) || m.length != 10) {
			dialog += "\n- Work phone (10 digits)";
		}
	}
	if (n == "") {
		dialog += "\n- Email";
	} else {
		var not_email = n.indexOf("@") == -1 || n.indexOf(".") == -1;
			if (not_email) {
			dialog += "\n- Email does not appear valid";
		}
	}
	if (ae != "") { 
		if (isNaN(ae) || ae.length != 10) {
			dialog += "\n- Summer phone (10 digits)";
		}
	}
	if (af != "") {
		var not_altemail = af.indexOf("@") == -1 || af.indexOf(".") == -1;
		if (not_altemail) {
			dialog += "\n- Summer email does not appear valid";
		}
	}
	if (t != "") {
		if (isNaN(t) || t.length != 9) {
			dialog += "\n- Social Security does not appear valid (9 digits)";
		} else {
			var not_ssn = ssnValid(t);
			if (not_ssn) {
				dialog += "\n- Social Security does not appear valid (9 digits)";
			}
		}
	}
	if (u && t == "") {
		dialog += "\n- Social Security (if attending UCLA Extension)";	
	}
	for(var i=0; i<o; i++) {
		var function_checked = document.account.function_id[i].checked;
		if (function_checked) {
			break;
		}
	}
	if (!function_checked) {
		dialog += "\n- Job function";
	}
	if (l == 0) { // if working in us
		if (p == 0) { // no county
			if (s == 0) { // no association
				dialog += "\n- County, District, School OR Association";
			}
		} else {
			if (q == 0) {
				dialog += "\n- District";
			} else {
				if (document.account.school_code.options.length != 1 && r == 0) {
					dialog += "\n- School";
				}
				if (aa == 9999999) {
					if (ab == "") {
						dialog += "\n- Name of school if not shown";
					}
				}
			}
		}
	} else { // not working in us
		if (s == 0) {
			dialog += "\n- Association";
		}
	}
	if (teacher_jobtitle || teacher_jobfunction) {
		if (x == 0) {
			dialog += "\n- Credential (if teacher)";
		}
	}
	if (v != "") {
		if (v > 8 || isNaN(v)) {
			dialog += "\n- LAUSD local district 1 through 8 only";	
		}
	}
	if (w != "") {
		if (w.length != 6 || isNaN(w)) {
			dialog += "\n- LAUSD employee number (6 digits)";	
		}
	}
	if (ac == 0) {
		dialog += "\n- Account creation self or else";
	}
	if (ac == 2 && ad == "") {
		dialog += "\n- Name if creating account for someone else";
	}
	if (dialog != "") {
		changeContent("newaccountprogress", newaccountprogressOff);
		alert("The following field(s) require(s) valid entry:" + dialog + "\n");
		return false;
	}
	document.account.disp_county.value = document.account.county_code.options[p].text;
	document.account.disp_district.value = document.account.district_code.options[q].text;
	document.account.disp_school.value = document.account.school_code.options[r].text;
	document.account.appname.value = navigator.appName;
	document.account.appversion.value = navigator.appVersion;
	document.account.platform.value = navigator.platform;
	document.account.useragent.value = navigator.userAgent;
	var validNewAccount = uniqueUser(a);
	if (!validNewAccount) {
		changeContent("newaccountprogress", newaccountprogressOff);
		alert("Sorry, that username is already in use. Please choose another.");
		document.forms[0].username.value = "";
		return false;
	}
	return true;
}

// valid login
function newLogin() {
	var a = document.forms[0].username.value;
	var b = document.forms[0].password.value;
	var c = document.forms[0].loginsubmit;
	if (a == "" || b == "") {
		alert("Please enter both username and password.");
		return false;
	}
	document.forms[0].appname.value = navigator.appName;
	document.forms[0].appversion.value = navigator.appVersion;
	document.forms[0].platform.value = navigator.platform;
	document.forms[0].useragent.value = navigator.userAgent;
	changeContent("loginprogress", progressOn);
	c.setAttribute("disabled", "disabled");
	return true;
}

// validate account edit
function accountEdit() {
	var a = document.accountedit.name_first.value;
	var b = document.accountedit.name_last.value;
	var c = document.accountedit.position_id.selectedIndex;
	var d = document.accountedit.position_other.value;
	var e = document.accountedit.address_street.value;
	var f = document.accountedit.address_city.value;
	var g = document.accountedit.address_state.value;
	var h = document.accountedit.address_zip.value;
	var j = document.accountedit.phone_work.value;
	var k = document.accountedit.email.value;
	var l = document.accountedit.phone_alternate.value;
	var m = document.accountedit.email_alternate.value;
	var not_email;
	var dialog = "";
	if (a === "") {
		dialog += "\n- First name";
	}
	if (b === "") {
		dialog += "\n- Last name";
	}
	if (c == 0) {
		dialog += "\n- Job Title";
	}
	if (document.accountedit.position_id[c].value == "0" && d === "") {
		dialog += "\n- Job title (if other)";
	}
	if (e === "") {
		dialog += "\n- Address";
	}
	if (f === "") {
		dialog += "\n- City";
	}
	if (g === "") {
		dialog += "\n- State";
	}
	if (h === "" || isNaN(h) || h.length != 5) {
		dialog += "\n- Zip (5 digits)";
	}
	if (j === "" || isNaN(j) || j.length != 10) {
		dialog += "\n- Work phone (10 digits)";
	}
	if (k === "") {
		dialog += "\n- Work Email";
	} else {
		not_email = k.indexOf("@") == -1 || k.indexOf(".") == -1;
			if (not_email) {
			dialog += "\n- Work email does not appear valid";
		}
	}
	if (l !== "") {
		if (isNaN(l) || l.length != 10) {
			dialog += "\n- Alternate phone (10 digits)";
		}
	}
	if (m !== "") {
		not_email = m.indexOf("@") == -1 || m.indexOf(".") == -1;
		if (not_email) {
			dialog += "\n- Alternate email does not appear valid";
		}
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog + "\n");
		return false;
	}
	return true;
}

// valid function edit
function functionEdit() {
	var a = document.forms[0].function_id.length;
	for(var i=0; i<a; i++) {
		var function_checked = document.forms[0].function_id[i].checked;
		if (function_checked) {
			break;
		}
	}
	if (!function_checked) {
		alert("Please select at least one job function.");
		return false;
	}
	return true;
}

// search for unique username when editing -- excludes current
function uniqueUserEdit(username) {
	var request = null;
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (request) {
		request.open("GET", "qry_usernameedit_script.lasso?username=" + username, false);
		request.send(null);
		if (request.status == 200) {
			var dbresults = request.responseText;
			if (dbresults == "error") {
				alert("Sorry, that username is already in use. Please choose another.");
				document.unpwedit.username.focus();
				return false;
			}
		} else {
			alert("There was a problem retrieving the XML data:\n" + request.statusText);
			return false;
		}
	} else {
		alert("Sorry, an error has occurred.");
		return false;
	}
	return true;
}

// valid username password edit
function unpwEdit() {
	var a = document.unpwedit.username.value;
	var b = document.unpwedit.password.value;
	var c = document.unpwedit.confirm_password.value;
	var dialog = "";
	if (a == "" || a.length < 6) {
		dialog += "\n- Username (at least 6 characters)";
	}
	if (b == "") {
		dialog += "\n- Password";
	}
	if (c != b) {
		dialog += "\n- Password confirm doesn't match password";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog + "\n");
		return false;
	}
	return uniqueUserEdit(a);
}

// valid cds edit
function cdsEdit() {
	var a = document.forms[0].county_code.selectedIndex;
	var b = document.forms[0].district_code.selectedIndex;
	var c = document.forms[0].school_code;
	var d = c.selectedIndex;
	var e = c[d].value;
	var f = document.forms[0].school_not_shown.value;
	var g = document.forms[0].cdsedit_submit;
	var dialog = "";
	if (a === 0) {
		dialog += "\n- County";
	}
	if (b === 0) {
		dialog += "\n- District";
	}
	if (d == 0) {
		dialog += "\n- School";
	}
	if (e == 9999999 && f === "") {
		dialog += "\n- Name of school if not shown";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog + "\n");
		return false;
	}
	changeContent("cdseditprogress", progressOn);
	g.setAttribute("disabled", "disabled");
	return true;
}

// valid association edit
function assocEdit() {
	var a = document.assocedit.association_id.selectedIndex;
	if (a == 0) {
		alert("Please choose an association.");
		return false;
	}
	return true;
}

// valid preferences edit -- just need to check phone numbers
function prefEdit() {
	var a = document.prefedit.phone_cell.value;
	var b = document.prefedit.phone_home.value;
	var c = document.prefedit.phone_fax.value;
	var d = document.prefedit.phone_emergency.value;
	var dialog = "";
	var aa = new Array(a, b, c, d);
	var ba = new Array("Cell phone", "Home phone", "Fax", "Emergency");
	for(var i=0; i<aa.length; i++) {
		if (aa[i] != "") {
			if (isNaN(aa[i]) || aa[i].length != 10) {
				dialog += "\n- " + ba[i] + "(10 digits)";
			}
		}
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog + "\n");
		return false;
	}
	return true;
}

// valid passport certifier update
function psptEdit() {
	var a = document.psptedit.cds_code.value;
	var b = document.psptedit.passport_certify.checked;
	if (!b) {
		alert("Please check confirmation.");
		return false;
	}
	return true;
}

// valid qeia certifier submission
function qeiaCert() {
	var a = document.qeiacert.qeia_certify.checked;
	if (!a) {
		alert("Please check confirmation.");
		return false;
	}
	return true;
}

// valid passport certifier remove record
function psptCertEdit() {
	var a = document.psptcertedit.passport_remove.checked;
	if (!a) {
		alert("Please check removal.");
		return false;
	}
	return true;
}

// valid qeia certifier remove
function qeiaCertEdit() {
	var a = document.qeiacertedit.qeia_remove.checked;
	if (!a) {
		alert("Please check removal confirmation.");
		return false;
	}
	return true;
}

// valid plg -- have to select all -- program, level, and grade
function plg() {
	//var a = document.submitplg.program_id.selectedIndex;
	var b = document.submitplg.level_id.selectedIndex;
	var c = document.submitplg.grade_id.selectedIndex;
	if ( b == 0 || c == 0) {
		alert("Please choose level and grade.");
		return false;
	}
	return true;
}

// prevent changing preselected program index
// variable defined on page and passed from program_id onchange
function noChange(e) {
	document.submitplg.program_id.selectedIndex = e;
}

// valid credential update
function credentialEdit() {
	var a = document.credentialedit.grade_teaching.selectedIndex;
	var b = document.credentialedit.credential_id.selectedIndex;
	var c = document.credentialedit.classroom_type.length;
	var dialog = "";
	if (a == 0) {
		dialog += "\n- Teaching grade";
	}
	if (b == 0) {
		dialog += "\n- Credential";
	}
	for (var i = 0; i < c; i++) {
		var classroomchecked = document.credentialedit.classroom_type[i].checked;
		if (classroomchecked) {
			break;
		}
	}
	if (!classroomchecked) {
		dialog += "\n- Classroom type";
	}
	if (dialog !== "") {
		alert("The following field((s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid LAUSD update
function lausdEdit() {
	var a = document.lausdedit.lausd_employee_num.value;
	if (a === "" || a.length != 6 || isNaN(a)) {
		alert("Employee number does not appear valid (6 digits).");
		return false;
	}
	return true;
}

// new lost password
function lostPassword() {
	var a = document.forms[0].username.value;
	var b = document.forms[0].security_id.selectedIndex;
	var c = document.forms[0].security_answer.value;
	var d = document.forms[0].lostpassword_submit;
	var dialog = "";
	if (a === "") {
		dialog += "\n- Username";
	}
	if (b === 0) {
		dialog += "\n- Security question";
	}
	if (c === "") {
		dialog += "\n- Security answer";
	}
	if (dialog !== "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	changeContent("lostpasswordprogress", progressOn);
	d.setAttribute("disabled", "disabled");
	return true;
}

// new version
function lostUsername() {
	var a = document.forms[0].password.value;
	var b = document.forms[0].security_id.selectedIndex;
	var c = document.forms[0].security_answer.value;
	var d = document.forms[0].lostusername_submit;
	var dialog = "";
	if (a === "") {
		dialog += "\n- Password";
	}
	if (b === 0) {
		dialog += "\n- Security question";
	}
	if (c === "") {
		dialog += "\n- Security answer";
	}
	if (dialog !== "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	changeContent("lostusernameprogress", progressOn);
	d.setAttribute("disabled", "disabled");
	return true;
}

// valid security question change
function qaEdit() {
	var a = document.qaedit.security_id.selectedIndex;
	var b = document.qaedit.security_answer.value;
	if (a == 0 || b == "") {
		alert("Please choose a security question and enter your answer.");
		return false;
	}
	return true;
}

function cancelReg() {
	window.location = "https://db.readinglions.net/register/index.lasso?fa=regevent";
}

// valid registration cancellation
function regCancel() {
	var a = document.forms[0].key;
	var b = a.length;
	var c = document.forms[0].regcancel_submit;
	var regchecked = false;
	var i = 0;
	var msg = "To proceed with cancelling the selected registrations, click \"OK.\"";
	if (b == null) {
		regchecked = a.checked;
	} else {
		for (i = 0; i < b; i++) {
			regchecked = a[i].checked;
			if (regchecked) {
				break;
			}
		}
	}
	if (!regchecked) {
		alert("Please select an event to cancel.");
		return false;
	}
	changeContent("regcancelprogress", progressOn);
	c.setAttribute("disabled", "disabled");
	return true;
}

// valid confirm instructor assignment
function assignStatus() {
	var a = document.forms[0].accept;
	var b = document.forms[0].accommodations;
	var c = document.forms[0].driving;
	var d = document.forms[0].assignstatus_submit;
	var acceptchecked = false;
	var accommodationschecked = false;
	var drivingchecked = false;
	var dialog = "";
	var i = 0;
	for (i = 0; i < a.length; i++) {
		acceptchecked = a[i].checked;
		if (acceptchecked) { break; }
	}
	for (i = 0; i < b.length; i++) {
		accommodationschecked = b[i].checked;
		if (accommodationschecked) { break; }
	}
	for (i = 0; i < c.length; i++) {
		drivingchecked = c[i].checked;
		if (drivingchecked) { break; }
	}
	if (!acceptchecked) { dialog += "\n- Confirmed"; }
	if (!accommodationschecked) { dialog += "\n- Hotel"; }
	if (!drivingchecked) { dialog += "\n- Driving"; }
	if (dialog !== "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	changeContent("assignstatusprogress", progressOn);
	d.setAttribute("disabled", "disabled");
	return true;
}

// valid search for open events
function openEvents() {
	var a = document.openevents.type_id.selectedIndex;
	var b = document.openevents.type_id[a].value;
	var c = document.openevents.program_id.selectedIndex;
	var dialog = "";
	if (a == 0) {
		dialog += "\n- Event type";
	}
	if (b == 1 && c == 0) {
		dialog += "\n- Program, if event type is Teacher Institute";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	// save a couple of hits to the db by gathering names here
	document.openevents.tn.value = document.openevents.type_id[a].text;
	document.openevents.pn.value = document.openevents.program_id[c].text;
	return true;
}

// show registration status
function regCapacityShow(ecid,course_capacity) {
	// query hack to add random number to search request
	// search results are stored in cache and won't change if request doesn't change
	var r = Math.round(Math.random() * 10000000);
	var request = null;
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (request) {
		request.open("GET", "qry_regcapacity_script.lasso?evt_crs_id=" + escape(ecid) + "&course_capacity=" + escape(course_capacity) + "&r=" + escape(r), false);
		request.send(null);
		if (request.status == 200) {
			var regstatus = request.responseText;
			// regstatus += "<br />&laquo; <a href=\"javascript:regCapacityHide(" + ecid + "," + course_capacity + ");\">Hide</a>";
			var spanname = "reg" + ecid;
			writeLayer(spanname,null,regstatus);
		} else {
			alert("There was a problem retrieving the XML data:\n" + request.statusText);
		}
	} else {
		alert("Sorry, a connection error has occurred.");
	}
}

// hide the reg status display
function regCapacityHide(ecid,course_capacity) {
	var regstatus = "<a href=\"javascript:regCapacityShow(" + ecid + "," + course_capacity + ");\">Show</a> &raquo;";
	var spanname = "reg" + ecid;
	writeLayer(spanname,null,regstatus);
}

// show program choice only if teacher institute is selected
function activeProgram(e) {
	var a = document.forms[0].program_id;
	if (e == 1) {
		a.removeAttribute("disabled");
	} else {
		a.selectedIndex = 0;
		a.setAttribute("disabled","disabled");
	}
}

// auto fill shipping address the same as mailing address
function shippingAddress(e) {
	var clicked = e.checked;
	var a = document.accountedit.address_street.value;
	var b = document.accountedit.address_city.value;
	var c = document.accountedit.address_state.value;
	var d = document.accountedit.address_zip.value;
	var e = document.accountedit.address_country.selectedIndex;
	if (clicked) {
		if (a == "" || b == "" || c == "" || d == "") {
			alert("Please enter your full address:\n- Street\n- City\n- State\n- Zip");
			document.accountedit.shipping_same.checked = false;
		} else {
			document.accountedit.shipping_street.value = a;
			document.accountedit.shipping_city.value = b;
			document.accountedit.shipping_state.value = c;
			document.accountedit.shipping_zip.value = d;
			document.accountedit.shipping_country.selectedIndex = e;
		}
	} else {
		document.accountedit.shipping_street.value = "";
		document.accountedit.shipping_city.value = "";
		document.accountedit.shipping_state.value = "";
		document.accountedit.shipping_zip.value = "";
		document.accountedit.shipping_country.selectedIndex = "";
	}
}

// valid summit reg
function summit() {
	var a = document.forms[0].accommodations.length;
	var b = document.forms[0].pr_number.value;
	var c = document.forms[0].po_number.value;
	var d = document.forms[0].check_number.value;
	var e = document.forms[0].amount.value;
	if (document.forms[0].billing_district) {
		var f = document.forms[0].billing_district.value;
	}
	var g = document.forms[0].billing_street.value;
	var h = document.forms[0].billing_city.value;
	var j = document.forms[0].billing_state.value;
	var k = document.forms[0].billing_zip.value;
	var dialog = "";
	for(var i=0; i<a; i++) {
		var accommchecked = document.forms[0].accommodations[i].checked;
		if (accommchecked) {
			break;
		}
	}
	if (!accommchecked) {
		dialog += "\n- Accommodations";
	}
	if (b == "" && c == "" && d == "") {
		dialog += "\n- PR, PO, or check number";
	}
	if (e == "") {
		dialog += "\n- Amount";
	} else if (isNaN(e)) {
		dialog += "\n- Amount does not appear valid (numbers only)";
	}
	if (f == "") {
		dialog += "\n- Billing district";
	}
	if (g == "") {
		dialog += "\n- Billing address";
	}
	if (h == "") {
		dialog += "\n- Billing city";
	}
	if (j == "") {
		dialog += "\n- Billing state";
	}
	if (k == "") {
		dialog += "\n- Billing zip";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid principal coach summit reg
function pcsummit() {
	var a = document.forms[0].pr_number.value;
	var b = document.forms[0].po_number.value;
	var c = document.forms[0].check_number.value;
	var d = document.forms[0].amount.value;
	if (document.forms[0].billing_district) {
		var e = document.forms[0].billing_district.value;
	}
	var f = document.forms[0].billing_street.value;
	var g = document.forms[0].billing_city.value;
	var h = document.forms[0].billing_state.value;
	var j = document.forms[0].billing_zip.value;
	var dialog = "";
	if (a == "" && b == "" && c == "") {
		dialog += "\n- PR, PO, or check number";
	}
	if (d == "") {
		dialog += "\n- Amount";
	} else if (isNaN(d)) {
		dialog += "\n- Amount does not appear valid (numbers only)";
	}
	if (e == "") {
		dialog += "\n- Billing district";
	}
	if (f == "") {
		dialog += "\n- Billing address";
	}
	if (g == "") {
		dialog += "\n- Billing city";
	}
	if (h == "") {
		dialog += "\n- Billing state";
	}
	if (j == "") {
		dialog += "\n- Billing zip";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid principal coach institute reg
function pcinstitute() {
	var a = document.forms[0].pr_number.value;
	var b = document.forms[0].po_number.value;
	var c = document.forms[0].check_number.value;
	var d = document.forms[0].amount.value;
	var e = document.forms[0].pc_inst_function.length;
	var f = document.forms[0].billing_first.value;
	var g = document.forms[0].billing_last.value;
	var h = document.forms[0].billing_street.value;
	var j = document.forms[0].billing_city.value;
	var k = document.forms[0].billing_state.value;
	var l = document.forms[0].billing_zip.value;
	var m = document.forms[0].billing_phone.value;
	var pcfunctionchecked = false;
	var pcfunctionvalue = "";
	var pcfunctionother = document.forms[0].pc_inst_function_other.value;
	var dialog = "";
	for (var i = 0; i < e; i++) {
		pcfunctionchecked = document.forms[0].pc_inst_function[i].checked;
		if (pcfunctionchecked) {
			pcfunctionvalue = document.forms[0].pc_inst_function[i].value;
			break;
		}
	}
	if (!pcfunctionchecked && pcfunctionother === "") {
		dialog += "\n- Job function";
	}
	if (document.forms[0].pc_inst_function[2].checked && pcfunctionother === "") {
		dialog += "\n- Job function, if other";
	}
	if (a === "" && b === "" && c === "") {
		dialog += "\n- PR, PO, or check number";
	}
	if (d === "" || isNaN(d)) {
		dialog += "\n- Amount (numbers only)";
	}
	if (f === "") {
		dialog += "\n- Contact first name";
	}
	if (g === "") {
		dialog += "\n- Contact last name";
	}
	if (h === "") {
		dialog += "\n- Contact address";
	}
	if (j === "") {
		dialog += "\n- Contact city";
	}
	if (k === "") {
		dialog += "\n- Contact state";
	}
	if (l === "" || isNaN(l) || l.length != 5) {
		dialog += "\n- Contact ZIP (5 digits)";
	}
	if (m === "" || isNaN(m) || m.length != 10) {
		dialog += "\n- Contact phone (10 digits)";
	}	
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid ab430 institute reg
function ab430() {
	var a = document.forms[0].pr_number.value;
	var b = document.forms[0].po_number.value;
	var c = document.forms[0].check_number.value;
	var d = document.forms[0].amount.value;
	var dialog = "";
	if (a === "" && b === "" && c === "") {
		dialog += "\n- PR, PO, or check number";
	}
	if (d === "" || isNaN(d)) {
		dialog += "\n- Amount (numbers only)";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid template training reg
function templateTraining() {
	var a = document.forms[0].pr_number.value;
	var b = document.forms[0].po_number.value;
	var c = document.forms[0].check_number.value;
	var d = document.forms[0].amount.value;
	var dialog = "";
	if (a == "" && b == "" && c == "") {
		dialog += "\n- PR, PO, or check number";
	}
	if (d == "") {
		dialog += "\n- Amount";
	} else if (isNaN(d)) {
		dialog += "\n- Amount does not appear valid (numbers only)";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid tot reg
function accomm() {
	var a = document.forms[0].accommodations.length;
	for(var i=0; i<a; i++) {
		var accommchecked = document.forms[0].accommodations[i].checked;
		if (accommchecked) {
			break;
		}
	}
	if (!accommchecked) {
		alert("Please check accommodations.");
		return false;
	}
	return true;
}

// valid leadership reg
function lpaccomm() {
	var a = document.forms[0].accommodations.length;
	var b = document.forms[0].date_checkin.length;
	var c = document.forms[0].date_checkout.length;
	var i = 0;
	var dialog = "";
	for (i=0; i < a; i++) {
		var accommchecked = document.forms[0].accommodations[i].checked;
		if (accommchecked) {
			break;
		}
	}
	var yesaccommchecked = document.forms[0].accommodations[0].checked;
	var noaccommchecked = document.forms[0].accommodations[1].checked;
	if (b == null) {
		var checkinchecked = document.forms[0].date_checkin.checked;
	} else {
		for (i = 0; i < b; i++) {
			var checkinchecked = document.forms[0].date_checkin[i].checked;
		 	if (checkinchecked) {
				break;
			}
		}
	}
	if (c == null) {
		var checkoutchecked = document.forms[0].date_checkout.checked;
	} else {
		for (i = 0; i < c; i++) {
			var checkoutchecked = document.forms[0].date_checkout[i].checked;
			if (checkoutchecked) {
				break;
			}
		}
	}
	if (!accommchecked) {
		dialog += "\n- Accommodations";
	}
	if (yesaccommchecked) {
		if (!checkinchecked || !checkoutchecked) {
			dialog += "\n- Check-in and check-out";
		}
	}
	var noaccomm_checkin = noaccommchecked && checkinchecked;
	if (noaccomm_checkin) {
		dialog += "\n- Check-in only if accommodations needed";
	}
	var noaccomm_checkout = noaccommchecked && checkoutchecked;
	if (noaccomm_checkout) {
		dialog += "\n- Check-out only if accommodations needed";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		if (noaccomm_checkin) {
			if (b == null) {
				document.forms[0].date_checkin.checked = false;
			} else {
				for (i = 0; i < b; i++) {
					document.forms[0].date_checkin[i].checked = false;
				}
			}	
		}
		if (noaccomm_checkout) {
			if (c == null) {
				document.forms[0].date_checkout.checked = false;
			} else {
				for (i = 0; i < c; i++) {
					document.forms[0].date_checkout[i].checked = false;	
				}
			}	
		}
		return false;
	}
	return true;
}

// valid ucla essay submission
function uclaEssay() {
	var a = document.uclaessay.reg_number.value;
	var b = a.slice(0,1);
	var c = a.slice(-4);
	var d = (b.match(/[a-zA-Z]/));
	var e = document.uclaessay.assignment.value;
	var dialog = "";
	if (!d || isNaN(c)) {
		dialog += "\n- Valid registration number";
	} else { // in case they paste in the course number
		var not_regnumber = a.indexOf("X") != -1 || a.indexOf("x") != -1 || a.indexOf(".") != -1;
		if (not_regnumber) {
			dialog += "\n- Registration number does not appear valid";
		}
	}
	if (e == "") {
		dialog += "\n- Assignment(s)";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// global replace pr, po, or check number for cc principal-coach summit registration
function updategNum(n) {
	var toggle = n;
	var a = document.gnum.g_num.value;
	var pr = document.gnum.g_type[0].checked;
	var po = document.gnum.g_type[1].checked;
	var ch = document.gnum.g_type[2].checked;
	var numfieldlength = document.ccaccountregpc.pr_number.length;
	if (toggle == 1) {
		if (a == "" || (!pr && !po && !ch)) {
			alert("Please enter a PO, PR, or check number and choose a field.");
			return false;
		} else {
			for(var i=0; i<document.gnum.g_type.length; i++) {
				if (document.gnum.g_type[i].checked) {
					var typechecked = document.gnum.g_type[i].value;
					break;
				}
			}
			switch(parseInt(typechecked)) {
			case 0:
				for(var i=0; i<numfieldlength; i++) {
					document.ccaccountregpc.pr_number[i].value = a;
				}
				break;
			case 1:
				for(var i=0; i<numfieldlength; i++) {
					document.ccaccountregpc.po_number[i].value = a;
				}
				break;
			case 2:
				for(var i=0; i<numfieldlength; i++) {
					document.ccaccountregpc.check_number[i].value = a;
				}
				break;
			}
			return false;
		}
	} else {
		for(var i=0; i<document.gnum.g_type.length; i++) {
			if (document.gnum.g_type[i].checked) {
				var typechecked = document.gnum.g_type[i].value;
				break;
			}
		}
		switch(parseInt(typechecked)) {
		case 0:
			for(var i=0; i<numfieldlength; i++) {
				document.ccaccountregpc.pr_number[i].value = "";
			}
			break;
		case 1:
			for(var i=0; i<numfieldlength; i++) {
				document.ccaccountregpc.po_number[i].value = "";
			}
			break;
		case 2:
			for(var i=0; i<numfieldlength; i++) {
				document.ccaccountregpc.check_number[i].value = "";
			}
			break;
		}
		document.gnum.g_num.value = "";
		document.gnum.g_type[0].checked = false;
		document.gnum.g_type[1].checked = false;
		document.gnum.g_type[2].checked = false;
		return false;
	}
}

// valid people search
function peopleSearch() {
	var a = document.forms[0].name_first.value;
	var b = document.forms[0].name_last.value;
	var c = document.forms[0].district.value;
	var d = document.forms[0].peoplesearch_submit;
	if (a === "" && b === "" && c === "") {
		alert("At least one field requires valid entry: \n" +
		"- First name\n" + 
		"- Last name\n" + 
		"- District");
		return false;
	}
	changeContent("peoplesearchprogress", progressOn);
	d.setAttribute("disabled", "disabled");
	return true;
}

// bail out of elpd registration
function cancelReg() {
	window.location = "https://db.readinglions.net/register/index.lasso?fa=countycourses";
}

// valid module attendance submission and parsing pre-lasso
function attendListMod() {
	var a = document.attendlist.elements.length;
	var i = 0;
	var j = 0;
	var k = 0;
	var complete = 0;
	var reg = [];
	var module = [];
	var item_value = [];
	var people = [];
	var last = [];
	var first = [];
	for (i = 0; i < a; i++) {
		if (document.attendlist.elements[i].type == "radio") {
				var item_name = document.attendlist.elements[i].name;
				var item_name_split = item_name.split("_");
				reg[k] = item_name_split[1];
				module[k] = item_name_split[2];
				people[k] = item_name_split[3];
				last[k] = item_name_split[4];
				first[k] = item_name_split[5];
				j = i + 1;
				if (document.attendlist.elements[i].checked) {
					item_value[k] = document.attendlist.elements[i].value;
				} else {
					item_value[k] = document.attendlist.elements[j].value;
				}
				if (item_value[k] != "") {
					complete++;
				}
				k++;
				i++;
		}
	}
	if (document.attendlist.total.value != complete) { // haven't entered attendance for everyone
		alert("Please select attendance for each participant.");
		return false;
	}
	document.attendlist.reg.value = reg;
	document.attendlist.module.value = module;
	document.attendlist.item_value.value = item_value;
	document.attendlist.people.value = people;
	document.attendlist.last.value = last;
	document.attendlist.first.value = first;
	return true;
}

// valid module attendance submission and parsing pre-lasso
function attendList5Day() {
	var a = document.attendlist.elements.length;
	var i = 0;
	var k = 0;
	var complete = 0;
	var reg = [];
	var eventcourse = [];
	var day1am = [];
	var day1pm = [];
	var day2am = [];
	var day2pm = [];
	var day3am = [];
	var day3pm = [];
	var day4am = [];
	var day4pm = [];
	var day5am = [];
	var day5pm = [];
	var h1 = [];
	var h2 = [];
	var h3 = [];
	var h4 = [];
	var ns = [];
	var comp = [];
	for (i = 0; i < a; i++) {
		if (document.attendlist.elements[i].type == "checkbox") {
				var item_name = document.attendlist.elements[i].name;
				var item_name_split = item_name.split("_");
				reg[k] = item_name_split[1];
				eventcourse[k] = document.attendlist.elements["eventcourse_" + item_name_split[1]].value;
				var i1 = i + 1;
				var i2 = i + 2;
				var i3 = i + 3;
				var i4 = i + 4;
				var i5 = i + 5;
				var i6 = i + 6;
				var i7 = i + 7;
				var i8 = i + 8;
				var i9 = i + 9;
				var i10 = i + 10;
				var i11 = i + 11;
				var i12 = i + 12;
				var i13 = i + 13;
				var i14 = i + 14;
				var i15 = i + 15;
				var checkentry = 0;
				if (document.attendlist.elements[i].checked) {
					day1am[k] = document.attendlist.elements[i].value;
					checkentry++;
				} else {
					day1am[k] = "";
				}
				if (document.attendlist.elements[i1].checked) {
					day1pm[k] = document.attendlist.elements[i1].value;
					checkentry++;
				} else {
					day1pm[k] = "";
				}
				if (document.attendlist.elements[i2].checked) {
					day2am[k] = document.attendlist.elements[i2].value;
					checkentry++;
				} else {
					day2am[k] = "";
				}
				if (document.attendlist.elements[i3].checked) {
					day2pm[k] = document.attendlist.elements[i3].value;
					checkentry++;
				} else {
					day2pm[k] = "";
				}
				if (document.attendlist.elements[i4].checked) {
					day3am[k] = document.attendlist.elements[i4].value;
					checkentry++;
				} else {
					day3am[k] = "";
				}
				if (document.attendlist.elements[i5].checked) {
					day3pm[k] = document.attendlist.elements[i5].value;
					checkentry++;
				} else {
					day3pm[k] = "";
				}
				if (document.attendlist.elements[i6].checked) {
					day4am[k] = document.attendlist.elements[i6].value;
					checkentry++;
				} else {
					day4am[k] = "";
				}
				if (document.attendlist.elements[i7].checked) {
					day4pm[k] = document.attendlist.elements[i7].value;
					checkentry++;
				} else {
					day4pm[k] = "";
				}
				if (document.attendlist.elements[i8].checked) {
					day5am[k] = document.attendlist.elements[i8].value;
					checkentry++;
				} else {
					day5am[k] = "";
				}
				if (document.attendlist.elements[i9].checked) {
					day5pm[k] = document.attendlist.elements[i9].value;
					checkentry++;
				} else {
					day5pm[k] = "";
				}
				if (document.attendlist.elements[i10].checked) {
					h1[k] = document.attendlist.elements[i10].value;
					checkentry++;
				} else {
					h1[k] = "";
				}
				if (document.attendlist.elements[i11].checked) {
					h2[k] = document.attendlist.elements[i11].value;
					checkentry++;
				} else {
					h2[k] = "";
				}
				if (document.attendlist.elements[i12].checked) {
					h3[k] = document.attendlist.elements[i12].value;
					checkentry++;
				} else {
					h3[k] = "";
				}
				if (document.attendlist.elements[i13].checked) {
					h4[k] = document.attendlist.elements[i13].value;
					checkentry++;
				} else {
					h4[k] = "";
				}
				if (document.attendlist.elements[i14].checked) {
					ns[k] = document.attendlist.elements[i14].value;
					checkentry++;
				} else {
					ns[k] = "";
				}
				if (document.attendlist.elements[i15].checked) {
					comp[k] = document.attendlist.elements[i15].value;
					checkentry++;
				} else {
					comp[k] = "";
				}
				if ( checkentry > 0) {
					complete++;
				}
				k++;
				i = i + 15;
		}
	}
	if (document.attendlist.total.value != complete) { // haven't entered attendance for everyone
		alert("Please select attendance for each participant.");
		return false;
	}
	document.attendlist.reg.value = reg;
	document.attendlist.eventcourse.value = eventcourse;
	document.attendlist.day1am.value = day1am;
	document.attendlist.day1pm.value = day1pm;
	document.attendlist.day2am.value = day2am;
	document.attendlist.day2pm.value = day2pm;
	document.attendlist.day3am.value = day3am;
	document.attendlist.day3pm.value = day3pm;
	document.attendlist.day4am.value = day4am;
	document.attendlist.day4pm.value = day4pm;
	document.attendlist.day5am.value = day5am;
	document.attendlist.day5pm.value = day5pm;
	document.attendlist.h1.value = h1;
	document.attendlist.h2.value = h2;
	document.attendlist.h3.value = h3;
	document.attendlist.h4.value = h4;
	document.attendlist.ns.value = ns;
	document.attendlist.complete.value = comp;
	return true;
}

// valid module attendance submission and instructor assignment record update
function submitAttendance() {
	var progressloader = "Adding. Please wait... <img src=\"images/ajax.gif\" alt=\"loading\" width=\"16\" height=\"16\" />";
	progressloader += "<img src=\"images/transpixel.gif\" alt=\" \" width=\"16\" height=\"27\" style=\"vertical-align:middle;\" />";
	changeContent("addingrecords", progressloader);
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status === 200) {
					// image include strictly cosmetic so text does not appear to jump
					var msg = request.responseText;
					msg += "<img src=\"images/transpixel.gif\" alt=\" \" width=\"16\" height=\"27\" style=\"vertical-align:middle;\" />";
					changeContent("addingrecords", msg);
				} else {
					alert("There was a problem retrieving the XML data:\n" + request.statusText + request.responseText);
				}
			}
		}
		request.open("GET", "queries/qry_submitattend_script.lasso", true);
		request.send(null);
	} else {
		alert("Sorry, an error has occurred.");
	}
}

// show program, level and grade choices only if teacher institute is selected for event search
function activeProgram(e) {
	var a = document.forms[0].program_id;
	var b = document.forms[0].level_id;
	var c = document.forms[0].grade_id;
	if(e == 1) {
		a.removeAttribute("disabled");
		b.removeAttribute("disabled");
		c.removeAttribute("disabled");
	} else {
		a.selectedIndex = 0;
		a.setAttribute("disabled","disabled");
		b.selectedIndex = 0;
		b.setAttribute("disabled","disabled");
		c.selectedIndex = 0;
		c.setAttribute("disabled","disabled");
	}
}

// valid search for events
function eventSearch() {
	var a = document.forms[0].type_id.selectedIndex;
	var b = document.forms[0].schedsearchsubmit;
	if(a == "") {
		alert("Please select an event type. All other fields are optional.");
		return false;
	}
	changeContent("schedsearchprogress", progressOn);
	b.setAttribute("disabled", "disabled");
	return true;
}

// ucla courses
function uclaCourses() {
	var a = document.uclacourses.cr.length;
	var coursechecked = false;
	for (var i = 0; i < a; i++) {
		coursechecked = document.uclacourses.cr[i].checked;
		if (coursechecked) {
			break;
		}
	}
	if (!coursechecked) {
		alert("Please select a course.");
		return false;
	}
	return true;
}

// warning for submitting duplicate attendance records
function attendWarning() {
	var msg = "Warning!\n\n";
	msg += "You have selected to submit attendance for an event that has current attendance records. ";
	msg += "If you submit records again, ALL previously submitted records will be deleted and replaced with your new submission.\n\n";
	msg += "Do you want to proceed?\n";
	if (confirm(msg)) {
		return true;
	} else {
		return false;
	}
}

// check all present when submitting module attendance
function checkAllMod() {
	var a = document.attendlist.elements.length;
	for (var i = 0; i < a; i++) {
		var b = document.attendlist.elements[i];
		if (b.type == "radio" && b.value == 1) {
			b.checked = true;
		}
	}
}

// check all present when submitting 5-day attendance
function checkAll5Day() {
	var a = document.attendlist.elements.length;
	for (var i = 0; i < a; i++) {
		var b = document.attendlist.elements[i];
		var item_name = document.attendlist.elements[i].name;
		var item_name_split = item_name.split("_");
		if (b.type == "checkbox" && item_name_split[0] != 'ns') {
			b.checked = true;
		}
	}
}

// when complete is checked - uncheck ns, check everything else
// when complete is unchecked - uncheck everything else
function checkAttendComplete(reg_id) {
	if (document.attendlist.elements["complete_" + reg_id].checked == true) {
		document.attendlist.elements["day1am_" + reg_id].checked = true;
		document.attendlist.elements["day1pm_" + reg_id].checked = true;
		document.attendlist.elements["day2am_" + reg_id].checked = true;
		document.attendlist.elements["day2pm_" + reg_id].checked = true;
		document.attendlist.elements["day3am_" + reg_id].checked = true;
		document.attendlist.elements["day3pm_" + reg_id].checked = true;
		document.attendlist.elements["day4am_" + reg_id].checked = true;
		document.attendlist.elements["day4pm_" + reg_id].checked = true;
		document.attendlist.elements["day5am_" + reg_id].checked = true;
		document.attendlist.elements["day5pm_" + reg_id].checked = true;
		document.attendlist.elements["h1_" + reg_id].checked = true;
		document.attendlist.elements["h2_" + reg_id].checked = true;
		document.attendlist.elements["h3_" + reg_id].checked = true;
		document.attendlist.elements["h4_" + reg_id].checked = true;
		document.attendlist.elements["ns_" + reg_id].checked = false;
	} else {
		document.attendlist.elements["day1am_" + reg_id].checked = false;
		document.attendlist.elements["day1pm_" + reg_id].checked = false;
		document.attendlist.elements["day2am_" + reg_id].checked = false;
		document.attendlist.elements["day2pm_" + reg_id].checked = false;
		document.attendlist.elements["day3am_" + reg_id].checked = false;
		document.attendlist.elements["day3pm_" + reg_id].checked = false;
		document.attendlist.elements["day4am_" + reg_id].checked = false;
		document.attendlist.elements["day4pm_" + reg_id].checked = false;
		document.attendlist.elements["day5am_" + reg_id].checked = false;
		document.attendlist.elements["day5pm_" + reg_id].checked = false;
		document.attendlist.elements["h1_" + reg_id].checked = false;
		document.attendlist.elements["h2_" + reg_id].checked = false;
		document.attendlist.elements["h3_" + reg_id].checked = false;
		document.attendlist.elements["h4_" + reg_id].checked = false;
		document.attendlist.elements["ns_" + reg_id].checked = false;
	}
}

// when no show is checked - uncheck everything else
function checkAttendNS(reg_id) {
	if (document.attendlist.elements["ns_" + reg_id].checked == true) {
		document.attendlist.elements["day1am_" + reg_id].checked = false;
		document.attendlist.elements["day1pm_" + reg_id].checked = false;
		document.attendlist.elements["day2am_" + reg_id].checked = false;
		document.attendlist.elements["day2pm_" + reg_id].checked = false;
		document.attendlist.elements["day3am_" + reg_id].checked = false;
		document.attendlist.elements["day3pm_" + reg_id].checked = false;
		document.attendlist.elements["day4am_" + reg_id].checked = false;
		document.attendlist.elements["day4pm_" + reg_id].checked = false;
		document.attendlist.elements["day5am_" + reg_id].checked = false;
		document.attendlist.elements["day5pm_" + reg_id].checked = false;
		document.attendlist.elements["h1_" + reg_id].checked = false;
		document.attendlist.elements["h2_" + reg_id].checked = false;
		document.attendlist.elements["h3_" + reg_id].checked = false;
		document.attendlist.elements["h4_" + reg_id].checked = false;
		document.attendlist.elements["complete_" + reg_id].checked = false;
	}
}

// when day or hw checked - uncheck no show
// when day or hw unchecked - uncheck complete
function checkAttendDayHW(item_name, reg_id) {
	if (document.attendlist.elements[item_name].checked == true) {
		document.attendlist.elements["ns_" + reg_id].checked = false;
	} else {
		document.attendlist.elements["complete_" + reg_id].checked = false;
	}
}

// valid vpss registration
function validVPSS() {
	var a = document.eventreg.vpss_assurances1;
	var b = document.eventreg.vpss_assurances2;
	var c = document.eventreg.vpss_assurances3;
	var d = document.eventreg.vpss_assurances4;
	var e = document.eventreg.vpss_assurances5;
	var f = document.eventreg.vpss_assurances6;
	var assurances_array = [a, b, c, d, e, f];
	var counter = 0;
	for (var i = 0; i < assurances_array.length; i++) {
		if (assurances_array[i].checked) {
			counter++;
		}
	}
	if (counter != assurances_array.length) {
		alert("Please check participant verifications and understandings.");
		return false;
	}
	document.eventreg.vpss_assurances.value = 1;
	return true;
}

// valid training of instructors reg form
function toiReg() {
	var selfpaychecked = document.forms[0].payment_responsibility[0].checked;
	var coepaychecked = document.forms[0].payment_responsibility[1].checked;
	var a = document.forms[0].payment_responsibility_subprovider_id.selectedIndex;
	var prsn = document.forms[0].payment_responsibility_subprovider_id[a].text;
	var b = document.forms[0].pr_number.value;
	var c = document.forms[0].po_number.value;
	var d = document.forms[0].check_number.value;
	var e = document.forms[0].amount.value;
	var dialog = "";
	if (!selfpaychecked && !coepaychecked) {
		dialog += "\n- Payment by";	
	}
	if (coepaychecked && a == 0) {
		dialog += "\n- County Office of Education";
	}
	if (b == "" && c == "" && d == "") {
		dialog += "\n- PR, PO, or check number";
	}
	if (e == "") {
		dialog += "\n- Amount";
	} else if (isNaN(d)) {
		dialog += "\n- Amount does not appear valid (numbers only)";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	document.forms[0].prsn.value = prsn;
	return true;
}

// reset toi reg form
function resetCOE() {
	document.forms[0].payment_responsibility_subprovider_id.selectedIndex = 0;
}

// reset toi regform
function resetPayBy(n) {
	if (n == 0) {
		document.forms[0].payment_responsibility[0].checked = true;
	} else {
		document.forms[0].payment_responsibility[1].checked = true;
	}
}

// valid qeia summit registration
function qeiaSummit() {
	var a = document.eventreg.qeia_position.selectedIndex;
	var b = document.eventreg.qeia_school_level.selectedIndex;
	var c = document.eventreg.qeia_certify.checked;
	/*
	var d = document.eventreg.accommodations;
	var e = d.length;
	var accommodationschecked = false;
	var i = 0;
	*/
	var dialog = "";
	if (a == 0) {
		dialog += "\n- Position";
	}
	if (b == 0) {
		dialog += "\n- School Level";
	}
	if (!c) {
		dialog += "\n- QEIA Certification";
	}
	/*
	for (i = 0; i < e; i++) {
		accommodationschecked = d[i].checked;
		if (accommodationschecked) {
			break;
		}
	}
	if (!accommodationschecked) {
		dialog += "\n- Hotel Information";
	}
	*/
	if (dialog !== "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid billing address edit submission
function billingEdit() {
	var a = document.billingedit.billing_street.value;
	var b = document.billingedit.billing_city.value;
	var c = document.billingedit.billing_state.value;
	var d = document.billingedit.billing_zip.value;
	var dialog = "";
	if (a == "") {
		dialog += "\n- Billing address";
	}
	if (b == "") {
		dialog += "\n- Billing city";
	}
	if (c == "") {
		dialog += "\n- Billing state";
	}
	if (d == "" || isNaN(d) || d.length != 5) {
		dialog += "\n- Billing ZIP (5 digits)";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid shipping address edit submission
function shippingEdit() {
	var a = document.shippingedit.shipping_street.value;
	var b = document.shippingedit.shipping_city.value;
	var c = document.shippingedit.shipping_state.value;
	var d = document.shippingedit.shipping_zip.value;
	var dialog = "";
	if (a == "") {
		dialog += "\n- Shipping address";
	}
	if (b == "") {
		dialog += "\n- Shipping city";
	}
	if (c == "") {
		dialog += "\n- Shipping state";
	}
	if (d == "" || isNaN(d) || d.length != 5) {
		dialog += "\n- Shipping ZIP (5 digits)";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// valid shipping address add submission
function shippingAdd() {
	var a = document.shippingadd.shipping_street.value;
	var b = document.shippingadd.shipping_city.value;
	var c = document.shippingadd.shipping_state.value;
	var d = document.shippingadd.shipping_zip.value;
	var dialog = "";
	if (a == "") {
		dialog += "\n- Shipping address";
	}
	if (b == "") {
		dialog += "\n- Shipping city";
	}
	if (c == "") {
		dialog += "\n- Shipping state";
	}
	if (d == "" || isNaN(d) || d.length != 5) {
		dialog += "\n- Shipping ZIP (5 digits)";
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// confirm both billing and shipping addresses, and order type for client type 3
function billingShipping() {
	var clientype3 = document.billingshipping.orderfor? true : false;
	var shippingaddress = document.billingshipping.shipping? true : false;
	var pickup = document.billingshipping.pickup? true : false;
	var ordertype = 0;
	var i = 0;
	var dialog = "";
	if (clientype3) {
		var a = document.billingshipping.orderfor;
		var orderforchecked = false;
		for (i = 0; i < a.length; i++) {
			orderforchecked = document.billingshipping.orderfor[i].checked;
			if (orderforchecked) {
				ordertype = document.billingshipping.orderfor[i].value;
				break;
			}
		}
		if (!orderforchecked) {
			dialog += "\n- Order";
		}
	}
	// if there's a shipping address, need shipping OR pickup checked
	// if there's no shipping address, need pickup checked
	// pickup always appears once a billing address is confirmed
	if (pickup) {
		var pickupchecked = document.billingshipping.pickup.checked;
	}
	if (shippingaddress) {	
		var b = document.billingshipping.shipping;
		var c = b.length;
		if (c == null) {
			var shippingchecked = document.billingshipping.shipping.checked;
		} else {
			for (i = 0; i < c; i++) {
				var shippingchecked = document.billingshipping.shipping[i].checked;
				if (shippingchecked) {
					break;
				}
			}
		}
		if (!pickupchecked && !shippingchecked && ordertype != 2) {
			dialog += "\n- Shipping address or pickup";
		}
	} else {
		if (!pickupchecked) {
			dialog += "\n- Pickup";
		}
	}
	if (dialog != "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	return true;
}

// do not display shipping options if ordering for one more schools in district
// reset shipping info just in case
function toggleDistrictShipping(n) {
	if (n == 2) {
		document.getElementById("shippingchoices").style.display = "none";
		var i = 0;
		var shippingaddress = document.billingshipping.shipping? true : false;
		var pickupaddress = document.billingshipping.pickup? true : false;
		if (shippingaddress) {
			var a = document.billingshipping.shipping;
			var b = a.length;
			if (b == null) {
				a.checked = false;
			} else {
				for (i = 0; i < b; i++) {
					a[i].checked = false;
				}
			}
		}
		if (pickupaddress) {
			var c = document.billingshipping.pickup;
			c.checked = false;
		}
	} else {
		document.getElementById("shippingchoices").style.display = "block";
	}
}

// toggle pickup and shipping address for orders
function toggleShipping(e) {
	// uncheck any shipping address, if shipping address exists, when pickup is checked
	// uncheck pickup if a shipping address exists and is checked
	var shippingaddress = e.name == "shipping";
	var pickupaddress = e.name == "pickup";
	var i = 0;	
	if (pickupaddress) {
		var shippingexists = document.billingshipping.shipping? true : false;
		if (shippingexists) {
			var a = document.billingshipping.shipping.length;
			if (a == null) {
				document.billingshipping.shipping.checked = false;
			} else {
				for (i = 0; i < a; i++) {
					document.billingshipping.shipping[i].checked = false;
				}
			}
		}
	}
	if (shippingaddress) {
		document.billingshipping.pickup.checked = false;
	}
}

// find uc davis course matching professional development training
function reqUnivCourses(n) {
	var a = document.ucd.course_id;
	var b = document.ucd.university_courses_id;
	if (n == "" || a.selectedIndex == 0) {
		changeContent("ucdaviscourse", progressOff);
		b.value = "";
		return;
	}
	changeContent("ucdaviscourse", progressOn);
	var r = Math.round(Math.random() * 10000000);
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status === 200) {
					var queryresults = request.responseText;				
					if (queryresults.indexOf("error") != -1) {
						changeContent("ucdaviscourse", progressOff);
						var alertmsg = "";
						alertmsg += "Sorry, the professional development course you have chosen does ";
						alertmsg += "not qualify for University of California, Davis credit."
						alert(alertmsg);
					} else {
						var resultsarray = queryresults.split("|");
						document.ucd.university_courses_id.value = resultsarray[0];
						changeContent("ucdaviscourse", resultsarray[1]);
					}
					
				} else {
					alert("There was a problem retrieving the data:\n" + request.statusText + request.responseText);
				}
			}
		};
		var action_params = "";
		action_params += "?course_id=" + escape(n);
		action_params += "&r=" + escape(r);
		request.open("GET", "queries/qry_univcourses.lasso" + action_params, true);
		request.send(null);
	} else {
		alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
	}
}

// valid ucd davis course and professional development course selections
function ucdProfDev() {
	var a = document.ucd.course_id.selectedIndex;
	var b = document.ucd.university_courses_id.value;
	
	if (a == 0) {
		alert("Please select a professional development course.");
		return false;
	}
	if (b == "") {
		var alertmsg = "";
		alertmsg += "Sorry, the professional development course you have chosen does ";
		alertmsg += "not qualify for University of California, Davis credit."
		alert(alertmsg);
		return false;
	}
	return true;
}

// specifically for type 7 rlc event
function eventReg7() {
	if (document.forms[0].teaching_grade) {
		var a = document.forms[0].teaching_grade.selectedIndex;
		if (a == 0) {
			alert("Please select your teaching grade.");
			return false;
		}
		return true;
	}
}

// valid submission of subclient and payment method
// redirect to sage if credit card payment
function regPaySelect() {
	// multiple clients triggered by multiple subclients for one people id
	// payment select triggered by rlc as event subprovider
	// possible to have one of these combos
	// multiple clients with payment select
	// multiple clients only
	// payment select only
	var clientlist = document.forms[0].subclient_id ? true : false;
	if (clientlist) {
		var a = document.forms[0].subclient_id.selectedIndex;
	}
	var paymentselect = document.forms[0].payment ? true : false;
	if (paymentselect) {
		var b = document.forms[0].payment;
		var c = b.length;
		var paychecked = false;
	}
	var d = document.forms[0].regpaysubmit;
	var creditcard = false;
	var i = 0;
	var dialog = "";
	if (clientlist) {
		if (a == 0) {
			dialog += "\n- Employer\/agency";
		}
	}
	if (paymentselect) {
		for (i = 0; i < c; i++) {
			paychecked = b[i].checked;
			creditcard = b[i].value == 1
			if (paychecked) { break; }
		}
		if (!paychecked) {
			dialog += "\n- Payment";
		}	
	}
	if (dialog !== "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	changeContent("regpayprogress", progressOn);
	d.setAttribute("disabled", "disabled");
	if (creditcard) {
		// document.forms[0].action = "https://www.sagepayments.net/eftcart/forms/express.asp";
		document.forms[0].action = "https://db.readinglions.net/register/index.lasso?fa=sagecardprocess";
	}
	return true;
}

// valid submission of reg payment contact info (pay later)
function regPayContact() {
	var a = document.forms[0].regpay_name_first.value;
	var b = document.forms[0].regpay_name_last.value;
	var c = document.forms[0].regpay_email.value;
	var d = document.forms[0].regpay_phone.value;
	var e = document.forms[0].regpay_po_number.value;
	var f = document.forms[0].regpaysubmit;
	var invalid_email = true;
	var invalid_phone = true;
	var dialog = "";
	if (a === "") {
		dialog += "\n- First name";
	}
	if (b === "") {
		dialog += "\n- Last name";
	}
	if (c === "") {
		dialog += "\n- Email";
	} else {
		invalid_email = c.indexOf("@") == -1 || c.indexOf(".") == -1;
		if (invalid_email) {
			dialog += "\n- Email appears to be invalid";
		}
	}
	if (d === "") {
		dialog += "\n- Phone (10 digits only)";
	} else {
		invalid_phone = isNaN(d) || d.length != 10;
		if (invalid_phone) {
			dialog += "\n- Phone (10 digits only)";
		}
	}
	if (e === "") {
		dialog += "\n- PR/PO/Check number";
	}
	if (dialog !== "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	changeContent("regpayprogress", progressOn);
	f.setAttribute("disabled", "disabled");
	return true;
}

// alert prompt that pay later requires contact info
function laterWarning() {
	var alertmsg = "";
	alertmsg += "Mail purchase order or check payable to:\n\nSacramento County Office of Education\n";
	alertmsg += "ATTN: Financial Services\nP.O. Box 269003\nSacramento, CA 95826\n\n";
	alertmsg += "or\n\nYou may bring a PO or check to the event.\n"
	alert(alertmsg);
}

// update the session var with the selected subclient id
function reqSubclientSession(subclient_id) {
	var r = Math.round(Math.random() * 10000000);
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status !== 200) {
					alert("There was a problem retrieving the XML data:\n" + request.statusText);
				}
			}
		};
		var action_params = "";
		action_params += "?r=" + escape(r);
		action_params += "&subclient_id=" + escape(subclient_id);
		request.open("GET", "queries/qry_subclientsession.lasso" + action_params, true); // true does not wait for server response
		request.send(null);
	} else {
		alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
	}
}

// dynamic request for lines event courses
// by county code and/or type id
function reqCountyCourses(id, n) {
	var a = document.forms[0].county_code;
	var b = a.selectedIndex;
	var county_code = a[b].value;
	var d = document.forms[0].type_id;
	var e = d.selectedIndex;
	var type_id = d[e].value;
	if (n == "county_code") {
		var selectprogress = "countyprogress";
	} else {
		var selectprogress = "typeprogress";
	}
	changeContent(selectprogress, progressOn);
	var r = Math.round(Math.random() * 10000000);
	var queryresults = ""
	var errormsg = "";
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status === 200) {
					queryresults = request.responseText;
					changeContent("countycoursesdisplay", queryresults);
					changeContent(selectprogress, progressOff);
				} else {
					changeContent(selectprogress, progressOff);
					alert("There was a problem retrieving the data:\n" + request.statusText + request.responseText);
				}
			}
		};
		var action_params = "";
		action_params += "?county_code=" + escape(county_code);
		action_params += "&type_id=" + escape(type_id);
		action_params += "&r=" + escape(r);
		request.open("GET", "queries/qry_countycourses.lasso" + action_params, true);
		request.send(null);
	} else {
		changeContent(selectprogress, progressOff);
		alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
	}
}

// valid advanced search for course
function courseSearch() {
	var a = document.forms[0].course_title.value === "";
	var b = document.forms[0].location_name.value === "";
	var c = document.forms[0].location_city.value === "";
	var d = document.forms[0].date_start.value === "";
	var e = document.forms[0].program_id.selectedIndex;
	var f = e === 0
	var g = document.forms[0].program_id[e].text;
	var h = document.forms[0].type_id.selectedIndex;
	var j = h === 0;
	var k = document.forms[0].type_id[h].text;
	var l = document.forms[0].subprovider_id.selectedIndex;
	var m = l === 0;
	var n = document.forms[0].subprovider_id[l].text;
	var o = document.forms[0].region_code.selectedIndex;
	var p = o === 0;
	var q = document.forms[0].coursesearchsubmit;
	var value_array = [a, b, c, d, f, j, m, p]
	var novalues = true;
	var i = 0;
	for (i = 0; i < value_array.length; i++) {
		novalues = value_array[i];
		if (!novalues) { break; }
	}
	if (novalues) {
		alert("Please enter at least one search criteria to begin.");
		return false;
	}
	document.forms[0].pn.value = g == "Select..." ? "" : g;
	document.forms[0].ct.value = k == "Select..." ? "" : k;
	document.forms[0].sn.value = n == "Select..." ? "" : n;
	changeContent("coursesearchprogress", progressOn);
	q.setAttribute("disabled", "disabled");
	return true;
}

// tally the number of makeupsessions checked
function sessionCheck() {	
	var sessionCheckedArray = new Array();
		sessionCheckedArray[0] = document.forms[0].mu_d1_am.checked? 1 : 0;
		sessionCheckedArray[1] = document.forms[0].mu_d1_pm.checked? 1 : 0;
		sessionCheckedArray[2] = document.forms[0].mu_d2_am.checked? 1 : 0;
		sessionCheckedArray[3] = document.forms[0].mu_d2_pm.checked? 1 : 0;
		sessionCheckedArray[4] = document.forms[0].mu_d3_am.checked? 1 : 0;
		sessionCheckedArray[5] = document.forms[0].mu_d3_pm.checked? 1 : 0;
		sessionCheckedArray[6] = document.forms[0].mu_d4_am.checked? 1 : 0;
		sessionCheckedArray[7] = document.forms[0].mu_d4_pm.checked? 1 : 0;
		sessionCheckedArray[8] = document.forms[0].mu_d5_am.checked? 1 : 0;
		sessionCheckedArray[9] = document.forms[0].mu_d5_pm.checked? 1 : 0;
	var totalChecked = 0;
	var i = 0;
	for (i = 0; i <sessionCheckedArray.length; i++) {
		totalChecked += sessionCheckedArray[i];
	}
	return totalChecked;
}

// valid submission of reg, makeupreg, and toireg form
// passkey if required and policy procedure agree
function regForm() {
	var passkey_required = document.forms[0].course_passkey ? true : false;
	var a = document.forms[0].accept;
	var acceptchecked = a.checked;
	var makeup_reg = document.forms[0].mu_this_year ? true : false;
	var toi_reg = document.forms[0].toipay_subprovider_id ? true : false;
	var dialog = ""
	var i = 0;
	if (makeup_reg) {
		var b = document.forms[0].mu_d1_am;
		var c = document.forms[0].mu_d1_pm;
		var d = document.forms[0].mu_d2_am;
		var e = document.forms[0].mu_d2_pm;
		var f = document.forms[0].mu_d3_am;
		var g = document.forms[0].mu_d3_pm;
		var h = document.forms[0].mu_d4_am;
		var j = document.forms[0].mu_d4_pm;
		var k = document.forms[0].mu_d5_am;
		var l = document.forms[0].mu_d5_pm;
		var m = document.forms[0].mu_this_year;
		var day1sessionChecked = b.checked || c.checked;
		var day2sessionChecked = d.checked || e.checked;
		var day3sessionChecked = f.checked || g.checked;
		var day4sessionChecked = h.checked || j.checked;
		var day5sessionChecked = k.checked || l.checked;
		var thisyearChecked = false;
		for (i = 0; i < m.length; i++) {
			thisyearChecked = m[i].checked;
			if (thisyearChecked) { break; }
		}
		var totalsessionsChecked = sessionCheck();
	}
	var n = document.forms[0].regformsubmit;
	if (passkey_required) {
		if (document.forms[0].course_passkey.value === "") {
			dialog += "\n- Course passkey";
		}
	}
	if (makeup_reg) {	
		if(totalsessionsChecked == 0) {
			dialog += "\n- At least one day's makeup session";
		}
		if(totalsessionsChecked > 9) {
			dialog += "\n- Cannot choose more than 9 makeup sessions";
		}
		if (!thisyearChecked) {
			dialog += "\n- Makeup for this year or last year";
		}
	}
	if (toi_reg) {
		if (document.forms[0].toipay_subprovider_id.selectedIndex == 0) {
			dialog += "\n- Training payment";
		}
	}
	if (!acceptchecked) {
		dialog += "\n- Acceptance of policies and details";
	}
	if (dialog !== "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	changeContent("regformprogress", progressOn);
	n.setAttribute("disabled", "disabled");
	return true;
}

// update people account with lines people subclient records
function accountUpdate() {
	var a = document.forms[0].accountupdate_submit;
	changeContent("accountupdateprogress", progressOn);
	a.setAttribute("disabled", "disabled");
	return true;
}

// valid open courses search
// will search by subprovider too at index.lasso
function openCourses() {
	var a = document.forms[0].course_title.value === "";
	var b = document.forms[0].location_name.value === "";
	var c = document.forms[0].location_city.value === "";
	var d = document.forms[0].date_start.value === "";
	var e = document.forms[0].program_id.selectedIndex;
	var f = e === 0
	var g = document.forms[0].program_id[e].text;
	var h = document.forms[0].type_id.selectedIndex;
	var j = h === 0;
	var k = document.forms[0].type_id[h].text;
	var l = document.forms[0].opencourses_submit;
	var value_array = [a, b, c, d, f, j]
	var novalues = true;
	var i = 0;
	for (i = 0; i < value_array.length; i++) {
		novalues = value_array[i];
		if (!novalues) { break; }
	}
	if (novalues) {
		alert("Please enter at least one search criteria to begin.");
		return false;
	}
	document.forms[0].pn.value = g == "Select..." ? "" : g;
	document.forms[0].ct.value = k == "Select..." ? "" : k;
	changeContent("opencoursesprogress", progressOn);
	l.setAttribute("disabled", "disabled");
	return true;
}

// for dtadmin change identity
function changeIdentity() {
	var a = document.forms[0].subprovider_id;
	var b = a.selectedIndex;
	var c = document.forms[0].changeidentity_submit;
	if (b === 0) {
		alert("Please select a subprovider.");
		return false;
	}
	changeContent("changeidentityprogress", progressOn);
	c.setAttribute("disabled", "disabled");
	return true;
}

// valid course search (outside of cam login)
function courseCalendar() {
	var a = document.forms[0].type_id;
	var b = a.selectedIndex;
	var c = b === 0;
	var d = a[b].text;
	var e = document.forms[0].program_id;
	var f = e.selectedIndex;
	var g = f === 0;
	var h = e[f].text;
	var j = document.forms[0].course_title.value;
	var k = j === "";
	var l = document.forms[0].location_name.value;
	var m = l === "";
	var n = document.forms[0].location_city.value;
	var o = n === "";
	var p = document.forms[0].viewallexpress;
	var q = document.forms[0].coursecalendar_submit;
	var viewallexpress = false;
	var i = 0;
	for (i = 0; i < p.length; i++) {
		viewallexpress = p[i].checked;
		if (viewallexpress) { break; }
	}
	if (!viewallexpress) {
		var novalues_array = [c, g, k, m, o];
		var novalue = true;
		for (i = 0; i < novalues_array.length; i++) {
			novalue = novalues_array[i];
			if (!novalue) { break; }
		}
		if (novalue) {
			alert("Please enter at least one search criteria.");
			return false;
		}
	}
	document.forms[0].tn.value = d == "Select..." ? "" : d; // type name text
	document.forms[0].pn.value = h == "Select..." ? "" : h; // program name text
	changeContent("coursecalendarprogress", progressOn);
	q.setAttribute("disabled", "disabled");
	return true;
}

// toggle functionality of grade, district, and school dropdowns
// clear out any address information if showing
function toggleGradeDistrictSchool(id) {
	var a = document.forms[0].county_code;
	var b = document.forms[0].district_code;
	var c = document.forms[0].school_code;
	var d = document.forms[0].school_not_shown;
	var e = document.forms[0].grade_id;
	var f = document.forms[0].address;
	var g = document.forms[0].city;
	var h = document.forms[0].zip;
	var j = document.forms[0].phone;
	var k = document.forms[0].email;
	var select_array = [b, c];
	var text_array = [d, f, g, h, j, k];
	var i = 0;
	a.selectedIndex = 0;
	if (id == 1) {
		for (i = 0; i < select_array.length; i++) {
			select_array[i].options.length = 0;
			select_array[i][0] = new Option("Select...","");
			select_array[i].removeAttribute("disabled");
		}
		d.removeAttribute("readonly");
		e.selectedIndex = 0;
		e.removeAttribute("disabled");
	} else {
		for (i = 0; i < select_array.length; i++) {
			select_array[i].options.length = 0;
			select_array[i][0] = new Option("Select...","");
			select_array[i].setAttribute("disabled", "disabled");
		}
		d.setAttribute("readonly", "readonly");
		e.selectedIndex = 0;
		e.setAttribute("disabled", "disabled");
	}
	for (i = 0; i < text_array.length; i++) {
		text_array[i].value = "";
	}
}

// dynamically populate district list based on county choice
function reqDistrictsExp(county_code) {
	var a = document.forms[0].employment;
	var b = document.forms[0].county_code;
	var c = document.forms[0].district_code;
	var d = document.forms[0].school_code;
	var e = document.forms[0].school_not_shown;
	var f = document.forms[0].address;
	var g = document.forms[0].city;
	var h = document.forms[0].state;
	var j = document.forms[0].zip;
	var k = document.forms[0].school_id;
	var address_array = [e, f, g, j, k];
	var employmentchecked = false;
	var cdsemployment = false;
	var queryresults;
	var r = Math.round(Math.random() * 10000000);
	var i = 0;
	for (i = 0; i < a.length; i++) {
		employmentchecked = a[i].checked;
		if (employmentchecked) { break; }
	}
	if (!employmentchecked) {
		b.selectedIndex = 0;
		alert("Please select your employment before choosing a county.");
		return;
	}
	for (i = 0; i < a.length; i++) {
		cdsemployment = a[i].checked && a[i].value == 1;
		if (cdsemployment) { break; }
	}
	// reset
	c.options.length = 0;
	c.options[0] = new Option("Select...","");
	d.options.length = 0;
	d.options[0] = new Option("Select...","");
	e.value = "";
	for (i = 0; i < address_array.length; i++) {
		address_array[i].value = "";
	}
	// do people really select "select"?
	if (county_code == 0) {	return; }
	if (cdsemployment) {
		changeContent("districtprogress", progressOn);
		var request = ajaxRequest();
		if (request) {
			request.onreadystatechange = function() {
				if (request.readyState === 4) {
					if (request.status === 200) {
						queryresults = request.responseText;
						changeContent("districtselect", queryresults);
						changeContent("districtprogress", progressOff);
					} else {
						changeContent("districtprogress", progressOff);
						alert("There was a problem retrieving the data:\n" + request.statusText);
					}
				}
			};
			var action_params = "";
			action_params += "?county_code=" + escape(county_code);
			action_params += "&r=" + escape(r);
			request.open("GET", "queries/qry_districts_exp.lasso" + action_params, true);
			request.send(null);
		} else {
			changeContent("districtprogress", progressOff);
			alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
		}
	}
}

// dynamically populate school list based on district choice
function reqSchoolsExp(district_code) {
	var a = document.forms[0].school_code;
	var b = document.forms[0].school_not_shown;
	var c = document.forms[0].address;
	var d = document.forms[0].city;
	var e = document.forms[0].state;
	var f = document.forms[0].zip;
	var g = document.forms[0].school_id;
	var address_array = [b, c, d, f, g];
	var queryresults;
	var r = Math.round(Math.random() * 10000000);
	var i = 0;
	a.options.length = 0;
	a.options[0] = new Option("Select...","");
	for (i = 0; i < address_array.length; i++) {
		address_array[i].value = "";
	}
	if (district_code == 0) { return; }
	changeContent("schoolprogress", progressOn);
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status === 200) {
					queryresults = request.responseText;
					changeContent("schoolselect", queryresults);
					changeContent("schoolprogress", progressOff);
				} else {
					changeContent("schoolprogress", progressOff);
					alert("There was a problem retrieving the data:\n" + request.statusText);
				}
			}
		};
		var action_params = "";
		action_params += "?district_code=" + escape(district_code);
		action_params += "&r=" + escape(r);
		request.open("GET", "queries/qry_schools_exp.lasso" + action_params, true);
		request.send(null);
	} else {
		changeContent("schoolprogress", progressOff);
		alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
	}
}

// let's grab the school address info for prepopulating the form
function reqSchoolAddressExp() {
	var a = document.forms[0].county_code;
	var b = a.selectedIndex;
	var countycode = a[b].value;
	var c = document.forms[0].district_code;
	var d = c.selectedIndex;
	var districtcode = c[d].value;
	// valid district code is first five only
	if (districtcode.length != 5) {
		var validdistrictcode = districtcode.slice(0,5);
		districtcode = validdistrictcode;
	}
	var e = document.forms[0].school_code;
	var f = e.selectedIndex;
	var schoolcode = e[f].value;
	var validschoolcode = schoolcode.indexOf("9999999") == -1;
	var cds_code = "";
	var g = document.forms[0].school_not_shown;
	var h = document.forms[0].address;
	var j = document.forms[0].city;
	var k = document.forms[0].state;
	var l = document.forms[0].zip;
	var m = document.forms[0].school_id;
	var formaddress_array = [g, h, j, l, m];
	var queryaddress_array = [h, j, k, l, m];
	var queryresults;
	var queryresults_array;
	var r = Math.round(Math.random() * 10000000);
	var i = 0;
	// reset form
	for (i = 0; i < formaddress_array.length; i++) {
		formaddress_array[i].value = "";
	}
	if (validschoolcode) {
		cds_code += countycode;
		cds_code += districtcode;
		cds_code += schoolcode;
	}
	if (!validschoolcode) {
		alert("Sorry, can't find a school address if school is not shown.");
		g.focus();
		return;
	}
	changeContent("addressprogress", progressOn);
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status === 200) {
					queryresults = request.responseText;
					queryresults_array = queryresults.split("|");
					for (i = 0; i < queryaddress_array.length; i++) {
						queryaddress_array[i].value = queryresults_array[i];
					}
					changeContent("addressprogress", progressOff);
				} else {
					changeContent("addressprogress", progressOff);
					alert("There was a problem retrieving the data:\n" + request.statusText);
				}
			}
		};
		var action_params = "";
		action_params += "?cds_code=" + escape(cds_code);
		action_params += "&r=" + escape(r);
		request.open("GET", "queries/qry_schooladdress_exp.lasso" + action_params, true);
		request.send(null);
	} else {
		changeContent("addressprogress", progressOff);
		alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
	}
}

// valid express reg form submission
function expressReg() {
	var a = document.forms[0].name_first.value;
	var b = document.forms[0].name_last.value;
	var c = document.forms[0].position.value;
	var d = document.forms[0].employment;
	var e = document.forms[0].county_code;
	var f = e.selectedIndex;
	var g = document.forms[0].district_code;
	var h = g.selectedIndex;
	var j = document.forms[0].school_code;
	var k = j.selectedIndex;
	var l = document.forms[0].school_not_shown.value;
	var m = document.forms[0].grade_id.selectedIndex;
	var n = document.forms[0].address.value;
	var o = document.forms[0].city.value;
	var p = document.forms[0].state.value;
	var q = document.forms[0].zip.value;
	var r = document.forms[0].phone.value;
	var s = document.forms[0].email.value;
	var t = document.forms[0].accept;
	var u = document.forms[0].submit_expressreg;
	var employmentchecked = false;
	var cdsemployment = false;
	var county = "";
	var district = "";
	var school = "";
	var i = 0;
	var dialog = "";
	if (a === "") {
		dialog += "\n- First name";
	}
	if (b === "") {
		dialog += "\n- Last name";
	}
	if (c === "") {
		dialog += "\n- Position";
	}
	for (i = 0; i < d.length; i++) {
		employmentchecked = d[i].checked;
		cdsemployment = d[i].value == 1;
		if (employmentchecked) { break; }
	}
	if (!employmentchecked) {
		dialog += "\n- Employment";
	}
	if (f === 0) {
		dialog += "\n- County";
	}
	if (cdsemployment) {
		if (h === 0) {
			dialog += "\n- District";
		}
		if (k === 0) {
			dialog += "\n- School";
		} else {
			if (j[k].value == "9999999" && l === "") {
				dialog += "\n- School if not shown";
			}
		}
		if (m === 0) {
			dialog += "\n- Teaching grade";
		}
	}
	if (n === "") {
		dialog += "\n- Address";
	}
	if (o === "") {
		dialog += "\n- City";
	}
	if (p === "") {
		dialog += "\n- State";
	}
	if (q === "" || isNaN(q) || q.length != 5) {
		dialog += "\n- ZIP (5 digits)";
	}
	if (r === "" || isNaN(r) || r.length != 10) {
		dialog += "\n- Phone (10 digits)";
	}
	if (s === "") {
		dialog += "\n- Email";
	} else {
		if (s.indexOf("@") == -1 || s.indexOf(".") == -1) {
			dialog += "\n- Email does not appear valid";
		}
	}
	if (!t.checked) {
		dialog += "\n- Acceptance of policies and details";
	}
	if (dialog !== "") {
		alert("The following field(s) require(s) valid entry:" + dialog);
		return false;
	}
	document.forms[0].county.value = e[f].text;
	document.forms[0].district.value = g[h].text == "Select..." ? "" : g[h].text;
	document.forms[0].school.value = j[k].text == "Select..." ? "" : j[k].text;
	changeContent("expressregprogress", progressOn);
	u.setAttribute("disabled", "disabled");
	return true;
}

// submit a search for upcoming courses from the cam index
// search by county code, express reg courses only or all
function reqCountyExpressReg() {
	document.getElementById("error").style.display = "none";
	changeContent("error", "");
	var a = document.forms[1].county_code;
	var b = a.selectedIndex;
	var c = a[b].value;
	var d = document.forms[1].viewallexpress;
	var viewexpress = false;
	var i = 0;
	var queryresults;
	var r = Math.round(Math.random() * 10000000);
	if (b === 0) {
		alert("Please select a county.");
		return;
	}
	for (i = 0; i < d.length; i++) {
		viewexpress = d[i].checked && d[i].value == 1;
		if (viewexpress) { break; }
	}
	changeContent("indexcoursesprogress", progressOn);
	var request = ajaxRequest();
	if (request) {
		request.onreadystatechange = function() {
			if (request.readyState === 4) {
				if (request.status === 200) {
					queryresults = request.responseText;
					if (queryresults.indexOf("false") != -1) {
						var errormsg = "";
						if (viewexpress) {
							errormsg += "<p class=\"alert\">Sorry, no Express registration courses ";
							errormsg += "were found in your selected county. Please select a different ";
							errormsg += "county or view the entire calendar.</p>";
						} else {
							errormsg += "<p class=\"alert\">Sorry, no courses were found in ";
							errormsg += "your selected county. Please select another.</p>";
						}
						changeContent("error", errormsg);
						changeContent("indexcoursesprogress", progressOff);
						document.getElementById("error").style.display = "block";
						return;
					} else {
						window.location = "https://db.readinglions.net/register/index.lasso?fa=quickcourseview";
					}
				} else {
					changeContent("indexcoursesprogress", progressOff);
					alert("There was a problem retrieving the data:\n" + request.statusText + request.responseText);
					return;
				}
			}
		};
		var action_params = "";
		action_params += "?courses_county_code=" + escape(c);
		action_params += "&viewexpress=" + escape(viewexpress);
		action_params += "&r=" + escape(r);
		request.open("GET", "queries/qry_countyexpressreg.lasso" + action_params, true);
		request.send(null);
	} else {
		changeContent("indexcoursesprogress", progressOff);
		alert("Sorry, an error has occurred. Your browser is unable to support dynamic requests.");
		return;
	}
}

// dt only function to search the mysql table for qeia training records
function dtQeiaSqlSearch() {
	var a = document.forms[0].grouphours_id.value !== "";
	var b = document.forms[0].training_type_all_id.value !== "";
	var c = document.forms[0].training_all_title.value !== "";
	var d = document.forms[0].qeia_people_id.value !== "";
	var e = document.forms[0].qeia_name_first.value !== "";
	var f = document.forms[0].qeia_name_last.value !== "";
	var g = document.forms[0].cam_people_id_created.value !== "";
	var h = document.forms[0].fm.value;
	var j = h !== "";
	var k = h == "yes" || h == "Yes" || h == "No" || h == "no";
	var l = document.forms[0].dtqeiasqlsearch_submit;
	var fieldarray = [a, b, c, d, e, f, g, j];
	var enteredvalue = false;
	var i = 0;
	for (i = 0; i < fieldarray.length; i++) {
		enteredvalue = fieldarray[i];
		if (enteredvalue) { break; }
	}
	if (!enteredvalue) {
		alert("Please enter at least one search criteria.");
		return false;
	}
	if (j && !k) {
		alert("Please enter \"yes\" or \"no\" for filemaker transfer.");
		return false;
	}
	changeContent("dtqeiasqlsearchprogress", progressOn);
	l.setAttribute("disabled", "disabled");
	return true;
}
