Package.create("application");
//Class.include("application.contentElement");
//Class.include("ubilabs.map.ContentManager");
//Class.include("ubilabs.map.CreateMode");
//Class.include("ubilabs.tracking.ETracker");
/**
 * Functions for pages in the content layout
 */

application = {

	initialize: function(options) {

    // searchbox
    this.observeSearchBox();

    return this;
  },

  // TODO: move this to a common place for all layouts (map, mixed, content)
  observeSearchBox: function(){
    // intercept the submit event in the search box of the mixed layout and redirect to the main map page
    $('f_geocoding').observe("submit", function(event){
      event.stop();
      var base_url = "http://" + document.location.host + "/#/";
      var what_value = $('geocodingCategory').value;
      var where_value = $('geocodingPlace').value;

      if (what_value) base_url += "what:" + what_value + "/";
      if (where_value) base_url += "where:" + where_value + "/";
      //console.log("observeSearchBox: redirecting to " + base_url);
      document.location.href = base_url;
    });

    $('resetButtonCategory').hide();
    $('resetButtonPlace').hide();

    /* // form reset
    $('resetButtonCategory').observe('click', function(){
      $('geocodingCategory').value = "";
    });

    $('resetButtonPlace').observe('click', function(){
      $('geocodingPlace').value = "";
    }); */

  }
};

document.observe('dom:loaded', application.initialize.bind(application));
document.observe('unload', GUnload);
