// $Id: json_demo.js 4432 2006-09-14 07:45:55Z shacka $
/**
 *
 * Copyright (c) 2006 by SouthProjects
 * http://www.southprojects.com
 * Santiago, Chile,
 * Version 1.2 Dec 2006.
 * All rights reserved.
 */

/*
 * Grid object
 */
var objGrid;

/*
 * Initializes grid from external source.
 * @param strUrl - source URL
 * @param strSourceType - source type: 'json/url', 'xml/url' or 'html/url'
 * @param strTheme - theme name
 */
function loadGrid(strUrl, strSourceType, strTheme) {
  objGrid = new southprojects.Grid({

    // Use specified URL as source
    source: strUrl,
    sourceType: strSourceType,

    // Put the grid into element with id "gridContainer"
    container: 'gridContainer',

    // Use specified theme
    theme: strTheme,

    // Display filter out forms
    filterOut: [
      // Filter Date
      {
        // Use first column
        column: 0,
        // Put checkboxes into element with id "filterDate"
        container: 'filterDate'
      },
      // Filter Account
      {
        // Use second column
        column: 1,
        // Use custom function filterOutAccount to display checkboxes
        callback: filterOutAccount
      }
    ]

  });
}

/*
 * Displays checkboxes to filter out Account.
 */
function filterOutAccount(arrUniqueColumnValues) {
  var strHtml = '';
  for (var iVal = 0; iVal < arrUniqueColumnValues.length; iVal++) {
    strHtml +=
     '<div>' + arrUniqueColumnValues[iVal].value +
     ' <input type="checkbox" checked onclick="' +
     arrUniqueColumnValues[iVal].onclick + '"/></div>';
  }
  document.getElementById('filterAccount').innerHTML = strHtml;
}

/*
 * Called when "Debits" button is clicked. Limits range of Amount to positive
 * numbers.
 */
function limitRangeDebits(form) {
  if (objGrid) {
    objGrid.limitRange({
      column: 4,
      min: 0,
      max: Infinity
    });
  }
}

/*
 * Called when "Credits" button is clicked. Limits range of Amount to negative
 * numbers.
 */
function limitRangeCredits(form) {
  if (objGrid) {
    objGrid.limitRange({
      column: 4,
      min: -Infinity,
      max: 0
    });
  }
}
