﻿function limitTextfieldLength(field, maxlimit) {
    if (field.value.length > maxlimit) 
    {
        // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    }
}

function disableEnterKey(e) {
    var key;
    if (window.event) {
        key = window.event.keyCode; //IE
    }
    else {
        key = e.which; //firefox
    }


    return (key != 13);
}

function changeRowColor(obj) {
    var rowObject = getParentRow(obj);
    if (rowObject == null) {
        return;
    }
    
    if (obj.checked) {
        rowObject.style.backgroundColor = '#FFFCC0';
    }
    else {
        rowObject.style.backgroundColor = '';
    }
}

// This method returns the parent row of the object
function getParentRow(obj) {
    do {
        if (isFireFox()) {
            obj = obj.parentNode;
        }
        else {
            obj = obj.parentElement;
        }
    }
    while (obj.tagName != "TR" && obj.id != "row")

    return obj;
}

function isFireFox() {
    return navigator.appName == "Netscape";
}

function openCenteredWindow(url, name, width, height) {
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    var windowFeatures = 'width=' + width + ',height=' + height + ',status,scrollbars=yes,resizable=no,left=' + left + ',top=' + top + 'screenX=' + left + ',screenY=' + top;
    return window.open(url, name, windowFeatures);
}

function checkByParent(aId, aChecked) {
    var collection = document.getElementById(aId).getElementsByTagName('INPUT');
    for (var x = 0; x < collection.length; x++) {
        if (collection[x].type.toUpperCase() == 'CHECKBOX' && collection[x].id.toUpperCase().indexOf('SELECTEDCB') != -1) {
            collection[x].checked = aChecked;
        }
    }
}

function ResetScrollPosition() {
    setTimeout("window.scrollTo(0,0)", 0);
}

