/*
	bandeau de la ville et fonctions MM
*/

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_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];}
}

// Fonctions pour les flash
function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  }	else {
    return document[movieName]
  }
}
function movieIsLoaded (theMovie) {
  if (typeof(theMovie) != "undefined") {
    return theMovie.PercentLoaded() == 100;
  } else {
    return false;
  }
}
function go(theFrame, movieName) {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).GotoFrame(theFrame);
	thisMovie(movieName).Play();
  }
}
// switch lang
/* Dialogue CONFIRM */
function confirmer(url,msg){
	var alerte;
	switch (msg) {
		case 'fr' :
			alerte = "Cette page n'est disponible qu'en Anglais";
			break;
		case 'en' :
			alerte = "This page is only available in French";
			break;
		default :
			break;
	}
	var redir = confirm(alerte);
	if (redir==true) {
		window.location=url;
	}
}
function Translate_this(nomSiteWeb){
  var ici = document.location.href;
  (ici.indexOf(nomSiteWeb + "_en")!=-1)?ici=ici.replace(nomSiteWeb + "_en", nomSiteWeb + "_fr"):ici=ici.replace(nomSiteWeb + "_fr", nomSiteWeb + "_en");
  this.location = ici;
}


// precharge boutons bandeau (pas de onload sur le body tag!!! <body onload=""
var precharge_bandeau_ville_old_onload = null;
if (typeof window.onload == 'function')
{
	precharge_bandeau_ville_old_onload = window.onload;
}
window.onload = function()
{
	var isIE5Mac = (!window.showModelessDialog && window.ActiveXObject && document.getElementById);
	if (precharge_bandeau_ville_old_onload)
	{
		precharge_bandeau_ville_old_onload();
		precharge_bandeau_ville_old_onload = null;
	}
	if (!standalone_mode)
	{
		MM_preloadImages(
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_arrond.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_fleche.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_mairie_en.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_vie_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/background_uniforme.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_arrond_en.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_index.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_mairie_en_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bt_plus.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_acces.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_arrond_en_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_index_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_mairie_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/coin10bd.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_acces_en.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_arrond_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_info.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_pratique.gif',
			'/pls/portal/docs/page/librairie_fr/images/coin10bg.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_acces_en_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_attraits.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_info_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_pratique_en.gif',
			'/pls/portal/docs/page/librairie_fr/images/coin10hd.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_acces_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_attraits_en.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_langue.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_pratique_en_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/coin10hg.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_accueil.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_attraits_en_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_langue_en.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_pratique_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/fleche_noir.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_accueil_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_attraits_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_langue_en_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_recherche.gif',
			'/pls/portal/docs/page/librairie_fr/images/ligne_390.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_affaires.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_bottin.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_langue_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_recherche_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/spacer.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_affaires_en.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_bottin_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_logob.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_vie.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_affaires_en_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_contactez.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_logor.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_vie_en.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_affaires_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_contactez_f2.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_mairie.gif',
			'/pls/portal/docs/page/librairie_fr/images/bn_corpo_vie_en_f2.gif'
		);
	}
	if (isIE5Mac) {fixBrowsers('IE5Mac');}
}

function fixBrowsers(browser)
{
	if (browser == 'IE5Mac')
	{
		var a = document.getElementById('metacontenu');
		var b = document.getElementById('wrapper-right');
		var c = document.getElementById('outils');
		var d = document.getElementById('cityfooter');
		var e = document.getElementById('menuprincipal');
		var f = document.getElementById('wrapper-innerright');
		var g = document.getElementById('nav-alt').all.tags('A')[1];
		if (typeof args[arg] != 'string')
		{
			if (f) {with (f.style)
			{
				position = 'absolute';
			}}
			else if (b) {with (b.style)
			{
				position = 'absolute';
			}}
			if (f) {
				a.style.height = Math.max((a.offsetHeight + f.offsetHeight),800) + 'px';
			} else if (b) {
				a.style.height = Math.max((a.offsetHeight + b.offsetHeight),800) + 'px';
			}
			if (c) {with (c.style)
			{
				position = 'absolute';
				bottom = '20px';
			}}
			if (d) {with (d.style)
			{
				position = 'absolute';
				bottom = '0px';
			}}
			if (e) {with (e.style)
			{
				paddingTop = '35px';
			}}
			if (g) {with (g.style)
			{
				position = 'relative';
				top = '60px';
			}}
		}
		else
		{
			if (d) {with (d.style)
			{
				width = '500px';
				overflow = 'hidden';
			}}
		}
	}
}





/*
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;
}

var preload_images_old_onload = null;
if (typeof window.onload == "function")
{
	preload_images_old_onload = window.onload;
}
window.onload = function()
{
	function hide_focus()
	{
		if (!document.compatMode) { return; }
		var els = ['a','area','img'], hf = [], i, j;
		for (i = 0; i < els.length;  i++)
		{
			hf[i] = document.getElementsByTagName(els[i]);
		}
		for (i = 0; i < hf.length; i++)
		{
			for (j = 0; j < hf[i].length; j++)
			{
				hf[i][j].hideFocus = true;
			}
		}
	}
	if (preload_images_old_onload)
	{
		preload_images_old_onload();
		preload_images_old_onload = null;
	}
	if (typeof preload_images == 'function')
	{
		preload_images();
		//hide_focus();
	}
}

// copyright - begin
//
//   Copyright (C) 2005 Espace Courbe inc.
//   You are free to modify and redistribute this code as long
//   as the following message is included:
//
//   Last modified:
//   $Date: 2006/09/06 20:47:20 $
//
//   Portions Copyright (C) 2006 Espace Courbe inc.
//   Home Page: http://www.espacecourbe.com/
//
//   Author: Christian Fecteau -- christian.fecteau@espacecourbe.com
//   Creation:  2005/12/06 17:05:02
//
// copyright - end

/*

$Id: fonctions.js,v 1.6 2006/09/06 20:47:20 christian Exp $
$Revision: 1.6 $

*/

function ecritBoutonImpression()
{
	if (typeof vi_html == 'string') { document.writeln(vi_html); }
}

function getGET(s1, s2)
{
	// 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);
		}
	}
}

function goImp(argn, se1, value, se2, targ)
{
	if (String(argn) == "undefined") { argn = arg; }
	if (String(se1) == "undefined") { se1 = sep1; }
	if (String(value) == "undefined") { value = val1; }
	if (String(se2) == "undefined") { se2 = sep2; }
	if (String(targ) == "undefined") { targ = tar; }
	var
	t = eval('window.' + targ),
	v = argn + se1 + value,
	c = argn + se1,
	w = eval("(t.location.href).replace(/" + se2 + "*$/,'')"),
	q = w.match(/\?[^#]*/),
	p = eval('/' + c + '[^' + se2 + ']*/g'),
	h = w.match(/#.*/);
	if (t.focus) t.focus();
	if (w.indexOf(c) != -1)
	{
		t.location.href = w.replace(p, v);
	}
	else if (q)
	{
		q = q[0] + se2 + v;
		t.location.href = w.replace(/\?[^#]*/, q);
	}
	else if (w.indexOf('#') != -1)
	{
		w = w.replace(/#.*/,'');
		t.location.href = w + '?' + v + h[0];
	}
	else
	{
		t.location.href = w + '?' + v;
	}
}

function ecritNav(imp, ret, onclk)
{
	if (typeof args[arg] == "string" && args[arg] == val1)
	{
		if (String(onclk) == "undefined") { onclk = 'retourEcran()'; }
		var n = '<div id="printbuttons"><form action="">';
		n += '<input onclick="window.print()" ';
		n += 'value="'+imp+'" type="button">&nbsp;&nbsp;';
		n += '<input onclick="'+onclk+'" value="'+ret+'" type="button" ';
		n += '/></form><hr /></div>';
		if (window.print) document.writeln(n);
	}
}

function retourEcran(targ)
{
	//history.go(-1);
	if (String(targ) == "undefined") { targ = tar; }
	var s = eval('/(\\?|\\' + sep2 + ')' + arg + sep1 + val1 + '/g');
	var t = eval('window.' + targ);
	var l = t.location.href;
	if (l.match(s))
	{
		eval("location.href = (t.location.href).replace(" + s + ",'')");
	}
	else
	{
		goImp(arg, sep1, val2, sep2);
	}
}

function checkVars()
{
	if (
		typeof href != 'undefined' &&
		typeof title != 'undefined' &&
		typeof Imp != 'undefined' &&
		typeof Ret != 'undefined'
	)
	{
		return true;
	}
	return false;
}


var args = {};

function linksNoClick(el)
{
	var a = null;
	var isIE5Mac = (!window.showModelessDialog && window.ActiveXObject && document.getElementById);
	if (document.getElementsByTagName) { a = document.getElementsByTagName(el); }
	else if (document.all) { a = document.all.tags(el); }
	else if (document.links) { a = document.links; }
	if (!a) return;
	for (var i = 0; i < a.length; i++)
	{
		a[i].onclick = function()
		{
			this.blur();
			window.status = '';
			return false;
		}
		a[i].onmouseover = function() { window.status = ''; return true; }
		if (!isIE5Mac && a[i].style) { a[i].style.cursor = 'default'; }
	}
}

if (checkVars())
{
	if (typeof arg == 'undefined') arg = 'vi';
	if (typeof sep1 == 'undefined') sep1 = '=';
	if (typeof val1 == 'undefined') val1 = '1';
	if (typeof val2 == 'undefined') val2 = '0';
	if (typeof sep2 == 'undefined') sep2 = '&';
	if (typeof tar == 'undefined') tar = 'self';
	getGET(sep1, sep2, val1);
	if (typeof args[arg] == "string" && args[arg] == val1)
	{
		if (document.title) { document.title += title; }
		document.writeln('<link ');
		document.write('rel="stylesheet" ');
		document.write('type="text/css" ');
		document.write('href="' + href + '" ');
		document.write('/>');
		if (typeof window.onload == "function" && window.scroll)
		{
			var impressionEC_old_onload = window.onload;
			window.onload = function()
			{
				if (impressionEC_old_onload)
				{
					impressionEC_old_onload();
					impressionEC_old_onload = null;
				}
				linksNoClick("A");
				setTimeout('window.scroll(0,0)',500);
			}
		}
	}
}

