Project.modules.comment= {
	init : function()
	{
		totalpage = $('#total_page').val();
		iRecId = $('#iRecId').val();
		eRecType = $('#eRecType').val();
		ipage = 2;
		var searchkeyword = $('#searchkeyword').val();

		$('#getmoredata').click(function() {
			if(ipage <= totalpage){
				$('#getmoredata_div').hide();
				$('#loading_div').show();
				$.post(site_url+'user/user/comment_block',{
					'ipage':ipage,
					'searchkeyword':searchkeyword,
					'iRecId':iRecId,
					'eRecType':eRecType
				}, function(data){
					if(data!="")
						$('#dealmoredata').append(data);
					if(ipage < totalpage){
						$('#getmoredata_div').show();
					}
					$('#loading_div').hide();
					ipage++;
				//alert(ipage);
				});
			}
		});

		$('.btnDeleteComment').live('click', function () {
			if (confirm('Are you sure you want to delete comment?')) {
				var comment_id = $(this).parents('div').find('#iCommentId').val();
				$.post(site_url+'user/user/deleteComments',{
					iCommentId: comment_id
				}, function(data){
					if ($.trim(data) != '') {
						$('#commentdiv_'+comment_id).remove();
						if ($('.comment_div').length == 0) {
							if ($('#getmoredata_div').css('display') == 'none') {
								var error_msg = '<div class="errormsg" align="center">No Comments Available</div>';
								$('#dealmoredata').html(error_msg);
							}
						}
					//						curr_page = $('.curr_page:last').val();
					//						//if ($('.comment_div').length != 0 ) {
					//						if ($('#getmoredata_div').css('display') != 'none' && curr_page >= 0 ) {
					//							for(var i=1; i<=curr_page; i++) {
					//								if (i==1) {
					//									mode = 'add';
					//									if (ipage != 1) ipage = 1;
					//								} else {
					//									mode = '';
					//								}
					//								//setTimeout("$('#getmoredata').trigger('click')", 500);
					//								var val = 500 * i;
					//								setTimeout(function(){
					//									$('#getmoredata').trigger('click');
					//								},val);
					//							}
					//						} else {
					//							var error_msg = '<div class="errormsg" align="center">No Comments Available</div>';
					//							$('#dealmoredata').html(error_msg);
					//						}
					//}
					}
					return false;
				});
			}
		});
	}
};

function article_love(articleid,articletype,liketype){
	var URL = site_url+"user/user/article_love"
	$.post(""+URL+"", {
		iArticleId: ""+articleid+"",
		eArticleType: ""+articletype+"",
		eLikeType: ""+liketype+""
	},
	function(data){
		$('#loveitartilce_'+articleid).html(data);
	});
}

function user_follow(userid,followerid,articleid){
	var URL = site_url+"user/user/follow_me"
	$.post(""+URL+"", {
		iUserId: ""+userid+"",
		iFollowerId: ""+followerid+""
	},
	function(data){
		response=jQuery.parseJSON(data);
		if(response['errmsg'] == 'Done'){
			window.location.href = site_url+'detail-page-post-listing-'+articleid+'.html';
		} else {
			return false;
		}
	});
}

//$('#btnCommentPost').click( function () {
//	var eRecType = $(this).parents('form').find('#eRecType').val();
//	var iRecId = $(this).parents('form').find('#iRecId').val();
//	var tDescription = $(this).parents('form').find('#tDescription').val();
//	var URL = site_url+"user/postComments"
//	$.post(""+URL+"", {
//		eRecType : ""+eRecType+"",
//		iRecId : ""+iRecId+"",
//		tDescription : ""+tDescription+""
//	},
//	function (data) {
//		if ($.trim(data) == '1'){
//
//			var URL = site_url+"user/comment_block";
//			$.ajax({
//				type:'post',
//				URL:URL,
//				success: function(resp) {
//					alert(resp);
//					return false;
//				}
//			});
//		}
//	});
//});
//
//function comment_test() {
//	var URLs = site_url+"user/user/comment_block";
//	$.ajax({
//		type:'post',
//		url:URLs,
//		success: function(resp) {
//			$('#dealmoredata').html(resp);
//		}
//	});
//}
//comment_test();
$("#frmPostComment").validate({
	rules:{
		tDescription:{
			required: true
		}
	}
});
