function getselector_duur(prov_id)
{
  if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  else if(window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.onreadystatechange = 
  function() 
  { 
  if (xmlhttp.readyState==4)
    if (xmlhttp.status==200)
          showselector_duur(xmlhttp);
  }
  xmlhttp.open('GET','require/getselector_duur.php?prov_id='+prov_id,true);
  xmlhttp.send(null);
}

function showselector_duur(req) 
{
  var xmlDoc = req.responseXML.documentElement;
  var items = xmlDoc.getElementsByTagName("duur");
  var content = '<span class="text_wit10"><b>Abonnementsduur:</b></span><br><select name="sduur">';
  for (var i = 0 ; i < items.length ; i++) 
  {
  	var item = items[i];
  	var naam = item.getElementsByTagName("naam")[0].firstChild.nodeValue;       
  	var id = item.getElementsByTagName("id")[0].firstChild.nodeValue;    
    content += '<option value="'+id+'">'+naam+'</option>';    
  }  
  content += '</select>';
  document.getElementById('selector_duur').innerHTML = content;
}


function getselector_tel(merk_id)
{
  if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  else if(window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.onreadystatechange = 
  function() 
  { 
  if (xmlhttp.readyState==4)
    if (xmlhttp.status==200)
          showselector_tel(xmlhttp,merk_id);
  }
  xmlhttp.open('GET','require/getselector_tel.php?merk_id='+merk_id,true);
  xmlhttp.send(null);
}

function showselector_tel(req,merk_id,merk) 
{
  var xmlDoc = req.responseXML.documentElement;
  var items = xmlDoc.getElementsByTagName("telefoon");
  var merknaam = xmlDoc.getElementsByTagName("merknaam")[0].firstChild.nodeValue;   
  
  var content = '<span class="text_wit10"><b>GSM type:</b></span><br><select name="stel_id" onchange="refresh_provider(this.value); enable_stype(this.value);">';
  content += '<option value="">Kies:</option>';
  content += '<option value="merk_'+merk_id+'">- Alle '+merknaam+' toestellen -</option>';
  for (var i = 0 ; i < items.length ; i++) 
  {
  	var item = items[i];
  	var type = item.getElementsByTagName("type")[0].firstChild.nodeValue;       
  	var id = item.getElementsByTagName("id")[0].firstChild.nodeValue;    
    content += '<option value="'+id+'">'+type+'</option>';    
  }  
  content += '</select>';
  document.getElementById('selector_tel').innerHTML = content;
}


function getselector_provider(tel_id)
{
  if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  else if(window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.onreadystatechange = 
  function() 
  { 
  if (xmlhttp.readyState==4)
    if (xmlhttp.status==200)
          showselector_provider(xmlhttp,tel_id);
  }
  xmlhttp.open('GET','require/getselector_provider.php?tel_id='+tel_id,true);
  xmlhttp.send(null);
}

function showselector_provider(req,tel_id) 
{
  document.getElementById('selector_provider').style.display='none';
  document.getElementById('selector_loader1').style.display='block';  

  var xmlDoc = req.responseXML.documentElement;
  var tellerall = xmlDoc.getElementsByTagName("tellerall")[0].firstChild.nodeValue;     
  var items = xmlDoc.getElementsByTagName("provider");
  var content = '<span class="text_wit10"><b>Provider:</b></span><br><select name="sprovider_id">';
  content += '<option value="all">Alle providers ('+tellerall+')</option>';  
  for (var i = 0 ; i < items.length ; i++) 
  {
  	var item = items[i];
  	var naam = item.getElementsByTagName("naam")[0].firstChild.nodeValue;       
  	var id = item.getElementsByTagName("id")[0].firstChild.nodeValue;
    content += '<option value="'+id+'">'+naam+'</option>';           
  }  
  content += '</select>';
  
  if (items.length==0)
  {
    content = '<br><span class="text_wit10">Er zijn geen abonnementen beschikbaar</span>';  
    document.getElementById('selector_zoek').style.display='none';     
  } else {
    document.getElementById('selector_zoek').style.display='block';   
  }
  
  document.getElementById('selector_provider').innerHTML = content;
  setTimeout("document.getElementById('selector_loader1').style.display='none';",1000);
  setTimeout("document.getElementById('selector_provider').style.display='block';",1000);
  getselector_formaction(tel_id);  
}


function getselector_formaction(tel_id)
{
  if (tel_id>0)
  {  
    if (document.forms['selector'].elements['stype'][0].checked==true) { type=1; }
    if (document.forms['selector'].elements['stype'][1].checked==true) { type=2; }
  } else {
    type=3;
  }
   
  if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
  else if(window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.onreadystatechange = 
  function() 
  { 
  if (xmlhttp.readyState==4)
    if (xmlhttp.status==200)
    {
      document.forms['selector'].action = xmlhttp.responseText;
    }
  }
  xmlhttp.open('GET','require/getselector_formaction.php?tel_id='+tel_id+'&type='+type,true);
  xmlhttp.send(null);
}

function getselector_url(stel_id)
{
  if (stel_id>0)
  {
    if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
    else if(window.ActiveXObject) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.onreadystatechange = 
    function() 
    { 
    if (xmlhttp.readyState==4)
      if (xmlhttp.status==200)
        document.getElementById('selector_url').style.display='block';
        document.getElementById('selector_url').innerHTML = xmlhttp.responseText;
    }
    xmlhttp.open('GET','require/getselector_url.php?tel_id='+stel_id,true);
    xmlhttp.send(null);
  } else {
    document.getElementById('selector_url').style.display='none';
  }
}


function refresh_provider(stel_id) 
{
  if (document.forms['selector'].elements['stype'][0].checked==true)
  {
    getselector_provider(stel_id);
  }
}

function enable_stype(stel_id) 
{
  if (stel_id>0)
  {  
    document.forms['selector'].elements['stype'][0].disabled=false;
    document.forms['selector'].elements['stype'][1].disabled=false;
  } else {
    document.getElementById('selector_prijzen').style.display='block'; 
    document.getElementById('selector_provider').style.display='none'; 
    document.getElementById('selector_zoek').style.display='block';  
    document.forms['selector'].elements['stype'][0].disabled=true;  
    document.forms['selector'].elements['stype'][1].checked=true;
    getselector_formaction(stel_id);    
  }
}

