function getCursorPosition (e) {
	if (!e)
		var e = window.event;
		
	var cursor = {x:0, y:0};
	
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		cursor.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		cursor.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	return cursor;
}
	
function CustomForms (list, fctOver) {
	this.list = list;
	
	for (var i in list) {
		document.getElementById (i).onmouseover = function onmouseover (event) { if (fctOver) fctOver (this); };
		document.getElementById (i).onmouseout  = document.getElementById (i).onmouseover;
		
		if (list[i] != '') {
			
			document.getElementById (i).value = list[i];
			document.getElementById (i).value0 = document.getElementById (i).value;
			
			document.getElementById (i).onfocus = function onfocus (event) { if (this.value == this.value0) this.value = ''; };
			document.getElementById (i).onblur = function onblur (event) { if (this.value == '' || this.value == this.value0) this.value = this.value0; };
		}
	}
	
	this.unset = function () {
		for (var i in this.list)
			if (document.getElementById (i).value == document.getElementById (i).value0)
				document.getElementById (i).value = '';
	}
	
	this.set = function () {
		for (var i in this.list)
			if (document.getElementById (i).value == '')
				document.getElementById (i).value = document.getElementById (i).value0;
	}
	
	this.setClassToElem = function (id_elem, className) {
		document.getElementById (id_elem).className = className;
	}
}



function IsNumber (value) {
	intValue = parseInt (value);
	return value.length != 0 && intValue == value && (''+intValue).length == value.length;
}

function DateValide (date, separator) {
	dmY = date.split (separator);

	if (dmY[0].length != 2    || dmY[1].length != 2    || dmY[2].length != 4 ||
		dmY[0].length == '00' || dmY[1].length == '00' || dmY[2].length == '0000' || dmY[1] > '12')
		return false;
			
	var tab_jours_mois = new Array (31, (bissextile (dmY[2]) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (dmY[0] > tab_jours_mois[dmY[1]-1])
		return false;
		
	return true;
}

function bissextile (year) {
	return year%4==0 && (year%100!=0 || year%400==0);
}

function getScreenSize() {
	var myWidth = 0, myHeight = 0;
	
	//Non-IE
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	
	//IE 6+ in 'standards compliant mode'
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	
	//IE 4 compatible
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	return Array(myWidth, myHeight);
}

// Browsercheck
function lib_bwcheck () {
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bsw = lib_bwcheck ();

// reloads the window if Nav4 resized
function MM_reloadPage (init) {  
  if (init==true) with (navigator) {
	  if ((appName=="Netscape")&&(parseInt(appVersion)>=4)) {
	    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
	 }
	}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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) { //v3.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); 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 MM_openBrWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function openWindowSimple (theURL, winName, width, height) { 
	if (!width)  width = 500;
	if (!height) height = 500;
		
  window.open(theURL,winName,'menubar=no,location=no,resizable=no,status=no, scrollbars=yes,menubar=no,width='+width+',height='+height);
}

function Impression(){
  window.print();
}
 
function rec(list) {
	self.location.href = list.options[list.selectedIndex].value
}
function redirect(dest) {
	self.location.href = dest
}

// Anti-spam
function emailProtect(adresse, dns, txt, classe, style){
	var name = adresse ;
	var domain = dns ;

	document.write('<a href=\"mailto:' + name + '@' + domain + '\"') ;
	if(classe != ""){
		document.write(' class=\"' + classe + '\"') ;
	}
	if(style != ""){
		document.write(' style=\"' + style + '\"') ;
	}
	document.write('>') ;
	if(txt != ""){
		document.write(txt + '</a>') ;
	}
	else{
		document.write(name + '@' + domain + '</a>') ;
	}
}

//Controle d'adresse email
function EmailOK(UnEmail)
{
  var re = /([a-z0-9]+([-_]?[a-z0-9]+)*.)*[a-z0-9]+([-_]?[a-z0-9]+)*@([a-z0-9]+([-_]?[a-z0-9]+)*.)+[a-z]{2,4}/gi;  
  return (UnEmail.value.match(re) == UnEmail.value);  
}

// FAVORIS
// exemple : AjouterFavoris('fr', 'http://www.brumont.fr', 'Brumont')
function AjouterFavoris(language, bookmarkurl, Brumont)
{
	if (document.all)
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
	else if (language=="fr")
		alert ('Cette action ne peut pas être automatisée sur votre navigateur,\nveuillez la réaliser manuellement.');
	else
		alert ('Your browser does not support this function,\nplease make it manually.');
}

// Gestion des calques
function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion 
    this.dom=document.getElementById?1:0 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
    return this 
} 
bw = new verifyCompatibleBrowser();

function showHide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	if(obj.visibility=='visible' || obj.visibility=='show'){
		obj.visibility='hidden';
		obj.display='none';
	}
	else{
		obj.visibility='visible';
		obj.display='block';
	}
}
//Shows the div
function show(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='visible';
	obj.display='block';
}
//Hides the div
function hide(div,nest){
	obj=bw.dom?document.getElementById(div).style:bw.ie4?document.all[div].style:bw.ns4?nest?document[nest].document[div]:document[div]:0; 
	obj.visibility='hidden';
	obj.display='none';
}