page = 0;
limit = 5;
max = maxPages();

$(document).ready(function() { 
	$('#process').submit(function() { 
		var options = { 
			success: function(responseText) { 
				$('#comments-list li:first').before("<li>" + stripper(responseText) + "</li>");
				$('#comments-list li:first').effect("highlight", {color: '#F88326'}, 3000);
			}
		}; 
	    $(this).ajaxSubmit(options); 
	    $(this).clearForm();
	    return false; 
	});

	$('#next').click( function() { 
		page=++page;
		if(page<=max) {
			start = page*limit;
			$.get("kiran/list.php?start=" + start, function(list){
				$('#thelist').replaceWith(list);
			});
	 	} else {
	 		page=max;
	 		return false;
	 	}
	});
	
	
	
	$('#prev').click( function() { 
		page=--page;
		
		if(page>=0) {
			start = page*limit;
			$.get("kiran/list.php?start=" + start, function(list){
				$('#thelist').replaceWith(list);
			});
		} else {
			page=0;
			return false;
		}
	});

});


function maxPages() {
	$.get("kiran/functions.php?action=max_pages", function(pages){
		max = pages/limit;
		return Math.ceil(max);
	});
}

function stripper(str) { //STRIP TAGS AND SLASHES
   str=str.replace(/\\'/g,'\'');
   str=str.replace(/\\"/g,'"');
   str=str.replace(/\\\\/g,'\\');
   str=str.replace(/\\0/g,'\0');
   str=str.replace(/&lt;\/?[^&gt;]+&gt;/gi, "");
   return str;
}