var charexp = /./
var letterexp = /[a-z]/i
var phonexp =  /^\d{10}$/
var memberexp = /^\d{3}$/
var zipexp = /^\d{5}$|^\d{5}[\-\s]?\d{4}$/
var pledgexp = /^\d*$|^\d*\.\d{2}$/


function emailCheck(n) {

 
	var tname = n.name;
	var str = n.value; // email string
	var emailexp = /^[a-z_0-9]{1}[a-z\_\-\.0-9]*@[a-z_0-9\.\-]+\.[a-z]{2,4}$/gi;
	var blnResult = emailexp.test( str );
	 
	if( blnResult ){
		return true;
	}
	else{
		window.alert( "Invalid email address!" );
		return false;
	}
	 


 
}

function isValid(pattern, str) {
	return pattern.test(str);
}

function hasLetter(str) {
	return letterexp.test(str);
}

function hasChar(str) {
	return charexp.test(str);
}

function stripChars(pattern, str) {
	return str.replace(pattern,'');
}

function stripNonDigits(str) {
	return str.replace(/[^0-9]/g,'');
}


function CheckName( tValue)
{
	//Check the first name text box for an entry
	if (tValue.value != '')
	{
		if  (!hasLetter(tValue.value)) {
			alert("Invalid  name");
			tValue.style.color = "Red";
			return false;
		}
		else
		{
			tValue.style.color = "Black";
			return true;
		}
	}
	else
	{
		tValue.style.color = "Black";
		return true;
	}
	return true;
}

function CheckEmail(n)
{
	if (n.value != '')
	{
		if (!emailCheck(n))
		{
			n.style.color = "Red";
			n.focus();
			n.select();
			return false;
		}
		else
		{
			n.style.color = "Black";
			return true;
		}
	}
	else
	{
		//Value was changed to blank
		n.style.color = "Black";
		return true;
	}
}

function CheckState( tValue)
{
	return true;
}

function CheckZipCode( tValue)
{
	//Check that the ZIP code entry is valid.
	if (!isValid(zipexp,tValue)) {
		alert("Invalid ZIP code");
		return false;
	}
	return true;
}

function CheckPhone( tValue)
{
	//Check that the phone entry is valid by first 
	//stripping off all nondigits.
	newphone = '';
	if (hasChar(tValue)) {
		newphone = stripNonDigits(tValue);
		notvalid = !isValid(phonexp,newphone);
	}
	if (newphone == '' || notvalid) {
	alert("Invalid phone number - include area code");
		return false;
	}

	return true;
}


function FlagText(tname)
{
	eval(tname+".style.backgroundColor = 'Red'");
	return true;
}
