// JavaScript Document Schiele Museum



//////////////////////////////////////////////////////////////////////////////////////////////////////
// CSS Dropdown Navigation for IE6-
startList = function(){
	if(document.all&&document.getElementById){
		navRoot = document.getElementById("nav");
		for(i=0; i<navRoot.childNodes.length; i++){
			node = navRoot.childNodes[i];
			if(node.nodeName=="LI"){
				node.onmouseover=function(){
					this.className+=" over";
				}
				node.onmouseout=function(){
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
	if(location.href == 'https://www.schielemuseum.org/membership_application.php'){checkState();}
}
window.onload=startList;



//////////////////////////////////////////////////////////////////////////////////////////////////////
// for older browsers that do not support Array.push method
if(typeof Array.prototype.push == "undefined")
  Array.prototype.push = function(){
    var i=0;
    b=this.length,a=arguments;
    for(i;i<a.length;i++)this[b+i]=a[i];
    return this.length
  }



//////////////////////////////////////////////////////////////////////////////////////////////////////
//E-commerce form logic





//////////////////////////////////////////////////////////////////////////////////////////////////////
//Validation for Forms
var returnVal;
var highlight; // highlight errors variable
var errorHighlight = new Array(); // collects input error to print in alert
var checkBoxFields; //used for checkboxes

function valForm(id){
	var obj; //form id
	var flag; //error flag
	var checked = new Array(); //use when php has checkbox field set with "[]" at end of name
	var error = new Array(); //holds error messsages 
	var regEmail = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/; //regex to test email
	var regNum = /^([0-9]+)$/; //regex to test fields which contain only numbers (phone, zip)
	var showErrorHighlight; //set to 1 in switch statement if you want to highlight fields that have errors
	
	//clear fields of highlight color
	if(highlight == 1){
		for(i=0; i<errorHighlight.length; i++){
			if(errorHighlight[i] == checkBoxFields){
				errorHighlight[i].style.backgroundColor = "#ffff33"; //set to background color of form
			}
			else{errorHighlight[i].style.backgroundColor = "#ffffff";} //set to background color of input tags
		}
		errorHighlight = new Array(); //reset array
	}
	
	//determine which form on website is to be validated
	var formId = document.getElementById(id).getAttribute('id');
 	switch(formId){
		case 'enews_registration':
			obj = document.getElementById(formId);
			showErrorHighlight = 1;
			validateENews();
			break;
		case 'rental_registration':
			obj = document.getElementById(formId);
			showErrorHighlight = 1;
			validateRentals();
			break;
		case 'education_registration':
			obj = document.getElementById(formId);
			showErrorHighlight = 1;
			validateEduReg();
			break;
		case 'member':
			obj = document.getElementById(formId);
			showErrorHighlight = 1;
			validateMembership();
			break;
	}

	//set error highlight on form field and add to error array for removal
	function setErrorHighlight(formFieldId){
		if(showErrorHighlight == 1){
			formFieldId.style.backgroundColor = "#ffff33"; //highlight color
			errorHighlight.push(formFieldId);
		}
	}

	// validate email
	function validateEmail(email,emailValue,customMessage){		
		if(emailValue == ''){
			if(customMessage){
				emailMes = customMessage;
			}
			else{
				emailMes = "Please enter a valid email address.";
			}
			error.push(emailMes);
			setErrorHighlight(email);
			flag = 1;
			return;
		}
		if(!emailValue.match(regEmail)){
			if(customMessage){
				emailMes = customMessage;
			}
			else{
				emailMes = "Please verify the email address you entered.";
			}
			error.push(emailMes);
			setErrorHighlight(email);
			flag = 1;
			return;
		}
	}


	// validate zip code
	function validateZip(zip,zipValue,customMessage){
		if(zipValue == ''){
			if(customMessage){
				zipMes = customMessage;
			}
			else{
				zipMes = "Please enter your zip code.";
			}
			error.push(zipMes);
			setErrorHighlight(zip);
			flag = 1;
			return;
		}
		if(!zipValue.match(regNum)){
			zipMes = "Zip code fields can only accept numbers.";
			error.push(zipMes);
			setErrorHighlight(zip);
			flag = 1;
			return;
		}
		
		if(zipValue.length < 5){
			zipMes = "Zip code fields must contain at least 5 numbers.";
			error.push(zipMes);
			setErrorHighlight(zip);
			flag = 1;
			return;
		}
	}


	// validate checkboxes when php has checkbox field set with "[]" at end of name
	function validateCheckBoxes(checkboxMes){
		for(j=0; j<obj.elements.length; j++){
			if(obj.elements[j].type == 'checkbox'){
				if(obj.elements[j].checked){
					checked.push('checked');
				}
				checkBoxFields = obj.elements[j].parentNode.parentNode.parentNode;
			}
		}
		if(checked.length < 1){
			error.push(checkboxMes);
			setErrorHighlight(checkBoxFields);
			flag = 1;
		}
	}


	//validate e-News
	function validateENews(){
		//form field identifiers
		var first_name = obj.enewsFirstName;
		var last_name = obj.enewsLastName;
		var email = obj.enewsEmail;
		var confirmEmail = obj.confirmEmail;
		var zip = obj.enewsZipPre;
		var interest = obj.enewsInterest;
		
		if(first_name.value == ''){
			first_nameMes = "Please enter your first name.";
			error.push(first_nameMes);
			setErrorHighlight(first_name);
			flag = 1;
		}
		if(last_name.value == ''){
			last_nameMes = "Please enter your last name.";
			error.push(last_nameMes);
			flag = 1;
			setErrorHighlight(last_name);
		}
		validateZip(zip,zip.value);
		if(email.value != confirmEmail.value){
			emailConfirmMes = "The email addresses you entered do not match, please verify and reenter.";
			error.push(emailConfirmMes);
			setErrorHighlight(email);
			setErrorHighlight(confirmEmail);
			flag = 1;
			return;
		}
		else{
			if(confirmEmail.value == ''){
				emailMes = "Please confirm your email.";
				error.push(emailMes);
				setErrorHighlight(confirmEmail);
				flag = 1;
			}
			validateEmail(email,email.value);
		}
		validateCheckBoxes('Please select at least one interest.');
	}


	//validate rentals
	function validateRentals(){
		var first_name = obj.firstName;
		var last_name = obj.lastName;
		var address1 = obj.address1;
		var city = obj.city;
		var state = obj.state;
		var zip = obj.zipPre;
		var email = obj.email;
		var phoneArea = obj.phoneArea;
		var phonePre = obj.phonePre;
		var phonePost = obj.phonePost;
		var contactType = obj.contactType;
		var referType = obj.referType;
		var eventType = obj.eventType;
		var monthFirstChoice = obj.monthFirstChoice;
		var dayFirstChoice = obj.dayFirstChoice;
		var yearFirstChoice = obj.yearFirstChoice;
		var eventTime = obj.eventHour;
		var eventAMPM = obj.eventAMPM;
		var numGuests = obj.numGuests;
		
		if(first_name.value == ''){
			first_nameMes = "Please enter your first name.";
			error.push(first_nameMes);
			setErrorHighlight(first_name);
			flag = 1;
		}
		if(last_name.value == ''){
			last_nameMes = "Please enter your last name.";
			error.push(last_nameMes);
			flag = 1;
			setErrorHighlight(last_name);
		}
		if(address1.value == ''){
			address1Mes = "Please enter an address.";
			error.push(address1Mes);
			flag = 1;
			setErrorHighlight(address1);
		}
		if(city.value == ''){
			cityMes = "Please enter a city.";
			error.push(cityMes);
			flag = 1;
			setErrorHighlight(city);
		}
		if(state.value == ''){
			stateMes = "Please enter a state.";
			error.push(stateMes);
			flag = 1;
			setErrorHighlight(state);
		}
		validateZip(zip,zip.value);
		validateEmail(email,email.value);
		if((phoneArea.value == '') || (phonePre.value == '') || (phonePost.value == '')){
			phoneMes = "Please check your phone number.";
			error.push(phoneMes);
			setErrorHighlight(phoneArea);
			setErrorHighlight(phonePre);
			setErrorHighlight(phonePost);
			flag = 1;
		}
		else{
			if((!phoneArea.value.match(regNum)) || (!phonePre.value.match(regNum)) || (!phonePost.value.match(regNum))){
				phoneMes = "Phone number fields can only except numbers.";
				error.push(phoneMes);
				flag = 1;
				setErrorHighlight(phoneArea);
				setErrorHighlight(phonePre);
				setErrorHighlight(phonePost);
			}
		}
		if(contactType.value == ''){
			contactTypeMes = "Please select how you would like to be contacted.";
			error.push(contactTypeMes);
			flag = 1;
			setErrorHighlight(contactType);
		}
		if(referType.value == ''){
			referTypeMes = "Please select how you heard about the museum.";
			error.push(referTypeMes);
			flag = 1;
			setErrorHighlight(referType);
		}
		if(eventType.value == ''){
			eventTypeMes = "Please select an event type.";
			error.push(eventTypeMes);
			flag = 1;
			setErrorHighlight(eventType);
		}
		if((monthFirstChoice.value == '') || (dayFirstChoice.value == '') || (yearFirstChoice.value == '')){
			phoneMes = "Please enter a event date.";
			error.push(phoneMes);
			setErrorHighlight(monthFirstChoice);
			setErrorHighlight(dayFirstChoice);
			setErrorHighlight(yearFirstChoice);
			flag = 1;
		}
		if(eventTime.value == ''){
			eventTimeMes = "Please select an event time.";
			error.push(eventTimeMes);
			setErrorHighlight(eventTime);
			flag = 1;
		}
		if(eventAMPM.value == ''){
			eventAMPMMes = "Please select whether your event time is AM or PM.";
			error.push(eventAMPMMes);
			setErrorHighlight(eventAMPM);
			flag = 1;
		}
		if(numGuests.value == ''){
			numGuestsMes = "Please let us know the number of guests.";
			error.push(numGuestsMes);
			flag = 1;
			setErrorHighlight(numGuests);
		}
	}


	//validate Education Registration
	function validateEduReg(){
		var first_name = obj.contactFirst;
		var last_name = obj.contactLast;
		var contactEmail = obj.contactEmail;
		var contactPhoneArea = obj.contactPhoneArea;
		var contactPhonePre = obj.contactPhonePre;
		var contactPhonePost = obj.contactPhonePost;
		var schoolName = obj.schoolName;
		var schoolType = obj.schoolType;
		var schoolAddress1 = obj.schoolAddress1;
		var schoolCity = obj.schoolCity;
		var schoolState = obj.schoolState;
		var zip = obj.schoolZipPre;
		var schoolCounty = obj.schoolCounty;
		var schoolSystem = obj.schoolSystem;
		var schoolEmail = obj.schoolEmail;
		var schoolPhoneArea = obj.schoolPhoneArea;
		var schoolPhonePre = obj.schoolPhonePre;
		var schoolPhonePost = obj.schoolPhonePost;
		var schoolFaxArea = obj.schoolFaxArea;
		var schoolFaxPre = obj.schoolFaxPre;
		var schoolFaxPost = obj.schoolFaxPost;
		var numClass = obj.numClass;
		var numStudents = obj.numStudents;
		var monthFirstChoice = obj.monthFirstChoice;
		var dayFirstChoice = obj.dayFirstChoice;
		var yearFirstChoice = obj.yearFirstChoice;
		var arrivalHour = obj.arrivalHour;
		var arrivalAMPM = obj.arrivalAMPM;
		var departureHour = obj.departureHour;
		var departureAMPM = obj.departureAMPM;
		var progID = obj.progID;
		var lunch = obj.lunch;
		
		if(first_name.value == ''){
			first_nameMes = "Please enter the contact person's first name.";
			error.push(first_nameMes);
			setErrorHighlight(first_name);
			flag = 1;
		}
		if(last_name.value == ''){
			last_nameMes = "Please enter the contact person's last name.";
			error.push(last_nameMes);
			flag = 1;
			setErrorHighlight(last_name);
		}
		validateEmail(contactEmail,contactEmail.value,'Please enter a valid  email address for the contact person.');
		if((contactPhoneArea.value == '') || (contactPhonePre.value == '') || (contactPhonePost.value == '')){
			contactPhoneMes = "Please check the contact person's phone number.";
			error.push(contactPhoneMes);
			setErrorHighlight(contactPhoneArea);
			setErrorHighlight(contactPhonePre);
			setErrorHighlight(contactPhonePost);
			flag = 1;
		}
		else{
			if((!contactPhoneArea.value.match(regNum)) || (!contactPhonePre.value.match(regNum)) || (!contactPhonePost.value.match(regNum))){
				phoneMes = "The contact's phone number fields can only except numbers.";
				error.push(phoneMes);
				flag = 1;
				setErrorHighlight(contactPhoneArea);
				setErrorHighlight(contactPhonePre);
				setErrorHighlight(contactPhonePost);
			}
		}
		if(schoolName.value == ''){
			schoolNameMes = "Please enter the school name.";
			error.push(schoolNameMes);
			setErrorHighlight(schoolName);
			flag = 1;
		}
		if(schoolType.value == ''){
			schoolTypeMes = "Please enter the type of school.";
			error.push(schoolTypeMes);
			setErrorHighlight(schoolType);
			flag = 1;
		}
		if(schoolAddress1.value == ''){
			schoolAddress1Mes = "Please enter the school address.";
			error.push(schoolAddress1Mes);
			flag = 1;
			setErrorHighlight(schoolAddress1);
		}
		if(schoolCity.value == ''){
			schoolCityMes = "Please select the city/town the school is in.";
			error.push(schoolCityMes);
			flag = 1;
			setErrorHighlight(schoolCity);
		}
		if(schoolState.value == ''){
			schoolStateMes = "Please select the state the school is in.";
			error.push(schoolStateMes);
			flag = 1;
			setErrorHighlight(schoolState);
		}
		validateZip(zip,zip.value,'Please enter school\'s zip code.');
		if(schoolCounty.value == ''){
			schoolCountyMes = "Please enter the county the school is in.";
			error.push(schoolCountyMes);
			flag = 1;
			setErrorHighlight(schoolCounty);
		}
		if(schoolSystem.value == ''){
			schoolSystemMes = "Please enter the school system's name.";
			error.push(schoolSystemMes);
			flag = 1;
			setErrorHighlight(schoolSystem);
		}
		validateEmail(schoolEmail,schoolEmail.value,'Please enter an email address with which we can contact the school.');
		if((schoolPhoneArea.value == '') || (schoolPhonePre.value == '') || (schoolPhonePost.value == '')){
			schoolPhoneMes = "Please check the school's phone number.";
			error.push(schoolPhoneMes);
			setErrorHighlight(schoolPhoneArea);
			setErrorHighlight(schoolPhonePre);
			setErrorHighlight(schoolPhonePost);
			flag = 1;
		}
		else{
			if((!schoolPhoneArea.value.match(regNum)) || (!schoolPhonePre.value.match(regNum)) || (!schoolPhonePost.value.match(regNum))){
				phoneMes = "The school's phone number fields can only except numbers.";
				error.push(phoneMes);
				flag = 1;
				setErrorHighlight(schoolPhoneArea);
				setErrorHighlight(schoolPhonePre);
				setErrorHighlight(schoolPhonePost);
			}
		}
		if((schoolFaxArea.value == '') || (schoolFaxPre.value == '') || (schoolFaxPost.value == '')){
			schoolFaxMes = "Please check the school's fax number.";
			error.push(schoolFaxMes);
			setErrorHighlight(schoolFaxArea);
			setErrorHighlight(schoolFaxPre);
			setErrorHighlight(schoolFaxPost);
			flag = 1;
		}
		else{
			if((!schoolFaxArea.value.match(regNum)) || (!schoolFaxPre.value.match(regNum)) || (!schoolFaxPost.value.match(regNum))){
				FaxMes = "The school's fax number fields can only except numbers.";
				error.push(FaxMes);
				flag = 1;
				setErrorHighlight(schoolFaxArea);
				setErrorHighlight(schoolFaxPre);
				setErrorHighlight(schoolFaxPost);
			}
		}
		if(numClass.value == ''){
			numClassMes = "Please enter the number of classes in attendance.";
			error.push(numClassMes);
			flag = 1;
			setErrorHighlight(numClass);
		}
		if(numStudents.value == ''){
			numStudentsMes = "Please enter the number of students in attendance.";
			error.push(numStudentsMes);
			flag = 1;
			setErrorHighlight(numStudents);
		}
		validateCheckBoxes('Please select all grades that will be attending.');
		if((monthFirstChoice.value == '') || (dayFirstChoice.value == '') || (yearFirstChoice.value == '')){
			eventDateMes = "Please enter the date you plan to visit.";
			error.push(eventDateMes);
			setErrorHighlight(monthFirstChoice);
			setErrorHighlight(dayFirstChoice);
			setErrorHighlight(yearFirstChoice);
			flag = 1;
		}
		if(arrivalHour.value == ''){
			arrivalHourMes = "Please select an arrival time.";
			error.push(arrivalHourMes);
			setErrorHighlight(arrivalHour);
			flag = 1;
		}
		if(arrivalAMPM.value == ''){
			arrivalAMPMMes = "Please select whether your arrival time is AM or PM.";
			error.push(arrivalAMPMMes);
			setErrorHighlight(arrivalAMPM);
			flag = 1;
		}
		if(departureHour.value == ''){
			departureHourMes = "Please select an departure time.";
			error.push(departureHourMes);
			setErrorHighlight(departureHour);
			flag = 1;
		}
		if(departureAMPM.value == ''){
			departureAMPMMes = "Please select whether your departure time is AM or PM.";
			error.push(departureAMPMMes);
			setErrorHighlight(departureAMPM);
			flag = 1;
		}
		if(progID.value == ''){
			progIDMes = "Please select at least one desired activity.";
			error.push(progIDMes);
			flag = 1;
			setErrorHighlight(progID);
		}
		if(lunch.value == ''){
			lunchMes = "Please let us know your lunch plans.";
			error.push(lunchMes);
			flag = 1;
			setErrorHighlight(lunch);
		}

	}
	

	//validate Membership Application
	function validateMembership(){
		var first_name = obj.firstNameMember1;
		var last_name = obj.lastNameMember1;
		var address1 = obj.address1;
		var city = obj.city;
		var state = obj.state;
		var zip = obj.zipPre;
		var phoneArea = obj.phoneArea;
		var phonePre = obj.phonePre;
		var phonePost = obj.phonePost;
		var email = obj.email;
		var giftMembership = obj.gift;
		var shipToRecip = obj.shipRecip;
		var cardNumber = obj.card_accountNumber;
		var cardExpMM = obj.card_expirationMonth;
		var cardExpYY = obj.card_expirationYear;

		//check if credit card selected
		function checkCardType(cardNumber){
			var selectCard = obj.card_cardType;
			var cardType;
			cardFlag = -1;
			for(i=0; i<selectCard.length; i++){
				if(selectCard[i].checked == true){
					cardType = selectCard[i].value;
					cardFlag = 2;
				}
			}
			if(cardFlag == -1){
				cardTypesMes = "Please select a credit card.";
				error.push(cardTypesMes);
				flag = 1;
				return;
			}
			else{
			// credit card validation
				var isValid = false;
				var ccCheckRegExp = /[^\d -]/;
				isValid = !ccCheckRegExp.test(cardNumber);
				  
				if(isValid){
					var cardNumNoSpace = cardNumber.replace(/ /g,"");
					var cardNumbersOnly = cardNumNoSpace.replace(/-/g,"");
					var cardNumberLength = cardNumbersOnly.length;
					var lengthIsValid = false;
					var prefixIsValid = false;
					var prefixRegExp;
				
					switch(cardType){
						case "001":
						lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
						prefixRegExp = /^4/;
						break;
						case "002":
						lengthIsValid = (cardNumberLength == 16);
						prefixRegExp = /^5[1-5]/;
						break;
						default:
						prefixRegExp = /^$/;
						alert("Card type not found");
					}
					prefixIsValid = prefixRegExp.test(cardNumbersOnly)
					isValid = prefixIsValid && lengthIsValid;;
				}
				if(isValid){
					var numberProduct;
					var numberProductDigitIndex;
					var checkSumTotal = 0;
					
					for(digitCounter = cardNumberLength - 1; digitCounter >= 0; digitCounter--){
						checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
						digitCounter--;
						numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
						for (var productDigitCounter = 0;productDigitCounter < numberProduct.length; productDigitCounter++){
							checkSumTotal += parseInt(numberProduct.charAt(productDigitCounter));
						}
					}
					isValid = (checkSumTotal % 10 == 0);
					return;
				}
				cardMes = "Please check your credit card number.";
				error.push(cardMes);
				setErrorHighlight(cardNumber);
				flag = 1;
				return isValid;
			}
		}

		if(first_name.value == ''){
			first_nameMes = "Please enter the member's first name.";
			error.push(first_nameMes);
			setErrorHighlight(first_name);
			flag = 1;
		}
		if(last_name.value == ''){
			last_nameMes = "Please enter the member's last name.";
			error.push(last_nameMes);
			flag = 1;
			setErrorHighlight(last_name);
		}
		if(address1.value == ''){
			address1Mes = "Please enter the member's address.";
			error.push(address1Mes);
			flag = 1;
			setErrorHighlight(address1);
		}
		if(city.value == ''){
			cityMes = "Please select the the member's city.";
			error.push(cityMes);
			flag = 1;
			setErrorHighlight(city);
		}
		if(state.value == ''){
			stateMes = "Please select the member's state.";
			error.push(stateMes);
			flag = 1;
			setErrorHighlight(state);
		}
		validateZip(zip,zip.value,'Please enter the member\'s zip code.');
		if((phoneArea.value == '') || (phonePre.value == '') || (phonePost.value == '')){
			phoneMes = "Please check the member's phone number.";
			error.push(phoneMes);
			setErrorHighlight(phoneArea);
			setErrorHighlight(phonePre);
			setErrorHighlight(phonePost);
			flag = 1;
		}
		else{
			if((!phoneArea.value.match(regNum)) || (!phonePre.value.match(regNum)) || (!phonePost.value.match(regNum))){
				phoneMes = "The member's phone number fields can only except numbers.";
				error.push(phoneMes);
				flag = 1;
				setErrorHighlight(phoneArea);
				setErrorHighlight(phonePre);
				setErrorHighlight(phonePost);
			}
		}
		validateEmail(email,email.value,'Please enter a valid email address.');
		
		var giftMembership;
		for(i=0; i<obj.gift.length; i++){
			if(obj.gift[i].checked == true){
				giftMembership = obj.gift[i].value;
			}
		}
		if(giftMembership == 1){
			var recip_first_name = obj.recipFirstName;
			var recip_last_name = obj.recipLastName;
			
			if(recip_first_name.value == ''){
				recip_first_nameMes = "Please enter the gift recipient's first name.";
				error.push(recip_first_nameMes);
				setErrorHighlight(recip_first_name);
				flag = 1;
			}
			if(recip_last_name.value == ''){
				recip_last_nameMes = "Please enter the gift recipient's last name.";
				error.push(recip_last_nameMes);
				flag = 1;
				setErrorHighlight(recip_last_name);
			}
		}
		
		var shipToRecip;
		for(i=0; i<obj.shipRecip.length; i++){
			if(obj.shipRecip[i].checked == true){
				shipToRecip = obj.shipRecip[i].value;
			}
		}
		if(shipToRecip == 1){
			var recip_first_name = obj.recipFirstName;
			var recip_last_name = obj.recipLastName;
			var recip_address1 = obj.recipAddress1;
			var recip_city = obj.recipCity;
			var recip_state = obj.recipState;
			var recip_zip = obj.recipZipPre;
			var recip_phoneArea = obj.recipPhoneArea;
			var recip_phonePre = obj.recipPhonePre;
			var recip_phonePost = obj.recipPhonePost;
			var recip_email = obj.recipEmail;
			
			if(recip_address1.value == ''){
				recip_address1Mes = "Please enter the gift recipient's address.";
				error.push(recip_address1Mes);
				flag = 1;
				setErrorHighlight(recip_address1);
			}
			if(recip_city.value == ''){
				recip_cityMes = "Please select the the gift recipient's city.";
				error.push(recip_cityMes);
				flag = 1;
				setErrorHighlight(recip_city);
			}
			if(recip_state.value == ''){
				recip_stateMes = "Please select the gift recipient's state.";
				error.push(recip_stateMes);
				flag = 1;
				setErrorHighlight(recip_state);
			}
			validateZip(recip_zip,recip_zip.value,'Please enter the gift recipient\'s zip code.');
			if((recip_phoneArea.value == '') || (recip_phonePre.value == '') || (recip_phonePost.value == '')){
				recip_phoneMes = "Please check the gift recipient's phone number.";
				error.push(recip_phoneMes);
				setErrorHighlight(recip_phoneArea);
				setErrorHighlight(recip_phonePre);
				setErrorHighlight(recip_phonePost);
				flag = 1;
			}
			else{
				if((!recip_phoneArea.value.match(regNum)) || (!recip_phonePre.value.match(regNum)) || (!recip_phonePost.value.match(regNum))){
					recip_phoneMes = "The gift recipient's phone number fields can only except numbers.";
					error.push(recip_phoneMes);
					flag = 1;
					setErrorHighlight(recip_phoneArea);
					setErrorHighlight(recip_phonePre);
					setErrorHighlight(recip_phonePost);
				}
			}
			validateEmail(recip_email,recip_email.value,'Please enter a valid email address for the gift recipient.');
		}
		checkCardType(cardNumber);
		if(cardExpMM.value == ''){
	 		cardExpMMMes = "Please enter the expiration month for your credit card.";
		 	error.push(cardExpMMMes);
			setErrorHighlight(cardExpMM);
		 	flag = 1;
		}
		if(cardExpYY.value == ''){
	 		cardExpYYMes = "Please enter the expiration year for your credit card.";
		 	error.push(cardExpYYMes);
			setErrorHighlight(cardExpYY);
		 	flag = 1;
		}
	}


// build error message
	if(flag == 1){
		errorString =error.join('\r\n');
		alert(errorString);
		returnVal= false;	
		highlight = 1;
	}
	else{
		returnVal= true;
	}
}





//////////////////////////////////////////////////////////////////////////////////////////////////////
//Gift Membership Functionality on Membership Application
var divId;

function showHide(state,divID){
	//if yes is selected to question is this order a gift, show gift table
 	divId = divID;
	if(state == 1){ 
		document.getElementById(divId).style.display = 'block';
		return;
	}
	
	var flag = 0;
	var obj = document.getElementById('member');		
	var r_names = new Array;
		r_names[0] = obj.recipFirstName
		r_names[1] = obj.recipLastName
		r_names[2] = obj.recipAddress1
		r_names[3] = obj.recipAddress2
		r_names[4] = obj.recipCity
		r_names[5] = obj.recipState
		r_names[6] = obj.recipZipPre
		r_names[6] = obj.recipPhoneArea
		r_names[7] = obj.recipPhonePre
		r_names[8] = obj.recipPhonePost
		r_names[9] = obj.recipEmail
		
	//if no is checked "Is this a gift membership?"
	if(state == 0){
 		for(i=0; i<r_names.length; i++){
			if(r_names[i].value != ''){flag = 1;}
		}
		if(flag == 1){
			if(confirm('By selecting "no" you will be deleting all\r\n recipient information you have input.\r\n If this is the action you wish to take, click OK.')){
 				if(divID == 'ecommRecipInfo'){
					subset_r_names = r_names.slice(2);
					for(i=0; i<subset_r_names.length; i++){
						subset_r_names[i].value = '';
					}
				}
				else{
					for(i=0; i<r_names.length; i++){
						r_names[i].value = '';
					}
					obj.shipRecip[0].checked = false;
					obj.shipRecip[1].checked = true;
  					document.getElementById('ecommRecipInfo').style.display = 'none';
				}
			}
		}
  		if(divID != 'ecommRecipInfo'){
			document.getElementById('ecommRecipInfo').style.display = 'none';
		}
		document.getElementById(divId).style.display = 'none';
		obj.shipRecip[0].checked = false;
		obj.shipRecip[1].checked = true;
	}
}

//shows gift table if gift radio button clicked
function checkState(){
	var checkGift;
	var obj = document.getElementById('member');
 	for(i=0; i<obj.gift.length; i++){
		if(obj.gift[i].checked){
			checkGift = obj.gift[i].value;
			if(checkGift == 'yes'){
				document.getElementById('ecommGiftInfo').style.display = 'block';
			}
		}
	}
}

