%( $Id: deslist_months.txt mickroue(a)yahoo.fr 20140127 templ=templm %)

%define;lex_month(xx)
  %apply;nth%with;
    /[*(month)]0/[*(month)]1/[*(month)]2/[*(month)]3/[*(month)]4/[*(month)]5/[*(month)]6/[*(month)]7/[*(month)]8/[*(month)]9/[*(month)]10/[*(month)]11%and;
    xx%end;
%end;

%define;monthsc()
  <span class="s4" style="top:3em;">[*(month)]0</span>
  <span class="s4" style="top:4em;">[*(month)]1</span>
  <span class="s4" style="top:5em;">[*(month)]2</span>
  <span class="s4" style="top:6em;">[*(month)]3</span>
  <span class="s4" style="top:7em;">[*(month)]4</span>
  <span class="s4" style="top:8em;">[*(month)]5</span>
  <span class="s4" style="top:9em;">[*(month)]6</span>
  <span class="s4" style="top:10em;">[*(month)]7</span>
  <span class="s4" style="top:11em;">[*(month)]8</span>
  <span class="s4" style="top:12em;">[*(month)]9</span>
  <span class="s4" style="top:13em;">[*(month)]10</span>
  <span class="s4" style="top:14em;">[*(month)]11</span>
%end;

%define;monthsb(z1,z2)
  %reset_count;
  %foreach;sorted_list_item;
    %if;(prev_item.1 != item.1)
      <div class="s1 bcbg1" style="height:160px;">
      <strong style="margin:3px;">%apply;lex_month(item.1)</strong>
      %apply;monthsc()
    %end;      
    %if;(prev_item.1 != item.1 or prev_item.2 != item.2 or prev_item.3 != item.3)
      %reset_count;%incr_count;
      <a href="%prefix;spouse=on;m=RLM;i%count;=%item.4;;t%count;=%count;;%nn;
    %end;
    %if;(prev_item.1 = item.1 and prev_item.2 = item.2 and prev_item.3 = item.3)
      %incr_count;
      i%count;=%item.4;;t%count;=%count;;%nn;
    %end;
    %if;(next_item.1 != item.1 or next_item.2 != item.2 or next_item.3 != item.3)
      %let;l_top;%expr(item.3 + 2)%in;
      %let;l_width0;%expr(count * l_size)%in;
      %let;l_width;%if;(l_width0 > max_width)%max_width;%else;%l_width0;%end;%in;
      %incr_count;
      i%count;=%index;;t%count;=z1%apply;lex_month(item.1)--z2%apply;lex_month(item.3)%nn;
      %if;(max_event >= count)
        " class="s5%item.2;" style="top:%l_top;em;border-width:%l_width;px;">%expr(count - 1)</a>
      %else;
        " style="display:none;"></a>
        <span class="s5%item.2;" style="top:%l_top;em;border-width:%l_width;px;">%count;</span>
      %end;
      %if;(next_item.1 != item.1)
        </div>
      %end;
    %end;
  %end;
%end;


%define;dmonthsa(z1,z2,z3,z4,curlev,maxlev)
  %foreach;family;
    %if;(curlev < maxlev and family.desc_level = curlev)
      %family.set_infinite_desc_level;
      %if;(z1 != "" and z3 != "")
        %incr_count;
        %apply;add_in_sorted_list(z1,z2,z3,z4)
      %end;
      %if;(has_children)
        %foreach;child;
          %apply;dmonthsa("z1","z2","z3","z4",curlev+1,maxlev)
        %end;
      %end;
    %end;
  %end;
%end;

%define;dmonthsd(z1,z2,z3,z4,curlev,maxlev)
  %if;(z1 != "" and z3 != "")
    %incr_count;
    %apply;add_in_sorted_list(z1,z2,z3,z4)
  %end;
  %foreach;family;
    %if;(curlev < maxlev and family.desc_level = curlev)
      %family.set_infinite_desc_level;
      %if;(has_children)
        %foreach;child;
          %apply;dmonthsd("z1","z2","z3","z4",curlev+1,maxlev)
        %end;
      %end;
    %end;
  %end;
%end;

%define;dmonths()
  %reset_count;%reset_desc_level;%empty_sorted_list;
  %if;(evar.tl2 = "1")
    <h3>[year/month/day]1 [birth] = [year/month/day]1 [birth] [spouse/spouses]0 ?</h3>
    %apply;dmonthsa("birth_date.month","spouse.sex","spouse.birth_date.month","spouse.index",0,l_v)
  %elseif;(evar.tl2 = "2")
    <h3>[year/month/day]1 [birth] = [year/month/day]1 [death] [spouse/spouses]0 ?</h3>
    %apply;dmonthsa("birth_date.month","spouse.sex","spouse.death_date.month","spouse.index",0,l_v)
  %elseif;(evar.tl2 = "3")
    <h3>[year/month/day]1 [death] = [year/month/day]1 [death] [spouse/spouses]0 ?</h3>
    %apply;dmonthsa("death_date.month","spouse.sex","spouse.death_date.month","spouse.index",0,l_v)
  %elseif;(evar.tl2 = "4")
    <h3>[year/month/day]1 [death] = [year/month/day]1 [birth] [spouse/spouses]0 ?</h3>
    %apply;dmonthsa("death_date.month","spouse.sex","spouse.birth_date.month","spouse.index",0,l_v)
  %else;
    <h3>[year/month/day]1 [birth] = [year/month/day]1 [death] ?</h3>
    %apply;dmonthsd("birth_date.month","sex","death_date.month","index",0,l_v)
  %end;
  %let;nb_date;%count;%in;
  <p>[*total] = %count; [person/persons]1</p>
  %let;l_size;%expr(120 / ((30 + nb_date) / 3 / 10))%in;
  %let;l_z1;
    %if;(evar.tl2 = "1" or evar.tl2 = "2")%birth_symbol;
    %elseif;(evar.tl2 = "3" or evar.tl2 = "4")%death_symbol;
    %else;%birth_symbol;
    %end;
  %in;
  %let;l_z2;
    %if;(evar.tl2 = "1" or evar.tl2 = "4")x%birth_symbol;
    %elseif;(evar.tl2 = "2" or evar.tl2 = "3")x%death_symbol;
    %else;%death_symbol;
    %end;
  %in
  %apply;monthsb(l_z1,l_z2)
%end;

%( tl1 = months %)
%let;max_width;180%in;
%let;l_url;%prefix;m=D;t=L;i=%index;;v=%l_v;;maxv=%evar.maxv;%in;
<div class="menu">
  <span><a href="%l_url;;tl1=months;tl2=">%birth_symbol; = %death_symbol; ?</a></span>
  <span><a href="%l_url;;tl1=months;tl2=1">%birth_symbol; = x%birth_symbol; ?</a></span>
  <span><a href="%l_url;;tl1=months;tl2=2">%birth_symbol; = x%death_symbol; ?</a></span>
  <span><a href="%l_url;;tl1=months;tl2=3">%death_symbol; = x%death_symbol; ?</a></span>
  <span><a href="%l_url;;tl1=months;tl2=4">%death_symbol; = x%birth_symbol; ?</a></span>
</div>
<p>%apply;togen(l_v)</p>
%apply;dmonths()
