
var ProjectSearchController = Class.create({
  
  initialize:function()
  {
    $('project_search_form').observe('submit', this.searchFormSubmit.bind(this));
  },
  
  searchFormSubmit:function(event)
  {
    // kill the regular event
    event.stop();
    
    // create url to go to
    var url = $('project_search_form').getAttribute('action');
    
    // add region?
    if ($('region_field').getValue()) {
      url += '/' + $('region_field').getValue();
    }
    
    // add industry?
    if ($('industry_field').getValue()) {
      url += '/' + $('industry_field').getValue();
    }
    
    // send browser to search results
    var baseUrl = $('baseTag').getAttribute('href');
    
    document.location = baseUrl + url;
  }
  
});

document.observe('dom:loaded', function() {
  new ProjectSearchController();
});

