var comment = {
	Type : 'videos',
	TypeId : 0,
	TypeTitle : '',
	maxItem : 5,
	showComments : 0
};

function displayComments() {
	var ctnState = comment.showComments;
	if (ctnState == 0) {
	   $('#commentCtn').slideDown('fast');
		comment.showComments = 1;
		$('#commentAction').html('Hide');
        
	} else {
        $('#commentCtn').slideUp('fast');
		comment.showComments = 0;
		$('#commentAction').html('View');
	}
}

function commentPagination(sp) {
	var pars = 'type='+ comment.Type +'&typeId='+ comment.TypeId + '&sp='+ sp +'&maxItem='+ comment.maxItem;
	var url = '/ajax/refreshComments.html';
    $.ajax( url, { dataType: 'json', type : 'POST', data: pars, success: function(json) {
                    $('#commentFormContainer').html(html);
                      
        			$('#commentContainer').html(json.comments);
        			$('.commentContainer .pagination').html(json.pagination_links);
        			$('#commentCount').html(json.total_comments);    
                }    
            });
     
}


function insertComment(submitFrm) {
	var url = '/ajax/insertComment.html';
	var pars = 'fullname='+ escape(submitFrm.fullname.value) + '&email='+ escape(submitFrm.email.value) + '&comment_body='+ escape(submitFrm.comment_body.value) + '&security='+ escape(submitFrm.security.value);
	pars += '&type='+ comment.Type +'&typeId='+ comment.TypeId +'&typeTitle='+ comment.TypeTitle;

    $.ajax( url, { dataType: 'json', type : 'POST', data: pars, success: function(json) {
                $('#commentFormContainer').html(json.html);
                if (json.success == false) {
		      		alert(json.msg);
    			} else {
    
    				$('comment_body').value = '';
    				$('fullname').value = '';
    				$('email').value = '';
    				$('security').value = '';	
    				commentPagination(0);
    			}
                      
            }    
        });
  

}

function displayCommentForm() {
	if (comment.allow == 1) { 
		var pars = 'type='+ comment.Type +'&typeId='+ comment.TypeId ;
		var url = '/ajax/displayCommentForm.html';       
        $.ajax( url, { dataType: 'html', type : 'POST', data: pars, success: function(html) {
                    $('#commentFormContainer').html(html);
                          
                }    
            });
            
	}
	
}


