/* Popup */

function popup(url,width,height) {
    var popup = document.getElementById('popup');

    if(typeof(popup)=="undefined") {
        alert("missing popup element...");
    } else {
        document.getElementById('popupcontainer').style.display='block';

        if(typeof(width)!="number") width = 750;
        if(typeof(height)!="number") height = 550;
        
        maxHeight = getWindowHeight();
        maxWidth = getWindowWidth();

        // check window size
        if(maxWidth < width) width = maxWidth;
        if(maxHeight - 60 < height) height = maxHeight - 60;

		_top = (maxHeight - height) / 2;
		_left = (maxWidth - width) / 2;

        popup.style.width = "" + width + "px";
        popup.style.height = "" + height + "px";
        popup.style.top = "" + _top + "px";
        popup.style.left = "" + _left + "px";
        popup.src = url;
    }
	return false;
}

function popupie6(url,width,height, margintop, margintop2) {
    var popup = document.getElementById('popup');

    if(typeof(popup)=="undefined") {
        alert("missing popup element...");
    } else {
        document.getElementById('popupcontainer').style.display='block';

        if(typeof(width)=="number") popup.style.width = ""+width+"px";
        else popup.style.width = "560px";

        if(typeof(height)=="number") popup.style.height = ""+height+"px";
        else popup.style.height = "500px";

        popup.src = url;

		// facturation affichee, on decale un peu plus
		if(typeof(margintop2)=="number" 
			&& (document.getElementById('facturation') && document.getElementById('facturation').style.display == "block")) {
			popup.style.top = margintop2;
		} else popup.style.top = margintop;

    }
	return false;
}

function close() { // close popup
	if(document.getElementById('popupcontainerie6'))
	    document.getElementById('popupcontainerie6').style.display='none';
	else
	    document.getElementById('popupcontainer').style.display='none';
}

function getWindowHeight() {
    if (typeof(window.innerHeight)=='number') {
        return window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
         return document.documentElement.clientHeight;
    }
    else if (document.body && document.body.clientHeight) {
         return document.body.clientHeight;
    }
    return 500;
}

function getWindowWidth() {
    if (typeof(window.innerWidth)=='number') {
        return window.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth) {
         return document.documentElement.clientWidth;
    }
    else if (document.body && document.body.clientWidth) {
         return document.body.clientWidth;
    }
    return 500;
}
