/**
 * History framework for managing
 *
 * @author Veeresh D.
 * @date September 2008
 */
var historyObject = new Array();
var historyCurrentIndex = 0;
var historyIsItResultDetails = 0;

var parityHistory =
{
    /**
    Set the page in history
    */
    setInHistory: function()
    {
        ++historyCurrentIndex;
        historyObject.length = historyCurrentIndex;
        historyObject[historyCurrentIndex] = document.getElementById("queryResultsDivId").innerHTML;        
        
        document.getElementById("historyPagesInfo").innerHTML = "(Page " + historyCurrentIndex + " of " + (historyObject.length - 1) + ")";
        
        if ( historyIsItResultDetails == 1 )
        {
            historySearchDetails.setItem(historyCurrentIndex, document.getElementById("queryResultDetailsDivId").innerHTML);
            historySearchPages.setItem(historyCurrentIndex, document.getElementById("paginationDivComponent").innerHTML);            
        }
        else
        {
            historySearchDetails.removeItem(historyCurrentIndex);
            historySearchPages.removeItem(historyCurrentIndex);            
        }        
    },
    
    /**
    Get the specified page from history
    */
    getFromHistory: function(i)
    {   
        document.getElementById("historyPagesInfo").innerHTML = "(Page " + i + " of " + (historyObject.length - 1) + ")";
        document.getElementById("queryResultsDivId").innerHTML = historyObject[i];
        document.getElementById("queryResultDetailsDivId").innerHTML = "";
        if ( historySearchDetails.hasItem(i) == true )
        {
            document.getElementById("queryResultDetailsDivId").innerHTML = historySearchDetails.getItem(i); 
            searchResults.showSearchResultsDetailsBorder();
            document.getElementById("paginationDivComponent").innerHTML = historySearchPages.getItem(i); 
            
            searchResults.showSearchResultsBorder();
	        searchResults.showSearchResultsDetailsBorder();
        	showPagination();
        	components.penel.hideMonthIssues();  /* Close notification/dialog content after getting the serach results */
	        components.penel.hideCurrentIssues();
	        components.penel.hideTopArticle();
        	components.penel.hideAds();
	        printer.printerPageType = 0;
	        printer.showPrinterPageLink();
        }
        else
        {
             hidePagination();
             searchResults.hideAllPanels();
             searchResults.emptySearchResultsDetails();
        }
    },
    
    /**
    Get the Next page from history
    */
    nextHistoryPage: function() 
    {
        if ( historyCurrentIndex == historyObject.length - 1 || historyObject.length == 0 )
        {
            alert("No more next pages");
            return;            
        }
        else        
            parityHistory.getFromHistory(++historyCurrentIndex);
    },
    
    /**
    Get the Previous page from history
    */
    previousHistoryPage: function()
    {
        if ( historyCurrentIndex == 1 || historyObject.length == 0 )
        {
            alert("No more previous pages");
            return;            
        }
        else        
            parityHistory.getFromHistory(--historyCurrentIndex);
    },
    
    /**
    Clear the history pages
    */
    clearHistoryPage: function()
    {
        historyObject.length = 0;
        historyCurrentIndex = 0;
        historyIsItResultDetails = 0;
        document.getElementById("historyPagesInfo").innerHTML = "";
    },
    
    /**
    Shows the history links
    */
    showHistoryLinks: function()
    {
        document.getElementById("queryTopAlerts").style.display = '';
        document.getElementById("historyData").style.display = '';
    },
    
    /**
    Hides the history links
    */
    hideHistoryLinks: function()
    {        
        document.getElementById("historyData").style.display = "none";
        document.getElementById("queryTopAlerts").style.display = "none";
    }        
}
