﻿function closeVisionneuse()
{
    document.getElementById('visionneuse').src = "about:blank";
    document.getElementById('fond').style.display = "none";
    document.getElementById('centerH').style.display = "none";
}

function openVisionneuse(url, w, h) {
    document.getElementById('visionneuse').src = url;
    document.getElementById('fond').style.display = "block";
    document.getElementById('fond').style.height = (getPageSize()[1] + 'px');
    document.getElementById('centerH').style.display = "block";
    document.getElementById('centerV').style.height = h + "px";
    document.getElementById('centerV').style.width = w + "px";
    var ws = getPageSize();
    if(w < ws[2])
        document.getElementById('centerV').style.marginLeft = "-" + w / 2 + "px";
    else
        document.getElementById('centerV').style.marginLeft = "-" + ws[2] / 2 + "px";
    if (h < ws[3])
        document.getElementById('centerV').style.top = "-" + h / 2 + "px";
    else
        document.getElementById('centerV').style.top = "-" + ws[3] / 2 + "px";
	scroll(0, 0);
}

function openPrecommande(url) {
    document.getElementById("visionneuse").scrolling = "yes";
    document.getElementById("visionneuse").contentWindow.document.body.scroll = "yes";
    openVisionneuse(url, 997, 850);
}

function openVisionneusePDF(url) {
    openVisionneuse(url, 580, 620);
}

function openVisionneuseBien(url)
{
    openVisionneuse(url, 800, 600);
}

//
// 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;
}

//http://mya.edforum.net/?p=59
function copyToClipboard(sText)
{
   if (window.clipboardData)
   {
      window.clipboardData.setData('Text', sText);
   }
   else if (typeof(netscape) == 'object' && typeof(Components) == 'object')
   {
        try
        {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch (e)
        {
            alert("Votre navigateur n'est pas configuré pour autorisé l'accès au presse-papier. Merci de copier l'adresse manuellement.");
        }
        var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
        gClipboardHelper.copyString(sText);
   }
   else
   {
      alert("Cette fonctionnalité n'est pas disponible pour votre navigateur. Merci de copier l'adresse manuellement.");
   }
}
