Bug 11088: Floating Save div for Patron entry page
[srvgit] / koha-tmpl / intranet-tmpl / prog / en / modules / members / memberentrygen.tt
index 0098c09..87cc2c4 100644 (file)
+[% USE Koha %]
+[% USE KohaDates %]
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Patrons &rsaquo; 
-[% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] [% IF ( categoryname ) %] [% categoryname %] patron[% ELSE %][% IF ( I ) %] Organization patron[% END %][% IF ( A ) %] Adult patron[% END %][% IF ( C ) %] Child patron[% END %][% IF ( P ) %] Professional patron[% END %][% IF ( S ) %] Staff patron[% END %][% END %][% UNLESS ( opadd ) %] [% surname %], [% firstname %][% END %]</title>
+<title>Koha &rsaquo; Patrons &rsaquo; [% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] patron [% IF (firstname) %][% firstname %] [% END %][% IF (surname) %][% surname %] [% END %]([%IF ( categoryname ) %][% categoryname %][% ELSE %][% IF ( I ) %]Organization[% END %][% IF ( A ) %]Adult[% END %][% IF ( C ) %]Child[% END %][% IF ( P ) %]Professional[% END %][% IF ( S ) %]Staff[% END %][% END %])</title>
 [% INCLUDE 'doc-head-close.inc' %]
 [% INCLUDE 'calendar.inc' %]
 <script type="text/javascript">
 //<![CDATA[
-    $(document).ready(function() {
-               $("fieldset.rows input").keydown(function(e){ return checkEnter(e); });
-        $("#guarantordelete").click(function() {
-            $("#contact-details").hide().find('a').remove();
-            $("#guarantorid, #contactname, #contactfirstname").each(function () { this.value = "" });
-            $("#contactname, #contactfirstname")
-                .each(function () { this.type = 'text' })
-                .parent().find('span').remove();
-            $("#guarantorsearch").val("Set to Patron");
-        });
-        $("#select_city").change(function(){
-            var myRegEx=new RegExp(/(.*)\|(.*)\|(.*)\|(.*)/);
-            document.form.select_city.value.match(myRegEx);
-            document.form.zipcode.value=RegExp.$1;
-            document.form.city.value=RegExp.$2;
-            document.form.state.value=RegExp.$3;
-            document.form.country.value=RegExp.$4;
-        });
-
-        [% IF categorycode %]
-            update_category_code( "[% categorycode %]" );
-        [% ELSE %]
-            if ( $("#categorycode").length > 0 ){
-                var category_code = $("#categorycode").find("option:selected").val();
-                update_category_code( category_code );
-            }
-        [% END %]
-        $("#dateofbirth").datepicker({ maxDate: "-1D" });
-        $("#entryform").preventDoubleFormSubmit();
-    });
+$(document).ready(function() {
 
-    function clear_entry(node) {
-        var original = $(node).parent();
-        $("textarea", original).attr('value', '');
-        $("select", original).attr('value', '');
+       [% IF categorycode %]
+               update_category_code( "[% categorycode %]" );
+       [% ELSE %]
+               if ( $("#categorycode_entry").length > 0 ){
+                       var category_code = $("#categorycode_entry").find("option:selected").val();
+                       update_category_code( category_code );
+               }
+       [% END %]
+       $("#dateofbirth").datepicker({ maxDate: "-1D", yearRange: "c-120:" });
+       dateformat = $("#dateofbirth").siblings(".hint").first().html();
+    if( $('#dateofbirth').length ) {
+        write_age();
     }
+       $("#entryform").validate({
+               rules: {
+                       email: {
+                               email: true
+                       },
+                       emailpro: {
+                               email: true
+                       },
+                       B_email: {
+                               email: true
+                       }
+               },
+               submitHandler: function(form) {
+                       $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
+                       if (form.beenSubmitted)
+                               return false;
+                       else
+                               form.beenSubmitted = true;
+                               form.submit();
+                       }
+       });
 
-    function clone_entry(node) {
-        var original = $(node).parent();
-        var clone = original.clone();
+       var mrform = $("#manual_restriction_form");
+       var mrlink = $("#add_manual_restriction");
+       mrform.hide();
+       mrlink.on("click",function(e){
+               $(this).hide();
+               mrform.show();
+               e.preventDefault();
+       });
+       $("#cancel_manual_restriction").on("click",function(e){
+               $('#debarred_expiration').val('');
+               $('#add_debarment').val(0);
+               $('#debarred_comment').val('');
+               mrlink.show();
+               mrform.hide();
+               e.preventDefault();
+       });
+});
 
-        var newId = 50 + parseInt(Math.random() * 100000);
-        $("input,select,textarea", clone).attr('id', function() {
-            return this.id.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
-        });
-        $("input,select,textarea", clone).attr('name', function() {
-            return this.name.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
-        });
-        $("label", clone).attr('for', function() {
-            return $(this).attr("for").replace(/patron_attr_\d+/, 'patron_attr_' + newId);
-        });
-        $("input#patron_attr_" + newId, clone).attr('value','');
-        $("select#patron_attr_" + newId, clone).attr('value','');
-        $(original).after(clone);
-        return false;
-    }
+function clear_entry(node) {
+       var original = $(node).parent();
+       $("textarea", original).attr('value', '');
+       $("select", original).attr('value', '');
+}
+
+function clone_entry(node) {
+       var original = $(node).parent();
+       var clone = original.clone();
+
+       var newId = 50 + parseInt(Math.random() * 100000);
+       $("input,select,textarea", clone).attr('id', function() {
+               return this.id.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
+       });
+       $("input,select,textarea", clone).attr('name', function() {
+               return this.name.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
+       });
+       $("label", clone).attr('for', function() {
+               return $(this).attr("for").replace(/patron_attr_\d+/, 'patron_attr_' + newId);
+       });
+       $("input#patron_attr_" + newId, clone).attr('value','');
+       $("select#patron_attr_" + newId, clone).attr('value','');
+       $(original).after(clone);
+       return false;
+}
+
+function update_category_code(category_code) {
+       if ( $(category_code).is("select") ) {
+               category_code = $("#categorycode_entry").find("option:selected").val();
+       }
+       var mytables = $(".attributes_table");
+       $(mytables).find("li").hide();
+       $(mytables).find(" li[data-category_code='"+category_code+"']").show();
+       $(mytables).find(" li[data-category_code='']").show();
+}
+
+function select_user(borrowernumber, borrower) {
+       var form = $('#entryform').get(0);
+       if (form.guarantorid.value) {
+               $("#contact-details").find('a').remove();
+               $("#contactname, #contactfirstname").parent().find('span').remove();
+       }
+
+       var id = borrower.borrowernumber;
+       form.guarantorid.value = id;
+       $('#contact-details')
+               .show()
+               .find('span')
+               .after('<a target="blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' + id + '">' + id + '</a>');
+
+       $(form.contactname)
+               .val(borrower.surname)
+               .before('<span>' + borrower.surname + '</span>').get(0).type = 'hidden';
+       $(form.contactfirstname)
+               .val(borrower.firstname)
+               .before('<span>' + borrower.firstname + '</span>').get(0).type = 'hidden';
+
+       form.streetnumber.value = borrower.streetnumber;
+       form.address.value = borrower.address;
+       form.address2.value = borrower.address2;
+       form.city.value = borrower.city;
+       form.state.value = borrower.state;
+       form.zipcode.value = borrower.zipcode;
+       form.country.value = borrower.country;
+       form.branchcode.value = borrower.branchcode;
 
-    function update_category_code(category_code) {
-        if ( $(category_code).is("select") ) {
-            category_code = $("#categorycode").find("option:selected").val();
+       form.guarantorsearch.value = _("Change");
+
+       return 0;
+}
+
+    function write_age() {
+        var hint = $("#dateofbirth").siblings(".hint").first();
+        hint.html(dateformat);
+
+        var age = CalculateAge(document.form.dateofbirth.value);
+
+        if (!age.year && !age.month) {
+            return;
+        }
+
+        var age_string;
+        if (age.year || age.month) {
+            age_string = _("Age: ");
+        }
+
+        if (age.year) {
+            age_string += age.year > 1 ? _("%s years ").format(age.year) : _("%s year ").format(age.year);
+        }
+
+        if (age.month) {
+            age_string += age.month > 1 ? _("%s months ").format(age.month) : _("%s month ").format(age.month);
         }
-        var mytables = $(".attributes_table");
-        $(mytables).find("li").hide();
-        $(mytables).find(" li[data-category_code="+category_code+"]").show();
-        $(mytables).find(" li[data-category_code='']").show();
+
+        hint.html(age_string);
     }
 
-               var MSG_SEPARATOR = _("Separator must be / in field ");
-        var MSG_INCORRECT_DAY = _("Invalid day entered in field ");
-        var MSG_INCORRECT_MONTH = _("Invalid month entered in field ");
-        var MSG_INCORRECT_YEAR = _("Invalid year entered in field ");
+        var MSG_SEPARATOR = _("Separator must be / in field %s");
+        var MSG_INCORRECT_DAY = _("Invalid day entered in field %s");
+        var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s");
+        var MSG_INCORRECT_YEAR = _("Invalid year entered in field %s");
         var MSG_DUPLICATE_PATRON = _("Warning: Duplicate patron");
         var MSG_DUPLICATE_ORGANIZATION = _("Warning: Duplicate organization");
         var MSG_LATE_EXPIRY = _("Warning: Expiration date falls before enrollment date");
-        var MSG_MISSING_MANDATORY = _("The following fields are mandatory:");
         var MSG_DUPLICATE_SUSPICION = _("Please confirm whether this is a duplicate patron");
         var MSG_PASSWORD_MISMATCH = _("The passwords entered do not match");
+        var MSG_PASSWORD_CONTAINS_TRAILING_SPACES = _("Password contains leading and/or trailing spaces.");
+        var LABEL_CHANGE = _("Change");
+        var LABEL_SET_TO_PATRON = _("Set to patron");
 //]]>
 </script>
 <script type="text/javascript" src="[% themelang %]/js/members.js"></script>
 [% INCLUDE 'patron-search.inc' %]
 
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; 
-[% IF ( opadd ) %]
-               Add[% IF ( categoryname ) %] [% categoryname %] patron[% ELSE %][% IF ( I ) %] Organization patron[% END %][% IF ( A ) %] Adult patron[% END %][% IF ( C ) %] Child patron[% END %][% IF ( P ) %] Professional patron[% END %][% IF ( S ) %] Staff patron[% END %][% END %]
-[% surname %] [% firstname %]
-[% ELSE %] 
-<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% firstname %] [% surname %]</a> &rsaquo; <strong>[% IF ( opduplicate ) %]Duplicate[% ELSE %]Modify[% END %][% IF ( categoryname ) %] [% categoryname %] patron[% ELSE %][% IF ( I ) %] Organization patron[% END %][% IF ( A ) %] Adult patron[% END %][% IF ( C ) %] Child patron[% END %][% IF ( P ) %] Professional patron[% END %][% IF ( S ) %] Staff patron[% END %][% END %]
-</strong>[% END %]</div>
+[% IF (firstname || surname ) %] <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% IF (firstname) %][% firstname %] [% END %][% IF (surname) %][% surname %] [% END %]</a>  &rsaquo;[% END %]
+<strong>[% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] patron ([%IF ( categoryname ) %][% categoryname %][% ELSE %][% IF ( I ) %]Organization[% END %][% IF ( A ) %]Adult[% END %][% IF ( C ) %]Child[% END %][% IF ( P ) %]Professional[% END %][% IF ( S ) %]Staff[% END %][% END %])</strong>
+</div>
 [% IF ( opadd ) %]<div id="doc" class="yui-t7">[% ELSE %]<div id="doc3" class="yui-t2">[% END %]
    
    <div id="bd">
        <div id="yui-main">
        <div class="yui-b">
-
     [% IF error_alert %]
         [% IF ( error_alert == "no_email" ) %]
             <div class="error">This member has no email</div>
     [% END %]
 
        [% IF ( no_add ) %]<div class="dialog alert"><h3>Cannot add patron</h3>
-               [% IF ( no_branches ) %]<p>There are <strong>no libraries defined</strong>. [% IF ( CAN_user_parameters ) %]Please <a href="/cgi-bin/koha/admin/branches.pl">add a library</a>.[% ELSE %]An administrator must define at least one library.[% END %]</p>[% END %]
-               [% IF ( no_categories ) %]<p>There are <strong>no patron categories defined</strong>. [% IF ( CAN_user_parameters ) %]Please <a href="/cgi-bin/koha/admin/categorie.pl">add a patron category</a>.[% ELSE %]An administrator must define at least one patron category.</p>[% END %][% END %]</div>[% END %]
+            [% IF ( no_branches ) %]<p><strong>There are no libraries defined.</strong> [% IF ( CAN_user_parameters ) %]<a href="/cgi-bin/koha/admin/branches.pl">Please add a library.</a>[% ELSE %]An administrator must define at least one library.[% END %]</p>[% END %]
+            [% IF ( no_categories ) %]<p><strong>There are no patron categories defined.</strong> [% IF ( CAN_user_parameters ) %]<a href="/cgi-bin/koha/admin/categories.pl">Please add a patron category.</a>[% ELSE %]An administrator must define at least one patron category.</p>[% END %][% END %]</div>[% END %]
 
        [% UNLESS ( no_add ) %]
-       [% IF ( opadd ) %]
-       <h1>
-               Add[% IF ( categoryname ) %] [% categoryname %] patron[% ELSE %][% IF ( I ) %] Organization patron[% END %][% IF ( A ) %] Adult patron[% END %][% IF ( C ) %] Child patron[% END %][% IF ( P ) %] Professional patron[% END %][% IF ( S ) %] Staff patron[% END %][% END %] [% firstname %] [% surname %] 
-       </h1>
-       [% ELSE %]
-       <h1>
-               [% IF ( opduplicate ) %]Duplicate[% ELSE %]Modify[% END %][% IF ( categoryname ) %] [% categoryname %] patron[% ELSE %][% IF ( I ) %] Organization patron[% END %][% IF ( A ) %] Adult patron[% END %][% IF ( C ) %] Child patron[% END %][% IF ( P ) %] Professional patron[% END %][% IF ( S ) %] Staff patron[% END %][% END %]
-[% firstname %] [% surname %] 
-       </h1>
-       [% END %]
+    <h1>[% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] patron [% IF (firstname) %][% firstname %] [% END %][% IF (surname) %][% surname %] [% END %]([%IF ( categoryname ) %][% categoryname %][% ELSE %][% IF ( I ) %]Organization[% END %][% IF ( A ) %]Adult[% END %][% IF ( C ) %]Child[% END %][% IF ( P ) %]Professional[% END %][% IF ( S ) %]Staff[% END %][% END %])</h1>
   
        [% IF ( check_member ) %]
                        <div class="dialog alert">
                                <h3>Duplicate patron record?</h3>
-                               <p><a class="popup" href="javascript:Dopop('moremember.pl?print=brief&amp;borrowernumber=[% check_member %]');" >View existing record</a></p>
-                               <form action="/cgi-bin/koha/members/memberentry.pl" method="get"><input type="hidden" name="op" value="modify" /><input type="hidden" name="borrowernumber" value="[% check_member %]" /><input type="hidden" name="category_type" value="[% check_categorytype %]" /><input class="edit" type="submit" value="It is a duplicate. Edit existing record" /></form>
+                <p><a class="popup" href="#" onclick="Dopop('moremember.pl?print=brief&amp;borrowernumber=[% check_member %]');return false;" >View existing record</a></p>
+                <form action="/cgi-bin/koha/members/memberentry.pl" method="get">
+                    <input type="hidden" name="op" value="modify" />
+                    <input type="hidden" name="borrowernumber" value="[% check_member %]" />
+                    <button type="submit" class="new"><i class="fa fa-pencil"></i> It is a duplicate.
+                    Edit existing record</button>
+                </form>
 
-                <form name="form_double" action="/cgi-bin/koha/members/memberentry.pl" method="post" autocomplete="off">
+                <form name="form" action="/cgi-bin/koha/members/memberentry.pl" method="post" autocomplete="off">
                                <input type="hidden" name="nodouble" value="1" />
-                               <input class="new" type="submit" value="Not a duplicate. Save as new record" />
+                <button type="submit" class="new"><i class="fa fa-plus"></i> Not a duplicate.
+                Save as new record</button>
                        </div>
        [% END %]
 
                        [% IF ( ERROR_login_exist ) %]
                                <li id="ERROR_login_exist">Username/password already exists.</li>
                        [% END %]
-                       [% IF ( ERROR_cardnumber ) %]
-                               <li id="ERROR_cardnumber">Cardnumber already in use.</li>
-                       [% END %]
+            [% IF ERROR_cardnumber_already_exists %]
+                <li id="ERROR_cardnumber">Cardnumber already in use.</li>
+            [% END %]
+            [% IF ERROR_cardnumber_length %]
+                <li id="ERROR_cardnumber">Cardnumber length is incorrect.</li>
+            [% END %]
                        [% IF ( ERROR_age_limitations ) %]
                                <li id="ERROR_age_limitations">Patron's age is incorrect for their category.  
                     Ages allowed are [% age_low %]-[% age_high %].</li>
                                <li id="ERROR_password_mismatch">Passwords do not match.</li>
                        [% END %]
             [% IF ( ERROR_extended_unique_id_failed ) %]
-                <li id="ERROR_extended_unique_id_failed">The attribute value 
-                    [% ERROR_extended_unique_id_failed %] is already is use by another patron record.</li>
+                <li id="ERROR_extended_unique_id_failed"><strong>[% ERROR_extended_unique_id_failed_description %]</strong> attribute value <i>[% ERROR_extended_unique_id_failed_value %]</i> is already in use by another patron record.</li>
                        [% END %]
+            [% IF ERROR_bad_email %]
+                <li id="ERROR_bad_email">The primary email is invalid.</li>
+            [% END %]
+            [% IF ERROR_bad_email_secondary %]
+                <li id="ERROR_bad_email_secondary">The secondary email is invalid.</li>
+            [% END %]
+            [% IF ERROR_bad_email_alternative %]
+                <li id="ERROR_bad_email_alternative">The alternative email is invalid.</li>
+            [% END %]
                        </ul>
                </div>
        [% END %]
 <input type="hidden" name="BorrowerMandatoryField" value="[% BorrowerMandatoryField %]" />
 <input type="hidden" name="category_type" value="[% category_type %]" />
 <input type="hidden" name="updtype" value="[% updtype %]" />
-<input type="hidden" name="select_roadtype" value="[% select_roadtype %]" />
 <input type="hidden" name="destination" value="[% destination %]" />
 <input type="hidden" name="check_member" value="[% check_member %]" />
-<input type="hidden" name="borrowernumber" value="[% IF ( opduplicate ) %][% ELSE %][% borrowernumber %][% END %]" />
-<input type="hidden" name="nodouble"  value="[% IF ( opduplicate ) %][% ELSE %][% nodouble %][% END %]" />
+<input type="hidden" name="borrowernumber" value="[% UNLESS opduplicate %][% borrowernumber %][% END %]" />
+<input type="hidden" name="nodouble"  value="[% UNLESS opduplicate %][% nodouble %][% END %]" />
 [% IF ( step ) %]<input type="hidden" name="step"  value="[% step %]" />[% END %]
 [% IF ( opadd ) %]<input type="hidden" name="op" value="insert" />
 [% ELSIF ( opduplicate ) %]
                [% END %]
                Surname: </label>
                [% IF ( uppercasesurnames ) %]
-                       [% IF ( opduplicate ) %]
-                               <input style="text-transform:uppercase;" type="text" id="surname" name="surname" size="20"  value="[% surname %]" onclick="this.value=''" />
-                       [% ELSE %]
-                               <input style="text-transform:uppercase;" type="text" id="surname" name="surname" size="20"  value="[% surname %]" />
-                       [% END %]
+            <input style="text-transform:uppercase;" type="text" id="surname" name="surname" size="20"  value="[% surname %]" />
                [% ELSE %]
-                       [% IF ( opduplicate ) %]
-                               <input type="text" id="surname" name="surname" size="20"  value="[% surname %]" onclick="this.value=''" />
-                       [% ELSE %]
-                               <input type="text" id="surname" name="surname" size="20"  value="[% surname %]" />
-                       [% END %]
+            <input type="text" id="surname" name="surname" size="20"  value="[% surname %]" />
                [% END %]
                [% IF ( mandatorysurname ) %]<span class="required">Required</span>[% END %]
                </li>
                 <label for="firstname">
                 [% END %]
                 First name: </label>
-                <input type="text" id="firstname" name="firstname" size="20"  value="[% IF ( opduplicate ) %][% ELSE %][% firstname %][% END %]" />
+                <input type="text" id="firstname" name="firstname" size="20"  value="[% UNLESS opduplicate %][% firstname %][% END %]" />
                 [% IF ( mandatoryfirstname ) %]<span class="required">Required</span>[% END %]
             </li>
         [% END %]
                 <label for="dateofbirth">
                 [% END %]
                 Date of birth: </label>
-                               
-       [% IF ( metric ) %]                     
-                <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="CheckDate(document.form.dateofbirth);" value="[% IF ( opduplicate ) %][% ELSE %][% dateofbirth %][% END %]" />
-[% ELSE %]
-                <input type="text" id="dateofbirth" name="dateofbirth" size="20" value="[% IF ( opduplicate ) %][% ELSE %][% dateofbirth %][% END %]" />
-[% END %]
+
+                <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="write_age();" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" />
 
         [% IF ( mandatorydateofbirth ) %]<span class="required">Required</span>[% END %]
         [% IF ( ERROR_dateofbirth ) %]<span class="required">(Error)</span>[% END %]
                     <label for="initials">
                 [% END %]
                 Initials: </label>
-                [% IF ( opduplicate ) %]
-                                       <input type="text" id="initials" name="initials" size="20"  value="[% initials %]" onclick="this.value=''" />
-                [% ELSE %]
-                                       <input type="text" id="initials" name="initials" size="20"  value="[% initials %]" />
-                [% END %]
+                <input type="text" id="initials" name="initials" size="20"  value="[% UNLESS opduplicate %][% initials %][% END %]" />
                 [% IF ( mandatoryinitials ) %]<span class="required">Required</span>[% END %]
             </li>
         [% END %]
                        [% ELSE %]
                        <label for="othernames">
                        [% END %]
-                       Other name: </label>
-                       [% IF ( opduplicate ) %]
-                               <input type="text" id="othernames" name="othernames" size="20"  value="[% othernames %]" onclick="this.value=''" />
-                       [% ELSE %]
-                               <input type="text" id="othernames" name="othernames" size="20"  value="[% othernames %]" />
-                       [% END %]
+            Other name: </label>
+            <input type="text" id="othernames" name="othernames" size="20"  value="[% UNLESS opduplicate %][% othernames %][% END %]" />
 [% IF ( mandatoryothernames ) %]<span class="required">Required</span>[% END %]
                [% IF ( I ) %]<input type="hidden" name="sex" value="N" />[% END %]
                </li>
     [% UNLESS ( I ) %]
         [% UNLESS nosex %]
                <li class="radio">
-               
-               [% IF ( female ) %]
-                               <label for="sex-female">Female </label><input type="radio" name="sex" id="sex-female" value="F" checked="checked"  />
-[% ELSE %]
-                               <label for="sex-female">Female </label><input type="radio" name="sex" id="sex-female" value="F" />
-[% END %]
-               [% IF ( male ) %]
-               <label for="sex-male">Male </label><input type="radio" name="sex" id="sex-male" value="M" checked="checked" />
-[% ELSE %]
-                               <label for="sex-male">Male </label><input type="radio" name="sex" id="sex-male" value="M" />
-[% END %]
-[% IF ( none ) %]
-                               <label for="sex-none">N/A </label><input type="radio" name="sex" id="sex-none" value=""  checked="checked"  />
-[% ELSE %]
-                               <label for="sex-none">N/A </label><input type="radio" name="sex" id="sex-none" value="" />
-[% END %]
+
+            [% UNLESS ( opduplicate ) %]
+                [% IF ( female ) %]
+                    <label for="sex-female">Female </label><input type="radio" name="sex" id="sex-female" value="F" checked="checked"  />
+                [% ELSE %]
+                    <label for="sex-female">Female </label><input type="radio" name="sex" id="sex-female" value="F" />
+                [% END %]
+                [% IF ( male ) %]
+                    <label for="sex-male">Male </label><input type="radio" name="sex" id="sex-male" value="M" checked="checked" />
+                [% ELSE %]
+                    <label for="sex-male">Male </label><input type="radio" name="sex" id="sex-male" value="M" />
+                [% END %]
+                [% IF ( none ) %]
+                    <label for="sex-none">None specified </label><input type="radio" name="sex" id="sex-none" value=""  checked="checked"  />
+                [% ELSE %]
+                    <label for="sex-none">None specified </label><input type="radio" name="sex" id="sex-none" value="" />
+                [% END %]
+            [% ELSE %]
+                <label for="sex-female">Female </label><input type="radio" name="sex" id="sex-female" value="F" />
+                <label for="sex-male">Male </label><input type="radio" name="sex" id="sex-male" value="M" />
+                <label for="sex-none">None specified </label><input type="radio" name="sex" id="sex-none" value="" checked="checked" />
+            [% END %]
+
                </li>
         [% END %]
     [% END %]
                    <span>[% contactname %]</span>
                    <input name="contactname" id="contactname" type="hidden" size="20" value="[% contactname %]" />
                    [% ELSE %]
-                           [% IF ( opduplicate ) %]
-                                               <input name="contactname" id="contactname" type="text" size="20" value="[% contactname %]" onclick="this.value=''" />
-                           [% ELSE %]
-                                               <input name="contactname" id="contactname" type="text" size="20" value="[% contactname %]" />
-                           [% END %]
+                    <input name="contactname" id="contactname" type="text" size="20" value="[% contactname %]" />
                    [% END %]
                </li>
 [% ELSE %]
      <span>[% contactname %]</span>
      <input name="contactname" id="contactname" type="hidden" size="20" value="[% contactname %]" />
      [% ELSE %]
-               [% IF ( opduplicate ) %]
-                       <input name="contactname" id="contactname" type="text" size="20" value="[% contactname %]" onclick="this.value=''" />
-               [% ELSE %]
-                       <input name="contactname" id="contactname" type="text" size="20" value="[% contactname %]" />
-               [% END %]
+        <input name="contactname" id="contactname" type="text" size="20" value="[% contactname %]" />
      [% END %]
  </li>
         [% END %]
      <span>[% contactfirstname %]</span>
      <input name="contactfirstname" id="contactfirstname" type="hidden" size="20" value="[% contactfirstname %]" />
      [% ELSE %]
-            [% IF ( opduplicate ) %]
-                               <input name="contactfirstname" id="contactfirstname" type="text" size="20" value="[% contactfirstname %]" onclick="this.value=''" />
-            [% ELSE %]
-                               <input name="contactfirstname" id="contactfirstname" type="text" size="20" value="[% contactfirstname %]" />
-            [% END %]
+        <input name="contactfirstname" id="contactfirstname" type="text" size="20" value="[% contactfirstname %]" />
      [% END %]
  </li>
         [% END %]
         <li>
             <span class="label">&nbsp;</span>
             [% IF ( guarantorid ) %]
-            <input id="guarantorsearch" type="button" value="Change" onclick="Dopopguarantor('guarantor_search.pl?category_type=[% category_type %]');" />
+            <input id="guarantorsearch" type="button" value="Change" onclick="Dopopguarantor('guarantor_search.pl');" />
             [% ELSE %]
-            <input id="guarantorsearch" type="button" value="Set to patron" onclick="Dopopguarantor('guarantor_search.pl?category_type=[% category_type %]');" />
+            <input id="guarantorsearch" type="button" value="Set to patron" onclick="Dopopguarantor('guarantor_search.pl');" />
             [% END %]
             <input id="guarantordelete" type="button" value="Delete" />
         </li>
+    [% IF guarantorid && Koha.Preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') %]
+        <li>
+            <label for="privacy_guarantor_checkouts">Show checkouts to guarantor</label>
+            <select name="privacy_guarantor_checkouts" id="privacy_guarantor_checkouts">
+                [% IF privacy_guarantor_checkouts %]
+                    <option value="0">No</option>
+                    <option value="1" selected>Yes</option>
+                [% ELSE %]
+                    <option value="0" selected>No</option>
+                    <option value="1">Yes</option>
+                [% END %]
+            </select>
+            <div class="hint">Allow guarantor of this patron to view this patron's checkouts from the OPAC</div>
+        </li>
+    [% END %]
         </ol>
     </fieldset>
 
 [% END %]
 [% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
-<fieldset class="rows">
-    <legend id="main_address_lgd">Main address</legend><ol>
-        [% UNLESS nostreetnumber %]
-    <li>
-      [% IF ( mandatorystreetnumber ) %]
-      <label for="streetnumber" class="required">
-      [% ELSE %]
-      <label for="streetnumber">
-      [% END %]
-      Street number: </label>
-      [% IF ( opduplicate ) %]
-               <input type="text" id="streetnumber" name="streetnumber" size="5" value="[% streetnumber %]" onclick="this.value=''" />
-      [% ELSE %]
-               <input type="text" id="streetnumber" name="streetnumber" size="5" value="[% streetnumber %]" />
-      [% END %]
-[% IF ( mandatorystreetnumber ) %]<span class="required">Required</span>[% END %]
-    </li>
-        [% END %]
-        [% UNLESS nostreettype %]
-    [% IF ( road_cgipopup ) %]
-      <li>
-      [% IF ( mandatorystreettype ) %]
-      <label for="streettype" class="required">
-      [% ELSE %]
-      <label for="streettype">
-      [% END %]
-      Street type: </label>
-      [% roadpopup %]
-         [% IF ( mandatorystreettype ) %]<span class="required">Required</span>[% END %]
-      </li>
-    [% END %] 
-        [% END %]
-        [% UNLESS noaddress %]
-    <li>
-      [% IF ( mandatoryaddress ) %]
-      <label for="address" class="required">
-      [% ELSE %]
-      <label for="address">
-      [% END %]
-      Address: </label>
-      [% IF ( opduplicate ) %]
-                       <input type="text" id="address" name="address" size="35" value="[% address %]" onclick="this.value=''" />
-      [% ELSE %]
-                       <input type="text" id="address" name="address" size="35" value="[% address %]" />
-      [% END %]
-         [% IF ( mandatoryaddress ) %]<span class="required">Required</span>[% END %]
-    </li>
-        [% END %]
-        [% UNLESS noaddress2 %]
-    <li>
-      [% IF ( mandatoryaddress2 ) %]
-      <label for="address2" class="required">
-      [% ELSE %]
-      <label for="address2">
-      [% END %]
-      Address 2: </label>
-      [% IF ( opduplicate ) %]
-                       <input type="text" id="address2" name="address2" size="35" value="[% address2 %]" onclick="this.value=''" />
-      [% ELSE %]
-                       <input type="text" id="address2" name="address2" size="35" value="[% address2 %]" />
-      [% END %]
-         [% IF ( mandatoryaddress2 ) %]<span class="required">Required</span>[% END %]
-    </li>  
-        [% END %]
-        [% UNLESS nocity %]
-    <li>
-      [% IF ( mandatorycity ) %]
-        <label for="city" class="required">
-      [% ELSE %]
-        <label for="city">
-      [% END %]
-      City: </label>
-        [% IF ( opduplicate ) %]
-                       <input type="text" id="city" name="city" size="20" value="[% city %]" onclick="this.value=''" />
-        [% ELSE %]
-                       <input type="text" id="city" name="city" size="20" value="[% city %]" />
-        [% END %]
-        [% IF ( city_cgipopup ) %]or <strong>choose</strong>
-        <select id="select_city" name="select_city">
-        [% FOREACH city_loo IN city_loop %]
-            [% IF ( city_loo.selected ) %]
-            <option value="[% city_loo.city_zipcode %]|[% city_loo.city_name %]|[% city_loo.city_state %]|[% city_loo.city_country %]" selected="selected">
-            [% ELSE %]
-            <option value="[% city_loo.city_zipcode %]|[% city_loo.city_name %]|[% city_loo.city_state %]|[% city_loo.city_country %]">
-            [% END %]
-                [% city_loo.city_name %] [% city_loo.city_state %] [% city_loo.city_zipcode %]
-            </option>
-        [% END %]
-        </select>
-        [% END %]
-         [% IF ( mandatorycity ) %]<span class="required">Required</span>[% END %]
-    </li>
-        [% END %]
-        [% UNLESS nostate %]
-    <li> 
-      [% IF ( mandatorystate ) %]
-        <label for="state" class="required">
-      [% ELSE %]
-        <label for="state">
-      [% END %]
-      State: </label>
-      <input type="text" name="state" id="state" size="20" value="[% state %]" />
-         [% IF ( mandatorystate ) %]<span class="required">Required</span>[% END %]
-    </li>
-        [% END %]
-        [% UNLESS nozipcode %]
-    <li> 
-      [% IF ( mandatoryzipcode ) %]
-        <label for="zipcode" class="required">
-      [% ELSE %]
-        <label for="zipcode">
-      [% END %]
-      Zip/Postal code: </label>
-      [% IF ( opduplicate ) %]
-                       <input type="text" name="zipcode" id="zipcode" size="10" value="[% zipcode %]" onclick="this.value=''" />
-      [% ELSE %]
-                       <input type="text" name="zipcode" id="zipcode" size="10" value="[% zipcode %]" />
-      [% END %]
-         [% IF ( mandatoryzipcode ) %]<span class="required">Required</span>[% END %]
-    </li>
-        [% END %]
-        [% UNLESS nocountry %]
-    <li> 
-      [% IF ( mandatorycountry ) %]
-        <label for="country" class="required">
-      [% ELSE %]
-        <label for="country">
-      [% END %]
-      Country: </label>
-      [% IF ( opduplicate ) %]
-                       <input type="text" name="country" id="country" size="20" value="[% country %]" onclick="this.value=''" />
-      [% ELSE %]
-                       <input type="text" name="country" id="country" size="20" value="[% country %]" />
-      [% END %]
-         [% IF ( mandatorycountry ) %]<span class="required">Required</span>[% END %]
-    </li>    
-        [% END %]
-       </ol>
-    </fieldset>
+    [% IF Koha.Preference( 'AddressFormat' ) %]
+        [% INCLUDE "member-main-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
+    [% ELSE %]
+        [% INCLUDE 'member-main-address-style-us.inc' %]
+    [% END %]
 [% END # nostreet && nocity etc group%]
 
 [% UNLESS nophone && nophonepro && nomobile && noemail && noemailpro && nofax %]
       <label for="phone">
       [% END %]
       Primary phone: </label>
-      [% IF ( opduplicate ) %]
-                       <input type="text" id="phone" name="phone" value="[% phone %]" onclick="this.value=''" />
-      [% ELSE %]
-                       <input type="text" id="phone" name="phone" value="[% phone %]" />
-      [% END %]
+        <input type="text" id="phone" name="phone" value="[% phone %]" />
          [% IF ( mandatoryphone ) %]<span class="required">Required</span>[% END %]<div class="hint">Shows on transit slips</div>
 
     </li>
       <label for="phonepro">
       [% END %]
       Secondary phone: </label>
-      [% IF ( opduplicate ) %]
-                       <input type="text" id="phonepro" name="phonepro" value="[% phonepro %]" onclick="this.value=''" />
-      [% ELSE %]
-                       <input type="text" id="phonepro" name="phonepro" value="[% phonepro %]" />
-      [% END %]
+    <input type="text" id="phonepro" name="phonepro" value="[% phonepro %]" />
          [% IF ( mandatoryphonepro ) %]<span class="required">Required</span>[% END %]
     </li>
         [% END %]
       <label for="mobile">
       [% END %]
       Other phone: </label>
-      [% IF ( opduplicate ) %]
-               <input type="text" id="mobile" name="mobile" value="[% mobile %]" onclick="this.value=''" />
-      [% ELSE %]
-               <input type="text" id="mobile" name="mobile" value="[% mobile %]" />
-      [% END %]
+        <input type="text" id="mobile" name="mobile" value="[% mobile %]" />
          [% IF ( mandatorymobile ) %]<span class="required">Required</span>[% END %]
     </li>
         [% END %]
       <label for="email">
       [% END %]
       Primary email: </label>
-      [% IF ( opduplicate ) %]
-               <input type="text" id="email" name="email" size="45" value="[% email %]" onclick="this.value=''" />
-      [% ELSE %]
-               <input type="text" id="email" name="email" size="45" value="[% email %]" />
-      [% END %]
+        <input type="text" id="email" name="email" size="45" value="[% email %]" />
          [% IF ( mandatoryemail ) %]<span class="required">Required</span>[% END %]<div class="hint">Shows on transit slips</div>
 
     </li>
       <label for="emailpro">
       [% END %]
       Secondary email: </label>
-      [% IF ( opduplicate ) %]
-               <input type="text" id="emailpro" name="emailpro" size="45" value="[% emailpro %]" onclick="this.value=''" />
-      [% ELSE %]
-               <input type="text" id="emailpro" name="emailpro" size="45" value="[% emailpro %]" />
-      [% END %]
+        <input type="text" id="emailpro" name="emailpro" size="45" value="[% emailpro %]" />
          [% IF ( mandatoryemailpro ) %]<span class="required">Required</span>[% END %]
     </li>
         [% END %]
       <label for="fax">
       [% END %]
       Fax: </label>
-      [% IF ( opduplicate ) %]
-               <input type="text" id="fax" name="fax" value="[% fax %]" onclick="this.value=''" />
-      [% ELSE %]
-               <input type="text" id="fax" name="fax" value="[% fax %]" />
-      [% END %]
+        <input type="text" id="fax" name="fax" value="[% fax %]" />
          [% IF ( mandatoryfax ) %]<span class="required">Required</span>[% END %]
     </li>
         [% END %]
 [% IF ( step_6 ) %]
 
     [% UNLESS noB_address && noB_address2 && noB_city && noB_zipcode && noB_state && noB_country &&nocontactnote && noB_phone && noB_email %]
-               <fieldset class="rows" id="memberentry_address">
-               <legend id="alt_address_lgd">Alternate address</legend><ol>
-        [% UNLESS noB_address %]
-                       <li>
-                               [% IF ( mandatoryB_address ) %]
-                                       <label for="B_address" class="required">
-                               [% ELSE %]
-                                       <label for="B_address">
-                               [% END %]
-                               Address: </label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" id="B_address" name="B_address" size="40" value="[% B_address %]" onclick="this.value=''" />
-                               [% ELSE %]
-                                       <input type="text" id="B_address" name="B_address" size="40" value="[% B_address %]" />
-                               [% END %]
-         [% IF ( mandatoryB_address ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noB_address2 %]
-                       <li>
-                               [% IF ( mandatoryB_address2 ) %]
-                                       <label for="B_address2" class="required">
-                               [% ELSE %]
-                                       <label for="B_address2">
-                               [% END %]
-                               Address 2: </label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" id="B_address2" name="B_address2" size="40" value="[% B_address2 %]" onclick="this.value=''" />
-                               [% ELSE %]
-                                       <input type="text" id="B_address2" name="B_address2" size="40" value="[% B_address2 %]" />
-                               [% END %]
-         [% IF ( mandatoryB_address2 ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noB_city %]
-                       <li>
-                               [% IF ( mandatoryB_city ) %]
-                                       <label for="B_city" class="required" >
-                               [% ELSE %]
-                                       <label for="B_city">
-                               [% END %]
-                               City: </label>
-                               <input type="text" id="B_city" name="B_city" size="20" value="[% B_city %]" />
-         [% IF ( mandatoryB_city ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noB_state %]
-                       <li>
-                               [% IF ( mandatoryB_state ) %]
-                                       <label for="B_state" class="required" >
-                               [% ELSE %]
-                                       <label for="B_state">
-                               [% END %]
-                               State: </label>
-                               <input type="text" id="B_state" name="B_state" size="20" value="[% B_state %]" />
-         [% IF ( mandatoryB_state ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noB_zipcode %]
-                       <li>
-                               [% IF ( mandatoryB_zipcode ) %]
-                                       <label for="B_zipcode" class="required">
-                               [% ELSE %]
-                                       <label for="B_zipcode">
-                               [% END %]
-                               Zip/Postal code: </label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" id="B_zipcode" name="B_zipcode" maxlength="10" size="10" value="[% B_zipcode %]" onclick="this.value=''" />
-                               [% ELSE %]
-                                       <input type="text" id="B_zipcode" name="B_zipcode" maxlength="10" size="10" value="[% B_zipcode %]" />
-                               [% END %]
-         [% IF ( mandatoryB_zipcode ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noB_country %]
-                       <li>
-                               [% IF ( mandatoryB_country ) %]
-                                       <label for="B_country" class="required">
-                               [% ELSE %]
-                                       <label for="B_country">
-                               [% END %]
-                               Country: </label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" id="B_country" name="B_country" size="20" value="[% B_country %]" onclick="this.value=''" />
-                               [% ELSE %]
-                                       <input type="text" id="B_country" name="B_country" size="20" value="[% B_country %]" />
-                               [% END %]
-         [% IF ( mandatoryB_country ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noB_phone %]
-            <li>
-                [% IF ( mandatoryB_phone ) %]
-                <label for="B_phone" class="required">
-                [% ELSE %]
-                <label for="B_phone">
-                [% END %]
-                Phone: </label>
-                [% IF ( opduplicate ) %]
-                                       <input type="text" id="B_phone" name="B_phone" value="[% B_phone %]" onclick="this.value=''" />
-                [% ELSE %]
-                                       <input type="text" id="B_phone" name="B_phone" value="[% B_phone %]" />
-                [% END %]
-                [% IF ( mandatoryB_phone ) %]<span class="required">Required</span>[% END %]
-            </li>
-        [% END %]
-        [% UNLESS noB_email %]
-                       <li> 
-        [% IF ( mandatoryB_email ) %]
-          <label for="B_email" class="required">
+        [% IF Koha.Preference( 'AddressFormat' ) %]
+            [% INCLUDE "member-alt-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
         [% ELSE %]
-          <label for="B_email">
-        [% END %]
-        Email: </label>
-        [% IF ( opduplicate ) %]
-                       <input type="text" id="B_email" name="B_email" size="45" value="[% B_email %]" onclick="this.value=''" />
-        [% ELSE %]
-                       <input type="text" id="B_email" name="B_email" size="45" value="[% B_email %]" />
-               [% END %]
-               [% IF ( mandatoryB_email ) %]<span class="required">Required</span>[% END %] </li>
-        [% END %]
-        [% UNLESS nocontactnote %]
-            <li>
-                [% IF ( mandatorycontactnote ) %]
-                <label for="contactnote" class="required">
-                [% ELSE %]
-                <label for="contactnote">
-                [% END %]
-                Contact note: </label>
-                <textarea id="contactnote" name="contactnote" cols="40" rows="2">[% contactnote %]</textarea>
-        [% IF ( mandatorycontactnote ) %]<span class="required">Required</span>[% END %]
-            </li>
+            [% INCLUDE 'member-alt-address-style-us.inc' %]
         [% END %]
-                       </ol>
-               </fieldset>
     [% END # UNLESS noB_address && noB_city && noB_state && noB_phone && noB_email %]
 [% END %]
 [% IF ( step_2 ) %]
     [% UNLESS noaltcontactsurname && noaltcontactfirstname && noaltcontactaddress1 && noaltcontactaddress2 && noaltcontactaddress3 && noaltcontactstate && noaltcontactzipcode && noaltcontactcountry && noaltcontactphone %]
-               <fieldset class="rows" id="memberentry_altaddress">       
-            <legend id="alt_contact_lgd">Alternate contact</legend><ol>
-        [% UNLESS noaltcontactsurname %]
-                       <li>
-                           [% IF ( mandatoryaltcontactsurname ) %]
-                               <label for="altcontactsurname" class="required">
-                               [% ELSE %]
-                               <label for="altcontactsurname">
-                               [% END %]
-                               Surname:</label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" name="altcontactsurname" id="altcontactsurname" value="[% altcontactsurname %]" onclick="this.value=''" />
-                               [% ELSE %]
-                                       <input type="text" name="altcontactsurname" id="altcontactsurname" value="[% altcontactsurname %]" />
-                               [% END %]
-                               [% IF ( mandatoryaltcontactsurname ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noaltcontactfirstname %]
-                       <li>
-                           [% IF ( mandatoryaltcontactfirstname ) %]
-                               <label for="altcontactfirstname" class="required">
-                               [% ELSE %]
-                               <label for="altcontactfirstname">
-                               [% END %]
-                               First name:</label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" name="altcontactfirstname" id="altcontactfirstname" value="[% altcontactfirstname %]" onclick="this.value=''" />
-                               [% ELSE %]
-                                       <input type="text" name="altcontactfirstname" id="altcontactfirstname" value="[% altcontactfirstname %]" />
-                               [% END %]
-                               [% IF ( mandatoryaltcontactfirstname ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noaltcontactaddress1 %]
-                       <li>
-                           [% IF ( mandatoryaltcontactaddress1 ) %]
-                               <label for="altcontactaddress1" class="required">
-                               [% ELSE %]
-                               <label for="altcontactaddress1">
-                               [% END %]
-                               Address:</label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" name="altcontactaddress1" id="altcontactaddress1" value="[% altcontactaddress1 %]" onclick="this.value=''" size="40" />
-                               [% ELSE %]
-                                       <input type="text" name="altcontactaddress1" id="altcontactaddress1" value="[% altcontactaddress1 %]" size="40" />
-                               [% END %]
-                               [% IF ( mandatoryaltcontactaddress1 ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noaltcontactaddress2 %]
-                       <li>
-                           [% IF ( mandatoryaltcontactaddress2 ) %]
-                               <label for="altcontactaddress2" class="required">
-                               [% ELSE %]
-                               <label for="altcontactaddress2">
-                               [% END %]
-                               Address 2:</label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" name="altcontactaddress2" id="altcontactaddress2" value="[% altcontactaddress2 %]" onclick="this.value=''" size="40" />
-                               [% ELSE %]
-                                       <input type="text" name="altcontactaddress2" id="altcontactaddress2" value="[% altcontactaddress2 %]" size="40" />
-                               [% END %]
-                               [% IF ( mandatoryaltcontactaddress2 ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noaltcontactaddress3 %]
-                       <li>
-                           [% IF ( mandatoryaltcontactaddress3 ) %]
-                               <label for="altcontactaddress3" class="required">
-                               [% ELSE %]
-                               <label for="altcontactaddress3">
-                               [% END %]
-                               City:</label>
-                               <input type="text" name="altcontactaddress3" id="altcontactaddress3" value="[% altcontactaddress3 %]" size="20" />
-                               [% IF ( mandatoryaltcontactaddress3 ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noaltcontactstate %]
-                       <li>
-                           [% IF ( mandatoryaltcontactstate ) %]
-                               <label for="altcontactstate" class="required">
-                               [% ELSE %]
-                               <label for="altcontactstate">
-                               [% END %]
-                               State:</label>
-                               <input type="text" name="altcontactstate" id="altcontactstate" value="[% altcontactstate %]" size="20" />
-                               [% IF ( mandatoryaltcontactstate ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noaltcontactzipcode %]
-                       <li>
-                           [% IF ( mandatoryaltcontactzipcode ) %]
-                               <label for="altcontactzipcode" class="required">
-                               [% ELSE %]
-                               <label for="altcontactzipcode">
-                               [% END %]
-                               Zip/Postal code:</label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" name="altcontactzipcode" id="altcontactzipcode" value="[% altcontactzipcode %]" onclick="this.value=''" size="5" />
-                               [% ELSE %]
-                                       <input type="text" name="altcontactzipcode" id="altcontactzipcode" value="[% altcontactzipcode %]" size="5" />
-                               [% END %]
-                               [% IF ( mandatoryaltcontactzipcode ) %]<span class="required">Required</span>[% END %]
-                       </li>
-        [% END %]
-        [% UNLESS noaltcontactcountry %]
-                       <li>
-                           [% IF ( mandatoryaltcontactcountry ) %]
-                               <label for="altcontactcountry" class="required">
-                               [% ELSE %]
-                               <label for="altcontactcountry">
-                               [% END %]
-                               Country:</label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" name="altcontactcountry" id="altcontactcountry" value="[% altcontactcountry %]" onclick="this.value=''" size="20" />
-                               [% ELSE %]
-                                       <input type="text" name="altcontactcountry" id="altcontactcountry" value="[% altcontactcountry %]" size="20" />
-                               [% END %]
-                               [% IF ( mandatoryaltcontactcountry ) %]<span class="required">Required</span>[% END %]
-                       </li>                   
-        [% END %]
-        [% UNLESS noaltcontactphone %]
-                       <li>
-                           [% IF ( mandatoryaltcontactphone ) %]
-                               <label for="altcontactphone" class="required">
-                               [% ELSE %]
-                               <label for="altcontactphone">
-                               [% END %]
-                               Phone:</label>
-                               [% IF ( opduplicate ) %]
-                                       <input type="text" name="altcontactphone" id="altcontactphone" value="[% altcontactphone %]" onclick="this.value=''" />
-                               [% ELSE %]
-                                       <input type="text" name="altcontactphone" id="altcontactphone" value="[% altcontactphone %]" />
-                               [% END %]
-                               [% IF ( mandatoryaltcontactphone ) %]<span class="required">Required</span>[% END %]
-                       </li>
+        [% IF Koha.Preference( 'AddressFormat' ) %]
+            [% INCLUDE "member-alt-contact-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
+        [% ELSE %]
+            [% INCLUDE 'member-alt-contact-style-us.inc' %]
         [% END %]
-            </ol>
-        </fieldset>
     [% END # UNLESS noaltcontactsurname && noaltcontactfirstname etc %]
 
 [% END %]
 
   <fieldset class="rows" id="memberentry_library_management">
     <legend id="library_management_lgd">Library management</legend><ol>
-        [% UNLESS nocardnumber %]
-   <li> [% IF ( mandatorycardnumber ) %]
-      <label for="cardnumber" class="required">
-    [% ELSE %]
-      <label for="cardnumber">
-    [% END %] 
-    Card number: </label>
-       <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" />
-         [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]</li>
-        [% END %]
-        [% UNLESS nobranchcode %]
+      [% UNLESS nocardnumber %]
+        <li>
+          [% IF ( mandatorycardnumber ) %]
+            <label for="cardnumber" class="required">
+          [% ELSE %]
+            <label for="cardnumber" class="validated">
+          [% END %]
+          Card number: </label>
+          [% IF minlength_cardnumber == maxlength_cardnumber %]
+                <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" minlength="[% minlength_cardnumber %]" maxlength="[% maxlength_cardnumber %]" />
+                [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]
+                <div class="hint">Card number must be exactly [% minlength_cardnumber %] characters.</div>
+          [% ELSIF minlength_cardnumber && maxlength_cardnumber %]
+                <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" minlength="[% minlength_cardnumber %]" maxlength="[% maxlength_cardnumber %]" />
+                [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]
+                <div class="hint">Card number must be between [% minlength_cardnumber %] and [% maxlength_cardnumber %] characters.</div>
+          [% ELSIF maxlength_cardnumber %]
+                <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" maxlength="[% maxlength_cardnumber %]" />
+                [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]
+                <div class="hint">Card number can be up to [% maxlength_cardnumber %] characters.</div>
+          [% ELSE %]
+                <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" />
+                [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]
+                <div class="hint">There is no minimum or maximum character length.</div>
+          [% END %]
+        </li>
+      [% END %]
+      [% UNLESS nobranchcode %]
     <li>
-      [%- IF ( mandatorybranchcode ) -%]
-        <label for="branchcode" class="required">
-      [%- ELSE -%]
-        <label for="branchcode">
-      [%- END -%]
-      Library:</label>
-      <select name="branchcode" size="1" id="branchcode">
+        <label for="libraries" class="required">Library:</label>
+        <select name="branchcode" size="1" id="libraries">
         [%- FOREACH branchloo IN branchloop %]
           [% IF ( branchloo.selected ) -%]
             <option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
           [%- END -%]
         [%- END %]
       </select>
-      [% IF ( mandatorybranchcode ) -%]
       <span class="required">Required</span>
-      [%- END %]
     </li>
         [% END %]
     <li>
-        <label for="categorycode">Category: </label>
-        <select id="categorycode" name="categorycode" onchange="update_category_code(this);">
+        <label for="categorycode_entry" class="required">Category: </label>
+        <select id="categorycode_entry" name="categorycode" onchange="update_category_code(this);">
         [% FOREACH typeloo IN typeloop %]
             [% FOREACH categoryloo IN typeloo.categoryloop %]
                 [% IF ( loop.first ) %]
-                    [% IF ( typeloo.typename_C ) %]<optgroup label="Child"        value="C">[% END %]
-                    [% IF ( typeloo.typename_A ) %]<optgroup label="Adult"        value="A">[% END %]
-                    [% IF ( typeloo.typename_S ) %]<optgroup label="Staff"        value="S">[% END %]
-                    [% IF ( typeloo.typename_I ) %]<optgroup label="Organization" value="I">[% END %]
-                    [% IF ( typeloo.typename_P ) %]<optgroup label="Professional" value="P">[% END %]
-                    [% IF ( typeloo.typename_X ) %]<optgroup label="Statistical"  value="X">[% END %]
+                    [% IF ( typeloo.typename_C ) %]<optgroup label="Child">[% END %]
+                    [% IF ( typeloo.typename_A ) %]<optgroup label="Adult">[% END %]
+                    [% IF ( typeloo.typename_S ) %]<optgroup label="Staff">[% END %]
+                    [% IF ( typeloo.typename_I ) %]<optgroup label="Organization">[% END %]
+                    [% IF ( typeloo.typename_P ) %]<optgroup label="Professional">[% END %]
+                    [% IF ( typeloo.typename_X ) %]<optgroup label="Statistical">[% END %]
                 [% END %]
                 [% IF ( categoryloo.categorycodeselected ) %]
                     <option value="[% categoryloo.categorycode %]" selected="selected" data-typename="[% typeloo.typename %]">[% categoryloo.categoryname %]</option>
             [% END %]
        [% END %]
        </select>
+       <span class="required">Required</span>
     </li>
         [% UNLESS nosort1 %]
     <li>
         <label for="sort1">
       [% END %]
       Sort 1: </label>
-      [% IF ( CGIsort1 ) %] 
-        [% CGIsort1 %]
-      [% ELSE %]
-          [% IF ( opduplicate ) %]
-            <input  type="text" id="sort1" name="sort1" size="20"  value="[% sort1 %]" onclick="this.value=''" />
-          [% ELSE %]
-            <input  type="text" id="sort1" name="sort1" size="20"  value="[% sort1 %]" />
-          [% END %]
-         [% IF ( mandatorysort1 ) %]<span class="required">Required</span>[% END %]
-      [% END %]   
+      [% PROCESS 'av-build-dropbox.inc' name="sort1", category="Bsort1", default=sort1, size = 20 %]
+      [% IF ( mandatorysort1 ) %]<span class="required">Required</span>[% END %]
     </li>
         [% END %]
         [% UNLESS nosort2 %]
     <label for="sort2">
     [% END %]
     Sort 2: </label>
-    [% IF ( CGIsort2 ) %] 
-      [% CGIsort2 %]
-    [% ELSE %]
-      [% IF ( opduplicate ) %]
-               <input  type="text" id="sort2" name="sort2" size="20"  value="[% sort2 %]" onclick="this.value=''" />
-      [% ELSE %]
-               <input  type="text" id="sort2" name="sort2" size="20"  value="[% sort2 %]" />
-      [% END %]
-         [% IF ( mandatorysort2 ) %]<span class="required">Required</span>[% END %]
-    [% END %] 
+    [% PROCESS 'av-build-dropbox.inc' name="sort2", category="Bsort2", default=sort2, size = 20 %]
+    [% IF ( mandatorysort2 ) %]<span class="required">Required</span>[% END %]
     </li>
         [% END %]
+    [% IF ( Koha.Preference( 'NorwegianPatronDBEnable' ) == 1 ) %]
+        <li>
+            <label for="sort2">Sync with the Norwegian national patron database:</label>
+            [% IF ( sync == 0 ) %]
+                <input type="radio" id="sync" name="sync" value="1"> Yes
+                <input type="radio" id="sync" name="sync" value="0" checked> No
+            [% ELSE %]
+                <input type="radio" id="sync" name="sync" value="1" checked> Yes
+                <input type="radio" id="sync" name="sync" value="0"> No
+            [% END %]
+        </li>
+    [% END %]
        </ol>
   </fieldset>
     [% UNLESS nodateenrolled &&  noopacnote && noborrowernotes %]
             <label for="from">
                        [% END %]
                        Registration date: </label>
-                       [% IF ( metric ) %]
+            [% IF ( dateformat == "metric" ) %]
                 <input type="text" id="from" name="dateenrolled"  maxlength="10" size="10" onchange="CheckDate(document.form.dateenrolled);check_manip_date('verify');" value="[% dateenrolled %]" class="datepickerfrom" />
-                       [% ELSE %]
+            [% ELSE %]
                 <input type="text" id="from" name="dateenrolled"  maxlength="10" size="10" value="[% dateenrolled %]" class="datepickerfrom" />
-                       [% END %]
+            [% END %]
                [% IF ( mandatorydateenrolled ) %]<span class="required">Required</span>[% END %]
                [% IF ( ERROR_dateenrolled ) %]<span class="required">(Error)</span>[% END %]
                <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
                        [% ELSE %]
             <label for="to">
                        [% END %]
-                       Expiry date (leave blank for auto calc) </label>
-                       [% IF ( metric ) %]
+                       Expiry date (leave blank for auto calc): </label>
+            [% IF ( dateformat == "metric" ) %]
                                [% UNLESS ( opadd ) %]
-                    <input type="text" id="to" name="dateexpiry" maxlength="10"  size="10" onchange="CheckDate(document.form.dateexpiry);check_manip_date('verify');" value="[% dateexpiry %]" class="datepickerto" />
+                    <input type="text" id="to" name="dateexpiry" maxlength="10"  size="10" onchange="CheckDate(document.form.dateexpiry);check_manip_date('verify');" value="[% UNLESS opduplicate %][% dateexpiry %][% END %]" class="datepickerto" />
                                [% ELSE %]
                     <input type="text" id="to" name="dateexpiry" maxlength="10"  size="10" onchange="CheckDate(document.form.dateexpiry);check_manip_date('verify');" class="datepickerto" />
                                [% END %]
                        [% ELSE %]
                                [% UNLESS ( opadd ) %]
-                <input type="text" id="to" name="dateexpiry" maxlength="10"  size="10" value="[% dateexpiry %]" class="datepickerto" />
+                <input type="text" id="to" name="dateexpiry" maxlength="10"  size="10" value="[% UNLESS opduplicate %][% dateexpiry %][% END %]" class="datepickerto" />
                                [% ELSE %]
                 <input type="text" id="to" name="dateexpiry" maxlength="10"  size="10" class="datepickerto" />
                                [% END %]
                                <label for="opacnote">
                        [% END %]       
                        OPAC note: </label>
-                       <textarea id="opacnote" name="opacnote" cols="55" rows="5">[% opacnote %]</textarea>
+            <textarea id="opacnote" name="opacnote" cols="55" rows="5">[% UNLESS opduplicate %][% opacnote %][% END %]</textarea>
                        <div class="hint">This message appears on this patron's user page in the OPAC</div>
          [% IF ( mandatoryopacnote ) %]<span class="required">Required</span>[% END %]
                </li>
                                <label for="borrowernotes">
                        [% END %]
                        Circulation note: </label>
-                       <textarea id="borrowernotes" name="borrowernotes" cols="55" rows="5">[% borrowernotes %]</textarea>
+            <textarea id="borrowernotes" name="borrowernotes" cols="55" rows="5">[% UNLESS opduplicate %][% borrowernotes %][% END %]</textarea>
                        <div class="hint">This message displays when checking out to this patron</div>
          [% IF ( mandatoryborrowernotes ) %]<span class="required">Required</span>[% END %]
                </li>
        [% END %]
 [% END %]
 
+[%# Dummy input to avoid Firefox from using userid/password saved for authentication %]
+<input type="text" disabled="disabled" style="display:none" />
+
          [% IF ( mandatoryuserid ) %]<span class="required">Required</span>[% END %]
                </li>
         [%END %]
                </fieldset>
         [% END # hide fieldset %][% END %]
                <!--this zones are not necessary in modif mode -->
-               [% UNLESS ( opadd ) %]
+        [% UNLESS ( opadd || opduplicate ) %]
                <fieldset class="rows">
             <legend>Patron account flags</legend>
                        <ol class="radio">
                        [% FOREACH flagloo IN flagloop %]
                                <li><label class="radio" for="yes[% flagloo.name %]">
                 [% IF ( flagloo.key == 'gonenoaddress' ) %]Gone no address:[% END %]
-                               [% IF ( flagloo.key == 'debarred' ) %]Restricted:[% END %]
                 [% IF ( flagloo.key == 'lost' ) %]Lost card:[% END %]
                 </label>
+                [% IF CAN_user_circulate_manage_restrictions %]
                                <label for="yes[% flagloo.name %]">Yes </label>
                                [% IF ( flagloo.yes ) %]
                                <input type="radio" id="yes[% flagloo.name %]" name="[% flagloo.name %]" value="1" checked="checked" />
                                [% ELSE %]
                                <input type="radio" id="no[% flagloo.name %]" name="[% flagloo.name %]" value="0" />
                                [% END %]
+                [% ELSE %]
+                  [% IF flagloo.yes %]Yes[% ELSE %]No[% END %]
+                [% END %]
 
             </li>
                        [% END %]
-                       <li>
-                               <label for="yesdebarred" class="radio">Restricted: </label>
-                               [% IF ( debarred ) %]
-                               <label for="yesdebarred">Yes </label>
-                               <input type="radio" id="yesdebarred" name="debarred" value="1" checked="checked"/>
-                <label for="nodebarred">No </label>
-                <input type="radio" id="nodebarred" name="debarred" value="0"/>
-                               [% ELSE %]
-                               <label for="yesdebarred">Yes </label>
-                               <input type="radio" id="yesdebarred" name="debarred" value="1" />
-                <label for="nodebarred">No </label>
-                <input type="radio" id="nodebarred" name="debarred" value="0" checked="checked"/>
-                               [% END %]
-
-                <span id="debarreduntil"><label for="datedebarred" class="inline">Until:</label>
-                                [% IF opduplicate %]
-                                    <input type="text" name="datedebarred" id="datedebarred" class="debarred datepicker" value="[% datedebarred %]" onclick="this.value=''" />
-                                [% ELSE %]
-                                    <input type="text" name="datedebarred" id="datedebarred" class="debarred datepicker" value="[% datedebarred %]" />
-                                [% END %]
-                <span class="hint">(optional)</span> </span>
-                </li>
-                <li>
-                       <label for="debarredcomment" class="radio">Comment:</label>
-                              [% IF ( opduplicate ) %] 
-                                  <textarea id="debarredcomment" name="debarredcomment" cols="55" rows="3" onclick="this.value=''">[% debarredcomment %]</textarea>
-                              [% ELSE %]
-                                  <textarea id="debarredcomment" name="debarredcomment" cols="55" rows="3">[% debarredcomment %]</textarea>
-                              [% END %]
-               </li>
 
                        </ol>
                        </fieldset>
-    
+
+              <fieldset class="rows">
+                <legend>Patron restrictions</legend>
+
+                [% IF ( debarments ) %]
+                    <table>
+                        <thead>
+                            <tr>
+                                 <th>Type</th>
+                                 <th>Comment</th>
+                                 <th>Expiration</th>
+                                 [% IF CAN_user_borrowers && CAN_user_circulate_manage_restrictions %]
+                                   <th>Remove?</th>
+                                 [% END %]
+                            </tr>
+                        </thead>
+
+                        <tbody>
+                            [% FOREACH d IN debarments %]
+                                <tr>
+                                    <td>[% d.type %]</td>
+                                    <td>[% d.comment %]</td>
+                                    <td>[% IF d.expiration %] [% d.expiration | $KohaDates %] [% ELSE %] <i>Indefinite</i> [% END %]</td>
+                                    [% IF CAN_user_borrowers && CAN_user_circulate_manage_restrictions %]
+                                      <td>
+                                        <input type="checkbox" id="debarment_[% d.borrower_debarment_id %]" name="remove_debarment" value="[% d.borrower_debarment_id %]" />
+                                      </td>
+                                    [% END %]
+                                </tr>
+                            [% END %]
+                        </tbody>
+                    </table>
+                [% ELSE %]
+                    <p>Patron is currently unrestricted.</p>
+                [% END %]
+
+                [% IF CAN_user_borrowers && CAN_user_circulate_manage_restrictions %]
+                    <p><a href="#" id="add_manual_restriction">Add manual restriction</a></p>
+                    <fieldset id="manual_restriction_form">
+                        <input type="hidden" id="add_debarment" name="add_debarment" value="0" />
+                        <legend>Add manual restriction</legend>
+                        <ol>
+                            <li><label for="debarred_comment">Comment: </label><input type="text" id="debarred_comment" name="debarred_comment" onchange="$('#add_debarment').val(1);" /></li>
+                            <li><label for="debarred_expiration">Expiration: </label><input name="debarred_expiration" id="debarred_expiration" size="10" readonly="readonly" value="" class="datepicker" onchange="$('#add_debarment').val(1);" />
+                                    <a href='javascript:void(0)' onclick="$('#debarred_expiration').val('');">Clear date</a></li>
+
+                        </ol>
+                        <p>
+                            <a class="cancel" id="cancel_manual_restriction" href="#">Cancel</a>
+                        </p>
+                    </fieldset>
+                [% END %]
+            </fieldset>
                [% END %]
 
 [% END %]
 
 [% IF ( step_4 ) %][% IF ( ExtendedPatronAttributes ) %][% UNLESS ( no_patron_attribute_types ) %]
   <fieldset class="rows" id="memberentry_patron_attributes">
-    <input type="hidden" name="setting_extended_patron_attributes" value="1" />
     <legend>Additional attributes and identifiers</legend>
+    <input type="hidden" name="setting_extended_patron_attributes" value="1" />
     [% FOREACH pa_loo IN patron_attributes %]
         [% IF pa_loo.class %]
             <fieldset id="aai_[% pa_loo.class %]">
                         <input type="hidden" id="[% patron_attribute.form_id %]_code" name="[% patron_attribute.form_id %]_code" value="[% patron_attribute.code |html %]" />
                         [% IF ( patron_attribute.use_dropdown ) %]
                             <select id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]">
-                                <option value="" />
+                                <option value=""></option>
                                 [% FOREACH auth_val_loo IN patron_attribute.auth_val_loop %]
-                                    [% IF ( auth_val_loo.selected ) %]
+                                    [% IF auth_val_loo.authorised_value == patron_attribute.value %]
                                         <option value="[% auth_val_loo.authorised_value %]" selected="selected">
                                             [% auth_val_loo.lib %]
                                         </option>
                                 [% END %]
                             </select>
                         [% ELSE %]
-                            [% IF ( opduplicate ) %]
-                            <textarea rows="2" cols="30" id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]" onclick="this.value=''" >[% patron_attribute.value %]</textarea>
-                            [% ELSE %]
                             <textarea rows="2" cols="30" id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]">[% patron_attribute.value %]</textarea>
-                            [% END %]
-                        [% END %]
-                        [% IF ( patron_attribute.password_allowed ) %]
-                            (<label class="yesno" for="[% patron_attribute.form_id %]_password">Password:</label> <input type="password" maxlength="64" value="[% patron_attribute.password %]"
-                                   id="[% patron_attribute.form_id %]_password" name="[% patron_attribute.form_id %]_password" />)
                         [% END %]
-                        <a href="#" class="clear-field" onclick="clear_entry(this); return false;">Clear</a>
+                        <a href="#" onclick="clear_entry(this); return false;"><i class="fa fa-fw fa-trash"></i> Clear</a>
                         [% IF ( patron_attribute.repeatable ) %]
-                        <a href="#" class="clone-field" onclick="clone_entry(this); return false;">New</a>
+                        <a href="#" onclick="clone_entry(this); return false;"><i class="fa fa-fw fa-plus"></i> New</a>
                         [% END %]
                 </li>
             [% END %]
 
 [% IF ( step_5 ) %][% IF ( EnhancedMessagingPreferences ) %]
   <fieldset class="rows" id="memberentry_messaging_prefs">
+    <legend id="patron_messaging_prefs_lgd">Patron messaging preferences</legend>
     [% IF ( opadd ) %]
     <!-- handle changing prefs if creating new patron and changing
          the patron category
             $('#memberentry_messaging_prefs > *').change(function() {
                 message_prefs_dirty = true;
             });
-            $('#categorycode').change(function() {
+            $('#categorycode_entry').change(function() {
                 var categorycode = $(this).val();
                 if (message_prefs_dirty) {
-                    if (!confirm('Change messaging preferences to default for this category?')) {
+                    if (!confirm(_("Change messaging preferences to default for this category?"))) {
                         return;
                     }
                 }
     </script>
     [% END %]
     <input type="hidden" name="setting_messaging_prefs" value="1" />
-    <legend id="patron_messaging_prefs_lgd">Patron messaging preferences</legend>
-    [% IF type_only %]
-        <p>If no preferences are selected, the default preferences for the category chosen will be applied on save, otherwise your selection here is saved</p>
-    [% END %]
     [% INCLUDE 'messaging-preference-form.inc' %]
     [% IF ( SMSSendDriver ) %]
         <p><label for="SMSnumber">SMS number:</label>
-          [% IF ( opduplicate ) %]
-            <input type="text" id="SMSnumber" name="SMSnumber" value="[% SMSnumber %]" onclick="this.value=''" />
-          [% ELSE %]
             <input type="text" id="SMSnumber" name="SMSnumber" value="[% SMSnumber %]" />
-        [% END %]
+        </p>
+        <p>
+            <label for="sms_provider_id">SMS provider:</label>
+            <select id="sms_provider_id" name="sms_provider_id"/>
+                <option value="">Unknown</option>
+                [% FOREACH s IN sms_providers %]
+                    [% IF s.id == sms_provider_id %]
+                        <option value="[% s.id %]" selected="selected">[% s.name %]</option>
+                    [% ELSE %]
+                        <option value="[% s.id %]">[% s.name %]</option>
+                    [% END %]
+                [% END %]
+            </select>
         </p>
     [% END %]
   </fieldset>
 [% END %] [% END %]
 
+<fieldset class="rows" id="save">
 [% UNLESS ( check_member ) %]
     <fieldset class="action">
         <input type="submit" name="save" onclick="return check_form_borrowers();" value="Save" />
           [% END %]
     </fieldset>
 [% END %]
+</fieldset>
 </form>
   
 </div>