function findPos(obj) 
{
	var curleft = curtop = 0;
	
	if (obj.offsetParent) 
	{
		do 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	
	return [curleft,curtop];
}

xMousePos = 0;
yMousePos = 0;

xMousePosMax = 0;
yMousePosMax = 0;

/* ####################################################################################### */
function captureMousePosition(e) 
{
    if (document.layers)
    {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
    else if (document.all)
    {
    	if (document.body) 
    	{
    		if ((navigator.appVersion.indexOf('Mac',0))>0) 
    		{
    			xMousePos = event.x+document.body.scrollLeft; 
     			yMousePos = event.y+document.body.scrollTop; 
     			//xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
     			xMousePosMax = document.body.clientWidth;
	        	yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    		} 
    		else if ((document.body.scrollLeft == 0) && (document.body.scrollTop == 0)) 
    		{
					xMousePos = window.event.x+document.documentElement.scrollLeft;
		        yMousePos = window.event.y+document.documentElement.scrollTop;
		        xMousePosMax = document.body.clientWidth+document.documentElement.scrollLeft;
	        	yMousePosMax = document.body.clientHeight+document.documentElement.scrollTop;
	      } 
	      else 
	      {
		       	xMousePos = window.event.x+document.body.scrollLeft;
		        yMousePos = window.event.y+document.body.scrollTop;
	    		xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
	        	yMousePosMax = document.body.clientHeight+document.body.scrollTop;
				}
			}
    	} 
    	else if (document.getElementById) 
    	{
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

if (document.layers) // Netscape s
{
    document.captureEvents(event.MOUSEMOVE);
}
else if (document.all) // Internet Explorer 
{
    document.onmousemove = captureMousePosition;
}
else if (document.getElementById) // Netcsape 6 
{ 
    document.onmousemove = captureMousePosition;
    if (navigator.userAgent.indexOf('Safari',0)>0) document.onclick=captureMousePosition;
}


/* ################################################################################################
 * Affiche un message d'attente pendant qu'une recherche est effectuée de maniere asynchrone 
 * ################################################################################################ */
function ShowWaitingMessage(message)
{
	// récupération du body
	var elmt_Body = document.getElementsByTagName("body").item(0); // récupération
	
	// création du div qui va "cacher" un peu tout
	var elmt_divObscure = document.createElement("div");
	elmt_divObscure.setAttribute("id", "overlay_white");// on lui ajoute une belle Id ;)
	
	var elmt_divContent = document.createElement("div"); // création
	elmt_divContent.setAttribute("id", "waitingMessage");// on lui ajoute une belle Id ;)
	
	elmt_divContent.innerHTML = message ; // <img src='/i/loading.gif'>	

	elmt_Body.appendChild(elmt_divObscure)
	elmt_divObscure.appendChild(elmt_divContent)
	
	setOpacity(elmt_divObscure, 60);
}


/* ####################################################################################### */
function hideWaitingMessage()
{
	document.getElementsByTagName('body').item(0).removeChild(document.getElementById('overlay_white'))	
}


/* ####################################################################################### */
function setOpacity(obj, opacity) {

	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;
	
	//alert(opacity);
}


/* #######################################################################################
 * Affiche le résulat d'une requete HTTPRequest dans un DIV de debug 
 * ####################################################################################### */
function ShowDebugMsg(msg)
{
	var objMain=document.getElementById("debug");
	objMain.innerHTML = msg;
}


/* ####################################################################################### */
function setCookie(nom,valeur)
{   
	var expiration = new Date();
	expiration.setTime(expiration.getTime() + (1000 * 60 * 60 * 24 * 30)); 

	document.cookie = nom + "=" + valeur + ";expires=" + expiration.toGMTString() + ";domain=lanotebleue.nouvellevague.fr;path=/" ;
}


/* ####################################################################################### */
function nv_getPageScroll() 
{
/*	yScroll = 0;
	maxScroll = 0;
	heightVisible = 0;
	
	if (window.scrollMaxY)
	{maxScroll = window.scrollMaxY;}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{maxScroll = document.body.scrollHeight - document.body.clientHeight;}
	else
	{maxScroll = document.documentElement.clientHeight;}
		
	if (self.innerHeight) {
		yScroll = self.pageYOffset;
		heightVisible = self.innerHeight;
	} else if (document.documentElement && (document.documentElement.scrollTop !== undefined))
	{	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		heightVisible = document.documentElement.clientHeight;
		
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		heightVisible = document.body.clientHeight;
	}*/
	nv_dimensionAndScroll = new structure_dimensionAndScrol();
	
	var max_height = nv_dimensionAndScroll.max_height;

	if (max_height < nv_dimensionAndScroll.height)
	{
		max_height = nv_dimensionAndScroll.height;
	}
	
	var arrayPageScroll = new Array(nv_dimensionAndScroll.height,nv_dimensionAndScroll.scroll_y, max_height) 
	

	return arrayPageScroll;
}

function structure_dimensionAndScrol()
{
	this.height = 0;
	this.width = 0;
	this.max_height = 0;
	this.max_width = 0;
	this.scroll_x = 0
	this.scroll_y = 0;	
	
	
	this.initHeightAndWidth = function()
	{
		if(window.innerHeight) 
		{
			this.height = window.innerHeight;
			this.width = window.innerWidth - 5;
		} 
		else 
		{
			if(document.documentElement && document.documentElement.clientHeight) 
			{
				this.height = document.documentElement.clientHeight;
				this.width = document.documentElement.clientWidth;
	        }
		    else if(document.body) 
		    {
                this.height = document.body.clientHeight;
                this.width = document.body.clientWidth;
            }
        }
        
        
    }
	
	this.initMaxHeight_andMaxWidth  = function()
	{
		var xScroll, yScroll;
 
		if (window.innerHeight && window.scrollMaxY)
		{   
			this.max_width = this.width + window.scrollMaxX;
            this.max_height = this.height + window.scrollMaxY;
        
        }
         else if (document.body.offsetHeight)
        {
			if (document.body.scrollHeight > document.body.offsetHeight)
			{
				this.max_width = document.body.scrollWidth;
				this.max_height = document.body.scrollHeight; 
			}
			else
			{
				this.max_width = document.body.offsetWidth;
				this.max_height = document.body.offsetHeight;
			}
        }
        else
        {
			this.max_width = this.width;
			this.max_height = this.height;
        }
        
        if (this.max_height < this.height)
        {this.max_height = this.height;}
        
        if (this.max_width < this.width)
        {this.max_width = this.width;}
     
        
	}
	
	this.initPositionScrol = function()
	{
        if(typeof(window.pageYOffset ) == 'number' )
        {
			this.scroll_y = window.pageYOffset;
			this.scroll_x = window.pageXOffset;
        }
        else if(document.body && (document.body.scrollLeft || document.body.scrollTop ))
        {
			this.scroll_y = document.body.scrollTop;
			this.scroll_x = document.body.scrollLeft;
        }
        else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop ))
        {
			this.scroll_y = document.documentElement.scrollTop;
			this.scroll_x = document.documentElement.scrollLeft;
        }
        
	}
	
	this.initHeightAndWidth();
	this.initMaxHeight_andMaxWidth();
	this.initPositionScrol()
	
	
}






/* ####################################################################################### */
function initSelectSousType(target, idType)
{
	var objTarget = document.getElementById(target);
	var xhrTo = objTarget.getAttribute("src") ;
	var lastId_name = "lastId";
	var forId = "id";

	// on check si une id n'a pas été spécifié
	if (objTarget.getAttribute(CONST_forId))
	{forId = objTarget.getAttribute(CONST_forId);}
	
	// on construi l'url
	xhrTo = xhrTo + '&' + forId + '=' + idType;
	if (objTarget.getAttribute(CONST_lastId_name))
	{lastId_name = objTarget.getAttribute(CONST_lastId_name);}
	
	if (objTarget.getAttribute(CONST_lastId))
	{xhrTo = xhrTo + "&" + lastId_name + "=" + objTarget.getAttribute(CONST_lastId);}
	

	objTarget.disabled= false;
	myXHR = new httpRequest(xhrTo, "", "POST");
	myXHR.LoadContent(target,'','');
	
		
}



/* #######################################################################################
 * Fonction qui récupère les paramètres GET de l'url courante et les retourne dans un 
 * tableau à 2 dimensions : 
 * 
 * Ex : url = http://www.truc.com/index.aspx ? param1=x & param2=y 
 * 
 *		- tab[0][0] = "param1"  ,  tab[0][1] = "x" 
 *		- tab[1][0] = "param2"  ,  tab[1][1] = "y" 
 *  
 * S'il n'y a pas de paramètres GET dans l'url la fonction renvoie la valeur 'null'.
 *
 * ####################################################################################### */
function getParams() 
{
	var params = location.search.substring(1, location.search.length);
	params = params.split("#");
	params = params[0];
	
	if ( params != "" ) 
	{
		var tab = new Array();
		params = params.split("&");
		
		for (i=0; i < params.length; i++) 
		{
			var variable = params[i].substring(0, params[i].indexOf("="));
			var valeur = params[i].substring((params[i].indexOf("=") + 1), params[i].length);
			
			tab[i] = new Array(variable, valeur);
		}
		
		return tab;
	}
	else 
	{
		return null;
	}
	
}


/* #######################################################################################
 * Fonction qui limite le nombres de caractères saisis dans un champ text ou textarea 
 * identifié par son id. 
 * Lorsqu'on atteint le maximum, la fonction efface les caractères en trop. 
 * 
 * @params	txt_id  : l'id du champ à contrôler 
 *			max		: le nombre maximum de caractères autorisé 
 * ####################################################################################### */
function countCar(txt_id, max) 
{
	var txt = document.getElementById(txt_id);
	
	if (txt.value.length > max) 
	{
		txt.value = txt.value.substr(0, max); // substr(0, max) <=> substring(0, max-1)
	}
}


/* #####################################################################################################
 * Fonction qui renvoie True ssi la chaine passée en paramètre a bien le format d'un e-mail valide 
 * ##################################################################################################### */
function check_email(chaine) 
{
	// chaine.toLowerCase();
	//var regexp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9]+)+$/;
	
	var regexp = /^[_a-z0-9-]+([_a-z0-9-\.]+)*@[a-z0-9-]+([_a-z0-9-\.]+)*\.[a-z0-9]{2,}$/;
	
	return (regexp.test(chaine));
}



function txtOnFocus(thisTxtBox, txtDefault)
{
	if (thisTxtBox.value == txtDefault)
	{
		thisTxtBox.value = '';
	}
}

function txtOnBlur(thisTxtBox, txtDefault)
{
	if (thisTxtBox.value == '')
	{
		thisTxtBox.value = txtDefault;
	}
}






//var timer_sessionTimeOut = 1200000; // 20  minutes
//var timer_pageToDisconnect = "/index.aspx"
//var timer_timeOut = setTimeout("document.location.href = timer_pageToDisconnect;", timer_sessionTimeOut);

//function verif_inactivite()
//{
//	clearTimeout(timer_timeOut)
//	timer_timeOut = setTimeout("document.location.href = timer_pageToDisconnect;", timer_sessionTimeOut)
//}


//if (typeof window.addEventListener == "function")
//{
//	window.addEventListener("mousemove", verif_inactivite, false);
//	window.addEventListener("keypress", verif_inactivite, false);
//}
//else
//{ 
//	window.attachEvent("onmousemove", verif_inactivite, false);
//	window.attachEvent("onkeypress", verif_inactivite, false);
//}


