/*#######################################
	LISTES UTILES
#########################################*/
var listeMois = new Array(12);
listeMois[0]= new Array('1','01');
listeMois[1]= new Array('2','02');
listeMois[2]= new Array('3','03');
listeMois[3]= new Array('4','04');
listeMois[4]= new Array('5','05');
listeMois[5]= new Array('6','06');
listeMois[6]= new Array('7','07');
listeMois[7]= new Array('8','08');
listeMois[8]= new Array('9','09');
listeMois[9]= new Array('10','10');
listeMois[10]= new Array('11','11');
listeMois[11]= new Array('12','12');
var anneeCourante = (new Date()).getFullYear();
var listeAnnee = new Array(anneeCourante-1899);
cpt=0;
for (a=anneeCourante; a>1899; a--){
	listeAnnee[cpt] = a;
	cpt++;
}

var listeAnneeFutur = new Array(2100-anneeCourante);
cpt=0;
for (a=anneeCourante; a<2100; a++){
	listeAnneeFutur[cpt] = a;
	cpt++;
}

function loyerAMontrer(){

	if(document.forms['ouverture'].elements['situationImmobiliere'].selectedIndex == 2){
		ajouterLoyer( 'loyer');
	}else{
		supprimerLoyer();
	}
}

function nomjf(prsNo){
	if(prsNo==1 && document.forms['ouverture'].elements['Mme'].checked){
		//document.forms['ouverture'].elements['methode'].value="montrerjf";
		ajouterNomJf(prsNo, 'nomJeuneFille');
	}else if(prsNo==1 && (document.forms['ouverture'].elements['M'].checked || document.forms['ouverture'].elements['Mlle'].checked)){
		//document.forms['ouverture'].elements['methode'].value="cacherjf";
		supprimerNomJf(prsNo);
	}else if(prsNo==2 && document.forms['ouverture'].elements['MmeCoEmp'].checked){
		ajouterNomJf(prsNo, 'nomJeuneFilleCoEmp');
	}else if(prsNo==2 && (document.forms['ouverture'].elements['MCoEmp'].checked || document.forms['ouverture'].elements['MlleCoEmp'].checked)){
		supprimerNomJf(prsNo);
	}
	
	//document.forms['ouverture'].submit();
	
	
}

function nomjfco(){
	
	if(document.forms['ouverture'].elements['MmeCoEmp'].checked){
		montrer('nomjfcocache');
	}else if(document.forms['ouverture'].elements['MCoEmp'].checked || document.forms['ouverture'].elements['MlleCoEmp'].checked){
		cacher('nomjfcocache');
	}
	
	
}

function coemprunteurMC(){
	if(document.forms['ouverture'].elements['oui'].checked){
		document.forms['ouverture'].elements['methode'].value="montrer";
	}else if(document.forms['ouverture'].elements['non'].checked){
		document.forms['ouverture'].elements['methode'].value="cacher";
	}
	
	document.forms['ouverture'].submit();
	
}

/*#######################################
	FONCTIONS DE CREATION D'ELEMENTS HTML
#########################################*/

/**
 * Créer un champ de sélection (combo list)
 */
function creerSelect(selectId, selectName, selectClass, firstOptionValue, firstOptionLabel, list, labelEqualsValue, onchange){
	select = document.createElement('select');
	idSelect = document.createAttribute('id');
	idSelect.nodeValue = selectId;
	nameSelect = document.createAttribute('name');
	nameSelect.nodeValue = selectName;
	if (selectClass && selectClass!=''){
		classSelect = document.createAttribute('class');
		classSelect.nodeValue = selectClass;
		select.setAttributeNode(classSelect);
	}
	if (onchange && onchange!=''){
		onch = document.createAttribute('onchange');
		onch.nodeValue = 'javascript:'+onchange;
		select.setAttributeNode(onch);
	}
	select.setAttributeNode(idSelect);
	select.setAttributeNode(nameSelect);
	option = document.createElement('option');
	valueOption = document.createAttribute('value');
	valueOption.nodeValue = firstOptionValue;
	option.setAttributeNode(valueOption);
	libelleOption = document.createTextNode(firstOptionLabel);
	option.appendChild(libelleOption);
	select.appendChild(option);
	for(i=0; i<list.length; i++){
		option = document.createElement('option');
		valueOption = document.createAttribute('value');
		if (!labelEqualsValue){
			valueOption.nodeValue = list[i][0];
			libelleOption = document.createTextNode(list[i][1]);
		} else {
			valueOption.nodeValue = list[i];
			libelleOption = document.createTextNode(list[i]);
		}
		option.setAttributeNode(valueOption);
		option.appendChild(libelleOption);
		select.appendChild(option);
	}
	
	return select;
}

/**
 * Crée un champ input du type donné
 */
function creerInput(inputId, inputName, inputType, inputValue, inputClass){
	input = document.createElement('input');
	typeInput = document.createAttribute('type');
	typeInput.nodeValue = inputType;
	idInput = document.createAttribute('id');
	idInput.nodeValue = inputId;
	nameInput = document.createAttribute('name');
	nameInput.nodeValue = inputName;
	valueInput = document.createAttribute('value');
	valueInput.nodeValue = inputValue;
	if (inputClass && inputClass!=''){
		classInput = document.createAttribute('class');
		classInput.nodeValue=inputClass;
		input.setAttributeNode(classInput);
	}
	input.setAttributeNode(typeInput);
	input.setAttributeNode(idInput);
	input.setAttributeNode(nameInput);
	input.setAttributeNode(valueInput);
	
	return input;
}

/**
 * Crée une image
 */
function creerImage(imageId, imageSrc, imageWidth, imageHeight, imageAlt){
	image = document.createElement('img');
	idImage = document.createAttribute('id');
	idImage.nodeValue = imageId;
	srcImage = document.createAttribute('src');
	srcImage.nodeValue = imageSrc;
	wImage = document.createAttribute('width');
	wImage.nodeValue = imageWidth;
	hImage = document.createAttribute('height');
	hImage.nodeValue = imageHeight;
	altImage = document.createAttribute('alt');
	altImage.nodeValue = imageAlt;
	titleImage = document.createAttribute('title');
	titleImage.nodeValue = imageAlt;
	
	image.setAttributeNode(idImage);
	image.setAttributeNode(srcImage);
	image.setAttributeNode(wImage);
	image.setAttributeNode(hImage);
	image.setAttributeNode(altImage);
	
	return image;
}

/**
 * Cree un lien
 */
function creerLien(lienHref, lienClass){
	lien = document.createElement('a');
	hrefLien = document.createAttribute('href');
	hrefLien.nodeValue = lienHref;
	lien.setAttributeNode(hrefLien);
	
	if (lienClass && lienClass!=''){
		classLien = document.createAttribute('class');
		classLien.nodeValue = lienClass;
		lien.setAttributeNode(classLien);
	}
	
	return lien
}

/**
 * Crée un élément paragraphe
 */
function creerParagraphe(paragId, paragClass){
	ligne = document.createElement('p');
	if (paragId && paragId!=''){
		idLigne = document.createAttribute('id');
		idLigne.nodeValue = paragId;
		ligne.setAttributeNode(idLigne);
	}
	if (paragClass && paragClass!=''){
		classLigne = document.createAttribute('class');
		classLigne.nodeValue = paragClass;
		ligne.setAttributeNode(classLigne);
	}
	
	return ligne;
}

/**
 * Crée un label
 */
function creerLabel(labelFor, labelText, required, labelClass){
	label = document.createElement('label');
	forLabel = document.createAttribute('for');
	forLabel.nodeValue = labelFor;
	textLabel = document.createTextNode(labelText);
	if (labelClass){
		classLabel = document.createAttribute('class');
		classLabel.nodeValue = labelClass
		label.setAttributeNode(classLabel);
	}
	label.setAttributeNode(forLabel);
	label.appendChild(textLabel);
	
	if (required){	
		span = document.createElement('span');
		classSpan = document.createAttribute('class');
		classSpan.nodeValue = 'rouge';
		textSpan = document.createTextNode(' *');
		span.setAttributeNode(classSpan);
		span.appendChild(textSpan);
		
		space = document.createTextNode(' ');
		
		label.appendChild(span);
		label.appendChild(space);
	}
	
	return label;
}

/**
 * Crée un hr
 */
function creerSeparationHr(hrId, hrClass){
	hr = document.createElement('hr');
	idHr = document.createAttribute('id');
	idHr.nodeValue = hrId;
	hr.setAttributeNode(idHr);
	if (hrClass){
		classHr = document.createAttribute('class');
		classHr.nodeValue = hrClass;
		hr.setAttribute(classHr);	
	}
	
	return hr;
}

/**
 * Crée un fieldset
 */
function creerFieldset(fsId, fsClass){
	fs = document.createElement('fieldset');
	idFs = document.createAttribute('id');
	idFs.nodeValue=fsId;
	fs.setAttributeNode(idFs);
	if (fsClass){
		classFs = document.createAttribute('id');
		classFs.nodeValue = fsClass;
		fs.setAttributeNode(classFs);
	}
	return fs;
}

/**
 * Cree une légende
 */
function creerLegend(legendText, legendClass, legendId){
	legend = document.createElement('legend');
	if (legendId){
		idLegend = document.createAttribute('id');
		idLegend.nodeValue=legendId;
		legend.setAttributeNode(idLegend);
	}
	if (legendClass){
		classLegend = document.createAttribute('id');
		classLegend.nodeValue = legendClass;
		legend.setAttributeNode(classLegend);
	}
	txtLegend = document.createTextNode(legendText);
	legend.appendChild(txtLegend);
	
	return legend;
}

/*###############################################
	FONCTIONS DE CREATION DE LIGNES DE FORMULAIRE
#################################################*/

/**
 *
 */
function creerLigneInput(ligneId, inputId, inputName, labelText, inputType, inputValue, required, inputClass ){
	ligne = creerParagraphe(ligneId);
	label = creerLabel(inputId, labelText, required);
	input = creerInput(inputId, inputName, inputType, inputValue, inputClass);
	
	ligne.appendChild(label);
	ligne.appendChild(input);
	
	return ligne;
}

function creerLigneSelect(ligneId, selectId, selectName, selectClass, firstOptionValue, firstOptionLabel, list, labelEqualsValue, labelText, required, onchange){
	ligne = creerParagraphe(ligneId);
	label = creerLabel(selectId, labelText, required);
	select = creerSelect(selectId, selectName, selectClass, firstOptionValue, firstOptionLabel, list, labelEqualsValue, onchange);
	
	ligne.appendChild(label);
	ligne.appendChild(select);
	
	return ligne;
	
}

function creerLigneDateMmAaaa(ligneId, selectMoisId, selectMoisName, selectAnneeId, selectAnneeName, labelText, required, futur){
	ligne = creerParagraphe(ligneId);
	label = creerLabel(selectMoisId, labelText, required);
	selectMois = creerSelect(selectMoisId, selectMoisName, 'select-mmaa-mm', '0', 'Mois', listeMois, false);
	if (futur){
		liste = listeAnneeFutur;
	} else {
		liste = listeAnnee;
	}
	selectAnnee = creerSelect(selectAnneeId, selectAnneeName, 'select-mmaa-aa', '0', 'Annee', liste, true);
	
	ligne.appendChild(label);
	ligne.appendChild(selectMois);
	ligne.appendChild(selectAnnee);
	
	return ligne;
}

/*###############################################
	FONCTIONS D'AFFICHAGE/MASQUAGE SPECIFIQUE
#################################################*/


/**
 * Fonction qui ajoute un champ de saisie de revenu sur la page budget
 */
function ajouterChampRevenu(listTypes, nomListeTypes, classSelect, classInput){
	var nb = document.forms['ouverture'].elements['nbRevenusAffiches'].value;
	if (nb<3){
		nb++;
		//on récupère l'élément "père" auquel on veut ajouter une ligne
		blocRevenus = document.getElementById('blocRevenus');
		//on crée le paragraphe et ses éléments
		ligneType = creerLigneSelect('typeRevenu'+nb, 'natureAutreRevenu'+nb, 'natureAutreRevenu'+nb, classSelect, '', 'Choisissez un type de revenu', listTypes, false, 'Type de revenu', true);
		ligneMontant = creerLigneInput('montantRevenu'+nb, 'montantAutreRevenu'+nb, 'montantAutreRevenu'+nb, 'Montant net', 'text', '0', true );
		postHr = creerSeparationHr('hrRevenu'+nb);

		//on met à jour la ligne contenant le bouton de suppression
		ligneAjout = document.getElementById('ajoutRevenu');
		ligneSuppr = document.getElementById('supprRevenu');
		if (ligneSuppr){
			blocRevenus.removeChild(ligneSuppr);
		}
		ligneSuppr = creerBoutonSuppressionRevenu(nomListeTypes, classSelect, classInput, nb)
		blocRevenus.insertBefore(ligneSuppr, ligneAjout);
		
		//on place les éléments créés dans l'arbre de la page
		ligneSuppr = document.getElementById('supprRevenu');
		blocRevenus.insertBefore(postHr, ligneSuppr);
		blocRevenus.insertBefore(ligneMontant, postHr);
		blocRevenus.insertBefore(ligneType, ligneMontant);
		if (nb==1){
			preHr = creerSeparationHr('hrRevenu'+(nb-1));
			blocRevenus.insertBefore(preHr, ligneType);
		}
		
		//on supprime le bouton d'ajout si il y a 3 credits affichés
		if(nb==3){
			blocRevenus.removeChild(ligneAjout);
		}
		
		//on incrémente le nombre de crédit
		document.forms['ouverture'].elements['nbRevenusAffiches'].value=nb;
	}
}

/**
 * Fonction qui ajoute le bouton d'ajout de revenu sur la page budget
 */
function ajouterBoutonAjoutRevenu(nomListeTypes, classSelect, classInput){
	var nb = document.forms['ouverture'].elements['nbRevenusAffiches'].value;
	if (nb<3){
		ligne = creerParagraphe('ajoutRevenu','text-aligner-input');
		
		image = creerImage('ajouterRevenu', '../../../ressources/commun/img/boutons/bouton-vert-clair-ajouter-s.png', '190', '19', 'Ajouter une source de revenu');
		lien = creerLien('javascript:ajouterChampRevenu('+nomListeTypes+',\''+nomListeTypes+'\',\''+classSelect+'\',\''+classInput+'\');');
		lien.appendChild(image);
		
		ligne.appendChild(lien);
		
		blocRevenus = document.getElementById('blocRevenus');
		ligneBas = blocRevenus.lastChild;
		while (ligneBas.nodeType!=1){
			ligneBas = ligneBas.previousSibling;
		}
		
		blocRevenus.insertBefore(ligne, ligneBas);
	}
}

/**
 * Fonction qui crée le bouton d'ajout de revenu sur la page budget
 */
function creerBoutonSuppressionRevenu(nomListeTypes, classSelect, classInput, nb){
	ligne = creerParagraphe('supprRevenu','text-aligner-input');
	
	image = creerImage('supprimerRevenu'+nb, '../../../ressources/commun/img/boutons/bouton-vert-clair-sup-s.png', '190', '19', 'Supprimer un crédit');
	lien = creerLien('javascript:supprimerChampRevenu(\''+nomListeTypes+'\', \''+classSelect+'\', \''+classInput+'\');');
	lien.appendChild(image);
	ligne.appendChild(lien);
	
	return ligne;
}

/**
 *
 */
function ajouterBoutonSuppressionRevenu(nomListeTypes, classSelect, classInput){
	var nb = document.forms['ouverture'].elements['nbRevenusAffiches'].value;
	if (nb>0){		
		ligneBtSuppr = creerBoutonSuppressionRevenu(nomListeTypes, classSelect, nb);
				
		blocRevenus = document.getElementById('blocRevenus');
		if (nb<3){
			ligneBtAjout = document.getElementById('ajoutRevenu');
			blocRevenus.insertBefore(ligneBtSuppr, ligneBtAjout);
		} else {
			ligneBas = blocRevenus.lastChild;
			while (ligneBas.nodeType!=1){
				ligneBas = ligneBas.previousSibling;
			}
			blocRevenus.insertBefore(ligneBtSuppr, ligneBas);
		}
	}
}

/**
 * Fonction qui supprime un champ de saisie de revenu sur la page budget
 */
function supprimerChampRevenu(nomListeTypes, classSelect, classInput){
	var nb = document.forms['ouverture'].elements['nbRevenusAffiches'].value;
	blocRevenus = document.getElementById('blocRevenus');
	
	//on supprime les deux lignes correspondant au revenu
	ligneASuppr = document.getElementById('typeRevenu'+nb);
	ligneASuppr2 = document.getElementById('montantRevenu'+nb);
	postHr = document.getElementById('hrRevenu'+nb);
	blocRevenus.removeChild(postHr);
	blocRevenus.removeChild(ligneASuppr);
	blocRevenus.removeChild(ligneASuppr2);
	if (nb==1){
		preHr = document.getElementById('hrRevenu'+(nb-1));
		blocRevenus.removeChild(preHr);
	}
	
	//on décrémente le nombre de revenus
	document.forms['ouverture'].elements['nbRevenusAffiches'].value=--nb;
	
	//on supprime la ligne du bouton supprimer
	ligneBtSuppr = document.getElementById('supprRevenu');
	if (ligneBtSuppr){
		blocRevenus.removeChild(ligneBtSuppr);
	}
	
	//si le nouveau nombre est à 2, on ajoute le bouton d'ajout
	if (nb==2){
		ajouterBoutonAjoutRevenu(nomListeTypes, classSelect, classInput);
	}
	
	//si il y a au moins un revenu affiché, on réécrit le bouton de suppression
	if (document.forms['ouverture'].elements['nbRevenusAffiches'].value >0){
		ligneBtSuppr = creerBoutonSuppressionRevenu(nomListeTypes, classSelect, classInput, document.forms['ouverture'].elements['nbRevenusAffiches'].value);
		ligneBtAjout = document.getElementById('ajoutRevenu');
		blocRevenus.insertBefore(ligneBtSuppr, ligneBtAjout);
	}
}

/**
 * Fonction qui ajoute un champ de saisie de credit sur la page budget
 */
function ajouterChampCredit(listTypes, nomListeTypes, classSelect, classInput){
	var nb = document.forms['ouverture'].elements['nbCreditsAffiches'].value;
	if (nb<3){
		++nb;
		//on récupère l'élément "père" auquel on veut ajouter une ligne
		blocCharges = document.getElementById('blocCharges');
		
		//on crée le paragraphe et ses éléments
		postHr = creerSeparationHr('hrCredit'+nb);
		ligneType = creerLigneSelect('typeCredit'+nb, 'natureAutreCredit'+nb, 'natureAutreCredit'+nb, classSelect, '', 'Choisissez un type de crédit', listTypes, false, 'Type de crédit', true);
		ligneMontant = creerLigneInput('montantCredit'+nb, 'montantAutreCredit'+nb, 'montantAutreCredit'+nb, 'Montant net', 'text', '0', true );
		ligneDate = creerLigneDateMmAaaa('dateCredit'+nb, 'moisDateAutreCredit'+nb, 'moisDateAutreCredit'+nb, 'anneeDateAutreCredit'+nb, 'anneeDateAutreCredit'+nb, 'Jusque', true, true);
		
		//on met à jour la ligne de suppression de credit
		ligneAjout = document.getElementById('ajoutCredit');
		ligneSuppr = document.getElementById('supprCredit');
		if (ligneSuppr){
			blocCharges.removeChild(ligneSuppr);
		}
		ligneSuppr = creerBoutonSuppressionCredit(nomListeTypes, classSelect, classInput, nb)
		blocCharges.insertBefore(ligneSuppr, ligneAjout);
		
		//on place les éléments dans l'arbre
		ligneSuppr = document.getElementById('supprCredit');
		blocCharges.insertBefore(postHr, ligneSuppr);
		blocCharges.insertBefore(ligneDate, postHr);
		blocCharges.insertBefore(ligneMontant, ligneDate);
		blocCharges.insertBefore(ligneType, ligneMontant);
		if (nb==1){
			preHr = creerSeparationHr('hrCredit'+(nb-1));
			blocCharges.insertBefore(preHr, ligneType);
		}
		
		if(nb==3){
			blocCharges.removeChild(ligneAjout);
		}
		
		document.forms['ouverture'].elements['nbCreditsAffiches'].value=nb;
	}
}

/**
 * Fonction qui ajoute le bouton d'ajout de credit sur la page budget
 */
function ajouterBoutonAjoutCredit(nomListeTypes, classSelect, classInput){
	var nb = document.forms['ouverture'].elements['nbCreditsAffiches'].value;
	if (nb<3){
		ligne = creerParagraphe('ajoutCredit','text-aligner-input');
		
		
		image = creerImage('ajouterCredit', '../../../ressources/commun/img/boutons/bouton-vert-clair-ajouter-c.png', '130', '19', 'Ajouter un crédit');
		lien = creerLien('javascript:ajouterChampCredit('+nomListeTypes+',\''+nomListeTypes+'\',\''+classSelect+'\',\''+classInput+'\');');
		lien.appendChild(image);
		
		ligne.appendChild(lien);
		ligneBas = document.getElementById('blocCharges').lastChild;
		while (ligneBas.nodeType!=1){
			ligneBas = ligneBas.previousSibling;
		}
		document.getElementById('blocCharges').insertBefore(ligne, ligneBas);
	}
}

/**
 * Fonction qui crée le bouton d'ajout de credit sur la page budget
 */
function creerBoutonSuppressionCredit(nomListeTypes, classSelect, classInput, nb){
	ligne = creerParagraphe('supprCredit','text-aligner-input');
	
	image = creerImage('supprimerCredit'+nb, '../../../ressources/commun/img/boutons/bouton-vert-clair-sup-c.png', '130', '19', 'Supprimer un crédit');
	lien = creerLien('javascript:supprimerChampCredit(\''+nomListeTypes+'\', \''+classSelect+'\', \''+classInput+'\');');
	lien.appendChild(image);
	ligne.appendChild(lien);
	
	return ligne;
}

/**
 *
 */
function ajouterBoutonSuppressionCredit(nomListeTypes, classSelect, classInput){
	var nb = document.forms['ouverture'].elements['nbCreditsAffiches'].value;
	if (nb>0){		
		ligneBtSuppr = creerBoutonSuppressionCredit(nomListeTypes, classSelect, classInput, nb);
				
		blocCharges = document.getElementById('blocCharges');
		if (nb<3){
			ligneBtAjout = document.getElementById('ajoutCredit');
			blocCharges.insertBefore(ligneBtSuppr, ligneBtAjout);
		} else {
			ligneBas = blocCharges.lastChild;
			while (ligneBas.nodeType!=1){
				ligneBas = ligneBas.previousSibling;
			}
			blocCharges.insertBefore(ligneBtSuppr, ligneBas);
		}
	}
}

/**
 * Fonction qui supprime un champ de saisie de credit sur la page budget
 */
function supprimerChampCredit(nomListeTypes, classSelect, classInput){
	var nb = document.forms['ouverture'].elements['nbCreditsAffiches'].value;
	blocCharges = document.getElementById('blocCharges');
	
	//on supprime les lignes
	postHr = document.getElementById('hrCredit'+nb);
	ligneASuppr = document.getElementById('typeCredit'+nb);
	ligneASuppr2 = document.getElementById('montantCredit'+nb);
	ligneASuppr3 = document.getElementById('dateCredit'+nb);
	blocCharges.removeChild(postHr);
	blocCharges.removeChild(ligneASuppr);
	blocCharges.removeChild(ligneASuppr2);
	blocCharges.removeChild(ligneASuppr3);
	if (nb==1){
		preHr = document.getElementById('hrCredit'+(nb-1));
		blocCharges.removeChild(preHr);
	}
	
	//on décrémente
	document.forms['ouverture'].elements['nbCreditsAffiches'].value=--nb;
	
	//on supprime la ligne du bouton supprimer
	ligneBtSuppr = document.getElementById('supprCredit');
	if (ligneBtSuppr){
		blocCharges.removeChild(ligneBtSuppr);
	}
	
	//si le nouveau nombre est à 2, on ajoute le bouton d'ajout
	if (nb==2){
		ajouterBoutonAjoutCredit(nomListeTypes, classSelect, classInput);
	}
	
	//si il y a au moins un credit affiché, on réécrit le bouton de suppression
	if (document.forms['ouverture'].elements['nbCreditsAffiches'].value >0){
		ligneBtSuppr = creerBoutonSuppressionCredit(nomListeTypes, classSelect, classInput, document.forms['ouverture'].elements['nbCreditsAffiches'].value);
		ligneBtAjout = document.getElementById('ajoutCredit');
		blocCharges.insertBefore(ligneBtSuppr, ligneBtAjout);
	}
}



/**
 *
 */
function choixProfession(formulaire, champProfession, champSecteur, champTypeContrat, prsNo) {
  
  if (document.forms[formulaire].elements[champProfession].selectedIndex < 0) return;
  if (p[document.forms[formulaire].elements[champTypeContrat].selectedIndex]) {
	  liste = (p[document.forms[formulaire].elements[champTypeContrat].selectedIndex])[2];
	  if (document.forms[formulaire].elements[champProfession].selectedIndex > 0
			  	&& liste[document.forms[formulaire].elements[champProfession].selectedIndex-1]) {
	    	liste = (liste[document.forms[formulaire].elements[champProfession].selectedIndex-1])[2];
	  } else {
    		liste = new Array(0);
	  }
  } else {
	  liste = new Array(0);
  }

  // supprime le contenu de la liste des secteurs
  for(i=0; i<document.forms[formulaire].elements[champSecteur].options.length;) {
    document.forms[formulaire].elements[champSecteur].options[i] = null;
  }
  document.forms[formulaire].elements[champSecteur].options[document.forms[formulaire].elements[champSecteur].options.length] = new Option("Choisissez", "");
      
  // ajoute les nouveaux secteurs
  for(i=0; i<liste.length; i++) {
    document.forms[formulaire].elements[champSecteur].options[document.forms[formulaire].elements[champSecteur].options.length] = new Option(liste[i][1], liste[i][0]);
  }
}

/**
 *
 */
function choixTypeContrat(formulaire, champProfession, champSecteur, champTypeContrat, prsNo) {
  
  coherenceChamps(formulaire, champTypeContrat, prsNo);

  if (document.forms[formulaire].elements[champTypeContrat].selectedIndex < 0) return;
  if (document.forms[formulaire].elements[champTypeContrat].selectedIndex > 0) {
  	if (p[document.forms[formulaire].elements[champTypeContrat].selectedIndex]) {
	    liste = (p[document.forms[formulaire].elements[champTypeContrat].selectedIndex])[2];
	} else {
		liste = new Array(0);
	}
  } else {
    liste = new Array(0);
  }

  if (document.forms[formulaire].elements[champProfession]){
	  // supprime le contenu de la liste des professions
	  for(i=0; i<document.forms[formulaire].elements[champProfession].options.length;) {
	    document.forms[formulaire].elements[champProfession].options[i] = null;
	  }
	  document.forms[formulaire].elements[champProfession].options[document.forms[formulaire].elements[champProfession].options.length] = new Option("Choisissez", "");
  }

  if (document.forms[formulaire].elements[champSecteur]){
	  // supprime le contenu de la liste des secteurs
	  for(i=0; i<document.forms[formulaire].elements[champSecteur].options.length;) {
	    document.forms[formulaire].elements[champSecteur].options[i] = null;
	  }
	  document.forms[formulaire].elements[champSecteur].options[document.forms[formulaire].elements[champSecteur].options.length] = new Option("Choisissez", "");
  }
  
  if (document.forms[formulaire].elements[champProfession]){
	  // ajoute les nouvelles professions
	  for(i=0; i<liste.length; i++) {
	    document.forms[formulaire].elements[champProfession].options[document.forms[formulaire].elements[champProfession].options.length] = new Option(liste[i][1], liste[i][0]);
	  }
  }

}

function masquerProfession(prsNo){
	prs = prsNo == 1 ? '':'CoEmp';
	//prs="";
	bloc = document.getElementById('sousBlocProf'+prs);
	ligne = document.getElementById('ligneProfession'+prs);
	if (ligne && bloc){
		bloc.removeChild(ligne);
	}
}

function afficherProfession(prsNo){
	prs = prsNo == 1 ? '':'CoEmp';
	//prs="";
	bloc = document.getElementById('sousBlocProf'+prs);
	liste = new Array(0);
	ligne = document.getElementById('ligneProfession'+prs);
	if (!ligne){
		onchange = 'choixProfession(\'ouverture\', \'profession'+prs+'\', \'secteurActivite'+prs+'\', \'typeContrat'+prs+'\', '+prsNo+');';
		ligne = creerLigneSelect('ligneProfession'+prs, 'profession'+prs, 'profession'+prs, null, '', 'Choisissez', liste, false, 'Statut professionnel', true, onchange);
		ligneTC = document.getElementById('ligneContrat'+prs);
		next = ligneTC.nextSibling;
		bloc.insertBefore(ligne, next);
	}	
}

function masquerSecteur(prsNo){
	prs = prsNo == 1 ? '':'CoEmp';
	//prs="";
	bloc = document.getElementById('sousBlocProf'+prs);
	ligne = document.getElementById('ligneSecteur'+prs);
	if (ligne && bloc){
		bloc.removeChild(ligne);
	}
}

function afficherSecteur(prsNo){
	prs = prsNo == 1 ? '':'CoEmp';
	//prs="";
	bloc = document.getElementById('sousBlocProf'+prs);
	liste = new Array(0);
	ligne = document.getElementById('ligneSecteur'+prs);
	if (!ligne){
		ligne = creerLigneSelect('ligneSecteur'+prs, 'secteurActivite'+prs, 'secteurActivite'+prs, null, '', 'Choisissez', liste, false, 'Secteur d\'activité', true);
		lignedebut = document.getElementById('ligneDateDebut'+prs);
		bloc.insertBefore(ligne, lignedebut);
	}
}

function masquerDateFin(prsNo){
	prs = prsNo == 1 ? '':'CoEmp';
	//prs="";
	bloc = document.getElementById('sousBlocProf'+prs);
	ligne = document.getElementById('ligneDateFin'+prs);
	if (ligne && bloc){
		bloc.removeChild(ligne);
	}
}

function afficherDateFin(prsNo){
	prs = prsNo == 1 ? '':'CoEmp';
	//prs="";
	bloc = document.getElementById('sousBlocProf'+prs);
	var ligneDF = document.getElementById('ligneDateFin'+prs);
	
	if (!ligneDF){
		ligneDF = creerLigneDateMmAaaa('ligneDateFin'+prs, 'moisFinProfessionnel'+prs, 'moisFinProfessionnel'+prs, 'anneeFinProfessionnel'+prs, 'anneeFinProfessionnel'+prs, 'Jusque', true, true);
	
		lignebas = document.getElementById('revenusp'+prs);
		bloc.insertBefore(ligneDF, lignebas);
	}
}

/**
 * Permet d'ajouter le champ de saisie du nom de jaune fille
 */
function ajouterNomJf(prsNo, nomEtIdChamp){
	var blocEtatCivil;
	var ligneNomJf;
	var lignePrenom;
	var prs = prsNo == 1 ? '':'CoEmp';
	blocEtatCivil = document.getElementById((prsNo == 1 ? 'blocEtatCivil':'sousBlocProfCoEmp'));
		
		ligneNomJf = document.getElementById('ligneNomJf'+prs);
		lignePrenom = document.getElementById('lignePrenom'+prs);
	

	if (!ligneNomJf){
		
			ligneNomJfId = 'ligneNomJf'+prs;
		
		ligneNomJf = creerLigneInput(ligneNomJfId, nomEtIdChamp, nomEtIdChamp, 'Nom de jeune fille', 'text', '', true );
		
		blocEtatCivil.insertBefore(ligneNomJf,lignePrenom);
	}
	
}

function ajouterLoyer( nomEtIdChamp){
	var blocLogement;
	var ligneLoyer;
	
	blocLogement = document.getElementById( 'logement');
	ligneLoyer = document.getElementById('ligneLoyer');

	if (!ligneLoyer){
		
		ligneLoyerId = 'ligneLoyer';
		ligneLoyer = creerLigneInput(ligneLoyerId , nomEtIdChamp, nomEtIdChamp, 'Loyer', 'text', '', false );
		ligneTC = document.getElementById('dateimmo');
		next = ligneTC.nextSibling;
		blocLogement.insertBefore(ligneLoyer,next);
	}
	
}
/**
 * Permer de supprimer le champ de saisie du nom de jeune fille
 */
function supprimerNomJf(prsNo){
	var blocEtatCivil;
	var ligneNomJf;
	var prs = prsNo == 1 ? '':'CoEmp';
		blocEtatCivil = document.getElementById((prsNo == 1 ? 'blocEtatCivil':'sousBlocProfCoEmp'));
		ligneNomJf = document.getElementById('ligneNomJf'+prs);
	
	if (ligneNomJf){
		blocEtatCivil.removeChild(ligneNomJf);
	}
}
function supprimerLoyer(prsNo){
	var blocLogement;
	var ligneLoyer;
	
		blocLogement = document.getElementById('logement');
		ligneLoyer = document.getElementById('ligneLoyer');
	
	if (ligneLoyer){
		blocLogement.removeChild(ligneLoyer);
	}
}



function afficherDepartementDeNaissance(prsNo, listeDepts){
	prs = prsNo == 1 ? '':'CoEmp';
	bloc = document.getElementById((prsNo == 1 ? 'blocEtatCivil':'sousBlocProfCoEmp'));
	var ligneDptN = document.getElementById('ligneDeptNais'+prs);
	
	if (!ligneDptN){
		ligneDptN = creerLigneSelect('ligneDeptNais'+prs, 'cpNaissance'+prs, 'cpNaissance'+prs, null, '', "Précisez le département", listeDepts, false, 'Département de naissance', true);
	
		ligneVN = document.getElementById('ligneVilleNaiss'+prs);
		
		bloc.insertBefore(ligneDptN, ligneVN);
	}
	
}

function masquerDepartementDeNaissance(prsNo){
	prs = prsNo == 1 ? '':'CoEmp';
	bloc = document.getElementById((prsNo == 1 ? 'blocEtatCivil':'sousBlocProfN'));
	var ligneDptN = document.getElementById('ligneDeptNais'+prs);
	
	if (ligneDptN){
		bloc.removeChild(ligneDptN);
	}
	
}

function gererAffichageDepartementNaisance(prsNo){
	prs = prsNo == 1 ? '':'CoEmp';
	nomChamp = 'paysNaissance'+prs;
	if (document.forms['ouverture'].elements[nomChamp].value=='FR'){
		afficherDepartementDeNaissance(prsNo, listeDepartements);
	} else {
		masquerDepartementDeNaissance(prsNo);
	}
}