var ElGoodies = {
	
	getDocument: function(){
		return this.ownerDocument;
	},
	
	getWindow: function(){
		return this.getDocument().getWindow?this.getDocument().getWindow():window;
	},

	dispose: function(){
		return this.parentNode.removeChild(this);
	},

	replaces: function(el){
		if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
		el.parentNode.replaceChild(this, el);
		return this;
	},

	hasClass: function(className){
		return this.className.contains(className, ' ');
	},

	addClass: function(className){
		if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
		return this;
	},

	removeClass: function(className){
		this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1').clean();
		return this;
	},

	toggleClass: function(className){
		return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
	},

	getComputedStyle: function(property){
		var result = null;
		if (this.currentStyle){
			result = this.currentStyle[property.camelCase()];
		} else {
			var computed = this.getWindow().getComputedStyle(this, null);
			if (computed) result = computed.getPropertyValue([property.hyphenate()]);
		}
		return result;
	},

	isBody: function() {
		return this.tagName.toLowerCase() == 'body';
	},

	getPosition: function(relative){
		function objectize(el) {
			if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
			return el;
		}
		if (this.isBody()) return {x: 0, y: 0};
		var el = this, position = {x: 0, y: 0};
		while (el){
			position.x += el.offsetLeft;
			position.y += el.offsetTop;
			el = el.offsetParent;
		}
		var rpos = (relative) ? objectize(relative).getPosition() : {x: 0, y: 0};
		return {x: position.x - rpos.x, y: position.y - rpos.y};
	},

	enrich: function(el){
		if(null==el) return;
		if('string'==(typeof el).toLowerCase()) el = document.getElementById(el);
		for( var methodName in this ) {
			if('enrich'==methodName) continue;
			if( 'undefined' == typeof el[methodName] || null == typeof el[methodName] ) {
				el[methodName] = this[methodName];
			}
		}
	}
};

function maximize(el) {
	if(!el.getPosition) ElGoodies.enrich(el);
	var soFarAway = document.getElementById('soFarAway');
	var farAway = document.getElementById('farAway');
	var lastDiv = (document.getElementsByTagName('div'))[document.getElementsByTagName('div').length-1];
	if( null==soFarAway ) {
		var sfaProps = {
			position:'absolute',
			right:'1px',
			bottom:'1px',
			overflow:'hidden',
			width:'1px',
			height:'1px',
			backgroundColor:'transparent',
			zIndex:'-1'
		};
		soFarAway = document.createElement('div');
		soFarAway.setAttribute('id','soFarAway');
		for( var prop in sfaProps ) soFarAway.style[prop] = sfaProps[prop];
		el.getDocument().body.insertBefore(soFarAway,document.body.firstChild);
		ElGoodies.enrich(soFarAway);
		ElGoodies.enrich(lastDiv);
	}
	lastDiv.pos = lastDiv.getPosition();
	soFarAway.pos = soFarAway.getPosition();
	el.style.width  = Math.max(soFarAway.pos.x+2,el.getDocument().body.clientWidth)+'px';
	//el.style.height = Math.max(soFarAway.pos.y+1,lastDiv.pos.y+lastDiv.offsetHeight)+'px';
	
	h = Math.max((window.innerHeight?window.innerHeight:0),(document.getElementsByTagName('body'))[0].offsetHeight,(document.getElementsByTagName('html'))[0].offsetHeight)
	el.style.height = h+'px';
	el.style.width = '994px';
	
	el.style.display = 'block';
}

function affichePopIn(nom_popup){
	maximize(document.getElementById('BgPopup'));
	document.getElementById(nom_popup).style.display='block';

	
	// on enleve les select
	var x = document.getElementsByTagName("select");
	for (i = 0; i < x.length; i++) {
	   //x[i].style.display = "none";
	   x[i].style.visibility = "hidden";
	}
	
	return false;
}

function cachePopIn(nom_popup){
	document.getElementById(nom_popup).style.display='none';
	document.getElementById('BgPopup').style.display='none';
	
	// on remet les select
	var x = document.getElementsByTagName("select");
	for (i = 0; i < x.length; i++) {
	   //x[i].style.display = "block";
	   x[i].style.visibility = "";
	}
	return false;
}// JavaScript Document
