/*window.onerror = mon_erreur;*/

function mon_erreur(nouvelle,fichier,ligne)
{
 erreur = "Message d'erreur:\n"+ nouvelle+"\n"+fichier+"\n"+ligne;
 affiche_erreur();
 return true;
}

function affiche_erreur()
{
 alert(window.erreur)
}

function PopupCentrer(page,largeur,hauteur,options) 
{
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  var w = window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function showhide(divname) {
 var style = document.getElementById(divname).style;
 if ((style.display=='none')||(style.display=='')) {
  style.display='block';
  }
 else {
  style.display='none';
  }
}

function storeCaret( textEl ) 
{
	if( textEl.createTextRange ) 
 		textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret( textEl, text ) 
{
	if( textEl.createTextRange && textEl.caretPos ) 
	{
 		var caretPos = textEl.caretPos;
 		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	}
	else
 		textEl.value  = text;
}

function fo(n,b,c)
{
	if( document.all )
	{
		document.all[n].style.color = c ;
		document.all[n].style.background = b;
	}	
	else
	{
		if( document.getElementById )
		{
			document.getElementById(n).style.color = c;
			document.getElementById(n).style.background = b;
		}
	}
}

/*
	tableruler()
	written by Chris Heilmann for alistapart.
	enables a rollover of rows for each table with the classname "hlrows"
*/

function tableruler()
{
	if (document.getElementById && document.createTextNode)
	{
		var tables=document.getElementsByTagName('table');
		for (var i=0;i<tables.length;i++)
		{
			if(tables[i].className=='ruler')
			{
				var trs=tables[i].getElementsByTagName('tr');
				for(var j=0;j<trs.length;j++)
				{
					if(trs[j].parentNode.nodeName=='TBODY')
					{
						trs[j].onmouseover=function(){this.className='ruled';return false}
						trs[j].onmouseout=function(){this.className='';return false}
					}
				}
			}
		}
	}
}


/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function handleEnter (field, event) 
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) 
	{
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
		return true;
}      

function setCook(nom,valeur) 
{
	document.cookie = nom + "=" + escape(valeur)
}

function setCookwithTime(nom,valeur,jours) 
{
	var expDate = new Date();
    expDate.setTime(expDate.getTime() + (jours * 24 * 3600 * 1000));
    document.cookie = nom + "=" + escape(valeur) + ";expires=" + expDate.toGMTString();
}

function delCook(nom) { setCookwithTime(nom,"",-1) }

function getCook(nom) 
{
	deb = document.cookie.indexOf(nom + "=")
	if (deb >= 0) 
	{
		deb += nom.length + 1
        fin = document.cookie.indexOf(";",deb)
        if (fin < 0) 
        	fin = document.cookie.length
        return unescape(document.cookie.substring(deb,fin))
     }
     return ""
}

function test_date(d) 
{
	if ( d == "" )	// Minimum x/x/xx 
		return false;
	
	e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
	
	if (!e.test(d))
		return false;
	
	j = parseInt(d.split("/")[0], 10); // jour
	m = parseInt(d.split("/")[1], 10); // mois
	a = parseInt(d.split("/")[2], 10); // année
	
	// Si l'année n'est composée que de 2 chiffres on complète automatiquement
	if (a < 1000) 
	{
		if (a < 89)  a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
		else a+=1900;
	}
	
	// 28 pour février si Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
	if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29; else fev = 28;
	
	nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
	
	return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
}


/***********************************************
* Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
* <input name="myemail" type="text" style="width: 270px"> <input type="submit" onClick="return checkmail(this.form.myemail)" 
***********************************************/
function checkmail(e)
{
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
	var returnval=emailfilter.test(e.value)
	if (returnval==false)
	{
		alert("Please enter a valid email address.")
		E.select()
	}
	return returnval
}


/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="images/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if(ie) return false;
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip


