var LocaleSelector = {
  bind:function(id) {
    
      var dd = document.getElementById(id);
      
      if (dd == null) return;
      if (typeof dd == 'undefined') return;
      
      dd.onchange = function() {

        LocaleSelector.switchLocale(this);
        
      }

     
  },
  switchLocale:function(opt) {
    var type = 'T';
    if (opt.options[opt.selectedIndex].value == 'en_US') {
      type = 'F';
    } 
    
    if (opt.options[opt.selectedIndex].value.indexOf('/landing/') > -1) {
      document.location.replace(PageVars.path_to_top + opt.options[opt.selectedIndex].value);
      return; 
    }
      
    if (typeof CoreSiteVars != 'undefined' && CoreSiteVars.cmscontext == 'staging') {
        url = window.location.replace(CoreSiteVars.adminTool + '?action=UA-update-user&uid=' + SiteVars.user.uid + '&cmfcurrentLocale=' +  opt.options[opt.selectedIndex].value + '&refreshURL=' + SiteVars.sitePrefix + CoreSiteVars.this_url + '&cmfcurrentLocaleType=' + type);
    } else {
      
       url = window.location.replace('/' + opt.options[opt.selectedIndex].value + PageVars.this_url);   
    }
  }
}

function switchLocale(locale){
    var type = 'T';
    if (locale == 'en_US') {
      type = 'F';
    } 

     if (typeof CoreSiteVars != 'undefined' && CoreSiteVars.cmscontext == 'staging') {
        url = window.location.replace(CoreSiteVars.adminTool + '?action=UA-update-user&uid=' + SiteVars.user.uid + '&cmfcurrentLocale=' +  locale + '&refreshURL=' + SiteVars.sitePrefix + CoreSiteVars.this_url + '&cmfcurrentLocaleType=' + type);
    } else {
      // url = window.location.replace('/' + locale + PageVars.this_url);
      
      // lets always send them to the homepage when they switch locales
      
       url = window.location.replace('/' + locale + '/' );
    }
  }
  
  
window.onload = function() {
  /* set rounded corners */
  DD_roundies.addRule('.box-form, .request-info, .standardform, #icon-bar', '6px', true);

   
/*
  
  if (document.getElementById('nav') == null) return;
  if (typeof document.getElementById('nav') != 'undefined') {
    sfHover();
  }
    */
  LocaleSelector.bind('locale-selector');
  
  // we may need to force the locale
  
};
