{* 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() {
  $("input[name='ip_name']").css("width","400px");
});

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

$(function(){
  var options = {
    success: showResponseFormIpAdd,
    timeout: 3000
  };
  $("#FormIpAdd").validate({
    submitHandler: function(form) {
      $(form).ajaxSubmit(options);
    },
    ignore: "",
    rules : {
      "ip_name" : {
        required : true,
        remote: {
          url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/IpIsset.ajax.php{literal}",
          type: "get",
          data: {
            ip_name: function() {
              return $("#ip_name").val();
            },
            ip_id: function() {
              return $("#ip_id").val();
            }
          }
        }
      }
    },
    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/IpSave.ajax.php" method="post" name="FormIpAdd" id="FormIpAdd">
  <input id="ip_id" name="ip_id" type="hidden" value="{if isset($ArrIp.ip_id)}{$ArrIp.ip_id}{/if}" />
  <table>
    <tr>
      <td><label for="ip_name">Адрес <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="ip_name" name="ip_name" value="{if isset($ArrIp.ip_name)}{$ArrIp.ip_name}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="FrmSvtHidden">СВТ :&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="FrmSvtHidden" name="FrmSvtHidden" value="" /></td>
      <td id="FormAdvSvtContent">
        {if isset($ArrIp.svt_id)}
          <div id="FrmAgreeSvtDivCheckboxes{$ArrIp.svt_id}"><input id="FrmAgreeSvtCheckboxes{$ArrIp.svt_id}" name="FrmAgreeSvtCheckboxes[]" value="{$ArrIp.svt_id}" checked="checked" type="checkbox" /> {if $ArrIp.svt_name}({$ArrIp.svt_name}) {/if}{$ArrIp.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{$ArrIp.svt_id}").remove();' /></div>
        {/if}
      </td>
    </tr>
    <tr>
      <td><label for="ip_note">Примечание :&nbsp;</label><span></span></td>
      <td colspan="2"><textarea cols="50" rows="2" id="ip_note" name="ip_note">{if isset($ArrIp.ip_note)}{$ArrIp.ip_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>