function trim(s) { return s.replace(/^\s+/,"").replace(/\s+$/,""); }

function checkArticleInput(f)
{
	var errors = Array();
	if (trim(f.LastName.value) == "") { errors[errors.length] = "Last Name"; }
	if (trim(f.FirstName.value) == "") { errors[errors.length] = "First Name"; }
	if (trim(f.BCIDBarcodeNumber.value) == "") { errors[errors.length] = "BC ID Barcode Number"; }
	if (trim(f.Department.value) == "") { errors[errors.length] = "Department"; }

	// Status
	var checked=false;
	for (var i=0; i<f.Status.length; i++) {
		if (f.Status[i].checked) {
			checked=true;
			if (f.Status[i].value == "Other") {
				if (trim(f.OtherStatus.value) == "") {
					errors[errors.length] = "Status (Other)";
				}
			}
		}
	}
	if (!checked) {
		errors[errors.length] = "Status";
	}

	// Contact
	if (trim(f.Email.value) == "" && trim(f.HomePhone.value) == "" && trim(f.BCOfficeExtension.value) == "" && trim(f.FaxNumber.value) == "") {
		errors[errors.length] = "At least one contact method must be specified";
	}

	if (trim(f.JournalTitle.value) == "") { errors[errors.length] = "Journal Title"; }
	if (trim(f.ArticleTitle.value) == "") { errors[errors.length] = "Article Title"; }
	if (trim(f.ArticleAuthor.value) == "") { errors[errors.length] = "Article Author"; }
	if (trim(f.YearofPublication.value) == "") { errors[errors.length] = "Year of Publication"; }
	if (trim(f.Volume.value) == "") { errors[errors.length] = "Volume"; }
	if (trim(f.Issue.value) == "") { errors[errors.length] = "Issue"; }
	if (trim(f.Pages.value) == "") { errors[errors.length] = "Pages"; }
		
	if (errors.length) {
		var msg = "The following required information is missing:\n";
		for (var i=0; i < errors.length; i++) {
			msg += "- "+errors[i]+"\n";
		}
		msg += "\nNote: You may type a \"?\" if you are not sure of the information.";
		alert(msg);
		return false;
	}
	return true;
}

function checkBookInput(f)
{
	var errors = Array();
	
	if (!f.CopiesAtCuny[0].checked && !f.CopiesAtCuny[1].checked) { errors[errors.length] = "Copies at CUNY"; }

	if (trim(f.LastName.value) == "") { errors[errors.length] = "Last Name"; }
	if (trim(f.FirstName.value) == "") { errors[errors.length] = "First Name"; }
	if (trim(f.BCIDBarcodeNumber.value) == "") { errors[errors.length] = "BC ID Barcode Number"; }
	if (trim(f.Department.value) == "") { errors[errors.length] = "Department"; }

	// Status
	var checked=false;
	for (var i=0; i<f.Status.length; i++) {
		if (f.Status[i].checked) {
			checked=true;
			if (f.Status[i].value == "Other") {
				if (trim(f.OtherStatus.value) == "") {
					errors[errors.length] = "Status (Other)";
				}
			}
		}
	}
	if (!checked) {
		errors[errors.length] = "Status";
	}

	// Contact
	if (trim(f.Email.value) == "" && trim(f.HomePhone.value) == "" && trim(f.BCOfficeExtension.value) == "" && trim(f.FaxNumber.value) == "") {
		errors[errors.length] = "At least one contact method must be specified";
	}

	if (trim(f.Author.value) == "") { errors[errors.length] = "Author"; }
	if (trim(f.Title.value) == "") { errors[errors.length] = "Title"; }
	if (trim(f.Publisher.value) == "") { errors[errors.length] = "Publisher"; }
	if (trim(f.PublicationDate.value) == "") { errors[errors.length] = "Date of Publication"; }
	
	if (errors.length) {
		var msg = "The following required information is missing:\n";
		for (var i=0; i < errors.length; i++) {
			msg += "- "+errors[i]+"\n";
		}
		msg += "\nNote: You may type a \"?\" if you are not sure of the information.";
		alert(msg);
		return false;
	}
	return true;
}
