{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[

$(function() {
  AltButtons();
});

function GeneratePass(){
  var chars="qazxswedcvfrtgbnhyujmkp123456789QAZXSWEDCVFRTGBNHYUJMKP";
  var max = 10;
  var size = chars.length-1;
  var password="";
  while (max--){
	 password = password+chars[Math.floor(Math.random() * (size + 1))];
	}
  $("#users_password")[0].value=password;
  $("#users_password2")[0].value=password;  
}

function StructureOrganizationGet(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/StructureOrganizationGet.ajax.php{literal}",
    success: function(answ){
      DialogStandartOpen('StructureOrganizationFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessSelectRecord}{literal}");
    }
  });
}

function StructureOrganizationSelectionSelect(VarId, VarText){
  if(!$("#FrmAgreeStructureOrganizationCheckboxes"+VarId).length){
    $("#FormAdvStructureOrganizationContent").html('<div id="FrmAgreeStructureOrganizationCheckboxes'+VarId+'"><input type="checkbox" id="FrmAgreeStructureOrganizationCheckboxes'+VarId+'" name="FrmAgreeStructureOrganizationCheckboxes[]" value="'+VarId+'" checked /> '+VarText+'&nbsp;<img style="vertical-align:middle;" title="Удалить" alt="Удалить" src="{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSmarty}/{$MS_SP->Sp_TemplateName}{literal}/css/images/delete.png" class="MsPseudoAT" onclick=\'$("#FrmAgreeStructureOrganizationCheckboxes'+VarId+'").remove();\'></div>');
  }
  $("#StructureOrganizationFrm").dialog("close");
}

$(function() {
  $("input[name='users_name']").css("width","400px");
  $("input[name='users_password']").css("width","400px");
  $("input[name='users_password2']").css("width","400px");
  $("input[name='users_fio']").css("width","400px");
  $("input[name='users_numofice']").css("width","400px");
  $("input[name='users_tel']").css("width","400px");
  $("input[name='users_telint']").css("width","400px");
  $("input[name='users_telcell']").css("width","400px");
  $("input[name='users_email']").css("width","400px");
  $("input[name='users_jobtitle']").css("width","400px");
  //$("input[name='users_status']").css("width","400px");
  $("textarea").css("width","400px");
  $("textarea").css("height","40px");
});

function showResponseFormUsersAdd(responseText){
  if(typeof(responseText['error'])=='undefined'){
    //alert(responseText['message']);
    $("#GridUsers").trigger("reloadGrid");
    $("#UsersEditFrm").dialog("close");
    DialogStandartMessageOpen("message", responseText['message']);
  }
  else{
    DialogStandartMessageOpen("error", responseText['error']);
  }
}

$(function(){
  var options = {
    success: showResponseFormUsersAdd,
    timeout: 3000
  };
  $("#FormUsersAdd").validate({
    submitHandler: function(form) {
      $(form).ajaxSubmit(options);
    },
    ignore: "",
    rules : {
      'FrmAgreeStructureOrganizationHidden' : {
        required: {
          depends: function(element) {
            if($(":checkbox[id^='FrmAgreeStructureOrganizationCheckboxes']:checked").length){
              return false;
            }
            else{
              return true;
            }
          }
        }
      },
      //users_name : {required : true},
      users_password : {required : true},
      users_password2 : {
        equalTo: "#users_password"
      },
      users_fio : {required : true},
      users_email : {email: true}
    },
    messages: {
      'FrmAgreeStructureOrganizationHidden': {
        required: "Выберите Подразделение"
      }
    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
});
//]]>
</script>
{/literal}

<form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UsersSave.ajax.php" method="post" name="FormUsersAdd" id="FormUsersAdd">
  <input id="users_id" name="users_id" type="hidden" value="{if isset($ArrUsers.users_id)}{$ArrUsers.users_id}{/if}" />
  <table>
    <tr>
      <td><label for="FrmAgreeStructureOrganizationHidden">Подразделение <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td style="width:16px;"><img title="Выбрать Подразделение" alt="Выбрать Подразделение" src="/{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSmarty}/{$MS_SP->Sp_TemplateName}/css/images/application_form_magnify.png" class="MsPseudoAT" onclick='StructureOrganizationGet();' /><input type="hidden" id="FrmAgreeStructureOrganizationHidden" name="FrmAgreeStructureOrganizationHidden" value="" /></td>
      <td id="FormAdvStructureOrganizationContent">
        {if isset($ArrUsers.structureorganization_id)}
          <div id="FrmAgreeStructureOrganizationDivCheckboxes{$ArrUsers.structureorganization_id}"><input id="FrmAgreeStructureOrganizationCheckboxes{$ArrUsers.structureorganization_id}" name="FrmAgreeStructureOrganizationCheckboxes[]" value="{$ArrUsers.structureorganization_id}" checked="checked" type="checkbox" /> {$ArrUsers.structureorganization_title}&nbsp;<img style="vertical-align: middle;" title="Удалить" alt="Удалить" src="/{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSmarty}/{$MS_SP->Sp_TemplateName}/css/images/delete.png" class="MsPseudoAT" onclick='$("#FrmAgreeStructureOrganizationDivCheckboxes{$ArrUsers.structureorganization_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
<!--    <tr>
      <td><label for="users_name">Логин <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_name" name="users_name" value="{if isset($ArrUsers.users_name)}{$ArrUsers.users_name}{/if}" /></td>
    </tr>-->
    <tr>
      <td><label for="users_password">Пароль <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="users_password" name="users_password" value="{if isset($ArrUsers.users_passclean)}{$ArrUsers.users_passclean}{/if}" /></td>
      <td><span class="AltButtons" onclick="javascript: GeneratePass()" style="text-align:left;" title="Генерировать пароль"><span class="ui-icon ui-icon-key"></span></span></td>
    </tr>
    <tr>
      <td><label for="users_password2">Пароль повторить <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_password2" name="users_password2" value="{if isset($ArrUsers.users_passclean)}{$ArrUsers.users_passclean}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="users_fio">ФИО <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_fio" name="users_fio" value="{if isset($ArrUsers.users_fio)}{$ArrUsers.users_fio}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="users_note">Описание :&nbsp;</label><span></span></td>
      <td colspan="3"><textarea cols="50" rows="2" id="users_note" name="users_note">{if isset($ArrUsers.users_note)}{$ArrUsers.users_note}{/if}</textarea></td>
    </tr>
    <tr>
      <td><label for="users_numofice">№ комнаты :&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_numofice" name="users_numofice" value="{if isset($ArrUsers.users_numofice)}{$ArrUsers.users_numofice}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="users_tel">Телефон :&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_tel" name="users_tel" value="{if isset($ArrUsers.users_tel)}{$ArrUsers.users_tel}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="users_telint">Телефон вн. :&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_telint" name="users_telint" value="{if isset($ArrUsers.users_telint)}{$ArrUsers.users_telint}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="users_telcell">Телефон сот. :&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_telcell" name="users_telcell" value="{if isset($ArrUsers.users_telcell)}{$ArrUsers.users_telcell}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="users_email">E-mail <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_email" name="users_email" value="{if isset($ArrUsers.users_email)}{$ArrUsers.users_email}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="users_jobtitle">Должность :&nbsp;</label><span></span></td>
      <td colspan="3"><input type="text" id="users_jobtitle" name="users_jobtitle" value="{if isset($ArrUsers.users_jobtitle)}{$ArrUsers.users_jobtitle}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="users_status">Активен/отключен :&nbsp;</label><span></span></td>
      <td colspan="3"><input type="checkbox" id="users_status" name="users_status" value="1" {if isset($ArrUsers.users_status) && 1 == $ArrUsers.users_status}checked{/if} /></td>
    </tr>
    <tr>
      <td colspan="3">
        <span class="ui-state-error"> * </span>поля обязательные для заполнения
      </td>
    </tr>
    <tr>
      <td colspan="3" class="MsFormSubmit"><input class="AltButtons" name="FormSubmit" value="сохранить" type="submit" /></td>
    </tr>
  </table>
</form>