var relation = 0 ;
var num_sosa ;
var enfant_numero ;

$Fx = new Array () ;
$Fy = new Array () ;

$Fx[1]  = 562 ;
$Fy[1]  = 620 ;
$Fx[2]  = 243 ;
$Fy[2]  = 438 ;
$Fx[3]  = 879 ;
$Fy[3]  = 438 ;
$Fx[4]  =  84 ;
$Fy[4]  = 277 ;
$Fx[5]  = 402 ;
$Fy[5]  = 277 ;
$Fx[6]  = 720 ;
$Fy[6]  = 277 ;
$Fx[7]  =1038 ;
$Fy[7]  = 277 ;
$Fx[8]  =   7 ;
$Fy[8]  =  98 ;
$Fx[9]  = 166 ;
$Fy[9]  =  98 ;
$Fx[10] = 325 ;
$Fy[10] =  98 ;
$Fx[11] = 484 ;
$Fy[11] =  98 ;
$Fx[12] = 643 ;
$Fy[12] =  98 ;
$Fx[13] = 802 ;
$Fy[13] =  98 ;
$Fx[14] = 961 ;
$Fy[14] =  98 ;
$Fx[15] =1120 ;
$Fy[15] =  98 ;

for (i=1 ; i<16 ; i++)
	{
	$Fx[i] += 0 ;
	$Fy[i] += 60 ;
	}

$lg = 166 ;
$ht = 69  ;

function js_OuvreSosa(a)
	{
	js_FermeSosa () ;
	
	if (a == 1)													// Ajout enfant
		{
		n = 1 ;
		
		var num   = document.getElementById("sosa2").innerHTML ;
		var c_num = document.getElementById("sosa3").innerHTML ;

		info = new Array () ;
		
		if (navigator.appName == "Netscape")
			{
			x = $Fx[1] - 0 ;
			y = $Fy[1] - 90 ;
		
			var enfant_nom = document.getElementById("F1").innerHTML.split("<br>") ;
			}
		else
			{
			x = $Fx[1] - 0 ;
			y = $Fy[1] - 115 ;
		
			var enfant_nom = document.getElementById("F1").innerHTML.split("<BR>") ;
			}

		info[0] = enfant_nom[0] ;
		info[1] = "" ;
		info[2] = "__.__.____" ;
		info[3] = "__.__.____" ;
		}
	else if ((a == 2) || (num_sosa == 0))								// Ajout nouveau personnage
		{
		if (document.forms["Modifier"].elements["btn_modifier_sujet"].disabled == true)
			{
			alert ("Saisie non autorisée !") ;
			return ;
			}

		if (document.forms["Modifier"].elements["base"].value == "Capet")
			{
			alert ("Saisie non autorisée en ascendance !") ;
			return ;
			}

		if (navigator.appName == "Netscape")
			{
			x = $Fx[n] - 21 ;
			y = $Fy[n] - 160 ;
			}
		else
			{
			x = $Fx[n] - 21 ;
			y = $Fy[n] - 185 ;
			}

		info = new Array () ;
		
		if (n > 1)
			{
			i = n / 2 ;
			i = parseInt (i) ;

			if (navigator.appName == "Netscape")
				enfant_numero = document.getElementById("sosa" + i).innerHTML ;
			else enfant_numero = document.getElementById("sosa" + i).innerHTML ;
			}
		else	enfant_numero = 0 ;

		info[0] = "" ;
		info[1] = "" ;
		info[2] = "__.__.____" ;
		info[3] = "__.__.____" ;
		}
	else
		{
		if (document.forms["Modifier"].elements["btn_modifier_sujet"].disabled == true)
			{
			alert ("Données non modifiables !") ;
			return ;
			}

		if (navigator.appName == "Netscape")
			{
			x = $Fx[n] - 0 ;
			y = $Fy[n] - 60 ;

			var info = document.getElementById("F"+n).innerHTML.split("<br>") ;
			}
		else
			{
			x = $Fx[n] - 0 ;
			y = $Fy[n] - 85 ;

			var info = document.getElementById("F"+n).innerHTML.split("<BR>") ;
			}
		
		var num  = document.getElementById("sosa"+n).innerHTML ;
	
		if (num == 0)
			{
			alert ("Saisie ascendante non autorisée !") ;
			return ;
			}
		}

	fond = document.getElementById("Fond") ;
	
	Sosa = document.createElement("form") ;
	fond.appendChild(Sosa) ;
	Sosa.id   = "Sosa" ;
	Sosa.name = "Sosa" ;
	Sosa.style.zIndex = 500 ;
	Sosa.style.position = "absolute" ;
	Sosa.style.left = x + "px" ;
	Sosa.style.top  = y + "px" ;
	Sosa.style.width  = "180px" ;
	Sosa.style.height = "200px" ;

	if (navigator.appName == "Netscape")
		{
		numero = document.createElement("input") ;
		Sosa.appendChild(numero) ;
		numero.id    = "numero" ;
		numero.name  = "numero" ;
		numero.type  = "hidden" ;
		numero.value = num ;
	
		conjoint = document.createElement("input") ;
		Sosa.appendChild(conjoint) ;
		conjoint.id    = "conjoint" ;
		conjoint.name  = "conjoint" ;
		conjoint.type  = "hidden" ;
		conjoint.value = c_num ;
		}
	else
		{
		numero = document.createElement("input") ;
		Sosa.appendChild(numero) ;
		numero.id    = "numero" ;
		numero.name  = "numero" ;
		numero.type  = "text" ;
		numero.size  = 1 ;
		numero.value = num ;
		numero.style.visibility = "hidden" ;
	
		conjoint = document.createElement("input") ;
		Sosa.appendChild(conjoint) ;
		conjoint.id    = "conjoint" ;
		conjoint.name  = "conjoint" ;
		conjoint.type  = "text" ;
		conjoint.size  = 1 ;
		conjoint.value = c_num ;
		conjoint.style.visibility = "hidden" ;
		}
	
	m_param = "document.getElementById('Sosa'), document.getElementById('nom'), document.getElementById('')" ;		// Pour auto-complétion
	auto    = "initAutoComplete(" + m_param + ")" ;

	nom = document.createElement("input") ;
	Sosa.appendChild(nom) ;
	nom.id    = "nom" ;
	nom.name  = "nom" ;
	nom.type  = "text" ;
	nom.size  = 25 ;
	nom.maxLength = 45 ;
	nom.value = info[0] ;
	nom.className = "champ" ;
	nom.style.textAlign    = "left" ;
	nom.style.marginBottom = "0px" ;
	nom.style.backgroundColor = "#FFC0C0" ;
	nom.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		nom.setAttribute('onkeyup', auto) ;
	else	nom.onkeyup = new Function (auto) ;
	
	prenom = document.createElement("input") ;
	Sosa.appendChild(prenom) ;
	prenom.id    = "prenom" ;
	prenom.name  = "prenom" ;
	prenom.type  = "text" ;
	prenom.size  = 25 ;
	prenom.maxLength = 90 ;
	prenom.value = info[1] ;
	prenom.className = "champ" ;
	prenom.style.textAlign    = "left" ;
	prenom.style.marginBottom = "0px" ;
	prenom.style.backgroundColor = "#FFC0C0" ;
	prenom.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		prenom.setAttribute('onfocus', 'js_IndiquerSexeSosa()') ;
	else	prenom.onfocus = new Function ('js_IndiquerSexeSosa()') ;
	
	if (a > 0)
		{
		if (navigator.appName == "Netscape")
			prenom.setAttribute('onblur', 'js_ChercheNomSosa()') ;
		else	prenom.onblur = new Function ('js_ChercheNomSosa()') ;
		}
	
	date = info[2].split(".") ;

	n_jour = document.createElement("input") ;
	Sosa.appendChild(n_jour) ;
	n_jour.id    = "n_jour" ;
	n_jour.name  = "n_jour" ;
	n_jour.type  = "text" ;
	n_jour.size  = 2 ;
	n_jour.maxLength = 2 ;
	if (date[0].substring(0,2) == "__") date[0] = "" ;
	n_jour.value = date[0] ;
	n_jour.className = "champ" ;
	n_jour.style.textAlign    = "left" ;
	n_jour.style.marginRight  = "0px" ;
	n_jour.style.marginBottom = "0px" ;
	n_jour.style.backgroundColor = "#FFC0C0" ;
	n_jour.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		n_jour.setAttribute('onkeyup', 'js_Autotab(this, n_mois)') ;
	else	n_jour.onkeyup = new Function ('js_Autotab(this, n_mois)') ;

	n_mois = document.createElement("input") ;
	Sosa.appendChild(n_mois) ;
	n_mois.id    = "n_mois" ;
	n_mois.name  = "n_mois" ;
	n_mois.type  = "text" ;
	n_mois.size  = 2 ;
	n_mois.maxLength = 2 ;
	if (date[1].substring(0,2) == "__") date[1] = "" ;
	n_mois.value = date[1] ;
	n_mois.className = "champ" ;
	n_mois.style.textAlign    = "left" ;
	n_mois.style.marginRight  = "0px" ;
	n_mois.style.marginBottom = "0px" ;
	n_mois.style.backgroundColor = "#FFC0C0" ;
	n_mois.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		n_mois.setAttribute('onkeyup', 'js_Autotab(this, n_annee)') ;
	else	n_mois.onkeyup = new Function ('js_Autotab(this, n_annee)') ;

	n_annee = document.createElement("input") ;
	Sosa.appendChild(n_annee) ;
	n_annee.id    = "n_annee" ;
	n_annee.name  = "n_annee" ;
	n_annee.type  = "text" ;
	n_annee.size  = 4 ;
	n_annee.maxLength = 4 ;
	if (date[2].substring(0,4) == "____") date[2] = "" ;
	n_annee.value = date[2] ;
	n_annee.className = "champ" ;
	n_annee.style.textAlign    = "left" ;
	n_annee.style.marginRight  = "0px" ;
	n_annee.style.marginBottom = "0px" ;
	n_annee.style.backgroundColor = "#FFC0C0" ;
	n_annee.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		n_annee.setAttribute('onkeyup', 'js_Autotab(this, n_code)') ;
	else	n_annee.onkeyup = new Function ('js_Autotab(this, n_code)') ;

	var reg  = new RegExp ("[,()]+", "g") ;
	var tableau = info[2].split(reg) ;

	m_param = "document.getElementById('Sosa'), document.getElementById('n_code'), document.getElementById('')" ;		// Pour auto-complétion
	auto    = "initAutoComplete(" + m_param + ")" ;

	n_code = document.createElement("input") ;
	Sosa.appendChild(n_code) ;
	n_code.id    = "n_code" ;
	n_code.name  = "n_code" ;
	n_code.type  = "text" ;
	n_code.size  = 10 ;
	n_code.maxLength = 30 ;
	if (tableau.length > 1) 
		n_code.value = tableau[1] ;
	else	n_code.value = "" ;
	n_code.className = "champ" ;
	n_code.style.textAlign    = "left" ;
	n_code.style.marginRight  = "0px" ;
	n_code.style.marginBottom = "0px" ;
	n_code.style.backgroundColor = "#FFC0C0" ;
	n_code.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		n_code.setAttribute('onkeyup', auto) ;
	else	n_code.onkeyup = new Function (auto) ;

	date = info[3].split(".") ;

	d_jour = document.createElement("input") ;
	Sosa.appendChild(d_jour) ;
	d_jour.id    = "d_jour" ;
	d_jour.name  = "d_jour" ;
	d_jour.type  = "text" ;
	d_jour.size  = 2 ;
	d_jour.maxLength = 2 ;
	if (date[0].substring(0,2) == "__") date[0] = "" ;
	d_jour.value = date[0] ;
	d_jour.className = "champ" ;
	d_jour.style.textAlign    = "left" ;
	d_jour.style.marginRight  = "0px" ;
	d_jour.style.marginBottom = "1px" ;
	d_jour.style.backgroundColor = "#FFC0C0" ;
	d_jour.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		d_jour.setAttribute('onkeyup', 'js_Autotab(this, d_mois)') ;
	else	d_jour.onkeyup = new Function ('js_Autotab(this, d_mois)') ;

	d_mois = document.createElement("input") ;
	Sosa.appendChild(d_mois) ;
	d_mois.id    = "d_mois" ;
	d_mois.name  = "d_mois" ;
	d_mois.type  = "text" ;
	d_mois.size  = 2 ;
	d_mois.maxLength = 2 ;
	if (date[1].substring(0,2) == "__") date[1] = "" ;
	d_mois.value = date[1] ;
	d_mois.className = "champ" ;
	d_mois.style.textAlign    = "left" ;
	d_mois.style.marginRight  = "0px" ;
	d_mois.style.marginBottom = "1px" ;
	d_mois.style.backgroundColor = "#FFC0C0" ;
	d_mois.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		d_mois.setAttribute('onkeyup', 'js_Autotab(this, d_annee)') ;
	else	d_mois.onkeyup = new Function ('js_Autotab(this, d_annee)') ;

	d_annee = document.createElement("input") ;
	Sosa.appendChild(d_annee) ;
	d_annee.id    = "d_annee" ;
	d_annee.name  = "d_annee" ;
	d_annee.type  = "text" ;
	d_annee.size  = 4 ;
	d_annee.maxLength = 4 ;
	if (date[2].substring(0,4) == "____") date[2] = "" ;
	d_annee.value = date[2] ;
	d_annee.className = "champ" ;
	d_annee.style.textAlign    = "left" ;
	d_annee.style.marginRight  = "0px" ;
	d_annee.style.marginBottom = "1px" ;
	d_annee.style.backgroundColor = "#FFC0C0" ;
	d_annee.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		d_annee.setAttribute('onkeyup', 'js_Autotab(this, d_code)') ;
	else	d_annee.onkeyup = new Function ('js_Autotab(this, d_code)') ;

	var reg  = new RegExp ("[,()]+", "g") ;
	var tableau = info[3].split(reg) ;

	m_param = "document.getElementById('Sosa'), document.getElementById('d_code'), document.getElementById('')" ;		// Pour auto-complétion
	auto    = "initAutoComplete(" + m_param + ")" ;

	d_code = document.createElement("input") ;
	Sosa.appendChild(d_code) ;
	d_code.id    = "d_code" ;
	d_code.name  = "d_code" ;
	d_code.type  = "text" ;
	d_code.size  = 10 ;
	d_code.maxLength = 30 ;
	if (tableau.length > 1) 
		d_code.value = tableau[1] ;
	else	d_code.value = "" ;
	d_code.className = "champ" ;
	d_code.style.textAlign    = "left" ;
	d_code.style.marginRight  = "0px" ;
	d_code.style.marginBottom = "1px" ;
	d_code.style.backgroundColor = "#FFC0C0" ;
	d_code.style.cursor = "text" ;
	if (navigator.appName == "Netscape")
		d_code.setAttribute('onkeyup', auto) ;
	else	d_code.onkeyup = new Function (auto) ;

	if (navigator.appName == "Netscape")
		{
		var btn_V = document.createElement("input") ;    					// Provoque erreur avec IE
		Sosa.appendChild(btn_V) ;
		btn_V.id    = "btn_valider_conjoint" + i ;
		btn_V.name  = "btn_valider_conjoint" + i ;
		btn_V.type  = "button" ;										// Provoque erreur avec IE
		btn_V.value = "Valider" ;
		btn_V.className = "bouton" ;
		btn_V.style.width = "54px" ;
		btn_V.style.marginBottom = "1px" ;
		btn_V.style.marginLeft = "0px" ;
		btn_V.setAttribute('onClick', 'js_ValideSosa('+a+')') ;

		var btn_A = document.createElement("input") ;    					// Provoque erreur avec IE
		Sosa.appendChild(btn_A) ;
		btn_A.id    = "btn_annuler_conjoint" + i ;
		btn_A.name  = "btn_annuler_conjoint" + i ;
		btn_A.type  = "button" ;										// Provoque erreur avec IE
		btn_A.value = "Annuler" ;
		btn_A.className = "bouton" ;
		btn_A.style.width = "54px" ;
		btn_A.style.marginBottom = "1px" ;
		btn_A.style.marginLeft = "2px" ;
		btn_A.setAttribute('onClick', 'js_FermeSosa()') ;
		}
	else
		{
		var btn_V = document.createElement("button") ;					// Internet Explorer
		Sosa.appendChild(btn_V) ;
		btn_V.id    = "btn_valider_conjoint" + i ;
		btn_V.name  = "btn_valider_conjoint" + i ;
//		btn_V.type  = "button" ;										// Provoque erreur avec IE
		btn_V.value = "Valider" ;
		btn_V.className = "bouton" ;
		btn_V.style.width = "54px" ;
		btn_V.style.height = "20px" ;
		btn_V.style.fontSize = "11px" ;
		btn_V.style.marginLeft = "0px" ;
//		btn_V.setAttribute('onClick', 'js_ValideSosa('+a+')') ;			// Ne marche pas avec IE
// 		btn_V.onclick = js_ValideSosa(a) ;								// Ne marche pas avec IE
// 		btn_V.onclick = function () {js_ValideSosa(a) ;}					// Prend i max comme paramètre
 		btn_V.onclick = new Function ('js_ValideSosa('+a+')') ;

		var btn_A = document.createElement("button") ;					// Internet Explorer
		Sosa.appendChild(btn_A) ;
		btn_A.id    = "btn_annuler_conjoint" + i ;
		btn_A.name  = "btn_annuler_conjoint" + i ;
//		btn_A.type  = "button" ;										// Provoque erreur avec IE
		btn_A.value = "Annuler" ;
		btn_A.className = "bouton" ;
		btn_A.style.width = "54px" ;
		btn_A.style.height = "20px" ;
		btn_A.style.fontSize = "11px" ;
		btn_A.style.marginLeft = "2px" ;
//		btn_A.setAttribute('onClick', 'js_FermeSosa()') ;					// Ne marche pas avec IE
// 		btn_A.onclick = js_FermeSosa() ;								// Ne marche pas avec IE
// 		btn_A.onclick = function () {js_FermeSosa() ;}					// Prend i max comme paramètre
 		btn_A.onclick = new Function ('js_FermeSosa()') ;
		}

	if ((a > 0) && (n == 1))
		{
		sexe = document.createElement("select") ;
		Sosa.appendChild(sexe) ;
		sexe.id = "sexe" ;
		sexe.style.marginLeft = "4px" ;
		sexe.style.width = "56px" ;

		option1 = document.createElement("option") ;
		sexe.appendChild(option1) ;
		t1 = document.createTextNode("Sexe");
		option1.value = 2 ;
		option1.appendChild(t1) ;

		option2 = document.createElement("option") ;
		sexe.appendChild(option2) ;
		t2 = document.createTextNode("Garçon");
		option2.value = 0 ;
		option2.style.textAlign = "left" ;
		option2.style.backgroundColor = "blue" ;
		option2.style.color = "#FFFFFF" ;
		option2.appendChild(t2) ;

		option3 = document.createElement("option") ;
		sexe.appendChild(option3) ;
		t3 = document.createTextNode("Fille");
		option3.value = 1 ;
		option3.style.textAlign = "left" ;
		option3.style.backgroundColor = "red" ;
		option3.style.color = "#FFFFFF" ;
		option3.appendChild(t3) ;
		}
	}
	
function js_FermeSosa()
	{
	if  (document.getElementById("Sosa") != null)
		document.getElementById("Sosa").parentNode.removeChild(document.getElementById("Sosa")) ;
		
	js_EffaceListe () ;
	}
	
	
function js_ValideSosa(a)
	{
	var xhr = getHTTPObject () ;
	var url ;

//	On définit 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)
			{
			js_FermeSosa () ;

			resultat = xhr.responseText ;

			var message = resultat.split("@") ;

			var enfant = message[0] ;

			var exp = new RegExp ("Modification non", "g") ;
			
			if (exp.test(enfant)) alert (enfant) ;						// Modification non autorisée
			
			base = document.forms["Modifier"].elements["base"].value ;

			url = window.location.toString().split('?') ;				
			url[0] += "?base=" + base + "&n=1" ;
		
			window.location.replace (url[0]) ;
			}		
		}
		
	if (a == 1)													// Ajout enfant
		{
		if (document.forms["Sosa"].elements["prenom"].value == "")
			{
			alert ("Veuillez saisir le prénom !\n\nSi prénom inconnu :\nSaisissez N... pour un garçon, Ne... pour une fille.") ;

			return;
			}

		ch  = (relation + "@") ;
		ch += (document.forms["Modifier"].elements["base"].value + "@") ;
		ch += (document.forms["Sosa"].elements["numero"].value + "@") ;
		ch += (document.forms["Sosa"].elements["conjoint"].value + "@") ;
		ch += (document.forms["Sosa"].elements["nom"].value + "@") ;
		ch += (document.forms["Sosa"].elements["prenom"].value + "@") ;
		ch += (document.forms["Sosa"].elements["sexe"].value + "@") ;

		ch += (document.forms["Sosa"].elements["n_jour"].value + "@") ;
		ch += (document.forms["Sosa"].elements["n_mois"].value + "@") ;
		ch += (document.forms["Sosa"].elements["n_annee"].value + "@") ;

		var lieu = document.forms["Sosa"].elements["n_code"].value ;
		var reg  = new RegExp ("[,()]+", "g") ;
		var tableau = lieu.split(reg) ;

		if (tableau.length > 1)
			{
			document.forms["Sosa"].elements["n_code"].value = tableau[1] ;
			ch += (tableau[0] + "@") ;
			ch += (tableau[1] + "@") ;
			}
		else
			{
			ch += ("@") ;
			ch += (document.forms["Sosa"].elements["n_code"].value + "@") ;
			}

		ch += (document.forms["Sosa"].elements["d_jour"].value + "@") ;
		ch += (document.forms["Sosa"].elements["d_mois"].value + "@") ;
		ch += (document.forms["Sosa"].elements["d_annee"].value + "@") ;

		var lieu = document.forms["Sosa"].elements["d_code"].value ;
		var reg  = new RegExp ("[,()]+", "g") ;
		var tableau = lieu.split(reg) ;

		if (tableau.length > 1)
			{
			document.forms["Sosa"].elements["d_code"].value = tableau[1] ;
			ch += (tableau[0] + "@") ;
			ch += (tableau[1] + "@") ;
			}
		else
			{
			ch += ("@") ;
			ch += (document.forms["Sosa"].elements["d_code"].value + "@") ;
			}

		document.getElementById("Sosa").parentNode.removeChild(document.getElementById("Sosa")) ;

		xhr.open ("POST", "ajaxAjoutEnfant.php", true) ;
		}
	else if (a == 2)												// Ajout nouveau personnage
		{
		if (document.forms["Sosa"].elements["prenom"].value == "")
			{
			alert ("Veuillez saisir le prénom !\n\nSi prénom inconnu :\nSaisissez N... pour un homme, Ne... pour une femme.") ;

			return;
			}
			
		if (n > 1)
			sexe = n%2 ;
		else sexe = document.forms["Sosa"].elements["sexe"].value ;

		ch  = (relation + "@") ;
		ch += (document.forms["Modifier"].elements["base"].value + "@") ;
		ch += (enfant_numero + "@") ;
		ch += (document.forms["Sosa"].elements["nom"].value + "@") ;
		ch += (document.forms["Sosa"].elements["prenom"].value + "@") ;
		ch += (sexe + "@") ;

		ch += (document.forms["Sosa"].elements["n_jour"].value + "@") ;
		ch += (document.forms["Sosa"].elements["n_mois"].value + "@") ;
		ch += (document.forms["Sosa"].elements["n_annee"].value + "@") ;

		var lieu = document.forms["Sosa"].elements["n_code"].value ;
		var reg  = new RegExp ("[,()]+", "g") ;
		var tableau = lieu.split(reg) ;

		if (tableau.length > 1)
			{
			document.forms["Sosa"].elements["n_code"].value = tableau[1] ;
			ch += (tableau[0] + "@") ;
			ch += (tableau[1] + "@") ;
			}
		else
			{
			ch += ("@") ;
			ch += (document.forms["Sosa"].elements["n_code"].value + "@") ;
			}

		ch += (document.forms["Sosa"].elements["d_jour"].value + "@") ;
		ch += (document.forms["Sosa"].elements["d_mois"].value + "@") ;
		ch += (document.forms["Sosa"].elements["d_annee"].value + "@") ;

		var lieu = document.forms["Sosa"].elements["d_code"].value ;
		var reg  = new RegExp ("[,()]+", "g") ;
		var tableau = lieu.split(reg) ;

		if (tableau.length > 1)
			{
			document.forms["Sosa"].elements["d_code"].value = tableau[1] ;
			ch += (tableau[0] + "@") ;
			ch += (tableau[1] + "@") ;
			}
		else
			{
			ch += ("@") ;
			ch += (document.forms["Sosa"].elements["d_code"].value + "@") ;
			}

		document.getElementById("Sosa").parentNode.removeChild(document.getElementById("Sosa")) ;

		xhr.open ("POST", "ajaxAjoutNouveau.php", true) ;
		}
	else															// Modification personnage
		{
		ch  = (document.forms["Modifier"].elements["base"].value + "@") ;
		ch += (document.forms["Sosa"].elements["numero"].value + "@") ;
		ch += (document.forms["Sosa"].elements["nom"].value + "@") ;
		ch += (document.forms["Sosa"].elements["prenom"].value + "@") ;

		ch += (document.forms["Sosa"].elements["n_jour"].value + "@") ;
		ch += (document.forms["Sosa"].elements["n_mois"].value + "@") ;
		ch += (document.forms["Sosa"].elements["n_annee"].value + "@") ;		

		var lieu = document.forms["Sosa"].elements["n_code"].value ;
		var reg  = new RegExp ("[,()]+", "g") ;
		var tableau = lieu.split(reg) ;

		if (tableau.length > 1)
			{
			document.forms["Sosa"].elements["n_code"].value = tableau[1] ;
			ch += (tableau[0] + "@") ;
			ch += (tableau[1] + "@") ;
			}
		else
			{
			ch += ("@") ;
			ch += (document.forms["Sosa"].elements["n_code"].value + "@") ;
			}

		ch += (document.forms["Sosa"].elements["d_jour"].value + "@") ;
		ch += (document.forms["Sosa"].elements["d_mois"].value + "@") ;
		ch += (document.forms["Sosa"].elements["d_annee"].value + "@") ;

		var lieu = document.forms["Sosa"].elements["d_code"].value ;
		var reg  = new RegExp ("[,()]+", "g") ;
		var tableau = lieu.split(reg) ;

		if (tableau.length > 1)
			{
			document.forms["Sosa"].elements["d_code"].value = tableau[1] ;
			ch += (tableau[0] + "@") ;
			ch += (tableau[1] + "@") ;
			}
		else
			{
			ch += ("@") ;
			ch += (document.forms["Sosa"].elements["d_code"].value + "@") ;
			}

		document.getElementById("Sosa").parentNode.removeChild(document.getElementById("Sosa")) ;

		xhr.open ("POST", "ajaxValidationSujet.php", true) ;
		}
		
	xhr.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded') ;
	xhr.send ("idChaine=" + ch) ;
	}

function js_IndiquerSexeSosa ()
	{
	if (n > 1) return ;
	
	var sexe = document.forms["Sosa"].elements["sexe"].value ;

	if (sexe > 1) alert ("Veuillez sélectionner le sexe !") ;
	}

function js_ChercheNomSosa ()
	{
	var xhr = getHTTPObject () ;

	var navigateur = navigator.appName ;
					
//	On définit 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)
			{
			resultat = xhr.responseText ;
			
			var personne = resultat.split(";") ;			

			var libelle ;
			
			var i = 0 ;
						
			while (personne[i] != "")
				{
				if (i == 0)
					{
					document.getElementById("smiley").style.display = "block" ;

					var liste = document.getElementById("liste") ;

					texte = document.createElement("div") ;
					texte.innerHTML = "<font color='red'><b>Vous êtes en train de saisir un nouveau personnage</b></font><br>Peut-être figure-t-il déjà dans la base généalogique ?<br>Si oui, sélectionnez-le dans la liste suivante :<br>" ;	
					liste.appendChild(texte) ;

					ret = document.createElement("br") ;
					liste.appendChild(ret) ;
					
					if (navigateur == "Netscape")
						{
						perso = document.createElement("input") ;
						perso.name  = "perso" ;
						perso.type  = "radio" ;
						perso.id    = "perso0" ;
						perso.value = 0 ;
						perso.setAttribute('onClick', 'js_SelectPersonne1('+ i + ',0)') ;
						}
					else
						{
						p = "<input type='radio' name='perso' id='perso0' value='0' onClick='js_SelectPersonne1(0, 0)'>" ;
						perso = document.createElement (p) ;
						}

					liste.appendChild(perso) ;
	
					texte = document.createElement("span") ;
					texte.innerHTML = "Création d'un nouveau personnage" ;	
					liste.appendChild(texte) ;

					ret = document.createElement("br") ;
					liste.appendChild(ret) ;
					}
					
				option = personne[i].split("@") ;
				
				var base = document.forms["Modifier"].elements["base"].value ;
				
				var loupe = "<a href='G_Personnage.php?base=" + base + "&n=" + option[0] + "' target='wclose'" ;
				loupe += "onclick=\"window.open('G_Personnage.php?base=" + base + "&n=" + option[0] + "' ,'wclose', 'width=380, height=180, toolbar=no, scrollbars=yes, status=no, left=264, top=170')\">" ;
				loupe += "<img src='images/loupe.png' border='0'></a>" ;
	
				libelle = option[2] + " " + option[1] + " (" + option[5] + "-" + option[9] + ")" + loupe ;
				
				liste = document.getElementById("liste") ;
				liste.style.backgroundColor = "#FFC0C0" ;	

				if (navigateur == "Netscape")
					{
					perso = document.createElement("input") ;
					perso.name  = "perso" ;
					perso.type  = "radio" ;
					perso.id    = "perso" + (i+1) ;
					perso.value = (i+1) ;
					perso.setAttribute('onClick', 'js_SelectPersonne1('+ option[0] + ',0)') ;
					}
				else
					{
					p = "<input type='radio' name='perso' id='perso" + (i+1) + "' value='" + (i+1) + "' onClick='js_SelectPersonne1(" + option[0] + ", 0)'>" ;
					perso = document.createElement (p) ;					
					}

				liste.appendChild(perso) ;

				texte = document.createElement("span") ;
				texte.innerHTML = libelle ;
				liste.appendChild(texte) ;

				ret = document.createElement("br") ;
				liste.appendChild(ret) ;
				
				i++ ;
				}

/////		liste = document.getElementById("Fiche") ;					// Redimensionnement de la fiche
/////		liste.style.height = perso.offsetTop + 380 + "px" ;			
			}		
		}
		
	if (n > 1)
		sexe = n%2 ;
	else	sexe = document.forms["Sosa"].elements["sexe"].value ;
		
	ch  = (document.forms["Modifier"].elements["base"].value + "@") ;
	ch += (document.forms["Sosa"].elements["nom"].value + "@") ;
	ch += (document.forms["Sosa"].elements["prenom"].value + "@") ;
	ch += (sexe + "@") ;

	xhr.open ("POST", "ajaxRecherche.php", true) ;
	xhr.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded') ;
	xhr.send ("idChaine=" + ch) ;
	}

function js_SelectPersonne1 (numero, n)
	{
	var xhr = getHTTPObject () ;

//	On définit 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)
			{
			resultat = xhr.responseText ;
			
			document.getElementById("smiley").style.display = "none" ;

			if (resultat != "Nouveau")
				{
				var ch = resultat.split("@") ;

//				On se sert de innerHTML pour afficher dans les champs

				document.forms["Sosa"].elements["nom"].value = ch[1] ;
				document.forms["Sosa"].elements["prenom"].value = ch[2] ;

				document.forms["Sosa"].elements["n_jour"].value = ch[3] ;
				document.forms["Sosa"].elements["n_mois"].value = ch[4] ;
				document.forms["Sosa"].elements["n_annee"].value = ch[5] ;
//				document.forms["Sosa"].elements["n_lieu"].value = ch[6] ;
//				document.forms["Sosa"].elements["n_dpt"].value = ch[7] ;
				document.forms["Sosa"].elements["n_code"].value = ch[7] ;

				document.forms["Sosa"].elements["d_jour"].value = ch[8] ;
				document.forms["Sosa"].elements["d_mois"].value = ch[9] ;
				document.forms["Sosa"].elements["d_annee"].value = ch[10] ;
//				document.forms["Sosa"].elements["d_lieu"].value = ch[11] ;
//				document.forms["Sosa"].elements["d_dpt"].value = ch[12] ;				
				document.forms["Sosa"].elements["d_code"].value = ch[12] ;

				relation = numero ;				

				alert ("Relation établie : vous pouvez compléter puis valider !") ;
				}
				
			js_EffaceListe () ;
			}		
		}
		
	ch = document.forms["Modifier"].elements["base"].value + "@" + numero ;

	xhr.open ("POST", "ajaxSelection.php", true) ;
	xhr.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded') ;
	xhr.send ("idNumero=" + ch) ;
	}

function js_Arbre()
	{
	var base = document.forms["Modifier"].elements["base"].value ;
	var url  = window.location.toString().split('?') ;				
	url[0] += "?base=" + base + "&n=1" ;
			
	window.location.replace (url[0]) ;
	}
	
function js_Supprimer(a)
	{
	if (num_sosa == 0)
		{
		alert ("Choix invalide !") ;
		}
	else
		{
		var base = document.forms["Modifier"].elements["base"].value ;		
		var url  = "G_Suppression.php?base=" + base + "&type=" + a + "&n=" + n ;

		window.open (url, "wclose", "width=380,height=300,toolbar=no,scrollbars=no,status=no,left=240,top=170") ;
		}
	}

function js_Ancetres()
	{
	if (num_sosa == 0)
		{
		alert ("Choix invalide !") ;
		}
	else
		{
		var base = document.forms["Modifier"].elements["base"].value ;
		var url  = "G_Asc.php?base=" + base + "&n=" + n ;

		window.open (url) ;
		}
	}

function js_Descendants()
	{
	if (num_sosa == 0)
		{
		alert ("Choix invalide !") ;
		}
	else
		{
		var base = document.forms["Modifier"].elements["base"].value ;
		var url  = "G_Desc.php?base=" + base + "&n=" + n ;

		window.open (url) ;
		}
	}

function js_Parente()
	{
	if (num_sosa == 0)
		{
		alert ("Choix invalide !") ;
		}
	else
		{
		var base = document.forms["Modifier"].elements["base"].value ;
		var url  = "G_Liste.php?base=" + base + "&n=" + n ;

//		window.open (url, "wclose", "width=740,height=400,toolbar=no,scrollbars=no,status=no,left=240,top=170") ;
		window.open (url, "wclose", "width=940,height=400,toolbar=no,scrollbars=no,status=no,left=240,top=170") ;
		}
	}

function js_Infos()
	{
	if (num_sosa == 0)
		{
		alert ("Choix invalide !") ;
		}
	else
		{
		var base = document.forms["Modifier"].elements["base"].value ;
		var url  = "G_Infos.php?base=" + base + "&n=" + n ;

		window.open (url, "wclose", "width=380,height=400,toolbar=no,scrollbars=no,status=no,left=240,top=170") ;
		}
	}

function js_Histo()
	{
	if (num_sosa == 0)
		{
		alert ("Choix invalide !") ;
		}
	else
		{
		var base = document.forms["Modifier"].elements["base"].value ;
		var url  = "G_Histo.php?base=" + base + "&n=" + n ;

		window.open (url, "wclose", "width=380,height=400,toolbar=no,scrollbars=no,status=no,left=240,top=170") ;
		}
	}

function js_Message()
	{
	if (num_sosa == 0)
		{
		alert ("Choix invalide !") ;
		}
	else
		{
		var base = $("#f_base").val() ;
		var url  = "G_Infos3.php?base=" + base + "&n=" + n ;

		window.open (url, "wclose", "width=480,height=400,toolbar=no,scrollbars=yes,status=no,left=240,top=170") ;
		}
	}

function js_Habilitation()
	{
	if (num_sosa == 0)
		{
		alert ("Choix invalide !") ;
		return ;
		}

	if (document.forms["Modifier"].elements["btn_modifier_sujet"].disabled == true)
		{
		alert ("Vous ne vous êtes pas identifié !") ;
		return ;
		}
	
	var base = document.forms["Modifier"].elements["base"].value ;
	var url  = "G_Habilitation.php?base=" + base + "&n=" + n ;

	window.open (url, "wclose", "width=380,height=400,toolbar=no,scrollbars=no,status=no,left=240,top=170") ;
	}

function js_Nouveau()
	{
	if ((n > 1) && (num_sosa != 0))
		{
		alert ("Choix invalide !") ;
		}
	else
		{
		js_OuvreSosa(2) ;
		}
	}

menu_elemt     = new Array ;
menu_elemt[0]  = "Informations supplémentaires|js_Infos()" ;
menu_elemt[1]  = "Historique des modifications|js_Histo()" ;
menu_elemt[2]  = "Ecrire aux auteurs|js_Message()" ;
menu_elemt[3]  = "" ;
menu_elemt[4]  = "Liste des ancêtres|js_Ancetres()" ;
menu_elemt[5]  = "Liste des descendants|js_Descendants()" ;
menu_elemt[6]  = "Parenté avec...|js_Parente()" ;
menu_elemt[7]  = "" ;
menu_elemt[8]  = "Saisie d'un nouveau personnage|js_Nouveau()" ;
menu_elemt[9]  = "" ;
menu_elemt[10] = "Modification|js_OuvreSosa(80)" ;
menu_elemt[11] = "Suppression totale|js_Supprimer('t')" ;
menu_elemt[12] = "Suppression lien père|js_Supprimer('p')" ;
menu_elemt[13] = "Suppression lien mère|js_Supprimer('m')" ;
menu_elemt[14] = "Suppression lien conjoint|js_Supprimer('c')" ;
menu_elemt[15] = "" ;
menu_elemt[16] = "Demande d'habilitation|js_Habilitation()" ;

function menu_position(e)
	{
//	menu_x = (navigator.appName == "Netscape") ? e.pageX : event.x+document.body.scrollLeft ;
//	menu_y = (navigator.appName == "Netscape") ? e.pageY : event.y+document.body.scrollTop ;
	menu_x = (navigator.appName == "Netscape") ? e.pageX : event.x+document.documentElement.scrollLeft ;
	menu_y = (navigator.appName == "Netscape") ? e.pageY : event.y+document.documentElement.scrollTop ;
	}

function menu_open()
	{
	n = 0 ;
	
	if (menu_x>$Fx[1] && menu_x<$Fx[1]+$lg && menu_y>$Fy[1] && menu_y<$Fy[1]+$ht) n = 1 ;
	else if (menu_x>$Fx[2] && menu_x<$Fx[2]+$lg && menu_y>$Fy[2] && menu_y<$Fy[2]+$ht) n = 2 ;
	else if (menu_x>$Fx[3] && menu_x<$Fx[3]+$lg && menu_y>$Fy[3] && menu_y<$Fy[3]+$ht) n = 3 ;
	else if (menu_x>$Fx[4] && menu_x<$Fx[4]+$lg && menu_y>$Fy[4] && menu_y<$Fy[4]+$ht) n = 4 ;
	else if (menu_x>$Fx[5] && menu_x<$Fx[5]+$lg && menu_y>$Fy[5] && menu_y<$Fy[5]+$ht) n = 5 ;
	else if (menu_x>$Fx[6] && menu_x<$Fx[6]+$lg && menu_y>$Fy[6] && menu_y<$Fy[6]+$ht) n = 6 ;
	else if (menu_x>$Fx[7] && menu_x<$Fx[7]+$lg && menu_y>$Fy[7] && menu_y<$Fy[7]+$ht) n = 7 ;
	else if (menu_x>$Fx[8] && menu_x<$Fx[8]+$lg && menu_y>$Fy[8] && menu_y<$Fy[8]+$ht) n = 8 ;
	else if (menu_x>$Fx[9] && menu_x<$Fx[9]+$lg && menu_y>$Fy[9] && menu_y<$Fy[9]+$ht) n = 9 ;
	else if (menu_x>$Fx[10] && menu_x<$Fx[10]+$lg && menu_y>$Fy[10] && menu_y<$Fy[10]+$ht) n = 10 ;
	else if (menu_x>$Fx[11] && menu_x<$Fx[11]+$lg && menu_y>$Fy[11] && menu_y<$Fy[11]+$ht) n = 11 ;
	else if (menu_x>$Fx[12] && menu_x<$Fx[12]+$lg && menu_y>$Fy[12] && menu_y<$Fy[12]+$ht) n = 12 ;
	else if (menu_x>$Fx[13] && menu_x<$Fx[13]+$lg && menu_y>$Fy[13] && menu_y<$Fy[13]+$ht) n = 13 ;
	else if (menu_x>$Fx[14] && menu_x<$Fx[14]+$lg && menu_y>$Fy[14] && menu_y<$Fy[14]+$ht) n = 14 ;
	else if (menu_x>$Fx[15] && menu_x<$Fx[15]+$lg && menu_y>$Fy[15] && menu_y<$Fy[15]+$ht) n = 15 ;

	if (n)
		{
		num_sosa = document.getElementById("sosa"+n).innerHTML ;

		document.getElementById("menu_box").style.top = menu_y + "px" ;
		document.getElementById("menu_box").style.left = menu_x + "px" ;
		document.getElementById("menu_ombre").style.top = menu_y+2 + "px" ;
		document.getElementById("menu_ombre").style.left = menu_x+2 + "px" ;
	
		if (num_sosa == 0)
			{
//			document.getElementById("menu_box").style.visibility = "hidden" ;
//			document.getElementById("menu_ombre").style.visibility = "hidden" ;
			document.getElementById("menu_box").style.visibility = "visible" ;
			document.getElementById("menu_ombre").style.visibility = "visible" ;
			}
		else
			{
			document.getElementById("menu_box").style.visibility = "visible" ;
			document.getElementById("menu_ombre").style.visibility = "visible" ;
			}

		return (false) ;
		}
	else	return (true) ;
	}

function menu_close()
	{
	if (document.getElementById)
		{
		document.getElementById("menu_box").style.top = 0 ;
		document.getElementById("menu_box").style.left = 0 ;
		document.getElementById("menu_ombre").style.top = 0 ;
		document.getElementById("menu_ombre").style.left = 0 ;
		document.getElementById("menu_box").style.visibility = "hidden" ;
		document.getElementById("menu_ombre").style.visibility = "hidden" ;
		}
	}

function menu_hl(mode, element)
	{
	if(mode == 1)
		{
		element.style.background = '#93A070' ;
		element.style.color = '#FFFFFF' ;
		}
	else
		{
		element.style.background ='#EED7A3' ;
		element.style.color = '#000000' ;
		}
	}

if(navigator.appName == "Netscape")
	document.captureEvents(Event.MOUSEMOVE) ;

