Ext.onReady(function(){
	if(Ext.get('home_search_btn')){

		Ext.get('home_search_btn').addListener('click', function(){
		
			var value = Ext.get('home_aroma_field').dom.value;
			if(value != "" && value != BASE.lang.product_search_field){
				Ext.Ajax.request({
					url : '../ajax/product_task.php',
					method : 'POST',
					params : {
						task : 'searchProduct',
						lang : Ext.get('lang_search_product').getValue(),
						product : value
					}, success : function(response){
						var responseData = Ext.decode(response.responseText);
						if(responseData.success == true){
							var arome_id = responseData.arome_id;
							var subarome_id = responseData.subarome_id;
							var pagename = 'produits';
							if(Ext.get('lang_search_product').getValue() == 'EN'){
								pagename = 'products';
							}
							window.location.href = 'http://www.metaromneotech.com/'+pagename+'/?arome_id='+arome_id+'&subarome_id='+subarome_id;
						}else{
							alert(BASE.lang.product_search_empty);
						}
					}, failure : function(e){
						if(e.status == 404){  // On reessaye avec une url différente
							Ext.Ajax.request({
								url : 'ajax/product_task.php',
								method : 'POST',
								params : {
									task : 'searchProduct',
									lang : Ext.get('lang_search_product').getValue(),
									product : value
								}, success : function(response){
									var responseData = Ext.decode(response.responseText);
									if(responseData.success == true){
										var arome_id = responseData.arome_id;
										var subarome_id = responseData.subarome_id;
										var pagename = 'produits';
										if(Ext.get('lang_search_product').getValue() == 'EN'){
											pagename = 'products';
										}
										window.location.href = 'http://www.metaromneotech.com/'+pagename+'/?arome_id='+arome_id+'&subarome_id='+subarome_id;
									}else{
										alert(BASE.lang.product_search_empty);
									}
								}
							});
						}
					}
				});
			}
		
		});
	}
});
