var popup_child = new Array();
function open_center_window(url, name, width, height, param)
{
	var x=0, y=0, w=0, h=0;
	if (window['screenX'] !== undefined) {
		x = parseInt(window.screenX);
		y = parseInt(window.screenY);
		w = parseInt(window.outerWidth);
		h = parseInt(window.outerHeight);
	} else if (window['screen'] !== undefined) {
		x = 0;
		y = 0;
		w = parseInt(window.screen.width);
		h = parseInt(window.screen.height);
	}

    if (width === undefined || width == null) {
        width = Math.round(w/2);
    } else {
        width = parseInt(width);
    }
    if (height === undefined || height == null) {
        height = Math.round(h/2);
    } else {
        height = parseInt(height);
    }
    if (param === undefined || param == null) {
        param = "";
    }
    
	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 window.open(url, name,'left=' + cx + 'px,top=' + cy + 'px,width=' + width + 'px,height=' + height +'px'+ param);
}

function open_bottom_right_window(url, name, width, height, param)
{
	var x=0, y=0, w=0, h=0;
	if (window['screenX'] !== undefined) {
		x = parseInt(window.screenX);
		y = parseInt(window.screenY);
		w = parseInt(window.outerWidth);
		h = parseInt(window.outerHeight);
	} else if (window['screen'] !== undefined) {
		x = 0;
		y = 0;
		w = parseInt(window.screen.width);
		h = parseInt(window.screen.height);
	}

    if (width === undefined || width == null) {
        width = Math.round(w);
    } else {
        width = parseInt(width);
    }
    if (height === undefined || height == null) {
        height = Math.round(h);
    } else {
        height = parseInt(height);
    }
    if (param === undefined || param == null) {
        param = "";
    }
    
	var cx = x;
	cx += Math.round(w - (width + 30));
	var cy = y;
	cy += Math.round(h - (height + 100));

	return window.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() {
    var hasOpener = (window['opener'] !== undefined && window.opener !== null);
    if (hasOpener) {
        var openerName = null;
        try { openerName = window.opener.name; } catch (e) { }
        if ((openerName||"").length == 0) {
            // console.log("chk_popup : opener EXTERN -> force to \"principale\"");
            window.name = "principale";
        } else {
            if ((window.name||"").length == 0) {
                // console.log("chk_popup : opener ("+openerName+") + window.name empty -> force to \"chk_popup\"");
                window.name = "chk_popup";
            } else {
                // console.log("chk_popup : opener ("+openerName+") + window.name NOT empty ("+window.name+")");
            }
        }
    } else {
        // console.log("chk_popup : NO opener -> force to \"principale\"");
        window.name = "principale";
    }
    // 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');});
    }
}

function letsGoHome()
{
	document.location = 'http://www.maxicours.com/';
}


