// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire == undefined) {
			daysToExpire=1000;
	  }
    var d = new Date();
    d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
    expire = '; expires=' + d.toGMTString();

    path = '; path=/';
    return (document.cookie = escape(name) + '=' + escape(value || '')+ path  + expire);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};

function default_filter_by_season(table_dom_id, field_id)
{
	Element.observe(window, 'load', function() {
	var default_value = Cookie.get('selected_season');
	if (default_value)
	{
		options = $(field_id).options;
		for (i = 0; i < options.length; i++) {
			var option = options[i];
			if (option.value == default_value) {
				option.selected = true;
				filter_by_season(table_dom_id, option.value);
			}
		}
	}
	});
}


function filter_by_season(table_dom_id, season_id)
{
	Cookie.set('selected_season', season_id);
	var all_rows = $$('#' + table_dom_id + ' tbody tr');
	var season_rows = $$('.season_' + season_id);
	if (season_id == 0) { season_rows = all_rows; }
		
	Element.hide('no_rows_msg');
	if (season_rows.size() == 0) { Element.show('no_rows_msg');	}
	
	all_rows.invoke('hide');
	season_rows.invoke('show');
}
