/*
sample:

<form id="maintPlans" onsubmit="doAjaxComment(this.id)">
	<input name="Full Name" value="">
</form>
*/

allFieldsRequired = true;			// Are all fields requred? True or false.
successMessage = '';				// Message popup after sending message 
									// Set to '' if you don't want it to come up.

targetLocation = '/thanks.html';	// Set location to go to after email is sent.
									// Set to '' if you don't want it to go anywhere.

										
function doAjaxComment(inID) {
	missingList = new Array();
	inFrm = document.forms[inID].elements;
	outURL = 'ajaxComment.php?=';
	//	Parse form content into URL string
	
	for (i=0; i<inFrm.length; i++) {
		if (inFrm[i].name) {
			if (inFrm[i].type == "checkbox") {
				if (inFrm[i].checked) {
					outURL = outURL + '&' + inFrm[i].name + '=Yes';
				} else {
					outURL = outURL + '&' + inFrm[i].name + '=No';
				}
			} else if (inFrm[i].type == "radio") {
				if (inFrm[i].checked) {
					outURL = outURL + '&' + inFrm[i].name + '=' + inFrm[i].value;
					missingList[inFrm[i].name] = true;
				} else {
					if (missingList[inFrm[i].name] != true) {
						missingList[inFrm[i].name] = false;
					}
				}
			} else {
				if (inFrm[i].value) {
					outURL = outURL + '&' + inFrm[i].name + '=' + escape(inFrm[i].value);
					missingList[inFrm[i].name] = true;
				} else {
					missingList[inFrm[i].name] = false;
				}
			}
		}
	}
	
	somethingMissing = false;
	for (var i in missingList) {
		if (!missingList[i]) {	somethingMissing = true;	}
	}
	
	if ((somethingMissing)&&(allFieldsRequired)) {
		alert('All fields are required');
	} else {
		$.get(outURL, function(data){
			if (data == 'true') {
				if (successMessage) {
					alert(successMessage);
				}
				if (targetLocation) {
					window.location = targetLocation;
				}
			} else {
				alert(data);
			}
		});
	}
}