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_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_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_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 MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function picturePopup(imageName,winName,alt) { //v1.0
	var xPos=Math.abs((screen.width-100)/2),yPos=Math.abs((screen.height-100)/2);
	newWindow = window.open('',winName,'toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,width=0,height=0,left=0,top=0');
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title>');
	newWindow.document.write('<head><script language="javascript">');
	newWindow.document.write('var NS=(navigator.appName=="Netscape")?true:false;');
	newWindow.document.write('function ajuste() {');
    	newWindow.document.write('iWidth=(NS)?window.innerWidth:document.body.clientWidth;iHeight=(NS)?window.innerHeight:document.body.clientHeight;');
    	newWindow.document.write('iWidth=document.images[0].width-iWidth;iHeight=document.images[0].height-iHeight;');
	newWindow.document.write('window.resizeBy(iWidth, iHeight);');
	newWindow.document.write('w=screen.availWidth;h=screen.availHeight;iWidth=document.images[0].width;iHeight=document.images[0].height;');
	newWindow.document.write('var leftPos=(w-iWidth)/2,topPos=(h-iHeight)/2;');
	newWindow.document.write('window.moveTo(leftPos, topPos);');
	newWindow.document.write('self.focus();');
	newWindow.document.write('}');
	newWindow.document.write('</script></head>');
	newWindow.document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onLoad="ajuste()" onBlur="self.close()">');
	newWindow.document.write('<center><img name="myImg" src='+imageName+'></center>');
	newWindow.document.write('</body></html>');
	newWindow.document.close();
}

function MM_jumpMenu(targ,selObj,restore) { //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function openFocusWindow(theURL,winName,features) { //v2.0
  newWindow=window.open(theURL,winName,features);
  newWindow.focus();
  return newWindow;
}

function FW_testField(field) {
	val = field.value;
	if (val=='' || val=='--- Mot-clé ---') {
		alert('Vous devez entrer un mot-clé');
		return false;
	} else return true;
}

function FW_counter() {
	var step,oldval,newval,obj,a=FW_counter.arguments;
	if (obj = MM_findObj(a[0])) {
		step = a[1];
		oldval = parseInt(obj.value);
		if (!oldval) oldval = 0;
		newval = oldval+step;
		if (a[2]==undefined
		|| (step>0 && newval<=a[2])
		|| (step<0 && newval>=a[2]))
			obj.value = newval;
	}
}

function chkCmd(chk, ray, fam, id) {
	switch (chk) {
		case 1: alert("Vous ne pouvez pas commander\nà partir d'un compte d'invité"); break;
		case 2: alert("Vous ne pouvez pas commander\nà partir d'un compte d'administrateur"); break;
		case 3: alert("Vous devez remplir votre fiche d'information\navant de commander. Rubrique \"Mon Compte\""); break;
		case 4: alert("Vous devez commander un minimum de 12 bouteilles\nde Champagne pour pouvoir valider votre commande"); break;
		case 5: alert("Vous devez commander un montant minimum de 50 €\nde bons d'achat\npour pouvoir valider votre commande"); break;
		case 6: alert("Chaque promotion de la cave est constituée d'un minimum de 36 bouteilles\nVous devez atteindre ce minimum pour chaque promotion choisie\npour pouvoir valider votre commande"); break;
		case 7: alert("Vous devez commander un minimum de 12 bouteilles\nde Grands Crus pour pouvoir valider votre commande"); break;
		default: window.location = 'private.php?pg=caddie&op=cgv&r='+ray+'&f='+fam+'&id='+id; break;
	}
}

function chkCGV(chk, ray, fam, id) {
	switch (chk) {
		case 1: alert("Vous ne pouvez pas commander\nà partir d'un compte de démonstration"); break;
		case 2: alert("Vous ne pouvez pas commander\nà partir d'un compte d'administrateur"); break;
		case 4: alert("Vous devez commander un minimum de 12 bouteilles\nde Champagne pour pouvoir valider votre commande"); break;
		case 5: alert("Vous devez commander un montant minimum de 50 €\nde bons d'achat\npour pouvoir valider votre commande"); break;
		default:
			var obj = MM_findObj('cgvok');
			if (obj && obj.checked) window.location = 'private.php?pg=commande&r='+ray+'&f='+fam+'&id='+id;
			else alert("Vous devez accepter les CGV\nen cochant la case correpondante");
			break;
	}
}

function chkCmd_im(chk,	id,	formName) {
	switch (chk) {
		case 1: alert("Vous ne pouvez pas commander\nà partir d'un compte d'invité"); break;
		case 2: alert("Vous ne pouvez pas commander\nà partir d'un compte d'administrateur"); break;
		case 3: alert("Vous devez remplir votre fiche d'information\navant de commander. Rubrique \"Mon Compte\""); break;
		default:
			var form = MM_findObj(formName);
			form.action = 'valid.php?pg=produit_im&id='+id;
			form.submit();
			break;
	}
}

function chkCGV_im(chk, id) {
	switch (chk) {
		case 1: alert("Vous ne pouvez pas commander\nà partir d'un compte de démonstration"); break;
		case 2: alert("Vous ne pouvez pas commander\nà partir d'un compte d'administrateur"); break;
		default:
			var obj = MM_findObj('cgvok');
			if (obj && obj.checked) window.location = 'private.php?pg=commande_im&id='+id;
			else alert("Vous devez accepter les CGV\nen cochant la case correpondante");
			break;
	}
}

function chkLiv(chk, direct) {
	$$('#livraison input').each(function(item)
	{
		if(item.type != 'checkbox') {
			item.disabled = !chk;
			item.className = (chk ? '' : 'dis') + 'field';
		}
	});
	if (!direct) $('livraison_coopef').checked = false;
}

function chkLivCoopef(chk) {
	if (chk) {
		$('frais_port').hide();
		$('total_port').hide();
		$('ht_port').hide();
		$('no_port').show();
		$('total_noport').show();
		$('ht_noport').show();
	} else {
		$('frais_port').show();
		$('total_port').show();
		$('ht_port').show();
		$('no_port').hide();
		$('total_noport').hide();
		$('ht_noport').hide();
	}
	$('livraison_autre').checked = false;
	chkLiv(false, true);
}

function delMsg(box,msg) {
	result = confirm("Etes-vous sûr de vouloir supprimer\ndéfinitivement ce message ?");
	if (result) window.location = 'valid.php?pg=inbox&op=del&box='+box+'&id='+msg;
}

function delAllMsg(box,objName,formName) {
	var obj = MM_findObj(objName);
	var test = false;
	if (obj!=null) {
		if (obj.length>1) {
			for (i=0;i<obj.length;i++) {
				test = obj[i].checked;
				if (test) break;
			}
		} else test = obj.checked;
			
		if (test) {
			result = confirm("Etes-vous sûr de vouloir supprimer\ndéfinitivement les messages sélectionnés ?");
			if (result) {
				var form = MM_findObj(formName);
				form.action = 'valid.php?pg=inbox&box='+box+'&op=supall';
				form.submit();
			}
		}
	}
}

function displayConseillers() {
	if ($('conseillers_ecoute').getStyle('display') != 'block') {
		var offset = $('ecoute').cumulativeOffset();
		$('conseillers_ecoute').setStyle({ left: offset.left + 'px', top: (offset.top + 31)  + 'px'});
		$('conseillers_ecoute').show();
	} else {
		$('conseillers_ecoute').hide();
	}
}

function affTab(tab, id)
{
	['associes', 'fiche'].each(function(item)
	{
		if (item != tab) {
			$(item + '_' + id).hide();
			$('tab_' + item + '_' + id).removeClassName('selected');			
		}
	});
	$(tab + '_' + id).show();
	$('tab_' + tab + '_' + id).addClassName('selected');
}
