/**
* @desc 	Fonction javascript de la boutique d'e-commerce France Massage
* @author 	Eric Warembourg <eric.warenbourg@pimentic.com> - DreamWeaver
* @author 	Fabien Caillot <fabien.caillot@ordinatUeur.org>
* @date 	27/09/2007
* @version 	1.0
*/

/**
 * @desc	effectue un roll out sur des images
 * @param	aucun 
 * @return aucun 
 */
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];}
}

/**
 * @desc	restore les images d'origines apres roll out
 * @param	aucun 
 * @return	aucun 
 */
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;
}

/**
 * @desc	precharge les images du roll over pour que la transition soit instantanée
 * @param	aucun 
 * @return	aucun 
 */
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];}}
}

/**
 * @desc	chargement dynamique du HTML (source : dreamweaver)
 * @param	 n, d : document
 * @return	x
 */
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;
}

/**
 * @desc	changement du module de nouveautés au survol
 * @param	 idprod : id du produit concerné par le survol, d : document
 * @return	rien
 */
function newAffich(idprod, aTab, lien) {

	if (typeof(aTab[idprod]) == "undefined") return false;
	var sElement1 = String(aTab[idprod][0])
	var sElement2 = String(aTab[idprod][1])
	var sElement3 = String(aTab[idprod][2])
	var sElement4 = String(aTab[idprod][3])
	if ( document.getElementById('news_titre') )
		document.getElementById('news_titre').innerHTML = sElement1;
	if ( document.getElementById('news_prix') )
		document.getElementById('news_prix').innerHTML = sElement2;
	if ( document.getElementById('news_image') )
		document.getElementById('news_image').innerHTML = '<a href="'+lien+'" id="lienImageNouveaute">'+sElement3+'</a>';

	if (image = document.getElementById('lienImageNouveaute').firstChild){
		hauteurImage = parseInt(sElement4);
		hauteurDiv = parseInt(document.getElementById('news_image').style.height);
		
// 		alert(aTab);
		
		margin_Top = Math.floor((hauteurDiv/2)-(hauteurImage/2));
		
		image.style.marginTop = margin_Top+"px";
		image.style.visibility = "visible";
	}
}

/**
 * @desc	changement du module de promotions au survol
 * @param	 idprod : id du produit concerné par le survol, d : document
 * @return	rien
 */
function promoAffich(idprodpromo, aTabPromos, lienPromo) {

	if (typeof(aTabPromos[idprodpromo]) == "undefined") return false;
	var sElement1 = String(aTabPromos[idprodpromo][0])
	var sElement2 = String(aTabPromos[idprodpromo][1])
	var sElement3 = String(aTabPromos[idprodpromo][2])
	var sElement4 = String(aTabPromos[idprodpromo][3])
	
	if ( document.getElementById('promo_titre') )
		document.getElementById('promo_titre').innerHTML = sElement1;
	if ( document.getElementById('promo_prix') )
		document.getElementById('promo_prix').innerHTML = sElement2;
	if ( document.getElementById('image_promo') )
		document.getElementById('image_promo').innerHTML = '<a href="'+lienPromo+'" id="lienImagePromo">'+sElement3+'</a>';

	if (image = document.getElementById('lienImagePromo').firstChild){
		hauteurImage = parseInt(sElement4);
		
		
		
		hauteurDiv = parseInt(document.getElementById('image_promo').style.height);
		
		margin_Top = Math.floor((hauteurDiv/2)-(hauteurImage/2));
		
		image.style.marginTop = margin_Top+"px";
		image.style.visibility = "visible";
	}
	
}



/**
 * @desc	valide la conformité des champs du formulaire francais
 * @param	'id_du_champ','','mode_de_vefification' (les parametres sont saisies par groupes de 3 comme précédent)
 * @return	rien
 */
function MM_validateForm_french()
{ //v4.0

	
	var i,p,q,nm,test,num,min,max,errors='',errchampobli='',args=MM_validateForm_2.arguments;
	for (i=0; i<(args.length-2); i+=3)
	{
		test=args[i+2];
		
		val=MM_findObj(args[i]);
		groupName = args[i+1];
		
		
		
		if (val)
		{
			if (val.alt)
				nm = val.alt;
			else
				nm=val.name;
				
				
			if(groupName!=''){
				for (j=i;j<(args.length-2);j+=3){
					valToCheck=MM_findObj(args[j]);
					groupNameToCheck = args[j+1];
					
					if (valToCheck)
					{
						if (val.alt)
							nmToCheck = valToCheck.alt;
						else
							nmToCheck = valToCheck.name;
					}
					if(groupNameToCheck==groupName){
						if(valToCheck.value!=val.value){
						alert(valToCheck.value+' > '+val.value);
							errors+=' Le champ "'+nm+'" doit être identique au champ "'+nmToCheck+'".\n';
						}
					}
				}
			}
				
				
				
			if ((val=val.value)!="" && (test != ""))
			{
				if (test.indexOf('isEmail')!=-1)
				{
					p=val.indexOf('@');p=val.indexOf('.',p);
					if (p<1 || p==(val.length-1))
						errors+=' Le champ "'+nm+'" doit contenir un e-mail valide.\n';
				}
				else if (test!='R')
				{
					num = parseFloat(val);
					if (isNaN(val)) 
						errors+=nm+' doit contenir un nombre.\n';
					if (test.indexOf('inRange') != -1)
					{ 
						p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num)
							errors+=nm+' doit contenir un nombre entre '+min+' et '+max+'.\n';
					}
				}
			} 
			else if (test.charAt(0) == 'R') 
				errchampobli = 'Tous les champs associés à * doivent être saisis obligatoirement.\n';
		}
	} 
	if (errors || errchampobli)
		alert(errchampobli+errors);
	document.MM_returnValue = (errors+errchampobli == '');
}


/**
 * @desc	valide la conformité des champs du formulaire francais
 * @param	'id_du_champ','','mode_de_vefification' (les parametres sont saisies par groupes de 3 comme précédent)
 * @return	rien
 */
function MM_validateForm_german()
{ //v4.0

	
	var i,p,q,nm,test,num,min,max,errors='',errchampobli='',args=MM_validateForm_2.arguments;
	for (i=0; i<(args.length-2); i+=3)
	{
		test=args[i+2];
		
		val=MM_findObj(args[i]);
		groupName = args[i+1];
		
		
		
		if (val)
		{
			if (val.alt)
				nm = val.alt;
			else
				nm=val.name;
				
				
			if(groupName!=''){
				for (j=i;j<(args.length-2);j+=3){
					valToCheck=MM_findObj(args[j]);
					groupNameToCheck = args[j+1];
					
					if (valToCheck)
					{
						if (val.alt)
							nmToCheck = valToCheck.alt;
						else
							nmToCheck = valToCheck.name;
					}
					if(groupNameToCheck==groupName){
						if(valToCheck.value!=val.value){
						alert(valToCheck.value+' > '+val.value);
							errors+=' Le champ "'+nm+'" doit être identique au champ "'+nmToCheck+'".\n';
						}
					}
				}
			}
				
				
				
			if ((val=val.value)!="" && (test != ""))
			{
				if (test.indexOf('isEmail')!=-1)
				{
					p=val.indexOf('@');p=val.indexOf('.',p);
					if (p<1 || p==(val.length-1))
						errors+=' Le champ "'+nm+'" doit contenir un e-mail valide.\n';
				}
				else if (test!='R')
				{
					num = parseFloat(val);
					if (isNaN(val)) 
						errors+=nm+' doit contenir un nombre.\n';
					if (test.indexOf('inRange') != -1)
					{ 
						p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num)
							errors+=nm+' doit contenir un nombre entre '+min+' et '+max+'.\n';
					}
				}
			} 
			else if (test.charAt(0) == 'R') 
				errchampobli = 'Tous les champs associés à * doivent être saisis obligatoirement.\n';
		}
	} 
	if (errors || errchampobli)
		alert(errchampobli+errors);
	document.MM_returnValue = (errors+errchampobli == '');
}


/**
 * @desc	valide la conformité des champs du formulaire francais
 * @param	'id_du_champ','','mode_de_vefification' (les parametres sont saisies par groupes de 3 comme précédent)
 * @return	rien
 */
function MM_validateForm_english()
{ //v4.0

	
	var i,p,q,nm,test,num,min,max,errors='',errchampobli='',args=MM_validateForm_2.arguments;
	for (i=0; i<(args.length-2); i+=3)
	{
		test=args[i+2];
		
		val=MM_findObj(args[i]);
		groupName = args[i+1];
		
		
		
		if (val)
		{
			if (val.alt)
				nm = val.alt;
			else
				nm=val.name;
				
				
			if(groupName!=''){
				for (j=i;j<(args.length-2);j+=3){
					valToCheck=MM_findObj(args[j]);
					groupNameToCheck = args[j+1];
					
					if (valToCheck)
					{
						if (val.alt)
							nmToCheck = valToCheck.alt;
						else
							nmToCheck = valToCheck.name;
					}
					if(groupNameToCheck==groupName){
						if(valToCheck.value!=val.value){
						alert(valToCheck.value+' > '+val.value);
							errors+=' Le champ "'+nm+'" doit être identique au champ "'+nmToCheck+'".\n';
						}
					}
				}
			}
				
				
				
			if ((val=val.value)!="" && (test != ""))
			{
				if (test.indexOf('isEmail')!=-1)
				{
					p=val.indexOf('@');p=val.indexOf('.',p);
					if (p<1 || p==(val.length-1))
						errors+=' Le champ "'+nm+'" doit contenir un e-mail valide.\n';
				}
				else if (test!='R')
				{
					num = parseFloat(val);
					if (isNaN(val)) 
						errors+=nm+' doit contenir un nombre.\n';
					if (test.indexOf('inRange') != -1)
					{ 
						p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num)
							errors+=nm+' doit contenir un nombre entre '+min+' et '+max+'.\n';
					}
				}
			} 
			else if (test.charAt(0) == 'R') 
				errchampobli = 'Tous les champs associés à * doivent être saisis obligatoirement.\n';
		}
	} 
	if (errors || errchampobli)
		alert(errchampobli+errors);
	document.MM_returnValue = (errors+errchampobli == '');
}


/**
 * @desc	valide la conformité des champs du formulaire francais
 * @param	'id_du_champ','','mode_de_vefification' (les parametres sont saisies par groupes de 3 comme précédent)
 * @return	rien
 */
function MM_validateForm_2()
{ //v4.0

	
	var i,p,q,nm,test,num,min,max,errors='',errchampobli='',args=MM_validateForm_2.arguments;
	for (i=0; i<(args.length-2); i+=3)
	{
		test=args[i+2];
		val=MM_findObj(args[i]);
		groupName = args[i+1];
		
		
		
		if (val)
		{
			if (val.alt)
				nm = val.alt;
			else
				nm=val.name;
				
				
			if(groupName!=''){
				for (j=i;j<(args.length-2);j+=3){
					valToCheck=MM_findObj(args[j]);
					groupNameToCheck = args[j+1];
					
					if (valToCheck)
					{
						if (val.alt)
							nmToCheck = valToCheck.alt;
						else
							nmToCheck = valToCheck.name;
					}
					if(groupNameToCheck==groupName){
						if(valToCheck.value!=val.value){
							errors+=' Le champ "'+nm+'" doit être identique au champ "'+nmToCheck+'".\n';
						}
					}
				}
			}
				
				
				
			if ((val=val.value)!="" && (test != ""))
			{
				if (test.indexOf('isEmail')!=-1)
				{
					p=val.indexOf('@');p=val.indexOf('.',p);
					if (p<1 || p==(val.length-1))
						errors+=' Le champ "'+nm+'" doit contenir un e-mail valide.\n';
				}
				else if (test!='R')
				{
					num = parseFloat(val);
					if (isNaN(val)) 
						errors+=nm+' doit contenir un nombre.\n';
					if (test.indexOf('inRange') != -1)
					{ 
						p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num)
							errors+=nm+' doit contenir un nombre entre '+min+' et '+max+'.\n';
					}
				}
			} 
			else if (test.charAt(0) == 'R') 
				errchampobli = 'Tous les champs associés à * doivent être saisis obligatoirement.\n';
		}
	} 
	if (errors || errchampobli)
		alert(errchampobli+errors);
	document.MM_returnValue = (errors+errchampobli == '');
}


/**
 * @desc	valide la conformité des champs du formulaire espanol
 * @param	'id_du_champ','','mode_de_vefification' (les parametres sont saisies par groupes de 3 comme précédent)
 * @return	rien
 */
function MM_validateForm_3()
{ //v4.0
	var i,p,q,nm,test,num,min,max,errors='',errchampobli='',args=MM_validateForm_3.arguments;
	for (i=0; i<(args.length-2); i+=3)
	{
		test=args[i+2];
		val=MM_findObj(args[i]);
		groupName = args[i+1];
		
		
		
		if (val)
		{
			if (val.alt)
				nm = val.alt;
			else
				nm=val.name;
				
				
			if(groupName!=''){
				for (j=0;j<(args.length-2);j+=3){
					valToCheck=MM_findObj(args[j]);
					groupNameToCheck = args[j+1];
					
					if (valToCheck)
					{
						if (val.alt)
							nmToCheck = valToCheck.alt;
						else
							nmToCheck = valToCheck.name;
					}
					if(groupNameToCheck==groupName){
						if(valToCheck.value!=val.value){
							errors+='El campo "'+nm+'" debe ser idéntico al campo "'+nmToCheck+'".\n';
						}
					}
				}
			}
				
				
				
			if ((val=val.value)!="" && (test != ""))
			{
				if (test.indexOf('isEmail')!=-1)
				{
					p=val.indexOf('@');p=val.indexOf('.',p);
					if (p<1 || p==(val.length-1))
						errors+='El campo "'+nm+'" debe contener un e mail válido.\n';
				}
				else if (test!='R')
				{
					num = parseFloat(val);
					if (isNaN(val)) 
						errors+='(traduire en esp)'+nm+' debe contener un número.\n';
					if (test.indexOf('inRange') != -1)
					{ 
						p=test.indexOf(':');
						min=test.substring(8,p); max=test.substring(p+1);
						if (num<min || max<num)
							errors+='(traduire en esp)'+nm+' debe contener un número entre '+min+' y '+max+'.\n';
					}
				}
			} 
			else if (test.charAt(0) == 'R') 
				errchampobli = 'Todos los campos asociados con * son obligatorios.\n';
		}
	} 
	if (errors || errchampobli)
		alert(errchampobli+errors);
	document.MM_returnValue = (errors+errchampobli == '');
}



/**
 * @desc	valide la conformité des champs du formulaire (appelée onkeyup du champs)
 * @param	element HTML ,nombre de groupes de chiffres
 * @return	rien
 */
function formatPhoneNumber(){
	args=formatPhoneNumber.arguments;
	champs = args[0];

	champsValue = champs.value;
	
	champsValue = champsValue.split(" ");
	champsValue = champsValue.join("");
	
	
	champsNewVal = "";
	
	
	
	lngGroupes = args[1];
	

	
	i=0;
	iN=0
	while (i < champsValue.length){
		champsNewVal += champsValue.charAt(i);
		
		if(parseInt(champsValue.charAt(i))|| champsValue.charAt(i)=="0"){
			
			if((iN+1)%lngGroupes==0 && i<champsValue.length-1){
				champsNewVal += " ";
			}
			iN++;
		}
		i++;
	}
	
	champs.value = champsNewVal;
}

/**
 * @desc	inhibe la saisie de caracteres autres que numérique  
 * @param	srcObj : objet qui envois l'evenent onclick   evt : evenement
 * @return	true : le caractere est numérique   false : le caractere n'est pas numérique
 */
function restrictNumber(srcObj,evt){
	

	if(window.event){
		keyCode = window.event.keyCode;
		evt = window.event;
	}else if (evt) keyCode = evt.which;
	else return true;
	
	//alert (keyCode);
	
//	if (keyCode==44 || keyCode==46)
	if (keyCode==46)
	{
		//On autorise l'insertion du point uniquement s'il est unique
		if (srcObj.value.indexOf('.')==-1 && srcObj.value.indexOf(',')==-1 ){
			return;
		}
		
	}
	
	
// 	document.getElementById(srcObj.id.split("_")[0]+"_modif").style.visibility="visible";
// 	saisieModif = true;

	
	if (((keyCode>=48) && (keyCode<=57)) || keyCode == 0 || keyCode == 8 || (keyCode == 43 && srcObj.value.length==0) || keyCode == 40 || keyCode == 41 || keyCode == 91 || keyCode == 93)
	{
		evt.returnValue = true;
		return true;
	}else{
		evt.returnValue = false;
		return false;
	}
}

/**
 * @desc	inhibe la saisie de caracteres autres que numérique  
 * @param	srcObj : objet qui envois l'evenent onclick   evt : evenement
 * @return	true : le caractere est numérique   false : le caractere n'est pas numérique
 */
function restrictNumberStrict(srcObj,evt){
	

	if(window.event){
		keyCode = window.event.keyCode;
		evt = window.event;
	}else if (evt) keyCode = evt.which;
	else return true;
	
	//alert (keyCode);
	
// 	if (keyCode==44 || keyCode==46)
// 	{
// 		//On autorise l'insertion du point uniquement s'il est unique
// 		if (srcObj.value.indexOf('.')==-1 && srcObj.value.indexOf(',')==-1 ){
// 			return;
// 		}
// 		
// 	}
	
	
// 	document.getElementById(srcObj.id.split("_")[0]+"_modif").style.visibility="visible";
// 	saisieModif = true;

	
	if ((keyCode>=48) && (keyCode<=57) || keyCode == 0 || keyCode == 8) 
	{
		evt.returnValue = true;
		return true;
	}else{
		evt.returnValue = false;
		return false;
	}
}


/**
 * @desc	met une majuscule en debut de mot et le reste en minuscule 
 * @param	srcObj 
 * @return	rien
 */
function makeName(srcObj){
	champsValue=srcObj.value;
	maj = champsValue.toUpperCase();
	min = champsValue.toLowerCase();
	champsValue = "";
	
	i=0;
	while (i < maj.length){
		
		if(i==0){
			champsValue += maj.charAt(i);
		}else{
			champsValue += min.charAt(i);
		}
		i++;
	} 
	srcObj.value = champsValue;
}

/**
 * @desc	met en majuscule tout le champs
 * @param	srcObj 
 * @return	rien
 */
function fullUpperCase(srcObj){
	srcObj.value = srcObj.value.toUpperCase();
}

