// JavaScript Document
var xhrSAV ;
////initInfosAchats();
corrHauteur = 18;
function ShowCaddie(id_prod){
		
	if (window.XMLHttpRequest) { //Navigateur FireFox
			xhrCaddie = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) //Navigateur IE 6 et plus
		{
			try {
			       xhrCaddie = new ActiveXObject("Msxml2.XMLHTTP");
			    } catch (e) {
					xhrCaddie = new ActiveXObject("Microsoft.XMLHTTP");
			   }
		}
	xhrCaddie.onreadystatechange = handleHttpResponseCaddie;
	var url = "/caddie_pc21.php?UC_AddId="+id_prod;
	xhrCaddie.open("GET", url, true);
	xhrCaddie.send(null);
}

function handleHttpResponseCaddie() {
    if(xhrCaddie.readyState == 4 && xhrCaddie.status == 200) {
		
		response = xhrCaddie.responseXML;
		var produit = response.getElementsByTagName("article");
		
		titre_prod = produit[0].getElementsByTagName("titre_prod")[0].firstChild.nodeValue;
		document.getElementById('titre_produit').innerHTML = titre_prod;
		mtt_total_ht = parseFloat(produit[0].getElementsByTagName("montant_ht")[0].firstChild.nodeValue);//Nb Montants total
		nb_articles =  parseInt(produit[0].getElementsByTagName("nb_articles")[0].firstChild.nodeValue);//Nb Article total
		id_prod =  parseInt(produit[0].getElementsByTagName("id_prod")[0].firstChild.nodeValue);//Référence du produit
		document.getElementById("caddie_popup").style.visibility='visible';
		//document.getElementById("caddie_popup").style.top=(((document.body.clientHeight - document.getElementById('caddie_popup').offsetHeight)/2) + document.body.scrollTop)+'px';
		///document.getElementById("caddie_popup").style.left=((document.body.clientWidth - document.getElementById('caddie_popup').offsetWidth)/2) + 'px';
		document.getElementById("caddie_popup").style.top=(((document.body.clientHeight - document.getElementById('caddie_popup').offsetHeight)/2) + document.body.scrollTop)+'px';
		document.getElementById("caddie_popup").style.left=((screen.width - document.getElementById('caddie_popup').offsetWidth)/2) + 'px';
		document.form_caddie_pc21.id_prod.value=id_prod;
		document.form_caddie_pc21.quantite.value=1;
		actualiseNbArticles(mtt_total_ht,nb_articles);
	}
}
function HideCaddie(){
	if(document.all){
		document.all["caddie_popup"].style.visibility='hidden';
	}else{
	
		if(document.getElementById){
			document.getElementById("caddie_popup").style.visibility='hidden';
		}
	}
	
	if(document.layers){
		document.layers["caddie_popup"].visibility='hidden';
	}
}


function initInfosAchats(){
	document.write("<div id='infos_achat' style='background-color:#FFFF99; position:absolute; display:block; z-index: 999; visibility:hidden' ></div>");
}


function ShowConseil(fichier){
	tab_conseil = "<table cellpadding='1' cellspacing='2'  style='background-color:#FFFFCC; border-color:#000099; border-style:solid; border-width:3px ' width='500'  ><tr>";
	//tab_conseil = "<table cellpadding='1' cellspacing='2'  style='border-top:#000099 solid 3px;border-left:#000099 solid 3px; border-right:#000099 solid 3px; border-bottom:#000099 solid 0px' width='500'  ><tr>";
	tab_conseil = tab_conseil + "<td align='left'  width='2' ><img src='/img-graph/puce_titre_transparent_popup.gif' border='0' ></td><td align='left' width='298' ><font class='titre_partie'>Conseil</font></td></tr>";
    tab_conseil = tab_conseil + "<tr><td>&nbsp;</td><td><font class='texte_noir'>Tél: 01 43 00 43 08 ou 01 43 00 98 47 du lundi au samedi de 8h00 à 19h00</font><br><font class='texte_noir_gras'>contact(at)pc21.fr (merci de remplacer le (at) par @)</font></td></tr>";
	if(fichier != null && ''+fichier != 'null' && fichier != ''){
		tab_conseil = tab_conseil + "<tr><td>&nbsp;</td><td ><font class='texte_noir'>Notre agrément : </font></td></tr>";
		tab_conseil = tab_conseil + "<tr><td colspan=2 >&nbsp;</td></tr><tr><td>&nbsp;</td><td align='center' ><img src=\'/logos_agrement/'+fichier+'\'/></td></tr>";
	}
	tab_conseil = tab_conseil + "<tr><td colspan=2>&nbsp;</td></tr></table><br>";
	
	var obj = document.getElementById('menu_conseil_achat');
	posConseilX = obj.offsetLeft;
	posConseilY = obj.offsetTop;
	document.getElementById('infos_achat').innerHTML = tab_conseil;
	document.getElementById("infos_achat").style.visibility='visible';
	document.getElementById("infos_achat").style.top=(posConseilY + corrHauteur - document.getElementById("infos_achat").offsetHeight)+'px';
	document.getElementById("infos_achat").style.left=(posConseilX - document.getElementById("infos_achat").offsetWidth/2 ) + 'px';
	
}

function HideConseil(){
	document.getElementById("infos_achat").style.visibility='hidden';
}

function ShowPopupPaiement(){
	tab_conseil = "<table cellpadding='1' cellspacing='2'  style='background-color:#FFFFCC; border-color:#000099; border-style:solid; border-width:3px ' width='500'  ><tr>";
	tab_conseil = tab_conseil + "<td align='left'  width='2' ><img src='/img-graph/puce_titre_transparent_popup.gif' border='0' ></td><td align='left' width='298' ><font class='titre_partie'>Paiement</font></td></tr>";
    tab_conseil = tab_conseil + "<tr><td>&nbsp;</td><td><font class='texte_noir'>- Carte Bancaire sécurisée via Pay Box (Débit de votre CB à l'expédition)<br>- Virement (Notre RIB figure dans la confirmation de commande)<br>- Chèque</font></td></tr>";
	tab_conseil = tab_conseil + "<tr><td colspan=2>&nbsp;</td></tr></table><br>";
	
	var obj = document.getElementById('menu_conseil_achat');
	posConseilX = obj.offsetLeft;
	posConseilY = obj.offsetTop;
	
	document.getElementById('infos_achat').innerHTML = tab_conseil;
	document.getElementById("infos_achat").style.visibility='visible';
	document.getElementById("infos_achat").style.top=(posConseilY + corrHauteur - document.getElementById("infos_achat").offsetHeight)+'px';
	document.getElementById("infos_achat").style.left=(posConseilX - document.getElementById("infos_achat").offsetWidth/2) + 'px';
	
}

function HidePopupPaiement(){
	document.getElementById("infos_achat").style.visibility='hidden';
}

function ShowModaliteLivraison(dispo,delai,ref){
	tab_livraison =  "<table cellpadding='1' cellspacing='2'  style='background-color:#FFFFCC; border-color:#000099; border-style:solid; border-width:3px ' width='500'  ><tr><td width='2' ><img src='/img-graph/puce_titre_transparent_popup.gif' ></td><td width='298' >&nbsp;<font class='titre_partie'>Livraison</font></td></tr>";
	tab_livraison = tab_livraison + "<tr><td>&nbsp;</td><td >";
	
	
	if(dispo == 0){
		tab_livraison = tab_livraison + "<font class=\'texte_noir\'>Colissimo Expert Remis contre Signature, UPS, ChronoPost, TAT Express, Hexa Trans en fonction des produits commandés et de la destination.</font>";
	}
	
	if(dispo == -2){
		tab_livraison = tab_livraison + "<font class=\'texte_noir\'>Colissimo Expert Remis contre Signature, UPS, ChronoPost, TAT Express, Hexa Trans en fonction des produits commandés et de la destination.</font>";
	}
	
	if(dispo == -1){
		if(delai > 0 && delai < 20){
			tab_livraison = tab_livraison + "<font class=\'texte_noir\'>Délai moyen de réapprovisionnement annoncé par notre fournisseur estimé à "+delai+" Jours environ ( Délai non garanti ). Possibilité de pré-commander ce produit en cliquant sur le panier .</font>";
		}
		
		if(delai == 0){
			tab_livraison = tab_livraison + "<font class=\'texte_noir\'>Produit sur commande.</font>";
		}
		
		if(delai >= 20){
			tab_livraison = tab_livraison + "<font class=\'texte_noir\'>Nous contacter pour savoir si ce produit peut encore être commandé ou le cas échéant connaître son produit de remplacement en cliquant</font> <a href='/nous_contacter.php?id_service=31&demande_specifique=2&ref_pc21="+ref+"' class='lien' >ICI</a>";
		}
		if(delai < 0){
			tab_livraison = tab_livraison + "<font class=\'texte_noir\'>Nous contacter pour savoir si ce produit peut encore être commandé ou le cas échéant connaître son produit de remplacement en cliquant</font> <a href='/nous_contacter.php?id_service=31&demande_specifique=2&ref_pc21="+ref+"' class='lien' >ICI</a>";
		}
	}
	
	
	tab_livraison = tab_livraison + "</td></tr><tr><td colspan=2 >&nbsp;</td></tr>"
	tab_livraison = tab_livraison + "<tr><td >&nbsp;</td><td><font class='texte_noir'>Frais de port par commande pour la France Métropolitaine :<br>entre 0 et 25 €HT - 5,50 €HT<br>entre 25 et 50 €HT - 6,65 €HT<br>entre 50 et 100 €HT - 8,00 €HT<br>supérieur à 100 €HT - 9,00 €HT<br>";
	tab_livraison = tab_livraison + "Pour toutes livraisons à l'International ou dans les D.O.M. T.O.M.,</font> <a href='/nous_contacter.php' class='lien'>nous contacter</a>.</td></tr><tr><td colspan=2>&nbsp;</td></tr></table><br>";

	var obj = document.getElementById('menu_conseil_achat');
	posConseilX = obj.offsetLeft;
	posConseilY = obj.offsetTop;
	
	document.getElementById('infos_achat').innerHTML = tab_livraison;
	document.getElementById("infos_achat").style.visibility='visible';
	document.getElementById("infos_achat").style.top=(posConseilY + corrHauteur - document.getElementById("infos_achat").offsetHeight)+'px';
	document.getElementById("infos_achat").style.left=(posConseilX - document.getElementById("infos_achat").offsetWidth/2) + 'px';

}

function HideModaliteLivraison(){
	document.getElementById("infos_achat").style.visibility='hidden';
}



function ShowSAV(id_mark){
	if (window.XMLHttpRequest) { //Navigateur FireFox
			xhrSAV = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) //Navigateur IE 6 et plus
		{
			try {
			       xhrSAV = new ActiveXObject("Msxml2.XMLHTTP");
			    } catch (e) {
					xhrSAV = new ActiveXObject("Microsoft.XMLHTTP");
			   }
		}
	xhrSAV.onreadystatechange = handleHttpResponseRecupSAV;
	var url = "/procedure_sav_pc21.php?id_mark="+id_mark;
	xhrSAV.open("GET", url, true);
	xhrSAV.send(null);
}



function HideSAV(){
	document.getElementById("infos_achat").style.visibility='hidden';
}

function handleHttpResponseRecupSAV(){
	 if(xhrSAV.readyState == 4 && xhrSAV.status == 200) {
		var responseSAV;
   		responseSAV = xhrSAV.responseXML;
		var donneesSAV = responseSAV.getElementsByTagName("pc21");
		
		tab_sav =  "<table cellpadding='1' cellspacing='2'  style='background-color:#FFFFCC; border-color:#000099; border-style:solid; border-width:3px ' width='750'  ><tr><td width='2' valign='top' ><img src='/img-graph/puce_titre_transparent_popup.gif' ></td><td colspan=2 >&nbsp;<font class='titre_partie'>Proc&eacute;dure&nbsp;du&nbsp;Service&nbsp;Après&nbsp;Vente&nbsp;"+ donneesSAV[0].getElementsByTagName("titre_mark")[0].firstChild.nodeValue+"&nbsp;pour&nbsp;les&nbsp;clients de&nbsp;PC21&nbsp;uniquement</font></td></tr>";
		tab_sav = tab_sav + "<tr><td colspan=3 >&nbsp;</td></tr>";
		tab_sav = tab_sav + "<tr><td>&nbsp;</td><td colspan=2 ><div style='border: none; overflow:auto; width: 700px; height: 200px'>"+ donneesSAV[0].getElementsByTagName("sav")[0].firstChild.nodeValue+"</div></td></tr>";
		
		tab_sav = tab_sav + "<tr><td colspan=3 >&nbsp;</td></tr></table><br>"
		
		var obj = document.getElementById('menu_conseil_achat');
		posConseilX = obj.offsetLeft;
		posConseilY = obj.offsetTop;
		
		document.getElementById('infos_achat').innerHTML = tab_sav;
		document.getElementById("infos_achat").style.visibility='visible';
		document.getElementById("infos_achat").style.top=(posConseilY  + corrHauteur - document.getElementById("infos_achat").offsetHeight)+'px';
		document.getElementById("infos_achat").style.left=(posConseilX - document.getElementById("infos_achat").offsetWidth/3) + 'px';
	 }
}
