/// <reference path="/js/jquery-1.3.2.min.js" />
var nindx = 2;
var ncunt = 0;
$(document).ready(function() {
    initRprtWndw();

    setInterval("updtRprtWndw()",8000);

    $('div.inxarprtshrt').click(function() {
        $('div.inxarprtshrtslct').attr('class', 'inxarprtshrt');
        $('div#indxshowrprt').html($("div#" + $(this).attr('id').toString() + "lg").html());
        $(this).attr('class', 'inxarprtshrt inxarprtshrtslct');
        nindx = parseInt($(this).attr('id').toString().replace('rep', '').replace('sh', ''));
    });

    $('img#imgInxleftarw').click(function(event) {
        event.preventDefault();
        olderPost();
        initReportsShow();
    });

    $('img#imgInxrightarw').click(function(event) {
        event.preventDefault();
        newerPost();
        initReportsShow();
    });
});

function olderPost() {
    var page = $('#hdnreppg').val();
    var pageNumber = parseInt(page);

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/WebService.asmx/BuildHomeReports",
        data: "{'strPage':'" + (pageNumber + 1).toString() + "'}",
        dataType: "json",
        success: function(msg) {
            if (msg.d != "0") {
                $('div#inxarprtmn').html(msg.d);
                $('#hdnreppg').attr('value', (pageNumber + 1).toString());
                if (pageNumber == 0) {
                    $('img#imgInxrightarw').removeAttr('style');
                }

                initRprtWndw();
            }
        }
    });
}

function newerPost() {
    var page = $('#hdnreppg').val();
    var pageNumber = parseInt(page);

    if (pageNumber > 0) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/WebService.asmx/BuildHomeReports",
            data: "{'strPage':'" + (pageNumber - 1).toString() + "'}",
            dataType: "json",
            success: function(msg) {
                if (msg.d != "0") {
                    $('div#inxarprtmn').html(msg.d);
                    $('#hdnreppg').attr('value', (pageNumber - 1).toString());
                    if (pageNumber == 1) {
                        $('img#imgInxrightarw').attr('style', 'opacity: 0.4; filter: alpha(opacity=40)');
                    }

                    initRprtWndw();
                }
            }
        });
    }
}

function initRprtWndw() {
    $('div#indxshowrprt').html($('div#rep1shlg').html());
    nindx = 2;
    ncunt = 0;
    $('div.inxarprt').each(function() { ncunt = ncunt + 1 });

    $('div.inxarprtlng').hide();
}

function updtRprtWndw() {
    $('div.inxarprtshrtslct').attr('class', 'inxarprtshrt');
    $('div#indxshowrprt').html($('div#rep' + nindx.toString() + 'shlg').html());
    $('div#rep' + nindx.toString() + 'sh').attr('class', 'inxarprtshrt inxarprtshrtslct');
    nindx = nindx + 1;
    if (nindx > ncunt) {
        nindx = 1;
    }
}
