var ie = (document.all)? true:false;
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var Drag = null;
var zEnCours = 0;

function alphaOk() {
 try {
  var ie =(window.navigator.appName.indexOf('Microsoft')!=-1);
  var version = parseFloat(window.navigator.appVersion);
  if (ie) {
   var idx = window.navigator.appVersion.indexOf('MSIE');
   var vers = window.navigator.appVersion.substr(idx+5, 3);
   version = parseFloat(vers);
  }
  
  return !(ie && version<7);
 } catch (e) {
  return false;
 } 
}


function checkCadre(num,level2) {
 var isCadre = (window.parent!=window);
 if (!isCadre) {
  if (level2)
   document.location = "../../principale.html?e="+num;
  else
   document.location = "../principale.html?e="+num;
 } 
}

function affiche(num) {
 var isCadre = (window.parent!=window);
 if (isCadre)
  window.parent.cacheAscenseur();
 else
  cacheAscenseur(); 
 
 var asce = false; 
 var page = 'blank.html';
 var titre = null;
 var liendirect = null;
 var haut = null;
 if (alphaOk())
  var ext = ".png";
 else
  var ext = ".gif"; 
 if (isCadre) {
  var prefC = "";
  var imt = window.parent.$('imgTitre');
  var lid = window.parent.$('lien_direct');
  var doc = window.parent.document;
 } else {
  var imt = $('imgTitre');
  var lid = $('lien_direct');
  var prefC = "pages/";
  var doc = document;
 }
 switch(num) {
  case 1 : page = 'qui.html';
           titre = 'titreQui'+ext;
           haut = 'Qui sommes nous?';
           asce = true; 
           liendirect = "http://info.accoss.com";
           break;
  case 2 : page = 'ou.html';
           titre = 'titreOu'+ext;
           haut = 'Nous contacter';
           liendirect = "http://contact.accoss.com";
           break;
  case 3 : page = 'quoi1.html';
           titre = 'titreQuoi1'+ext;
           haut = 'L\'Officine';
           liendirect = "http://officine.accoss.com";
           break;
  case 4 : page = 'quoi2.html';
           titre = 'titreQuoi2'+ext;
           haut = 'L\'Hôpital';
           liendirect = "http://hopital.accoss.com";
           break;
           
  case 5 : page = 'index.php'; //newsletter
           titre = 'titreNews'+ext;
           haut = 'Newsletter';
           if (!prefC)
            prefC = "../newsletters_db/";
           else
            prefC = "newsletters_db/";
           asce = true; 
           liendirect = "http://newsletter.accoss.com";
           break;   
  case 6 : page = 'prescrire.html';
           titre = 'titrePrescrire'+ext;
           haut = 'L\'Hôpital - Prescrire';
           liendirect = "http://prescrire.accoss.com";
           break;
  case 7 : page = 'fabriquer.html';
           titre = 'titreFabriquer'+ext;
           haut = 'L\'Hôpital - Fabriquer';
           asce = true; 
           liendirect = "http://fabriquer.accoss.com";
           break; 
  case 8 : page = 'administrer.html';
           titre = 'titreAdministrer'+ext;
           haut = 'L\'Hôpital - Administrer';
           liendirect = "http://administrer.accoss.com";
           break; 
  
  case 9 : page = 'pharmagora2009.html';
           titre = 'titrePharmagora2009'+ext;
           haut = 'PHARMAGORA 2009';
           liendirect = "http://pharmagora.accoss.com";
           break; 
  case 10: prefC = "demo/";
           page = 'demo.html';
           titre = 'titreQuoi2'+ext;
           haut = 'Serveur Démo';
           
           break;                 
                                                                     
 }
 ecours = num;
 if (isCadre)
  document.location = prefC+page; 
 else
  $('epage').src = prefC+page;
 
 if (asce) {
  if (isCadre)
   window.parent.afficheAscenseur();
  else
   afficheAscenseur(); 
 } 
  
  
 if (titre) {
  imt.src = 'images/'+titre;
  if (liendirect && lid)
   lid.href = liendirect;
  else
   lid.href = "";
  
  imt.show();
 } else {
  imt.hide();
  
 }
 
 
  
 if (haut) 
  doc.title = "ACCOSS : " + haut + " ------- ";
 else
  doc.title = "ACCOSS : Bienvenue sur @ccoss.com ------- "; 
}

function init() {
 $('imgTitre').hide();
 var URLparams = getURLParams();
 ecours = parseInt(URLparams['e']);
 if (ecours)
  affiche(ecours);
 deplaceBtnAccueil();
}

function initFrame() {
 var URLparams = getURLParams();
 var a = parseInt(URLparams['a']);
 if (a=1)
  afficheBadAscenseur();
}

function deplaceBtnAccueil() {
 $('btn_accueil').style.top = (getTopAbsolute($('epage'))+$('epage').offsetHeight+50)+"px"; 
 $('btn_accueil').style.left = (getRightAbsolute($('epage'))+155)+"px"; 
}

function setImgOpacity(obj) {
 var imgs = null;
 if (obj.tagName=='IMG')
  imgs = new Array(obj);
 else 
  imgs = obj.getElementsByTagName('IMG');
 if (imgs.length>0) {
  
  if (document.all) {
   if (obj == imgs[0]) {
    imgs[0].className='btn_opacityon';
   } 
   imgs[0].onmouseover = function (e) {
    this.className='btn_opacityon';
    
   }
   imgs[0].onmouseout = function (e) {
    this.className='';
   }
   
  } else {
   imgs[0].className='btn_opacity';
   obj.setAttribute("onmouseover","");
  }
 } 
 
  
}

function getURLParams(byindex) {
 urlvar = new Array();
 urlvarnum = new Array();
 if (window.location.search != "") {
  longueur = window.location.search.length - 1;
  data = window.location.search.substr(1,longueur);
  donnees = data.split("&");
  
  for (var i=0; i < donnees.length; i++) {
   position = donnees[i].indexOf("=");
   variable = donnees[i].substr(0,position);
   pos = position + 1;
   valeur = decodeURI(donnees[i].substr(pos,donnees[i].length));
   while (valeur.search(/\+/) != -1)
    valeur = valeur.replace(/\+/," ");
   urlvar[variable] = valeur;
   urlvarnum[i] = valeur;
  }
 }
 if (byindex)
  return urlvarnum;
 else
  return urlvar; 
} 

function loaded(){
 $('loaderImg').hide();
 $('page').show();
}


function getLeftAbsolute(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
	 if (el==document.body)
	  return tmp;
		tmp += el.offsetLeft;
		
		el = el.offsetParent;
	}
	return tmp;
}

function getRightAbsolute(el) {
	var tmp = el.offsetLeft;
	var w = el.offsetWidth;
	el = el.offsetParent
	while(el) {
	 if (el==document.body)
	  return tmp + w;
		tmp += el.offsetLeft;
		
		el = el.offsetParent;
	}
	return tmp + w;
}

function getTopAbsolute(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent
	while(el) {
	 if (el==document.body)
	  return tmp;
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}

function getParent(el) {
 if (el.parentNode) 
  return el.parentNode;
 else
  return el.parentElement; 
}

function getTarget(e) {
 if (window.event) e = window.event;
 return e.target ? e.target : e.srcElement;
}

function afficheAscenseur() {
 //if (alphaOk()) {
  if (!asc)
   asc = new Ascenseur($('epage'));
  asc.show(); 
 //} //else afficheBadAscenseur();
}

function afficheBadAscenseur() {
 if (!alphaOk()){
  if ($('epage'))
   var doc = $('epage').contentWindow.document; 
  else
   var doc = document; 
  //doc.write('<style type="text/css">');
  //doc.writeln('html { overflow:auto; }');
  //doc.write('body { overflow:visible; }');
  //doc.write('</style>');
  doc.body.style.overflow = "auto";
  
 } 
}

function cacheAscenseur() {
 if (asc) 
  asc.hide();
  
}


/*
//drag & drop
var ie=document.all;
var x,y;
var lift = null;
var dragapproved=false;
var nDrag = 0;

function move(e){
if (window.event) e = window.event;
var target = e.target ? e.target : e.srcElement;
if((e.button==1 || e.which==1)&&dragapproved)
	{
	if (lift) {
	 lift.style.left="0px";
	 
	 if (lift.offsetTop>=0 && lift.offsetTop<=(getParent(lift).offsetHeight-lift.offsetHeight))
	  lift.style.top=(temp2+e.clientY-y)+"px";
	} else { 
	 $("msg-box").style.left=(temp1+e.clientX-x)+"px";
	 $("msg-box").style.top=(temp2+e.clientY-y)+"px";
	} 
	return false
	}
}

function drags(e){
if (window.event) e = window.event;
var target = e.target ? e.target : e.srcElement;
evclass=target.className
//alert(evclass);
if(evclass=="win-header" || evclass=="win-tl" || evclass=="win-tc" || evclass=="win-tr" || evclass=="win-header-text" || evclass=="lift")
	{
	if (evclass=="lift")
	 lift = target;
	else
	 lift = null; 
	dragapproved=true;
	nDrag++;
	if (lift) {
	 lift.onmouseup = stopDrags;
	 temp1=0;
	 temp2=target.offsetTop;
	 x=e.clientX;
	 y=e.clientY;
	} else {
	 temp1=$("msg-box").offsetLeft;
	 temp2=$("msg-box").offsetTop;
	 x=e.clientX;
	 y=e.clientY;
	}
	
	document.onmousemove=move}
}

function stopDrags(e) {
  dragapproved=false;
  if (lift) {
   if (lift.offsetTop<0) lift.style.top = "0px";
   if (lift.offsetTop>(getParent(lift).offsetHeight-lift.offsetHeight)) lift.style.top = (getParent(lift).offsetHeight-lift.offsetHeight) + "px";
  }
   
  lift = null;
  nDrag--;
 }; 


document.onmousedown=drags;
document.onmouseup=stopDrags;

*/

// End Drag & Drop //

function createPlan(fichier,width,height,bgcolor) {
 if (window.parent == window)
  return new Plan(fichier,width,height,bgcolor);
 else
  return new window.parent.Plan(fichier,width,height,bgcolor); 
}

function Plan(fichier,width,height,bgcolor) {
 
 if (window.parent == window) {
  this.element = document.createElement('div');
  document.body.appendChild(this.element);
 } else {
  this.element = window.parent.document.createElement('div');
  window.parent.document.body.appendChild(this.element); 
 } 
 if (bgcolor)
  this.element.style.backgroundColor = bgcolor;
 this.element.style.height = height + "px";
 this.element.style.width = width + "px";
 
 this.image = new Image();
 this.image.src = fichier;
 this.image.alt = "Cliquez pour fermer";
 this.image.title = "Cliquez pour fermer";
 this.image.style.cursor= "pointer";
 this.element.appendChild(this.image);
 
 
 this.element.style.top = "50%";
 this.element.style.left = "50%";
 try {
  this.element.style.marginLeft = (-width/2) + "px";
  this.element.style.marginTop = (-height/2) + "px";
 } catch(e) {
 } 
 
 
 this.element.style.position = "absolute";
 this.element.style.border = "2px solid Black";
 this.element.style.textAlign = "right";
 this.element.style.verticalAlign = "top";
 this.image.fPlan = this;
 this.image.onmousedown = function (e) {
  setImgOpacity(getTarget(e));
 }
 this.image.onclick = function(e) {
  var t = getTarget(e);
  t.fPlan.close();
 }
 this.close = function() {
  if (window.parent == window)
  document.body.removeChild(this.element);
 else
  window.parent.document.body.removeChild(this.element);
 }
}

function createPopup(fichier,width,height,bgcolor,scroll,draggable,title) {
 if (window.parent == window)
  return new Popup(fichier,width,height,bgcolor,scroll,draggable,title);
 else
  return new window.parent.Popup(fichier,width,height,bgcolor,scroll,draggable,title); 
}

function Popup(fichier,width,height,bgcolor,scroll,draggable,title) {
 var doc = null; 
 var win = null;
 if (window.parent == window) {
  doc = document;
  win = window;
 } else {
  doc = window.parent.document; 
  win = window.parent;
 } 
 
 this.element = doc.createElement('div');
 doc.body.appendChild(this.element);
 this.width=width;
 this.height=height;
 
 if (zEnCours) {
  this.element.style.zIndex=zEnCours;
  zEnCours++;
 }
 
 if (bgcolor)
  this.element.style.backgroundColor = bgcolor;
 this.element.style.height = height + "px";
 this.element.style.width = width + "px";
 
 this.haut = doc.createElement('div');
 this.element.appendChild(this.haut);
 if (Drag && draggable) {
  Drag.init(this.haut,this.element);
 } 
 if (bgcolor)
  this.haut.style.backgroundColor = bgcolor;
 
 this.haut.style.textAlign = "left";
 this.haut.style.fontFamily = "Arial";
 this.haut.style.fontSize = "10px";
 this.haut.style.height = "15px";
 this.haut.style.cursor = "pointer";
 this.haut.style.background = "url(../images/dlgblack.png) repeat-x Black";
 this.haut.style.color="White";
 
 this.btnclose = document.createElement('div');
 this.haut.appendChild(this.btnclose);
 this.btnclose.className= "btnclosered";
 
 this.btnup = document.createElement('div');
 this.haut.appendChild(this.btnup);
 this.btnup.className= "btnupred";
 
 if (title) 
  this.haut.appendChild(doc.createTextNode(' '+title));
 
 this.holder = doc.createElement('iframe');
 this.element.appendChild(this.holder);
 this.holder.style.height = (height-15) + "px";
 this.holder.style.width = width + "px";
 
 this.holder.setAttribute("frameborder","0");
 if (!scroll)
  this.holder.setAttribute("scrolling","no"); 
 this.holder.setAttribute("marginheight","0"); 
 this.holder.setAttribute("marginwidth","0");
 this.holder.src = fichier;
 
 if (Drag && draggable) {
  this.element.style.top = ((win.innerHeight/2)-(height/2))+"px";
  this.element.style.left = ((win.innerWidth/2)-(width/2))+"px";
 }
 else {
  this.element.style.top = "50%";
  this.element.style.left = "50%";
 } 
 if (!(Drag && draggable)) 
 try {
  this.element.style.marginLeft = (-width/2) + "px";
  this.element.style.marginTop = (-height/2) + "px";
 } catch(e) {
 } 
 
 
 this.element.style.position = "absolute";
 this.element.style.border = "2px solid Black";
 this.element.style.textAlign = "right";
 this.element.style.verticalAlign = "top";
 this.btnclose.fPlan = this;
 this.btnup.fPlan = this;
 this.haut.fPlan = this;
 
 this.btnclose.onclick = function(e) {
  this.fPlan.close();
 }
 
 this.btnup.onclick = function(e) {
  if (this.fPlan.expanded)
   this.fPlan.collapse();
  else
   this.fPlan.expand(); 
 }
 this.haut.ondblclick = function(e) {
  if (this.fPlan.expanded)
   this.fPlan.collapse();
  else
   this.fPlan.expand(); 
 }
 
 this.close = function() {
  if (window.parent == window)
  document.body.removeChild(this.element);
 else
  window.parent.document.body.removeChild(this.element);
 }
 
 this.expanded = true;
 
 this.collapse = function() {
  this.expanded=false;
  this.holder.style.display="none";
  this.element.style.height = this.haut.style.height;
 }
 this.expand = function () {
  this.expanded=true;
  this.holder.style.display="";
  this.element.style.height = this.height+"px";
 }
}

function creationXHR() {
var resultat = null;
if (window.XMLHttpRequest) {
 resultat = new XMLHttpRequest();
 } else if (window.ActiveXObject) {
 resultat = new ActiveXObject("Microsoft.XMLHTTP");
 } else alert('Erreur');
 return resultat;
}

function actuOpBtn() {
 
 $('op_btn').src ="";
 $('op_btn').src = "ouBtn.html";
 
}

var dragged = null;

function dragMove(e) {
      dragged = this; 
      if (ie) {
            //Récupération de la position de la souris
            window.lastX=event.clientX;
            window.lastY=event.clientY;
            // lance doDrag tant que l'on appuie sur le bouton de la souris en la bougeant
            document.onmousemove=doDrag;
            // lance endDrag quand on relache le bouton de la souris
            document.onmouseup=endDrag; } 
       else if (ns4) {
            //Récupération de la position de la souris
            window.lastX=e.pageX;
            window.lastY=e.pageY;
            // lance doDrag tant que l'on appuie sur le bouton de la souris en la bougeant
            document.captureEvents(Event.MOUSEMOVE)
            document.onmousemove=doDrag;
            // lance endDrag quand on relache le bouton de la souris
            document.captureEvents(Event.MOUSEUP)
            document.onmouseup=endDrag; }
       else if (ns6) {
            //Récupération de la position de la souris
            window.lastX=e.clientX;
            window.lastY=e.clientY;
            // lance doDrag tant que l'on appuie sur le bouton de la souris en la bougeant
            window.onmousemove=doDrag;
            // lance endDrag quand on relache le bouton de la souris
            window.onmouseup=endDrag; }

}

function doDrag(e) {

      if (ie) {
            // Calcul de l'écart de position de la souris
            var difX=event.clientX-window.lastX;
            var difY=event.clientY-window.lastY;
            //Récupération de la position du div et ajout de l'écart de position de la souris
            var newX1 = parseInt(dragged.style.left)+difX;
            var newY1 = parseInt(dragged.style.top)+difY;
            // Assignation des nouvelles coordonnées au div
            mon_div.style.left=newX1+"px";
            mon_div.style.top=newY1+"px";
            //Assignation de l'anciènne position de la souris
            window.lastX=event.clientX;
            window.lastY=event.clientY; }else if (ns4) {
            // Calcul de l'écart de position de la souris
            var difX=e.pageX-window.lastX;
            var difY=e.pageY-window.lastY;
            //Récupération de la position du div et ajout de l'écart de position de la souris
            var newX1 = parseInt(dragged.left)+difX;
            var newY1 = parseInt(dragged.top)+difY;
            // Assignation des nouvelles coordonnées au div
            dragged.left=newX1;
            dragged.top=newY1;
            //Assignation de l'anciènne position de la souris
            window.lastX=e.pageX;
            window.lastY=e.pageY; }
            else if (ns6) {
            // Calcul de l'écart de position de la souris
            var difX=e.clientX-window.lastX;
            var difY=e.clientY-window.lastY;
            //Récupération de la position du div et ajout de l'écart de position de la souris
            var newX1 = parseInt(dragged.style.left)+difX;
            var newY1 = parseInt(dragged.style.top)+difY;
            // Assignation des nouvelles coordonnées au div
            dragged.style.left=newX1+"px";
            dragged.style.top=newY1+"px";
            //Assignation de l'anciènne position de la souris
            window.lastX=e.clientX;
            window.lastY=e.clientY; } 

}

function endDrag(e) {

      if (ie || ns4) {
            //Réinitialisation du onmousemove
            document.onmousemove=null; }
            else if (ns6) {
            //Réinitialisation du onmousemove
            window.onmousemove=null; }
            
     dragged = null;       

}

function createMenuInterne(div,title,elements) {
 if (window.parent == window)
  return new MenuInterne(div,title,elements);
 //else
  //return new window.parent.MenuInterne(div,title,elements); 
}

var Tclignotage = null;

function MenuInterne(div,title,elements) {
 this.parent = div;
 this.titleText = title;
 this.element = document.createElement('div');
 this.parent.appendChild(this.element);
 this.title = document.createElement("span");
 this.element.appendChild(this.title);
 this.title.innerHTML = this.titleText;
 this.elements= new Array();
 var left = 10 + this.title.offsetWidth;
 for (var i=0;i<elements.length;i++) {
  this.elements.push(new MenuElement(this,elements[i].src,elements[i].action,elements[i].title,i));
  this.elements[i].element.style.left=left+"px";
  left+=20+10;
 }
 this.element.style.position="absolute";
 this.element.style.width = left + "px";
 this.element.style.height="26px";
 this.element.style.textAlign = "left";
 this.element.style.fontFamily = "Arial";
 this.element.style.fontSize = "10px";
 this.element.style.cursor = "default";
 this.element.style.background = "url(../images/dlgblack.png) repeat-x Black";
 this.element.style.color="White";
 this.element.style.bottom = "0px";
 this.element.style.left="50%";
 this.element.style.marginLeft="-"+(Math.round(left/2)) + "px";
 this.element.style.zIndex = "100";
 this.title.style.marginLeft="10px";
 this.title.style.marginTop="5px";
 this.title.style.position="absolute";
 
 this.info = document.createElement('div');
 this.element.appendChild(this.info);
 this.info.style.position="absolute";
 this.info.style.height="14px";
 this.info.style.top="6px";
 this.info.style.width="0px";
 this.info.style.textAlign = "center";
 this.info.style.fontFamily = "Arial";
 this.info.style.fontSize = "10px";
 this.info.style.cursor = "default";
// this.info.style.background = "url(../images/dlgblack.png) repeat-x Black";
 this.info.style.backgroundColor ="#808080";
 this.info.style.zIndex = "1";
 this.info.style.display="none";
 this.info.style.left=left + "px";
 
 this.showInfo = function () {
  this.info.style.display="";
  var w=parseInt(this.info.style.width); 
  if (w==0)
   this.info.innerHTML = this.elements[this.indexClignote].title;
  w+=10;
  if (w<=200) {
   this.info.style.width = w+"px";
   setTimeout("if (menu) menu.showInfo();",10);
  }
   
 }
 
 this.hideInfo = function () {
  this.info.style.display="none";
  this.info.style.width="0px";
 }
 
 this.indexClignote=-1;
 this.clignote = function () {
  this.hideInfo();
  this.indexClignote++;
  if (this.indexClignote>=this.elements.length) this.indexClignote = 0;
  for (var i=0;i<this.elements.length;i++) {
   if (i==this.indexClignote)
    this.elements[i].imageElement.style.opacity = "1";
   else
    this.elements[i].imageElement.style.opacity = "0.7"; 
  } 
  Tclignotage = setTimeout("if (menu) menu.clignote();",500);
 }
 Tclignotage = setTimeout("if (menu) menu.clignote();",5000);
}

function MenuElement(menu,image,action,title,index) {
 this.index = index;
 this.menu = menu;
 this.parent = this.menu.element;
 this.image = image;
 this.action = action;
 this.element = document.createElement('div');
 this.parent.appendChild(this.element);
 this.element.style.width="20px";
 this.element.style.height="20px";
 this.imageElement = new Image();
 this.imageElement.src=this.image;
 this.element.appendChild(this.imageElement);
 this.imageElement.style.verticalAlign="middle";
 this.imageElement.data = this;
 this.imageElement.onclick=function (e) {
  eval(this.data.action);
 }
 this.imageElement.onmouseover=function(e) {
  this.data.menu.indexClignote = this.data.index;
  this.style.opacity = "1";
  this.data.element.style.top = "-1px";
  if (Tclignotage)
   clearTimeout(Tclignotage);
  this.data.menu.showInfo(); 
   
 }
 this.imageElement.onmouseout=function(e) {
  this.style.opacity = "0.7";
  this.data.element.style.top = "3px";
  Tclignotage = setTimeout("if (menu) menu.clignote();",5000);
  this.data.menu.hideInfo(); 
 }
 this.title = title;
 this.imageElement.alt="It"+this.index;
 //this.imageElement.title=title;
 this.imageElement.style.width="20px";
 this.imageElement.style.height="20px";
 this.imageElement.style.opacity = "0.7";
 this.imageElement.style.cursor="pointer";
 this.element.style.position="absolute";
 this.element.style.left="0px";
 this.element.style.top="3px";
 
}