{* Smarty *}

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

$(function() {
  AltButtons();
});
  
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 UsersGet(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/UsersGet.ajax.php{literal}",
    success: function(answ){
      DialogStandartOpen('UsersFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessSelectRecord}{literal}", 740);
      $('#GridUsers').setGridWidth(720, false);
    }
  });
}

function UsersSelect(){
  var VarCountSelectedRows = $("#GridUsers").jqGrid('getGridParam','selarrrow').length;
  if(1 == VarCountSelectedRows){
    var VarId = $("#GridUsers").jqGrid('getGridParam','selrow');
    var VarText = $("#GridUsers").jqGrid('getRowData',VarId).users_fio;
    if(!$("#FrmAgreeUsersCheckboxes"+VarId).length){
      $("#FormAdvUsersContent").html('<div id="FrmAgreeUsersCheckboxes'+VarId+'"><input type="checkbox" id="FrmAgreeUsersCheckboxes'+VarId+'" name="FrmAgreeUsersCheckboxes[]" 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=\'$("#FrmAgreeUsersCheckboxes'+VarId+'").remove();\'></div>');
    }
    $("#UsersFrm").dialog("destroy");
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

$(function(){
  $("textarea").css("width","400px");
  $("textarea").css("height","40px");
});

function showResponseFormSvtAdd(responseText){
  if(typeof(responseText['error'])=='undefined'){
    $("#GridSvt").trigger("reloadGrid");
    $("#GridSvtMove").trigger("reloadGrid");
    $("#SvtEditFrm").dialog("destroy");
    DialogStandartMessageOpen("message", responseText['message']);
  }
  else{
    DialogStandartMessageOpen("error", responseText['error']);
  }
}

$(function(){
  var options = {
    success: showResponseFormSvtAdd,
    timeout: 3000
  };
  $("#FormSvtAdd").validate({
    submitHandler: function(form) {
      $(form).ajaxSubmit(options);
    },
    ignore: "",
    rules : {
      'svtmove_date' : {required : true},
      'FrmAgreeStructureOrganizationHidden' : {
        required: {
          depends: function(element) {
            if($(":checkbox[id^='FrmAgreeStructureOrganizationCheckboxes']:checked").length){
              return false;
            }
            else{
              return true;
            }
          }
        }
      }
    },
    messages: {
      'FrmAgreeStructureOrganizationHidden': {
        required: "Выберите Подразделение"
      }
    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
});

$(function(){
  var VarYearE = (new Date).getFullYear()+1;
  $("#svtmove_date").datepicker($.extend({yearRange: '1970:'+VarYearE, dateFormat: "dd.mm.yy", changeMonth: true, changeYear: true, closeText: 'X', showButtonPanel: true, showStatus: true,showOn: 'both', buttonText: 'Выбрать дату', buttonImageOnly: true, buttonImage: '{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSmarty}/{$MS_SP->Sp_TemplateName}/css/images/ms_check_calendar.png{literal}'})); 
  $("#svtmove_date").datepicker( "setDate", '0d');
});
//]]>
</script>
{/literal}

<form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtMoveSave.ajax.php" method="post" name="FormSvtAdd" id="FormSvtAdd">
  <input id="svt_id" name="svt_id" type="hidden" value="{if isset($ArrSvt.svt_id)}{$ArrSvt.svt_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="SpanPseudoAT" onclick='StructureOrganizationGet();' /><input type="hidden" id="FrmAgreeStructureOrganizationHidden" name="FrmAgreeStructureOrganizationHidden" value="" /></td>
      <td id="FormAdvStructureOrganizationContent">
        {if isset($ArrSvt.structureorganization_id)}
          <div id="FrmAgreeStructureOrganizationDivCheckboxes{$ArrSvt.structureorganization_id}"><input id="FrmAgreeStructureOrganizationCheckboxes{$ArrSvt.structureorganization_id}" name="FrmAgreeStructureOrganizationCheckboxes[]" value="{$ArrSvt.structureorganization_id}" checked="checked" type="checkbox" /> {$ArrSvt.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{$ArrSvt.structureorganization_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
    <tr>
      <td><label for="FrmAgreeUsersHidden">Пользователь :&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="SpanPseudoAT" onclick='UsersGet();' /><input type="hidden" id="FrmAgreeUsersHidden" name="FrmAgreeUsersHidden" value="" /></td>
      <td id="FormAdvUsersContent">
        {if isset($ArrSvt.users_id)}
          <div id="FrmAgreeUsersDivCheckboxes{$ArrSvt.users_id}"><input id="FrmAgreeUsersCheckboxes{$ArrSvt.users_id}" name="FrmAgreeUsersCheckboxes[]" value="{$ArrSvt.users_id}" checked="checked" type="checkbox" /> {$ArrSvt.users_fio}&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='$("#FrmAgreeUsersDivCheckboxes{$ArrSvt.users_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
    <tr>
      <td><label for="svtmove_date">Дата перемещения <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2">
        <input type="text" id="svtmove_date" name="svtmove_date" value="{if isset($ArrSvt.svtmove_date)}{$ArrSvt.svtmove_date|date_format:'%d.%m.%Y'}{/if}" />
      </td>
    </tr>
    <tr>
      <td><label for="svtmove_note">Примечание :&nbsp;</label><span></span></td>
      <td colspan="2"><textarea cols="50" rows="2" id="svtmove_note" name="svtmove_note">{if isset($ArrSvt.svtmove_note)}{$ArrSvt.svtmove_note}{/if}</textarea></td>
    </tr>
    <tr>
      <td colspan="3">
        <span class="ui-state-error"> * </span>{$MS_SP->Sp_LangMessage.label.ReqFields}
      </td>
    </tr>
    <tr>
      <td colspan="3" class="MsFormSubmit"><input class="AltButtons" name="FormSubmit" value="сохранить" type="submit" /></td>
    </tr>
  </table>
</form>