// + + + 
// xWindow.js - v2.4 | 09.7.2005
// popup window handling functions

// note: 
//	Si 'xLeft' et 'xTop' ont une valeur de null, le popup est automatiquement centré dans le browser. 
//	ex: xPopup('xPage','320','200','xWinName',null,null,'scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,dependent=no');

var xWin = null;
function xOpenDoc(xDoc) {
	xPopup(xDoc,'550','500','xDoc',null,null,'scrollbars=no,toolbar=no,location=yes,status=no,menubar=no,resizable=yes,dependent=no');
}

function xPopup(xPage,xWidth,xHeight,xWinName,xLeft,xTop,xFeatures){
	var xWinLeft;
	var xWinTop;
	(xLeft!=null)?xWinLeft=xLeft : xWinLeft=(screen.width-xWidth)/2;
	(xTop!=null)?xWinTop=xTop : xWinTop=(screen.height-xHeight)/2;
	xSettings='width='+xWidth+',height='+xHeight+',top='+xWinTop+',left='+xWinLeft+','+xFeatures+'';
	xWin=window.open(xPage,xWinName,xSettings);
	if(xWin!=null || xWin != undefined){
		xWin.xParent = self;
		if(parseInt(navigator.appVersion) >= 4){xWin.window.focus();}
	}
}

function xResizeWindow(xWidth,xHeight) { 
	   var NS = (navigator.appName=="Netscape")?true:false; 
       xCurrentWidth = (NS)?window.innerWidth:document.body.clientWidth; 
       xCurrentHeight = (NS)?window.innerHeight:document.body.clientHeight; 
       self.resizeBy(xWidth-xCurrentWidth, xHeight-xCurrentHeight); 
       self.focus(); 
}

function xCenterWindow(xWidth,xHeight) { 
		xWinLeft=(screen.width-xWidth)/2;
		xWinTop=(screen.height-xHeight)/2;
		window.moveTo(xWinLeft,xWinTop);
}

// + + +
// xLayers.js
// Div & layer manipulation related functions

function xGetTarget(xTarget)
{
	var xLV1;
	if(document.all && document.getElementById) xLV1 = document.all[xTarget];
	if(document.layers) xLV1 = document.layers[xTarget];
	if(document.addEventListener) xLV1 = document.getElementById(xTarget);
	return xLV1;
}

function xGetPosition(xTarget,xProp)
{
	var xLV1;
	if(xProp=='offsetLeft'){(!(document.layers))? xLV1 = xTarget.offsetLeft : xLV1 = xTarget.pageX;}
	if(xProp=='offsetTop'){(!(document.layers))? xLV1 = xTarget.offsetTop : xLV1 = xTargetpageY;}
		return xLV1;
}
	
function xSetPosition(xTarget,xLeft,xTop)
{
	(!(document.layers))? xTarget.style.left = xLeft+'px' : xTarget['left'] = xLeft;
	(!(document.layers))? xTarget.style.top = xTop+'px' : xTarget['top'] = xTop;
}

function xSetVisibility(xTarget,xValue)
{	
	(!(document.layers))? xTarget.style.visibility = xValue : xTarget['visibility'] = xValue;
}

function xGetNumByName(xString,xName)
{
	var xRegExp = new RegExp("^"+xName, "i") 
	var xNum = xString.replace(xRegExp,"");
	return xNum;
}

function xGetNumBySep(xString)
{
	return xString.substr(xString.indexOf('_')+1,xString.length-1);
}

function xGetNameBySep(xString)
{
	return xString.substr(0,xString.indexOf('_'));
}

function xPand(xTarget,xValue) {
	// Utiliser sur un lien
	// Exemple pour toggle visibility : "javascript:xPand('test');"
	// Exemple pour forced visibility : "javascript:xPand('test',1);"
	
	// Icone : 
	// Utiliser le meme ID que le target et ajoueter "_i" 
	// ex: (target="test")
	// <img id="test_i" src="/images/icon.gif" alt="" border="0" /> 
	// l'icone remplacé sera "icon_a.gif"
	
	
	
	if (typeof(xTarget) == "string") {
		xTargetName = xTarget;
		xIcon = xGetTarget(xTargetName+"_i");
		xTarget = xGetTarget(xTarget);
	} else {
		xRef = xTarget;
		xTargetName = xRef.id;
		xIcon = xGetTarget(xTargetName+"_i");
		xTarget = xGetTarget(xTargetName+"_c");
	}
	
	if (xValue >= 0 && typeof(xTarget) == "object") {
		switch (xValue) {
			case 0: xTarget.style.display = "none";xTarget.xOpened = 0;break;
			
			case 1: xTarget.style.display = "block";xTarget.xOpened = 1;break;
		}
	} else {
		if (xTarget.style.display == "block") xTarget.xOpened = 1;
		if (xTarget.xOpened && typeof(xTarget) == "object") {
			if (xTarget.xOpened == 1) {
				xTarget.style.display = "none";
				xTarget.xOpened = 0;
			} else {
				xTarget.style.display = "block";
				xTarget.xOpened = 1;
			}
			
		} else if (typeof(xTarget) == "object") {
			xTarget.style.display = "block";
			xTarget.xOpened = 1;
			if (xIcon) xIcon.oSrc = xIcon.src;
		}
	}
	
	if (xIcon && typeof(xTarget) == "object") {
		if (!xIcon.oSrc) xIcon.oSrc = xIcon.src;
		if (xTarget.xOpened == 1) {
			xSep = xIcon.oSrc.indexOf(".jpg");
			if (xSep < 0) xSep = xIcon.oSrc.indexOf(".gif");
			if (xSep > 0) {
				xIcon.src = xIcon.oSrc.substr(0,xSep) + "_a" + xIcon.oSrc.substr(xSep,xIcon.oSrc.length);
			}
		} else {
			xIcon.src = xIcon.oSrc;
		}
	}
}