function Trim(texto){
    var newtext = String(texto);
    var letra;    

    // por la derecha
    letra = newtext.substring(newtext.length - 1, newtext.length);
    while(letra == ' ' && newtext.length > 0){
		newtext = newtext.substring(0, newtext.length - 1);
		letra = newtext.substring(newtext.length - 1, newtext.length);
	}
    // por la izda
    letra = newtext.substring(0, 1);
    while(letra == ' ' && newtext.length > 0){
		newtext = newtext.substring(1, newtext.length);
		letra = newtext.substring(0, 1)
	} 

    return newtext;
}


// FUNCIÓN QUE GESTIONA EL REDIRECCIONAMIENTO HACIA OTRAS WEBS, EXCEPTO
// LA DE VIAJES.
function validarGuia(){
	// Eliminación de espacios en blanco.
	var tmpTexto;
	var tmpTexto = Trim(document.forms.frmGuia.textoGuia.value);

	// La siguiente línea la pongo pq sino existirían problemas en la asignación
	// del valor devuelto por Trim() al campo del formulario cuando se utiliza el
	// navegador Netscape v6.0.
	document.forms.frmGuia.textoGuia.value = "l";
	document.forms.frmGuia.textoGuia.value = tmpTexto;

	// Validación del texto introducido.
	
	var strTexto = document.forms.frmGuia.textoGuia.value;
	var strOpcion = document.forms.frmGuia.opcionGuia.selectedIndex;
	var strDir = Trim(document.forms.frmGuia.dir.value);
	strDir="elcorteingles.es"
	var strDirDeportes, strDirHogar, strDirInformatica, strDirLibros, strDirMusica;
	var strDirPerfumeria, strDirVideojuegos, strDirCine, strDirVinos, strDirViajes, strDirCoches;
    var strDirMultitienda, strDirBuscador;

	strDirCoches = "http://coches." + strDir;
	strDirFlores = "/flores";
	strDirLibros = "/libros";
	strDirInformatica = "/informatica";
	strDirMusica = "/musica";
	strDirPerfumeria = "/perfumeria";
	strDirCine = "/cine";
	strDirVinos = "/vinos";
	strDirDeportes = "/deportes";
	strDirVideojuegos = "/videojuegos";
	strDirHogar = "/hogar";
	strDirMultitienda = "/multitienda";
	
	strDirBuscador = "/buscador";

	switch (strOpcion){
		case 0: //WWW
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			document.forms.frmGuia.txtBuscar.value = escape(strTexto);
			document.forms.frmGuia.OPERATIVA.value = 'BUSQTOT';
			//document.forms.frmGuia.action = strDirBuscador + '/comun/redir.asp?idcentro=ECI&tipotienda=bebes&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			
			// pruebas en preproducción
			//Cuando se ponga en produccion hay que cambiar una linea por la otra
			//document.forms.frmGuia.action =  'http://www.ws.pre.eci.geci/buscador/buscador/BuscadorGlobal?OPERATIVA=BUSQTOT&txtBuscar=' + escape(strTexto);			
			//document.forms.frmGuia.action = strDirBuscador + '/buscador/ServletBuscador?OPERATIVA&txtBuscador=' + escape(strTexto);			
			//20041014
			document.forms.frmGuia.action = 'http://www.elcorteingles.es/buscador6/buscador6/BuscadorGlobal?OPERATIVA=BUSQTOT&txtBuscar=' + escape(strTexto);
			
			break;
		case 1: //Bebés
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			//document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=bebes&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=bebes&url=' + strDirMultitienda + '/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			break;
		case 2: //Coches			// no hacemos nada. Lo ignoramos.			document.forms.frmGuia.action = 'javascript:void(null)'
			break;
		case 3: //deportes
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.txtLiteral.value = strTexto;
			document.forms.frmGuia.method = 'get';
			document.forms.frmGuia.action = strDirDeportes + '/asp/buscador/buscaresul.asp';
			break;
		case 4: //eletronica
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			//document.forms.frmGuia.action = document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=electronica&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=electronica&url=' + strDirMultitienda + '/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			break;
		case 5: //flores
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.palabraClave.value = strTexto;
			document.forms.frmGuia.action = strDirFlores + '/buscador/buscaresul.asp?palabraClave=' + escape(strTexto);
			break;
		case 6: //hogar
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			document.forms.frmGuia.action = strDirHogar + '/secciones/guiafacil/buscadorhog.asp?texto_seek=' + escape(strTexto);
			break;
		case 7: // informática
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			document.forms.frmGuia.action = strDirInformatica + '/secciones/guiafacil/buscadorinf.asp?texto_seek='+escape(strTexto);
			break;		case 8: // juguetes
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			//document.forms.frmGuia.action = document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=juguetes2&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=juguetes2&url=' + strDirMultitienda + '/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			break;	
		case 9: // libros
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();				return false;			}			document.forms.frmGuia.guiafacil.value = strTexto;			document.forms.frmGuia.action = strDirLibros + '/secciones/buscador/buscasolo_f.asp?guiafacil=' + escape(strTexto);			break;		case 10: // maletas			if (strTexto.length < 2){				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			//document.forms.frmGuia.action = document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=disney&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=disney&url=' + strDirMultitienda + '/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			break;						
		case 11: //moda
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			//document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=moda&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=moda&url=' + strDirMultitienda + '/secciones/guiafacil/buscadortienda2.asp?texto_seek=' + escape(strTexto) + '%26ecis=225';
			break;
		case 12: // música
			if (strTexto == ''){
				alert("Debe teclear un texto de búsqueda.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.textoBuscado.value = strTexto;
			document.forms.frmGuia.method = 'get'
			document.forms.frmGuia.action = strDirMusica + '/buscador/resultadobuscadorcorto.asp';
			break;			
		case 13: //papeleria
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			//document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=papeleria&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=PAPELERIA&url=' + strDirMultitienda + '/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			break;
		case 14: // cine
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.textfieldName.value = strTexto;
			document.forms.frmGuia.method = 'get'
			document.forms.frmGuia.action = strDirCine + '/secciones/buscadorcorto/resultadocorto.asp';
			break;	
		case 15: // perfumería
		    if (strTexto == ''){
				alert("Debe teclear un texto de búsqueda.");
				document.forms.frmGuia.textoGuia.focus();				return false;			}			document.forms.frmGuia.CodigoClave.value = strTexto;			document.forms.frmGuia.action = strDirPerfumeria + '/BuscarArticulos/asp/guia_facil.asp?CodigoZona=M&CodigoClave='+escape(strTexto);			break;		case 16: // relojes			if (strTexto.length < 2){				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");				document.forms.frmGuia.textoGuia.focus();				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			//document.forms.frmGuia.action = document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=relojes&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			document.forms.frmGuia.action = document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=relojes&url=' + strDirMultitienda + '/secciones/guiafacil/buscadortienda2.asp?texto_seek=' + escape(strTexto)+ '%26ecis=235';
																																																													   
			break;
		case 17: // telefonía
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			//document.forms.frmGuia.action = document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=telefonia2&url=http://multitienda.elcorteingles.es/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			document.forms.frmGuia.action = document.forms.frmGuia.action = strDirMultitienda + '/comun/redir.asp?idcentro=ECI&tipotienda=telefonia2&url=' + strDirMultitienda + '/secciones/guiafacil/buscadortienda.asp?texto_seek=' + escape(strTexto);
			break;
		case 18: // videojuegos
		    if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;
			}
			document.forms.frmGuia.texto_seek.value = strTexto;
			document.forms.frmGuia.litBusc.value = strTexto;
			
			document.forms.frmGuia.action = strDirVideojuegos + '/buscador/buscador.asp?tipobusqueda=gf&litBusc='+escape(strTexto)+'&texto_seek='+escape(strTexto);
			break;		
		case 19: // vinos
			if (strTexto.length < 2){
				alert("Debe teclear un texto de búsqueda de 2 o más caracteres.");
				document.forms.frmGuia.textoGuia.focus();
				return false;			}			document.forms.frmGuia.txtNombre.value = strTexto;			document.forms.frmGuia.method = 'get';			document.forms.frmGuia.action = strDirVinos + '/buscador/resultados.asp';
			break;
		case 20: // viajes
			// no hacemos nada. Lo ignoramos.
			document.forms.frmGuia.action = 'javascript:void(null)'
			break;
		default:
			if (strTexto == '')
				alert("Debe seleccionar una tienda y teclear un texto de búsqueda.");
			else alert("Debe seleccionar una tienda.");			document.forms.frmGuia.opcionGuia.focus();			return false;	}	//document.forms.frmGuia.submit();	return true;}// FUNCION PARA IR A VIAJESfunction mostrarOpcionesViajes(){	if(document.frmGuia.opcionGuia.selectedIndex == 20){		window.location.href="http://www.elcorteingles.es/tiendas_e/cda/viajes_eci/0,3561,VECI,FF.html";		}}// FUNCION PARA IR A COCHESfunction mostrarOpcionesCoches(){	if(document.frmGuia.opcionGuia.selectedIndex == 2){		window.location.href="http://coches.elcorteingles.es/";		}}