//********************************************
// Javascript d'ouverture de fenetre multiplateforme
// Hubert Gailly hgailly@quantix.fr
// Copyright Quantix 2000-2001
//********************************************


// Les variables
var params;
var strns;
var strie;
var w;
var h;
var x
var y;

// 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 getSize(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 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;
	}
		
	getSize(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){
			thiswindow = window.open(theUrl , Nom , topparams);
			thiswindow.focus();
			arWinRef[indice] = thiswindow;
		}
		else{
			thiswindow = arWinRef[indice].open(theUrl , Nom);
			arWinRef[indice].focus();
		}
	}
	
	
}

function moveWindow (width , height , margeleft , margetop , adroite , enbas , thiswindow) {
	
	getSize(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();
	}
}


function doAlert() {
	openWindow (alertUrl , 'Alerte' , 300 , 250);
}