function checkitem(checkBox, textBox1) {
    var e = document.getElementById(textBox1.id);
    var f = document.getElementById(checkBox.id);
    if (f.checked == true) {
        e.disabled = true;
    }
    else {
        e.disabled = false;
    }
}
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
function validateCode(obj) {
    var duplicate = false;
    var duplicatecode = '';
    var i = 0, j = 0;
    $('#ctl00_CP_AssignBooksToClassGridView').find('tr').each(function () {
        if ($(this).find('.testvalidatecode').attr('id') != $(obj).attr('id') && $(this).find('.testvalidatecode').attr('id') != undefined) {
            var enteredcode = $(obj).val();
            var code = $(this).find('.testvalidatecode').val();
            if (enteredcode.indexOf(',') != -1 && code.indexOf(',') != -1) {
                enteredcode = enteredcode.split(',');
                code = code.split(',');
                for (j = 0; j < enteredcode.length; j++) {
                    for (i = 0; i < code.length; i++) {
                        if (enteredcode[j] == code[i]) {
                            duplicate = true;
                            duplicatecode = enteredcode[j];
                        }
                    }
                }
            }
            else if (enteredcode.indexOf('.') != -1 && code.indexOf('.') != -1) {
                enteredcode = enteredcode.split('.');
                code = code.split('.');
                for (j = 0; j < enteredcode.length; j++) {
                    for (i = 0; i < code.length; i++) {
                        if (enteredcode[j] == code[i]) {
                            duplicate = true;
                            duplicatecode = enteredcode[j];
                        }
                    }
                }
            }
            else if (enteredcode.indexOf(',') != -1 && code.indexOf(',') == -1) {
                enteredcode = enteredcode.split(',');
                for (j = 0; j < enteredcode.length; j++) {
                    if (enteredcode[j] == $(obj).val()) {
                        duplicate = true;
                        duplicatecode = enteredcode[j];
                    }
                }
            }
            else if (enteredcode.indexOf('.') != -1 && code.indexOf('.') == -1) {
                enteredcode = enteredcode.split('.');
                for (j = 0; j < enteredcode.length; j++) {
                    if (enteredcode[j] == $(obj).val()) {
                        duplicate = true;
                        duplicatecode = enteredcode[j];
                    }
                }
            }
            else if (code.indexOf(',') != -1 && enteredcode.indexOf(',') == -1) {
                code = code.split(',');
                for (j = 0; j < code.length; j++) {
                    if (code[j] == $(obj).val()) {
                        duplicate = true;
                        duplicatecode = code[j];
                    }
                }
            }
            else if (code.indexOf('.') != -1 && enteredcode.indexOf('.') == -1) {
                code = code.split('.');
                for (j = 0; j < code.length; j++) {
                    if (code[j] == $(obj).val()) {
                        duplicate = true;
                        duplicatecode = code[j];
                    }
                }
            }
            else {
                if ($(this).find('.validatecode').val() == $(obj).val()) {
                    duplicate = true;
                    duplicatecode = $(obj).val();
                }
            }
        }
        else if ($(this).find('.testvalidatecode').attr('id') == $(obj).attr('id')) {
            var newcode = $(obj).val();
            if (newcode.indexOf(',') != -1) {
                newcode = newcode.split(',');
                for (j = 0; j < newcode.length - 2; j++) {
                    for (i = 0; i < newcode.length - 1; i++) {
                        if (newcode[j] == newcode[i + 1]) {
                            duplicate = true;
                        }
                        if (duplicate == true) {
                            duplicatecode = newcode[i + 1];
                        }
                    }
                }
            }
            else if (newcode.indexOf('.') != -1) {
                newcode = newcode.split('.');
                for (j = 0; j < newcode.length - 2; j++) {
                    for (i = 0; i < newcode.length - 1; i++) {
                        if (newcode[j] == newcode[i + 1]) {
                            duplicate = true;
                        }
                        if (duplicate == true) {
                            duplicatecode = newcode[i + 1];
                        }
                    }
                }
            }
        }
    });
    if (duplicate == true) {
        //  var str = duplicatecode + "code is duplicate";
        var t = '<div class="messageHolder"><div class="himsWireBox" style="width:100%;padding-left:1px"><div class="himsBoxHeader"><div></div></div><div class="himsBoxContent messageMessage"><div class="errorContainer"><div class="fLeft statusImage"><div style="width: 18px; height: 19px;"></div></div><div class="statusMessage fLeft"><div>';
        t += "duplicate Book code", t += '</div><div id="hideShowError"><ul>' + duplicatecode + '</ul></div></div><div align="right" class="pRight5 cursorHand" id="maxmin"><div id="hideShowImg" class="fRight"><img src="../../../images/minimize.jpg" title="Minimize" onclick="maxmin()" /></div></div><div class="cBoth"></div></div></div><div class="himsBoxFooter"><div></div></div></div></div>';
        var r = document.getElementById("MessageBoxDiv");
        r.innerHTML = t
        //alert('duplicate Book code \n' + duplicatecode);
        //$(obj).val('');
    }
    else {
        var t = '<div class="messageHolder"><div class="himsWireBox" style="width:100%;padding-left:1px"><div class="himsBoxHeader"><div></div></div><div class="himsBoxContent messageMessage"><div class="errorContainer"><div class="fLeft statusImage"><div style="width: 18px; height: 19px;"></div></div><div class="statusMessage fLeft"><div>';
        t += "duplicate Book code", t += '</div><div id="hideShowError"><ul>' + duplicatecode + '</ul></div></div><div align="right" class="pRight5 cursorHand" id="maxmin"><div id="hideShowImg" class="fRight"><img src="../../../images/minimize.jpg" title="Minimize" onclick="maxmin()" /></div></div><div class="cBoth"></div></div></div><div class="himsBoxFooter"><div></div></div></div></div>';
        var r = document.getElementById("MessageBoxDiv");
        r.innerHTML = '';
    }
}

