function trim(inputString) {
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") {
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") {
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) {
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
   }
   return retValue;
}
function RemoveBad(strTemp) {
        strTemp = strTemp.replace(/\<|\>|\"|\%|\,|\;|\.|\:|\_|\(|\)|\{|\}|\[|\]|\&|\$|\+|\=|\\|\/|\#|\~|\*|\¬|\º|\ª|\!|\¡|\?|\¿/g," ");
return strTemp;
}
function valida() {
valor=document.forms[0].buscar.value
valornet=RemoveBad(valor)
valornet=trim(valornet)

document.forms[0].buscar.value=valornet
  if (document.forms[0].buscar.value.length > 0 && document.forms[0].buscar.value != " ") {
        if (valornet.length < 3){
                alert('Debes introducir 3 caracteres como mínimo');
                document.forms[0].buscar.value=''
                document.forms[0].buscar.focus();
                return false;
        }
        if (valornet.length > 20){
                alert('La búsqueda es demasiado larga');
                document.forms[0].buscar.value=''
                document.forms[0].buscar.focus();
                return false;
        }
        return true;
  }
  else {
document.forms[0].buscar.value=valornet
  return false;
  }
}
