if(typeof(benchmark) == "undefined") { var benchmark = new Object(); }

benchmark.ObjBlocRecherche = function(mode){
	this.initialise = function(){
		this.bindActions();
	};
	/**
	 * Voir ObjChaine::getChaineUrl().
	 * @param str chaîne source
	 * @return la chaîne sans accents, espaces et caractères non-alphanum.
	 */
	this.traduitChaine = function(str) {
		var dict = {
				"ÀÁÂÃÄÅàáâãäå": "a",
				"ÒÓÔÕÖØòóôõöø": "o",
				"ÈÉÊËèéêë": "e",
				"Çç": "c",
				"ÌÍÎÏìíîï": "i",
				"ÙÚÛÜùúûü": "u",
				"ÿ": "y",
				"Ññ": "n"
		};
		jQuery.each( dict, function(k){
			var re = "[" + k + "]";
			str = str.replace( new RegExp( re, "g" ), dict[k] );
		});
		str = str.toLowerCase();
		str = str.replace( new RegExp( "[^\.a-z0-9-]+", "g" ), "-" );
		str = str.replace( new RegExp( "(^-+|-+$)", "g" ), "" );
		return str;
	};
	
	this.soumetsRecherche = function(e,form) {
		var motscles = this.traduitChaine(form.f_motscles_qr.value);
		var defaut = this.traduitChaine( $(form.f_motscles_qr).attr( 'valeurpardefaut' ) );
		if ( ( motscles.length == 0 ) || ( motscles == defaut ) ){
			return false;
		}
		var cat_id = form.f_rech_categorie.value;
		var cat_lib = this.traduitChaine(form.f_rech_categorie.options[form.f_rech_categorie.selectedIndex].text);
		var url = form.action + [ motscles, cat_id, cat_lib, 1 ].join("/") + "/";
		window.location = url;
		return false;
	}
	
	this.bindActions = function(){
		var form_recherche = $("#f_blocrecherche");
		if ( form_recherche.length > 0) {
			/*
			 * Comme on veut utiliser une URL propre pour la recherche, on
			 * capture le submit, on réécrit l'URL, on fait une redirection et
			 * annule la soumission.
			 */
			form_recherche
				.bind( 'submit',
					{self:this},
					function(e) {
						return e.data.self.soumetsRecherche(e,this);
					}
					
			);
			$('#blocrecherche .bouton_ok')
			    .bind( 'click',
			    		{self:this},
			    		function(e){
			    			var form = $('#f_blocrecherche');
			    			return e.data.self.soumetsRecherche(e,form[0]);
			    		}
			);
		}
	};
	this.initialise();
}
/**
* pour l'instant l'instanciation est automatique :
*/
$(document)
	.ready(
		function()
		{
			/**
			* on créé si besoin le domaine d'instanciation :
			*/
			if(typeof(benchmark.execution) == 'undefined') { benchmark.execution = new Object(); }
			// instance :
			benchmark.execution.objBlockRecherche = new benchmark.ObjBlocRecherche();
		}
	);