﻿



function initCommentList(){
	$("#_new_comment_list").quickPager({
		pageSize: 10,
		currentPage: 1,
		pagerLocation: "after"
	});
}

function initCatalogList(){
	$("#_news_catalog_list").quickPager({
		pageSize: 10,
		currentPage: 1,
		pagerLocation: "after"
	});
}

function initNewList(sett){
	$("#_news_list_"+sett+" tbody").quickPager({
		pageSize: 5,
		currentPage: 1,
		holder: "#_news_list_pager_"+sett,
		pagerLocation: "holder"
	});
}


function showFormComment(){
	$("#new_frm_comment").slideToggle("slow");
}
function showListComment(){
	$("#new_list_comment").slideToggle("fast");
	
	var n = $("#_detail_new_id").val();
	var url = "modules/news/news.action.php?cmd=list_comment&id="+n;
	loadPortlet(url,"new_list_comment");
}

function initCommentForm(){
	var message = "Người Việt xài hàng Việt. Xin vui lòng gõ tiếng Việt có dấu.";
	var content = $("#_comment_form_content");
	content.val(message);
	content.focus(function(){
		if($(this).val()==message){
			$(this).val('');
		}
	});
}

function submitCommentForm(){
	var message = "Người Việt xài hàng Việt. Xin vui lòng gõ tiếng Việt có dấu.";
	var content = $("#_comment_form_content");
	if(content.val()==message){
		content.val('');
	}
	
	$("#_new_comment_form").validate({
		rules: {
			"_comment_form_name": {
				required: true,
				maxlength: 200
			},
			"_comment_form_email": {
				required: true,
				email: true,
				maxlength: 220
			},
			"_comment_form_content": {
				required: true,
				maxlength: 1000
			},
			"_comment_form_code":{
				required: true,
				equalTo: "#_comment_form_code2"
			}
		},
		messages: {
			"_comment_form_name": {
				required: "Tên của bạn không được để trống!",
				maxlength: "Tối đa 200 ký tự!"
			},
			"_comment_form_email": {
				required: "Email của bạn không được để trống!",
				email: "Email không hợp lệ!",
				maxlength: "Tối đa 220 ký tự!"
			},
			"_comment_form_content": {
				required: "Nội dung không được để trống!",
				maxlength: "Tối đa 1000 ký tự!"
			},
			"_comment_form_code":{
				required: "Mã số xác nhận không được để trống!",
				equalTo: "Mã số xác nhận không chính xác !"
			}
		}
	});
	
	$("#_faq_add_frm input[class='error']").addClass("control_err");
	
		if($("#_new_comment_form").valid()){
			var n = $("#_comment_form_name").val();
			var e = $("#_comment_form_email").val();
			var c = $("#_comment_form_content").val();
			var id = $("#_comment_form_new").val();
			$.post('modules/news/news.action.php', { cmd: "post_comment", id: id, name: n, email: e, content: c}, function(response){
				$("#new_frm_comment").html('<b>'+response+'</b>');
				setTimeout(function(){
					$("#new_frm_comment").slideUp();
				}, 2000);
			});
		}
}
