﻿function inputDigitOnly(e, digiCollection) {
    var key, keychar, currentPos;
    currentPos = 0
    key = (window.event) ? window.event.keyCode : ((e) ? e.which : null);
    if (key == null) return true;

    currentCtrl = e.srcElement;

    maxInput = currentCtrl.getAttribute("maxlength");
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    digiCollection = digiCollection.toLowerCase();

    if (digiCollection.indexOf(keychar) != -1) {
        currentInputedValue = currentCtrl.value;
        ifHasDot = (currentInputedValue.indexOf('.') != -1);
        ifHasMinus = (currentInputedValue.indexOf('-') != -1);

        if (keychar == '-' && ifHasMinus)
            return false;
        if (keychar == '.' && ifHasDot)
            return false;
        else {
            currentPos = getCurrentCaretPos(currentCtrl);


            if (keychar == '-' && currentPos != 0)
                return false;


            if (keychar == '.') {
                if (currentInputedValue.length < (maxInput - 1) && currentInputedValue.length >= 0)
                    return true;
                else
                    return false;
            }
            else
                return true;
        }
    }



    if (key == null || key == 0 || key == 8 || key == 9 || key == 27 || key == 13)
        return true;


    return false;
}



//********************************************************************************************************************************************
function inputDigi() {
    return inputDigitOnly(event, '0123456789');
}
//********************************************************************************************************************************************
function inputDigiAndDotOnly() {
    return inputDigitOnly(event, '0123456789.');
}


//******************************************************************************************************************************************** 
function inputDigiAndDot() {

    return inputDigitOnly(event, '0123456789.-');
}
//********************************************************************************************************************************************
function mousehover(currow) {
    var curNode;
    for (var i = 0; i < currow.childNodes.length; i++) {
        curNode = currow.childNodes[i];
        curNode.backColor = curNode.style.backgroundColor;
        curNode.style.backgroundColor = "#fbe1e6";
    }
}
//********************************************************************************************************************************************
function mouseout(currow) {
    var curNode;
    for (var i = 0; i < currow.childNodes.length; i++) {
        curNode = currow.childNodes[i];
        curNode.style.backgroundColor = curNode.backColor;
    }
}
//********************************************************************************************************************************************
function cellMousehover(curcell) {
    var curNode;
    var tb;
    var cur_Row_Index = 0;
    var cur_Col_Index = 0;

    //  alert(0);
    tb = curcell.parentNode.parentNode.parentNode;
    // alert(cur_Row_Index);
    //alert(tb.rows.length);

    curcell.backColor = curcell.style.backgroundColor;

    for (var i = 0; i < tb.rows.length; i++) {
        for (var j = 0; j < tb.rows[i].cells.length; j++) {
            if (tb.rows[i].cells[j] == curcell) {
                cur_Row_Index = i;
                cur_Col_Index = j;
            }
        }
    }


    for (var i = 0; i < tb.rows.length; i++) {
        for (var j = 0; j < tb.rows[i].cells.length; j++) {
            if (i == cur_Row_Index || j == cur_Col_Index) {
                curNode = tb.rows[i].cells[j];
                curNode.backColor = curNode.style.backgroundColor;
                curNode.style.backgroundColor = "#ccdbf8";
            }
        }
    }

    curcell.style.backgroundColor = "#99ccff";
}
//********************************************************************************************************************************************
function cellMouseout(curcell) {


    var curNode;
    var tb;
    var cur_Row_Index = 0;
    var cur_Col_Index = 0;

    tb = curcell.parentNode.parentNode.parentNode;


    for (var i = 0; i < tb.rows.length; i++) {
        for (var j = 0; j < tb.rows[i].cells.length; j++) {
            if (tb.rows[i].cells[j] == curcell) {
                cur_Row_Index = i;
                cur_Col_Index = j;
            }
        }
    }

    for (var i = 0; i < tb.rows.length; i++) {
        for (var j = 0; j < tb.rows[i].cells.length; j++) {
            if (i == cur_Row_Index || j == cur_Col_Index) {
                curNode = tb.rows[i].cells[j];
                curNode.style.backgroundColor = curNode.backColor;
            }
        }
    }

    curcell.style.backgroundColor = curcell.backColor;

}



//********************************************************************************************************************************************
function displayStar(ddi) {
    var x = document.getElementsByTagName('span');
    if (x.length > 0) {
        for (var i = 0; i < x.length; i++) {
            if (x[i].flg == "star") {
                if (ddi)
                    x[i].style.display = '';
                else
                    x[i].style.display = 'none';
            }
        }
    }
}


//********************************************************************************************************************************************
function UpdateImg(ctrl, imgsrc) {
    var img = document.getElementById(ctrl);
    img.src = imgsrc;
}


function encodeString(str) {
    str = str.replace(new RegExp("<", "gm"), "&lt;");
    str = str.replace(new RegExp(">", "gm"), "&gt;");
    return str;
}

function showExpand(n) {
    document.getElementById(n + "_picon").style.display = "none";
    document.getElementById(n + "_micon").style.display = "block";
    document.getElementById(n + "_content").style.display = "block";
}
function hideExpand(n) {
    document.getElementById(n + "_picon").style.display = "block";
    document.getElementById(n + "_micon").style.display = "none";
    document.getElementById(n + "_content").style.display = "none";
}

function txtCriteria_OnFocus(source, value) {
    source.value = value;

}
function txtCriteria_OnBlur(source, value) {
    if (source.value == "") {
        source.value = value;
    } else {
        location.href = "search.aspx?id=" + source.value;
    }
}
function txtCriteria_OnFocus1(source, value) {
    source.value = value;

}
function txtCriteria_OnBlur1(source, value) {
    if (source.value == "") {
        source.value = value;
    }
    //else{
    //location.href= "search.aspx?id="+source.value;
    //}
}
 
 
