function cache(id)
{
	if (document.getElementById(id))
	{
		if (document.getElementById(id).style.display == "block")
			document.getElementById(id).style.display = "none";
		else
			document.getElementById(id).style.display = "block";
	}
}
function montre_cache(tab_montre, tab_cache)
{
	//Definition de la hauteur du fond grisé
	var height;
	if (document.body.clientHeight > $('bgrd').scrollHeight)
		height = document.body.clientHeight;
	else
		height = $('bgrd').scrollHeight;
	$('overlay').style.height = height + "px";
	$('overlay_popup').style.marginLeft = "0px";
	// on montre les elements 
	if (tab_montre)
		for( var i = 0; i <= tab_montre.length; i++)
		{
			if (document.getElementById(tab_montre[i]))
			{
				if (document.getElementById(tab_montre[i]).style.display == "none")
					document.getElementById(tab_montre[i]).style.display = "block";
				$('overlay_popup').style.visibility = 'hidden';
			}
		}
	// on cache les elements
	if (tab_cache)
		for( var j = 0; j <= tab_cache.length; j++)
		{
			if (document.getElementById(tab_cache[j]))
			{
				if (document.getElementById(tab_cache[j]).style.display == "block")
					document.getElementById(tab_cache[j]).style.display = "none";
			}
		}
	var popupWidth = $('overlay_popup').getDimensions().width;
	var bodyWidth = document.body.clientWidth;
	var marginLeft = (bodyWidth - popupWidth) / 2;
	$('overlay_popup').style.marginLeft = marginLeft + "px";
	/*****************************************/
	/*****************************************/
	//Centrage vertical de la popup
	//Hauteur de l'image div
	var heightDiv = $('overlay_popup').offsetHeight;
	//Hauteur de la page
	var heightScroll = document.body.scrollTop + document.documentElement.scrollTop;
	//Point haut de la page, en prenant en compte le deplacement des ascenceurs
	var heightPage = document.documentElement.clientHeight + heightScroll;
	var positionTop = heightPage - heightDiv - ((document.documentElement.clientHeight - heightDiv) / 2);
	if (positionTop < 0)
		positionTop = 0;
	$('overlay_popup').style.top = positionTop + "px";
	//FIN centrage vertical
	/*****************************************/
	/*****************************************/
	$('overlay_popup').style.visibility = 'visible';
}
function changeclass(objet, myClass)
{
	objet.className = myClass;
}
function SetFocus(TargetFormName)
{
	var target = 0;
	if (TargetFormName != "")
		for(i = 0; i < document.forms.length; i++)
		{
			if (document.forms[i].name == TargetFormName)
			{
				target = i;
				break;
			}
		}
	var TargetForm = document.forms[target];
	for(i = 0; i < TargetForm.length; i++)
	{
		if ((TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit"))
		{
			TargetForm.elements[i].focus();
			if ((TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password"))
				TargetForm.elements[i].select();
			break;
		}
	}
}
function RemoveFormatString(TargetElement, FormatString)
{
	if (TargetElement.value == FormatString)
		TargetElement.value = "";
	TargetElement.select();
}
function CheckDateRange(from, to)
{
	if (Date.parse(from.value) <= Date.parse(to.value))
		return true;
	else
		return false;
}
function IsValidDate(DateToCheck, FormatString)
{
	var strDateToCheck;
	var strDateToCheckArray;
	var strFormatArray;
	var strFormatString;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var intDateSeparatorIdx = -1;
	var intFormatSeparatorIdx = -1;
	var strSeparatorArray = new Array("-", " ", "/", ".");
	var strMonthArray = new Array("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
	var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	strDateToCheck = DateToCheck.toLowerCase();
	strFormatString = FormatString.toLowerCase();
	if (strDateToCheck.length != strFormatString.length)
	{
		return false;
	}
	for(i = 0; i < strSeparatorArray.length; i++)
	{
		if (strFormatString.indexOf(strSeparatorArray[i]) != -1)
		{
			intFormatSeparatorIdx = i;
			break;
		}
	}
	for(i = 0; i < strSeparatorArray.length; i++)
	{
		if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1)
		{
			intDateSeparatorIdx = i;
			break;
		}
	}
	if (intDateSeparatorIdx != intFormatSeparatorIdx)
		return false;
	if (intDateSeparatorIdx != -1)
	{
		strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
		if (strFormatArray.length != 3)
		{
			return false;
		}
		strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
		if (strDateToCheckArray.length != 3)
		{
			return false;
		}
		for(i = 0; i < strFormatArray.length; i++)
		{
			if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm')
				strMonth = strDateToCheckArray[i];
			if (strFormatArray[i] == 'dd')
				strDay = strDateToCheckArray[i];
			if (strFormatArray[i] == 'yyyy')
				strYear = strDateToCheckArray[i];
		}
	}
	else
	{
		if (FormatString.length > 7)
		{
			if (strFormatString.indexOf('mmm') == -1)
				strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
			else
				strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
			strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
			strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
		}
		else
		{
			return false;
		}
	}
	if (strYear.length != 4)
	{
		return false;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday))
	{
		return false;
	}
	if (intday < 1)
	{
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth))
	{
		for(i = 0; i < strMonthArray.length; i++)
		{
			if (strMonth == strMonthArray[i])
			{
				intMonth = i + 1;
				break;
			}
		}
		if (isNaN(intMonth))
		{
			return false;
		}
	}
	if (intMonth > 12 || intMonth < 1)
	{
		return false;
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear))
	{
		return false;
	}
	if (IsLeapYear(intYear) == true)
	{
		intDaysArray[1] = 29;
	}
	if (intday > intDaysArray[intMonth - 1])
	{
		return false;
	}
	return true;
}
function IsLeapYear(intYear)
{
	if (intYear % 100 == 0)
	{
		if (intYear % 400 == 0)
			return true;
	}
	else
	{
		if ((intYear % 4) == 0)
			return true;
	}
	return false;
}
//Gestion du roll-over
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_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];
		}
}
//Fin gestion du roll-over
function deleteConfirm()
{
	reponse = confirm('Confirmez vous la suppression ?');
	if (reponse)
		return true;
	else
		return false;
}
//Ouverture de fenêtre
function openBRWindow(theURL, winName, features)
{
	window.open(theURL, winName, features);
}
function PopupCentrer(page, largeur, hauteur, options)
{
	var top = (screen.height - hauteur) / 2;
	var left = (screen.width - largeur) / 2;
	winName = window.open(page, 'zoom', "top=" + top + ",left=" + left + ",width=" + largeur + ",height=" + hauteur + "," + options);
	//On retaille la fenetre par rapport au contenu
	IE5 = NN4 = NN6 = false;
	if (document.all)
		IE5 = true;
	else
		if (document.getElementById)
			NN6 = true;
		else
			if (document.layers)
				NN4 = true;
	if (IE5)
		winName.resizeTo(parseInt(largeur) + 10, parseInt(hauteur) + 41);
	else
		winName.resizeTo(parseInt(largeur) + 8, parseInt(hauteur) + 38);
	winName.focus();
}
function addFav()
{
	if (document.all)
	{
		window.external.AddFavorite(location.href, document.title);
	}
	else
	{
		alert(JS_ADD_FAVORIS);
	}
}
//Validation du formulaire pour la recommandation à un ami
function valid_formulaire()
{
	var txt_erreur = JS_ERROR;
	var erreur = 0;
	if (document.getElementById('nom').value == '')
	{
		txt_erreur += JS_LAST_NAME;
		erreur = 1;
	}
	if (document.getElementById('email').value == '' || document.getElementById('emaildest').value == '')
	{
		txt_erreur += JS_EMAIL_EMPTY;
		erreur = 1;
	}
	if ((document.getElementById('email').value && !checkMail(document.getElementById('emaildest').value)) || (document.getElementById('emaildest').value && !checkMail(document.getElementById('email').value)))
	{
		txt_erreur += ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
		erreur = 1;
	}
	if (erreur == 1)
	{
		alert(txt_erreur);
		return false;
	}
	else
		return true;
}
//Validation du formulaire pour la demande de contact
function valid_formulaire_contact()
{
	var txt_erreur = JS_ERROR;
	var erreur = 0;
	if (document.getElementById('contactName').value == '')
	{
		txt_erreur += JS_LAST_NAME;
		erreur = 1;
	}
	if (document.getElementById('contactEmail').value == '')
	{
		txt_erreur += JS_EMAIL_EMPTY;
		erreur = 1;
	}
	if (document.getElementById('contactEmail').value && !checkMail(document.getElementById('contactEmail').value))
	{
		txt_erreur += ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
		erreur = 1;
	}
	if (erreur == 1)
	{
		alert(txt_erreur);
		return false;
	}
	else
		return true;
}
function checkMail(x)
{
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(x))
		return true;
	else
		return false;
}
function correctPng() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	for( var i = 0; i < document.images.length; i++)
	{
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length - 3, imgName.length) == "PNG")
		{
			var imgID = (img.id) ? "id='" + img.id + "' " : "";
			var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.align == "left")
				imgStyle = "float:left;" + imgStyle;
			if (img.align == "right")
				imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href)
				imgStyle = "cursor:hand;" + imgStyle;
			var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
			img.outerHTML = strNewHTML;
			i = i - 1;
		}
	}
}
//Fonction pour calculer l'assurance sur les frais de port
function calcul_assurance_ship(elmt)
{
	var shipping_cost = Number(document.getElementById('shipping_ship_departements_cost').value);
	var montant_assurance = Number(elmt.value);
	if (elmt.checked)//Ajout du montant de l'assurance
	{
		shipping_cost = shipping_cost + montant_assurance;
		//Modification de l'intitulé ("Avec assurance")
		document.getElementById('shipping_ship_departements_method').value = document.getElementById('shipping_ship_departements_method_with_assurance').value;
		document.getElementById('shipping_selected_ship_departements').value = 'ship_departements_assur';
	}
	else
	//Suppression du montant de l'assurance
	{
		shipping_cost = shipping_cost - montant_assurance;
		//Modification de l'intitulé ("Sans assurance")
		document.getElementById('shipping_ship_departements_method').value = document.getElementById('shipping_ship_departements_method_without_assurance').value;
		document.getElementById('shipping_selected_ship_departements').value = 'ship_departements';
	}
	if (shipping_cost > 0)
		document.getElementById('shipping_ship_departements_cost').value = shipping_cost;
}
//fonction pour updater les points de fidelite
function updateFidelisation(nbpoint)
{
	document.location = "caddie.php?action=fidelite&nbpoint=" + nbpoint;
}
function displayLotImage(image)
{
	document.getElementById('imgLotPdts').innerHTML = image;
}
function displayInPopupError(message)
{
	$('popup_error').innerHTML = message;
	if (message != '')
		$('popup_error').style.display = 'block';
	else
		$('popup_error').style.display = 'none';
}
function cache(id)
{
	if (document.getElementById(id))
	{
		if (document.getElementById(id).style.display == "block")
		{
			document.getElementById(id).style.display = "none";
		}
		else
			document.getElementById(id).style.display = "block";
	}
}
function reinitAfterKeyUp(element)
{
	document.getElementById(element).style.background = '';
	document.getElementById(element).removeEventListener('keydown', reinitAfterKeyUp, false);
}
function showParrainagePopup()
{
	var options = 'context=ajax_parrainage&action=getContent&page=login';
	//var options='file=parrainage';
	new Ajax.Request('index.php', { onSuccess :showParrainagePopupCallBack, parameters :options });
}
function showParrainagePopupCallBack(response)
{
	displayInPopupError('');
	//window.eval(response.responseText); 
	var tmp = eval('(' + response.responseText + ')');
	//displayInPopup('parrainage');
	//cache('overlay');
	document.getElementById('popup_content').innerHTML = tmp['content'];
	montre_cache(Array('overlay', 'popup_content'), Array('popup_friend', 'popup_cart'));
}
function showFriendPopup()
{
	var options = 'context=ajax_send_friend&action=getContent';
	new Ajax.Request('index.php', { onSuccess :showFriendPopupCallBack, parameters :options });
}
function showFriendPopupCallBack(response)
{
	displayInPopupError('');
	var tmp = eval('(' + response.responseText + ')');
	document.getElementById('popup_content').innerHTML = tmp['content'];
	montre_cache(Array('overlay', 'popup_content'), Array('popup_parainage', 'popup_cart'));
}
function showSendFriendProductPopup($_id_pdt)
{
	var options = 'context=ajax_send_friend_product&action=getContent&id_pdt=' + $_id_pdt;
	new Ajax.Request('index.php', { onSuccess :showSendFriendProductPopupCallBack, parameters :options });
}
function showSendFriendProductPopupCallBack(response)
{
	displayInPopupError('');
	var tmp = eval('(' + response.responseText + ')');
	document.getElementById('popup_content').innerHTML = tmp['content'];
	montre_cache(Array('overlay', 'popup_content'), Array('popup_friend', 'popup_parainage', 'popup_cart'));
}
function showLoginPopup()
{
	var options = 'context=ajax_login&action=getContent&page=login';
	new Ajax.Request('index.php', { onSuccess :showLoginPopupCallBack, parameters :options });
}
function showLoginPopupCallBack(jsonretour)
{
	displayInPopupError('');
	var tmp = eval('(' + jsonretour.responseText + ')');
	document.getElementById('popup_content').innerHTML = tmp['content'];
	montre_cache(Array('overlay', 'popup_content'), Array('popup_friend', 'popup_parainage'));
}
function login()
{
	var mail = $('email_address_login2').value;
	if (!checkMail($('email_address_login2').value))
	{
		displayInPopupError(JS_ERROR);
		$('email_address_login2').style.background = '#cc0000';
		return false;
	}
	else
	{
		var options = 'context=ajax_login&action=logIn&login=' + $('email_address_login2').value + '&password=' + $('password_login2').value;
		new Ajax.Request('index.php', { onSuccess :loginCallBack, parameters :options });
	}
}
function loginCallBack(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	if (tmp['return'] < 0)
	{
		displayInPopupError(tmp['content']);
		if (tmp['return'] == '-2')
		{//password error
			$('password_login2').style.background = '#cc0000';
			if ($('password_login2').addEventListener)
			{
				$('password_login2').addEventListener('keydown', function()
				{
					reinitAfterKeyUp('password_login2');
				}, false);
			}
			else
				if (el.attachEvent)
					$('password_login2').attachEvent('keydown', function()
					{
						reinitAfterKeyUp('password_login2');
					});
		}
		else
		{//login
			$('email_address_login2').style.background = '#cc0000';
			if ($('email_address_login2').addEventListener)
			{
				$('email_address_login2').addEventListener('keydown', function()
				{
					reinitAfterKeyUp('email_address_login2');
				}, false);
			}
			else
				if ($('email_address_forgot').attachEvent)
					$('email_address_login2').attachEvent('keydown', function()
					{
						reinitAfterKeyUp('email_address_login2');
					});
		}
	}
	else
		if (tmp['return'] == 2)
		{
			displayInPopupError('');
			document.getElementById('popup_content').innerHTML = tmp['content'];
			$('btnCompteId').href = "compte.php";
			//cache('overlay');
		}
		else
			if (tmp['return'] == 1)
			{
				montre_cache('', Array('popup_content', 'overlay'));
				$('btnCompteId').innerHTML = tmp['texte_header'];
				$('btnCompteId').href = "compte.php";
				// redirection vers la page du compte
				document.location = "compte.php";
			}
}
function showRecupPasswdPopup()
{
	var options = 'context=ajax_login&action=getContent&page=passwd_recup';
	new Ajax.Request('index.php', { onSuccess :showRecupPasswdPopupCallBack, parameters :options });
}
function showRecupPasswdPopupCallBack(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	displayInPopupError('');
	document.getElementById('popup_content').innerHTML = tmp['content'];
	//montre_cache(Array('overlay'),Array('popup_friend','popup_cart'));
}
function recupPasswdAction()
{
	if (!checkMail($('email_address_forgot').value))
	{
		displayInPopupError(JS_ERROR);
		$('email_address_forgot').style.background = '#cc0000';
		if ($('email_address_forgot').addEventListener)
		{
			$('email_address_forgot').addEventListener('keydown', function()
			{
				reinitAfterKeyUp('email_address_forgot');
			}, false);
		}
		else
			if ($('email_address_forgot').attachEvent)
				$('email_address_forgot').attachEvent('keydown', function()
				{
					reinitAfterKeyUp('email_address_forgot');
				});
		return;
	}
	var options = 'context=ajax_login&action=recupPasswd&mail=' + $('email_address_forgot').value;
	new Ajax.Request('index.php', { onSuccess :recupPasswdActionCallBack, parameters :options });
}
function recupPasswdActionCallBack(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	if (tmp['return'] < 0)
	{
		displayInPopupError(tmp['content']);
	}
	else
	{
		displayInPopupError('');
		$('popup_content').innerHTML = tmp['content'];
	}
}
function showImageProductInPopup(pid)
{
	var options = 'context=ajax_fiche_produit&action=showImage&pid=' + pid;
	new Ajax.Request('index.php', { onSuccess :showImageProductInPopupCallBack, parameters :options });
}
function showImageProductInPopupCallBack(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	$('popup_content').innerHTML = tmp['content'];
	displayInPopupError('');
	setTimeout( function()
	{
		montre_cache(Array('overlay'), Array('popup_friend', 'popup_cart'));
	}, 400);
}
function showImageSuppProductInPopup(pid, id_img)
{
	var options = 'context=ajax_fiche_produit&action=showImageSupp&pid=' + pid + '&id_img_supp=' + id_img;
	new Ajax.Request('index.php', { onSuccess :showImageSuppProductInPopupCallBack, parameters :options });
}
function showImageSuppProductInPopupCallBack(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	$('popup_content').innerHTML = tmp['content'];
	setTimeout( function()
	{
		montre_cache(Array('overlay'), Array('popup_friend', 'popup_cart'));
	}, 400);
}
function showContactInPopup()
{
	var options = 'context=ajax_contact&action=getContent';
	new Ajax.Request('index.php', { onSuccess :showContactInPopupCallBack, parameters :options });
}
function showContactInPopupCallBack(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	$('popup_content').innerHTML = tmp['content'];
	displayInPopupError('');
	montre_cache(Array('overlay'), null);
}
function sendContactAction()
{
	if (!checkMail($('contactEmail').value))
	{
		displayInPopupError(JS_ERROR);
		$('contactEmail').style.background = '#cc0000';
		if ($('contactEmail').addEventListener)
		{
			$('contactEmail').addEventListener('keydown', function()
			{
				reinitAfterKeyUp('contactEmail');
			}, false);
		}
		else
			if ($('contactEmail').attachEvent)
				$('contactEmail').attachEvent('keydown', function()
				{
					reinitAfterKeyUp('contactEmail');
				});
		return;
	}
	var options = "context=ajax_contact&action=sendContact&name=" + $('contactName').value + "&mail=" + $('contactEmail').value + "&enquiry=" + $('contactEnquiry').value;
	new Ajax.Request('index.php', { onSuccess :sendContactActionCallBack, parameters :options });
}
function sendContactActionCallBack(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	if (tmp['return'] > 0)
	{
		displayInPopupError('');
		$('popup_content').innerHTML = tmp['content'];
	}
	else
	{
		cache('overlay');
	}
}
function sendFriendCallback(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	$('popup_content').innerHTML = tmp['content'];
	displayInPopupError('');
	montre_cache(Array('overlay'), null);
}
function sendFriend()
{
	/**
	 * Mail de destination
	 */
	if (!checkMail($('emaildest').value))
	{
		displayInPopupError(JS_ERROR);
		$('emaildest').style.background = '#cc0000';
		if ($('emaildest').addEventListener)
		{
			$('emaildest').addEventListener('keydown', function()
			{
				reinitAfterKeyUp('emaildest');
			}, false);
		}
		else
			if ($('emaildest').attachEvent)
				$('emaildest').attachEvent('keydown', function()
				{
					reinitAfterKeyUp('emaildest');
				});
		return;
	}
	/**
	 * Mail de l'expéditeur
	 */
	if (!checkMail($('emailfrom').value))
	{
		displayInPopupError(JS_ERROR);
		$('emailfrom').style.background = '#cc0000';
		if ($('emailfrom').addEventListener)
		{
			$('emailfrom').addEventListener('keydown', function()
			{
				reinitAfterKeyUp('emailfrom');
			}, false);
		}
		else
			if ($('emailfrom').attachEvent)
				$('emailfrom').attachEvent('keydown', function()
				{
					reinitAfterKeyUp('emailfrom');
				});
		return;
	}
	var options = 'context=ajax_send_friend&action=sendfriend&emaildest=' + $('emaildest').value + '&emailfrom=' + $('emailfrom').value + '&nom=' + $('nom').value + '&message=' + $('message').value + '&url_recom=' + $('url_recom').value;
	new Ajax.Request('index.php', { parameters :options, onSuccess :sendFriendCallback });
}
function sendFriendProduct($_id_pdt)
{
	if (!checkMail($('mail_ami').value))
	{
		displayInPopupError(JS_ERROR);
		$('mail_ami').style.background = '#cc0000';
		if ($('mail_ami').addEventListener)
		{
			$('mail_ami').addEventListener('keydown', function()
			{
				reinitAfterKeyUp('mail_ami');
			}, false);
		}
		else
			if ($('mail_ami').attachEvent)
				$('mail_ami').attachEvent('keydown', function()
				{
					reinitAfterKeyUp('mail_ami');
				});
		return;
	}
	if (!checkMail($('mail_sender').value))
	{
		displayInPopupError(JS_ERROR);
		$('mail_sender').style.background = '#cc0000';
		if ($('mail_sender').addEventListener)
		{
			$('mail_sender').addEventListener('keydown', function()
			{
				reinitAfterKeyUp('mail_sender');
			}, false);
		}
		else
			if ($('mail_sender').attachEvent)
				$('mail_sender').attachEvent('keydown', function()
				{
					reinitAfterKeyUp('mail_sender');
				});
		return;
	}
	var options = 'context=ajax_send_friend_product&action=sendfriendproduct&mail_ami=' + $('mail_ami').value + '&mail_sender=' + $('mail_sender').value + '&nom_sender=' + $('nom_sender').value + '&message=' + $('message').value + '&id_pdt=' + $_id_pdt;
	new Ajax.Request('index.php', { parameters :options, onSuccess :sendFriendCallback });
}
var valid = false;
function verifyFilleulCallback(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	var retour = tmp['return'];
	if (retour == -1)
	{//le client existe déjà
		document.getElementById('send').style.visibility = 'hidden';
		document.getElementById('error').style.display = 'block';
		document.getElementById('error').innerHTML = "Ce client à déjà ouvert un compte";
		valid = false;
	}
	else
		if (retour == -2)
		{//Cette addresse mail a dejà recu une invitation
			document.getElementById('send').style.visibility = 'hidden';
			document.getElementById('error').innerHTML = "Cette adresse mail a déjà recue une invitation";
			document.getElementById('error').style.display = 'block';
			valid = false;
		}
		else
		{
			valid = true;
			document.getElementById('error').style.display = 'none';
			document.getElementById('send').style.visibility = 'visible';
		}
}
function verifyMailParrain(email, number)
{
	if (checkMail(email) == null)
	{
		showResultParrainage(0, 0);
		return false;
	}
	else
	{
		return true;
	}
}
function updateParrainWidget(email)
{
	valid = false;
	document.getElementById('error').innerHTML = "";
	var verif = /^.*@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/;
	if (verif.exec(email) == null)
	{
		// document.getElementById('valid').src="<?php echo URL_THEMES.'no_valid.png'?>";
		document.getElementById('error').innerHTML = "adresse mail incorrecte";
		document.getElementById('error').style.display = 'block';
		document.getElementById('send').style.display = 'none';
		valid = false;
		return false;
	}
	else
	{
		var options = 'context=ajax_parrainage&action=check&mail=' + email;
		new Ajax.Request(urlParrain, { onSuccess :verifyFilleulCallback, parameters :options });
	}
}
function verifyMail(email_bis, number_bis)
{
	if (checkMail(email_bis) == null)
	{
		showResultParrainage(0, number_bis);
		return false;
	}
	else
	{
		return true;
	}
}
function sendParrainageInvit()
{
	if (verifyMailParrain(document.getElementById('mail_parrain').value, 0) && verifyMail(document.getElementById('email1').value, 1))
	{
		if (document.getElementById('email2').value == "" || verifyMail(document.getElementById('email2').value, 2))
		{
			if (document.getElementById('email3').value == "" || verifyMail(document.getElementById('email3').value, 3))
			{
				var options = 'context=ajax_parrainage&action=sendInvit&mail_parrain=' + document.getElementById('mail_parrain').value + '&email1=' + document.getElementById('email1').value + '&email2=' + document.getElementById('email2').value + '&email3=' + document.getElementById('email3').value;
				new Ajax.Request(urlParrain, { parameters :options, onSuccess :sendParrainageInvitCallback });
			}
		}
	}
}
function sendParrainageInvitCallback(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	var retour = tmp['return'];
	var email = tmp['email'];
	showResultParrainage(retour, email);
}
function alertMeOnProductStock($_pID)
{
	if (checkMail(document.getElementById('mailAlert').value))
	{
		var options = 'context=ajax_product_add_stock_alert&mailAlert=' + document.getElementById('mailAlert').value + '&pID=' + $_pID;
		new Ajax.Request(urlParrain, { parameters :options, onSuccess :alertMeOnProductStockCallback });
	}
}
function alertMeOnProductStockCallback(jsonretour)
{
	var tmp = eval('(' + jsonretour.responseText + ')');
	var content = tmp['content'];
	try
	{
		document.getElementById('alertStock').innerHTML = content;
	}
	catch (e)
	{
		try
		{
			document.getElementById('alertStock').innerText = content;
		}
		catch (e)
		{
		}
	}
}
/**
 * Fonction permettant de simplement modifier la classe CSS d'un élement par son id.
 * L'ancienne classe CSS est écrasé
 *
 * @param string l'id de l'élément à modifier
 * @param string la nouvelle classe CSS
 * @return bool true
 */
function changeCSSCLass($_id, $_newClass)
{
	if (document.getElementById($_id))
	{
		document.getElementById($_id).setAttribute('class', $_newClass);
		document.getElementById($_id).className = $_newClass;
	}
	return true;
}
//Fonction pour info bulle zoom produits
// La variable i nous dit si la bulle est visible ou non
var bulle_visible = false;
function move(e)
{
	var offset = 0;
	if (document.getElementById("divInfoBulle") != null)
	{
		var heightDiv = document.getElementById("divInfoBulle").offsetHeight;
		//Hauteur de la page
		var heightScroll = document.body.scrollTop + document.documentElement.scrollTop;
		var heightPage = document.documentElement.clientHeight + heightScroll;
		if (bulle_visible)
		{
			if (navigator.appName != "Microsoft Internet Explorer")
			{
				if ((e.pageY + heightDiv) >= heightPage)
					offset = heightDiv;
				document.getElementById("divInfoBulle").style.left = e.pageX + 5 + "px";
				document.getElementById("divInfoBulle").style.top = e.pageY + (10 - offset) + "px";
			}
			else
			{
				if (document.documentElement.clientWidth > 0)
				{
					if ((event.y + document.documentElement.scrollTop + heightDiv) >= heightPage)
						offset = heightDiv;
					document.getElementById("divInfoBulle").style.left = event.x + document.documentElement.scrollLeft + "px";
					document.getElementById("divInfoBulle").style.top = 10 + event.y + document.documentElement.scrollTop - offset + "px";
				}
				else
				{
					if ((event.y + document.body.scrollTop + heightDiv) >= heightPage)
						offset = heightDiv;
					document.getElementById("divInfoBulle").style.left = event.x + document.body.scrollLeft + "px";
					document.getElementById("divInfoBulle").style.top = 10 + event.y + document.body.scrollTop - offset + "px";
				}
			}
		}
	}
}
function montre_infobulle(text, type)
{
	if (bulle_visible == false && document.getElementById("divInfoBulle"))
	{
		document.getElementById("divInfoBulle").className = "infobulle " + type;
		document.getElementById("divInfoBulle").style.visibility = "visible";
		document.getElementById("divInfoBulle").innerHTML = text;
		bulle_visible = true;
	}
}
function cache_infobulle()
{
	if (bulle_visible == true && document.getElementById("divInfoBulle"))
	{
		document.getElementById("divInfoBulle").style.visibility = "hidden";
		document.getElementById("divInfoBulle").innerHTML = '';
		bulle_visible = false;
	}
}
document.onmousemove = move;
function CreateBookmarkLink(title, url)
{
	if (window.sidebar)
	{ // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, "");
	}
	else
		if (window.external)
		{ // IE Favorite
			window.external.AddFavorite(url, title);
		}
		else
			if (window.opera && window.print)
			{ // Opera Hotlist
				return true;
			}
}
/**
 * Fonction de définition des onglets si on est sur la fiche produit
 */
if (document.getElementById('pages'))
{
	var myTabs = new YAHOO.widget.TabView("pages");
	myTabs.set('activeIndex', 0);
}
/**
 * HACK : 
 *	- 	lorsque l'on a uniquement deux blocs centraux, il faut que ce soit les id modulesIndexLeft et modulesIndexRight 
 *		et non pas modulesIndexMiddle même si les blocs ont été placé dedans...
 */
( function()
{
	var d = document;
	if (d.getElementById('modulesIndexCentre') && !d.getElementById('modulesIndexLeft') && d.getElementById('modulesIndexRight'))
	{
		var center = d.getElementById('modulesIndexCentre');
		center.setAttribute('id', 'modulesIndexLeft');
		center.setAttribute('class', 'modulesIndexLeft');
		center.className = 'modulesIndexLeft';
	}
	if (d.getElementById('modulesIndexCentre') && d.getElementById('modulesIndexLeft') && !d.getElementById('modulesIndexRight'))
	{
		var center = d.getElementById('modulesIndexCentre');
		center.setAttribute('id', 'modulesIndexRight');
		center.setAttribute('class', 'modulesIndexRight');
		center.className = 'modulesIndexRight';
	}
})();
/**
 * Fonction permettant de simplement afficher/masquer un élément HTML par son id en jouant sur la propriéré display: none/block
 *
 * @param string l'id de l'élément HTML
 * @return bool false
 */
function reverseContentDisplay($_elementId)
{
	if (document.getElementById($_elementId))
		document.getElementById($_elementId).style.display = document.getElementById($_elementId).style.display == 'block' ? 'none' : 'block';
	return false;
}
/**
 * Fonction permettant de récupérer la valeur d'un champ de formulaire que ce soit une liste de sélection, un champ test ou testarea.
 * Pour cela, lui passer l'id de l'élément du formulaire. 
 * Pour le moment, elle contient les éléments de base d'un formulare, à faire évoluer si nécessaire
 *
 * @param string l'id de l'élément HTML du formulaire
 * @return la valeur du champ du formulaire ou null si le champ n'a pas été trouvé
 */
function getFieldValue(/*string*/$_id)
{
	//displayDebug('getFieldValue',$_id,false);
	if (document.getElementById($_id))
	{
		var el = document.getElementById($_id);
		switch (el.tagName)
		{
			case 'TEXTAREA':
				//displayDebug('getFieldValue',el.innerHTML,false);
				return el.innerHTML;
				break;
			case 'INPUT':
				switch (el.type)
				{
					case 'text':
					case 'TEXT':
					case 'PASSWORD':
					case 'password':
					case 'HIDDEN':
					case 'hidden':
					case 'RADIO':
					case 'radio':
					case 'FILE':
					case 'file':
						//displayDebug('getFieldValue',el.value,false);
						return el.value;
						break;
					case 'CHECKBOX':
					case 'checkbox':
						//displayDebug('getFieldValue',el.checked,false);
						return (el.checked == 'on' ? 1 : 0);
						break;
				}
				break;
			case 'SELECT':
				//displayDebug('getFieldValue',el.options[el.selectedIndex].value,false);
				return el.options[el.selectedIndex].value;
				break;
		}
	}
	else
		return null;
}
