/* ********* General Functionnalities **************/
/* ***************** Global ************************/

function alphaRender(sender,alpha)
{

    if (sender.filters)
      sender.filters.alpha.opacity=alpha*100
    else
      sender.style.MozOpacity=alpha
}

function askAdd (sender, urlAdd)
{
	window.location = urlAdd;
}

function askSupp (sender, urlSupp, suppMsg)
{
	if ( typeof(suppMsg) == 'undefined' )
	{
		suppMsg = "Do you want to suppress selected information ?";
	}
	if ( confirm (suppMsg) )
	{
		window.location = urlSupp;
	}
	
}

function PopulateHiddenField (sender, field,val)
{
	//var obj = sender.document.getElementById (field) ;
	var obj = document.getElementById (field) ;
	if ( obj == null ) { return ; }
	obj.value = val;

}

function PopulateHiddenFieldandSubmit (sender,formId, field,val)
{
  
	//var obj = sender.document.getElementById (field) ;
	var obj = document.getElementById (field) ;
	if ( obj == null ) { return ; }
	obj.value = val;
  SubmitForm(this,formId,false);
}

function SubmitForm (sender, formId, action, askConfirm)
{
	if ( typeof(action) != 'undefined' )
	{
		//var objAction = sender.document.getElementById ('action') ;
		var objAction = document.getElementById ('action') ;
		if ( objAction != null )
		{
			objAction.value = action ;
		}
	}
	if ( typeof(askConfirm) == 'undefined' )
		askConfirm = false;
	
	var valid = true ;
	if ( askConfirm )
		valid = confirm ('Do you confirm your action ?') ;
	
	if ( valid )
	{
		if ( typeof(formId) == 'undefined' )
		{
			sender.document.forms[0].submit () ;
		}
		else
		{
			//var objForm = sender.document.getElementById (formId) ;
			var objForm = document.getElementById (formId) ;
			objForm.submit() ;
		}
	}
}

function DisplayMenu (sender, mnuId)
{
	//alert('DisplayMenu in commun.js');
	//var objMnu = sender.document.getElementById (mnuId) ;
	var objMnu = document.getElementById (mnuId) ;
	if ( objMnu == null ) { return ; }
	
	objMnu.style.display = (objMnu.style.display == 'none')?'':'none' ;
}
/* ************************************************ */

/* *************** IFrame Functionnalities ******** */
/* ***************** Global *********************** */

/* ***************** Functions ******************** */
function CallUrlInFrame (sender, FrameId, url)
{
  var objFrame   = document.getElementById ( FrameId ) ;
	//var objFrame   = sender.document.getElementById ( FrameId ) ;
	if ( objFrame == null )
		return ;
	objFrame.src = url ;

}
/* ************************************************ */

// Etiquettes

var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 20;
offsetY = 0;
tipW = 300;

var toolTipSTYLE="";

function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function toolTip(msg, fg, bg,tipWi)
{
  if(toolTip.arguments.length < 1) // hide
  {
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
// ou couleurs définies en paramètres, sinon par défaut
	if(!fg) fg = "#000000";
   	if(!bg) bg = "#C8D0DB";
	if(!tipWi) tipWi = tipW;
	
    var content =
	'<?PHP include("sipia/fonctions.php"); ?>'+
	'<table width="' + tipWi +'" border="1" cellspacing="0" cellpadding="0" bgcolor="' + fg + '"><td>' +
    '<table width="100%" border="0" cellspacing="0" cellpadding="10" bgcolor="' + bg + 
    '"><td class="CIA_NS" align="left"><font color="' + fg + 
    '">' + msg + '</font></td></table></td></table>';
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
  }
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
	var x = event.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft);
	var y = event.clientY + (document.body.scrollTop || document.documentElement.scrollTop);
  }
// selon la place restante à l'écran, l'étiquette se positionne à gauche ou à droite du lien
  if((x + tipW) <= document.body.clientWidth)
  {
	toolTipSTYLE.left = x + offsetX;
  }
  else
  {
	toolTipSTYLE.left = x - (tipW + offsetX);
  }
  toolTipSTYLE.top = y + offsetY;
  return true;
}

