	
	
	/* MINDING YOUR MIND - FORM VALIDATION JAVASCRIPT (valid-form.js) - 
	   this file contains JavaScript used to validate forms and otherwise handle form content
	   and is included on all pages. */
	  
	  
	// these are specific function calls for form validation
	
	function submitForm(frmNm) {
		// call this for submit action w/o any validation
		
		document.forms[frmNm].submit();
	}
	
	function validForm(frmNm) {
		// now that CF validation has been removed, call this for submit action
		
		if (ExtendJS(frmNm))
			document.forms[frmNm].submit();
	}
	
	function ExtendJS(frmNm) {
		// add additional validation to CF's auto validation (specifically, for registration form)
		// now changed to handle ALL validation; CF validation has been disabled.

		var reqls = ['FirstName','LastName','Address1','City','Zip','Email'];
		var goon = true;

		// since IE 6 can't handle CF validation, do the field validation manually... grrr
		if (!allFieldsValid(frmNm, reqls)) {
			// field not entered, fail with alert
			alert("Please enter your full name, address, and email in order to continue.");
			goon = false;
			return false;		
		}

		if (!selectRequired(frmNm, 'State')) {
			alert("Please select the state of your street address.");
			goon = false;
			return false;
		}
		
		if (frmNm == 'dntFrm') {
			// additional validation for donation form, first gift fields
			if (!isAnumberGTzero(frmNm, 'giftAmt')) {
				alert("Please enter a total gift amount in order to continue.");
				goon = false;
				return false;				
			}
			
			if (isChecked(frmNm, 'isRecurring[1]')) {
				// recurring, validate no of months also
				if (!isAnumberGTzero(frmNm, 'noPmts')) {
					alert("Please enter the number of payments for a recurring monthly gift.");
					goon = false;
					return false;				
				}				
			}

			if (!isChecked(frmNm, 'canPubAck[0]') && !isChecked(frmNm, 'canPubAck[1]')) {
				// did not answer pub acknowledgement question
				alert("Please answer if your gift may be publicly ackowledged or not.");
				goon = false;
				return false;								
			}
						
			/* if (isChecked(frmNm, 'doTribute')) {
				// sending acknowledgement, validate those fields also

				reqls = ['ackFirstName','ackLastName','ackAddress1','ackCity','ackZip'];
				if (!allFieldsValid(frmNm, reqls)) {
					// field not entered, fail with alert
					alert("Please enter the contact information if you are choosing to send an acknoweldgement.");
					goon = false;
					return false;		
				}	 
				
				if (!selectRequired(frmNm, 'ackState')) {
					alert("Please select the state of the acknowledgement address.");
					goon = false;
					return false;
				}
			} */
			
		} else if (frmNm == 'cardFrm') {
			// additional validation for card order form, for now just quantity
			
			if (!isAnumberGTzero(frmNm, 'noBoxes')) {
				alert("Please enter the desired quantity of boxes of cards in order to continue.");
				goon = false;
				return false;				
			}			
		}
				
		if (goon)
			return true;
				
		/*
		// make sure, for any selected events with guidelines, that agree box and signature were entered
		for (b=0; b<eventLs.length; b++) {
			if (isChecked(frmNm, eventLs[b])) {
				// this event was selected, see if it has guidelines
				if (mustAgreeLs[b] == 1) {
					// has guidelines, see if agree box was checked
					if (!isChecked(frmNm, agreeCkLs[b])) {
						// not checked, fail with alert
						alert("You must agree to the guidelines for all selected incentives.");	
						return false;
					} else if (!isNotEmpty(frmNm, evSignLs[b])) {
						// signature not entered, fail with alert
						alert("You must enter signature for all selected incentives.");
						return false;
					}		
				}	
			}	
		}
		*/	
		
	}	
	
	function toggleForm(Form, CkBox, HolderID, ContentID) {
		// if CkBox field on Form is checked, replace content of HolderID with content of ContentID
		// if not, vice versa
		var mode;
		if (isChecked(Form, CkBox)) {
			// swap form content into proper, visible place on form and wipe out content so not duplicate fields
			mode = 1;
		} else {
			// if form content in holder, return it to content div
			mode = 0;
		}
		fillHolderWithContent(mode, HolderID, ContentID);
	}
	
	function fillHolderWithContent(mode, HolderID, ContentID) {
		// swap HolderID content with content from ContentID (if mode == 1)
		// or, do reverse swap if HolderID has content to swap back (if mode == 0)
	
		if (mode == 1) {
			// swap form content into proper, visible place on form
			setElementText(HolderID, getElementText(ContentID));
			// wipe out content so not duplicate fields
			setElementText(ContentID, " ");
		} else {
			// if form content in holder, return it to content div
			if (getElementText(HolderID).length > 5)
				setElementText(ContentID, getElementText(HolderID));
			// in either case, wipe out holder div content	
			setElementText(HolderID, " ");
		}	
		
	}

	function swapOccasionContent(mode) {
		// specialized function for donate.cfm to switch between select and regular text inputs for Occasion
		var otheridx = document.dntFrm.Occasion.options.length-1;

		if (mode == 1) {
			// replace select box with text box, saving old content
			fillHolderWithContent(1, "occasionSelContent", "occasionHldr");
			//setElementText("occasionSelContent", getElementText("occasionHldr"));
			fillHolderWithContent(1, "occasionHldr", "occasionTxtContent");
			//setElementText("occasionHldr", getElementText("occasionTxtContent"));
		} else {
			// save text field content in its holder
			fillHolderWithContent(1, "occasionHldr", "occasionTxtContent");
			// replace regular holder content with select box content
			fillHolderWithContent(0, "occasionSelContent", "occasionHldr");
		}
	}
	
	function swapOccasionAsTxt() {
		// specialized function for donate.cfm to switch between select and regular text inputs for Occasion
		var otheridx = document.dntFrm.Occasion.options.length-1;
		var mode;
		
		if (document.dntFrm.Occasion.selectedIndex == otheridx) {
			// replace select box with text box, saving old content
			swapOccasionContent(1);
		}
	}
	
	function updateOrderText() {
		// specialized function for ordercards.cfm to update order amount and description
		// as quantity is entered
		var noBoxes = document.cardFrm.noBoxes.value;
		var orderCostStr = " - ";
		var unitCost = 19.95;
		var orderDescrip = " - ";
		if (strIsNumGtZero(noBoxes)) {
			// update unit cost based on quantity entered
			if (noBoxes >= 2 && noBoxes <= 4)
				unitCost = 17.95;
			else if (noBoxes >= 5)
				unitCost = 15.95;
			// calculate order amount
			orderCost = roundNum(unitCost*noBoxes, 2);
			// form order description string
			orderDescrip = "You have requested " + noBoxes.toString();
			if (noBoxes == 1)
				orderDescrip = orderDescrip + " box";
			else
				orderDescrip = orderDescrip + " boxes";
			orderDescrip = orderDescrip + " of greeting cards at $" + unitCost.toString() + " each. ";
			orderCostStr = '$' + decFormatNum(orderCost.toString())
		}

		$('#cardOrderDescrip').html(orderDescrip);
		$('#cardOrderAmt').html(orderCostStr);
		
	}
		
	function updateGiftAmts(doMoPmt) {
		// specialized function for donate.cfm to update gift amounts automatically as entered
		var giftAmt = document.dntFrm.giftAmt.value;
		var noPmts = document.dntFrm.noPmts.value;
		var moAmt = document.dntFrm.moAmt.value;
		
		// only bother if selected recurring payment
		if (isChecked('dntFrm', 'isRecurring[1]')) {
			if (strIsNumGtZero(noPmts)) {
				if (doMoPmt) {
					if (strIsNumGtZero(giftAmt)) {
						document.dntFrm.moAmt.value = roundNum(giftAmt/noPmts, 2);
					} else {
						document.dntFrm.moAmt.value = "";
					}
				} else {
					if (strIsNumGtZero(moAmt)) {
						document.dntFrm.giftAmt.value = moAmt*noPmts;						
					} else {
						document.dntFrm.giftAmt.value = "";						
					}
				}			
			} else {
				// blank out whichever field is being updated
				if (doMoPmt)
					document.dntFrm.moAmt.value = "";
				else
					document.dntFrm.giftAmt.value = "";
			}
		}
		
	}
	
	function clearMoGiftAmts() {
		if (isChecked('dntFrm', 'isRecurring[0]')) {
			// selected one time payment, clear monthly fields
			document.dntFrm.moAmt.value = "";
			document.dntFrm.noPmts.value = "";
		}
	}



	  