function postComment(article_id) {
  new Ajax.Request (
    "/articles/comment/" + article_id + "/",
    {
	  method: "post",
	  parameters: Form.serialize('comment_form'),
      onComplete:  parseResponse
    }
  );
}

function showRecaptcha() {
  Recaptcha.create("6LdGGQAAAAAAAEr0sgM_vZjCZyNKqlceah1ccrbd", "captcha", {
        tabindex: 0,
        callback: Recaptcha.focus_response_field
  });
}

function parseResponse(transport) {
	var response = transport.responseText
	var jsonObj = eval("("+response+")") 
	if (jsonObj.success) {
		$('page').innerHTML = "<div style=\"text-align:center; font-size:30px; color:gray;\">Thanks! Your comment has been posted.</div>"
	}
	else {
		if (jsonObj.not_success.name) {
			var nameError = "<span style=\"font-size:20px;\"> &#8727</span> Please enter your name."
			$('nameError').innerHTML = nameError;
			showRecaptcha();
		} 
		else {
			$('nameError').innerHTML = "";
		}
		if (jsonObj.not_success.email) {
			var emailError = "<span style=\"font-size:20px;\"> &#8727</span> Please enter your email address...it won't be shared"
			$('emailError').innerHTML = emailError;
			showRecaptcha();
		} 
		else {
			$('emailError').innerHTML = "";
		}
		if (jsonObj.not_success.captcha_error) {
			var captchaError = "<span style=\"font-size:20px;\"> &#8727</span> Please try entering the words again."
			$('captchaError').innerHTML = captchaError;
			showRecaptcha();
		}
	}
}
