/*

	Résumé de l'API :
	
	//////////////////// Recuperations / tests ////////////////////
	initNavigatorVersion()
	getDiv ( strDivName, wantStyle )
	setDivStyle( objDiv, strPropriete, strValue)
	isValideDiv(obj)
	
	//////////////////// Ecriture / Lecture ////////////////////
	addToDiv ( div, chaine )
	writeToDiv ( div, chaine )
	readFromDiv ( div )
	
	
	
	//////////////////// Proprietes ////////////////////
	getClipValue ( obj, which )		(which = "left" || "top" || "bottom" || "right")
	clipTo ( obj, t, r, b, l )
	clipBy ( obj, t, r, b, l )
	
	resizeDivTo ( obj, width, height )
	resizeDivBy ( obj, decallageX, decallageY )
	
	moveDivTo ( obj, x, y )
	moveDivBy ( obj, x, y )
	
	getDivWidth ( obj )
	getDivHeight ( obj )
	
	getDivAbsoluteWidth ( obj )
	getDivAbsoluteHeight ( obj )
	
	getDivPosition( obj )
	setDisplayDiv( obj, name )
	
	setDivWidth(obj, newWidth)
	setDivHeight ( obj, newHeight )
	
	getDivPosX ( obj )
	getDivPosY ( obj )
	
	setDivPosX ( obj, newX )
	setDivPosY ( obj, newY )
	
	getDivZIndex ( objDiv )
	setDivZIndex ( objDiv, value )
	setDivColor ( objDiv, color )	

	isPointInDiv ( objDiv, posX, posY );
	showDiv ( objDiv );
	hideDiv ( objDiv );

	setDivAlpha( oDiv, percent );
	
*/



function gfxPadding( x, y, xx, yy )
{
	this.left	= x;
	this.top	= y;
	this.right	= xx;
	this.bottom	= yy;
}



// +--[ getDiv() ]---------------------------------------------------------------------------------------
// |
// | Permet de recuper un pointeur vers le layer (et/ou une de ses propriétées)
// | 
// |
// +-----------------------------------------------------------------------------------------------------


function getDiv ( strDivName, wantStyle )
{
	var returnObjDiv = null;
	
	switch (AppBrowser) 
	{
		case "ns4":
		
			returnObjDiv = eval("document.layers['" + strDivName + "']");
			break;
			
		case "ns6": 	
		
			if (wantStyle) 
			{
				returnObjDiv = eval("document.getElementById('" + strDivName + "').style");
			} 
			else 
			{
				returnObjDiv = eval("document.getElementById('" + strDivName + "')");
			}
			break; 			
			
		case "ie4": 
		
			if (wantStyle) 
			{	
				returnObjDiv = eval("document.all['" + strDivName + "'].style");
			}
			else
			{
				returnObjDiv = eval("document.all['" + strDivName + "']");
			}
			break; 			
			
		default: 
		
			if (wantStyle) 
			{	
				returnObjDiv = eval("document.getElementById('" + strDivName + "').style");
			} 
			else 
			{
				returnObjDiv = eval("document.getElementById('" + strDivName + "')");
			}
			break; 
	} 
	
	return returnObjDiv;
	
} // Fin de getDiv()


function setDivStyle( objDiv, strPropriete, strValue)
{
	var tempEval = ""

	var monDivTemp = objDiv;
	
	if ( !monDivTemp ) return;
	
	if ( ns4 )
	{
		eval("monDivTemp." + strPropriete + " = \"" + strValue + "\"");
		
	}
	else
	{
		eval("monDivTemp.style." + strPropriete + " = \"" + strValue + "\"");
	}

}



// Fonction qui ajoute du texte à un DIV
function addToDiv ( div, chaine )
{
	var oldContenu = "";
	
	if ( ! isValideDiv ( div ) )
	{
		return;
	}

	// On lit l'ancien contenu
	oldContenu = readFromDiv ( div );
	
	// On ecrit son nouveau contenu
	writeToDiv ( div, oldContenu + chaine );
	
}

// Fonction qui écrit du texte dans un DIV
function writeToDiv ( div, chaine )
{
	if ( ns4 )
	{
		div.document.open();
		div.document.writeln(chaine);
		div.document.close();
	}
	else
	{
		div.innerHTML = chaine;		// Semble fonctionner sur NS6 et + !!!
	}
}



// Fonction qui lit le contenu (HTML) d'un DIV
function readFromDiv ( div )
{
	var strReadFromDiv = "";		// Contenu brut du Div
	var strContenuReel = "";		// Contenu sans les balises div (<div>CONTENU</div>)

	// On lit le contenu du Div
	if (ie4)
	{
		strReadFromDiv = div.outerHTML;
		// Si jamais le Div est vide...
		if ( strReadFromDiv.indexOf ( ">" ) == strReadFromDiv.lastIndexOf ( "<" ) - 1 )
		{
			strContenuReel = ""
		}
		else
		{
			strContenuReel = strReadFromDiv.substring ( strReadFromDiv.indexOf ( ">" ) + 1, strReadFromDiv.lastIndexOf ( "<" ) );
		}
	}
	else if ( ismozilla )
	{
		strContenuReel = DOM_outerHTML( div );
		// on retire le <div></div> autour du contenu renvoyé par DOM_outerHTML
		var pos1 = strContenuReel.indexOf( ">" );
		var pos2 = strContenuReel.lastIndexOf( "<" );
		strContenuReel = strContenuReel.substring( pos1 + 1, pos2 )
	}
	else
	{
	// 		A VOIR POUR NS !!!
		strContenuReel = ""
	}
	
	return strContenuReel;
}


// Fonction qui renvoie true si l'objet est bien un div

function isValideDiv(obj)
{
	if( ! obj )
	{
		return false;
	}

	if( ns4 && !obj.document )
	{
		return false;
	}
	
	return true;
}


function getClipping ( obj)
{
	if ( ie4 )
	{
		return obj.style.clip;
	}
	else
	{
		return obj.style.clip;
	}
}

// Recupere les valeurs du clip (obj = div, which = "left" || "top" || "bottom" || "right")
function getClipValue ( obj, which )
{
	var chaine = "";
	var returnValue = 0;
	
	if ( ns4 )
	{
		if (which=="top")
		{
			returnValue = obj.style.clip.top;
		}
		if (which=="right")
		{
			returnValue = obj.style.clip.right;
		}
		if (which=="bottom")
		{
			returnValue = obj.style.clip.bottom;
		}
		if (which=="left")
		{
			returnValue = obj.style.clip.left;
		}
	}
	else
	{
		chaine = obj.style.clip;
		chaine = internalReplace( chaine, ",", "" );
		chaine = chaine.split("rect(");
		
		if( chaine.length < 2 )
		{
			switch( which )
			{
				case "top" :	
				case "left" :
					return 0;
					
				case "right" : return getDivAbsoluteWidth( obj );
				case "bottom" : return getDivAbsoluteHeight( obj );
			}
		}
		
		chaine = chaine[1].split(")");
		chaine = chaine[0].split("px");

		if (which == "top")
		{
			returnValue = internalParseInt(chaine[0].replace( " ", "" ));
		}
		if (which == "right")
		{
			returnValue = internalParseInt(chaine[1].replace( " ", "" ));
		}
		if (which == "bottom")
		{
			returnValue = internalParseInt(chaine[2].replace( " ", "" ));
		}	
		if (which == "left")
		{
			returnValue = internalParseInt(chaine[3].replace( " ", "" ));
		}
	}

	return returnValue;
}


function clipTo ( obj, t, r, b, l ) 
{
	if ( t < 0 )	t = getClipValue ( obj, "top" );
	if ( r < 0 )	r = getClipValue ( obj, "right" );
	if ( r < 0 )	b = getClipValue ( obj, "bottom" );
	if ( l < 0 )	l = getClipValue ( obj, "left" );

	if ( ns4 )
	{
		obj.clip.top = t;
		obj.clip.right = r;
		obj.clip.bottom = b;
		obj.clip.left = l;
	}
	else
	{
		obj.style.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
	}
/*
	else 
	{	
		obj.style.clip.top = t;
		obj.style.clip.right = r;
		obj.style.clip.bottom = b;
		obj.style.clip.left = l;
	}
*/	
}



function clipBy ( obj, t, r, b, l ) {

	var initTop		= getClipValue ( obj, "top" );
	var initRight	= getClipValue ( obj, "right" );
	var initBottom	= getClipValue ( obj, "bottom" );
	var initLeft	= getClipValue ( obj, "left" );
	var chaineClip	= "";
		
	if ( ns4 )
	{
		obj.clip.top = initTop + t;
		obj.clip.right = initRight + r;
		obj.clip.bottom = initBottom + b;
		obj.clip.left = initLeft + l;
	}
	else
	{
		obj.style.clip = "rect("+ (initTop+t) +"px " + (initRight+r) + "px " + (initBottom+b) + "px " + (initLeft+l) + "px)";
	}
}



function resizeDivTo ( obj, width, height )
{
	setDivWidth ( obj, width );
	setDivHeight ( obj, height );
}


function resizeDivBy ( obj, decallageX, decallageY )
{
	var newWidth = 0, newHeight = 0;

	newWidth = ( getDivWidth ( obj ) + decallageX );
	newHeight = ( getDivHeight ( obj ) + decallageY );
		
	if ( newWidth < 0 )
	{
		newWidth = 0;
	}
	if ( newHeight < 0 )
	{
		newHeight = 0;
	}
		
	setDivWidth ( obj, newWidth );
	setDivHeight ( obj, newHeight );

	return;
}


function moveDivTo ( obj, x, y )
{
	setDivPosX ( obj, x );
	setDivPosY ( obj, y );
}


function moveDivBy ( obj, x, y )
{
	setDivPosX ( obj, getDivPosX( obj ) + x );
	setDivPosY ( obj, getDivPosY( obj ) + y );
}



function getDivWidth ( obj )
{
	var returnValue = 0;

	if ( ! ns4 )
	{
		returnValue = obj.style.width;
	}	
	
	return internalParseInt ( returnValue );
}


function getDivHeight(obj)
{
	var returnValue = 0;

	if ( ! ns4 )
	{
		returnValue = obj.style.height;
	}	
	
	return internalParseInt ( returnValue );
}


function setDivWidth ( obj, newWidth )
{
	if ( ! ns4 && newWidth > 0 )
	{
		obj.style.width = newWidth + "px";
	}
}

function setDivHeight ( obj, newHeight )
{
	if ( ! ns4 && newHeight > 0 )
	{
		obj.style.height = newHeight + "px";
	}
}

function getDivPosX ( obj )
{
	var returnValue = 0;

	if ( ! ns4 )
	{
		returnValue = obj.style.left;
	}	
	
	return internalParseInt ( returnValue );
}

function getDivPosY ( obj )
{
	var returnValue = 0;

	if ( ! ns4 )
	{
		returnValue = obj.style.top;
	}	
	
	return internalParseInt ( returnValue );
}

function setDivPosX ( obj, newX )
{
	if ( ! obj ) return;
	if ( ! ns4 )
	{
		obj.style.left = newX + "px";
	}
}


function setDivPosY ( obj, newY )
{
	if ( ! obj ) return;
	if ( ns4 )
	{
		obj.top = newY;
	}
	else
	{
		obj.style.top = newY + "px";
	}

}


// Fonction qui elargie/retrecie un layer de sa pos/taille actuelle à la pos (x,y), et à la taille (w, h)
/*
function divEnlargeAnim(objDiv, x, y, w, h, timeout)
{
	var strFuncToCall = "";
	var continueAnim = false;

	if(continueAnim)
	{
		setTimeout(divEnlargeAnim(objDiv, x, y, w, h, timeout), timeout)
	}
}*/

function getDivZIndex ( objDiv )
{
	var returnValue = 0;

	if ( ! ns4 )
	{
		returnValue = objDiv.style.zIndex;
	}
	
	return returnValue;
}


function setDivZIndex ( objDiv, value )
{
	if ( ! ns4 )
	{
		objDiv.style.zIndex = value;
	}
}



function setDivColor ( objDiv, color )
{
	if ( ! ns4 )
	{
		objDiv.style.backgroundColor = color;
	}
}


function getDivPosition( obj )
{
	if ( ie4 )
	{
		return obj.currentStyle.position;
	}
	else
	{
		return obj.style.position;
	}
}


// IMPORTANT : obj ne doit pas etre un style, mais directement l'objet Div !!!
// note : renvoie la véritable width, non pas celle fixée par notre programme et que le navigateur ne prend pas tjrs en compte
function getDivAbsoluteWidth ( obj )
{
	var returnValue = 0;

	if ( ns4 ) 
	{
		returnValue = obj.document.width;
	}
	else if ( ns6 )
	{
		returnValue = obj.offsetWidth;
	}
	else if ( ! ns4 )
	{
		returnValue = obj.offsetWidth;
	}	
	
	return internalParseInt ( returnValue );
	return 0;	// Evite Warning du nouveau compilateur Mozilla...
}


// IMPORTANT : obj ne doit pas etre un style, mais directement l'objet Div !!!
// note : renvoie la véritable height, non pas celle fixée par notre programme et que le navigateur ne prend pas tjrs en compte
function getDivAbsoluteHeight ( obj )
{
	var returnValue = 0;

	if ( ns4 ) 
	{
		returnValue = obj.document.height;
	}
	else if ( ns6 )
	{
		returnValue = obj.offsetHeight - 2;							// Offset de decallage specifié pour retomber sur un comportement IE 4 +
	}
	else if ( ! ns4 )
	{
		returnValue = obj.offsetHeight;
	}	
	
	return internalParseInt ( returnValue );
}


function isPointInDiv ( objDiv, posX, posY )
{
	if ( !objDiv ) return false;
	
	var x = getDivPosX ( objDiv );
	var y = getDivPosY ( objDiv );

	var w = getDivAbsoluteWidth( objDiv );
	var h = getDivAbsoluteHeight( objDiv );

	if ( posX >= x && posX <= x + w && posY >= y && posY <= y + h )
	{
		return true;
	}
	
	return false;
}


function setDisplayDiv( obj, p_name )
{
	obj.style.display = p_name;
}


function showDiv ( objDiv )
{
	setDivStyle( objDiv, "visibility", "visible" );
}

function hideDiv ( objDiv )
{
	setDivStyle( objDiv, "visibility", "hidden" );
}


function setDivAlpha( oDiv, percent )
{
	if ( ie4 )
	{
		if ( percent < 1 ) percent = percent * 100;
		setDivStyle( oDiv, "filter", "alpha(opacity=" + percent + ", style=0);" );
	}
	else
	{
		if ( percent > 1 ) percent = percent / 100;
		setDivStyle( oDiv, "mozOpacity", percent );
		setDivStyle( oDiv, "opacity", percent );
	}
}

function layerScroll( oDiv, scrollX, scrollY )
{
	layerScrollX( oDiv, scrollX )
	layerScrollY( oDiv, scrollY )
}

function layerScrollX( oDiv, scrollX )
{
	oDiv.scrollLeft = scrollX;
}
function layerScrollY( oDiv, scrollY )
{
	oDiv.scrollTop = scrollY;
}

function getNodePosX( oDiv )
{
	var curleft = 0;
	if ( oDiv.offsetParent )
	{
		while ( oDiv.offsetParent )
		{
			curleft += oDiv.offsetLeft;
			oDiv = oDiv.offsetParent;
		}
	}
	else if ( oDiv.x )
	{
		curleft += oDiv.x;
	}
	
	return curleft;
}


function getNodePosY( oDiv )
{
	var curtop = 0;

	if ( oDiv.offsetParent )
	{
		while (oDiv.offsetParent)
		{
			curtop += oDiv.offsetTop;
			oDiv = oDiv.offsetParent;
		}
	}
	else if ( oDiv.y )
	{
		curtop += oDiv.y;
	}
	
	return curtop;
}


function getNodeWidth( p_oNode )
{
	return p_oNode.offsetWidth;
}

function getNodeHeight( p_oNode )
{
	return p_oNode.offsetHeight;
}



function showNode( p_id )
{
	var oNode = document.getElementById( p_id )
	if (!oNode ) return 
	oNode.style.display = "block";
}

/* Pour les tr/td/table, un cas special s'offre à nous, chouette ... ;) */
function showTrNode( p_id )
{
	var oNode = document.getElementById( p_id )
	if (!oNode ) return 
	if ( ie4 )	oNode.style.display = "block";
	else oNode.style.display = "table-row";
}

function hideNode( p_id )
{
	var oNode = document.getElementById( p_id )
	if (!oNode ) return 
	oNode.style.display = "none";
}
initNavigatorVersion();


