
/////////////////////////
// form reset function //
/////////////////////////

function resetTheForm(oldSubmitValue) {
	document.theForm.submit.value = oldSubmitValue;
	document.theForm.submit.disabled = false;
	document.theForm.reset();
}

/////////////////////////////////////////////////
// validation function for gift certifate form //
/////////////////////////////////////////////////

function prepareSubmit (form) {
	
	// update gift card amounts for paypal hidden form field os0
	//var amountIndex = form.os0.selectedIndex;
	//form.amount.value = form.os0.options[amountIndex].value;

	// initialize variables for error message construction
	var message = "Oops! ";
	var fields = "";
		
		// check for gift card amount
		var amountIndex = form.amount.selectedIndex;
		var value = form.amount.options[amountIndex].value;
		if (!value) {
	        fields = fields + "\n" + " No Gift Card Amount Chosen";
	    }
		
		// check for first name
		if (!form.recipientFirstName.value) {
	        fields = fields + "\n " + "Recipient First Name Missing";
	    }
		
		// check for last name
		if (!form.recipientLastName.value) {
	        fields = fields + "\n " + "Recipient Last Name Missing";
	    }
		
		// the following runs only if there are no other prior errors, eg. this form "would" be submitted otherwise
		if (fields == "") {
			// concatanate the values from the recipient first/last name fields and set the os0 value for paypal
			recipientFullName = form.recipientFirstName.value + " " + form.recipientLastName.value;
			form.os0.value = recipientFullName;
			// put the personal message into the os1 value for paypal
			if (form.msg.value != "") {
				form.os1.value = form.msg.value;
			} else {
				form.os1.value = "None";
			}
			// store old submit value, disable submit button and display wait message
			var oldSubmitValue = form.submit.value;
			form.submit.value = "Please Wait...";
			form.submit.disabled = true;
			// call the form reset function
			setTimeout('resetTheForm(\''+oldSubmitValue+'\')', 4000);
		}

	// produce alert box with errors or submit data if there are no errors
	if (fields) {
		alert(message + "\n" + fields + "\n");
		return false;
	}
}

//////////////////////////////////////////////////
// validation function for rewards program form //
//////////////////////////////////////////////////

function submitRewardProgram (form) {
	
	// initialize variables for error message construction
	var message = "Oops! ";
	var fields = "";
		
	// name
	if (!form.name.value) {
			fields = fields + "\n "+"Name missing"
	}
		
	// address
	if (!form.address.value){
			fields = fields + "\n "+"Address missing"
	}
	
	// city
	if (!form.city.value) {
			fields = fields + "\n "+"City missing"
	}
	
	// state
	if (!form.state.value) {
			fields = fields + "\n "+"State missing"
	}
	
	// zip
	if (!form.zip.value) {
				fields = fields + "\n "+"Zip missing"
	}
	
	// check for email > make sure that email contains "." and "@"
	var at = false;
	var regEx = /^.+\@.+\..+$/
	at = regEx.test(form.email.value);
	
	if ((!form.email.value) || (at == false))  {
				fields = fields + "\n "+"E-Mail missing or invalid"
	}
	
	// phone	
	if (!form.phone.value) {
				fields = fields + "\n "+"Phone missing"
	}
		
	// birthday
	if (!form.birthday.value) {
			fields = fields + "\n "+"Birthday missing"
	}

	// produce alert box with errors or submit data if there are no errors
	if (fields) {
		alert(message + "\n" + fields + "\n");
		return false;
	}
}


///////////////////////////////////////////////
// validation function for gift card contest //
///////////////////////////////////////////////

function submitGiftCardContest (form) {
	
	// initialize variables for error message construction
	var message = "Oops! ";
	var fields = "";
		
	// fname
	if (!form.fname.value) {
			fields = fields + "\n "+"First Name missing"
	}
	
	// lname
	if (!form.lname.value) {
			fields = fields + "\n "+"Last Name missing"
	}
	
	// zip
	if (!form.zip.value) {
				fields = fields + "\n "+"Zip Code missing"
	}
		
	// check for email > make sure that email contains "." and "@"
	var at = false;
	var regEx = /^.+\@.+\..+$/
	at = regEx.test(form.email.value);
	
	if ((!form.email.value) || (at == false))  {
				fields = fields + "\n "+"E-Mail missing or invalid"
	}

	// produce alert box with errors or submit data if there are no errors
	if (fields) {
		alert(message + "\n" + fields + "\n");
		return false;
	}
}