﻿var userCommentsManager =
    {                           
         commentsResultDiv : '', //the div where the user comments list should be displayed
         commentsCurrentPage: 1,
         commentsSort: 'Date',
         commentsSortDirection: 'desc',
         commentsPageSize: 15,
         searchTypeHidden: Object,                         

         //sets the result divs
         Init: function(commentsDiv)
         {            
            userCommentsManager.commentsResultDiv = commentsDiv;
         },
                  
        //calls the webservice to get the comments list into the comments results div
        GetComments: function()
        {
              SearchEngineService.GetComments( 
                    userCommentsManager.commentsResultDiv,                     
                    userCommentsManager.commentsPageSize,
                    userCommentsManager.commentsCurrentPage,
                    userCommentsManager.commentsSort,
                    userCommentsManager.commentsSortDirection,
                    userCommentsManager.GetComments_Complete
                    );
        },
        
        //the "complete" event handler for the webmethod called in GetComments 
        //(appends the returned html to the comments result div
         GetComments_Complete : function(args)
        {
            userCommentsManager.AppendResult(document.getElementById(args.Target), args.Result, args.Info);
        },
        
        DeleteCommentsDocument: function(documnetId)
        {
            SearchEngineService.DeleteComment(documnetId,userCommentsManager.DeleteCommentsDocumentComplete); 
        },
    
        DeleteCommentsDocumentComplete: function(args)
        {
             userCommentsManager.GetComments();
        },
        
        //checks that data has been returned (result== true)
        //if it had been returned, puts the returned html (info) into the target's innerHtml
        //otherwise, puts a message  the target's innerHtml
        AppendResult: function(target, result, info)
        {
            if(result != null && result== true)
                target.innerHTML = info;
            else    
                target.innerHTML = '<div style="height: 150px">לא נמצאו מסמכים מתאימים</div>';
        }//,
                 
//        ToggleCommentsSortDirection: function()
//        {
//            userCommentsManager.commentsSortDirection = userCommentsManager.commentsSortDirection == 'desc' ? 'asc' : 'desc';
//        },

//        GoToPage: function(page)
//        {                            
//            userCommentsManager.commentsCurrentPage = page;
//            userCommentsManager.GetComments();
//                                       
//        },

//        GoToPageSizeSelect: function(select)
//        {                                                    
//            userCommentsManager.commentsPageSize = select.options[select.selectedIndex].value;                
//            userCommentsManager.GetComments();
//        },

//        GoToSort: function(SortExpresion)
//        {                             
//            userCommentsManager.commentsSort = SortExpresion;
//            userCommentsManager.ToggleCommentsSortDirection();
//            userCommentsManager.GetComments();                
//        }        
}

function ToggleCommentsSortDirection()
{   
    userCommentsManager.commentsSortDirection =  userCommentsManager.commentsSortDirection== 'desc' ? 'asc' : 'desc';
}        

function GoToPage(page)
{            
    userCommentsManager.commentsCurrentPage = page;
    userCommentsManager.GetComments();                                           
}

function GoToPageSizeSelect(select)
{                                                    
    userCommentsManager.commentsPageSize = select.options[select.selectedIndex].value;               
    userCommentsManager.GetComments();
}

function GoToSort(SortExpresion)
{                     
    userCommentsManager.commentsSort = SortExpresion;
    ToggleCommentsSortDirection(); 
    userCommentsManager.GetComments();               
}

function ShowCommentRow(imgId , rowId)
{
    //if (document.getElementById(imgId).nameProp == "Plus.gif")
    if (document.getElementById(rowId).className == "HideHomePageDiv")
    {
        document.getElementById(rowId).className = "ShowHomePageDiv";
        document.getElementById(imgId).src = "Images/Minus.gif";
    }
    else
    {
        document.getElementById(rowId).className = "HideHomePageDiv";
        document.getElementById(imgId).src = "Images/Plus.gif";
    }
    
}

function ShowComment(obj, id)
{
	//debugger;
	if (!obj) return;
	
	if (obj.src.indexOf(imgPlus.src) != -1)
	{
		obj.src = imgMinus.src;
		ShowCommentText(id, true);
	}
	else
	{
		obj.src = imgPlus.src;
		ShowCommentText(id, false);
	}
}

function ShowCommentText(id, flag)
{
	//debugger;
	var obj = document.getElementById("comment" + id);
	if (obj) obj.style.display = (flag ? "" : "none");
}    