/* URL to the PHP page called for receiving suggestions for a keyword*/
var xmlUrl = "http://www.flughafenklick.de/search.php";
/* the keyword for which an HTTP request has been initiated */
var httpRequestKeyword = "";
var httpRequestType = "";
/* the last keyword for which suggests have been requested */
var userKeyword = "";
var userType = "";
/* number of suggestions received as results for the keyword */
var suggestions = 0;
/* the maximum number of characters to be displayed for a suggestion */
var suggestionMaxLength = 10;
/* flag that indicates if the up or down arrow keys were pressed
the last time a keyup event occurred */
var isKeyUpDownPressed = false;
/* the last suggestion that has been used for autocompleting the keyword */
//var autocompletedKeyword = "";
/* flag that indicates if there are results for the current requested keyword*/
var hasResults = false;
/* the identifier used to cancel the evaluation with the clearTimeout method. */
var timeoutId = -1;
/* the currently selected suggestion (by arrow keys or mouse)*/
var position = -1;
/* cache object containing the retrieved suggestions for different keywords */
var oCache = new Object();
/* the minimum and maximum position of the visible suggestions */
var minVisiblePosition = 0;
var maxVisiblePosition = 9;
// when set to true, display detailed error messages
var debugMode = false;
/* the XMLHttp object for communicating with the server */
var xmlHttpGetSuggestions = createXmlHttpRequestObject();
/* the onload event is handled by our init function */
//window.onload = init;
var checkForChangesHandler = null;
// creates an XMLHttpRequest instance
function createXmlHttpRequestObject()
{
// will store the reference to the XMLHttpRequest object
var xmlHttp;
// this should work for all browsers except IE6 and older
try
{
// try to create XMLHttpRequest object
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
// assume IE6 or older
var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP");
// try every prog id until one works
for (var i=0; i"
// create a new array entry in the cache
if(!oCache[type])
oCache[type] = new Array();
if(!oCache[type][keyword])
oCache[type][keyword] = new Array();
oCache[type][keyword][0] = new Array();
oCache[type][keyword][1] = new Array();
// add all the values to the keyword's entry in the cache
for(i=0; i"
// check to see if the keyword is already in the cache
if(oCache[type] && oCache[type][keyword])
return true;
/*
// try to find the biggest prefixes
for(i=keyword.length-2; i>=0; i--)
{
// compute the current prefix keyword
var currentKeyword = keyword.substring(0, i+1);
// check to see if we have the current prefix keyword in the cache
if(oCache[type][currentKeyword])
{
// the current keyword's results already in the cache
var cacheResults = oCache[type][currentKeyword][0];
// the results matching the keyword in the current cache results
var searchResults = new Array();
var searchResultsSize = 0;
var resultsResults = new Array();
var resultsResultsSize = 0;
// try to find all matching results starting with the current prefix
for(j=0;jgetSuggestions: " +keyword+",="" "+type+" "
/* continue if keyword isn't null and the last pressed key wasn't up or
down */
if(keyword != "" && !isKeyUpDownPressed)
{
// check to see if the keyword is in the cache
isInCache = checkCache(keyword, type);
// if keyword is in cache...
if(isInCache == true)
{
if(debugMode)document.getElementById('debugDiv').innerHTML += "isInCache: "+keyword+" "
// retrieve the results from the cache
httpRequestKeyword=keyword;
httpRequestType=type;
userKeyword=keyword;
userType=type;
// display the results in the cache
displayResults(keyword, type, oCache[type][keyword][0], oCache[type][keyword][1]);
}
// if the keyword isn't in cache, make an HTTP request
else
{
if(xmlHttpGetSuggestions)
{
try
{
/* if the XMLHttpRequest object isn't busy with a previous
request... */
if (xmlHttpGetSuggestions.readyState == 4 ||
xmlHttpGetSuggestions.readyState == 0)
{
if(debugMode)document.getElementById('debugDiv').innerHTML += "NotInCache: "+keyword+" "
httpRequestKeyword = keyword;
httpRequestType = type;
userKeyword = keyword;
userType = type;
xmlHttpGetSuggestions.open("GET",
xmlUrl + "?keyword=" + keyword + "&type=" + encode(type), true);
xmlHttpGetSuggestions.onreadystatechange =
handleGettingSuggestions;
xmlHttpGetSuggestions.send(null);
}
// if the XMLHttpRequest object is busy...
else
{
// retain the keyword the user wanted
userKeyword = keyword;
userType = type;
// clear any previous timeouts already set
if(timeoutId != -1)
clearTimeout(timeoutId);
// try again in 0.5 seconds
timeoutId = setTimeout("getSuggestions(userKeyword, userType);", 500);
}
}
catch(e)
{
displayError("Can't connect to server:\n" + e.toString() + "\nLine: "+ e.lineNumber);
}
}
}
}
}
/* transforms all the children of an xml node into an array */
function xmlToArray(resultsXml)
{
// initiate the resultsArray
var resultsArray= new Array();
// loop through all the xml nodes retrieving the content
for(i=0;i= 0
|| response.indexOf("error:") >= 0
|| response.length == 0)
throw(response.length == 0 ? "Void server response." : response);
// retrieve the document element
response = xmlHttpGetSuggestions.responseXML.documentElement;
// initialize the new array of functions' names
searchArray = new Array();
resultsArray = new Array();
// check to see if we have any results for the searched keyword
if(response.childNodes.length)
{
/* we retrieve the new functions' names from the document element as
an array */
searchArray= xmlToArray(response.getElementsByTagName("search"));
if(debugMode)document.getElementById('debugDiv').innerHTML += searchArray.length+" "
resultsArray= xmlToArray(response.getElementsByTagName("results"));
}
// check to see if other keywords are already being searched for
if(httpRequestKeyword == userKeyword)
{
if(debugMode)document.getElementById('debugDiv').innerHTML += "displayResults "
// display the results array
displayResults(httpRequestKeyword, httpRequestType, searchArray, resultsArray);
}
else
{
if(debugMode)document.getElementById('debugDiv').innerHTML += "going to addToCache "
// add the results to the cache
// we don't need to display the results since they are no longer useful
addToCache(httpRequestKeyword, httpRequestType, searchArray, resultsArray);
}
}
/* populates the list with the current suggestions */
function displayResults(keyword, type, searchArray, resultsArray)
{
// start building the HTML table containing the results
var div = "";
// if the searched for keyword is not in the cache then add it to the cache
if((!oCache[type] || !oCache[type][keyword]) && keyword)
addToCache(keyword, type, searchArray, resultsArray);
// if the array of results is empty display a message
if(searchArray.length == 0)
{
div += "";
// set the flag indicating that no results have been found
// and reset the counter for results
hasResults = false;
suggestions = 0;
}
// display the results
else
{
// resets the index of the currently selected suggestion
position = -1;
// resets the flag indicating whether the up or down key has been pressed
isKeyUpDownPressed = false;
/* sets the flag indicating that there are results for the searched
for keyword */
hasResults = true;
// get the number of results from the cache
suggestions = oCache[type][keyword][0].length;
// loop through all the results and generate the HTML list of results
for (var i=0; i"
// set the string link for the for the current function
// to the name of the function
// start building the HTML row that contains the link to the
// PHP help page of the current function
div += "" +
"";
// check to see if the current function name length exceeds the maximum
// number of characters that can be displayed for a function name
/*if(crtFunction.length <= suggestionMaxLength)
{
// bold the matching prefix of the function name and of the keyword
div += "" +
crtFunction.substring(0, httpRequestKeyword.length) +
""
div += crtFunction.substring(httpRequestKeyword.length,
crtFunction.length) +
"";
}
else
{
// check to see if the length of the current keyword exceeds
// the maximum number of characters that can be displayed
if(httpRequestKeyword.length < suggestionMaxLength)
{
// bold the matching prefix of the function name and that of the keyword
div += "" +
crtFunction.substring(0, httpRequestKeyword.length) +
""
div += crtFunction.substring(httpRequestKeyword.length,
suggestionMaxLength) +
"";
}
else
{
// bold the entire function name
div += "" +
crtFunction.substring(0,suggestionMaxLength) +
""
}
}*/
//div += "" // hier hab ich den zweiten wert raus gemacht
div += "";
}
}
// end building the HTML table
div += "
";
// retrieve the suggest and scroll object
var oSuggest = document.getElementById("suggest");
var oScroll = document.getElementById("scroll");
// update the suggestions list and make it visible
oSuggest.innerHTML = div;
var tempSuggestions = suggestions;
if(hasResults && tempSuggestions > 0){
if(tempSuggestions > maxVisiblePosition)
tempSuggestions = 10;
}else{
tempSuggestions = 1;
}
oScroll.style.display = "";
// scroll to the top of the list
oScroll.scrollTop = 0;
oSuggest.style.display = "";
setScrollDivDimensions();
if(tempSuggestions > 0){
var firstTd = document.getElementById("td0");
var tdOffsetHeight = 17;
if(firstTd.offsetHeight)
tdOffsetHeight = firstTd.offsetHeight;
//oScroll.style.height = ((tempSuggestions * tdOffsetHeight) + 2)+"px"
}
// if we had results we apply the type ahead for the current keyword
// if(searchArray.length > 0)
// autocompleteKeyword();
}
function setScrollDivDimensions(){
//try{
var objKeyword = document.getElementById("keyword");
var pos = findPos(objKeyword);
if(objKeyword.offsetHeight)
pos[1] += objKeyword.offsetHeight
else
pos[1] += 15;
var oSuggest = document.getElementById("suggest");
var oScroll = document.getElementById("scroll");
oScroll.style.width = objKeyword.offsetWidth+"px"
try{
if(oSuggest.getElementsByTagName('table')[0].offsetWidth > objKeyword.offsetWidth)
oScroll.style.width = (oSuggest.getElementsByTagName('table')[0].offsetWidth+20)+"px"
}catch(e){}
oScroll.style.left = pos[0]+"px"
oScroll.style.top = pos[1]+"px"
//}catch(e){}
}
/* function that periodically checks to see if the typed keyword has changed */
function checkForChanges()
{
// retrieve the keyword object
var keyword = document.getElementById("keyword").value;
if (isNaN(keyword)) {
var type="name";
} else {
if (keyword.substr(0,1)=="0") {
var type="vorwahl";
} else {
var type="plz";
}
}
// var type = "name";
// var type = document.getElementById("t").options[document.getElementById("t").selectedIndex].value;
// check to see if the keyword is empty
if(keyword == "" || keyword=="Meinen Ort finden")
{
// hide the suggestions
hideSuggestions();
// reset the keywords
userKeyword="";
userType=type;
httpRequestKeyword="";
httpRequestType=type;
clearTimeout(checkForChangesHandler)
checkForChangesHandler = setTimeout("checkForChanges()", 500);
return;
}
// set the timer for a new check
clearTimeout(checkForChangesHandler)
checkForChangesHandler = setTimeout("checkForChanges()", 500);
// check to see if there are any changes
if((userKeyword != keyword || userType != type) &&
//(autocompletedKeyword != keyword) &&
(!isKeyUpDownPressed))
// update the suggestions
getSuggestions(keyword, type);
}
/* function that handles the keys that are pressed */
function handleKeyUp(e)
{
// get the event
e = (!e) ? window.event : e;
// get the event's target
target = (!e.target) ? e.srcElement : e.target;
if (target.nodeType == 3)
target = target.parentNode;
// get the character code of the pressed button
code = (e.charCode) ? e.charCode :
((e.keyCode) ? e.keyCode :
((e.which) ? e.which : 0));
// check to see if the event was keyup
if (e.type == "keyup")
{
isKeyUpDownPressed =false;
if(document.getElementById('scroll').style.display != "none"){
// check to see we if are interested in the current character
if ((code < 13 && code != 8) ||
(code >=14 && code < 32) ||
(code >= 33 && code <= 46 && code != 38 && code != 40) ||
(code >= 112 && code <= 123))
{
// simply ignore non-interesting characters
}
else{
// if the down arrow is pressed we go to the next suggestion
var trOffsetHeight = 17;
if(code == 40)
{
newTR=document.getElementById("tr"+(++position));
oldTR=document.getElementById("tr"+(--position));
// deselect the old selected suggestion
if(position>=0 && position maxVisiblePosition)
{
try{
trOffsetHeight = oldTR.offsetHeight;
}catch(e){}
oScroll = document.getElementById("scroll");
oScroll.scrollTop += trOffsetHeight;
maxVisiblePosition += 1;
minVisiblePosition += 1;
}
}
else
// if the up arrow is pressed we go to the previous suggestion
if(code == 38)
{
newTR=document.getElementById("tr"+(--position));
oldTR=document.getElementById("tr"+(++position));
// deselect the old selected position
if(position>=0 && position <= suggestions - 1)
{
oldTR.className = "";
}
// select the new suggestion and update the keyword
if(position > 0)
{
newTR.className = "highlightrow";
updateKeywordValue(newTR);
position--;
// scroll up if the current window is no longer valid
if(position"
}
/* function that updates the keyword value with the value
of the currently selected suggestion */
function updateKeywordValue(oTr)
{
if(debugMode)document.getElementById('debugDiv').innerHTML += "updateKeywordValue: td"+oTr.id.substring(2,oTr.id.length)+" "
// retrieve the keyword object
var oKeyword = document.getElementById("keyword");
// retrieve the link for the current function
var crtLink = document.getElementById("td" +
oTr.id.substring(2,oTr.id.length)).innerHTML;
if(debugMode)document.getElementById('debugDiv').innerHTML += "updateKeywordValue: "+crtLink+" "
// update the keyword's value
oKeyword.value = crtLink;
}
/* function that removes the style from all suggestions*/
function deselectAll()
{
for(i=0; i"
if(theSrc.nodeName == "OPTION")
return false;
}catch(e){}
var oScroll = document.getElementById("scroll");
oScroll.style.display = "none";
}
/* function that selects a range in the text object passed as parameter */
function selectRange(oText, start, length)
{
// check to see if in IE or FF
if (oText.createTextRange)
{
//IE
var oRange = oText.createTextRange();
oRange.moveStart("character", start);
oRange.moveEnd("character", length - oText.value.length);
oRange.select();
}
else
// FF
if (oText.setSelectionRange)
{
oText.setSelectionRange(start, length);
}
oText.focus();
}
/* function that autocompletes the typed keyword*/
function autocompleteKeyword()
{
//retrieve the keyword object
var oKeyword = document.getElementById("keyword");
// reset the position of the selected suggestion
position=0;
// deselect all suggestions
deselectAll();
// highlight the selected suggestion
document.getElementById("tr0").className="highlightrow";
// update the keyword's value with the suggestion
// updateKeywordValue(document.getElementById("tr0"));
// apply the type-ahead style
selectRange(oKeyword,httpRequestKeyword.length,oKeyword.value.length);
// set the autocompleted word to the keyword's value
//autocompletedKeyword=oKeyword.value;
}
/* function that displays an error message */
function displayError(message)
{
// display error message, with more technical details if debugMode is true
if(debugMode)
alert("Error accessing the server! "+
(debugMode ? "\n" + message : ""));
}
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curleft,curtop];
}
function chSuggestBox(obj){
var days = 365;
var ex= new Date();
ex.setTime(ex.getTime()+(days*24*60*60*1000));
var ex = ex.toGMTString();
var oKeyword = document.getElementById("keyword")
if(obj.checked){
httpRequestType = userType = document.getElementById("t").options[document.getElementById("t").selectedIndex].value
httpRequestKeyword = userKeyword = "";
checkForChangesHandler = setTimeout("checkForChanges()", 500);
cset("suggest", "true", ex, "/");
oKeyword.onkeyup = handleKeyUp;
document.body.onresize = function(){ // IE
setScrollDivDimensions();
}
window.onresize = setScrollDivDimensions; // FF
document.getElementById('content').onclick = hideSuggestions
}else{
clearTimeout(checkForChangesHandler)
cset("suggest", "false", ex, "/");
oKeyword.onkeyup = null
document.body.onresize = null
window.onresize = null
document.getElementById('content').onclick = null
}
oKeyword.focus();
setCaretToEnd (oKeyword)
}
/*function chTypeSelect(obj){
var oCheckBox = document.getElementById("suggestBox");
if(oCheckBox.checked){
httpRequestType = userType = document.getElementById("t").options[document.getElementById("t").selectedIndex].value
httpRequestKeyword = userKeyword = "";
checkForChanges()
//alert("checkForChanges")
}
}
*/
function csearch(naam) {
var str = document.cookie;
var zstr = naam + "=";
var start = str.indexOf(zstr, 0);
if(start == -1) {
return false;
} else {
start += zstr.length;
var eind = str.indexOf(";", start);
if(eind == -1) eind = str.length;
return unescape(str.substring(start, eind));
}
}
function cset(name, value, expires, path) {
document.cookie = name+"="+escape(value)+";expires="+expires+";path="+path;
}
function setCaretToEnd (control) {
if (control.createTextRange) {
var range = control.createTextRange();
range.collapse(false);
range.select();
}
else if (control.setSelectionRange) {
control.focus();
var length = control.value.length;
control.setSelectionRange(length, length);
}
}