function trim(strText) {
        // this will get rid of leading spaces
        while (strText.substring(0,1) == ' ')
            strText = strText.substring(1, strText.length);

        // this will get rid of trailing spaces
        while (strText.substring(strText.length-1,strText.length) == ' ')
            strText = strText.substring(0, strText.length-1);

       return strText;
    }

function checkIfValid(qn)
{
   qn.value = trim(qn.value);
   var queryValue = qn.value;
   for (var i = 0; i < queryValue.length; i++)
   {
      var oneChar = queryValue.charAt(i);
      if(oneChar == ' ')
      {
         continue;
      }
      if (isLetter(oneChar) == false && isDigit(oneChar) == false )
      {
         return false;
      }
   }
   return true;
}

function isLetter (c)
{
   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

function isDigit (c)
{
   return ((c >= "0") && (c <= "9"));
}

function validateField(field,name)
{
   var val = field.value;
   for (var i = 0; i < val.length; i++)
      {
         var oneChar = val.charAt(i);
         if (isDigit(oneChar) == false &&  oneChar.charCodeAt(0)!= 44)
         {
         
        alert("Only numbers and commas are accepeted in this field.\n\nFor example: 1,000,000 or 1000000");
        break;
         }
      }
}
function checkSpaceSize(txtObj) // a space cannot be > 1 or the SQL will bomb
{
   var val = txtObj.value;
   var len = val.length;
   var spaceFound = 0;
   var output = "";

   for(var i = 0; i < len; i++)
   {
      var oneChar = val.charAt(i);
      if(oneChar== ' ')
      {
         spaceFound = spaceFound+1 ;
         if( spaceFound > 1 )
         {
            // keep going
         }
         else
         {
            output = output + oneChar;
         }
      }
      else
      {
         output = output + oneChar;
         spaceFound = 0;
      }
   }

   txtObj.value = output;
}


