/* $Id: pleade.js 13643 2009-02-12 14:46:43Z jcwiklinski $ */
/**
Copyright (C) 2003-2008 AJLSM, Anaphore
Voir le fichier LICENCE
**/
/* Ce fichier de configuration fait partie de la distribution standard
de Pleade. Vous pouvez le modifier à votre guise. */
/*
	Retourne la hauteur totale d'un élément.

	A noter que dans IE et dans Firefox, $(el).getHeight() retourne la somme de:
		- border-top-width
		- padding-top
		- hauteur comme telle de l'élément
		- padding-bottom
		- border-bottom-width
	Par contre, cette hauteur n'inclut pas margin-top et margin-bottom.

	Pour inclure les marges, mettre le second paramètre (includeMargins) à true.
*/
function getHeight(el, includeMargins) {
	if (!el || !$(el)) return 0;
	var iMargin = false;
	if (includeMargins) iMargin = true;
	var h = $(el).getHeight();
	if ( iMargin ) h += getVMargin(el);
	return h;
}

function getWidth(el, includeMargins) {
	if (!el || !$(el)) return 0;
	var iMargin = false;
	if (includeMargins) iMargin = true;
	var w = $(el).getWidth();
	if ( iMargin ) w += getHMargin(el);
	return w;
}

/*
	Définit la hauteur totale d'un élément.

	La hauteur totale est la somme de:
		- margin-top
		- border-top-width
		- padding-top
		- hauteur comme telle de l'élément
		- padding-bottom
		- border-bottom-width
		- margin-bottom

	Le paramètre height est la hauteur totale désirée. C'est la propriété
	CSS height qui sera modifiée, les marges, bordures et padding ne sont pas
	touchés. Le paramètre height est donc diminué de la somme des ces hauteurs.
*/
function setTotalHeight(el, height) {
	if (!height || !el || !$(el)) return;
	var h = height - getVMargin(el) - getVPadding(el) - getVBorder(el);
	if ( h < 0 ) h = 0;
	$(el).setStyle({height: h + "px"});
}

/* Retourne les marges verticales d'un élément */
function getVMargin(el) {
	return getVDimension(el, "margin");
}

/* Retourne les marges horizontales d'un élément */
function getHMargin(el) {
	return getHDimension(el, "margin");
}

/* Retourne le padding vertical d'un élément */
function getVPadding(el) {
	return getVDimension(el, "padding");
}

/* Retourne l'épaisseur (verticale) des bordures horizontales */
function getVBorder(el) {
	return getVDimension(el, "border", "-width");
}

/* Retourne les valeurs top et bottom d'une dimension verticale */
function getVDimension(el, prop, suffix) {
	if (!prop || !el || !$(el)) return 0;
	el = $(el);
	suffix = suffix || "";
	var hT = parseInt($(el).getStyle(prop + "-top" + suffix));
	var hB = parseInt($(el).getStyle(prop + "-bottom" + suffix));
	var h = 0;
	if ( hT ) h += hT;
	if ( hB ) h += hB;
	return h;
}
/* Retourne les valeurs left et right d'une dimension horizontale */
function getHDimension(el, prop, suffix) {
	if (!prop || !el || !$(el)) return 0;
	el = $(el);
	suffix = suffix || "";
	var hT = parseInt($(el).getStyle(prop + "-left" + suffix));
	var hB = parseInt($(el).getStyle(prop + "-right" + suffix));
	var h = 0;
	if ( hT ) h += hT;
	if ( hB ) h += hB;
	return h;
}

/*	Ouvre une nouvelle fenêtre, nommée ou non	*/
var popups = new Array();
function newWin(href, name, width, height) {
	if( !href ) return true;
	//var options = "directory=yes,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=yes";
	var options = "";
	var opts = "";
	if( width!='' && width != undefined ){
		opts = "width="+width;
	}
	if( height!='' && height != undefined ){
		if( opts != '' ) opt += ",";
		opts += "height="+height;
	}
	if( opts != '' ) opts += ';';
	opts += options;
	var newWin = window.open(href, name, opts);
	newWin.focus();
	return false;
}
/*function winFocus(href, name, width, height) {
	if (!href) return true;
	if (popups && popups[name] && !popups[name].closed && popups[name].location) {
		if(popups[name].location.href == href);
		else popups[name].location.href = href;
	} else {
		var w = screen.width;
		if (width && width != '') w = width;
		var h = screen.height;
		if (height && height != '') h = height;
		var options = "directory=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes";
		popups[name]=window.open(href, name, options);
		if ( w == screen.width && h == screen.height ) popups[name].moveTo(0,0);
		popups[name].resizeTo(w,h);
	}
	if (popups && popups[name] && popups[name].focus) try { popups[name].focus(); } catch (e) {}
	return false;
}*/
function winFocus(href, name, width, height, full) {
	if (!href) return true;
	if (popups && popups[name] && !popups[name].closed && popups[name].location) {
		if(popups[name].location.href == href);
		else popups[name].location.href = href;
	} else {
		var options = "directory=yes,location=yes,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=yes";
    if( full == 'true' ) options = "directory=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,fullscreen=yes";
		var opts = "";
		if( width!='' && width != undefined ){
			opts = "width="+width;
		}
		if( height!='' && height != undefined ){
			if ( opts != '' ) opts += ',';
			opts += "height="+height;
		}
		if ( opts != '' ) opts += ';';
		opts += options;
		popups[name]=window.open(href, name, opts);
	}
	if (popups && popups[name] && popups[name].focus) try { popups[name].focus(); } catch (e) {}
	return false;
}

/**
*		Ouvre la visionneuse d'images.
*/
function openImgViewer(url) {
	return winFocus(url, 'imgviewer', null, null, 'true');
}

/**
*	Ouvre une fenêtre pour un document attaché.
*/
function openAttachedDocument(url) {
	return winFocus(url, 'attdoc');
}
