

function registrationStudent() {
	
	for (i=0;i<myInputs.length;i++) {
		
		var place=myInputs[i][0];
		var label=myInputs[i][1];
		var word=/\w+/;
		
		var v=document.form.elements[place].value
		var entry=v.match(word);
		
		if (!entry) {
			alert ("Please enter your "+label+" before sending your registration.");
			document.form.elements[place].focus();
			return false
		}

		var quotes = /"/;
		var entry2=v.match(quotes);
		
		if (entry2) {
		alert("Please do not use double quotation in the entry: "+label+". \nIf necessary, use single quotation marks.");
			document.form.elements[place].focus();
			return false		

		}
	}
		
	if (document.form.state.value == 0) {
		alert ("Please enter your school's location and submit again.");
		document.form.state.focus();
		return false
	}
		
	var password=password_check("student");
		if (!password) {return false}
	
	return true
}

function password_check(i) {
	
	if (i == "school") {
		var p=document.form.school_password;
		var c=document.form.confirm_school_password.value;
		
	}
	else { 
		var p=document.form.password;
		var c=document.form.confirm_password.value;
	}
	
	
	if (p.value.length<5) {
		alert ("Your password should be at least 5 characters long. \nPlease re-enter it.");
		p.value="";
		p.focus();
		return false
	}
	
	if (p.value != c) {
		alert ("Password and confirmation password do not match.\nPlease try again by retyping both.");
		p.value="";
		document.form.confirm_password.value="";
		p.focus();
		return false
	}

	return true
}


function registrationTeacher() {
	
	for (i=0;i<myInputs.length;i++) {
		
		var place=myInputs[i][0];
		var label=myInputs[i][1];
		var word=/\w+/;
		
		var v=document.form.elements[place].value
		var entry=v.match(word);
		
		if (!entry) {
			alert ("Please enter your "+label+" before sending your registration.");
			document.form.elements[place].focus();
			return false
		}

		var quotes = /"/;
		var entry2=v.match(quotes);
		
		if (entry2) {
		alert("Please do not use double quotation in the entry: "+label+". \nIf necessary, use single quotation marks.");
			document.form.elements[place].focus();
			return false		

		}
	}
		
	
		
	var password=password_check("student");
		if (!password) {return false}
	
	return true
}

function registrationSchool() {
	
	for (i=0;i<myInputs.length;i++) {
		
		var place=myInputs[i][0];
		var label=myInputs[i][1];
		var word=/\w+/;
		
		var v=document.form.elements[place].value
		var entry=v.match(word);
		
		if (!entry) {
			alert ("Please include the "+label+" before sending your registration.");
			document.form.elements[place].focus();
			return false
		}

		var quotes = /"/;
		var entry2=v.match(quotes);
		
		if (entry2) {
		alert("Please do not use double quotation in the entry: "+label+". \nIf necessary, use single quotation marks.");
			document.form.elements[place].focus();
			return false		

		}
	}
		
	if (document.form.state.value == 0) {
		alert ("Please enter your school's location and submit again.");
		document.form.state.focus();
		return false
	}
		
	var password=password_check("school");
		if (!password) {return false}

	var c = document.form.school_email.value;
	if (document.form.confirm_email.value != c) {
		alert ("School email and the confirmation email do not match.\nPlease try again by retyping both.");
		document.form.confirm_email.focus();
		return false
	}
	
	var full=0;
	for (i=0;i<myTEACHERInputs.length;i++) {
		
		var place=myTEACHERInputs[i][0];
		var label=myTEACHERInputs[i][1];
		var word=/\w+/;
		
		var v=document.form.elements[place].value
		var entry=v.match(word);
		
		var quotes = /"/;
		var entry2=v.match(quotes);
		
		if (entry2) {
		alert("Please do not use double quotation with "+label+". \nIf necessary, use single quotation marks.");
			document.form.elements[place].focus();
			return false	
		}	
		if (entry) {
			full++;
		}
	}
	if (full != 0 && full != myTEACHERInputs.length) {
		alert("If you are going to complete the optional teacher registration form, you must fill out all fields.");
			return false	
	}
	
	return true
}


function checkAddStudent(t,l) {
	var word=/\w+/;
	
	for (var x=0; x<l; x++) {
		var entry=document.forms['form'].elements[x];
		var result=entry.value.match(word);
		var n=entry.name;
		
		if (n=="confirm_email" || n=="confirm_password" || n=="ext") {
			continue
		}

		if (n== "state" && entry.value == 0) {
			alert ("Please enter your school\'s location and submit again.");
			return false
		}
		if (!result) {
			
			alert ("Please enter your "+labels[x]+" and submit again.");
			document.forms['form'].elements[n].focus();
			return false
		}
		
		
		
		
	}
	
}


function checkInfo(t,l) {
	var word=/\w+/;
	
	for (var x=0; x<l; x++) {
		var entry=document.forms['form'].elements[x];
		var result=entry.value.match(word);
		var n=entry.name;
		
		if (n=="confirm_email" || n=="confirm_password" || n=="ext") {
			continue
		}

		if (!result) {
			
			alert ("Please enter your "+labels[x]+" and submit again.");
			document.forms['form'].elements[n].focus();
			return false
		}
		
		
		
		
	}
	
	
	if (t=="school") {
		var p=document.form.school_password;
	}
	else {
		var p=document.form.password;
	}
	var c=document.form.confirm_password.value;
	
	if (p.length<5) {
	alert ("Your password should be at least 5 characters long. \nPlease re-enter it.");
		p.value="";
		document.form.confirm_password.value="";
		p.focus();
		return false
	}

	if (p.value != c) {
		alert ("Password and confirmation password do not match.\nPlease try again by retyping both.");
		p.value="";
		document.form.confirm_password.value="";
		p.focus();
		return false
	}
	


}

function checkTeachers() {
	
	
	var info=new Array('name',
			'email',
			'username',
			'password');
	
	var filled=0;
	var empty=new Array();
	var el=0;
		
	for (var j=0;j<info.length;j++) {
			var item=info[j];
			var word=/\w+/;
			
			var entry=document.forms['form'].elements[item].value;
		
			var result=entry.match(word);
			if (!result) {
				empty[el]=info[j];
				el++;
				
			}
			else {filled++;}
	
		}
		
	if (filled<info.length && filled != 0) {
		
		var needs=empty.join(", ");
	
		var message="You did not enter all of the required information about yourself.\n";	
		alert(message+"Please enter your "+needs+".");
		return false
		}	
	
		
		
		else {return true}
		

}
	


function checkStudents() {
	
	
	var info=new Array('last name',
			'first name',
			'username',
			'password');
	
	var names=new Array('last',
			'first',
			'student_username',
			'student_password');
		var usernames=new Array();
	for (i=0;i<25;i++) {
		var filled=0;
			var empty=new Array();
		
			var el=0;
			var error=0;
			var match=0;
			var k=i+1;
		for (j=0;j<info.length;j++) {
			
			var word=/\w+/;
			var item=names[j]+"["+i+"]";
			var formName="form";
			var entry=document.forms[formName].elements[item].value;
			var result=entry.match(word);
			if (j==2) {
				if (i==0) {usernames[i]=entry}
				else {
				
					for (m=0;m<usernames.length;m++) {
					if (result && entry==usernames[m]) {
						var notice="More than one of your students has the username: "+entry;
						var message="\nPlease make sure that all student usernames are unique.";
						alert(notice+message);
						return false
					}
					}
					usernames[i]=entry;
				}
			}

			
			if (!result) {
				empty[el]=info[j];
				el++;
				
			}
			else {filled++;}
	
		}

		

		if (filled<info.length && filled != 0) {
		
			var needs=empty.join("\n\t");
			error++;
			var message="You did not enter all of the required information about Student #"+k+".\n\n";	
			alert(message+"Please enter his/her: \n\t"+needs);
			return false
		}

		
	
	}	
	
	if (error==0 && match==0) {return true}
	else {return false}
		
		

}
		
