// JavaScript Document

function setpng(img) { if(document.all && (IEver=parseFloat(navigator.appVersion.split("MSIE")[1])) && (IEver>=5.5) && (IEver<7) && document.body.filters && img) {
	imgName=img.src.toUpperCase();
	if(imgName.substring(imgName.length-3,imgName.length)=="PNG") img.outerHTML=
		"<span "+(img.id?"id='"+img.id+"' ":"")+(img.className?"class='"+img.className+"' ":"")+(img.title?"title=\""+img.title+"\" ":"")
		+"style=\"width:"+img.width+"px;height:"+img.height+"px;"+(img.align=="left"?"float:left;":(img.align=="right"?"float:right;":""))
		+(img.parentElement.href?"cursor:hand;":"")+"display:inline-block;"+img.style.cssText+";"
		+"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img.src+"',sizingMethod='scale');\"></span>";
}}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function effacercontenu(form,champs,init)
{
	if(document.forms[form].elements[champs].value == init)
	{
		document.forms[form].elements[champs].value = '';
	}
	else return false;
}

function affiche_nav(el_name, img_name, img_src)
{
	if(el_name != '')	document.getElementById(el_name).style.display = "";
	document.getElementById(img_name).src = "squelettes/IMG/" + img_src + ".gif";
}

function masque_nav(el_name, img_name, img_src)
{
	if(el_name != '')	document.getElementById(el_name).style.display = "none";
	document.getElementById(img_name).src = "squelettes/IMG/" + img_src + ".gif";
}

function affiche_formation(el)
{
	display = document.getElementById('texte_formation_' + el).style.display;
	if(display == "none")
	{
		document.getElementById('texte_formation_' + el).style.display = "";
		document.getElementById('titre_formation_' + el).className = "titre_formation_hp_on";
		document.getElementById('img_fleche_' + el).src = "squelettes/IMG/btn_fleche_formation_on.gif";
		document.getElementById('fleche_formation_' + el).className = "fleche_lien_formation_on";
	}
	else
	{
		document.getElementById('texte_formation_' + el).style.display = "none";
		document.getElementById('titre_formation_' + el).className = "titre_formation_hp";
		document.getElementById('img_fleche_' + el).src = "squelettes/IMG/btn_fleche_formation.gif";
		document.getElementById('fleche_formation_' + el).className = "fleche_lien_formation";
	}
}



/***********************************/
/**		Formulaires
/**** ***************************  */
function verif_form_contact(form_name) {
	error = false;
	form = form_name;
	error_message = "Merci de remplir ou corriger les champs suivants\n\n";
	
	check_radio("profil", "Votre profil\n");
	check_input("prenom", '1', "Votre prenom\n");
	check_input("nom", '1', "Votre nom\n");
	check_input("mutualite", '1', "Votre mutualite\n");
	check_input("ville", '1', "Votre ville\n");
	check_input_email("email", "Votre email\n");
	check_input("sujet", '1', "Votre sujet\n");
	check_select("message", "", "Votre message\n");
	check_input("verif", '1', "Le code de verification\n");

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function verif_form_newsletter(form_name) {
	error = false;
	form = form_name;
	error_message = "Merci de remplir ou corriger les champs suivants\n\n";
	
	check_radio("profil", "Votre profil\n");
	check_input("prenom", '1', "Votre prenom\n");
	check_input("nom", '1', "Votre nom\n");
	check_input("specialite", '1', "Votre specialite\n");
	check_input("adresse", '1', "Votre adresse\n");
	//check_input("adresse2", '1', "La suite de votre adresse\n");
	check_input("cp", '1', "Votre code postal\n");
	check_input("ville", '1', "Votre ville\n");
	check_input_email("email", "Votre email\n");

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function verif_form_inscription_praticien(form_name) {
	error = false;
	form = form_name;
	error_message = "Merci de remplir ou corriger les champs suivants\n\n";
	
	check_input("nb_praticien", '1', "Le nombre de praticien\n");
	compt_praticien = form.nb_praticien.value;
	for(i = 1; i <= compt_praticien; i++)
	{
		check_input("prenom_" + i, '1', "Le prenom du praticien " + i + "\n");
		check_input("nom_" + i, '1', "Le nom du praticien " + i + "\n");	
	}
	check_input("adresse", '1', "Votre adresse\n");
	check_input("cp", '1', "Votre code postal\n");
	check_input("ville", '1', "Votre ville\n");
	check_input("tel", '1', "Votre telephone\n");
	if(form_name.email.value != '')		check_input_email("email", "Votre email n'a pas un format correct\n");

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}

function verif_form_inscription_assistante(form_name) {
	error = false;
	form = form_name;
	error_message = "Merci de remplir ou corriger les champs suivants\n\n";
	
	check_input("nb_assistante", '1', "Le nombre d'assistantes\n");
	compt_assitante = form.nb_assistante.value;
	for(i = 1; i <= compt_assitante; i++)
	{
		check_input("prenom_assistante_" + i, '1', "Le prenom de l'assistante " + i + "\n");
		check_input("nom_assistante_" + i, '1', "Le nom de l'assistante " + i + "\n");	
	}
	check_input("nom_employeur_assistante", '1', "Le nom de votre employeur\n");
	check_input("adresse", '1', "Votre adresse\n");
	check_input("cp", '1', "Votre code postal\n");
	check_input("ville", '1', "Votre ville\n");
	check_input("tel", '1', "Votre telephone\n");
	if(form_name.email.value != '')		check_input_email("email", "Votre email n'a pas un format correct\n");

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}


function verif_form_inscription_praticien_assistante(form_name) {
	error = false;
	form = form_name;
	error_message = "Merci de remplir ou corriger les champs suivants\n\n";

	if( (form.nb_praticien.value == '' || form.nb_praticien.value == '0')
	   && (form.nb_assistante.value == '' || form.nb_assistante.value == '0'))
	{
		error_message = error_message + "* Veuillez renseigner au moins 1 praticien ou 1 assistante\n\n";
		error = true;
	}
	
	if(form.nb_praticien.value != '' && form.nb_praticien.value != '0')
	{
		check_input("nb_praticien", '1', "Le nombre de praticien\n");
		
		compt_praticien = form.nb_praticien.value;
		for(i = 1; i <= compt_praticien; i++)
		{
			check_input("prenom_" + i, '1', "Le prenom du praticien " + i + "\n");
			check_input("nom_" + i, '1', "Le nom du praticien " + i + "\n");	
		}
	}
	
	if(form.nb_assistante.value != '' && form.nb_assistante.value != '0')
	{
		check_input("nb_assistante", '1', "Le nombre d'assistantes\n");
		
		compt_assitante = form.nb_assistante.value;
		for(i = 1; i <= compt_assitante; i++)
		{
			check_input("prenom_assistante_" + i, '1', "Le prenom de l'assistante " + i + "\n");
			check_input("nom_assistante_" + i, '1', "Le nom de l'assistante " + i + "\n");	
		}
		check_input("nom_employeur_assistante", '1', "Le nom de votre employeur (assistante)\n");
	}
	check_input("adresse", '1', "Votre adresse\n");
	check_input("cp", '1', "Votre code postal\n");
	check_input("ville", '1', "Votre ville\n");
	check_input("tel", '1', "Votre telephone\n");
	if(form_name.email.value != '')		check_input_email("email", "Votre email n'a pas un format correct\n");

	if (error == true) {
		alert(error_message);
		return false;
	} else {
		submitted = true;
		return true;
	}
}


/***********************************/
/**		Fonctions ajout praticiens, assistantes ...
/**** ***************************  */
function ajouter_praticien(nb)
{
	if(Number(nb))
	{
		total_init = document.formulaire_inscription.total_praticien.value;
		
		if(Number(total_init) < Number(nb))
		{
		
			for(j = Number(total_init) + 1; j <= Number(nb); j++)
			{
				total = document.formulaire_inscription.total_praticien.value;
				
				next = (Number(total)+1);
				
				var newRow = document.getElementById('base_praticien').insertRow(-1);
				var newCell = newRow.insertCell(0);
				i = 1;
				newCell.id = 'praticien_' + next;
				newCell.innerHTML = 'Nom ' + next + ' *';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = '<input id="nom_' + next + '" name="nom_' + next + '" type="text" value="" class="champs_texte" />';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = '';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = 'Pr&eacute;nom ' + next + ' *';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = '<input id="prenom_' + next + '" name="prenom_' + next + '" type="text" value="" class="champs_texte" />';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = '<a href="#" onclick="supprimer_praticien(this); return false;">X</a>';
			
				document.formulaire_inscription.total_praticien.value = next;
			}
			
		}
	}
}

function supprimer_praticien(id)
{
	document.getElementById('base_praticien').deleteRow(id.parentNode.parentNode.sectionRowIndex);
	
	total = document.formulaire_inscription.total_praticien.value;
	
	next = (Number(total)-1);
	
	document.formulaire_inscription.total_praticien.value = next;
	document.formulaire_inscription.nb_praticien.value = next;
}

function ajouter_assistante(nb)
{
	if(Number(nb))
	{
		total_init = document.formulaire_inscription.total_assistante.value;
		
		if(Number(total_init) < Number(nb))
		{
		
			for(j = Number(total_init) + 1; j <= Number(nb); j++)
			{
				total = document.formulaire_inscription.total_assistante.value;
				
				next = (Number(total)+1);
				
				var newRow = document.getElementById('base_assistante').insertRow(-1);
				var newCell = newRow.insertCell(0);
				i = 1;
				newCell.id = 'praticien_' + next;
				newCell.innerHTML = 'Nom ' + next + ' *';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = '<input id="nom_assistante_' + next + '" name="nom_assistante_' + next + '" type="text" value="" class="champs_texte" />';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = '';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = 'Pr&eacute;nom ' + next + ' *';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = '<input id="prenom_assistante_' + next + '" name="prenom_assistante_' + next + '" type="text" value="" class="champs_texte" />';
				newCell = newRow.insertCell(i); i++;
				newCell.innerHTML = '<a href="#" onclick="supprimer_assistante(this); return false;">X</a>';
			
				document.formulaire_inscription.total_assistante.value = next;
			}
			
		}
	}
}

function supprimer_assistante(id)
{
	document.getElementById('base_assistante').deleteRow(id.parentNode.parentNode.sectionRowIndex);
	
	total = document.formulaire_inscription.total_assistante.value;
	
	next = (Number(total)-1);
	
	document.formulaire_inscription.total_assistante.value = next;
	document.formulaire_inscription.nb_assistante.value = next;
}


/* Formulaires formations */
// AJAX
function getXhr()
{
	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)
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else  // XMLHttpRequest non supporté par le navigateur
	{
		alert("Votre navigateur ne supporte pas les objets XMLHttpRequest.");
		xhr = false;
	}
	return xhr;
}

function ajax_form_formation(nom_form, change_type)
{
	type 			= valeurradio(nom_form.type);
	id_theme 		= nom_form.id_theme.value;
	id_region 		= nom_form.id_region.value;
	date_formation 	= nom_form.date_formation.value;
	
	if(change_type)
	{
		id_theme		= '';
		id_region		= '';
		date_formation	= '';
	}
	
	var docXML = null;
	var xhr = getXhr();
	
	//on défini ce qu'on va faire quand on va aura la réponse
	xhr.onreadystatechange = function()
	{
		// On ne fait que quelque chose que si on a tout recu et que le serveur est OK
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			var docXML= xhr.responseXML;
			
			var id_theme_select = nom_form.id_theme;
			var id_region_select = nom_form.id_region;
			var date_formation_select = nom_form.date_formation;

			// initialise les liste déroulante a 1 pour ne pas perdre la mention "choisissez"
			id_theme_select.options.length = 0;
			id_region_select.options.length = 0;
			date_formation_select.options.length = 0;

			// définition du nombre d'option themes :
			id_theme_select.options.length = docXML.getElementsByTagName('theme').length;
			// récupération du theme sélectionné :
			theme_select = '';
			if(docXML.getElementsByTagName('theme_select')[0].firstChild.data != 'off')
			{
				theme_select = docXML.getElementsByTagName('theme_select')[0].firstChild.data;
			}
			// remplissage de la liste themes
			for (i = 0; i < docXML.getElementsByTagName('theme').length; i++)
			{
				element = docXML.getElementsByTagName('theme')[i];
				if(element.getElementsByTagName('theme_id')[0].firstChild.data == "choisissez") {
					id_theme_select.options[i].value = "";
				}
				else	id_theme_select.options[i].value = element.getElementsByTagName('theme_id')[0].firstChild.data;
				id_theme_select.options[i].text  = element.getElementsByTagName('theme_nom')[0].firstChild.data;
			}
			if(theme_select != '')	document.getElementById('id_theme').value = theme_select;
			
			// définition du nombre d'option region :
			id_region_select.options.length = docXML.getElementsByTagName('region').length;
			// récupération de la région sélectionné :
			region_select = '';
			if(docXML.getElementsByTagName('region_select')[0].firstChild.data != 'off')
			{
				region_select = docXML.getElementsByTagName('region_select')[0].firstChild.data;
			}
			// remplissage de la liste region
			for (i = 0; i < docXML.getElementsByTagName('region').length; i++)
			{
				element = docXML.getElementsByTagName('region')[i];
				if(element.getElementsByTagName('region_id')[0].firstChild.data == "choisissez") {
					id_region_select.options[i].value = "";
				}
				else	id_region_select.options[i].value = element.getElementsByTagName('region_id')[0].firstChild.data;
				id_region_select.options[i].text  = element.getElementsByTagName('region_nom')[0].firstChild.data;
			}
			if(region_select != '')	document.getElementById('id_region').value = region_select;
			
			// définition du nombre d'option dates :
			date_formation_select.options.length = docXML.getElementsByTagName('date').length;
			// récupération de la région sélectionné :
			date_select = '';
			if(docXML.getElementsByTagName('date_select')[0].firstChild.data != 'off')
			{
				date_select = docXML.getElementsByTagName('date_select')[0].firstChild.data;
			}
			// remplissage de la liste dates
			for (i = 0; i < docXML.getElementsByTagName('date').length; i++)
			{
				element = docXML.getElementsByTagName('date')[i];
				if(element.getElementsByTagName('date_id')[0].firstChild.data == "choisissez") {
					date_formation_select.options[i].value = "";
				}
				else	date_formation_select.options[i].value = element.getElementsByTagName('date_id')[0].firstChild.data;
				date_formation_select.options[i].text  = element.getElementsByTagName('date_nom')[0].firstChild.data;
			}
			if(date_select != '')	document.getElementById('date_formation').value = date_select;
			
		}
	}
	
	alea = Math.round(Math.random() * 10000);
	xhr.open("GET", "./includes/formulaires/ajax_form_formations.php?nocache=" + alea + "&type=" + type + "&id_theme=" + id_theme + "&id_region=" + id_region + "&date_formation=" + date_formation, true);
	xhr.send(null);
}
