var ECI_old_onload = null;
if (typeof window.onload == "function")
{
	ECI_old_onload = window.onload;
}
window.onload = function()
{
	var isIE5Mac = (!window.showModelessDialog && window.ActiveXObject && document.getElementById);
	if (ECI_old_onload)
	{
		ECI_old_onload();
		ECI_old_onload = null;
	}
	if (typeof preload_images == 'function')
	{
		preload_images();
	}
	if (typeof list_products == 'object')
	{
		rollover_accueil(list_products);
	}
	if (isIE5Mac) {fixBrowsers('IE5Mac');}
}

function fixBrowsers(what)
{
	if (what == 'IE5Mac')
	{
		var a = document.getElementById('metacontenu');
		var b = document.getElementById('navigation');
		var c = document.getElementById('accessibilite');
		var d = document.getElementById('signature');
		// s'assurer que nous ne sommes pas dans la version imprimable
		if (typeof eci_vi.args[eci_vi.arg] != "string")
		{
			if (a) {
			a.style.position = 'absolute';
			a.style.top = '90px';
			a.style.height = Math.max(a.offsetHeight, b.offsetHeight) + 'px'; }

			if (c) {
			c.style.visibility = 'hidden'; }

			if (d && a) {
			d.style.position = 'absolute';
			d.style.top = Math.max(a.offsetHeight, b.offsetHeight) + 'px'; }
		}
	}
	if (what == 'under_menu')
	{
		var nav = document.getElementById('navigation');
		var menu = document.getElementById('navigation').getElementsByTagName('ul')[0];
		var con = document.getElementById('contenu');
		var div = document.getElementById('navigation-bas');
		var pro = document.getElementById('promo-produits') || 1;
		// s'assurer que nous ne sommes pas dans la version imprimable
		if (typeof eci_vi.args[eci_vi.arg] != "string" && (nav && con && div && menu))
		{
			var h1 = nav.offsetHeight || nav.clientHeight;
			var h2 = con.offsetHeight || con.clientHeight;
			var h3 = menu.offsetHeight || menu.clientHeight;
			var h4 = pro.offsetHeight || pro.clientHeight || -180;
			var h5 = div.offsetHeight || div.clientHeight;
			if (!h1 || !h2 || !h3) return;
			//document.title = "menu=" + h3 + "; promo=" + h4 + "; div=" + h5 + "; nav=" + h1 + "; contenu=" + h2;
			if ((h2-h3-h4) < h5)
			{
				div.style.height = (h2-h3-h4+50) + 'px';
				document.body.style.backgroundImage = 'none';
			}
		}
	}
}

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 rollover_accueil(prod)
{
	if (!document.getElementById) return;
	var isIE5Mac = (!window.showModelessDialog && window.ActiveXObject && document.getElementById);
	for (var i = 0; i < prod.length; i++)
	{
		var el = document.getElementById(prod[i]);
		if (!el) continue;
		// remove cursor and click action from A inside DIV
		for (var j = 0, a; a = el.getElementsByTagName('a')[j]; j++)
		{
			a.onclick = function() { return false; }
			// IE5Mac crashes when setting cursor property
			if (!isIE5Mac) a.style.cursor = (document.all ? 'hand' : 'pointer');
		}
		el.getElementsByTagName('h2')[0].style.visibility = 'hidden';
		el.getElementsByTagName('h2')[0].style.backgroundColor = 'transparent';
		el.style.backgroundColor = 'transparent';
		// onclick go to href of first A inside el
		el.onclick = function()
		{
			location.href = this.getElementsByTagName('a')[0].href;
		}
		// onmouseover show text and change src of first image inside el
		el.onmouseover = function()
		{
			this.getElementsByTagName('img')[0].src = (this.getElementsByTagName('img')[0].src).replace(/\.jpg$/,'_on.jpg');
			this.getElementsByTagName('h2')[0].style.visibility = 'visible';
			window.status = this.getElementsByTagName('a')[0].href;
		}
		// onmouseout hide text and set back src of first image inside el
		el.onmouseout = function()
		{
			this.getElementsByTagName('img')[0].src = (this.getElementsByTagName('img')[0].src).replace(/_on\.jpg$/,'.jpg');
			this.getElementsByTagName('h2')[0].style.visibility = 'hidden';
			window.status = '';
		}
		if (!isIE5Mac) el.style.cursor = (document.all ? 'hand' : 'pointer');
	}
}


function getGet(s1, s2)
{
	var args = {};
	// retrieve arguments from location
	if (location.search)
	{
		var query = unescape(location.search.substring(1));
		var pairs = query.split(s2);
		for (var i = 0; i < pairs.length; i++)
		{
			var pos = pairs[i].indexOf(s1);
			if (pos == -1) { continue; }
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			args[argname] = String(value);
		}
	}
	return args;
}


function checkRadioButtonFromUrl(buttonId, argKey, argValue, argsSeparator, argValSeparator)
{
	if (!document.getElementById) return;
	var el = document.getElementById(buttonId);
	if (!el) return;
	var argsSep = argsSeparator;
	if (!el) return;
	if (typeof argsSeparator == 'object')
	{
		// trouvons quel est le séparateur pour les arguments en choisissant le plus fréquent
		for (var i = 0; i < argsSeparator.length; i++)
		{
			if (
				argsSeparator[i+1] &&
				location.href.split(argsSeparator[i+1]).length > location.href.split(argsSeparator[i]).length
			)
			{
				argsSep = argsSeparator.splice(i+1, 1)[0];
			}
			else
			{
				argsSep = argsSeparator.splice(i, 1)[0];
			}
		}
	}
	//alert(argsSep);
	var args = getGet(argValSeparator, argsSep);
	if (args[argKey] && args[argKey] == argValue) { el.checked = true; }
}


// pour images al?atoires
// imprime un ?l?ment style ou un ?l?ment img
// arguments de la fonction (obj,mode,pos,attr,sel) :
/*

obj = array de 1 ou 2 dimension(s) (object) REQUIRED

exemple 1 dimension:

	var logosInterne = [
	  "../../images/iu/bandeau-secondaire/defaut.jpg",
	  "../../images/iu/bandeau-secondaire/img01.jpg",
	  "../../images/iu/bandeau-secondaire/img02.jpg",
	  "../../images/iu/bandeau-secondaire/img03.jpg"
	];


exemple 2 dimensions:

	var logosAccueil = [
	  {
	    "milieu":"../images/iu/accueil/phare/01-milieu.jpg",
	    "bas":"../images/iu/accueil/phare/01-bas.jpg",
	    "haut":"../images/iu/bandeaupiv/bandeaux/accueil/01-haut.jpg"
	  },
	  {
	    "milieu":"../images/iu/accueil/phare/02-milieu.jpg",
	    "bas":"../images/iu/accueil/phare/02-bas.jpg",
	    "haut":"../images/iu/bandeaupiv/bandeaux/accueil/02-haut.jpg"
	  },
	  {
	    "milieu":"../images/iu/accueil/phare/03-milieu.jpg",
	    "bas":"../images/iu/accueil/phare/03-bas.jpg",
	    "haut":"../images/iu/bandeaupiv/bandeaux/accueil/03-haut.jpg"
	  },
	  {
	    "milieu":"../images/iu/accueil/phare/04-milieu.jpg",
	    "bas":"../images/iu/accueil/phare/04-bas.jpg",
	    "haut":"../images/iu/bandeaupiv/bandeaux/accueil/04-haut.jpg"
	  }
	];

*/

// mode = 'img' ou 'style' (string) REQUIRED
// pos = cl? du array si 2 dimensions (string) exemple: 'haut' ou null si pas de cl?
// attr = array des attributs (object) OPTIONAL exemple: ['alt=""','border="0"'] ou ['type="text/css"'] ou []
// sel = s?lecteur CSS si mode='style' (string) exemple: '#menu-accueil'

function imagesAleatoires(obj, mode, pos, attr, sel)
{
	if (document.layers) return;
	var out = '';
	if (typeof obj.alea == 'undefined')
	{
		obj.alea = Math.floor(Math.random()*obj.length);
	}
	out += (mode == 'img' ? '<img src="' : "\n\n<style");
	if (attr && attr.length && mode=='style' && sel)
	{
		for (var i=0; i<attr.length; i++)
		{
			out += (' ' + attr[i] + ' ');
		}
		out += (">\n" + sel + ' {background-image:url("');
	}
	out += (pos ? obj[obj.alea][pos] : obj[obj.alea]);
	out += (mode == 'img' ? '"' : "\");}\n");
	if (attr && attr.length && mode=='img')
	{
		for (var i=0; i<attr.length; i++)
		{
			out += (' ' + attr[i] + ' ');
		}
	}
	out += (mode == 'img' ? ' />' : "</style>\n\n");
	document.writeln(out);
}



/*

résultat cliquable

*/

function resultat_cliquable_click(ref, url)
{
	location = url;
}

function resultat_cliquable_over(ref, class_name)
{
	ref.className = class_name;
}

function resultat_cliquable_out(ref, class_name)
{
	ref.className = class_name;
}

/*
script provided by http://www.howtocreate.co.uk/perfectPopups.html
changes made:
- changed target _blank to imgWin
- added a var statement for PositionX, etc.
- if (scW < oW || scH < oH) { imgWin = window.open(document.images[0].src); if (imgWin) self.close(); }
*/


//really not important (the first two should be small for Opera's sake)
var PositionX = 10,
PositionY = 10,
defaultWidth = 600,
defaultHeight = 400;

//kinda important
var AutoClose = false;

//don't touch
function popImage(imageURL,imageTitle){
	imgWin = window.open('','imgWin','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
		'function resizeWinTo() {\n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }\n'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'if (scW < oW || scH < oH) { imgWin = window.open(document.images[0].src); if (imgWin) self.close(); }\n'+
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
		'<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}








// impression keep form data
function ecritBoutonImpression()
{
	if (typeof vi_html == 'string') { document.writeln(vi_html); }
}
// impression no unload and keep forms data
if (!window.imprimerEC && !window.apercuEC && !window.boutonsEC) {
window.imprimerEC = function(path,lang)
{

	function feuilleDeStyle()
	{
		if	(
				(String(path) == "undefined") ||
				(!document.createStyleSheet && !document.createElement) ||
				!document.getElementsByTagName ||
				!document.body.insertBefore ||
				!document.body.appendChild
			)
		{
			return;
		}
		if (String(lang) == "undefined") { lang = 'fr'; }
		this.injecter(this.boutons());
	}

	feuilleDeStyle.prototype.boutons = function()
	{
		this.imp = Imp; 
		this.ret = Ret;
		this.nav = '';
		if (window.print)
		{
			this.nav +=
			(
				'<input type="button" ' +
				'onclick="window.print()" '+
				'value="' + this.imp + '" />&#160;&#160;' +
				'<input type="button" ' +
				'onclick="window.apercuEC.disabled=true; window.boutonsEC.style.display=\'none\'" ' +
				'value="' + this.ret + '" /><hr />'
			);
		}
		this.div = document.createElement("DIV");
		this.div.setAttribute('id','printbuttons');
		this.div.innerHTML = this.nav;
		return this.div;
	}

	feuilleDeStyle.prototype.injecter = function(menu)
	{
		this.body = document.getElementsByTagName("BODY")[0];
		window.boutonsEC = this.body.insertBefore(menu,this.body.firstChild);
		if (document.createStyleSheet)
		{
			window.apercuEC = document.createStyleSheet(path);
		}
		else
		{
			this.link = document.createElement("LINK");
			this.link.setAttribute('rel','stylesheet');
			this.link.setAttribute('type','text/css');
			this.link.setAttribute('href',path);
			window.apercuEC = document.getElementsByTagName("HEAD")[0].appendChild(this.link);
		}
	}

	if (window.apercuEC && window.boutonsEC)
	{
		window.apercuEC.disabled = false;
		window.boutonsEC.style.display = 'block';
	}
	else
	{
		new feuilleDeStyle();
	}

	if (window.scroll) { window.scroll(0,0); }

}}
