var page_id = location.pathname.replace(/\//g, '-').substr(1); if (page_id.substr(page_id.length-1, 1) == '-') { page_id = page_id+'index.html'; } if (page_id == "newone.html") { page_id = "comments.html"; } $(document).ready(function() { //alert(page_id); $.ajax({ type: "GET", url: '/php/comments.php?form&page_id='+page_id, success: function(html){ document.getElementById('commentFormContent').innerHTML= html; $('#commentForm').submit(function() { if ($('#name').val() == '') { alert("Заполните поля имя!"); return false; } if ($('#comment').val() == '') { alert("Введите текст сообщения!"); return false; } if (!$('#notrobot').is(':checked')) { alert( "Отметьте галочку" ); return false; } /* if ($('#secpic').val() == '') { alert("Введите защитный код!"); return false; }*/ $.blockUI(); $(this).ajaxSubmit({ success: processJson, dataType: 'xml'}); return false; }); } }); //$('#comments_div').load('/comments/'+page_id+'?'+Math.random()); //alert('/comments/'+page_id); $.ajax({ type: "GET", dataType: 'text', url: '/php/comments.php?page_id='+page_id, success: function(html){ //alert(html); showComment(html); } }); }); function showComment(content){ content = '
'+content+'
'; document.getElementById('comments_div').innerHTML= content; var table = document.getElementById('comments_table'); count_page = Math.ceil(table.getElementsByTagName('tr').length/(3*5)); if (count_page > 1) { pager_content = ''; for(var i=0; i'+(i+1)+'  '; } document.getElementById('comment_pager_top').innerHTML = pager_content; document.getElementById('comment_pager_bootom').innerHTML = pager_content; } showPage(1); } function showPage(page) { var table = document.getElementById('comments_table'); var trList= table.getElementsByTagName('tr'); p = page - 1; s = p*5*3; e = s + (5*3); npost = 1; for (var i=0;i '; npost++; } if (i < s || i> e ) { trList[i].style.display = 'none'; } else { trList[i].style.display = ''; } } } function processJson(answer) { result = $(answer).find('result').text(); $.unblockUI(); if (result == 'success') { $("#name").val(''); $("#comment").val(''); $.ajax({ type: "GET", url: '/comments/'+page_id+'?'+Math.random(), success: function(html){ showComment(html); }}); /*document.getElementById('secpic_img').src = '/php/comments.php?secpic&' + Math.random();*/ alert('Коментарий успешно добавлен!\n\nПовторный комментарий можно оставлять не ранее чем через 15 минут.'); } else { error = $(answer).find('error').text(); /*document.getElementById('secpic_img').src = '/php/comments.php?secpic&' + Math.random();*/ /*$("#secpic").val('');*/ alert(error); } } function isNotMax(e){ e = e || window.event; var target = e.target || e.srcElement; var code=e.keyCode?e.keyCode:(e.which?e.which:e.charCode) switch (code){ case 13: case 8: case 9: case 46: case 37: case 38: case 39: case 40: document.getElementById('countchars').innerHTML = target.value.length; return true; } document.getElementById('countchars').innerHTML = target.value.length; return target.value.length < target.getAttribute('maxlength'); }