/*
Datei: LinkedSelection.js
Datum: 04.01.2010
Autor: Maik Jurischka
Beschreibung: erstellt die selektiven Auswahllisten
*/

lock = false;//sperre bei laufendem request
req  = false;//request-objekt
objLayer=false;//container für die boxen

 if(window.XMLHttpRequest)
  {
   try {
     req = new XMLHttpRequest();
    }
   catch(e) {
     req = false;
    }
   }
  else if(window.ActiveXObject)
   {
    try
     {
      req = new ActiveXObject("Msxml2.XMLHTTP");
     }
    catch(e)
     {
      try
       {
        req = new ActiveXObject("Microsoft.XMLHTTP");
       }
      catch(e)
       {
        req = false;
       }
     }
   }

function clear(id) {
aktNode = document.getElementById(id);
for(i=aktNode.childNodes.length-1;i>1;--i)
	aktNode.removeChild(aktNode.childNodes[i]);
}

function request_data(objBox)
{
if(!req) {
	alert('Ihr Browser unterstützt kein XMLhttpRequest!');
	return;
}

if(lock) return;

var ort=0,entf=0,art=0,tour=0;
switch ( objBox.getAttribute('name') ) {
	case 'ort':
		objLayer = document.getElementById('entf');
		clear('art');
		clear('route');
		break;
	case 'entf':
		objLayer = document.getElementById('art');
		ort = document.forms[1].ort.value;
		clear('route');
		break;
	case 'art':
		objLayer = document.getElementById('route');
		ort = document.forms[1].ort.value;
		entf = document.forms[1].entf.value;
		break;
	case 'auswahl':
		objLayer = document.getElementById('entf');
		ort = document.forms[1].ort.value;
		clear('art');
		clear('entf');
		clear('route');
		break;
}
lock = true;

for(i=objLayer.childNodes.length-1;i>0;--i) {
	if(objLayer.childNodes[i]==objBox)break;
	objLayer.removeChild(objLayer.childNodes[i]);
}

req.onreadystatechange = new Function('f','get_http_response()');
ausw = (document.forms[1].auswahl[0].checked == true ) ? 0 : 1;
path = (is_admin == true) ? '../inc/box.php?box=' : 'inc/box.php?box=';
req.open("GET", path+objBox.value+'&ausw='+String(ausw)+'&ort='+ort+'&entf='+entf+'&art='+art+'&tour='+tour+'&'+new Date().getTime(), true);
req.send((document.all && !window.opera)?null:true);
}

function get_http_response()
{
 if(req.readyState == 4)
  {
   if(req.status == 200)
    {
	xml = req.responseXML;
	op = xml.getElementsByTagName('option');
	for (i=0;i<op.length;i++) {
		obj = document.createElement('option');
		attr = document.createAttribute("value");
		attr.nodeValue = op[i].getAttribute('value');
		obj.setAttributeNode(attr);
		obj.appendChild(document.createTextNode(op[i].firstChild.nodeValue));
		objLayer.appendChild(obj);
		}
     lock=false
    }
   else
    {
     alert(req.statusText);
    }
   if(document.all && !window.opera)
    {
     req.abort();
    }
   lock = false;
  }
}
