// ----------------------------------------------------------------------------
// Post the form to strAction.
// ----------------------------------------------------------------------------
function _RegistrationAction(strRegistrationForm, strFromForm, strAction)
{
	var objRegistrationForm;
	eval("objRegistrationForm = document." + strRegistrationForm + ";");

	if (strFromForm != "")
	{
		var objFromForm;
		eval("objFromForm = document." + strFromForm + ";");

		objRegistrationForm._RegistrationFormValue.value = _GetFormInputs(objFromForm);
	}

	objRegistrationForm.action = strAction;
	objRegistrationForm.submit();
}

// ----------------------------------------------------------------------------
// Post the form to strAction.
// ----------------------------------------------------------------------------
function _PostAction(strForm, strAction)
{
	var objForm;
	eval("objForm = document." + strForm + ";");

	objForm.action = strAction;
	objForm.submit();
}

// ----------------------------------------------------------------------------
// Validate that at least one checkbox is selected.
// ----------------------------------------------------------------------------
function _ValidateDelete(strForm, strItem, strAction)
{
	var objForm;
	eval("objForm = document." + strForm + ";");

	var blnIsChecked = _IsCheckboxChecked(strForm, strItem);

	if (!blnIsChecked)
	{
		alert("Please select one item to delete!");
		return false;
	}
	else
	{
		if (!confirm("Do you want to delete the selected item?"))
		{
			return false;
		}
		else
		{
			objForm.action = strAction;
			objForm.submit();
		}
	}
}

// ----------------------------------------------------------------------------
// Validate that at least one checkbox is selected.
// ----------------------------------------------------------------------------
function _IsCheckboxChecked(strForm, strItem)
{
	var objForm;
	eval("objForm = document." + strForm + ";");

	var lngRecordCount = _GetElementCount(strForm, strItem);

	var objItem;
	eval("objItem = objForm." + strItem + ";");

	var blnIsChecked = false;
	if (lngRecordCount > 1)
	{
		for (var i = 0; i < objItem.length; ++i)
		{
			if (objItem[i].checked)
			{
				blnIsChecked = true;
				break;
			}
		}
	}
	else
	{
		blnIsChecked = objItem.checked;
	}

	return blnIsChecked;
}

// ----------------------------------------------------------------------------
// Get the total number of elements with this name.
// ----------------------------------------------------------------------------
function _GetElementCount(strForm, strItemName)
{
	var objForm;
	eval("objForm = document." + strForm + ";");

	var lngElementCount = 0;
	for (var i = 0; i < objForm.elements.length; ++i)
	{
		if (objForm.elements[i].name == strItemName)
			++lngElementCount;
	}

	return lngElementCount;
}

// ----------------------------------------------------------------------------
// Split a string into array, just like the VB Split counterpart.
// ----------------------------------------------------------------------------
function _Split(strInputString, strDelimeter)
{
	var arrElement = new Array();
	
	// convert number to string.
	strInputString = strInputString.toString();
	if (_StringFind(strInputString, strDelimeter))
		arrElement = strInputString.split(strDelimeter);
	else
		arrElement[0] = strInputString;
		
	return arrElement;
}

// Helper for split function.
function _StringFind(strInputString, strDelimeter)
{
	// convert number to string.
	strInputString = strInputString.toString();
	return strInputString.search(strDelimeter);
}

// ----------------------------------------------------------------------------
// To determine if a variable exists in a form.
// ----------------------------------------------------------------------------
function _IsExist(objForm, strVariableName)
{
	var blnNotFound;
	blnNotFound = eval("!(objForm." + strVariableName + ");");
	return !blnNotFound;
}

// ----------------------------------------------------------------------------
// To retreive all inputs for a form as string.
// ----------------------------------------------------------------------------
function _GetFormInputs(objForm)
{
	var lngLength = objForm.length;
	var strForm = "";
	var strName, strValue, strType;
	for (var i=0; i < lngLength; ++i)
	{
		strType = objForm.elements[i].type;
		if ((strType == "radio") || (strType == "checkbox"))
		{
			if (!objForm.elements[i].checked)
				continue;
		}

		strName = objForm.elements[i].name;
		strValue = objForm.elements[i].value;
		
		if (i == 0)
		{
			strForm = strName + '=' + strValue;
		}
		else
		{
			strForm = strForm + '&' + strName + '=' + strValue;
		}
	}
	return strForm;
}