function chaddsearch(form) {
	return true;
}

function pickeddb(form) {
	var debtor = document.getElementById("dbpick").value;

	if (debtor == "" ) {
		alert("You need to pick a debtor");
		return false;
	} else {
		return true;
	}
}

function checkdbchsts(form) {
	var errstring = "";
	var ischecked = false;
	
	for (var i = 0; i < form.csts.length; i++) {	
		if (form.csts[i].checked) {
			ischecked = true;
			var valindex = i;
		}
	}	
		
	if (ischecked) {
		errstring = "The status passed is: " + form.csts[valindex].value;
		alert(errstring);
		return false;
	} else {
		alert("You need to pick a status");
		return false;
	}
}

function checkcontactus(form) {
	var email = document.getElementById('email').value;
	var comment = document.getElementById('comment').value;
	var x = document.forms[0].elements;
	var there_is_an_error = false; 
	var error_string = "You need to correct these: \n\n";
	var emailat = form.elements['email'].value.indexOf('@');
	var emailper = form.elements['email'].value.indexOf('.');

	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].value == "") {
			error_string = error_string + "Fill out all fields.\n";
			there_is_an_error = true;
			break;
		}
	}


	for (var i = 0; i < form.elements.length; i++) {
		if ((form.elements[i].type == "text")
				&& form.elements[i].value.length > 25 ) {
			error_string = error_string + form.elements[i].value + " -- is longer than 25 \n";
			there_is_an_error = true;
		}
	}

	/* Check to see if emails are in the right format */
	if (emailat < 1 ) {
		error_string = error_string + "Email does not have an @.\n";	
		there_is_an_error = true;
	}

	if (emailper < 1 ) {
		error_string = error_string + "Email does not have a period.\n";	
		there_is_an_error = true;
	}

	if(comment.length < 5) {
			error_string = error_string + "Comment is less than 5 characters.\n";
			there_is_an_error = true;
	}
	
	/* Check to see if yourissue is chosen. */
	if (form.yourissue.selectedIndex == 0) {
			error_string = error_string + "You need to pick a issue.\n";
			there_is_an_error = true;
	}
	
	if (there_is_an_error) {
		alert(error_string);
		return false;
	} else {
		return true;
	}
}

function checkforgot(form) {
	var email = document.getElementById("email").value;
	var answer = document.getElementById("answer").value;
	var x = document.forms[0].elements;
	var there_is_an_error = false; 
	var error_string = "You need to correct these: \n\n";
	var emailat = form.elements['email'].value.indexOf('@');
	var emailper = form.elements['email'].value.indexOf('.');

	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].value == "") {
			error_string = error_string + "Fill out all fields.\n";
			there_is_an_error = true;
			break;
		}
	}
	
	for (var i = 0; i < form.elements.length; i++) {
		if ((form.elements[i].type == "text") 
				&& form.elements[i].value.length > 25 ) {
			error_string = error_string + form.elements[i].value + " -- is longer than 25 \n";
			there_is_an_error = true;
		}
	}

	/* Check to see if emails are in the right format */
	if (emailat < 1 ) {
		error_string = error_string + "Email does not have an @.\n";	
		there_is_an_error = true;
	}

	if (emailper < 1 ) {
		error_string = error_string + "Email does not have a period.\n";	
		there_is_an_error = true;
	}
	
	if(answer.length < 5) {
			error_string = error_string + "Answer is less than 5 characters.\n";
			there_is_an_error = true;
	}
	
	/* Check to see if Question is chosen. */
	if (form.secretquestion.selectedIndex == 0) {
			error_string = error_string + "You need to pick a question.\n";
			there_is_an_error = true;
	}
	
	if (there_is_an_error) {
		alert(error_string);
		return false;
	} else {
		return true;
	}
}

function checklogin(form) {
	var email = document.getElementById("email").value;
	var password = document.getElementById("password").value;
	var x = document.forms[0].elements;
	var there_is_an_error = false; 
	var error_string = "You need to correct these: \n\n";
	var emailat = form.elements['email'].value.indexOf('@');
	var emailper = form.elements['email'].value.indexOf('.');

	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].value == "") {
			error_string = error_string + "Fill out all fields.\n";
			there_is_an_error = true;
			break;
		}
	}
	
	for (var i = 0; i < form.elements.length; i++) {
		if ((form.elements[i].type == "text" || form.elements[i].type == "password") 
				&& form.elements[i].value.length > 25 ) {
			error_string = error_string + form.elements[i].value + " -- is longer than 25 \n";
			there_is_an_error = true;
		}
	}

	/* Check to see if emails are in the right format */
	if (emailat < 1 ) {
		error_string = error_string + "Email does not have an @.\n";	
		there_is_an_error = true;
	}

	if (emailper < 1 ) {
		error_string = error_string + "Email does not have a period.\n";	
		there_is_an_error = true;
	}
	
	if(password.length < 5) {
			error_string = error_string + "Password is less than 5 characters.\n";
			there_is_an_error = true;
	}
	
	if (there_is_an_error) {
		alert(error_string);
		return false;
	} else {
		return true;
	}
}

function checkjoinus(form) {
	var email1 = document.getElementById("email1").value;
	var email2 = document.getElementById("email2").value;
	var password1 = document.getElementById("password1").value;
	var password2 = document.getElementById("password2").value;
	var x = document.forms[0].elements;
	var there_is_an_error = false; 
	var error_string = "You need to correct these: \n\n";
	var email1at = form.elements['email1'].value.indexOf('@');
	var email1per = form.elements['email1'].value.indexOf('.');
	var email2at = form.elements['email2'].value.indexOf('@');
	var email2per = form.elements['email2'].value.indexOf('.');

	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].value == "") {
			error_string = error_string + "Fill out all fields.\n";
			there_is_an_error = true;
			break;
		}
	}

	for (var i = 0; i < form.elements.length; i++) {
		if ((form.elements[i].type == "text" || form.elements[i].type == "password") 
				&& form.elements[i].value.length > 25 ) {
			error_string = error_string + form.elements[i].value + " -- is longer than 25 \n";
			there_is_an_error = true;
		}
	}

	/* Check to see if emails are in the right format */
	if (email1at < 1 ) {
		error_string = error_string + "Email does not have an @.\n";	
		there_is_an_error = true;
	}
	if (email1per < 1 ) {
		error_string = error_string + "Email does not have a period.\n";	
		there_is_an_error = true;
	}
	if (email2at < 1) {
		error_string = error_string + "Confirm Email does not have an @.\n";	
		there_is_an_error = true;
	}
	if (email2per < 1 ) {
		error_string = error_string + "Confirm Email does not have a period.\n";	
		there_is_an_error = true;
	}
	
	/* Check to see if emails match. */	
	if (email1 !== email2) {
			error_string = error_string + "The emails do not match.\n";
			there_is_an_error = true;
	}

	/* Check to see if passwords are long enough */
	if(password1.length < 5) {
			error_string = error_string + "Password is less than 5 characters.\n";
			there_is_an_error = true;
	}	
	if(password2.length < 5) {
			error_string = error_string + "Confirm Password is less than 5 characters.\n";
			there_is_an_error = true;
	}
	
	/* Check to see if passwords match. */
	if (password1 !== password2) {
			error_string = error_string + "The Passwords do not match.\n";
			there_is_an_error = true;
	}
	
	/* Check to see if Month is chosen. */
	if (form.DateOfBirth_Month.selectedIndex == 0) {
			error_string = error_string + "You need to pick a Month.\n";
			there_is_an_error = true;
	}
	
	/* Check to see if Day is chosen. */
	if (form.DateOfBirth_Day.selectedIndex == 0) {
			error_string = error_string + "You need to pick a Day.\n";
			there_is_an_error = true;
	}

	/* Check to see if Month is chosen. */
	if (form.DateOfBirth_Year.selectedIndex == 0) {
			error_string = error_string + "You need to pick a Year.\n";
			there_is_an_error = true;
	}
	
	/* Check to see if Question is chosen. */
	if (form.secretquestion.selectedIndex == 0) {
			error_string = error_string + "You need to pick a Question.\n";
			there_is_an_error = true;
	}

	if (there_is_an_error) {
		alert(error_string);
		return false;
	} else {
		return true;
	}
}
