﻿// JScript File
//var strDivOutput;

function GetXmlHttpObject(handler)
{ 
    var objXmlHttp = null;
    if (!window.XMLHttpRequest)
    {
        objXmlHttp = GetMSXmlHttp();
        if (objXmlHttp != null)
        {
            objXmlHttp.onreadystatechange = handler;
        }
    } 
    else
    {
        // Mozilla | Netscape | Safari
         objXmlHttp = new XMLHttpRequest();
        if (objXmlHttp != null)
        {
            if(document.all)
            {
                objXmlHttp.onreadystatechange = handler;
            }
            else
            {
                objXmlHttp.onload = handler;
                objXmlHttp.onerror = handler;
            }
        }
    } 
    return objXmlHttp; 
} 

function GetMSXmlHttp() 
{
    var xmlHttp = null;
    var clsids = ["Msxml2.XMLHTTP.6.0",
                  "Msxml2.XMLHTTP.4.0",
                  "Msxml2.XMLHTTP.3.0",
                  "Msxml2.XMLHTTP",
                  "Microsoft.XMLHTTP"];
    for(var i=0; i<clsids.length && xmlHttp == null; i++) 
    {
        xmlHttp = CreateXmlHttp(clsids[i]);
    }
    return xmlHttp;
}

function CreateXmlHttp(clsid) 
{
    var xmlHttp = null;
    try 
    {
        xmlHttp = new ActiveXObject(clsid);
        lastclsid = clsid;
        return xmlHttp;
    }
    catch(e) {}
}

function SendXmlHttpRequest(xmlhttp, url) 
{ 
    xmlhttp.open('GET', url, true); 
    xmlhttp.send(null); 
}

var xmlHttp; 

function ExecuteCall(url)
{ 
    try 
    { 
        xmlHttp = GetXmlHttpObject(CallbackMethod); 
        SendXmlHttpRequest(xmlHttp, url); 
    }
    catch(e)
    {
        //alert(e.toString());
    } 
} 
    
//CallbackMethod will fire when the state 
//has changed, i.e. data is received back 

function CallbackMethod() 
{
     try
    {
        //readyState of 4 or 'complete' represents 
        //that data has been returned 
        if (xmlHttp.readyState == 4 || 
            xmlHttp.readyState == 'complete')
        {
            var response = xmlHttp.responseText; 
            if (response.length > 0)
            {
                document.getElementById("tmessage").innerHTML 
                                                   = response; 
                window.setTimeout("ShowRecords(0,4)",200);   
            } 
        }
    }
    catch(e)
    {
        //alert(e.toString())
    }
}
function vote()
{
    //ExecuteCall("../Test2.aspx");
}

function ShowRecords(startIndex,recordsCount)
{
  
    var table = document.getElementById("navList");
    // The format which we are getting in the table header is "dddd, MMMM dd, yyyy" 
    // i.e: day in words, month in words date in numbers , year in numbers.
    
    if(table != null)
    {
    
        var dateLastUpdated = table.title;
        document.getElementById("navLastUpdDate").innerHTML= dateLastUpdated;
        document.getElementById("txtMore").innerHTML= "More";
        var totalRecords = table.rows.length;
        
        //Hide those rows, which are already in display
        //If we are in the first index, then we have just check whether
        //the last two records are not visible.
        if(startIndex == 0)
        {
         
            for(var i=0;i<=totalRecords;i++)
            {
                try
                {
                    table.rows[i].style.display = 'none';
                }
                catch(e){}
            }
        }
        else
        {
            //If we are not in the first index, then just hide the previous records
            //which are already visible.
            for(var i=startIndex-1;i>=(startIndex-recordsCount);i--)
            {
                try
                {
                    table.rows[i].style.display = 'none';
                }   
                catch(e){}
            }
        }
        
        //Now hiding is done.We can start displaying the records
        for(var i = startIndex;i < (startIndex+recordsCount);i++)
        {
            try
            {
                table.rows[i].style.display = '';
            }
            catch(e){}
        }

        //If we reach the last record, reset the start index
        if((startIndex+recordsCount) >= totalRecords)    
            startIndex = 0;         
        else 
        {  
            startIndex = startIndex + recordsCount;
        }
        //Recursively call this function to continue the cycle
        //window.setTimeout("ShowRecords("+startIndex+","+recordsCount+")",2000);
    }
    else
    {
        
    }
}

