function trim(str) {
    var s = new String(str);

    //trailing spaces
    while (s.length > 0 && isSpaceCharacter("" + s.charAt(s.length - 1))) {
        s = s.substring(0, s.length - 1);
    }

    //leading spaces
    while (s.length > 0 && isSpaceCharacter("" + s.charAt(0))) {
        s = s.substring(1);
    }

    return s;
}

var spaces = " \t\r\n" + String.fromCharCode(160);

function isSpaceCharacter(ch) {
    return spaces.indexOf(ch) > -1;
}

function isEmpty(elem) {
    return trim(elem.value).length == 0;
}

function isEmptyText(text) {
    return trim(text).length == 0;
}
