
  //**************************************
  //     
  // Name: Best Trim function
  // Description:Sturdy javascript trim function.
  //     A must for good form validation!
  //     Good javascript trim functions are hard 
  //     to come by.
  // By: David Knipper
  //
  // Inputs: Trim(your_value);
  //
  // Returns:String
  //
  // This code is copyrighted and has
  // limited warranties.Please see
  //     http://www.1JavaStreet.com/vb/scripts/ShowCode.asp?txtCodeId=3621&amp;lngWId=2
  //     for details.
  //**************************************
  //

  // this code has been modified for QiiWorks

  function trim(TRIM_VALUE){

    if(TRIM_VALUE.length < 1){
      return "";
    }
    TRIM_VALUE = rtrim(TRIM_VALUE);
    TRIM_VALUE = ltrim(TRIM_VALUE);

    if(TRIM_VALUE==""){
      return "";
    }

    else{
      return TRIM_VALUE;
    }

  }

  function rtrim(VALUE){

    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";

    if(v_length < 0){
      return "";
    }

    var iTemp = v_length -1;

    while(iTemp > -1){

      if(VALUE.charAt(iTemp) == w_space){}
      else{
        strTemp = VALUE.substring(0,iTemp +1);
        break;
      }
      iTemp = iTemp-1;

    }

    return strTemp;

  }

  function ltrim(VALUE){

    var w_space = String.fromCharCode(32);

    if(v_length < 1){
      return"";
    }

    var v_length = VALUE.length;
    var strTemp = "";
    var iTemp = 0;

    while(iTemp < v_length){

      if(VALUE.charAt(iTemp) == w_space){}
      else{
        strTemp = VALUE.substring(iTemp,v_length);
        break;
      }
      iTemp = iTemp + 1;

    }

    return strTemp;

  }
