// Version 31/03/2007


/* Test petit navigateur et renvoie sur mobile
if((!screen.width || screen.width < 600) && location.hostname.substring(0,7) != 'mobile.') {
location.replace('http://mobile.'+location.hostname+location.pathname); }  */


/* Test Explorer Macintosh */
var agent = navigator.userAgent.toLowerCase(); 
if ( ( agent.indexOf("firefox") == -1 && agent.indexOf("safari") == -1 
          && agent.indexOf("konqueror") == -1 && agent.indexOf("galeon") == -1 
          && agent.indexOf("opera") == -1 && agent.indexOf("msie") != -1 )
          && agent.indexOf("mac") != -1) { var agent = "Explorer"; }

if(agent== 'Explorer' && window.location.href.indexOf('/en/')==-1) 
          alert("Ce site est conforme aux dernières normes en vigueur pour l'accès aux personnes handicapées.\n\n"+
                "Depuis le 31 janvier 2006, Microsoft conseille l'utilisation de Safari et déconseille formellement "+
                "l'utilisation d'Explorer sur Macintosh car périmé et ne respectant pas ces normes. Vous pouvez "+
                "accéder au site, mais certaines images, et animation Flash, risquent de ne pas se charger et la "+
                "mise en page d'être erratique.\n\nTous les navigateurs récents sont compatibles, sur toutes les plateformes.");
else if(agent == 'Explorer') 
          alert("This website is compliant with the latest recommandations for disabled people access.\n\n"+
                "Since January 31st 2006, Microsoft suggest the use of Safari and doesn't support Explorer on Macintosh. "+
                "You can access this website althougth not fully compatible. You won's be able to see the Flash "+
                "animations due to lack of XHTML support in Explorer.");




// Fonction ouvreFenetre (Pop Up)
// url,nom,dimx,dimy,menus,centrer,masque

var browser = 0; var version = parseInt(navigator.appVersion);
if (navigator.appName.substring(0,8) == "Netscape" && version > 3 ) browser = 1;
if (navigator.appName.substring(0,9) == "Microsoft" &&  version >= 4 ) browser = 1;
if (navigator.appName.substring(0,9) == "Microsoft" &&  version > 3 && navigator.appVersion.indexOf("Mac") > 0 ) browser = 1;

var newwindow;

function popup(url1,nom,dimx,dimy,menus,centrer,masque) {
  if (browser == 0 && navigator.appVersion.indexOf("Win") > 0) dimy=dimy-19;
  if (centrer == 2){ LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-dimx)):100;
                     TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-dimy)-75)):100;}
  if (centrer == 1){ LeftPosition=(screen.width)?(screen.width-dimx)/2:100;
                     TopPosition=(screen.height)?(screen.height-dimy)/2:100;}
       if (menus == 1) { featur = "toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,"; } 
  else if (menus == 2) { featur = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,"; }
  else if (menus == 3) { featur = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,"; }
  else if (menus == 4) { featur = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,"; }
                  else { featur = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,"; }
  featur = featur + "width="+ dimx + ",height=" + dimy + ",top="+TopPosition+",left="+LeftPosition+',screenX='+LeftPosition+',screenY='+TopPosition;
  if (masque == 1) { newwindow = window.open("",nom,featur); cl.blur(); self.focus(); cl.location=url1; }
              else { newwindow = window.open(url1,nom,featur); if (window.focus) { newwindow.focus() } }
  }




function SWFobject(url,width,height,bgcolor) {
  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
	  'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '+
	  'width="'+width+'" height="'+height+'">'+"\n");
  document.write('<param name="wmode" value="opaque" />'+"\n");
  document.write('<param name="movie" value="'+bgcolor+'" />'+"\n");
  document.write('<param name="menu" value="false" />'+"\n");
  document.write('<param name="FlashVars" value="" />'+"\n");
  document.write('<param name="scale" value="noscale" />'+"\n");
  document.write('<param name="salign" value="tl" />'+"\n");
  document.write('<param name="quality" value="high" />'+"\n");
  document.write('<param name="bgcolor" value="'+bgcolor+'" />'+"\n");
  document.write('<embed src="'+url+'" flashvars="" width="'+width+'" height="'+height+
	  '" scale="noscale" quality="high" bgcolor="'+bgcolor+'" salign="tl" menu="false" '+
	  'pluginspage="http://www.macromedia.com/go/getflashplayer" '+
	  'type="application/x-shockwave-flash" wmode="opaque" ></embed>'+"\n");
  document.writel('</object>'+"\n");
}




// Fonction Flyer
// par Michel Poulain (La Shampoo)

var popUpwin=new Date(); var gauche=0; var haut=0; 

function popImage(image,largeur,hauteur,couleur,titre,centrer,text,url) {

    if(url===undefined) url=""; 
    if(text===undefined) text="";
    titre   = titre.replace(/\"/g,'&quot;');
    hauteur = (hauteur*1)-1; // to avoid vetical lift 
    largeur = (largeur*1)-2; // turn into numerical
    
if(centrer) { 

    gauche = (screen.width)?(screen.width-largeur)/2:100;
    haut =(screen.height)?(screen.height-hauteur)/2:100;

} else {

    if( (screen.width-(largeur+gauche))<0 ) 
        { gauche=0; haut=haut+200; }
    if( (screen.height-(hauteur+haut))<0 ) 
        { gauche=0; haut=0; }

}

    popUpwin++; page = window.open('about:blank',popUpwin,
    'width='+largeur+',height='+hauteur+
    ',menubar=no,status=no,toolbar=no,scrollbars=no'+
    ',resizable=no,dependent=yes,left='+gauche+',top='+haut+
    ',screenX='+gauche+',screenY='+haut);

    setTimeout('displayImage("'+image+'","'+titre+
    '","'+largeur+'","'+hauteur+'","'+couleur+'","'+text+'","'+url+'")',20); 
    
    gauche=gauche+largeur; //window.focus();

}


function displayImage(image,titre,largeur,hauteur,couleur,text,url) { 

    var contenu = "<html><head><title>"+titre+"</title>\n"+
    '<' + 'script type="text/javascript" language="javascript">'+
    'document.onkeypress = function Ferme() { '+
    'if (event.keyCode==27) window.close(); }<'+'/script>'+
    "<base href='http://"+location.host+"/'></head>\n" +
    '<body bgcolor="'+couleur+'" LEFTMARGIN="0" MARGINWIDTH="0" ' +
    'TOPMARGIN="0" MARGINHEIGHT="0"><center>' + "\n";
    if(url!="") contenu = contenu+'<a href="'+url+'" target="_blank">';
    contenu = contenu+'<img src="'+image+'" alt="'+titre+
	          '" border="0" onclick="window.close()" title="'+text+'" />';
    if(url!="") contenu = contenu+'</a>';
    contenu = contenu+"\n" +'</center></body></html>';

    page.document.write(contenu);

}






function STsetCookie(name,value,mins) {
    if (isNaN(mins)) mins = 365 * 24 * 60; // 1 year
    var expires = new Date();
    expires.setTime(expires.getTime() + (mins*60*1000));
    document.cookie = escape(name) + "=" + escape(value) + "; path=/; expires=" + expires.toGMTString();
}


function STgetCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}


function STgetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
         var j = i + alen;
         if (document.cookie.substring(i, j) == arg)
                return STgetCookieVal(j);
         i = document.cookie.indexOf(" ", i) + 1;
         if (i == 0) break;
    }
    return 0;
}


//
// cookies accepted?  STcookiesOK = 1; 
var test = Math.random(); STsetCookie('STtest',test); 
STcookiesOK = (STgetCookie('STtest')==test) ? 1 : 0; 
STsetCookie('STtest',0,0); // delete cookie



//
// Floating scroll DIV with min value
//
function FloatTopDiv(idDiv, startY, minY)
{
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(y){this.style.top=y+'px';};
		el.y = startY;
		return el;
	}
	window.stayTopLeft=function()
	{
		var pY = ns ? pageYOffset : document.body.scrollTop;
		if(startY >= pY && pY <= minY) pY = startY-pY;
		ftlObj.y += (pY + minY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml(idDiv);
	stayTopLeft();
}


// Instant form submission + Ajax rutines + autoinit
// by Michel Poulain 31.03.2007


var xmlhttpTimer; var xmlhttpFunction;
var xmlhttp = getHTTPObject();


addEvt(window, "load", instantForm_init);


function instantForm(formID,next,microseconds) {
    clearInterval(xmlhttpTimer);
    xmlhttpFunction = next;
    microseconds = (isNaN(microseconds)) ? 0 : microseconds;
    xmlhttpTimer = setInterval("sendForm('"+formID +"')", microseconds);
}


function instantForm_init() {
    if (!document.getElementsByTagName) return;
    Frms = document.getElementsByTagName("form");
    for (m=0;m<Frms.length;m++) {
        thisFrm = Frms[m];
        if (((' '+thisFrm.className+' ').indexOf("instantform") != -1) && (thisFrm.id)) {
			thisFrm.onsubmit = function() { return false; };
            for (n=0;n<thisFrm.length;n++) {
				thisTag=thisFrm[n];
                tag=thisTag.tagName.toLowerCase();
                if((tag=="input" || tag=="select" || tag=="textarea") && thisTag.name) {
                    thisTag.onkeyup=eval(thisFrm.id+"Function");thisTag.onkeyup();
                    thisTag.onchange=eval(thisFrm.id+"Function");thisTag.onchange();
                }
            }
        }
    }
}


function sendForm(formID,next) {
    clearInterval(xmlhttpTimer);
	if(next!==undefined && next) xmlhttpFunction = next;
    var parameters = form2string(formID);
    var n = document.getElementById(formID);
    getHTTPrequest(n.action,n.method,parameters,handleHttpResponse);
    return false;
}


function getHTTPrequest(url,method,parameters,callback) {
  method = (method.toUpperCase()=="POST") ? "POST" : "GET";
  if(method=="GET" && parameters) {
    url += "?"+parameters;
    parameters = null;
  }
  xmlhttp.open(method,url,true);
  if(method=="POST") 
      xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xmlhttp.onreadystatechange = callback;
  xmlhttp.send(parameters);
  return false;     
}


function handleHttpResponse() {
  //0 = non initialisé 
  //1 = en cours de chargement 
  //2 = chargé 
  //3 = interaction 
  //4 = terminé
  //alert("xmlhttp.readyState="+xmlhttp.readyState);
  if (xmlhttp.readyState == 4) {
    //http.getAllResponseHeaders()
    //http.getResponseHeader('Last-Modified')
    //alert("Reponse="+xmlhttp.responseText);
    if(xmlhttpFunction) eval(xmlhttpFunction);
  }
}


function getHTTPObject() {
  var temp;
  try {
    temp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
     try {
        temp = new ActiveXObject("Microsoft.XMLHTTP");
     } catch (E) {
        temp = false;
     }
  }
  if (!temp && typeof temp != 'undefined') {
    try {
      temp = new XMLHttpRequest();
    } catch (e) {
      temp = false;
    }
  }
  return temp;
}



// Form parsing & handling

function form2string(formID) {
    var n = document.getElementById(formID);
	if(!n) alert("No "+formID);
    var parameters = new Array();
    var v = '';
    for (var i=0; i < n.elements.length; i++) {
        var j = n.elements[i];
        if(j.name && j.value) {
            v=encodeURI(j.value);
            v=v.replace(/\+/g,'%2B'); 
            v=v.replace(/&/g,'%26'); 
            parameters.push(encodeURI(j.name)+"="+v);
        }
    }
    return parameters.join('&');
}

function formDisable(formID,state) {
    var n = document.getElementById(formID);
    for (var i=0; i < n.elements.length; i++) {
        n.elements[i].disabled = state;
    }
    return false;
}

function trim(string) { 
    return string.replace(/(^\s*)|(\s*$)/g,''); 
} 




function testEmail(Email) {
    regCode=/([0-9a-z_\-\.]+)@([0-9a-z_\-\.]+)\.([a-z]{2,4})/ig;
    return (regCode.test(Email)) ? true : false;
}


function majBloquee(e) {
    var item = (arguments[1] && document.getElementById(arguments[1])) ? 
        document.getElementById(arguments[1]) : false;
    kc = e.keyCode ? e.keyCode : e.which;
    sk = e.shiftKey ? e.shiftKey : ((kc == 16) ? true : false );
    if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk)) {
        if(item) item.style.visibility = 'visible';
        alert("Votre touche Majuscules vérouillées est activée");
    } else if(item) item.style.visibility = 'hidden';
}


function minMAJ() {
    if(!arguments[0]) return;
        else champ=arguments[0];
    var alerte = (typeof(arguments[1]) == "string") ? arguments[1] :
        "Respectez les minuscules et les Majuscules !\n\n"
		+"- les Noms Propres commencent par une majuscule\n"
		+"- un nom de rue commence par une majuscule\n"
		+"- le reste est en minuscules";
    var min = 0; var MAJ = 0;
    var texte = champ.value;
    for (i=0;i<texte.length;i++) {
        if (texte.charAt(i).toLowerCase() == texte.charAt(i).toUpperCase()) { }
        else if (texte.charAt(i) == texte.charAt(i).toUpperCase()) MAJ++;
        else if (texte.charAt(i) == texte.charAt(i).toLowerCase()) min++;
    }
    texte = texte.charAt(0).toUpperCase()+texte.substr(1).toLowerCase();
    if((MAJ && !min) || (min && !MAJ) || (MAJ > min)) { 
	alert(alerte);
	champ.value=texte; champ.focus();
	return true;
    }
    return false; 
}




// HTML handling

function changeStyleTAG(tag,prop,val) {
    var elements = document.getElementsByTagName(tag);
    for(var i = 0; i < elements.length; i++) {
        elements.item(i).style[prop] = val;
    }
}

function changeStyleID(objId,prop,val) {
    if (document.getElementById) {
        obj = document.getElementById(objId);
		obj.style[prop] = val;
    }
}

function changeHTML(objID,texte,ajout) {
    var obj = document.getElementById
            ? document.getElementById(objID) 
            : document.all[objID] ;
	obj.innerHTML = (ajout) ? obj.innerHTML+texte : texte;
}




// Fade in & out rutines

function setOpacityMP(objId, opacity) {

  if (document.getElementById) {
	obj = document.getElementById(objId);
  } else return;
  
  obj.style.visibility = 'visible';
  obj.style.display = 'block';
  
  opacity = (opacity == 100) ? 99.999 : opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari 1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;

}


function fadeInMP(objId,timing,opacity) {
  if(isNaN(timing)) timing = 50;
  if(isNaN(opacity)) opacity = 0;
  if (opacity <= 100) {
	setOpacityMP(objId, opacity);
	opacity += 10;
	window.setTimeout("fadeInMP('"+objId+"',"+timing+","+opacity+")", timing);
  }
}



function fadeOutMP(objId,timing,opacity) {
  if(isNaN(timing)) timing = 50;
  if(isNaN(opacity)) opacity = 100;
  if (opacity >= 0) {
	setOpacityMP(objId, opacity);
	opacity -= 10;
	window.setTimeout("fadeOutMP('"+objId+"',"+timing+","+opacity+")", timing);
  }
}


function initImage(imageId) {
  setOpacity(imageId, 0);
  contents = document.getElementById(imageId);
  contents.style.visibility = 'visible';
  fadeIn(imageId, 0, 50);
}


function addEvt(elm, evType, fn, useCapture)
// addEvt and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
} 


