
/* ####################################################################################### */
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;
}


 

/* ####################################################################################### */
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 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 analogue à ucfirst en Php : Met en majuscule le 1er caractère d'une chaine 
 * ####################################################################################### */
function ucFirst(str) 
{
    if (str.length > 0) {
        return str[0].toUpperCase() + str.substring(1);
    } else {
        return str;
    }
}


/* #######################################################################################
 * 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-zA-Z0-9-]+([_a-zA-Z0-9-\.]+)*@[a-zA-Z0-9-]+([_a-zA-Z0-9-\.]+)*\.[a-zA-Z0-9]{2,}$/;
	
	return (regexp.test(chaine));
}


//#####################################################################################################
// Fonction qui ouvre une fenetre popUp centrée sur l'écran 
// params : 
//			url		, type String	, url de la page affichée dans la fenetre pop up 
//			nom		, type String	, nom de la fenetre 
//			largeur	, type Integer	, largeur de la fenetre pop up 
//			hauteur	, type Integer	, hauteur de la fenetre pop up 
//			options	, type String	, options de la méthode window.open() MAIS SANS les attributs width et height ! 
// 
//#####################################################################################################
function centerPopup(url, nom, largeur, hauteur, options) 
{
	//alert(url);
	
	var x = (screen.width/2) - (largeur/2);
	var y = (screen.height/2) - (hauteur/2);
	
	if (options != '') {
		options += ',';
	}
	
	options += 'width=' + largeur + ',height=' + hauteur + ',top=' + y + ',left=' + x;
	//alert(options);
	//alert('centerPopup OK, now window.open...');
	window.open(url, nom, options);
	//alert('...window.open OK !');
}


//#####################################################################################################
// Fonction qui ouvre une msgBox de type confirm (bouton Ok et cancel)
// params : 
//	msg			, type String	, Message qui s'affichera dans la msgBox
//	urlValidate	, type String	, Si l'utilisateur click sur oui, on redirige l'utilisateur vers cette url
//#####################################################################################################
function msgConfirme(msg, urlValidate)
{
	if (confirm(msg))
	{
		document.location.href = urlValidate;
		return true;
	}
	else {
		return false;
	}
}

/* ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ */
/* Charge le contenu d'un onglet multimédia */
/* ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ */

function load_multimedia_content(type_multimedia)
{
	myXHR_multimedia = new httpRequest('http://mollatcms.nouvellevague.fr/App_ajax/frontoffice/AJAX_FO_MULTIMEDIA.aspx?type_multimedia=' + type_multimedia, "", "POST");
	myXHR_multimedia.LoadContent('target_foliotage','Chargement de la page','load_multimedia_coldroite("' + type_multimedia + '");');
}

function load_multimedia_coldroite(type_multimedia)
{
	myXHR_coldroite = new httpRequest('http://mollatcms.nouvellevague.fr/App_ajax/frontoffice/AJAX_FO_MULTIMEDIA.aspx?colonne_droite=1&type_multimedia=' + type_multimedia, "", "POST");
	myXHR_coldroite.LoadContent('target_ajax_multimedia_droite','Chargement de la page','');
}


/* #######################################################################################
 * Tristan - 05/10/2010 => Mantis 1521 : Amélioration ds formulaires 
 * 
 * Fonction qui efface le caractère saisi s'il est égal à <car> 
 * dans un champ text ou textarea identifié par son id. 
 * (Fonction applicable sur le onkeyup) 
 * 
 * @params	txt_id  : l'id du champ à contrôler 
 *			car		: le caractère interdit choisi, par défaut c'est l'espace 
 * ####################################################################################### */
function suppr_car(txt_id, car) 
{
	var txt = document.getElementById(txt_id);
	
	if (!car) {
	    car = ' ';
	}
	
	if ( txt.value.substr((txt.value.length - 1), 1) == car ) 
	{
		txt.value = txt.value.substr(0, (txt.value.length - 1));
	}
}

/* #######################################################################################
 * Tristan - 05/10/2010 => Mantis 1521 : Amélioration ds formulaires 
 * 
 * Fonction qui efface le caractère saisi si ce n'est pas un nombre
 * dans un champ text ou textarea identifié par son id. 
 * (Fonction applicable sur le onkeyup) 
 * 
 * @params	txt_id  : l'id du champ à contrôler 
 * ####################################################################################### */
function suppr_nan(txt_id) 
{
	var txt = document.getElementById(txt_id);
	
	if ( isNaN(txt.value.substr((txt.value.length - 1), 1)) || txt.value.substr((txt.value.length - 1), 1) == ' ' ) 
	{
		txt.value = txt.value.substr(0, (txt.value.length - 1));
	}
}
