var produit_recherche='';

var tabhisto = new Array();
var histo_precedent = 0;

var ligne_selectionne;
var cip_selectionne = '';
var cip_selectionne_ordonnance = '';
var id_selectionne_ordonnance = '';

var gestion_livret_therapeutique = 0;

var idsearch_en_cours = 0;

var lien_contenu_data = '';

function recherche_bcb(debut)
{
	if (document.frmbcb.type.value != 4)
	{
	
		if ((document.frmbcb.type.value != 2) && (document.frmbcb.type.value != 3))
			nb_caracteres_mini = 3;
		else
			nb_caracteres_mini = 5;
	
		if (debut.length<nb_caracteres_mini)
		{
			if (debut.length==0) {
				document.getElementById('contenu').innerHTML = '';
			} else {
				document.getElementById('contenu').innerHTML = '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center" class="bcb_noresult">Vous devez saisir au moins ' + nb_caracteres_mini + ' caractères.</td></tr></table>';
			}
			idsearch_en_cours = 0;
		}
		else
		{
			if (debut!=produit_recherche)
			{
				patienter('contenu');
				setTimeout("lance_recherche('" + debut + "')", 500);
			}
		}
	
	}

}

function relance_recherche()
{
	produit_recherche = "";
	debut_actuel = document.frmbcb.recherche.value;
	if (debut_actuel == "") document.frmbcb.recherche.focus();

	if (document.frmbcb.type.value <= 3)
	{
		recherche_bcb(debut_actuel);
	}
	else
	{
		recherche_bcb2(debut_actuel);
	}
}

function lance_recherche(debut)
{
	ligne_selectionne = null;
	cip_selectionne = "";
	debut_actuel = document.frmbcb.recherche.value;
	// SI le debut du produit recherché est différent de la dernière recherche effectuée
	// ET si le début du produit recherché est égal à ce qu'il y a actuellement dans la zone de saisie
	// ALORS on peut lancer la recherche
	if ((debut!=produit_recherche) && (debut_actuel==debut))
	{
		produit_recherche=debut;
		//alert("c'est parti");
		recherche_bcb2(debut);
	}
}

function recherche_bcb2(debut)
{
	// On masque le bouton permettant de revenir en arrière
	visibilite("bouton_precedent", false);
	
	patienter('contenu');
	
	var xhr=null;
	if(window.XMLHttpRequest) // Firefox et autres
	xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e1) {
				xhr = null;
			}
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}
	
	switch(document.frmbcb.type.value)
	{
	
	// RECHERCHE PAR DENOMINATION COMMUNE
	case "5":
	
		xhr.onreadystatechange = function() {
			retourne_info_html(xhr);
		}
		
		option_recherche = "";
		if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
		
		tabhisto[0] = "bcb_recherche/dc.asp?critere=" + escape(debut) + option_recherche;
		
		// Recherche par dénomination commune
		xhr.open("GET", tabhisto[0], true);
		xhr.send(null);		
	
		break;
		
	// RECHERCHE PAR LABORATOIRE
	case "6":
	
		xhr.onreadystatechange = function() {
			retourne_info_html(xhr);
		}
		
		option_recherche = "";
		if (document.frmbcb.chk_supprime.checked == true) option_recherche += "&supp=1";
		if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
		
		tabhisto[0] = "bcb_recherche/labo.asp?critere=" + escape(debut) + option_recherche;
		
		// Recherche par dénomination commune
		xhr.open("GET", tabhisto[0], true);
		xhr.send(null);		

		break;
		
	// RECHERCHE PAR COMPOSANT
	case "7":
	
		xhr.onreadystatechange = function() {
			retourne_info_html(xhr);
		}
		
		option_recherche = "";
		if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
		
		tabhisto[0] = "bcb_recherche/composant.asp?critere=" + escape(debut) + option_recherche;
		
		//document.getElementById("ordonnance").innerHTML = "bcb_recherche/composant.asp?critere=" + escape(debut) + option_recherche;
		
		// Recherche par dénomination commune
		xhr.open("GET", tabhisto[0], true);
		xhr.send(null);		

		break;
		
	// RECHERCHE PAR INDICATION
	case "8":
	
		visibilite("lien_contenu", false);

		xhr.onreadystatechange = function() {
			retourne_pathologies(xhr);
		}

		option_recherche = "";
		if (document.frmbcb.chk_nimporteou.checked == true) option_recherche += "&ts=1"; else option_recherche += "&ts=0"
		
		// On génére un nombre aléatoire qui sera retourné dans le fichier XML
		// afin de bien identifier la dernière recherche étant donné qu'elles sont asynchrones
		idsearch = Math.floor(Math.random() * 1000) + 1;
		
		idsearch_en_cours = idsearch;
		
		xhr.open("GET", "bcb_xml/pathologies.asp?critere=" + debut + option_recherche + "&idsearch=" + idsearch, true);
		xhr.send(null);
		
		break;
		
	// RECHERCHE PAR DENOMINATION COMMUNE (MEDICAMENT VIRTUEL)
	case "11":
		
		xhr.onreadystatechange = function() {
			retourne_info_html(xhr);
		}
		
		//option_recherche = "";
		//if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
						
		// Recherche par dénomination commune
		xhr.open("GET", "bcb_recherche/mv.asp?critere=" + escape(debut), true);
		xhr.send(null);		
		
		break;
	
	// RECHERCHE PAR NOM, CODE CIP, CODE UCD, ASPECT
	default:
	
		xhr.onreadystatechange = function() {
			retourne_info(xhr);
		}
	
		option_recherche = "";
		if (document.frmbcb.chk_supprime.checked == true) option_recherche += "&supp=1";
		if (document.frmbcb.chk_nimporteou.checked == true) option_recherche += "&lexico=1";
		if (document.frmbcb.chk_specialites.checked == true) option_recherche += "&specialite=1"; else option_recherche += "&specialite=0";
		if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
		if (gestion_livret_therapeutique == 1) option_recherche +="&livret=1"; else option_recherche += "&livret=0";
		option_recherche += "&type=" + document.frmbcb.type.value;
		
		// On génére un nombre aléatoire qui sera retourné dans le fichier XML
		// afin de bien identifier la dernière recherche étant donné qu'elles sont asynchrones
		idsearch = Math.floor(Math.random() * 1000) + 1;
		idsearch_en_cours = idsearch;
		
		//document.getElementById("ordonnance").innerHTML = "bcb_xml/recherche.asp?critere=" + escape(debut) + option_recherche + "&idsearch=" + idsearch;
		
		xhr.open("GET", "bcb_xml/recherche.asp?critere=" + escape(debut) + option_recherche + "&idsearch=" + idsearch, true);
		xhr.send(null);

		break;
	
	}
		
}

function patienter(div_name)
{
	document.getElementById(div_name).innerHTML = '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center"><img src="bcb_images/chargement.gif"></td></tr></table>';
}

function retourne_info_html(xhr)
{
	
	if (xhr.readyState==4)
	{
		
		// On remet le contenu par défaut dans le div lien_contenu
		document.getElementById('lien_contenu').innerHTML = lien_contenu_data;
		
		if (document.frmbcb.type.value!=11)
		{
			visibilite("lien_contenu", false);
		}
		//} else {
		//	document.getElementById('lien_contenu').innerHTML = '<a href="javascript:ordonnance(\'add\');" class="bcb_lien_fonction">Ajouter à l\'ordonnance</a>&nbsp;&nbsp;<a href="javascript:infos(3,1);" class="bcb_lien_fonction">Monographie</a>';
		//}
		
		// La recherche est terminée, on remet à blanc la recherche
		produit_recherche = "";
		
		document.getElementById('contenu').innerHTML = xhr.responseText;
	}
	
}

function retourne_info(xhr)
{
	if (xhr.readyState==4)
	{
		
		// On remet le contenu par défaut dans le div lien_contenu
		document.getElementById('lien_contenu').innerHTML = lien_contenu_data;
		
		if (xhr.status==200)
		{
			var docXML = xhr.responseXML;
			
			var item_bcb = docXML.getElementsByTagName("bcb").item(0);
			idsearch = item_bcb.getAttribute("idsearch");
			
			// Si le code de la recherche correspond à la recherche en cours, on affiche le résultat
			if (idsearch == idsearch_en_cours)
			{
				
				message_erreur = '';
				if (docXML.getElementsByTagName("erreur").item(0).firstChild != null) message_erreur = docXML.getElementsByTagName("erreur").item(0).firstChild.data;
		
				if (message_erreur != '') {
					
					document.getElementById('contenu').innerHTML = '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center" class="bcb_noresult">' + message_erreur + '</td></tr></table>';

				} else {
					
					var items = docXML.getElementsByTagName("produit");
					var chaine = '<table border="0" cellspacing="0" cellpadding="2" width="100%" class="bcb_ligne_out" style="border-collapse:collapse;cursor:pointer;">\n';
					//on fait juste une boucle sur chaque element "donnee" trouvé
					for (i=0;i<items.length;i++)
					{
						if (items.item(i).getElementsByTagName("hospitalier")[0].firstChild.data == 1)
							hospitalier = '<img src="bcb_images/hopital.gif" alt="Produit hospitalier" title="Produit hospitalier">';
						else
							hospitalier = '&nbsp;';
							
						if (gestion_livret_therapeutique==1)
						{
							// livret_therapeutique est présent dans le XML, on affiche donc l'info
							valeur_livret = items.item(i).getElementsByTagName("livret_therapeutique")[0].firstChild.data;
							switch(valeur_livret)
							{
							case "0":
								livret_therapeutique = '<td class="bcb_liste_tableau">&nbsp;</td>';
								break;
							case "1":
								livret_therapeutique = '<td class="bcb_liste_tableau"><a href="javascript:infos_livret(\'' + items.item(i).getElementsByTagName("code")[0].firstChild.data + '\');"><img SRC="bcb_images/livret_sans_info.gif" alt="Présent dans le livret thérapeutique sans informations complémentaires" title="Présent dans le livret thérapeutique sans informations complémentaires" width="12" height="11" border="0"></a></td>';
								break;
							case "2":
								livret_therapeutique = '<td class="bcb_liste_tableau"><a href="javascript:infos_livret(\'' + items.item(i).getElementsByTagName("code")[0].firstChild.data + '\');"><img SRC="bcb_images/livret_avec_info.gif" alt="Présent dans le livret thérapeutique avec informations complémentaires" title="Présent dans le livret thérapeutique avec informations complémentaires" width="12" height="11" border="0"></a></td>';
								break;
							}
						}
						else
						{
							livret_therapeutique = '';
						}
						
						var docofficiel = items.item(i).getElementsByTagName("document");
						if (docofficiel.length >= 1) {
							document_officiel = '<td class="bcb_liste_tableau"><a href="documents_officiels.asp?cip=' +  items.item(i).getElementsByTagName("code")[0].firstChild.data + '" target="_blank"><img SRC="bcb_images/doc_officiel.gif" alt="Consulter le(s) document(s) officiel(s)" title="Consulter le(s) document(s) officiel(s)" width="12" height="15" border="0"></a></td>';
						} else {
							document_officiel = '<td class="bcb_liste_tableau">&nbsp;</td>';
						}
						
						var referent = items.item(i).getElementsByTagName("referent")[0].firstChild.data;
						var generique = items.item(i).getElementsByTagName("generique")[0].firstChild.data;
						referent_generique = '&nbsp;';
						if (referent == "1") referent_generique = '<img src="bcb_images/referents.gif" alt="Produit référent" title="Produit référent">';
						if (generique == "1") referent_generique = '<img src="bcb_images/generiques.gif" alt="Produit générique" title="Produit générique">';
						
						libelle_produit =  items.item(i).getElementsByTagName("nom")[0].firstChild.data;
						// Si le produit est supprimé, on applique le style de la classe "produit_supprime"
						if (items.item(i).getElementsByTagName("date_suppression")[0].firstChild != null) libelle_produit = '<span class="bcb_produit_supprime">' + libelle_produit + '</span>';
						chaine += '<tr onMouseOver="survol(this, \'in\');" onMouseOut="survol(this, \'out\');" onClick="select_line(this, \'' + items.item(i).getElementsByTagName("code")[0].firstChild.data + '\', \'recherche\');" onDblClick="ordonnance(\'add\');"><td width="20" class="bcb_liste_tableau" valign="middle" align="center">' + hospitalier + '</td><td class="bcb_liste_tableau">' + libelle_produit + '</font></td><td class="bcb_liste_tableau">' + referent_generique + '</td>' + livret_therapeutique + document_officiel + '<td class="bcb_liste_tableau">' + items.item(i).getElementsByTagName("code")[0].firstChild.data + '</td></tr>\n';
					}
					chaine += '</table>';
					document.getElementById('contenu').innerHTML = chaine;
					
					visibilite("lien_contenu", true);
					
					// La recherche est terminée, on remet à blanc la recherche
					produit_recherche = "";
					
					if (items.length==0) document.getElementById('contenu').innerHTML = '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center" class="bcb_noresult">Aucun produit trouvé.</td></tr></table>';
				}
			}
		}
		else
		{
			alert("Une erreur s'est produite, la recherche ne peut aboutir.");
			document.getElementById('contenu').innerHTML = ' ';
		}
	}
}

function retourne_pathologies(xhr)
{
	if (xhr.readyState==4)
	{
		if (xhr.status==200)
		{
			var docXML = xhr.responseXML;
			
			var item_bcb = docXML.getElementsByTagName("bcb").item(0);
			idsearch = item_bcb.getAttribute("idsearch");
			
			// Si le code de la recherche correspond à la recherche en cours, on affiche le résultat
			if (idsearch == idsearch_en_cours)
			{
				
				message_erreur = '';
				if (docXML.getElementsByTagName("erreur").item(0).firstChild != null) message_erreur = docXML.getElementsByTagName("erreur").item(0).firstChild.data;
		
				if (message_erreur != '') {
					
					document.getElementById('contenu').innerHTML = '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center" class="bcb_noresult">' + message_erreur + '</td></tr></table>';

				} else {
										
					var items = docXML.getElementsByTagName("pathologie");
					var chaine = '<table border="0" cellspacing="0" cellpadding="2" width="100%" class="bcb_ligne_out" style="border-collapse:collapse;cursor:pointer;">\n';
					//on fait juste une boucle sur chaque element "pathologie" trouvé
					for (i=0;i<items.length;i++)
					{
						code_patho =  items.item(i).getElementsByTagName("code")[0].firstChild.data;
						libelle_patho =  items.item(i).getElementsByTagName("libelle")[0].firstChild.data;
						type_patho =  items.item(i).getElementsByTagName("type")[0].firstChild.data;
						
						switch(type_patho)
						{
							case "1":
								lib_type_patho = "AMM";
								break;
							case "3":
								lib_type_patho = "CIM10";
								break;
						}
						
						chaine += '<tr onMouseOver="survol(this, \'in\');" onMouseOut="survol(this, \'out\');" onClick="recherche_pathologies(\'' + code_patho + '\', ' + type_patho + ');"><td class="bcb_liste_tableau">' + libelle_patho + '</font></td><td class="bcb_liste_tableau" align="center">' + lib_type_patho + '</td><td width="20" class="bcb_liste_tableau"><img src="bcb_images/spacer.gif"></td></tr>\n';
					}
					chaine += '</table>';
					document.getElementById('contenu').innerHTML = chaine;
					
					if (items.length==0) document.getElementById('contenu').innerHTML = '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center" class="bcb_noresult">Aucune pathologie trouvée.</td></tr></table>';
				}
			}
		}
		else
		{
			alert("Une erreur s'est produite, la recherche ne peut aboutir.");
			document.getElementById('contenu').innerHTML = ' ';
		}
	}
}

function select_line(ligne, code, nom_liste)
{
	if (ligne_selectionne != null) ligne_selectionne.className='bcb_ligne_out';
	ligne_selectionne = ligne;
	
	cip_selectionne = code;
	cip_selectionne_ordonnance = "";
	id_selectionne_ordonnance = "";
		
	ligne.className='bcb_ligne_select';
}

function select_line_ordo(ligne, code, nom_liste, id_datasession)
{
	if (ligne_selectionne != null) ligne_selectionne.className='bcb_ligne_out';
	ligne_selectionne = ligne;
	
	cip_selectionne = "";
	cip_selectionne_ordonnance = code;
	id_selectionne_ordonnance = id_datasession;
		
	ligne.className='bcb_ligne_select';
}

function survol(ligne, in_out)
{
	if (ligne != ligne_selectionne)
	{
		if (in_out == 'in')
			ligne.className = 'bcb_ligne_over';
		else
			ligne.className = 'bcb_ligne_out';
	}
}

function ordonnance(type)
{
	blnSelectionne = false;
	if (type=='add' && cip_selectionne!='') blnSelectionne = true;
	if (type=='remove' && id_selectionne_ordonnance!='') blnSelectionne = true;
	if (type=='load') blnSelectionne = true;
	if (type=='removeall') blnSelectionne = true;
	
	if (blnSelectionne)
	{
		var xhr=null;
		if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
		else if(window.ActiveXObject)
		{ // Internet Explorer
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e1) {
					xhr = null;
				}
			}
		}
		else { // XMLHttpRequest non supporté par le navigateur
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		}
		
		xhr.onreadystatechange = function() {
			ajout_ordonnance2(xhr);
		}
		
		patienter('ordonnance');
		switch(type)
		{
		case 'add':
			xhr.open("GET", "bcb_xml/ordonnance.asp?cip=" + cip_selectionne, true);
			break
		case 'remove':
			xhr.open("GET", "bcb_xml/ordonnance.asp?supp=" + id_selectionne_ordonnance, true);
			break;
		case 'load':
			xhr.open("GET", "bcb_xml/ordonnance.asp", true);
			break;
		case 'removeall':
			xhr.open("GET", "bcb_xml/ordonnance.asp?supp=all", true);
			break;
		}			
			
		xhr.send(null);
	}
	else
	{
		alert("Vous devez sélectionner un produit dans la liste.");
	}
}

function ajout_ordonnance2(xhr)
{
	if (xhr.readyState==4)
	{
		
		var docXML= xhr.responseXML;
		
		message_erreur = '';
		if (docXML.getElementsByTagName("erreur").item(0).firstChild != null) message_erreur = docXML.getElementsByTagName("erreur").item(0).firstChild.data;
		
		if (message_erreur != '') {
			
			document.getElementById('alertes').innerHTML = " "
			document.getElementById('ordonnance').innerHTML = '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center" class="bcb_noresult">' + message_erreur + '</td></tr></table>';
			
		}
		else
		{	
			var items_alertes = docXML.getElementsByTagName("alertes");
			
			// Gestion des feux interactions
			switch(items_alertes.item(0).getElementsByTagName("interactions")[0].firstChild.data)
			{
			case "0":
				interactions_feu = '<td><img src="bcb_images/feux_g.gif" border="0"></td><td class="bcb_texte_alerte">Interactions</td>';
				break;
			case "1":
				interactions_feu = '<td><img src="bcb_images/feux_v.gif" border="0"></td><td class="bcb_texte_alerte">Interactions</td>';
				break;
			case "2":
				interactions_feu = '<td><a href="javascript:interactions();"><img src="bcb_images/feux_r.gif" border="0"></a></td><td><a href="javascript:interactions();" class="bcb_lien_alerte">Interactions</a></td>';
				break;
			}
			
			// Gestion des feux contre-indications
			switch(items_alertes.item(0).getElementsByTagName("contre_indications")[0].firstChild.data)
			{
			case "0":
				ci_feu = '<td><img src="bcb_images/feux_g.gif" border="0"></td><td class="bcb_texte_alerte">Contre-indications</td>';
				break;
			case "1":
				ci_feu = '<td><img src="bcb_images/feux_v.gif" border="0"></td><td class="bcb_texte_alerte">Contre-indications</td>';
				break;
			case "2":
				ci_feu = '<td><a href="javascript:contre_indications();"><img src="bcb_images/feux_j.gif" border="0"></a></td><td><a href="javascript:contre_indications();" class="bcb_lien_alerte">Contre-indications</a></td>';
				break;
			case "3":
				ci_feu = '<td><a href="javascript:contre_indications();"><img src="bcb_images/feux_r.gif" border="0"></a></td><td><a href="javascript:contre_indications();" class="bcb_lien_alerte">Contre-indications</a></td>';
				break;			
			}
			
			// Gestion des feux précautions d'emploi
			switch(items_alertes.item(0).getElementsByTagName("precautions_emploi")[0].firstChild.data)
			{
			case "0":
				pe_feu = '<td><img src="bcb_images/feux_g.gif" border="0"></td><td class="bcb_texte_alerte">Précautions d\'emploi</td>';
				break;
			case "1":
				pe_feu = '<td><img src="bcb_images/feux_v.gif" border="0"></td><td class="bcb_texte_alerte">Précautions d\'emploi</td>';
				break;
			case "2":
				pe_feu = '<td><a href="javascript:precautions_emploi();"><img src="bcb_images/feux_j.gif" border="0"></a></td><td><a href="javascript:precautions_emploi();" class="bcb_lien_alerte">Précautions d\'emploi</a></td>';
				break;			
			}		
			
			// Gestion des feux hypersensibilités
			switch(items_alertes.item(0).getElementsByTagName("hypersensibilites")[0].firstChild.data)
			{
			case "0":
				hypersensibilites_feu = '<td><img src="bcb_images/feux_g.gif" border="0"></td><td class="bcb_texte_alerte">Hypersensibilités</td>';
				break;
			case "1":
				hypersensibilites_feu = '<td><img src="bcb_images/feux_v.gif" border="0"></td><td class="bcb_texte_alerte">Hypersensibilités</td>';
				break;
			case "2":
				hypersensibilites_feu = '<td><a href="javascript:hypersensibilites();"><img src="bcb_images/feux_r.gif" border="0"></a></td><td><a href="javascript:hypersensibilites();" class="bcb_lien_alerte">Hypersensibilités</a></td>';
				break;			
			}
			
			// Gestion des incompatibilités physico-chimiques
			switch(items_alertes.item(0).getElementsByTagName("ipc")[0].firstChild.data)
			{
			case "0":
				ipc_feu = '<td><img src="bcb_images/feux_g.gif" border="0"></td><td class="bcb_texte_alerte">Incompatibilités physico-chimiques</td>';
				break;
			case "1":
				ipc_feu = '<td><img src="bcb_images/feux_v.gif" border="0"></td><td class="bcb_texte_alerte">Incompatibilités physico-chimiques</td>';
				break;
			case "2":
				ipc_feu = '<td><a href="javascript:ipc();"><img src="bcb_images/feux_r.gif" border="0"></a></td><td><a href="javascript:ipc();" class="bcb_lien_alerte">Incompatibilités physico-chimiques</a></td>';
				break;			
			}				
			
			// Gestion du surdosage
			switch(items_alertes.item(0).getElementsByTagName("surdosage")[0].firstChild.data)
			{
			case "0":
				surdosage_feu = '<td><img src="bcb_images/feux_g.gif" border="0"></td><td class="bcb_texte_alerte">Redondances th&eacute;rapeutiques</td>';
				break;
			case "1":
				surdosage_feu = '<td><img src="bcb_images/feux_v.gif" border="0"></td><td class="bcb_texte_alerte">Redondances th&eacute;rapeutiques</td>';
				break;
			case "2":
				surdosage_feu = '<td><a href="javascript:surdosage();"><img src="bcb_images/feux_r.gif" border="0"></a></td><td><a href="javascript:surdosage();" class="bcb_lien_alerte">Redondances th&eacute;rapeutiques</a></td>';
				break;			
			}				
			
			document.getElementById('alertes').innerHTML = '<table border="0" cellspacing="0" cellpadding="4">' + ci_feu + pe_feu + surdosage_feu + '</table><table border="0" cellspacing="0" cellpadding="4">' + ipc_feu + interactions_feu + hypersensibilites_feu + '</table>';	
			
			var items = docXML.getElementsByTagName("produit");
			var chaine = '<table border="0" cellspacing="0" cellpadding="2" width="100%" class="bcb_ligne_out" style="border-collapse:collapse;cursor:pointer;">\n';
			//on fait juste une boucle sur chaque element "donnee" trouvé
			for (i=0;i<items.length;i++)
			{
				if (items.item(i).getElementsByTagName("hospitalier")[0].firstChild.data == 1)
					hospitalier = '<img src="bcb_images/hopital.gif">';
				else
					hospitalier = '&nbsp;';
	
				libelle_produit =  items.item(i).getElementsByTagName("nom")[0].firstChild.data;
				// Si le produit est supprimé, on applique le style de la classe "produit_supprime"
				if (items.item(i).getElementsByTagName("date_suppression")[0].firstChild != null) libelle_produit = '<span class="bcb_produit_supprime">' + libelle_produit + '</span>';
				
				code_affiche = items.item(i).getElementsByTagName("code")[0].firstChild.data;
				if (code_affiche.substring(0, 2)=='81') code_affiche='-';
				chaine += '<tr onMouseOver="survol(this, \'in\');" onMouseOut="survol(this, \'out\');" onClick="select_line_ordo(this, \'' + items.item(i).getElementsByTagName("code")[0].firstChild.data + '\', \'ordonnance\', \'' + items.item(i).getElementsByTagName("id_datasession")[0].firstChild.data + '\');"><td width="20" class="bcb_liste_tableau" valign="middle" align="center">' + hospitalier + '</td><td class="bcb_liste_tableau">' + libelle_produit + '</td><td class="bcb_liste_tableau" align="center">' + code_affiche + '</td></tr>\n';
			}
			chaine += '</table>';
			document.getElementById('ordonnance').innerHTML = '<table border="0" cellspacing="0" cellpadding="2" width="100%"><tr class="bcb_ligne_select"><td align="center"><b>Ordonnance</b></td></tr></table>' + chaine;
		}
	}
}

function visibilite(thingId, afficher)
{
	var targetElement;
	targetElement = document.getElementById(thingId) ;
	if (afficher == true)
		targetElement.style.display = "" ;
	else
		targetElement.style.display = "none" ;
}

function change_type_recherche()
{
	produit_recherche = '';
			
	afficher_case_nimporteou = false;
	afficher_case_specialite = false;
	afficher_case_supprime = false;
	afficher_bouton_rechercher = false;
	afficher_bouton_precedent = false;
	afficher_zone_saisie = true;
	afficher_lien_ouvrir = false;
	afficher_case_livret = true;
	
	// Pour la recherche par nom on affiche la case nimporteou, specialite et supprime
	if (document.frmbcb.type.value == 1)
	{
		afficher_case_nimporteou = true;
		afficher_case_specialite = true;
		afficher_case_supprime = true;
	}
	
	// Pour les recherches par code cip, ucd, on affiche la case supprime
	if (document.frmbcb.type.value == 2 || document.frmbcb.type.value == 3)
	{
		afficher_case_supprime = true;
	}
	
	// Pour la recherche par aspect, on affiche le bouton rechercher
	if (document.frmbcb.type.value == 4)
	{
		afficher_bouton_rechercher = true;
		afficher_case_supprime = true;
	}
	
	// Pour la recherche par laboratoire
	if (document.frmbcb.type.value == 6)
	{
		afficher_case_specialite = true;
		afficher_case_supprime = true;		
	}
	
	// Pour la recherche par laboratoire
	if (document.frmbcb.type.value == 7)
	{
		afficher_case_supprime = true;		
	}
	
	// Pour la recherche par indication
	if (document.frmbcb.type.value == 8)
	{
		afficher_case_nimporteou = true;	
	}

	// Pour la recherche par classe thérapeutique BCB
	if (document.frmbcb.type.value == 9)
	{
		afficher_zone_saisie = false;
		afficher_lien_ouvrir = true;
		mywindow = window.open("bcb_recherche/classes_produits.asp?cc=1&filtrelivret=", "search_classes", "height=600,width=600,scrollbars=yes,status=no,toolbar=no,location=no");
		mywindow.focus();
	}
	
	// Pour la recherche par classe thérapeutique BCB
	if (document.frmbcb.type.value == 10)
	{
		afficher_zone_saisie = false;
		afficher_lien_ouvrir = true;
		mywindow = window.open("bcb_recherche/classes_produits.asp?cc=2&filtrelivret=", "search_classes", "height=600,width=600,scrollbars=yes,status=no,toolbar=no,location=no");
		mywindow.focus();
	}
	
	// Pour la recherche par dénomination commune (médicament virtuel)
	if (document.frmbcb.type.value == 11)
	{
		afficher_case_livret = false;
	}
	
	// On affiche/masque les boutons/options
	if (afficher_zone_saisie == true)
	{
		visibilite("zone_saisie", true);
		document.frmbcb.recherche.value='';
		document.frmbcb.recherche.focus();
	}
	else
	{
		visibilite("zone_saisie", false);
	}
	
	if (afficher_case_nimporteou == true) visibilite("option_nimporteou", true); else visibilite("option_nimporteou", false);
	if (afficher_case_specialite == true) visibilite("option_specialite", true); else visibilite("option_specialite", false);
	if (afficher_case_supprime == true) visibilite("option_supprime", true); else visibilite("option_supprime", false);
	if (gestion_livret_therapeutique == 1)
	{
		if (afficher_case_livret == true) visibilite("option_livret", true); else visibilite("option_livret", false);
	}
	if (afficher_bouton_rechercher == true) visibilite("bouton_rechercher", true); else visibilite("bouton_rechercher", false);
	if (afficher_bouton_precedent == true) visibilite("bouton_precedent", true); else visibilite("bouton_precedent", false);
	if (afficher_lien_ouvrir == true) visibilite("lien_ouvrir", true); else visibilite("lien_ouvrir", false);
	
}

function interactions()
{
	mywindow = window.open('alerte_interactions.asp', 'alerte_interactions');
	mywindow.focus();
}
function ipc()
{
	mywindow = window.open('alerte_ipc.asp', 'alerte_ipc');
	mywindow.focus();
}
function surdosage()
{
	mywindow = window.open('alerte_rt.asp', 'alerte_rt');
	mywindow.focus();
}
function contre_indications()
{
	mywindow = window.open('alerte_ci.asp', 'alerte_ci');
	mywindow.focus();
}
function precautions_emploi()
{
	mywindow = window.open('alerte_pe.asp', 'alerte_pe');
	mywindow.focus();
}
function hypersensibilites()
{
	mywindow = window.open('alerte_hypersensibilites.asp', 'alerte_hypersensibilites');
	mywindow.focus();
}
function infos(type, liste)
{
	var cip = "";
	if (type==1) page = "monographie.asp";
	if (type==2) page = "equivalents.asp";
	//if (type==3) page = "monomv.asp"
	if (liste==1) cip = cip_selectionne;
	if (liste==2) cip = cip_selectionne_ordonnance;
	if (cip!='') {
		mywindow = window.open(page + '?cip=' + cip);
		mywindow.focus();
		//document.all.frame_infos.src = page + '?cip=' + cip;
	} else {
		alert("Vous devez sélectionner un produit dans la liste.");
	}
}
function infos_livret(codecip) {
	window.open("details_produit.asp?cip=" + codecip, "bcbh_details","scrollbars=yes,menubar=no,location=no,status=yes,toolbar=no,height=420,width=550");
}
function imprimer_ordonnance() {
	window.open("imprimordo.asp", "bcbh_imprimer");		
}

function recherche_dc(code_classe, dosage, forme)
{
	patienter('contenu');
	
	var xhr=null;
	if(window.XMLHttpRequest) // Firefox et autres
	xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e1) {
				xhr = null;
			}
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}
	
	if (dosage == "" && forme == "")
	{
		xhr.onreadystatechange = function() {
			retourne_info_html(xhr);
		}
		
		option_recherche = "";
		if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
		
		tabhisto[1] = "bcb_recherche/dc2.asp?dci=" + escape(code_classe) + option_recherche;
		histo_precedent = 0;
		visibilite("bouton_precedent", true);
		
		xhr.open("GET", tabhisto[1], true);
		xhr.send(null);
	}
	else
	{
		xhr.onreadystatechange = function() {
			retourne_info(xhr);
		}
		
		// On génére un nombre aléatoire qui sera retourné dans le fichier XML
		// afin de bien identifier la dernière recherche étant donné qu'elles sont asynchrones
		idsearch = Math.floor(Math.random() * 1000) + 1;
		idsearch_en_cours = idsearch;
		
		option_recherche = "";
		if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
		if (gestion_livret_therapeutique == 1) option_recherche +="&livret=1"; else option_recherche += "&livret=0";
		
		histo_precedent = 1;
		visibilite("bouton_precedent", true);
		
		xhr.open("GET", "bcb_xml/recherche_dc.asp?dci=" + escape(code_classe) + "&dosage=" + escape(dosage) + "&forme=" + escape(forme) + "&idsearch=" + idsearch + option_recherche, true);
		xhr.send(null);
	}
}

function recherche_labo(code_labo)
{

	patienter('contenu');
	
	var xhr=null;
	if(window.XMLHttpRequest) // Firefox et autres
	xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e1) {
				xhr = null;
			}
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}

	xhr.onreadystatechange = function() {
		retourne_info(xhr);
	}
	
	// On génére un nombre aléatoire qui sera retourné dans le fichier XML
	// afin de bien identifier la dernière recherche étant donné qu'elles sont asynchrones
	idsearch = Math.floor(Math.random() * 1000) + 1;
	idsearch_en_cours = idsearch;
	
	option_recherche = "";
	if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
	if (gestion_livret_therapeutique == 1) option_recherche +="&livret=1"; else option_recherche += "&livret=0";
	if (document.frmbcb.chk_supprime.checked == true) option_recherche += "&supp=1";
	
	histo_precedent = 0;
	visibilite("bouton_precedent", true);
	
	xhr.open("GET", "bcb_xml/recherche_labo.asp?code=" + escape(code_labo) + "&idsearch=" + idsearch + option_recherche, true);
	xhr.send(null);

}

function recherche_composant(code_composant)
{

	patienter('contenu');
	
	var xhr=null;
	if(window.XMLHttpRequest) // Firefox et autres
	xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e1) {
				xhr = null;
			}
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}

	xhr.onreadystatechange = function() {
		retourne_info(xhr);
	}
	
	// On génére un nombre aléatoire qui sera retourné dans le fichier XML
	// afin de bien identifier la dernière recherche étant donné qu'elles sont asynchrones
	idsearch = Math.floor(Math.random() * 1000) + 1;
	idsearch_en_cours = idsearch;
	
	option_recherche = "";
	if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
	if (gestion_livret_therapeutique == 1) option_recherche +="&livret=1"; else option_recherche += "&livret=0";
	if (document.frmbcb.chk_supprime.checked == true) option_recherche += "&supp=1";
	
	histo_precedent = 0;
	visibilite("bouton_precedent", true);
	
	//document.getElementById("ordonnance").innerHTML = "bcb_xml/recherche_composant.asp?code=" + escape(code_composant) + "&idsearch=" + idsearch + option_recherche
	
	xhr.open("GET", "bcb_xml/recherche_composant.asp?code=" + escape(code_composant) + "&idsearch=" + idsearch + option_recherche, true);
	xhr.send(null);

}

function recherche_pathologies(code_classe, type_ind)
{

	patienter('contenu');
	
	var xhr=null;
	if(window.XMLHttpRequest) // Firefox et autres
	xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e1) {
				xhr = null;
			}
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}

	xhr.onreadystatechange = function() {
		retourne_info(xhr);
	}
	
	// On génére un nombre aléatoire qui sera retourné dans le fichier XML
	// afin de bien identifier la dernière recherche étant donné qu'elles sont asynchrones
	idsearch = Math.floor(Math.random() * 1000) + 1;
	idsearch_en_cours = idsearch;
	
	option_recherche = "";
	if (document.frmbcb.chk_livret.checked == true) option_recherche +="&filtrelivret=1"; else option_recherche += "&filtrelivret=0";
	if (gestion_livret_therapeutique == 1) option_recherche +="&livret=1"; else option_recherche += "&livret=0";
	
	//histo_precedent = 0;
	//visibilite("bouton_precedent", true);
	
	xhr.open("GET", "bcb_xml/recherche_indication.asp?code=" + escape(code_classe) + "&typeind=" + escape(type_ind) + "&idsearch=" + idsearch + option_recherche, true);
	xhr.send(null);

}

function precedent()
{
	patienter('contenu');
	
	var xhr=null;
	if(window.XMLHttpRequest) // Firefox et autres
	xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e1) {
				xhr = null;
			}
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}
	
	xhr.onreadystatechange = function() {
		retourne_info_html(xhr);
	}
	
	xhr.open("GET", tabhisto[histo_precedent], true);
	xhr.send(null);
	
	if (histo_precedent==0)
	{
		visibilite("bouton_precedent", false);
	}
	else
	{
		histo_precedent--;
	}

}

function apostrophe(chaine)
{
	var reg=new RegExp('(\')', 'g');
	chaine = chaine.replace(reg, '\\\'');
	return chaine;
}

function afssaps()
{
	if (cip_selectionne!='') {
		// On recherche le code CIS correspondant
		var xhr=null;
		if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
		else if(window.ActiveXObject)
		{ // Internet Explorer
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e1) {
					xhr = null;
				}
			}
		}
		else { // XMLHttpRequest non supporté par le navigateur
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		}
	
		//alert("profil_save.asp?type=" + type + "&sexe=" + sexe + "&age=" + age + "&poids=" + poids + "&g=" + grossesse + "&a=" + allaitement);
	
		xhr.open("GET", "bcb_xml/fonctionsbcb.asp?cip=" + cip_selectionne + "&num=1", false);
		xhr.send(null);
		// ---------------------------------------------------

		if (xhr.responseText != "" && xhr.responseText != "0")
		{
			mywindow = window.open("http://afssaps-prd.afssaps.fr/php/ecodex/extrait.php?specid=" + xhr.responseText);
			mywindow.focus();
		}
		else
		{
			alert("Aucune information disponible.");
		}
	} else {
		alert("Vous devez sélectionner un produit dans la liste.");
	}
}

function calculCleCIP13(cip13){  
      var cle = 0;
      var cleRangPair = 0;
      var cleRangImpair = 0;
      var calculCle = 0;
      // somme des valeurs de rang pair
      var totRangPair = parseInt(cip13.charAt(1))+parseInt(cip13.charAt(3))+parseInt(cip13.charAt(5))+parseInt(cip13.charAt(7))+parseInt(cip13.charAt(9))+parseInt(cip13.charAt(11));
      // somme des valeurs de rang impair
      var totRangImpair = parseInt(cip13.charAt(0))+parseInt(cip13.charAt(2))+parseInt(cip13.charAt(4))+parseInt(cip13.charAt(6))+parseInt(cip13.charAt(8))+parseInt(cip13.charAt(10));
      var totInter = totRangPair * 3 + totRangImpair;
      //alert(" somme : "+totInter);
      var pos = totInter.toString().length;
      if (parseInt(totInter.toString().charAt(pos-1)) > 0){
        cle = 10 - parseInt(totInter.toString().charAt(pos-1));
      }
      return cle;
}

function ameli()
{
	if (cip_selectionne!='') {
		cip13 = '34009' + cip_selectionne;
		cip13 = cip13 + calculCleCIP13(cip13);
		mywindow = window.open("http://www.codage.ext.cnamts.fr/codif/bdm_it//fiche/index_fic_medisoc.php?p_code_cip=" + cip13 + "&p_site=AMELI");
		mywindow.focus();
	} else {
		alert("Vous devez sélectionner un produit dans la liste.");
	}
}

function has()
{
	if (cip_selectionne!='') {
		// On recherche le code CIS correspondant
		var xhr=null;
		if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest();
		else if(window.ActiveXObject)
		{ // Internet Explorer
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e1) {
					xhr = null;
				}
			}
		}
		else { // XMLHttpRequest non supporté par le navigateur
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		}
	
		//alert("profil_save.asp?type=" + type + "&sexe=" + sexe + "&age=" + age + "&poids=" + poids + "&g=" + grossesse + "&a=" + allaitement);
	
		xhr.open("GET", "bcb_xml/fonctionsbcb.asp?cip=" + cip_selectionne + "&num=2", false);
		xhr.send(null);
		// ---------------------------------------------------

		if (xhr.responseText != "" && xhr.responseText != "0")
		{
			mywindow = window.open("http://www.has-sante.fr/portail/jcms/c_5267/actes-produits-de-sante?portlet=c_63468&text=" + xhr.responseText);
			mywindow.focus();
		}
		else
		{
			alert("Aucune information disponible.");
		}
	} else {
		alert("Vous devez sélectionner un produit dans la liste.");
	}	
}

function init_lien_contenu()
{
	// On mémorise ce qu'il y a dans lien contenu par défaut
	lien_contenu_data = document.getElementById('lien_contenu').innerHTML;
}
