jQuery(document).ready(function($){

  if (typeof gtag !== 'function') {
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
  }

  console.log('Gtag dataLayer  - I am I want loaded');
  var iAM = 'not set';
  var iWant = 'not set';
  var selection_value = 'https://uct.ac.za/search';

  $('[name="i_am_select"]').on('change', function() {
    iAM = (this.value);
  });

  $('.iWantSelect').on('change', function() {
    iWant = this.options[this.selectedIndex].text;
    selection_value = this.value;
    $('[name="select_choice"]').val(selection_value);
  });
  
  $('.i-am-submit-btn').on('click', function(e){
    e.preventDefault();
    
    if (typeof gtag === 'function') {

      gtag('event', 'I am I want', {
        'i_am': iAM,
        'i_want': iWant,
        'selection_value': selection_value,
        'event_callback': function() {
          window.location = selection_value;
        }
      });

    } else {
      window.location = selection_value;
    }
    
  });
  
});