var NETSCAPE = (navigator.appName == 'Netscape');

//-----------------------
function ObjCentre( div_){
  var PosX, PosY;
  var Right, Bottom;
  var Left, Top;
  var Larg, Haut;
  var Obj = document.getElementById(div_);
  if( Obj){
	if( NETSCAPE){
	  with( window){
		Left   = pageXOffset;
		Top    = pageYOffset;
		Right  = innerWidth;
		Bottom = innerHeight;
		if( Right > document.width)
		  Right = document.width;
		if( Bottom > document.height)
		  Bottom = document.height;
		Right  += Left;
		Bottom += Top;
	  }
	  Larg = Obj.offsetWidth;
	  Haut = Obj.offsetHeight;
	}
	else{
	  with( document.body){
		Left   = scrollLeft;
		Top    = scrollTop;
		Right  = Left +clientWidth;
		Bottom = Top  +clientHeight;
	  }
	  Larg = Obj.scrollWidth;
	  Haut = Obj.scrollHeight;
	}
	PosX = (Right  -Larg)/2;
	PosY = (Bottom -Haut)/2;
	if( PosX < Left) PosX = Left;
	if( PosY < Top)  PosY = Top;
	//ObjMoveTo( div_, PosX, PosY); // à définir
	//alert(PosY);
	//alert(PosX);
	document.getElementById(div_).style.top=PosY+"px";
	document.getElementById(div_).style.left=PosX+"px";
  }
 
}
function addFavoris(){
	var title = "A3P";
	var href = "http://www.a3p.org";
	if (window.ActiveXObject){ //IE
		window.external.AddFavorite(href, title);
	}
	else{//Firefox
		window.sidebar.addPanel(title,href,"");	
	}
}

function verifmail(email) {
	var mail = new RegExp ("^[a-z0-9]+[a-z0-9\.\_\-]*@[a-z0-9]+[a-z0-9\.\_\-]*[\.]{1,1}[a-zA-Z]{2,4}$");
	reponse=mail.test(email);
	if (!reponse) 
	{
		return false;
	}
	else 
	{
		return true;
	}
}

function destroy_session(recherche){
	var obj = getXhr();
	obj.onreadystatechange = function(){
		if(obj.readyState == 4 && obj.status == 200){
			history.go(0);
		}
	}
	obj.open("GET","ajax/general.php?action=destroy_session&recherche="+recherche,true);
	obj.send(null);
}

function DoPopup(url)
{
	var OuvrirQuoi=window.open(url,"Portfolio","toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0,width=660,height=520,left=0,top=0");
	if (!OuvrirQuoi.opener) OuvrirQuoi.opener = self;
	if (OuvrirQuoi.focus != null) OuvrirQuoi.focus();
}


//----------------------------------- fonction ouverture de popup ---------------------------------------------------------------------
function popup(mapage,width,height,params) 
{
    x = (640 - width)/2, y = (480 - height)/2;
    if (screen)
    {
       y = (screen.availHeight - height)/2;
       x = (screen.availWidth - width)/2;
    }
    if (screen.availWidth > 1800)
    {
      x = ((screen.availWidth/2) - width)/2;
    }
   var OuvrirQuoi= window.open(mapage,'','width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+','+params);
}

function popup2(mapage,width,height,params,fenetre) 
{
    x = (640 - width)/2, y = (480 - height)/2;
    if (screen)
    {
       y = (screen.availHeight - height)/2;
       x = (screen.availWidth - width)/2;
    }
    if (screen.availWidth > 1800)
    {
      x = ((screen.availWidth/2) - width)/2;
    }
   var OuvrirQuoi= window.open(mapage,fenetre,'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+','+params);
   if (!OuvrirQuoi.opener) OuvrirQuoi.opener = self;
   if (OuvrirQuoi.focus != null) OuvrirQuoi.focus();
}

//fonction replaces
function remplace(cherche,remplace,chaine){
	var reg=new RegExp("("+cherche+")", "g");
	var nouv = chaine.replace(reg,remplace);
	return nouv;
}


//-------------------------- fonction de ajax -------------------------------------------------------

//activation de l'objet XMLHttpRequest et verif que le navigateur le supporte
function getXhr2(){
	if(window.XMLHttpRequest) // Firefox et autres
	xhr = new XMLHttpRequest();
	else if(window.ActiveXObject){ // Internet Explorer
	try {
	xhr = new ActiveXObject("Msxml2.XMLHTTP");
	
	} catch (e) {
	xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	}
	else { // XMLHttpRequest non supporté par le navigateur
	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	xhr = false;
	}
}
function getXhr(){
	var xhr2;
	if(window.XMLHttpRequest) // Firefox et autres
	xhr2 = new XMLHttpRequest();
	else if(window.ActiveXObject){ // Internet Explorer
	try {
	xhr2 = new ActiveXObject("Msxml2.XMLHTTP");
	
	} catch (e) {
	xhr2 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	}
	else { // XMLHttpRequest non supporté par le navigateur
	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	xhr2 = false;
	}
	
	return xhr2;
}



//fonction d'appel du script php qui traite la recherche et de renvoi des resultats
function go2(){
	
	getXhr();
	/*if(last_charge==document.add_rdv.Nom.value){
		return false;
	}
	current_line = 1;	
	last_charge = document.add_rdv.Nom.value;*/
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function(){
		// On ne fait quelque chose que si on a tout reçu et que le	serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200){
		//alert(xhr.responseText);
			document.getElementById("resultat").style.display="block";
			//document.getElementById("resultat").focus();
			document.getElementById("resultat").innerHTML=xhr.responseText;
		}
	}
	xhr.open("GET","php/recherche_patient.php?nom="+document.add_rdv.Nom.value,true);
	xhr.send(null);
}


function hautBas2(evenement){
	if (document.getElementById("resultat").style.display=="block") {
		var touche = window.event ? window.event.keyCode : evenement.keyCode ;
		
		switch (touche) {
			case 13:
				//alert(document.getElementById("ligne_" + current_line).innerHTML);
				//document.getElementById("resultat").style.display="none";
				valeur=document.getElementById("input_"+current_line).value;
				tab = valeur.split(",");
				bulldog = 1;
				rempli_patient2(tab[0],tab[1],tab[2],tab[3],tab[4],tab[5],tab[6],tab[7],tab[8],tab[9],tab[10]);
				return false;
				break;
			case 38:
				current_line--;
				if (current_line < 1) current_line = 1;
				break;
			case 40:
				current_line++;
				if (current_line > 10) current_line = 10;
				break;
		}
		
		for (i = 1; i <= 10; i++) {
			if (document.getElementById("ligne_" + i)) {
				with (document.getElementById("ligne_" + i)) {
					
					if (i == current_line) {
						style.background='#E5EFF0'; 
					} else {
						style.background='#fff'; 
					}
				}
			}
		}
	}	
}



//-------------------------- EOF fonction de ajax -------------------------------------------------------


function openWindow2(mapage,width,height) {
	x = (640 - width)/2, y = (480 - height)/2;
	if (screen) {
	y = (screen.availHeight - height)/2;
	x = (screen.availWidth - width)/200;
	}
	if (screen.availWidth > 1800) {
	x = ((screen.availWidth/2) - width)/2;
	}
	window.open(mapage,"",'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+',scrollbars=yes,resizable=yes');
}

function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

function cache(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='none';}
}


function confirmation(mess,url)
{
	if(confirm(mess))
	{
		document.location=url;
	}
}

function affiche(id)
{
	var d = document.getElementById(id);
	d.style.display = "block";
}
function cache(id)
{
	var d = document.getElementById(id);
	d.style.display = "none";
}

//----
function confirm_suppr(lien,mess) //confirmation de suppression
{
	
	if(confirm("Etes-vous sur de vouloir supprimer "+mess+"?"))
	{
		document.location = (lien);
	}
	
}



//----------------------------------- ouvre une image dans un popup -----------------------------------
function ouvrir(chemin,titre,largeur,hauteur) 
{
	test = window.open("about:blank","","width="+largeur+",height="+hauteur+"");
	texte = "<title>"+titre+"</title><a href='#' onClick='window.close()'><img src='"+chemin+"' alt='Cliquez pour fermer' border='0'></a>";
	test.document.write(texte);
}

//rempli les champs de formulaire apres ouverture popup
function remplir(input1,input2)
{
		window.opener.document.add_auteur_livre.id_auteur.value=input1;
		//window.opener.document.add_auteur_livre.auteur.value=input2;
		window.close();
		window.opener.document.add_auteur_livre.submit();
}
function remplir2(input1,input2)
{
		window.opener.document.add_editeur_livre.id_editeur.value=input1;
		//window.opener.document.add_editeur_livre.editeur.value=input2;
		window.close();
		window.opener.document.add_editeur_livre.submit();
}
function remplir3(input1,input2)
{
		window.opener.document.add_collection_livre.id_collection.value=input1;
		//window.opener.document.add_collection_livre.collection.value=input2;
		window.close();
		window.opener.document.add_collection_livre.submit();
}
function remplir4(input1,input2)
{
		window.opener.document.add_categorie_livre.id_categorie.value=input1;
		//window.opener.document.add_categorie_livre.categorie.value=input2;
		window.close();
		window.opener.document.add_categorie_livre.submit();
}

function redir_t()
{
	setTimeout("history.go(0)",1000);	
}

function redir(url)
{
	document.location=(url);	
}


function HorlogeDynamique() {
	var DateActuel = new Date();
	var heure = DateActuel.getHours();
	var minutes = DateActuel.getMinutes();
	var secondes = DateActuel.getSeconds();

	if (heure == 0) {
		heure = "0" + heure;
		}
	if (minutes <= 9) {
		minutes = "0" + minutes;
		}
	if (secondes <= 9) {
		secondes = "0" + secondes;
		}
	
	Horloge = "<b>"+ heure + ":" + minutes + ":" + secondes + "</b>";
	

	if (document.getElementById) {
		document.getElementById("clock").innerHTML = Horloge;
		
		}

	if (document.layers) { 
    		document.clock.document.write("<br>&nbsp;&nbsp;"+Horloge); 
		document.clock.document.close(); 
  		}

	if ((document.all)&&(!document.getElementById)) { 
    		document.all["clock"].innerHTML = Horloge;
 		}

	setTimeout("HorlogeDynamique()", 1000)
	}
	
