/* AFFICHER MASQUER DIV */
window.onload=montre;
function montre(id) {
var d = document.getElementById(id);
        for (var i =1 ; i<=10; i++) {
                if (document.getElementById('tooltip_0'+i)) {document.getElementById('tooltip_0'+i).style.display='none';}
        }
if (d) {
	if(d.innerHTML.length>10) d.style.display='block';
	//alert(d.innerHTML.length);
	
}
}

/*window.setInterval("document.getElementById('tooltip_01').style.display='none'",3000);
window.setInterval("document.getElementById('tooltip_02').style.display='none'",3000);
*/

/*Gestion de l'accordeon - sélection du véhicule*/
function get_lst_accordeon(lvl,id,libelle){
  $("#divaccordeon"+lvl).load('./ajax/lst_accordeon.php',{level:lvl,param:id},function(){
	  	if(lvl>1) {
	  		$('#listAccordeon').children('div.title.selected').html((lvl-1)+' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+libelle);
	  		jQuery('#listAccordeon').accordion("activate", (lvl-1));
	  	}
	  	//setTimeout('init_scrollPane("'+lvl+'")',0);
	  	//$('.scroll-pane').jScrollPane();
		//$('.scroll-pane').jScrollPane({showArrows:true});
	  	$('#divaccordeon'+lvl).jScrollPane({showArrows:true});
  });

}

/*Gestion de l'affichage d'image - abandonné*/
function zoom_img(id){
	$("#splashimg").hide();
	$("#splashimg").attr("src","");
	$("#splashimg").attr("src",$("#"+id).attr("src"));
	h=$("#"+id).height();
	w=$("#"+id).width();
	t=$("#"+id).offset().top;
	l=$("#"+id).offset().left;
	
	$("#splashimg").attr("src",$("#"+id).attr("src"));
	$("#splashimg").height(h*2);
	$("#splashimg").css('top',t+'px');
	$("#splashimg").css('left',l+'px');
	$("#splashimg").width(w*2);
	$("#splashimg").fadeIn("slow");
	
}

function unzoom_img(id){
	$("#splashimg").fadeOut("slow");

}


/* Gestion du panier */
function ajouter_panier(reference, type_vehicule, js_path) {
	$.post(js_path + 'ajout_panier.php', {
			reference : reference,
			type_vehicule : type_vehicule
			}, function() {
				recalcule_bulle_pannier(js_path,reference);
			}
	
	)
}

function recalcule_bulle_pannier(js_path,reference){
	$("#NbrArticlePanier").load(js_path + 'get_nbr_article_panier.php');
	$("#tooltip_02").load(js_path + 'get_content_bulle_panier.php',{ref:reference});
}

function show_bulle_panier(){
	$("#tooltip_02").slideDown("slow");

}


function supplignepanier(id){
	if(confirm("Voulez-vous supprimer cette ligne de votre panier ?")){
		$("#parampanier").attr('value',id);
		$("#formulairePanier").submit();
	}
}

function supprimer_vehicule(ktypenr_t){
	if(confirm("Voulez-vous vraiment supprimer ce véhicule ?")){
	  $("#vehicule"+ktypenr_t).load('./ajax/supprimervehicule.php',{ktypenr:ktypenr_t},function(data){
		  if(data != 'false'){
			  $("#vehicule"+ktypenr_t).hide();
			  if(data == '0'){
				  $("#novehicules").show();  
			  }
		  }
	  });
	}
}

function recalcule_bulle_infos(){
	var divcontent = $("#tooltip_01").text();
	if(divcontent.length > 5){
		 blink_bulle_infos();
		 show_bulle_infos();
	}
}

function show_bulle_infos(){
	$("#tooltip_01").slideDown("slow");

}

function hide_bulle_infos(){
	$("#tooltip_01").slideUp("slow");

}

function blink_bulle_infos(){
	//$("#tooltip01_link").addClass('blinkaideinfo');
	$("#tooltip01_link").attr('href','moncompte.php');
}


/*
	display a new form with onsubmit ajax
*/
var survey_switch = function (data, node_id)
{
// for (var v in this) { alert(typeof v + ': ' + v + '=' + this[v]);}

	var block_toggle = $('#'+node_id);
	var block_lock = block_toggle.parents('.bloc_lock');
	var block_cadre = block_toggle.parents('.bloc_cadre');

	// disable submit imput while loading
	$('#'+node_id+' input#valider').attr('disabled', 'disabled');

	// prevent ie display bug with opacity and maybe cleartype (transparent pixel doesn't work)
	//block_toggle.css('background', 'transparent url(../images/css/cadre-bloc.gif) no-repeat scroll center top');

	// if data received from post contains form
	if ( $.trim(data).length && $('form.sondage', data).is('form') )
	{
		// keep bloc height
		block_lock.css( {height: block_cadre.outerHeight() + parseInt(block_cadre.css('margin-top')) + parseInt(block_cadre.css('margin-bottom'))} );
		block_lock.css('overflow', 'hidden');
		// hide
		block_toggle.animate(
			{opacity: 0, height: 'toggle'}
		,	1000, 'easeInOutQuart'
		,	function()
			{
				// then replace form with a new one
				$('form.sondage', this).replaceWith( $('form.sondage', data) );
				// and show (+ie remove inline style)
				$(this).animate(
					{ opacity: 1, height: 'toggle' } // $(this).children().outerHeight()+'px'
				,	750, 'easeInOutQuart'
				,	function()
					{
						$(this).removeAttr('style');
						block_lock.animate( { 'height': block_cadre.outerHeight() + parseInt(block_cadre.css('margin-top')) + parseInt(block_cadre.css('margin-bottom')) }, 250, function(){$(this).removeAttr('style')} );
					}
				);
			}
		);
	}
	// else hide survey
	else
	{
		// hide form
		block_toggle.animate( { height: 'toggle' }, 1250, 'easeInOutQuart', function() { block_lock.empty(); });

		// and hide container bloc
		block_cadre.animate(
			{opacity: 0, marginTop: '0px', marginBottom: '0px'}
		,	750, 'easeInOutQuart'
		);
	}
}