<div class="settings_common_container">

	<div class="settings_common_header">
		
		<%= link_to 'Отмена', settings_users_path, class:"href_delete_button", style:"float:left" %>
		<div class="settings_common_header_text"><%= t('.create_user')%></div>
	</div>
	
	<div class="settings_common_table_container" style="padding-top:10px">
		
		<%= form_for :user, url: settings_users_path do |f| %>
		<table class="table_body">
			
  		  	<tr>
     		   	<td align="right"><%= f.label "#{t('.user_name')}:" %></td>
   				<td><%= f.text_field :username, :onchange => "check_user_name()", :class => "text_field_relative" %></td>
  		  	</tr>
  		  	<tr id="update_user_wrong_name" style="display:none">
   			 	<td colspan="2" align="center" style="color:<%= $red %>"><%= t('.user_exist')%></td>
  		  	</tr>
  		  	<tr>
				<td align="right"><%= f.label "#{t('.group')}:" %></td>
  				<td><%= f.select "user_group_id", UserGroup.all.collect {|p| [ p.name_rus, p.id ] } %></td>
  		  	</tr>
 		   	<tr>
     		   	<td align="right"><%= f.label "#{t('.new_pass')}:" %></td>
     		   	<td><%= f.password_field :new_password, :onchange => 'check_passwords()', :onkeyup => 'check_passwords()', :class => "text_field_relative" %></td>
  		 	</tr>
  		  	<tr>
    			<td align="right"><%= f.label "#{t('.retype_pass')}:" %></td>
    			<td><%= f.password_field :re_password, :onchange => 'check_passwords()', :onkeyup => 'check_passwords()', :class => "text_field_relative" %></td>
  		  	</tr>
  		  	<tr id="update_user_confirm_button" style="display:none">
   			 	<td colspan="2" align="center"><%= f.submit t(:create) %></td>
  		  	</tr>
  		  	<tr id="update_user_confirm_error" style="display:none">
   			 	<td colspan="2" align="center" style="color:<%= $red %>"><%= t('.pass_no_match')%></td>
  		  	</tr>
			
		</table>
		<% end %>
	</div>
</div>
<script>
var check_name=0
function check_passwords(){
	pass=document.getElementById('user_new_password').value
	re_pass=document.getElementById('user_re_password').value
	if (pass == re_pass && check_name > 0 && pass.length > 0 ){
		document.getElementById('update_user_confirm_button').style.display=''
	}else{
		document.getElementById('update_user_confirm_button').style.display='none'
	}
	document.getElementById('update_user_confirm_error').style.display= pass == re_pass ? 'none' : ''
	document.getElementById('update_user_wrong_name').style.display= check_name > 0 ? 'none' : ''
}
function check_user_name(){
	user_name=document.getElementById('user_username').value
	$.get('/settings/users/check_username',{name: user_name}, function(result){
		if (result == 1 && user_name.length > 0){
			check_name=1
		}
		check_passwords()
	})
}
</script>