function tronquer(chaine) {
	var maxlength = 33;
	if (chaine.length > maxlength)
		return chaine.substring(0, maxlength) + "...";
	else
		return chaine;
}

function montre(id) {
	var d = document.getElementById(id);
	if (d) {
		etat = d.style.display;
	}
	for (var i = 1; i <= 3; i++) {
		if (document.getElementById('options'+i)) {document.getElementById('options'+i).style.display='none';}
	}
	if (d) {
		if (etat == 'block') {
			d.style.display = 'none';
		} else {
			d.style.display = 'block';
			encours = 1;
		}
	}
}
function sel(n, val, id) {
	val = tronquer(val);
	$('select'+n).update(val);
	if (n == 1) { // cas du select des types
		$('idsel1').value = id;
		$('options1').style.display = 'none';
		// on vide la liste des ssfamilles-produits
		$('options3').childElements().each(function(s) {
				s.remove();
		});
		// on met à jour la liste des marques
		$('select2').update('2 - '+$('defsel2').value);
		$('options2').childElements().each(function(s) { // on la vide d'abord
				s.remove();
		});
		// on met à jour la liste des produits
		$('select3').update('3 - '+$('defsel3').value);
		$('options3').childElements().each(function(s) { // on la vide d'abord
				s.remove();
		});
		
		var url = HTTP_MAIN + 'applications/ajaxFunction.php';
		var methode = "post";
		var parametres = "rechav=marques&type=" + id;
		// requete Ajax
		var myAjax = new Ajax.Updater(
			"options2",
			url,
			{
				method: methode,
				parameters: parametres,
				evalScripts: true
			}
		);
	}
	if (n == 2) { // cas du select des marques
		$('options2').style.display = 'none';
		// on met à jour la liste des produits
		$('options3').childElements().each(function(s) { // on la vide d'abord
				s.remove();
		});
		var url = HTTP_MAIN + 'applications/ajaxFunction.php';
		var methode = "post";
		var parametres = "rechav=appareils&marque=" + id + "&type=" + $('idsel1').value;
		// requete Ajax
		var myAjax = new Ajax.Updater(
			"options3",
			url,
			{
				method: methode,
				parameters: parametres,
				evalScripts: true
			}
		);
	}
	if (n == 3) {
		$('options3').style.display = 'none';
		var url = HTTP_MAIN + 'applications/ajaxFunction.php';
		var parametres = "redirapp=" + id;
		new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: parametres,
				onSuccess: function(transport) {
					document.location.href = transport.responseText;
				}
			}
		);
	}
}

function emptybasket()
{
	var url1 =  HTTP_MAIN + 'applications/ajaxFunction.php?modebasket=empty';
	var req1 = new Ajax.Request(url1, {
		method: 'get',
		onSuccess: function(transport, info) {
			$('nbart').update(transport.responseText);
			if ($('listeprod')) {
				$('listeprod').update('<li>'+$F('liblistevide')+'</li>');
			}
			if ($('contactlisteprod')) {
				$('contactlisteprod').update('<li>'+$F('liblistevide')+'</li>');
			}
		}
	});
}