// JavaScript Document

function isLetter(c)
{
	if(((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")))
	{
		return false;
	}//end if
	return true;
}//end isAlpha()

/**
*Checks for alphabetic characters, hyphens and spaces
*/
function isAlpha(c)
{
	if(((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && ((c != "-") && (c != " ")))
	{
		return false;
	}//end if
	return true;
}//end isAlpha()

/**
*Checks for numeric characters
*/
function isNumber(c)
{
	if((c < "0") || (c > "9"))
	{
		return false;
	}//end if
	return true;
}//end isNumber

/**
*Checks for numeric characters, () and -
*/
function isPhoneNumber(c)
{
	if(((c < "0") || (c > "9")) && ((c != "(") && (c != ")") && (c != "-")))
	{
		return false;
	}//end if
	return true;
}//end isNumber

/**
*Checks for alphanumeric characters, spaces, hyphens, periods and pound
*/
function isAlphaNum(c)
{
	if(((c < "0") || (c > "9")) && (((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && (c != " ") && (c != "-") && (c != ".") && (c != "#")))
	{
		return false;
	}//end if
	return true;
}//end isAlphaNum()

/*Checks for alphanumeric characters, spaces, hyphens, periods and pound*/
function isAlphaNum(c)
{
	if(((c < "0") || (c > "9")) && (((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && (c != " ") && (c != "-") && (c != ".") && (c != "#")))
	{
		return false;
	}//end if
	return true;
}//end isAlphaNum()

/*Makes sure that the fname field has been filled and contains appropriate characters*/
function checkFName()
{
	var fname = document.form.fname.value;
	
	if((fname == "") || (fname == null))
	{
		document.form.fname.style.color = "FFFFFF";
		document.form.fname.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
	
	for(var i = 0; i < fname.length; i+=1)
	{
		var isGood = isAlpha(fname.charAt(i));
		if(!isGood)
		{
			document.form.fname.style.color = "FFFFFF";
 			document.form.fname.style.backgroundColor = "FFFFCC";
			return false;
		}//end if
	}//end for
	return true;
}//end checkFName()

/*Makes sure that the bname field has been filled and contains appropriate characters*/
function checkbName()
{
	var bname = document.form.bname.value;	
		
	if((bname == "") || (bname == null))
	{
		document.form.bname.style.color = "FFFFFF";
		document.form.bname.style.backgroundColor = "FFFFCC";
		return false;
	}//end if	
		
	for(var i = 0; i < bname.length; i+=1)
	{
		var isGood = isAlpha(bname.charAt(i));
		if(!isGood)
		{
			document.form.bname.style.color = "FFFFFF";
			document.form.bname.style.backgroundColor = "FFFFCC";
			return false;
		}//end if
	}//end for
	return true;
}//end checkbName()

/*Makes sure that the phone field has been filled and contains appropriate characters*/
function checkPhone()
{
	var phone = document.form.phone.value;
	
	if(phone == null || phone == "")
	{
		document.form.phone.style.color = "FFFFFF";
		document.form.phone.style.backgroundColor ="FFFFCC";
		return false;
	}//end if
	
	for(var i = 0; i < phone.length; i += 1)
	{
		var isGood = isPhoneNumber(phone.charAt(i));
		
		if(!isGood)
		{
			document.form.phone.style.color = "FFFFFF";
			document.form.phone.style.backgroundColor ="FFFFCC";
			return false;
		}//end if
	}//end for
	return true;
}//end checkPhone()

/*Checks to make sure a valid email address has been added*/
function checkEmail() 
{
	var email = document.form.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.ca)|(\..{2,2}))$)\b/gi);
	
	if (email)
	{
	   return true;
	}//end if
	else 
	{
		document.form.email.style.color = "FFFFFF";
		document.form.email.style.backgroundColor = "FFFFCC";
		return false;
	}//end if
}//end checkEmail()

function checkAll()
{
	var fname = checkFName();
	var bname = checkbName();
	var email = checkEmail();
	var phone = checkPhone();
	
	if(!fname)
	{
		return false;
	}//end if
	
	if(!bname)
	{
		return false;
	}//end if
	
	if(!email)
	{
		return false;
	}//end if
	
	if(!phone)
	{
		return false;
	}//end if
}//end checkAll

function changeColor(c)
{
	c.style.color = "000000";
	c.style.backgroundColor = "FFFFFF";
}//end changeColor()