var PComment = PComment || {}; PComment.Ajax = { XMLHttpFactories: [ function () {return new XMLHttpRequest()}, function () {return new ActiveXObject("Msxml2.XMLHTTP")}, function () {return new ActiveXObject("Msxml3.XMLHTTP")}, function () {return new ActiveXObject("Microsoft.XMLHTTP")} ], sendRequest: function (url, callback, postData) { var req = this.createXMLHTTPObject(); var method = (postData) ? "POST" : "GET"; if (!req) { return; } req.open(method, url, true); req.setRequestHeader('User-Agent', 'XMLHTTP/1.0'); req.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); if (postData) { req.setRequestHeader('Content-type','application/x-www-form-urlencoded'); } req.onreadystatechange = function () { if (req.readyState != 4) { return; } if (req.status != 200 && req.status != 304) { return; } callback(req); } if (req.readyState == 4) { return; } req.send(postData); }, createXMLHTTPObject: function () { var xmlhttp = false; for (var i = 0; i < this.XMLHttpFactories.length; i++) { try { xmlhttp = this.XMLHttpFactories[i](); } catch (e) { continue; } break; } return xmlhttp; }, get: function (url, container_id) { this.sendRequest(url, function (req) { document.getElementById(container_id).innerHTML = req.responseText; }); }, post: function (url, container_id, postData) { this.sendRequest(url, function (req) { document.getElementById(container_id).innerHTML = req.responseText; }, postData); } }; PComment.Utils = { importCss: function (cssFile) { if (document.createStyleSheet) { document.createStyleSheet(cssFile); } else { var styles = "@import url(" + cssFile + ");"; var newSS = document.createElement('link'); newSS.rel = 'stylesheet'; newSS.href = 'data:text/css,' + escape(styles); document.getElementsByTagName("head")[0].appendChild(newSS); } }, getElementsByClass: function (searchClass, node, tag) { var classElements = new Array(); if (node == null) { node = document; } if (tag == null) { tag = '*'; } var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (var i = 0, j = 0; i < elsLen; i++) { if (pattern.test(els[i].className)) { classElements[j] = els[i]; j++; } } return classElements; }, addEvent: function (obj, type, fn) { if (obj.addEventListener) { obj.addEventListener( type, fn, false ); } else if (obj.attachEvent) { obj["e"+type+fn] = fn; obj[type+fn] = function() { obj["e"+type+fn]( window.event ); } obj.attachEvent( "on"+type, obj[type+fn] ); } else { obj["on"+type] = obj["e"+type+fn]; } }, serialize: function(form) { if (!form || form.nodeName !== "FORM") { return; } var i, j, q = []; for (i = form.elements.length - 1; i >= 0; i = i - 1) { if (form.elements[i].name === "") { continue; } switch (form.elements[i].nodeName) { case 'INPUT': switch (form.elements[i].type) { case 'text': case 'hidden': case 'password': case 'button': case 'reset': case 'submit': q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); break; case 'checkbox': case 'radio': if (form.elements[i].checked) { q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); } break; } break; case 'file': break; case 'TEXTAREA': q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); break; case 'SELECT': switch (form.elements[i].type) { case 'select-one': q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); break; case 'select-multiple': for (j = form.elements[i].options.length - 1; j >= 0; j = j - 1) { if (form.elements[i].options[j].selected) { q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].options[j].value)); } } break; } break; case 'BUTTON': switch (form.elements[i].type) { case 'reset': case 'submit': case 'button': q.push(form.elements[i].name + "=" + encodeURIComponent(form.elements[i].value)); break; } break; } } return q.join("&"); } }; PComment.Front = { commentSubmit: function (frm, validationErrors, baseUrl) { var message = validationErrors.dataNotValid; var isValid = true; var id = frm.id.value; var name = frm.name.value; var comment = frm.comment.value; var vcode = frm.verification.value; var re = /^([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+)+$/; if (name.length < 1) { message += "\n - " + validationErrors.requiredName; isValid = false; } if (comment.length < 1) { message += "\n - " + validationErrors.requiredComment; isValid = false; } if (frm.email && frm.email.value.length < 1) { message += "\n - " + validationErrors.requiredEmail; isValid = false; } if (frm.email && frm.email.value.match(re) == null){ message += "\n - " + validationErrors.invalidEmail;; isValid = false; } if (vcode.length < 1) { message += "\n - " + validationErrors.requiredVcode; isValid = false; } if (isValid) { PComment.Ajax.sendRequest(baseUrl + 'frontend_js/include/captcha_process.php?id=' + id + '&code=' + frm.verification.value, function (req) { if (req.responseText == '1') { PComment.Ajax.sendRequest(baseUrl + 'frontend_js/include/submit_comment.php', function (req) { // reset comments form PComment.Front.resetCommentForm(frm); // show message PComment.Front.showMessage('sys_message_wrapper_' + id, req.responseText); // reset verification image PComment.Ajax.get(baseUrl + 'frontend_js/include/captcha_refresh.php?id=' + id, 'captcha_' + id); // reload the comments PComment.Ajax.get(baseUrl + 'frontend_js/include/load_comments.php?id=' + id, "comments_wrapper_" + id); }, PComment.Utils.serialize(frm)); } else { message += "\n - " + req.responseText; alert(message); } }); } if (!isValid) { alert(message); } }, resetCommentForm: function (frm) { frm.name.value = ''; frm.comment.value = ''; frm.verification.value = ''; if (frm.email != undefined) { frm.email.value = ''; } }, showMessage: function(wrapper, msg) { document.getElementById(wrapper).innerHTML = msg; } };document.writeln('
'); validationErrors = { dataNotValid: "Your form data was not correct", requiredName: "Your Name", requiredEmail: "Your Email", invalidEmail: "Invalid email address", requiredComment: "Place Your Item Description Here With Your Phone Number.", requiredVcode: "Verification Code" } PComment.Utils.importCss("http://www.1010wspc.com/trading_post/css/style.css"); PComment.Ajax.get("/trading_post/frontend_js/include/load_form.php?1=1&id=1", "comments_form_wrapper_1");