function switchMenu(id){
	var el = document.getElementById(id);
	if(el.style.display != "block")
	{
		el.style.display = "block";		
	}
	else
	{
		el.style.display = "none";	
	}
}



function ajoutBib(id,id_m){
    $.ajax({
               type: "POST",
               url: "../../public/ajax/xajoutBib.php",
               data: "id="+id+"&id_membre="+id_m,
               success: function(msg){
                    if(msg == 1){
                        $(".action_ajout_livre_recherche_0_"+id).css("display","none");
                        $(".action_ajout_livre_recherche_1_"+id).css("display","block");
                    }
               }
    });
}

function switch2Menu(id1,id2){
var el1 = document.getElementById(id1);
var el2 = document.getElementById(id2);
	if(el1.style.display != "block")
	{
		el1.style.display = "block";
		el2.style.display = "none";
	}
	else
	{
		el1.style.display = "none";
		el2.style.display = "block";
	}

}

function switch2Menu2(id1,id2){
var el1 = document.getElementById(id1);
var el2 = document.getElementById(id2);

el1.style.display = "block";
el2.style.display = "none";
}

function affiche(id) {
 document.getElementById(id).style.display = 'block';
}

function masque(id) {
 document.getElementById(id).style.display = 'none' ;
}

/************************/

function change_class(id) {
	document.getElementById(id).className= "actif";
}
/*retour a l'etat initial sur les li*/
function change_class_back(id) {
	document.getElementById(id).className= "inactif";
}
/*************************************/

/*********************************/

function change_classlien(id) {
	document.getElementById(id).className= "lien-actif";
}
/*retour a l'etat initial sur les a*/
function change_classlien_back(id) {
	document.getElementById(id).className= "lien-inactif";
}

/******************************/
// JavaScript Document
function setActiveStyleSheet(title) {
 var i, a, main;
 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
 a.disabled = true;
 if(a.getAttribute("title") == title) {a.disabled = false;}
 }
 }
}
function getActiveStyleSheet() {
 var i, a;
 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
 if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {return a.getAttribute("title");}
 }
 return null;
}
function getPreferredStyleSheet() {
 var i, a;
 for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
 if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")
 ) {return a.getAttribute("title");}
 }
 return null;
}
function createCookie(name,value,days) {
 if (days) {
 var date = new Date();
 date.setTime(date.getTime()+(days*24*60*60*1000));
 var expires = "; expires="+date.toGMTString();
 }
 else {expires = "";}
 document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0;i < ca.length;i++) {
 var c = ca[i];
 while (c.charAt(0)==' ') {c = c.substring(1,c.length);}
 if (c.indexOf(nameEQ) === 0) {return c.substring(nameEQ.length,c.length);}
 }
 return null;
}

function change_note(notation, note) {

for(var i = 1 ;i<=note;i++) {
	img = document.getElementById('img_note_'+notation+'_'+i);
	img.src = "public/images/note_pleine.png";
}

for(i = note+1 ;i<6;i++) {
	img = document.getElementById('img_note_'+notation+'_'+i);
	img.src = "public/images/note_vide.png";
}

document.getElementById('notation_'+notation).value = note;
if (note==0)
{
	img = document.getElementById('img_note_'+notation+'_0');
	img.src = "public/images/note_nulle2.png";
}
if (note!=0)
{
	img = document.getElementById('img_note_'+notation+'_0');
	img.src = "public/images/note_nulle.png";
}
}
function choisirTag(tag, id){
	tab = document.getElementById('string').value.split(',');
	var string_present;
	document.getElementById('string').value	=	'';

	for (var i=0;i<tab.length;i++){
		if (i!=tab.length-1){
			if (i==0){
				string_present	=	tab[i];
			}else{
				string_present	+=	','+tab[i];
			}
		}
	}

	if (string_present){
		document.getElementById('string').value = string_present+','+tag;
	}else{
		document.getElementById('string').value = tag;
	}
	document.getElementById('zoneResultats').style.display 	=	'none';
	document.getElementById('zoneResultats').style.visibility 	='hidden';
}

function loadData(id) {
	tab = document.getElementById('string').value.split(',');
	num = tab.length - 1;
		document.getElementById('zoneResultats').style.display 	=	'block';

	search = connectURL('private/actions/xRechercheTag.php?recherche='+ tab[num]+'&id='+id);
	document.getElementById('zoneResultats').style.visibility = 'visible';
	document.getElementById('zoneResultats').innerHTML = search

}

// contrainte en largeur (pas de conservation des rapports)
function redimage(img, maxwidth) {
	if (img.width > maxwidth) {
		width = img.width;
		img.width = maxwidth;
	}
}
// contrainte en hauteur avec conservation des rapports
function redime(image,taille){
	var height_max		=	taille
	var height_actuel	=	image.height;
	var width_actuel	=	image.width

	if (image.height>height_max){
		image.height	=	height_max;
		image.width		=	width_actuel*height_max/height_actuel;
	}
}

function cacheImage(id,url) {

	var id_image	=	'image_'+id;
	var id			=	id;
	var url			=	url;

	var xhr_object = null;

	if(window.XMLHttpRequest) {
		xhr_object = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		xhr_object = new window.ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return(false);
	}

	xhr_object.onreadystatechange = function() {
		if(xhr_object.readyState == 4) {
			if(xhr_object.status  == 200)  {
				document.getElementById(id_image).src	=	xhr_object.responseText;
				document.getElementById(id_image).onload	=	null;
			}
		}
	}

	xhr_object.open("GET", '/public/ajax/cacheImage.php?id='+id+'&url='+url, true);
	xhr_object.send(null);
}

function cacheImage_t(gencode,id){
	var id_image	=	'image_'+id;
		
	$.ajax(
		 	{	
				url: "/public/ajax/cacheImage_t.php",
				
				data: "gencode="+gencode,
				async: true,
				success: function(html){
			     		if (html!=""){
			     			document.getElementById(id_image).src	=	html;
							document.getElementById(id_image).onload	=	null;	
						}		     					
				 }
	         })

}




function switchMenuDetail(titre, detail){
	var el = document.getElementById(detail);
	var el2 = document.getElementById(titre);

	if(el.style.display != "block")
	{
		el.style.display = "block";
		el2.style.backgroundImage = "url('../public/themes/default/images/parametre_bg2.gif')";
	}
	else
	{
		el.style.display = "none";	
		el2.style.backgroundImage = "url('../public/themes/default/images/parametre_bg.gif')";
	}
}

function afficheLienTrad(id,destination){
		var comm		=	document.getElementById(id);
		var trad		=	document.getElementById('trad_'+id);
		var text 		= 	comm.innerHTML;		
		text_format		=	text.substring(0,100);
		
		google.language.detect(text_format, function(result) {
			if (result.language != destination){
				
				trad.innerHTML='<a style="cursor:pointer;" onclick="trad('+id+')">Traduction automatique du commentaire</a>';
			}
		});
	}
	
function noenter() {
	return !(window.event && window.event.keyCode == 13); 
}	


/********* toooltiip *********/
var affiche=true;
var test=false;
function tout(){test = true;}      
if($.fn.tbetterTooltip == undefined){
    $.fn.tbetterTooltip = function(options){  

         var defaults = {  speed: 200,  delay: 300  };  
         
         var options = $.extend(defaults, options);  
 
         getTip = function() {          
              if(affiche){
                var tTip =   
                "<div class='tip' style='z-index:1000;width: 350px;padding-top: 37px;display: none;position: absolute;background: transparent url(http://www.libfly.com/public/javascript/popup/image/tipTop.png) no-repeat top;'>" +  
                     "<div class='tipMid' style='background: transparent url(http://www.libfly.com/public/javascript/popup/image/tipMid.png) repeat-y; padding: 0 16px 2px 16px;'>"    +  
                     "</div>" +  
                     "<div class='tipBtm' style='background: transparent url(http://www.libfly.com/public/javascript/popup/image/tipBtm.png); height: 32px;'></div>" +  
                 "</div>"; 
                 affiche = false; 
             }else{
                var tTip="";
             }
             return tTip;  
         }  
         $("body").prepend(getTip());  
    
         $(this).each(function(){ 
             var $this = $(this);  
             var tip = $('.tip');  
             var tipInner = $('.tip .tipMid');
             var tipcrit =  $('#popup_note_crit'); 
               
             var tTitle = (this.title);  
             this.title = "";  
               
             var offset = $(this).offset();  
             var tLeft = offset.left;  
             var tTop = offset.top;  
             var tWidth = $this.width();  
             var tHeight = $this.height();  
             /* Mouse over and out functions*/  
             $this.click(function() {                  
                     tipcrit.html(tTitle); 
                     tipInner.html(tTitle);  
                     setTip(tTop, tLeft);  
                     setTimer();  
                     setTimeout("tout();",100);
                 },   
                 function() {  
                     stopTimer();  
                     tip.hide();
                     tipcrit.hide(); 
                     tipcrit.slideUp("slow"); 
                 } 
             );
             
                         
        $('*').click(function(){
            if(test){
               stopTimer();  
               tip.hide(); 
               tipcrit.slideUp("slow"); 
               test = false;
            }
           }
        );           

         setTimer = function() {  
             $this.showTipTimer = setInterval("showTip()", defaults.delay);  
         }  
       
         stopTimer = function() {  
             clearInterval($this.showTipTimer);  
         }  
       

         setTip = function(top, left){  
             var topOffset = tip.height();  
             var xTip = (left-54)+"px";  
             var yTip = (top-topOffset-60)+"px";  
             tip.css({'top' : yTip, 'left' : xTip});  
         }  
       
         showTip = function(){  
             stopTimer();   
             tip.animate({"top": "+=20px", "opacity": "toggle"}, defaults.speed); 
             tipcrit.slideDown("slow");
         }  
     });  
 }; 
}
setTimeout("$(\'.tTip\').tbetterTooltip({speed: 150, delay: 300})",1000)





