﻿var PageContainerIDCollection;
var CurrentPageIndex;
var CurrentContainerIndex;
var TotalNoOfDiv;
var PageCount;
var ItemCountPerContainer;
//this function will be fired when user click on first
function GotoFirst() {
    HideContainer(CurrentContainerIndex);
    CurrentContainerIndex = 1;
    ShowContainer(CurrentContainerIndex);
}

//this function will be fired when user click on Last
function GotoLast() {
    HideContainer(CurrentContainerIndex);
    if(PageContainerIDCollection!=null)
        CurrentContainerIndex = TotalNoOfDiv;
    ShowContainer(CurrentContainerIndex);
}

//this function will be fired when user click on Next
function GotoNext() {
    HideContainer(CurrentContainerIndex);
    CurrentContainerIndex = eval(parseInt(CurrentContainerIndex) + 1);
    if (CurrentContainerIndex > TotalNoOfDiv)
        CurrentContainerIndex = TotalNoOfDiv;
    ShowContainer(CurrentContainerIndex);
}

//this function will be fired when user click on Previous
function GotoPrevious() {
    HideContainer(CurrentContainerIndex);
    CurrentContainerIndex = eval(parseInt(CurrentContainerIndex) - 1);
    if (CurrentContainerIndex < 1)
        CurrentContainerIndex = 1;
    ShowContainer(CurrentContainerIndex);
}

function ShowContainer(index) {
    if (PageContainerIDCollection != null) 
    {
        $get(PageContainerIDCollection[index]).style.display = 'block';
    }
}


function HideContainer(index) {
    if (PageContainerIDCollection != null) 
    {
        $get(PageContainerIDCollection[index]).style.display = 'none';
    }
}

function HideAllContainer() {
    if(PageContainerIDCollection!=null)
    {
        for (var i = 0; i < PageContainerIDCollection.length; i++) {
            $get(PageContainerIDCollection[i]).style.display = 'none';
        }
    }
}

//fires when user page loads
function ConfigurePaging() 
{
    var pagedatas = $get("divPageData").innerHTML;
    var dataarray = pagedatas.split(',');
    
    PageCount = parseInt(dataarray[0]);
    CurrentPageIndex = parseInt(dataarray[1]);
    ItemCountPerContainer = parseInt(dataarray[2]);
    TotalNoOfDiv = parseInt(dataarray[3]);
    
    CurrentContainerIndex = parseInt( eval(CurrentPageIndex / ItemCountPerContainer));
    
    if ((CurrentPageIndex % ItemCountPerContainer) > 0) {
        CurrentContainerIndex = CurrentContainerIndex + 1;
    }

    PageContainerIDCollection = new Array(TotalNoOfDiv);
    
    for (var i = 1; i <= TotalNoOfDiv; i++) 
    {
        PageContainerIDCollection[i] = 'divPaging' + i;
    }
}

// Notify ScriptManager that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();