/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// XML Objekt
var XMLHTTP = null;
var sElementToReplace = "";
var bShowWait = true;
if ( window.XMLHttpRequest ) {
XMLHTTP = new XMLHttpRequest( );
}
else if ( window.ActiveXObject ) {
try {
XMLHTTP = new ActiveXObject( "Msxml2.XMLHTTP" );
}
catch ( ex ) {
try {
XMLHTTP = new ActiveXObject( "Microsoft.XMLHTTP" );
}
catch ( ex ) {
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// In Element externe Daten nachladen
var bAjaxRequestRunning = false;
function ajax_GetDataVia( spiElementToReplace, spiURL, spiParam, bpiSendViaPost, bpiReplace ) {
if ( bAjaxRequestRunning == false ) {
var sParam = null;
var sSendVia = "GET";
bAjaxRequestRunning = true;
sElementToReplace = spiElementToReplace;
if ( bpiSendViaPost ) {
sSendVia = "POST";
}
if ( spiParam.length > 0 ) {
if( bpiSendViaPost ) { sParam = spiParam; }
else { spiURL = spiURL + "?" + spiParam; }
}
x_ajax_Wait( );
XMLHTTP.open( sSendVia, spiURL );
if ( bpiSendViaPost ) { XMLHTTP.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ); }
if ( bpiReplace ) { XMLHTTP.onreadystatechange = x_ajax_AreaReplace; }
else { XMLHTTP.onreadystatechange = x_ajax_AreaAddAfter; }
XMLHTTP.send( sParam );
}
else {
alert( 'Request currently running...' );
}
}
function ajax_LoadContent( spiElementToReplace, spiURL ) {
var nPos = spiURL.indexOf( "?" );
if ( nPos > 0 ) {
var sURL = spiURL.substr( 0, nPos );
var sParam = spiURL.substr( nPos + 1, spiURL.length );
}
else {
var sURL = spiURL;
var sParam = "";
}
ajax_GetDataVia( spiElementToReplace, sURL, sParam, false, true );
}
function x_ajax_AreaReplace( ) {
if ( XMLHTTP.readyState == 4 ) {
var objHTML = document.getElementById( sElementToReplace );
objHTML.innerHTML = XMLHTTP.responseText;
bAjaxRequestRunning = false;
}
}
function x_ajax_AreaAddAfter( ) {
if ( XMLHTTP.readyState == 4 ) {
var objHTML = document.getElementById( sElementToReplace );
objHTML.innerHTML += XMLHTTP.responseText;
bAjaxRequestRunning = false;
}
}
function ajax_WaitImg( bpiSwitch ) {
if ( bpiSwitch ) {
bShowWait = true;
}
else {
bShowWait = false;
}
}
function x_ajax_Wait( ) {
if ( bShowWait ) {
var objHTML = document.getElementById( sElementToReplace );
objHTML.innerHTML = "
";
}
else {
bShowWait = true;
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Live Search
var sLSElement = '';
var sLSElementResult = '';
var bLSBrowserIE = false;
var sLSUrl = '';
var sLSParam = '';
var sLSLastQuery = '';
var bLSStyleIsSet = false;
var objLSHideTimer = null;
function ajax_livesearch_init( spiElementInput, spiElementResult, spiURL, spiParam ) {
sLSElement = spiElementInput;
sLSElementResult = spiElementResult;
sLSUrl = spiURL;
sLSParam = spiParam;
// add EventListener to element
if ( navigator.userAgent.indexOf( 'Safari' ) > 0 ) {
document.getElementById( sLSElement ).addEventListener( 'keydown', x_ajax_livesearch_event, false );
} else if ( navigator.product == 'Gecko' ) {
document.getElementById( sLSElement ).addEventListener( 'keypress', x_ajax_livesearch_event, false );
document.getElementById( sLSElement ).addEventListener( 'blur', x_ajax_livesearch_event, false );
} else {
document.getElementById( sLSElement ).attachEvent( 'onkeydown', x_ajax_livesearch_event );
bLSBrowserIE = true;
}
x_ajax_livesearch_set_style( );
x_ajax_livesearch_timer( );
}
function x_ajax_livesearch_event( event ) {
// perform action on event
if (event.keyCode == 40 ) {
//KEY DOWN
highlight = document.getElementById("livesearchHighlight");
if (!highlight) {
highlight = document.getElementById("returndresult").firstChild;
} else {
highlight.removeAttribute("id");
highlight.style.backgroundColor = "transparent";
highlight = highlight.nextSibling;
}
if (highlight) {
highlight.style.backgroundColor = "#abcdef";
highlight.setAttribute("id","livesearchHighlight");
}
}
else if (event.keyCode == 38) {
//KEY UP
highlight = document.getElementById("livesearchHighlight");
if (!highlight) {
highlight = document.getElementById("returndresult").lastChild.previousSibling;
}
else {
highlight.removeAttribute("id");
highlight.style.backgroundColor = "transparent";
highlight = highlight.previousSibling;
}
if (highlight) {
highlight.style.backgroundColor = "#abcdef";
highlight.setAttribute("id","livesearchHighlight");
}
}
else if (event.keyCode == 27) {
//ESC
x_ajax_livesearch_hide_element( );
}
else if (event.keyCode == 13) {
//Submit
var objElement = document.getElementById( sLSElement );
var highlight = document.getElementById("livesearchHighlight");
if ( highlight.value != '' ) {
objElement.value = highlight.getAttribute("title");
sLSLastQuery = objElement.value;
x_ajax_livesearch_hide_element( );
// pause( 1 );
}
return true;
}
x_ajax_livesearch_hide( );
}
function x_ajax_livesearch_timer( ) {
// check every x seconds on new input
window.setTimeout( "x_ajax_livesearch_search( )", 500 );
}
function x_ajax_livesearch_search( ) {
var objElement = document.getElementById( sLSElement );
x_ajax_livesearch_timer( );
if ( objElement.value != sLSLastQuery && objElement.value != '' ) {
var objElementResult = document.getElementById( sLSElementResult );
sLSLastQuery = objElement.value;
// abort current transaction if unsuccessful
if ( XMLHTTP && XMLHTTP.readyState < 4 ) {
XMLHTTP.abort( );
}
ajax_LoadContent( sLSElementResult, sLSUrl + '?' + sLSParam + '=' + sLSLastQuery );
objElementResult.style.display = "block";
x_ajax_livesearch_hide( );
}
else if ( objElement.value == '' ) {
sLSLastQuery = '';
x_ajax_livesearch_hide_element( );
}
}
function x_ajax_livesearch_hide( ) {
// destroy timer for hiding
if ( objLSHideTimer ) {
window.clearTimeout( objLSHideTimer );
}
objLSHideTimer = window.setTimeout( "x_ajax_livesearch_hide_element( )", 10000 );
}
function x_ajax_livesearch_hide_element( ) {
var highlight = document.getElementById("livesearchHighlight");
if ( highlight ) {
highlight.removeAttribute("id");
highlight.style.backgroundColor = "transparent";
}
document.getElementById( sLSElementResult ).style.display = "none";
}
function x_ajax_livesearch_set_style( ) {
var objElementResult = document.getElementById( sLSElementResult );
if( !bLSStyleIsSet ) {
document.getElementById(sLSElement).setAttribute("autocomplete","off");
objElementResult.style.border = "1px solid #999";
objElementResult.style.width = "240px";
objElementResult.style.padding = "0 8px";
objElementResult.style.backgroundColor = "#FFF";
objElementResult.style.fontFamily = "arial";
objElementResult.style.marginTop = "2px";
objElementResult.style.textAlign = "left";
objElementResult.style.zIndex = "2";
bLSStyleIsSet = true;
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// Form submit
function ajax_SubmitForm( spiParentElement, spiElementToReplace, spiURL, spiParam, spiHideElementAfterSubmit ) {
var sParam = sGetElementValues( spiParentElement );
if( spiHideElementAfterSubmit.length > 0 ) {
document.getElementById( spiHideElementAfterSubmit ).style.display = "none";
}
if( spiParam.length > 0 ) {
spiParam += '&';
}
else {
spiParam = '';
}
ajax_LoadContent( spiElementToReplace, spiURL + '?' + spiParam + sParam );
}
function sGetElementValues( spiParentElement ) {
var sParam = new Array( );
sParam[0] = '';
sParam[1] = sGetValuesFromElements( spiParentElement, 'input' );
sParam[2] = sGetValuesFromElements( spiParentElement, 'textarea' );
for( i=1; i < sParam.length; i++ ) {
if( sParam[0].length > 0 && sParam[i].length > 0 ) {
sParam[0] += '&';
}
sParam[0] += sParam[i];
}
return sParam[0];
}
function sGetValuesFromElements( spiParent, spiHTMLElement ) {
var sParam = '';
var nCount = 0;
var objaSubitems = document.getElementById( spiParent ).getElementsByTagName( spiHTMLElement );
for (nCount=0; nCount < objaSubitems.length; nCount++) {
if ( sParam.length > 0 ) {
sParam += '&';
}
sParam += objaSubitems[nCount].name + '=' + sGetUrlText( objaSubitems[nCount].value );
}
return sParam;
}
function sGetUrlText ( spiText ) {
// Replaces all bad characters in text with good chars: ' ' -> '%20'
var sNewText = spiText;
sNewText = sNewText.replace( ' ', '%20' );
return sNewText;
}