// ================================================ CENTRAGE VERTICAL PAGE ACCUEIL
	function centrageVertical()
	{
		hauteurPage = document.getElementById("repere").offsetTop + 1;
		hauteurContenu = 600;
		
		if(hauteurPage > hauteurContenu)
		{
			difference = hauteurPage - hauteurContenu;
			document.body.style.paddingTop = (difference/2) +"px";
		}
		else
		{
			document.body.style.paddingTop = 0;
		}
	}
	
	function centrageVertical2()
	{
		hauteurPage = document.getElementById("repere").offsetTop + 1;
		hauteurContenu = 600;
		
		if(hauteurPage > hauteurContenu)
		{
			difference = hauteurPage - hauteurContenu;
			document.body.style.paddingTop = (difference/2) +"px";
		}
		else
		{
			document.body.style.paddingTop = 0;
		}
	}
// ================================================ CENTRAGE VERTICAL PAGE ACCUEIL

// ================================================	CALCUL DE LA SURFACE

function calculSurface(quantite,surface,prix){
	if(form_input_is_int(quantite))
	{
	/*var recalcul=surface*quantite;*/
	var recalcul=Math.round((surface*quantite)*1000)/1000;
	var prixxx = Math.round((prix*quantite)*100)/100;

	/*//on replace le nombre de zero necessaire derrier le chiffre
	if ((prixxx.length-Math.abs(prixxx.indexOf('.')))==2)//cas ou un chiffre derriere la point.rem: la value absolue sert a ne pas tomber dasn le cas ou indexOf=-1
	{
	prixxx =prixxx+'0';
	}
	else if (prixxx.indexOf('.')==-1)// cas ou entier
	{
	prixxx=prixxx+'.00';
	}
	else if ((prixxx.length-prixxx.indexOf('.'))==1) //cas ou point mais pas de chiffres derriere
	{
	prixxx=prixxx+'.00';
	} */
	
	change_div('surface',recalcul);
	change_div('prixQ',prixxx);	
	}
	else
	{
		document.getElementById("quantite").value="1";
		alert('La quantité n\'est pas valide');
	}
}

 function form_input_is_int(input){
    return !isNaN(input)&&parseInt(input)==input;
  }



// ================================================	CALCUL DE LA SURFACE

// ================================================ AJAX
	
	var http_request = false; 
	function makeRequest(url) 
	{ 
		if (window.XMLHttpRequest) http_request = new XMLHttpRequest(); 
		else if (window.ActiveXObject) http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
		http_request.onreadystatechange = alertContents; 
		http_request.open('GET', url, true); 
		http_request.send(null); 
	} 

	function alertContents() 
	{ 
		if (http_request.readyState == 4) 
		{ 
			if (http_request.status == 200) 
			{
				//alert(http_request.responseText); 
				eval(http_request.responseText); 
			}
			else alert('Erreur de chargement!'); 
		} 
	} 

	function change_div(nom,valeur)
	{
		if (document.getElementById) document.getElementById(nom).innerHTML = valeur;
		else if (document.all) document.all[nom].innerHTML = valeur;
}
	
// ================================================ AJAX

// ================================================ validation formulaire
	function validationForm(monform)
	{
		var reg_email = /^[A-Za-z0-9\.\-_]+[@][A-Za-z0-9\-\.]+[\.][A-Za-z][A-Za-z][A-Za-z]?$/;
		
		if (monform.nom.value=='')
		{
			alert("Veuillez indiquer votre nom");
			monform.nom.focus();
			return false;
		}
		if (monform.prenom.value=='')
		{
			alert("Veuillez indiquer votre prénom");
			monform.prenom.focus();
			return false;
		}
		if (monform.adresse.value=='')
		{
			alert("Veuillez indiquer votre adresse");
			monform.adresse.focus();
			return false;
		}
		if (monform.cp.value=='')
		{
			alert("Veuillez indiquer votre code postal");
			monform.cp.focus();
			return false;
		}
		if (monform.ville.value=='')
		{
			alert("Veuillez indiquer votre ville");
			monform.ville.focus();
			return false;
		}
		if(monform.tel)
		{
			if (monform.tel.value=='')
			{
				alert("Veuillez indiquer votre n° de téléphone");
				monform.tel.focus();
				return false;
			}
			if (monform.email.value=='')
			{
				alert("Veuillez indiquer votre adresse email");
				monform.email.focus();
				return false;
			}
			if(!reg_email.test(monform.email.value))
			{
				alert("Le format de votre adresse email est invalide");
				monform.email.focus();
				return false;
			}
			if (monform.mdp.value=='')
			{
				alert("Veuillez choisir votre mot de passe");
				monform.mdp.focus();
				return false;
			}
			if (monform.mdp2.value=='')
			{
				alert("Veuillez confirmer votre mot de passe");
				monform.mdp2.focus();
				return false;
			}
			if (monform.mdp2.value != monform.mdp.value)
			{
				alert("Votre mot de passe et la confirmation de votre mot de passe ne correspondent pas");
				monform.mdp.focus();
				return false;
			}
		}
		return true;
	}
	
	function validationForm2(monform)
	{
		var reg_email = /^[A-Za-z0-9\.\-_]+[@][A-Za-z0-9\-\.]+[\.][A-Za-z][A-Za-z][A-Za-z]?$/;
		
		if (monform.email2.value=='')
		{
			alert("Veuillez indiquer votre adresse email");
			monform.email2.focus();
			return false;
		}
		if(!reg_email.test(monform.email2.value))
		{
			alert("Le format de votre adresse email est invalide");
			monform.email2.focus();
			return false;
		}
		if (monform.mdp3.value=='')
		{
			alert("Veuillez indiquer votre mot de passe");
			monform.mdp3.focus();
			return false;
		}
		return true;
	}
	
	function validationForm3(monform)
	{
		var reg_email = /^[A-Za-z0-9\.\-_]+[@][A-Za-z0-9\-\.]+[\.][A-Za-z][A-Za-z][A-Za-z]?$/;
		
		if (monform.emailOubli.value=='')
		{
			alert("Veuillez indiquer votre adresse email");
			monform.emailOubli.focus();
			return false;
		}
		if(!reg_email.test(monform.emailOubli.value))
		{
			alert("Le format de votre adresse email est invalide");
			monform.emailOubli.focus();
			return false;
		}
		return true;
	}
// ================================================ validation formulaire


// ================================================ Paiement
	function verifPaiement(modePaiement)
	{
		if(document.getElementById('validCGV').checked == false)
		{
			alert('Vous devez accepter les conditions générales de vente en cochant la case correspondante');
			return false;
		}
		else
		{
			
			if(modePaiement == 'cb')
			{
				return confirm('Je confirme vouloir payer par carte bancaire');
			}
			
			if(modePaiement == 'paypal')
			{
				if(confirm('Je confirme vouloir payer par paypal'))
				{
					makeRequest('ajax-paiement-paypal.php');
				}
			}
			if(modePaiement == 'cheque')
			{
				if(confirm('Je confirme vouloir payer par chèque'))
				{
					window.open('paiement-cheque.php','_self');
				}
			}
			if(modePaiement == 'virement')
			{
				if(confirm('Je confirme vouloir payer par virement bancaire'))
				{
					window.open('paiement-virement.php','_self');
				}
			}
		}
	}
// ================================================ Paiement

function isInt(x) 
{
	var y=parseInt(x);
	if (isNaN(y)) return false;
	return x==y && x.toString()==y.toString();
 }

//	=============================================== MONTRER CACHER LIVRAISON

function cache(span){
	document.getElementById(span).style.display='none';
	makeRequest('ajax-calcul-fraisdeport.php?USINE=0');
}

function montre(span){
	document.getElementById(span).style.display='inline';
	makeRequest('ajax-calcul-fraisdeport.php?USINE=1');
	if(document.getElementById('montantFP').innerHTML){
		document.getElementById('montantTOTAL').innerHTML=parseFloat(document.getElementById('montantTOTAL').innerHTML)+parseFloat(document.getElementById('montantFP').innerHTML)+' &euro;';
	}
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function verifierCP(valeur){
	if(IsNumeric(valeur)&& valeur.length==5)
	{
		makeRequest('ajax-calcul-fraisdeport.php?DEPT='+valeur);
		
	}
}


//	=============================================== MONTRER CACHER LIVRAISON

function effaceChamp(champ,valeur){
	if(document.getElementById(champ).value==valeur)
		document.getElementById(champ).value='';
}

function rempliChamp(champ,valeur){
	if(document.getElementById(champ).value=='')
		document.getElementById(champ).value=valeur;
}

function voirPhoto(){
	if(document.getElementById('aff1').style.display=='block')
	{
		document.getElementById('aff1').style.display='none';
		document.getElementById('aff2').style.display='block';
	}
	else
	{
		document.getElementById('aff1').style.display='block';
		document.getElementById('aff2').style.display='none';
	}
}

function afficheFlash(version,nom,largeur,hauteur){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+',0,0,0" width='+largeur+' height='+hauteur+'>\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value='+nom+' />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<embed src='+nom+' quality="high" wmode="transparent" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width='+largeur+' height='+hauteur+'></embed>\n');
	document.write('</object>\n');
}

/***********************************************/


function defilAuto1(){
	defilAuto('defilAuto1()', 'div#flashAccueil2010')
}

var mon_timer;

function defilAuto(act, monslide){
	$(monslide+' .stripTransmitter a').each(function(i){
		if($(this).hasClass('current'))
			cur=i;
	});

	nb=$(monslide+' .stripTransmitter a').size();

	if(cur==nb-1)
		suivant=0;
	else
		suivant=cur+1;
	
	el=$(monslide+' .stripTransmitter a').get(suivant);

	defilSuivante(el, 732, suivant, 'div#mercerieOffresListe');

	//setTimeout(act, 5000);
}

/************ AJAX COMMANDE SUR MESURE	*****************/

function calculMesure(produit,quantite,longueur,largeur,champ)
{
	makeRequest('ajax-formulaire-commande.php?ID='+produit+'&q='+quantite+'&long='+longueur+'&larg='+largeur+'&champ='+champ);
}

/************ AJAX COMMANDE SUR MESURE	*****************/