// JavaScript Document
var fenetrefixe=0;
function fenetre_fix(URLStr, left, top, width, height)
{ 
  if(fenetrefixe)
  {
    if(!fenetrefixe.closed) fenetrefixe.close();
  }
  fenetrefixe = open(URLStr, 'fenetre_fixe', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}
var fenetrefixe2=0;
function fenetre_fix2(URLStr, left, top, width, height)
{ 
  if(fenetrefixe2)
  {
    if(!fenetrefixe2.closed) fenetrefixe2.close();
  }
  fenetrefixe2 = open(URLStr, 'fenetre_fixe2', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}


// fonction qui calcule et retourne la hauteur de la fenetre du navigateur (en fct du navigateur.
// cette hauteru est ensuite utilisable (ajout de "px" effectué).
function CalculeHeight(id)
{
if (document.all)
	{
	return document.all.id.offsetHeight + "px";		
	}
	else
	{
	return document.getElementById(id).offsetHeight + 20 + "px";
	}
}

function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}

/* fonction pour retailler l'ecran à l'ouverture de la fenetre
Appeler cette foncton par :
<body onLoad="resizing(700,720);"> 
*/
		function resizing(newwidth,newheight) {
			self.moveTo((screen.availWidth/2)-(width/2),0);
			if (document.layers) {
					width < screen.availWidth;
					height < screen.availHeight;
			} else {
					var width = screen.availWidth;
					var height = screen.availHeight;
			}
			if (width > newwidth) {
				width = newwidth;
				}
			if (height > newheight) {
				height = newheight;
				}
 			// self.resizeTo(width, height);
 			self.resizeTo(width, screen.availHeight);
			// self.moveTo((screen.availWidth/2)-(width/2), (screen.availHeight/2)-(height/2));
			self.moveTo((screen.availWidth/2)-(width/2),0);
		}
// Vide le texte dans la balise de message :
function ChangeImage(Img, Source)
	{
	document.getElementById(Img).src = Source;
	}

		
//changer la position de l'image. Utilise par la page accueil. (pour les actualites)		
	function ImagePosition(id,Left)
		{
		var DivImg = document.getElementById(id).style;
		Img = document.getElementById("img" + id);
		DivImg.marginTop =  "-" + (20+ parseInt(Img.height)) + "px";
		if (Left =="o")
			DivImg.marginLeft =  ((parseInt(Img.width))/2)- (parseInt(Img.width)) + "px";
		}


function _show(calque){
	try{
		document.getElementById(calque).style.visibility="visible";
		document.getElementById(calque).style.display="block";
	}catch(e){}
}
function _hide(calque){
	try{
		document.getElementById(calque).style.visibility="hidden";
		document.getElementById(calque).style.display="none";
	}catch(e){}
}

function showHide(calque){
	if (document.getElementById(calque).style.visibility=="hidden" || document.getElementById(calque).style.display=="none"){
		_show(calque);
	}else{
		_hide(calque);
	}
}

function showFondSurimpression(){
	w="800";
	h="600";
	
	try{
		if (document.documentElement && (document.documentElement.clientWidth||document.documentElement.clientHeight)){
			// IE 6+
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}else if ( typeof( window.innerWidth ) == 'number' ){
			// Non IE
			w = window.innerWidth;
			h = window.innerHeight;
		}else if(document.body && (document.body.clientWidth||document.body.clientHeight )){
			// Old IE
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}		
	}catch(e){}	
	var fd = document.getElementById("surimpression");
	_show("surimpression");
	fd.style.width=w;
	fd.style.height=h;	
}
function HideSurimpression1() {
	_hide('surimpression');
	_hide('PremierPlan');
	}
function HideSurimpression2() {
	_hide('surimpression');
	_hide('PremierPlan2');
	}


/* fonction pour ajouter des evenements  : id de l'elt, nom de l'evenement, fonction à lier à cet evenement */
function AjouterEvent( element, NomEvenement, fonc)
	{
	if( element.AjouterEventListener )
		{
		element.AjouterEventListener( NomEvenement, fonc, false );
		return true;
		}
	else if( element.attachEvent )
		{
		var r = element.attachEvent( 'on' + NomEvenement, fonc );
		return r;
		}
	else
		{
		element[ 'on' + NomEvenement ] = fonc;
		}
	return true;
	}


// Fct pour faire disparaitre les div contenant les formulaires de langue avant d'en  faire rapparaitre la bonne...
function FaireDisparaitreDivLangue(id)
	{ //--> on suppose qu'il y a au max 20 langues..... ce qui est déjà énorme
	div = id +"_";
	for (t = 0; t < 20 ; t++)
		{
		LaDiv = div + t ;
		if ($( LaDiv ) )
			{
			$( LaDiv ).style.display= 'none';
			}
		}
	}

// Savoir si une variable js est un tableau : retourne true ou false
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}


// Fonction pour remplacer un 'o' par un 'n' ou l'inverse, en fct du contenu de l'id
function SwapValue(id) 
{
	if (!$(id)) return false;
	if ($(id).innerHTML == 'o') $(id).innerHTML = 'n';else $(id).innerHTML ='o';
}



function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

// les deux fonctions suisvnates remontent le scroll progressivement en haut (avant ouverture fenetre surimpression)
function RollTo (x, y) {
window.scrollTo(x,y);}

function RollUp() { 
//position actuelle de la fenetre :
	a = 0.2;
	XY = getScrollXY();
	x = XY[0] ;
	y = XY[1] ; 
	while (y > 0)
		{
		XY = getScrollXY();
		x = XY[0] ;
		y = XY[1] ; 
		a = a + 0.2;
		y = y - a;
		RollTo(x, y);
		}
}

function attendreafficherimage(pgm,url)
	{
	//setTimeout("changerimage('"+pgm+"', '"+url+"')", 800);
	setTimeout("changerimage ( '"+ pgm + "','"+ url + "')", 800);
	}
function changerimage(pgm,url)
	{
	$('ProduitImage').src=url;
	$('ProduitImageA').onclick = function(){
		Effect.Appear('surimpression2', {duration:0.5, from:0.0, to:0.65});
		AjaxUpdater('Fenetre2', pgm, 'mediaurl', url );
		}
	Effect.Appear('ProduitImage', {duration:0.7 , from:0.0, to:1.0});
	}
