// JavaScript Document
var xhr1 ;
var type_client;
function getPrixDispo(idProd, typeClient){
	type_client = typeClient;
	
	if (window.XMLHttpRequest) { //Navigateur FireFox
			xhr1 = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) //Navigateur IE 6 et plus
		{
			try {
			       xhr1 = new ActiveXObject("Msxml2.XMLHTTP");
			    } catch (e) {
					xhr1 = new ActiveXObject("Microsoft.XMLHTTP");
			   }
		}
	xhr1.onreadystatechange = handleHttpResponsePrixDispo;
	var url = "/prix_dispo.php?id_prod="+idProd;
	xhr1.open("GET", url, true);
	xhr1.send(null);
}
function handleHttpResponsePrixDispo() {
    if(xhr1.readyState == 4 && xhr1.status == 200) {
		var response;
		var dispo;
		var delai_dispo;
		var prix_ht;
		var prix_ttc;
		var prix_public_ht;
		var prix_public_ttc;
		var remise;
		var id;
		var chaine_prix = '';
		var chaine_caddie = '';
		var chaine_qte_maj = '';
		
		var ref_pc21;
		var img_prod;
		var zoom;
		var titre_prod;
		var qte_appro;
		var date_appro;
		var source_delai;
		var date_fin_promo;
		
   		response = xhr1.responseXML;
		var produits = response.getElementsByTagName("pc21");
		
		dispo = produits[0].getElementsByTagName("dispo")[0].firstChild.nodeValue;
		delai_dispo = produits[0].getElementsByTagName("delai_dispo")[0].firstChild.nodeValue;
		prix_ht = produits[0].getElementsByTagName("prix_ht")[0].firstChild.nodeValue;
		prix_ttc = produits[0].getElementsByTagName("prix_ttc")[0].firstChild.nodeValue;
		prix_public_ht = produits[0].getElementsByTagName("prix_public_ht")[0].firstChild.nodeValue;
		prix_public_ttc = produits[0].getElementsByTagName("prix_public_ttc")[0].firstChild.nodeValue;
		remise = produits[0].getElementsByTagName("remise")[0].firstChild.nodeValue;
		id = produits[0].getElementsByTagName("id")[0].firstChild.nodeValue;
		ref_pc21 = produits[0].getElementsByTagName("ref_pc21")[0].firstChild.nodeValue;
		img_prod = produits[0].getElementsByTagName("img_prod")[0].firstChild.nodeValue;
		qte_stock = produits[0].getElementsByTagName("qte_stock")[0].firstChild.nodeValue;
		date_maj = produits[0].getElementsByTagName("date_maj")[0].firstChild.nodeValue;
		heure_maj = produits[0].getElementsByTagName("heure_maj")[0].firstChild.nodeValue;
		taxes = produits[0].getElementsByTagName("taxes")[0].firstChild.nodeValue;
		date_fin_promo = produits[0].getElementsByTagName("date_fin_promo")[0].firstChild.nodeValue;
		
		if(dispo == -3){
			qte_appro = produits[0].getElementsByTagName("qte_appro")[0].firstChild.nodeValue;
			date_appro = produits[0].getElementsByTagName("date_appro")[0].firstChild.nodeValue;
		 	source_delai = produits[0].getElementsByTagName("source_delai")[0].firstChild.nodeValue;
		}
		
		
		if(dispo == 0){
			if(!(qte_stock == 0 && date_maj == 'nc'))
				chaine_qte_maj = chaine_qte_maj + '<font class=\'texte_dispo_petit\' >(';
			if(qte_stock > 0)
				chaine_qte_maj = chaine_qte_maj +  'Quantité ' + qte_stock + ' - ';
			
			if(date_maj != 'nc')
				chaine_qte_maj = chaine_qte_maj +  'Mise à jour le ' + date_maj + ' à ' + heure_maj;
								   
			if(!(qte_stock == 0 && date_maj == 'nc'))
				chaine_qte_maj =  chaine_qte_maj + ')</font>';
		}
		
		if(dispo == -1 || dispo == -3){
			if(date_maj != 'nc')
				chaine_qte_maj = chaine_qte_maj +  '<font class=\'texte_dispo_petit\'>( Mise à jour le : ' + date_maj + ' à ' + heure_maj + ')</font>';
		}
		
		
		///if(produits[0].getElementsByTagName("zoom")[0].firstChild.nodeValue != 'sansphoto')
			zoom = produits[0].getElementsByTagName("zoom")[0].firstChild.nodeValue;
		
		titre_prod = produits[0].getElementsByTagName("titre_prod")[0].firstChild.nodeValue;
		
		if(document.getElementById('image') != null){
			if(document.getElementById('zoom') != null && zoom != null && ''+zoom != 'sansphoto')
				document.getElementById('image').innerHTML = '<a href="javascript:ShowZoom(\'http://www.pc21.fr/zoom/'+zoom+'\');" class=\'lien\' ><img src=\'http://www.pc21.fr/img-prod/grand/'+ img_prod + '\' border=\'0\' onMouseOver="ShowBulle(\''+titre_prod+'\')" onMouseMove="ShowBulle(\''+titre_prod+'\')" onMouseOut="HideBulle()"></a>';
			else
				document.getElementById('image').innerHTML = '<img src=\'http://www.pc21.fr/img-prod/grand/'+ img_prod + '\' border=\'0\' onMouseOver="ShowBulle(\''+titre_prod+'\')" onMouseMove="ShowBulle(\''+titre_prod+'\')" onMouseOut="HideBulle()">';
				
			if(document.getElementById('zoom') != null && ''+zoom != 'sansphoto' ){
				document.getElementById('zoom').innerHTML = '<a href="javascript:ShowZoom(\'http://www.pc21.fr/zoom/'+zoom+'\');" class=\'lien\' >Zoom</a>';
			}
		}
		
		if(dispo != -2 && remise >= 5){
			document.getElementById('remise').innerHTML = '<table width=\'80\' height=\'80\'><tr><td width=\'80\' style=\'background-image:url(/img-graph/reduction.gif); background-repeat:no-repeat; background-position:center; \'><font face=\'Arial, Helvetica, sans-serif\' color=\'#FFFFFF\'  size=\'4\' style=\'font-weight:bold \'><div align=\'center\' ><b>-' +  remise + '%</b></div></font></td></tr></table>';
		}
		
		//alert(remise);
		
		if(type_client == 0){
			chaine_prix = chaine_prix + '<center><table border=\'0\'><tr><td width=\'100%\' align=center >';
			if(dispo != -2 ){
				if(''+date_fin_promo != 'nc'){
					chaine_prix = chaine_prix + '<span class=\'texte_rouge_gras\'>PROMOTION</span> <span class=\'texte_noir\'>valable jusqu\'au : </span><span class=\'texte_rouge_gras\'>'+date_fin_promo+'</span><br><span class=\'texte_noir\'>(commandes saisies avant 12H00 sous réserve de disponibilité du stock alloué prix modifiables sans préavis)</span><br></td></tr><tr><td width=\'100%\' align=center >&nbsp;</td></tr><tr><td width=\'100%\' align=center >';
				}
				
				chaine_prix = chaine_prix + '<span class=\'texte_gris_fonce_gras\'>Votre prix : </span><span class=\'prix_ht\' style=\'border:1px solid #cc3300; border-bottom:2px solid #cc3300; border-right:2px solid #cc3300; background-color:#FFFF00;\'>&nbsp;'+prix_ht+'&nbsp;&euro;&nbsp;HT </span>'
				if(parseInt(prix_public_ht) > 0 && remise >= 5){
					chaine_prix = chaine_prix + '&nbsp;<span class=\'texte_gris\'> au lieu de ' + prix_public_ht + ' &euro;&nbsp;HT</span>';
				}
				
				if( ''+taxes != 'nc'){
					chaine_prix = chaine_prix + '</td></tr><tr><td align=center width=\'100%\'>&nbsp;<span class=\'texte_gris\'>dont Taxes incluses (Eco-Part, RPCP, Copy) : '+taxes+'&nbsp;&euro;&nbsp;HT</span>';
				}
			}
			
			chaine_prix = chaine_prix + '</td></tr><tr><td align=center width=\'100%\'>';
			
			if(dispo != -2 ){
				chaine_prix = chaine_prix + '<span class=\'texte_gris_fonce_gras\'>soit : </span> <span class=\'prix_ttc\'>' +  prix_ttc + ' &euro;&nbsp;TTC </span>';
				if(parseInt(prix_public_ttc) > 0 && remise >= 5){
					chaine_prix = chaine_prix + '<span class=\'texte_gris_fonce\'>au lieu de ' + prix_public_ttc + ' &euro;&nbsp;TTC</span>';
				}
			}
			
			chaine_prix = chaine_prix + '</td></tr></table></center>'
		}
		
		
		
		if(type_client == 1){
			chaine_prix = chaine_prix + '<center><table border=\'0\'><tr><td width=\'100%\' >';
			if(dispo != -2){
				chaine_prix = chaine_prix + '<span class=\'texte_gris_fonce_gras\'>Votre prix : </span> <span class=\'prix_ht\' style=\'border:1px solid #cc3300; border-bottom:2px solid #cc3300; border-right:2px solid #cc3300; background-color:#FFFF00;\'>&nbsp;'+prix_ht+'&nbsp;&euro;&nbsp;HT </span>';
				if(parseInt(prix_public_ht) > 0 && remise >= 5){
					chaine_prix = chaine_prix + '&nbsp;<span class=\'texte_gris\'> au lieu de ' + prix_public_ht + ' &euro;&nbsp;HT</span>';
				}
			}
			
			chaine_prix = chaine_prix + '</td></tr><tr><td align=center width=\'100%\'>';
			
			if(dispo != -2){
				chaine_prix = chaine_prix + '<span class=\'texte_gris_fonce_gras\'>soit : </span> <span class=\'prix_ttc\'>' +  prix_ttc + ' &euro;&nbsp;TTC </span>';
				if(parseInt(prix_public_ttc) > 0 && remise >= 5){
					chaine_prix = chaine_prix + '<span class=\'texte_gris_fonce\'>au lieu de ' + prix_public_ttc + ' &euro;&nbsp;TTC</span>';
				}
			}
			
			chaine_prix = chaine_prix + '</td></tr></table></center>';
		}
		
		
		
		if(type_client == 2){
			chaine_prix = chaine_prix + '<center><table border=\'0\' ><tr><td width=\'100%\' >';
			if(dispo != -2){
				chaine_prix = chaine_prix + '<span class=\'texte_gris_fonce_gras\'>Votre prix : </span> <span class=\'prix_ht\' style=\'border:1px solid #cc3300; border-bottom:2px solid #cc3300; border-right:2px solid #cc3300; background-color:#FFFFFF;\'>' + prix_ttc + '&nbsp;&euro;&nbsp;TTC </span>';
				if(parseInt(prix_public_ttc) > 0 && remise >= 5){
					chaine_prix = chaine_prix + '&nbsp;<span class=\'texte_gris\'> au lieu de ' + prix_public_ttc + ' &euro;&nbsp;TTC</span>';
				}
			}
			chaine_prix = chaine_prix + '</td></tr></table></center>';
		}
		
		document.getElementById('prix').innerHTML = chaine_prix;
		
		
		if(dispo != -2){
			chaine_caddie = chaine_caddie + '<br>';
			if(dispo == 0){
				if(chaine_qte_maj != ''){
					chaine_caddie = chaine_caddie + '<center><table border=\'0\' style=\' background-color:#00CC00 \'><tr><td>&nbsp;</td><td align=\'center\'><font class=\'texte_dispo\'>DISPONIBLE</font><br>'+chaine_qte_maj+'<br><font class=\'texte_dispo\'>Exp&eacute;di&eacute;&nbsp;en&nbsp;24/48&nbsp;H</font></td><td>&nbsp;</td></tr></table><br>';
					chaine_caddie = chaine_caddie + '<table><tr><td><a href=\'javascript:ShowCaddie('+id+');\' ><img src=\'/img-graph/valid_panier.gif\' alt=\'Ajouter ce produit à votre panier\' border=\'0\'></a> </td></tr></table></center>';
				}else{
					chaine_caddie = chaine_caddie + '<center><table border=\'0\' style=\' background-color:#00CC00 \'><tr><td>&nbsp;</td><td align=\'center\'><font class=\'texte_dispo\'>DISPONIBLE<br>Exp&eacute;di&eacute;&nbsp;en&nbsp;24/48&nbsp;H</font></td><td>&nbsp;</td></tr></table><br>';
					chaine_caddie = chaine_caddie + '<table><tr><td><a href=\'javascript:ShowCaddie('+id+');\' ><img src=\'/img-graph/valid_panier.gif\' alt=\'Ajouter ce produit à votre panier\' border=\'0\'></a> </td></tr></table></center>';
				}
			}else{
				if(dispo == -1){
					if(''+delai_dispo != 'nc'){
						if(parseInt(delai_dispo) > 0 && parseInt(delai_dispo) <= 20){
							chaine_caddie = chaine_caddie + '<center><table border=\'0\' style=\' background-color:#FF9900 \'><tr><td>&nbsp;</td><td align=\'center\'><font class=\'texte_dispo\'>SUR COMMANDE<br>D&eacute;lai&nbsp;indicatif&nbsp;de&nbsp;'+delai_dispo+'&nbsp;Jours&nbsp;environ&nbsp;(&nbsp;non&nbsp;garanti&nbsp;)</font></td><td>&nbsp;</td></tr></table><br>';
							chaine_caddie = chaine_caddie + '<table><tr><td><a href=\'javascript:ShowCaddie('+id+');\' ><img src=\'/img-graph/valid_panier.gif\' alt=\'Ajouter ce produit à votre panier\' border=\'0\'></a></td></tr></table></center>';
						}else{
							chaine_caddie = chaine_caddie + '<center><table border=\'0\' style=\' background-color:#FF0000 \' cellpadding=10 cellspacing=10 ><tr><td>&nbsp;</td><td align=\'center\'><a href=\'/nous_contacter.php?id_service=31&demande_specifique=1&ref_pc21='+ref_pc21+'\' class=\'lien_dispo_gras\'>D&eacute;lai&nbsp;:&nbsp;nous&nbsp;consulter</a></td><td>&nbsp;</td></tr></table></center>';
						}
					}else{
						chaine_caddie = chaine_caddie + '<center><table border=\'0\' style=\' background-color:#FF9900 \'><tr><td>&nbsp;</td><td><font class=\'texte_dispo\'>SUR&nbsp;COMMANDE</font></td><td>&nbsp;</td></tr></table><br>';
						chaine_caddie = chaine_caddie + '<table><tr><td align=\'center\'><a href=\'javascript:ShowCaddie('+id+');\' ><img src=\'/img-graph/valid_panier.gif\' alt=\'Ajouter ce produit à votre panier\' border=\'0\'></a></td></tr></table></center>';
					}
				}else{
					if(dispo == -3){						
						chaine_caddie = chaine_caddie + '<center><table border=\'0\' style=\' background-color:#000099 \'><tr><td>&nbsp;</td><td align=\'center\'><font class=\'texte_dispo\'>PRE-COMMANDE<br><table cellpadding="0" cellspacing="0" border="0"><tr><td><span class=\'texte_dispo\'>Prochain appro : </span></td><td><img src=\'/img-graph/prochaine_appro.png\'></td><td><span class=\'texte_dispo\' >&nbsp;'+qte_appro+'</span></td></tr></table>Annoncé&nbsp;pour&nbsp;le&nbsp;'+date_appro+'&nbsp;(non garanti)';
						if(''+source_delai != 'nc')
							chaine_caddie = chaine_caddie + '<br>Délai&nbsp;annoncé&nbsp;par&nbsp;'+source_delai+'</font>';
						
						chaine_caddie = chaine_caddie + '<br>'+chaine_qte_maj+'</td><td>&nbsp;</td></tr></table><br>';
						chaine_caddie = chaine_caddie + '<table><tr><td><a href=\'javascript:ShowCaddie('+id+');\' ><img src=\'/img-graph/valid_panier.gif\' alt=\'Ajouter ce produit à votre panier\' border=\'0\'></a> </td></tr></table></center>';
					}
				}
			}
		}else{
			chaine_caddie = chaine_caddie + '<center><table border=\'0\' style=\' background-color:#FF0000 \' ><tr><td>&nbsp;</td><td align=\'center\'><font class=\'texte_dispo\'>EPUISE&nbsp;ET&nbsp;ARRETE<br>nous contacter pour conna&icirc;tre<br>le produit de remplacement en cliquant&nbsp;<a href=\'/nous_contacter.php?id_service=31&demande_specifique=2&ref_pc21='+ref_pc21+'\' class=\'lien_blanc_gras\'>ICI</a></font></td><td>&nbsp;</td></tr></table></center>';
		}
		
		document.getElementById('caddie').innerHTML = chaine_caddie;
		
		
		
		
	}
}
