hs.graphicsDir='./highslide/graphics/';
hs.outlineType = 'rounded-white';
hs.showCredits = false;
hs.outlineWhileAnimating = true;

function see_type(act_value)
{
var xhr = getXhr();
var msg;
var	prov;

if (xhr == false)
	return ;

xhr.onreadystatechange = function() {
	if (xhr.readyState == 4 && xhr.status == 200){
		if (xhr.responseText == 'false')
			document.getElementById('avert').innerHTML = ' &nbsp;Ne sera lié à aucun groupe de couleur.';
		else if (xhr.responseText.indexOf('true:') > -1)
		{
			prov = xhr.responseText.substr(5);
			document.getElementById('avert').innerHTML = ' &nbsp;Sera lié au groupe : ' + prov;
		}
		else
			alert(xhr.responseText);
	}
}

xhr.open('POST', './ref_lm_test.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
msg = "id=" + act_value;
xhr.send(msg);
}

/* Recherche Ajax */
function getXhr(){
	var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	   xhr = false; 
	} 
	return xhr;
}

function sendInfo(param, page)
{
var xhr = getXhr();

// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
	// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
	if(xhr.readyState == 4 && xhr.status == 200){
		document.getElementById("info").innerHTML = xhr.responseText;
	}
}

// Ici on va voir comment faire du post
xhr.open("POST",page,true);
// ne pas oublier ça pour le post
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send(param);
}

function sendData(param, page, num)
{
var xhr = getXhr();

if (num==1) {
	var content = document.getElementById("liste1");
} else {   
	if (num==2) {
		var content = document.getElementById("liste2");
	} else {  
		if (num==3) {
			var content = document.getElementById("liste3");
		}
	}
}

// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
	// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
	if(xhr.readyState == 4 && xhr.status == 200){
		content.innerHTML = xhr.responseText;
	}
}

// Ici on va voir comment faire du post
xhr.open("POST",page,true);
// ne pas oublier ça pour le post
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send(param);
}
// Fin Recherche Ajax

// Recherche famille en fonction de la collection
function sendFamille(param, div)
{
var xhr = getXhr();
var content = document.getElementById(div);
// On défini ce qu'on va faire quand on aura la réponse
xhr.onreadystatechange = function(){
	// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
	if(xhr.readyState == 4 && xhr.status == 200){
		content.innerHTML = xhr.responseText;
	}
}

// Ici on va voir comment faire du post
xhr.open("POST","select-famille.php",true);
// ne pas oublier ça pour le post
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send(param);
}

// Fin recherche famille en fonction de la collection

// Gestion du sous menu visible ou non

function afficheCacheSousMenu(bloc)
{
	if (document.getElementById(bloc).style.visibility == 'hidden')
	{
		document.getElementById(bloc).style.visibility = 'visible';
		document.getElementById(bloc).style.display = 'block';
	}
	else
	{
		document.getElementById(bloc).style.visibility = 'hidden';
		document.getElementById(bloc).style.display = 'none';
	}
}
// Fin Gestion du sous menu visible ou non

function check_all(container_id)
{
	if (document.getElementById(container_id).select_all.checked == true) 
	{
		state = true;
	} else {
		state = false;
	}

	var checkboxes = document.getElementById(container_id).getElementsByTagName('input');

	for (var i=0;i<checkboxes.length;i++)
	{
		if ( (checkboxes[i].type == 'checkbox') && (checkboxes[i].name != 'select_all') )
		{
			checkboxes[i].checked = state;
		}
	}
}

function verif_check(container_id)
{
	var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
	var vrai;
	vrai = 0;
	for (var i=0;i<checkboxes.length;i++)
	{
		if ( (checkboxes[i].type == 'checkbox') && (checkboxes[i].checked == true) ) 
		{
			vrai = 1;
			break;
		}
	}
	if (vrai == 1) supprimer();
}

function supprimer()
{
	var reponse;

	reponse = confirm ("Vous allez supprimer ce produit de votre panier. Confirmez-vous ?");
	if (reponse != true) return;
	document.getElementById('panier').submit();
}

function supprimerTout()
{
	var reponse;

	reponse = confirm ("Vous allez supprimer tous les produits de votre panier. Confirmez-vous ?");
	if (reponse != true) return;
	document.getElementById('panier').submit();
}

var vis=false; // La variable i nous dit si la bulle est visible ou non

function move(e) {
  if(vis) {  // Si la bulle est visible, on calcul en temps reel sa position ideale
	if (navigator.appName!="Microsoft Internet Explorer") { // Si on est pas sous IE
	document.getElementById("curseur").style.left=e.pageX + 10+"px";
	document.getElementById("curseur").style.top=e.pageY + 0+"px";
	}
	else { // Modif proposé par TeDeum, merci à lui
	if(document.documentElement.clientWidth>0) {
		document.getElementById("curseur").style.left=20+event.x+document.documentElement.scrollLeft+"px";
		document.getElementById("curseur").style.top=10+event.y+document.documentElement.scrollTop+"px";
	}
	else {
		document.getElementById("curseur").style.left=20+event.x+document.body.scrollLeft+"px";
		document.getElementById("curseur").style.top=10+event.y+document.body.scrollTop+"px";
	}
	}
  }
}

function montre_2(t) {
  var ch;
  if(vis==false) {
  ch = t;
  document.getElementById("curseur").style.visibility="visible"; // Si il est cacher (la verif n'est qu'une securité) on le rend visible.
  document.getElementById("curseur").innerHTML = ch; // Cette fonction est a améliorer, il parait qu'elle n'est pas valide (mais elle marche)
  vis=true;
  }
}

function montre(ref_lm, ref_or) {
  var ch;
  var ch2;
  if(vis==false) {
  ch2 = ref_lm.substring(0,5);
  ch = '<img src="../produits/'+ch2+'/'+ref_lm+'_small" border="0" alt="" /><br /><span style="text-align:center">'+ref_or+'</span>';
  document.getElementById("curseur").style.visibility="visible"; // Si il est cacher (la verif n'est qu'une securité) on le rend visible.
  document.getElementById("curseur").innerHTML = ch; // Cette fonction est a améliorer, il parait qu'elle n'est pas valide (mais elle marche)
  vis=true;
  }
}
function cache() {
if(vis==true) {
document.getElementById("curseur").style.visibility="hidden"; // Si la bulle etais visible on la cache
vis=false;
}
}
document.onmousemove=move; // des que la souris bouge, on appelle la fonction move pour mettre a jour la position de la bulle.

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function refresh_card(lp, mod, id)
{
	var qte;
	var	qte_nb;
	var	price;
	var	tprice;
	var	price_nb;
	var	tprice_nb;
	var	line;

	qte = document.getElementById('qte' + lp);
	qte_nb = qte.innerHTML;
	if (mod == 0)
		qte_nb++;
	else
	{
		qte_nb--;
		if (qte_nb == 0)
		{
			line = document.getElementById('item'+id);
			line.style.display = 'none';
		}
	}
	qte.innerHTML = qte_nb;
	price = document.getElementById('price' + lp);
	tprice = document.getElementById('tprice' + lp);
	price_nb = price.innerHTML;
	tprice_nb = qte_nb * price_nb;
	tprice.innerHTML = convert_price(tprice_nb);
	ttprice = document.getElementById('total_price');
	ttprice_nb = ttprice.innerHTML;
	if (mod == 0)
		ttprice_nb = parseFloat(ttprice_nb) + parseFloat(price_nb);
	else
		ttprice_nb = parseFloat(ttprice_nb) - parseFloat(price_nb);

	ttprice.innerHTML = convert_price(ttprice_nb);
}

function maxus_minus_cart (item, mode, lp, id)
{
	var test;

	if (mode != 'add')
	{
		test = document.getElementById('qte' + lp);
		if (test.innerHTML - 1 == 0)
			if (!(confirm("Vous êtes sur le point de supprimer ce produit du panier. En êtes-vous sûr ?")))
				return  ;
	}
	if (mode == 'add')
		addToCart(item);
	else
		subToCart(item);
	refresh_card(lp, (mode == 'add' ? 0 : 1), id);
}

function convert_price(price)
{
	price = (String) (price);
	price = price.valueOf();
	pos = price.indexOf('.');
	if (pos == -1)
		return (price + '.00');
	len = price.length;
	if (len - pos == 1)
		return (price + '00');
	else if (len - pos == 2)
		return (price + '0');
	else if (len - pos == 3)
		return (price);
	return (price.substr(0, pos + 2));
}

function c(static_relative)
{
	var mode;

	if (static_relative == 0)
		mode = 'static';
	else
		mode = 'relative';
	document.getElementById('content_produit').style.position = mode;
}

// Afficher les articles dans le panier
function loadCart()
{
	loadXMLDoc("panier_recherche.php");
}

// ajouter un article dans le panier
function addToCart(id)
{
	loadXMLDoc("panier_action.php?action=addToCart&id="+id);
}

//En enlever 1
function subToCart(id)
{
	loadXMLDoc("panier_action.php?action=subToCart&id="+id);
}

// supprimer un article dans le panier
function removeFromCart(id)
{
	loadXMLDoc("panier_action.php?action=removeFromCart&id="+id);
}

// Annuler le panier
function emptyCart()
{
	loadXMLDoc("panier_action.php?action=emptyCart");
}

//fonction pour traiter le fichier XML retourné par le serveur
function xmltraitement(monxml) {

	var vide = monxml.getElementsByTagName('err');     //Si aucun article
	var	add = monxml.getElementsByTagName('add');
	var langue;
	langue = 1;
	langue = monxml.getElementsByTagName('langue')[0].firstChild.data;
	if (vide.length>0)
	{
		if (langue==1) document.getElementById('cartItems').innerHTML = 'Votre panier est vide';
		if (langue==2) document.getElementById('cartItems').innerHTML = 'Your cart is empty';
		if (langue==3) document.getElementById('cartItems').innerHTML = 'La cesta está vacía';
		document.getElementById('shopcart_picture').src="./images/basket_go.png";
	}
	else
	{
		var fichiers = monxml.getElementsByTagName('item');
		var items="";
		var txt="";
		var total = 0;
		var	total_price = 0.0;

		for(var i = 0; i < fichiers.length; i++) {

			var id = fichiers[i].getElementsByTagName('id')[0].firstChild.data;
			var title = fichiers[i].getElementsByTagName('titre')[0].firstChild.data;
			var newQty = fichiers[i].getElementsByTagName('qty')[0].firstChild.data;
			var prix = fichiers[i].getElementsByTagName('prix')[0].firstChild.data;
			langue = fichiers[i].getElementsByTagName('langue')[0].firstChild.data;
			var sous_total=(Math.round((newQty*prix) * 100) / 100);
			total += sous_total;
		}
		if(fichiers.length>1)
		{
			if (langue==1) txt = 'articles';
			if (langue==2) txt = 'items';
			if (langue==3) txt = 'artículos';
		}
		else
		{
			if (langue==1) txt = 'article';
			if (langue==2) txt = 'item';
			if (langue==3) txt = 'artículo';
		}
		total_price = convert_price(total);

		if (langue==1)  document.getElementById('cartItems').innerHTML = '<a href="page/commande.html">' +fichiers.length+' '+txt + '</a> = ' + total_price + ' &euro;';
		if (langue==2)  document.getElementById('cartItems').innerHTML = '<a href="page/commande.html">' +fichiers.length+' '+txt + '</a> = ' + total_price + ' &euro;';
		if (langue==3)  document.getElementById('cartItems').innerHTML = '<a href="page/commande.html">' + fichiers.length + ' ' + txt + '</a> = ' + total_price + ' &euro;';
		document.getElementById('shopcart_picture').src="./images/basket_go_vert.png";
	}
	if (add.length > 0)
	{
		hs.htmlExpand(document.getElementById('secret_link'), {contentId: 'lmk_hs'});
	}
}

//Fonction qui ouvre les pdf dans une nouvelle fenêtre
function openPDF(form_id, page, type) {
	var checkboxes = document.getElementById(form_id).getElementsByTagName('input');
	var ids = '';
	for (var i=0; i<checkboxes.length; i++) {
		if ((checkboxes[i].type == 'checkbox') && (checkboxes[i].checked == true) && (checkboxes[i].value != '')) {
			ids += checkboxes[i].value+';';
		}
	}
	ids = ids.substr(0, (ids.length-1));
	window.open("../pdf/"+page+"-pdf.php?id="+ids+"&amp;type="+type, "", "directories=yes,location=yes,menubar=yes,resizable=yes,status=yes,toolbar=yes");
}
