var preload = new Image();

function call_sel() {
  if (hold == true) return;
  var url = "/web/sel/" + region + "/" + supercat + "/" + subcat + "/reg/" + tv
  Element.show($('main_loader'));
}

function change_supercat(new_supercat) {
  if (supercat != new_supercat) {
    old_supercat = supercat;
    supercat = new_supercat;
    call_sel();
  }
}

function change_subcat(new_subcat) {
  if (subcat != new_subcat) {
    subcat = new_subcat;
    call_sel();
  }
}

function change_region(new_region) {
  if (region != new_region) {
    region = new_region;
    call_sel();
  }
}

function change_region_bf(new_region) {
  region = new_region;
  var _bf_supcat = (bf_supcat)?bf_supcat:'-1'
 
  if (hold==true) return;
  var url = "/web/sel/" + region + "/" + _bf_supcat + "/0/bus/" + tv
  Element.show($('main_loader'));
}




function start_timer() {
  clearTimeout(timerID);
  timerID  = setTimeout("menu_timeout_close()", 327);
}
function stop_timer() {
  clearTimeout(timerID);
}

function sro(name,off,on) {
  onImg[name]= on;
  offImg[name]= off;
  preload.src = on;
  preload.src = off;
}

function img_mouseover(name) {
 $(name).src = onImg[name];
}

function img_mouseout(name) {
  if ((name == supercat)||(name == ("sub_"+subcat))||(name == tv)||(name == region)||(name == contact)||(name == ("bf_"+bf_supcat))) return;
  $(name).src = offImg[name];
}


function on_tv_over(n) {
  var ns = "-" + $(n+"_tv_chooser").getStyle('width') + " center";
  $(n+"_tv_chooser").style.backgroundPosition = ns;
}
function on_tv_out(n) {
  if ( n != tv) {
    $(n+"_tv_chooser").style.backgroundPosition = '0 center';
  }
}


function on_tv(n,callr) {
  
  Element.hide($("tv_survey_details_outer"));
  
  var r = document.getElementsByClassName('bthvn');
  stv = "/" + tv + "/"
  ntv = "/" + n + "/"
  for (var i=0;i<r.length;i++) {
    el = r[i];
    if (el != callr) {
      link = r[i].href
      r[i].href = link.replace(stv,ntv);
    }
  }
  
  
  //$(tv).src = offImg[tv];
  $(tv+"_left").style.backgroundImage = "url('/images/tv_inactive_bg.gif')";
  // alert('Hey!')
  Element.setStyle($(tv+"_tv_chooser"),{backgroundPosition:'0 center'});
  Element.hide($("tv_"+tv+"_outer"));
  tv = n;
  
  var ns = "-" + $(tv+"_tv_chooser").getStyle('width') + " center";
  $(tv+"_tv_chooser").style.backgroundPosition = ns;
  
  $(tv+"_left").style.backgroundImage = "url('/images/tv_active_bg.gif')";
  Element.show($("tv_"+tv+"_outer"));
}

function surveys_loading() {
  Element.hide($('tv_comp_surveys_outer')); 
  Element.show('survey_loading');
}

function on_footnote(w) {
  close_submenu(supercat);
  hold=true;  change_supercat('footnotes');
  hold=false; change_subcat(w);
}

function chart_details(num) {
  
  Element.hide($("tv_comp_surveys_outer"));
  $("survey_details_desc").update(survey_details[num]);
  $("survey_details_name").update(survey_names[num]);
  var el = $("tv_survey_details_outer");
  Element.show(el);
//  CSBfleXcroll('survey_details_desc');
}

function survey_rtn() {
  Element.hide($("tv_survey_details_outer"));
  Element.show($("tv_comp_surveys_outer"));
}

