function chargement(num)
{
	//Affiche un image de chargement
	MM_findObj('img_chargement'+num).style.display='inline';	
}

function stop_chargement(num)
{
	//Stoppe l'image de chargement
	MM_findObj('img_chargement'+num).style.display='none';		
}


var slide_actif	=	null;

// Permet d'utiliser un effet de deroulement vers le bas sur un element (div)
function slide_down(id)
{
	if(slide_actif != id)
	{
		if(slide_actif != null)
		{
			jQuery("#"+slide_actif).slideUp("slow");
		}
		slide_actif	=	id;
		jQuery("#"+slide_actif).slideDown("slow");
	}
	else
	{
		jQuery("#"+slide_actif).slideUp("slow");
		slide_actif	= null;
	}
}

function init_centre()
{
	// test selon le div a utiliser 'centre_home' sur index.php et l'autre sinon
	if(document.getElementById("centre"))
		div	=	"centre";
	else
		div	=	"centre_home";
	
	MM_findObj(div).onmouseover	=	function()
	{
		if(slide_actif != null)
		{
			jQuery("#"+slide_actif).slideUp("slow");
			slide_actif	=	null;
		}
	}
}

function precharge_image()
{
	MM_preloadImages('images/enregistrement.jpg','images/ok_annuaire_on.gif','images/ok_violet_on.jpg','images/retour_on.jpg','images/deconnexion_on.gif','images/catalogue_film_on.gif','images/choix_film_on.jpg','images/choix_personne_on.jpg','images/petites_annonces_on.jpg','images/newsletter_on.jpg','images/forum_on.jpg','images/annuaires_on.jpg','images/fond_aide_on.jpg','images/formation_on.jpg','images/actualites_on.jpg','images/inscrire_on.gif', 'images/ok_orange_on.jpg', 'images/onglet_01_on.jpg', 'images/onglet_02_on.jpg', 'images/onglet_03_on.jpg', 'images/onglet_04_on.jpg', 'images/onglet_s_01_on.jpg', 'images/onglet_s_02_on.jpg', 'images/onglet_s_03_on.jpg', 'images/onglet_s_04_on.jpg', 'images/debit_on.jpg')
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function trim(aString) 
{
	var regExpBeginning = /^\s+/;
	var regExpEnd       = /\s+$/;
    return aString.replace(regExpBeginning, "").replace(regExpEnd, "");
}

function set_date_mask(champ)
{
	jQuery("#"+champ).mask("99/99/9999",{completed:function(){ if(!isDate(this.val())){alert("Veuillez saisir une date valide.");}}});
}

function set_phone_mask(champ)
{
	jQuery("#"+champ).mask("99 99 99 99 99");
	
}

var div_masque	=	null;
var interval	=	null;
function ouvrir_fenetre(id_fenetre)
{
	// Calcul du scroll top pour positioner la fenetre
	if(!document.getElementById('div_masque'))
	{
		/*div_masque = document.createElement("div");
		div_masque.setAttribute('id','div_masque');
		div_masque.style.display = 'none';
		*/
		var objBody = $$('body')[0];

		objBody.appendChild(Builder.node('div',{id:'div_masque'}));
		$('div_masque').hide().observe('click', (function() { fermer_fenetre(); }).bind(this));
	}
	else
	{
		
	}
	div_masque	=	document.getElementById('div_masque');	
	
	var db	=	document.documentElement.clientWidth;
	var D	=	document;
	db =! D.documentElement.clientWidth ? D.body : D.documentElement //quirk IE6
	var gk	=	window.Event ? 1 : 0//Gecko;
	var sy	=	gk ? document.documentElement.scrollTop : db.scrollTop;  

	var arrayPageSize 			=	getPageSize();
	div_fenetre					=	MM_findObj(id_fenetre);
	div_masque.style.height		=	arrayPageSize[1]+'px';
	
	// Effets scriptaculous
	new Effect.Appear(div_masque, { duration: 0.2, from: 0.0, to: 0.8 });
	centrerDiv(div_fenetre);
	interval	=	setInterval("centrerDiv(div_fenetre)", 100);

	div_fenetre.style.display	=	"block";
}

function fermer_fenetre()
{
	new Effect.Fade(div_masque, { duration: 0.2, from: 0.8, to: 0.0 });
	div_fenetre.style.display	=	"none";
	clearInterval(interval);
}

function getValue(id)
{
	return MM_findObj(id).value;
}

function getStyle(x,styleProp)
{
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function centrerDiv(div)
{
	var Scroll	=	getScroll();
	ScrollX		=	Scroll[0];
	ScrollY		=	Scroll[1];
	
	var size	=	getViewPortSize();
	width		=	size[0];
	height		=	size[1];
	
	if(div.style.height == '')
		divHeight	=	getStyle(div, 'height');
	else
		divHeight	=	div.style.height;
	if(div.style.width == '')
		divWidth	=	getStyle(div, 'width');
	else
		divWidth	=	div.style.width;
		
	// On enleve le 'px'
	divHeight	=	divHeight.substr(0, divHeight.length - 2);
	divWidth	=	divWidth.substr(0, divWidth.length - 2);
	
	if(divHeight < height)
		div.style.top	=	((height / 2 - divHeight / 2 + ScrollY)) + "px";
	else
		div.style.top	=	(25 + ScrollY) +'px';
	
	if(divWidth < width)
		div.style.left	=	((width / 2 - divWidth / 2 + ScrollX)) + "px";
	else
		div.style.left	=	(25 + ScrollX) +'px';
}

function getScroll()
{
	if (navigator.appName=="Microsoft Internet Explorer")
	{
		ScrollY = document.documentElement.scrollTop + document.body.scrollTop;
		ScrollX = document.documentElement.scrollLeft + document.body.scrollLeft;
	}
	else
	{
		ScrollY = window.pageYOffset;
		ScrollX = window.pageXOffset;
	}
	return new Array(ScrollX, ScrollY);
}

function getViewPortSize()
{
	/*
	if (document.body)
	{
		var larg = (document.body.clientWidth);
		var haut = (document.body.clientHeight);
	}
	else
	{
		var larg = (window.innerWidth);
		var haut = (window.innerHeight);
	}
	*/
	var viewportwidth;
 	var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	return new Array(viewportwidth, viewportheight);
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} 
	else 
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) 
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight) 
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) 
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} 
	else 
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	} 
	else 
	{
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function verif_date(date)
{
	var e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");			
	if (!e.test(date)) // On teste l'expression régulière pour valider la forme de la date
	{
		return false;
	}	
	return true;
}

function realOffset(el, offsetType) {

 var offset = 0;

 while(el) {
  offset += el[offsetType]; 
  el = el.offsetParent;
 }

 return offset;

}

String.prototype.no_space = function ()
{
 return this.replace(/(\s*)/g,"");
}

String.prototype.virgule_to_point = function ()
{
 return this.replace(/(,)/g,".");
}


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_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_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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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 affiche_element(nom_el)
{
	monElement = MM_findObj(nom_el);
	if (monElement.style.display == 'none')
		monElement.style.display = '';
	else
		monElement.style.display = 'none';
}

function affiche_div(nom_el)
{
	monElement = MM_findObj(nom_el);
	if (monElement.style.display == 'none')
		monElement.style.display = 'block';
	else
		monElement.style.display = 'none';
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=args[i+1]; if ((val=trim(val.value))!="") {
		if (test.indexOf('isDate')!=-1) {
			if(!isDate(val))
				errors+='- '+nm+' doit être une date existante au format jj/mm/aaaa.\n';
		}
		else  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' doit être une adresse email valide.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' doit être 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 être un nombre compris entre '+min+' et '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' est obligatoire.\n'; }
  } 
  if (errors)
  	 alert('Les erreurs suivantes ont été trouvées:\n'+errors);
  document.MM_returnValue = (errors == '');
}