// (c)2007 MINGUET LAURENT, tout droit réservé
 
var id_grey_template		= 'DIV_GREY_TEMPLATE';
var id_grey_main			= 'DIV_GREY_MAIN';
var id_grey_content			= 'DIV_GREY_CONTENT';
var grey_params				= new Array();
var grey_fnc_resize_after	= null;


function greyResizeMain()
{
	var obj_tple = document.getElementById(id_grey_template);
	var obj_main = document.getElementById(id_grey_main);

	if (!obj_tple) return false;
	if (!obj_main) return false;

	var info_size = getPageSize();

	// largeur et hauteur de la fenettre
	var body_w	= info_size[2];
	var body_h	= info_size[3];

	obj_tple.style.width		= body_w+'px';
	obj_tple.style.height		= body_h+'px';

	obj_main.style.width		= body_w+'px';
	obj_main.style.height		= body_h+'px';

	var w = body_w-60;
	var h = body_h-60;

	if (grey_params['width']) w = grey_params['width'];
	if (grey_params['height']) h = grey_params['height'];

	greyResizeWindow(w, h);

	if (grey_fnc_resize_after) eval(grey_fnc_resize_after+'(body_w, body_h);');
}

function greyResizeWindow(w, h)
{
	var obj_cont = document.getElementById(id_grey_content);

	if (!obj_cont) return false;

	obj_cont.style.width		= w+'px';
	obj_cont.style.height		= h+'px';
	obj_cont.style.marginLeft	= -parseInt(0.5*w)+'px';
	obj_cont.style.marginTop	= -parseInt(0.5*h)+'px';
}

function greyShow(w, h, d)
{
	grey_params		= new Array();
	grey_params['width']	= w;
	grey_params['height']	= h;

	greyResizeMain();

	var con_grey = document.getElementById(id_grey_content)
	if (d)
	{
		con_grey.style.border		= 'none';	
		con_grey.style.background	= 'none';	
	}
	else
	{
		con_grey.style.border		= 'solid 1px #777777';	
		con_grey.style.background	= '#FFFFFF';	
	}

	var obj_grey = document.getElementById(id_grey_main);
	obj_grey.style.display = 'block'
}

function greyHide()
{
	var obj_grey = document.getElementById(id_grey_main);
	obj_grey.style.display = 'none';
}

function greyOpen(contenu, w, h, d)
{
	document.getElementById(id_grey_content).innerHTML = contenu;

	greyShow(w, h, d);
}

function greyMessage(msg)
{
	var contenu = '<div style="text-align: center; width: 100%; font-weight: bold; font-size: 12px;"><br>'+msg+'<br><br></div>';
	greyOpen(contenu, 500, 50);
}

function greyWindow(contenu)
{
	var reg = new RegExp("^resize:([0-9]+),([0-9]+)","gi")
	
	if (contenu=='reload_page')
	{
		greyMessage('Chargement en cours...');
		setTimeout('window.location.reload();', '10');
		return true;
	}
	
	if (contenu.substr(0,11)=='javascript:')
	{
		eval(contenu.substr(11));
		return true;
	}

	if (contenu.substr(0,7)=='resize:' || contenu.substr(0,7)=='window:')
	{
		var disp_win = (contenu.substr(0,7)=='window:');

		contenu = contenu.split("\n");
		var tmp = contenu[0].substr(7).split(',');
		contenu[0] = null;

		var msg = contenu.join("\n");
		var w	= tmp[0].replace(/[^0-9]/gi, '');
		var h	= tmp[1].replace(/[^0-9]/gi, '');
	}
	else
	{
		var msg	= contenu;
		var w	= 0;
		var h	= 0;
	}

	greyOpen(msg, w, h, disp_win);
	return true;
}

function greyLoad(url, no_msg)
{
	var msg = 'Chargement en cours...';
	if (no_msg) msg = null;

	HTTPObject_add(url , null, null, 'greyWindow(http_result);', msg);
}

function greyClose()
{
	document.getElementById(id_grey_content).innerHTML = '';
	greyHide();
}

function greyInit()
{
	if (!document.body)
	{
		setTimeout('greyInit()', 200);
		return false;
	}
	
	addEvent(window, 'resize',	greyResizeMain);
	greyResizeMain();
	setTimeout("greyResizeMain();", 500);

	return true;
}


// 
// getPageSize() 
// Returns array with page width, height and window width, height 
// Core code from - quirksmode.org 
// Edit for Firefox by pHaez 
// 
function getPageSize()
{ 
	var xScroll, yScroll; 
	 
	if (window.innerHeight && window.scrollMaxY)
	{	 
		xScroll = document.body.scrollWidth; 
		yScroll = window.innerHeight + window.scrollMaxY; 
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)		// all but Explorer Mac 
	{
		xScroll = document.body.scrollWidth; 
		yScroll = document.body.scrollHeight; 
	}
	else  										// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
	{
		xScroll = document.body.offsetWidth; 
		yScroll = document.body.offsetHeight; 
	} 
	 
	var windowWidth, windowHeight; 
	if (self.innerHeight)								// all except Explorer 
	{
		windowWidth = self.innerWidth; 
		windowHeight = self.innerHeight; 
	}
	else if (document.documentElement && document.documentElement.clientHeight)	 // Explorer 6 Strict Mode 
	{
		windowWidth = document.documentElement.clientWidth; 
		windowHeight = document.documentElement.clientHeight; 
	}
	else if (document.body)								 // other Explorers 
	{
		windowWidth = document.body.clientWidth; 
		windowHeight = document.body.clientHeight; 
	}	 
	 
	// for small pages with total height less then height of the viewport 
	if(yScroll < windowHeight)
	{ 
		pageHeight = windowHeight; 
	}
	else
	{  
		pageHeight = yScroll; 
	} 
 
	// for small pages with total width less then width of the viewport 
	if(xScroll < windowWidth)
	{	 
		pageWidth = windowWidth; 
	}
	else
	{ 
		pageWidth = xScroll; 
	} 
 
 
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)  
	return arrayPageSize; 
}

greyInit();