// ajax.js - adaptiert durch Tim Reeves aus Internet-Pro 11/05,
// ursprunglich programmiert von Marco Zierl.
// Stand: 2009-10-02 (mit neuen BuchbarkeitsIcons)

// THE BASIS OF ALL AJAX

var ajaxok = false;
var prefix = '../';		// Relative path prefix to server scripts
// 2006-08-25 Prefix is now always '../', since all Webpages are by design "one dir down"
var xmlhttp = null;
var target_select_obj = null;

function getXMLHttpRequest() {
	// mochiKit does it more or less so...
    var tryThese = [
        function () { return new XMLHttpRequest(); },
        function () { return new ActiveXObject('Msxml2.XMLHTTP'); },
        function () { return new ActiveXObject('Microsoft.XMLHTTP'); },
        function () { return new ActiveXObject('Msxml2.XMLHTTP.4.0'); },
    ];
    for (var i = 0; i < tryThese.length; i++) {
        var func = tryThese[i];
        try {
            return func();
        } catch (e) {
            // pass
        }
    }
    return null;
}

function getFirefox() {
	var getFF = "Am Besten holen Sie den modernen Gratis-Browser \"Firefox\" \nper DownLoad. Wollen Sie jetzt Firefox herunterladen?"
	var ans = confirm(getFF);
	if (ans == true) location.href = 'http://www.mozilla-europe.org/de/products/firefox/';
	return;
}

// EVERY page calls either ajaxProbe() or ajaxOnload()
// so both of these set the general server path prefix
// 2006-08-25 Prefix is now always '../', since all Webpages are by design "one dir down"
function setPrefix() {
	// The url is something like...
	// http://localhost/hauser7/allgemein/philosphie.html
	// http://localhost/hauser7/leiter/Heinrich_Gruber.html
	// http://www.grafik-fischer.de/hauser3/allgemein/philosphie.html
	// http://www.hauser-exkursionen.de/allgemein/philosphie.html
	// var url = document.URL;
	// IF it starts like "http://.../" then delete that
	// var r1 = url.replace(/http:\/\/.+?\/(.)/, "$1");
	// IF "hauser{.*}/" follows, then delete that too
	// var r2 = r1.replace(/hauser.*?\/(.)/, "$1");
	// IF there is yet another slash, then it's a subdir, prefix='../'
	// if (r2.search(/\/./) != -1) prefix = '../';

	var agent=navigator.userAgent;
	if (agent.indexOf('Mac') != -1 && agent.indexOf('MSIE 5') != -1){
		// MSIE on Mac is a catastrophy - not supported
		alert("Sie verwenden den MSIE 5 - Mac Browser, mit\ndem diese Website nicht korrekt dargestellt wird.");
		getFirefox();
	}
	if (!document.getElementById){
		alert("Sie verwenden ein sehr veralteter Browser, mit\ndem diese Website nicht korrekt dargestellt wird.");
		getFirefox();
	}

	return;
}

// Standard functions to delete a subtree in DOM model
function delKids(prnt)
{
	// alert('delKids: ' + prnt.nodeName + ' / ' + prnt.nodeValue);
	var c = prnt.lastChild, p;
	while (c) {
		// Note previous while last is still there!
		p = c.previousSibling;
		delTree(prnt, c);
		c = p;
	}
	return;
}

function delTree(prnt, chld)
{
	// alert('delTree:: Parent: ' + prnt.nodeName + ' / ' + prnt.nodeValue +
	// 	  ' Child: ' + chld.nodeName + ' / ' + chld.nodeValue);
	var c = chld.lastChild, p;
	while (c) {
		p = c.previousSibling;
		delTree(chld, c);
		c = p;
	}
	prnt.removeChild(chld);
	return;
}

function debugToPfad(txt) {
	var jetzt = new Date();
	var debugTxt = jetzt.getTime() + ' ' + txt;
	var pfad = document.getElementById('pfad'); delKids(pfad);
	var textObj = document.createTextNode(debugTxt);
	pfad.appendChild(textObj);
	return;
}

function ctrImage() {
	// The hidden counter which gathers statistics
	// Insert the URL call as the source of an image which is added via DOM
	// alert('Counter-Call');
	var ref = '';
	if (document.images && document.referrer && document.referrer.length>0)
	 { ref += escape(document.referrer); }
	var fbt = '..', cookies = ' U';
	if (screen.colorDepth && screen.colorDepth != null) {
		fbt = screen.colorDepth;
		if (fbt.length == 1) { fbt = '0' + screen.colorDepth; }
		}
	if (typeof navigator.cookieEnabled == 'boolean')
		cookies = navigator.cookieEnabled ? ' J' : ' N';
	ref += '&sh='+screen.height+'&sw='+screen.width+'&user='+fbt+cookies;
	var ctrImg = document.createElement('img');
	ctrImg.width = 1;
	ctrImg.height = 1;
	ctrImg.src = '/cgi-bin/counter.pl?id=1&rl=1800&ref=' + ref;
	// ctrImg.src = '/cgi-bin/counter.pl?id=1&rl=0&ref=' + ref;
	var ctrDiv = document.getElementById('ctrDiv');
	ctrDiv.appendChild(ctrImg);
	return;
}

function initPage() {
	// Set the window name to allow us to know if this is the inital website entry
	var re = /^Hauser_exkursionen_Website_de/;
	if (! re.test(window.name)) {
		// It IS the initial website entry - set the window name
		window.name = 'Hauser_exkursionen_Website_de';
		// And call the counter
		ctrImage();
	}
	// Caveat: Since hardly any site sets the window name, it tends to stay this way
	//         meaning that subsequent visits - even hours later - are not noted
	// The alternative is to have the counter called by EVERY page and the data is
	// not recorded by the counter software if the IP address is (time-)locked out.
	// NOTE that the window name is tab-specific in browsers with tabs
	return;
}

// Perform a test for AJAX capability on page loading
// Called by dynamic pages which don't require AJAX-setting of
// Team-Name / Touren-Ampel / E-Mail-Adresse

// Those which do call ajaxOnload() (for the above reasons)
// get an unneccessary Ajax-Update of Volltext- und Tourensuche
// Probe:  vtsuche.php, leitersuche.php, toursuche.php
// Onload: teamsuche.php (wg. Mitarbeiter-Emails)

function ajaxProbe() {
	setPrefix();
	xmlhttp = getXMLHttpRequest();
	if (xmlhttp)
		ajaxok = true;
	else
		alert("AJAX-Technologie nicht verfügbar");
	// Set window name and call the counter if inital website entry
	initPage();
	return;
}

// THE FUNCTIONS FOR UPDATING THE LAND LIST ON CONTINENT CHANGE

// Add a single option element to a select list
function add_option(obj, optext, optval, selval)
{
	// alert("add_element: " + optext);
	var newOption = new Option(optext, optval);
	var idx = obj.options.length;
	obj.options[idx] = newOption;
	obj.options[idx].selected = (optval == selval);
	return;
}

// Insert the number of tours which match the field values
function set_anztouren(anz)
{
	var anztext = anz == ' ' ? ' ' : ' ' + anz + ' ';
	var agent=navigator.userAgent.toLowerCase();
	if (agent.indexOf('safari') != -1) {
		// Safari ALWAYS displays a button - nutze die Button-Beschriftung
		optval = '»' + anztext + 'Touren zeigen';
		document.getElementById('banztouren').value = optval;
		}
	else
		document.getElementById('sanztouren').firstChild.nodeValue = anztext;
	return;
}

// Rebuild a complete list of select box options
// Called when continent changes for new list of lands
function optionData()
{
	var xmlDocument = xmlhttp.responseXML;
	var optval='', optext='', base=null, i=0;

	// Remove all old options from the list
	// showProps(target_select_obj.options);
	while (target_select_obj.options.length > 0) {
		if (target_select_obj.remove)
			target_select_obj.remove(0);
		else
			target_select_obj.options.remove(0);
	}
	// Add new options to list
	for (i=0; i< xmlDocument.getElementsByTagName("llopt").length; i++)
	{
		base = xmlDocument.getElementsByTagName("llopt")[i];
		optval = base.getElementsByTagName("optval")[0].childNodes[0].nodeValue;
		optext = base.getElementsByTagName("optext")[0].childNodes[0].nodeValue;
		// No option will be selected, display defaults to the first
		add_option(target_select_obj, optext, optval, '');
	}
	// Enable the listbox again if it has more than one option
	if (i>1) target_select_obj.disabled = false;

	// ANZAHL TOUREN
	if (xmlDocument.getElementsByTagName("anztouren")[0])
	   set_anztouren(xmlDocument.getElementsByTagName("anztouren")[0].childNodes[0].nodeValue);

	// Remove any old message
	if (document.getElementById('toursuchemsg')) {
		var chld = document.getElementById('toursuchemsg');
		var prnt = chld.parentNode;
		delTree(prnt,chld);
		// IE positioning bug - button slips down, although posn "bottom"
		document.getElementById('panztouren').className = 'panztouren';
		document.getElementById('danztouren').className = 'danztouren';
		}

	return;
}

function optionsHttpState()
{
	if (xmlhttp.readyState == 4)
	{
		if ( xmlhttp.status == 200) {
			// daten erfolgreich geladen: starte Verarbeitung
			optionData();
		} else {
			alert("Fehler beim Abrufen der Option-XML Daten - Status " + xmlhttp.status);
			alert("Statusmeldung vom Server: " + xmlhttp.statusText);
			alert("Debug: Url=" + document.URL + " Prefix=" + prefix);
		}
	}
	return;
}

function get_select_data(select_name, url, selected_id)
{
	// select_name = name of target dropdown to get new option list
	// url         = url to call which should deliver the new option data
	// selected_id = name of dropdown calling this function - delivers index
	// UND ZWAR: get_select_data('f_land','get_options.php?typ=laender','f_ziel');

	// var debugTxt = "get_select_data: " + select_name + " / " + url + " / " + selected_id;
	// debugToPfad(debugTxt);

	// Do nothing if AJAX technology not available
	if (!ajaxok) return;

	if (select_name != "") {
		target_select_obj = eval("document.forms['toursuche']." + select_name);
		// Disable the target dropdown
		target_select_obj.disabled = true;
	}
	else
		target_select_obj = null;

	if (selected_id != ""){
		url += "&sel=" + eval("document.forms['toursuche']." + selected_id + ".value");
	}
	// Get the new option list via AJAX
	if (xmlhttp) {
		// xmlhttp.open("GET", prefix + "cgi-bin/" + url, true );	// Fails at Strato
		// xmlhttp.open("GET", "asien.xml", true ); 		// Works at Strato
		// 3rd parameter is true for asynchronous, false for synchronous
		xmlhttp.open("GET", prefix + 'scripts/' + url, true);
		// alert("XMLHttpObject geöffnet");
		xmlhttp.onreadystatechange = optionsHttpState;
		xmlhttp.send(null);
		}
	else {
		alert("XMLHttpObject fehlt!");
	}
	return;
}

// THE FUNCTIONS TO POPULATE THE FORM FIELDS AND ICONS ON PAGE LOADING

function onloadData()
{
	var xmlDocument = xmlhttp.responseXML;
	var optval='', optext='', welches='', i=0, obj=null;

	// Empty text values mean there is no child node - catch them
	// alert(xmlhttp.responseText);

	// DIE VOLLTEXT-SUCHE
	if (xmlDocument.getElementsByTagName("vtsuche")[0] &&
		xmlDocument.getElementsByTagName("vtsuche")[0].childNodes[0] &&
		document.forms['vtsuche'].f_vtsuche)
		document.forms['vtsuche'].f_vtsuche.value =
			xmlDocument.getElementsByTagName("vtsuche")[0].childNodes[0].nodeValue;

	// AKTUELLER KONTINENT
	obj = document.forms['toursuche'].f_ziel;
	welches = xmlDocument.getElementsByTagName("ziel")[0].childNodes[0].nodeValue;
	for (i=0; i< obj.options.length; i++)
	{
		if (obj.options[i].value == welches) {
			obj.options[i].selected = true;
			break;
			}
	}

	// DIE LÄNDERLISTE
	var land_list_obj = document.forms['toursuche'].f_land;
	welches = xmlDocument.getElementsByTagName("land")[0].childNodes[0].nodeValue;
	// Remove all old options from the list
	// showProps(target_select_obj.options);
	while (land_list_obj.options.length > 0) {
		if (land_list_obj.remove)
			land_list_obj.remove(0);
		else
			land_list_obj.options.remove(0);
	}
	// Add new options to the list
	for (i=0; i< xmlDocument.getElementsByTagName("llopt").length; i++)
	{
		obj = xmlDocument.getElementsByTagName("llopt")[i];
		optval = obj.getElementsByTagName("optval")[0].childNodes[0].nodeValue;
		optext = obj.getElementsByTagName("optext")[0].childNodes[0].nodeValue;
		add_option(land_list_obj, optext, optval, welches);
	}
	// Enable the listbox if it has more than one option
	if (i>1) land_list_obj.disabled = false;

	// MAX. PREIS
	if (xmlDocument.getElementsByTagName("maxpreis")[0])
		document.forms['toursuche'].f_maxpreis.value =
			xmlDocument.getElementsByTagName("maxpreis")[0].childNodes[0].nodeValue;

	// SCHWIERIGKEITSGRAD
	obj = document.forms['toursuche'].f_schwierig;
	welches = xmlDocument.getElementsByTagName("schwierig")[0].childNodes[0].nodeValue;
	for (i=0; i< obj.options.length; i++)
	{
		if (obj.options[i].value == welches) {
			obj.options[i].selected = true;
			break;
			}
	}

	// FRÜHESTER ABREISE
	if (xmlDocument.getElementsByTagName("abdatum")[0])
		document.forms['toursuche'].f_abdatum.value =
			xmlDocument.getElementsByTagName("abdatum")[0].childNodes[0].nodeValue;

	// SPÄTESTER RÜCKREISE
	if (xmlDocument.getElementsByTagName("rueckdatum")[0])
		document.forms['toursuche'].f_rueckdatum.value =
			xmlDocument.getElementsByTagName("rueckdatum")[0].childNodes[0].nodeValue;

	// ANZAHL TOUREN
	if (xmlDocument.getElementsByTagName("anztouren")[0] &&
		xmlDocument.getElementsByTagName("anztouren")[0].childNodes[0])
	   set_anztouren(xmlDocument.getElementsByTagName("anztouren")[0].childNodes[0].nodeValue);

	// REISELEITER VOR- UND NACHNAME (falls Seite mit RL-Suche)
	if (document.forms['leitersuche']) {
		if (xmlDocument.getElementsByTagName("rlvorname")[0] &&
			xmlDocument.getElementsByTagName("rlvorname")[0].childNodes[0])
			document.forms['leitersuche'].f_rlvorname.value =
				xmlDocument.getElementsByTagName("rlvorname")[0].childNodes[0].nodeValue;
		if (xmlDocument.getElementsByTagName("rlnachname")[0] &&
			xmlDocument.getElementsByTagName("rlnachname")[0].childNodes[0])
			document.forms['leitersuche'].f_rlnachname.value =
				xmlDocument.getElementsByTagName("rlnachname")[0].childNodes[0].nodeValue;
	}

	// MITARBEITER VOR- UND NACHNAME (falls Seite mit Team-Suche)
	if (document.forms['teamsuche']) {
		if (xmlDocument.getElementsByTagName("htvorname")[0] &&
			xmlDocument.getElementsByTagName("htvorname")[0].childNodes[0])
			document.forms['teamsuche'].f_htvorname.value =
				xmlDocument.getElementsByTagName("htvorname")[0].childNodes[0].nodeValue;
		if (xmlDocument.getElementsByTagName("htnachname")[0] &&
			xmlDocument.getElementsByTagName("htnachname")[0].childNodes[0])
			document.forms['teamsuche'].f_htnachname.value =
				xmlDocument.getElementsByTagName("htnachname")[0].childNodes[0].nodeValue;
	}

	// ALLE BUCHBARKEITSICONS EINSETZEN
	var rsnr = '', bbar = '', icon = '', text = '', idx, obj;
	var anz = xmlDocument.getElementsByTagName("reise").length;
	// alert(anz + ' Touren gefunden auf der Seite');
	for (i=0; i<anz; i++)
	{
		rsnr = xmlDocument.getElementsByTagName("reise")[i].childNodes[0].firstChild.data;
		bbar = xmlDocument.getElementsByTagName("reise")[i].childNodes[1].firstChild.data;
		icon = xmlDocument.getElementsByTagName("reise")[i].childNodes[2].firstChild.data;
		text = xmlDocument.getElementsByTagName("reise")[i].childNodes[3].firstChild.data;
		// alert(rsnr + ': ' + bbar + '/' + icon + '/' + text);
		obj = document.getElementById('ampel' + (i+1));
		obj.src = prefix + 'images/' + icon;
		obj.alt = text;
		obj.title = text;
		// Nicht-buchbare Touren dürfen keinen "Buchen" Verweis haben
		// - entfernen falls da
		if (bbar == 'N' && obj.nextSibling) {
			var chld = obj.nextSibling;
			var prnt = obj.parentNode;
			delTree(prnt,chld);
			}
	}

	// ETWAIGE EMAIL-ADRESSEN EINSETZEN
	var nr = '', link='', title='', subject='', href='';
	var textObj=null, linkObj=null, spanObj=null;
	var anz = xmlDocument.getElementsByTagName("email").length;
	for (var i=0; i<anz; i++)
	{
		// Hier zählt 'i' lediglich durch die Antworten, doch
		// <nr> bezieht sich korrekterweise auf die Anfrage!!
		nr = xmlDocument.getElementsByTagName("email")[i].childNodes[0].firstChild.data;
		// childNodes[1] = ID => not needed (but good for debugging :)
		link = xmlDocument.getElementsByTagName("email")[i].childNodes[2].firstChild.data;
		show = xmlDocument.getElementsByTagName("email")[i].childNodes[3].firstChild.data;
		title = xmlDocument.getElementsByTagName("email")[i].childNodes[4].firstChild.data;
		subject = xmlDocument.getElementsByTagName("email")[i].childNodes[5].firstChild.data;
		href = subject == '' ? 'mailto:' + link
							 : 'mailto:' + link + '?subject=' + subject;
		// alert(link);
		// Zunächst den Link vorbereiten
		textObj = document.createTextNode(show);
		linkObj = document.createElement('a');
		linkObj.setAttribute('href',href);
		linkObj.setAttribute('title',title);
		// Nun Grafik aushängen und Link einhängen
		spanObj = document.getElementById('email' + nr);
		delKids(spanObj);
		spanObj.appendChild(linkObj);
		// MSIE mag es nicht wenn der Textknoten vor dem Einhängen angehängt wird
		spanObj.childNodes[0].appendChild(textObj);
	}

	return;
}

function onloadHttpState()
{
	if (xmlhttp.readyState == 4)
	{
		if ( xmlhttp.status == 200) {
			// daten erfolgreich geladen: starte Verarbeitung
			onloadData();
		} else {
			alert("Fehler beim Abrufen der Onload-XML Daten - Status " + xmlhttp.status);
			alert("Statusmeldung vom Server: " + xmlhttp.statusText);
		}
	}
	return;
}

// This is called by all "static" pages i.e. *.html as <body onload> event
function ajaxOnload() {
	setPrefix();
	// Opera calculates the width of select boxes via w3c box model
	if (window.opera) {
		document.getElementById('f_ziel').className = 'schnell std';
		document.getElementById('f_land').className = 'schnell std';
		document.getElementById('f_maxpreis').className = 'schnell std serif';
		document.getElementById('f_schwierig').className = 'schnell std serif';
		if (document.getElementById('f_landname')) {
			document.getElementById('f_landname').style.height = '12px';
			}
		if (document.getElementById('f_landname2')) {
			document.getElementById('f_landname2').style.height = '12px';
			document.getElementById('f_landname').style.top = '0px';
			document.getElementById('f_landname2').style.top = '0px';
			}
	}
	// Perform a test for AJAX on page loading
	xmlhttp = getXMLHttpRequest();
	if (xmlhttp)
		ajaxok = true;
	else {
		alert("AJAX-Technologie nicht verfügbar");
		return;
		}
	var curid = '', touren = '', emails = '', ref = '', sep='?', i;
	// Get a list of all the Tour Numbers on the page
	// They are the text content of cells with id's like "tournr<n>"
	for (i=1; true; i++) {
		curid = 'tournr' + i;
		if (document.getElementById(curid) &&
			document.getElementById('ampel' + i)) {
			touren += sep + curid + '=' +
					  document.getElementById(curid).firstChild.nodeValue;
			sep = '&';
			}
		else break;
	}
	// Get a list of all the Email Numbers on the page
	// They are the content of span-elements with id's like "email<n>"
	for (i=1; true; i++) {
		curid = 'email' + i;
		if (document.getElementById(curid)) {
			emails += sep + curid + '=' +
					  document.getElementById(curid).firstChild.id;
			sep = '&';
			}
		else break;
	}
	// Provisionspartner: For html-files add a referrer-parameter
	var docpath = window.location.pathname;
	var pathlen = docpath.length;
	var docext = docpath.slice(pathlen-5);
	var ref = '';
	if ((docext == '/' || docext == '.html') &&
		  document.referrer && document.referrer.length > 0)
	 { ref = sep + 'referrer=' + escape(document.referrer); }
	// Call "onload.php" on the server to return the current values
	// and insert these values into the displayed page
	var url = prefix + 'scripts/onload.php' + touren + emails + ref;
	// alert(url);
	// debugToPfad(url);
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = onloadHttpState;
	xmlhttp.send(null);
	// Set window name and call the counter if initial website entry
	initPage();
	return;
}

// THE FUNCTIONS TO UPDATE SERVER SESSION VARS ON SINGLE FIELD CHANGE

/*  Whenever the user changes a field value (in either form) then the
	new value is sent to the server and put in the session variables -
	which involves getting at least a small return document from the server.
	However, when the form is submitted this action is not required - in fact,
	a document would be returned to a page which no longer exists, so we want
	to suppress the onChange action when the event which triggers the onChange
	is the form submission. This in turn is caused by EITHER
	- the user is in a text input field and hits ENTER, or
	- he or she clicks on the submit button.
	In both cases the onChange happens BEFORE the onSubmit, so we have to
	add a small delay to the onChange action, and then not do it if we find
	we are at that time submitting the form.
	Note that onChange is triggered by onMouseDown on the submit button -
	it'll come up again and be a click soon enough! If we would wait for the
	onClick event we would have to wait too long - an indefinite period as the
	user may "sit" on the mouse button!
*/

var nowSubmitting = '';

function setNowSubmitting(typ) {
	// Note a form submission to suppress the onchange action - see neuWert()
	window.nowSubmitting = typ;
	// alert("setnowSubmitting: " + typ);
	return true;
}

// Decode the answer to a changed field value in the "Schnellsuche"
function tourData()
{
	// alert(xmlhttp.responseText);
	var xmlDocument = xmlhttp.responseXML;
	// Check for a modified value
	if (xmlDocument.getElementsByTagName("FLD")[0]) {
		// This can currently only be a normalised or rejected date
		var fld='', val='';
		fld = xmlDocument.getElementsByTagName("FLD")[0].childNodes[0].nodeValue;
		val = xmlDocument.getElementsByTagName("VAL")[0].childNodes[0].nodeValue;
		document.getElementById(fld).value = val;
		}
	// ANZAHL TOUREN - Insert the number of matching tours behind the button
	if (xmlDocument.getElementsByTagName("anztouren")[0])
	   set_anztouren(xmlDocument.getElementsByTagName("anztouren")[0].childNodes[0].nodeValue);
	// Display any message above the Schnellsuche
	if (xmlDocument.getElementsByTagName("MSG")[0]) {
		var msg='';
		msg = xmlDocument.getElementsByTagName("MSG")[0].childNodes[0].nodeValue;
		// Insert the message between div.schnellsuche and form-id 'toursuche'
		if (document.getElementById('toursuchemsg')) {
			var chld = document.getElementById('toursuchemsg');
			chld.firstChild.data = msg;
			}
		else {
			var myNode = document.createElement("p");
			// Give it the id attribute
			myNode.setAttribute('id', 'toursuchemsg');
			// Append the text node for the link
			var myText = document.createTextNode(msg);
			myNode.appendChild(myText);
			// Insert it into the DOM before the form
			var sblg = document.getElementById('toursuche');
			var prnt = sblg.parentNode;
			prnt.insertBefore(myNode,sblg);
			// IE positioning bug - button slips up, although posn "bottom"
			document.getElementById('panztouren').className = 'panztouren';
			document.getElementById('danztouren').className = 'danztouren';
			}
		}
	else {
		// Remove any old message
		if (document.getElementById('toursuchemsg')) {
			var chld = document.getElementById('toursuchemsg');
			var prnt = chld.parentNode;
			delTree(prnt,chld);
			// IE positioning bug - button slips down, although posn "bottom"
			document.getElementById('panztouren').className = 'panztouren';
			document.getElementById('danztouren').className = 'danztouren';
			}
		}
	return;
}

// Preview of the matching Reiseleiter / Mitarbeiter as user types name in
function persData()
{
	// alert(xmlhttp.responseText);
	var xmlDocument = xmlhttp.responseXML;
	// We only get search results if there is at least one input char
	if (xmlDocument.getElementsByTagName("zuwenigzeichen")[0]) {
		// Make the result panel invisible
		document.getElementById('persergebnisse').style.visibility="hidden";
		// And the standard panel visible
		document.getElementById('col2').style.visibility="visible";
		return;
	}
	// Prepare the content in the result panel
	var persname='', persfile='', i=0, obj=null;
	var myNode=null, myText=null;
	var hitliste = document.getElementById('hitliste');
	var anzhits = xmlDocument.getElementsByTagName("pers").length;
	if (document.getElementById('f_htvorname')) {
		var vn = 'f_htvorname';
		var nn = 'f_htnachname';
		}
	else {
		var vn = 'f_rlvorname';
		var nn = 'f_rlnachname';
		}
	if (anzhits == 0) {
		document.getElementById(vn).style.backgroundColor = '#FFE4E4';
		document.getElementById(nn).style.backgroundColor = '#FFE4E4';
		}
	else if (anzhits == 1) {
		document.getElementById(vn).style.backgroundColor = '#CDEFC7';
		document.getElementById(nn).style.backgroundColor = '#CDEFC7';
		}
	else {
		document.getElementById(vn).style.backgroundColor = '';
		document.getElementById(nn).style.backgroundColor = '';
		}
	// First delete the previous content
	delKids(hitliste);
	// Now add a link for each person found
	for (i=0; i<anzhits; i++)
	{
		obj = xmlDocument.getElementsByTagName("pers")[i];
		persname = obj.getElementsByTagName("name")[0].childNodes[0].nodeValue;
		persfile = obj.getElementsByTagName("file")[0].childNodes[0].nodeValue;
		if (i>0) {
			// Add a <br /> Element so each Person on a new line
			myNode = document.createElement("br");
			hitliste.appendChild(myNode);
		}
		myText = document.createTextNode(persname);
		if (persfile == ' ')
			hitliste.appendChild(myText);
		else {
			// Append the link node
			myNode = document.createElement("a");
			// Give it the href attribute
			myNode.setAttribute('href', persfile);
			// The following is more puristic for attributes, but IE5.5 can't
			// myAttr = document.createAttribute("href");
			// myAttr.nodeValue = persfile + persFileExt;
			// myNode.setAttributeNode(myAttr);
			// Append the text node for the link
			myNode.appendChild(myText);
			// Append it to the results
			hitliste.appendChild(myNode);
			}
	}
	if (i == 0) {
		myText = document.createTextNode('Keine Treffer.');
		hitliste.appendChild(myText);
	}
	// Make the standard panel invisible
	document.getElementById('col2').style.visibility="hidden";
	// and the result panel visible
	document.getElementById('persergebnisse').style.visibility="visible";
	return;
}

function ajaxFehler()
{
	alert("Fehler beim Notieren des neuen Feldwertes - Status " + xmlhttp.status);
	alert("Statusmeldung vom Server: " + xmlhttp.statusText);
	return;
}

function tourWertHttpState()
{
	if (xmlhttp.readyState == 4)
	{
		if ( xmlhttp.status == 200) {
			// daten erfolgreich geladen: starte Verarbeitung
			tourData();
		}
		else ajaxFehler();
	}
	return;
}

function vtsWertHttpState()
{
	if (xmlhttp.readyState == 4)
	{
		if ( xmlhttp.status == 200) {
			// Antwort erfolgreich - es gibt jedoch keine lokale Verarbeitung
			return;
		}
		else ajaxFehler();
	}
	return;
}

function persWertHttpState()
{
	if (xmlhttp.readyState == 4)
	{
		if ( xmlhttp.status == 200) {
			// daten erfolgreich geladen: starte Verarbeitung
			persData();
		}
		else ajaxFehler();
	}
	return;
}

function neuWert(typ,fld) {
	// Pass a new form field value to it's session variable via AJAX
	// But don't do it if the form is being submitted anyway
	// Since onchange() and onkeyup() are called BEFORE onsubmit(), we must wait...
	// Bekannte Typen: 'v' => Volltextsuche; 't' => Toursuche; 'r' => Reiseleiter
	//                 'm' => Mitarbeiter
	// var debugTxt = "neuWert: " + typ + " für " + fld.name + ", nowSubmitting=" + window.nowSubmitting;
	// alert(debugTxt);		// Triggers onBlur
	// debugToPfad(debugTxt);
	if (! ajaxok) return;
	var aufruf = "neuWertWaited('" + typ + "','" + fld.id + "')";
	window.setTimeout(aufruf,5);
	return;
}

function neuWertWaited(typ,fldid) {
	// alert("neuWertWaited: " + typ + " für " + fldid + ", nowSubmitting=" + window.nowSubmitting);
	if (typ == window.nowSubmitting || ! ajaxok) return;
	xmlhttp = getXMLHttpRequest();
	// Call "set_formval.php" on the server to note new field value
	// Note that the response can be ignored for a VollTextSuche
	var fld = document.getElementById(fldid);
	var url = 'scripts/set_formval.php?fld=' + fld.name + '&val=' + escape(fld.value);
	xmlhttp.open("GET", prefix + url, true);
	if (fldid == 'f_rlvorname' || fldid == 'f_rlnachname' ||
		fldid == 'f_htvorname' || fldid == 'f_htnachname')
		// Send a request for Reiseleiter-Felder
		xmlhttp.onreadystatechange = persWertHttpState;
	else
		// A request for Volltext- oder Toursuche
		xmlhttp.onreadystatechange = fld.name == "f_vtsuche" ? vtsWertHttpState : tourWertHttpState;
	xmlhttp.send(null);
	return;
}

function reiseDaten() {
	var xmlDocument = xmlhttp.responseXML;
	// alert(xmlhttp.responseText);
	var rn = xmlDocument.getElementsByTagName('rn')[0].firstChild.data;
	var titel = xmlDocument.getElementsByTagName('titel')[0].firstChild.data;
	var spanObj = document.getElementById('reiseShow');
	var textObj = document.createTextNode(titel);
	var obj = document.getElementById('euro');
	var rno = document.getElementById('f_reisenummer');
	var land = '', von = '', bis = '', preis = '';
	delKids(spanObj);

		land = xmlDocument.getElementsByTagName('land')[0].firstChild.data;
		if (land == '-') {
			// We got no data
			land = '';
			spanObj.appendChild(textObj);
			obj.style.visibility = "hidden";
			rno.className = 'myField fehlerfarbe';
			}
		else {
			// Link einsetzen
			linkObj = document.createElement('a');
			linkObj.setAttribute('href',xmlDocument.getElementsByTagName('file')[0].firstChild.data);
			linkObj.setAttribute('title','Zur Reisebeschreibung');
			spanObj.appendChild(linkObj);
			// MSIE mag es nicht wenn der Textknoten vor dem Einhängen angehängt wird
			spanObj.childNodes[0].appendChild(textObj);
			obj.style.visibility = "visible";
			rno.className = 'myField weissefarbe';
			von = xmlDocument.getElementsByTagName('von')[0].firstChild.data;
			bis = xmlDocument.getElementsByTagName('bis')[0].firstChild.data;
			preis = xmlDocument.getElementsByTagName('preis')[0].firstChild.data + ',-';
			}

	obj = document.getElementById('f_reiseland');
	obj.value = land;
	obj = document.getElementById('f_reisevon');
	obj.value = von;
	obj = document.getElementById('f_reisebis');
	obj.value = bis;
	obj = document.getElementById('f_reisepreis');
	obj.value = preis;
	return;
}

function reiseDatenHttpState() {
	if (xmlhttp.readyState == 4) {
		if ( xmlhttp.status == 200) {
			// daten erfolgreich geladen: starte Verarbeitung
			reiseDaten();
		} else {
			alert("Fehler beim Abrufen der Reisedaten - Status " + xmlhttp.status);
			alert("Statusmeldung vom Server: " + xmlhttp.statusText);
		}
	}
	return;
}

// This is called at onBlur() of the reisenr-Field of the booking form
function neueReiseNr(val) {
	if (! ajaxok) return;
	xmlhttp = getXMLHttpRequest();
	// Call "reisedaten.php" on the server
	var url = '../scripts/reisedaten.php?rn=' + val;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = reiseDatenHttpState;
	xmlhttp.send(null);
	return;
}

function dummyHttp() {
	return;
}

// This is a generic function to write an entry to the web log (zB onclick PDF-Anzeige)
function weblog(kuerzel,p1,p2) {
	if (! ajaxok) return;
	xmlhttp = getXMLHttpRequest();
	// Call "weblog.php" on the server
	var url = '../scripts/weblog.php?kl=' + kuerzel + '&p1=' + p1 + '&p2=' + p2;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = dummyHttp;
	xmlhttp.send(null);
	return;
}
