var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var NS6 = (document.getElementById && !document.all) ? true : false;

/*	Capture du mouvement souris			*/
var mouse_x = 0;
var mouse_y = 0;
var snapname='';
var snapmode=false;
var divVisible=false;

document.onmousemove = mouseMove
if (NS4) 
	document.captureEvents(Event.MOUSEMOVE)
/*	----------------------------------- */

function GetDocObject(whName)
{
	var whObject=eval("document."+whName);
	
	if(IE4)
			var whObject=eval("document.all."+whName);
	if(NS4)
			var whObject=eval("document."+whName);
	if(NS6 || IE5)
			var whObject=document.getElementById(whName);
	
	return(whObject);
}

function ShowDIV(whName,whValue)
//	whValue=true ou false
{
	var whObject=GetDocObject(whName);
	var contwidth=(NS4)?GetDocObject(snapname).clip.width:parseInt(GetDocObject(snapname).style.width);
	
	
	if(IE4 || IE5 || NS6)
			whObject.style.visibility = (whValue==true)?"visible":"hidden";
	if(NS4)
			whObject.visibility = (whValue==true)?"show":"hide";

	if(whName==snapname)
		{
	//	snapmode=whValue;
		divVisible=whValue;
		}

	MoveDIV(snapname,parseInt(mouse_x-contwidth),mouse_y+20);
}

function mouseMove(e)
{
	if (NS4 || NS6) 
	{
		mouse_x=e.pageX; 
		mouse_y=e.pageY;
	}
	if (IE4) 
		{
		mouse_x=event.x; 
		mouse_y=event.y;
		}
	if (IE5) 
		{

	 		mouse_x=event.x+ document.body.scrollLeft; 
			mouse_y=event.y+document.body.scrollTop;
		}
	
}

function SnapDIV(whName)
{
	snapname=whName;
}

function PopUpDIV(whTitre,whContenu,whVisible)
{
	var whHTML;

	if(snapname!='')
	{
		var contwidth=(NS4)?GetDocObject(snapname).clip.width:parseInt(GetDocObject(snapname).style.width);
		var contheight=(NS4)?GetDocObject(snapname).clip.height:parseInt(GetDocObject(snapname).style.height);

		whContenu+="<p align=\"center\"><a href=\"javascript:void(0);\" onclick=\"ShowDIV(snapname,false);\">Fermer</a></p>"

		if(NS4)
			{
			whHTML="<TABLE width="+contwidth+" border=0 cellpadding=0 cellspacing=0><tr><td bgcolor=#666666><TABLE width="+contwidth+" border=0 cellspacing=1 cellpadding=2>"
			if(whTitre)
				whHTML+="<TR><TD bgcolor=#B9B9FF valign=center><font size=1 face=Verdana, Arial, Helvetica, sans-serif>"+whTitre+"</FONT></TD></TR>"
			whHTML+="<TR><TD bgcolor=#E8E8FF><font size=1 face=Verdana, Arial, Helvetica, sans-serif>"+whContenu+"</FONT></TD></TR></TABLE></td></tr></table>"			
			}
		else
			{
			whHTML="<TABLE width="+contwidth+" border=0 cellpadding=0 cellspacing=0><tr><td class=bords><TABLE width="+contwidth+" border=0 cellspacing=1 cellpadding=2>"
			if(whTitre)
				whHTML+="<TR><TD class=Libel valign=center>"+whTitre+"</TD></TR>"
			whHTML+="<TR><TD class=cellule>"+whContenu+"</TD></TR></TABLE></td></tr>"
			}
		
		var whObject=GetDocObject(snapname);
		
		if(IE4 || IE5 || NS6)
			whObject.innerHTML=whHTML;
		if(NS4)
		{
			whObject=whObject.document;
			whObject.write(whHTML);
			whObject.close();
		}
				
		ShowDIV(snapname,whVisible);

	}
}

function GetWindowWidth()
{
	if(NS4 || NS6)
		{
		return(parseInt(window.innerWidth));
		}
	if(IE4 || IE5)
		{
		return(parseInt(document.body.clientWidth));
		}
}

function GetWindowHeight()
{
	if(NS4 || NS6)
		{
		return(parseInt(window.innerHeight));
		}
	if(IE4 || IE5)
		{
		return(parseInt(document.body.clientHeight));
		}
}

function MoveDIV(whName,x,y)
{
	var whObject=GetDocObject(whName);

	if(!NS4)
		whObject=whObject.style;

	if(x!='') whObject.left=x;
	if(y!='') whObject.top=y;
	
}

function CheckNavigatorCss()
{
	if(!IE4 && !NS6 && !IE5)
		return false;
	else
		return true;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
		
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
  	if (v=='show')
		{
		hideElement("SELECT");
			if(NS4) 
				obj.left=1; 
		}
	else
		showElement("SELECT");
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function moins(txtQte,btn)
{
	var txtQuantite
	if (typeof(btn.form.btnMoins.length)=="undefined")
	{
		txtQuantite=txtQte
	}
	else
	{
		for (i=0;i<btn.form.btnMoins.length; i++)
		{
			if (btn==btn.form.btnMoins[i])
			{
				txtQuantite=txtQte[i]
			}
		}
	}
	var quantite
	quantite=parseInt(txtQuantite.value)
	if (isNaN(quantite)) quantite = 0
	if (quantite>0) quantite = quantite - 1
	txtQuantite.value=quantite
	return false;
}

function moinsIncrement(txtQte,btn,increment)
{
	var txtQuantite
	if (typeof(btn.form.btnMoins.length)=="undefined")
	{
		txtQuantite=txtQte
	}
	else
	{
		for (i=0;i<btn.form.btnMoins.length; i++)
		{
			if (btn==btn.form.btnMoins[i])
			{
				txtQuantite=txtQte[i]
			}
		}
	}
	
	var quantite
	quantite=parseInt(txtQuantite.value)
	if (quantite>0) quantite = quantite - increment
	txtQuantite.value=quantite
	return false;
}

function plus(txtQte,btn)
{
	var txtQuantite
	if (typeof(btn.form.btnPlus.length)=="undefined")
	{
		txtQuantite=txtQte
	}
	else
	{
		for (i=0;i<btn.form.btnPlus.length; i++)
		{
			if (btn==btn.form.btnPlus[i])
			{
				txtQuantite=txtQte[i]
			}
		}
	}
	var quantite
	quantite=parseInt(txtQuantite.value)
	if (isNaN(quantite)) quantite = 0
	quantite = quantite + 1
	txtQuantite.value=quantite
	return false;
}

function plusIncrement(txtQte,btn,increment)
{
	var txtQuantite
	if (typeof(btn.form.btnPlus.length)=="undefined")
	{
		txtQuantite=txtQte
	}
	else
	{
		for (i=0;i<btn.form.btnPlus.length; i++)
		{
			if (btn==btn.form.btnPlus[i])
			{
				txtQuantite=txtQte[i]
			}
		}
	}
	
	var quantite
	quantite=parseInt(txtQuantite.value)
	if (isNaN(quantite)) quantite = 0
	quantite = quantite + increment
	txtQuantite.value=quantite
	return false;
}

function hideElement(elmID)
{
	if (IE4 || IE5) {
		for (i = 0; i < document.all.tags(elmID).length; i++)
		{
			obj = document.all.tags(elmID)[i];
			obj.style.visibility = "hidden";
		}
	}
}

function showElement(elmID)
{
	if (IE4 || IE5) {
		for (i = 0; i < document.all.tags(elmID).length; i++)
		{
			obj = document.all.tags(elmID)[i];
			obj.style.visibility = "";
		} 
	}
}

function DisplayPopup(theURL,winName,features) { 
  var wnd;
  wnd=window.open(theURL,winName,features);
  wnd.focus();
}

function ShowWarning(theURL)
{
  var wnd;
  var a;
  
  a=confirm("Vous allez quitter Hospitalis et entrer sur le site d\'un partenaire.\nLes informations produits fournies par les sites partenaires sont de la responsabilité des fabricants.\n\nSouhaitez-vous continuer ?");
  
  if (a==true && theURL!='') {
	  wnd=window.open(theURL,'partenaire');
	  wnd.focus();
	  }
	  
  return(a);

}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function Aff_Plein_Ecran() { 
	if (parent!=self){
		top.location.href = self.location.href;
	}
}

// Affiche le message d'avertissement dans le domaine vie des produits
function displayBCBAlert() {
	alert('Vous quittez le site HOSPITALIS pour accéder à la base Médicaments (CIP-Claude Bernard) et à la base Dispositifs Médicaux (Fabricants). Le contenu et la mise à jour de ces bases sont de la responsabilité de leurs éditeurs.\nCes bases ne peuvent être entièrement à jour du fait des délais de réception et de mise en ligne des Résumés des Caractéristiques Produit. Pour vous assurer de la dernière mise à jour, contacter le laboratoire ou fabricant exploitant du produit.');
}

/* fonction d(ouverture de popup */
var w;
function Ouvrir(page,nom,option,largeur,hauteur) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	w = window.open(page,nom,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+option);
 
}

/* fonction pour fermer un popup ouvert depuis cette page */
function Fermer() {
   if (w.document) { w.close(); }
}


//remplace les occurences de a par b dans expr
function remplace(expr,a,b) {
	  var i=0
	  while (i!=-1) {
		 i=expr.indexOf(a,i);
		 if (i>=0) {
			expr=expr.substring(0,i)+b+expr.substring(i+a.length);
			i+=b.length;
		 }
	  }
	  return expr
}


// Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
// Le séparateur est défini dans la variable separateur
function checkDate(d) {

	  if (remplace(d," ","").length == 0)
	  	return true;
		
      var amin=1900; // année mini
      var amax=2100; // année maxi
      var separateur="/"; // separateur entre jour/mois/annee
      var j=(d.substring(0,2));
      var m=(d.substring(3,5));
      var a=(d.substring(6));
      var ok=true;
	
	  if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) {
         alert("Veuillez saisir une date au format 'jj/mm/aaaa'\n(exemple : 01/01/2005)"); 
		 ok=false;
      }
	  
      if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
         alert("Veuillez saisir un jour valide"); ok=false;
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
         alert("Veuillez saisir un mois valide"); ok=false;
      }
      if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) ) {
         alert("Veuillez saisir une année valide"); ok=false;
      }
     
      return ok;
   }
   
  

/********************************************************************************************/
/* @FONCTION: checkHour																		*/							
/* @AUTEUR: DHOLT																			*/
/* @DESCRIPTION: Cette fonction vérifie le format hh:mm:ss saisi et la validité de l'heure.	*/
/*  Le séparateur est défini dans la variable separateur									*/
/********************************************************************************************/

function checkHour(d) {

      // si param r tester vide on considcre que c'est OK
	  if (remplace(d," ","").length == 0)
	  	return true;
		
      var H_MIN=0; // heure mini
      var H_MAX=24; // heure maxi
	  var MAX_DURATION = 59; //nb max de minutes et de secondes
      var separateur=":"; // separateur entre heure/minutes/secondes
      var h=(d.substring(0,2));
      var m=(d.substring(3,5));
      var s=(d.substring(6));
      var ok=true;
	
	  if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) ) {
         alert("Vous devez spécifier une heure qui soit valide (hh:mm:ss)"); 
		 ok=false;
      }
	  
      if ( ((isNaN(h))||(h< H_MIN)||(h> H_MAX)) && (ok==1) ) {
         alert("L'heure saisie n'est pas correcte"); ok=false;
      }
      if ( ((isNaN(m))||(m<0)||(m>MAX_DURATION)) && (ok==1) ) {
         alert("Les minutes saisies sont incorrectes"); ok=false;
      }
      if ( ((isNaN(s))||(s<0)||(s>MAX_DURATION)) && (ok==1) ) {
         alert("Les secondes saisies sont incorrectes"); ok=false;
      }
     
      return ok;
}
   
/********************************************************************************************/
/* @FONCTION: identification																*/							
/* @AUTEUR: VHELLIN																			*/
/* @DESCRIPTION: Cette fonction regarde sur quel site on se trouve pour ensuite faire la 	*/
/*  redirection en HTTPS ou HTTP															*/
/* Prérequis : la page doit contenir un formulaire appelé "Identification"					*/
/********************************************************************************************/
function identification() {
	if(document.location.toString().indexOf('www.hospitalis.org')!=-1) {
		document.Identification.action = "https://www.hospitalis.org/Cedhys.ASP?WCI=Identification&WCE=Valider&WCU";
	} else {
		document.Identification.action = "Cedhys.ASP?WCI=Identification&WCE=Valider&WCU";
	}
	document.Identification.submit();
	return true;
}
