function toProfiSearch() {
  document.car.show.value = 0;
  document.car.profi.value = 1;
  document.car.submit();
}
function doQuickSearch() {
  document.car.show.value = 1;
  document.car.profi.value = 0;
}

/////////////////////////////////

function init(mode) {
  if(no_ctype==0) { showOpt(CTYPE, 'CONSTRUCTIONTYPE', val_ctype); }
  optCType();
  
  if(val_stype>0) { 
    optProd(); 
    optCateg();
  } else { 
    document.car.PRODUCER.options[0] = new Option("---", 0, false, true);
    //document.car.CATEGORY.options[0] = new Option("---", 0, false, true);
  }
  if(val_prod>0) { optType(); } else { document.car.TYPE.options[0] = new Option("---", 0, false, true); }
}

function delOpt(name) {
  var len = eval('document.car.'+name+'.length;');
  for (i=0;i<len;i++){
    eval('document.car.'+name+'.options[document.car.'+name+'.length-1] = null;');
  }
}

function showOpt(arr, name, selected) {
  var index = 0;
  for(var i in arr) {
    eval('document.car.'+name+'.options[document.car.'+name+'.length] = new Option(arr[i], i, false, true);');
    if(i==selected) { index = eval('document.car.'+name+'.length - 1;'); }
  }
  eval('document.car.'+name+'.options['+index+'].selected = true;');
}

function changeSType(stype) {
  val_stype = stype;
  val_prod = 0;
  val_type = 0;
  optProd();
  optType();
  optCType();
  optCateg();
}

function changeProd(prod) {
  val_prod = prod;
  val_type = 0;
  optType();
}

function optProd() {  
  delOpt('PRODUCER');
  var index = 0;
  if(val_stype > 0) {
    eval('var ARR = PROD_'+val_stype+';');
    for(var i in ARR) {
      document.car.PRODUCER.options[document.car.PRODUCER.length] = new Option(ARR[i][0], i, false, true);
      if(i==val_prod) { index = document.car.PRODUCER.length - 1; }
    }
    document.car.PRODUCER.options[index].selected = true;
  }
  else {  
    document.car.PRODUCER.options[0] = new Option("---", 0, false, true);
  }
}

function optCType() {  
  if(no_ctype==1) { return; }
  delOpt('CONSTRUCTIONTYPE');
  var index = 0;
  var h_sub = new String(val_stype);
  for(var i in CTYPE) {    
    var hilf = CTYPE[i][1];
    if(hilf.indexOf(h_sub)>0) {
      document.car.CONSTRUCTIONTYPE.options[document.car.CONSTRUCTIONTYPE.length] = new Option(CTYPE[i][0], i, false, true);
      if(i==val_ctype) { index = document.car.CONSTRUCTIONTYPE.length - 1; }
    }
  }
  document.car.CONSTRUCTIONTYPE.options[index].selected = true;  
}

function optType() {
  delOpt('TYPE');
  var index = 0;
  if(val_prod > 0) {
    eval('var ARR = PROD_'+val_stype+';');
    document.car.TYPE.options[0] = new Option("beliebig", 0, false, true);
    for(var i=1;i<ARR[val_prod].length;i++) {
      document.car.TYPE.options[document.car.TYPE.length] = new Option(ARR[val_prod][i][1], ARR[val_prod][i][0], false, true);
      if(ARR[val_prod][i][0]==val_type) { index = document.car.TYPE.length - 1; }
    }
    document.car.TYPE.options[index].selected = true;
  }
  else {
    document.car.TYPE.options[0] = new Option("---", 0, false, true);
  }
}

function optCateg() { 
  if(no_categ==1) { return; }
  delOpt('CATEGORY');
  var index = 0;
  var i = 0;
  var s = 0;
    
  if(val_stype > 0) {
    var CATEG = new Array();
    CATEG[1] = "Unfallwagen";
    CATEG[2] = "Unter 750";
    CATEG[3] = "Für Bastler";

    document.car.CATEGORY.options[0] = new Option("beliebig", 0, false, true);
    for(var i in CATEG) {      
      s = ((parseInt(val_stype)-1)*10) + parseInt(i);
      document.car.CATEGORY.options[document.car.CATEGORY.length] = new Option(CATEG[i], s, false, true);
      if(s==val_categ) { index = document.car.CATEGORY.length - 1; }
    }
    document.car.CATEGORY.options[index].selected = true;
  } else {  
    document.car.CATEGORY.options[0] = new Option("---", 0, false, true);
  }
}