
// --------------------------------------------------
// Gestion du nombre de logements
// --------------------------------------------------
function nombreLogements(selecteur , demandeur)
{
	if (selecteur.options [selecteur.selectedIndex].value == 'autre:')
		document.getElementById('bien_nombre_autre_div' + demandeur).style.display = 'block';
	else
		document.getElementById('bien_nombre_autre_div' + demandeur).style.display = 'none';
}

// --------------------------------------------------
// En savoir plus (affichage/masquage paragraphe)
// --------------------------------------------------
function enSavoirPlus(affichage)
{
	if (affichage == true)
	{
		document.getElementById('savoir-plus-link').style.display = 'none';		
		document.getElementById('savoir-plus').style.display = 'inline';		
	}
	else
	{
		document.getElementById('savoir-plus-link').style.display = 'inline';		
		document.getElementById('savoir-plus').style.display = 'none';		
	}
}

// --------------------------------------------------
// Gestion des champs à afficher selon une liste sélective
// --------------------------------------------------
function afficherChamp(aAfficher , prefix)
{
	for(i = 0; i < aAfficher.options.length; i++)
	{
		var id = aAfficher.options [ i ].index;
		if (document.getElementById(prefix + id) != null)
			document.getElementById(prefix + id).style.display = 'none';
	}
	document.getElementById(prefix + aAfficher.selectedIndex).style.display = 'block';
}

// --------------------------------------------------
// Gestion des champs préremplis
// --------------------------------------------------
var champsPreremplis = Array();

function viderChamp(element)
{
	if (champsPreremplis [ element.getAttribute('name') ] == null || champsPreremplis [ element.getAttribute('name') ] == '')
	{
		element.innerHTML = '';
		champsPreremplis [ element.getAttribute('name') ] = 'wasEmptied';
	}
}

// --------------------------------------------------
// Vérifie aprÃ¨s le passage d'un champ s'il est marqué comme obligatoire; si oui et qu'il est rempli, on  le repasse en blanc
// --------------------------------------------------
function verifierChamp(champ)
{
	if (champ.value != '')
	{
		var classes = champ.className.split(' ');
		champ.className = '';
		for (classe in classes)
		{
			if (classes [ classe ] != 'obligatoire')
				champ.className += classes [ classe ] + ' ';
		}
	}
}

// --------------------------------------------------
// Vérification du formulaire (d'abord tous les champs obligatoires, puis les chamos interdépendants)
// --------------------------------------------------
function verifierFormulaire()
{
	var tmp = document.getElementById(document.getElementById('demandeur').value + '_obligatoire').value;
	var champsObligatoires = tmp.split(',');
	var champsOK = true;
	for(champ = 0; champ < champsObligatoires.length; champ++)
	{		
		if (document.getElementById(champsObligatoires [ champ ]) != null && document.getElementById(champsObligatoires [ champ ]).value == '')
		{
			if (champsOK)
				window.location = '#' + champsObligatoires [ champ ] + '_titre';
			document.getElementById(champsObligatoires [ champ ]).className += ' obligatoire';
 			champsOK = false;
		}
	}
	if (champsOK)
	{
		if ((document.getElementById('reponse1').checked || document.getElementById('reponse3').checked))
		{
			if (document.getElementById('demandeur_email_' + document.getElementById('demandeur').value).value == '')
			{
				window.location = '#demandeur_email_' + document.getElementById('demandeur').value + '_titre';
				document.getElementById('demandeur_email_' + document.getElementById('demandeur').value).className += ' obligatoire';
				champsOK = false;
			}
		}
	}
	if (champsOK)
		afficherConfirmation();
	return false;
}

// --------------------------------------------------
// Affichage du message de confirmation
// --------------------------------------------------
function afficherConfirmation()
{
	var htmlConfirmation = '<img src="demande_numerotation_confirmation.png" alt="" /><br />';
	htmlConfirmation += '<table border="0" width="100%">';
	// Listing de tous les champs (seulement pour l'utilisateur sélectionné)
	var tousChamps = document.forms['contenu'];
	var typeDemandeur = document.getElementById('demandeur').value;
	var titrePrecedent = '';
	for (var champ = 0; champ < tousChamps .elements.length; champ ++)
	{
		// S'il y a un titre précisé dans les préférences et que le champ n'est pas vide
		if (listeChamps [ tousChamps.elements[champ].name ] != null && tousChamps.elements[champ].value != null && tousChamps.elements[champ].value != '')
		{
			// S'il ne s'agit pas d'un bouton radio, ou d'un bouton radio coché
			if (tousChamps.elements[champ].type != 'radio' || (tousChamps.elements[champ].type == 'radio' && tousChamps.elements[champ].checked))
			{
				// On ajoute le champ s'il fait partie du panneau de l'utilisateur sélectionné
				var typeChamp = tousChamps.elements[champ].name;
				typeChamp = typeChamp.split('_');
				var typeDemandeurChamp = typeChamp [ typeChamp.length - 1 ];
				if ((typeDemandeurChamp != 'particulier' && typeDemandeurChamp != 'professionnel') || typeDemandeurChamp == typeDemandeur)
				{
					if (listeChamps [ tousChamps.elements[champ].name ] == titrePrecedent)
						var titre = '';
					else
						var titre = listeChamps [ tousChamps.elements[champ].name ];
					htmlConfirmation += '<tr><td vertical-align="top"><b>' + titre + '</b></td><td vertical-align="top">' + tousChamps.elements[champ].value + '</td></tr>';
					titrePrecedent = listeChamps [ tousChamps.elements[champ].name ];
					
				}
			}
		}
	}
	
	htmlConfirmation += '</table><br />';
	htmlConfirmation += '<input type="button" onclick="document.getElementById(\'contenu\').submit();" value="Envoyer" />';
	htmlConfirmation += '<input type="button" onclick="document.getElementById(\'voile\').style.display=\'none\';document.getElementById(\'confirmation\').style.display=\'none\';" value="Modifier" /></span>';
	
	document.getElementById('confirmationcontent').innerHTML = htmlConfirmation;
	document.getElementById('confirmation').style.display = 'block';
	document.getElementById('voile').style.height = '2000px';
	document.getElementById('voile').style.display = 'block';
	window.location = '#';
}

// --------------------------------------------------
// Gestion des onglets
// --------------------------------------------------
function onglet(aActiver , aDesactiver)
{
	// Affichage du bon titre
	document.getElementById('titre_' + aActiver).style.display = 'block';
	document.getElementById('titre_' + aDesactiver).style.display = 'none';
	// Affichage du bon onglet
	document.getElementById(aActiver + '_on').style.display = 'block';
	document.getElementById(aDesactiver + '_on').style.display = 'none';
	// Affichage du bon contenu
	document.getElementById(aActiver + '_content').style.display = 'block';
	document.getElementById(aDesactiver + '_content').style.display = 'none';
	// Enregistrement du type d'utilisateur
	document.getElementById('demandeur').value = aActiver;
	document.getElementById('ignore').value = aDesactiver;
}

// --------------------------------------------------
// Gestion des bulles d'aide
// --------------------------------------------------
function aide(lien)
{
	if (document.getElementById('help').style.display == 'block')
	{
		document.getElementById('help').style.display = 'none';
		lien.title = document.getElementById('helpcontent').innerHTML;
	}
	else
	{
		document.getElementById('help').style.display = 'block';
		document.getElementById('helpcontent').innerHTML = lien.title;
		lien.title = '';
	}		
}

// --------------------------------------------------
// Gestion de la position des bulles d'aide
// --------------------------------------------------
var mouseX; var mouseY;
document.onmousemove = function(e)
{
	if (navigator.appName.substring(0,3) == "Mic")
	{ e = window.event; mouseX = e.clientX + document.documentElement.scrollLeft; mouseY = e.clientY + document.documentElement.scrollTop; }
	else { mouseX = e.pageX; mouseY = e.pageY; }
	document.getElementById('help').style.marginLeft = (mouseX + 15) + "px" ;	
	document.getElementById('help').style.marginTop = (mouseY + 15) + "px" ;	
}

