/*
function domainMessage()
{
	alert("If your email address is provided by either Comcast (comcast.net) or Roadrunner (roadrunner.com or rr.com), we are unable to send you the Health News monthly newsletter since these Internet Service Providers consider our newsletter spam.  This spam detection immediately blocks all email from the Schiff websites. " + '\n\n' + "You will be able to sign up for the Schiff Rewards program and access the online offers, but will be automatically excluded from receiving the monthly Health News Newsletter. " + '\n\n' + "If you have an alternate email address, we strongly suggest you use that email address instead. We apologize for this inconvenience.");
}

function domainMessage2()
{
	alert("If your email address is provided by either Comcast (comcast.net) or Roadrunner (roadrunner.com or rr.com), we may be unable to respond to you via email. " + '\n\n' + "These Internet Service Providers incorrectly consider our monthly Schiff newsletter spam; and this spam detection automatically blocks all email from the Schiff websites. " + '\n\n' + "If you prefer an email response and have an alternate email address, we strongly suggest you use that email address instead. We apologize for this inconvenience. You may also call us directly at 1-800-526-6251");
}
*/

function birthdateMessage()
{
	alert("We need your birthdate to verify your age.\nThis offer is valid only for adults age 18 and over.\nWe may also send additional special offers on your birthday!\n");
}

function noRedeem()
{ // Original - Replace with SELECT CASE and next three functions.
	alert("We're sorry, you either do not have enough points for this reward or you have already redeemed a reward in the past 30 days. Remember: You may only redeem one reward in any 30-day period. If you need further assistance, please contact Consumer Services at 1-800-526-6251.\n");
}

function noRedeemNEP()
{ // Not Enough Points.
	alert("We're sorry, you do not have enough points for this reward. If you need further assistance, please contact Consumer Services at 1-800-526-6251.\n");
}

function noRedeemTE()
{ // Too Early.
	alert("We're sorry, you have already redeemed a reward in the past 30 days. Remember: You may only redeem one reward in any 30-day period. If you need further assistance, please contact Consumer Services at 1-800-526-6251.\n");
}

function noRedeemNCP()
{ // No Coscto Purchases (and trying to redeem for a Costco check).
	alert("We're sorry, you have not entered a code from at least one product you purchased from Costco. If you need further assistance, please contact Consumer Services at 1-800-526-6251.\n");
}

function systemReqMessage()
{
	alert("SYSTEM REQUIREMENTS:\nCoupon printing is supported by the following operating systems. NOTE: Turn off any pop-up blockers prior to clicking the coupon button.\n\nCoupon Printing for Windows\nCoupon printing is currently supported on Windows Operating Systems Vista, XP, ME, 2000, and NT4 when used with Internet Explorer 5.5 or newer, Netscape 7 or newer, FireFox and most MSN and AOL browsers.\n\nCoupon Printing for Macintosh\nCoupon printing is also supported on Macintosh when using the Safari browser under OS X 10.3 and higher.\n");
}

function emailNotFoundMessage()
{
	alert("We could not find an account with that email address.\n\nPlease try again.\n");
}

function passwordNotFoundMessage()
{
	alert("We could not find an account with that password.\n\nPlease try again.\n");
}

function open_video_a_win()
{
	window.open("http://www.schiffloyaltyrewards.com/video_a.asp","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=475, height=505");
}

function open_video_b_win()
{
//	window.open("http://www.schiffloyaltyrewards.com/video_b.asp","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=475, height=505");
	window.open("http://www.schiffloyaltyrewards.com/video_b.asp","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=475, height=550");
}

function open_image_win()
{
	//DJ - Image is 300x350. Size window taking into account extra spacing.
	window.open("http://www.schiffloyaltyrewards.com/images/product_code_MFA+Energy.jpg","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=318, height=368");
}

function open_points_win()
{
	window.open("http://www.schiffloyaltyrewards.com/points.asp","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=575, height=650");
}

function open_pp_win()
{
	window.open("http://www.schiffloyaltyrewards.com/privacy_policy.asp","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=805, height=600");
}

function open_tac_win()
{
	window.open("http://www.schiffloyaltyrewards.com/terms_and_conditions.asp","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=805, height=600");
}

function open_faq_win()
{
	window.open("http://www.schiffloyaltyrewards.com/faqs_popup.asp","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=805, height=600");
}

function open_cu_win()
{
	window.open("http://www.schiffloyaltyrewards.com/contact_us.asp","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=805, height=600");
}

function close_this_win()
{
	this.close();
}

function isValidLoyaltyCode(input)
{
	var checkDigit;
	var checkSum = 0;
	for(i=0; i<(input.length-1); i++) { checkSum += input.charCodeAt(i) * (i+1); }
	if ((checkSum % 11) == 0) { checkDigit = String.fromCharCode(97); }
	else if ((checkSum % 11) == 1) { checkDigit = null; }
	else { checkDigit = String.fromCharCode(97 + (11 - (checkSum % 11))); }
	if (checkDigit == input.charAt(input.length-1)) { return true; } else { return false; }
}

function newLocation(x)
{
	window.location=x;
}

//****************** Function to check email format: ******************
function isValidEmail(x) {
	var blnValid;
	var strPattern;
	
	blnValid = true;
	
	//DJ - Oookay... so Javascript RegExp needs to be further edited by doubling up your "\s" I guess.
	strPattern = new RegExp("^([A-Za-z0-9_\\-\\.])+\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})$"); //DJ - This actually works.
	blnValid = strPattern.test(x);
	
	return(blnValid);
}


//****************** Function to check password format: ******************
function isValidPW(x) {
	var blnFoundBadChar;
	var strPattern;
	
	blnFoundBadChar = true;
	
	//DJ - Find ANY ONE character that is NOT alphanumeric (or is NOT an underscore).
	strPattern = new RegExp("[\\W]"); //DJ - This works.
	blnFoundBadChar = strPattern.test(x);
	
	if (blnFoundBadChar == true) {
		return(false);
	}
	else {
		return(true);
	}
}


//****************** Function to check the form fields: ******************
function checkForm() {
	var alertMessage;
	var submitFlag;
	
	var email;
	var emailConfirm;
	var password;
	var passwordConfirm;
	var firstName;
	var lastName;
	var address1;
	var city;
	var state;
	var zip;
	var mm;
	var dd;
	var yyyy;
	
	email = (document.getElementById("email").value);
	emailConfirm = (document.getElementById("emailconfirm").value);
	password = (document.getElementById("password").value);
	passwordConfirm = (document.getElementById("passwordconfirm").value);
	firstName = (document.getElementById("firstname").value);
	lastName = (document.getElementById("lastname").value);
	address1 = (document.getElementById("address1").value);
	city = (document.getElementById("city").value);
	state = (document.getElementById("state").value);
	zip = (document.getElementById("zip").value);
	mm = (document.getElementById("mm").value);
	dd = (document.getElementById("dd").value);
	yyyy = (document.getElementById("yyyy").value);
	
	alertMessage = ("Alert:\n");
	submitFlag = true;
	
	
	//****************** CHECK ALL FOR BLANKS ******************
	if (email == "") {
		document.getElementById("lblemail").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Email Address\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lblemail").style.color="#000000";
	}
	
	if (emailConfirm == "") {
		document.getElementById("lblemailconfirm").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Confirm Email Address\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lblemailconfirm").style.color="#000000";
	}
	
	if (password == "") {
		document.getElementById("lblpassword").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Password\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lblpassword").style.color="#000000";
	}
	
	if (passwordConfirm == "") {
		document.getElementById("lblpasswordconfirm").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Confirm Password\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lblpasswordconfirm").style.color="#000000";
	}
	
	if (firstName == "") {
		document.getElementById("lblfirstname").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"First Name\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lblfirstname").style.color="#000000";
	}
	
	if (lastName == "") {
		document.getElementById("lbllastname").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Last Name\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lbllastname").style.color="#000000";
	}
	
	if (address1 == "") {
		document.getElementById("lbladdress1").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Address\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lbladdress1").style.color="#000000";
	}
	
	if (city == "") {
		document.getElementById("lblcity").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"City\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lblcity").style.color="#000000";
	}
	
	if (state == "") {
		document.getElementById("lblstate").style.color="#ff0000";
		alertMessage = alertMessage + ("Please select your \"State\".\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lblstate").style.color="#000000";
	}
	
	if (zip == "") {
		document.getElementById("lblzip").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Zip Code\" textbox.\n");
		submitFlag = "No";
	}
	else {
		document.getElementById("lblzip").style.color="#000000";
	}
	
	if (document.getElementById("male").checked || document.getElementById("female").checked) {
		document.getElementById("lblgender").style.color="#000000";
	}
	else {
		document.getElementById("lblgender").style.color="#ff0000";
		alertMessage = alertMessage + ("Please select your \"Gender\".\n");
		submitFlag = "No";
	}
	
	if (mm == "") {
		document.getElementById("lbldob").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Birthdate month\" textbox.\n");
		submitFlag = "No";
	}
	
	if (dd == "") {
		document.getElementById("lbldob").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Birthdate day\" textbox.\n");
		submitFlag = "No";
	}
	
	if (yyyy == "") {
		document.getElementById("lbldob").style.color="#ff0000";
		alertMessage = alertMessage + ("Please fill in \"Birthday year\" textbox.\n");
		submitFlag = "No";
	}
	
	if (mm != "" && dd != "" && yyyy != "") {
		document.getElementById("lbldob").style.color="#000000";
	}
	
	if (document.getElementById("pp").checked && document.getElementById("tac").checked) {
		document.getElementById("lblppandtac").style.color="#ffffff";
	}
	else {
		document.getElementById("lblppandtac").style.color="#ff0000";
		alertMessage = alertMessage + ("You must check both of the \"Terms & Conditions\" boxes to continue.\n");
		submitFlag = "No";
	}
	
	
	//****************** CHECK EMAIL FORMAT ******************
	if (email == "") {
		//nothing
	}
	else {
		if (isValidEmail(email) == false) {
			document.getElementById("lblemail").style.color="#ff0000";
			alertMessage = alertMessage + ("Error: Your email does not appear to be entered in a valid format. Please try again.\n");
			submitFlag = "No";
		}
	}
	
	
	//****************** CHECK PASSWORD FORMAT ******************
	if (password == "") {
		//nothing
	}
	else {
		if (isValidPW(password) == false) {
			document.getElementById("lblpassword").style.color="#ff0000";
			alertMessage = alertMessage + ("Error: Your password does not appear to be entered in a valid format. Please try again using only letters, numbers or underscores (\"_\").\n");
			submitFlag = "No";
		}
	}
	
	
	//****************** CHECK EMAIL CONFIRM ******************
	if (email == "" || emailConfirm == "") {
		//nothing
	}
	else {
		if (email.toLowerCase() == emailConfirm.toLowerCase()) {
			//nothing
		}
		else {
			document.getElementById("lblemail").style.color="#ff0000";
			document.getElementById("lblemailconfirm").style.color="#ff0000";
			alertMessage = alertMessage + ("Error: Your email confirmation did not match your email. Please try again.\n");
			submitFlag = "No";
		}
	}
	
	
	//****************** CHECK PASSWORD CONFIRM ******************
	if (password == "" || passwordConfirm == "") {
		//nothing
	}
	else {
		if (password.toLowerCase() == passwordConfirm.toLowerCase()) {
			//nothing
		}
		else {
			document.getElementById("lblpassword").style.color="#ff0000";
			document.getElementById("lblpasswordconfirm").style.color="#ff0000";
			alertMessage = alertMessage + ("Error: Your password confirmation did not match your password. Please try again.\n");
			submitFlag = "No";
		}
	}
	
	
	//****************** SO... HOW'D IT GO? ******************
	if (submitFlag == "No") {
		alert(alertMessage);
		return(false);
	}
	else {
		return(true);
	}
	
}
