function isCP(a){return a.length==5&&!isNaN(a)}function getHidden(a){return $("#"+a.attr("id")+"Hidden")}function razCpCom(b,c){var a={"Code Postal":"cp",Commune:"commune"};b=b.parent().html('<input type="text" tabindex="'+b.attr("tabindex")+'" class="text '+a[c]+'" id="'+b.attr("id")+'" name="'+b.attr("name")+'" />').children();getHidden(b).val("");textInput(b,c);return b.each(function(){initQuestion($(this).parents(".lq"))})}function majCom(b,a,f){if(submitSuspended){return false}a=razCpCom(a,"Commune");var d=b.val();try{submitSuspended=true;jQuery.ifajax.ajax({type:"GET",url:settings.url_ajax_cp,data:{cp:d,com:""},cache:false,dataType:"json",success:function(g){submitSuspended=false;if(g.com.length===0){textInput(a,"Commune");b.focus();setErreurMsg(b,"Aucune commune trouvée pour le code postal "+d+" !")}else{if(g.com.length==1){a.val(g.com[0]);getHidden(a).val(a.val())}else{if(g.com.length>1){a=a.parent().html('<select class="select commune" tabindex="'+a.attr("tabindex")+'" id="'+a.attr("id")+'" name="'+a.attr("name")+'"></select>').children();a.append('<option value="Choix">Choisissez...</option>');for(var e=0;e<g.com.length;e++){a.append("<option>"+g.com[e]+"</option>")}a.each(function(){initQuestion($(this).parents(".lq"))});a.focus()}}}if(g.com.length>=1){if(typeof f=="function"){majErreur(a,f())}else{majErreur(a,g.com.length==1)}}else{majErreur(a,false)}},error:function(){submitSuspended=false;if(typeof f=="function"){majErreur(a,f())}else{majErreur(a,true)}a.focus();return false}})}catch(c){submitSuspended=false;if(typeof f=="function"){majErreur(a,f())}else{majErreur(a,true)}a.focus()}return a}function majCp(a,b,d){if(submitSuspended){return false}b=razCpCom(b,"Code Postal");try{submitSuspended=true;jQuery.ifajax.ajax({type:"GET",url:settings.url_ajax_cp,data:{cp:"",com:a.val().toUpperCase()},cache:false,dataType:"json",success:function(f){submitSuspended=false;if(f.cp.length===0){textInput(b,"Code Postal");a.focus();setErreurMsg(a,"Aucune commune a été trouvée portant ce nom !")}else{if(f.cp.length==1){b.val(f.cp[0]);getHidden(b).val(b.val());a.parents("li").next("li:visible").find(":input").focus();a.val(a.val().toUpperCase())}else{if(f.cp.length>1){b=b.parent().html('<select class="select cp" tabindex="'+b.attr("tabindex")+'" id="'+b.attr("id")+'" name="'+b.attr("name")+'"></select>').children();b.append('<option value="Choix">Choisissez...</option>');for(var e=0;e<f.cp.length;e++){b.append("<option>"+f.cp[e]+"</option>")}b.each(function(){initQuestion($(this).parents(".lq"))});b.focus();a.val(a.val().toUpperCase())}}}if(f.cp.length>=1){if(typeof d=="function"){majErreur(b,d())}else{majErreur(b,f.cp.length==1)}}else{majErreur(b,false)}},error:function(){submitSuspended=false;if(typeof d=="function"){majErreur(b,d())}else{majErreur(b,true)}b.focus();return false}})}catch(c){submitSuspended=false;if(typeof d=="function"){majErreur(b,d())}else{majErreur(b,true)}b.focus()}return b}function verifCp(d,a,b,f){b=b||{type:""};var e=d.val();var c=getHidden(d);if(b.type=="change"){c.val(e)}else{if(c.val().length>0){d.val(c.val())}}if(e=="Choix"){setErreurMsg(a,"Sélectionnez le code postal dans la liste.",true);return typeof f=="function"?majErreur(d,f()):false}else{if(d.is("select")){return typeof f=="function"?majErreur(d,f()):true}else{if(e==d.data("valeurVide")){setErreurMsg(d,settings.msg_cp_com_vide,true);return typeof f=="function"?majErreur(d,f()):false}else{if(e.length===0||!isCP(e)){setErreurMsg(d,settings.msg_cp_com_vide,true);a=razCpCom(a,"Commune");a.focus();return typeof f=="function"?majErreur(d,f()):false}}}}if(b.type=="change"){a=majCom(d,a,f);return"wait"}return typeof f=="function"?majErreur(d,f()):true}function verifCom(c,f,e,g){e=e||{type:""};var d=c.val();var b=getHidden(c);var a=b.val()!=d;if(e.type=="change"){b.val(d)}else{if(b.val().length>0){c.val(b.val())}}if(d=="Choix"){setErreurMsg(c,"Sélectionnez la commune dans la liste.",true);return typeof g=="function"?majErreur(c,g()):false}else{if(c.is("select")){return typeof g=="function"?majErreur(c,g()):true}}if(d==c.data("valeurVide")){setErreurMsg(c,settings.msg_cp_com_vide,true);return typeof g=="function"?majErreur(c,g()):false}else{if(d.length===0||!isNaN(d)){setErreurMsg(c,settings.msg_cp_com_vide,true);f=razCpCom(f,"Code Postal");f.focus();return typeof g=="function"?majErreur(c,g()):false}else{if(e.type=="change"&&a){f=majCp(c,f,g);return"wait"}}}return typeof g=="function"?majErreur(c,g()):true};