/** 
 *  ########################################################################
 *  Message 'simulation indisponible'
 *  ########################################################################
 */
var MESS_SIMU_INDISPO = "Le service de simulation est indisponible pour le moment.";
var MENS_LEGALES = "Offre de vente \340 cr\351dit r\351serv\351e aux particuliers. Montants et taux sont indiqu\351s hors assurance facultative. Bar\350me en vigueur au 15/10/2007, susceptible de variations. Sous r\351serve d'acceptation du dossier de cr\351dit li\351e \340 une vente par VIAXEL, d\351partement de Sofinco, SA au capital de 193 859 835 &euro;, 542 097 522 RCS Paris, si\350ge social : 128-130 boulevard Raspail - 75006 Paris, soci\351t\351 de courtage inscrite \340 ORIAS sous le n\260 07 008 079."

/**
 *	########################################################################
 *	Appel du service de simulation en ajax (post)
 *		- url            :  mapping url simulation
 *		- form           :  id formulaire html
 *		- flashUrl       : url flash de lecture xml
 *		- flashDiv       : div d'affichage du flash
 *		- noflashDiv     : div affichage tab html
 *      - buildArrayHtml : fonction javascript g?n?rant le html alternatif 
 *	########################################################################
 */
function simulationAjax(url, form, flashUrl, flashDiv, buildArrayHtml,css_fv) 
{
	// D?finition de la requete ajax
	new Ajax.Request(url, {
  		method: 'post',
  		parameters: $(form).serialize(),
  		onLoading: function(){
  			// Affichage image spinner d'attente
  			$(flashDiv).update("<br /><br /><br /><img src='../images/espace-public/spinner.gif'/>");
			$(flashDiv).innerHTML;
			
  		},
  		onFailure: function(){
  			// Erreur dans la simulation
  			$(flashDiv).update("<br/>" + MESS_SIMU_INDISPO);
			$(flashDiv).innerHTML;
  		},
  		onSuccess: function(response) 
  		{

			// Test Erreurs
			if(xmlHasErrors(response)){
				
				xmlErrors(response, flashDiv);
				
			}
			else{
		
				// Appel fonction g?n?rant le tableau html alternatif
				eval(buildArrayHtml + "(response, '" + flashDiv + "');");
				//on a mis cette ligne en commentaire car on a fait le choix de construire les ML
				// tout suite apres la construction du tableau 
			//	showMentions(response, 'mentions_legales'); 
				
				
	  			//Affichage du resultat dans le flash
	  			var so = new SWFObject("../swf/espace-public/reglette2.swf", "", "630", "820", "9", "");
				so.addVariable("xml_fv", flashUrl);
				so.addParam("wmode", "transparent");
				so.addVariable("css_fv",css_fv);
				so.write($(flashDiv));

				//Decochages des prestations si elles ne sont pas valides suite a la simulation
				
				$('band-erreur').update("");
				$('band-erreur').innerHTML;	
	
				var maform = document.forms[0];					
				for (var champ=0; champ < maform.elements.length; champ++) 
				{						
					if (maform.elements[champ].value == 'PRENT' && maform.elements[champ].checked == true)		
					{
						VerifTopPrestation(response,form,'PRENT','TOP_PREST_ENTRETIEN','PREST_ENTRETIEN_OK');
					}
					if (maform.elements[champ].value == 'PRCAR' && maform.elements[champ].checked == true)		
					{
						VerifTopPrestation(response,form,'PRCAR','TOP_PREST_SECURICAR','PREST_SECURICAR_OK' );
					}
				}				
			}
		}
	});

}

/**
 *	########################################################################
 *	Test de presence d'erreurs dans le flux XML renvoye
 *	########################################################################
 */
function xmlHasErrors(response){
	var test = 0;
   	try //Internet Explorer
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";	
		xmlDoc.loadXML(response.responseText);	
		var errorsNode = xmlDoc.getElementsByTagName('errors')[0];
		if(errorsNode.hasChildNodes())
		{
			return(true);
		}
		else{
			return(false);
		}
	 }
	 catch(e) {
			try //Firefox, Mozilla, Opera, etc.
			{
				parser = new DOMParser();
				xmlDoc = parser.parseFromString(response.responseText,"text/xml");
				var nsResolver = xmlDoc.createNSResolver(xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);

				/*Creation du tableau HTML par rapport au doc xmlDoc et Xpath*/
				var errors = xmlDoc.evaluate("datas/errors/error", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
				var thisErrors = errors.iterateNext();
				if(thisErrors){
					return(true);
				}
				else{
					return(false);
				}
			}
			catch(e) {
				return(true);
			}
 		}
}


/**
 *	########################################################################
 *	Affichage des erreurs dans l'IHM
 *	########################################################################
 */
function xmlErrors(response, noflashDiv){
   		try //Internet Explorer
		{
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";	
			xmlDoc.loadXML(response.responseText);	
			var errorsNode = xmlDoc.getElementsByTagName('errors')[0];
			var errorsHtml = "Erreurs : <br/>";
			for(i=0; i<errorsNode.childNodes.length; i++ ){
				var nodeError = errorsNode.getElementsByTagName('error')[i];
				var text = nodeError.getElementsByTagName("text")[0].firstChild.data;
				var lastChar = text.charAt(text.length - 1)
				var point = (lastChar == ".") ? "" : ".";
				errorsHtml += "<p>" + text + point + "</p>";
			}
			$(noflashDiv).update(errorsHtml);
			$(noflashDiv).innerHTML;
		}
		catch(e) {
			try //Firefox, Mozilla, Opera, etc.
			{
				parser = new DOMParser();
				xmlDoc = parser.parseFromString(response.responseText,"text/xml");
				var nsResolver = xmlDoc.createNSResolver(xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);

				/*Creation du tableau HTML par rapport au doc xmlDoc et Xpath*/
				var errors = xmlDoc.evaluate("datas/errors/error", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
				var thisErrors = errors.iterateNext();
					var errorsHtml = "Erreurs : <br/>";
					while (thisErrors) {
						var xmlText = xmlDoc.evaluate("text", thisErrors, nsResolver, XPathResult.ANY_TYPE, null);
						var text = xmlText.iterateNext().firstChild.nodeValue;
						var lastChar = text.charAt(text.length - 1)
						var point = (lastChar == ".") ? "" : ".";
						errorsHtml += "<p>" + text + point + "</p>";
						var thisErrors = errors.iterateNext();
					}
					$(noflashDiv).update(errorsHtml);
				  	$(noflashDiv).innerHTML;
			}
			catch(e) {
				$(noflashDiv).update(MESS_SIMU_INDISPO);
				$(noflashDiv).innerHTML;
			}
 		}
}




/**
 *	########################################################################
 *	Construction du tableau html alternatif pour la simulation >> LOA <<
 *	########################################################################
 */
function buildLoaArrayHtml(response, noflashDiv)
{
	
  	try //Internet Explorer
	{			
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(response.responseText);				  		
		var datasetNode = xmlDoc.getElementsByTagName('simulations')[0];
		var details = datasetNode.getElementsByTagName('DETAILS');
 		var nbSimulation = 10;
 		var nblignes = 1;
 		if (details.length < 10)
 			{nbSimulation = details.length;}
 		else
 			{nblignes = 2;}	
 					
		if(datasetNode.childNodes.length > 3)
		{	
	  		var reponseHtml = "<br/>";				  		
	  		
	  		/*------- TABLEAU DES LABELS -------*/
	  		reponseHtml += "<table class='tabSimulationIE'>";
	  		reponseHtml += "<tr><th>Duree en mois : </th></tr>";
			reponseHtml += "<tr><th>Mensualite : </th></tr>";
			var dataLabel = datasetNode.getElementsByTagName('DETAILS')[0];
			for(i=0; i<dataLabel.childNodes.length; i++ ) 
			{
				reponseHtml += "<tr><th>"+dataLabel.getElementsByTagName('LABEL')[i].firstChild.data+"</th></tr>";						
			}
			reponseHtml += "</table>";						
			/*------- FIN TABLEAU LABELS -------*/
			for(ligne=0;ligne<nblignes;ligne++)
	  		{
				if(ligne == 0)
				{						
					for(i=0; i<nbSimulation; i++ ) 
					{
						var dataValue = datasetNode.getElementsByTagName('DETAILS')[i];
					
						if(i%2 != 0)
						{
							reponseHtml += "<table class='tabSimulationIE'>";
						}
						else
						{
							reponseHtml += "<table class='tabSimulationGrayIE'>";
						}
						reponseHtml += "<tr><td>"+datasetNode.getElementsByTagName('DUREE')[i].firstChild.data+"</td></tr>";
						reponseHtml += "<tr><td>"+datasetNode.getElementsByTagName('MENS')[i].firstChild.data+"</td></tr>";
						for(j=0; j<dataValue.childNodes.length; j++)
						{
							reponseHtml += "<tr><td>"+dataValue.getElementsByTagName('VALUE')[j].firstChild.data+"</td></tr>";
						}
						reponseHtml += "</table>"
					}
				}
				if(ligne == 1)
				{						
					for(i=10; i<datasetNode.childNodes.length-3; i++ ) 
					{
						var dataValue = datasetNode.getElementsByTagName('DETAILS')[i];
						if(i%2 == 0)
						{
							reponseHtml += "<table class='tabSimulationIE'>";
						}
						else
						{
							reponseHtml += "<table class='tabSimulationGrayIE'>";
						}
						reponseHtml += "<tr><td>"+datasetNode.getElementsByTagName('DUREE')[i].firstChild.data+"</td></tr>";
						reponseHtml += "<tr><td>"+datasetNode.getElementsByTagName('MENS')[i].firstChild.data+"</td></tr>";
						for(j=0; j<dataValue.childNodes.length; j++)
						{
							reponseHtml += "<tr><td>"+dataValue.getElementsByTagName('VALUE')[j].firstChild.data+"</td></tr>";
						}
						reponseHtml += "</table>";
					}
				}						
			}
					
			/*----------------*/			
			
			
			var mentionsNode = xmlDoc.getElementsByTagName('MENTIONS_OFFRE')[0];
			var mentionsNodeGen = xmlDoc.getElementsByTagName('MENTIONS_GENERIQUES')[0];
			var mentionsNodeSiege = xmlDoc.getElementsByTagName('MENTIONS_SIEGE')[0];
			var mentionsNodeStatic = xmlDoc.getElementsByTagName('MENTIONS_STATIQUES_ASSURANCES')[0];
					
			var mentionStaticHTML = '';
			for(i=0; i<mentionsNodeStatic.childNodes.length; i++ ) 
			{
				var temp=mentionsNodeStatic.childNodes[i].firstChild.data;
				mentionStaticHTML+=''+temp+'\n';
			}
		
			var mentionsHtml = '<TEXTAREA cols="63" rows="8" readonly>'+mentionStaticHTML+mentionsNode.firstChild.data+'\n'+mentionsNodeGen.firstChild.data+'\n'+mentionsNodeSiege.firstChild.data+'</TEXTAREA>';
			reponseHtml +=mentionsHtml;
			
		  	$(noflashDiv).update(reponseHtml);
		  	$(noflashDiv).innerHTML;
		}
	  	else
	  	{	
			$(noflashDiv).update(MESS_SIMU_INDISPO);
		  	$(noflashDiv).innerHTML;
	  	}
	}
	catch(e)
	{
		try //Firefox, Mozilla, Opera, etc.
		{
			parser = new DOMParser();
			xmlDoc = parser.parseFromString(response.responseText,"text/xml");
			var nsResolver = xmlDoc.createNSResolver(xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
					/*--------------*/
		  	var nbSimulations = xmlDoc.evaluate("count(//SIMULATION)", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
			if(nbSimulations.numberValue > 0)
			{
				var reponseHtml = "<br/>";
				var nbligne = 1;
				if(nbSimulations.numberValue > 9)
					{nbligne = 2;}
					
				
				var headings = xmlDoc.evaluate("datas/simulations/SIMULATION", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
				var thisHeading = headings.iterateNext();
			
				var compteurSimulation = 0;
				/*------- TABLEAU DES LABELS -------*/
				reponseHtml += "<table class='tabSimulationFF'>";
				reponseHtml += "<tr><th>Duree en mois</th></tr>";
				reponseHtml += "<tr><th>Mensualite avec Options </th></tr>";
				var xmlDetails = xmlDoc.evaluate("DETAILS/DETAIL", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
				var thisDetail = xmlDetails.iterateNext();
				while(thisDetail)
				{
					var xmlLabel = xmlDoc.evaluate("LABEL", thisDetail, nsResolver, XPathResult.ANY_TYPE, null);
					var label = xmlLabel.iterateNext().firstChild.nodeValue;
					reponseHtml += "<tr><th>"+label+"</th></tr>";
					var thisDetail = xmlDetails.iterateNext();
				}	
				reponseHtml += "</table>";	
				/*------- FIN TABLEAU LABELS -------*/
				for(ligne=0;ligne<nbligne;ligne++)
				{
					if(ligne == 0)
					{
						while (thisHeading && compteurSimulation < 10)
						{
								if(compteurSimulation%2 == 0)
								{
									reponseHtml += "<table class='tabSimulationFF'>";
								}
								else
								{
									reponseHtml += "<table class='tabSimulationGrayFF'>";
								}
								var xmlDuree = xmlDoc.evaluate("DUREE", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var duration = xmlDuree.iterateNext().firstChild.nodeValue;
								reponseHtml += "<tr><td>"+duration+"</td></tr>";
								
							  	var xmlCost = xmlDoc.evaluate("MENS", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var cost = xmlCost.iterateNext().firstChild.nodeValue;
								reponseHtml += "<tr><td>"+cost+"</td></tr>";
								
								var xmlDetails = xmlDoc.evaluate("DETAILS/DETAIL", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var thisDetail = xmlDetails.iterateNext();
								while(thisDetail)
								{
									var xmlValue = xmlDoc.evaluate("VALUE", thisDetail, nsResolver, XPathResult.ANY_TYPE, null);
									var value = xmlValue.iterateNext().firstChild.nodeValue;
									reponseHtml += "<tr><td>"+value+"</td></tr>";
									var thisDetail = xmlDetails.iterateNext();
								}
								reponseHtml += "</table>";
								compteurSimulation++;
								thisHeading = headings.iterateNext();
						}	
					}
								
					if(ligne == 1)
					{
						while (thisHeading) 
						{														
							if(compteurSimulation > 9)
							{
								if(compteurSimulation%2 != 0)
								{
									reponseHtml += "<table class='tabSimulationFF'>";
								}
								else
								{
									reponseHtml += "<table class='tabSimulationGrayFF'>";
								}
								var xmlDuree = xmlDoc.evaluate("DUREE", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var duration = xmlDuree.iterateNext().firstChild.nodeValue;
								reponseHtml += "<tr><td>"+duration+"</td></tr>";
								
							  	var xmlCost = xmlDoc.evaluate("MENS", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var cost = xmlCost.iterateNext().firstChild.nodeValue;
								reponseHtml += "<tr><td>"+cost+"</td></tr>";
								
								var xmlDetails = xmlDoc.evaluate("DETAILS/DETAIL", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var thisDetail = xmlDetails.iterateNext();
								while(thisDetail)
								{
									var xmlValue = xmlDoc.evaluate("VALUE", thisDetail, nsResolver, XPathResult.ANY_TYPE, null);
									var value = xmlValue.iterateNext().firstChild.nodeValue;
									reponseHtml += "<tr><td>"+value+"</td></tr>";
									var thisDetail = xmlDetails.iterateNext();
								}
								reponseHtml += "</table>";
										
							}
							compteurSimulation++;
							thisHeading = headings.iterateNext();	
						}	
					}
			}					
							
			var mentionsNodeGen = xmlDoc.evaluate("datas/simulations/MENTIONS_GENERIQUES", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
				
			var mentionsNodeSiege = xmlDoc.evaluate("datas/simulations/MENTIONS_SIEGE", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
			var mentionsNode = xmlDoc.evaluate("datas/simulations/MENTIONS_OFFRE", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
			
			
			var xmlMentionsNodeStatic = xmlDoc.evaluate("datas/MENTIONS_STATIQUES_ASSURANCES", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
			var thisMentionsNodeStatic = xmlMentionsNodeStatic.iterateNext();
			var xmlMentionStatic = xmlDoc.evaluate("MENTION_STATIQUE_ASSURANCE", thisMentionsNodeStatic, nsResolver, XPathResult.ANY_TYPE, null);
			var thisMentionStatic = xmlMentionStatic.iterateNext();
			var mentionStaticHTML = '';
		
			while(thisMentionStatic)
			{					
				var temp = thisMentionStatic.firstChild.nodeValue;	
				mentionStaticHTML += temp+'\n';					
				thisMentionStatic = xmlMentionStatic.iterateNext();					
			}
			
			/*Creation du tableau HTML par rapport au doc xmlDoc et Xpath*/
			var mentionsHtml = '<TEXTAREA cols="64" rows="5" readonly>'+mentionStaticHTML+'\n'+mentionsNode.iterateNext().firstChild.nodeValue+'\n'+mentionsNodeGen.iterateNext().firstChild.nodeValue+'\n'+mentionsNodeSiege.iterateNext().firstChild.nodeValue+'</TEXTAREA>';
			reponseHtml +=mentionsHtml;
			
			$(noflashDiv).update(reponseHtml);
		  	$(noflashDiv).innerHTML;
						 
			}
			else
			{
				$(noflashDiv).update(MESS_SIMU_INDISPO);
		  		$(noflashDiv).innerHTML;
			}
		}
		catch(e) 
		{			
			$(noflashDiv).update(MESS_SIMU_INDISPO);
			$(noflashDiv).innerHTML;
		}
		
	}
}


/**
 *	########################################################################
 *	Construction du tableau html alternatif pour la simulation >> VAC <<
 *	########################################################################
 */
function buildVacArrayHtml(response, noflashDiv)
{
  		try //Internet Explorer
		{
			  	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			  	xmlDoc.async="false";	
			  	xmlDoc.loadXML(response.responseText);	
			  	var datasetNode = xmlDoc.getElementsByTagName('simulations')[0];
			  	if(datasetNode.childNodes.length > 3)
			  	{	
			  		var reponseHtml = "<br/>";
			  		
				  	/*------- TABLEAU DES LABELS -------*/
				  	reponseHtml += "<table class='tabSimulationIE'>";
				  	reponseHtml += "<tr><th>Duree en mois : </th></tr>";
					reponseHtml += "<tr><th>Mensualite : </th></tr>";
					var dataLabel = datasetNode.getElementsByTagName('DETAILS')[0];
					for(i=0; i<dataLabel.childNodes.length; i++ ) 
					{
						reponseHtml += "<tr><th>"+dataLabel.getElementsByTagName('LABEL')[i].firstChild.data+"</th></tr>";
					}
					reponseHtml += "</table>";
					/*------- FIN TABLEAU LABELS -------*/
					for(i=0; i<datasetNode.childNodes.length-3; i++ ) 
					{
						var dataValue = datasetNode.getElementsByTagName('DETAILS')[i];
						if(i%2 != 0)
						{
							reponseHtml += "<table class='tabSimulationIE'>";
						}
						else
						{
							reponseHtml += "<table class='tabSimulationGrayIE'>";
						}
						reponseHtml += "<tr><td>"+datasetNode.getElementsByTagName('DUREE')[i].firstChild.data+"</td></tr>";
						reponseHtml += "<tr><td>"+datasetNode.getElementsByTagName('MENS')[i].firstChild.data+"</td></tr>";
						for(j=0; j<dataValue.childNodes.length; j++)
						{
							reponseHtml += "<tr><td>"+dataValue.getElementsByTagName('VALUE')[j].firstChild.data+"</td></tr>";
						}
						reponseHtml += "</table>"
					}
				/*----------------*/	

					var mentionsNode = xmlDoc.getElementsByTagName('MENTIONS_OFFRE')[0];
					var mentionsNodeGen = xmlDoc.getElementsByTagName('MENTIONS_GENERIQUES')[0];
					var mentionsNodeSiege = xmlDoc.getElementsByTagName('MENTIONS_SIEGE')[0];
					var mentionsNodeStatic = xmlDoc.getElementsByTagName('MENTIONS_STATIQUES_ASSURANCES')[0];
					
					var mentionStaticHTML = '';
					for(i=0; i<mentionsNodeStatic.childNodes.length; i++ ) 
					{
						var temp=mentionsNodeStatic.childNodes[i].firstChild.data;
						mentionStaticHTML+=''+temp+'\n';
					}
					
					var mentionsHtml = '<TEXTAREA cols="75" rows="4" readonly>'+mentionStaticHTML+mentionsNode.firstChild.data+'\n'+mentionsNodeGen.firstChild.data+'\n'+mentionsNodeSiege.firstChild.data+'</TEXTAREA>';
				
					reponseHtml +=mentionsHtml;
							
									  	
				  	$(noflashDiv).update(reponseHtml);
				  	$(noflashDiv).innerHTML;
				  	
				}
				else
			  	{
					$(noflashDiv).update(MESS_SIMU_INDISPO);
				  	$(noflashDiv).innerHTML;
			  	}
		 }
		 catch(e) 
		 {
			try //Firefox, Mozilla, Opera, etc.
			{
				parser = new DOMParser();
				xmlDoc = parser.parseFromString(response.responseText,"text/xml");
				var nsResolver = xmlDoc.createNSResolver(xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);
						/*--------------*/
			  	var nbSimulations = xmlDoc.evaluate("count(//SIMULATION)", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
				if(nbSimulations.numberValue > 0)
				{
					var reponseHtml = "<br/>";
					
					var headings = xmlDoc.evaluate("datas/simulations/SIMULATION", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
					var thisHeading = headings.iterateNext();
					
					var compteurSimulation = 0;
					/*------- TABLEAU DES LABELS -------*/
					reponseHtml += "<table class='tabSimulationFF'>";
					reponseHtml += "<tr><th>Duree en mois</th></tr>";
					reponseHtml += "<tr><th>Mensualite avec Options </th></tr>";
					var xmlDetails = xmlDoc.evaluate("DETAILS/DETAIL", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
					var thisDetail = xmlDetails.iterateNext();
					while(thisDetail)
					{
						var xmlLabel = xmlDoc.evaluate("LABEL", thisDetail, nsResolver, XPathResult.ANY_TYPE, null);
						var label = xmlLabel.iterateNext().firstChild.nodeValue;
						reponseHtml += "<tr><th>"+label+"</th></tr>";
						var thisDetail = xmlDetails.iterateNext();
					}	
					reponseHtml += "</table>";	
					for(ligne=0;ligne<2;ligne++)
					{
						
						/*------- FIN TABLEAU LABELS -------*/
						if(ligne == 0)
						{
							while (thisHeading && compteurSimulation < 10) 
							{
								if(compteurSimulation%2 == 0)
								{
									reponseHtml += "<table class='tabSimulationFF'>";
								}
								else
								{
									reponseHtml += "<table class='tabSimulationGrayFF'>";
								}
								var xmlDuree = xmlDoc.evaluate("DUREE", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var duration = xmlDuree.iterateNext().firstChild.nodeValue;
								reponseHtml += "<tr><td>"+duration+"</td></tr>";
								
							  	var xmlCost = xmlDoc.evaluate("MENS", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var cost = xmlCost.iterateNext().firstChild.nodeValue;
								reponseHtml += "<tr><td>"+cost+"</td></tr>";
								
								var xmlDetails = xmlDoc.evaluate("DETAILS/DETAIL", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
								var thisDetail = xmlDetails.iterateNext();
								while(thisDetail)
								{
									var xmlValue = xmlDoc.evaluate("VALUE", thisDetail, nsResolver, XPathResult.ANY_TYPE, null);
									var value = xmlValue.iterateNext().firstChild.nodeValue;
									reponseHtml += "<tr><td>"+value+"</td></tr>";
									var thisDetail = xmlDetails.iterateNext();
								}
								reponseHtml += "</table>";
								compteurSimulation++;
								thisHeading = headings.iterateNext();
							}	
						}
						
						if(ligne == 1)
						{
							while (thisHeading) 
							{
								if(compteurSimulation > 9)
								{
									if(compteurSimulation%2 != 0)
									{
										reponseHtml += "<table class='tabSimulationFF'>";
									}
									else
									{
										reponseHtml += "<table class='tabSimulationGrayFF'>";
									}
									var xmlDuree = xmlDoc.evaluate("DUREE", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
									var duration = xmlDuree.iterateNext().firstChild.nodeValue;
									reponseHtml += "<tr><td>"+duration+"</td></tr>";
									
								  	var xmlCost = xmlDoc.evaluate("MENS", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
									var cost = xmlCost.iterateNext().firstChild.nodeValue;
									reponseHtml += "<tr><td>"+cost+"</td></tr>";
									
									var xmlDetails = xmlDoc.evaluate("DETAILS/DETAIL", thisHeading, nsResolver, XPathResult.ANY_TYPE, null);
									var thisDetail = xmlDetails.iterateNext();
									while(thisDetail)
									{
										var xmlValue = xmlDoc.evaluate("VALUE", thisDetail, nsResolver, XPathResult.ANY_TYPE, null);
										var value = xmlValue.iterateNext().firstChild.nodeValue;
										reponseHtml += "<tr><td>"+value+"</td></tr>";
										var thisDetail = xmlDetails.iterateNext();
									}
									reponseHtml += "</table>";
								}
								compteurSimulation++;
								thisHeading = headings.iterateNext();	
							}	
						}
					}
					var mentionsNodeGen = xmlDoc.evaluate("datas/simulations/MENTIONS_GENERIQUES", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
				
					var mentionsNodeSiege = xmlDoc.evaluate("datas/simulations/MENTIONS_SIEGE", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
					var mentionsNode = xmlDoc.evaluate("datas/simulations/MENTIONS_OFFRE", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
					
					
					
					var xmlMentionsNodeStatic = xmlDoc.evaluate("datas/MENTIONS_STATIQUES_ASSURANCES", xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
					var thisMentionsNodeStatic = xmlMentionsNodeStatic.iterateNext();
					var xmlMentionStatic = xmlDoc.evaluate("MENTION_STATIQUE_ASSURANCE", thisMentionsNodeStatic, nsResolver, XPathResult.ANY_TYPE, null);
					var thisMentionStatic = xmlMentionStatic.iterateNext();
					var mentionStaticHTML = '';
					
					while(thisMentionStatic)
					{					
						var temp = thisMentionStatic.firstChild.nodeValue;	
						mentionStaticHTML += temp+'\n';					
						thisMentionStatic = xmlMentionStatic.iterateNext();					
					}
	
					/*Creation du tableau HTML par rapport au doc xmlDoc et Xpath*/
					var mentionsHtml = '<TEXTAREA cols="75" rows="3" readonly>'+mentionStaticHTML+'\n'+mentionsNode.iterateNext().firstChild.nodeValue+'\n'+mentionsNodeGen.iterateNext().firstChild.nodeValue+'\n'+mentionsNodeSiege.iterateNext().firstChild.nodeValue+'</TEXTAREA>';
					reponseHtml +=mentionsHtml;

					$(noflashDiv).update(reponseHtml);
				  	$(noflashDiv).innerHTML;
				  	
					 
				}
		  	else
			{
				$(noflashDiv).update(MESS_SIMU_INDISPO);
			  	$(noflashDiv).innerHTML;
			}
		}
		catch(e) 
		{
			$(noflashDiv).update(MESS_SIMU_INDISPO);
			$(noflashDiv).innerHTML;
		}
		
	}	
}

/**
 *	########################################################################
 *	Verification des tops prestation pour decocher les cases des prestations 
 *  et cacher la zone de saisie des infos du v?hicule
 *	########################################################################
 */
function VerifTopPrestation(response,form,codePrestation,noeud, valeurNoeud){
	
	var thisPrestationIE = '';
	var thisPrestationFF = '';
  	try //Internet Explorer
	{
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";	
		xmlDoc.loadXML(response.responseText);	
		thisPrestationIE = xmlDoc.getElementsByTagName(noeud)[0].firstChild.data;						
	}
	catch(e) {
		try //Firefox, Mozilla, Opera, etc.
		{
			parser = new DOMParser();
			xmlDoc = parser.parseFromString(response.responseText,"text/xml");
			var nsResolver = xmlDoc.createNSResolver(xmlDoc.ownerDocument == null ? xmlDoc.documentElement : xmlDoc.ownerDocument.documentElement);

			/*Creation du tableau HTML par rapport au doc xmlDoc et Xpath*/
			var topPrestation = xmlDoc.evaluate('//'+noeud, xmlDoc, nsResolver, XPathResult.ANY_TYPE, null);
			thisPrestationFF = topPrestation.iterateNext().firstChild.nodeValue;
																	
		}
		catch(e) {
			//il n'a pas reussi a prendre la valeur du noeud donc il est vide						
			if (thisPrestationIE != valeurNoeud && thisPrestationFF != valeurNoeud)
			{
				var maform = document.forms[0];					
				for (var champ=0; champ < maform.elements.length; champ++) 
				{						
					if (maform.elements[champ].value == codePrestation)						
					{																		
						document.forms[0].elements[champ].checked = false;
						gestionPrestation(this, form, false);
						
						$('band-erreur').update("Ce v&eacute;hicule ne peut pr&eacute;tendre &agrave; l'option s&eacute;lectionn&eacute;e");
						$('band-erreur').innerHTML;					
					}
				}												
			}
		}
	}
}


