// +----------------------------------------------------------------------+
// | JavaScript 1.3                                                       |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002, 2005 Jeckel-Dev                                  |
// +----------------------------------------------------------------------+
// | Description :                                                        |
// | Traitement des popups, ouverture, fermeture et synchronisation avec  |
// | la page appelante.                                                   |
// | Version : 1.1                                                        |
// +----------------------------------------------------------------------+
// | Authors: Julien MERCIER <jeckel@jeckel-dev.com>                      |
// +----------------------------------------------------------------------+
// | Fichier           : ArkadiaPopups.js                                 |
// | Date creation     : 10/09/02                                         |
// | Date modification : 13/08/04                                         |
// +----------------------------------------------------------------------+
// | Variables indispensables dans le fichier appelant :                  |
// |                                                                      |
// | Variables propriétaires générées :                                   |
// |    - __lstPopups : Tableau contenant la liste des popups ouvertes    |
// |                                                                      |
// +----------------------------------------------------------------------+



if (typeof(ark_dflToolBar) == 'undefined')     var ark_dflToolBar = 0;
if (typeof(ark_dflMenuBar) == 'undefined')     var ark_dflMenuBar = 0;
if (typeof(ark_dflLocationBar) == 'undefined') var ark_dflLocationBar = 0;
if (typeof(ark_dflStatusBar) == 'undefined')   var ark_dflStatusBar = 0;
if (typeof(ark_dflWidth) == 'undefined')       var ark_dflWidth = 400;
if (typeof(ark_dflHeight) == 'undefined')      var ark_dflHeight = 300;
if (typeof(ark_dflTop) == 'undefined')         var ark_dflTop = 250;
if (typeof(ark_dflLeft) == 'undefined')        var ark_dflLeft = 250;
if (typeof(ark_dflResize) == 'undefined')      var ark_dflResize = 0;
if (typeof(ark_dflScrollBar) == 'undefined')   var ark_dflScrollBar = 1;

if (typeof(addEvent) == 'undefined') {
	function addEvent(obj, evType, fn) {
		if (obj.addEventListener) {
			obj.addEventListener(evType, fn, true);
			return true;
		} else if (obj.attachEvent) {
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		} else {
			return false;
		}
	}  // function addEvent
}

// +----------------------------------------------------------------------+
// | Fonction    : Popup                                                  |
// | Description : Description de l'objet Popup qui permet de gérer       |
// |               l'ensemble de la popup                                 |
// | Paramètres  :                                                        |
// |    - nom     : Nom de la popup                                       |
// |    - url     : Url chargée dans le popup                             |
// |    - refresh : Si une popup du même nom existe déjà :                |
// |                true => on rafraichis le contenu                      |
// |                false => on se contente de mettre en avant la popup   |
// | Retour      :                                                        |
// +----------------------------------------------------------------------+


function Popup(nom, url, refresh) {
	this.nom         = nom;
	this.url         = url;
	this.refresh     = refresh;

	this.params      = new Object;

	this.params['toolbar']    = ark_dflToolBar;
	this.params['menubar']    = ark_dflMenuBar;
	this.params['location']   = ark_dflLocationBar;
	this.params['status']     = ark_dflStatusBar;
	this.params['width']      = ark_dflWidth;
	this.params['height']     = ark_dflHeight;
	this.params['top']        = ark_dflTop;
	this.params['left']       = ark_dflLeft;
	this.params['resizable']  = ark_dflResize;
	this.params['scrollbars'] = ark_dflScrollBar;
}


// +----------------------------------------------------------------------+
// | Fonction    : openPopup                                              |
// | Description : Function de traitement de l'ouverture de la Popup      |
// | Paramètres  :                                                        |
// | Retour      :                                                        |
// +----------------------------------------------------------------------+

function openPopup() {
	var dad = window.top;
	var paramWindow;

	if (typeof(dad.__lstPopups[this.nom]) != 'undefined') {
      try {
         dad.__lstPopups[this.nom].close();
      } catch(ex) { }
	}
	paramWindow  = 'toolbar=' + this.params['toolbar'];
	paramWindow += ',menubar=' + this.params['menubar'];
	paramWindow += ',location=' + this.params['location'];
	paramWindow += ',status=' + this.params['status'];
	paramWindow += ',width=' + this.params['width'];
	paramWindow += ',height=' + this.params['height'];
	paramWindow += ',top=' + this.params['top'];
	paramWindow += ',left=' + this.params['left'];
	paramWindow += ',resizable=' + this.params['resizable'];
	paramWindow += ',scrollbars=' + this.params['scrollbars'];
	
	win = dad.__lstPopups[this.nom] = window.open('', this.nom, paramWindow);
	doc = '<html><head>';
	if (typeof(this.title) != 'undefined') {
		doc += '<title>' + this.title + '</title>';
	}
	doc += '</head>';
	doc += '<frameset cols="0,100%" frameborder="NO" border="0" framespacing="0"><frame /><frame src="' + this.url + '" /></frameset>';
	doc += '</html>';
	win.document.open();
//	win.document.write('<frameset cols="0,100%" frameborder="NO" border="0" framespacing="0"><frame /><frame src="' + this.url + '" /></frameset>');
	win.document.write(doc);
	win.document.close();

	win.dad = dad;
}

Popup.prototype.open = openPopup;
if (! window.top.__lstPopups)
	window.top.__lstPopups = new Object;


// +----------------------------------------------------------------------+
// | Fonction    : closePopups                                            |
// | Description : Function de fermeture de l'ensemble des popups encore  |
// |               ouvertes                                               |
// | Paramètres  :                                                        |
// | Retour      :                                                        |
// +----------------------------------------------------------------------+

function closePopups() {
	var dad = window.top;
	for(popup in dad.__lstPopups)
		if ((typeof(dad.__lstPopups[popup]) != 'undefined') && (typeof(dad.__lstPopups[popup].name) != 'unknown'))
			dad.__lstPopups[popup].close();
}

addEvent(window, 'unload', closePopups);

