var current_nbr = 0; function suggestion(caseRecherche,event) { var value = caseRecherche.val(); var caseLeft = caseRecherche.offset().left; var caseTop = caseRecherche.offset().top; var caseWidth = caseRecherche.width(); caseTop = caseTop + caseRecherche.height() + 20; caseWidth = caseWidth + 20; $("#caseSuggestion").css({ "top": caseTop+"px", "left": caseLeft+"px", "width": caseWidth+"px" }); switch (event.which) { // TOUCHE " FLECHE BAS " case 40 : if (current_id_focus > 9) { document.getElementById('caseSuggestion').scrollTop = current_id_focus * 20; } else { document.getElementById('caseSuggestion').scrollTop = 0; } if ( current_id_focus > 0 && current_id_focus < current_nbr) { loose_focus_style(current_id_focus); } if ( current_id_focus < current_nbr ) { give_focus_style(current_id_focus+1); current_id_focus++; } break; // TOUCHE " FLECHE HAUT " case 38 : if (current_id_focus > 9) { document.getElementById('caseSuggestion').scrollTop = current_id_focus * 20; } else { document.getElementById('caseSuggestion').scrollTop = 0; } if ( current_id_focus >= 1 ) { loose_focus_style(current_id_focus); if ( current_id_focus >= 2 ) give_focus_style(current_id_focus-1); this.current_id_focus--; } break; // TOUCHES " FLECHE GAUCHE " et " FLECHE DROITE " desactivees case 37 : break; case 39 : break; // TOUCHE " ENTRER " case 13 : if ( current_id_focus >= 1 ) { envoiSuggestion(current_id_focus); hide_list(); } // TOUTES LES AUTRES TOUCHES default : if ( value == '' ) { current_id_focus = 0; current_nbr = 0; hide_list(); } else if (value.length > 2) { affichageSuggestion(value); } break; } } function give_focus_style(id,control) { if ( id != 0 && id != current_id_focus) { surlignerSuggestion('in',id); } if ( control == 1 && id != current_id_focus) { loose_focus_style(current_id_focus); current_id_focus = id; } } function loose_focus_style(id) { if ( current_id_focus != 0 ) { surlignerSuggestion('out',id); } } function redirect() { if (document.getElementById('formSearch').q.value.length < 2) { alerte("
Your search is too short","ok"); return false; } else if (current_id_focus < 1) { return true; } else { return false; } } function affichageSuggestion(value) { //window.alert("test3"); this.current_id_focus = 0; document.getElementById('caseSuggestion').scrollTop = 0; document.getElementById('caseSuggestion').innerHTML = "
Chargement
"; $("#caseSuggestion").fadeIn('slow'); //window.alert(value); var url = "/executions/suggestion.php"; var parametres = "recherche="+value; $.ajax({ type: "POST", url: url, data: parametres, success: function(data){ afficheReponseSuggestion(data); } }); } function afficheReponseSuggestion(doc) { //window.alert(doc); if (doc == "rien") { $("#caseSuggestion").fadeOut(); } else if (doc == "aucun") { $("#caseSuggestion").fadeOut(); } else { var tableauResultat = doc.split("|||"); current_nbr = tableauResultat[0]; var codeHtml = tableauResultat[1]; document.getElementById('caseSuggestion').innerHTML = codeHtml; } } function surlignerSuggestion(mode,id) { if (mode == "in") { document.getElementById("ligneSuggestion"+id).className = "ligneSuggestion2"; if (document.getElementById("soustitreSuggestion"+id)) { document.getElementById("soustitreSuggestion"+id).className = "suggestionSoustitre2"; } if (document.getElementById("optionSuggestion"+id)) { document.getElementById("optionSuggestion"+id).className = "suggestionOption2"; } } else { document.getElementById("ligneSuggestion"+id).className = "ligneSuggestion"; if (document.getElementById("soustitreSuggestion"+id)) { document.getElementById("soustitreSuggestion"+id).className = "suggestionSoustitre"; } if (document.getElementById("optionSuggestion"+id)) { document.getElementById("optionSuggestion"+id).className = "suggestionOption"; } } } function envoiSuggestion(id) { var url = document.getElementById('infosSuggestion'+id).value; location.href = url; // window.alert(url); } function focus_on() { focus = true; } function focus_off() { focus = false; } document.onclick = function () { if ( focus == false ) hide_list(); }; function hide_list() { $("#caseSuggestion").fadeOut(); } function suggestionOld(value,event) { this.current_search = document.getElementById('formSearch').q.value; //window.alert("key : "+event.keyCode); switch (event.which) { // TOUCHE " FLECHE BAS " case 40 : if (current_id_focus > 9) { document.getElementById('caseSuggestion').scrollTop = current_id_focus * 20; } else { document.getElementById('caseSuggestion').scrollTop = 0; } if ( current_id_focus > 0 && current_id_focus < current_nbr) { loose_focus_style(current_id_focus); } if ( current_id_focus < current_nbr ) { give_focus_style(current_id_focus+1); current_id_focus++; } break; // TOUCHE " FLECHE HAUT " case 38 : if (current_id_focus > 9) { document.getElementById('caseSuggestion').scrollTop = current_id_focus * 20; } else { document.getElementById('caseSuggestion').scrollTop = 0; } if ( current_id_focus >= 1 ) { loose_focus_style(current_id_focus); if ( current_id_focus >= 2 ) give_focus_style(current_id_focus-1); this.current_id_focus--; } break; // TOUCHES " FLECHE GAUCHE " et " FLECHE DROITE " desactivees case 37 : break; case 39 : break; // TOUCHE " ENTRER " case 13 : if ( current_id_focus >= 1 ) { envoiSuggestion(current_id_focus); hide_list(); } // TOUTES LES AUTRES TOUCHES default : if ( value == '' ) { current_id_focus = 0; current_nbr = 0; hide_list(); } else if (value.length > 2) { affichageSuggestion(value); } break; } }