/// <summary>
        /// Проверка выбранных тем лиц.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="model">Модель.</param>
        /// <returns></returns>
        public ActionResult CheckPersonThemes(string control, PersonDossierModel model)
        {
            // 1. Необходимо проверить если хотя бы одна тема в нескольких каталогах
            string themes = model.PersonThemes ?? "";



            if (String.IsNullOrEmpty(themes))
            {
                PersonCardType personType = Repository.Persons.GetInstance(model.PersonID).PersonType;
                if (personType == PersonCardType.Juridical)
                {
                    return(JavaScript(String.Format(@"alert('У лица должен быть хотя бы один тип');   ViewModel.dispatchModelCommand('{0}', '{1}');", "choosetypes", control)));
                }
            }

            string script = String.Format(@"(function() {{
                    window.showModalDialog('{1}?themes={0}&idClient={2}&sectionID={3}', window.self, 'dialogHeight:300px;dialogWidth:500px;resizable:no;scroll:no;');
				}})()"                ,
                                          themes,
                                          Url.FullPathAction("AvailablePersonTypes", "Dossier"),
                                          model.PersonID,
                                          control
                                          );

            return(JavaScript(script));
        }
        protected string RenderRecords(List <Kesco.Persons.BusinessLogic.DataAccess.PersonTypeAccessor.PersonTypeInfo> personsTypeInfo, int clientID, int sectionID)
        {
            bool           isNatural  = true;
            PersonCardType personType = Repository.Persons.GetInstance(clientID).PersonType;

            if (personType == PersonCardType.Juridical)
            {
                isNatural = false;
            }
            bool       check          = false;
            String     w              = null;
            var        catalogsIDs    = personsTypeInfo.GroupBy(a => a.КодТемыЛица);
            List <int> personTypesIDs = PersonTypeAccessor.Accessor.GetPersonTypeIDListByPersonID(clientID);

            w += String.Format(@"
            <script language='javascript'>
             window.document.title = 'Типы лиц в каталогах'; 
            
            function SaveTypesNew()
            {{
                 var typeIDs = '';
                checkboxes = document.getElementsByName('checkBoxInput');
                for(var i=0, n=checkboxes.length;i<n;i++) {{
                    if(checkboxes[i].checked){{
                        typeIDs += checkboxes[i].id; typeIDs += ', ';
                    }}
                }}
                if(typeIDs == '' && '{2}' == 'False'){{  alert('У лица должен быть хотя бы один тип'); return; }};
                finalTypeIDs = typeIDs.substring(0, typeIDs.length - 2);
                dialogArguments.ViewModel.saveTypes(finalTypeIDs, {1});
                self.close();
                    
            }}

            function checkAll(check){{
                checkboxes = document.getElementsByName('checkBoxInput');
                for(var i=0, n=checkboxes.length;i<n;i++) {{
                if(!checkboxes[i].disabled){{ checkboxes[i].checked = check;}}
              }}

            }}
            </script>
              <style>
                .tableTypes {{
	                border-collapse:collapse;
	                table-layout:fixed;
	                width:500px;
                }}

                .gridHeader
                {{
                    background: url(/MVC/persons/styles/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png) 50% 50% repeat-x;
                  
                }}
                .Tdata {{
	                height:245px;
	                width:500px;
	                overflow-y:auto;
	                overflow-x:hidden;
                    background-color: #EEEEEE;
                }}
                td, th{{
	                padding:2px 4px;
	                border-left:1px solid #c5c5c5;
	                border-bottom:1px solid #c5c5c5;
                   
                }}
                td:first-child, th:first-child {{border-left:0;}}
                .DivFixTable {{
	                width:500px;
	                border:1px solid #c5c5c5;
                }}

                #MyTable .tdContent
                {{
                    padding-top: 5px;
                    padding-bottom: 5px;
                }}

                .themeTd
                {{
                    font-size: 13pt;
                    background-color: #EEEEEE;
                }}
            </style>
", AppStyles.URI_Styles_Css, sectionID, isNatural);
            w +=
                String.Format(
                    @"<div class='DivFixTable'>
                                <table class='tableTypes'>
		                            <col width=100> <col width=120>"        );
            w += "<tr class='gridHeader'><th>Тип лица</th><th> <input type=checkbox " + ((check) ? "checked" : "") +
                 " onclick=checkAll(this.checked)> В каталогах</th>";
            w += "</table>";


            w += string.Format(@"<div class='Tdata'><table id='MyTable' class='tableTypes'><col width=100> <col width=120>");

            foreach (var catalogsID in catalogsIDs)
            {
                int i = 0;

                //Если у темы лица есть только 1 каталог, активируем cheackbox и делаем его readonly
                int replyThemes = personsTypeInfo.Count(m => m.КодТемыЛица == catalogsID.Key);
                foreach (var personTypeInfo in catalogsID)
                {
                    check = personTypesIDs.Contains(personTypeInfo.КодТипаЛица);
                    if (i == 0)
                    {
                        w += String.Format(@"<tr class='themeTd'><td>{0}</td><td class='tdContent'>
                        <input id='{4}' name='checkBoxInput' type=checkbox {2} {3}>
                        {1}</td></tr>", personTypeInfo.ТемаЛица, personTypeInfo.Каталог, ((check || replyThemes == 1) ? "checked" : ""), ((replyThemes == 1) ? "disabled" : ""), personTypeInfo.КодТипаЛица);
                    }
                    else
                    {
                        w += String.Format(@"<tr class='themeTd'><td></td><td class='tdContent'>
                         <input id='{2}' name='checkBoxInput' type=checkbox {1}>
                         {0}</td></tr>", personTypeInfo.Каталог, ((check) ? "checked" : ""), personTypeInfo.КодТипаЛица);
                    }
                    i++;
                }
            }
            w += "</table></div>";
            w += "<table class='tableTypes' style='text-align: right;'><tr class='gridHeader'><td>";
            w += "<input type='button' onclick=SaveTypesNew();  value='Сохранить'>";
            w += "&nbsp;";
            w += "<input type='button' onclick=self.close();  value='Отмена'>";
            w += "</tr></tr></table>";
            //w +="<tr>";
            //w +="<td align='right' colspan=2 noWrap>&nbsp;</td>";
            //w +="</tr>";

            w += "</div>";


            return(w);
        }