﻿function CallbackAll() {
    CallbackGridList.Callback();
    CallbackCalendarLeft.Callback();
}

function CalendarLeft_select(sender, e) {
    if (TabStripOptions.GetSelectedTab().ID == 'Quick' && (!(document.getElementById('txtDebtor').value == "") || !(document.getElementById('txtCaseNum').value == ""))) {
        CallbackGrid("QuickSearch");
    }
    else {
        CallbackGrid();
    }
}

function CallbackGrid() {
    CallbackGridList.Callback();
}

var lastTime;
function CompareTime(currentTime) {
    var _out = (currentTime != lastTime);
    lastTime = currentTime;
    return _out;
}

function QuickSearch() {
    if ((document.getElementById('txtDebtor').value == "") && (document.getElementById('txtCaseNum').value == "")) {
        CallbackGrid();
        CallbackCalendarLeft.Callback();
    }
    else {
        CallbackGrid("QuickSearch");
        CallbackCalendarLeft.Callback();
    }
}

function Splitter1_load(sender, e) {
    CallbackAll();
}

function CallbackGridList_complete(sender, e) {
    AdjustGridWrapper();
}

function AdjustGridWrapper() {
    var height = (Splitter1.get_panes()[1].get_panes()[1].get_height() - 60);
    var width = Splitter1.get_panes()[1].get_panes()[1].get_width();
    if (width > 0 & height > 0 && window.Splitter1 && document.getElementById("divGridWrapper")) {
        document.getElementById("divGridWrapper").style.height = height + 'px';
        document.getElementById("divGridWrapper").style.width = width + 'px';
        var p = Math.round(height / 28);
        GridList.set_pageSize(p);
        GridList.set_pageCount(Math.ceil(GridList.get_recordCount() / p));
        GridList.render();
    }
    else {
        setTimeout("AdjustGridWrapper", 100);
    }
}

function entsub(e) {
    if (!e) var e = window.event;

    if (e.keyCode == 13) {
        QuickSearch('QuickSearch')
        return false;
    }
}

function GridList_itemExpand(sender, e) {
    if (GridList.get_table().get_groups() == null) {
        var ps = GridList.get_pageSize(); //Items per Page
        var idx = GridList.get_currentPageIndex(); //Current Page Index
        var spos = (idx * ps); //Start Position
        var rc = GridList.get_recordCount(); //Record Count
        var epos = (spos + ps) > rc ? (spos + (rc - spos)) : (spos + ps); //End Position
        var item = e.get_item();
        for (var i = spos; i < epos; i++) {
            var subItem = GridList.getItemFromPath([i]);
            if (item.get_index() != i) {
                if (subItem.get_expanded()) {
                    GridList.collapseItem(subItem);
                }
            }
        }
        GridList.select(item);
    }
}

function GridList_click(sender, e) {
    if (!e.get_item().get_expanded()) {
        GridList.expandItem(e.get_item());
    }
    else {
        GridList.collapseItem(e.get_item());
    }    
}


//Load loading Screen
function loadImages() {
    if (document.getElementById) {  // DOM3 = IE5, NS6
        document.getElementById('hidepageWrapper').style.visibility = 'hidden';
    }
    else {
        if (document.layers) {  // Netscape 4
            document.hidepageWrapper.visibility = 'hidden';
        }
        else {  // IE 4
            document.all.hidepageWrapper.style.visibility = 'hidden';
        }
    }
}

//Check for Screen Res.  PublicCalendar doesnt look very good at 800x600 :(
function screenRes() {
    if (screen.width < 801)
        alert("PublicCalendar has detected your screen resolution is lower then 1024 by 768. Please note you may have a had time using PublicCalendar until you adjust your resolution to 1024 by 768 or higher. Thank you.");
}

function ClearQuickSearch() {
    document.getElementById('txtDebtor').value = ""
    document.getElementById('txtCaseNum').value = ""
    QuickSearch();
}

function ResetFilterDefaults() {
    document.getElementById('txtDebtor').value = ""
    document.getElementById('txtCaseNum').value = ""
    CallbackSearch.Callback();
}

function CallbackError(sender,e) {
    alert("Whoops! An error has occurred.  Please delete your temporary internet files and refresh your browser.  If the problem continues please contact Luke Adams @ 850-443-0471.  I apologize for the inconvenience.");
}