function visibilite(thingId)
{
var targetElement;
targetElement = document.getElementById(thingId) ;
if (targetElement.style.display == "none")
{
targetElement.style.display = "" ;
} else {
targetElement.style.display = "none" ;
}
}

function GetIdVisuelAdmin(adr,pwidth,pheigth)
{
	id_visuel = document.laforme.id_visuel.value;
	if ((id_visuel != 0) && (id_visuel != '')) {
		open_admin(adr + "&id=" + id_visuel,pwidth,pheigth)
	}
}
function open_admin(adr,pwidth,pheigth)
{
 window.open(adr,"admin",'scrollbars=1,screenX=10,screenY=10,status=1,location=0, menubar=0,toolbar=0,resizable=1,width=' + pwidth + ',height=' + pheigth);
}

function ShowType(thingId)
{
	visibilite(thingId);
}

function afficher(calque){
	if (document.getElementById)
		document.getElementById(calque).style.visibility="visible";
	if (document.all && !document.getElementById)
		document.all[calque].style.visibility="visible";
	if (document.layers)
		document.layers[calque].visibility="visible";
}
	
function masquer(calque){
	if (calque != "test2") AffZone(calque,"");
	
	if (document.getElementById)
		document.getElementById(calque).style.visibility="hidden";
	if (document.all && !document.getElementById)
		document.all[calque].style.visibility="hidden";
	if (document.layers)
		document.layers[calque].visibility="hidden";
}

function JSReplace(inStr, inReplace){
while(inStr.indexOf(inReplace) > 0){
inStr = inStr.replace(inReplace);
};
};

function GetNbEnreg(zone,url)
{ 
    var xhr; 
    try { xhr = new XMLHttpRequest(); }                 
    catch(e) 
    {    
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    } 

    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              	
              	nb = xhr.responseText;
              	nb = nb.replace(new RegExp( "\\n", "g" ),'');
              	
	
	fleche_haute = '<div class="btscrollmenu"><a class="up" href="#" onMouseover="scrollspeed=-2" onMouseout="scrollspeed=0"></a></div>'
	fleche_bas = '<div class="btscrollmenu" ><a class="down" href="#" onMouseover="scrollspeed=2;" onMouseout="scrollspeed=0"></a></div>'
	if (nb > 33) { 
		document.getElementById(zone).innerHTML = fleche_haute + '<iframe id="datamain" src="vide.html" allowtransparency="true"  style="background-color:transparent" width=180 height=630 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></iframe>' + fleche_bas;
	}
	else {
		height_frame = 18 * nb;
		document.getElementById(zone).innerHTML = '<iframe id="datamain" src="vide.html" allowtransparency="true"  style="background-color:transparent" width=180 height=' +  height_frame + ' marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></iframe>'
	}
	
	document.getElementById("datamain").src = url;
	afficher(zone);
              	
              }
              else nb = 0;
              
              return nb;
         }
    }; 
   
   xhr.open( "GET", url + "&nb=1",  true); 
   xhr.send(null); 
   

} 

function executerOperation1(zone,url)
{
	nb = GetNbEnreg(zone,url);
	
}

function executerOperation(zone,url)
{ 
    AffZone(zone,'<ul><li><img src="images/wait.gif" border="0"></li></ul>');
    afficher(zone);
    
    var xhr; 
    try { xhr = new XMLHttpRequest(); }                 
    catch(e) 
    {    
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    } 

    xhr.onreadystatechange  = function()
    { 
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200) {
              	
              	if (document.all) eval(zone).innerHTML = xhr.responseText;
		else document.getElementById(zone).innerHTML  = xhr.responseText;
              }
              else AffZone(zone,'<ul><li>Aucun contenu</li></ul>');
         }
    }; 

   xhr.open( "GET", url,  true); 
   xhr.send(null); 
} 

function AffZone(zone,contenu)
{
	if (document.all) eval(zone).innerHTML = contenu;
	else document.getElementById(zone).innerHTML  = contenu;
	
	
}

function ChangeNavPublication(id_item)
{
		
	afficher("type");

}

function ChangeNav(id_item)
{
		
	afficher("type");
	liste = "";
	for (i=0;i<4;i++) {
		if (i!=id_item) liste = liste + Tnav[i];
		else titre = Tnav[i];
	}
	
	titre = titre.replace("<li>","");
	titre = titre.replace("</li>","");
	AffZone("type",titre);
	AffZone("l2",liste);
}

function GoType(zone,url,id_item)
{
	masquer('test2');
	masquer('enseignement');
	masquer('dossier');
	
	if (document.laforme.id_item.value != id_item) document.laforme.id_rub.value = 0;
	document.laforme.id_item.value = id_item;
	
	url = url + "&id_rub=" + document.laforme.id_rub.value;
	executerOperation(zone,url);
}

function GoTypePublication(zone,url,id_item)
{
	masquer('test2');
	masquer('enseignement');
	masquer('dossier');
	
	executerOperation(zone,url);
}

function GoTypeId(zone,url)
{
	masquer(zone);
	masquer("dossier");
	
	executerOperation1(zone,url);
}

function GoTypeIdOther(zone,url)
{
	masquer(zone);
	masquer("dossier");
	
	executerOperation(zone,url);
}

function AffTitreZone(zone,titre,id_item,id_rub)
{
	
	document.laforme.id_item.value = id_item;
	document.laforme.id_rub.value = id_rub;
	AffZone(zone,titre);
	
	afficher(zone);
	masquer('test');
	masquer('dossier');
	
}

function AffTitreZonePublication(zone,titre,id_item,id_rub)
{
	AffZone(zone,titre);
	afficher(zone);
	masquer('test');
	masquer('dossier');
	
}

function ShowVisuel(id_type,visuel,id_visuel,titre)
{
	if (document.getElementById("test2").style.visibility != "hidden") {
		masquer("test2");
		AffZone("dossier",titre);
		afficher("dossier");
	}
	
	document.laforme.id_visuel.value = id_visuel;
	if (id_type == 1) {
		document.getElementById('div8').style.display="none";
		document.getElementById('video').style.display="none";
		document.getElementById('div1').style.display="";
		

		AffZone('div1','<img src="upload/projet/visuel/' + visuel + '" alt="image" border="0" /> ')
		
	}
	else {
		document.getElementById('video').style.display="none";
		document.getElementById('div8').style.display="";
	}
}

function HideVideo()
{
	AffZone('cadre2',"&nbsp;")
	document.getElementById(document.laforme.tampon_visuel.value).style.display="";
	//new Effect.Appear('video', { duration: 1.0, from:0.95, to:0.0 });
	document.getElementById('video').style.display="none";
	
}

function ShowVideo(id_type,visuel,id_visuel,m_width,m_height)
{
	document.laforme.id_visuel.value = id_visuel;
	if (document.getElementById('div8').style.display == "none") document.laforme.tampon_visuel.value = "div1";
	else document.laforme.tampon_visuel.value = "div8";
	document.getElementById('div8').style.display="none";
	document.getElementById('div1').style.display="none";
	document.getElementById('video').style.display="none";
	//url_video = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="640" height="480" id="amiens" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="upload/projet/video/' + visuel + '" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#4d4d45" /><embed src="upload/projet/video/' + visuel + '" loop="false" quality="high" wmode="transparent" bgcolor="#4d4d45" width="640" height="480" name="amiens" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object> '
	url_video = '<EMBED SRC="upload/projet/video/' + visuel + '" HEIGHT=' + m_height + ' WIDTH=' + m_width + '>;'
	AffZone('cadre2',url_video)
	
	document.getElementById('video').style.display="";
	//new Effect.Appear('video', { duration: 3.0, from:0.0, to:0.95 });
	
}

function ShowPublicationMedia(id)
{
	afficher('preview');
	executerOperation('preview','include/ShowPublicationMedia.php?id=' + id);
}

function GoRecherche()
{
	zone = "test";

	url = "include/recherche.php?ch=" + document.Recherche.ch.value;
	executerOperation(zone,url);
	
}

function getTotalHeight() {

		  // firefox is ok
		  var height = document.documentElement.scrollHeight;
		
		  // now IE 7 + Opera with "min window"
		  if(document.documentElement.clientHeight > height ) {
		    height  = document.documentElement.clientHeight;
		  }
		  return height;
		}


