//This file contains the following functions:
//
// ltrim	- Remove all spaces to the left of a string
// rtrim	- Remove all spaces to the right of a string
// trim		- Remove all spaces to the left and right of a string

//Remove all spaces to the left of a string
//-------------------------------------------
function ltrim(sValue) {
    var iLength=0;
    var i;

    iLength=sValue.length;

    //Empty String
    if (iLength ==0)
        return sValue;

    //No spaces found
    if (sValue.indexOf(' ') == -1)
        return sValue;

    //Find the first character on the left that isn't a space
    for (i=0; i < iLength; i++) {
        if (sValue.charAt(i) != ' ')
            break;
    }
    return sValue.substring(i, iLength);
}

//Remove all spaces to the right of a string
//-------------------------------------------
function rtrim(sValue) {
    var iLength=0;
    var i;

    iLength=sValue.length;

    //Empty String
    if (iLength ==0)
        return sValue;

    //No spaces found
    if (sValue.indexOf(' ') == -1)
        return sValue;

    for (i=iLength-1; i >= 0; i--) {
        if (sValue.charAt(i) != ' ')
            break;
    }

    return sValue.substring(0, i+1)
}

//Remove all spaces to the left and right of a string
//----------------------------------------------------
function trim(sValue) {
    var sNewValue='';

    iLength=sValue.length;

    //Empty String
    if (iLength ==0)
        return sValue;

    //No spaces found
    if (sValue.indexOf(' ') == -1)
        return sValue;

    //First left trim it
    sNewValue = ltrim(sValue);
    sValue = sNewValue;

    //Now Right trim it
    sNewValue = rtrim(sValue);

    return sNewValue;
}

