function clearField1() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
    document.form1.Card_1_Number.value = '';
}
function clearField2() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
    document.form1.Card_2_Number.value = '';
}
function clearField3() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
    document.form1.Card_3_Number.value = '';
}

function clearEmail() {
    document.form1.Contact_Email.value = '';
}

function clearFormerLastName() {
    document.form1.Contact_FormerLastName.value = '';
}

function checkReason() {
if (document.form1.Reason.value.length != 1) {
      alert("Please indicate what would you like us to do for you.");
document.form1.Reason.focus();
document.form1.Reason.selectedIndex = 1;
      return false;
      }
if (document.form1.Contact_Card.value == ' Enter your 10-digit AdvantEdge Card number, if known') {
     document.form1.Contact_Card.value = '';
      }
   return true;

}

function checkMiddleInitial() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if (document.form1.Contact_MiddleInitial.value == ' Middle Initial') {
     document.form1.Contact_MiddleInitial.value = '';
      return false;
      }
	midname = document.form1.Contact_MiddleInitial.value;
	midInitial= midname.substring(0,1);
	document.form1.Contact_MiddleInitial.value = midInitial;
if (document.form1.Contact_LastName.value== ' Last Name*') {
	document.form1.Contact_LastName.value = '';
	}
return true
 }

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid email address.")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid email address.")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid email address.")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid email address.")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid email address.")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid email address.")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid email address.")
		    return false
		 }

 		 return true					
	}

function ValidateEmail(){
	var emailID=document.form1.Contact_Email
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	
	if ((emailID.value==null)||(emailID.value=="")||(emailID.value==" Email Address")){
	document.form1.Contact_Email.value = '';
	if (document.form1.Contact_HomePhone.value == ' Home Phone'){
	document.form1.Contact_HomePhone.value = '';
	}
return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
if (document.form1.Contact_HomePhone.value == ' Home Phone'){
	document.form1.Contact_HomePhone.value = '';
	}
	return true
 }
 
 // Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length == minDigitsInIPhoneNumber);
}

function ValidatePhone(){
	var Phone=document.form1.Contact_HomePhone
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	
if ((checkInternationalPhone(Phone.value)==false) && (Phone.value!="")){
		alert("Please enter a valid 10-digit phone number including area code.")
		Phone.value=""
		Phone.focus()
		return false
	}
	document.form1.Contact_HomePhone.value = s
	document.form1.License_Number.value = ""
	return true
 }
 
 function ValidateFirstName(){
	var FirstName=document.form1.Contact_FirstName
	if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	if ((FirstName.value==null)||(FirstName.value=="")||(FirstName.value==" First Name*")){
		alert("Please enter your legal first name.")
		FirstName.focus();
    	document.form1.Contact_FirstName.value = '';
		return false
	}
	if (document.form1.Contact_MiddleInitial.value== ' Middle Initial') {
	document.form1.Contact_MiddleInitial.value = '';
	}
return true
 }


function ValidateLastName(){
	var LastName=document.form1.Contact_LastName
	if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	if ((LastName.value==null)||(LastName.value=="")||(LastName.value==" Last Name*")){
		alert("Please enter your current legal last name.")
		LastName.focus();
    	document.form1.Contact_LastName.value = '';
		return false
	}
	if (document.form1.Contact_FormerLastName.value== ' Former Last Name') {
	document.form1.Contact_FormerLastName.value = '';
	}
return true
}

function ValidateFormerLastName(){
	var FormerLastName=document.form1.Contact_FormerLastName
	var LastName=document.form1.Contact_LastName
	if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	if ((LastName.value=="")||(LastName.value==" Last Name*")){
		alert("Please enter your current legal last name.")
		LastName.focus();
    	document.form1.Contact_LastName.value = '';
		return false
	}
	if (document.form1.Contact_FormerLastName.value== ' Former Last Name') {
	document.form1.Contact_FormerLastName.value = '';
	}
	document.form1.Contact_StreetAddress.value = '';
return true
}


function ValidateStreetAddress(){
	var StreetAddress=document.form1.Contact_StreetAddress
	if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	
	if ((StreetAddress.value==null)||(StreetAddress.value=="")||(StreetAddress.value==" Street Address*")){
		alert("Please enter your street address.")
		StreetAddress.focus();
    	document.form1.Contact_StreetAddress.value = '';
	}
	if (document.form1.Contact_AptNumber.value==" Floor or Apt. #"){
    	document.form1.Contact_AptNumber.value = '';
    return false
	}
return true
 }
 
function ValidateAptNumber(){
	var AptNumber=document.form1.Contact_AptNumber
	if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	if (AptNumber.value==" Floor or Apt. #"){
    	document.form1.Contact_AptNumber.value = '';
	}
	if (document.form1.Contact_City.value==" City*"){
    	document.form1.Contact_City.value = '';
    	return false
	}
return true
 }

function ValidateCity(){
	var City=document.form1.Contact_City
	
	if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	if ((City.value==null)||(City.value=="")||(City.value==" City*")){
		alert("Please enter your city.")
		City.focus();
    	City.value = '';
		return false
	}
return true
 }
 
  function ValidateState(){
	var State=document.form1.Contact_State
 	var City=document.form1.Contact_City
	
	if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
	if ((State.value==null)||(State.value=="")||(City.value=="")||(City.value==null)){
		alert("Please enter a city and select a state.")
		City.focus();
    	City.value = '';
		return false
	}
	if (document.form1.Contact_ZipCode.value== ' ZIP/Postal Code*') {
	document.form1.Contact_ZipCode.value = '';
	}
return true
 }
 
 
function sendtoinformz()
{
        var e= document.form1.Contact_Email
         if ((e.value!= '')  || (e.value.length > 5))
        {
        
window.open("http://www.informz.net/pricechopper/default.asp?action=autosubscribe&formats=3&returnUrl=http://www2.pricechopper.com/service/response2.html&interests=187,150,186,185,289,290,183,195&brandid=55&pid=68&personal=card_form&email="+e.value,'newWindow','scrollbars=no,status=no,width=250,height=250')
        }
        return true;
}

function checkchars(){
//change max length to determine below
var maxlength=10
var minlength=0
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if (document.form1.Contact_Card.value == " Enter your 10-digit AdvantEdge Card number, if known") {
document.form1.Contact_Card.value = '';
}

if ((document.form1.Contact_Card.value.length!=maxlength) && (document.form1.Contact_Card.value.length!=minlength)) {
alert("The AdvantEdge Card Number field requires 10 digits. If your card has fewer digits, use leading zeros. If you don't have a card and only have a key tag, contact our Guest Services department at 1 (800) 666-7667.")
		document.form1.Contact_Card.focus();
return false
}
if (document.form1.Contact_FirstName.value==" First Name*"){
    	document.form1.Contact_FirstName.value = '';
    	return false
	}
return true
 }


function checkZip() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if (document.form1.Contact_State.value.length != 2) {
	document.form1.Contact_State.focus();
return false
}

if ((document.form1.Contact_State.value == "ON") || (document.form1.Contact_State.value == "AB") || 
(document.form1.Contact_State.value == "BC") || 
(document.form1.Contact_State.value == "MB") || 
(document.form1.Contact_State.value == "NB") || 
(document.form1.Contact_State.value == "NL") || 
(document.form1.Contact_State.value == "NT") || 
(document.form1.Contact_State.value == "NS") || 
(document.form1.Contact_State.value == "NU") || 
(document.form1.Contact_State.value == "PE") || 
(document.form1.Contact_State.value == "QC") || 
(document.form1.Contact_State.value == "SK") || 
(document.form1.Contact_State.value == "YT")) {
if (document.form1.Contact_ZipCode.value.length != 6)

{
      alert("Please provide a six-character\nCanadian postal code\nwithout any blank spaces or dashes,\n such as N4A3B3.");
document.form1.Contact_ZipCode.focus();
      return false;
      }
   return true;

}
if (document.form1.Contact_ZipCode.value.length != 5)

{
      alert("Please provide a five-character\nU.S. ZIP code\nwithout blank spaces or dashes,\nsuch as 12345.");
document.form1.Contact_ZipCode.focus();
      return false;
      }
if(document.form1.Contact_HomePhone.value == " Home Phone") {
document.form1.Contact_HomePhone.value = "";
return true
}
}

function checkBdayMonth() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if ((document.form1.Birthday_Month.value.length != 2) || (document.form1.Birthday_Day.value.length != 2)) {
      alert("You must provide either an AdvantEdge Card number or complete driver's license information.");
document.form1.Birthday_Month.focus();
      return false;
      }
   return true;

}


function checkBdayDay() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if ((document.form1.Contact_Card.value.length != 10) && (document.form1.Birthday_Day.value.length != 2)) {
      alert("You must provide either an AdvantEdge Card number or complete driver's license information.");
document.form1.Birthday_Day.focus();
      return false;
      }
document.form1.Birthday_Year.value = '';
   return true;

}

function checkBdayYear() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
else if (document.form1.Birthday_Year.value == ' Birthday Year') {
document.form1.Birthday_Year.value = '';
return true;
	}
else if ((document.form1.Birthday_Year.value < (1910 - 0)) || (document.form1.Birthday_Year.value > (2000 - 0))) {
      alert("Please enter birthday year as 4 digit number.");
document.form1.Birthday_Year.focus();
      return false;
      }
   return true;
}

function checkLicenseNumber() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if ((document.form1.Contact_Card.value.length != 10) && ((document.form1.License_Number.value == '')|| (document.form1.License_Number.value.length <= 4)|| (document.form1.License_Number.value.length >= 19)|| (document.form1.License_Number.value == ' License Number'))) {
      alert("You must provide either an AdvantEdge Card number or complete driver's license information.");
document.form1.License_Number.focus();
document.form1.License_Number.value = '';
return false;
      }
if ((document.form1.Contact_Card.value.length != 10) && ((document.form1.License_Number.value != '')||(document.form1.License_Number.value != ' License Number'))&&(document.form1.License_State.value.length != 2)) {
      alert("You must provide either an AdvantEdge Card number or complete driver's license information.");
document.form1.License_State.focus();
	return false;
      }
   return true;

}

function clearYear() {
document.form1.Birthday_Year.value = '';
}


function checkLicenseState() {
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if ((document.form1.Contact_Card.value.length != 10) && (document.form1.License_State.value.length != 2)) {
      alert("You must provide either an AdvantEdge Card number or complete driver's license information.");
document.form1.License_State.focus();
      return false;
      }
   return true;

}



function checkFamcards1(){
//change max length to determine below
var maxlength=10
var minlength=0
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if ((document.form1.Card_1_Number.value.length!=maxlength) && (document.form1.Card_1_Number.value.length!=minlength)) {
alert("The AdvantEdge Card Number field requires 10 digits. If your family member's card has fewer digits, use leading zeros. If your family member only has a key tag, contact our Guest Services department at 1 (800) 666-7667, Option 1.")
return false
}
document.form1.Card_1_Name.value = ""
return true
}

function checkFamcards2(){
//change max length to determine below
var maxlength=10
var minlength=0
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if ((document.form1.Card_2_Number.value.length!=maxlength) && (document.form1.Card_2_Number.value.length!=minlength)) {
alert("The AdvantEdge Card Number field requires 10 digits. If your family member's card has fewer digits, use leading zeros. If your family member only has a key tag, contact our Guest Services department at 1 (800) 666-7667, option 1.")
return false
}
document.form1.Card_2_Name.value = ""
return true
}

function checkFamcards3(){
//change max length to determine below
var maxlength=10
var minlength=0
if (document.form1.Reason.value.length != 1) {
	alert("Please tell us what you'd like us to do for you.")
		document.form1.Reason.focus();
		return false
		}
if ((document.form1.Card_3_Number.value.length!=maxlength) && (document.form1.Card_3_Number.value.length!=minlength)) {
alert("The AdvantEdge Card Number field requires 10 digits. If your family member's card has fewer digits, use leading zeros. If your family member only has a key tag, contact our Guest Services department at 1 (800) 666-7667, option 1.")
return false
}
document.form1.Card_3_Name.value = ""
return true
}

function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
}   


function checkAll() {
if ((document.form1.Reason.value.length != 1) || (document.form1.Contact_FirstName.value == '') || (document.form1.Contact_FirstName.value == ' First Name*') || (document.form1.Contact_LastName.value == '') || (document.form1.Contact_LastName.value == ' Last Name*') || (document.form1.Contact_StreetAddress.value == '') || (document.form1.Contact_StreetAddress.value == ' Street Address*') || (document.form1.Contact_State.value.length != 2) || (document.form1.Contact_ZipCode.value == '') || (document.form1.Contact_ZipCode.value == ' ZIP/Postal Code*')) {
alert("Some required information is missing. Please check your form and resubmit.");
return false;
}
if ((document.form1.Contact_Card.value.length != 10) && ((document.form1.License_Number.value == '') || (document.form1.License_Number.value == ' License Number') || (document.form1.License_State.value.length != 2))) {
      alert("You must provide either an AdvantEdge Card number or complete driver's license information, including your license number.");
document.form1.Contact_Card.focus();
      return false;
      }
if (document.form1.Contact_MiddleInitial.value == ' Middle Initial') {
     document.form1.Contact_MiddleInitial.value = '';
      }
	midname = document.form1.Contact_MiddleInitial.value;
	midInitial= midname.substring(0,1);
	document.form1.Contact_MiddleInitial.value = midInitial;

if (document.form1.Contact_Card.value == ' Enter your 10-digit AdvantEdge Card number, if known') {
     document.form1.Contact_Card.value = '';
      }
if (document.form1.Contact_AptNumber.value == ' Floor or Apt. #') {
     document.form1.Contact_AptNumber.value = '';
      }
if (document.form1.Contact_Email.value == ' Email Address') {
     document.form1.Contact_Email.value = '';
      }
if (document.form1.Birthday_Year.value == ' Birthday Year') {
     document.form1.Birthday_Year.value = '';
      }
if (document.form1.License_Number.value == ' License Number') {
     document.form1.License_Number.value = '';
      }
if (document.form1.Card_1_Number.value == ' Card Number') {
     document.form1.Card_1_Number.value = '';
      }
if (document.form1.Card_2_Number.value == ' Card Number') {
     document.form1.Card_2_Number.value = '';
      }
if (document.form1.Card_3_Number.value == ' Card Number') {
     document.form1.Card_3_Number.value = '';
      }
if (document.form1.Card_1_Name.value == ' Cardholder Name') {
     document.form1.Card_1_Name.value = '';
      }
if (document.form1.Card_2_Name.value == ' Cardholder Name') {
     document.form1.Card_2_Name.value = '';
      }
if (document.form1.Card_3_Name.value == ' Cardholder Name') {
     document.form1.Card_3_Name.value = '';
      }
document.form1.Contact_HomePhone.value = s
for (var i=0; i<what.elements.length;i++) {
        if (what.elements[i].name.indexOf('text') != -1)
            what.elements[i].value = replace(replace(what.elements[i].value,'\r',' '),'\n',' ');
}
      

return true;
}