$(document).ready(function(){
	
  $('#RequesterTeamId').live('change', function() {
    if($(this).val().length != 0) {
	  team = $(this).val();
		
      $.getJSON('/requesters/get_requesters_ajax',{idteam:team}, function(requesters) {
                    if(requesters !== null) {
                      populateTeamsSupervList(requesters);
                    }
        });		
      }
    });	

  $('#submitReqAdd').click(function() {
		//$('#select-superv').removeAttr('disabled'); 
		//$('#select-team').removeAttr('disabled'); 
		$('#select-superv').prop('disabled', false);		
		$('#select-team').prop('disabled', false);
		$('#RequesterAddForm').submit();
  });

  $('#submitReqEdit').click(function() {
		//$('#select-superv').removeAttr('disabled'); 
		$('#select-superv').prop('disabled', false);
		$('#select-team').prop('disabled', false);
		$('#RequesterEditForm').submit();
  });  
 
});


function populateTeamsSupervList(requesters) {
  var options = '';
 
  options += '<option value="">...has no supervisor assigned...</option>'
 
  $.each(requesters, function(index, requester) {
    options += '<option value="' + index + '">' + requester + '</option>';
  });
  $('#select-superv').html(options);
}