﻿function XGridView_MovePager(parentPanelID, scrollPanelID, gridID)
{
    var parentPanel = document.getElementById(parentPanelID);
    var scrollPanel = document.getElementById(scrollPanelID);
    var t = document.getElementById(gridID);
    var t2 = t.cloneNode(true);
    var t3 = t.cloneNode(true);
    for(i = t2.rows.length - 1;i > 0;i--)
        t2.deleteRow(i);
    for(i = t3.rows.length - 2;i >= 0;i--)
        t3.deleteRow(i);
    t.deleteRow(0);
    t.deleteRow(t.rows.length - 1);
    
    scrollPanel.appendChild(t);
    parentPanel.appendChild(t2);
    parentPanel.appendChild(scrollPanel);
    parentPanel.appendChild(t3);
}

function XGridView_SelectAllSelectionBoxes(sender, gridClientID)
{
    var prefix = gridClientID;
    var grid = document.getElementById(prefix);
    var max = grid.attributes['NumOfChildControls'].value;
    var box1 = null;
    var box2 = null;
    for(var i=0; i<=100; i++)
    {
        var tmp = document.getElementById(prefix + "_ctl" + ((i<10)?"0" + i:i) + "_chkItemselectCount");
        if(tmp != null && box1 != null && box2 == null) box2 = tmp;
        if(tmp != null && box1 == null) box1 = tmp;
        if(box1 != null && box2 != null) break;
    }
    if(sender.checked && box1 != null) box1.value = 0;
    if(sender.checked && box2 != null) box2.value = 0;
    var cbId;
    for(var i=0; i<=max; i++)
    {
        cbId = prefix + "_ctl" + ((i<10)?"0" + i:i) + "_chkItem";
        var cb = document.getElementById(cbId);
        if(cb != null)
        {
            cb.checked = sender.checked;
            if(box1 != null) box1.value = (sender.checked)?parseInt(box1.value) + 1:parseInt(box1.value) - 1;
            if(box2 != null) box2.value = (sender.checked)?parseInt(box2.value) + 1:parseInt(box2.value) - 1;
        }
        if(!sender.checked && box1 != null) box1.value = 0;
        if(!sender.checked && box2 != null) box2.value = 0;
    }
}

function XGridView_SelectIndividualSelectionBox(sender, gridClientID)
{
    var prefix = gridClientID;
    var grid = document.getElementById(prefix);
    var max = grid.NumOfChildControls;
    var box1 = null;
    var box2 = null;
    for(var i=0; i<=100; i++)
    {
        var tmp = document.getElementById(prefix + "_ctl" + ((i<10)?"0" + i:i) + "_chkItemselectCount");
        if(tmp != null && box1 != null && box2 == null) box2 = tmp;
        if(tmp != null && box1 == null) box1 = tmp;
        if(box1 != null && box2 != null) break;
    }
    if(box1 != null) box1.value = (sender.checked)?parseInt(box1.value) + 1:parseInt(box1.value) - 1;
    if(box2 != null) box2.value = (sender.checked)?parseInt(box2.value) + 1:parseInt(box2.value) - 1;
}

/*
function XGridView_validGridExport(gridClientID, exportingSelectionQuestion, exportingPageQuestion, exportingAllQuestion, exportingSelectionAlert, exportingErrorAlert)
{
    var actionArray = new Array('Selected', 'Page', 'All');
    var confirmArray = new Array(exportingSelectionQuestion, exportingPageQuestion, exportingAllQuestion);
    if (action_name == actionArray[0]) 
    {
        try {
            elm=document.forms[0].elements;
            for (i=0; i<elm.length;i++)
            {
                if(elm[i].type=="checkbox" && elm[i].id.indexOf('chkItem') !=-1 && elm[i].checked == true)
                {
                    for (var i =0; i< actionArray.length; i++)
                    {
                        if (action_name == actionArray[i])
                        {
                            return(confirm(confirmArray[i]));
                        }
                    }
                }
            }
            alert(exportingSelectionAlert);
            return(false);
        }
        catch (e)
        {
            alert(exportingErrorAlert + e.description);
            return(false);
        }
    }
    else
    {
        for (var i =0; i< actionArray.length; i++)
        {
            if (action_name == actionArray[i])
            {
                return(confirm(confirmArray[i]));
            }
        }
    }
}
 */
 
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function XGridView_setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) {
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
   	var currentColor = null;    
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == null || currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function