//***********************************************************
//
// HelperFunctions.js consolidates Javascript functions for
// use in WAD pages for client-side operations.
//
//***********************************************************

function checkEnterKeyPress(controlToInvokeId)
{
	if((event.which && event.which == 13) ||
		(event.keyCode && event.keyCode == 13))
	{
		control = document.getElementById(controlToInvokeId);
		if(control)
		{
			control.click();
		}
	}
}

function suppressEnterKeyPress()
{
	if((event.which && event.which == 13) ||
		(event.keyCode && event.keyCode == 13))
	{
		return false;
	}
}

// Shows and hides an element.
function SetElementDisplay(id)
{
	myElement = document.getElementById(id);
	if(myElement)
	{
		if(myElement.style.display == 'none')
		{
			myElement.style.display = 'block';
		}
		else
		{
			myElement.style.display = 'none';
		}
	}
	return(false);
}


//***********************************************************
// Delete confirmation alert functions.
//***********************************************************


// Ensures the user wants to delete an LDAP attribute from the configuration. This function
// is used for the Manage Attributes and Manage Pages admin pages.
function ConfirmAttributeDelete(attributeName)
{
	if(confirm('Are you sure you want to delete the ' + attributeName
		+ ' attribute? You cannot undo this operation and must add the attribute again if you need it in the future.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function ConfirmGroupDelete(groupName)
{
	if(confirm('Are you sure you want to delete the ' + groupName + ' group? You cannot undo this operation and all '
	+ 'access control lists that use the group will be unable to use the group in the future.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function ConfirmAccessControlListDelete(accessControlListName)
{
	if(confirm('Are you sure you want to delete the ' + accessControlListName + ' access control list? You cannot '
	+ 'undo this operation and all attributes that use the access control list will be unable to use the list in the future.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function ConfirmAccessControlEntryDelete(accessControlEntryName)
{
	if(confirm('Are you sure you want to remove the ' + accessControlEntryName + ' group from this access control list? You cannot '
	+ 'undo this operation and you must add the group again to use it in the future for this access control list.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function ConfirmListChoiceItemDelete(listItemName)
{
	if(confirm('Are you sure you want to delete the ' + listItemName + ' list item? You cannot '
	+ 'undo this operation and you must add the list item again to use it in the future.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function ConfirmDNAttributeValueItemDelete()
{
	if(confirm('Are you sure you want to delete the item? You may cancel the operation '
	+ 'before you update the data if you accidentally delete an item and want to cancel the changes.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function ConfirmTabDelete(tabName)
{
	if(confirm('Are you sure you want to delete the ' + tabName
		+ ' tab? You cannot undo this operation and you will delete ' +
		'all settings for the entire tab from you application configuration.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function ConfirmTaskItemDelete(taskItemName)
{
	if(confirm('Are you sure you want to delete the ' + taskItemName
		+ ' task item? You cannot undo this operation and you will delete ' +
		'all settings for the entire task item from you application configuration.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

// Ensures the user wants to remove a row or column from a screen layout. This function
// is used for the Manage Pages admin page.
function ConfirmRowColumnDelete(itemType)
{
	if(confirm('Are you sure you want to remove the ' + itemType
		+ '? You cannot undo this operation and all attributes contained in the ' + itemType
		+ ' will be deleted from \nthe page layout. You must add the attributes to another row and column '
		+ 'if you want to use them in this page layout.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

// Confirmation message to delete source search property pairs.
function ConfirmSourceSearchPropertyPairDelete(sourceSearchPropertyPairSourceName)
{
	if(confirm('Are you sure you want to delete the ' + sourceSearchPropertyPairSourceName + ' source search property? You cannot '
		+ 'undo this operation.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

// Confirmation message to delete an object.
function ConfirmObjectDelete()
{
	if(confirm('Are you sure you want to permanently delete this object from the directory? You cannot '
		+ 'undo this operation and the object will immediately be deleted from the directory.'))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}