_docparams_ = "";
try { var floating = undefined; }
catch(e) { var floating = null; }
var floating_officialtop = 220;
var floating_topoffset = 110;
var floating_bottomoffset = -140;
var num_vehicles = 0;
var debug = true;

function validate_pricerange_p1(f) {
  if(f.price2.selectedIndex > 1 && f.price2.selectedIndex <= f.price1.selectedIndex) {
    f.price2.selectedIndex = f.price1.selectedIndex + 1;
  }
}

function validate_pricerange_p2(f) {
  if(f.price2.selectedIndex > 1 && f.price1.selectedIndex > 1 && f.price1.selectedIndex >= f.price2.selectedIndex) {
    f.price1.selectedIndex = f.price2.selectedIndex - 1;
  }
}

function validate_leasing_p1(f) {
  if(f.payment2.selectedIndex > 1 && f.payment2.selectedIndex <= f.payment1.selectedIndex && f.payment2.selectedIndex != f.payment2.options.length -1) {
    f.payment2.selectedIndex = f.payment1.selectedIndex + 1;
  }
}

function validate_leasing_p2(f) {
  if(f.payment2.selectedIndex > 1 && f.payment1.selectedIndex >= f.payment2.selectedIndex) {
    f.payment1.selectedIndex = f.payment2.selectedIndex - 1;
  }
}

function openGMOptimum() {
  window.open("gm-opt.spy","GMOPT","directories=0,menubar=0,status=1,location=0,scrollbars=1,width=500,height=500");
  return false;
}

function openSaturn() {
  window.open("saturn-opt.spy","SaturnOPT","directories=0,menubar=0,status=1,location=0,scrollbars=1,width=500,height=500");
  return false;
}

function openSaab() {
  window.open("saab-opt.spy","SaabOPT","directories=0,menubar=0,status=1,location=0,scrollbars=1,width=500,height=500");
  return false;
}

function moveFloating() {
  if(isNaN(window.pageYOffset)) {
    floating_topoffset = (document.body.scrollTop > floating_officialtop) ? 2 : 110 - (document.body.scrollTop / 2);
  }
  else {
    floating_topoffset = (window.pageYOffset > floating_officialtop) ? 2 : 110 - (window.pageYOffset / 2);
  }
  if(isNaN(floating_topoffset)) floating_topoffset = 2;

  var scroll_ypos = window.pageYOffset || document.body.scrollTop;
  var float_ypos = parseInt(Element.getStyle(floating, 'top') || 0);
  if(isNaN(float_ypos)) float_ypos = 0;

  if(floating_topoffset == undefined) {
    floating_topoffset = float_ypos;
  }

  if(scroll_ypos != float_ypos) {
    var distance = Math.abs(scroll_ypos - float_ypos);
    var step     = Math.max(1, distance / 1.0);

    if(scroll_ypos < float_ypos) {
      float_ypos -= step;
    }
    else {
      float_ypos += step;
    }

    var float_height = parseInt(Element.getStyle(floating, "height"));
    var lower_limit  = $('floatend').offsetTop;
    var upper_limit  = $('floatbegin').offsetTop + $('floatbegin').offsetHeight;

    if(isNaN(float_height)) float_height = 400;
    if(isNaN(upper_limit)) upper_limit = 0;
    if(isNaN(lower_limit)) lower_limit = 0;

    float_ypos = Math.max(float_ypos + floating_topoffset, upper_limit + floating_topoffset);
    float_ypos = Math.min(float_ypos + floating_topoffset, lower_limit - float_height - floating_bottomoffset);

    Element.setStyle(floating, {top:(float_ypos) + "px"});
  }

  window.setTimeout(moveFloating, 20);
}

function init(pageparams) {
  var browserSupported = true;
  var sAgent = navigator.userAgent.toLowerCase();
  IsIE = sAgent.indexOf("msie") != -1;
  if(IsIE) {
    majVer = navigator.appVersion.match(/MSIE (.)/)[1];
    minVer = navigator.appVersion.match(/MSIE .\.(.)/)[1];
    if(majVer < 6) {
      browserSupported = false;

      // Define a bugus Effect object
      Effect = new Object();
      Effect.Fade = function(id, params) {}
      Effect.Appear = function(id, params) {}
    }
  }

  _docparams_ = pageparams;
  floating = $e("floatingbar");
  if(floating != null) {
    if(browserSupported) {
      window.setTimeout(moveFloating, 100);
    }
    else {
      floating.style.top = 226;
      floating.style.height = 360;
    }
    floating.style.display = "block";
  }

  updateFloater(null);
}

function _checkLS(){return (_ls_==1)?true:false;}

function details_switchTab(tabid) 
{
  var tabRoot = "detailstab";
  var imgRoot = "detailstabimg";
  var d = {};
  var activate = false;

  tabid = parseInt(tabid);
  
  jQuery(".menu-tab-ajax .selected").removeClass("selected");
  for(var i = 1; i <= 6; i++)
  {
    if(i == tabid)
    {
      activate = true;
    }
     
    d[i] = [XLib.getElement(tabRoot + i), XLib.getElement(imgRoot + i)];
    if(d[i][0].style.display != 'none') 
    {
      d[i][0].style.display = 'none';
    }
  }

  if(activate) 
  {
    d[tabid][0].style.display = "block";
    jQuery("#menu-" + tabid).addClass("selected");
  }
  return false;
}


function details_switchTab2(tabid) {
  var tabRoot = "detailinfotab";
  var d = {};
  var activate = false;

  tabid = parseInt(tabid);
  for(var i = 1; i <= 6; i++) {
    if(i == tabid) activate = true;
    d[i] = XLib.getElement(tabRoot + i);
    if(d[i].style.display != 'none') {
      d[i].style.display = 'none';
    }
  }
  if(activate) {
    d[tabid].style.display = "block";
  }
  return false;
}

function ucclassifieds_model_openCloseSection(position, num) {
  var o = document.getElementById("ucoverview" + position.toString());
  var shown = false;
  
  if(o != null) {
    for(var i=0; i < num; i++) {
      var idname = "ucmodel" + position.toString() + "_" + (i + 1).toString();
      var b = document.getElementById(idname);
      if(b != null) {
        if(i == 0) {
          shown = (b.style.display == 'none') ? false : true;
          o.innerHTML = shown ? "+" : "-";
        }
        b.style.display = shown ? "none" : "";
      }
    }
  }
  return false;
}

function used_search_details_tabContent(tabnum, url, ignoreLoaded, showWaiting) 
{
  var tabRoot = "detailstab" + tabnum.toString();
  var tab = document.getElementById(tabRoot);
  
  if(tab != null) 
  {
    var a = tab.getAttribute("loaded");
    if ((ignoreLoaded) || (a == null || a != "1")) 
    {
      var ee = document.getElementById(showWaiting);
      if(ee != null) ee.className = "wait-icon";
      
      YAHOO.util.Connect.resetFormState();
      var callback = {
        success: used_search_details_tabContent_success,
        failure: used_search_details_tabContent_failure,
        argument: [tab]
      };
      var c = YAHOO.util.Connect.asyncRequest("GET", url, callback, null);
    }
  }
  return false;
}

function used_search_details_tabContent_success(o) {
  var tab = o.argument[0];
  tab.innerHTML = o.responseText;
  tab.setAttribute("loaded", "1");
}

function used_results_compare() {
  var o = document.getElementById("comparelink");
  if(o != null) {
    if(typeof(o.href) != "undefined" && o.href != "") {
      window.location.href = o.href;
    }
  }
  return false;
}


