function EffaceErreur()
{
document.getElementById("result").innerHTML='';
}


function VerifChoixVersion(code)
{
var xhr=null;
    var url="";	
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { VerifChoixVersion2(xhr); };

	url="VerifChoixVersion.php?code="+code;


//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);



}

function VerifChoixVersion2(xhr)
{

    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
		var itemsresult = docXML.getElementsByTagName("result");

		
		if(itemsresult.item(0).firstChild.data=='OK')
			{
			var itemsurl = docXML.getElementsByTagName("url");
			var itemsimg = docXML.getElementsByTagName("img");
			//on fait apparaitre la bonne image
			
			document.getElementById("boutonversion").innerHTML='<img src="images/bouton_rouge_'+itemsimg.item(0).firstChild.data+'.png" onclick="location.href=\''+itemsurl.item(0).firstChild.data+'\' ">';
			
			}
		else
			{
			document.getElementById("result").innerHTML='Code incorrect';
			}

	}

}

function AfficheFact()
{
	if(document.getElementById("boutonfact").checked==true)
		Effect.Appear("LEFORMULAIREFACT");
	else
		document.getElementById("LEFORMULAIREFACT").style.display='none';

	
	
}



function AjoutePanier(idsession,ref,ajoutSuppr)
{

var xhr=null;
    var url="";	
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { AjoutePanier2(xhr); };

	url="ajoutepanier.php?session="+idsession+"&ref="+ref+"&ajoutSuppr="+ajoutSuppr;


//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);




}

function AjoutePanier2(xhr)
{
    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
		var itemssession = docXML.getElementsByTagName("session");
		var itemsref = docXML.getElementsByTagName("ref");
		var itemsdesi = docXML.getElementsByTagName("desi");
		var itemspx = docXML.getElementsByTagName("px");
		var itemspds = docXML.getElementsByTagName("pds");
		var itemstva = docXML.getElementsByTagName("tva");
		var itemsquantite = docXML.getElementsByTagName("quantite");
		var itemstotalPds = docXML.getElementsByTagName("totalPds");
		var itemstotalHT = docXML.getElementsByTagName("totalHT");
		var itemstotalQuantite = docXML.getElementsByTagName("totalQuantite");


		if(itemstotalQuantite.item(0).firstChild.data <=1)
		chainePanier="Votre Panier contient "+itemstotalQuantite.item(0).firstChild.data+" Article.";
		else
		chainePanier="Votre Panier contient "+itemstotalQuantite.item(0).firstChild.data+" Articles.";
		
		
		chainePanier=chainePanier+"<div style='padding-left:140px;padding-top:10px;height:20px;background:url(images/detail_valid.jpg) right no-repeat;cursor:hand' onclick=\"Effect.Appear('LEPANIER');\"></div>";

		
		tableau="";
		
		Idsession=itemssession.item(0).firstChild.data;
		
		document.getElementById("entetepanier").innerHTML=chainePanier;
		
		tableau=tableau+"<table align='center' class='Style0'><tr><td><img src='images/Logo_SFTA_100.jpg'></td><td>VOTRE PANIER</td></tr></table>";
		
		tableau=tableau+"<table cellspacing='0' cellpadding='0' style='border:#000000 1px solid;' align='center' class='Style0'><tr bgcolor='#c0c0c0' class='Style0bold'><td align='center'>Ref.</td><td align='center'>Designation</td><td align='center'>Quantite</td><td align='center'>P.U</td><td align='center'>Prix HT</td><td align='center'></td><td align='center'>Supprimer 1 article</td></tr>";
		
		for (i=0;i<itemsref.length;i=i+1)
		{
		
		tableau=tableau+"<tr ><td align='center' style='border-top:#000000 1px solid;'>"+itemsref.item(i).firstChild.data+"</td><td style='border-top:#000000 1px solid;' align='center'>"+itemsdesi.item(i).firstChild.data+"</td><td style='border-top:#000000 1px solid;' align='center'>"+itemsquantite.item(i).firstChild.data+"</td><td style='border-top:#000000 1px solid;' align='right'>"+itemspx.item(i).firstChild.data+"</td><td align='right' style='border-top:#000000 1px solid;'>"+itemspx.item(i).firstChild.data * itemsquantite.item(i).firstChild.data+"</td><td style='border-top:#000000 1px solid;' align='center'>&euro;</td><td style='border-top:#000000 1px solid;cursor:hand;' align='center' onclick=\"AjoutePanier("+Idsession+",'"+itemsref.item(i).firstChild.data+"',0);\"><img src='images/poubelle.jpg'></td></tr>";
		
		}
		
		tableau=tableau+"<tr class='Style0bold'><td style='border-top:#000000 1px solid;'>&nbsp;</td><td style='border-top:#000000 1px solid;'>&nbsp;</td><td style='border-top:#000000 1px solid;'>&nbsp;</td><td style='border-top:#000000 1px solid;' align='center' bgcolor='#c0c0c0'>Total HT</td><td style='border-top:#000000 1px solid;' align='right' bgcolor='#c0c0c0'>"+itemstotalHT.item(0).firstChild.data+"</td><td bgcolor='#c0c0c0' style='border-top:#000000 1px solid;' align='center'>&euro;</td><td style='border-top:#000000 1px solid;'>&nbsp;</td></tr>";
		tableau=tableau+"</table><br><table align='center' class='Style0bold'><tr><td>Afin de calculer le port et la TVA, veuillez passer à l'étape suivante.</td></tr>";
		tableau=tableau+"<tr><td>Pour toute commande supérieure à 250 &euro; HT livrée en France Métropolitaine, le port est <b>OFFERT</b></td></tr></table>";
		
		tableau=tableau+"<div style='margin-top:100px;padding-left:0px;'><table width='90%' class='Style0' align='center' cellspacing='30'><tr><td align='center' onclick=\"Effect.Fade('LEPANIER');\" style='cursor:hand;background:#ffffff;color:#ffffff;font-weight:bold;' ><img src='images/bouton_rouge_site_retour_bout.jpg'></td><td style='cursor:hand;background:#ffffff;color:#ffffff;font-weight:bold'  align='center' onclick=\";Effect.Fade('LEPANIER');Effect.Appear('LEFORMULAIRE');\"><img src='images/bouton_rouge_etape_suiv.jpg'> </td></tr>";
		
		document.getElementById("LEPANIER").innerHTML=tableau;
		
	}
	
}

function AfficheRecap(session)
{
var xhr=null;
    var url="";	
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { AfficheRecap2(xhr); };

	url="recap.php?session="+session;
//ON FAIT PATIENTER
document.getElementById('patience').style.display='block';


//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);


}

function AfficheRecap2(xhr)
{
    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
		var itemssession = docXML.getElementsByTagName("session");
		
		var itemsip = docXML.getElementsByTagName("ip");
		
		var itemsmail= docXML.getElementsByTagName("mail");
		var itemsref = docXML.getElementsByTagName("ref");
		var itemsdesi = docXML.getElementsByTagName("desi");
		var itemspx = docXML.getElementsByTagName("px");
		var itemspds = docXML.getElementsByTagName("pds");
		var itemstva = docXML.getElementsByTagName("tva");
		var itemsquantite = docXML.getElementsByTagName("quantite");
		var itemstotalPds = docXML.getElementsByTagName("totalPds");
		var itemstotalHT = docXML.getElementsByTagName("totalHT");
		var itemstotalTTC = docXML.getElementsByTagName("totalTTC");
		var itemstotal = docXML.getElementsByTagName("total");
		var itemstotalQuantite = docXML.getElementsByTagName("totalQuantite");
		var itemsPort = docXML.getElementsByTagName("port");
		var itemsTvaTotal = docXML.getElementsByTagName("TvaTotal");
		var itemsPays = docXML.getElementsByTagName("zone");
		var itemstotalHTEtPort = docXML.getElementsByTagName("HTport");
		var itemstotalLigneHT = docXML.getElementsByTagName("totalLigneHT");
		tableau="";
		
		if(itemsip.item(0).firstChild.data=='90.41.97.15')
		tableau=tableau+"<form id='RECAPFORM' name='RECAPFORM' method='post' action='http://autodata.fr/paiementligne/call_requestV2.php'><table width='100%' cellspacing='0' cellpadding='0' style='border:#000000 1px solid;' align='center' class='Style0'><tr bgcolor='#c0c0c0' class='Style0bold'><td align='center' style='border-right:#000000 1px solid;'>Ref.</td><td align='center'>Designation</td><td align='center'>Quantite</td><td align='center'>P.U</td><td align='center'>Prix HT</td><td align='center'></td></tr>";
		else
		//tableau=tableau+"<form id='RECAPFORM' name='RECAPFORM' method='post' action='http://autodata.fr/cyberplus3d/script/call_request.php'><table width='100%' cellspacing='0' cellpadding='0' style='border:#000000 1px solid;' align='center' class='Style0'><tr bgcolor='#c0c0c0' class='Style0bold'><td align='center' style='border-right:#000000 1px solid;'>Ref.</td><td align='center'>Designation</td><td align='center'>Quantite</td><td align='center'>P.U</td><td align='center'>Prix HT</td><td align='center'></td></tr>";
		tableau=tableau+"<form id='RECAPFORM' name='RECAPFORM' method='post' action='http://autodata.fr/paiementligne/call_requestV2.php'><table width='100%' cellspacing='0' cellpadding='0' style='border:#000000 1px solid;' align='center' class='Style0'><tr bgcolor='#c0c0c0' class='Style0bold'><td align='center' style='border-right:#000000 1px solid;'>Ref.</td><td align='center'>Designation</td><td align='center'>Quantite</td><td align='center'>P.U</td><td align='center'>Prix HT</td><td align='center'></td></tr>";
				

		for (i=0;i<itemsref.length;i=i+1)
		{
		
		tableau=tableau+"<tr ><td align='center' style='border-top:#000000 1px solid;border-right:#000000 1px solid;'>"+itemsref.item(i).firstChild.data+"</td><td style='border-top:#000000 1px solid;' align='center'>"+itemsdesi.item(i).firstChild.data+"</td><td style='border-top:#000000 1px solid;' align='center'>"+itemsquantite.item(i).firstChild.data+"</td><td style='border-top:#000000 1px solid;' align='center'>"+itemspx.item(i).firstChild.data+"</td><td align='center' style='border-top:#000000 1px solid;'>"+itemstotalLigneHT.item(i).firstChild.data+"</td><td style='border-top:#000000 1px solid;' align='left'>&euro;</td></tr>";
		
		}
		
		tableau=tableau+"<tr class='Style0bold'><td style='border-top:#000000 1px solid;'>&nbsp;</td><td style='border-top:#000000 1px solid;'>&nbsp;</td><td colspan='2' style='border-top:#000000 1px solid;' align='left' bgcolor='#c0c0c0'>Total HT</td><td style='border-top:#000000 1px solid;' align='center' bgcolor='#c0c0c0'>"+itemstotalHT.item(0).firstChild.data+"</td><td bgcolor='#c0c0c0' style='border-top:#000000 1px solid;' align='left'>&euro;</td></tr>";
		
		if(itemsPort.item(0).firstChild.data=='OFFERT')
		devise='';
		else
		devise='&euro;';
		tableau=tableau+"<tr class='Style0bold'><td >&nbsp;</td><td >&nbsp;</td><td colspan='2  align='center' bgcolor='#c0c0c0'>Port</td><td  align='center' bgcolor='#c0c0c0'>"+itemsPort.item(0).firstChild.data+"</td><td bgcolor='#c0c0c0'  align='left'>"+devise+"</td></tr>";
	
		if(itemsPays.item(0).firstChild.data=='FRANCE')
		{
		//ON INCLUE TOTAL TTC, PORT
		var ApayerAuFinalAvecPort=itemstotal.item(0).firstChild.data;
		tableau=tableau+"<tr class='Style0bold'><td >&nbsp;</td><td >&nbsp;</td><td colspan='2  align='center' bgcolor='#c0c0c0'>TVA</td><td  align='center' bgcolor='#c0c0c0'>"+itemsTvaTotal.item(0).firstChild.data+"</td><td bgcolor='#c0c0c0'  align='left'>&euro;</td></tr>";
		
		
		}
		else
		{
		var ApayerAuFinalAvecPort=itemstotalHTEtPort.item(0).firstChild.data ;
		
		}
		

		
		tableau=tableau+"<tr class='Style0bold'><td >&nbsp;</td><td >&nbsp;</td><td colspan='2  align='center' bgcolor='#c0c0c0'>Total TTC</td><td  align='center' bgcolor='#c0c0c0'>"+ApayerAuFinalAvecPort+"</td><td bgcolor='#c0c0c0'  align='left'>&euro;</td></tr>";

		tableau=tableau+"</table>";
		tableau=tableau+"<br><table align='center' width='80%' class='Style0' style='border:#08204f 2px solid'>";
		tableau=tableau+"<tr><td colspan='2' align='center' style='font-weight:bold;font-size:14px;'>Le montant de votre panier s'élève à "+ApayerAuFinalAvecPort+" &euro;.</td></tr>";
		tableau=tableau+"<tr><td width='40%'>&nbsp;</td><td></tr>";
		tableau=tableau+"<tr><td  align='right' style='font-weight:bold;font-size:11px;'><input type='radio' name='paiement' id='paiementcheque' value='CAR'></td>";
		tableau=tableau+"<td>Paiement par chèque.</td></tr>";
		
		if(itemsPays.item(0).firstChild.data=='FRANCE' || itemsPays.item(0).firstChild.data=='DOMTOM')
		{
		tableau=tableau+"<tr><td align='right' style='font-weight:bold;font-size:11px;'>";
		tableau=tableau+"<input type='hidden' id='amount' name='amount' value='"+ApayerAuFinalAvecPort+"'>";	
		tableau=tableau+"<input type='hidden' id='customer_ip_address' name='customer_ip_address' value='"+itemsip.item(0).firstChild.data+"'>";		
		tableau=tableau+"<input type='hidden' id='order_id' name='order_id' value='"+itemssession.item(0).firstChild.data+"'>";		
	
		tableau=tableau+"<input checked type='radio' name='paiement' id='paiementcb' value='CB'>";
		//tableau=tableau+"</form>";
		tableau=tableau+"</td>";
		tableau=tableau+"<td>Paiement par carte bancaire. <img src='images/CLEF.gif'><img width='20px' src='images/CB.gif'><br>(<i style='font-size:10px'>Vous serez redirigé vers un espace sécurisé.</i>)</td></tr>";
		}
		else
		{
		tableau=tableau+"<tr><td align='right' style='font-weight:bold;font-size:11px;'>";
		tableau=tableau+"<div style='display:none;'><input type='radio' name='paiement' id='paiementcb' value='CB'></div>";	
		tableau=tableau+"<input checked type='radio' name='paiement' id='paiementswift' value='SWIFT'>";
		//tableau=tableau+"</form>";
		tableau=tableau+"</td>";
		tableau=tableau+"<td>Paiement par virement SWIFT.</td></tr>";

		}
		tableau=tableau+"<tr><td colspan='2' style='cursor:pointer;background:#ffffff;color:#000000' align='center' onclick=\"TestMoyenPaiement('"+itemssession.item(0).firstChild.data+"','"+ApayerAuFinalAvecPort+"');\"><img src='images/bouton_rouge_valider.png'></td><tr>";		
		tableau=tableau+"<tr><td colspan='2' style='font-weight:bold'>&nbsp;</td><tr>";

		tableau=tableau+"<div style='margin-top:10px;padding-left:0px;'><table width='100%' class='Style0' align='center'><tr><td align='left' onclick=\"Effect.Fade('LERECAP');Effect.Appear('LEFORMULAIRE');AfficheFact();\" style='cursor:pointer;background:#ffffff;color:#000000' ><img src='images/bouton_rouge_site_retour.jpg'></td><td></td></tr>";
		tableau=tableau+"<tr><td colspan='2' align='center'></td></tr></table>";
		tableau=tableau+"</form>";

		
		//ON FAIT PLUS PATIENTER
document.getElementById('patience').style.display='none';

		
		document.getElementById("contenuRecap").innerHTML=tableau;
		

		
	}
}



function TestMoyenPaiement(session,TotalTTC)
{
	
	if(document.getElementById('RECAPFORM').paiement[0].checked==false && document.getElementById('RECAPFORM').paiement[1].checked==false && document.getElementById('RECAPFORM').paiement[2].checked==false)
	{
		alert("Vous devez choisir un moyen de paiement.");
		return false;
	}
	
	if(document.getElementById('RECAPFORM').paiement[0].checked==true)
	{
		document.getElementById('paiementphraseCAR').style.display='block';
		Effect.Appear('ContenuConfirmCommande');
		FaitPDF(session,'CAR'); 	
		MajPaiementBDD(session,TotalTTC,'CAR');	
		return true;
	}
	
	if(document.getElementById('RECAPFORM').paiement[1].checked==true)
	{			
		MajPaiementBDD(session,TotalTTC,'CB');		
		
		return true;
	}
	
	if(document.getElementById('RECAPFORM').paiement[2].checked==true)
	{
		document.getElementById('paiementphraseSWIFT').style.display='block';
		MajPaiementBDD(session,TotalTTC,'SWIFT');		
		Effect.Appear('ContenuConfirmCommande');
		FaitPDF(session,'SWIFT'); 
		return true;
	}


}


function MajPaiementBDD(session,TotalTTC,paiement)
{
var xhr=null;
    var url="";	
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { MajPaiementBDD2(xhr,paiement); };

	

	url="MajPaiementBDD.php?session="+session+"&paiement="+paiement+"&totalttc="+TotalTTC;
//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);

	
}

function MajPaiementBDD2(xhr,paiement)
{
	    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
		if(paiement=='CB')
		document.getElementById('RECAPFORM').submit();
	}
}




function FaitPDF(session,paiement)
{

var xhr=null;
    var url="";	
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { FaitPDF2(xhr,session); };

	

	url="bdc.php?session="+session+"&paiement="+paiement;
//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);




}


function FaitPDF2(xhr,session)
{
    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
		var itemsnumdoc = docXML.getElementsByTagName("numdoc");
		
		//var fenetre=window.open("PDF/"+itemsnumdoc.item(0).firstChild.data+".pdf","bdc");
		
		
			

			chaine="<img src='images/bouton_rouge_devis.png' onclick=\"location.href='download.php?numdoc="+itemsnumdoc.item(0).firstChild.data+"&session="+session+"';\">";
			
			document.getElementById('telecharge').innerHTML=chaine;
			document.getElementById('telecharge').style.display='block';
		
	}

}

function CheckFormFact()
{
	
	//coté facturation
	var societefact=document.getElementById('societefact').value;
	var telfact=document.getElementById('telfact').value;
	var interlocfact=document.getElementById('interlocfact').value;
	var adrfact=document.getElementById('adrfact').value;
	var adr2fact=document.getElementById('adr2fact').value;
	var cpfact=document.getElementById('cpfact').value;
	var villefact=document.getElementById('villefact').value;
	var payscodezonefact=document.getElementById('paysfact').value;
	var zonefact=document.getElementById('zonefact').value;

	
	var payscodezonefact_explose=payscodezonefact.split('|');
	
	
	var paysfact = payscodezonefact_explose[1];
	
	
	var verif 	= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	
	
	if(societefact=="")
	{
	alert(" le champ \"société (facturation)\" est obligatoire");
	return false;
	}
	
	else if(telfact=="")
	{
	alert(" le champ \"téléphone (facturation)\" est obligatoire");
	return false;
	}

	else if(interlocfact=="")
	{
	alert(" le champ \"interlocuteur (facturation)\" est obligatoire");
	return false;
	}

	else if(adrfact=="")
	{
	alert(" le champ \"Adresse (facturation)\" est obligatoire");
	return false;
	}

	else if(cpfact=="")
	{
	alert(" le champ \"Code Postal (facturation)\" est obligatoire");
	return false;
	}
	
	
	
	
	
	
	else if(cpfact.substr(0,2)=="97" && zonefact!='DOMTOM')
	{
	alert(" le champ \"Code Postal (facturation)\" ne correspond pas à la Zone Pays (facturation), Veuillez sélectionner le pays correct dans le champs Pays (facturation)");
	return false;
	}

	else if(cpfact.substr(0,2)=="98" && zonefact=='DOMTOM')
	{
	alert(" le champ \"Code Postal (facturation)\" ne correspond pas à la Zone Pays (facturation), Veuillez sélectionner le pays correct dans le champs Pays (facturation)");
	return false;
	}


	else if(villefact=="")
	{
	alert(" le champ \"ville (facturation)\" est obligatoire");
	return false;
	}

	else if(paysfact=="")
	{
	alert(" le champ \"pays (facturation)\" est obligatoire");
	return false;
	}

	
	else if(cpfact.length!=5 && zonefact=='FRANCE')
	{
	alert("le champ \"Code Postal (facturation)\" ne correspond pas au pays (facturation)");
	return false;
	}

		
	
	
	if(cpfact.length==5 )
	{
		if(paysfact=='France')
		{
			if(cpfact.substr(0,2)>="01" && cpfact.substr(0,2)<="95")
				if( zonefact!='FRANCE')
				{
					//ici on est censé avoir un cp francais, 5 caracteres, pays=FRANCE, les 2 premiers caracteres sont compris entre 01 et 95
					alert("le champ \"Code Postal\" (facturation)ne correspond pas à la Zone Pays (facturation)");
					return false;
				}
		}
	
	}
	
	
	return true;
	
}


function CheckForm()
{
	
	//coté livraison
	var societe=document.getElementById('societe').value;
	var tel=document.getElementById('tel').value;
	var interloc=document.getElementById('interloc').value;
	var adr=document.getElementById('adr').value;
	var adr2=document.getElementById('adr2').value;
	var cp=document.getElementById('cp').value;
	var ville=document.getElementById('ville').value;
	var payscodezone=document.getElementById('pays').value;
	var zone=document.getElementById('zone').value;
	var mail=document.getElementById('mail').value;
	var com=document.getElementById('com').value; 
	
	var payscodezone_explose=payscodezone.split('|');
	
	
	var pays = payscodezone_explose[1];
		//il faut tester tout les champs
	
	
		var verif 	= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	
	
	if(societe=="")
	{
	alert("le champ \"société\" est obligatoire");
	return false;
	}
	
	else if(tel=="")
	{
	alert("le champ \"téléphone\" est obligatoire");
	return false;;
	}

	else if(interloc=="")
	{
	alert("le champ \"interlocuteur\" est obligatoire");
	return false;
	}

	else if(adr=="")
	{
	alert("le champ \"Adresse\" est obligatoire");
	return false;
	}

	else if(cp=="")
	{
	alert("le champ \"Code Postal\" est obligatoire");
	return false;
	}
	
	else if(cp.length!=5 && zone=='FRANCE')
	{
	alert("le champ \"Code Postal\" ne correspond pas à la Zone Pays");
	return false;
	}
	
	
	
	
	else if(cp.substr(0,2)=="97" && zone!='DOMTOM')
	{
	alert("le champ \"Code Postal\" ne correspond pas au champs Pays, Veuillez sélectionner le pays correspondant au Code Postal");
	return false;
	}

	else if(cp.substr(0,2)=="98" && zone!='DOMTOM')
	{
	alert("le champ \"Code Postal\" ne correspond pas au champs Pays, Veuillez sélectionner le pays correspondant au Code Postal");
	return false;
	}

	


	else if(ville=="")
	{
	alert("le champ \"ville\" est obligatoire");
	return false;
	}

	else if(pays=="")
	{
	alert("le champ \"pays\" est obligatoire");
	return false;
	}

	

   	else if (verif.exec(mail) == null)
	{
	alert("Votre email "+mail+" a une mauvaise syntaxe");
	return false;
	}
		
	
	
	if(cp.length==5 )
	{
		if(pays=='France')
		{
			if(cp.substr(0,2)>="01" && cp.substr(0,2)<="95")
				if( zone!='FRANCE')
				{
					//ici on est censé avoir un cp francais, 5 caracteres, pays=FRANCE, les 2 premiers caracteres sont compris entre 01 et 95
					alert("le champ \"Code Postal\" ne correspond pas à la Zone Pays");
					return false;
				}
				
		}
	
	}
	

	
	
	return true;
	
}




function EnregClient(idsession)
{

var xhr=null;
var boutonfact;
	
	var error=0;
	
	
	
	if(document.getElementById("boutonfact").checked==true)
	boutonfact=1;	
	else
	boutonfact=0;
	
	
		var societe=document.getElementById('societe').value;
	var tel=document.getElementById('tel').value;
	var interloc=document.getElementById('interloc').value;
	var adr=document.getElementById('adr').value;
	var adr2=document.getElementById('adr2').value;
	var cp=document.getElementById('cp').value;
	var ville=document.getElementById('ville').value;
	var pays=document.getElementById('pays').value;
	var zone=document.getElementById('zone').value;
	var mail=document.getElementById('mail').value;
	var com=document.getElementById('com').value; 

	
			//coté facturation
	var societefact=document.getElementById('societefact').value;
	var telfact=document.getElementById('telfact').value;
	var interlocfact=document.getElementById('interlocfact').value;
	var adrfact=document.getElementById('adrfact').value;
	var adr2fact=document.getElementById('adr2fact').value;
	var cpfact=document.getElementById('cpfact').value;
	var villefact=document.getElementById('villefact').value;
	var paysfact=document.getElementById('paysfact').value;
	var zonefact=document.getElementById('zonefact').value;

	
	if(boutonfact==1)
	{
		if(zonefact!=zone)
		{
			alert("la zone pays LIVRAISON et la zone pays FACTURATION doivent être identiques.\nSi c'est une erreur, nous vous prions de la corriger, \nsinon veuillez contacter notre Service Commercial (04.75.96.96.96) qui vous établira un devis personnalisé.");
			error=1;
		}
	
	}
	
	
	if(error==0)
	{








    var url="";	
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { EnregClient2(xhr,idsession); };

	
	
	
	
	com=com.replace(/'/g," ");
	com=com.replace(/\n/g,"<br>");
	com=com.replace(/"/g," ");
	
	societe=societe.replace(/'/g," ");
	societe=societe.replace(/\n/g,"<br>");
	societe=societe.replace(/"/g," ");

	societefact=societefact.replace(/'/g," ");
	societefact=societefact.replace(/\n/g,"<br>");
	societefact=societefact.replace(/"/g," ");

	tel=tel.replace(/'/g," ");
	tel=tel.replace(/\n/g,"<br>");
	tel=tel.replace(/"/g," ");

	telfact=telfact.replace(/'/g," ");
	telfact=telfact.replace(/\n/g,"<br>");
	telfact=telfact.replace(/"/g," ");

	
	interloc=interloc.replace(/'/g," ");
	interloc=interloc.replace(/\n/g,"<br>");
	interloc=interloc.replace(/"/g," ");

	interlocfact=interlocfact.replace(/'/g," ");
	interlocfact=interlocfact.replace(/\n/g,"<br>");
	interlocfact=interlocfact.replace(/"/g," ");

	
	adr=adr.replace(/'/g," ");
	adr=adr.replace(/\n/g,"<br>");
	adr=adr.replace(/"/g," ");

	adrfact=adrfact.replace(/'/g," ");
	adrfact=adrfact.replace(/\n/g,"<br>");
	adrfact=adrfact.replace(/"/g," ");
	
	adr2=adr2.replace(/'/g," ");
	adr2=adr2.replace(/\n/g,"<br>");
	adr2=adr2.replace(/"/g," ");

	adr2fact=adr2fact.replace(/'/g," ");
	adr2fact=adr2fact.replace(/\n/g,"<br>");
	adr2fact=adr2fact.replace(/"/g," ");
	
	cp=cp.replace(/'/g," ");
	cp=cp.replace(/\n/g,"<br>");
	cp=cp.replace(/"/g," ");


	cpfact=cpfact.replace(/'/g," ");
	cpfact=cpfact.replace(/\n/g,"<br>");
	cpfact=cpfact.replace(/"/g," ");

	
	ville=ville.replace(/'/g," ");
	ville=ville.replace(/\n/g,"<br>");
	ville=ville.replace(/"/g," ");

	villefact=villefact.replace(/'/g," ");
	villefact=villefact.replace(/\n/g,"<br>");
	villefact=villefact.replace(/"/g," ");

	
	pays=pays.replace(/'/g," ");
	pays=pays.replace(/\n/g,"<br>");
	pays=pays.replace(/"/g," ");

	paysfact=paysfact.replace(/'/g," ");
	paysfact=paysfact.replace(/\n/g,"<br>");
	paysfact=paysfact.replace(/"/g," ");
		
		
		
	// if(document.getElementById("formulaire").memo[0].checked==true)
	var memo=1;
	// else
	// memo=0;
	
	if(document.getElementById("formulaire").civ[0].checked==true)
	civ="M.";
	else
	civ="Mme.";

if(document.getElementById("formulairefact").civfact[0].checked==true)
	civfact="M.";
	else
	civfact="Mme.";
	
	Effect.Fade('LEFORMULAIRE');
	Effect.Fade('LEFORMULAIREFACT');
	Effect.Appear('LERECAP');
	
	
	url="EnregClient.php?boutonfact="+boutonfact+"&tel="+tel+"&session="+idsession+"&societe="+societe+"&interloc="+interloc+"&adr="+adr+"&adr2="+adr2+"&cp="+cp+"&ville="+ville+"&pays="+pays+"&zone="+zone+"&memo="+memo+"&mail="+mail+"&com="+com+"&civ="+civ+"&telfact="+telfact+"&societefact="+societefact+"&interlocfact="+interlocfact+"&adrfact="+adrfact+"&adr2fact="+adr2fact+"&cpfact="+cpfact+"&villefact="+villefact+"&paysfact="+paysfact+"&zonefact="+zonefact+"&civfact="+civfact;

	//document.write(url);
//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);

}


}
function EnregClient2(xhr,idsession)
{
    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
	AfficheRecap(idsession);
	}
}




function EnregClientCD(idsession)
{

var xhr=null;
  var url="";	
  var error=0;
  
var objet=document.getElementById('objetcd').value;
var mail=document.getElementById('mailcd').value;
var com=document.getElementById('comcd').value; 
var interloc=document.getElementById('interloccd').value;
var societe=document.getElementById('societecd').value;
	var adr=document.getElementById('adrcd').value;
	var adr2=document.getElementById('adr2cd').value;
	var tel=document.getElementById('telcd').value;
	var ville=document.getElementById('villecd').value;
	var cp=document.getElementById('cpcd').value;
	var civ=document.getElementById('civcd').value;
	var pays=document.getElementById('payscd').value;
	
var verif 	= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	if(com=="")
	{
	alert("le champ \"Commentaires\" est obligatoire");
	error=1;
	}
	
	if(interloc=="")
	{
	alert("le champ \"Interlocuteur\" est obligatoire");
	error=1;
	}
	
	if(societe=="")
	{
	alert("le champ \"Société\" est obligatoire");
	error=1;
	}

	if(adr=="")
	{
	alert("le champ \"Adresse\" est obligatoire");
	error=1;
	}
	
	if(tel=="")
	{
	alert("le champ \"Téléphone\" est obligatoire");
	error=1;
	}
	
	if(pays=="")
	{
	alert("le champ \"Pays\" est obligatoire");
	error=1;
	}
	
if(objet=="")
	{
	alert("le champ \"Objet\" est obligatoire");
	error=1;
	}



   			if (verif.exec(mail) == null)
			{
				alert("Votre email a une mauvaise syntaxe");
				error=1;
			}
			
	if(error==0)
	{
  
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { EnregClientCD2(xhr); };

	Effect.Fade('LEFORMULAIRE_CD')
	
	
	
	com=com.replace(/'/g,"--APOS--");
	com=com.replace(/\n/g,"--SDL--");
	com=com.replace(/"/g,"--GUILL--");

	adr=adr.replace(/"/g,"--GUILL--");
	adr=adr.replace(/\n/g,"--SDL--");
	adr=adr.replace(/'/g,"--APOS--");
	
	adr2=adr2.replace(/"/g,"--GUILL--");
	adr2=adr2.replace(/\n/g,"--SDL--");
	adr2=adr2.replace(/'/g,"--APOS--");

	ville=ville.replace(/"/g,"--GUILL--");
	ville=ville.replace(/\n/g,"--SDL--");
	ville=ville.replace(/'/g,"--APOS--");

	societe=societe.replace(/"/g,"--GUILL--");
	societe=societe.replace(/\n/g,"--SDL--");
	societe=societe.replace(/'/g,"--APOS--");

	interloc=interloc.replace(/"/g,"--GUILL--");
	interloc=interloc.replace(/\n/g,"--SDL--");
	interloc=interloc.replace(/'/g,"--APOS--");
	
	pays=pays.replace(/"/g,"--GUILL--");
	pays=pays.replace(/\n/g,"--SDL--");
	pays=pays.replace(/'/g,"--APOS--");

	objet=objet.replace(/"/g,"--GUILL--");
	objet=objet.replace(/\n/g,"--SDL--");
	objet=objet.replace(/'/g,"--APOS--");

	

	
	url="EnregClientCD.php?session="+idsession+"&pays="+pays+"&civ="+civ+"&mail="+mail+"&objet="+objet+"&com="+com+"&societe="+societe+"&interloc="+interloc+"&adr="+adr+"&adr2="+adr2+"&cp="+cp+"&ville="+ville+"&tel="+tel;

	
	AfficheConfirmCD();
	
	//document.write(url);
//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);

	}


}
function EnregClientCD2(xhr)
{
    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
		//ON FAIT RIEN		
	}
}




function EnvoiMail(session)
{var xhr=null;
    var url="";	
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { EnvoiMail2(xhr); };
	
	
	url="EnvoiMail.php?session="+session;
	
	//document.write(url);
//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);


}

function EnvoiMail2(xhr)
{
    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
		var itemstest = docXML.getElementsByTagName("test");
		

	}
}


function EnvoiMailContact()
{

	var xhr=null;
    var url="";	
    var error=0;
	
	var email=document.getElementById('mailcontact').value;
	var interloc=document.getElementById('interloc').value;
	var societe=document.getElementById('societe').value;
	var adr=document.getElementById('adr').value;
	var adr2=document.getElementById('adr2').value;
	var tel=document.getElementById('tel').value;
	var ville=document.getElementById('ville').value;
	var cp=document.getElementById('cp').value;
	var civ=document.getElementById('civ').value;
	var pays=document.getElementById('pays').value;
	
	var obj=document.getElementById('objetcontact').value;
	var objautre=document.getElementById('objetautrecontact').value; 
	var corps=document.getElementById('comcontact').value;
	
	var verif 	= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	
	
	if(corps=="")
	{
	alert("le champ \"Commentaires\" est obligatoire");
	error=1;
	}
	
	if(interloc=="")
	{
	alert("le champ \"Interlocuteur\" est obligatoire");
	error=1;
	}
	
	if(societe=="")
	{
	alert("le champ \"Société\" est obligatoire");
	error=1;
	}

	if(adr=="")
	{
	alert("le champ \"Adresse\" est obligatoire");
	error=1;
	}
	
	if(tel=="")
	{
	alert("le champ \"Téléphone\" est obligatoire");
	error=1;
	}
	
	if(pays=="")
	{
	alert("le champ \"Pays\" est obligatoire");
	error=1;
	}
	
		
	
	
   			
   			if (verif.exec(email) == null)
			{
				alert("Votre email a une mauvaise syntaxe");
				error=1;
			}
			
	
	
	
	if(error==0)
	{
	if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { EnvoiMailContact2(xhr); };
	
	
	corps=corps.replace(/'/g,"--APOS--");
	corps=corps.replace(/\n/g,"--SDL--");
	corps=corps.replace(/"/g,"--GUILL--");

	adr=adr.replace(/"/g,"--GUILL--");
	adr=adr.replace(/\n/g,"--SDL--");
	adr=adr.replace(/'/g,"--APOS--");
	
	adr2=adr2.replace(/"/g,"--GUILL--");
	adr2=adr2.replace(/\n/g,"--SDL--");
	adr2=adr2.replace(/'/g,"--APOS--");

	ville=ville.replace(/"/g,"--GUILL--");
	ville=ville.replace(/\n/g,"--SDL--");
	ville=ville.replace(/'/g,"--APOS--");

	societe=societe.replace(/"/g,"--GUILL--");
	societe=societe.replace(/\n/g,"--SDL--");
	societe=societe.replace(/'/g,"--APOS--");

	interloc=interloc.replace(/"/g,"--GUILL--");
	interloc=interloc.replace(/\n/g,"--SDL--");
	interloc=interloc.replace(/'/g,"--APOS--");
	
	pays=pays.replace(/"/g,"--GUILL--");
	pays=pays.replace(/\n/g,"--SDL--");
	pays=pays.replace(/'/g,"--APOS--");

	objautre=objautre.replace(/"/g,"--GUILL--");
	objautre=objautre.replace(/\n/g,"--SDL--");
	objautre=objautre.replace(/'/g,"--APOS--");
	
	url="EnvoiMailContact.php?pays="+pays+"&civ="+civ+"&from="+email+"&obj="+obj+"&objautre="+objautre+"&corps="+corps+"&societe="+societe+"&interloc="+interloc+"&adr="+adr+"&adr2="+adr2+"&cp="+cp+"&ville="+ville+"&tel="+tel;
	
	
	AfficheConfirm();
	//document.write(url);
//url=url.replace(/( )/g,"%20");
//alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);
	}

}

function EnvoiMailContact2(xhr)
{
    if (xhr.readyState==4 && xhr.status == 200) 
    {
    	var docXML= xhr.responseXML;
		
	}
}


function AfficheConfirm()
{
	
Effect.SlideDown('ContenuConfirmPanier',{duration:0.5});	
document.getElementById('confirmadress').innerHTML="<span>"+document.getElementById('mailcontact').value+"</span>";

}

function AfficheConfirmCD()
{
	
Effect.SlideDown('ConfirmEnvoiCD',{duration:0.5});	
document.getElementById('confirmadressCD').innerHTML="<span>"+document.getElementById('mailcd').value+"</span>";

}



function EffaceContact()
{
document.getElementById('mailcontact').value='';
document.getElementById('comcontact').value='';
}

