var run_script = 1;

//alert("here at top of new_acqs.js");

function global_subject_selection_manager(mode)
{
	//alert("here is mode in global_subject_selection_manager: " + mode);
	
	var regex_foreign_law = /foreign_law_subjects/;	
	var regex_special_c  = /special_c_subjects/;
	var regex_other = /other_subjects/;
	
	// First switch off converse global selection within given subject area, or both select-all and clear-all options if user
	// has selected an individual subject
	if ((mode == "clear_all_foreign_law") || (mode =="foreign_law_not_global"))
	{
		document.getElementById("ID_foreign_law_select_all").checked = false;
	}
	if ((mode == "select_all_foreign_law") || (mode =="foreign_law_not_global"))
	{
		document.getElementById("ID_foreign_law_clear_all").checked = false;
	}
	
	/* 
	if ((mode == "clear_all_special_c") || (mode =="special_c_not_global"))
	{
		document.getElementById("ID_special_c_select_all").checked = false;
	}
	if ((mode == "select_all_special_c") || (mode =="special_c_not_global"))
	{
		document.getElementById("ID_special_c_clear_all").checked = false;
	}
	*/
	
	if ((mode == "clear_all_other") || (mode =="other_not_global"))
	{
		document.getElementById("ID_other_select_all").checked = false;
	}
	if ((mode == "select_all_other") || (mode =="other_not_global"))
	{
		document.getElementById("ID_other_clear_all").checked = false;
	}

	// Check if user has opted to select all subjects within a given subject area
	if (document.getElementById("ID_foreign_law_select_all").checked == true)
	{
		num_form_elements = document.landing_main_form.elements.length;
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.landing_main_form.elements[index].name;
			if (regex_foreign_law.test(current_element))
			{	
				document.landing_main_form.elements[index].checked = true;	
			}
		}
	}
	if (document.getElementById("ID_other_select_all").checked == true)
	{
		num_form_elements = document.landing_main_form.elements.length;
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.landing_main_form.elements[index].name;
			if (regex_other.test(current_element))
			{	
				document.landing_main_form.elements[index].checked = true;	
			}
		}
	}
	/*
	if (document.getElementById("ID_special_c_select_all").checked == true)
	{
		num_form_elements = document.landing_main_form.elements.length;
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.landing_main_form.elements[index].name;
			if (regex_special_c.test(current_element))
			{	
				document.landing_main_form.elements[index].checked = true;	
			}
		}
	}
	*/
	
	// Check if user has opted to clear all subjects within a given subject area
	if (document.getElementById("ID_foreign_law_clear_all").checked == true)
	{
		num_form_elements = document.landing_main_form.elements.length;
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.landing_main_form.elements[index].name;
			if (regex_foreign_law.test(current_element))
			{	
				document.landing_main_form.elements[index].checked = false;	
			}
		}
	}
	if (document.getElementById("ID_other_clear_all").checked == true)
	{
		num_form_elements = document.landing_main_form.elements.length;
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.landing_main_form.elements[index].name;
			if (regex_other.test(current_element))
			{	
				document.landing_main_form.elements[index].checked = false;	
			}
		}
	}
	/*
	if (document.getElementById("ID_special_c_clear_all").checked == true)
	{
		num_form_elements = document.landing_main_form.elements.length;
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.landing_main_form.elements[index].name;
			if (regex_special_c.test(current_element))
			{	
				document.landing_main_form.elements[index].checked = false;	
			}
		}
	}	
	*/
}

function global_bookcover_selection_manager(mode)
{
	//alert("here is mode in global_bookcover_selection_manager: " + mode);
	var num_form_elements = 0;
	var current_element = "";
	var regex_bookcover_selections = /bookcover_selections_.+\[\]/;
	
	// Check if user has opted to clear all bookcover selections
	if (document.getElementById("ID_bookcover_selections_clear_all").checked == true)
	{
		num_form_elements = document.bookcover_selections_form.elements.length;
		//alert("here is num_form_elements: " + num_form_elements);
		
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.bookcover_selections_form.elements[index].name;
			//alert("here is current_element: " + current_element);
			if (regex_bookcover_selections.test(current_element))
			{	
				document.bookcover_selections_form.elements[index].checked = false;	
			}
		}
	}	
}

function specific_bookcover_selection_manager(hollis_id, bookcover_tab)
{
	//alert("here inside specific_bookcover_selection_manager with hollis_id of " + hollis_id + " bookcover_tab of " + bookcover_tab);
	//alert("here inside specific_bookcover_selection_manager with hollis_id of " + hollis_id);
	var num_form_elements = 0;
	var current_element = "";
	var current_element_value = "";
	// Need to create RegExp object to allow variable-based content in regexp pattern
	var regex_bookcover_tab = new RegExp(bookcover_tab);
	var checked_status = false;
	
	num_form_elements = document.bookcover_selections_form.elements.length;
	//alert("here is num_form_elements: " + num_form_elements);
	
	// Find current checked status of this checkbox
	for (var index = 0; index < num_form_elements; index++)
	{
		current_element = document.bookcover_selections_form.elements[index].name;
		current_element_value = document.bookcover_selections_form.elements[index].value;
		//alert("here is current_element: " + current_element);
		if (regex_bookcover_tab.test(current_element))
		{	
			if (current_element_value == hollis_id)
			{
				checked_status = document.bookcover_selections_form.elements[index].checked;
				//alert("here is checked_status of this checkbox: " + checked_status);
			}
		}
	}
	// Synch up checked status of possible dup value in other tab area
	for (var index = 0; index < num_form_elements; index++)
	{
		current_element = document.bookcover_selections_form.elements[index].name;
		current_element_value = document.bookcover_selections_form.elements[index].value;
		//alert("here is current_element: " + current_element);
		if (!regex_bookcover_tab.test(current_element))
		{	
			if (current_element_value == hollis_id)
			{
				document.bookcover_selections_form.elements[index].checked = checked_status;
			}
		}
	}
	// If any checkbox in tabbed areas is set to on, verify that global clear is set to off
	for (var index = 0; index < num_form_elements; index++)
	{
		if (document.bookcover_selections_form.elements[index].checked == true)
		{
			document.getElementById("ID_bookcover_selections_clear_all").checked = false;
		}
	}
}

function setActiveTab(tabID, mode) 
{
	//alert("here inside setActiveTab");
	if (mode == "landing")
	{
		//alert("here is tab: " + tabID);
		/* Both class and className need to be set since IE uses the latter and Firefox the former (if I remember correctly) */
		if (tabID == "tab1")
		{
			document.getElementById("tab1").setAttribute("class", "activetab");
			document.getElementById("tab2").setAttribute("class", "inactivetab");
			document.getElementById("tab4").setAttribute("class", "inactivetab");
			document.getElementById("tab1").setAttribute("className", "activetab");
			document.getElementById("tab2").setAttribute("className", "inactivetab");
			document.getElementById("tab4").setAttribute("className", "inactivetab");
			document.getElementById("tab1").style.borderBottomWidth = "0px";
			document.getElementById("tab2").style.borderBottomWidth = "1px";
			document.getElementById("tab4").style.borderBottomWidth = "1px";
			document.getElementById("tab1_content").style.display = "block";
			document.getElementById("tab2_content").style.display = "none";
			document.getElementById("tab4_content").style.display = "none";
		}
		else if (tabID == "tab2")
		{
			document.getElementById("tab2").setAttribute("class", "activetab");
			document.getElementById("tab1").setAttribute("class", "inactivetab");
			document.getElementById("tab4").setAttribute("class", "inactivetab");
			document.getElementById("tab2").setAttribute("className", "activetab");
			document.getElementById("tab1").setAttribute("className", "inactivetab");
			document.getElementById("tab4").setAttribute("className", "inactivetab");
			document.getElementById("tab2").style.borderBottomWidth = "0px";
			document.getElementById("tab1").style.borderBottomWidth = "1px";
			document.getElementById("tab4").style.borderBottomWidth = "1px";
			document.getElementById("tab2_content").style.display = "block";
			document.getElementById("tab1_content").style.display = "none";
			document.getElementById("tab4_content").style.display = "none";
		}
		else if (tabID == "tab4")
		{
			document.getElementById("tab4").setAttribute("class", "activetab");
			document.getElementById("tab1").setAttribute("class", "inactivetab");
			document.getElementById("tab2").setAttribute("class", "inactivetab");
			document.getElementById("tab4").setAttribute("className", "activetab");
			document.getElementById("tab1").setAttribute("className", "inactivetab");
			document.getElementById("tab2").setAttribute("className", "inactivetab");
			document.getElementById("tab4").style.borderBottomWidth = "0px";
			document.getElementById("tab1").style.borderBottomWidth = "1px";
			document.getElementById("tab2").style.borderBottomWidth = "1px";
			document.getElementById("tab4_content").style.display = "block";
			document.getElementById("tab1_content").style.display = "none";
			document.getElementById("tab2_content").style.display = "none";
			//alert("here in tab4");
		}		
		document.getElementById("tab2").style.borderLeftWidth = "0px";
		document.getElementById("tab4").style.borderLeftWidth = "0px";
	}
	if (mode == "email_alert")
	{
		//alert("here is tab: " + tabID);
		/* Both class and className need to be set since IE uses the latter and Firefox the former (if I remember correctly) */
		if (tabID == "tab1")
		{
			document.getElementById("tab1").setAttribute("class", "activetab");
			document.getElementById("tab3").setAttribute("class", "inactivetab");
			document.getElementById("tab1").setAttribute("className", "activetab");
			document.getElementById("tab3").setAttribute("className", "inactivetab");
			document.getElementById("tab1").style.borderBottomWidth = "0px";
			document.getElementById("tab3").style.borderBottomWidth = "1px";
			document.getElementById("tab1_content").style.display = "block";
			document.getElementById("tab3_content").style.display = "none";
		}
		else if (tabID == "tab3")
		{
			document.getElementById("tab3").setAttribute("class", "activetab");
			document.getElementById("tab1").setAttribute("class", "inactivetab");
			document.getElementById("tab3").setAttribute("className", "activetab");
			document.getElementById("tab1").setAttribute("className", "inactivetab");
			document.getElementById("tab3").style.borderBottomWidth = "0px";
			document.getElementById("tab1").style.borderBottomWidth = "1px";
			document.getElementById("tab3_content").style.display = "block";
			document.getElementById("tab1_content").style.display = "none";
			//alert("here in tab3");
		}		
		document.getElementById("tab3").style.borderLeftWidth = "0px";
	}
	
	return;	
} 

function setActiveTab_bookcovers(tabID, mode) 
{
	if (mode == "landing")
	{
		//alert("here is tab: " + tabID);
		/* Both class and className need to be set since IE uses the latter and Firefox the former (if I remember correctly) */
		if (tabID == "tab1")
		{
			document.getElementById("tab1").setAttribute("class", "activetab");
			document.getElementById("tab2").setAttribute("class", "inactivetab");
			document.getElementById("tab3").setAttribute("class", "inactivetab");
			document.getElementById("tab4").setAttribute("class", "inactivetab");
			document.getElementById("tab1").setAttribute("className", "activetab");
			document.getElementById("tab2").setAttribute("className", "inactivetab");
			document.getElementById("tab3").setAttribute("className", "inactivetab");
			document.getElementById("tab4").setAttribute("className", "inactivetab");
			document.getElementById("tab1").style.borderBottomWidth = "0px";
			document.getElementById("tab2").style.borderBottomWidth = "1px";
			document.getElementById("tab3").style.borderBottomWidth = "1px";
			document.getElementById("tab4").style.borderBottomWidth = "1px";
			document.getElementById("tab1_content").style.display = "block";
			document.getElementById("tab2_content").style.display = "none";
			document.getElementById("tab3_content").style.display = "none";
			document.getElementById("tab4_content").style.display = "none";
		}
		else if (tabID == "tab2")
		{
			document.getElementById("tab2").setAttribute("class", "activetab");
			document.getElementById("tab1").setAttribute("class", "inactivetab");
			document.getElementById("tab3").setAttribute("class", "inactivetab");
			document.getElementById("tab4").setAttribute("class", "inactivetab");
			document.getElementById("tab2").setAttribute("className", "activetab");
			document.getElementById("tab1").setAttribute("className", "inactivetab");
			document.getElementById("tab3").setAttribute("className", "inactivetab");
			document.getElementById("tab4").setAttribute("className", "inactivetab");
			document.getElementById("tab2").style.borderBottomWidth = "0px";
			document.getElementById("tab1").style.borderBottomWidth = "1px";
			document.getElementById("tab3").style.borderBottomWidth = "1px";
			document.getElementById("tab4").style.borderBottomWidth = "1px";
			document.getElementById("tab2_content").style.display = "block";
			document.getElementById("tab1_content").style.display = "none";
			document.getElementById("tab3_content").style.display = "none";
			document.getElementById("tab4_content").style.display = "none";
		}
		else if (tabID == "tab3")
		{
			document.getElementById("tab3").setAttribute("class", "activetab");
			document.getElementById("tab1").setAttribute("class", "inactivetab");
			document.getElementById("tab2").setAttribute("class", "inactivetab");
			document.getElementById("tab4").setAttribute("class", "inactivetab");
			document.getElementById("tab3").setAttribute("className", "activetab");
			document.getElementById("tab1").setAttribute("className", "inactivetab");
			document.getElementById("tab2").setAttribute("className", "inactivetab");
			document.getElementById("tab4").setAttribute("className", "inactivetab");
			document.getElementById("tab3").style.borderBottomWidth = "0px";
			document.getElementById("tab1").style.borderBottomWidth = "1px";
			document.getElementById("tab2").style.borderBottomWidth = "1px";
			document.getElementById("tab4").style.borderBottomWidth = "1px";
			document.getElementById("tab3_content").style.display = "block";
			document.getElementById("tab1_content").style.display = "none";
			document.getElementById("tab2_content").style.display = "none";
			document.getElementById("tab4_content").style.display = "none";
			//alert("here in tab3");
		}
		else if (tabID == "tab4")
		{
			document.getElementById("tab4").setAttribute("class", "activetab");
			document.getElementById("tab1").setAttribute("class", "inactivetab");
			document.getElementById("tab2").setAttribute("class", "inactivetab");
			document.getElementById("tab3").setAttribute("class", "inactivetab");
			document.getElementById("tab4").setAttribute("className", "activetab");
			document.getElementById("tab1").setAttribute("className", "inactivetab");
			document.getElementById("tab2").setAttribute("className", "inactivetab");
			document.getElementById("tab3").setAttribute("className", "inactivetab");
			document.getElementById("tab4").style.borderBottomWidth = "0px";
			document.getElementById("tab1").style.borderBottomWidth = "1px";
			document.getElementById("tab2").style.borderBottomWidth = "1px";
			document.getElementById("tab3").style.borderBottomWidth = "1px";
			document.getElementById("tab4_content").style.display = "block";
			document.getElementById("tab1_content").style.display = "none";
			document.getElementById("tab2_content").style.display = "none";
			document.getElementById("tab3_content").style.display = "none";
			//alert("here in tab4");
		}		
		document.getElementById("tab2").style.borderLeftWidth = "0px";
		document.getElementById("tab3").style.borderLeftWidth = "0px";
		document.getElementById("tab4").style.borderLeftWidth = "0px";
	}
	
	return;	
} 

function javascript_alert_demo() {
	
	// ALERTS REQUIRE ONE ARGUMENT
	var message = "Remember to log out before exiting...";

	// ALERTS DO NOT RETURN A VALUE
	// ALERTS ARE INFORMATIONAL ONLY
	alert (message);
}

function validate_alert_email()
{

	//alert("here inside validate_alert_email ... ");
	
	var email_initial = "";
	var email_confirm = "";
	var regex_email_format = /@/;
	
	email_initial = document.getElementById("ID_email_initial").value;
	email_confirm = document.getElementById("ID_email_confirm").value;
	
	//alert("here is email_initial: [" + email_initial + "] and here is email_confirm: [" + email_confirm + "]");
	
	if (email_initial != email_confirm)
	{
		alert("Error -- the e-mail addresses you have entered do not match.  Please re-enter.\n");
		return false;
	}
	else if ((!email_initial) && (!email_confirm))
	{
		alert("Error -- you have not entered an e-mail address.\n");
		return false;		
	}
	else if (!regex_email_format.test(email_initial))
	{
		alert("Error -- the entered e-mail address is not properly formed.  Please re-enter.\n");
		return false;		
	}	
	return true;
}

function confirm_alert_unsubscribe()
{

	//alert("here inside validate_alert_email ... ");
	
	var email_initial = "";
	var email_confirm = "";
	var regex_email_format = /@/;
	
	email_initial = document.getElementById("ID_email_initial").value;
	email_confirm = document.getElementById("ID_email_confirm").value;
	
	//alert("here is email_initial: [" + email_initial + "] and here is email_confirm: [" + email_confirm + "]");
	
	if (email_initial != email_confirm)
	{
		alert("Error -- the e-mail addresses you have entered do not match.  Please re-enter.\n");
		return false;
	}
	else if ((!email_initial) && (!email_confirm))
	{
		alert("Error -- you have not entered an e-mail address.\n");
		return false;		
	}
	else if (!regex_email_format.test(email_initial))
	{
		alert("Error -- the entered e-mail address is not properly formed.  Please re-enter.\n");
		return false;		
	}	
	
	var answer = confirm("Please verify that you want to unscribe the following e-mail from the alert service: " + email_initial)
	if (answer)
	{
		alert("The following e-mail will now be unsubscribed from the alert service: " + email_initial)
	}
	else
	{
		return false;
	}
	return true;
}

function validate_alert_input()
{

	var selection_found = 0;
	var regex_subjects_display = /subjects_display/;
	
	num_form_elements = document.email_alert_form.elements.length;
	
	// Check to see if user has made any subject selections
	for (var index = 0; index < num_form_elements; index++)
	{
		current_element = document.email_alert_form.elements[index].name;
		current_element_value = document.email_alert_form.elements[index].value;
		current_element_test = "#####" + current_element + "=" + current_element_value + "#####";
		//alert("here is current_element_test: " + current_element_test);
		if (regex_subjects_display.test(current_element))
		{
			//alert("here in subjects_display check ...");
			if (document.email_alert_form.elements[index].checked == true)
			{
				//alert("selection found ... ");
				selection_found = 1;	
			}
		}
	}
	if (!selection_found)
	{
		alert("Error -- no subjects have been selected.  Please select at least one subject for which you want to receive an alert.\n");
		return false;
	}	
		
	return true;	
}

function validate_landing_page_input()
{	
	var current_element;
	var current_element_value;
	var num_form_elements;
	var null_search = 1;
	var regex_clear_all = /clear_all/;
	
	//alert("hello there");
	// If user selects full listing, uncheck all other options
	if (document.getElementById("ID_subjects_display_all").checked == true)
	{
		//document.getElementById("ID_subjects_display_all").checked = false;	
		num_form_elements = document.landing_main_form.elements.length;
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.landing_main_form.elements[index].name;
			current_element_value = document.landing_main_form.elements[index].value;	
			if ((document.landing_main_form.elements[index].checked == true) && (current_element_value != "Display_All_Subjects"))
			{
				//alert ("the following has been checked true: " + current_element_value);
				document.landing_main_form.elements[index].checked = false;	
			}
		}
	}
	else
	{
		num_form_elements = document.landing_main_form.elements.length;
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.landing_main_form.elements[index].name;
			current_element_value = document.landing_main_form.elements[index].value;	
			if ((document.landing_main_form.elements[index].checked == true) && (!regex_clear_all.test(current_element)))
			{
				null_search = 0;
			}
		}
		if (null_search == 1)
		{
			alert("Error -- you have not selected any subjects for retrieval.");
			return false;				
		}
	}
	return true;
}

Array.prototype.find = function(searchStr) {
  var returnArray = false;
  for (i=0; i<this.length; i++) {
    if (typeof(searchStr) == 'function') {
      if (searchStr.test(this[i])) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    } else {
      if (this[i]===searchStr) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    }
  }
  return returnArray;
}

function validate_bookcover_editor_input()
{	
	//alert("here inside validate_bookcover_editor_input");

	var current_element = "";
	var current_element_value = "";
	var null_search = 1;
	var bookcover_count = 0;
	var regex_bookcover_selections = /bookcover_selections_.+\[\]/;
	var hollis_ids_array = [];
	
	num_form_elements = document.bookcover_selections_form.elements.length;
	//alert("here is num_form_elements: " + num_form_elements);
	for (var index = 0; index < num_form_elements; index++)
	{
		current_element = document.bookcover_selections_form.elements[index].name;
		current_element_value = document.bookcover_selections_form.elements[index].value;
		if ((document.bookcover_selections_form.elements[index].checked == true) && regex_bookcover_selections.test(current_element))
		{
			//alert("here is current_element displaying checked status: " + current_element);
			//alert("here is current_element with value of: " + document.bookcover_selections_form.elements[index].value);
			bookcover_count++;
			null_search = 0;	
			
			// Do not allow duplicate Hollis IDs in array
			if (!hollis_ids_array.find(current_element_value))
			{
				hollis_ids_array.push(current_element_value);
			}
			
		}
		//alert("here is null_search: " + null_search);
	}
	//alert("here is length of hollis_ids_array: " + hollis_ids_array.length);
	if (null_search == 1)
	{
		alert("Error -- you have not made any book flipper selections.");
		return false;
	}	
	else if (hollis_ids_array.length < 4)
	{
		alert("Error -- you have made less than 4 selections.  You must select at least 4 bookcovers.");
		return false;		
	}	
	return true;
}

function validate_input()
{	
	/* Validates input on subject editor page */
	
	var num_form_elements = 0;
	var current_element = "";
	var current_element_value = "";
	var current_element_test = "";
	var regex_white_space = /^\s*$/;	
	
	var regex_subject_call_letter = /call_letter/;	
	var regex_subject_call_num_begin_or_end = /call_num/;	
	var regex_subject_call_num_begin = /begin/;	
	var regex_subject_call_num_end = /end/;	
	var regex_subject_subject = /subject/;	
	var regex_subject_class_system = /class_system/;	
	var regex_subject_group_assignment = /group_assignment/;	
	var regex_call_num_integer_check = /^[\d\.]*$/;	
	
	var regex_subject_class_system_options = /^(Moody|LC|Special\sC)$/;		
	var return_value = true;
	var subject_count = 0;
	var null_record = true;
	
	var regexp_var_name = /^(add|db).*?(\d+)/;
	var regexp_test = false;
	var regexp_matches = new Array();
	var matched_int = 0;
	var matched_prefix = "";
	var curr_matched_signature = "";
	var prev_matched_signature = "";
	var required_field_missing = false;
	var incorrect_class_system = false;
	var first_time = true;
	var call_num_count = 0;
	var call_num_invalid = false;
	var call_num_begin = 0;
	var call_num_end = 0;
	
	//alert("here is run_script: " + run_script);
	if (run_script == 0)
	{
		return_value = true;
		return return_value;
	}
	else
	{
		num_form_elements = document.main_form.elements.length;
		
		// Check for null  records => do not alert user since these will either be deleted (if a pre-existing record from db) or ignored (if in new subjects area) -- user
		// has been informed about meaning of null records in each area.  Deletion routine is hanlded in new_acqs_subject_editor.php
		for (var index = 0; index < num_form_elements; index++)
		{
			current_element = document.main_form.elements[index].name;
			current_element_value = document.main_form.elements[index].value;
			current_element_test = "#####" + current_element + "=" + current_element_value + "#####";
			//alert("here is current_element_test: " + current_element_test);
			
			// Test for constructed edit-box signature to allow record boundaries
			if(regexp_test = regexp_var_name.test(current_element))
			{
				regexp_matches = regexp_var_name.exec(current_element);
				matched_prefix = regexp_matches[1];
				matched_int = regexp_matches[2];
				curr_matched_signature = matched_prefix + "_" + matched_int;
				//alert("here is curr_matched signature: " + curr_matched_signature);
			}
			else
			{
				//alert("no signature match");	
				continue;
			}			
			//alert("here is curr_matched_signature and prev_matched_signature: [" + curr_matched_signature + "] -- [" + prev_matched_signature + "]");
			if ((curr_matched_signature != prev_matched_signature) && (!first_time))
			{
				subject_count++;
				//alert("current and prevous signatures do not match ... ");
				// Assume that all records are null till proven otherwise
				if (null_record)
				{
					// Don't generate any errors -- go to next record.	
					//alert("null record detected");
				}
				// Some content has been entered into the record -- generate alerts if user has input errors.
				else if (required_field_missing)
				{
					alert("Error -- incomplete data entry for record no. " + subject_count + ".\n\nEach subject entry requires the following values:\n1. call letter\n2. subject\n3. class system\n4. group assignment\n\nPlease enter required information and resubmit.\n ");
					return false;
				}
				else if 	(incorrect_class_system)	
				{
					alert("Error -- incorrect classification system designation entered for record no. " + subject_count + ".\n\nAcceptable classification-system values:\n1. Moody\n2. LC\n\nPlease enter required information and resubmit -- be sure to use proper case and verify that no extra white space has been added.\n ");
					return false;	
				}
				// call_num_count must be tripped twice (once for start and once for end) to indicate complete range -- acceptable values: 0 (for no call-number range) and 2
				else if 	(call_num_count == 1)
				{
					alert("Error -- incomplete call-number range entered for record no. " + subject_count + ".\n\nYou must enter values both for Call Number Start and Call Number End if you enter a value for either one of them.\n");
					return false;	
				}
				// Call number start and end must consist of integers
				else if 	(call_num_invalid)
				{
					alert("Error -- iinvalid call-number range value entered for record no. " + subject_count + ".\n\nCall Number Start and Call Number End can only consist of digits.\n");
					return false;	
				}
				// Call number range must be properly sequenced (smaller to larger)
				else if ((call_num_begin) && (call_num_end))
				{
					if (call_num_begin > call_num_end)
					{
						//alert("here is call_num_begin: " + call_num_begin + " and call_num_end: "  + call_num_end);
						alert("Error -- iinvalid call-number range sequence entered for record no. " + subject_count + ".\n\nCall Number Start must be smaller than Call Number End.\n");
						return false;	
					}
				}
				
				// Re-initialize error vars in preparation for processing of next record
				null_record = true;	
				required_field_missing = false;	
				incorrect_class_system = false;	
				call_num_invalid = false;
				call_num_count = 0;		
				call_num_begin = 0;
				call_num_end = 0;
			}
			 			
			// Check to see if any content has been entered into the record
			if (regex_subject_call_letter.test(current_element) || regex_subject_subject.test(current_element) || regex_subject_class_system.test(current_element) || regex_subject_group_assignment.test(current_element) || regex_subject_call_num_begin_or_end.test(current_element))
			{	
				// Check for only whitespace or  null values in all fields
				if (!((regex_white_space.test(current_element_value) || current_element_value == "")))
				{
					//alert("content detected");
					null_record = false;
				}
			}
			
			// Check for missing content in required fields
			if (regex_subject_call_letter.test(current_element) || regex_subject_subject.test(current_element) || regex_subject_class_system.test(current_element) || regex_subject_group_assignment.test(current_element))
			{	
				// Check for only whitespace or null values in required fields
				if (regex_white_space.test(current_element_value) || current_element_value == "")
				{
					//alert("required field missing content");
					required_field_missing = true;
				}
				else if (regex_subject_class_system.test(current_element) && (!regex_subject_class_system_options.test(current_element_value)))
				{
					//alert("incorrect class system entered");
					incorrect_class_system = true;
				}				
			}
			
			// Check for incomplete call-number range
			if (regex_subject_call_num_begin_or_end.test(current_element))
			{	
				// Check for only whitespace or null values in required fields
				if (!(regex_white_space.test(current_element_value) || current_element_value == ""))
				{
					call_num_count++;
				}
			}
			
			// Check for non-integer content in call number
			if (regex_subject_call_num_begin_or_end.test(current_element))
			{	
				if (!(regex_call_num_integer_check.test(current_element_value)))
				{
					call_num_invalid = true;
				}
			}
			
			// Check for proper call-number range sequencing (smaller to larger)
			if (regex_subject_call_num_begin_or_end.test(current_element))
			{	
				//alert("here is current_element: " + current_element + " and here is current_element_value: " + current_element_value);
				// Re-cast call-num values as integers
				if (regex_subject_call_num_begin.test(current_element))
				{
					//call_num_begin = parseInt(current_element_value);
					call_num_begin = parseFloat(current_element_value);
				}
				else if (regex_subject_call_num_end.test(current_element))
				{
					//call_num_end = parseInt(current_element_value);
					call_num_end = parseFloat(current_element_value);
				}
			}
			
			prev_matched_signature = curr_matched_signature;
			first_time = false;
		}
		
		// For-loop above terminates before fully processing last record -- must be completed here
		subject_count++;
		if (null_record)
		{
			// Don't generate any errors -- go to next record.
			//alert("null record detected");
		}
		// Some content has been entered into the record -- generate alerts if user has input errors.
		else if (required_field_missing)
		{
			alert("Error -- incomplete data entry for record no. " + subject_count + ".\n\nEach subject entry requires the following values:\n1. call letter\n2. subject\n3. class system\n4. group assignment\n\nPlease enter required information and resubmit.\n ");
			return false;
		}
		else if 	(incorrect_class_system)	
		{
			alert("Error -- incorrect classification system designation entered for record no. " + subject_count + ".\n\nAcceptable classification-system values:\n1. Moody\n2. LC\n\nPlease enter required information and resubmit -- be sure to use proper case and verify that no extra white space has been added.\n ");
			return false;	
		}
		// call_num_count must be tripped twice (once for start and once for end) to indicate complete range -- acceptable values: 0 (for no call-number range) and 2
		else if 	(call_num_count == 1)
		{
			alert("Error -- incomplete call-number range entered for record no. " + subject_count + ".\n\nYou must enter values both for Call Number Start and Call Number End if you enter a value for either one of them.\n");
			return false;	
		}
		// Call number start and end must consist of integers
		else if 	(call_num_invalid)
		{
			alert("Error -- iinvalid call-number range value entered for record no. " + subject_count + ".\n\nCall Number Start and Call Number End can only consist of digits.\n");
			return false;	
		}
		// Call number range must be properly sequenced (smaller to larger)
		else if ((call_num_begin) && (call_num_end))
		{
			if (call_num_begin > call_num_end)
			{
				//alert("here is call_num_begin: " + call_num_begin + " and call_num_end: "  + call_num_end);
				alert("Error -- iinvalid call-number range sequence entered for record no. " + subject_count + ".\n\nCall Number Start must be smaller than Call Number End.\n");
				return false;	
			}
		}
	}
	return true;
}

// This is needed to keep add new subjects button from executing body of validate_input() --
// which should only be executed by main form's submit button
function set_run_script(signal)
{				
	//alert("setting run_script global");
	run_script = signal;
}

function scroll_pos_url_params()
{
	
	//alert("here in scroll_pos_url");
	
	set_run_script(0);

	var regex_delete_prev_params = /\?.*$/;	
	var regex_delete_initial_amp = /\?&/;	
	var regex_complete_param = /#####[^#=]+=[^#]+#####/;
	
	if (self.pageYoffset) // Netscape
	{
		//alert("here inside Netscape scroll pos detection");
		position = self.pageYoffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) // IE 6 and up
	{
		position = document.documentElement.scrollTop;
	}
	else if (document.body) // IE 5.5
	{
		position = document.body.scrollTop;	
	}
	
	//alert("here is position: " + position);
	// Strip possible previous params
	href_string = window.location.href;
	//alert("here is href_string before stripping of params: " + href_string); 					
	var param_list = "?";
	num_form_elements = document.main_form.elements.length;
	for (var index = 0; index < num_form_elements; index++)
	{
		current_element = document.main_form.elements[index].name;
		current_element_value = document.main_form.elements[index].value;
		current_full_param_test = "#####" + current_element + "=" + current_element_value + "#####";
		if (!(regex_complete_param.test(current_full_param_test)))
		{
			//alert("here is failed current_full_param_test: " + current_full_param_test);
			continue;
		}
		else
		{
			//alert("here is passed current_full_param_test: " + current_full_param_test);		
			param_list += "&" + current_element + "=" + current_element_value;
		}
	}
	
	//alert("here is initial param_list: " + param_list);								

	param_list = param_list.replace(regex_delete_initial_amp, "?");	
	//alert("here is param_list: " + param_list);								
 	href_string = href_string.replace(regex_delete_prev_params, "");
 	 	
 	//alert("here is href_string after stripping of params: " + href_string);
 	href_string = href_string + param_list;
 	alert("here is href_string after adding param_list: " + href_string); 					
 	window.location.href = href_string + "&position=" + position;
 	//window.location.href = href_string;
 	//alert("here is window.location.href after adding position param: " + window.location.href);
 	alert("hello");
}

// This is the implementation of SimpleSwap
// by Jehiah Czebotar
// Version 1.1 - June 10, 2005
// Distributed under Creative Commons
//
// Include this script on your page
// then make image rollovers simple like:
// <img src="/images/ss_img.gif" oversrc="/images/ss_img_over.gif">
//
// http://jehiah.com/archive/simple-swap
// 

function SimpleSwap(el,which){
  el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}

var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}
