	var http;
	var NET = (navigator.userAgent.indexOf("Netscape")>-1) ? 1 : 0;
	var FF = (navigator.userAgent.indexOf("Firefox")>-1) ? 1 : 0;
	var SF = (navigator.userAgent.indexOf("Safari")>-1) ? 1 : 0;
	var IE6 = (navigator.userAgent.indexOf("MSIE 6")>-1) ? 1 : 0;
	var IE7 = (navigator.userAgent.indexOf("MSIE 7")>-1) ? 1 : 0;
	
	function trim(string)
	{
		return string.replace(/(^\s*)|(\s*$)/g,'');
	} 

	function getAbsoluteLeft(oNode){
		// Fonction prise chez microsoft pour ie
		if (IE6 || IE7) {
			var oCurrentNode=oNode;
		   	var iLeft=0;
		   	while(oCurrentNode.tagName!="BODY"){
		    	iLeft+=oCurrentNode.offsetLeft;
		    	oCurrentNode=oCurrentNode.offsetParent;
		  	}
		  	return iLeft;
		} 
		else return oNode.offsetLeft;
	}

	function getAbsoluteTop(oNode){
		// Fonction prise chez microsoft pour ie
		if (IE6 || IE7) {
			var oCurrentNode=oNode;
			var iTop=0;
			while(oCurrentNode.tagName!="BODY"){
		    	iTop+=oCurrentNode.offsetTop;
		    	oCurrentNode=oCurrentNode.offsetParent;
			}
		  	return iTop;
		}
		else return oNode.offsetTop;
	}
		
	function urldecode(chaine) {
	  var regex = /\+/g;
	  var regex2 = /\\'/g;
	  var regex3 = /\\\"/g;
	  var tmp = unescape(String(chaine).replace(regex, " "));
	  tmp = String(tmp).replace(regex2, "'");
	  return String(tmp).replace(regex3, "\"");
	}
	
	function journuit(item) {
		if (document.getElementById('ul'+item).style.display=='none') {
			document.getElementById('ul'+item).style.display='block';
			document.getElementById('img'+item).src = "admin/img_admin/puces/moins.png";
		}
		else {
			document.getElementById('ul'+item).style.display='none';
			document.getElementById('img'+item).src = "admin/img_admin/puces/plus.png";
		}
	}
	
	function getHTTPObject() {
	  var xmlhttp;
	  // Pour IE
	  /*@cc_on
	  @if (@_jscript_version >= 5)
	    try {
	      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	      } catch (e) {
	      try {
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	        } catch (E) {
	        xmlhttp = false;
	        }
	      }
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	  	try {
	    	xmlhttp = new XMLHttpRequest();
	      	if (xmlhttp.overrideMimeType) {
    			 xmlhttp.overrideMimeType("text/xml");
   			}
	    } catch (e) {
	    	xmlhttp = false;
	    }
	  }
	  return xmlhttp;
	}
	var http = getHTTPObject();
	
	var img = document.createElement('img');
	var animEncours = false;
	
	function animePanier(idProduit, destX, destY, x, y) {
		if (y>destY) y-=10;
		if (x>destX) x-=10;
		if (y<destY+20) img.style.zIndex = '-1';
		img.style.top = y+'px';
		img.style.left = x+'px';
		if (IE7 || IE6) img.style.filter = 'alpha(opacity='+(y-destY)+');';
		else img.style.opacity = (y-destY)/100;
		if (x>destX || y>destY) window.setTimeout("animePanier("+idProduit+", "+destX+", "+destY+", "+x+", "+y+")", 1);
		else {
			document.getElementById('container').removeChild(img);
			animEncours = false;
		}
	}	
	
	function ajouterPanier(idProduit) {
		var imgOrigine;
		var qte=1;
		if (document.getElementById('imgPdt'+idProduit)) {
			animEncours = true;
			document.getElementById('container').appendChild(img);
			imgOrigine = document.getElementById('imgPdt'+idProduit);
			img.src = imgOrigine.src;
			img.style.zIndex = '500';
			img.style.position = 'absolute';
			img.style.top = imgOrigine.style.top;
			img.style.left = imgOrigine.style.left;
			
			if (IE7 || IE6) img.style.filter = 'alpha(opacity=50);';
			else img.style.opacity = 0.5;
			
			destX = getAbsoluteLeft(document.getElementById('panierResume')) + 10;
			destY = getAbsoluteTop(document.getElementById('panierResume'));			
	
			animePanier(idProduit, destX, destY,  getAbsoluteLeft(imgOrigine), getAbsoluteTop(imgOrigine));
		}
		
	 	if (typeof http != 'undefined') {
	 		if (document.getElementById('txtQuantite')) qte = document.getElementById('txtQuantite').value;
	  		http.open("GET", racine+'index.php?idR='+idR+'&action=16&actionAjax=1&idProduit=' + idProduit + '&qte=' + qte, true);
	  		http.onreadystatechange = afficheReponse;
	  		http.send(null);
	  	}
	  	else return false;
	}
	
	function alertPanier(message) {
		if (animEncours) window.setTimeout("alertPanier('"+message+"')",1);
		else alert(message);
	}
	
	
	function afficheReponse() {
		var resume;
		if (http.readyState == 4) {
			var xml;	
			if (http.status == 200) {
				xml = http.responseXML;
				if (IE6)
					resume = xml.getElementsByTagName('resume')[0].firstChild.nodeValue;
				else
					resume = xml.getElementsByTagName('resume').item(0).firstChild.nodeValue;
					
				if (resume) {
					document.getElementById('panierResume').innerHTML = resume;
					if (IE6) {
						alertPanier(trim(xml.getElementsByTagName('message')[0].firstChild.nodeValue));
					}
					else {
						alertPanier(trim(xml.getElementsByTagName('message').item(0).firstChild.nodeValue));					
					}
				}
				else {
					alertPanier("Il y a eu un problème lors de l'ajout du produit");
				}
				//dest.innerHTML = xml.getElementsByTagName('quantite').item(0).firstChild.nodeValue;
           }
		}
	}
		
	function afficherLivraison() {
		document.getElementById('adresseLivraison').style.display = 'block';
	}

	function cacherLivraison() {
		document.getElementById('adresseLivraison').style.display = 'none';
	}
	
	function supprimerProduit(idProduit) {
		if (confirm('Etes-vous sûr de vouloir supprimer ce produit ?')) document.location.href = pageBoutique+'&action=4&idProduit='+idProduit;
	}
	
	function selectRubrique(id) {
		document.location.href = pageBoutique+'&action=&idCB='+id;
	}
	
	function viderPanier() {
		if (confirm('Etes-vous sûr de vouloir vider le panier ?')) document.location.href = pageBoutique+'&action=8';
	}
	
	function validerFormulaire(submit) {
		var msg = '';
		var tErreur = new Array();
		var frm = document.formClient;
		
		if (frm.txtNom.value=='') {
		 msg += 'Le champ Nom est obligatoire\n';
		 tErreur.push('txtNom');
		}
		if (frm.txtPrenom.value=='') {
		 msg += 'Le champ Prénom est obligatoire\n';
		 tErreur.push('txtPrenom');
		}
		if (!frm.radCivilite[2].checked && !frm.radCivilite[1].checked && !frm.radCivilite[0].checked) {
		 msg += 'Le champ Civilité est obligatoire\n';
		 tErreur.push('radCivilite');
		}
		if (frm.txtEmail.value=='') {
		 msg += 'Le champ Email est obligatoire\n';
		 tErreur.push('txtEmail1');
		}
		if (frm.txtId.value=='') {
			if (frm.txtPassword.value=='') {
			 msg += 'Le champ Mot de passe est obligatoire\n';
			 tErreur.push('txtPassword1');
			}
			if (frm.txtPassword2.value=='') {
			 msg += 'Le champ Mot de passe pour vérification est obligatoire\n';
			 tErreur.push('txtPassword2');
			}
		}
		if (frm.txtPassword2.value!=frm.txtPassword.value) {
		 msg += 'Les 2 mots de passe ne concordent pas.\n';
		 tErreur.push('txtPassword1', 'txtPassword2');
		}
		if (frm.txtAdresse.value=='') {
		 msg += 'Le champ Adresse est obligatoire\n';
		 tErreur.push('txtAdresse');
		}
		if (frm.txtCp.value=='') {
		 msg += 'Le champ Code Postal est obligatoire\n';
		 tErreur.push('txtCp');
		}
		if (frm.txtVille.value=='') {
		 msg += 'Le champ Ville est obligatoire\n';
		 tErreur.push('txtVille');
		}
		if ((frm.cbbPays.value==0)||(frm.cbbPays.value==-1)) {
		 msg += 'Le champ Pays est obligatoire\n';
		 tErreur.push('cbbPays');
		}
		
		if (frm.radLivraison[0].checked) {
			if (frm.txtNomLiv.value=='') {
			 msg += 'Le champ Nom est obligatoire\n';
			 tErreur.push('txtNomLiv');
			}
			if (frm.txtPrenomLiv.value=='') {
			 msg += 'Le champ Prénom est obligatoire\n';
			 tErreur.push('txtPrenomLiv');
			}
			if (frm.radLivraison.length==0) {
			 msg += 'Le champ Civilité est obligatoire\n';
			 tErreur.push('radCiviliteLiv');
			}
			if (frm.txtAdresseLiv.value=='') {
			 msg += 'Le champ Adresse est obligatoire\n';
			 tErreur.push('txtAdresseLiv');
			}
			if (frm.txtCpLiv.value=='') {
			 msg += 'Le champ Code Postal est obligatoire\n';
			 tErreur.push('txtCpLiv');
			}
			if (frm.txtVilleLiv.value=='') {
			 msg += 'Le champ Ville est obligatoire\n';
			 tErreur.push('txtVilleLiv');
			}
			if ((frm.cbbPays.value==0)||(frm.cbbPays.value==-1)) {
			 msg += 'Le champ Pays est obligatoire\n';
			 tErreur.push('cbbPaysLiv');
			}			
		}
		
		if (msg!='') {
			for (var i=0; i<tErreur.length; i++) {
				document.getElementById(tErreur[i]).style.border = '2px solid red';
			}
			alert(msg);
		}
		else if(submit) frm.submit();
	}
	
	function enregistrerPanier() {
		if (http.readyState == 4) {
			if (http.status == 200) {
				var text = http.responseText;
				alert (text);
           }
		}
		document.formPaiement.submit();
	}
	
	function gopaiement() {
		var frm = document.formPaiement;
		var error=0;
		var nbPaiement = 0;
		
		if ((GetE('txtLivraison').value == '')||(!GetE('radLivraison').checked)) {
			 alert('Vous devez choisir un mode de livraison');
			 error=1;
		}
		
		if (GetE('radPaiement1') && GetE('radPaiement1').checked) {
			nbPaiement++;
		}
	
		if (GetE('radPaiement2') && GetE('radPaiement2').checked) {
			nbPaiement++;
		}
	
		if (GetE('radPaiement3') && GetE('radPaiement3').checked) {
			nbPaiement++;
		}
	
		if (nbPaiement==0) {
			 alert('Vous devez choisir un moyen de paiement');
			 error=1;
		}
		if (!GetE('chkCGV').checked) {
			 alert('Vous devez accepter les conditions générales de vente');
			 error=1;
		}	
		if (error==0) {
			if (!confirm('Attention, si vous procédez au paiement il vous sera impossible de revenir en arrière pour ajouter ou supprimer un article.')) {
				error=1;
			}
		}
				
		if (error==0) {
//			if (confirm('Voulez-vous enregistrer le panier avant de procéder au paiement ?')) {
//				enregistrementPanier = true;
//		  		http.open("GET", 'index.php?action=16&actionAjax=2', true);
//		  		http.onreadystatechange = enregistrerPanier;
//		  		http.send(null);
//			}
//			else 
			frm.submit();
		}
	}