function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function raz_menu(menu_actif){
	if(menu_actif!=1)	document.form1.epoque.selectedIndex=0;
	if(menu_actif!=2)	document.form1.categorie.selectedIndex=0;
	if(menu_actif!=3)	document.form1.taille.selectedIndex=0;
}

function change_txt_results(champ,toThis){
	if (document.getElementById)
    {
    document.getElementById(champ).innerHTML = toThis;
    }
  else if (document.all) 
    {
    document.all[champ].innerHTML = toThis;
    }

}

function show_hide(champ,toThis){
	if (document.getElementById)
    {
    document.getElementById(champ).style.display = toThis;
    }
  else if (document.all) 
    {
    document.all[champ].style.display= toThis;
    }

}

function add_panier(id){

		var poststr = "id_a_ajouter="+id ;
		makePOSTRequest('panier.php', poststr,"panier");
		maction="";
}

function supp_panier(id){

		var poststr = "id_a_supprimer="+(id+1) ;
		makePOSTRequest('panier.php', poststr,"paniersupp");
		maction="";
}

function change_region_livraison(region){
		var poststr = "region_livraison="+region ;
		makePOSTRequest('panier.php', poststr,"region");
		maction="";	
}

function frais_livraison(frais){
		var poststr = "frais_livraison="+frais ;
		makePOSTRequest('panier.php', poststr,"frais");
		maction="";	
}
 
//envoi des informations vers la bdd
 var http_request = false;
 var mresultat;
 
   function makePOSTRequest(url, parameters,todo) {
   
   	var xhr_object = null;
	
	if(window.XMLHttpRequest) // Firefox
	   xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
	   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	   return;
	}

	xhr_object.onreadystatechange = function alertContents() {
      if (xhr_object.readyState == 4) {
         if (xhr_object.status == 200) {
            mresultat = unescape(xhr_object.responseText);
            //alert(result);
				if(todo=="panier"){
					change_txt_results("textepanier",mresultat);
				}
				if(todo=="paniersupp"){
					//alert(mresultat);
					document.location="panier-mamzelleswing.php";
				}
				
				
         } else {
            alert('There was a problem with the request.');
         }
      }
	  }
	  xhr_object.open('POST', url, true);
	  xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xhr_object.setRequestHeader("Content-length", parameters.length);
      xhr_object.setRequestHeader("Connection", "close");
	  
	  xhr_object.send(parameters);
 }

function affiche_offert(){
	change_region_livraison(0);
	
	//change_txt_results("total_commande",prix_total_commande);
	//frais_livraison(0);
	document.location="panier-mamzelleswing.php";

}

function tarifs_horsfrance(region){
	/*change_region_livraison(region);
	document.location="panier-mamzelleswing.php";*/
	document.form3.submit();

}

flag_adresse_livraison =false;
function afficher_adresse_livraison(){
	if(flag_adresse_livraison){
		flag_adresse_livraison=false;
	}else{
		flag_adresse_livraison=true;
	}
	
	if(flag_adresse_livraison){
		show_hide("autreadresse","block");		
	}else{
		show_hide("autreadresse","none");
	}
	
}
  
function validation_form_commande(){
	myForm = MM_findObj("infos_livraison");
	message="";
	if(myForm.nom.value==""){message=message +"- Vous devez laisser votre nom\n";}
	if(myForm.prenom.value==""){message=message +"- Vous devez laisser votre prénom\n";}
	if(myForm.tel.value==""){message=message +"- Vous devez laisser votre téléphone\n";}
	if(myForm.mail.value==""){message=message +"- Vous devez laisser votre E-mail\n";}
	if(message!=""){
		alert(message);
	}else{
		myForm.submit();
	}
}
  
function go_paiement(){
	tmp = MM_findObj("validation_recap");
	if(tmp.conditions.checked){
		tmp.submit();
	}else{
		alert("Vous devez accepter les conditions générales de ventes pour passer votre commande");
	}
//ERR : 

} 

paiement_type="";

function fct_paiement_type($type){
	paiement_type =$type;
}

function paiement_action(){
	if(paiement_type){
		//alert(paiement_type);
		if(paiement_type=="CB")	location.href='paiementCB-mamzelleswing.php';
		if(paiement_type=="PAYPAL") document._xclick.submit();
		if(paiement_type=="CHEQUE")	location.href='paiementCheque-mamzelleswing.php';
	}else{
		alert("Vous devez choisir un mode de paiement.")
	}
}

