/*============== SCRIPT D'ENTETE COMMUN AU DIFFERENTS DOCUMENTS =======================*/


//------------------ fonction de désactivation du click droit de la souris --------

function disableRightClick(e)
{ 
  if(!document.rightClickDisabled) // initialize
  {
    if(document.layers) 
    {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = disableRightClick;
    }
    else document.oncontextmenu = disableRightClick;
    return document.rightClickDisabled = true;
  }
  if(document.layers || (document.getElementById && !document.all))
  {
    if (e.which==2||e.which==3)
      return false;
  }
  else
  {
    return false;
  }
}

//------------------ ouverture d'une PopUp Window ---------------------
// URLStr : url a ouvrir
// Left   : position horizontale en px du coin haut gauche
// top    : position verticale en px du coin haut gauche
// width  : largeur en px de la fenetre
// height : hauteur en px de la fenetre
// full   : ouverture de le fenetre en plein ecran IE
// resize : fenetre redimentionnable yes non
// popUpMin : identifiant de la fenetre
// RETOUR : identifiant de la fenetre
//------------------------------------------------------------------------

function popUpWindow(URLStr, left, top, width, height, full, popUpWin, resize, scrollbar)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  return(open(URLStr,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollbar+',resizable='+resize+',fullscreen='+full+',copyhistory=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top+''));
}

function popupCenter(URL, name, width, height)
{
  var posX = parseInt((screen.availWidth-10-width) / 2);
	var posY = parseInt((screen.availHeight-30-height) / 2);
	
	return window.open(URL, name, 'scrollbars=yes,width='+width+',height='+height+',left='+posX+',top='+posY+',screenX='+posX+',screenY='+posY+'');
}

var GL_param=0;
function ouvre_parametres(home_dir)
{
  GL_param = popupCenter(home_dir + "parametres.php", "GL_param", 500, 500);
}

var GL_info=0;

function ouvre_info(home_dir)
{
  GL_info = popupCenter(home_dir + "info.php", "GL_info", 480, 400);
}

//----------------- Ouverture de la fenetre de l'aide en ligne ------------
// tag: target de positionnement (ancre)
//--------------------------------------------------------------------------

var GLBaide=0;

function ouvre_aide(home_dir, tag)
{
  GLBaide=popUpWindow(home_dir + "aides/aide.php?TAG="+tag,70,70,800,550,'no',GLBaide,'yes','no');
}

//---------------------------------- CONTROLE DU CONTENU d'UN CHAMPS ----------------
// type: type de valeur 2) reel 1) entier val : valeur saisie mini : valeur minimum   maxi : valeur maximum
//-----------------------------------------------------------------------------------

function controle_valeur(type,obj,mini,maxi,ancval)
{
	switch(type) 
	{
	case 1:
  		if(isNaN(parseInt(obj.value)) || parseInt(obj.value)!=obj.value || obj.value<mini || obj.value>maxi) 
			{
			affiche_erreur("Vous devez saisir un nombre entier\r(Compris entre "+mini+" et "+maxi+")",0);
			if(ancval=='') ancval='0';
			obj.value=ancval;
			}
		break;
	case 2:
		if(isNaN(parseFloat(obj.value)) || parseFloat(obj.value)!=obj.value || obj.value<mini || obj.value>maxi) 
			{
			affiche_erreur("Vous devez saisir un montant\r(Compris entre "+mini+" et "+maxi+")",0); 
			if(ancval=='') ancval='0';
			obj.value=ancval;
			}
		break;
	}
	return true;	
}


//---------------------------AFFICHAGE D'UN MESSAGE D'ERREUR ----------------------
//  message: message d'erreur
// gravité: Warning 0 Erreur grave 1
//-----------------------------------------------------------------------------------

function affiche_erreur(message,gravite)
{
	alert("ERREUR:\r"+message);
	switch(gravite) {
		case 1:
			top.close();
			break;
		}
}


function setStatusBar(txt)
{
  if (window.top.fstatus != null && window.top.fstatus.document.message != null && window.top.fstatus.document.message.txt != null)
    window.top.fstatus.document.message.txt.value = txt;
}

function addToStatusBar(txt)
{
  if (window.top.fstatus != null && window.top.fstatus.document.message != null && window.top.fstatus.document.message.txt != null)
    window.top.fstatus.document.message.txt.value = window.top.fstatus.document.message.txt.value + txt;
}

function resetStatusBar()
{
  if (window.top.fstatus != null && window.top.fstatus.document.message != null && window.top.fstatus.document.message.txt != null)
    window.top.fstatus.document.message.txt.value = "";
}


function quitterAppli()
{
  if (confirm("Voulez-vous quitter l'application"))
    window.top.close();
}



