﻿//Clears the selected property of all items in the specified listbox.
function ListBoxClearSelection(listBoxId)
{
	var listBox = document.getElementById(listBoxId);
	for (var optionIndex = 0; optionIndex < listBox.options.length; optionIndex++)
	{
		listBox.options[optionIndex].selected = false;
	}
}

//Copies the items from the source to the destination listboxes.
function ListBoxCopySelectedItems(sourceListBoxId, destinationListBoxId)
{
	var sourceListBox = document.getElementById(sourceListBoxId);
	var destinationListBox = document.getElementById(destinationListBoxId);
	for (var optionIndex = 0; optionIndex < sourceListBox.options.length; optionIndex++)
	{
		if (sourceListBox.options[optionIndex].selected)
		{
			if (!ListBoxValueExists(destinationListBox, sourceListBox.options[optionIndex].value))
			{
				var option = document.createElement("option");
				option.text = sourceListBox.options[optionIndex].text;
				option.value = sourceListBox.options[optionIndex].value;
				destinationListBox.options.add(option);
			}
		}
	}
}

//Copies the values and descriptions of the specified listbox as a newline seperated list to the specified input.
function ListBoxCopyValuesToHiddenInput(listBoxId, hiddenInputId)
{
	var listBox = document.getElementById(listBoxId);
	var hiddenInput = document.getElementById(hiddenInputId);
	var optionValues = new Array();
	optionValues.length = listBox.options.length;
	for (var i = 0; i < listBox.options.length; i++)
	{
		optionValues[i] = new Object();
		optionValues[i].Key = listBox.options[i].value;
		optionValues[i].Value = listBox.options[i].text;
	}

	//	var selectedOptions = "";
	//	for (var optionIndex = 0; optionIndex < listBox.options.length; optionIndex ++) {
	//	    if (optionIndex != 0) {
	//	        selectedOptions += "\r\n";
	//	    }
	//	    selectedOptions += listBox.options[optionIndex].value + "\r\n" + listBox.options[optionIndex].text;
	//	}
	hiddenInput.value = JSON.stringify(optionValues);
}

//Sets the value of the first child in the specified span to the number of selected items in the specified listbox.
function ListBoxDisplayItemCount(listBoxId, spanId)
{
	var span = document.getElementById(spanId);
	span.firstChild.data = ListBoxGetSelectedItemCount(listBoxId);
}

//Prepends the listbox items' values to the text if displayValues = true, or removes it from text if false.
function ListBoxDisplayValues(listBoxId, displayValues)
{
	var listBox = document.getElementById(listBoxId);
	for (var optionIndex = 0; optionIndex < listBox.options.length; optionIndex++)
	{
		var option = listBox.options[optionIndex];
		var selected = option.selected;
		var hyphenIndex = option.text.indexOf(" - ");
		if (displayValues)
		{
			if (hyphenIndex == -1)
			{
				option.text = option.value + " - " + option.text;
			}
		}
		else
		{
			if (hyphenIndex > -1)
			{
				option.text = option.text.substr(hyphenIndex + 3);
			}
		}
		option.selected = selected;
	}
}

//Get the number of options in the specified listbox.
function ListBoxGetSelectedItemCount(listBoxId)
{
	var listBox = document.getElementById(listBoxId);
	return listBox.options.length;
}

//Remove items from the specified listbox if they are selected.
function ListBoxRemoveSelectedItems(listBoxId)
{
	var listBox = document.getElementById(listBoxId);
	for (var optionIndex = listBox.options.length - 1; optionIndex >= 0; optionIndex--)
	{
		if (listBox.options[optionIndex].selected)
		{
			listBox.remove(optionIndex);
		}
	}
}

//Select all items in the specified listbox.
function ListBoxSelectAll(listBoxId)
{
	var listBox = document.getElementById(listBoxId);
	for (var optionIndex = 0; optionIndex < listBox.options.length; optionIndex++)
	{
		listBox.options[optionIndex].selected = true;
	}
}

//Select all items in the specified listbox using the provided search text.
function ListBoxSelectByText(listBoxId, searchText, startingWith)
{
	searchText = searchText.replace(/\(/i, "\\(");
	searchText = searchText.replace(/\)/i, "\\)");
	searchText = searchText.replace(/\./i, "\\.");
	searchText = searchText.replace(/\+/i, "\\+");
	searchText = searchText.replace(/\?/i, "\\?");

	var listBox = document.getElementById(listBoxId);
	for (var optionIndex = 0; optionIndex < listBox.options.length; optionIndex++)
	{
		var compareText;
		if (startingWith)
		{
			compareText = listBox.options[optionIndex].text.substr(0, searchText.length);
		}
		else
		{
			compareText = listBox.options[optionIndex].text;
		}

		var regularExpression = RegExp(searchText, "gi");
		if (compareText.search(regularExpression) > -1)
		{
			listBox.options[optionIndex].selected = true;
		}
	}
}

//Return true if the listbox contains an item with a value matching the specified value.
function ListBoxValueExists(listBox, optionValue)
{
	for (var optionIndex = 0; optionIndex < listBox.options.length; optionIndex++)
	{
		var option = listBox.options[optionIndex];
		if (option.value == optionValue)
		{
			return true;
		}
	}
	return false;
}

//Add countries from selection to selected listbox.
function OnCountryAdd()
{
	ListBoxCopySelectedItems(countryListBoxId, selectedCountriesListBoxId);
	ListBoxCopyValuesToHiddenInput(selectedCountriesListBoxId, selectedCountriesHiddenInputId);
	ListBoxDisplayItemCount(selectedCountriesListBoxId, "countryCurrentLabel");
	UpdateSelectedCount();
}

//Remove countries from selected listbox.
function OnCountryRemove()
{
	ListBoxRemoveSelectedItems(selectedCountriesListBoxId);
	ListBoxCopyValuesToHiddenInput(selectedCountriesListBoxId, selectedCountriesHiddenInputId);
	ListBoxDisplayItemCount(selectedCountriesListBoxId, "countryCurrentLabel");
	UpdateSelectedCount();
}

//Perform search on country listbox.
function OnCountrySearch()
{
	var countrySearchTextValue = document.getElementById("countrySearchText").value;
	var countrySearchTextBeginChecked = document.getElementById("countrySearchTextBegin").checked;
	if (ValidateSearchTerms("countrySearchText"))
		ListBoxSelectByText(countryListBoxId, countrySearchTextValue, countrySearchTextBeginChecked);
}

//Add groups from selection to selected listbox.
function OnGroupAdd()
{
	ListBoxCopySelectedItems(groupListBoxId, selectedCountriesListBoxId);
	ListBoxCopyValuesToHiddenInput(selectedCountriesListBoxId, selectedCountriesHiddenInputId);
	ListBoxDisplayItemCount(selectedCountriesListBoxId, "countryCurrentLabel");
	UpdateSelectedCount();
}

//Perform search on groups listbox.
function OnGroupSearch()
{
	var groupSearchTextValue = document.getElementById("groupSearchText").value;
	var groupSearchTextBeginChecked = document.getElementById("groupSearchTextBegin").checked;
	if (ValidateSearchTerms("groupSearchText"))
		ListBoxSelectByText(groupListBoxId, groupSearchTextValue, groupSearchTextBeginChecked);
}

//Add HSCodes from Codes tree to selected listbox.
function OnHSCodeAdd(maximumHSCodeCount)
{
	if (TreeViewValidateHSCodeCount(hsCodeTreeViewId, selectedHSCodesListBoxId, maximumHSCodeCount))
	{
		TreeViewCopySelectedItems(hsCodeTreeViewId, selectedHSCodesListBoxId)
		ListBoxCopyValuesToHiddenInput(selectedHSCodesListBoxId, selectedHSCodesHiddenInputId);
		ListBoxDisplayItemCount(selectedHSCodesListBoxId, "hsCodeCurrentLabel");
		UpdateSelectedCount();
	}
}

//Remove HSCodes from selected listbox.
function OnHSCodeRemove()
{
	ListBoxRemoveSelectedItems(selectedHSCodesListBoxId);
	ListBoxCopyValuesToHiddenInput(selectedHSCodesListBoxId, selectedHSCodesHiddenInputId);
	ListBoxDisplayItemCount(selectedHSCodesListBoxId, "hsCodeCurrentLabel");
	UpdateSelectedCount();
}

//Perform search callback for HSCodes.
function OnHSCodeSearch()
{
	var hsCodeSearchTextValue = document.getElementById("hsCodeSearchText").value;
	var hsCodeSearchTextValue = hsCodeSearchTextValue.replace(/[^a-z0-9*+ ]/gi, "");
	var hsCodeSearchCodeOnlyChecked = document.getElementById("hsCodeSearchCodeOnly").checked;
	if (ValidateSearchTerms("hsCodeSearchText"))
	{
		SearchResultsShowMessage("Loading, please wait...");
		CallServer(hsCodeSearchTextValue + "," + hsCodeSearchCodeOnlyChecked, hsCodeSearchTextValue);
	}
}

//Add items from HSCodes search result to selected listbox.
function OnSearchResultAdd(maximumHSCodeCount)
{
	if (SearchResultsValidateHSCodeCount("searchResults", selectedHSCodesListBoxId, maximumHSCodeCount))
	{
		SearchResultsCopySelectedItems("searchResults", selectedHSCodesListBoxId);
		ListBoxCopyValuesToHiddenInput(selectedHSCodesListBoxId, selectedHSCodesHiddenInputId);
		ListBoxDisplayItemCount(selectedHSCodesListBoxId, "hsCodeCurrentLabel");
		UpdateSelectedCount();
	}
}

//select all the search results.
function OnSearchResultSelectAll()
{
	var outerDiv = document.getElementById("searchResults");
	var innerDivs = outerDiv.getElementsByTagName("div");
	for (var divIndex = 0; divIndex < innerDivs.length; divIndex++)
	{
		var inputs = innerDivs[divIndex].getElementsByTagName("input");
		for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)
		{
			if (inputs[inputIndex].type == "checkbox")
			{
				inputs[inputIndex].checked = true;
			}
		}
	}
}

//Clear the HSCode searchresult checkboxes.
function OnSearchResultClearSelection()
{
	var outerDiv = document.getElementById("searchResults");
	var innerDivs = outerDiv.getElementsByTagName("div");
	for (var divIndex = 0; divIndex < innerDivs.length; divIndex++)
	{
		var inputs = innerDivs[divIndex].getElementsByTagName("input");
		for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)
		{
			if (inputs[inputIndex].type == "checkbox")
			{
				inputs[inputIndex].checked = false;
			}
		}
	}
}

//If showcodes = true, prepends the values to the text of country and group textboxes
//otherwise, remove the value from the beginning of the text.
function OnShowCodes(showCodes)
{
	ListBoxDisplayValues(countryListBoxId, showCodes);
	ListBoxDisplayValues(groupListBoxId, showCodes);
	ListBoxDisplayValues(selectedCountriesListBoxId, showCodes);
	document.getElementById('showCodesCheckBox').checked = showCodes;
	document.getElementById('showCodesCheckBoxGroups').checked = showCodes;
}

//Check that at least one value is selected for each variable.
function OnValidate()
{
	var selectedCountriesListBoxElement = document.getElementById(selectedCountriesListBoxId);
	var selectedHSCodesListBoxElement = document.getElementById(selectedHSCodesListBoxId);
	var observationsCount = GetObservationsCount();
	var countriesCount = selectedCountriesListBoxElement.options.length;
	var hsCodesCount = selectedHSCodesListBoxElement.options.length;

	var errorMessage = "Please select at least one value for the following variables: \n\r";
	var hasError = false;

	if (observationsCount == 0)
	{
		errorMessage += "    -Observations\n\r"
		hasError = true;
	}

	//  if no countries or hs codes are selected, their corresponding totals will be selected and the boxes disabled.
	//	if (countriesCount == 0){
	//	    errorMessage += "    -Countries\n\r";
	//	    hasError = true;
	//	}

	//	if (hsCodesCount == 0) {
	//	    errorMessage += "    -HS codes\n\r";
	//	    hasError = true;
	//	}
	if (countriesCount == 0)
		countriesCount = 1;
	if (hsCodesCount == 0)
		hsCodesCount = 1;

	if (hasError)
		alert(errorMessage);
	else
	{
		var selectedCount = observationsCount * countriesCount * hsCodesCount;
		if (selectedCount > downloadMaximum)
		{
			alert("You have selected more data than can be processed. Please reduce your selection.");
			hasError = true;
		}
		else if (selectedCount > displayMaximum)
			return confirm("You have selected more data than can be displayed. You will only be able to download this data. Would you like to continue?");
	}

	return !hasError;
}

//Callback function to handle data received from searcher after performing search.
function ReceiveServerData(arg, context)
{
	var outerDiv = document.getElementById("searchResults");
	while (outerDiv.hasChildNodes())
	{
		outerDiv.removeChild(outerDiv.lastChild);
	}

	var searchResults = JSON.parse(arg);
	if (searchResults.length > 0)
	{
		for (var index = 0; index < searchResults.length; index++)
		{
			var hsCodeDescription = searchResults[index].Key + " " + searchResults[index].Value;

			var innerDiv = document.createElement("div");
			innerDiv.className = "searchResult";

			var checkBox = document.createElement("input");
			checkBox.id = "hsCodeCheckBox" + index;
			checkBox.name = "hsCodeCheckBox" + index;
			checkBox.type = "checkbox";
			checkBox.value = searchResults[index].Key;
			checkBox.title = hsCodeDescription;

			var span = document.createElement("label");
			//span.id = "hsCodeSpan" + index;
			span.title = hsCodeDescription;
			span.htmlFor = checkBox.id;
			//			if (span.addEventListener)
			//			    span.addEventListener("click", RepopulatePage, false);
			//			else
			//			    span.attachEvent("onclick", RepopulatePage);

			var spanText = document.createTextNode(hsCodeDescription);

			span.appendChild(spanText);
			innerDiv.appendChild(checkBox);
			innerDiv.appendChild(span);
			outerDiv.appendChild(innerDiv);
		}
	}
	else
	{
		SearchResultsShowMessage("No search results found for: " + context);
	}
}

//Add any selected items from HSCodes search results to the selected items listbox.
function SearchResultsCopySelectedItems(sourceSearchResultsId, destinationListBoxId)
{
	var listBox = document.getElementById(destinationListBoxId);
	var outerDiv = document.getElementById(sourceSearchResultsId);
	var innerDivs = outerDiv.getElementsByTagName("div");
	for (var divIndex = 0; divIndex < innerDivs.length; divIndex++)
	{
		var inputs = innerDivs[divIndex].getElementsByTagName("input");
		for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)
		{
			if (inputs[inputIndex].type == "checkbox")
			{
				if (inputs[inputIndex].checked)
				{
					var span = inputs[inputIndex].nextSibling;
					if (!ListBoxValueExists(listBox, inputs[inputIndex].value))
					{
						var option = document.createElement("option");
						option.text = span.firstChild.data;
						option.value = inputs[inputIndex].value;
						option.setAttribute("title", span.firstChild.data);
						listBox.options.add(option);
					}
				}
			}
		}
	}
}

//Show a message in the SearchResults container.
function SearchResultsShowMessage(message)
{
	var outerDiv = document.getElementById("searchResults");
	while (outerDiv.hasChildNodes())
	{
		outerDiv.removeChild(outerDiv.lastChild);
	}

	var innerDiv = document.createElement("div");
	innerDiv.id = "searchResultsMessage";

	var span = document.createElement("span");
	var spanText = document.createTextNode(message);

	span.appendChild(spanText);
	innerDiv.appendChild(span);
	outerDiv.appendChild(innerDiv);
}

//Unselect all selected items in the treeview.
function TreeViewClearSelection(treeViewId)
{
	var treeView = document.getElementById(treeViewId);
	var tables = treeView.getElementsByTagName("table");
	for (var tableIndex = 0; tableIndex < tables.length; tableIndex++)
	{
		var inputs = tables[tableIndex].getElementsByTagName("input");
		for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)
		{
			if (inputs[inputIndex].type == "checkbox")
			{
				inputs[inputIndex].checked = false;
			}
		}
	}
}

//Add all items selected in the HSCodes treeview to the selected items listbox.
function TreeViewCopySelectedItems(sourceTreeViewId, destinationListBoxId)
{
	var sourceTreeView = document.getElementById(sourceTreeViewId);
	var destinationListBox = document.getElementById(destinationListBoxId);
	var tables = sourceTreeView.getElementsByTagName("table");
	for (var tableIndex = 0; tableIndex < tables.length; tableIndex++)
	{
		var inputs = tables[tableIndex].getElementsByTagName("input");
		for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)
		{
			if (inputs[inputIndex].type == "checkbox")
			{
				if (inputs[inputIndex].checked)
				{
					var span = inputs[inputIndex].nextSibling;
					var hidden = span.nextSibling;
					if (!ListBoxValueExists(destinationListBox, hidden.value))
					{
						var option = document.createElement("option");
						option.text = span.firstChild.data;
						option.value = hidden.value;
						option.setAttribute("title", span.firstChild.data);
						destinationListBox.options.add(option);
					}
				}
			}
		}
	}
}

//Get the number of selected applicable observations.
function GetObservationsCount()
{
	var observationCount = 0;
	if (!document.getElementById(ObservationCClientID).disabled &&
			document.getElementById(ObservationCClientID).checked)
		observationCount++;
	if (!document.getElementById(ObservationQClientID).disabled &&
			document.getElementById(ObservationQClientID).checked)
		observationCount++;
	if (!document.getElementById(ObservationVClientID).disabled &&
			document.getElementById(ObservationVClientID).checked)
		observationCount++;
	if (!document.getElementById(ObservationFClientID).disabled &&
			document.getElementById(ObservationFClientID).checked)
		observationCount++;
	return observationCount;
}

//Update the value of the textbox displaying the amount of selected rows.
function UpdateSelectedCount()
{
	var selectedCountryCount = ListBoxGetSelectedItemCount(selectedCountriesListBoxId);
	var selectedHSCodeCount = ListBoxGetSelectedItemCount(selectedHSCodesListBoxId);
	var selectedObservationsCount = GetObservationsCount();

	var rowTotal;

	//removed the substitution of zero values with one, as all the fields are mandatory.
	rowTotal = selectedCountryCount * selectedHSCodeCount * selectedObservationsCount;

	var selectedCountElement = document.getElementById("selectedCount");

	selectedCountElement.value = rowTotal;
}

//Validate the input for performing a search.
function ValidateSearchTerms(textBoxId)
{
	var textBox = document.getElementById(textBoxId);
	if (textBox.value.length < 1)
	{
		alert("You have entered no search text, please enter some text and search again.");
		textBox.focus();
		return false;
	}
	else
	{
		return true;
	}
}

//Capture the keypress and perform the provided function if it is enter.
function CheckKey(searchFunction, evnt)
{
	var e = evnt || window.event;
	if (e.keyCode == 13)
	{
		e.cancelBubble = true;
		e.returnValue = false;
		if (e.preventDefault)
			e.preventDefault();
		eval(searchFunction);
	}
	return false;
}

//Enable or disable the observation checkboxes based on the datatype selectd.
function SetObservationCheckboxes()
{
	if (document.getElementById(TIMClientID).checked)
		SetObservationsEnabled(false, false, false, true);
	else if (document.getElementById(TEXClientID).checked)
		SetObservationsEnabled(true, false, true, false);
	else if (document.getElementById(TRXClientID).checked)
		SetObservationsEnabled(true, false, true, false);
	else if (document.getElementById(TERClientID).checked)
		SetObservationsEnabled(true, false, true, false);
	else DoClick(document.getElementById(TIMClientID));
	UpdateSelectedCount();
}

function RepopulateCountries()
{
	var selectedCountriesText = document.getElementById(selectedCountriesHiddenInputId).value;
	if (selectedCountriesText == "")
		return;
	var selectedCountriesDictionary = JSON.parse(selectedCountriesText);
	var selectedCountryListBox = document.getElementById(selectedCountriesListBoxId);
	for (var i in selectedCountriesDictionary)
	{
		var option = document.createElement("option");
		option.text = selectedCountriesDictionary[i].Value;
		option.value = selectedCountriesDictionary[i].Key;
		selectedCountryListBox.options.add(option);
	}
	ListBoxCopyValuesToHiddenInput(selectedCountriesListBoxId, selectedCountriesHiddenInputId);
	ListBoxDisplayItemCount(selectedCountriesListBoxId, "countryCurrentLabel");
}

function RepopulateHSCodes()
{
	var selectedHSCodesText = document.getElementById(selectedHSCodesHiddenInputId).value;
	if (selectedHSCodesText == "")
		return;
	var selectedHSCodesDictionary = JSON.parse(selectedHSCodesText);
	var selectedHSCodesListBox = document.getElementById(selectedHSCodesListBoxId);
	for (var i in selectedHSCodesDictionary)
	{
		var option = document.createElement("option");
		option.text = selectedHSCodesDictionary[i].Value;
		option.value = selectedHSCodesDictionary[i].Key;
		selectedHSCodesListBox.options.add(option);
	}
	ListBoxCopyValuesToHiddenInput(selectedHSCodesListBoxId, selectedHSCodesHiddenInputId);
	ListBoxDisplayItemCount(selectedHSCodesListBoxId, "hsCodeCurrentLabel");
}

//Disable the observations checkboxes as specified.
function SetObservationsEnabled(disableC, disableQ, disableV, disableF)
{
	document.getElementById(ObservationCClientID).disabled = disableC;
	document.getElementById(ObservationQClientID).disabled = disableQ;
	document.getElementById(ObservationVClientID).disabled = disableV;
	document.getElementById(ObservationFClientID).disabled = disableF;
}

//Reload the values in the page from the hidden inputs.
function RepopulatePage()
{
	RepopulateCountries();
	RepopulateHSCodes();
	SetObservationCheckboxes();
	OnShowCodes(document.getElementById('showCodesCheckBox').checked);
}

//Setup eventhandlers to fire on the load event to enable observation checkboxes. This is neccesary because the value of
//the datatype radiobuttons are preserved, but not the enabled attribute of the observation checkboxes when the back button
//is pressed.
function SetupLoadHandlers()
{
	if (window.addEventListener)
		window.addEventListener("load", RepopulatePage, false);
	else
		window.attachEvent("onload", RepopulatePage);
}

function TreeViewValidateHSCodeCount(sourceTreeViewId, destinationListBoxId, maximumHSCodeCount)
{
	var selectedHSCodeCount = ListBoxGetSelectedItemCount(destinationListBoxId);
	var hsCodeCount = 0;
	var sourceTreeView = document.getElementById(sourceTreeViewId);
	var destinationListBox = document.getElementById(destinationListBoxId);
	var tables = sourceTreeView.getElementsByTagName("table");
	for (var tableIndex = 0; tableIndex < tables.length; tableIndex++)
	{
		var inputs = tables[tableIndex].getElementsByTagName("input");
		for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)
		{
			if (inputs[inputIndex].type == "checkbox")
			{
				if (inputs[inputIndex].checked)
				{
					var span = inputs[inputIndex].nextSibling;
					var hidden = span.nextSibling;
					if (!ListBoxValueExists(destinationListBox, hidden.value))
					{
						hsCodeCount++;
						if (hsCodeCount + selectedHSCodeCount > maximumHSCodeCount)
						{
							alert('Too many HS Codes selected.\r\nMaximum allowed ' + maximumHSCodeCount + '.');
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}

function SearchResultsValidateHSCodeCount(sourceSearchResultsId, destinationListBoxId, maximumHSCodeCount)
{
	var selectedHSCodeCount = ListBoxGetSelectedItemCount(destinationListBoxId);
	var hsCodeCount = 0;
	var listBox = document.getElementById(destinationListBoxId);
	var outerDiv = document.getElementById(sourceSearchResultsId);
	var innerDivs = outerDiv.getElementsByTagName("div");
	for (var divIndex = 0; divIndex < innerDivs.length; divIndex++)
	{
		var inputs = innerDivs[divIndex].getElementsByTagName("input");
		for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++)
		{
			if (inputs[inputIndex].type == "checkbox")
			{
				if (inputs[inputIndex].checked)
				{
					var span = inputs[inputIndex].nextSibling;
					if (!ListBoxValueExists(listBox, inputs[inputIndex].value))
					{
						hsCodeCount++;
						if (hsCodeCount + selectedHSCodeCount > maximumHSCodeCount)
						{
							alert('Too many HS Codes selected.\r\nMaximum allowed ' + maximumHSCodeCount + '.');
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}
