var preloadFlag = true;

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}


function changeImages() {
	changeImagesArray(changeImages.arguments);
}

function preloadImages() {
	if (document.images) {
		pre_prestations2 = newImage('images/prestations2.jpg');
		pre_devis2 = newImage('images/devis2.jpg');
		pre_societe2 = newImage('images/societe2.jpg');
		pre_contact2 = newImage('images/contact2.jpg');
		pre_devis_perso2 = newImage('images/devis-perso2.jpg');
		pre_devis_arealiser2 = newImage('images/devis-arealiser2.jpg');
		preloadFlag = true;
	}
}


function maj_tableau(form) {
	var nature_transaction,nature_bien,date_permis,installation_gaz,installation_elec;
	var tab_diag = new Array();
	
	tab_diag['A-C-E-H-I'] = 'Loi Carrez, Performance énergétique, Termites, Repérage amiante, Accessibilité au plomb, Installation intérieure de gaz, Installation intérieure d\'électricité';	// new
	tab_diag['A-C-E-H'] = 'Loi Carrez, Performance énergétique, Termites, Repérage amiante, Accessibilité au plomb, Installation intérieure de gaz';
	tab_diag['A-C-E'] = 'Loi Carrez, Performance énergétique, Termites, Repérage amiante, Accessibilité au plomb';
	tab_diag['A-C-F-H-I'] = 'Loi Carrez, Performance énergétique, Termites, Repérage amiante, Installation intérieure de gaz, Installation intérieure d\'électricité';			// new
	tab_diag['A-C-F-H'] = 'Loi Carrez, Performance énergétique, Termites, Repérage amiante, Installation intérieure de gaz';
	tab_diag['A-C-F'] = 'Loi Carrez, Performance énergétique, Termites, Repérage amiante';
	tab_diag['A-C-G'] = 'Loi Carrez, Performance énergétique, Termites';
	tab_diag['A-D-E-H-I'] = 'Performance énergétique, Termites, Repérage amiante, Accessibilité au plomb, Installation intérieure de gaz, Installation intérieure d\'électricité';				// new
	tab_diag['A-D-E-H'] = 'Performance énergétique, Termites, Repérage amiante, Accessibilité au plomb, Installation intérieure de gaz';
	tab_diag['A-D-E'] = 'Performance énergétique, Termites, Repérage amiante, Accessibilité au plomb';
	tab_diag['A-D-F-H-I'] = 'Performance énergétique, Termites, Repérage amiante, Installation intérieure de gaz, Installation intérieure d\'électricité';						// new
	tab_diag['A-D-F-H'] = 'Performance énergétique, Termites, Repérage amiante, Installation intérieure de gaz';
	tab_diag['A-D-F'] = 'Performance énergétique, Termites, Repérage amiante';
	tab_diag['A-D-G'] = 'Performance énergétique, Termites';
	tab_diag['B-C-E'] = 'Performance énergétique, Accessibilité au plomb';
	tab_diag['B-C-F'] = 'Performance énergétique';
	tab_diag['B-C-G'] = 'Performance énergétique';
	tab_diag['B-D-E'] = 'Performance énergétique, Accessibilité au plomb';
	tab_diag['B-D'] = 'Performance énergétique';
	tab_diag['B-D-F'] = 'Performance énergétique';
	tab_diag['B-D-G'] = 'Performance énergétique';
	
	var lien_devis = document.getElementById('lien-devis');
	
	var nature_transaction_radio = form.nature_transaction;
	for (var i=0;i<nature_transaction_radio.length;i++) {
		if (nature_transaction_radio[i].checked) { nature_transaction = nature_transaction_radio[i].value; break; }
	}
	
	var nature_bien_radio = form.nature_bien;
	for (var i=0;i<nature_bien_radio.length;i++) {
		if (nature_bien_radio[i].checked) { nature_bien = nature_bien_radio[i].value; break; }
	}
	
	var date_permis_radio = form.date_permis;
	for (var i=0;i<date_permis_radio.length;i++) {
		if (date_permis_radio[i].checked) { date_permis = date_permis_radio[i].value; break; }
	}
	
	if (form.installation_gaz.checked) {
		installation_gaz = form.installation_gaz.value;
	}
	if (form.installation_elec.checked) {
		installation_elec = form.installation_elec.value;
	}
	
	var tab = document.getElementById('tab-devis');
	var liste_diags = document.getElementById('liste-diags');
	var liste_tr = tab.getElementsByTagName('tr');
	
	var reg = new RegExp("[\-]+", "g");
	var tab_lettres, display;
	
	var tab_index;
	if (nature_transaction != null) {
		tab_index = nature_transaction;
		if (nature_bien != null) {
			tab_index += '-' + nature_bien;
			if (date_permis != null) {
				tab_index += '-' + date_permis;
				if (installation_gaz != null) {
					tab_index += '-' + installation_gaz;
					if (installation_elec != null) {
						tab_index += '-' + installation_elec;
					}
				}
			}
		}
	}
	
	if (tab_diag[tab_index] != null) {
		lien_devis.href = 'devis-gratuit.php?diag='+escape(tab_diag[tab_index]);
		var reg=new RegExp("(,)", "g");
		liste_diags.innerHTML = '<strong>&bull; ' + tab_diag[tab_index].replace(reg, '</strong><br /><strong>&bull; ');
		
	} else {
		lien_devis.href = 'devis-gratuit.php';
		liste_diags.innerHTML = '';
	}
	
	var nbre_select = 0;
	if (nature_transaction != null) { nbre_select++; }
	if (nature_bien != null) { nbre_select++; }
	if (date_permis != null) { nbre_select++; }
	if (installation_gaz != null) { nbre_select++; }
	if (installation_elec != null) { nbre_select++; }
	
	
	for (var i=0;i<liste_tr.length;i++) {
		if (liste_tr[i].id == '') { continue; }
		tab_lettres = liste_tr[i].id.split(reg);
		display = true;
		
		if (nature_transaction != null && tab_lettres[0] == nature_transaction) {
			liste_tr[i].style.display = '';
		} else {
			liste_tr[i].style.display = 'none';
			display = false;
		}
		
		if (nature_bien == null) { continue; }
		if (display && nature_bien != null && tab_lettres[1] == nature_bien) {
			liste_tr[i].style.display = '';
		} else {
			liste_tr[i].style.display = 'none';
			display = false;
		}
		
		if (date_permis == null) { continue; }
		if (display && date_permis != null && tab_lettres[2] == date_permis) {
			liste_tr[i].style.display = '';
		} else {
			liste_tr[i].style.display = 'none';
			display = false;
		}
		
		if (installation_gaz == null) { continue; }
		if (display && installation_gaz != null && tab_lettres[3] == installation_gaz) {
			liste_tr[i].style.display = '';
		} else {
			liste_tr[i].style.display = 'none';
			display = false;
		}
		
		if (installation_elec == null) { continue; }
		if (display && installation_elec != null && tab_lettres[4] == installation_elec) {
			liste_tr[i].style.display = '';
		} else {
			liste_tr[i].style.display = 'none';
			display = false;
		}
	}
	//tab.style.display = '';
}
