function getScrollPosition() 
{
    var mytop = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
    var myleft = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;

    return  { left: myleft,  top: mytop };
}

function getSize() {
    var myWidth = 0, myHeight = 0;

    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    return { width: myWidth, height: myHeight };
}

function showModal(idDiv)
{	
	var body = $("body");
	var size = getSize();
	var modale = $("#" + idDiv);
	
	// Globale
	
	var divGlobale = document.getElementById("divGlobale");
	
	if (!divGlobale)
	{
		divGlobale = document.createElement("div");
		divGlobale.setAttribute("id","divGlobale");

		modale.parent().append(divGlobale);
    }

    /*
    var trace = modale.find(".trace");

    if (trace.length==0) {

   
        modale.append("<div class=\"trace\"></div>");

        trace = modale.find(".trace");
        //alert("!trace");
    }

    trace.text(size.height + "x" + size.width);
    */


	var	globale = $("#divGlobale");

	globale.width(size.width);
	globale.height(size.height);


	globale.show();
	
	// Modale
	var modale = $("#" + idDiv);

	modale.css("top", parseInt((size.height - modale.attr("modalHeight")) / 2));
	modale.css("left", parseInt((size.width - modale.attr("modalWidth")) / 2));
	
	modale.show();
	modale.find(".cancel").click(function() { modalClose(); });
}

function modalClose() 
{
    $("#divGlobale").remove();
    //$(".modale.trace").remove();
    $(".modale:VISIBLE").hide();
}

$(window).resize(function () { windowResize(); });
$(window).scroll(function () { windowResize(); });

function windowResize()
{

    var size = getSize();

    var modale = $(".modale:VISIBLE");
    /*
    var trace = modale.find(".trace");
    trace.text(size.height + "x" + size.width);
    */

    var globale = $("#divGlobale");

    if (globale) 
    {
        globale.width(size.width);
        globale.height(size.height);
    }

    modale.css("top", parseInt((size.height - modale.attr("modalHeight")) / 2));
    modale.css("left", parseInt((size.width - modale.attr("modalWidth")) / 2));
}
