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);
}

/* Fonctions Ajax
--------------------------------*/

function sauvegarder_panier() {
	var libelle = document.getElementById('libelle');
	url = './ajax/sauvegarde_panier.cgi?libelle='+escape(libelle.value);
	texte = file(url);
	document.getElementById('contenu').innerHTML = texte;
}

function afficher_panier(id) {
	url = './proshop/ajax/afficher_panier.php?panier_id='+escape(id);
	texte = file(url);
	document.getElementById('contenu_panier').innerHTML = texte;
}

function afficher_selection_cat(lang)
{
	var liste = document.getElementById('select_fam');
	var valeur = liste.options[liste.selectedIndex].value;
	
	url = './ajax/selection_cat.cgi?fam_id='+escape(valeur)+'&Lg='+escape(lang);
	texte = file(url);
	document.getElementById('div_select_cat').innerHTML = texte;
	
	afficher_selection_sscat(lang);
}

function afficher_selection_sscat(lang)
{
	var liste = document.getElementById('select_cat');
	var valeur = liste.options[liste.selectedIndex].value;
	
	if(valeur != 'Aucune') {
		document.getElementById('val_select_cat').value = valeur;
	
		url = './ajax/selection_sscat.cgi?cat_id='+escape(valeur)+'&Lg='+escape(lang);
		texte = file(url);
		document.getElementById('div_select_sscat').innerHTML = texte;
	}
	
	var liste_sscat = document.getElementById('select_sscat');
	var valeur_sscat = liste_sscat.options[liste_sscat.selectedIndex].value;
	
	if(valeur_sscat != 'Aucune') {
		document.getElementById('val_select_sscat').value = valeur_sscat;
	
		url = './ajax/selection_sscat.cgi?cat_id='+escape(valeur)+'&Lg='+escape(lang);
		texte = file(url);
		document.getElementById('div_select_sscat').innerHTML = texte;
	}
}

function get_val_select_sscat()
{
	var liste_sscat = document.getElementById('select_sscat');
	var valeur_sscat = liste_sscat.options[liste_sscat.selectedIndex].value;
	
	document.getElementById('val_select_sscat').value = valeur_sscat;
}

/* Fonctions
--------------------------------*/
function fct_plus(item)
{
	var input = document.getElementById(item);
	var plus = parseInt(input.value) + 1;
	input.value = plus;
}

function fct_moins(item) 
{
	var input = document.getElementById(item);
	if(input.value == 1)
	{
		var plus = parseInt(input.value);
	}
	else 
	{
		var plus = parseInt(input.value) - 1;
	}
	input.value = plus;
}

function redirection(adresse)
{
	window.location.href = adresse;	
}


function verif_formulaire(item)
{	
	var qt = document.getElementById(item);
	
	if (qt.value > 0) 
	{
	   return true;
	}
	else
	{
	  window.alert("La quantit\351 saisie doit \352tre sup\351rieur ou \351gale \340 1!");
	  return false;
	}
}

function Verif_longueur(long_mini)
{
	var saisie = parseInt(document.getElementById('Saisie_Longueur').value); //On récupère ce que l'utilisateur à saisie dans la case Longueur en mm
	if(saisie < long_mini)
	{
		alert('longeur minimum '+long_mini+'mm');
		saisie = long_mini;
	} 
	
	document.getElementById('Saisie_Longueur').value = saisie;
}


function get_longueur(form)
{
	val = document.getElementById('Saisie_Longueur').value;
	form.champs_longueur.value = val;
}

function ctlsaisie(obj) 
{
	var valide = false;
	
	for (var i = 1; i < (obj.length-1); i+=1) 
	{
		if (obj.elements[i].name.substr(0,3) == 'qte' && obj.elements[i].value != 0) 
		{
			valide = true;
		} 
	}
	if (!valide)
	{
		alert ('Choisir un article et saisir la quantité en regard')
	}
	return valide;
}


function ctldelete() 
{
	nbr_select = 0;
	for (i=0;i < document.Form_Delete.Contenu_Panier.options.length;i++)
	{
		if(document.Form_Delete.Contenu_Panier.options[i].selected)
		{
			nbr_select++;
		}
	}
	
	if (nbr_select == 0) 
	{
		alert('Veuillez sélectionner un article à supprimer');
		return false;
	}
}

function popupcentree(page,largeur,hauteur,options) 
{     
	var top=(screen.height-hauteur)/2;     
    var left=(screen.width-largeur)/2;     
    window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options); 
}

function recalc(name,quantite) 
{
	alert(name+' '+quantite);
	var destination = "psm.cgi?Lg=fr&action=re_calc&"+name+"="+quantite;
	window.location.href = destination;
}


function changePageF(ref) 
{
	if ((ref.options[ref.selectedIndex].value != ' ') && (ref.selectedIndex != 0)) 
	{
		document.popupFam.result.value = ref.options[ref.selectedIndex].value;
        nPos = 0;
	}
  	else 
	{
		alert ("Choisissez une famille");		
	}
}

function changePageC(ref) 
{
	if ((ref.options[ref.selectedIndex].value != ' ') && (ref.selectedIndex != 0))
	{
		document.popupCat.result.value = ref.options[ref.selectedIndex].value;
		nPos = 0;
	}
	else 
	{
		alert ("Choisissez une catégorie");
		document.popupCat.result.value = '0';
	}
}

function changeGroupe(ref) 
{
	if ((ref.options[ref.selectedIndex].value != ' ') && (ref.selectedIndex != 0)) 
  	{
		document.popupGroupe.result.value = ref.options[ref.selectedIndex].value;
	  	nPos = 0;
	} 
	else 
	{
		alert ("Choisissez un groupe d'articles");
	 	document.popupGroupe.result.value = '-1'
	}
}

function condition_generale()
{
	if(document.getElementById('condition_vente').checked == false)
	{
		alert('Veuillez accepter les conditions de vente afin de continuer votre commande');
		return false;
	}
	else
	{
		return true;
	}
}

function retirer_du_panier() {

	$rep = confirm("Voulez-vous vraiment supprimer ces articles de votre commande ?");
	if($rep) {
		for($i=0; $i<document.getElementById('taille_panier').value; $i++) {
			if(document.getElementById('chk_'+$i).checked)
				document.getElementById('Quantity_'+document.getElementById('artId_'+$i).value+'.'+($i+1)).value='0';
		}
	}
	return $rep;
}

function majChk() {

	$trouve = false;
	for($i=0; $i<document.getElementById('taille_panier').value; $i++) {
		if(!document.getElementById('chk_'+$i).checked) {
			$trouve = true;
			document.getElementById('chk_all').checked = false;
			break;
		}
	}
	if(!$trouve)
		document.getElementById('chk_all').checked = true;
}

function majChk_Gen() {

	$check = document.getElementById('chk_all').checked;
	for($i=0; $i<document.getElementById('taille_panier').value; $i++) {
		document.getElementById('chk_'+$i).checked = $check;
	}
}

function afficher(item)
{
	var div = document.getElementById(item);
	if (div.style.display == "none"){
	  div.style.display = "";
	}
	else {
	  div.style.display = "none";
	}
} 

function NewWindow(mypage, myname, w, h, scroll) 
{
	var winl = 20;
	var wint = 20;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function supp_champs_spe(value,ligne)
{
	mode = document.getElementById('mode_choix_'+ligne);
	
	if(value == false)
	{
		mode.value = 'off';
	}
	else
	{
		mode.value = 'on';
	}
}

/* Script PNG
---------------------------------*/

function IE_CorrectAlpha_PNG(){
	for(i=0; i<document.images.length; i++){
		img    = document.images[i];
		imgExt  = img.src.substring(img.src.length-3, img.src.length);
		imgExt  = imgExt.toUpperCase();
		if (imgExt == "PNG"){
			imgID    = (img.id) ? "id='" + img.id + "' " : "";
			imgClass= (img.className) ? "class='" + img.className + "' " : "";
			imgTitle= (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			imgStyle= "display:inline-block;" + img.style.cssText;
			if (img.align == "left") { imgStyle = "float:left;"  + imgStyle; } else if (img.align == "right"){ imgStyle = "float:right;" + imgStyle; }
			if (img.parentElement.href)   { imgStyle = "cursor:hand;" + imgStyle; }      
			strNewHTML    = '<span '+imgID+imgClass+imgTitle+' style="width:'+img.width+'px; height:'+img.height+'px;'+imgStyle+';'+'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+img.src+'\', sizingMethod=\'image\');"></span>';
			img.outerHTML = strNewHTML;
			i = i-1;
		}
	}
}
 var userAgent=navigator.userAgent;
 if (userAgent.indexOf('MSIE') != -1) {
	  window.attachEvent("onload", IE_CorrectAlpha_PNG);
 }

