// JavaScript Document
//checkForBlanks()
//
// given input of the format "field", "fieldname"
// check to see if field is blank

function checkForBlanks()
{
	var stringToCheck;

	for (var i = 0; i < arguments.length; i += 2)
	{
		stringToCheck = arguments[i].value;
		stringToCheck = stringToCheck.replace("\s+","")
					
		if (stringToCheck == "")
		{
			alert(arguments[i+1] + " is a required entry.");
			arguments[i].select();
			arguments[i].focus();
			return false;
		}
	}
	return true;
}



//limitText()
//
//	Prevents input from going over the max size	

function limitText(textField, maxSize)
{
	if (textField.value.length > maxSize)
	{
		alert("Sorry, no more characters can be inserted.");
		textField.value = textField.value.substring(0, maxSize);
	}
}



//checkEmail()
//
//	Checks for proper email nomenclature		

function checkEmail(email)
{
	if(!email.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/))
	{
		alert("email is in the incorrect format");
		email.select();
		email.focus();
		return false;
	}
	return true;
}							

//checkZip()
//
//  Checks for proper zipcode nomenclature

function checkZip(zip)
{
	if(!zip.value.match(/(^\d{5}$)|(^\d{9}$)|(^\d{5}-\d{4}$)/))
	{
		alert("Zipcode is in the incorrect format. Use: #####, ######### or #####-####");
		zip.select();
		zip.focus();
		return false;
	}
	return true;
}
					
//checkLength()
//
//	Checks input to determine if it falls within the prescribed limits

function checkLength(aInput, MIN, MAX, strDesc)
{
	if ((aInput.value.length < MIN) || (aInput.value.length > MAX))
	{
		alert(strDesc + " field is not within the prescribed size limits.");
		aInput.select();
		aInput.focus();
		return false;
	}
	return true;
}


//checkPassword()
//
//	Checks input to determine if it contains invalid characters or
//  a bad type of password.

function checkPassword(strInput)
{
	var password = strInput.value;
			
	//check for any single or double quotes
	if ((password.indexOf('\'') >= 0) || (password.indexOf('"') >= 0))
	{
		alert("Password contains invalid characters!  Please try again.");
		strInput.select();
		strInput.focus();
		return false;
	}
			
	//check to make sure the password is not ALL numbers and not ALL letters
	if (password.match(/[a-zA-Z]+|[0-9]+/) == password)
	{
		alert("Password must contain a combination of letters, numbers, and/or symbols.");
		strInput.select();
		strInput.focus();
		return false;
	}
	return true;
		
}


//comparePasswords()
//
//	Simple String comparison for equality.

function comparePasswords(original, duplicate)
{
	if (original.value != duplicate.value)
	{
		alert("Passwords do not match!  Please try again.");
		original.select();
		original.focus();
		return false;
	}
	return true;
}


function validBTTG(aForm)
{
	var isValid;

	isValid = checkForBlanks(
			aForm.firstname, "First Name",
			aForm.lastname, "Last Name",
	        aForm.address1, "Address",
	        aForm.city, "City",
			aForm.state, "State",
			aForm.zip, "Zip",
			aForm.country, "Country",
			aForm.area_code, "Your Complete Phone Number",
			aForm.prefix, "Your Complete Phone Number",
			aForm.suffix, "Your Complete Phone Number",
			aForm.email, "Your Email address"
			);
	if (!isValid) return false;

	isValid = checkEmail(aForm.email);
	if(!isValid) return false;
				
	return true;
}