var ajax;

// Tab Switcher

function select_tab(section,tab) {
  if (tab == active_tab[section]) return false;
  active_tab[section] = tab;
  for (var i in tabs[section]) {
    if (typeof tabs[section][i] != "string" || tabs[section][i]  == tab)  continue;
    roll_tab(section,tabs[section][i],"inactive");
  }

  document.getElementById('tab_'+section+'_'+tab).src = "/_stat/tabs/"+section+"/"+tab+"_active.png";
  return false;
}

function roll_tab(section,tab,what) {
  if (tab == active_tab[section]) return;
  document.getElementById('tab_'+section+'_'+tab).src = "/_stat/tabs/"+section+"/"+tab+"_"+what+".png";
  return false;
}

function get_bts_content(which) {
  document.getElementById('bts_about_im').src = "/images/bts/"+which+".jpg";

  ajax = new sack();
  ajax.requestFile  = '/_ajax/get_bts_content.php?which='+which;
  ajax.onCompletion = function() {
                        if (ajax.response) {
                          document.getElementById('bts_content').innerHTML = ajax.response;
                          select_tab("home",which);
                        }
                      }
  ajax.runAJAX();
}

function preload_images() {
  if (!document.images) return false;
  document.preload = new Array();
  j = 0;
  for (var i in preloadImages) {
    if (typeof preloadImages[i] != "string") continue;
    document.preload[j]      = new Image;
    document.preload[j].src  = preloadImages[i];
    j++;
  }
}

function toggle_contact_box() {
  if (cbox) {
    document.getElementById('popup_contact').style.display = 'none';
    document.getElementById('popup_contact_hack').style.display = 'none';
  } else {
    document.getElementById('popup_contact').style.display = 'inline';
    document.getElementById('popup_contact_hack').style.display = 'inline';
  }
  cbox = !cbox;
}

function toggle_eaf() {
  document.getElementById('sb_eaf').style.display = (eaf) ? 'none' : 'inline';
  eaf = !eaf
}


function send_popup_enquiry() {
  with (document.forms.popup_contact_form) {
    ajax = new sack();

    ajax.setVar('name',name.value);
    ajax.setVar('email',email.value);
    ajax.setVar('telephone',telephone.value);
    ajax.setVar('comments',comments.value);
    ajax.setVar('publish',publish.value);
    ajax.setVar('spam',(document.getElementById('spam').checked)?1:0);
    ajax.setVar('FORM_NAME','popup_contact');

    ajax.requestFile  = '/_ajax/_send_popup_contact.php';
    ajax.onCompletion = function() {
                          if (ajax.response) eval(ajax.response);
                        }
    ajax.runAJAX();
  }
}

function send_eaf(sec,sbid) {
  with (document.forms.eaf_form) {
    ajax = new sack();

    ajax.setVar('eaf_y_name',     eaf_y_name.value);
    ajax.setVar('eaf_y_email',     eaf_y_email.value);
    ajax.setVar('eaf_f_name',     eaf_f_name.value);
    ajax.setVar('eaf_f_email',    eaf_f_email.value);
    ajax.setVar('eaf_p_message',  eaf_p_message.value);
    ajax.setVar('FORM_NAME',      'eaf_form');

    ajax.requestFile  = '/_ajax/_send_eaf_form.php?id='+sbid+'&section='+sec;
    ajax.onCompletion = function() {
                          if (ajax.response) eval(ajax.response);
                        }
    ajax.runAJAX();
  }
}

function get_rev_about(whichbox,r_id) {
  ajax = new sack();
  ajax.requestFile  = "/_ajax/getreviewboxcontent.php";
  ajax.onCompletion = function() {
                          if (ajax.response) {
                            document.getElementById('rev_about').innerHTML = ajax.response;
                            roll_tab("reviews",whichbox,'active');
                            var foo = active_tab.reviews;
                            active_tab.reviews = whichbox;
                            roll_tab("reviews",foo,'inactive');
                            if (whichbox == 'photo_gal')  initLightbox();
                          }
                        }
  ajax.setVar('show',whichbox);
  ajax.setVar('r_id',r_id);
  ajax.runAJAX();
}

function get_model(modval,orig) {
  if (typeof orig == 'undefined') orig = 'rev';
  ajax = new sack();
  ajax.requestFile  = "/_ajax/get_models.php?make="+modval+"&orig="+orig;
  ajax.onCompletion = function() {
                        if (!ajax.response) return;
                        eval(ajax.response);
                      }
  ajax.runAJAX();
}

function adsCT(adid,logid) {
  ajax = new sack();
  ajax.requestFile  = "/out.php?aid="+adid+"&lid="+logid+"&redirect=0";
  ajax.onCompletion = function() {
                      }
  ajax.runAJAX();
}

function sb(dowhat,link,title) {
  link  = "http://"+link;
  switch (dowhat) {
    case 'favourites' :
      if (window.sidebar)       return window.sidebar.addPanel(title,link,'');
      else if (window.external) return window.external.AddFavorite(link,title);
      else                      return false;
      break;

  }
}

function  scroll_to(what) {
  window.scrollTo(0,100000);
}
