
var ajax_on_flag = function(i18n) {
    new Ajax.Request(
        '/user/language',
        { 
          onComplete:function(request, json) { // function(request, json) {
              if('success' == json.status) {
                  document.location = json.location;
              }
          },
           
          evalScripts:false, 
          parameters: 'i18n='+i18n
        }
    );
}

var on_click_event_on_flag_hun = function() {
  ajax_on_flag('hun');
}

var on_click_event_on_flag_eng = function() {
  ajax_on_flag('eng');
}

/* ----------------------------------------------------------------------- */

Event.observe(window, 'load', function() {
  if ($('flag_hun')) {
      Event.observe($('flag_hun'), 'click', on_click_event_on_flag_hun);
  }

  if ($('flag_eng')) {  
      Event.observe($('flag_eng'), 'click', on_click_event_on_flag_eng);
  }
});
