//-----------------------------------------------------------------------------
// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
//-----------------------------------------------------------------------------
function trim(input_string) {
    if (typeof input_string != 'string') { 
        return input_string; 
    }
    var retValue = input_string;
    var ch = retValue.substring(0, 1);

    // Check for spaces at the beginning of the string
    while (ch == ' ') { 
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length-1, retValue.length);

    // Check for spaces at the end of the string
    while (ch == ' ') { 
        retValue = retValue.substring(0, retValue.length-1);
        ch = retValue.substring(retValue.length-1, retValue.length);
    }

    // Look for multiple spaces within the string
    while (retValue.indexOf('  ') != -1) { 
        retValue = retValue.substring(0, retValue.indexOf('  ')) + retValue.substring(retValue.indexOf('  ') + 1, retValue.length);
    }

    return retValue;
} // trim()

//-----------------------------------------------------------------------------
// "trim" a field and make sure a field is not empty
//-----------------------------------------------------------------------------
function isEmpty(field, empty_message) {
    field.value = trim(field.value);
    if (field.value == '') {
        if (empty_message != '') {
            alert(empty_message);
			field.focus();
        }
        return true;
    } else {
        return false;
    }
}
