function isFunction(a) {
    return typeof a == 'function';
}

if (!isFunction(Array.prototype.push)) {
    Array.prototype.push = function (obj) {        
        this[this.length] = obj;
        return this.length;
    };
}

var OnLoadFunctions = new Array();
var OnLoadFunctionsEx = new Array();
function AddOnLoadFunction(OnLoadFunction, OnLoadFunctionEx)
{
    OnLoadFunctions.push(OnLoadFunction);
    OnLoadFunctionsEx.push(OnLoadFunctionEx);
}

window.onload = OnBodyLoad;
function OnBodyLoad()
{
	for (var i = 0; i < OnLoadFunctions.length; i++)
    {
        var cfunction = OnLoadFunctions[i];
        var cfunctionex = OnLoadFunctionsEx[i];
        eval("if (window." + cfunction + ") { " + cfunctionex + "; }");
    }
}

AddOnLoadFunction("OnPageLoad","OnPageLoad()");

function OnPageLoad()
{
	if( LoadMenu != null )
		LoadMenu();
		
	MM_preloadImages('images/bgaucheon.gif','images/bdroiton.gif');
}

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.0
  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 && document.getElementById) x=document.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 GetEventObject( evt )
{
	if( !evt && window.event )
	{
		evt = window.event;
	}

    if (evt)
	{
		if( evt.srcElement )
			return evt.srcElement;
		else
			return evt.target;
	}
	else
		return null;
}

function getRealLeft(imgElem)
{
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null)
	{
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
  	
    if(navigator.platform == "MacPPC" && navigator.userAgent.indexOf("MSIE") != -1)
    {           
        //Dans IE pour Mac, il faut additionner la marge du body.
        xPos += parseInt(document.body.currentStyle.marginLeft);       
    }
      	
	return xPos;
}

function getRealTop(imgElem)
 {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while ( tempEl != null )
	{
        //Note: On a pas besoin de passer par ici pour calculer la position avec
        //      opera car offsetTop contient déjà la bonne position.  On a pas besoin
        //      de l'additionnner aux positions de ses éléments parent.
  		yPos += tempEl.offsetTop;
  		
  		if(navigator.userAgent.indexOf("Opera") != -1 && yPos != 0)
  		    tempEl = null;
  		else
  		    tempEl = tempEl.offsetParent;	
  	}
  	
    if(navigator.platform == "MacPPC" && navigator.userAgent.indexOf("MSIE") != -1)
    {           
        //Dans IE pour Mac, il faut additionner la marge du body.
        yPos += parseInt(document.body.currentStyle.marginTop);       
    } 
              	
	return yPos;
}

function ValideContact()
{
	if(document.FContact.INom.value == "")
  {
    alert("Veuillez inscrire votre nom");
    document.FContact.INom.focus();
		return false;
  }
  else if(document.FContact.IEmail.value == "")
  {
    alert("Veuillez inscrire votre courriel");
    document.FContact.IEmail.focus();
		return false;
  }
  else if((document.FContact.IEmail.value.indexOf("@") == -1) || (document.FContact.IEmail.value.indexOf(".") == -1))
  {
    alert("Veuillez inscrire un courriel valide");
    document.FContact.IEmail.focus();
		return false;
  }
	else if(document.FContact.IMessage.value == "")
  {
    alert("Veuillez inscrire votre message");
    document.FContact.IMessage.focus();
		return false;
  }
}

// Changer l'image du diaporama
function ChangeImage(strNav)
{
	var oImgDiapo = document.getElementById("imgDiapo");
	
	var i = 0;
	var j = 0;
	var idxStr = oImgDiapo.src.substr(oImgDiapo.src.indexOf('.jpg')-2,2);

	if( idxStr.indexOf("0") == 0 )
		i = parseInt(idxStr.substr(1,1));
	else
		i =  parseInt(idxStr);
		
	if(strNav == "next")
	{
		j = i + 1;
		if(j == 12) j = 1;
	}
	else
	{
		j = i - 1;
		if (j == 0)	j = 11;
	}

	var istr = "";
	var jstr = "";
	
	if( i < 10 )
		istr = "0" + i;
	else
		istr = i;
		
	if( parseInt(j) < 10 )
		jstr = "0" + j;
	else
		jstr = j;
	
	oImgDiapo.src = oImgDiapo.src.replace(istr,jstr);
}
