// JavaScript Validation for the Los Angeles Management Council Member/Administration Site
var threenumberexp = /^\d{3}$/;
var fournumberexp = /^\d{4}$/;
var fivenumberexp = /^\d{5}$/;
var sixnumberexp = /^\d{6}$/;
var lowercaseletterexp = /[a-z]/;
var uppercaseletterexp = /[A-Z]/;
var numericexp = /[0-9]/;
var specialcharacterexp = /["~", "`", "!", "@", "#", "$", "%", "^", "&", ";", "*", "(", ")", "_", "\-", "+", "=", "{", "}", "|", "\\", "\]", "[", ":", ";", "'", "<", ">", ".", "?", "/"]/; 
var letterexp = /[a-z]/i;

function hasLetter(str) {
        return letterexp.test(str);
}
function isValid(pattern, str) {
		return pattern.test(str);
}
function hasNumber(str) {
		return numericexp.test(str);
}
function hasLowerCaseLetter(str) {
		return lowercaseletterexp.test(str);
}
function hasUpperCaseLetter(str) {
		return uppercaseletterexp.test(str);
}
function hasSpecialCharacter(str) {
		return specialcharacterexp.test(str);
}

function validFourNumericDigits(str)
{
	if  (isValid(fournumberexp,str))
		{
			return true;
		}
}

function validFiveNumericDigits(str)
{
	if  (isValid(fivenumberexp,str))
		{
			return true;
		}
}

function validSixNumericDigits(str)
{
	if  (isValid(sixnumberexp,str))
		{
			return true;
		}
}

function functYesOrNo_LACountyInfo()
{
	if (confirm("Are You Sure?\n\nYou Will Be Sent To the County Portal."))
	{		
		return true;
	}
	else
	{
		return false;
	}
}

function functYesOrNo_LogoutLACountyInfo()
{
	if (confirm("Are You Sure?\n\nYou Will Be Logged Out and Sent To the County Portal."))
	{		
		return true;
	}
	else
	{
		return false;
	}
}

function functYesOrNo_Home()
{
	if (confirm("Are You Sure?\n\nYou Will Be Returned To The Management Council Public Home Page"))
	{		
		return true;
	}
	else
	{
		return false;
	}
}

function functLogoutYesOrNo_Home()
{
	if (confirm("Are You Sure?\n\nYou will be logged out\nAnd Returned To The Management Council Public Home Page"))
	{		
		return true;
	}
	else
	{
		return false;
	}
}

function getCurrentDate()
{
	theDate = new Date();
//	alert("The Date is: " + ((theDate.getMonth() +1) + "-" + theDate.getDate() + "-" + theDate.getFullYear()));
	return ((theDate.getMonth() +1) + "-" + theDate.getDate() + "-" + theDate.getFullYear());
}	

function OnChangeOfDuesPaying()
{
	// Verify whether Dues Paying has been Selected:
	if (document.form1.selDuesPaying.selectedIndex == 1)
	{
		document.form1.txtMemberDate.value = getCurrentDate();
	}
	else
	{
		document.form1.txtMemberDate.value = "";
	}
}

// Function to validate Phone Numbers:
function isValidPhone(phoneStr)
{
	// This lines requrie that the phone number be in the form 999-999-9999:
	var phonePattern = /^(\d{3})-(\d{3})-(\d{4})$/;
	var matchArray = phoneStr.match(phonePattern); // is the format ok?
	if (matchArray == null) 
	    {
	    return false;
	    }
	else
	    {
	    return true;
	    }
}

// E-mail validation:
// a valid email address should contain: 
// at least one character preceding the "@," 
// the characters preceding may contain "." and/or "_,"
// an "@" following the preceding character(s), 
// at least one character following the "@", followed by a dot (.), and
// followed by either a two character or three character string (a two character country code or the standard three character US code, such as com, edu etc) 
function checkEmail(emailStr) 
{ 
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(emailStr)) 
	{
		return true;
	}
	else
	{ 
		return false;
	} 
} 

// Validate zip code: it can be either five digits long (99999), or 5-digits hyphen 4-digits (99999-9999):
function isValidZipCode(zipStr) 
{ 
	var validZip1 = /^(\d{5})$/;
	var validZip2 = /^(\d{5})-(\d{4})$/;
	if (validZip1.test(zipStr) || validZip2.test(zipStr)) 
	{
		return true;
	}
	else
	{ 
		return false;
	} 
} 


