//<![CDATA[
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];}
}

function toggle_spinner()
{
	Element.toggle('loader_ajax_club');
}

function toggle_spinner2()
{
	Element.toggle('loader_ajax_boutique');
}

function identification_club()
{
	Element.hide('missing');
	
	var erreur = false;
	
	// vérification des champs d'abord
	if ($F('login').empty())
	{
		erreur = true;
	}
	
	if ($F('password').empty())
	{
		erreur = true;
	}
	// fin verif
	if (!erreur)
	{
		new Ajax.Updater('ajax_club', 'ajax-include/identification_club.php', 
		{
			method: 'post',
			synchronous: true,
			contentType: 'application/x-www-form-urlencoded',
			encoding: 'UTF-8',
			parameters: { login : $F('login'), password: $F('password')}, 
			onLoading: toggle_spinner,
			onComplete: toggle_spinner,
			onSuccess: function(requester) {
				switch(requester.responseText)
				{
					case "erreur": 
						Element.update('missing', '<font color=red>Les informations saisies ne correspondent à aucun compte actif.</font>');
						Element.show('missing');
					break;
					case "champ_vide": 
						Element.update('missing', '<font color=red>Les champs "identifiant" et "mot de passe" sont obligatoires.</font>');
						Element.show('missing');
					break;
					default:
						new Effect.Fade('formu_ident', {queue : 'front'});
						new Effect.Appear('ajax_club', {queue : 'end'});
					break;
				}
			},
			onFailure: function() {
				Element.update('missing', '<font color=red>Une erreur est survenue, veuillez ré-essayer plus tard.</font>');
				Element.show('missing');
			}
		});
	}
	else
	{
		Element.update('missing', '<font color=red>Les champs "identifiant" et "mot de passe" sont obligatoires.</font>');
		Element.show('missing');
	}
	
	return false;
}

function recupere_mdp_club_perdu()
{
	Element.hide('missing');
	
	var erreur = false;
	
	// vérification d'abord
	if ($F('email_perdu').empty())
	{
		erreur = true;
	}
	
	// fin verif
	if (!erreur)
	{
		new Ajax.Request('ajax-include/recupere_mdp_club_perdu.php', 
		{
			method: 'post',
			synchronous: true,
			contentType: 'application/x-www-form-urlencoded',
			encoding: 'UTF-8',
			parameters: { login : $F('email_perdu')}, 
			onLoading: toggle_spinner,
			onComplete: toggle_spinner,
			onSuccess: function(requester) {
				switch(requester.responseText)
				{
					case "erreur": 
						Element.update('missing', '<font color=red>Les informations saisies ne correspondent à aucun compte actif.</font>');
						Element.show('missing');
					break;
					case "pb_mail": 
						Element.update('missing', '<font color=red>Une erreur est survenue lors de l\'envoi de ton mot de passe.</font>');
						Element.show('missing');
					break;
					case "champ_vide": 
						Element.update('missing', '<font color=red>Tu dois saisir ton e-mail pour récupérer ton mot de passe.</font>');
						Element.show('missing');
					break;
					default:
						Element.update('missing', '<font color=red>Un e-mail contenant ton mot de passe vient d\'être envoyé à ton adresse.</font>');
						Element.show('missing');
						new Effect.Fade('ajax_club_mdp_perdu', {queue : 'front'});
						new Effect.Appear('formu_ident', {queue : 'end'});
					break;
				}
			},
			onFailure: function() {
				Element.update('missing', '<font color=red>Une erreur est survenue, veuillez ré-essayer plus tard.</font>');
				Element.show('missing');
			}
		});
	}
	else
	{
		Element.update('missing', '<font color=red>Tu dois saisir ton e-mail pour récupérer ton mot de passe.</font>');
		Element.show('missing');
	}
	
	return false;
}

function affiche_formulaire_mdp_oublie()
{
	new Effect.Fade('formu_ident', {queue : 'front'});
	new Effect.Appear('ajax_club_mdp_perdu', {queue : 'end'});
}

function parrainage()
{
	Element.hide('message_ajax_parrainage');
	Element.update('message_ajax_parrainage', '');
	
	// on vérifie d'abord le réglement
	if ($F('optin_valide_cg') != '1')
	{
		Element.update('message_ajax_parrainage', '<font color=red>Tu dois accepter les conditions générales.</font>');
		Element.show('message_ajax_parrainage');
	}
	else
	{
		var cmpt = 0;
		
		for (i = 1; i <= 5; i++)
		{
			var champ = 'email_filleul_'+i;
			
			if (trim_js($F(champ)) != '')
			{					
				if (!verif_email($F('email_filleul_'+i)))
				{
					Element.update('message_ajax_parrainage', '<font color=red>L\'adresse e-mail "'+$F('email_filleul_'+i)+'" ne semble pas valide.</font>');
					Element.show('message_ajax_parrainage');
					return false;
				}
				else
				{
					cmpt++;
				}
			}
		}
		
		if (cmpt == 0)
		{
			Element.update('message_ajax_parrainage', '<font color=red>Merci de saisir au moins une adresse e-mail.</font>');
			Element.show('message_ajax_parrainage');
		}
		else
		{
			// ok, traitement + envoi mail
			new Ajax.Request('ajax-include/traitement_parrainage.php', 
			{
				method: 'post',
				synchronous: true,
				contentType: 'application/x-www-form-urlencoded',
				encoding: 'UTF-8',
				parameters: { optin_valide_cg : $F('optin_valide_cg'), email_filleul_1 : $F('email_filleul_1'), email_filleul_2 : $F('email_filleul_2'), email_filleul_3 : $F('email_filleul_3'), email_filleul_4 : $F('email_filleul_4'), email_filleul_5 : $F('email_filleul_5')}, 
				onSuccess: function(requester) {
					switch(requester.responseText)
					{
						case "pas_d_envoi": 
							Element.update('message_ajax_parrainage', '<font color=red>Aucun e-mail n\'a été envoyé<br />(e-mail filleul soit non valide, soit temporaire, soit déjà présent dans la base)</font>');
							Element.show('message_ajax_parrainage');
						break;
						case "optin": 
							Element.update('message_ajax_parrainage', '<font color=red>Tu dois accepter les conditions générales.</font>');
							Element.show('message_ajax_parrainage');
						break;
						case "pb_mail": 
							Element.update('message_ajax_parrainage', '<font color=red>Une erreur est survenue lors de l\'envoi de mail.</font>');
							Element.show('message_ajax_parrainage');
						break;
						case "champ_vide": 
							Element.update('message_ajax_parrainage', '<font color=red>Tu dois saisir au moins une adresse e-mail.</font>');
							Element.show('message_ajax_parrainage');
						break;
						default:
							Element.update('message_ajax_parrainage', '<font color=red>Ta demande a bien été prise en compte.</font>');
							Element.show('message_ajax_parrainage');
						break;
					}
				},
				onFailure: function() {
					Element.update('message_ajax_parrainage', '<font color=red>Une erreur est survenue, veuillez ré-essayer plus tard.</font>');
					Element.show('message_ajax_parrainage');
				}
			});
		}
	}
	
	return false;
}

function popup_produit_boutique(id_produit)
{
	new Ajax.Updater('popup_image', 'ajax-include/recupere-zoom_produit.php',
	{
		method: 'post',
		synchronous: true,
		contentType: 'application/x-www-form-urlencoded',
		encoding: 'UTF-8',
		parameters: { produit : id_produit}
	});
	
	new Effect.Appear('popup_image');
}

function echange_points(id_formulaire)
{
	Element.update('message_ajax_boutique', '');
	Element.hide('message_ajax_boutique');
	
	var erreur = false;
	var type_erreur = 'parametres_manquants';
	
	// vérification des champs d'abord
	// id_produit et nb_points obligatoires
	// si taille présente, taille != -1
	if ($F(id_formulaire+'_id_produit').empty())
	{
		erreur = true;
	}
	
	if ($F(id_formulaire+'_nb_points').empty())
	{
		erreur = true;
	}
	
	if ($(id_formulaire+'_taille'))
	{
		if ($F(id_formulaire+'_taille') == -1)
		{
			erreur = true;
			type_erreur = 'choix_taille';
		}
	}
	
	// fin verif
	if (!erreur)
	{
		// demande de confirmation
		if (confirm('Etes-vous sûr de vouloir commander cet article?'))
		{
			// 2 cas possibles, à cause de la taille...
			if ($(id_formulaire+'_taille'))
			{
				new Ajax.Updater('message_ajax_boutique', 'ajax-include/echange_points.php', 
				{
					method: 'post',
					synchronous: true,
					contentType: 'application/x-www-form-urlencoded',
					encoding: 'UTF-8',
					parameters: { id_produit : $F(id_formulaire+'_id_produit'), nb_points : $F(id_formulaire+'_nb_points'), taille : $F(id_formulaire+'_taille')}, 
					onLoading: toggle_spinner2,
					onComplete: toggle_spinner2,
					onSuccess: function() {
						new Ajax.Updater('membre_nb_points', 'ajax-include/maj-nb-points.php');
					},
					onFailure: function() {
						Element.update('message_ajax_boutique', '<font color=red>Une erreur est survenue, veuillez ré-essayer plus tard.</font>');
					}
				});
			}
			else
			{
				new Ajax.Updater('message_ajax_boutique', 'ajax-include/echange_points.php', 
				{
					method: 'post',
					synchronous: true,
					contentType: 'application/x-www-form-urlencoded',
					encoding: 'UTF-8',
					parameters: { id_produit : $F(id_formulaire+'_id_produit'), nb_points : $F(id_formulaire+'_nb_points')}, 
					onLoading: toggle_spinner2,
					onComplete: toggle_spinner2,
					onSuccess: function() {
						new Ajax.Updater('membre_nb_points', 'ajax-include/maj-nb-points.php');
					},
					onFailure: function() {
						Element.update('message_ajax_boutique', '<font color=red>Une erreur est survenue, veuillez ré-essayer plus tard.</font>');
					}
				});	
			}
		}
	}
	else
	{
		// message différent suivant le type d'erreur
		if (type_erreur == 'choix_taille')
		{
			Element.update('message_ajax_boutique', '<font color=red>Vous devez sélectionner une taille<br />avant de commander cet article.</font>');
		}
		else if (type_erreur == 'parametres_manquants')
		{
			Element.update('message_ajax_boutique', '<font color=red>Erreur! Paramètres manquants.</font>');
		}
	}
	
	Element.show('message_ajax_boutique');
	
	return false;
}


/**
	Frédéric Saunier
	http://www.tekool.net/javascript/backtothehtml

	This program is part of a free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

**/

/*****************************************************************************
* BackToTheHtml Command
*///**************************************************************************
function BackToTheHtml(node)
{
	if(node == null)
		this.node = document; 
	else
		this.node = node; 
};
BackToTheHtml.prototype.node = null;

BackToTheHtml.prototype.execute = function()
{
	this.activateObject();
}

BackToTheHtml.prototype.activateObject = function(domObject)
{
	var aDomObject = this.node.getElementsByTagName('object');
	var activationObject;
	for(var i=0; i<aDomObject.length; i++)
		if
		(
			aDomObject[i].getAttributeNode('BackToTheHtml') == null
			&&
			(activationObject = this.getActivationObject(aDomObject[i])) != null
		)
			activationObject.execute();
};

BackToTheHtml.prototype.getActivationObject = function(domObject)
{
	var classid = domObject.classid.toUpperCase().substr('clsid:'.length);
	var mimeType = domObject.type.toLowerCase();

	switch(true)
	{
		case 
			classid == 'D27CDB6E-AE6D-11CF-96B8-444553540000' 
			||
			mimeType == 'application/x-shockwave-flash'
		:
			return new ActivateObjectFlash(domObject);

		default :
			return null;
	}
};

BackToTheHtml.uniqueID = function(prefix)
{
	var sPrefix;
	if(prefix == null)
		sPrefix = 'uniqueId';
	else
		sPrefix = prefix;
		
	var i=0;
	while(document.getElementById(sPrefix + (i++)))
		;
	return sPrefix + (i-1);
};

BackToTheHtml.isParentOf = function(parent,child)
{
	var found = false;
	for(var i=0; i<parent.childNodes.length; i++)
		if(parent.childNodes[i] == child)
			return true;
		else
			found = arguments.callee(parent.childNodes[i],child);

	return found;
}

/*****************************************************************************
* ActivateObject Command
*///**************************************************************************
function ActivateObject(domObject)
{
	this.domObject = domObject;
}

ActivateObject.prototype.domObject = null;
ActivateObject.prototype.classid = null;
ActivateObject.prototype.aHtmlAttribute = ['accessKey','align','alt','archive','border','code','codeBase','codeType','declare','dir','height','hideFocus','hspace','lang','language','name','standby','tabIndex','title','useMap','vspace','width'];
ActivateObject.prototype.aObjectProperty = null;

ActivateObject.prototype.execute = function()
{
	this.xndObjectId = BackToTheHtml.uniqueID();
	this.setTextHtml();
	this.writeObject();

	this.xndObject = document.getElementById(this.xndObjectId);
	this.setSpecialProperties();
	this.removeOriginalObject();
}

ActivateObject.prototype.setTextHtml = function()
{
	var str = '';
	str += '<object BackToTheHtml ' + '\n';
	str += ' classid="clsid:' + this.classid + '" ' + '\n';

	//Add HTML attributes to the <object> tag
	for(var i=0; i<this.aHtmlAttribute.length; i++)
	{
		var name = this.aHtmlAttribute[i];
		if(typeof this.domObject[name] != 'undefined' && this.domObject[name].toString() != '')
			str += '\t' + name + '="' + this.domObject[name].toString() + '" ' + '\n';
	}

	str += 'id="' + this.xndObjectId + '" ' + '\n';
	str += '>';

	for(var i=0; i<this.aObjectProperty.length; i++)
	{
		var name = this.aObjectProperty[i];
		if(typeof this.domObject[name] != 'undefined' && this.domObject[name].toString() != '' )
			str += '\t<param name="' + name + '" value="' + this.domObject[name].toString() + '"></param>' + '\n';
	}
	str += '</object>';

	this.textHtml = str;
};

ActivateObject.prototype.writeObject = function()
{
	this.domObject.insertAdjacentHTML("afterEnd",this.textHtml);
};

ActivateObject.prototype.setSpecialProperties = function()
{
	if(typeof this.domObject.className != 'undefined' && this.domObject.className.toString() != '')
		this.xndObject.className = this.domObject.className

	if(typeof this.domObject.style.cssText != 'undefined' && this.domObject.style.cssText.toString() != '')
		this.xndObject.style.cssText = this.domObject.style.cssText;

	if(typeof this.domObject.SWRemote != 'undefined' && this.domObject.SWRemote.toString() != '')
		this.xndObject.FlashVars = this.domObject.SWRemote;

	if(typeof this.domObject.codebase == 'undefined' || this.domObject.codebase.toString() == '')
		this.xndObject.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0';

	if(typeof this.domObject.id != 'undefined' && this.domObject.id.toString() != '')
		this.xndObject.id = this.domObject.id;

};

ActivateObject.prototype.removeOriginalObject = function()
{
	this.domObject.parentNode.removeChild(this.domObject);
};

/*****************************************************************************
* ActivateObjectFlash Command
*///**************************************************************************
function ActivateObjectFlash(domObject)
{
	ActivateObject.call(this,domObject);
}
ActivateObjectFlash.prototype = new ActivateObject;
ActivateObjectFlash.prototype.aObjectProperty = ['FrameNum','Playing','Quality','Quality2','Scalemode','Scale','AlignMode','SAlign','BackgroundColor','BGColor','Loop','Movie','WMode','Base','DeviceFont','EmbedMovie','SWRemote','FlashVars','AllowScriptAccess'];
ActivateObjectFlash.prototype.classid = 'D27CDB6E-AE6D-11CF-96B8-444553540000';


/*****************************************************************************
* Script initialisation
*///**************************************************************************
if(typeof ActiveXObject != 'undefined' && typeof Function.call != 'undefined')
{
	var styleId = BackToTheHtml.uniqueID();
	document.write('<style id="' + styleId + '" ></style>');
	var domStyle = document.getElementById(styleId);

	var isHead = false;
	var aHead = document.getElementsByTagName('head');
	for(var i=0; i<aHead.length; i++)
		if(BackToTheHtml.isParentOf(aHead[i],domStyle))
			isHead = true;

	if(isHead)
	{
		document.write('<style type="text/css">OBJECT{visibility:hidden;}</style>');
		document.onreadystatechange = function()
		{
			if(document.readyState == 'complete')
			{
				new BackToTheHtml().execute();
				document.styleSheets[document.styleSheets.length-1].addRule("OBJECT","visibility:visible;");
				//alert('head');
				//alert(document.body.innerHTML);
			}
		}
	}
	else
	{
		new BackToTheHtml().execute();
		//alert('body');
		//alert(document.body.innerHTML);
	}
	
	domStyle.parentNode.removeChild(domStyle);
}


function ouvre_popup(page,nom_page,largeur, hauteur)
{
       window.open(page,"nom_page", config='height='+hauteur+', width='+largeur+', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
}
/*
exemple d'utilisation de la fonction ouvre_popup: 
<a target="_top" href="javascript:ouvre_popup('conditions-generales-popup.php','conditions générales',930 ,400);">Conditions générales</a>
*/

//]]>
