/* ********************************************************************* */
// 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 info_fiche 		= '#info_fiche_'+ idson;
			var titre 			= '#titre_'+ idson;
			var description 	= '#description_'+ idson;
			var tags 			= '#tags_'+ 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 QUELLE TAILLE ON EST
	
	
	if ($(fiche).css('height') == '200px') {
		// SI ON EST EN GRANDE TAILLE ON PASE EN PETITE TAILLE
	
		// VAKEUR POUR LES PETITE TAILLE
			var fiche_height	= '75px';
			
			var info_fiche_left 	=	'70px';
			var info_fiche_top		=	'4px' ;
			var info_fiche_height	=	'90%';
			var info_fiche_width	=	'35%';
			
			var titre_left 		= '00px'; // a virer'70px'
			var titre_top 		= '0px'; // '4px'
			var titre_height 	= '30px';
			var titre_width 	= '98%';  // '400px'
	
			var description_visibility = 'hidden';
			
			var photo_left 		= '8px';
			var photo_top 		= '4px';
			var photo_height 	= '55px';
			var photo_width 	= '55px';
			
			var localisation_left = '2px'; //'70px'
		
			var cat_sscat_left 	= '0px'; // '220px'
			var cat_sscat_width = '265px';  // A prendre en compte dans la suite
			
			var waveform_left 	= '75px'; // '585px'
			var waveform_top 	= '5px';
			var waveform_height = '60px';
			var waveform_width 	= '30%'; // '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 {
		// Si on est en petite taille on passe en grande taille
		
		// Valeurs pour la grande taille
			var fiche_height 	= '200px';
			
			var info_fiche_left 	=	'4px'	;
			var info_fiche_top		=	'4px' 	;
			var info_fiche_height	=	'90%'	;
			var info_fiche_width	=	'35%'	;  // 50%
			
			var titre_left 		= '-62px'; // '10px'
			var titre_top 		= '00px'; //'10px';
			var titre_height 	= '38px'; // '38px';
			var titre_width 	= '100%';  //'50%';
	
			var description_visibility = 'visible';
			
			var photo_left 		= '10px';
			var photo_top 		= '60px';
			var photo_height 	= '130px';
			var photo_width 	= '147px';
			
			var localisation_left 	= '520px';	//'160px';
			var localisation_top 	= '320px';	//'160px';
			
			var cat_sscat_left 	= '00px';  // '310px'
			var cat_sscat_top 	= '00px';  // '310px'
			
			var waveform_left 	= '0px';		//'685px'
			var waveform_top	= '100px';		//'10px'
			var waveform_height = '100px'; 		//'45px' 100
			var waveform_width 	= '600px';		 //'300px' 600
			
			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
// CHANGEMENT  DE LA TAILLE DE LA FICHE
		// $(fiche).animate( { height: "200px" } , { queue:false, duration:200 } ) ;
		$(fiche).animate( { height: fiche_height } , { queue:false, duration:200 } ) ;
		
// PLACEMENT DU TITRE
		$(info_fiche).animate( { left: info_fiche_left , top: info_fiche_top , height: info_fiche_height , width: info_fiche_width  } , { queue:false, duration:500 } ) ;  // OK
		// $(titre).animate( { left: titre_left , top: titre_top , height: titre_height , width: titre_width  } , { queue:false, duration:500 } ) ;  // OK
		//  $(titre).css( { fontSize: "16pt" } ) ;	// OK
		
// CHANGEMENT DISPLAY DESCRIPTION		
		$(description).css( { visibility: description_visibility } ) ; 
		// $(description).FadeIn(500) ; 
	 	$(tags).css( { visibility: description_visibility } ) ;
		
		
// ANIMATION DE LA PHOTO
		//$(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
		
//  ANIMATION DU CHAMPS LOCALISATION
		// $(localisation).css( { float: 'none' } ) ; 
		$(localisation).animate( { left: localisation_left, top: localisation_top } , { queue:false, duration:500 } ) ;  // OK
	
		$(cat_sscat).animate( { left: cat_sscat_left } , { queue:false, duration:500 } ) ;  // OK
		// $(cat_sscat).css( { fontSize: "10pt" } ) ;	// OK
	
// ANIMATION DE LA WAVEFORM
	// $(waveform).css( { 	float: none } ) ; 
	//	$(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
		$(action).animate( { right: action_right , top: action_top  } , { 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" });


}


/* ***************************************************************** */
/*  FONCTION QUI GERE LA DEMANDE D EDITION DE LA FICHE SUR LAQUELLE ON CLIC SUR LE CRAYON
/* ***************************************************************** */
function edit_fiche(idson) {
	
	alert('Vous pourrez prochainement nous envoyer des remarques sur ce son ' + idson);
	
	// SELON LES DROITS ATTRIBU2ES AU USER  ON PEUT
		// SOIT EDITER LA FICHE  >  ADMIN ET PROPRIETAIRE DU SONEN QUESTION
		// SOIT ENVOYER UN COURRIER CONCERNAT CE SON SOIT SUR LE PRIX SOIT SUR LE CONTENU POUR LES USERS IDENTIFIES
		// SOIT TRADUIRE LE SON POUR LES USERS TRADUCTEURS MODIFICATEURS*
		// SOIT envoyer un courrier general avec demande d'in fo pôur les users son loggués.
		
	
}

