+<script type="text/javascript">// <!--
+ var baseurl = platal_baseurl + "search/";
+ {literal}
+ // display an autocomplete row : blabla (nb of found matches)
+ function make_format_autocomplete(block) {
+ return function(row) {
+ regexp = new RegExp('(' + RegExp.escape(block.value) + ')', 'i');
+
+ name = row[0].replace(regexp, '<strong>$1<\/strong>');
+
+ if (row[1] === "-1") {
+ return '...';
+ }
+
+ camarades = (row[1] > 1) ? "camarades" : "camarade";
+
+ return name + '<em> - ' + row[1] + ' ' + camarades + '<\/em>';
+ };
+ }
+
+ // when changing country, open up region choice
+ function changeCountry(a2) {
+ $(".autocompleteTarget[@name='country']").attr('value',a2);
+
+ if (a2) {
+ $(".autocomplete[@name='countryTxt']").addClass('hidden_valid');
+
+ $("[@name='region']").parent().load(baseurl + 'list/region/', { country:a2 }, function() {
+ if ($("select[@name='region']").children("option").size() > 1) {
+ $("select[@name='region']").attr('value', '{/literal}{$smarty.request.region}{literal}');
+
+ $("tr#region_ln").show();
+ } else {
+ $("select[@name='region']").attr('value', '');
+
+ $("tr#region_ln").hide();
+ }
+ });
+ } else {
+ $(".autocomplete[@name='countryTxt']").removeClass('hidden_valid');
+
+ $("select[@name='region']").attr('value', '');
+
+ $("tr#region_ln").hide();
+ }
+ }
+
+ // when changing school, open diploma choice
+ function changeSchool(schoolId) {
+ $(".autocompleteTarget[@name='school']").attr('value',schoolId);
+
+ if (schoolId) {
+ $(".autocomplete[@name='schoolTxt']").addClass('hidden_valid');
+ } else {
+ $(".autocomplete[@name='schoolTxt']").removeClass('hidden_valid');
+ }
+
+ $("[@name='diploma']").parent().load(baseurl + 'list/diploma/', { school:schoolId }, function() {
+ $("select[@name='diploma']").attr('value', '{/literal}{$smarty.request.diploma}{literal}');
+ });
+ }
+
+ // when choosing autocomplete from list, must validate
+ function select_autocomplete(name) {
+ nameRealField = name.replace(/Txt$/, '');
+
+ // nothing to do if field is not a text field for a list
+ if (nameRealField == name)
+ return null;
+
+ // if changing country, might want to open region choice
+ if (nameRealField == 'country')
+ return function(i) {
+ changeCountry(i.extra[1]);
+ }
+
+ if (nameRealField == 'school')
+ return function(i) {
+ changeSchool(i.extra[1]);
+ }
+
+ // change field in list and display text field as valid
+ return function(i) {
+ nameRealField = this.field.replace(/Txt$/, '');
+
+ $(".autocompleteTarget[@name='"+nameRealField+"']").attr('value',i.extra[1]);
+
+ $(".autocomplete[@name='"+this.field+"']").addClass('hidden_valid');
+ }