// Copyright (C) 2008 Dwain Blazej

// TODO: submit Medical Group info to separate CGI to get around 200 char restriction.
// TODO: modify Brennemann to auto change price at correct time.

// ----------------------------------------
// Globals to customize.

// Where to send payment forms.
// var paymentSubmit='https://www.sandbox.paypal.com/cgi-bin/webscr';
var paymentSubmit='https://www.paypal.com/cgi-bin/webscr';

var paymentSend='payment';
// Anti-Spambot crawler.
paymentSend+='@lap' + 'edsoc' + '.org';

// Where to email bugs.
var problemReportEmail='la' + 'pedsoc' + '+bug';
// Anti-Spambot crawler.
problemReportEmail += '@gmail.com';


// Handle situation when the Medical Group box is checked and the page is reloaded.
// onload=medicalGroupFormInsert();

// ----------------------------------------
// Begin: Interative buttons


// Preload Alert icon next to correction text.
var imageButtonAddDonationNormal = new Image();
imageButtonAddDonationNormal.src = '../images/alert.gif';

// add_donation ....................
var imageButtonAddDonationNormal = new Image();
imageButtonAddDonationNormal.src = '../images/button_-_add_donation_-_normal.gif';
function buttonAddDonationNormal(obj) {
	obj.src = imageButtonAddDonationNormal.src;
}

var imageButtonAddDonationOver = new Image();
imageButtonAddDonationOver.src = '../images/button_-_add_donation_-_over.gif';
function buttonAddDonationOver(obj) {
	obj.src = imageButtonAddDonationOver.src;
}

var imageButtonAddDonationClick = new Image();
imageButtonAddDonationClick.src = '../images/button_-_add_donation_-_click.gif';
function buttonAddDonationClick(obj) {
	obj.src = imageButtonAddDonationClick.src;
}

// add_payment ....................
var imageButtonAddPaymentNormal = new Image();
imageButtonAddPaymentNormal.src = '../images/button_-_add_payment_-_normal.gif';
function buttonAddPaymentNormal(obj) {
	obj.src = imageButtonAddPaymentNormal.src;
}

var imageButtonAddPaymentOver = new Image();
imageButtonAddPaymentOver.src = '../images/button_-_add_payment_-_over.gif';
function buttonAddPaymentOver(obj) {
	obj.src = imageButtonAddPaymentOver.src;
}

var imageButtonAddPaymentClick = new Image();
imageButtonAddPaymentClick.src = '../images/button_-_add_payment_-_click.gif';
function buttonAddPaymentClick(obj) {
	obj.src = imageButtonAddPaymentClick.src;
}

// pay_now ....................
var imageButtonPayNowNormal = new Image();
imageButtonPayNowNormal.src = '../images/button_-_pay_now_-_normal.gif';
function buttonPayNowNormal(obj) {
	obj.src = imageButtonPayNowNormal.src;
}

var imageButtonPayNowOver = new Image();
imageButtonPayNowOver.src = '../images/button_-_pay_now_-_over.gif';
function buttonPayNowOver(obj) {
	obj.src = imageButtonPayNowOver.src;
}

var imageButtonPayNowClick = new Image();
imageButtonPayNowClick.src = '../images/button_-_pay_now_-_click.gif';
function buttonPayNowClick(obj) {
	obj.src = imageButtonPayNowClick.src;
}

function controlDisplay(controlId,displayId) {
	var controlObj = document.getElementById(controlId);
	var displayObj = document.getElementById(displayId);
	if (displayObj) {
		if (controlObj.checked) {
			displayObj.style.display='block';
		} else {
			displayObj.style.display='none';
		}
	}
}

// End: Interative buttons
// ----------------------------------------

// Begin: Lib
// ----------------------------------------

// Customize

// colorForProblem='#ffc4be';
var colorForProblem='#fdff89';

// ....................
// User special variable "onerror" to customize error handler.
onerror=handleError;  // Function in lib.js

// Array of getElementById that are highlighted as problems.
var arrayProblemHighlight = new Array();



function debugMessage(msg) {
	// var x = document.getElementById('debugID')
	// x.innerHTML = x.innerHTML + msg;
	// document.getElementById('debugID').innerHTML += '<div bgcolor="#fdff89">' + msg + '</div><br />';
	document.getElementById('debugID').style.backgroundColor='#fdff89';
	document.getElementById('debugID').innerHTML += '<div>' + msg + '</div>';

}

/*
Return:
	true: form is valid.
	false: form is not valid.
*/
function validateForm(eltMessageArea, funcValidateForm) {
	resetCorrectionFeedback(eltMessageArea);
	if (funcValidateForm != undefined) {
		if (typeof funcValidateForm == 'function') {
			funcValidateForm();
		} else {
			throw('validateForm: Function expected for funcValidateForm.');
		}
	}

	var issue;
	if (correctionMessages.length > 0) {
		if (correctionMessages.length == 1) {
			issue = 'issue';
		} else {
			issue = 'issues';
		}
		var msgHeading = 'Please address the following ' + issue + ' then try again:';
		// debugMessage('Correctionmessages length is ' + correctionMessages.length);
		var listOfCorrections = '<ul>';
		for(var i=0; i<correctionMessages.length; i++) {
			listOfCorrections += '<li class="problem">' + correctionMessages[i] + '</li>';
		}
		listOfCorrections += '</ul>';

		// var elt = document.getElementById('correctionMessageID');
		var elt = eltMessageArea;
		highlightProblem(eltMessageArea);
		// Using table instead of iframe because table has better browser support.
		elt.innerHTML = '<p><table width="100%" class="problem"><tr><td align="center" valign="top" rowspan="2"><img src="../images/alert.gif" alt="[Alert]"></td><th align="left">' +  msgHeading + '</th></tr><tr><td>' + listOfCorrections + '</td></tr></table></p>';
		document.location.href='#' + eltMessageArea.id;
		return false;
	} else {
		// Clean current page.
		resetCorrectionFeedback(eltMessageArea);
		return true;
	}		
}


function processForm(form, eltMessageArea, funcCustomizeForm, funcValidateForm) {
	if (! form) {
		throw('processForm: Form undefined.');
	}

	if ( validateForm(eltMessageArea, funcValidateForm) 
		 && formConfigure(form, funcCustomizeForm)
	   ) {
		return true;
	} else {
		return false;
	}

}
// object	form
// string	name, value
// string	id: Optional.
function addHiddenInputToForm(form,name,value,id) {
	var new_element = document.createElement('input');
	new_element.setAttribute('type', 'hidden');
	new_element.setAttribute('name', name);
	new_element.setAttribute('value', value);
	if (id) {
		new_element.setAttribute('id', id);
	}
	// document.forms['form_name'].appendChild(new_element); 
	if (! form.appendChild(new_element)) {
		throw('addHiddenInputToForm: failed to append to form name=' + name + ' value=' + value);
	} else {
		// debugMessage('Added name=' + new_element.name + ' value=' + new_element.value);
	}
}


// eltMessageArea string
function resetCorrectionFeedback(eltMessageArea) {
	// var elt = document.getElementById(eltMessageArea);
	var elt = eltMessageArea;
	elt.style.backgroundColor='';
	elt.innerHTML = '';

	for(var i=0; i<arrayProblemHighlight.length; i++) {
		// document.getElementById(eltToHighlight).bgColor='';
		//document.getElementById(i).style.backgroundColor='';
		// document.getElementById(arrayProblemHighlight[i]).style.backgroundColor='';
		arrayProblemHighlight[i].style.backgroundColor='';
	}
	arrayProblemHighlight = [];
	correctionMessages = [];
}

// eltToHighlight: element to highlight.
function highlightProblem(eltToHighlight) {
	arrayProblemHighlight.push(eltToHighlight);
	// document.getElementById(eltToHighlight).bgColor=;
	//document.getElementById(eltToHighlight).className += 'problem';
	// document.getElementById(eltToHighlight).style.backgroundColor=colorForProblem;
	eltToHighlight.style.backgroundColor=colorForProblem;
}

/*
message string: Verbose correction message to show user.
* string: DOM elements to highlight.
*/
function userCorrectionRequired(message) {
	if(! message) throw('userCorrectionRequired: expected correction message');

	correctionMessages.push(message);
	// Skip the first argument, a text message to the user.
	var highlightObj;
	for (var i=1; i < arguments.length; i++) {
		highlightObj = document.getElementById(arguments[i]);
		if (! highlightObj) {
			throw('userCorrectionRequired: element id at argument index ' + i + ' is unknown: ' + arguments[i]);
		} else {
			highlightProblem(highlightObj);
		}
	}
	isValid=false;  // Usually in call scope.
}

// ----------------------------------------
// End: Lib


// ----------------------------------------
// Begin: Form validity feedback.

// End: Form validity feedback.
// ----------------------------------------

// ----------------------------------------
// Begin: Form validity checks.

// ----------------------------------------
// End: Form validity checks.


// ----------------------------------------
// Begin: Helper functions.


function formConfigure(form, funcCustomizeForm) {
	// Validate assertion before making changes. Run the funcCustomizeForm last to override defaults.
	if (! funcCustomizeForm) {
		throw('formConfigure: Form not customized.');
		return false;
	} else if (typeof funcCustomizeForm != 'function') {
		throw('formConfigure: Form not customization not given a function.');
		return false;
	}

	// While the document is in "get" mode, IE v6  creates a URL for all the name value pairs.  The URL gets truncated when long.  To get around this limitation, change form method from "get" to "post" before making other additions to the form.
	form.method='post';

	// These values customized.
	// addHiddenInputToForm(form,'item_name','');  // Max 127 chars.
	// addHiddenInputToForm(form,'item_number','');  // Max 127 chars.
	// addHiddenInputToForm(form,'amount','');

	// addHiddenInputToForm(form,'on0','');	 // "Optional Field Name", max 64 chars.

	/* "Optional Field Setting", max 200 chars, with these caveats:
		each new line is represented by a ^M^J sequence.
		when the variable is displayed in the cart during checkout and in the seller's order details, multiple new lines are compressed to one space.
		all 200 chars can be retrieved by using the download report feature.
	*/
	// addHiddenInputToForm(form,'os0','');	 


	// Form customization function needs to specify the 'cmd'.
	// addHiddenInputToForm(form,'cmd','');	// "_xclick" = Buy Now, "_cart"= Add to, view, or upload cart.

	// Use with add to cart.
	// addHiddenInputToForm(form,'add','1');
	// Use with view cart.
	// addHiddenInputToForm(form,'display','1');


	addHiddenInputToForm(form,'business', paymentSend);
	addHiddenInputToForm(form,'return','http://lapedsoc.org/form/paypal_return.html');
	addHiddenInputToForm(form,'cbt_shipping','Return to Los Angeles Pediatric Society');
	addHiddenInputToForm(form,'cancel_return','http://lapedsoc.org/form/paypal_cancel.html');  // Max 60 chars.
	addHiddenInputToForm(form,'shipping','0.00');
	addHiddenInputToForm(form,'no_shipping','0');
	addHiddenInputToForm(form,'no_note','0'); // "0" (default) payer is prompted to include a note, 1 no note.  Max note length is 255 chars.
	addHiddenInputToForm(form,'cn','Leave any special instructions.'); // Label above payer's leave a note text box..  Max 40 chars.  Default "Add Instructions to Seller"

	addHiddenInputToForm(form,'currency_code','USD');
	addHiddenInputToForm(form,'tax','0.00');
	addHiddenInputToForm(form,'lc','US'); // Language for PayPal login page.
	addHiddenInputToForm(form,'cpp_headerback_color','d7c9c9'); // Optional: background color for the header of the payment page.

	addHiddenInputToForm(form,'cpp_headerborder_color','bda0a0');


	// If no existing window called paypall, a new window will be created.
	// Note: if this not set PayPal cart will *not* display the "contiune shopping" button.  Clicking the "contiune shopping" button simply closes the cart window, exposing the item window.
	// form.target='paypal';

	form.action = paymentSubmit;

	// Run the funcCustomizeForm last to override defaults.
	funcCustomizeForm();
	return true;
}

// End: Helper functions.
// ----------------------------------------


// ----------------------------------------
// Begin: Form submit entry points.
//

// Form onsubmit action.
// form object required: 
// str_idMessageArea string required: place to display the form feedback messages.
// idInputHighlight string: optional. If only one element has need of highlight name it here.  If more than on, just go ahead and hard code the element's ID into the submitForm function.
function submitForm(form, str_idMessageArea, str_idInputHighlight) {
	// This "true" code path is for unsupported browser using the unmodified form.action
	if (! supportedBrowser()) { return true; } else { form.action='#'; }
	
	if (! str_idMessageArea) {
		throw('processForm: str_idMessageArea undefined.');
	}
	var eltMessageArea = document.getElementById(str_idMessageArea);
	if (! eltMessageArea) {
		throw('processForm: eltMessageArea undefined.');
	}


	switch(form.name)	{
	case 'nameFormViewCart':
		var funcCustomizeForm = function() {
			addHiddenInputToForm(form,'cmd','_cart');
			addHiddenInputToForm(form,'display','1');
			form.target='paypal';
		}
		return processForm(form, eltMessageArea, funcCustomizeForm);

	case 'nameFormMembershipDues':
		var selector = document.getElementById('idMembershipDueSelected');
		// var duesType =  selector.options[selector.selectedIndex].text;
		var duesType =  selector.options[selector.selectedIndex].value;
		// debugMessage('duesType=' + duesType);

		var validationFunc = function() {
			if (duesType == 'unselected') {
				userCorrectionRequired('Select the type of dues to pay.','idMembershipDuesCorrectionHighlight');
				if (selector.focus) selector.focus();
				return false;
			}
		}

		var funcCustomizeForm = function() {
			switch(duesType) {
			case 'Yearly Dues':
				addHiddenInputToForm(form,'amount','125.00');
				addHiddenInputToForm(form,'item_number','20080000_1-01_01');  // Max 127 chars.
				break;
			case 'Emeritus':
				addHiddenInputToForm(form,'amount','25.00');
				addHiddenInputToForm(form,'item_number','20080000_1-02_01');  // Max 127 chars.
				break;
			case 'Life Membership':
				addHiddenInputToForm(form,'amount','1250.00');
				addHiddenInputToForm(form,'item_number','20080000_1-03_01');  // Max 127 chars.
				break;
			default:
				throw('submitForm: Unexpected dues type "' + duesType + '"');
				return false;
			}

			addHiddenInputToForm(form,'item_name',duesType);
			addHiddenInputToForm(form,'cmd','_cart');
			addHiddenInputToForm(form,'add','1');
			form.target='paypal';
			return true;
		}

		return(processForm(form, eltMessageArea, funcCustomizeForm, validationFunc));
	case 'nameFormSummberProgramDonation':
		var selector = document.getElementsByName('nameSummerProgramDonation');
		var selectedValue = undefined;
		var selectedId = undefined;
		for (var i = 0; i < selector.length; i++) {
			if (selector[i].checked) {
				selectedValue = selector[i].value;
				selectedId = selector[i].id;
			}
			// debugMessage('loop index=' + i + '  id is ' + selector[i].id);
		}
		/*
		var dedication = document.getElementsByName('nameSummerProgramDonationDedication');
		document.getElementById('idSummerProgramDonationCorrectionHighlight'));			
		debugMessage('end loop index ' + i);
		debugMessage('end loop index value ' + selector[i].id);
		debugMessage('end loop var ' + selectorId);
		*/
		var amountOther;
		if (selectedId != undefined && selectedId == 'idSummerProgramDonationOther') {
			amountOther = document.getElementById('idSummerProgramDonationOtherAmount').value;
		}

		var contributionDedication = document.getElementsByName('nameSummerProgramDonationDedication');
		var contributionDedicationValue = undefined;
		var contributionDedicationId = undefined;
		var contributionDedicationObj;
		for (var i = 0; i < contributionDedication.length; i++) {
			if (contributionDedication[i].checked) {
				contributionDedicationObj = contributionDedication[i];
				contributionDedicationId = contributionDedicationObj.id;
				/* value is 'on' if checked: contributionDedicationValue = trimExtraSpaces(contributionDedicationObj.value); */
			}
		}
		if (contributionDedicationId == undefined) {
			throw('submitForm: Unexpected contributionDedicationId');
			return false;
		}
		if (contributionDedicationId != 'idSummerProgramDonationDedicationNone') {
			contributionDedicationValue = trimExtraSpaces(document.getElementById(contributionDedicationId + 'Name').value);
			// debugMessage('contributionDedicationValue=' + contributionDedicationValue);
		} else {
			contributionDedicationValue = '';
		}


		if (document.getElementById('idMedicalGroupIs').checked) {
			var medicalGroupName = trimExtraSpaces(document.getElementById('idMedicalGroupName').value);
			var medicalGroupAddress1 = trimExtraSpaces( document.getElementById('idMedicalGroupAddress1').value);
			var medicalGroupAddress2 = trimExtraSpaces( document.getElementById('idMedicalGroupAddress2').value);
			var medicalGroupCity = trimExtraSpaces( document.getElementById('idMedicalGroupCity').value);
			var medicalGroupState = trimExtraSpaces( document.getElementById('idMedicalGroupState').value);
			var medicalGroupZip = trimExtraSpaces( document.getElementById('idMedicalGroupZip').value);
			var medicalGroupContributors = trimExtraSpaces( document.getElementById('idMedicalGroupContributors').value);
		}


		var validationFunc = function() {
			var isValid = true;
			if (selectedId == undefined) {
				userCorrectionRequired('Select a donation amount.','idSummerProgramDonationCorrectionHighlight');
				if (selector.focus) selector.focus();
				isValid=false;
			} else {
				if (selectedId == 'idSummerProgramDonationOther') {
					amountOtherValidated = amountOther.replace(/^\$/g,'');
					// debugMessage('10 amountOther=' + amountOther + ' amountOtherValidated=' + amountOtherValidated);
					if (amountOther == '') {
						userCorrectionRequired('You selected type "Other" for a donation amount, but you did not enter the amount you wish to donate.','idSummerProgramDonationOtherAmountHighlight');
					} else if (! (amountOtherValidated.match(/^\d+\.\d\d$/) || amountOtherValidated.match(/^\d+$/))) {
						userCorrectionRequired('Donation amount must be entered as dollars (such as "55"), or dollars and cents (such as "55.00").','idSummerProgramDonationOtherAmountHighlight');
					} else if (isNaN(amountOtherValidated)) {
						throw('validationFunc: expected a number. amountOtherValidated=' + amountOtherValidated);
					} else if (amountOtherValidated < 1) {
						userCorrectionRequired('Donations must be at least one dollar.','idSummerProgramDonationOtherAmountHighlight');
					}
				}
			}

			if (contributionDedicationId != 'idSummerProgramDonationDedicationNone'
				&& contributionDedicationValue == ''
			   ) {
				switch(contributionDedicationId) {
				case 'idSummerProgramDonationDedicationHonor':
					userCorrectionRequired('Enter the name this donation is in honor of.','idSummerProgramDonationDedicationHonorHighlight');
					break;
				case 'idSummerProgramDonationDedicationMemory':
					userCorrectionRequired('Enter the name this donation is in memory of.','idSummerProgramDonationDedicationMemoryHighlight');
					break;
				default:
					throw('submitForm: Unexpected donation dedication type "' + contributionDedicationId + '"');
					return false;
				}
				if (contributionDedicationObj.focus) contributionDedicationObj.focus();
			}

			if (document.getElementById('idMedicalGroupIs').checked) {
				if (medicalGroupName == '') {
					userCorrectionRequired('Enter the Medical Group\'s name.','idMedicalGroupNameHighlight');
				}

				if (medicalGroupAddress1 == '') {
					userCorrectionRequired('Enter the Medical Group\'s address.','idMedicalGroupAddress1Highlight');
				}

				if (medicalGroupCity == '') {
					userCorrectionRequired('Enter the Medical Group\'s city.','idMedicalGroupCityHighlight');
				}

				if (medicalGroupState == '') {
					userCorrectionRequired('Enter the Medical Group\'s state.','idMedicalGroupStateHighlight1','idMedicalGroupStateHighlight2');
				} else if (! medicalGroupState.match(/(?:DC)|(?:AA)|(?:AE)|(?:AP)|(?:AL)|(?:AK)|(?:AZ)|(?:AR)|(?:CA)|(?:CO)|(?:CT)|(?:DE)|(?:FL)|(?:GA)|(?:HI)|(?:ID)|(?:IL)|(?:IN)|(?:IA)|(?:KS)|(?:KY)|(?:LA)|(?:ME)|(?:MD)|(?:MA)|(?:MI)|(?:MN)|(?:MS)|(?:MO)|(?:MT)|(?:NE)|(?:NV)|(?:NH)|(?:NJ)|(?:NM)|(?:NY)|(?:NC)|(?:ND)|(?:OH)|(?:OK)|(?:OR)|(?:PA)|(?:RI)|(?:SC)|(?:SD)|(?:TN)|(?:TX)|(?:UT)|(?:VT)|(?:VA)|(?:WA)|(?:WV)|(?:WI)|(?:WY)/i)) {
					/* Could use: 
						http://javascript.internet.com/forms/country-state-drop-down.html
						http://msconline.maconstate.edu/tutorials/JSDHTML/JSDHTML06/jsdhtml06-03.htm
					*/
					userCorrectionRequired('The Medical Group\'s state code is incorrect.','idMedicalGroupStateHighlight1','idMedicalGroupStateHighlight2');
				}
				if (medicalGroupZip == '') {
					userCorrectionRequired('Enter the Medical Group\'s Zip Code.','idMedicalGroupZipHighlight1', 'idMedicalGroupZipHighlight2');
				} else if (! (medicalGroupZip.match(/^\d{5}$/) || medicalGroupZip.match(/^\d{5}-\d{4}$/) || medicalGroupZip.match(/^\d{9}$/))) {
					userCorrectionRequired('The Medical Group\'s Zip Code must be either a 5 digit zip code, or 9 digit zip plus four code.','idMedicalGroupZipHighlight1', 'idMedicalGroupZipHighlight2');
				}

				/*
				if (medicalGroupContributors == '') {
					userCorrectionRequired('Enter the Medical Group contributors to recognize.','idMedicalGroupContributorsHighlight');
				}
				*/

			}


			return isValid;
		}

		var funcCustomizeForm = function() {
			switch(selectedId) {
			case 'idSummerProgramDonationPlatinum':
				addHiddenInputToForm(form,'amount','5000.00');
				addHiddenInputToForm(form,'item_number','20080000_2-07_01');  // Max 127 chars.
				break;
			case 'idSummerProgramDonationGold':
				addHiddenInputToForm(form,'amount','2000.00');
				addHiddenInputToForm(form,'item_number','20080000_2-06_01');  // Max 127 chars.
				break;
			case 'idSummerProgramDonationSilver':
				addHiddenInputToForm(form,'amount','1000.00');
				addHiddenInputToForm(form,'item_number','20080000_2-05_01');  // Max 127 chars.
				break;
			case 'idSummerProgramDonationStandard':
				addHiddenInputToForm(form,'amount','500.00');
				addHiddenInputToForm(form,'item_number','20080000_2-04_01');  // Max 127 chars.
				break;
			case 'idSummerProgramDonationDonor':
				addHiddenInputToForm(form,'amount','100.00');
				addHiddenInputToForm(form,'item_number','20080000_2-03_01');  // Max 127 chars.
				break;
			case 'idSummerProgramDonationIndividual':
				addHiddenInputToForm(form,'amount','50.00');
				addHiddenInputToForm(form,'item_number','20080000_2-02_01');  // Max 127 chars.
				break;
			case 'idSummerProgramDonationOther':
				addHiddenInputToForm(form,'amount',amountOtherValidated);
				addHiddenInputToForm(form,'item_number','20080000_2-01_01');  // Max 127 chars.
				break;
			default:
				throw('submitForm: Unexpected dues type "' + duesType + '"');
				return false;
			}

			addHiddenInputToForm(form,'on0', 'Customization');
			var os0 = '';

			if (contributionDedicationValue) {
				if (os0 != '') os0 += ' ';
				os0 += '[Dedication: ' + contributionDedicationValue + ']';
			}

			if (document.getElementById('idSummerProgramDonationTargetSeidel').checked) {
				if (os0 != '') os0 += ' ';
				os0 += '[Target Dr. Jim Seidel Memorial]';
			}

			if (document.getElementById('idMedicalGroupIs').checked) {
				if (os0 != '') os0 += ' ';
				os0 += '[Medical Group: ' + medicalGroupName + '; ' + medicalGroupAddress1 + '; ' + medicalGroupAddress2 + '; ' + medicalGroupCity + '; ' + medicalGroupState + '; ' + medicalGroupZip;
				os0 += ']';
			}

			// Paypal will not report the value of os1 if os0 is not used as well.  Include the text 'none' do give context to an otherwise meaningless option field "Customization".
			if (os0 == '') {
				os0 += 'none';
			}
			addHiddenInputToForm(form,'os0', os0);
			
				
			if (document.getElementById('idMedicalGroupIs').checked && medicalGroupContributors != '') {
				addHiddenInputToForm(form,'on1','Contribution Recognition');
				addHiddenInputToForm(form,'os1', medicalGroupContributors.replace(/\n/g, '; '));
			}

			addHiddenInputToForm(form,'item_name',selectedValue);
			addHiddenInputToForm(form,'cmd','_cart');
			addHiddenInputToForm(form,'add','1');
			form.target='paypal';
			return true;
		}

		return(processForm(form, eltMessageArea, funcCustomizeForm, validationFunc));

	default:
		throw('submitForm: Unexpected form name "' + form.name + '"');
		return(false);
	}
}

// ----------------------------------------
// End: Form submit entry points.
