
// ajax functions ###############################################################################################/

var ajax = new sack();

function change_panel_car_category (drop) {
  var select = document.getElementById('car_search_manufacturer');
  if (drop) {
    select.options.length = 0;
    select.options[0] = new Option('Please wait...','');

    ajax.requestFile  = '/components/ajax/car_manufacturers.html?category=' + drop;
    ajax.onCompletion = function () {load_data('car_search_manufacturer')};
    ajax.runAJAX();

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

function change_panel_brand_category (drop) {
  var select = document.getElementById('brand_search_brand');
  if (drop) {
    select.options.length = 0;
    select.options[0] = new Option('Please wait...','');

    ajax.requestFile  = '/components/ajax/product_manufacturers.html?category=' + drop;
    ajax.onCompletion = function () {load_data('brand_search_brand')};
    ajax.runAJAX();

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

function change_panel_manufacturer (drop) {
  if (drop == 'universal') {
    search_car_panel();
  }
  var category = document.getElementById('car_search_category').value;

  var select = document.getElementById('car_search_model');
  if (drop && category) {
    select.options.length = 0;
    select.options[0] = new Option('Please wait...','');

    ajax.requestFile  = '/components/ajax/car_models.html?manufacturer=' + drop + ';category=' + category;
    ajax.onCompletion = function () {load_data('car_search_model')};
    ajax.runAJAX();

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

function change_model (drop) {
  if (drop) {
  }
}

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

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

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

// panel searchs #################################################################################################/

function search_category_panel () {
  var category = document.getElementById('panel_category').value;
  if (category == 'tyres') {
	window.location = '/pages/products/tyres.html?category=' + category;
  } else if (category) {
	window.location = '/pages/products/?category=' + category;
  }
}

function search_car_panel () {
  var category	   = document.getElementById('car_search_category').value;
  var manufacturer = document.getElementById('car_search_manufacturer').value;
  var model		   = document.getElementById('car_search_model').value;

  if (category) {
	if (model) {
      window.location = '/pages/products/product_car.html?category=' + category + ';model=' + model;
	} else if (manufacturer == 'universal') {
      window.location = '/pages/products/product_list.html?category=' + category;
	} else {
      alert('Please select a model');
	}
  } else {
	alert('Please select a category');
  }
}

function search_brand_panel () {
  var category = document.getElementById('brand_search_category').value;
  var brand = document.getElementById('brand_search_brand').value;
  if (category && brand) {
    window.location = '/pages/products/product_car.html?category=' + category + ';manufacturer=' + brand;
  } else {
	alert('Please select a category and a brand');
  }
}

// popup functions ###############################################################################################/
function open_popup (ref, url, width, height, scroll, menu, toolbar, location, status, resizable, titlebar) {
  window.open(url,
              ref,
              "toolbar=no, location=no, menubar=" + ((menu) ? 'yes' : 'no')  + ", " +
              "scrollbars=" + ((scroll) ? 'yes' : 'no')  + ", " +
              "toolbar=" + ((toolbar) ? 'yes' : 'no')  + ", " +
              "status=" + ((status) ? 'yes' : 'no')  + ", " +
              "location=" + ((location) ? 'yes' : 'no')  + ", " +
              "resizable=" + ((resizable) ? 'yes' : 'no')  + ", " +
		      "titlebar=" + ((titlebar) ? 'yes' : 'no') + ", " +
              "width=" + width + ", height=" + height
             );
}

// add to favourites #############################################################################################/
function bookmark () {
  var uri  = 'http://www.rimstyle.com';
  var text = 'Rimstyle.com | Styling and Tuning Specialists';

  if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(text, uri, '');
	} else if (window.external) { // IE Favorite
		window.external.AddFavorite(uri, text);
  }
}