

function ShowHide( pObject )
{
	if( pObject.style.display == "none")
	{
		pObject.style.display = "";
	} else 
	{
		pObject.style.display = "none";
	}
} 


function GetIfCSSExist( pClassName )
{
	if( !document.styleSheets )	{return false; }
	var lAllClass = '';
	
	for( var lCssIndex = 0; lCssIndex < document.styleSheets.length; lCssIndex++ )
	{
		var lStyleSheet = document.styleSheets[ lCssIndex ];								
		var lRuleTotalCount = 0;
		if( lStyleSheet.cssRules )	{ lRuleTotalCount = lStyleSheet.cssRules.length; } 
		else						{ lRuleTotalCount = lStyleSheet.rules.length; }

		for( var lRuleIndex=0; lRuleIndex < lRuleTotalCount; lRuleIndex++ )
		{
			var lCSSRule	= false; 
			if( lStyleSheet.cssRules )	{ lCSSRule = lStyleSheet.cssRules[lRuleIndex]; } 
			else						{ lCSSRule = lStyleSheet.rules[lRuleIndex]; }
			if( lCSSRule )
			{
			lAllClass+= lCSSRule.selectorText+' | ';
				if( lCSSRule.selectorText.indexOf( pClassName ) >= 0 )
				{
					return true;
				}
			}
		}// scan all Rule
	}// scan all css
	return false;
}// GetIfCLassExist

function FinAndUnderlineCurrentLink()
{
	var lLinkArray = document.getElementsByTagName("a");

	var lDocumentUrl = document.location.href;

	var lHaveExtension = false;	
	var lExtensionIndex = 0;

	lExtensionIndex = ( lDocumentUrl.indexOf( ".php" ) > 0 ) || (lDocumentUrl.indexOf( ".html" )>0) || (lDocumentUrl.indexOf( ".htm" ) > 0 );

	if( lExtensionIndex <= 0 )
	{
		if( lDocumentUrl.indexOf( ".htm" ) <= 0 )
		{
			if( lDocumentUrl.indexOf( ".html" ) <= 0 )
			{
				lDocumentUrl += 'index.php';			/* la page par default */
			}
		}
	}
	else
	{
		lHaveExtension = true;
	}	


	var lDocumentUrlWithoutExtension = lDocumentUrl;

	if( lHaveExtension )
	{
		lDocumentUrlWithoutExtension = lDocumentUrl.substring( 0, lDocumentUrl.indexOf( ".php" ) );
		lDocumentUrlWithoutExtension = lDocumentUrlWithoutExtension.substring( 0, lDocumentUrlWithoutExtension.indexOf( ".html" ) );
		lDocumentUrlWithoutExtension = lDocumentUrlWithoutExtension.substring( 0, lDocumentUrlWithoutExtension.indexOf( ".htm" ) );
	}

	var lIsAParentLink = false;var lHaveAGoodLink = false;

	for( var lIndex = 0; lIndex < lLinkArray.length; lIndex++ )
	{
		var lLinkUrl = lLinkArray[ lIndex ].href;
		
		if( lLinkUrl )
		{
			lIsAParentLink = false;
			lHaveAGoodLink = ( lDocumentUrl == lLinkUrl);
			

			if( !lHaveAGoodLink && (!( lLinkUrl.indexOf('?') >=0 ))  ) 
			{
				if( lDocumentUrl.indexOf( lLinkUrl ) >= 0 )
				{
					lHaveAGoodLink = true;
				}
				else
				{
					if( lLinkUrl.indexOf( lDocumentUrl ) >= 0 )
					{
						lHaveAGoodLink = true;
					}
					else
					{
						lLinkUrlWithout = lLinkUrl.substring( 0, lLinkUrl.lastIndexOf( '.' ) );
						if( lDocumentUrl.indexOf( lLinkUrlWithout ) >= 0 )
						{
							lHaveAGoodLink = true;
							lIsAParentLink = true;
						}
						else
						{
							var lLangPos = lLinkUrlWithout.lastIndexOf('_');
							if( lLangPos > 0 )
							{
								if( (lLinkUrlWithout.length - lLangPos ) <= 3 )
								{
									if( lDocumentUrl.indexOf( lLinkUrlWithout.substring( 0, lLangPos ) ) >= 0 )
									{
										lHaveAGoodLink = true;
										lIsAParentLink = true;
									}
								}
							}
						}


					}
				}
			}
			
			if( lHaveAGoodLink)
			{
				//window.alert(  lLinkArray[ lIndex ] +' | '+ lDocumentUrl);
				
				if( (lLinkArray[ lIndex ].id.indexOf("DontUnderline") < 0) && (lLinkArray[ lIndex ].className.indexOf("NoActive") < 0) ) 
				{
					if( lLinkArray[ lIndex ].className.indexOf("Active") < 0 ) 
					{
						var lHaveActiveClassVersion = false;

						if( lLinkArray[ lIndex ].className.length > 0 )
						{// have a classname
								var lActiveClassName = lLinkArray[ lIndex ].className + 'Active';
								
								if( lIsAParentLink )
								{
									var lParentClassName = lLinkArray[ lIndex ].className + 'ActiveParent';
									if( GetIfCSSExist( lParentClassName ) )
									{
										lLinkArray[ lIndex ].className += ' ' + lParentClassName;
										lHaveActiveClassVersion = true;
										//window.alert( lParentClassName);
									}
									else
									{
										lIsAParentLink = false;
									}
								}
								
								if( !lIsAParentLink )
								{
									if( GetIfCSSExist( lActiveClassName ) )
									{
										lLinkArray[ lIndex ].className += ' ' + lActiveClassName;
										lHaveActiveClassVersion = true;
										//window.alert( 'lActiveClassName');
									}
								}
								
						}// link have a className



						//lLinkArray[ lIndex ].className = lLinkArray[ lIndex ].className + 'Active';

						if( !lHaveActiveClassVersion )
						{
							//lLinkArray[ lIndex ].style.textDecoration='underline';
							if( lIsAParentLink )
							{
								//window.alert( 'ActiveParent' + lLinkUrl+' - '+ lDocumentUrl);
								lLinkArray[ lIndex ].className += ' UnderlineLink ActiveParent';
							}
							else
							{
								//window.alert( 'Active:'+ lLinkUrl +' - '+ lDocumentUrl);
								lLinkArray[ lIndex ].className += ' UnderlineLink Active';
							}
						}// underline by default
					}
				}// Dont underline
			}// Have a good link
		}
	}
}


function AppendHtml( pElement )
{
	if (document.body.appendChild)
	{
	  document.body.appendChild( pElement );
	} else if( document.documentElement.appendChild )
	{
	  document.documentElement.appendChild( pElement );
	} else if( document.appendChild ) 
	{
	  document.appendChild( pElement );
	}
}


function ShowWaitingFileUpload( pObject )
{
	modular_waiting( pObject, true,'<div class="WaitingText">Merci de patienter<br>pendant le transfert de votre document.</div>'
		+'<img src="imagespfdp/wait2.gif" width="220" height="19" class="WaitingImage"> ' );

		
}


function modular_waiting( pObject, vis, msg, options) {
// Pass true to show the dialogue screen, false to hide
// options are optional.  This is a JSON object with the following (optional) properties
// opacity:0-100         // Lower number implies a more transparent dialog box
// zindex: #             // HTML elements with a higher zindex appear on top of others with a lower number
// height: 0-100         // The height in percentage terms relative to the browser screen
// width:  0-100         // The width in percentage terms relative to the browser screen
// name: text         // A name for your dialog box - this is what you will refer to when showing and hiding the dialog
// align: text         // Should the text be placed in the: center, justify, left or right
// fontcolor: (#xxxxxx)  // Standard RGB Hex color code
// fontweight: 100-900   // The boldness of the text in increments of 100. 900 implies maximum boldness
// bgcolor: (#xxxxxx)    // Standard RGB Hex color code
// borderwidth: #     // The thickness of the border
// bordercolor: (#xxxxxx)// The color of the border in HEX
// borderstyle: text     // The style of the border. One of dashed, dotted, double, groove, inset, none, outset, ridge, solid
// modular_waiting(false); // hide the dialog
// modular_waiting(true, 'my message to show here', {'name':'myName', 'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'}); // show the dialog
// Because options is JSON opacity/zindex/bgcolor are all optional and can appear
// in any order.  Pass only the properties you need to set.
var options   = options || {};
var zindex   = options.zindex || 100;
var height   = options.height || 25;
var width   = options.width || 35;
var opacity   = options.opacity || 90;
var opaque   = (opacity / 100);
var bgcolor   = options.bgcolor || '#FFDC75';
var fColor   = options.fontcolor || '#0000FF';
var fWeight  = options.fontweight || 600;
var bcolor   = options.bordercolor || 'black';
var bstyle  = options.borderstyle || 'solid'
var bwidth  = options.borderweight || '3px'
var align   = options.align || 'center';
var __div_id__ = options.name ||  '__modular__popup__';

var dark=document.getElementById(__div_id__ );

if (!dark) {
	
	var tnode = document.createElement('div');       // Create the layer.
	tnode.style.position='fixed';                 // Position absolutely
	tnode.style.overflow='auto';
	tnode.style.display='none';                      // Start out Hidden
	tnode.id=__div_id__ ;                    // Name it so we can find it later

	this.mDocumentObject = document.createElement( 'div' ); 
	this.mDocumentObject.setAttribute( 'id', 'ClassWindow' );
	tnode.className	= 'WaitingDiv';

	AppendHtml( tnode );

	dark=document.getElementById(__div_id__ );       // Get the object.
}

if (vis) {

//var txt = document.createElement('font')

//txt.className	= 'WaitingText';
//txt.innerHTML = msg;//.replace(/\"/g,""").replace(/\'/g,"'").replace(/\/g,">").replace(/\n/g,"<br/>")

dark.setAttribute('align',align);
dark.style.display='block';
//dark.style.left =  '50%'
//dark.style.top  =  '50%'

//dark.appendChild(txt);

	dark.innerHTML = msg;

} else {
// TODO - should i remove the element?
dark.style.display='none';
dark.innerHTML = "";
}

}



var gOnLoadArray = new Array();

function AddOnLoadFunction( pFunction )
{
	gOnLoadArray.push( pFunction );
}


function OnLoadLocalEvent()
{
	if( eval( 'window.BackupScroll' ) )
	{
		BackupScroll();
	}

	FinAndUnderlineCurrentLink();

	for( var lIndex = 0; lIndex < gOnLoadArray.length; lIndex++ )
	{
		(gOnLoadArray[ lIndex ])();
	}

}


//_____________________________________________________________________________
window.onload	= OnLoadLocalEvent;
//_____________________________________________________________________________

