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

function SvtTypeSelect(){
  var VarCountSelectedRows = $("#GridSvtType").jqGrid('getGridParam','selarrrow').length;
  if(1 == VarCountSelectedRows){
    var VarId = $("#GridSvtType").jqGrid('getGridParam','selrow');
    var VarText = $("#GridSvtType").jqGrid('getRowData',VarId).svttype_name;
    if(!$("#FrmAgreeSvtTypeCheckboxes"+VarId).length){
      $("#FormAdvSvtTypeContent").html('<div id="FrmAgreeSvtTypeCheckboxes'+VarId+'"><input type="checkbox" id="FrmAgreeSvtTypeCheckboxes'+VarId+'" name="FrmAgreeSvtTypeCheckboxes[]" 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=\'$("#FrmAgreeSvtTypeCheckboxes'+VarId+'").remove();\'></div>');
    }
    $("#SvtTypeFrm").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 OrganizGet(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/OrganizGet.ajax.php{literal}",
    success: function(answ){
      DialogStandartOpen('OrganizFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessSelectRecord}{literal}", 740);
      $('#GridOrganiz').setGridWidth(720, false);
    }
  });
}

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

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

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

$(function(){
  $("input[name='svt_name']").css("width","400px");
  $("input[name='svt_buxname']").css("width","400px");
  $("input[name='svt_invnum']").css("width","400px");
  $("input[name='svt_serialnum']").css("width","400px");
//  $("input[name='svt_garant_date']").css("width","400px");
//  $("input[name='svt_date']").css("width","400px");
  //$("input[name='svt_note']").css("width","400px");
  $("textarea").css("width","400px");
  $("textarea").css("height","40px");
});

function showResponseFormSvtAdd(responseText){
  if(typeof(responseText['error'])=='undefined'){
    $("#GridSvt").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 : {
      'svt_buxname' : {required : true},
      'FrmAgreeStructureOrganizationHidden' : {
        required: {
          depends: function(element) {
            if($(":checkbox[id^='FrmAgreeStructureOrganizationCheckboxes']:checked").length){
              return false;
            }
            else{
              return true;
            }
          }
        }
      },
      'FrmAgreeSvtStatusHidden' : {
        required: {
          depends: function(element) {
            if($(":checkbox[id^='FrmAgreeSvtStatusCheckboxes']:checked").length){
              return false;
            }
            else{
              return true;
            }
          }
        }
      },
      'FrmAgreeSvtTypeHidden' : {
        required: {
          depends: function(element) {
            if($(":checkbox[id^='FrmAgreeSvtTypeCheckboxes']:checked").length){
              return false;
            }
            else{
              return true;
            }
          }
        }
      }
    },
    messages: {
      'FrmAgreeStructureOrganizationHidden': {
        required: "Выберите Подразделение"
      },
      'FrmAgreeSvtTypeHidden': {
        required: "Выберите Тип СВТ"
      },
      'FrmAgreeSvtStatusHidden': {
        required: "Выберите Статус"
      }
    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
});
  
$(function(){
  var VarYearE = (new Date).getFullYear()+2;
  $.datepicker.setDefaults($.datepicker.regional['ru']);
  $("#svt_garant_date").datepicker($.extend({yearRange: '2011:'+VarYearE, 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}'}));
    
  var VarYearE = (new Date).getFullYear()+1;
  $("#svt_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}'}));
  if("" == $("#svt_id").val()){
    $("#svt_date").datepicker( "setDate", '0d');
  }  
});
//]]>
</script>
{/literal}

<form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtSave.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}" />
<!--  <input id="FrmAgreeStructureOrganizationCheckboxesRules" name="FrmAgreeStructureOrganizationCheckboxesRules" type="hidden" value="" />-->
<!--  <input id="FrmAgreeSvtStatusCheckboxesRules" name="FrmAgreeSvtStatusCheckboxesRules" type="hidden" value="" />-->
  <table>
    <tr>
      <td><label for="FrmAgreeSvtTypeHidden">Тип СВТ <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='SvtTypeGet();' /><input type="hidden" id="FrmAgreeSvtTypeHidden" name="FrmAgreeSvtTypeHidden" value="" /></td>
      <td id="FormAdvSvtTypeContent">
        {if isset($ArrSvt.svttype_id)}
          <div id="FrmAgreeSvtTypeDivCheckboxes{$ArrSvt.svttype_id}"><input id="FrmAgreeSvtTypeCheckboxes{$ArrSvt.svttype_id}" name="FrmAgreeSvtTypeCheckboxes[]" value="{$ArrSvt.svttype_id}" checked="checked" type="checkbox" /> {$ArrSvt.svttype_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='$("#FrmAgreeSvtTypeDivCheckboxes{$ArrSvt.svttype_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
     <tr>
      <td><label for="FrmAgreeSvtStatusHidden">Статус <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='SvtStatusGet();' /><input type="hidden" id="FrmAgreeSvtStatusHidden" name="FrmAgreeSvtStatusHidden" value="" /></td>
      <td id="FormAdvSvtStatusContent">
        {if isset($ArrSvtStatusVal) && is_array($ArrSvtStatusVal) && 1 <= count($ArrSvtStatusVal)}
          {foreach $ArrSvtStatusVal as $val}
          <div id="FrmAgreeSvtStatusDivCheckboxes{$val.svtstatus_id}"><input id="FrmAgreeSvtStatusCheckboxes{$val.svtstatus_id}" name="FrmAgreeSvtStatusCheckboxes[]" value="{$val.svtstatus_id}" checked="checked" type="checkbox" /> {$val.svtstatus_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='$("#FrmAgreeSvtStatusDivCheckboxes{$val.svtstatus_id}").remove();' /></div>
          {/foreach}
        {/if}
      </td>
    </tr>
    <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="FrmAgreeOrganizHidden">Поставщик :&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='OrganizGet();' /><input type="hidden" id="FrmAgreeOrganizHidden" name="FrmAgreeOrganizHidden" value="" /></td>
      <td id="FormAdvOrganizContent">
        {if isset($ArrSvt.organiz_id)}
          <div id="FrmAgreeOrganizDivCheckboxes{$ArrSvt.organiz_id}"><input id="FrmAgreeOrganizCheckboxes{$ArrSvt.organiz_id}" name="FrmAgreeOrganizCheckboxes[]" value="{$ArrSvt.organiz_id}" checked="checked" type="checkbox" /> {$ArrSvt.organiz_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='$("#FrmAgreeOrganizDivCheckboxes{$ArrSvt.organiz_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
    <tr>
      <td><label for="svt_buxname">Наименование бух. <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="svt_buxname" name="svt_buxname" value="{if isset($ArrSvt.svt_buxname)}{$ArrSvt.svt_buxname}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="svt_name">Наименование сет. :&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="svt_name" name="svt_name" value="{if isset($ArrSvt.svt_name)}{$ArrSvt.svt_name}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="svt_invnum">Инв. номер :&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="svt_invnum" name="svt_invnum" value="{if isset($ArrSvt.svt_invnum)}{$ArrSvt.svt_invnum}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="svt_serialnum">Сер. номер :&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="svt_serialnum" name="svt_serialnum" value="{if isset($ArrSvt.svt_serialnum)}{$ArrSvt.svt_serialnum}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="svt_garant_date">Гарантия до :&nbsp;</label><span></span></td>
      <td colspan="2">
        <input type="text" id="svt_garant_date" name="svt_garant_date" value="{if isset($ArrSvt.svt_garant_date)}{$ArrSvt.svt_garant_date|date_format:'%d.%m.%Y'}{/if}" />
      </td>
    </tr>
    <tr>
      <td><label for="svt_date">Дата приобретения :&nbsp;</label><span></span></td>
      <td colspan="2">
        <input type="text" id="svt_date" name="svt_date" value="{if isset($ArrSvt.svt_date)}{$ArrSvt.svt_date|date_format:'%d.%m.%Y'}{/if}" />
      </td>
    </tr>
    <tr>
      <td><label for="svt_note">Примечание :&nbsp;</label><span></span></td>
      <td colspan="2"><textarea cols="50" rows="2" id="svt_note" name="svt_note">{if isset($ArrSvt.svt_note)}{$ArrSvt.svt_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>