var http_request; function search() { var query = encodeURI(document.searchform.q.value); var request_url = 'xml.php?q='+query+' -cgi-bin -shoutboxserver'; if( document.searchform.q.value.length>=3 ) { var resultdiv = document.getElementById('results'); if(resultdiv.childNodes.length>0) { var child = resultdiv.firstChild; resultdiv.removeChild( child ); } var msgDivNode = document.createElement("div"); var attr_class_msgDivNode = document.createAttribute("class"); attr_class_msgDivNode.nodeValue = "msg"; msgDivNode.setAttributeNode(attr_class_msgDivNode); var msg_img = document.createElement('img'); var attr_src_msg_img = document.createAttribute("src"); attr_src_msg_img.nodeValue = 'load.gif'; msg_img.setAttributeNode(attr_src_msg_img); msgDivNode.appendChild(msg_img); resultdiv.appendChild(msgDivNode); makeRequest(request_url); } else if( document.searchform.q.value.length<3 ) { var resultdiv = document.getElementById('results'); if(resultdiv.childNodes.length>0) { var child = resultdiv.firstChild; resultdiv.removeChild( child ); } var msgDivNode = document.createElement("div"); var attr_class_msgDivNode = document.createAttribute("class"); attr_class_msgDivNode.nodeValue = "msg"; msgDivNode.setAttributeNode(attr_class_msgDivNode); var msg_text = document.createTextNode('Bitte mindestens 3 Zeichen eingeben!'); msgDivNode.appendChild(msg_text); resultdiv.appendChild(msgDivNode); } } function makeRequest(url) { // Mozilla etc. if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); } // IE else if (window.ActiveXObject) { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } http_request.onreadystatechange = setContents; http_request.open('GET', url, true); http_request.send(null); } function setContents() { if (http_request.readyState == 4) { if(http_request.status == 200) { xml = http_request.responseText; updateResults(xml); } else { document.write('FEHLER beim XMLHttpRequest!'); } } } function updateResults(xml) { var resultdiv = document.getElementById('results'); if(resultdiv.childNodes.length>0) { var child = resultdiv.firstChild; resultdiv.removeChild( child ); } var results = Array(); results = createArrayFromXML(xml); var resultDivNode = document.createElement("div"); var attr_class_a_resultDivNode = document.createAttribute("class"); attr_class_a_resultDivNode.nodeValue = "searchitems"; resultDivNode.setAttributeNode(attr_class_a_resultDivNode); for( i=0; i0) { var child = resultdiv.firstChild; resultdiv.removeChild( child ); } var resultDivNode = document.createElement("div"); var attr_class_a_resultDivNode = document.createAttribute("class"); attr_class_a_resultDivNode.nodeValue = "msg"; resultDivNode.setAttributeNode(attr_class_a_resultDivNode); var msg_text = document.createTextNode('Nichts gefunden!'); resultDivNode.appendChild(msg_text); } resultdiv.appendChild(resultDivNode); } function createArrayFromXML( xmlDocument ) { xmlTemp = stringToDOM(xmlDocument); var results = xmlTemp.getElementsByTagName('searchresult'); var returnResults = new Array( results.length ); for( var i = 0; i < results.length; i++ ) { returnResults[i] = new Array(3); var _url = getValues( results[i], "url" ); var _title = getValues( results[i], "title" ); var _desc = getValues( results[i], "desc" ); returnResults[i][0] = _url; returnResults[i][1] = _title; returnResults[i][2] = _desc; } return returnResults; } function getValues( xmlDocument, strTagName ) { var xmlTags; xmlTags = xmlDocument.getElementsByTagName( strTagName ); var intLen = xmlTags.length; if( !intLen ) { return null; } else if( intLen == 1 ) { return xmlTags[ 0 ].firstChild.nodeValue; } else { var arrValues = new Array( ); for( var i = 0; i < intLen; i++ ) { arrValues[ i ] = xmlTags[ i ].firstChild.nodeValue; } return arrValues; } } function stringToDOM(varString) { if(typeof DOMParser != "undefined") { return (new DOMParser).parseFromString(varString, "text/xml"); } else if(typeof ActiveXObject != "undefined") { var parser = new ActiveXObject("Microsoft.XMLDOM"); parser.async = "false"; parser.loadXML(varString); return parser; } else if (typeof XMLHttpRequest != "undefined") { var req = new XMLHttpRequest; req.open("GET", "data:" + (contentType || "application/xml") + ";charset=utf-8," + encodeURIComponent(str), false); if (req.overrideMimeType) { req.overrideMimeType(contentType); } req.send(null); return req.responseXML; } } //