function toggle(id) {
	if(set[id]==0) {
		f_open(id)
	} else {
		f_close(id)
	}
	e(button).blur()
}

function f_open(id) {
	button="pm_"+id
	content="c_"+id
	tsrc=e(button).src
	tsrc=tsrc.replace('_p','_m');
	set[id]=1
	e(button).src=tsrc
	e(content).style.display='block'
}
function f_close(id) {
	button="pm_"+id
	content="c_"+id
	tsrc=e(button).src
	tsrc=tsrc.replace('_m','_p');
	set[id]=0
	e(button).src=tsrc
	e(content).style.display='none'
}

function suchen(q) {
	vorgang=0
	document.faq_search.q.value=document.faq_search.q.value.replace(/[^ \wüäö]/ig,'')

	for (var id in title) {
		f_close(id)
	}
	for (var id in restore_t) {
		temp='t_'+restore_t[id]
		e(temp).innerHTML=title[restore_t[id]]
	}
	for (var id in restore_a) {
		temp='c_'+restore_a[id]
		e(temp).innerHTML=text[restore_a[id]]
	}
	if(q.length>0 && q.length<3) {
		info("mind. 3 Zeichen erforderlich")
	} else if(q.length>=3) {
		query(q)
	} else {
		info("Suchbegriff eingeben:")
	}
	return false;
}

function query(q) {
	anzahl=0
	restore_t=new Array()
	restore_a=new Array()
	for (var id in title) {
		temp='found=title[id].search(/'+q+'/i)';
		eval(temp)
		if(found!=-1) {
			anzahl++
			f_open(id);
			if(level[id]==0) {
				restore_t.push(id)
				temp="temp=e('t_"+id+"').innerHTML=e('t_"+id+"').innerHTML.replace(/("+q+")/gi,'<span style=\"background-color:yellow;\">\$1</span>')";
				eval(temp)
			}
			if(level[id]==1) {
				restore_t.push(id)
				f_open(upper[id]);
				temp="temp=e('t_"+id+"').innerHTML=e('t_"+id+"').innerHTML.replace(/("+q+")/gi,'<span style=\"background-color:yellow;\">\$1</span>')";
				eval(temp)
			}
			if(level[id]==2) {
				restore_t.push(id)
				f_open(upper[upper[id]]);
				f_open(upper[id]);
				temp="temp=e('t_"+id+"').innerHTML=e('t_"+id+"').innerHTML.replace(/("+q+")/gi,'<span style=\"background-color:yellow;\">\$1</span>')";
				eval(temp)
			}
		}
		if(document.faq_search.volltext.checked==true && level[id]==2) {
			temp='found=text[id].search(/'+q+'/i)';
			eval(temp)
			if(found!=-1) {
				anzahl++
				restore_a.push(id)
				f_open(upper[upper[id]]);
				f_open(upper[id]);
				f_open(id);
				temp="temp=e('c_"+id+"').innerHTML=e('c_"+id+"').innerHTML.replace(/("+q+")/gi,'<span style=\"background-color:yellow;\">\$1</span>')";
				eval(temp)
			}
		}
	}

	if(anzahl==0 && vorgang==0 && document.faq_search.volltext.checked==false) {
		//alert('Keine Einträge gefunden.\nEs wird jetzt eine Volltextsuche durchgeführt.')
		vorgang=1
		document.faq_search.volltext.checked=true
		query(q)
	} else {
		if(anzahl==0) {
			info("keine Einträge gefunden")
		} else if(anzahl==1) {
			info("1 Eintrag gefunden")
		} else {
			info(anzahl+" Einträge gefunden")
		}
		log_faq(q,document.faq_search.volltext.checked,anzahl)
	}
}

function info(msg) {
	e('s_info').innerHTML=msg
}

function log_faq(query,volltext,ergebnisse) {
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();								// Mozilla, Safari, Opera, IE 7
	} else if (window.ActiveXObject) {
		try {
			xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');			// IE 5
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');	// IE 6
			} catch (e) {}
		}
	}

	if (!xmlHttp) {
		//alert("XMLHTTP-Instanz kann nicht erzeugt werden.\nBitte laden Sie die Seite neu.");
		return false;
	} else {
		xmlHttp.open("POST","/cgi-bin/faq_log.pl",true);
		var string=escape(query)+'|'+volltext+'|'+anzahl
		xmlHttp.send(string);

		// State Description 
		// 0 The request is not initialized 
		// 1 The request has been set up 
		// 2 The request has been sent 
		// 3 The request is in process 
		// 4 The request is complete

		//xmlHttp.onreadystatechange=function() {
		//	if(xmlHttp.readyState==4) {
		//		alert(xmlHttp.responseText)
		//	}
		//}
	}
}
