/*FONCTION AJAX*/
function getXhr(){
	var xhr = null; 
	if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){
		try{
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else{
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		xhr = false; 
	} 
	return xhr
}

/*AFFICHE AVEC AJAX*/
function ouvre_page(div,page,variable,type){
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			document.getElementById(div).innerHTML = xhr.responseText;
		}
	}
	xhr.open(type,page,true);
	if(type=="POST"){
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send(variable);
	}
	else xhr.send(null);
}

/*AFFICHE OU MASQUE DES BLOCS*/
function display_block(bloc) {
	if(document.getElementById(bloc).style.display == 'block') document.getElementById(bloc).style.display = 'none';
	else document.getElementById(bloc).style.display = 'block';
}

/*RECUPERER LA VALEUR COCHEE D'UN BOUTON RADIO*/
function testerRadio(radio){
	for(var i=0;i<radio.length;i++){
		if(radio[i].checked) return radio[i].value;
	}
}

/*AFFICHER UN FLASH*/
function RunFoo(swf, hauteur, largeur){
	document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+hauteur+"\" height=\""+largeur+"\">");
	document.write("<param name=\"movie\" value=\""+swf+"\" />");
	document.write("<param name=\"quality\" value=\"high\" />");
	document.write("<param name=\"menu\" value=\"false\" />");
	document.write("<param name=\"wmode\" value=\"transparent\" />");
	document.write("<embed src=\""+swf+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" menu=\"false\" width=\""+hauteur+"\" height=\""+largeur+"\" wmode=\"transparent\"></embed>");
}

/*AJOUTER UN VIN DANS LE PANIER*/
function ajout_panier(id){
	ouvre_page('nb_panier','gestion_panier.php?id='+id+'&nouveau=ok','','GET');
	document.getElementById('ajout_panier_'+id).style.display = 'none';
	document.getElementById('suppr_panier_'+id).style.display = 'block';
}

/*SUPPRIMER UN VIN DU PANIER*/
function suppr_panier(id){
	ouvre_page('nb_panier','gestion_panier.php?id='+id+'&enlever=ok','','GET');
	document.getElementById('ajout_panier_'+id).style.display = 'block';
	document.getElementById('suppr_panier_'+id).style.display = 'none';
}

/*MODIFIER LA QUANTITE*/
function new_qte(id,type){
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			var reponse = xhr.responseText;
			var explode_reponse = reponse.split('/');
			
			document.getElementById('qte_panier_'+id).innerHTML = explode_reponse[0];
			document.getElementById('prix_ht_'+id).innerHTML = explode_reponse[1]+' &euro;';
			document.getElementById('prix_ttc_'+id).innerHTML = explode_reponse[2]+' &euro;';
			document.getElementById('prix_total').innerHTML = explode_reponse[3]+' &euro;';
			document.getElementById('moins_qte_'+id).style.display = explode_reponse[4];
		}
	}
	xhr.open('GET','gestion_panier.php?id='+id+'&type='+type+'&modif_qte=ok',true);
	xhr.send(null);
}

