// JavaScript Document

var bgDialog = null;
var innerDialog = null;
var innerDialogContentPane = null;

function getScreenDimension() {

	var winW = 1024, winH = 768;
	
	if (document.body && document.body.offsetWidth) {
	 winW = document.body.offsetWidth;
	 winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' &&
		document.documentElement &&
		document.documentElement.offsetWidth ) {
		winW = document.documentElement.offsetWidth;
		winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	}

	return [ winW, winH ];

}

function showDialog( pTitle, pContent, pModal ) {

	var offset = document.body.scrollTop;

	if ( !offset ) {
		offset = window.pageYOffset;
	}
	if ( !offset ) {
		offset = 0;	
	}

	var screenWidth = getScreenDimension()[ 0 ];
	var screenHeight = getScreenDimension()[ 1 ];

	bgDialog = document.createElement( "div" );
	bgDialog.style.position = "absolute";
	bgDialog.style.backgroundColor = "#666666";
	bgDialog.style.left = "0px";
	bgDialog.style.top = "0px";
	bgDialog.style.width = screenWidth + "px";
	bgDialog.style.height = "1500px";
	bgDialog.style.opacity = "0.5";
	bgDialog.style.filter = "alpha(Opacity=50)";
	bgDialog.style.zIndex = 10;

	innerDialog = document.createElement( "div" );
	innerDialog.style.position = "absolute";
	innerDialog.style.backgroundColor = "white";

	var width = ( screenWidth * 0.9 );
	var left = ( screenWidth - width ) / 2;
	var height = ( 0.8 * screenHeight );

	innerDialog.style.left = left + "px";

	// Disable it
	offset = 0;

	innerDialog.style.top = ( offset + ( screenHeight - height ) / 2 ) + "px";
	innerDialog.style.width = width + "px";
	innerDialog.style.borderColor = "#999999";
	innerDialog.style.borderStyle = "solid";
	innerDialog.style.borderWidth = "2px";
	innerDialog.style.opacity = "1";
	innerDialog.style.filter = "alpha(Opacity=100)";
	innerDialog.style.zIndex = 100;
	innerDialog.style.padding = 10;

	var html = "<table width='100%' cellpadding='0' cellspacing='0'><tr><td width='*' style='font-family:helvetica;font-size:14px'>";
	html += pTitle;
	html += "</td><td width='20' onclick='closeDialog()' onmouseOver=\"this.style.cursor='hand'\">[x]</td>"
	html += "</tr></table>";
	html += "<div style='border-top-color:#999999;border-top-width:1px;border-top-style:solid;margin-bottom:10px;margin-top:10px'>&nbsp;</div>";

	var innerDialogHeader = document.createElement( "div" );
	innerDialogHeader.innerHTML = html;
	innerDialog.appendChild( innerDialogHeader );
	innerDialogContentPane = document.createElement( "div" );
	innerDialog.appendChild( innerDialogContentPane );

	innerDialogContentPane.style.fontSize = "11px";

	if ( !pModal ) {
		innerDialogContentPane.innerHTML = "<img src='/images/communs/loading.gif'> Chargement en cours...";
	} else {
		innerDialogContentPane.innerHTML = pContent;
	}

	document.body.appendChild( bgDialog );
	document.body.appendChild( innerDialog );

}

function closeDialog() {

	document.body.removeChild( bgDialog );
	document.body.removeChild( innerDialog );

	bgDialog = null;
	innerDialog = null;

}

