function contactFormcheck(theform,themessage,thediv) {
	var badcount = 0;
	var errormsg = "";
	var emsg = "";
	if (!theform) { theform = document.MiniContactForm; }
	if (thediv == '') { thediv = 'getintouchform'; }
	if (themessage == '') { themessage = '<h3>Thank you<\/h3><p>We will be in touch with you soon.<\/p>'; }

	if (theform.Name.value=='' || theform.Name.value=='Name') {
		badcount++;
		errormsg += '\n' + badcount + ': Please enter your name.';
		theform.Name.value = 'Name';
		theform.Name.className = theform.Name.className + ' required';
		}
	if (theform.Email.value=='' || theform.Email.value=='Email') {
		badcount++;
		errormsg += '\n' + badcount + ': Please enter your email address.';
		theform.Email.value = 'Email';
		theform.Email.className = theform.Email.className + ' required';
		} else {
		emsg = Contactemailcheck(theform.Email.value);
		if (emsg != '') {
			badcount++;
			errormsg += '\n' + badcount + ': ' + emsg;
			theform.Email.value = 'Email';
			theform.Email.className = theform.Email.className + ' required';
			}
		}
	if (theform.textarea_Message.value.length == 0 || theform.textarea_Message.value == 'Message') {
		badcount++;
		errormsg += '\n' + badcount + ': Please enter your message.';
		theform.textarea_Message.value = 'Message';
		theform.textarea_Message.className = theform.textarea_Message.className + ' required';
		}
	if (badcount > 0) {
		alert(errormsg);
		} else {
		// set up the ajax submit
		var geturl = '';
		var posturl = '/being-strategic/feedback';
		var poststr = "feedback_mode=ajax";
		for (var i=0;i<theform.elements.length;i++) {
			if (theform.elements[i].type == 'checkbox' || theform.elements[i].type == 'radio') {
				if (theform.elements[i].checked) {
					poststr = poststr + "&" + theform.elements[i].name + "=" + encodeURIComponent( theform.elements[i].value );
					}
				} else {
				poststr = poststr + "&" + theform.elements[i].name + "=" + encodeURIComponent( theform.elements[i].value );
				}
			}

		// send to ajax:
		// get url, post url, post string, function upon success, function upon fail
		DOCStudioSharedAjaxFunction(
			geturl,
			posturl,
			poststr,
			function(aresponse) {
				var selectDiv = document.getElementById(thediv);
				if (aresponse != 'OK') {
					selectDiv.innerHTML=themessage + aresponse;
					} else {
					selectDiv.innerHTML=themessage
					}
				},
			function(msg) {
				alert('Please try again.');
			})

		}
}

function Contactemailcheck(email) {
	var emailadd = email;
	var msg = "";
	if (emailadd.indexOf('"') != -1 || emailadd.indexOf("'") != -1) {
		msg = "Your email address cannot contain quotes. ";
		}
	if (emailadd.indexOf(",") != -1) {
		msg += "Your email address cannot contain commas. ";
		}
	if (msg=="") {
		if (emailadd.search(/^\S+\@\S+\.\S+$/) == -1) {
			msg = "Please enter a full email address - for example, byron@yahoo.com";
			}
		}
	
	return(msg);
}
