function file(fichier)
{
	if(window.XMLHttpRequest) // FIREFOX
	  xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) // IE
	  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else 
	  return(false); 
	xhr_object.open("GET", fichier, false); 
	xhr_object.send(null); 
	if(xhr_object.readyState == 4) return(xhr_object.responseText);
	else return(false);
}


function popup(href, id, w, h, r, s) {
	window.open(href, id, 'width='+(parseInt(w)+20)+',height='+(parseInt(h)+20)+',resizable='+r+',scrollbars='+s+',toolbar=0,directories=0,status=0,menubar=0');
}

function affectPrix(bon_achat_id,valeur,panier,ports)
{
	if(panier>0)
	{
		if(document.getElementById(bon_achat_id).checked)
		{
			texte = file('/ajax/ajax_ba.php?bon_achat_id='+ bon_achat_id);
			if(texte=="ok")
			{
				document.getElementById(bon_achat_id).checked=true;
				$('total').innerHTML=Math.round((parseFloat(panier) - parseFloat(valeur))*100)/100;
			}
			else if(texte=="ok2")
			{
				//document.getElementById(bon_achat_id).disabled=true;
				//$('total').innerHTML=Math.round((parseFloat(panier) - parseFloat(valeur))*100)/100;
				$('total').innerHTML=ports;
				
				erreur_ba = file('/ajax/ajax_txt.php?erreur_ba=1');
				alert(erreur_ba);
			}
			else
			{
				document.getElementById(bon_achat_id).checked=false;
				alert(texte);
			}
		}
		else
		{
			texte = file('/ajax/ajax_ba.php?del=1&bon_achat_id='+ bon_achat_id);
			$('total').innerHTML=panier;
		}
	}
	else
	{
		alert("Le montant de votre panier est nul, vous ne pouvez pas utiliser vos bons d'achat");		
	}
}

function SecureConfirm(obj)
{
	if(confirm('Voulez-vous supprimer votre adresse du carnet ?')) {
		obj.submit();
	}else{
		return false;
	}
}



function envoyerami(obj)
{
		new Ajax(
		'/ajax/envoyerami.php',
		{
			method: 'post',
			data:$(obj).toQueryString(),
			onComplete: function(req) {
				arr = req.split('|');
				if(arr[0] == 'ok')
				{
					$('rollamis').style.display = "none";
					document.forms['send_friend'].reset();
				}

				alert(arr[1]);
			},			
			evalScripts: true
		}
	).request();
}

function ActionSelect(Objet){  
	var val = Objet.value.toLowerCase();       
	var dest;        
	switch(val){            
		case "nouvelle_adresse" :                
			dest="/account_address_book.html?cmd=add&amp;origin=panier";                
			break;            
		default:                
			return false;            
	}        
	location.href=dest;
}



function showHide(id) {
	
	var obj = document.getElementById(id);

	if (obj.style.display == 'inline')
	{
		obj.style.display = 'none'
	}else{
		obj.style.display = 'inline'
	}	
	
}

var curForm = false;

function addNewsletter(obj)
{
	
	curForm = obj;
	new Ajax(
		obj.action,
		{
			data:$(obj).toQueryString(),
			onComplete: function(txt)
			{
				alert(txt);
				curForm.reset();
			}
		}
	).request();
}



function displayError(txt)
{
	alert(txt);	
	if(txt.indexOf('notre') != -1)
		curForm.reset();
}




function check_add_panier(toto)
{
	if(!toto)
		nVarNom = prompt("Entrez un nom pour votre panier :");
	else
		nVarNom = prompt("Vous devez entrer un nom pour votre panier :");
		
	if(nVarNom != null) //check_add_panier('toto')
	{
		if(!nVarNom)
			check_add_panier('toto');
		else
		{
			document.forms['savepanier'].elements['panier_nom'].value = nVarNom;	
			document.forms['savepanier'].submit();	
		}
			
		
	}
		
		//document.forms['savepanier'].submit();	
}


var fondDiv = false;
var dataDiv = false;

function addPanier(idForm)
{
	if(!fondDiv){
		fondDiv = document.createElement('div');
		fondDiv.style.position = 'absolute';
		document.body.appendChild(fondDiv);
	}
	fondDiv.innerHTML = '';
	//alert(getHeight());

	$(fondDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '100%',
	   height: getScrollHeight(),
	   position: 'absolute',
	   opacity: '0.5',
	   overflow: 'hidden',
	   top: '0px',
	   zIndex: '1500',
	   visibility: 'hidden'
	});

	if(!dataDiv){
		dataDiv = document.createElement('div');
		dataDiv.style.position = 'absolute';
		document.body.appendChild(dataDiv);
	}

	$(dataDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '500px',
	   height: '250px',
	   position: 'absolute',
	   border: '1px solid #000',
	   top: '50%',
	   left: '50%',	   
	   marginLeft: '-250px',	   
	   marginTop: (getScrollTop()-125) + 'px',	   	   	   
	   zIndex: '1600',
	   visibility: 'hidden'
	});

	new Ajax(
		'/panier-change-ajax.php',
		{
			method: 'get',
			update: dataDiv,
			data:$(idForm).toQueryString() + '&' + $('majimage').toQueryString(),
			onSuccess: function(req) {
				$$(fondDiv).setStyles({visibility: 'visible' });
				$$('select').setStyles({visibility: 'hidden' });
				$$('select.visiblect').setStyles({visibility: 'visible' });				
				$$(dataDiv).setStyles({visibility: 'visible' });

				new Ajax(
					'/ajax/updatePanier.php',
					{
						update: $('spanpan')
					}
				).request();
				
			},
			evalScripts: true
		}
	).request();
	
}


function removeDivPanier()
{
	if(fondDiv){
		$(fondDiv).remove();
		fondDiv = false;
	}	

	if(dataDiv){
		$(dataDiv).remove();
		dataDiv = false;
	}	
	
	$$('select').setStyles({visibility: 'visible' });		
}


function checkEtape(status,obj)
{
	//alert(status+' '+obj);
	//alert($(obj).toQueryString());

	
	if(status)
	{
		if($('verifcote'))
		{
			checkCote($('verifcote').value, obj);
		}	
		else
		{
			obj.submit();
		}
	}
	
}

var ministatus = false;

function checkCote(what, form) {
	
	
	new Ajax(
		'/ajax/checkcote.php',
		{
			method: 'post',
			data:$('form_etape3').toQueryString() + '&what='+ what,
			onComplete: function(req) {
				
				req = req.split('|');
				
				if(req[0] == 'ok')
				{
					form.submit();
				}
				else
				{
					alert(req[1]);
				}
			},
			evalScripts: true
		}
	).request();
}

function processPanier(v, id){ 
	
	var save = document.getElementById('qte'+id).value;

	if (v == "plus") {
		document.getElementById('qte'+id).value = parseInt(save,10) + 1; 
	}else{
		document.getElementById('qte'+id).value = save-1; 

	}
}


function updatePrixTableau(obj){
	new Ajax(
		'/ajax/prixtableau.php',
		{
			method: 'post',
			update: $('prix_final'),
			data:$('produit').toQueryString(),
			evalScripts: true
		}
	).request();
}

function updatePrix(obj){
	
	
	new Ajax(
		'/ajax/updateprix.php',
		{
			method: 'post',
			update: $('prix_final'),
			data:$('produit').toQueryString(),
			evalScripts: true
		}
	).request();
}

function updatePrixTableau2(obj){
	if(isNaN(obj.value))
		obj.value=1;	
	else
	{	
		new Ajax(
			'/ajax/prixtableau.php',
			{
				method: 'post',
				update: $('prix_final'),
				data:$('produit').toQueryString(),
				evalScripts: true
			}
		).request();
	}
}

function updatePrix2(obj){

	if(isNaN(obj.value))
		obj.value=1;	
	else
	{
		new Ajax(
			'/ajax/updateprix.php',
			{
				method: 'post',
				update: $('prix_final'),
				data:$('produit').toQueryString(),
				evalScripts: true
			}
		).request();
	}
}



function show(what)
{
	if($(what))
		$(what).setStyles({display: 'block' });
}

function hide(what)
{
	if($(what))
		$(what).setStyles({display: 'none' });
}

function switchdis(id)
{
	if($(id+'_qte').disabled == true)
	{
		$(id+'_qte').value = 1;
		$(id+'_qte').disabled = '';
		$(id+'_qte').onchange();
	}
	else
	{
		$(id+'_qte').value = 0;
		$(id+'_qte').disabled = 'disabled';
		$(id+'_qte').onchange();
	}

}

function switchretombee(id)
{
	if(id == 116)
	{
		$('retombee-div').style.display = 'block';
		$('produit_taille_retombee').disabled = '';
	}
	else
	{
		$('retombee-div').style.display = 'none';
		$('produit_taille_retombee').disabled = true;
	}
}

function verifEsc(id)
{
	arrArt = $$('#produit_esc_id2 option');
	arrArt_beta = $$('#produit_esc_id_beta option');

	numArt = arrArt.length;
	numArt2 = arrArt_beta.length;
		
	if(id == 140 || id == 141 || id == 152)
	{
		
			document.getElementById('produit_esc_id2').options.length = 0;
			var obj = document.getElementById('produit_esc_id2');

			for(i=0;i < numArt2;i++)
			{
				if(arrArt_beta[i].value != '151')
					obj.options[obj.options.length] = new Option(arrArt_beta[i].text,arrArt_beta[i].value);
			}


	}
	else
	{

			document.getElementById('produit_esc_id2').options.length = 0;
			var obj = document.getElementById('produit_esc_id2');

			for(i=0;i < numArt2;i++)
			{
				obj.options[obj.options.length] = new Option(arrArt_beta[i].text,arrArt_beta[i].value);
			}


	}
}

function verifEsc2(id)
{
	
	if(id == 140 || id == 141 || id == 152)
	{
		$('esc_151').style.display = 'none';
		$('aucun_150').checked = true;
	}
	else
	{
		$('esc_151').style.display = 'block';	
	}

}

function switch_adr_livr_fac(obj)
{
	if(obj.checked == true)
	{
		arrinput = $$('#adresse_factu_table input');

		for(i=0;i < arrinput.length;i++)
		{
			arrinput[i].disabled=true;
		}		
		
		arrinput = $$('#adresse_factu_table select');

		for(i=0;i < arrinput.length;i++)
		{
			arrinput[i].disabled=true;
		}		


	}
	else
	{

		arrinput = $$('#adresse_factu_table input');

		for(i=0;i < arrinput.length;i++)
		{
			arrinput[i].disabled=false;
		}		
		
		arrinput = $$('#adresse_factu_table select');

		for(i=0;i < arrinput.length;i++)
		{
			arrinput[i].disabled=false;
		}	
		
	}
	
	obj.disabled = false;	
}