
var btnWhichButton;

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
function validatePLWID(){
    var thisForm = document.forms['plwid'];
    var petwillsTag = thisForm.petwillsTag; 
    if(petwillsTag.value.length < 5 || petwillsTag.value.length > 10){
        alert(' Pet Living Wills ID must be between 5 and 10 characters \n');
        return false;
    }else{
        return true;
        
    }
 
}
function validateSignup1(thisForm, update){
    thisForm = document.forms[thisForm];
    var email = thisForm.userEmail;
    var pass1 = thisForm.userPassword;
    var pass2 = thisForm.userPasswordRe;
    var coupon = thisForm.coupon;
    var petname = thisForm.petname;
    var pettype = thisForm.pettype;
    var firstName = thisForm.firstName;
    var lastName = thisForm.lastName;
    var address = thisForm.address;
    var city = thisForm.city;
    var state = thisForm.state;
    var zip = thisForm.zipcode;
    var phone = thisForm.phonep1;
    var petwillsTag = thisForm.petwillsTag; 
    var cardType = thisForm.cardType;
    var cardNumber = thisForm.cardNumber;
    var expMonth = thisForm.cardExpMonth;
    var expYear = thisForm.cardExpYear;
    
    var timenow = new Date();
    var billName = thisForm.billName;
    var billCVV = thisForm.billCVV
    var billAddress = thisForm.billAddress;
    var billCity = thisForm.billCity;
    var billState = thisForm.billState;
    var billZip = thisForm.billZipcode;
    
    //var petwillsTag = thisForm.petwillsTag;
    
    var termsconditions = thisForm.termsconditions;
    var returnMsg = '';
     
    if(email.value == '' || !isValidEmail(email.value)){
        alert('Please enter a valid email address');
        email.focus();
        email.select();
        return false;
    }
    if(pass1.value != '' && pass1.value.length > 0){
        // verify if 2nd password == first password
        if(pass1.value != pass2.value){
            alert("Passwords don't match, please try again");
            pass1.focus();
            pass1.select();
            return false;
        }
    } else if(update == 0){
        alert('Please enter a password');
        pass1.focus();
        pass1.select();
        return false;
    }
        
     
    
    if(firstName.value == ''){returnMsg += ' First Name is required \n';}
    
    if(lastName.value == ''){returnMsg += ' Last Name is required \n';}
    
    if(address.value == ''){returnMsg += ' Address is required \n';}
    
    if(city.value == ''){returnMsg += ' City is required \n';}
    
    if(state.value == '' || state.value == 'null'){returnMsg += ' State is required \n';}
    
    if(zip.value == ''){returnMsg += ' Zipcode is required \n';}
    
    if(phone.value == ''){returnMsg += ' Phone is required \n';}
    
    if(petwillsTag.value.length < 5 || petwillsTag.value.length > 10){
        returnMsg += ' Pet Living Wills ID must be between 5 and 10 characters \n';
    }
    
     
     if(coupon.value == ''){
        if(cardType.value == '' || cardType.value == 'null'){returnMsg += ' Card Type is required \n';}
        
        if(cardNumber.value == '' || isNaN(cardNumber.value) == true){returnMsg += ' Card Number is required \n';}
        
        if(expMonth.value == '' || expMonth.value == 'null'){returnMsg += ' Card Expiration Month is required \n';}
        
        if(expYear.value == '' || expYear.value == 'null'){returnMsg += ' Card Expiration year is required \n';}
        if(!returnMsg){
            var expdate = new Date();  
            expdate.setFullYear(expYear.value, expMonth.value,1);
        }
        if(expdate < timenow){returnMsg += ' Card Expiration is in the past \n';}
        
        if(billName.value == ''){returnMsg += ' Billing Name is required \n';}
        
        
        if(cardType.value == 'Visa' || cardType.value == 'MasterCard' ||cardType.value == 'Discover')
        {        
            if(billCVV.value == '' || billCVV.value.length != 3 || isNaN(billCVV.value) == true){
                returnMsg += ' CVV is required and must be three digits\n';
            }
            if(cardNumber.value.length != 16 && cardNumber.value.length != 13 ){
                returnMsg += ' Card Number must be 16 digits long \n';
            }
        }
        if(cardType.value == 'Amex')
        {
            if(billCVV.value == '' || billCVV.value.length != 4 || isNaN(billCVV.value) == true){returnMsg += ' CVV is required and must be four digits\n';}
            if(cardNumber.value.length != 15 ){
                returnMsg += ' Card Number must be 15 digits long \n';
            }
        }
        
        
        if(billAddress.value == ''){returnMsg += ' Billing Address is required \n';}
        
        if(billCity.value == ''){returnMsg += ' Billing City is required \n';}
        
        if(billState.value == '' || billState.value == 'null'){returnMsg += ' Billing State is required \n';}
        
        if(billZip.value == ''){returnMsg += ' Billing Zipcode is required \n';}  
    }
    
    if(termsconditions.checked == false){returnMsg += ' You have to agree with our terms and conditions if you would like to use our service \n';}  
    
    if(returnMsg != ''){
        alert('Please correct the following item(s): \n' + returnMsg);
        return false;
    }else {
        return true;
    }
}

function vetCertified(){
    var errMsg = '';
    var email = document.getElementById("vEmailAddress").value;
    var checkbox = document.getElementById("vetyes");
    if(!isValidEmail(email)){
        errMsg += "Please specify a valid email address \n";   
    }
    if(!checkbox.checked){
        errMsg += "You didn't agree with our policy \n";    
    }
    
    if(errMsg.length > 0){
        alert("The following errors occurred: \n" + errMsg);
        return false;
    } else{
        return true;
    }
    
}

function validateSecurity(){
	
	var email = document.forms.signup.userEmail;
	var pass1 = document.forms.signup.userPassword;
	var pass2 = document.forms.signup.userPasswordRe;
	// verify if email address is valid
	if(email.value != '' && isValidEmail(email.value)){
		// email is valid, let's see if the password is ok
		if(pass1.value != '' && pass1.value.length > 0){
			// verify if 2nd password == first password
			if(pass1.value == pass2.value){
				return true;
			} else {
				alert("Passwords don't match, please try again");
				pass1.focus();
				pass1.select();
				return false;
			}
		} else{
			alert('Please enter a password');
			pass1.focus();
			pass1.select();
			return false;
		}
		
	} else{
		alert('Please enter a valid email address');
		email.focus();
		email.select();
		return false;	
	}
	
	
}

function validateVetSecurity(){
      // instantiate all objects
      var thisForm = document.forms.vetSecurity;
      var name = thisForm.vetName;
      var address = thisForm.vetAddress;
      var city = thisForm.vetCity;
      var state = thisForm.vetState;
      var zip = thisForm.vetZip;
      var email = thisForm.vetEmail;
      var pw1 = thisForm.pw1;
      var pw2 = thisForm.pw2;
      var returnMsg = '';
         
      if(name.value == ''){returnMsg += ' (Business) Name is Required \n';}
                 
      if(address.value == ''){returnMsg += ' Address is Required \n';}
               
      if(city.value == ''){returnMsg += ' City is Required \n';}
      
      if(state.value == '' || state.value == 'none'){returnMsg += ' State is Required \n';}
       
      if(zip.value == ''){returnMsg += ' Zip Code is Required \n';}
            
      if(email.value == '' || !isValidEmail(email.value)){returnMsg += ' Valid Email Address is Required \n';} 
      
      if(pw1.value == ''){returnMsg += ' Password is Required \n';}
      
      if(returnMsg != ''){
		alert('Please correct the following item(s): \n' + returnMsg);
		return false;
	  }else {
		if(pw1.value == pw2.value){
			return true
		} else {
			alert('Passwords do not match, please try again');
			return false;
	  	}
	  } 
}

function validateRep(thisForm, context){
    var firstName   = thisForm.firstName;
    var lastName    = thisForm.lastName;
    var email      = thisForm.email;
    var email2      = thisForm.email2; 
    var password1   = thisForm.password1; 
    var password2   = thisForm.password2; 
    var account_id  = thisForm.account_id;
    
    
    var returnMsg = '';
          
    if(firstName.value == ''){returnMsg += ' First Name is required \n';}
    if(lastName.value == ''){returnMsg += ' Last Name is required \n';}
    if(email.value == '' || !isValidEmail(email.value)){returnMsg += ' Valid Email Address is Required \n';} 
    if(email2.value != email.value){returnMsg += ' Email Addresses don\'t match \n';}
    if(context != 'repChangesRep' && context != 'vetChangesRep'){   
        if(password1.value == ''){returnMsg += ' Password is required \n';}             
        if(password2.value != password1.value){returnMsg += ' Passwords don\'t match \n';}
    }
    if(account_id.value == ''){returnMsg += ' Pet Living Wills Partner Account # is Required \n';}
    
    if(returnMsg.length > 0){
        alert("The following errors occurred: \n" + returnMsg);
        return false;
    } else{
        return true;
    }
    
    
     
}

function validateCaregiver(thisForm, update){
    var email = thisForm.userEmail;
    var pass1 = thisForm.userPassword;
    var pass2 = thisForm.userPasswordRe;
    var oldpass = thisForm.userPasswordOld;
    var firstName = thisForm.firstName;
    var lastName = thisForm.lastName;
    var businessName = thisForm.businessName;
    var accountType = thisForm.accountType;
    var other_type = thisForm.other_type;
    var businessName = thisForm.businessName;
    var address = thisForm.address;
    var city = thisForm.city;
    var state = thisForm.state;
    var zipcode = thisForm.zipcode;
    var phone1 = thisForm.phonep1;
    var phone2 = thisForm.phonep2;
    var phone3 = thisForm.phonep3;
    var phone = phone1.value + phone2.value + phone3.value;  
    var termsconsent = thisForm.termsconsent;
    
    var returnMsg = '';
    
    // verify if email address is valid
    if(email.value == '' || !isValidEmail(email.value)){returnMsg += ' Email is not valid \n';} 
    
    if(update == 0 || pass1.value != ''){
        if(update){
            if(oldpass.value == '' || oldpass.value.length < 1){returnMsg += ' Old Password is required \n';}
        }
        if(pass1.value == '' || pass1.value.length < 1){returnMsg += ' Password is required \n';}
        if(pass2.value == '' || pass2.value.length < 1){returnMsg += ' Re-enter Password is required \n';}
        if(pass1.value != pass2.value){returnMsg += ' Passwords don\'t match \n';} 
    } 
           
    if(firstName.value == ''){returnMsg += ' First Name is required \n';}
    
    if(lastName.value == ''){returnMsg += ' Last Name is required \n';}
        
    if(businessName.value == ''){returnMsg += ' Business Name is required \n';}
    
    if(accountType.value == '0'){returnMsg += ' Business Type is required \n';}
        
    if(accountType.value == '99'){
        if(other_type.value == ''){returnMsg += ' Business Type Description is required if you pick "other" \n';}
    }
    
    if(address.value == ''){returnMsg += ' Address is required \n';}
    
    if(city.value == ''){returnMsg += ' City is required \n';}
    
    if(state.value == '' || state.value == 'null'){returnMsg += ' State is required \n';}
    
    if(zipcode.value == ''){returnMsg += ' Zipcode is required \n';}
    
    if(phone == ''){returnMsg += ' Phone is required \n';}
                                                                                 
    if(termsconsent.value == ''){returnMsg += ' Terms and Conditions consent is required \n';}
    
    
        
    if(returnMsg != ''){
        alert('Please correct the following item(s): \n' + returnMsg);
        return false;
    }else {
        return true;
    }
    
}

function validateReferConsent(thisForm){
    var termsconsent = thisForm.termsconsent;
    var returnMsg = '';
    if(termsconsent.value == ''){returnMsg += ' Terms and Conditions consent is required \n';}
    if(returnMsg != ''){
        alert(returnMsg);
        return false;
    }else {
        return true;
    }
}

function validateCaredetails(){  
    if(btnWhichButton.value == 'Finish Later'){
        return true;
    } 
    var recoveryFields = new Array('nowLikely', 'ongoingLikely', 'nowPartial', 'ongoingPartial', 'nowUnlikely', 'ongoingUnlikely', 'nowVeryUnlikely', 'ongoingVeryUnlikely', 'nowPalliative');
    for(i=0;i<recoveryFields.length;i++){
        
        
        var field = document.forms.signup[recoveryFields[i]];
        
        if(field.value == 'false'){
            alert('You have to select a value for each field');
            field.focus();
            return false;    
        }else if(field.value == 'custom'){
            otherfieldname = recoveryFields[i] + 'Other';
            var otherfield = document.forms.signup[otherfieldname];
            if(otherfield.value == '' || !validateNumber(otherfield, 'nomsg', 0, 999999999999999999)){
                alert('If you select \'other\' you need to specify a custom amount, and it needs to be numeric');
                otherfield.focus();
                return false; 
            }
        }
    }
    return true;
            
}

function validateDeathdetails(){
	if(btnWhichButton.value == 'Finish Later'){
        return true;
    } 
    var remains = document.forms.signup.carecremains;
	var burial = document.forms.signup.careburial;
	var items = document.forms.signup.caretoyhandling;

	
	// validate pet remains
	if(remains.value == ''){
		alert('What would you like done with the remains is a required field');
		remains.focus();
		return false;
	}
	// validate pet burial arrangements
	if(burial.value == ''){
		alert('Burial Arrangements is a required field');
		burial.focus();
		return false;
	}
	//validate pet effects
	if(items.value == ''){
		alert('What would you like to be done with your pets effects  is a required field');
		items.focus();
		return false;
	}

	
	return true;
}

function validateVetdetails(){
	var vetfirstname = document.forms.signup.firstName;
	var vetlastname = document.forms.signup.lastName;
	var clinicname = document.forms.signup.clinicName;
	var vetaddress = document.forms.signup.address;
	var vetcity = document.forms.signup.city;
	var vetzipcode = document.forms.signup.zipcode;
	var vetareacode = document.forms.signup.phonep1;
	var vetphonethree = document.forms.signup.phonep2;
	var vetphonefour = document.forms.signup.phonep3;

	
	// validate vet firstname
	if(vetfirstname.value == ''){
		alert('Vets first name is a required field');
		vetfirstname.focus();
		return false;
	}
	// validate vet lastname
	if(vetlastname.value == ''){
		alert('Vets last name is a required field');
		vetlastname.focus();
		return false;
	}
	if(clinicname.value == ''){
		alert('Clinic name is a required field');
		clinicname.focus();
		return false;
	}
	if(vetaddress.value == ''){
		alert('Vets Address is a required field');
		vetaddress.focus();
		return false;
	}
	if(vetcity.value == ''){
		alert('Vets city is a required field');
		vetcity.focus();
		return false;
	}
	if(vetzipcode.value == '' || vetzipcode.value.length != 5 || isNaN(vetzipcode.value) == true){
		alert('Vets zip code is a required field and must be five digits long');
		vetzipcode.focus();
		return false;
	}
	
	if(vetareacode.value == '' || vetareacode.value.length != 3 || isNaN(vetareacode.value) == true){
		alert('Vets areacode is a required field and must be three digits long');
		vetareacode.focus();
		return false;
	}
	
	if(vetphonethree.value == '' || vetphonefour.value == '' || vetphonethree.value.length != 3 || vetphonefour.value.length != 4 || isNaN(vetphonefour.value) == true || isNaN(vetphonethree.value) == true){
		alert('Vets Phone is a required field and must be seven digits long');
		vetphonethree.focus();
		return false;
	}
	
		return true;
}


function validateAddPet(){
    if(btnWhichButton.value == 'Finish Later'){
        return true;
    } 
	var petName = document.forms.signup.petname;
	var petType = document.forms.signup.pettype;
	var breed = document.forms.signup.petprimarybreed;
	//added by Wes Jones
	var birthday = document.forms.signup.petbirthdate;
	var petage = document.forms.signup.petage;
	var picture = document.forms.signup.petPicture;
	var description = document.forms.signup.petownernotephys;
	
	// validate pet name
	if(petName.value == ''){
		alert('Pet name is a required field');
		petName.focus();
		petName.select();
		return false;
	}
	// validate pet type
	if(petType.value == 'nochoice'){
		alert('Animal Type is a required field');
		petType.focus();
		return false;
	}
	
	//validate breed 
	if(petType.value == 'dog' || petType.value == 'cat')
	{
		if(breed.value == '0'){
			alert('Animal Breed is a required field');
			breed.focus();
			return false;
		}
	}
	
	
	if(description.value == ''){
		alert('Animal description is a required field');
		description.focus();
		return false;
	}		
	
	
	//validate age or birthday
	if(petage.value == ''){
		alert('Animal Age is a required field');
		petage.focus();
		return false;
	}
		
	if(picture.value != ''){
		
		var myRegExp = /.png|.gif|.jpg|.PNG|.GIF|.JPG/;
		//alert(picture.value.search(myRegExp));
		if(picture.value.search(myRegExp) < 0)
		{
			alert('Picture must be a png, gif, or a jpg');
			picture.focus();
			return false;
		}
	}	
	
	return true;
}

function checkpettype()
{
	//alert('I am here');
	var petType = document.forms.signup.pettype;
	
	if(petType.value == 'dog' || petType.value == 'cat')
	{
		//alert(petType.value);
		petbreed.style.color = 'red';
		petnotes.style.color = 'black';
		petnotestyle.style.display = 'none';
	}
	else
	{
		//alert(petType.value);
		petnotes.style.color = 'red';
		petbreed.style.color = 'black';	
		petnotestyle.style.display = 'inline';	
	}	
}




function validateOwner(review){
	if(btnWhichButton.value == 'Finish Later'){
        return true;
    } 
    
    var thisForm = document.forms.signup;
	var firstName = thisForm.firstName;
	var lastName = thisForm.lastName;
	var address = thisForm.address;
	var city = thisForm.city;
	var state = thisForm.state;
	var zip = thisForm.zipcode;
	var phone = thisForm.phonep1;
	var cardType = thisForm.cardType;
	var cardNumber = thisForm.cardNumber;
	var expMonth = thisForm.cardExpMonth;
	var expYear = thisForm.cardExpYear;
    var expdate = new Date();  
    expdate.setFullYear(expYear.value,expMonth.value,1);
    var timenow = new Date();
	var billName = thisForm.billName;
	var billCVV = thisForm.billCVV
	var billAddress = thisForm.billAddress;
	var billCity = thisForm.billCity;
	var billState = thisForm.billState;
	var billZip = thisForm.billZipcode;
    var CCUpdate = thisForm.CCUpdate;
    var petwillsTag = thisForm.petwillsTag;
    var coupon = thisForm.coupon;
    var termsconditions = thisForm.termsconditions;
    
	var returnMsg = '';
	      
	if(firstName.value == ''){returnMsg += ' First Name is required \n';}
	
	if(lastName.value == ''){returnMsg += ' Last Name is required \n';}
	
	if(address.value == ''){returnMsg += ' Address is required \n';}
	
	if(city.value == ''){returnMsg += ' City is required \n';}
	
	if(state.value == '' || state.value == 'null'){returnMsg += ' State is required \n';}
	
	if(zip.value == ''){returnMsg += ' Zipcode is required \n';}
	
	if(phone.value == ''){returnMsg += ' Phone is required \n';}
    
    if(petwillsTag.value.length < 5 || petwillsTag.value.length > 10){
        returnMsg += ' Pet Living Wills ID must be between 5 and 10 characters \n';
    }
	
     
	 if((review != 1 || CCUpdate.value == 1) && document.getElementById("CCInfo").style.display != "none" && coupon.value == ''){
        if(cardType.value == '' || cardType.value == 'null'){returnMsg += ' Card Type is required \n';}
	    
	    if(cardNumber.value == '' || isNaN(cardNumber.value) == true){returnMsg += ' Card Number is required \n';}
	    
	    if(expMonth.value == '' || expMonth.value == 'null'){returnMsg += ' Card Expiration Month is required \n';}
	    
	    if(expYear.value == '' || expYear.value == 'null'){returnMsg += ' Card Expiration year is required \n';}
	    
        if(expdate < timenow){returnMsg += ' Card Expiration is in the past \n';}
        
	    if(billName.value == ''){returnMsg += ' Billing Name is required \n';}
	    
	    
		if(cardType.value == 'Visa' || cardType.value == 'MasterCard' ||cardType.value == 'Discover')
		{	    
	    	if(billCVV.value == '' || billCVV.value.length != 3 || isNaN(billCVV.value) == true){
                returnMsg += ' CVV is required and must be three digits\n';
            }
            if(cardNumber.value.length != 16 && cardNumber.value.length != 13 ){
                returnMsg += ' Card Number must be 16 digits long \n';
            }
		}
		if(cardType.value == 'Amex')
		{
	    	if(billCVV.value == '' || billCVV.value.length != 4 || isNaN(billCVV.value) == true){returnMsg += ' CVV is required and must be four digits\n';}
            if(cardNumber.value.length != 15 ){
                returnMsg += ' Card Number must be 15 digits long \n';
            }
		}
	    
	    
	    if(billAddress.value == ''){returnMsg += ' Billing Address is required \n';}
	    
	    if(billCity.value == ''){returnMsg += ' Billing City is required \n';}
	    
	    if(billState.value == '' || billState.value == 'null'){returnMsg += ' Billing State is required \n';}
	    
	    if(billZip.value == ''){returnMsg += ' Billing Zipcode is required \n';}
        
        if(termsconditions.checked == false){returnMsg += ' You have to agree with our terms and conditions if you would like to use our service \n';}
    } else if(coupon.value != ''){
        if(termsconditions.checked == false){returnMsg += ' You have to agree with our terms and conditions if you would like to use our service \n';}
    }
		
	if(returnMsg != ''){
		alert('Please correct the following item(s): \n' + returnMsg);
		return false;
	}else {
		return true;
	}
	
}
function validateOwnerUpdate(){
    var thisForm = document.forms.signup;
    var firstName = thisForm.firstName;
    var lastName = thisForm.lastName;
    var address = thisForm.address;
    var city = thisForm.city;
    var state = thisForm.state;
    var zip = thisForm.zipcode;
    var phone = thisForm.phonep1;
    
    
    var returnMsg = '';
          
    if(firstName.value == ''){returnMsg += ' First Name is required \n';}
    
    if(lastName.value == ''){returnMsg += ' Last Name is required \n';}
    
    if(address.value == ''){returnMsg += ' Address is required \n';}
    
    if(city.value == ''){returnMsg += ' City is required \n';}
    
    if(state.value == '' || state.value == 'null'){returnMsg += ' State is required \n';}
    
    if(zip.value == ''){returnMsg += ' Zipcode is required \n';}
    
    if(phone.value == ''){returnMsg += ' Phone is required \n';}
     
        
    if(returnMsg != ''){
        alert('Please correct the following item(s): \n' + returnMsg);
        return false;
    }else {
        return true;
    }
    
}

function validateNumber(field, msg, min, max){
	
	if (!min) { min = 0 }
	if (!max) { max = 100 } 
	if (!msg || msg == ''){
		msg = 'Only numeric values are allowed';
	}
	if(field.value != '' && (parseInt(field.value) != field.value || field.value.length < min || field.value.length > max)){
		if(msg != 'nomsg'){alert(msg)};
		field.focus();
		field.select();
		return false;
	} else {
		return true;
	}
}

function validateGift(type){
    
    var amt = document.forms.gift.amount;
    
    var to_name = document.forms.gift.to_name;
    var from_email = document.forms.gift.from_email;
    var from_name = document.forms.gift.from_name; 
    var message = document.forms.gift.message;
    
    
    if(amt.value == 0){
        alert('You need to select an amount');
        amt.focus(); 
        return false;     
    } else if(type == 'egift'){
        var to_email = document.forms.gift.to_email; 
        if(to_email.value == '' || !isValidEmail(to_email.value)){
        alert('Recipient e-mail is invalid');
        to_email.focus(); 
        return false;
        }
    } else if(message.value.length>300){
        alert('Message can only contain 300 characters');
        message.focus();
        return false;
    }else{
     return true; 
    }
    
}

function validateGiftCC(){
    var cardType = document.forms.giftCC.cardType;
    var cardNumber = document.forms.giftCC.cardNumber;
    var expMonth = document.forms.giftCC.cardExpMonth;
    var expYear = document.forms.giftCC.cardExpYear;
    var expdate = new Date();  
    expdate.setFullYear(expYear.value,expMonth.value,1);
    var timenow = new Date();
    var billCVV = document.forms.giftCC.billCVV;
    var billName = document.forms.giftCC.billName;
    var billAddress = document.forms.giftCC.billAddress;
    var billCity = document.forms.giftCC.billCity;
    var billState = document.forms.giftCC.billState;
    var billZip = document.forms.giftCC.billZipcode;
    var returnMsg = '';
    
    if(cardType.value == '' || cardType.value == 'null'){returnMsg += ' Card Type is required \n';}
    
    if(cardNumber.value == '' || isNaN(cardNumber.value) == true){returnMsg += ' Card Number is required \n';}
    
    if(expMonth.value == '' || expMonth.value == 'null'){returnMsg += ' Card Expiration Month is required \n';}
    
    if(expYear.value == '' || expYear.value == 'null'){returnMsg += ' Card Expiration year is required \n';}
    
    if(expdate < timenow){returnMsg += ' Card Expiration is in the past \n';}
    
    if(billName.value == ''){returnMsg += ' Billing Name is required \n';}
    
    if(cardType.value == 'Visa' || cardType.value == 'MasterCard' ||cardType.value == 'Discover')
    {        
        if(billCVV.value == '' || billCVV.value.length != 3 || isNaN(billCVV.value) == true){
            returnMsg += ' CVV is required and must be three digits\n';
        }
        if(cardNumber.value.length != 16 && cardNumber.value.length != 13 ){
            returnMsg += ' Card Number must be 16 digits long \n';
        }
    }
    if(cardType.value == 'Amex')
    {
        if(billCVV.value == '' || billCVV.value.length != 4 || isNaN(billCVV.value) == true){returnMsg += ' CVV is required and must be four digits\n';}
        if(cardNumber.value.length != 15 ){
            returnMsg += ' Card Number must be 15 digits long \n';
        }
    }
    
    if(billAddress.value == ''){returnMsg += ' Billing Address is required \n';}
    
    if(billCity.value == ''){returnMsg += ' Billing City is required \n';}
    
    if(billState.value == '' || billState.value == 'null'){returnMsg += ' Billing State is required \n';}
    
    if(billZip.value == ''){returnMsg += ' Billing Zipcode is required \n';}
    
    if(returnMsg != ''){
        alert('Please correct the following item(s): \n' + returnMsg);
        return false;
    }else {
        return true;
    }
}


