/**********************************************************
 TRUCKSTOPCO.com - FONCTIONS DIV_POPUP
 Créé le 5 juillet 2005 par Jean-Bernard Filion
 Dernière modification : 5 juillet 2005
**********************************************************/

/*-------------------------------------------------------*/
// PARAMÈTRES USAGERS /////////////////////////////////////
/*-------------------------------------------------------*/
// - Définition du ID de la div_popup
// - Définition des styles CSS de la div_popup
/*-------------------------------------------------------*/
div_id = 			"div_pop_up0000";

div_style = 		"";
div_style += 		"width:					250px;";
div_style += 		"height:				;";
div_style += 		"padding:				8px;";
div_style += 		"color:					#655d47;";
div_style += 		"background-color:		#ffefbf;";
div_style += 		"font-size:				11px;";
div_style += 		"font-family:			Arial, Helvetica, sans-serif;";
div_style += 		"text-align:			left;";
div_style += 		"border:				1px solid #c3b792;";

/*-------------------------------------------------------*/
// INIT SYSTEM /////////////////////////////////////
/*-------------------------------------------------------*/
xmouse = 0;
ymouse = 0;
over_right = false;
over_bottom = false;
is_active = false;
	
init_div_popup();

//Init des paramètres de mouseTracking
IE = document.all ? true : false
if(!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
/*-------------------------------------------------------*/
// FONCTIONS APPELÉS PAR LA PAGE //////////////////////////
/*-------------------------------------------------------*/
// - afficher_div_popup(str_message)
// - masquer_div_popup()
/*-------------------------------------------------------*/
function afficher_div_popup(str_message){
	deplacer_div_popup();
	valider_position();
	$(div_id).innerHTML = str_message;
	$(div_id).style.display = 'block';
	is_active = true;
}
//--------------------------------------------------------
function masquer_div_popup(){
	$(div_id).style.display = 'none';
	$(div_id).innerHTML = '';
	is_active = false;
}

/*-------------------------------------------------------*/
// FONCTIONS SYSTÈMES //////////////////////////
/*-------------------------------------------------------*/
// - deplacer_div_popup()
// - getMouseXY(e)
/*-------------------------------------------------------*/
//---------------------------------------------------------------------
function init_div_popup(){
	//Écriture de la DIV
	document.write('<div id="'+div_id+'" style="display:none; position:absolute; top:; left:; right:; bottom:; z-index:99; '+div_style+'">');
	document.write('</div>');
}
//---------------------------------------------------------------------
function valider_position(){
	// Cacul de l'espace
	div_width =		Number($(div_id).style.width.replace(/px/,''));
	div_height = 	Number($(div_id).style.height.replace(/px/,''));
	
	var div_right = 	xmouse + 10 + div_width;
	var div_bottom = 	ymouse + 5 + div_height;
	
	if (document.all){
		margin_right = 		document.body.clientWidth - div_right;
		margin_bottom = 	document.body.clientHeight - div_bottom;
	}else{
		margin_right = 		window.innerWidth - div_right;
		margin_bottom = 	window.innerHeight - div_bottom;
	}
	
	over_right = (margin_right < 75) ? true : false;
	over_bottom = (margin_bottom < 75) ? true : false;
	
}
//---------------------------------------------------------------------
function deplacer_div_popup(){
	ypos = 		(ymouse + 5) + 'px';
	xpos = 		(xmouse + 10) + 'px';
	//Si l'espace est négatif, il faut overrider
	if (over_right && over_bottom){
		ypos = 		(ymouse - 10 - div_height) + 'px';
		xpos = 		(xmouse - 10 - div_width) + 'px';
	}else if(over_right){
		xpos = 		(xmouse - 10 - div_width) + 'px';
	}else if(over_bottom){
		ypos = 		(ymouse - 15 - div_height) + 'px';
	}
	
	$(div_id).style.top = ypos;
	$(div_id).style.left = xpos;
}
//---------------------------------------------------------------------
//---------------------------------------------------------------------
function getMouseXY(e){
	if(IE){ 
		tempX = event.clientX + document.documentElement.scrollLeft;
		tempY = event.clientY + document.documentElement.scrollTop;
	
	}else{ 
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	
	// catch possible negative values in NS4
	if(tempX < 0)	tempX = 0;
	if(tempY < 0)	tempY = 0;
  
	xmouse = tempX;
	ymouse = tempY;

	if(is_active) deplacer_div_popup();
	return true;
}