{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
  
$(function() {
  AltButtons();
});

function SvtGet(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtGet.ajax.php{literal}",
    success: function(answ){
      DialogStandartOpen('SvtFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessSelectRecord}{literal}", 740);
      $('#GridSvt').setGridWidth(720, false);
    }
  });
}

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

function SvtGiveoutStatusGet(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtGiveoutStatusGet.ajax.php{literal}",
    success: function(answ){
      DialogStandartOpen('SvtGiveoutStatusFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessSelectRecord}{literal}", 740);
      $('#GridSvtGiveoutStatus').setGridWidth(720, false);
    }
  });
}

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

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() {
  $("select").css("width","400px");
  $("textarea").css("width","400px");
  $("textarea").css("height","40px");
});

function showResponseFormSvtGiveoutAdd(responseText){
  if(typeof(responseText['error'])=='undefined'){
    //alert(responseText['message']);
    $("#GridSvtGiveout").trigger("reloadGrid");
    $("#SvtGiveoutEditFrm").dialog("destroy");
    DialogStandartMessageOpen("message", responseText['message']);
  }
  else{
    DialogStandartMessageOpen("error", responseText['error']);
  }
}

$(function() {
  var options = {
    success: showResponseFormSvtGiveoutAdd,
    timeout: 3000
  };
  $("#FormSvtGiveoutAdd").validate({
    submitHandler: function(form) {
      $(form).ajaxSubmit(options);
    },
    ignore: "",
    rules : {
      "FrmAgreeMasterCheckboxes[]" : {required : true},
      'FrmAgreeSvtHidden' : {
        required: {
          depends: function(element) {
            if($(":checkbox[id^='FrmAgreeSvtCheckboxes']:checked").length){
              return false;
            }
            else{
              return true;
            }
          }
        }
      },
      'FrmAgreeUsersHidden' : {
        required: {
          depends: function(element) {
            if($(":checkbox[id^='FrmAgreeUsersCheckboxes']:checked").length){
              return false;
            }
            else{
              return true;
            }
          }
        }
      },
      'FrmAgreeSvtGiveoutStatusHidden' : {
        required: {
          depends: function(element) {
            if($(":checkbox[id^='FrmAgreeSvtGiveoutStatusCheckboxes']:checked").length){
              return false;
            }
            else{
              return true;
            }
          }
        }
      },
      svtgiveout_date_b : {required : true},
      svtgiveout_date_e : {required : true}
    },
    messages: {
      'FrmAgreeSvtHidden': {
        required: "Выберите СВТ"
      },
      'FrmAgreeUsersHidden': {
        required: "Выберите Пользователя"
      },
      'FrmAgreeSvtGiveoutStatusHidden': {
        required: "Выберите Статус"
      }
    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
});

$(function(){
  $.datepicker.setDefaults($.datepicker.regional['ru']);
  var VarYearB = (new Date).getFullYear()-10;
  var VarYearE = (new Date).getFullYear()+10;
  $("#svtgiveout_date_b").datepicker($.extend({yearRange: VarYearB+':'+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}'}));
  $("#svtgiveout_date_b").datepicker( "setDate", '+0d');

  $("#svtgiveout_date_e").datepicker($.extend({yearRange: VarYearB+':'+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}'}));
  $("#svtgiveout_date_e").datepicker( "setDate", '+7d');
});
//]]>
</script>
{/literal}

<form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtGiveoutSave.ajax.php" method="post" name="FormSvtGiveoutAdd" id="FormSvtGiveoutAdd">
  <input id="svtgiveout_id" name="svtgiveout_id" type="hidden" value="{if isset($ArrSvtGiveout.svtgiveout_id)}{$ArrSvtGiveout.svtgiveout_id}{/if}" />
  <table>
    <tr>
      <td><label for="FrmAgreeMasterCheckboxes[]">Исполнитель :&nbsp;</label><span></span></td>
      <td colspan="2">
        {foreach $ArrUsersMaster as $val}
          {if $val@first}
            <select id="FrmAgreeMasterCheckboxes" name="FrmAgreeMasterCheckboxes[]">
              <option value="">---выберите исполнителя---</option>
          {/if}
              <option value="{$val.users_id}" {if isset($ArrSvtGiveout.demands_masterid) && $ArrSvtGiveout.demands_masterid eq $val.users_id}selected="selected"{/if}>{$val.users_fio}</option>
          {if $val@last}
            </select>
          {/if}
        {/foreach}
      </td>
    </tr>
    <tr>
      <td><label for="FrmAgreeSvtHidden">СВТ <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='SvtGet();' /><input type="hidden" id="FrmAgreeSvtHidden" name="FrmAgreeSvtHidden" value="" /></td>
      <td id="FormAdvSvtContent">
        {if isset($ArrSvtGiveout.svt_id)}
          <div id="FrmAgreeSvtDivCheckboxes{$ArrSvtGiveout.svt_id}"><input id="FrmAgreeSvtCheckboxes{$ArrSvtGiveout.svt_id}" name="FrmAgreeSvtCheckboxes[]" value="{$ArrSvtGiveout.svt_id}" checked="checked" type="checkbox" /> {if $ArrSvtGiveout.svt_name}({$ArrSvtGiveout.svt_name}) {/if}{$ArrSvtGiveout.svt_buxname}&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='$("#FrmAgreeSvtDivCheckboxes{$ArrSvtGiveout.svt_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
    <tr>
    <tr>
      <td><label for="FrmAgreeSvtGiveoutStatusHidden">Статус <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='SvtGiveoutStatusGet();' /><input type="hidden" id="FrmAgreeSvtGiveoutStatusHidden" name="FrmAgreeSvtGiveoutStatusHidden" value="" /></td>
      <td id="FormAdvSvtGiveoutStatusContent">
        {if isset($ArrSvtGiveout.svtgiveoutstatus_id)}
          <div id="FrmAgreeSvtGiveoutStatusDivCheckboxes{$ArrSvtGiveout.svtgiveoutstatus_id}"><input id="FrmAgreeSvtGiveoutStatusCheckboxes{$ArrSvtGiveout.svtgiveoutstatus_id}" name="FrmAgreeSvtGiveoutStatusCheckboxes[]" value="{$ArrSvtGiveout.svtgiveoutstatus_id}" checked="checked" type="checkbox" /> {$ArrSvtGiveout.svtgiveoutstatus_name}&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='$("#FrmAgreeSvtGiveoutStatusDivCheckboxes{$ArrSvtGiveout.svtgiveoutstatus_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
    <tr>
      <td><label for="FrmAgreeUsersHidden">Кому <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='UsersGet("Users");' /><input type="hidden" id="FrmAgreeUsersHidden" name="FrmAgreeUsersHidden" value="" /></td>
      <td id="FormAdvUsersContent">
        {if isset($ArrSvtGiveout.users_id)}
          <div id="FrmAgreeUsersDivCheckboxes{$ArrSvtGiveout.users_id}"><input id="FrmAgreeUsersCheckboxes{$ArrSvtGiveout.users_id}" name="FrmAgreeUsersCheckboxes[]" value="{$ArrSvtGiveout.users_id}" checked="checked" type="checkbox" /> {$ArrSvtGiveout.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{$ArrSvtGiveout.users_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
     <tr>
      <td><label for="svtgiveout_note">Примечание :&nbsp;</label><span></span></td>
      <td colspan="2"><textarea cols="50" rows="2" id="svtgiveout_note" name="svtgiveout_note">{if isset($ArrSvtGiveout.svtgiveout_note)}{$ArrSvtGiveout.svtgiveout_note}{/if}</textarea></td>
    </tr>
    <tr>
      <td><label for="svtgiveout_date_b">Дата с <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2">
        <input type="text" id="svtgiveout_date_b" name="svtgiveout_date_b" value="{$ArrSvtGiveout.svtgiveout_date_b}" />
      </td>
    </tr>
    <tr>
      <td><label for="svtgiveout_date_e">Дата по <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2">
        <input type="text" id="svtgiveout_date_e" name="svtgiveout_date_e" value="{$ArrSvtGiveout.svtgiveout_date_e}" />
      </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>