//---------------------------------------------------------
// Application	: Business Names Register
// Author			: Patricia Luperdi
// File				: methods.js
//
// Copyright 2003 IBM Business Consulting Services
//---------------------------------------------------------

//-------------------------------------------------------------------
// openDefinitionWindow(url)
//   Opens a definition window via the passed in url
//-------------------------------------------------------------------
function openDefinitionWindow(url)
{
	this.openWindow(url, '200', '200');
}

//-------------------------------------------------------------------
// openDefinitionWindow(url, top, left)
//   Opens a definition window via the passed in url, at the specified location
//-------------------------------------------------------------------
function openWindow(url, top, left)
{
	params='width=500, height=200, resizable=yes, scrollbars=yes, top=' + top + ', left=' + left;
    window.open(url, '_blank', params);
}

//-------------------------------------------------------------------
// openDefinitionWindow(url)
//   Opens the printer friendly details window via the passed in url
//-------------------------------------------------------------------
function openPrinterFriendlyWindow(url)
{
    window.open(url, '_blank', 'resizable=yes, scrollbars=yes');
}

//-------------------------------------------------------------------
// activate_businessnamesearch()
//  Enables the business names search and disables the other searches
//-------------------------------------------------------------------
function activate_businessnamesearch()
{
	if (!searchByBusNameForm.businessName.readonly)
	{
		if (searchByBusNameForm.businessName.value == "")
		{
			searchByRegNumberForm.registrationNr.disabled = false;
			searchByRegNumberForm.searchButton.disabled = false;
			searchByRegNumberForm.registrationNr.style.backgroundColor = "#FFFFFF";
			
			if (document.searchByABNForm != null)
			{
				searchByABNForm.abn.disabled = false;
				searchByABNForm.searchButton.disabled = false;
				searchByABNForm.abn.style.backgroundColor = "#FFFFFF";
			}
		}
		else
		{
			searchByRegNumberForm.registrationNr.disabled = true;
			searchByRegNumberForm.searchButton.disabled = true;
			searchByRegNumberForm.registrationNr.style.backgroundColor = "#CCCCCC";

			if (document.searchByABNForm != null)
			{
				searchByABNForm.abn.disabled = true;
				searchByABNForm.searchButton.disabled = true;
				searchByABNForm.abn.style.backgroundColor = "#CCCCCC";
			}
		}
	}
}

//-------------------------------------------------------------------
// activate_ABNsearch()
//  Enables the ABN search and disables the other searches
//-------------------------------------------------------------------
function activate_ABNsearch()
{
	if (!searchByABNForm.abn.readonly)
	{
		if (searchByABNForm.abn.value == "")
		{
			searchByRegNumberForm.registrationNr.disabled = false;
			searchByRegNumberForm.searchButton.disabled = false;
			searchByRegNumberForm.registrationNr.style.backgroundColor = "#FFFFFF";
			searchByBusNameForm.businessName.disabled = false;
			searchByBusNameForm.searchButton.disabled = false;
			searchByBusNameForm.keywordSearch.disabled = false;
			searchByBusNameForm.includeNonCurrent.disabled = false;
			searchByBusNameForm.businessName.style.backgroundColor = "#FFFFFF";
		}
		else
		{
			searchByRegNumberForm.registrationNr.disabled = true;
			searchByRegNumberForm.searchButton.disabled = true
			searchByRegNumberForm.registrationNr.style.backgroundColor = "#CCCCCC";
			searchByBusNameForm.businessName.disabled = true;
			searchByBusNameForm.keywordSearch.disabled = true;
			searchByBusNameForm.includeNonCurrent.disabled = true;
			searchByBusNameForm.searchButton.disabled = true;
			searchByBusNameForm.businessName.style.backgroundColor = "#CCCCCC";
		}
	}
}

//-------------------------------------------------------------------
// activate_registrationnumbersearch()
//  Enables the Registration Number search and disables the other searches
//-------------------------------------------------------------------
function activate_registrationnumbersearch()
{
	if (!searchByRegNumberForm.registrationNr.readonly)
	{
		if (searchByRegNumberForm.registrationNr.value == "")
		{
			searchByBusNameForm.businessName.disabled = false;
			searchByBusNameForm.keywordSearch.disabled = false;
			searchByBusNameForm.includeNonCurrent.disabled = false;
			searchByBusNameForm.searchButton.disabled = false;
			searchByBusNameForm.businessName.style.backgroundColor = "#FFFFFF";

			if (document.searchByABNForm != null)
			{
				searchByABNForm.abn.disabled = false;
				searchByABNForm.searchButton.disabled = false;
				searchByABNForm.abn.style.backgroundColor = "#FFFFFF";
			}
		}
		else
		{
			searchByBusNameForm.businessName.disabled = true;
			searchByBusNameForm.searchButton.disabled = true;
			searchByBusNameForm.keywordSearch.disabled = true;
			searchByBusNameForm.includeNonCurrent.disabled = true;
			searchByBusNameForm.businessName.style.backgroundColor = "#CCCCCC";

			if (document.searchByABNForm != null)
			{
				searchByABNForm.abn.disabled = true;
				searchByABNForm.searchButton.disabled = true;
				searchByABNForm.abn.style.backgroundColor = "#CCCCCC";
			}
		}
	}
}

//-------------------------------------------------------------------
// checkDisabled(field)
//  Alerts the user that the search is disabled
//-------------------------------------------------------------------
function checkDisabled(field)
{
	if (field.disabled)
	{
		alert("To enable this search, delete text entered.");
	}
}

//-------------------------------------------------------------------
// keywordSearch_checked()
// If the keyword search checkbox is unticked, untick the include non-current checkbox
//-------------------------------------------------------------------
function keywordSearch_checked()
{
	if (!searchByBusNameForm.keywordSearch.checked)
	{
		searchByBusNameForm.includeNonCurrent.checked = false;
	}
}

//-------------------------------------------------------------------
// includeNonCurrent_checked()
// If the include non-current checkbox is ticked, tick the keyword search checkbox 
//-------------------------------------------------------------------
function includeNonCurrent_checked()
{
	if (searchByBusNameForm.includeNonCurrent.checked)
	{
		searchByBusNameForm.keywordSearch.checked = true;
	}
}