function BlockScreenObj(pTarget,pFadeInTime,pFadeOutTime,pAlternateParent){
	this.Target = (typeof pTarget == "string") ? document.getElementById(pTarget) : pTarget;
	this.FadeInTime = ( pFadeInTime != undefined ) ? pFadeInTime : 250;
	this.FadeOutTime = ( pFadeOutTime != undefined ) ? pFadeOutTime : 250;
	this.Parent = (pAlternateParent != undefined) ? pAlternateParent : this.Target.parentNode;
	this.Attached = false;

	if(this.Parent.style.position != "relative" && this.Parent.style.position != "absolute") {
		this.Parent = document.body;
	}
	
	this.BlockScreenContainer = document.createElement('DIV');
	this.BlockScreenContainer.className = 'blockScreenContainer';
	this.BlockScreenContainer.style.display = 'none';
	
	var ShadeDiv = document.createElement('DIV');
	ShadeDiv.className = 'blockScreenShade';
	
	var ImgDiv = document.createElement('DIV');
	ImgDiv.className = 'blockScreenImg';
	ImgDiv.style.display = 'none';
	
	//Attacher les Div au parent
	this.BlockScreenContainer.appendChild(ShadeDiv);
	this.BlockScreenContainer.appendChild(ImgDiv);
	
	
	
	this.show = function(){
		if( !this.Attached ){
			this.attach();
		}
		//Lancer le processus seulement si le processus n'est pas déjà en cours.
		if( this.BlockScreenContainer.style.display != 'block' ){
			this.BlockScreenContainer.style.display = 'block';
			this.fader = fadeIn(this.BlockScreenContainer.childNodes[0],this.FadeInTime,50, bindFunction(function(){this.BlockScreenContainer.childNodes[1].style.display = 'block'},this));
		}
	}
	
	this.hide = function(){
		var nOpacityStart = 50;
		if( this.fader ){
			window.clearInterval( this.fader.interval );
			nOpacityStart = this.fader.curVal;
		}
		this.BlockScreenContainer.childNodes[1].style.display = 'none';
		fadeOut(this.BlockScreenContainer.childNodes[0],this.FadeOutTime, nOpacityStart , bindFunction( function(){this.BlockScreenContainer.style.display = 'none';this.dettach();},this));
	}
	
	this.attach = function(){
		this.Parent.appendChild(this.BlockScreenContainer);
		this.BlockScreenContainer.style.top = getAbsoluteTop(0,this.Target,this.Parent) + "px";
		this.BlockScreenContainer.style.left = getAbsoluteLeft(0,this.Target,this.Parent) + "px";
		this.BlockScreenContainer.style.height = this.Target.clientHeight + "px";
		this.BlockScreenContainer.style.width = this.Target.clientWidth + "px";
		this.BlockScreenContainer.childNodes[0].style.height = this.Target.clientHeight + "px";
		this.BlockScreenContainer.childNodes[0].style.width = this.Target.clientWidth + "px";
		this.BlockScreenContainer.childNodes[1].style.height = this.Target.clientHeight + "px";
		this.BlockScreenContainer.childNodes[1].style.width = this.Target.clientWidth + "px";
		this.Attached = true;
	}
	
	this.dettach = function(){
		if( this.Attached ){
			this.Attached = false;
			this.Parent.removeChild(this.BlockScreenContainer);
		}
	}
}

/**
 * Méthode qui fait apparaitre un élément graduellement sur une durée de temps définie
 * @param pTarget : Élément à faire apparaitre. Son opacité devrait être à 0 et son display à une valeur visible
 * @param pDuration : Le temps aloué pour faire apparaitre l'élément
 * @param pFinalOpacity : Opacité à laquelle le fadeIn s'arrête, si n'est pas spécifier, la valeur 100 est prise
 * @param pOnComplete : Méthode CallBack qui sera lancé lorsque le fadeIn est complété
 * @return Retourne le pointeur de gestion de fadeIn. 
 */
function fadeIn(pTarget,pDuration,pFinalOpacity,pOnComplete){
	//s'assurer que l'on a une valeur pour pFinalOpacity
	if( pFinalOpacity == undefined || pFinalOpacity == null || pFinalOpacity <= 0 || pFinalOpacity > 100 ){
		pFinalOpacity = 100;
	}
	//s'assurer que la cible à une opacité 0
	pTarget.style.filter = 'Alpha(Opacity:0)';
	pTarget.style.mozOpacity = '0';
	pTarget.style.opacity = '0';
	//Déterminer les increments requis pour se rendre a opacité complete dans le temps requis
	var nTime = pDuration / pFinalOpacity;
	var nIncrement = 1;
	if( nTime < 10 ){
		nTime = 10;
		nIncrement = pFinalOpacity / (pDuration / 10); 
	}
	//Affecter le timer et les propriétés requisent
	f = function(){
		this.target.style.filter = 'Alpha(Opacity:' + Math.round(f.curVal) + ")";
		this.target.style.mozOpacity = Math.round(f.curVal) / 100;
		this.target.style.opacity = Math.round(f.curVal) / 100;
		this.curVal = this.curVal + this.increment;
		if( this.curVal >= this.finalOpacity ){
			window.clearInterval(this.interval);
			if( this.onComplete ){
				this.onComplete();
			}
		}
	}
	f.target = pTarget;
	f.curVal = 0;
	f.increment = nIncrement;
	f.onComplete = pOnComplete;
	f.finalOpacity = pFinalOpacity;
	var n = window.setInterval( bindFunction(f,f),nTime);
	f.interval = n;
	
	return f;
}

/**
 * 
 * @param pTarget
 * @param pDuration
 * @param pOnComplete
 * @return
 */
function fadeOut(pTarget,pDuration,pStartOpacity,pOnComplete){
	//s'assurer que l'on a une valeur pour pFinalOpacity
	if( pStartOpacity == undefined || pStartOpacity == null || pStartOpacity <= 0 || pStartOpacity > 100 ){
		pStartOpacity = 100;
	}

	//s'assurer que la cible à une la bonne opacité
	pTarget.style.filter = 'Alpha(Opacity:' + pStartOpacity + ')';
	pTarget.style.mozOpacity = pStartOpacity / 100;
	pTarget.style.opacity = pStartOpacity / 100;
	//Déterminer les increments requis pour se rendre a opacité complete dans le temps requis
	var nTime = pDuration / pStartOpacity;
	var nIncrement = 1;
	if( nTime < 10 ){
		nTime = 10;
		nIncrement = pStartOpacity / (pDuration / 10); 
	}
	//Affecter le timer et les propriétés requisent
	f = function(){
		this.target.style.filter = 'Alpha(Opacity:' + Math.round(f.curVal) + ")";
		this.target.style.mozOpacity = Math.round(f.curVal) / 100;
		this.target.style.opacity = Math.round(f.curVal) / 100;
		this.curVal = this.curVal - this.increment;
		if( this.curVal <= 0 ){
			window.clearInterval(this.interval);
			if( this.onComplete ){
				this.onComplete();
			}
		}
	}
	f.target = pTarget;
	f.curVal = pStartOpacity;
	f.increment = nIncrement;
	f.onComplete = pOnComplete;
	var n = window.setInterval( bindFunction(f,f),nTime);
	f.interval = n;
	
	return f;
}

var oBlockScreen = undefined;
var oBtnDisabled = undefined;

function blockScreen(pTarget, pBtnDisabled) {
	if(oBlockScreen != undefined) {
		oBlockScreen.dettach();
		if(oBtnDisabled != undefined) { 
			oBtnDisabled.disabled = false;
		}
		oBlockScreen = undefined;
	}
	if(pBtnDisabled != undefined) {
		oBtnDisabled = $(pBtnDisabled);
		oBtnDisabled.disabled = true;
	}
	oBlockScreen = new BlockScreenObj($(pTarget));
	oBlockScreen.show();
}

function showScreen() {
	if(oBtnDisabled != undefined) {
		oBtnDisabled.disabled = false;
		oBtnDisabled = undefined;
	}
	if(oBlockScreen != undefined) {
		oBlockScreen.hide();
		oBlockScreen = undefined;
	}
}
