﻿/////////////////////////////
/// Gestion popup Modal
/////////////////////////////
// Variables globales
//var isFirfox;
var objDiv = null;
var originalDivHTML = "";
var idPopup = "";
var over = false;
var mbrowser;
var mddlName="";

function Load(){
    /////////////////////////////////
    // Chargement de l'objet popup
    /////////////////////////////////
    mbrowser=new browser;   
    
    document.onmousedown = MouseDown;
    document.onmousemove = MouseMove;
    document.onmouseup = MouseUp;

    //Image de fond    
    //document.write('<div id="PopModIma" class="PopModIma" style="width:'+ window.screen.width + 'px; height:' + window.screen.height +'px"></div>');
}


function MaskObjet(id){
    mddlName=id;
}

function ShowPopupModal(id, title, width, height,idFrame,srcFrame){
    //////////////////////////////////
    // Afficher la popup modal
    //////////////////////////////////
    // Mode Modal 
    $j('body').prepend('<div id="PopModIma" class="PopModIma" style="width:' + window.screen.width + 'px; height:' + window.screen.height + 'px"></div>');
        
    $j('#PopModIma').css({ opacity: '0.7',display:'block' });
	idPopup = id;
    
	document.getElementById('PopModIma').style.visibility = "visible";
    // Caractéristique de la popup
    document.getElementById(id).style.width = width + 'px';
    document.getElementById(id).style.height = height + 'px';
    // Centrer sur l'écran
    document.getElementById(id).style.left = (window.screen.width/4)-30 + 'px';
    document.getElementById(id).style.top = '130px'//(window.screen.height/4) + 'px';
	
	var Header;
	
	if (originalDivHTML == "")
	    originalDivHTML = document.getElementById(id).innerHTML;
	    
	// Contruction de l'entete 
	Header = '<table style="width:' + width + 'px" class="PopModTit">' +
	         '<tr><td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px">' + title + '</td>' + 
	         '<td style="width:18px" align="right"><a href="javascript:HidePopupModal();void(0);">' + 
	         '<img alt="Close..." title="Fermer..." src="Images/Close.png" border="0"/></a></td></tr></table>';
	//MaskObjet
	if (mddlName != '') {document.getElementById(mddlName).style.display = 'none';}
        
    // Ajoute l'entete'
	document.getElementById(id).innerHTML = Header + originalDivHTML;
	document.getElementById(id).className = 'PopMod';
	document.getElementById(id).style.visibility = "visible";
	document.getElementById(id).style.display='block';
	if (idFrame !=''){
	    document.getElementById(idFrame).src = srcFrame;	    
	}
}


function HidePopupModal(){
    //////////////////////////////////
    // Masquer la popup modal
    //////////////////////////////////       
	document.getElementById(idPopup).innerHTML = originalDivHTML;	
	document.getElementById(idPopup).style.visibility='hidden';	
	document.getElementById(idPopup).style.display='none';	
	document.getElementById('PopModIma').style.visibility = 'hidden';		
	if (mddlName!=''){
	   document.getElementById(mddlName).style.display='block';	
	}
	mddlName="";
	idPopup = "";
	originalDivHTML="";
}

function MouseDown(e){
    //////////////////////////////////
    // Gestion Click sur la popup
    //////////////////////////////////
    // Focus dessus
    if (over) {
        // Navigateur
        if (mbrowser.firfox) {
        
            objDiv = document.getElementById(idPopup);            
            X = e.layerX;
            Y = e.layerY;
            return false;
        }
        else {
            objDiv = document.getElementById(idPopup);
            objDiv = objDiv.style;
            X = event.offsetX;
            Y = event.offsetY;
        }
    }
}


function MouseMove(e){
    //////////////////////////////////
    // Gestion deplacement de la popup
    //////////////////////////////////
    
    if (objDiv) {
        if (mbrowser.firfox) {
            
            objDiv.style.top = (e.pageY-Y) + 'px';
            objDiv.style.left = (e.pageX-X) + 'px';
            return false;
        }
        else{
            objDiv.pixelLeft = event.clientX-X + document.body.scrollLeft;
            objDiv.pixelTop = event.clientY-Y + document.body.scrollTop;
            return false;
        }
    }
}

function MouseUp(){
    ////////////////////
    // Relache la popup
    ////////////////////
   
    objDiv = null;
}

 Load() 


