﻿// ACL Free Services (Find-A-Church, Find-A-Business, Find-A-Person)
// Client-side validation functions
//
function dropdownHasSelectedValue(ddl)
{
	var hasSelectedValue = false;
	if (ddl != null && ddl.selectedIndex != null && ddl.options != null)
	{
		var i = ddl.selectedIndex;
		var hasSelection = (i >= 0);
		if (hasSelection)
		{
			var option = ddl.options[i];
			hasSelectedValue = (option.value != null && option.value != "");
		}
	}
	return hasSelectedValue;
}

function validateDenominationDropDown(objValidator, args)
{
	if (args != null)
	{
		if (!dropdownHasSelectedValue(document.getElementById("denominationDropDown")))
		{
			args.IsValid = false;
		}
	}
}

function validateStateDropDown(objValidator, args)
{
	if (args != null)
	{
		if (!dropdownHasSelectedValue(document.getElementById("stateDropDown")))
		{
			args.IsValid = false;
		}
	}
}

function validateZipCodeLength(objValidator, args)
{
	if (args != null)
	{
		var obj = document.getElementById("zipTextBox");
		if (obj != null && obj.value != null)
		{
			var s = obj.value;
			if (s.length != 5)
			{
				args.IsValid = false;
			}
			else
			{
				var allDigits = true;
				for (var i = 0; i < s.length && allDigits; ++i)
				{
					var c = s.substring(i, i+1);
					allDigits = ("0" <= c && c <= "9");
				}
				if (!allDigits)
				{
					args.IsValid = false;
				}					
			}
		}
	}
}
// end.
