function trim(inputString) {

   // 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.
  
   var temp;
   if (inputString == null) temp = "";
   else temp = inputString;
   
   if (typeof temp != "string") { return temp; }

   var retValue = temp;

   var ch = retValue.substring(0, 1);

   while (ch == " ") { // Check for spaces at the beginning of the string

      retValue = retValue.substring(1, retValue.length);

      ch = retValue.substring(0, 1);

   }

   ch = retValue.substring(retValue.length-1, retValue.length);

   while (ch == " ") { // Check for spaces at the end of the string

      retValue = retValue.substring(0, retValue.length-1);

      ch = retValue.substring(retValue.length-1, retValue.length);

   }

   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string

      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings

   }

   return retValue; // Return the trimmed string back to the user

} // Ends the "trim" function
function BusquedaBinA(inicio,fin,valor, A){
   var Mitad,selected,item,Busqueda,lenBusqueda,k;
  
	Mitad = parseInt((inicio + fin)/2);
  
	Busqueda = valor.toUpperCase();
    lenBusqueda = valor.length;
	  item = A[Mitad].substring(0,((lenBusqueda < A[Mitad].length)?lenBusqueda:A[Mitad].length)).toUpperCase();
    if (item == Busqueda){
          for (k = Mitad - 1;k>= inicio;k--){
             item = A[k].substring(0,((lenBusqueda <A[k].length)?lenBusqueda:A[k].length)).toUpperCase();
             if (item != Busqueda){
                return (k + 1);
                
             }
          }
          return inicio;
    }
	else{
      if (inicio >= fin){
		if (item > Busqueda)
			return (Mitad-1);
	    else
		    return Mitad;
        
 	  }
      if (item > Busqueda)
        return BusquedaBinA(inicio,Mitad-1,valor, A);
      else
        return BusquedaBinA(Mitad + 1,fin, valor, A);  
    }     
}
function BusquedaBin(inicio,fin,valor, selec){
   var Mitad,selected,item,Busqueda,lenBusqueda,k;
    Mitad = parseInt((inicio + fin)/2);
    Busqueda = valor.toUpperCase();
    lenBusqueda = valor.length;
    item = selec.options[Mitad].text.substring(0,((lenBusqueda < selec.options[Mitad].text.length)?lenBusqueda:selec.options[Mitad].text.length)).toUpperCase();
    if (item == Busqueda){
          for (k = Mitad - 1;k>= inicio;k--){
             item = selec.options[k].text.substring(0,((lenBusqueda < selec.options[k].text.length)?lenBusqueda:selec.options[k].text.length)).toUpperCase();
             if (item != Busqueda){
                selec.selectedIndex = k + 1;
                return;
             }
          }
          selec.selectedIndex = inicio;
    }
	else{
      if (inicio >= fin){
		if (item > Busqueda)
			selec.selectedIndex  = Mitad-1;
	    else
		    selec.selectedIndex  = Mitad;
        return;
 	  }
      if (item > Busqueda)
        BusquedaBin(inicio,Mitad-1,valor, selec);
      else
        BusquedaBin(Mitad + 1,fin, valor, selec);  
    }     
}
function makeSqlString(Str){
  var temp,S = Str;
    if (S == null) S = "";
     temp = S.replace(/'/gi,"''");
	return "'"+temp+"'";
}


