////////////////////////////////////////////////////////////////////////////////// manufacturer image
function changeManufacturerImage(imageName, folderName, numberOfImages, delay, picIndex) {
  picIndex = (!picIndex || picIndex >= numberOfImages) ? 1 : picIndex + 1;
  document.images[imageName].src = folderName + '/' + picIndex + '.jpg';
  setTimeout("changeManufacturerImage('" + imageName +"', '" + folderName +"', " + numberOfImages + ", " + delay + ", " + picIndex + ")", delay);
}

function startImages() {
  setTimeout("changeManufacturerImage('a', '/images/search/car', 49, 2500)",2500);
}

function startImages2() {
  setTimeout("changeManufacturerImage('b', '/images/search/manufacturer/brand/new', 4, 2800)",2500);
}

////////////////////////////////////////////////////////////////////////////////// get browser
var agent       = navigator.userAgent.toLowerCase(); 
var isIE        = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
var isNetscape6 = (!document.all && !document.layers && navigator.appName == "Netscape" && parseInt(navigator.appVersion) >=5) ? true : false;
var isMac       = (agent.indexOf("mac") != -1) ? true : false;
var isIE4       = (agent.indexOf("msie") != -1 && agent.indexOf("4.0;") != -1) ? true : false;
var isNetscape  = (agent.indexOf("mozilla") != -1 && agent.indexOf("4.") != -1) ? true : false;
var win2000     = ((agent.indexOf("winnt") != -1) || (agent.indexOf("windows nt 5.0") != -1)) ? true : false; 
var winXP       = ((agent.indexOf("winnt") != -1) || (agent.indexOf("windows nt 5.1") != -1)) ? true : false; 

////////////////////////////////////////////////////////////////////////////////// popup pages
function openWin (url, ref, width, height, scroll) {
  window.open(url, ref, "width=" + width + ",height=" + height + ",toolbar=no,location=no,menubar=no,scrollbars=" + ((scroll) ? 'yes' : 'no') + ",resizable=no");
}

////////////////////////////////////////////////////////////////////////////////// ajax car search 

var ajax = new sack();

function change_manufacturer (drop) {

  var select = document.getElementById('vehicle_model');

  if (drop) {
    select.options.length = 0;
    select.options[0] = new Option('Please wait...','');

    ajax.requestFile  = '/pages/products/ajax/car_models.mhtml?manufacturer=' + drop;
    ajax.onCompletion = function () { load_selection('vehicle_model') };
    ajax.runAJAX();

  } else {
    select.options.length = 0;
    select.options[0] = new Option('Please select...','');

    disable_field('vehicle_model');
  }
}

function change_category (drop) {

  var select = document.getElementById('part_sub_category');

  if (drop) {
    select.options.length = 0;
    select.options[0] = new Option('Please wait...','');

    ajax.requestFile  = '/pages/products/ajax/sub_category_parts.mhtml?category=' + drop;
    ajax.onCompletion = function () { load_selection('part_sub_category') };
    ajax.runAJAX();

  } else {
    select.options.length = 0;
    select.options[0] = new Option('Please select...','');

    disable_field('part_sub_category');
  }
}

function disable_field (id) {
  document.getElementById(id).disabled = true;
}

function load_selection (container) {
  var select = document.getElementById(container);

  select.options.length = 0;
  select.options[0] = new Option('Please select...','');

  eval(ajax.response);
  select.disabled = false;
}

function search_car () {
  var manufacturer = document.getElementById('vehicle_manufacturer').value;
  var model		   = document.getElementById('vehicle_model').value;

  if (manufacturer && model) {
    window.location = '/pages/products/search_car/product.mhtml?car=' + model;
  } else {
    alert('Please select a Manufacturer and Model');
  }
}

function search_part () {
  var category = document.getElementById('part_category').value;
  var part	   = document.getElementById('part_sub_category').value;

  if (category && part) {
    window.location = '/pages/products/category_sub_results.mhtml?category=' + category + ';sub_category=' + part;
  } else {
    alert('Please select a Category and Part');
  }
}

////////////////////////////////////////////////////////////////////////////////// post quikcode 

function quikcode () {
  var id = document.getElementById('quikcode').value;

  if (id) {
    window.location = '/pages/products/product_info.mhtml?product=' + id;
  }
}