function showSpan (showItem)
{
	document.getElementById(showItem).style.display = "";
	setFooter();
}

function hideSpan(showItem)
{
	document.getElementById(showItem).style.display = "none";
	setFooter();
}

function showSection (fldObj, sectionName)
{
	formObj = document.forms[1];
	
	if (fldObj.value == "Yes")
		showSpan (sectionName + 'Table');
	else
		hideSpan (sectionName + 'Table');
}

function showHidden (fldObj, emailgone)
{
	formObj = document.forms[1];
	
	if (fldObj.value == "Yes")
		showSpan (emailgone);
	else
		hideSpan (emailgone);
}

function showPrevScam (fldObj, tempvar)
{
	formObj = document.forms[1];
	
	if (fldObj.value == "Yes")
		showSpan (tempvar);
	else
		hideSpan (tempvar);
}

function showOther (fldObj, idName)
{
	formObj = document.forms[1];
	
	if (fldObj.value == "Other")
		showSpan (idName);
	else
		hideSpan (idName);
}

function showTables (sectionName)
{
	formObj = document.forms[1];
	countFld = eval ("formObj." + sectionName + "Count");
	var itemCount = parseInt (countFld.value, 10);
	
	if (itemCount < 5)
	{
		itemCount++;
		showSpan (sectionName + "_" + itemCount);
		countFld.value = itemCount;
		
		if (itemCount >= 5)
		{
			addNewBtn = eval ("formObj." + sectionName + "New");
			addNewBtn.disabled = true;
		}
		if (itemCount > 1)
		{
			removeBtn = eval ("formObj." + sectionName + "Remove");
			removeBtn.disabled = false;
		}
	}
}

function hideTables (sectionName)
{
	formObj = document.forms[1];
	countFld = eval ("formObj." + sectionName + "Count");
	var itemCount = parseInt (countFld.value, 10);
	
	if (itemCount > 0)
	{
		hideSpan (sectionName + "_" + itemCount);
		itemCount--;
		countFld.value = itemCount;

		if (itemCount <= 1)
		{
			removeBtn = eval ("formObj." + sectionName + "Remove");
			removeBtn.disabled = true;
		}
		if (itemCount < 5)
		{
			addNewBtn = eval ("formObj." + sectionName + "New");
			addNewBtn.disabled = false;
		}
	}
}

// This function checks the Field Object (Parameter One) to see if it is empty. It removes all white space.
function isEmpty (fldStr)
{
	// Set the regular expression to remove all white space
	var regexp = /\s/gi;
	tmpStr = fldStr.replace (regexp, "");
	// If the length of the string is 0, the field is Empty. Return true.
	if (tmpStr.length == 0)
		return true;
	// Return false if the length has a value in it.
	return false;
}

// This function is used in error checking. It sets focus on the field (Parameter One) and return's false.
function setFocus (objStr)
{
	// Create an object from the field name parsed.
	focusObj = eval ("document.forms[1]." + objStr);
	// Focus the cursor on the field
	focusObj.focus ();
	return false;
}

// This function tests to see if a field object value (Parameter One) is numeric.
function isNumeric (fldStr)
{
	// Set the regular expression to remove all digits.
	var regexp = /\d/gi;
	tmpStr = fldStr.replace (regexp, "");
	// If the length of the string is 0, then all characters are numeric. Return true.
	if (tmpStr.length == 0)
		return true;
	return false;
}

function checkRadio (groupObj)
{
	isChecked = false;
	for (r = 0; r < groupObj.length; r++)
	{
		if (groupObj[r].checked)
			isChecked = true;
	}
	return isChecked;
}

// This function will test to see if the specified element; ID or NAME (Parameter One) exists
function elementExists (elementName)
{
	// Create a name and id object with the element name
	idObj = document.getElementById(elementName);
	nameObj = document.getElementsByName(elementName);
	
	if (!idObj || !nameObj)
		// element does not exist with id or name
		return false;
	else
		return true;
}

// Function returns true if date is Future Dated, otherwise false
function isFutureDated (dayFld, monthFld, yearFld)
{
	dayObj = findElementByName (dayFld);
	monthObj = findElementByName (monthFld);
	yearObj = findElementByName (yearFld);
	dateStr = monthObj.value + "/" + dayObj.value + "/" + yearObj.value;
	dateStr = Date.parse (dateStr);
	dateObj = new Date ();
	dateDiff = dateObj.getTime () - dateStr;
	// is the date future dated?
	if (dateDiff < 0)
		return true;
	return false;
}

// Function returns a reference to the fldName in the page.
function findElementByName (fldName)
{
	return document.getElementsByName (fldName)[0];
}

function isValidEmail (fldStr)
{
	var filter = /^.+@.+\..{2,4}/
	
	if (filter.test (fldStr))
		return true;
	else
		return false;
}
