var productConfirmValueWrongCount = 0; var commentSubmitted = false; String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); } var checkCommentSubmit = function (productID){ var msg = ""; var rv = true; var confirmvalue = 0; var comment_text = ""; var comment_name = ""; var comment_city = ""; var comment_type = ""; var comment_ref_id = ""; var comment_date = ""; var comment_descr = ""; var confirm_value = ""; // prevent a double submit if (commentSubmitted) { return false; } comment_text = document.forms['prsc_insert'].elements['PRODUCT_COMMENT.TEXT'].value; comment_name = document.forms['prsc_insert'].elements['PRODUCT_COMMENT.NAME'].value; comment_city = document.forms['prsc_insert'].elements['PRODUCT_COMMENT.CITY'].value; comment_type = document.forms['prsc_insert'].elements['PRODUCT_COMMENT.TYPE'].value; comment_ref_id = document.forms['prsc_insert'].elements['PRODUCT_COMMENT.REF_ID'].value; comment_date = document.forms['prsc_insert'].elements['ZA_ARTICLE.ARTICLE_DATE'].value; comment_descr = document.forms['prsc_insert'].elements['ZA_ARTICLE.DESCR'].value; confirm_value = document.forms['prsc_insert'].elements['confirm_value'].value; if (comment_text == "") { msg += "You must provide a comment.\n"; } else if (comment_text.length > 2500) { msg += "Your comment must not exceed 2500 characters. Please shorten your comment by " + (document.forms['prsc_insert'].elements['PRODUCT_COMMENT.TEXT'].value.length - 2500) + " characters.\n"; } if (document.forms['prsc_insert'].elements['PRODUCT_COMMENT.NAME'].value == "") { msg += "You must provide your first name.\n"; } if (document.forms['prsc_insert'].elements['PRODUCT_COMMENT.CITY'].value == "") { msg += "You must provide your hometown.\n"; } if (document.forms['prsc_insert'].elements['confirm_value'].value.trim() != "12") { msg += "Your answer to What is eight plus four? is not correct.\n"; productConfirmValueWrongCount++; if (productConfirmValueWrongCount > 5) { productConfirmValueWrongCount=0; document.location = "http://www.competitivecyclist.com/za/CCM?PAGE=HOME"; } } if (msg != "") { alert("Your form has the following problems:\n\n" + msg); rv = false; } else { commentSubmitted= true; var url = "/za/CCM"; var pars = "&OPTION=COMMENT_INSERT&PRODUCT_COMMENT.TEXT=" + comment_text + "&PRODUCT_COMMENT.NAME=" + comment_name + "&PRODUCT_COMMENT.CITY=" + comment_city + "&PRODUCT_COMMENT.TYPE=" + comment_type + "&PRODUCT_COMMENT.REF_ID=" + comment_ref_id + "&ZA_ARTICLE.ARTICLE_DATE=" + comment_date + "&ZA_ARTICLE.DESCR=" + comment_descr + "&confirm_value=" + confirm_value + "&rand=" + Math.floor(Math.random()*10000001); var myAjax = new Ajax.Request( url, { method: 'post', parameters: pars, onComplete: dbUpdateComplete(productID)}); } } var dbUpdateComplete = function (productID){ setTimeout("getComments('','YES'," + productID + ")", 3000); //getComments('','YES',productID); } var getComments = function (page,refresh,productID){ var url = "/za/CCM"; var pars = "PAGE=PRODUCT_COMMENTS&PAGE_NUM=" + page + "&PRODUCT.ID=" + productID + "&REFRESH_COMMENTS=" + refresh + "&PRSET_VERSION=" + 4 + "&rand=" + Math.floor(Math.random()*10000001); var myAjax = new Ajax.Request( url, { method: 'post', parameters: pars, onComplete: getCommentsComplete}); } var getCommentsComplete = function (request){ $('product_comments').innerHTML = request.responseText; clearDataEntered(); } var focusToCommentText = function (){ document.getElementById('add_Comment').focus(); } var clearDataEntered = function (){ document.forms['prsc_insert'].elements['PRODUCT_COMMENT.TEXT'].value = ""; document.forms['prsc_insert'].elements['PRODUCT_COMMENT.NAME'].value = ""; document.forms['prsc_insert'].elements['PRODUCT_COMMENT.CITY'].value = ""; document.forms['prsc_insert'].elements['confirm_value'].value = ""; }