﻿// JScript File

var TotalPage=0;
var TotalRecordPerPage=7;
var HtmlCode='';
var StartingPoint=0;

function GeneratePaggingSourceSite()
{   

     TotalPage = parseInt(eval(document.getElementById('hdnSourceSiteTotalRecord').value) / TotalRecordPerPage);
     if ((eval(document.getElementById('hdnSourceSiteTotalRecord').value) / TotalRecordPerPage)>TotalPage)
     {
        TotalPage++;
     }          
     HtmlCode = '<table width=100%  border=0 ><tr><td width=85% class=paggingLink> <div align=right> ';     
     
     if (document.getElementById('hdnSourceSiteCurrentPageIndex').value==0)
     {

     }
     else
     {
          HtmlCode = HtmlCode +  '&nbsp;<a href="javascript:void(0)" onclick=document.getElementById("hdnSourceSiteCurrentPageIndex").value=0;FillSourceSites();>First</a>&nbsp;';
          HtmlCode = HtmlCode +  '<a href="javascript:void(0)"  onclick=SubstractPage("hdnSourceSiteCurrentPageIndex");FillSourceSites();>Previous</a>';        
     }
     var PageIndex=0;
     if ((document.getElementById('hdnSourceSiteCurrentPageIndex').value==0) && (TotalPage>5))
     {
        
        StartingPoint=5;
        PageIndex=1;
     }
     else if ((document.getElementById('hdnSourceSiteCurrentPageIndex').value==0) && (TotalPage<5))
     {
        StartingPoint=TotalPage;
        PageIndex=1;
      
     }
     else if ((eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)+2)<TotalPage)
     {
        
        StartingPoint=eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)+2;
        PageIndex=eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)-2;
        if (PageIndex<1)
        {   
            StartingPoint= eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)+2;   
            PageIndex=StartingPoint-2;
            if (PageIndex<1)
            {
                PageIndex=1;
            }
            if ((StartingPoint+2)>TotalPage)
            {
                StartingPoint=TotalPage;
            }
            else
            {
                StartingPoint=StartingPoint+2 ;
            }            
         }        
     }
     else
     {
        StartingPoint=eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)+2;
        PageIndex=eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)-2;
        
            if (PageIndex<1)
            {
                PageIndex=1;
            }
            if ((StartingPoint+2)>TotalPage)
            {
                StartingPoint=TotalPage;
            }
            else
            {
                StartingPoint=StartingPoint+2 ;
            }                       
     }    
     for(PageIndex;PageIndex<=StartingPoint;PageIndex++)
     {
        
        if ((eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)+1)==PageIndex)
        {
            HtmlCode  = HtmlCode +  '<a class=selectedLnk href=javascript:void(0);>' + (PageIndex ) + '</a>';
        }
        else
        {
            HtmlCode = HtmlCode +  '<a href="javascript:void(0);" onclick=document.getElementById("hdnSourceSiteCurrentPageIndex").value=' +(PageIndex -1) + ';FillSourceSites();>' + (PageIndex ) + '</a>';
        }
     }
     
     
  if (eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)==(eval(TotalPage.toFixed(0))-1))
     {
     }
    else if (eval(document.getElementById('hdnSourceSiteCurrentPageIndex').value)==(eval(TotalPage.toFixed(0))))
     {
          HtmlCode = HtmlCode +  '&nbsp;<a disabled=true href="javascript:void(0)" >&gt;</a>';
          HtmlCode = HtmlCode + '<a disabled=true  href="javascript:void(0);">&gt;&gt;</a>';
     }
     else
     {
          var LastPageIndex=0;
          LastPageIndex =(eval(TotalPage.toFixed(0))-1)
          HtmlCode = HtmlCode +  '&nbsp;<a  href="javascript:void(0)"  onclick=AddPage("hdnSourceSiteCurrentPageIndex");FillSourceSites();>Next</a>';        
          HtmlCode = HtmlCode + '<a href="javascript:void(0);"  onclick=document.getElementById("hdnSourceSiteCurrentPageIndex").value=' + LastPageIndex +';FillSourceSites();>Last</a>';
     }
     HtmlCode = HtmlCode + '</div></td><td style="padding-right: 10px" width=15% align=right></td>'; 
     HtmlCode = HtmlCode + '</tr></table>';     
     document.getElementById('spnPaggingSourceSite').innerHTML=HtmlCode;    
     //document.getElementById('Spnpagingtop').innerHTML= HtmlCode;    
                              
}
function SubstractPage(ctrl)
{
    document.getElementById(ctrl).value=eval(document.getElementById(ctrl).value)-1;
}
function AddPage(ctrl)
{
    document.getElementById(ctrl).value=eval(document.getElementById(ctrl).value)+1;
}

