{* Smarty *}

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

$(function() {
  AltButtons();
});

function GeneratePass(){
  var chars="qazxswedcvfrtgbnhyujmkp123456789QAZXSWEDCVFRTGBNHYUJMKP";
  var max = 10;
  var size = chars.length-1;
  var password="";
  while (max--){
	 password = password+chars[Math.floor(Math.random() * (size + 1))];
	}
  $("#pass_pass")[0].value=password; 
}

$(function() {
  $("input[name='pass_name']").css("width","400px");
  $("input[name='pass_login']").css("width","400px");
  $("input[name='pass_pass']").css("width","400px");
  $("textarea").css("width","400px");
  $("textarea").css("height","40px");
});

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

$(function(){
  var options = {
    success: showResponseFormPassAdd,
    timeout: 3000
  };
  $("#FormPassAdd").validate({
    submitHandler: function(form) {
      $(form).ajaxSubmit(options);
    },
    ignore: "",
    rules : {
      "pass_name" : {required : true},
      "pass_login" : {required : true},
      "pass_pass" : {required : true}
    },
    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/PassSave.ajax.php" method="post" name="FormPassAdd" id="FormPassAdd">
  <input id="pass_id" name="pass_id" type="hidden" value="{if isset($ArrPass.pass_id)}{$ArrPass.pass_id}{/if}" />
  <table>
    <tr>
      <td><label for="pass_name">Наименование <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="pass_name" name="pass_name" value="{if isset($ArrPass.pass_name)}{$ArrPass.pass_name}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="pass_login">Имя пользователя <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td colspan="2"><input type="text" id="pass_login" name="pass_login" value="{if isset($ArrPass.pass_login)}{$ArrPass.pass_login}{/if}" /></td>
    </tr>
    <tr>
      <td><label for="pass_pass">Пароль <span class="ui-state-error">* </span>:&nbsp;</label><span></span></td>
      <td><input type="text" id="pass_pass" name="pass_pass" value="{if isset($ArrPass.pass_pass)}{$ArrPass.pass_pass}{/if}" /></td>
      <td><span class="AltButtons" onclick="javascript: GeneratePass()" style="text-align:left;" title="Генерировать пароль"><span class="ui-icon ui-icon-key"></span></span></td>
    </tr>
    <tr>
      <td><label for="pass_note">Примечание :&nbsp;</label><span></span></td>
      <td colspan="2"><textarea cols="50" rows="2" id="pass_note" name="pass_note">{if isset($ArrPass.pass_note)}{$ArrPass.pass_note}{/if}</textarea></td>
    </tr>
    <tr>
      <td><label for="pass_share">Приватный :&nbsp;</label><span></span></td>
      <td colspan="2"><input type="checkbox" id="pass_share" name="pass_share" value="1" {if isset($ArrPass.pass_share) && 1 == $ArrPass.pass_share}checked{/if} /></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>