jQuery.fn.centerPop = function () {
  this.css("position","absolute");
  this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
  this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
  return this;
}
function verifChiffre(obj)
{
	val = obj.value.replace(',','.');
	obj.value = val;
	if(isNaN(val))
	{
		obj.value = '';
		obj.focus();
		return false;
	}
	return true;
}
function lanceCalendDate(o)
{
	var t  = o.value.split('_');
	var mois = parseFloat(t[0]) - 1;
	if(mois == 0)
	mois = 12;
	changelecalend(mois,t[1]);
}
function retourneLongueurSansEspaces(chaine)
{
	u = 0;
	for(i = 0; i < chaine.length; i++)
	{
		if(chaine.charAt(i) == ' ')
		u++;
	}
	return u;
}
function nbrePromoChamp(o)
{
	if(o.checked)
	{
		$('#chpcachenbrechamp').fadeIn('fast');
	}
	else
	{
		$('#chpcachenbrechamp').fadeOut('fast').css('display','none');
	}
	calculeMontant("o");
}
function ouvertureFenetreProchainePromo(id)
{
	$('body').append('<div id = "fenetreOuvranteP"></div>');
	$('#fenetreOuvranteP').hide();
	$('#fenetreOuvranteP').html('<div style = "float:right;margin-right:-25px;margin-top:-20px;"><form method = "post" action = "" name = "ffenetrepromo"><input type = "hidden" name = "fermeturefenetrepromo" value = "ok"/><img src = "images/close.png" style = "cursor:pointer;" onclick = "document.ffenetrepromo.submit();"/></form></div>');
	centrerElement('fenetreOuvranteP',444,555);
	$.ajax({
		  	type : 'POST', 
			url : "includes/moteurajax.php5" ,
			data : 'expofenetrepromo='+id ,
			success : function(data){ 
				creationFondSombre("document.ffenetrepromo.submit();");
			$('#fenetreOuvranteP').append(data).css({border:'1px ridge #ffffff',backgroundColor:"#000000",padding:"10px",width: "555px",height : "444px"}).fadeIn('fast');	
			}
	      });
}
function raffraichir(lien)
{
	document.location.href = lien;
}
function creationFondSombre(fct)
{
	hauteur = retourneHauteur();
	hauteur += 400;
	$('body').append('<div id = "lefondmodal"></div>');
	$('#lefondmodal').css("backgroundColor","#000000");
	$('#lefondmodal').css("position","absolute");
	$('#lefondmodal').css("zIndex","2000");
	$('#lefondmodal').css("top","0px");
	$('#lefondmodal').css("left","0px");
	$('#lefondmodal').css("bottom","0px");
	$('#lefondmodal').css("right","0px");
	$('#lefondmodal').css("width","100%");
	$('#lefondmodal').css("height",hauteur+"px");
	$('#lefondmodal').hide();
	$('#lefondmodal').fadeOut("fast").fadeTo("slow", 0.7);
	if(fct != '')
	$('#lefondmodal').click(function(){eval(fct);})
}
function fermeForme()
{
	$('#fenetreOuvrante').animate( { width: "0px",height : "0px", padding : "0px", border : "0px" },800,function(){
	$('#fenetreOuvrante').css({border:"0px",backgroundColor:"none"}).html('').remove();
	$('#lefondmodal').fadeOut("fast").remove();
	}
	);
}
function fermeFormeA()
{
	$('#divVidePourImage').fadeOut('slow').html('').css("display","none");
	$('#lefondmodal').fadeOut("fast").remove();
}
function retourneHauteur()
{
	var scrollH = 0;	// scrollY
	var windowH = 0;	// largeur de la fenêtre
	if (document.doctype == null || document.documentElement.clientHeight == 0)
	{
		if (window.innerWidth || (document.body.offsetHeight == document.documentElement.offsetHeight))
		{
			scrollH = document.body.scrollTop;
			windowH = document.body.clientHeight;
		}
		else
		{
			scrollH = document.documentElement.scrollTop;
			windowH = document.documentElement.clientHeight;
		}

	}
	else
	{
		if (document.doctype.publicId.search(/xhtml/i) != -1)
		scrollH = document.documentElement.scrollTop;
		else
		scrollH = document.body.scrollTop;
	}
	if (window.innerHeight)
	windowH = window.innerHeight;
	return windowH+scrollH;
}
function retourneLargeur()
{
	var scrollW = 0;	// scrollY
	var windowW = 0;	// largeur de la fenêtre
	if (document.doctype == null || document.documentElement.clientWidth == 0)
	{
		if (window.innerWidth || (document.body.offsetWidth == document.documentElement.offsetWidth))
		{
			scrollW = document.body.scrollLeft;
			windowW = document.body.clientWidth;
		}
		else
		{
			scrollW = document.documentElement.scrollLeft;
			windowW = document.documentElement.clientWidth;
		}

	}
	else
	{
		if (document.doctype.publicId.search(/xhtml/i) != -1)
		scrollW = document.documentElement.scrollLeft;
		else
		scrollW = document.body.scrollLeft;
	}
	if (window.innerWidth)
	windowW = window.innerWidth;
	return windowW+scrollW;
}
function changelecalend(mois,annee)
{
	if(mois == '12')
	{
		mois = 1;
		annee = parseFloat(annee) + 1;
	}
	else
	{
		mois = parseFloat(mois) + 1;
	}
	$('#contenuCalend').fadeOut('slow');
	$.ajax({
		  	type : 'POST', 
			url : "includes/moteurajax.php5" ,
			data : 'moisc='+mois+'&anneec='+annee ,
			success : function(data){ 
			$('#contenuCalend').html(data).fadeIn('slow');
			}
	      });
}
function changelecalendMoins(mois,annee)
{
	if(mois == '1')
	{
		mois = 12;
		annee = parseFloat(annee) - 1;
	}
	else
	{
		mois = parseFloat(mois) - 1;
	}
	$('#contenuCalend').fadeOut('slow');
	$.ajax({
		  	type : 'POST', 
			url : "includes/moteurajax.php5" ,
			data : 'moisc='+mois+'&anneec='+annee , 
			success : function(data){ 
			$('#contenuCalend').html(data).fadeIn('slow');
			}
	      });
}
function changelecalendANN(mois,annee)
{
	annee = parseFloat(annee) + 1;
	$.ajax({
		  	type : 'POST', 
			url : "includes/moteurajax.php5" ,
			data : 'moisc='+mois+'&anneec='+annee ,
			success : function(data){ 
			$('#contenuCalend').fadeOut('slow',function()
			{
				$('#contenuCalend').html(data).fadeIn('slow');
			}
			
			)
		}
	      });
}
function changelecalendMoinsANN(mois,annee)
{
	annee = parseFloat(annee) - 1;
	$.ajax({
		  	type : 'POST', 
			url : "includes/moteurajax.php5" ,
			data : 'moisc='+mois+'&anneec='+annee ,
			success : function(data){ 
			$('#contenuCalend').fadeOut('slow',function()
			{
				$('#contenuCalend').html(data).fadeIn('slow');
			}
			
			)
		}
	      });
}
function centrerElement(element,haut,large) {
	hauteur = retourneHauteur();
	largeur = retourneLargeur();
$('#'+element).css({
position : 'absolute',
zIndex:'30000',
top: ((hauteur/2)- (haut/2))+'px',
left: ((largeur/2)- (large/2))+'px'
});
}

function ouvreImage(obj)
{
	$('body').append('<div id = "fenetreOuvrante"></div>');
	$('#fenetreOuvrante').hide();
	source = obj.src.replace("mini-","");
	contenu = '<center><img src = "'+source+'" id = "grdIm"/></center>';
	creationFondSombre("fermeForme();");
	$('#fenetreOuvrante').html(contenu);
	large = $('#grdIm').width();
	haut = $('#grdIm').height();
	if(parseFloat(large) > 800)
	{
		haut = (parseFloat(haut)/parseFloat(large)) * 800;
		large = 800;
		$('#grdIm').css("width",large+'px');
	}
	$('#fenetreOuvrante').css({width:'0px',height:'0px'});
	centrerElement('fenetreOuvrante',haut,large);
	$('#fenetreOuvrante').append('<div style = "float:right;margin-right:-23px;margin-bottom:-10px;"><img src = "images/close.png" style = "cursor:pointer;" onclick = "fermeForme();"/></div>');
	$('#fenetreOuvrante').css({border:'1px ridge #ffffff',backgroundColor:"#000000",padding:"10px"}).animate( { width: large+"px",height : haut+"px" },800);
}
var leTimerEssaiIm = null;
function ouvreImageA(obj)
{
	if(leTimerEssaiIm != null)
	clearTimeout(leTimerEssaiIm);
	source = obj.src.replace("mini-","");
	contenu = '<img src = "'+source+'" id = "grdIm"/>';
	$('#divVidePourImage').css('display','block').html(contenu);
	large = 0;
	haut = 0;
	large = $('#grdIm').width();
	haut = $('#grdIm').height();
	$('#divVidePourImage').hide();
	if(large > 0 && haut > 0)
	{
		if(large > 800)
		{
			haut = (haut/large) * 800;
			large = 800;
			$('#grdIm').css("width",large+'px');
		}
		creationFondSombre("fermeFormeA();");
		centrerElement('divVidePourImage',haut,large);
		$('#divVidePourImage').css({border:'1px ridge #ffffff',backgroundColor:"#000000",padding:"10px"}).fadeIn('slow').append('<p><div style = "float:right;margin-right:-23px;margin-bottom:-23px;"><img src = "images/close.png" style = "cursor:pointer;" onclick = "fermeFormeA();"/></div></p>');
	}
	else
	leTimerEssaiIm = setTimeout("ouvreImageA("+obj+")","500");
}
function verifResa(forme)
{
	retablirFresa(forme);
	lnom = retourneLongueurSansEspaces(forme.nom.value);
	if(forme.nom.value.length == lnom)
	{
		alerteForme("Vous devez saisir votre nom !");
		$('#itnom').css({backgroundColor:'red'});
		return false;
	}
	lnom = retourneLongueurSansEspaces(forme.prenom.value);
	if(forme.prenom.value.length == lnom)
	{
		alerteForme("Vous devez saisir votre pr&eacute;nom !");
		$('#itprenom').css({backgroundColor:'red'});
		return false;
	}
	lnom = retourneLongueurSansEspaces(forme.tel.value);
	if(forme.tel.value.length == lnom)
	{
		alerteForme("Vous devez saisir votre num&eacute;ro de t&eacute;l&eacute;phone !");
		$('#ittel').css({backgroundColor:'red'});
		return false;
	}
	lnom = retourneLongueurSansEspaces(forme.email.value);
	if(forme.email.value.length == lnom)
	{
		alerteForme("Vous devez saisir votre adresse email !");
		$('#itemail').css({backgroundColor:'red'});
		return false;
	}
	if(forme.email.value.indexOf("@") == "-1" || forme.email.value.indexOf(".") == "-1")
	{
		alerteForme("Votre adresse email n'est pas valide !");
		$('#itemail').css({backgroundColor:'red'});
		return false;
	}
	return true;
}
function retablirFresa(forme)
{
	forme.nom.style.backgroundColor = '#ffffff';
	forme.prenom.style.backgroundColor = '#ffffff';
	forme.tel.style.backgroundColor = '#ffffff';
	forme.email.style.backgroundColor = '#ffffff';
}
function alerteForme(txt)
{
	$('#alerteFResa').hide().html(txt).fadeIn("slow");
}
function ouvreFormulaireResa(id)
{
	raffraichir("formulaire-reservation.php5?id="+id);
}
function calculeMontant(obj)
{
	chemin = document.fResa;
	lid = chemin.id.value;
	nbre = chemin.nb.value;
	nbreBout = 0;
	if(chemin.chpn.checked)
	nbreBout = chemin.nbrebouteilles.value;
	$.ajax({
		  	type : 'POST', 
			url : "includes/moteurajax.php5" ,
			data : 'montantR='+nbre+'&idR='+lid+'&nbreb='+nbreBout ,
			success : function(data){ 
			$('#leMontant').fadeOut('slow',function()
			{
				$('#leMontant').html(data).fadeIn('slow');
			}
			
			)
		}
	      });
}
function ouverturePopMenu()
{
	creationFondSombre("fermeMenu();");
	largeur = 580;
	leleft = (retourneLargeur() - largeur)/2;
	var lesOpt = {
		display:'block',
		backgroundColor : "#000000",
		width:largeur+'px',
		position : 'absolute',
		left:leleft+"px",
		marginLeft:'-50px',
		zIndex:'30000',
		border : "1px solid #ffffff"
	}
	$('#contenuMenu').css(lesOpt).hide();
	$('#contenuMenu').append('<div style = "float:right;margin-right:-28px;margin-bottom:-28px;" id = "btnAlerte"><img src = "images/close.png" style = "cursor:pointer;" onclick = "fermeMenu();"/></div>');
	$('#contenuMenu').fadeIn('slow');
}
function fermeMenu()
{
	$('#contenuMenu').fadeOut('slow');
	$('#btnAlerte').remove();
	$('#contenuMenu').css('display','none');
	$('#lefondmodal').fadeOut("fast").remove();
}
function ouverturePopMessage(mes)
{
	$('body').append('<div id = "fenetreOuvranteMess"></div>');
	$('#fenetreOuvranteMess').hide();
	creationFondSombre();
	largeur = 580;
	leleft = (retourneLargeur() - largeur)/2;
	var lesOpt = {
		display:'block',
		backgroundColor : "#000000",
		width:largeur+'px',
		position : 'absolute',
		left:leleft+"px",
		top : "300px",
		padding:"44px",
		textAlign : 'center',
		zIndex:'30000',
		border : "1px solid #ffffff"
	}
	$('#fenetreOuvranteMess').css(lesOpt);
	$('#fenetreOuvranteMess').html(mes);
	$('#fenetreOuvranteMess').fadeIn('slow');
}


