// FIRST NAME

function checkFirstname(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter your first name.\n"
	}
	return error;	  
}


// LAST NAME

function checkLastname(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter your last name.\n"
	}
	return error;	  
}


// FULL NAME

function checkFullname(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter your name.\n"
	}
	return error;	  
}

// EMAIL

function checkEmail (strng) {
	var error="";

	if (strng == "") {
		error = "Please enter your email address.\n";
	}

 	var emailFilter=/^.+@.+\..{2,3}$/;

	if (!(emailFilter.test(strng))) { 
		 error = "Please enter a valid email address.\n";
	} else {

		//test email for illegal characters

		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/

		if (strng.match(illegalChars)) {
			error = "The email address contains illegal characters.\n";
		}
	}
	return error;    
}


// STREET

function checkStreet(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter your street address.\n"
	}
	return error;	  
}


// CITY

function checkCity(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter your city.\n"
	}
	return error;	  
}


// STATE

function checkState(choice) {
	var error = "";

	if (choice == 0) {
		error = "Please select your state.\n";
	}    
	return error;
}


// ZIP

function checkZip(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter your zip code.\n"
	}
	return error;	  
}


// DONATION AMOUNT

function checkDonateAmount(checkvalue, amountOther) {

	var error = "";

	if (!(checkvalue) && amountOther == "") {
		error = "Please select a donation amount.\n";
	}

	return error;
}


// CREDIT CARD TYPE

function checkCCType(checkvalue) {

	var error = "";

	if (!(checkvalue)) {
		error = "Please select a credit card.\n";
	}

	return error;
}


// CREDIT CARD NUMBER

function checkCCNum(strng) {
	var error = "";

	if (strng.length < 13) {
		error = "Please enter a valid credit card number.\n"
	}
	return error;
}


function checkCCExpire(month, year) {

	var error = "";

	if (month == "Month" || year == "Year") {
		error = "Please enter a valid credit card expiration date.\n"
	} else {

		var now = new Date();
		var CurrentDate = new Date();
		var ExpiresDate = new Date();

		CurrentDate.setFullYear(now.getFullYear(), now.getMonth(), 1);
		ExpiresDate.setFullYear(year*1+2000, month-1, 1);

		if (ExpiresDate < CurrentDate)
			error = "Please enter a valid credit card expiration date.\n"

		//expiresIn.setMonth(expiresIn.getMonth()+1);

		//if(now.getTime() < expiresIn.getTime())
		//	error = "Please enter a valid credit card expiration date.\n"

		//error = "Current:" + CurrentDate + "\nExpire date:" + ExpiresDate + "\n";
	}

	return error;
}


// ZIP

function checkcvv2(strng, ccnum) {
	var error = "";

	if (strng.length == 0 && ccnum != "1111111111111111") {
		error = "Please enter your cvv2 code.\n"
	}
	return error;	  
}


// SUBJECT LINE

function checkSubject(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter a subject line.\n"
	}
	return error;	  
}


// TO EMAIL

function checkToEmail(strng) {
	var error="";

	if (strng == "") {
		error = "Please enter an email address.\n";
	}

 	var emailFilter=/^.+@.+\..{2,3}$/;

	if (!(emailFilter.test(strng))) { 
		 error = "Please enter a valid email address.\n";
	} else {

		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/

		if (strng.match(illegalChars)) {
			error = "The email address contains illegal characters.\n";
		}
	}
	return error; 	  
}


// MESSAGE

function checkMessage(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter a message to send.\n"
	}
	return error;	  
}












// FULL NAME

function checkInHonorName(strng) {
	var error = "";

	if (strng.length == 0) {
		error = "Please enter your honoree's name.\n"
	}
	return error;	  
}

// EMAIL

function checkInHonorEmail (strng) {
	var error="";


 	var emailFilter=/^.+@.+\..{2,3}$/;

	if (!(emailFilter.test(strng))) { 
		 error = "Please enter a valid email address for your honoree.\n";
	} else {

		//test email for illegal characters

		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/

		if (strng.match(illegalChars)) {
			error = "The honoree's email address contains illegal characters.\n";
		}
	}
	return error;    
}









// PHONE NUMBER - strip out delimiters and check for 10 digits

function checkPhone (strng) {
	var error = "";

	if (strng == "") {
		error = "You didn't enter a phone number.\n";
	}

	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters

	if (isNaN(parseInt(stripped))) {
		error = "The phone number contains illegal characters.";
	}

	if (!(stripped.length == 10)) {
		error = "The phone number is the wrong length. Make sure you included an area code.\n";
	} 
	return error;
}

