/*============================================================================================
 Fichier Javascript
 Fichier contenant divers Boite de dialogue

 AUTEUR:					Alban BALLIEUX
 CREATION:					07/07/2008
 VARIABLE GLOBALES:			Target
							Opacity
							oldscroll
 MODIFICATIONS:	
 	Alban BALLIEUX		- 16/07/2008 - Amelioration de messageErreur
	Cédric POUYEZ		- 27/11/2008 - Ajout de AfficheModalMessage et CloseModalMessage et OnScrollMessage
	Joanny HARRANT		- 25/03/2009 - Utilisation de la méthode ChangeOpac() pour la DIV Transparente dans la méthode AfficheModalMessage()
	Alban BALLIEUX		- 03/04/2009 - Modification du boxover pour qu'il prenne en compte la largeur et la hauteur

===============================================================================================
	copyright 2009 Alban BALLIEUX - ballieuxa@laon.noirot
	http://www.phpmyportal.info

	This file is part of phpMyPortal.

    phpMyPortal is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 2.1 of the License, or
    any later version.

    phpMyPortal is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with phpMyPortal; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===============================================================================================*/
var Target;
var Opacity;
var TMacrosContext;
var CurContext;
/*******************************************************************
 * 							BOXOVER
 *******************************************************************/
/**
 * Affiche une DIV contenant des informations
 * Utilisation: Il faut ajouter trois attributs à l'élément, name qui contiendra BOXOVER pour informer qu'il faut afficher un boxover,
 * entete qui contiendra le titre de la DIV et corp qui contiendra le contenu de la DIV.
 * 
 * La fonction BoxOver est appellée par la fonction InitBoxOver (system.js)
 * 
 * @param {Object} e	evenement
 */
function BoxOver(e){
	if (!e) var e = window.event;
	if (isset(e.target)){
		Target = e.target;
	}else{
		Target = e.srcElement;
	}
	
// Le target est vide ...
	if (!isset(Target)) return false;
	
	DecalX=10;
	DecalY=20;
	cpt=0;
	LT=0;
	
	PtBO = GetPtId('DBOXOVER');
	
	while(Target.tagName!='HTML' && !(isset(Target.getAttribute('boxover')) || isset(Target.getAttribute('entete')) ) ){Target=Target.parentNode;}
	
	while (cpt<Target.childNodes.length){
		LT = Target.childNodes[cpt++].scrollWidth;
	}
	
	if (( isset(Target.getAttribute('boxover')) || isset(Target.getAttribute('entete')) ) && (Target.clientWidth<LT || !isset(LT))){
		PtBO.style.zIndex=6000;
		PtBO.style.position="absolute";
		var entete=Target.getAttribute('entete');
		var corp=Target.getAttribute('boxover');

		var HTML='';
		if (isset(entete) && entete!=''){HTML+='<div id="TBox">'+entete+'</div>';}
		if (isset(corp) && corp!='' && corp!='#VAL#'){HTML+='<div id="TBox1">'+corp+'</div>';}
		if (isset(corp) && corp=='#VAL#'){
			if (isset(Target.textContent)){
				HTML+='<div id="TBox1">'+Target.textContent+'</div>';
			}else{
				HTML+='<div id="TBox1">'+Supprime_Tag(Target.innerHTML)+'</div>';
			}
		}
		PtBO.innerHTML=HTML;
		
		PosX=e.clientX+DecalX;
		PosY=e.clientY+DecalY;

		deltaX=window.innerWidth-PosX-PtBO.clientWidth;
		deltaY=window.innerHeight-PosY-PtBO.clientHeight;
		if (deltaX<0)PosX=PosX-PtBO.clientWidth - (DecalX*2);
		if (deltaY<0)PosY=PosY-PtBO.clientHeight - (DecalY*2);
		if (typeof BoxOver != 'function' ){
			return false;
		}
		TScroll=getScrollXY();
		PtBO.style.left=PosX+TScroll[0]+'px';
		PtBO.style.top=PosY+TScroll[1]+'px';
		//PtBO.style.width='100%';
		ChangeOpac(PtBO.id,90);
		Opacity = true;
		TimerBOXOVER = 2;
		PtBO.style.display='block';

		if (isNumber(Target.getAttribute('DltX'))){
			PtBO.style.Width=Target.getAttribute('DltX');
		}
		if (isNumber(Target.getAttribute('DltY'))){
			PtBO.style.Width=Target.getAttribute('DltY');
		}
		if (Target.getAttribute('SANSNOWRAP')=='1'){
			PtBO.style.whiteSpace='nowrap';
		}
	}else{
		if (Opacity == true){
			Opacity = false;
			disparition(PtBO.id,90,'GetPtId(Id).style.zIndex=-1');
		}
	}
}

/**
 * Fonction de changement du corp de boxover
 * 
 * @param {Object} Id		Identifiant du boxover
 * @param {Object} Corp		Corp du boxover
 * @param {Object} Entete	Entete du boxover
 */
function ChangeBoxOver(Id,Corp,Entete){
	if (!isset(Id)) 	return false;
	ID=GetPtId(Id);
	if (ID == false)	return false;
	if (isset(Corp)) 	ID.setAttribute('boxover', Corp);
	if (isset(Entete)) 	ID.setAttribute('entete', Entete);
}
//---------------------------------------------------------------------------------------
// Fonctions Propres Au messages Modaux
//---------------------------------------------------------------------------------------
var oldscroll;
/**
 * Affiche un boite d'information
 * 
 * @param {Object} Corp					Corp de la boite
 * @param {Object} Largeur				Largeur de la boite
 * @param {Object} Hauteur				Hauteur de la boite
 * @param {Object} Transparence
 * @param {Object} Ombre				
 * @param {Object} SansBoite			Ne pas mettre de boite en fond
 */
function AfficheModalMessage(Corp,Largeur,Hauteur,Transparence,Ombre){
	
	largeurpage=parseInt(Size()[0]);
	hauteurpage=parseInt(Size()[1]);
	
	if(!isset(Largeur)){
		Largeur=1;
	}
	if(!isset(Hauteur)){
		Hauteur=1;
	}
	if(!isset(Corp)){
		Corp='';
	}
	if(!isset(Transparence)){
		Transparence='true';
	}
	if(!isset(Ombre)){
		Ombre='false';
	}

	if(!GetPtId('GrisageModal')){
		DivGrisage = document.createElement('DIV');
		DivGrisage.id='GrisageModal' ;
		AjouteGrisage=true;
	}else{
		DivGrisage=GetPtId('GrisageModal');
		AjouteGrisage=false;
	}
	DivGrisage.style.left='0px';
	DivGrisage.style.top='0px';
	DivGrisage.style.width=document.body.offsetWidth+'px';
	DivGrisage.style.height=(document.body.offsetHeight+2000)+'px';
	DivGrisage.style.background='rgb(88,88,88)';
	DivGrisage.style.position='absolute';
	DivGrisage.style.zIndex=90000;
	
	if(!GetPtId('ContenuModal')){
		DivContenu = document.createElement('DIV');
		DivContenu.id='ContenuModal' ;
		AjouteContenu=true;
	}else{
		DivContenu=GetPtId('ContenuModal');
		AjouteContenu=false;
	}
	PosX = Math.round(largeurpage/2 - Largeur/2) ;
	PosY = Math.round(hauteurpage/2 - Hauteur/2) + document.documentElement.scrollTop;
	DivContenu.style.left=PosX+'px' ;
	DivContenu.style.top=PosY+'px' ;
	DivContenu.style.width=Largeur+'px' ;
	DivContenu.style.height=Hauteur+'px' ;
	DivContenu.style.position='absolute';
	DivContenu.style.zIndex=100000;
	
	if (Transparence!='true') {
		DivContenu.className='modalpmp';
	} else {
		DivContenu.className='modalpmp_transparent';
	}
	
	DivContenu.innerHTML=Corp;
	
	if (Ombre=='true'){
		if(!GetPtId('OmbreModal')){
			DivOmbre = document.createElement('DIV');
			DivOmbre.id='OmbreModal' ;
			AjouteOmbre=true;
		}else{
			DivOmbre=GetPtId('OmbreModal');
			AjouteOmbre=false;
		}
		DivOmbre.style.left=(PosX+5)+'px' ;
		DivOmbre.style.top=(PosY+5)+'px' ;
		DivOmbre.style.width=Largeur+'px' ;
		DivOmbre.style.height=Hauteur+'px' ;
		DivOmbre.style.background='rgb(110,110,110)' ;
		DivOmbre.style.position='absolute';
		DivOmbre.style.zIndex=95000;
		
		if(AjouteOmbre==true){
			document.body.appendChild(DivOmbre);
		}else{
			DivOmbre.style.display='block';
		}
	}
	
	if(AjouteGrisage==true){
		document.body.appendChild(DivGrisage);
	}else{
		DivGrisage.style.display='block';
	}
	ChangeOpac('GrisageModal',40);
	if(AjouteContenu==true){
		document.body.appendChild(DivContenu);
	}else{
		DivContenu.style.display='block';
	}
	oldscroll=window.onscroll;
	AjouteEvent('onscroll',OnScrollMessage,window);
//	window.onscroll=OnScrollMessage;
}

/**
 * 
 */
function CloseModalMessage(){
	GetPtId('GrisageModal').style.display='none';
	GetPtId('ContenuModal').style.display='none';
	if(IdExiste('OmbreModal')){
		GetPtId('OmbreModal').style.display='none';
	}
	window.onscroll=oldscroll;
}

/**
 * 
 */
function OnScrollMessage(){
	largeurpage=parseInt(Size()[0]);
	hauteurpage=parseInt(Size()[1]);
	if(IdExiste('OmbreModal')){
		DivOmbre=GetPtId('OmbreModal');
	}
	DivContenu=GetPtId('ContenuModal');
	
	Largeur = DivContenu.clientwidth;
	Hauteur	= DivContenu.clientHeight;
	PosX = Math.round(largeurpage/2 - Largeur/2) ;
	PosY = Math.round(hauteurpage/2 - Hauteur/2) + document.documentElement.scrollTop;
	
	DivContenu.style.top=PosY+'px' ;
	if(IdExiste('OmbreModal')){
		DivOmbre.style.top=(PosY+5)+'px' ;
	}
}