var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;

function switchDiv(strDivName,bolVisible){
    //identify the element based on browser type
    if (isNS4) {
        objElement = document.layers[strDivName];
    } else if (isIE4) {
        objElement = document.all[strDivName];
    } else if (isIE5 || isNS6) {
        objElement = document.getElementById(strDivName);
    }

    if (isNS4) {
        if(bolVisible) {
            objElement.visibility ="visible"
        } else {
            objElement.visibility ="hidden"
        }     
    } else {
        if(bolVisible) {
            objElement.style.visibility = "visible";
        } else {
            objElement.style.visibility = "hidden";
        }
    }
}

function popup(url, width, height) {
    var win = window.open(url, 'win', 'toolbar=0,scrollbars=1,status=0,resizable=1,width='+width+',height='+height);
    win.focus();
    return win;
}

function changeLoc(select) {
    var href = select.options[select.selectedIndex].value;
    if (href != " ") {
        document.location = href;
    }
}

function isWhitespace(ch) {
    if(ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t') {
        return true;
    }
    return false;
}

function ltrim(val) {
    if(val == null) return null;
    var start = -1;
    for(var i=0; i<val.length; i++) {
        if(! isWhitespace(val.charAt(i))) {
            start = i;
            break;
        }
    }
    if(start == -1) {
        return "";
    }
    return val.substring(start, val.length);
}

function rtrim(val) {
    if(val == null) return null;
    var end = -1;
    for(var i=val.length-1; i>-1; i--) {
        if(! isWhitespace(val.charAt(i))) {
            end = i;
            break;
        }
    }
    if(end == -1) {
        return "";
    }
    return val.substring(0, end+1);
}

function trim(val) {
    if(val == null) return null;
    return rtrim(ltrim(val));
}

function ntrim(val) {
    var tmp = trim(val);
    if(tmp == "") return null;
    return tmp;
}


function capitalizeValue(element) {
    var tmp = element.value;
    if(tmp) {
        element.value = tmp.toUpperCase();
    }
}
