function trim(s){
  return s.replace(/^\s+|\s+$/, '');
}
function checkCommentForm(){
    var captcha_text_value=document.getElementById("captcha_text").value;
    if (document.getElementById("comment_name").value.length==0){
        alert("Please input your name");
        document.getElementById("comment_name").focus();
    }else if (document.getElementById("comment_comment").value.length==0 || document.getElementById("comment_comment").value=="Comment Here..."){
        alert("Please input your comment");
        document.getElementById("comment_comment").focus();
    }else if (captcha_text_value.length==0){
        alert("Please input the text code");
        document.getElementById("captcha_text").focus();
    }else{
        new HttpRequest().start("/get_captcha.html?rnd="+encodeURIComponent(Date()), 
                                function(responseText){
	                            responseText=trim(responseText);
                                    if (captcha_text_value==responseText){
                                        alert("Thank you for submitting your comment, we will review it before publishing on the website.");
                                        document.getElementById("comment_form").submit();
                                    }else{
                                        alert("The text in the box does not match, please correct it.");
                                        captcha_text.focus();
                                    }
                                }
                               );
    }
    return false;
}

