
/*****************************************************************************
This function allows the user to confirm the deletion.
******************************************************************************/
function confirmDeletion()
{		
	if (confirm("Are you sure you want to delete this record?"))
	{
		return true;
	}
	else
	{
		return false;
	}
}						


/*****************************************************************************
This function allows the user to confirm the closing of a screen
******************************************************************************/
function confirmClose()
{		
	if (confirm("Are you sure you want to close?  Any unsaved changes will be lost."))
	{
		return true;
	}
	else
	{
		return false;
	}
}						

/***********************************************************************************
This function is used to call LOV windows.
Parameters:
  -  dataSetName       : a text value representing the data to display in the LOV
  -  returnFormName    : the name of the HTML form of the return field
  -  returnFieldName   : the name of the text field to return the value to
************************************************************************************/
function callLov(dataSetName, returnFormName, returnFieldName, returnDisplayField)
{
	window.open('lov.aspx?dataSetName=' + dataSetName + '&returnFormName=' + returnFormName + '&returnFieldName=' + returnFieldName + '&returnDisplayField=' + returnDisplayField + '',
				'lovwindow',
				'toolbar=no,status=no,width=500,height=450,scrollbars=yes'
				);
}

/***********************************************************************************
This function is used to call LOV windows.
Parameters:
  -  dataSetName       : a text value representing the data to display in the LOV
  -  eventTypeItem     : the name of the form item for event type
  -  returnFormName    : the name of the HTML form of the return field
  -  returnFieldName   : the name of the text field to return the value to
  -  returnDisplayName : the name of the text field to return the display value to
************************************************************************************/
function callFilterLov(dataSetName, eventTypeItem, returnFormName, returnFieldName, returnDisplayField)
{
	var eventTypeRadio = eval("document." + returnFormName + ".getElementById(\"" + eventTypeItem + "\")");
	var eventTypeCode;

	// loop through radio buttons to determine selected value
	for (i=0;i<eventTypeRadio.length;i++)
	{
		if (eventTypeRadio[i].checked)
		{
			eventTypeCode = eventTypeRadio[i].value;
		}
	}

	window.open('lov.aspx?dataSetName=' + dataSetName + 
				'&eventTypeCode=' + eventTypeCode +
				'&returnFormName=' + returnFormName + '&returnFieldName=' + returnFieldName + '&returnDisplayField=' + returnDisplayField + '',
				'lovwindow',
				'toolbar=no,status=no,width=500,height=450,scrollbars=yes'
				);
}

/***********************************************************************************
This function passes a value back to the calling window
Parameters:
  -  returnFormName    : the name of the HTML form of the return field
  -  returnFieldName   : the name of the text field to return the value to
  -  returnValue       : the value to return to the field
************************************************************************************/
function passback(returnFormName, returnFieldName, returnValue, returnDisplayField, returnDisplayValue)
{
	var returnField = eval("opener.document.getElementById(\"" + returnFieldName + "\")");
	returnField.value = returnValue;

	var returnDisplayField = eval("opener.document.getElementById(\"" + returnDisplayField + "\")");
	returnDisplayField.value = returnDisplayValue;

}

/***********************************************************************************
This function adds two numbers together and sets it as the value of the specified field
Parameters:
  -  dataSetName       : a text value representing the data to display in the LOV
  -  returnFormName    : the name of the HTML form of the return field
  -  returnFieldName   : the name of the text field to return the value to
************************************************************************************/
function addNumbers (number1, number2, fieldName)
{
	var num1 = new Number(0);
	var num2 = new Number(0);
	
	num1 = parseInt((eval(number1)).value, 10);
	
	if (isNaN(num1))
	{
		num1 = 0;
	}

	num2 = parseInt((eval(number2)).value, 10);
	
	if (isNaN(num2))
	{
		num2 = 0;
	}
	
   (eval(fieldName)).value = num1 + num2;
}

// Function to convert a string to titlecase
function ToTitleCase(inStr)
{
	var bufStr = Trim(inStr)
	var index = bufStr.indexOf(" ")

	if(index > 0)
	{
		return ToTitleCase(bufStr.substring(0, index)) + " " + ToTitleCase(bufStr.substr(index + 1))
	}
	else
	{
		return bufStr.substr(0, 1).toUpperCase() + bufStr.substr(1).toLowerCase()
	}
}

// Function to trim spaces from the start and end of a string
function Trim(inStr)
{
	return TrimStart(TrimEnd(inStr))
}

// Function to trim spaces from the start of a string
function TrimStart(inStr)
{
	var index = 0

	while(inStr.charAt(index) == " ")
	{
		index++
	}

	return inStr.substr(index)
}

// Function to trim spaces from the end of a string
function TrimEnd(inStr)
{
	var index = inStr.length - 1

	while(inStr.charAt(index) == " ")
	{
		index--
	}

	return inStr.substring(0, index + 1)
}

// Function to get value of a field
function GetValue(fieldName)
{
	return document.getElementById(fieldName).value
}

// Function to set value of a field
function SetValue(fieldName, fieldValue)
{
	document.getElementById(fieldName).value = fieldValue
}

// Function to trim spaces from the start and end of a field
function TrimField(fieldName)
{
	SetValue(fieldName, Trim(GetValue(fieldName)))
}

// Function to check if a field contains any text or not. Returns "Y" if no text, otherwise returns "N"
function IsNull(fieldName)
{
	if(Trim(GetValue(fieldName)).length > 0)
	{
		return "N"
	}
	else
	{
		return "Y"
	}
}

