function show_price(item) {
  item.style.cursor='pointer';
  item.style.cursor='hand';
  if(document.getElementById('price_field')) {
    document.getElementById('price_field').style.display="inline";
    }
}

function hide_price(item) {
  if(document.getElementById('price_field')) {
    document.getElementById('price_field').style.display="none";
  }
}

function selected(item) {
  item.style.background="#063d75";
  item.style.cursor='pointer';
  item.style.cursor='hand';
}

function deselected(item) {
  item.style.background=" #0d58a2";
}

function clicked(page_id) {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  location.href=baseName + "?page_id=" + page_id;
}

function search_clicked(search_id) {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  location.href=baseName + "?page_id=5&search=" + search_id;
}

function showRoute(page_id){
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location = baseName + "?page_id=" + page_id + "&subpage_id=" + document.routeform.menu.value;
}

function searchPartNr(page_id, search){
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location = baseName + "?page_id=" + page_id + "&search=" + search + "&part_number=" + encodeURIComponent(document.searchform.part_number.value);
}

function searchGearboxCode(page_id, search){
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location = baseName + "?page_id=" + page_id + "&search=" + search + "&gearbox_code=" + encodeURIComponent(document.searchform.gearbox_code.value);
}

function searchMotorCode(page_id, search){
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location = baseName + "?page_id=" + page_id + "&search=" + search + "&motor_code=" + encodeURIComponent(document.searchform.motor_code.value);
}

function searchLagerNr(page_id, search){
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location = baseName + "?page_id=" + page_id + "&search=" + search + "&lager_nr=" + encodeURIComponent(document.searchform.lager_nr.value);
}

function fillManufacturer() {
  /* Initial settings */
  eval('document.cars.manufacturer.options.length = 0;');
  eval('document.cars.type.options.length = 0;');

  eval('document.cars.manufacturer.options[0] = new Option("-- Hersteller selektieren --","");');
  eval('document.cars.type.options[0] = new Option("-- Hersteller selektieren --","");');

  var selectedManufacturer = decodeURIComponent(getget('manufacturer'));

  for(var i = 0; i < herstellerArray.length; i++ ) {
    eval('document.cars.manufacturer.options[i+1] = new Option(herstellerArray[i],herstellerArray[i]);');
    if(herstellerArray[i] == selectedManufacturer) {
      eval('document.cars.manufacturer.options[i+1].selected = true;');
    }
  }
}

function getget(name) {
  var q = document.location.search;
  var i = q.indexOf(name + '=');

  if (i == -1) {
    return false;
  }

  var r = q.substr(i + name.length + 1, q.length - i - name.length - 1);

  i = r.indexOf('&');

  if (i != -1) {
    r = r.substr(0, i);
  }

  return r.replace(/\+/g, ' ');
}

function setType() {
  eval('document.cars.type.options.length = 0');

  var selectedType = decodeURIComponent(getget('type'));

  if(document.cars.manufacturer.value != "") {
    eval('document.cars.type.options[0] = new Option("-- Typ selektieren --","");');

    var tArray = new Array();
    eval("tArray = " + document.cars.manufacturer.value.toLowerCase().replace(/ /gi, "").replace(/-/gi, "") + "Array;");
    for(var i = 0; i < tArray.length; i++ ) {
      eval('document.cars.type.options[i+1] = new Option(tArray[i],tArray[i]);');
      if(tArray[i] == selectedType) {
        eval('document.cars.type.options[i+1].selected = true;');
      }
    }
  } else {
    eval('document.cars.type.options[0] = new Option("-- Hersteller selektieren --","");');
  }
}

function changeSelectManufacturer() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&manufacturer=' + encodeURIComponent(document.cars.manufacturer.value);
}

function changeSelectType() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&manufacturer=' + encodeURIComponent(document.cars.manufacturer.value) + '&type=' + encodeURIComponent(document.cars.type.value);
}

function changeSearchSelection() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&search=' + document.searchform.search.value;
}

function changeManufacturerSelection() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&search=' + document.searchform.search.value + 
  '&manufacturer=' + encodeURIComponent(document.searchform.manufacturer.value);
}

function changeTypeSelection() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&search=' + document.searchform.search.value + 
  '&manufacturer=' + encodeURIComponent(document.searchform.manufacturer.value) + 
  '&type=' + encodeURIComponent(document.searchform.type.value);
}

function changePartSelection() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&search=' + document.searchform.search.value + 
  '&manufacturer=' + encodeURIComponent(document.searchform.manufacturer.value) + 
  '&type=' + encodeURIComponent(document.searchform.type.value) +
  '&part=' + encodeURIComponent(document.searchform.part.value);
}

function changePartSelection2() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&search=' + document.searchform.search.value + 
  '&part_number=' + encodeURIComponent(document.searchform.part_number.value) + 
  '&part=' + encodeURIComponent(document.searchform.part.value);
}

function changePartSelection3() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&search=' + document.searchform.search.value + 
  '&gearbox_code=' + encodeURIComponent(document.searchform.gearbox_code.value) + 
  '&part=' + encodeURIComponent(document.searchform.part.value);
}

function changePartSelection4() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&search=' + document.searchform.search.value + 
  '&motor_code=' + encodeURIComponent(document.searchform.motor_code.value) + 
  '&part=' + encodeURIComponent(document.searchform.part.value);
}

function changePartSelection5() {
  basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/"));
  baseName = window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
  document.location=baseName + '?page_id=' + getget('page_id') + '&search=' + document.searchform.search.value + 
  '&lager_nr=' + encodeURIComponent(document.searchform.lager_nr.value) + 
  '&part=' + encodeURIComponent(document.searchform.part.value);
}

function doLoad() {
  fillManufacturer();
  setType();
}

function setImage(type, nr) {
  if(nr < imagess.length) {
    document.car_image.src="image.php?type=" + type + "&width=400&height=300&image=" + imagess[nr];
  } else {
    document.car_image.src="image.php?type=" + type + "&image=&width=400&height=300";
  }
  current_image=nr;
  if (current_image > 0) {
    document.previous_arrow.style.display="inline";
  } else {
    document.previous_arrow.style.display="none";
  }
  if (current_image != imagess.length - 1 && imagess.length) {
    document.next_arrow.style.display="inline";
  } else {
    document.next_arrow.style.display="none";
  }
 
  // Situaties:
  // Afbeelding 1
  // Afbeelding 2 ... n -1
  // Afbeelding n
  
  if(imagess.length == 0) {
    document.imageone.style.display="none";
    document.getElementById('imageonetext').innerHTML = "&nbsp;";
    document.imagetwo.style.display="none";
    document.getElementById('imagetwotext').innerHTML = "&nbsp;";
    document.imagethree.style.display="none";
    document.getElementById('imagethreetext').innerHTML = "&nbsp;";
  } else if(nr == 0) {
    document.imageone.style.display="none";
    document.getElementById('imageonetext').innerHTML = "&nbsp;";
    
    document.imagetwo.style.display="inline";
    document.imagetwo.src="image.php?type=" + type + "&width=100&height=75&image=" + imagess[nr];
    document.getElementById('imagetwotext').innerHTML = (nr + 1) + "/" + (imagess.length);
    
    if(nr < imagess.length - 1) {
      document.imagethree.style.display="inline";
      document.imagethree.src="image.php?type=" + type + "&width=100&height=75&image=" + imagess[nr + 1];
      document.getElementById('imagethreetext').innerHTML = (nr + 2) + "/" + (imagess.length);
    } else {
      document.imagethree.style.display="none";
      document.getElementById('imagethreetext').innerHTML = "&nbsp;";
    }
    
    
    
  } else if(nr > 0 && nr < imagess.length - 1) {
    document.imageone.style.display="inline";
    document.imageone.src="image.php?type=" + type + "&width=100&height=75&image=" + imagess[nr - 1];
    document.getElementById('imageonetext').innerHTML = (nr) + "/" + (imagess.length);
    document.imagetwo.style.display="inline";
    document.imagetwo.src="image.php?type=" + type + "&width=100&height=75&image=" + imagess[nr];
    document.getElementById('imagetwotext').innerHTML = (nr + 1) + "/" + (imagess.length);
    document.imagethree.style.display="inline";
    document.imagethree.src="image.php?type=" + type + "&width=100&height=75&image=" + imagess[nr + 1];
    document.getElementById('imagethreetext').innerHTML = (nr + 2) + "/" + (imagess.length);
    
    
  } else if(nr == imagess.length - 1) {
    document.imagethree.style.display="none";
    document.getElementById('imagethreetext').innerHTML = "&nbsp;";
    document.imagetwo.style.display="inline";
    document.imagetwo.src="image.php?type=" + type + "&width=100&height=75&image=" + imagess[nr];
    document.getElementById('imagetwotext').innerHTML = (nr + 1) + "/" + (imagess.length);
    
    if(imagess.length > 1) {
          document.imageone.style.display="inline";
          document.imageone.src="image.php?type=" + type + "&width=100&height=75&image=" + imagess[nr - 1];
          document.getElementById('imageonetext').innerHTML = (nr) + "/" + (imagess.length);
        } else {
          document.imageone.style.display="none";
          document.getElementById('imageonetext').innerHTML = "&nbsp;";
    }
  }
}

