{* 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, 'Выбрать подразделение.');
    }
  });
}

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='purchase_name']").css("width","400px");
  $("input[name='purchase_price']").css("width","400px");
  $("input[name='purchase_quantity']").css("width","400px");
  $("#purchase_note").css("width","400px");
  $("#purchase_note").css("height","40px");
});

function showResponseFormPurchaseAdd(responseText){
  if(typeof(responseText['error'])=='undefined'){
    $("#GridPurchase").trigger("reloadGrid");
    $("#PurchaseEditFrm").dialog("destroy");
    DialogStandartMessageOpen("message", responseText['message']);
  }
  else{
    DialogStandartMessageOpen("error", responseText['error']);
  }
}

$(function(){
  var options = {
    success: showResponseFormPurchaseAdd,
    timeout: 3000
  };
  $("#FormPurchaseAdd").validate({
    submitHandler: function(form) {
      $(form).ajaxSubmit(options);
    },
    ignore: "",
    rules : {
      "purchase_name" : {required : true},
      'purchase_price' : {number : true},
      'purchase_quantity' : {number : true}
    },
    errorPlacement: function(error, element) {
      var er = element.attr("name");
      error.appendTo($("label[for='" + er + "']").next() );
    }
  });
});
  
$(function(){
  var VarYearE = (new Date).getFullYear()+10;
  $.datepicker.setDefaults($.datepicker.regional['ru']);
  $("#purchase_datetill").datepicker($.extend({yearRange: '1978:'+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}'}));
});
  
//]]>
</script>
{/literal}

<form action="{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/PurchaseSave.ajax.php" method="post" name="FormPurchaseAdd" id="FormPurchaseAdd">
  <input id="purchase_id" name="purchase_id" type="hidden" value="{if isset($ArrPurchase.purchase_id)}{$ArrPurchase.purchase_id}{/if}" />
  <table>
    <tr>
      <td><label for="purchase_name">Наименование <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="purchase_name" name="purchase_name" value="{if isset($ArrPurchase.purchase_name)}{$ArrPurchase.purchase_name}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="FrmAgreePurchaseStatusCheckboxes[]">Статус :&nbsp;</label><span></span></td>
      <td colspan="2">
        {foreach $ArrPurchaseStatus as $val}
          {if $val@first}
            <select id="FrmAgreePurchaseStatusCheckboxes" name="FrmAgreePurchaseStatusCheckboxes[]">
              <option value="">---выберите статус---</option>
          {/if}
              <option value="{$val.purchasestatus_id}" {if isset($ArrPurchase.purchasestatus_id) && $ArrPurchase.purchasestatus_id eq $val.purchasestatus_id}selected="selected"{/if}>{$val.purchasestatus_name}</option>
          {if $val@last}
            </select>
          {/if}
        {/foreach}
      </td>
    </tr>
    <tr>
      <td><label for="purchase_price">Цена :&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="purchase_price" name="purchase_price" value="{if isset($ArrPurchase.purchase_price)}{$ArrPurchase.purchase_price}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="purchase_quantity">Количество :&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="purchase_quantity" name="purchase_quantity" value="{if isset($ArrPurchase.purchase_quantity)}{$ArrPurchase.purchase_quantity}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="FrmAgreeStructureOrganizationHidden">Подразделение :&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($ArrPurchase.structureorganization_id)}
          <div id="FrmAgreeStructureOrganizationDivCheckboxes{$ArrPurchase.structureorganization_id}"><input id="FrmAgreeStructureOrganizationCheckboxes{$ArrPurchase.structureorganization_id}" name="FrmAgreeStructureOrganizationCheckboxes[]" value="{$ArrPurchase.structureorganization_id}" checked="checked" type="checkbox" /> {$ArrPurchase.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{$ArrPurchase.structureorganization_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
    <tr>
      <td><label for="purchase_datetill">Дата закупки :&nbsp;</label><span></span></td>
      <td colspan="2">
        <input type="text" id="purchase_datetill" name="purchase_datetill" value='{if isset($ArrPurchase.purchase_datetill)}{$ArrPurchase.purchase_datetill|date_format:"%d.%m.%Y"}{/if}' />
      </td>
    </tr>
    <tr>
      <td><label for="purchase_note">Примечание <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2"><textarea cols="50" rows="2" id="purchase_note" name="purchase_note">{if isset($ArrPurchase.purchase_note)}{$ArrPurchase.purchase_note}{/if}</textarea></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>