var popup_child = new Array();
function open_center_window(url, name, width, height, param)
{
	var x=0; var y=0; var w=0; var h=0;
	if (bw.ie)
	{
		//x = window.screenLeft;
		//y = window.screenTop;
		x = 0;
		y = 0;
		//w = window.document.body.offsetWidth;
		//h = window.document.body.offsetHeight;
		w = screen.width;
		h = screen.height;
	}
	else
	{
		x = window.screenX;
		y = window.screenY;
		w = window.outerWidth;
		h = window.outerHeight;
	}
	var cx = x;
	if (w > width) cx += Math.round((w - width) / 2);
	var cy = y;
	if (h > height) cy += Math.round((h - height) / 2);

	return open(url, name,'left=' + cx + 'px,top=' + cy + 'px,width=' + width + 'px,height=' + height +'px'+ param);
}

function popup_child_add(ref)
{
	popup_child.push(ref);
}

function popup_child_close()
{
	for (i=0 ; i<popup_child.length ; i++) popup_child[i].close();
}

function checkbox_work(id)
{
	c = document.getElementById(id);
	if (c != null)
	{
		if (c.checked) c.checked=false;
		else c.checked=true;
	}
}

function autosize() {
	if(xautosize == 'undefined')
		xautosize = 650;

	var sheight = document.body.scrollHeight;
	var oheight = document.body.offsetHeight;

	if (sheight >= oheight) y = sheight;
	else y = oheight;

	if (y > 500) y=500;

	window.self.resizeTo(xautosize,y+100);
	self.focus();	
}

function chk_popup() {
	if(window.name.substring(0,5) == 'histo') {
		if(!window.location.href.match('popup=1|#','i'))
			window.location.replace(window.location.href+'&popup=1');
	} else window.name = 'principale';
}

var divtime = 0;
var divtop = 0;

function div_center(divobj,divbtop,objw) {
	window.clearTimeout(divtime);
	divtime = setTimeout('div_center(\''+divobj+'\','+divbtop+','+objw+')',20);

	if(bw.ie) {
		if(document.documentElement && document.documentElement.scrollTop > 0)
			divtop = document.documentElement.scrollTop+document.documentElement.clientHeight/2-objw/2;
		else if(document.body && document.body.scrollTop > 0)
			divtop = document.body.scrollTop+document.body.clientHeight/2-objw/2;
		else divtop = divbtop;
	}
	else
	{
		if(window.pageYOffset > 0)
			divtop = window.pageYOffset + window.innerHeight/2-objw/2;
		else divtop = divbtop;
	}

	document.getElementById(divobj).style.top = Math.ceil(divtop) + 'px';
}

function mxc_include_once(script_src)
{
	var script_elem = document.getElementsByTagName('script');
	var script_list = Array;
	for (i=0 ; i<script_elem.length-1 ; i++)
		if (script_elem[i] != null)
		{
			script_list[script_elem[i].getAttribute('src')] = 1;
		}

	var head_elem = document.getElementsByTagName('head');
	if (head_elem == null) return;

	if (script_list[script_src] == null)
	{
		var script_ajout = document.createElement('script');
		script_ajout.type = "text/javascript";
		script_ajout.src = script_src;
		head_elem[0].appendChild(script_ajout);
	}

}

function dnoneToggle(id, className)
{

    var listeElement = null;
    if (className != undefined && className !== '' && className != null) {
        listeElement = $ES('.' + className, id);
    } else {
        var el = $(id);
        if (el != null) {
            listeElement = new Array();
            listeElement.push($(id));
        }
    }

    if (listeElement != null) {
        listeElement.each(function(el){el.toggleClass('dnone');});
    }
}

