/* ********************************************************************* */
// Ce javascript gere le champs de recherche de mots dans son ensemble 
/* ********************************************************************* */



/* ***************************************************************** */
//  VIDE LE CHAMPS RECHERCHE  QUAND RECHERCHE RAPIDE  EST ECRIT ****************
/* ***************************************************************** */
function focusRecherche(champ){ //v3.0
	 if (champ.value=="Recherche Rapide") { champ.value=""; } else { champ.select(); }
	 if (champ.value=="Recherche") { champ.value=""; } else { champ.select(); }
	 if (champ.value=="Search") { champ.value=""; } else { champ.select(); }
	 if (champ.value=="Chercher des photos") { champ.value=""; } else { champ.select(); }
}


/* ***************************************************************** */
//  REMPLI LE CHAMP MAIL QUAND IL EST VIDE  *********************************************
/* ***************************************************************** */ 
function blurRecherche(champ){ //v3.0
	 if (champ.value=="") { champ.value="Search";}
}





/* ***************************************************************** */
/*  AJOUTE LE MOT CLIQUE A LA RECHERCHE PRECEDENTE   * en cours de verification   */
/* ***************************************************************** */
function ajouteMotARecherche(recherche) {
	mot = document.forms['formMotCle'].elements['motSon'].value ;
	if (mot!="") {
		if (recherche!="") {
			mot=recherche+","+mot;
		}
		window.location.href = "chercherson.php?mot="+mot;
	}
}



/* ***************************************************************** */
/* FONCTION REALISANT L'AFFICHAGE DES PROPOSITIONS DE RECHERCHES     */
/* ***************************************************************** */
function onTapeRecherche(e) {
	

	// alert("vous venez de taper la lettre"+e.charCode);
	// pressed est la valeur asci de la dtouche pressée
	pressed=(e.charCode)?e.charCode: ((e.keyCode)?e.keyCode:((e.which)?e.which:0));


	//alert("pressed est  "+pressed)
	//  la vartiable recherche correspond à la requete demandée.
	recherche = document.forms['recherche'].elements['mot'].value;

	
	//	alert("voila le champs recherche - "+ recherche+ "-");


	if (pressed!=8) { //  si on tape le retour en arriere
		recherche=recherche+String.fromCharCode(pressed);
	} else {
		recherche=recherche.substring(0,recherche.length-1);
	}

	if (recherche=="") {
		with(document.getElementById('suggest').style) {
			display="none";
		}
	} else {
		with(document.getElementById('suggest').style) {
			display="block";
		}
			document.getElementById('suggest').innerHTML="<ul><li>Searching ...</li></ul>";
	}

	xmlhttp=null;
		// code for Mozilla, etc.
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest();
  	} else if (window.ActiveXObject) { 
		// code for IE
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}

	// var url = "http://localhost:8888/SALADOTEC/ajax/suggestmotcles.php?commence="+recherche ; // Adresse pour la page de sugeestion de mot clés
	// var url = "http://www.saladotec.com/ajax/suggestmotcles.php?commence="+recherche ; // Adresse pour la page de sugeestion de mot clés


	   var url = "ajax/suggestmotcles.php?commence="+recherche ; // Adresse pour la page de suggestion de mot clés


	xmlhttp.open("GET", url ,true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			// condition si il n'y a pas de réponse  dans la requete suggestmotcles.
			
			// alert(xmlhttp.responseText);  // affiche les résultat temporairament dans une fenetre.
			document.getElementById('suggest').innerHTML=xmlhttp.responseText;
		}
  }
	xmlhttp.send(null);
}



/* ***************************************************************** */
/* RENVOI DE LA PAGE VERS LA RECHERCHE DU MOT                        */
/* ***************************************************************** */
function chercherMot(mot) {
	// alert("recherche vers le mot "+mot);
		window.location.href = "chercherson.php?mot="+mot;
}


/* ***************************************************************** */
/*  FONCTION DE GESTION DES AFFICHAGES DES FICHES DE RESUTATS DE RECHERCHE
/* ***************************************************************** */
function masque_fiche(idson) {
	
	var cadre = '#fiche_'+ idson;
	// alert('masquage de la fiche'+ cadre );
	$(cadre).css({ display: "none"});

	 /*  CA MARCHE */
	 
}


/* ***************************************************************** */
/*  FONCTION DE GESTION DES AFFICHAGES DES FICHES DE RESUTATS DE RECHERCHE
/* ***************************************************************** */
function voile_fiche(idson) {
	// alert('voilage de la fiche'+ idson );
	
	// change l opcite du cadre demandé pour le rendre plus blanc
		var cadre = '#fiche_'+ idson;
		// alert('masquage de la fiche'+ cadre );
	// definition des valeurs d opacite
		// var full_view 	= '1' ;
		// var opac_view	= '0.2' ;
		
	// Reprend l etat de l opcité du cadre 
		var opaq = $(cadre).css( "opacity" );
		
			if (opaq >= 1)  {
				$(cadre).animate({ opacity: 0.2 }, 200 );
			} else {
				$(cadre).animate({ opacity: 1 }, 200 );
			}
	 /* CA MARCHE */	
}


/* ********************************************************************************* */
/*  FONCTION DE GESTION DES AFFICHAGES DES FICHES DE RESUTATS DE RECHERCHE
/* ********************************************************************************* */
function reduit_fiche(idson) {
	// alert('reduction de la fiche'+ idson );
	
		// Liste des cadres a changer

			var fiche 			= '#fiche_'+ idson;
			var titre 			= '#titre_'+ idson;
			var description 	= '#description_'+ idson;
			var waveform 		= '#waveform_'+ idson;
			var photo 			= '#photo_'+ idson;
			var localisation 	= '#localisation_'+ idson;
			var cat_sscat 		= '#cat_sscat_'+ idson;
			var format_audio 	= '#format_audio_'+ idson;
			var bundle 			= '#bundle_'+ idson;
			var duree 			= '#duree_'+ idson;
			var action 			= '#action_'+ idson;
			var prix 			= '#prix_'+ idson;
	
	
	
	// Parametre à toggliser

	// determiner dans quel talle on est
	
	if ($(fiche).css('height') == '200px') {
	
		// Valeur pour la petite taille
			var fiche_height	= '75px';
			
			var titre_left 		= '70px';
			var titre_top 		= '4px';
			var titre_height 	= '30px';
			var titre_width 	= '500px';
	
			var description_visibility = 'hidden';
			
			var photo_left 		= '8px';
			var photo_top 		= '4px';
			var photo_height 	= '55px';
			var photo_width 	= '55px';
			
			var localisation_left = '70px';
		
			var cat_sscat_left 	= '220px';
			
			var waveform_left 	= '585px';
			var waveform_top 	= '5px';
			var waveform_height = '60px';
			var waveform_width 	= '400px';
			
			var format_audio_visibility = 'visible';
			
			var bundle_visibility = 'hidden';
			
			var action_right 	= '2px';
			var action_top 		= '40px';
			var action_height 	= '30px';
			var action_width 	= '130px';
					 
 	} else {
		
		// Valeurs pour la grande taille
			var fiche_height 	= '200px';
			
			var titre_left 		= '10px';
			var titre_top 		= '10px';
			var titre_height 	= '38px';
			var titre_width 	= '50%';
	
			var description_visibility = 'visible';
			
			var photo_left 		= '10px';
			var photo_top 		= '60px';
			var photo_height 	= '130px';
			var photo_width 	= '147px';
			
			var localisation_left = '160px';
		
			var cat_sscat_left 	= '310px';
			
			var waveform_left 	= '685px';
			var waveform_top	= '10px';
			var waveform_height = '45px';
			var waveform_width 	= '300px';
			
			var format_audio_visibility = '';
			
			var bundle_visibility = 'visible';
			
			var action_right 	= '2px';
			var action_top 		= '20px';
			var action_height 	= '35px';
			var action_width 	= '130px';
		
	}

			// aller chercher la taille de la fiche
			
		// $(fiche).animate( { height: "200px" } , { queue:false, duration:200 } ) ;
		$(fiche).animate( { height: fiche_height } , { queue:false, duration:200 } ) ;
		
		$(titre).animate( { left: titre_left , top: titre_top , height: titre_height , width: titre_width  } , { queue:false, duration:500 } ) ;  // OK
		// $(titre).css( { fontSize: "18pt" } ) ;	// OK
		
		$(description).css( { visibility: description_visibility } ) ; 
		// $(description).FadeIn(500) ; 
		
		
		//$(photo).css( { left: photo_left , top: photo_top , height: photo_height , width: photo_width  } ) ;  // OK
		$(photo).animate( { left: photo_left , top: photo_top , height: photo_height , width: photo_width  } , { queue:false, duration:350 } ) ;  // OK
		
		
		$(localisation).animate( { left: localisation_left } , { queue:false, duration:500 } ) ;  // OK
	
		$(cat_sscat).animate( { left: cat_sscat_left } , { queue:false, duration:500 } ) ;  // OK
		// $(cat_sscat).css( { fontSize: "10pt" } ) ;	// OK
	
		$(waveform).animate( { 	left: waveform_left , top: waveform_top , height: waveform_height , width: waveform_width } , { queue:false, duration:500 } ) ;  // OK
		
		//  $(format_audio).css( { visibility: "visible" } ) ; 
		
		// $(duree).animate( { position: "absolute" ,	right: "140px" , top: "10px" , height: "35px" , width: "90px" } , { queue:false, duration:500 } ) ;  // OK
		// $(duree).css( { fontSize: "12pt" } ) ;	// OK
		
		// $(prix).animate( { position: "absolute" ,	right: "0px" , top: "100px" , height: "25px" , width: "120px" } , { queue:false, duration:500 } ) ;  // OK
		// (prix).css( { right: "100px" , top: "70px" , height: "25px" , width: "120px"  } ) ;	// OK
		

		$(bundle).css( { visibility: bundle_visibility } ) ; 

		$(action).animate( { right: action_right , top: action_top , height: action_height , width: action_width } , { queue:false, duration:500 } ) ;  // OK

		
		
}


/* ***************************************************************** */
/*  FONCTION DE GESTION DES AFFICHAGES DES FICHES DE RESUTATS DE RECHERCHE
/* ***************************************************************** */
function selectionne_fiche(idson) {
		var cadre = '#fiche_'+ idson;
	// alert('masquage de la fiche'+ cadre );

	$(cadre).css({ color: "red", background: "blue" });


}

