/* Some tools used in the advanced search page */ function searchFinished() { Element.hide("search_indicator"); $("criterio_opts").focus(); $("operand_opts").show(); } function showSearchHelp() { Element.show('adv_search_help_text_div'); Element.hide('adv_search_help_text_link'); Element.show('adv_search_hide_help_link'); } function hideSearchHelp() { Element.hide('adv_search_help_text_div'); Element.hide('adv_search_hide_help_link'); Element.show('adv_search_help_text_link'); } /* // Para hacer que el navegador recargue la página cuando se pincha en el Back, // añado el tiempo después del URL. Si has pasado más de 10000 segundos recargo la página. // Como el id de la búsqueda se guarda en la sesión, al recardgar salen todos los pasos en la // búsqueda actual. // De: http://www.irt.org/script/832.htm */ function checkLocationTime() { // console.log("Antes: "+window.location); var nowsecs = getTime(); if (window.location.search) { // console.log("check location time"); var thensecs = location.search.substring(1); var difference = nowsecs - thensecs; if ((nowsecs - thensecs) > 10000) { // console.log('reloading ....'); window.location.replace(window.location.href.substring(0,window.location.href.length - window.location.search.length) + '?' + nowsecs); } } else { // console.log('append time to location'); window.location.replace(window.location.href + '?' + nowsecs); } // console.log("Después: "+window.location); } /* // Una función que añade/borra la opción Año de la lista de criterios dependiendo del operand. */ function setYearOption(event) { year_text = "Año" var sel = event.element().selectedIndex if ((sel == 0) && ($('criterio_opts').options.length == 7)) { $('criterio_opts').options[$('criterio_opts').options.length] = new Option(year_text, 'year'); } else { $('criterio_opts').options[$('criterio_opts').options.length-1] = null; } } /* // Behaviours. */ CriterioSelector = Behavior.create({ initialize: function() { var source = this.element this._setCurrent(source.options[source.selectedIndex].value) this._setDefaultForCurrent() }, onchange: function(e) { var source = Event.element(e); this._setCurrent(source.options[source.selectedIndex].value) this._setDefaultForCurrent() }, _setCurrent: function(selected_value) { $('operand_select').enable(); if (this._current_input) { $(this._current_input).removeClassName('year_text'); $(this._current_input).removeClassName('txt_text'); $(this._current_input).removeClassName('ac_text'); $(this._current_input).removeClassName('user_text'); } if ( selected_value == 'title' ) { $('slct').hide(); $('year_opts').hide(); $('ac').hide(); $('ac').value=""; current = 'txt'; $(current).addClassName("txt_text") } else if (selected_value == 'year') { $('slct').hide(); $('ac').hide(); $('ac').value=""; current = 'txt'; $('year_opts').show(); $('operand_select').disable(); $(current).addClassName("year_text") } else if (selected_value == 'language') { $('year_opts').hide(); $('ac').hide(); $('ac').value=""; $('txt').hide(); current = 'slct'; $('slct').options.length = 0 langOpts.each(function(item, index) { $('slct').options[index] = new Option(item[1], item[0]) }); } else if (selected_value == 'doc_type') { $('year_opts').hide(); $('ac').hide(); $('ac').value=""; $('txt').hide(); current = 'slct'; $('slct').options.length = 0 dtOpts.each(function(item, index) { $('slct').options[index] = new Option(item[1], item[0]) }); } else { $('year_opts').hide(); $('slct').hide(); $('txt').hide(); $('txt').value=""; current = 'ac'; $(current).addClassName("ac_text") } this._current_input = current; this._selected_option = selected_value; }, _setDefaultForCurrent: function() { current = $(this._current_input) current.show(); if (this._selected_option == 'year') { current.value = 'escriba el año'; } else { current.value = 'escriba el criterio'; } // current.activate(); } }); CriterioInput = Behavior.create({ onclick: function(e) { this.element.value = ""; this.element.addClassName('user_text'); } }); /* Nota para Explorer. // Explorer no asigna los behaviors si se asignan los dos con el mismo addBehavior. // Por eso lo hago en dos líneas */ Event.addBehavior({ '#criterio_opts' : CriterioSelector }); Event.addBehavior({ '.input_text': CriterioInput }), /* // back button problem's fix */ Event.observe(window, 'load', checkLocationTime);