function validateCaptcha(formId)
{
	var theform = document.getElementById(formId);

	var challengeField = theform.elements['recaptcha_challenge_field'].value ;
	var responseField = theform.elements['recaptcha_response_field'].value ;
	//var challengeField = $(formId + "#recaptcha_challenge_field").val();
	//var responseField = $(formId + "#recaptcha_response_field").val();
	
	//console.log(challengeField);
	//console.log(responseField);
	//return false;
	var html = $.ajax({
		type: "POST",
		url: "/common/captchaverify.php",
		data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
		async: false
		}).responseText;
 	
	//console.log( html );
	if(html == "success") {
		//Add the Action to the Form
		//Indicate a Successful Captcha
		// Uncomment the following line in your application
		theform.submit();
		return true;
	} else {
		$("#captchaStatus").html("The security code you entered did not match. Please try again.");
		Recaptcha.reload();
		return false;
	}
}	


function validateEmailFormCaptcha(formId, imageRegenSrc, imageId, formAction){
	
	$("#captchaStatus").html("");
	
	var theform = document.getElementById(formId);
	var responseField = theform.elements['captcha'].value ;
	
	//var challengeField = $(formId + "#recaptcha_challenge_field").val();
	//var responseField = $(formId + "#recaptcha_response_field").val();
	
	//console.log(challengeField);
	//console.log(responseField);
	//return false;
	var html = $.ajax({
		type: "POST",
		url: "/includes/email-form-handler.php",
		data: "captcha=" + responseField,
		async: false
		}).responseText;
		
		html =   html.replace(/^\s+|\s+$/g, '') ;
		
		success = "success";
 	
	//console.log( html );
	if(html == success) {
		//Add the Action to the Form
		//Indicate a Successful Captcha
		// Uncomment the following line in your application
		//Now post all the variables to the form handler
		theform.action=formAction;
		theform.submit();
		return true;
	} else {
		$("#captchaStatus").html("The security code you entered did not match. Please try again.");
		
		var img = document.getElementById(imageId);
		img.src = imageRegenSrc;
	
		return false;
	}
}	

function postForm(path, theform) {
	
	
    method = "post"; // Set method to post by default, if not specified.

    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);
	
	for (i = 0; i < theform.elements.length; i++){
		 var el = theform.elements[i];
		 
		alert('building form parm - name - ' + el.name + ' = ' + el.value);
		 
		var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", el.name);
        hiddenField.setAttribute("value", el.value);

        form.appendChild(hiddenField);
		 
	}
	
	alert('action - ' + path);
	
    document.body.appendChild(form);
	
	
	alert('submitting form ');
    form.submit();
}



