// creer l'instanciation de l'objet XHR qu'inporte le navigateur
function getXMLHttpRequest() {
	var xhr = null;
	
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			var tableau_xhr_activeX = [
				'Msxml2.XMLHTTP.6.0',
				'Msxml2.XMLHTTP.3.0',
				'Msxml2.XMLHTTP',
				'Microsoft.XMLHTTP'
			];
			
			for (var value in tableau_xhr_activeX) {
				try { 
					xhr = new ActiveXObject(tableau_xhr_activeX[value]); 
					break;
				} catch(error) {};
			};
			
		} else {
			xhr = new XMLHttpRequest();
		};
		
	} else {
		// alert('Votre navigateur ne supporte pas l\'objet XmlHTTPRequest, permetant l\'utilisation d'ajax.');
		return null;
	};
	return xhr;
};

// Permet le non rafraichissement d'une page en exploitant l'objet XHR
////////ajax_file////////
function ajax_file(fichier) {
	 if(window.XMLHttpRequest) // FIREFOX-
		  xhr_object = new XMLHttpRequest();
	 else if(window.ActiveXObject) // IE
		  xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	 else 
		  return(false);
	 xhr_object.open("GET", fichier, false);
	 xhr_object.send(null);
	 if(xhr_object.readyState == 4) return(xhr_object.responseText);
	 else return(false);
}

// Affichage du bloc qui gère le numero de retour
function showNumRetourEtiquette(idOrder, multiTransp, parentPath, idOrderTransp, idTransporteur) {

	// ELEMENT DU DIV POPUP
	var numDIVObjet = document.getElementById('popup_numero_retour');
	
	//Test pour vérifier si il s'agit d'une commande multitransporteur
	if(multiTransp == 1){
		var numObjet = document.getElementById('num_retourDIV_' + idTransporteur);
		var divPrintPdfObjet = document.getElementById('printPdf_' + idTransporteur);
	}
	else{
		var divPrintPdfObjet = document.getElementById('printPdf');
		var numObjet = document.getElementById('num_retourDIV');
	}
	var numDiv_coli = document.getElementById('colissimo');
	var numDiv_mory = document.getElementById('mory');
	
	// ELEMENT DU BLOC DANS LE DETAIL
	if(multiTransp == 1){
		var divCreateNumRetourObjet = document.getElementById('createNumRetour_' + idTransporteur);
		var numRetourObjet			= document.getElementById('num_retour_' + idTransporteur);
	}else{
		var divCreateNumRetourObjet = document.getElementById('createNumRetour');
		var numRetourObjet			= document.getElementById('num_retour');
	}

	var numRetour = ''; 
	switch (idTransporteur){
		case 1:
			if( numDiv_coli ) numDiv_coli.style.display = 'block';
			if( numDiv_mory ) numDiv_mory.style.display = 'none';
			break;
		case 2:
			if( numDiv_coli ) numDiv_coli.style.display = 'none';
			if( numDiv_mory ) numDiv_mory.style.display = 'block';
			break;
	}
	
	// expression régulière qui servira au decoupage de la reponse
	if( typeof(idOrderTransp) != 'undefined' )
		var numRetour = ajax_file( parentPath + 'ajax_num_etiquette.php?idOrder=' + idOrder + '&multiTransp=' + multiTransp + '&idOrderTransp=' + idOrderTransp);
	else
		var numRetour = ajax_file( parentPath + 'ajax_num_etiquette.php?idOrder=' + idOrder + '&multiTransp=' + multiTransp);

	// Securité : la commande n'appartient pas au client connecté
	if (numRetour!='false'){
		
		numDIVObjet.style.display = 'block';
		numObjet.innerHTML = numRetour;
		
		numRetourObjet.innerHTML = numRetour;				
		divCreateNumRetourObjet.style.display = 'none';
		divPrintPdfObjet.style.display = 'block';
		
		document.getElementById('shad').style.display = 'block';
	}
}

function createEtiquetteRetour(idOrder, parentPath, multiTransp){
	//Test pour vérifier si il s'agit d'une commande multitransporteur
	if(multiTransp == 1){
		var choixRetourDivObjet = document.getElementById('choixRetourDiv_');
		var choixRetourObjet = document.getElementById('choixRetour_');
	}else{
		var choixRetourDivObjet = document.getElementById('choixRetourDiv');
		var choixRetourObjet = document.getElementById('choixRetour');
	}
	var choix = 0;
	
	if (choixRetourObjet.value != '0')
		choix = choixRetourObjet.value;
	else
		choix = choixRetourDivObjet.value;
	
	switch (choix){
		case '1':
			var txtRaison = 'Droits de rétractation';
			break;
		case '2':
			var txtRaison = 'Article non conforme à la commande';
			break;
		case '3':
			var txtRaison = 'Article Cassé / Défectueux';
			break;
		case '4':
			var txtRaison = 'Problème de Taille / Qualité';
			break;	
		case '5':
			var txtRaison = 'Autres';		
			break;
	}
	
	var response = ajax_file( parentPath + 'ajax_create_etiquette.php?idOrder=' + idOrder + '&choix=' + txtRaison + '&numChoix=' + choix +'&multiTransp=' + multiTransp);
	if(response){

		var listeRaisonBlocObjet = document.getElementById('liste_motif_retour');
		var btnPrintPdfBlocObjet = document.getElementById('btnPrintPdf');
		
		
		if(txtRaison == "Autres"){
			listeRaisonBlocObjet.innerHTML = '<u>Raison du retour</u> : ' + txtRaison + '<input type="hidden" id="choixRetour" value="'+choix+'">';
		}
		else
		{
			listeRaisonBlocObjet.innerHTML = txtRaison + '<input type="hidden" id="choixRetour" value="'+choix+'">';
		}
		
		btnPrintPdfBlocObjet.style.display = 'block';
		
		document.getElementById('shad').style.display = 'none';
		document.getElementById('popup_numero_retour').style.display = 'none';

		window.open(response);		
	}

}

// Affiche la liste des sous categories d'un produit
function showSousCategOptionListe(objCateg, objSousCategId, objetId, idSousCateg ) {

	var optionSousCateg = document.getElementById(objSousCategId);
	var optionObjet = document.getElementById(objetId);

	if ( objCateg.value != 'non_attribue' ){

			
		var response = ajax_file('../ajax/ajax_sousCateg_optionliste.php?idCateg=' + objCateg.value 
								 + '&index=' + objSousCategId.split('_')[1] + '&idSousCateg=' + idSousCateg);
		
		optionSousCateg.style.display = 'block';
		optionObjet.style.display = 'none';
		if (response == '') { optionSousCateg.innerHTML = ''; optionObjet.innerHTML = ''; }
		else { optionSousCateg.innerHTML = response; optionObjet.innerHTML = ''; }
	
	}else{
		optionSousCateg.innerHTML = '';
		optionObjet.innerHTML = '';
	}
}
// --------------------------------------------------------------------------------

// Affiche la liste des objets d'un produit
function showObjetOptionListe(objSousCateg,objetId, idObjet) {
	var optionObjet = document.getElementById(objetId);
	var response = ajax_file('../ajax/ajax_objet_optionliste.php?idSousCateg=' + objSousCateg.value 
							 + '&index=' + objetId.split('_')[1] + '&idObjet=' + idObjet);
	optionObjet.style.display = 'block';
	if (response)
		optionObjet.innerHTML = response;
	else
		optionObjet.innerHTML = '';	
		
}
// --------------------------------------------------------------------------------

// Affiche la liste des auantites d'un produit (HTML Tag select)
function showQteListe(elementID, idProduit,parentPath) {
	var listQte = document.getElementById(elementID);
	var alternative_listQte = document.getElementById('liste_qte_spe');
	if (listQte || alternative_listQte) {
	
		if(listQte){
			
			listQte.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" style="padding-left:10px;"><tr><td style="font-size:11px;"><img src="' + parentPath + 'img/sablier.gif" />Chargement...</td></tr></table>';
			
			if(document.getElementById('couleurProd')) var couleurs = document.getElementById('couleurProd');
			else var couleurs = 'none';
			
			if(document.getElementById('tailleProd')) var tailles = document.getElementById('tailleProd');
			else var tailles = 'none';
			
		}
		else{
			var couleurs = 'none';
			var tailles = 'none';
			alternative_listQte.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" style="padding-left:10px;"><tr><td style="font-size:11px;"><img src="' + parentPath + 'img/sablier.gif" />Chargement...</td></tr></table>';
		}
	
		//if (couleurs.value != "" && tailles.value != "") {
			var response = ajax_file(parentPath + 'ajax_liste_qte.php?idprod=' + idProduit + '&idcouleur=' + couleurs.value + '&idtaille=' + tailles.value);
			if (response){
				if(listQte) listQte.innerHTML = response;
				else alternative_listQte.innerHTML = response;
			}	
		//}
		//else
//			listQte.innerHTML = '';
	}
}

function showQteListeGamme(elementID, idProduit,parentPath) {
	var listQte = document.getElementById(elementID);
	var alternative_listQte = document.getElementById('liste_qte_spe_'+idProduit);
	if (listQte || alternative_listQte) {
	//alert('qteProd_'+idProduit);
		if(listQte){
			if(document.getElementById('couleurProd_'+idProduit)) var couleurs = document.getElementById('couleurProd_'+idProduit).value;
			if(document.getElementById('tailleProd_'+idProduit)) var tailles = document.getElementById('tailleProd_'+idProduit).value;
			listQte.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" style="padding-left:10px;"><tr><td style="font-size:11px;"><img src="' + parentPath + 'img/sablier.gif" />Chargement...</td></tr></table>';
		}
		else{
			var couleurs = 'none';
			var tailles = 'none';
			alternative_listQte.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" style="padding-left:10px;"><tr><td style="font-size:11px;"><img src="' + parentPath + 'img/sablier.gif" />Chargement...</td></tr></table>';
		}
	
		//if (couleurs.value != "" && tailles.value != "") {
			var response = ajax_file(parentPath + 'ajax_liste_qte_alerte.php?idprod=' + idProduit + '&idcouleur=' + couleurs + '&idtaille=' + tailles);
			if (response){
				if(listQte) listQte.innerHTML = response;
				else alternative_listQte.innerHTML = response;
			}	
		//}
		//else
//			listQte.innerHTML = '';
	}
}

// Verifie si le produit ou la commande existe
function verif_base(elementID, val, parentPath) {
	var mess = document.getElementById(elementID);
	if (elementID=='mess_num_commande') var variable = 'numCommande';
	else var variable = 'refProduit';
	
	if (mess) {
		var response = ajax_file(parentPath + 'ajax_verif_contact.php?'+variable+'='+ val );
		if (response) {
			mess.innerHTML = response;
			var nom_label = document.getElementById('contactNomLabel');
			var td_img = document.getElementById('preview_tof');
			
			if(variable=='refProduit') {
				if(!document.getElementById('erreur')) {
					var img_name = document.getElementById("img_name").value;
					var img_rep = document.getElementById("dir").value;
					var img_type = document.getElementById("image_type").value;
					var td = document.createElement('td');
					td.setAttribute('id','preview_tof');
					if (document.all){
						td.style.setAttribute('cssText','padding-left:45px;');
						if(img_type=='vert') td.style.setAttribute('cssText','padding-left:45px;vertical-align:top;padding-top:7px;');
					}						
					else{
						td.setAttribute('style','padding-left:45px;');
						if(img_type=='vert') td.setAttribute('style','padding-left:45px;vertical-align:top;padding-top:7px;');
					}
					td.rowSpan=5;
					
					var img = document.createElement('img');
					var dest_img = img_rep+img_name+'.jpg';
					img.setAttribute('src', dest_img);
					img.setAttribute('id',img_name);
					
					if(img_type=='hor') img.setAttribute('class','cadre_photo_hor');
					else img.setAttribute('class','cadre_photo_vert');
					
					td.appendChild(img);
					if(!td_img) nom_label.parentNode.parentNode.appendChild(td);
				}
				else 
				{
					var nom_label = document.getElementById('contactNomLabel');
					if(td_img) nom_label.parentNode.parentNode.removeChild(td_img);
				}
			}
		}
		else mess.innerHTML = "";
	}
}

function showQteListeAssoc(elementID, idProduit, parentPath) {
	
	var listQte = document.getElementById(elementID);
	var alternative_listQte = document.getElementById('liste_qte_spe_'+idProduit);
	listQte.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" style="padding-left:10px;"><tr><td style="font-size:11px;"><img src="' + parentPath + 'img/sablier.gif" />Chargement...</td></tr></table>';
	var couleurs = document.getElementById('couleurProdAssoc_'+idProduit);
	var tailles = document.getElementById('tailleProdAssoc_'+idProduit);
	if (listQte || alternative_listQte) {
	
		if(listQte){
			var couleurs = document.getElementById('couleurProd_'+idProduit).value;
			var tailles = document.getElementById('tailleProd_'+idProduit).value;
			listQte.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" style="padding-left:10px;"><tr><td style="font-size:11px;"><img src="' + parentPath + 'img/sablier.gif" />Chargement...</td></tr></table>';
		}
		else{
			var couleurs = 'none';
			var tailles = 'none';
			alternative_listQte.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" style="padding-left:10px;"><tr><td style="font-size:11px;"><img src="' + parentPath + 'img/sablier.gif" />Chargement...</td></tr></table>';
		}
	
		//if (couleurs.value != "" && tailles.value != "") {
			var response = ajax_file(parentPath + 'ajax_liste_qte_alerte.php?idprod=' + idProduit + '&idcouleur=' + couleurs.value + '&idtaille=' + tailles.value);
			if (response) {
				// On exécute deux fois car replace ne remplace qu'une seule fois alors que nous avons deux occurences
				response = response.replace( 'qteProd_', 'qteProdAssoc_' );
				response = response.replace( 'qteProd_', 'qteProdAssoc_' );
				if(listQte) listQte.innerHTML = response;
				else alternative_listQte.innerHTML = response;
				
			}
		//}
		//else
//			listQte.innerHTML = '';
	}
}

function showTailleListeGamme(elementID, idProduit,parentPath, tailleProd) {
	
	var eltaille = document.getElementById( elementID );
	
	if (eltaille) {
		var response = ajax_file(parentPath + 'ajax_liste_taille.php?idprod=' + idProduit + '&tailleprod = ' + tailleProd);
		if ( response ) {
			
			eltaille.innerHTML = response;
			//showQteListeGamme('liste_qte_<?php echo $produits->produit_id;?>', '<?php echo $produits->produit_id;?>', '');
			
		} else {
			
			//showQteListeGamme('liste_qte_<?php echo $produits->produit_id;?>', '<?php echo $produits->produit_id;?>', '');
			
		}
		
	}
		
}



function showTailleListeAssoc(elementID, idProduit, parentPath, tailleProd) {
	
	var eltaille = document.getElementById( elementID );
	
	if (eltaille) {
		var response = ajax_file(parentPath + 'ajax_liste_taille.php?idprod=' + idProduit + '&tailleprod = ' + tailleProd);
		
		if ( response ) {
			
			response = response.replace('tailleProd_', 'tailleProdAssoc_');
			response = response.replace('tailleProd_', 'tailleProdAssoc_');
			response = response.replace('liste_qte_', 'liste_qte_assoc_');
			response = response.replace('showQteListeGamme', 'showQteListeAssoc');
			eltaille.innerHTML = response;
			
			//showQteListeAssoc('liste_qte_assoc_<?php echo $produits->produit_id;?>', '<?php echo $produits->produit_id;?>', '');
			
		} else {
			
			//showQteListeAssoc('liste_qte_assoc_<?php echo $produits->produit_id;?>', '<?php echo $produits->produit_id;?>', '');
			
		}
	}
}


function checkStocksProduct() {
	var id_product_element = document.getElementById('produit_id');
	
	if (id_product_element) {
		var id_product = id_product_element.value;
		
		var response = ajax_file(parentPath + 'ajax/ajax_check_stock.php?id_product='+id_product);
		
		if (response && response < 1) {
			
			alert(ajax_file('ajax_sprintf.php?arg1=js_error_no_stock'));
			return false;
			
		}
		
		return true;
	}
}

// Classe les categories 
function ajax_classer(){
	var sortable1 = Sortable.serialize('list1');
	var sortable2 = Sortable.serialize('list2');
	//var sortable3 = Sortable.serialize('list3');
	
	
	
	//var response = ajax_file('ajax/ajax_classer_categ.php?' + sortable1 + '&' + sortable2 + '&' + sortable3);
	var response = ajax_file('ajax/ajax_classer_categ.php?' + sortable1 + '&' + sortable2);

	if (response){
		var message = document.getElementById('messFinish');
		message.style.display = "block";
		Effect.Pulsate(message);
	}

}
// --------------------------------------------------------------------------------

// Affiche la liste des auantites d'un produit (HTML Tag select)
function	showQteListePanier(elementID, idProduit, i, paniervirtuelId) {
	
	var listQtePanier = document.getElementById(elementID);
	
	var couleurs = document.getElementById('couleurProd'+i);
	var tailles = document.getElementById('tailleProd'+i);
	
	var idCouleur = 0;
	var idTaille = 0;
	
	if (couleurs) idCouleur = couleurs.value;
	if (tailles) idTaille = tailles.value;
	
	if (listQtePanier) {
			var response = ajax_file('ajax/ajax_liste_qte_panier.php?idprod=' + idProduit + '&idcouleur=' + idCouleur + '&idtaille=' + idTaille + '&i=' + i + '&panierId=' + paniervirtuelId );
			if (response)
				listQtePanier.innerHTML = response;
	}
}

function updatePanier(idProduit, i, paniervirtuelId){
	var couleurs = document.getElementById('couleurProd'+i);
	var tailles = document.getElementById('tailleProd'+i);
	var qte = document.getElementById('ProdQte'+i);

	var idCouleur = 0;
	var idTaille = 0;
	
	if (couleurs) idCouleur = couleurs.value;
	if (tailles) idTaille = tailles.value;
	

	ajax_file('ajax/ajax_upd_panier.php?idprod=' + idProduit + '&idcouleur=' + idCouleur + '&idtaille=' + idTaille + '&qte=' + qte.value + '&panierId=' + paniervirtuelId);
}

function newUpdatePanier(idProduit, i, paniervirtuelId, prixU, isAssoc, path_web, titreObjet, idElTaille, lastTaille, idElCouleur, lastCouleur, idQte){
	
	if (i != '') {
		
		
		if (isAssoc == true) {
		
			i = 'Assoc_'+i;
				
		} else {
			
			i = '_'+i;
			
		}
		
		prixU = document.getElementById('prixU'+i).value;
		
	}
	

	
	var couleurs = document.getElementById('couleurProd'+i);
	var tailles = document.getElementById('tailleProd'+i);
	
	if(tailles && tailles.value == '') {
		
		alert(ajax_file(path_web+'ajax_sprintf.php?arg1=js_error_size'));
		return false;
		
	} else if(couleurs && couleurs.value == '') {
		
		alert(ajax_file(path_web+'ajax_sprintf.php?arg1=js_error_couleur'));
		return false;
		
	} else if (document.getElementById('qteProd'+i) && document.getElementById('qteProd'+i).value == '') {
		
		alert(ajax_file(path_web+'ajax_sprintf.php?arg1=js_error_quantity'));
		return false;
		
	} else {
		
		var qte = 0;
		
		if (document.getElementById('qteProd'+i)) {
			
			qte = document.getElementById('qteProd'+i).value;
			
		}
		
		var idCouleur = 0;
		var idTaille = 0;
		
		if (couleurs) idCouleur = couleurs.value;
		if (tailles) idTaille = tailles.value;
		
		var array_response = new Array();
		var response = ajax_file(path_web+'ajax_upd_panier.php?prixu=' + prixU + '&idprod=' + idProduit + '&idcouleur=' + idCouleur + '&idtaille=' + idTaille + '&qte=' + qte + '&panierId=' + paniervirtuelId);
	
		if (response) {
			
			array_response = response.split("//");
			
			var designation = array_response[0];
			
			if ( titreObjet.match('^[0-9]') ) {
			
				if ( designation == 1 ) {
				
					designation += ' lot de';
					
				} else {
					
					designation += ' lots de';
					
				}
				
			}
			
			designation += ' ' + titreObjet;
			
			if ( document.getElementById(idElTaille) ) {
				
				if ( document.getElementById(idElTaille).selectedIndex ) {
					
					//designation += ' - ' + document.getElementById(idElCouleur).text; // ne fonctionne pas
					designation += ' - Taille ' + document.getElementById(idElTaille).options[document.getElementById(idElTaille).selectedIndex].text;
					
					
				} else if ( lastTaille != '' ) {
					
					designation += ' - Taille ' + lastTaille;
					
				}
				
			}
			
			if ( document.getElementById(idElCouleur) ) {
				
				if ( document.getElementById(idElCouleur).selectedIndex ) {
				
					//designation += ' - ' + document.getElementById(idElCouleur).text; // ne fonctionne pas
					designation += ' - ' + document.getElementById(idElCouleur).options[document.getElementById(idElCouleur).selectedIndex].text;
					
				} else if ( lastCouleur != '' ) {
				
					designation += ' - ' + lastCouleur;
					
				}
				
			}
			
			array_response[0] = designation;
			
		}
		
		return array_response;
	}
}

function	showMontanTotalProduit(elementID, i){
	var montantProduit = document.getElementById(elementID);
	qte = document.getElementById("ProdQte"+i);
	prix = document.getElementById("prixProd"+i);
	
	var response = ajax_file('ajax/ajax_montant_total_produit.php?qte=' + qte.value + '&prix=' + prix.value );
	
	if (response)
				montantProduit.innerHTML = response;
}

function showMontanTotalPanier(elementID){
		var montantTotalPanier = document.getElementById(elementID);
		var response = ajax_file('ajax/ajax_montant_total_panier.php');
		
		if (response)
				montantTotalPanier.innerHTML = response;
		
}
//Affiche la liste des questions appropriées au service demandé
function show_question(elementID, fieldID, idService, parentPath) {
	var list_question = document.getElementById(elementID);
	clearTimeout(time_out);
	var field = document.getElementById(fieldID);
	if (list_question) {
		var response = ajax_file(parentPath + 'ajax_list_question.php?idService=' + idService);
		if (response) {
			list_question.innerHTML = response;
			field.innerHTML = "";
		}
	}
}

// Affiche les champs appropriées au service et à la question demandé
function show_fields(elementID, idService, idQuestion, parentPath) {
	
	var list_field = document.getElementById(elementID);
	clearTimeout(time_out);
	if (list_field) {
		var response = ajax_file(parentPath + 'ajax_field_contact.php?idService=' + idService + '&idQuestion=' + idQuestion);
		if (response) {
			list_field.innerHTML = response;
			document.getElementById('selectquestion_contact').innerHTML = document.getElementById('question_contact').options[document.getElementById('question_contact').selectedIndex].text;
			
			tab = new Array();
			tab[0] = new Array('alpha','contactNom','contact_field_nom');
			tab[1] = new Array('alpha','contactPrenom','contact_field_prenom');
			tab[2] = new Array('mail','contactMail','contact_field_mail');
			
			var i = 3;
			
			if( idService == 2 && idQuestion == 5 ) {
				tab[i] = new Array('alphanum','contactRefProduit','contact_field_ref_produit');
				i++;
			}
			
			if( !(idService == 3 && ( idQuestion == 2 || idQuestion == 4 || idQuestion ==5 )) )
				tab[i] = new Array('no_empty','contactMessage','contact_field_message');
			
		}
		else
			list_field.innerHTML = '';
	}
}

// --------------------------------------------------------------------------------

// On va regarde si des valeur ont ete modifiees dans les blocs de filtre (taille, couleur, promo)
// et si c'est le cas on peux faire de l'ajax
function changeFiltre( id, type, idObj, parentPath ) {
	
	elem = $("#select_"+id).children("div").children(".styled");
	elem_length = elem.length;
		
	cpt_check = 0;
	for( var j=0 ; j<elem_length ; j++ ) {
		
		//On regarde toute les checkbox a true et si le bloc n'est pas present on le cree
		// Dans l'autre cas on regarde si le bloc existe et si c'est le cas on le supprime
		if( elem[j].checked ) {
			
			if( $("#btn_suppr_" + elem[j].id).length == 0 ) {
			
				var string = '<div id="btn_suppr_' + elem[j].id + '" class="btn_suppr f_left"><img src="' + path_relative_root_search + 'img/btn_suppr_tri.jpg" alt="Supprimer" title="Supprimer" onclick="delCheckBox(\'' + elem[j].id + '\',\'' + type + '\','+idObj+',\'' + parentPath + '\');" /> ' + elem[j].value + '</div>';
				$("#select_" + id + "_suppr").append(string);
				
			}
			
		}
		else {
			
			if( $("#btn_suppr_" + elem[j].id) != 0 ) $("#btn_suppr_" + elem[j].id).remove();
			
		}
		
	}
	
	generateNewBlocProd( type, idObj, parentPath );
	
}

function changeFiltreSearch( id, parameters, page, parentPath, nb_product ) {
	
	elem = $("#select_"+id).children("div").children(".styled");
	elem_length = elem.length;
	
	cpt_check = 0;
	for( var j=0 ; j<elem_length ; j++ ) {
		
		//On regarde toute les checkbox a true et si le bloc n'est pas present on le cree
		// Dans l'autre cas on regarde si le bloc existe et si c'est le cas on le supprime
		if( elem[j].checked ) {
			
			if( $("#btn_suppr_" + elem[j].id).length == 0 ) {
				//', parameters, page, parentPath, nb_product
				var string = '<div id="btn_suppr_' + elem[j].id + '" class="btn_suppr f_left"><img src="' + path_relative_root_search + 'img/btn_suppr_tri.jpg" alt="Supprimer" title="Supprimer" onclick="delCheckBoxSearch(\'' + elem[j].id + '\',\'' + parameters + '\','+page+',\'' + parentPath + '\',' + nb_product + ');" /> ' + elem[j].value + '</div>';
				$("#select_" + id + "_suppr").append(string);
				
			}
			
		}
		else {
			
			if( $("#btn_suppr_" + elem[j].id) != 0 ) $("#btn_suppr_" + elem[j].id).remove();
			
		}
		
	}
	
	generateNewBlocSearch( parameters, page, parentPath, nb_product );
	
}
function changeFiltreGift( id, parameters, page, parentPath, nb_product ) {

	elem = $("#select_"+id).children("div").children(".styled");
	elem_length = elem.length;
	
	cpt_check = 0;
	for( var j=0 ; j<elem_length ; j++ ) {
		
		//On regarde toute les checkbox a true et si le bloc n'est pas present on le cree
		// Dans l'autre cas on regarde si le bloc existe et si c'est le cas on le supprime
		if( elem[j].checked ) {
			
			if( $("#btn_suppr_" + elem[j].id).length == 0 ) {
																																																								//', parameters, page, parentPath, nb_product
				var string = '<div id="btn_suppr_' + elem[j].id + '" class="btn_suppr f_left"><img src="' + path_relative_root_search + 'img/btn_suppr_tri.jpg" alt="Supprimer" title="Supprimer" onclick="delCheckBoxGift(\'' + elem[j].id + '\',\'' + parameters + '\','+page+',\'' + parentPath + '\',' + nb_product + ');" /> ' + elem[j].value + '</div>';
				$("#select_" + id + "_suppr").append(string);
			
			}
		
		}
		else {
			
			if( $("#btn_suppr_" + elem[j].id) != 0 ) $("#btn_suppr_" + elem[j].id).remove();
			
		}
		
	}
	
	generateNewBlocGift( parameters, page, parentPath, nb_product );
		
}

// Quand on click sur le bouton de suppression d'une taille, couleur, promo
function delCheckBox( id, type, idObj, parentPath  ) {
	
	$("#btn_suppr_"+id).remove();
	$("#"+id).attr('checked',false);
	$("#"+id).prev().css('backgroundPosition','0 0');
	
	generateNewBlocProd( type, idObj, parentPath );
}	
// Quand on click sur le bouton de suppression d'une taille, couleur, promo
function delCheckBoxSearch( id, parameters, page, parentPath, nb_product  ) {
	
	$("#btn_suppr_"+id).remove();
	$("#"+id).attr('checked',false);
	$("#"+id).prev().css('backgroundPosition','0 0');
	
	generateNewBlocSearch( parameters, page, parentPath, nb_product );
	
}

// Quand on click sur le bouton de suppression d'une taille, couleur, promo
function delCheckBoxGift( id, parameters, page, parentPath, nb_product  ) {

	$("#btn_suppr_"+id).remove();
	$("#"+id).attr('checked',false);
	$("#"+id).prev().css('backgroundPosition','0 0');
	
	generateNewBlocGift( parameters, page, parentPath, nb_product );

}

// On va regarde tout les bloc et on envoi l'ajax
// Pour les blocs de cases à cocher
// Pour le slider des prix
// Pour le bouton qui supprime un element
function generateNewBlocProd( type, idObj, parentPath, page, nb_product ) {

	var tab_bloc = new Array('taille','couleur','promo');
	var tab_get_taille = new Array();
	var tab_get_couleur = new Array();
	var tab_get_promo = new Array();
	var tab_get_eclat = new Array();
	var tab_bloc_length = tab_bloc.length;
	
	// On parcourt tt les bloc de checkbox et on regarde s'il y en a de cocher pour chaque bloc( taille, couleur, promo )
	for( var k=0 ; k<tab_bloc_length ; k++ ) {
	
		elem_bloc = $("#select_"+tab_bloc[k]).children("div").children(".styled");
		elem_bloc_length = elem_bloc.length;
		
		for( var l=0 ; l<elem_bloc_length ; l++ ) {
			
			var id = elem_bloc[l].id;
			
			if( tab_bloc[k] == 'taille' && elem_bloc[l].checked ) tab_get_taille.push(id.substring(id.indexOf('_')+1));
			else if( tab_bloc[k] == 'couleur' && elem_bloc[l].checked ) tab_get_couleur.push(id.substring(id.indexOf('_')+1));
			else if( tab_bloc[k] == 'promo' && elem_bloc[l].checked ){
				
				//on regarde si c'est une marque ou une promotion
				if( id[0] == 'p' ) tab_get_promo.push(id.substring(id.indexOf('_')+1));
				else tab_get_eclat.push(id.substring(id.indexOf('_')+1));
				
			}
		
		}
	
	}
	
	var is_from_page = false;
	
	// On check si l'utilisateur a clique sur la pagination ou le nombre de produit par page
	if(typeof(page) != 'undefined') {
		document.getElementById('page').value = page;
		is_from_page = true;
	}
	if(typeof(nb_product) != 'undefined') document.getElementById('nb_prod').value = nb_product;
	
	var str_taille = '';
	var str_couleur = '';
	var str_promo = '';
	var str_eclat = '';
	var str_prix = '';
	var str_final = '';
	
	if( tab_get_taille.length > 0 ) str_taille = tab_get_taille.join('~');
	if( tab_get_couleur.length > 0 ) str_couleur = tab_get_couleur.join('~');
	if( tab_get_promo.length > 0 ) str_promo = tab_get_promo.join('~');
	if( tab_get_eclat.length > 0 ) str_eclat = tab_get_eclat.join('~');
	// Cas special pour les prix
	str_prix = document.getElementById('amount1').value + '~' + document.getElementById('amount2').value;
	
	str_final += '&taille=' + str_taille;
	str_final += '&couleur=' + str_couleur;
	str_final += '&promo=' + str_promo;
	str_final += '&eclat=' + str_eclat;
	str_final += '&prix=' + str_prix;
	document.getElementById('wrapper_visus_produit').innerHTML = '<p id="loading"><img style="margin-top:35px;margin-right:10px;" src="' + parentPath + 'img/loader.gif" />Chargement...<span></span></p>';
	var response = ajax_file(parentPath + 'ajax_reload_products.php?page=' + document.getElementById('page').value + '&type=' + type + '&parentPath=' + parentPath + '&idObj=' + idObj + '&nb_prod=' + document.getElementById('nb_prod').value + '&is_page=' + is_from_page + str_final );
	
	var tab_response = response.split('#');
	if( tab_response[0] != '' ) {
		
		var bloc_photo = tab_response[0];
		document.getElementById('wrapper_visus_produit').innerHTML = bloc_photo;
		/*
		$(".cadre1").each(function() {
			$(this).hover(function() {									
				$(this).animate({ backgroundColor : '#efefef' }, 250);							
			}	, function() {
				$(this).animate({ backgroundColor : '#ffffff' }, 250);
			});
		})
		*/
		var nb_articles = tab_response[1];
		document.getElementById('title_nb_articles').innerHTML = nb_articles;
		document.getElementById('nb_articles').innerHTML = nb_articles;
		document.getElementById('nb_pages').innerHTML = Math.ceil(nb_articles/document.getElementById('nb_prod').value);
		
		var nav = tab_response[2];
		var nav_bas = tab_response[3];
		document.getElementById('pagination_haut').innerHTML = nav;
		document.getElementById('pagination_bas').innerHTML = nav_bas;
		
		var nb_prod = tab_response[4];
		document.getElementById('nb_prod').style.display = 'block';
		if(document.getElementById('nb_prod_numeric')) document.getElementById('nb_prod_numeric').innerHTML = nb_prod;
		
	}
	else {
		
		document.getElementById('wrapper_visus_produit').innerHTML = ajax_file(parentPath + 'ajax_sprintf.php?arg1=no_response_search');
		
		document.getElementById('pagination_haut').innerHTML = '';
		document.getElementById('pagination_bas').innerHTML = '';
		
		document.getElementById('title_nb_articles').innerHTML = 0;
		document.getElementById('nb_articles').innerHTML = 0;
		document.getElementById('nb_pages').innerHTML = 0;
	
	}

}

//On va regarde tout les bloc et on envoi l'ajax
//Pour les blocs de cases à cocher
//Pour le slider des prix
//Pour le bouton qui supprime un element
function generateNewBlocSearch( parameters, page, parentPath, nb_product ) {
	
	var tab_bloc = new Array('taille','couleur','promo');
	var tab_get_taille = new Array();
	var tab_get_couleur = new Array();
	var tab_get_promo = new Array();
	var tab_get_eclat = new Array();
	var tab_bloc_length = tab_bloc.length;
	
	// On parcourt tt les bloc de checkbox et on regarde s'il y en a de cocher pour chaque bloc( taille, couleur, promo )
	for( var k=0 ; k<tab_bloc_length ; k++ ) {
		
		elem_bloc = $("#select_"+tab_bloc[k]).children("div").children(".styled");
		elem_bloc_length = elem_bloc.length;
		
		for( var l=0 ; l<elem_bloc_length ; l++ ) {
			
			var id = elem_bloc[l].id;
			
			if( tab_bloc[k] == 'taille' && elem_bloc[l].checked ) tab_get_taille.push(id.substring(id.indexOf('_')+1));
			else if( tab_bloc[k] == 'couleur' && elem_bloc[l].checked ) tab_get_couleur.push(id.substring(id.indexOf('_')+1));
			else if( tab_bloc[k] == 'promo' && elem_bloc[l].checked ){
				
				//on regarde si c'est une marque ou une promotion
				if( id[0] == 'p' ) tab_get_promo.push(id.substring(id.indexOf('_')+1));
				else tab_get_eclat.push(id.substring(id.indexOf('_')+1));
				
			}
			
		}
		
	}
	
	var is_from_page = false;
	
	// On check si l'utilisateur a clique sur la pagination ou le nombre de produit par page
	if(typeof(page) != 'undefined') {
		document.getElementById('page').value = page;
		is_from_page = true;
	}
	if(typeof(nb_product) != 'undefined') document.getElementById('nb_prod').value = nb_product;
	
	var str_taille = '';
	var str_couleur = '';
	var str_promo = '';
	var str_eclat = '';
	var str_prix = '';
	var str_final = parameters;
	
	if( tab_get_taille.length > 0 ) str_taille = tab_get_taille.join('~');
	if( tab_get_couleur.length > 0 ) str_couleur = tab_get_couleur.join('~');
	if( tab_get_promo.length > 0 ) str_promo = tab_get_promo.join('~');
	if( tab_get_eclat.length > 0 ) str_eclat = tab_get_eclat.join('~');
	// Cas special pour les prix
	str_prix = document.getElementById('amount1').value + '~' + document.getElementById('amount2').value;
	
	str_final += '&taille=' + str_taille;
	str_final += '&couleur=' + str_couleur;
	str_final += '&promo=' + str_promo;
	str_final += '&eclat=' + str_eclat;
	str_final += '&prix=' + str_prix;
	document.getElementById('wrapper_visus_produit').innerHTML = '<p id="loading"><img style="margin-top:35px;margin-right:10px;" src="' + parentPath + 'img/loader.gif" />Chargement...<span></span></p>';
	var response = ajax_file(parentPath + 'ajax_reload_search.php?' + str_final + '&is_page=' + is_from_page + '&parentPath=' + parentPath + '&nbProducts='+nb_product + '&page=' + page );
	
	var tab_response = response.split('#');
	if( tab_response[0] != '' ) {
		
		var bloc_photo = tab_response[0];
		document.getElementById('wrapper_visus_produit').innerHTML = bloc_photo;
		/*
		$(".cadre1").each(function() {
			$(this).hover(function() {									
				$(this).animate({ backgroundColor : '#efefef' }, 250);							
			}	, function() {
				$(this).animate({ backgroundColor : '#ffffff' }, 250);
			});
		})
		*/
		var nb_articles = tab_response[1];
		document.getElementById('nb_articles').innerHTML = nb_articles;
		document.getElementById('nb_pages').innerHTML = Math.ceil(nb_articles/document.getElementById('nb_prod').value);
		
		var nav = tab_response[2];
		var nav_bas = tab_response[3];
		document.getElementById('pagination_haut').innerHTML = nav;
		document.getElementById('pagination_bas').innerHTML = nav_bas;
		
		var nb_prod = tab_response[4];
		if(document.getElementById('nb_prod_numeric')) document.getElementById('nb_prod_numeric').innerHTML = nb_prod;
		
	}
	else {
		
		document.getElementById('wrapper_visus_produit').innerHTML = ajax_file(parentPath + 'ajax_sprintf.php?arg1=no_response_search');
		
		document.getElementById('pagination_haut').innerHTML = '';
		document.getElementById('pagination_bas').innerHTML = '';
		
		document.getElementById('nb_articles').innerHTML = 0;
		document.getElementById('nb_pages').innerHTML = 0;
		
	}
	
}

//On va regarde tout les bloc et on envoi l'ajax
//Pour les blocs de cases à cocher
//Pour le slider des prix
//Pour le bouton qui supprime un element
function generateNewBlocGift( parameters, page, parentPath, nb_product ) {

	var tab_bloc = new Array('taille','couleur','promo');
	var tab_get_taille = new Array();
	var tab_get_couleur = new Array();
	var tab_get_promo = new Array();
	var tab_get_eclat = new Array();
	var tab_bloc_length = tab_bloc.length;
	
	// On parcourt tt les bloc de checkbox et on regarde s'il y en a de cocher pour chaque bloc( taille, couleur, promo )
	for( var k=0 ; k<tab_bloc_length ; k++ ) {
	
		elem_bloc = $("#select_"+tab_bloc[k]).children("div").children(".styled");
		elem_bloc_length = elem_bloc.length;
		
		for( var l=0 ; l<elem_bloc_length ; l++ ) {
			
			var id = elem_bloc[l].id;
			
			if( tab_bloc[k] == 'taille' && elem_bloc[l].checked ) tab_get_taille.push(id.substring(id.indexOf('_')+1));
			else if( tab_bloc[k] == 'couleur' && elem_bloc[l].checked ) tab_get_couleur.push(id.substring(id.indexOf('_')+1));
			else if( tab_bloc[k] == 'promo' && elem_bloc[l].checked ){
				
				//on regarde si c'est une marque ou une promotion
				if( id[0] == 'p' ) tab_get_promo.push(id.substring(id.indexOf('_')+1));
				else tab_get_eclat.push(id.substring(id.indexOf('_')+1));
				
			}
		
		}
	
	}
	
	var is_from_page = false;
	
	// On check si l'utilisateur a clique sur la pagination ou le nombre de produit par page
	if(typeof(page) != 'undefined') {
		document.getElementById('page').value = page;
		is_from_page = true;
	}
	if(typeof(nb_product) != 'undefined') document.getElementById('nb_prod').value = nb_product;
	
	var str_taille = '';
	var str_couleur = '';
	var str_promo = '';
	var str_eclat = '';
	var str_prix = '';
	var str_final = parameters;
	
	if( tab_get_taille.length > 0 ) str_taille = tab_get_taille.join('~');
	if( tab_get_couleur.length > 0 ) str_couleur = tab_get_couleur.join('~');
	if( tab_get_promo.length > 0 ) str_promo = tab_get_promo.join('~');
	if( tab_get_eclat.length > 0 ) str_eclat = tab_get_eclat.join('~');
	// Cas special pour les prix
	str_prix = document.getElementById('amount1').value + '~' + document.getElementById('amount2').value;
	
	str_final += '&taille=' + str_taille;
	str_final += '&couleur=' + str_couleur;
	str_final += '&promo=' + str_promo;
	str_final += '&eclat=' + str_eclat;
	str_final += '&prix=' + str_prix;
	document.getElementById('wrapper_visus_produit').innerHTML = '<p id="loading"><img style="margin-top:35px;margin-right:10px;" src="' + parentPath + 'img/loader.gif" />Chargement...<span></span></p>';
	var response = ajax_file(parentPath + 'ajax_reload_gift.php' + str_final + '&is_page=' + is_from_page +  '&parentPath=' + parentPath + '&nbProducts='+nb_product + '&page=' + page );
	
	var tab_response = response.split('#');
	if( tab_response[0] != '' ) {
		
		var bloc_photo = tab_response[0];
		document.getElementById('wrapper_visus_produit').innerHTML = bloc_photo;
		/*
		$(".cadre1").each(function() {
			$(this).hover(function() {									
				$(this).animate({ backgroundColor : '#efefef' }, 250);							
			}	, function() {
				$(this).animate({ backgroundColor : '#ffffff' }, 250);
			});
		})
		*/
		var nb_articles = tab_response[1];
		document.getElementById('title_nb_articles').innerHTML = nb_articles;
		document.getElementById('nb_articles').innerHTML = nb_articles;
		document.getElementById('nb_pages').innerHTML = Math.ceil(nb_articles/document.getElementById('nb_prod').value);
		
		var nav = tab_response[2];
		var nav_bas = tab_response[3];
		document.getElementById('pagination_haut').innerHTML = nav;
		document.getElementById('pagination_bas').innerHTML = nav_bas;
		
		var nb_prod = tab_response[4];
		if(document.getElementById('nb_prod_numeric')) document.getElementById('nb_prod_numeric').innerHTML = nb_prod;
		
	}
	else {
		
		document.getElementById('wrapper_visus_produit').innerHTML = ajax_file(parentPath + 'ajax_sprintf.php?arg1=no_response_search');
		
		document.getElementById('pagination_haut').innerHTML = '';
		document.getElementById('pagination_bas').innerHTML = '';
		
		document.getElementById('nb_articles').innerHTML = 0;
		document.getElementById('nb_pages').innerHTML = 0;
	
	}

}

// Affiche la liste des commandes selon le type
function show_orders_by_type(elementID, type, parentPath) {
	
	// Gestion de la surbrillance des onglets
	var i = 1;
	while( document.getElementById('onglet_'+i+'_left') ) {
		if( type == i ) {
			
			$("#onglet_"+i+"_left").attr('class','left-on');
			$("#onglet_"+i+"_mid").attr('class','mid-on');
			$("#onglet_"+i+"_right").attr('class','right-on');
			
		}
		else {
		
			$("#onglet_"+i+"_left").attr('class','left-off');
			$("#onglet_"+i+"_mid").attr('class','mid-off');
			$("#onglet_"+i+"_right").attr('class','right-off');
		
		}
		i++;
	}
	
	var container = document.getElementById(elementID);

	//clearTimeout(time_out);
	if (container) {
		var response = ajax_file(parentPath + 'ajax_account_orders_by_type.php?type=' + type);
		
		if (response)
			container.innerHTML = response;
		else
			container.innerHTML = '';
	}
}

function show_message(mId, hide) {

	if (hide == 0) {
		var ajax_content = ajax_file('ajax_show_messages.php?mId='+ mId);
		if (ajax_content) {

			document.getElementById("message_"+ mId).innerHTML = ajax_content;

			document.getElementById("message_"+ mId).onclick = '';
			document.getElementById("message_"+ mId).style.cursor = 'default';

		}
	} else {
	var ajax_content = ajax_file('ajax_show_messages.php?mId='+ mId + '&hide=1');
		if (ajax_content) {

			document.getElementById("message_" + mId).innerHTML = ajax_content;
		
			document.getElementById("message_" + mId).onclick = "show_message("+mId+",0);";
				
			document.getElementById("message_" + mId).style.cursor = 'pointer';

		}
	}
}
var timer;
// --------------------------------------------------------------------------------
function newNewsletterFromCmpid() {

	var flag = verif_mail( 'email_inscription_home','login_email' );
	if( flag ) {
		
		flag = ajax_file(path_relative_root+'ajax_email_newsletter_exist.php?mail='+ document.getElementById('email_inscription_home').value);
		
		var elementID = 'email_inscription_home';
		
		var objElement = document.getElementById(elementID);
		var objLabel = document.getElementById(elementID + 'Label');
		var erreurText = document.getElementById('erreur_msg');
		
		if( flag === '1' ) flag = false;
		else flag = true;
		
		if( !flag ) {
		
			erreurText.innerHTML = '<p class="title_toolltip">' + ajax_file(path+'ajax_sprintf.php?arg1=login_email') + ' :</p>' + ajax_file(path+'ajax_sprintf.php?arg1=js_mail_newsletter_exist');
			objElement.className = 'inputErr';
			objLabel.className = 'labelErr';
		
		}
		else {
		
			objElement.className = 'input_spontanee';
			objElement.style.border="1px solid #CCCCCC";
			objLabel.className = 'labelForm';
		
		}
		
	}
	
	if( flag ) {
		
		clearTimeout(timer);
		
		document.getElementById("bloc_erreur").style.display = 'none';
		
	}
	else{
		
		elem = document.getElementById('email_inscription_home');
		
		elem.style.border="1px solid #EA6195";
		pos = getPos(elem);
		
		document.getElementById('bloc_erreur').style.position = 'absolute';
		
		var nav = navigator.appVersion;
		
		if(!jQuery.browser.msie) $("#bloc_erreur").fadeIn(400);
		else document.getElementById("bloc_erreur").style.display = 'block';
		
		/*if ( nav.indexOf('MSIE 7') >= 0 ) {
		
			pos_parent = getPos(document.getElementById('bloc_erreur').parentNode);
			
			if (document.getElementById('bloc_erreur').parentNode.id == 'home_wrapper') {
				document.getElementById('bloc_erreur').style.top = (pos.y) - (document.getElementById('bloc_erreur').offsetHeight) + 'px';
				document.getElementById('bloc_erreur').style.left = ((pos.x-15)) + 'px';
			} else {
				document.getElementById('bloc_erreur').style.top = (pos.y-pos_parent.y) - (document.getElementById('bloc_erreur').offsetHeight) + 'px';
				document.getElementById('bloc_erreur').style.left = ((pos.x-15) - pos_parent.x) + 'px';
			}
			
		} else {*/
			document.getElementById('bloc_erreur').style.top = pos.y - (document.getElementById('bloc_erreur').offsetHeight) + 'px';
			document.getElementById('bloc_erreur').style.left = (pos.x-15) + 'px';
		//}
		document.getElementById('bloc_erreur').style.zIndex = '99999';
		
		window.clearTimeout(timer);
		
		timer = setTimeout("closeInfobulle('bloc_erreur')",5000);
		
	}
	
	return flag;

}

function checkAndAddMail() {
	
	if( newNewsletterFromCmpid() ) {
		
		$("#btn_conf_cmpid").css('display','none');
		$("#loader_popup").css('display','block');
		
		response = ajax_file(path_relative_root+'ajax_add_email_newsletter.php?mail='+ document.getElementById('email_inscription_home').value);
		
		if( response == 1 ) {
		
			$("#formu_inscription_news").fadeOut(750,function() {
				$("#conf_inscription_news").fadeIn(750);
			});
			
			//$("#shad").attr('onclick','close_popup(\'popup_inscription_home\')');
			document.getElementById('shad').setAttribute('onclick',function(){ close_popup('popup_inscription_home'); });
			document.getElementById('shad').onclick=function(){ close_popup('popup_inscription_home');}
			
		}
		
	}
	
}

function ajaxDeconnect(path_relative_root) {

	response = ajax_file( path_relative_root + 'ajax_deconnect.php' );
	
	// On regarde d'abord dans quelle page on se trouve
	var url = window.location.pathname;
	var index_deb = url.lastIndexOf('/');
	var index_fin = url.lastIndexOf('.');
	var provenance = url.substring(index_deb+1,index_fin);
	
	// Et on redirige si on est dans des pages en relation avec le compte client
	if( provenance == 'adresses' || provenance == 'mes_infos' || provenance == 'newsletter' || provenance == 'parrainage' || provenance == 'mon-compte' || provenance == 'facture-liste' || provenance == 'avoir-liste' || provenance == 'commande_detail' )
		window.location.href = path_relative_root + 'connexion.php';
	else {
		if( response == 'true' ) {
			
			document.getElementById('topMenuConnexionTop').innerHTML = '<img style="margin-left:89px;margin-top:61px;float:left;" src="'+path_relative_root+'img/loader.gif" /><p style="float:left;margin-left:10px;margin-top:64px;"><strong>Deconnexion...</strong></p>';
			
			var str_return = '<table cellspacing="0" cellpadding="0" border="0"><tr id="bloc_login_top"><td valign="top">';
			str_return += '<table cellspacing="0" cellpadding="0" border="0">';
			str_return += '<form method="post" name="auth" onsubmit="return ajax_checkAllForm(tabAuthTop, 1, \'' + path_relative_root + '\');" onblur="openConnexionTop();">';
			str_return += '</form>';
			str_return += '<input name="caid" value="" type="hidden">';							
			str_return += '<input name="act" value="ident" type="hidden">';
			str_return += '<tbody>';
			str_return += '<tr>';
			str_return += '<td style="height:28px; padding-left: 17px; width: 100px;" id="clientMailAuthTopLabel" class="mc_texte" >E-mail : </td>';
			str_return += '<td>';
			str_return += '<input onblur="checkForm(\'mail\',this,\'login_email\',null, 1);" name="userbdd" id="clientMailAuthTop" value="" class="inputFormSite" style="width: 150px;" type="text" />';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr>';
			str_return += '<td style="height:28px; padding-left: 17px;" id="clientPwdAuthTopLabel" class="mc_texte">Mot de passe : </td>';
			str_return += '<td style="padding-right:17px;"><input onblur="checkForm(\'alphanum\',this,\'login_mdp\',null, 1)" name="passbdd" id="clientPwdAuthTop" value="" class="inputFormSite" style="width: 150px;" type="password" /></td>';
			str_return += '</tr>';
			str_return += '<tr>';
			str_return += '<td style="height:28px; padding-left:17px;" >&nbsp;</td>';
			str_return += '<td><input onclick="ajax_checkAllForm(tabAuthTop, 1, \'' + path_relative_root + '\');" name="Identification" class="btn_rose" value="VALIDER" type="submit"></td>';
			str_return += '</tr>';
			str_return += '<tr class="cache" id="clientMailAuthTopErr">';
			str_return += '<td style="height:16px; padding-left:17px; padding-right:17px;" colspan="2">';
			str_return += '<p style="font-size:11px; color:#ff0000;">';
			str_return += '<span style="height:11px; vertical-align:-3px; line-height:11px;"><img style="height:16px;" alt="erreur" src="' + path_relative_root + 'img/picto_panneau.png" /></span>';
			str_return += 'L\'adresse e-mail est invalide.';
			str_return += '</p>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr class="cache" id="clientPwdAuthTopErr">';
			str_return += '<td style="height:16px; padding-left:17px; padding-right:14px;" colspan="2">';
			str_return += '<p style="font-size:11px; color:#ff0000;">';
			str_return += '<span style="height:11px; vertical-align:-3px; line-height:11px;"><img style="height:16px;" alt="erreur" src="' + path_relative_root + 'img/picto_panneau.png" /></span>';
			str_return += 'Le mot de passe doit faire au moins 3 caractères.';
			str_return += '</p>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr class="cache" id="AuthTopErr">';
			str_return += '<td style="height:16px; padding-left:17px; padding-right:17px;" colspan="2">';
			str_return += '<p style="font-size:11px; color:#ff0000;">';
			str_return += '<span style="height:11px; vertical-align:-3px; line-height:11px;"><img style="height:16px;" alt="erreur" src="' + path_relative_root + 'img/picto_panneau.png" /></span>';
			str_return += 'Les identifiants sont incorrectes.';
			str_return += '</p>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr>';
			str_return += '<td></td>';
			str_return += '<td style="height:28px;" align="left">';
			str_return += '<span style="height:28px; vertical-align:10px; line-height:20px;"><a class="pink" href="javascript:;" onclick="afficheLostPasswordTop();">Mot de passe oublié ?</a></span>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr class="topMenuConnexionBottom" >';
			str_return += '<td style="height:28px;" class="topMenuConnexionBottomInside" onmouseover="this.style.cursor = \'pointer\';" onclick="javascript:window.location.replace(\'connexion.php\');" colspan="2">';
			str_return += '<strong>NOUVEAU CLIENT ?</strong> <a style="padding-left:30px;" href="' + path_relative_root + 'connexion.php">Inscrivez vous</a>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '</tbody>';
			str_return += '</table>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr id="bloc_lost_password_top" class="cache">';
			str_return += '<td style="padding-top: 13px;" valign="top">';
			str_return += '<table width="100%" border="0" cellpadding="0" cellspacing="0">';
			str_return += '<tbody>';
			str_return += '<tr id="lostpwdTopSuccesTitle">';
			str_return += '<td style="padding-left:17px;" colspan="2"><p style="font-weight: bold; color: rgb(102, 102, 102); font-family: Essai;">RECEVEZ VOTRE MOT DE PASSE :</p></td>';
			str_return += '</tr>';
			str_return += '<form method="post" name="lostpwd" onsubmit="return ajax_checkAllForm(tabLostPwdTop, 1, \'' + path_relative_root + '\');" action="">';
			str_return += '</form>';
			str_return += '<input name="act" value="new mdp link" type="hidden">';
			str_return += '<tr id="lostpwdTopSucces1">';
			str_return += '<td style="height:48px; padding-left:17px; width:70px;" id="mailLostTopLabel" class="mc_texte" >E-mail : </td>';
			str_return += '<td style="padding-right:17px;"><input style="width:180px;" onblur="checkForm(\'mail\',this,\'login_email\',null, 1);" id="mailLostTop" name="email" value="" class="inputFormSite" type="text"></td>';
			str_return += '</tr>';
			str_return += '<tr id="lostpwdTopSucces2">';
			str_return += '<td style="height:20px;"></td>';
			str_return += '<td align="left">';
			str_return += '<input onclick="ajax_checkAllForm(tabLostPwdTop, 1, \'' + path_relative_root + '\');" class="btn_rose" name="envoyer" value="ENVOYER" type="submit">';
			str_return += '<input class="btn_rose" name="annuler" value="ANNULER" type="button" style="margin-left:12px;" onclick="reloadBlocLoginTop();">';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr id="lostpwdTopSucces3" style="display:none;">';
			str_return += '<td style="height:48px; text-align:center;">';
			str_return += '<p style="font-weight: bold; color: rgb(102, 102, 102); font-family: Essai;">Un e-mail a bien été envoyé.<br />Il vous permettra de choisir votre nouveau<br /> mot de passe.</p>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr id="lostpwdTopSucces4" style="display:none;">';
			str_return += '<td style="height:20px;">&nbsp;</td><td></td>';
			str_return += '</tr>';
			str_return += '<tr class="cache" id="mailLostTopErr">';
			str_return += '<td style="height:16px; padding-left:17px;" colspan="2">';
			str_return += '<p style="margin-top:12px; font-size:11px; color:#ff0000;">';
			str_return += '<span style="height:11px; vertical-align:-3px; line-height:11px;"><img style="height:16px;" alt="erreur" src="' + path_relative_root + 'img/picto_panneau.png" /></span>';
			str_return += 'L\'adresse e-mail est invalide.';
			str_return += '</p>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr class="cache" id="lostpwdTopErr">';
			str_return += '<td style="height:16px; padding-left:17px;" colspan="2">';
			str_return += '<p style="margin-top:12px; font-size:11px; color:#ff0000;">';
			str_return += '<span style="height:11px; vertical-align:-3px; line-height:11px;"><img style="height:16px;" alt="erreur" src="' + path_relative_root + 'img/picto_panneau.png" /></span>';
			str_return += 'Vous n\'êtes pas enregistré, veuillez vous inscrire.';
			str_return += '</p>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '<tr>';
			str_return += '<td></td>';
			str_return += '<td style="height:14px;" align="left">&nbsp;</td>';
			str_return += '</tr>';
			str_return += '<tr class="topMenuConnexionBottom">';
			str_return += '<td style="height:28px;" class="topMenuConnexionBottomInside" colspan="2" onclick="javascript:document.location.href=\'connexion.php\';">';
			str_return += '<strong>NOUVEAU CLIENT ?</strong> <a style="padding-left:30px;" href="connexion.php">Inscrivez vous</a>';
			str_return += '</td>';
			str_return += '</tr>';
			str_return += '</tbody>';
			str_return += '</table>';					
			str_return += '</td>';
			str_return += '</tr></table>';
			
			document.getElementById('topMenuConnexionTop').innerHTML = str_return;
			document.getElementById('entete_connexion').innerHTML = ' Connexion  ';
			document.getElementById('lien_mon_compte').href = path_relative_root + 'connexion.php';
		
		}
		
	}

}

function send_mail_contact(path_relative_root)
{
	var act = document.getElementById('form_contact').elements[0].value;
	var civilite;
	if(document.getElementById('form_contact').elements[1].checked)
		civilite = "M";
	else
	{
		if(document.getElementById('form_contact').elements[2].checked)
			civilite = "Mme";
		else
			civilite = "Mlle";
	}
	var nom = document.getElementById('form_contact').elements[4].value;
	var prenom = document.getElementById('form_contact').elements[5].value;
	var raison_sociale = document.getElementById('form_contact').elements[6].value;
	var email = document.getElementById('form_contact').elements[7].value;
	var email_verif = document.getElementById('form_contact').elements[8].value;
	var pays = document.getElementById('form_contact').elements[9].value;
	var cp = document.getElementById('form_contact').elements[10].value;
	var tel = document.getElementById('form_contact').elements[11].value;
	var fax = document.getElementById('form_contact').elements[12].value;
	var message = document.getElementById('form_contact').elements[13].value;
	if(document.getElementById('form_contact').elements[14].checked)
		var actus = 1;
	else
		var actus = 0;
	if(document.getElementById('form_contact').elements[15].checked)
		var actusPartenaires = 1;
	else
		var actusPartenaires = 0;
	
	var res = ajax_file(path_relative_root + "ajax_send_mail_contact.php?act="+act+"&civilite="+civilite+"&nom="+nom+"&prenom="+prenom+"&raison_sociale="+raison_sociale+"&email="+email+"&email_verif="+email_verif+"&pays="+pays+"&cp="+cp+"&tel="+tel+"&fax="+fax+"&message="+message+"&actus="+actus+"&actusPartenaires="+actusPartenaires);
	if(res)
	{
		jQuery('#contact_form').slideUp(600);
		jQuery('#popup_contact').slideDown(600);
	}
}

function send_mail_distributeur(path_relative_root)
{
	var act = document.getElementById('devenirDistributeur').elements[0].value;
	var raison_sociale = document.getElementById('devenirDistributeur').elements[1].value;
	var adresse = document.getElementById('devenirDistributeur').elements[2].value;
	var cp = document.getElementById('devenirDistributeur').elements[3].value;
	var ville = document.getElementById('devenirDistributeur').elements[4].value;
	var pays = document.getElementById('devenirDistributeur').elements[5].value;
	var email = document.getElementById('devenirDistributeur').elements[6].value;
	if(document.getElementById('devenirDistributeur').elements[7].checked)
		var circuit = document.getElementById('devenirDistributeur').elements[7].value;
	if(document.getElementById('devenirDistributeur').elements[8].checked)
		var circuit = document.getElementById('devenirDistributeur').elements[8].value;
	if(document.getElementById('devenirDistributeur').elements[9].checked)
		var circuit = document.getElementById('devenirDistributeur').elements[9].value;
	if(document.getElementById('devenirDistributeur').elements[10].checked)
		var circuit = document.getElementById('devenirDistributeur').elements[10].value;
	var circuit_autre = document.getElementById('devenirDistributeur').elements[11].value;
	var nb_employes = document.getElementById('devenirDistributeur').elements[12].value;
	var ca = document.getElementById('devenirDistributeur').elements[13].value;
	/*
		SPECIALITE NON TRAITEE PAR LE CONTROLLER !!
		DEPARTEMENT NON TRAITEE PAR LE CONTROLLER !!
	*/
	if(document.getElementById('devenirDistributeur').elements[25].checked)
		var licencie = document.getElementById('devenirDistributeur').elements[25].value;
	if(document.getElementById('devenirDistributeur').elements[26].checked)
		var licencie = document.getElementById('devenirDistributeur').elements[26].value;
	var licence_type = document.getElementById('devenirDistributeur').elements[27].value;
	var licence_dpt = document.getElementById('devenirDistributeur').elements[28].value;
	if(document.getElementById('devenirDistributeur').elements[29].checked)
		var salon = document.getElementById('devenirDistributeur').elements[29].value;
	if(document.getElementById('devenirDistributeur').elements[30].checked)
		var salon = document.getElementById('devenirDistributeur').elements[30].value;
	var salon_nom = document.getElementById('devenirDistributeur').elements[31].value;
	var message = document.getElementById('devenirDistributeur').elements[32].value;
	
	var res = ajax_file(path_relative_root + "ajax_send_mail_distributeur.php?act="+act+"&raison_sociale="+raison_sociale+"&adresse="+adresse+"&cp="+cp+"&ville="+ville+"&pays="+pays+"&email="+email+"&circuit="+circuit+"&circuit_autre="+circuit_autre+"&nb_employes="+nb_employes+"&ca="+ca+"&licencie="+licencie+"&licence_type="+licence_type+"&licence_dpt="+licence_dpt+"&salon="+salon+"&salon_nom="+salon_nom+"&message="+message);
	if(res)
	{
		jQuery('#wrapper_form_distributeur').slideUp(600);
		jQuery('#popup_distributeur').slideDown(600);
	}
}

function send_mail_newsletter(path_relative_root)
{
	var act = document.getElementById('inscriptionNewsletter').elements[0].value;
	if(document.getElementById('inscriptionNewsletter').elements[1].checked)
		var newsletterCivilite = document.getElementById('inscriptionNewsletter').elements[1].value;
	else if(document.getElementById('inscriptionNewsletter').elements[2].checked)
		var newsletterCivilite = document.getElementById('inscriptionNewsletter').elements[2].value;
	else if(document.getElementById('inscriptionNewsletter').elements[3].checked)
		var newsletterCivilite = document.getElementById('inscriptionNewsletter').elements[3].value;
	var newsletterNom = document.getElementById('inscriptionNewsletter').elements[4].value;
	var newsletterPrenom = document.getElementById('inscriptionNewsletter').elements[5].value;
	var newsletterMail = document.getElementById('inscriptionNewsletter').elements[6].value;
	var newsletterSociete = document.getElementById('inscriptionNewsletter').elements[7].value;
	var newsletterActusSC = document.getElementById('inscriptionNewsletter').elements[8].value;
	if(document.getElementById('inscriptionNewsletter').elements[9].checked)
		var newsletterActuspartenairesSC = document.getElementById('inscriptionNewsletter').elements[9].value;
	
	var res = ajax_file(path_relative_root + "ajax_send_mail_newsletter.php?act="+act+"&newsletterCivilite="+newsletterCivilite+"&newsletterNom="+newsletterNom+"&newsletterPrenom="+newsletterPrenom+"&newsletterMail="+newsletterMail+"&newsletterSociete="+newsletterSociete+"&newsletterActusSC="+newsletterActusSC+"&newsletterActuspartenairesSC="+newsletterActuspartenairesSC);
	if(res)
	{
		jQuery('#form_candidature_spontanee').slideUp(600);
		jQuery('#popup_newsletter').slideDown(600);
	}
}
