function telAantalOccs()
{
    if ( document.occasion.telling_aan.value == 'Y')
    {
  
      var soort_voertuig = document.occasion.f_categorie_2.value;
      var merk           = document.occasion.f_merk.value;
      var model          = document.occasion.f_model.value;
      var prijs_van      = document.occasion.f_prijs1.value;
      var prijs_tot      = document.occasion.f_prijs2.value;
      var trefwoord      = document.occasion.f_trefw.value;
      var brandstof      = document.occasion.f_brandstof.value;
      var bouwjaar_van   = document.occasion.f_bouwj1.value;
      var bouwjaar_tot   = document.occasion.f_bouwj2.value;
      var postcode       = document.occasion.f_pc_cijfers.value;
      var straal         = document.occasion.f_straal_postc.value;
      
      var url = '/owa_dima/owa/!att_occsearch.telAantalOccs'+
                '?p_soort_voertuig='+soort_voertuig+
                '&p_merk='+merk+
                '&p_model='+model+
                '&p_prijs_van='+prijs_van+
                '&p_prijs_tot='+prijs_tot+
                '&p_trefwoord='+trefwoord+
                '&p_brandstof='+brandstof+
                '&p_bouwjaar_van='+bouwjaar_van+
                '&p_bouwjaar_tot='+bouwjaar_tot+
                '&p_postcode='+postcode+
                '&p_straal='+straal;
              
    xmlhttpHandler2(url, 'telling');
    }

}
function getBezoekersAantal() {
    var url = '/owa_dima/owa/tel_bezoeker_xml';
    xmlhttpHandler2(url, 'bezoekerstelling');
}

function vulModellenBrandstof(merk,brandstof) {
   var url = '';
   var soort_voertuig = document.occasion.f_categorie_2.value;
   url = '/owa_dima/owa/att_occsearch.getOccModellen_xml?p_merk=' + merk + '&p_brandstof=' + brandstof + '&p_soort_voertuig=' + soort_voertuig;
   xmlhttpHandler2(url, 'modelbrandstof');
}

function vulBrandstof(merk,model) {
   var url = '';
   var soort_voertuig = document.occasion.f_categorie_2.value;
   url = '/owa_dima/owa/att_occsearch.getBrandstof_xml?p_merk=' + merk + '&p_model=' + model + '&p_soort_voertuig=' + soort_voertuig;
   xmlhttpHandler2(url, 'brandstof');
}

function vulMerkModellen(brandstof) {
   var url = '';
   var soort_voertuig = document.occasion.f_categorie_2.value;
   url = '/owa_dima/owa/att_occsearch.getMerken_xml?p_brandstof=' + brandstof + '&p_soort_voertuig=' + soort_voertuig;
   xmlhttpHandler2(url, 'merkmodel');
}

function xmlhttpResponse(dom, soort)
{
 if ( soort == "brandstof" )
  {
    var poplist         = document.occasion.f_brandstof;
    var poplist_value   = dom.getElementsByTagName('SOORT');
    var poplist_oms     = dom.getElementsByTagName('OMS');
    var selected_value  = poplist.value;
  
    with (poplist)
    {
      for(i=options.length-1;i>0;i--) 
      {
        options[i] = null;
      }
      // altijd een default option
      options[0] = new Option('alle brandstoffen','0');
      // vul de poplist
      for (var i=0; i<poplist_value.length;i++) 
      {
	   //PHO 08-04-2008: alleen toevoegen als niet alle brandstoffen
	   if (poplist_value[i].firstChild.nodeValue!='0') {
        options[i+1] = new Option(poplist_oms[i].firstChild.nodeValue,poplist_value[i].firstChild.nodeValue);
  	     if (poplist_value[i].firstChild.nodeValue == selected_value)
         {
	      poplist.options[i+1].selected=true;
         }
	   }
      }
    }
    telAantalOccs();
  }
  if ( soort == "merkmodel" )
  {
    var poplist         = document.occasion.f_merk;
    var poplist_value   = dom.getElementsByTagName('MERK_VALUE');
    var poplist_oms     = dom.getElementsByTagName('MERK_OMS');
    var selected_value  = poplist.value;
    var soort_voertuig  = document.occasion.f_categorie_2.value;
  
    with (poplist)
    {
      for(i=options.length-1;i>0;i--) 
      {
        options[i] = null;
      }
      // altijd een default option
      options[0] = new Option('alle merken','');
      // vul de poplist
      for (var i=0; i<poplist_value.length;i++) 
      {
        options[i+1] = new Option(poplist_oms[i].firstChild.nodeValue,poplist_value[i].firstChild.nodeValue);
	  if (poplist_value[i].firstChild.nodeValue == selected_value)
        {
	    poplist.options[i+1].selected=true;
        }
      }
    }
   var url = '';
   url = '/owa_dima/owa/att_occsearch.getOccModellen_xml?p_merk=' + document.occasion.f_merk.value + 
                                                       '&p_brandstof=' + document.occasion.f_brandstof.value + 
                                                       '&p_soort_voertuig=' + soort_voertuig;
   xmlhttpHandler2(url, 'model');
  }

  if ( soort == "modelbrandstof" )
  {
    var poplist         = document.occasion.f_model;
    var poplist_value   = dom.getElementsByTagName('MODEL_VALUE');
    var poplist_oms     = dom.getElementsByTagName('MODEL_OMS');
    var selected_value  = poplist.value;
    var soort_voertuig  = document.occasion.f_categorie_2.value;

    with (poplist) 
    {
      for(i=options.length-1;i>0;i--) 
      {
        options[i] = null;
      }
      // altijd een default option
      if (document.occasion.f_merk.value == "")
      {
        options[0] = new Option('Kies eerst merk','');
      } else
      {
        options[0] = new Option('alle modellen','');
      }
      // vul de poplist
      for (var i=0; i<poplist_value.length;i++) 
      {
        options[i+1] = new Option(initCaps(poplist_oms[i].firstChild.nodeValue),poplist_value[i].firstChild.nodeValue);
	  if (poplist_value[i].firstChild.nodeValue == selected_value)
        {
	    poplist.options[i+1].selected=true;
        }
      }
    }
   // Als de modellen worden ververst dan ook de brandstofsoorten
   var url = '';
   url = '/owa_dima/owa/att_occsearch.getBrandstof_xml?p_merk=' + document.occasion.f_merk.value + 
                                                     '&p_model=' + document.occasion.f_model.value + 
                                                     '&p_soort_voertuig=' + soort_voertuig;
   xmlhttpHandler2(url, 'brandstof');
  }
  if ( soort == "model" )
  {
    var poplist         = document.occasion.f_model;
    var poplist_value   = dom.getElementsByTagName('MODEL_VALUE');
    var poplist_oms     = dom.getElementsByTagName('MODEL_OMS');
    var selected_value  = poplist.value;
    with (poplist) 
    {
      for(i=options.length-1;i>0;i--) 
      {
        options[i] = null;
      }
      // altijd een default option
      if ( document.occasion.f_merk.value == "" )
      {
        options[0] = new Option('Kies eerst merk','');
      } else
      {
        options[0] = new Option('alle modellen','');
      }
      // vul de poplist
      for (var i=0; i<poplist_value.length;i++) 
      {
        options[i+1] = new Option(initCaps(poplist_oms[i].firstChild.nodeValue),poplist_value[i].firstChild.nodeValue);
	  if (poplist_value[i].firstChild.nodeValue == selected_value)
        {
	    poplist.options[i+1].selected=true;
        }
      }
    }
    telAantalOccs();
  }
  if ( soort == "reload" )
  {
    var poplist         = document.occasion.f_model;
    var poplist_value   = dom.getElementsByTagName('MODEL_VALUE');
    var poplist_oms     = dom.getElementsByTagName('MODEL_OMS');
    var selected_value  = poplist[poplist.selectedIndex].value;
    var soort_voertuig  = document.occasion.f_categorie_2.value;
    
    with (poplist) 
    {
      for(i=options.length-1;i>0;i--) 
      {
        options[i] = null;
      }
      // altijd een default option
      if (document.occasion.f_merk.value == "")
      {
        options[0] = new Option('Kies eerst merk','');
      } else
      {
        options[0] = new Option('alle modellen','');
      }
      // vul de poplist
      for (var i=0; i<poplist_value.length;i++) 
      {
        options[i+1] = new Option(initCaps(poplist_oms[i].firstChild.nodeValue),poplist_value[i].firstChild.nodeValue);
	  if (poplist_value[i].firstChild.nodeValue == selected_value)
        {
	    poplist.options[i+1].selected=true;
        }
      }
    }
   // Als de modellen worden ververst dan ook de brandstofsoorten
   var url = '';
   url = '/owa_dima/owa/att_occsearch.getBrandstof_xml?p_merk=' + document.occasion.f_merk.value + 
                                                     '&p_model=' + document.occasion.f_model.value + 
                                                     '&p_soort_voertuig=' + soort_voertuig;
   xmlhttpHandler2(url, 'brandstof');
  }

//  if ( soort != 'telling')
//  {
//    telAantalOccs();
//  }
  
  if ( soort == 'telling' )
  {

    var aantalGevonden   = dom.getElementsByTagName('AANTAL');
  
    document.getElementById('aantalOccs').innerHTML = aantalGevonden[1].firstChild.nodeValue+' occasions gevonden&nbsp;&nbsp;';
    
  }
  if ( soort == "bezoekerstelling" )
  {
    var aantalBezoekers   = dom.getElementsByTagName('AANTAL_ONLINE');
    document.getElementById('num_bez_online').innerHTML = aantalBezoekers[0].firstChild.nodeValue;
	ajaxCheckModelHome();
  }
  
}
function initCaps(in_str) {
   var out_str = '';
   out_str = in_str.substr(0,1).toUpperCase()+in_str.substr(1).toLowerCase();
   return out_str;
}