






// 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>';
			var couleurs = document.getElementById('couleurProd');
			var tailles = document.getElementById('tailleProd');
		}
		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){
			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 + '&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, idQte){
	
	if (i != '') {
		
		
		if (isAssoc == true) {
		
			i = 'Assoc_'+i;
				
		} else {
			
			i = '_'+i;
			
		}
		
		prixU = document.getElementById('prixU'+i).value;
		
	}
	

	
	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;
			
		}

//alert(prixU + '&' + idProduit + '&' + qte + '&' + paniervirtuelId);
		
		var array_response = new Array();
		var response = ajax_file(path_web+'ajax_upd_panier.php?prixu=' + prixU + '&idprod=' + idProduit + '&qte=' + qte + '&panierId=' + paniervirtuelId);
//alert(response);
		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;
			
				
			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;
		else
			list_field.innerHTML = '';
	}
}



// Permet le non rafraichissement d'une page en exploitant l'objet XHR
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);
}
// --------------------------------------------------------------------------------