﻿var tempValue;
function SetTempValue(hole)
{
    tempValue=parseInt(hole.value);
    hole.focus();
    return false;
}
function SetTotalValue(hole, hfClientId)
{
    var total=document.getElementById(document.getElementById(hfClientId).value);
    if (parseInt(hole.value) != parseInt(tempValue))
    {
        var diverence=parseInt(hole.value)-parseInt(tempValue);
        total.innerHTML=parseInt(total.innerHTML)+diverence;
    }
    return false;
}

var gvToImportCID="<%= gvToImport.ClientID %>";
function checkAll(cbxchecked) 
{
    var grid = document.getElementById(gvToImportCID);
    if (grid == null)
        return;
    var gridTrs = grid.getElementsByTagName("tr");
    for (var i = 1; i < gridTrs.length; i++) {
        controlsCollection = gridTrs[i].getElementsByTagName("input");
        var cbx = getControl(controlsCollection, "cbxSelect");
        cbx.checked = cbxchecked;
        selectRow(cbx);
    }
    return false;
}
        
function getControl(controlsCollection, name)
{
    for (var i = 0; i < controlsCollection.length; i++) 
    {
        var id = controlsCollection[i].getAttribute("id");
        if (id.indexOf(name) != -1)
        {
            return controlsCollection[i];
        }
    }
    return null;
}

function selectRow(cbx) 
{
    var tr = cbx.parentNode.parentNode;
    if (cbx.checked)
    {
        tr.style.backgroundColor = "Silver";
    }
    else
    {
        tr.style.backgroundColor = "White";
    }
}

function IrOnKeyDown(evt)
{
    var e = evt ? evt : window.event;
    if (e.keyCode == 13)
    {
        var myind = e.srcElement.tabIndex;
        var ctrl = getControlByTabIndex( e.srcElement.form, myind+1 )
        if (ctrl)
        {
            if (ctrl.type == "text")
                ctrl.select();
            else
                ctrl.focus();
        }
        return false;
    }
    return true;
}

function getControlByTabIndex( form, index )
{
    try
    {
        var i = form.length-1;
        for ( a=0; a<i; a++)
        {
            var d = form.elements[a].tabIndex;
            if (d == parseInt(index))
                return form.elements[a];
        }
        return null;
    }
    catch(err)
    {}
    return null;
}
