//********************************************
// Javascript d'ouverture de fenetre multiplateforme
// Hubert Gailly hgailly@quantix.fr
// Copyright Quantix 2000-2001
//********************************************

// Lex constantes Quantix
var qt_margin = 20;
var qt_big1 = 680;
var qt_big2 = 565;
var qt_small1 = 300;
var qt_small2 = 200;
var qt_normal1 = 563;
var qt_normal2 = 500;
var big_horizontal = -3;
var small_horizontal = -2;
var normal_horizontal = -1;
var big_vertical = 3;
var small_vertical = 2;
var normal_vertical = 1;
var custom = 0;
var left = 1;
var right = 2;
var center = 0;


// Les variables
var params;
var strns;
var strie;
var w=0;
var h=0;
var x=0;
var y=0;

// Pour la platforme

var isNS = (navigator.appName == "Netscape");
var isMAC = (navigator.platform.indexOf('Mac') != -1);
 

// Les parametres NS_MAC : NS-PC : IE_MAC : IE_PC
// Marge Largeur
deltaWidth = (isNS)? ((isMAC)? -10 : -20) : ((isMAC)? -20 : -20);
// Marge Hauteur
deltaHeight = (isNS)? ((isMAC)? -50 : -62) : ((isMAC)? -5 : -70);
// Décalage gauche
deltaLeft = (isNS)? ((isMAC)? -6 : -6) : ((isMAC)? -5 : -5);
// Décalage haut
deltaTop = (isNS)? ((isMAC)? -30 : -30) : ((isMAC)? -10 : -30);

// Les tableaux pour retenir les fenetres

var arWinRef = new Array();
var arWinName = new Array();

var thiswindow;

function getSizeOpen(width , height  , margeleft , margetop  , adroite , enbas){
		
	if(width == null || height == null) {
		w = screen.width + deltaWidth;
 		h = screen.height + deltaHeight;
	}
	else {
		w = width;
		h = height;
	}
	if(margeleft != null){
		if(adroite == null || adroite == false)
			x = margeleft + deltaLeft;
		else
			x = screen.width - w - margeleft + deltaLeft;
	}
	else{
		x = (screen.width - w) / 2 + deltaLeft;
	}
	if(margetop != null){
		if(enbas == null || enbas == false)
			y = margetop + deltaTop + 30;
		else
			y = screen.height - h - margetop + deltaTop - 20;
	}
	else{
		y = (screen.height - h) / 2 + deltaTop;
	}
}



function popUp (theUrl , position , size , width , height){
	
	
	if(size == null){
		if(width != null && height != null)
			size = custom;
		else
			size = normal_vertical;
			
	}
	if(size != big_horizontal  && size != small_horizontal && size != normal_horizontal && size != big_vertical  && size != small_vertical && size != custom){
		size = normal_vertical;
	}
	if(size == big_horizontal){
		width = qt_big1;
		height = qt_big2;
	}
	else if(size == small_horizontal){
		width = qt_small1;
		height = qt_small2;
	}
	else if(size == normal_horizontal){
		width = qt_normal1;
		height = qt_normal2;
	}
	else if(size == big_vertical){
		width = qt_big2;
		height = qt_big1;
	}
	else if(size == small_vertical){
		width = qt_small2;
		height = qt_small1;
	}
	else if(size == normal_vertical){
		width = qt_normal2;
		height = qt_normal1;
	}
		
	if(position == null)
		position = center;
	if(position == left)
		openWindow (theUrl , 'PopUpLeft' ,  width , height , qt_margin , qt_margin);
	else if(position == right)
		openWindow (theUrl , 'PopUpRight' ,  width , height , qt_margin , qt_margin , true , false);
	else
		openWindow (theUrl , 'PopUpCenter' ,  width , height);
	
}


function openWindow (theUrl , Nom , width , height , margeleft , margetop , adroite , enbas , winparams) {
	
	// openwindow(Url , Nom) -> ouvre en plein écran //
	// openwindow(Url , Nom , width , height ) -> ouvre centré //	
	// openwindow(Url , Nom , width , height , -1) -> ouvre stacked natural //		
	// openwindow(Url , Nom , width , height  , margeleft , margetop  , adroite , enbas) -> ouvre positionné  //
	
	var isStacked = false;
	if(margeleft != null){
		if(margeleft == -1)
			isStacked = true;
	}
	
	getSizeOpen(width , height  , margeleft , margetop  , adroite , enbas);
	
	
	if(winparams == null){
		if(isStacked){
			strns = 'scrollbars=no,status=no,resizable=no,width=' + w + ',height=' + h;
			strie = 'scrollbars=no,status=no,resizable=no,width=' + w + ',height=' + h;
		}
		else{	
			strns = 'scrollbars=no,status=no,resizable=no,width=' + w + ',height=' + h + ',screenX=' + x + ',screenY=' + y;
			strie = 'scrollbars=no,status=no,resizable=no,width=' + w + ',height=' + h + ',left=' + x + ',top=' + y;
		}
	}
	else{	
		if(isStacked){	
			strns = winparams + ',width=' + w + ',height=' + h;
			strie = winparams + ',width=' + w + ',height=' + h;
		}
		else{
			strns = winparams + ',width=' + w + ',height=' + h + ',screenX=' + x + ',screenY=' + y;
			strie = winparams + ',width=' + w + ',height=' + h + ',left=' + x + ',top=' + y;
		}
	}
	
	topparams = (isNS) ? strns  : strie;
	var indice = findInArray(Nom);
	
	if(indice == -1){
		thiswindow = window.open(theUrl , Nom , topparams);
		thiswindow.focus();
		arWinRef = new Array(arWinRef.length + 1);
		arWinRef[arWinRef.length-1] = thiswindow;
		arWinName = new Array(arWinName.length + 1);
		arWinName[arWinName.length-1] = Nom;
	}
	else{
		if(!arWinRef[indice].closed){
			arWinRef[indice].close();
		}
		thiswindow = window.open(theUrl , Nom , topparams);
		thiswindow.focus();
		arWinRef[indice] = thiswindow;
	}
}

function moveWindow (width , height , margeleft , margetop , adroite , enbas , thiswindow) {
	
	getSizeOpen(width , height  , margeleft , margetop  , adroite , enbas);
	if(navigator.appName == "Netscape"){
		h = h - 80;
	}
	else{	
		w = w + 10
		h = h + 30;
	}
	top.resizeTo(w, h);
	top.moveTo(x,y)
}

function findInArray(Name){
	var i = -1;
	for(j = 0 ; j < arWinName.length ; j++){
		if(arWinName[j] == Name){
			i = j
			j = arWinName.length
		}	
	}
	return i;
}

function closeWindow (Name) {
	var indice = findInArray(Name);
	if(indice >= 0){
		arWinRef[indice].close();
	}
}

