function constructCriteres(mod_annee){marque=document.getElementById('marques');modele=document.getElementById('modeles');annee=document.getElementById('circulationYear');alimentation=document.getElementById('alimentation');cylindree=document.getElementById('cylindree');puissance=document.getElementById('puissance');m='';if(marque!==undefined){m=marque.value}mo='';if(modele!==undefined){mo=modele.value}a='';if(annee!==undefined){a=annee.value}al='';if(alimentation!==undefined){al=alimentation.value}cy='';if(cylindree!==undefined){cy=cylindree.value}pu='';if(puissance!==undefined){pu=puissance.value}callCriteres(m,mo,a,al,cy,pu)}var _xmlModelesHttp=null;var _adresseCarnet='/CarnetEntretienFiche.aspx';var TModeles=null;var TModelesID=null;function getXMLHTTP(){var xhr=null;if(window.XMLHttpRequest)xhr=new XMLHttpRequest();else if(window.ActiveXObject){try{xhr=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{xhr=new ActiveXObject("Microsoft.XMLHTTP")}catch(e1){xhr=null}}}else{alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...")}return xhr}function callModeles(valeur){_xmlModelesHttp=null;TModeles=null;TModelesID=null;if(_xmlModelesHttp&&_xmlModelesHttp.readyState!==0){_xmlModelesHttp.abort()}_xmlModelesHttp=getXMLHTTP();if(_xmlModelesHttp){_xmlModelesHttp.open("GET",_adresseCarnet+"?id_marque="+valeur+"&nocache="+Math.random(),true);_xmlModelesHttp.onreadystatechange=function(){if(_xmlModelesHttp.readyState==4&&_xmlModelesHttp.responseXML){TModeles=traiteXml(_xmlModelesHttp.responseXML,'option');TModelesID=traiteXmlID(_xmlModelesHttp.responseXML,'option');metsEnPlaceModeles(TModeles,TModelesID);if(_adresseCarnet!='/ContactezNous.aspx'){viderSelect(document.getElementById('circulationYear'));mySelectYear._onChangeFunction=function(){return false};mySelectYear.init();addOption(document.getElementById('circulationYear'),'','An');mySelectYear.init();mySelectYear._onChangeFunction=function(){constructCriteres(true)};mySelectAlimentation._onChangeFunction=function(){return false};mySelectAlimentation.init();viderSelect(document.getElementById('alimentation'));addOption(document.getElementById('alimentation'),'','Choix alimentation');mySelectAlimentation.init();mySelectAlimentation._onChangeFunction=function(){constructCriteres(false)};mySelectCylindree._onChangeFunction=function(){return false};mySelectCylindree.init();viderSelect(document.getElementById('cylindree'));addOption(document.getElementById('cylindree'),'','Choix cylindree');mySelectCylindree.init();mySelectCylindree._onChangeFunction=function(){constructCriteres(false)};mySelectPuissance._onChangeFunction=function(){return false};mySelectPuissance.init();viderSelect(document.getElementById('puissance'));addOption(document.getElementById('puissance'),'','Choix puissance');mySelectPuissance.init();mySelectPuissance._onChangeFunction=function(){constructCriteres(false)}}}};_xmlModelesHttp.send(null)}}var TCriteres=null;var _xmlCriteresHttp=null;function callCriteres(marque,modele,annee,alimentation,cylindree,puissance){_xmlCriteresHttp=null;if(_xmlCriteresHttp&&_xmlCriteresHttp.readyState!==0){_xmlCriteresHttp.abort()}_xmlCriteresHttp=getXMLHTTP();if(_xmlCriteresHttp){_xmlCriteresHttp.open("GET",_adresseCarnet+"?upd_criteres=1&marque="+marque+"&modele="+modele+"&annee="+annee+"&alimentation="+alimentation+"&cylindree="+cylindree+"&puissance="+puissance+"&nocache="+Math.random(),true);_xmlCriteresHttp.onreadystatechange=function(){if(_xmlCriteresHttp.readyState==4&&_xmlCriteresHttp.responseXML){mySelectAlimentation._onChangeFunction=function(){return false};mySelectAlimentation.init();traiteXmlCriteres(_xmlCriteresHttp.responseXML,'Alimentations','alimentation');mySelectAlimentation._onChangeFunction=function(){return false};mySelectAlimentation.init();mySelectAlimentation._onChangeFunction=function(){constructCriteres(false)};mySelectCylindree._onChangeFunction=function(){return false};mySelectCylindree.init();traiteXmlCriteres(_xmlCriteresHttp.responseXML,'Cylindrees','cylindree');mySelectCylindree._onChangeFunction=function(){return false};mySelectCylindree.init();mySelectCylindree._onChangeFunction=function(){constructCriteres(false)};mySelectPuissance._onChangeFunction=function(){return false};mySelectPuissance.init();traiteXmlCriteres(_xmlCriteresHttp.responseXML,'Puissances','puissance');mySelectPuissance._onChangeFunction=function(){return false};mySelectPuissance.init();mySelectPuissance._onChangeFunction=function(){constructCriteres(false)}}};_xmlCriteresHttp.send(null)}}function traiteXmlCriteres(xml,elem,name_select){optionsRoot=xml.getElementsByTagName(elem);options=optionsRoot[0].childNodes;optionsListe=new Array();selection=1;optionsListe.push('Choix '+name_select);for(var i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data);if(options[i].getAttribute('selected')!==null){selection=options[i].getAttribute('value')}}viderSelect(document.getElementById(name_select));for(i=0;i<optionsListe.length;i++){if(i===0){addOption(document.getElementById(name_select),'',optionsListe[i])}else{addOption(document.getElementById(name_select),optionsListe[i],optionsListe[i])}if(selection==optionsListe[i]){document.getElementById(name_select).selectedIndex=i}}}var _xmlAnneesHttp=null;var TAnnees=null;var _adresseContact='/ContactezNous.aspx';var _adresseContact2='';function callAnnees(valeur,id_modele){_xmlAnneesHttp=null;TAnnees=null;TAnneesID=null;if(_xmlAnneesHttp&&_xmlAnneesHttp.readyState!==0){_xmlAnneesHttp.abort()}_xmlAnneesHttp=getXMLHTTP();if(_xmlAnneesHttp){_xmlAnneesHttp.open("GET",_adresseContact+"?id_marque="+valeur+"&id_modele="+id_modele+"&nocache="+Math.random(),true);_xmlAnneesHttp.onreadystatechange=function(){if(_xmlAnneesHttp.readyState==4&&_xmlAnneesHttp.responseXML){TAnnees=traiteXml(_xmlAnneesHttp.responseXML,'option');TAnneesID=traiteXmlID(_xmlAnneesHttp.responseXML,'option');if(_adresseContact=='/ContactezNous.aspx'){metsEnPlaceAnnees(TAnnees)}else{metsEnPlaceAnneesCE(TAnnees,TAnneesID)}}};_xmlAnneesHttp.send(null)}}function metsEnPlaceAnneesCE(liste_val,liste_val_id){if(typeof(mySelectYear)!="undefined"){viderSelect(document.getElementById('circulationYear'));mySelectYear.init();for(i=0;i<liste_val.length;i++){addOption(document.getElementById('circulationYear'),liste_val_id[i],liste_val[i])}mySelectYear.init()}else if(typeof(mySelectAnnees)!="undefined"){viderSelect($('annees'));mySelectAnnees.init();for(i=0;i<liste_val.length;i++){addOption(document.getElementById('annees'),liste_val_id[i],liste_val[i])}mySelectAnnees.init()}}var _xmlMineHttp=null;var TMine=null;function callMine(mine){_xmlMineHttp=null;if(_xmlMineHttp&&_xmlMineHttp.readyState!==0){_xmlMineHttp.abort()}_xmlMineHttp=getXMLHTTP();if(_xmlMineHttp){_xmlMineHttp.open("GET",_adresseContact+"?mine="+mine+"&nocache="+Math.random(),true);_xmlMineHttp.onreadystatechange=function(){if(_xmlMineHttp.readyState==4&&_xmlMineHttp.responseXML){var optionsRoot=null;var options=null;var optionsListe=new Array();var optionsListeId=new Array();var selection=1;optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Marques');if(optionsRoot[0]!==null){options=optionsRoot[0].childNodes;optionsListe=new Array();optionsListeId=new Array();selection=1;for(i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data);optionsListeId.push(options[i].getAttribute('value'));if(options[i].getAttribute('selected')!==null){selection=options[i].getAttribute('value')}}viderSelect(document.getElementById('marques'));mySelectMarques.init();mySelectMarques._onChangeFunction=function(){return false};for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('marques'),optionsListeId[i],optionsListe[i]);if(selection==optionsListeId[i]){document.getElementById('marques').selectedIndex=i}}mySelectMarques._onChangeFunction=function(){return false};mySelectMarques.init();mySelectMarques._onChangeFunction=function(){_adresseCarnet='/ContactezNous.aspx';if(document.getElementById('marques').value!=-1){callModeles(document.getElementById('marques').value)}};optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Modeles');options=optionsRoot[0].childNodes;optionsListe=new Array();optionsListeId=new Array();for(i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data);optionsListeId.push(options[i].getAttribute('value'));if(options[i].getAttribute('selected')!==null){selection=options[i].getAttribute('value')}}viderSelect(document.getElementById('modeles'));mySelectModeles.init();for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('modeles'),optionsListeId[i],optionsListe[i]);if(selection==optionsListeId[i]){document.getElementById('modeles').selectedIndex=i}}mySelectModeles.init();optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Annees');options=optionsRoot[0].getElementsByTagName('option');optionsListe=new Array();for(i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data)}viderSelect(document.getElementById('annees'));mySelectAnnees.init();for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('annees'),optionsListe[i],optionsListe[i])}mySelectAnnees.init()}else{alert('Le type mine saisi n\'a pas ete identifie.')}}};_xmlMineHttp.send(null)}}function callMine2(mine){_xmlMineHttp=null;if(_xmlMineHttp&&_xmlMineHttp.readyState!==0){_xmlMineHttp.abort()}_xmlMineHttp=getXMLHTTP();if(_xmlMineHttp){_xmlMineHttp.open("GET",_adresseCarnet+"?type_mine="+mine+"&nocache="+Math.random(),true);_xmlMineHttp.onreadystatechange=function(){if(_xmlMineHttp.readyState==4&&_xmlMineHttp.responseXML){var optionsRoot=null;var options=null;var optionsListe=new Array();var optionsListeId=new Array();var selection=1;optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Marques');if(optionsRoot[0]!==null){options=optionsRoot[0].childNodes;optionsListe=new Array();optionsListeId=new Array();selection=1;for(var i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data);optionsListeId.push(options[i].getAttribute('value'));if(options[i].getAttribute('selected')!==null){selection=options[i].getAttribute('value')}}viderSelect(document.getElementById('marques'));mySelectMarques.init();mySelectMarques._onChangeFunction=function(){return false};for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('marques'),optionsListeId[i],optionsListe[i]);if(selection==optionsListeId[i]){document.getElementById('marques').selectedIndex=i}}mySelectMarques._onChangeFunction=function(){return false};mySelectMarques.init();mySelectMarques._onChangeFunction=function(){if(document.getElementById('marques').value!=-1){callModeles(document.getElementById('marques').value)}};optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Modeles');options=optionsRoot[0].childNodes;optionsListe=new Array();optionsListeId=new Array();for(i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data);optionsListeId.push(options[i].getAttribute('value'));if(options[i].getAttribute('selected')!==null){selection=options[i].getAttribute('value')}}viderSelect(document.getElementById('modeles'));mySelectModeles._onChangeFunction=function(){return false};mySelectModeles.init();for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('modeles'),optionsListeId[i],optionsListe[i]);if(selection==optionsListeId[i]){document.getElementById('modeles').selectedIndex=i}}mySelectModeles.init();mySelectModeles._onChangeFunction=function(){if(document.getElementById('modeles').value!==-1&&document.getElementById('modeles').value!==''){_adresseContact='/CarnetEntretienFiche.aspx';callAnnees(document.getElementById('marques').value,document.getElementById('modeles').value)}};optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Annees');options=optionsRoot[0].getElementsByTagName('option');optionsListe=new Array();for(i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data)}viderSelect(document.getElementById('circulationYear'));mySelectYear._onChangeFunction=function(){return false};mySelectYear.init();for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('circulationYear'),optionsListe[i],optionsListe[i])}mySelectYear.init();mySelectYear._onChangeFunction=function(){constructCriteres(true)};selection='';optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Alimentations');options=optionsRoot[0].getElementsByTagName('option');optionsListe=new Array();for(i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data);if(options[i].getAttribute('selected')!==null){selection=options[i].getAttribute('value')}}mySelectAlimentation._onChangeFunction=function(){return false};mySelectAlimentation.init();viderSelect(document.getElementById('alimentation'));for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('alimentation'),optionsListe[i],optionsListe[i]);if(selection==optionsListe[i]){document.getElementById('alimentation').selectedIndex=i}}mySelectAlimentation.init();mySelectAlimentation._onChangeFunction=function(){constructCriteres(false)};selection='';optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Cylindrees');options=optionsRoot[0].getElementsByTagName('option');optionsListe=new Array();for(i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data);if(options[i].getAttribute('selected')!==null){selection=options[i].getAttribute('value')}}mySelectCylindree._onChangeFunction=function(){return false};mySelectCylindree.init();viderSelect(document.getElementById('cylindree'));for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('cylindree'),optionsListe[i],optionsListe[i]);if(selection==optionsListe[i]){document.getElementById('cylindree').selectedIndex=i}}mySelectCylindree.init();mySelectCylindree._onChangeFunction=function(){constructCriteres(false)};selection='';optionsRoot=_xmlMineHttp.responseXML.getElementsByTagName('Puissances');options=optionsRoot[0].getElementsByTagName('option');optionsListe=new Array();for(i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data);if(options[i].getAttribute('selected')!==null){selection=options[i].getAttribute('value')}}mySelectPuissance._onChangeFunction=function(){return false};mySelectPuissance.init();viderSelect(document.getElementById('puissance'));for(i=0;i<optionsListe.length;i++){addOption(document.getElementById('puissance'),optionsListe[i],optionsListe[i]);if(selection==optionsListe[i]){document.getElementById('puissance').selectedIndex=i}}mySelectPuissance.init();mySelectPuissance._onChangeFunction=function(){constructCriteres(false)}}else{alert('Le type mine saisi n\'a pas ete identifie.')}}};_xmlMineHttp.send(null)}}function traiteXml(xmlDoc,nomElem){var options=xmlDoc.getElementsByTagName(nomElem);var optionsListe=new Array();for(var i=0;i<options.length;i++){optionsListe.push(options[i].firstChild.data)}return optionsListe}function traiteXmlID(xmlDoc,nomElem){var options=xmlDoc.getElementsByTagName(nomElem);var optionsListe=new Array();for(var i=0;i<options.length;i++){optionsListe.push(options[i].getAttribute('value'))}return optionsListe}function metsEnPlaceModeles(liste_val,liste){viderSelect(document.getElementById('modeles'));mySelectModeles._onChangeFunction=function(){return false};mySelectModeles.init();for(i=0;i<liste.length;i++){addOption(document.getElementById('modeles'),liste[i],liste_val[i])}mySelectModeles.init();mySelectModeles._onChangeFunction=function(){if(document.getElementById('modeles').value!==-1&&document.getElementById('modeles').value!==''){if(_adresseContact2!='/ContactezNous.aspx'){_adresseContact='/CarnetEntretienFiche.aspx'}callAnnees(document.getElementById('marques').value,document.getElementById('modeles').value)}}}function metsEnPlaceAnnees(liste_val){viderSelect(document.getElementById('annees'));mySelectAnnees.init();for(i=0;i<liste_val.length;i++){addOption(document.getElementById('annees'),liste_val[i],liste_val[i])}mySelectAnnees.init()}function viderSelect(selectbox){while(selectbox.options.length>0){selectbox.options[0]=null}}function addOption(selectbox,value,text){var optn=document.createElement("OPTION");optn.text=text;optn.value=value;selectbox.options.add(optn)}function compare_date_carnet(){date_1=new Date(document.getElementById('ctYear').value,document.getElementById('ctMonth').value-1,document.getElementById('ctDay').value);date_2=new Date(document.getElementById('circulationYear').value,document.getElementById('circulationMonth').value-1,document.getElementById('circulationDay').value);diff=date_2.getTime()-date_1.getTime();return(diff==0?diff:diff/Math.abs(diff))}function verif_carnet(){var Erreur="";if(document.getElementById('marques').value==-1){Erreur=Erreur+"Veuillez choisir une marque ainsi qu'un modele.\n"}if(document.getElementById('circulationYear').value==''||document.getElementById('circulationYear').value=='-1'||document.getElementById('circulationYear').value=='An'){Erreur=Erreur+'Veuillez choisir une annee de mise en circulation.\n'}if(document.getElementById('immatriculation').value.length==0){Erreur=Erreur+"Veuillez renseigner l'immatriculation de votre vehicule.\n"}if(document.getElementById('kmcompteur').value.length==0){Erreur=Erreur+"Veuillez renseigner le kilometrage au compteur de votre vehicule.\n"}if(compare_date_carnet()>0){Erreur=Erreur+"La date de mise en circulation doit etre inferieure a la date du dernier controle technique.\n"}retImmat=validImmat(document.getElementById('immatriculation').value);if(retImmat!=document.getElementById('immatriculation').value){Erreur=Erreur+"L'immatriculation ne doit contenir que des lettres majuscules et des chiffres.\n"}if(Erreur.length!=0){alert(Erreur);return false}else{return true}}
