function sqGridCheckbox(grid, rowIndex, colIndex, row, params) {
    var isChecked = false;

    if ("checkedWidgets" in grid.rows[rowIndex].userData && colIndex in grid.rows[rowIndex].userData.checkedWidgets && grid.rows[rowIndex].userData.checkedWidgets[colIndex] == true) {
        isChecked = true;
    }

    var isDisabled = false;
    if (row.disabled) {
        isDisabled = true;
    }
    if (grid.getCellCustomData(rowIndex, colIndex, "cellsDisabled")) {
        isDisabled = true;
    }

    IncrementalDOM.elementOpenStart('div');
    IncrementalDOM.attr("class", "grid-widget-checkbox");
    IncrementalDOM.attr("onmousedown", function (event) {
        event.stopPropagation();
        var elementCheckbox = null;
        if (event.target.tagName == "INPUT") {
            elementCheckbox = event.target;
        } else {
            elementCheckbox = event.target.children[0];
        }
        if (!("checkedWidgets" in grid.rows[rowIndex].userData)) {
            grid.rows[rowIndex].userData.checkedWidgets = {};
        }
        grid.rows[rowIndex].userData.checkedWidgets[colIndex] = !elementCheckbox.checked;

        sqGridSendEvent(event, "checkboxChecked", rowIndex, colIndex, !elementCheckbox.checked);

        grid.bodyRedraw();
    });
    IncrementalDOM.elementOpenEnd('div');

    IncrementalDOM.elementOpenStart('input');
    IncrementalDOM.attr("type", "checkbox");
    if (isDisabled) {
        IncrementalDOM.attr("disabled", "disabled");
    }
    IncrementalDOM.attr("onclick", function (event) {
        event.preventDefault();
    });
    IncrementalDOM.elementOpenEnd('input');
    var currentElement = IncrementalDOM.currentElement();
    currentElement.checked = isChecked;
    IncrementalDOM.elementClose('input');

    IncrementalDOM.elementClose('div');
}


function sqGridCheckboxGetValue(grid, rowIndex, colIndex) {
    return grid.getCellWidgetValue(rowIndex, colIndex, "checkedWidgets");
}

function sqGridCheckboxSetValue(grid, rowIndex, colIndex, checked, disableBodyRedraw) {
    grid.setCellCustomData(rowIndex, colIndex, "checkedWidgets", checked);
    if (!disableBodyRedraw) {
        grid.bodyRedraw();
    }
}
