/*put in IQ-Share/IBE * /var loggingInfo = {};var defaultText = "City, town, airport or airport code (hc)";var noResultsText = "No results found (hc)";var noResultsLink = "http://luna.rent-at-avis.com/budgetonline/test/de/budget.nsf";var noResultsLinkText = "Try our advanced Search station  finder blubs (hc)";var timeoutlength = 500;*/var tah_location_info_time = 150;var stationinfos = {};var isRTL;var savedVal = "";$(document).ready(function(){	if( $.browser.msie && parseInt($.browser.version, 10) < 7  ){				$('.dropdowns').show();		$('.typeahead').hide();		$('.switchlink').hide();		return;	}		isRTL = $('body .bg').hasClass('rtl');		//$(':not( #sta_search:focus, #ilc_search:focus)')			//	$('#sta_search, #ilc_search').each( function(){	$( '#sta_search:not( :focus ), #ilc_search:not( :focus )' ).each( function(){		$(this).addClass( 'inactive' )		if( $( this ).val() == "" || $( this ).data( 'station' ) == ""  )			$(this).val( defaultText );	});		$('#sta_search, #ilc_search').keyup( handleSearchfield ); // bind keyevent to jquery	$('#sta_search, #ilc_search')		.focusin( function(){			_this = $(this);			_this.removeClass( 'inactive' );						if( $('.reslist:visible') && _this.next().find('.reslist:visible').length < 1 ) {				$('.reslist:visible').parent().andSelf().hide()			}			if( ( _this.data( 'country' ) !== "" || _this.data( 'station' ) !== "" ) && 1 > $('.reslist:visible').length ) {				savedVal = $(this).val()				$(this).val('')			}		})		.focusout( function(){			_this = $(this);						if( savedVal === "" ) {				_this					.removeData('station')					.removeAttr('data-station')					.removeData('country')					.removeAttr('data-country')			//	$('.reslist:visible').hide();					.removeClass('loading')								}			if( ( _this.data( 'country' ) !== "" || _this.data( 'station' ) !== "" ) && savedVal !== "" ) {				_this.val( savedVal ? savedVal : defaultText )			}			if( $( this ).val() == "" || $( this ).data( 'station' ) == ""  )				$(this)					.val( defaultText )					.addClass( 'inactive' );		});		$('#qb .head .switchlink a').click(function(e){		e.preventDefault();		$('.typeahead, .dropdowns').toggle();		TAH_log( e.currentTarget )	});		$('#ilc_searchform_ro td .extraLink').click(function(){		$('#ilc_searchform_ro').remove();		$('#ilc_searchform').show();	});		$('#get_a_quote').hover(function(){		TAH_log( $(this) );	});		$('.noreslink').live('click', function () {		TAH_log( $(this)[0]);		$.ajax(			gTALgPath,			{				cache: false,				async: false,				data: loggingInfo			}		);	});});	var tah_requestTimer;getResultsFromSearch = function( elem ) {	// display loading thingie...	$( elem ).addClass( 'loading' )	if( $(elem).val().length >= 3 ) {		$request = $.ajax({			//url: 'request/getStations.json',			url: ( gStationsURL + '/typeaheadsearch?OpenAgent' ),			cache: false,			dataType: 'json',			data: {				"IBEOwner": gIBEOwner,				"LNG": gLng,				"query": $(elem).val()			},			success: function( json ){				//console.log( elem );				renderResultList(elem, json);				// hide loading thingie...				$(elem).removeClass( 'loading' )			}			/*,			error: function(e){				try {				console.error( "Error:" )				console.log( e )				} catch (e) {				alert( "Error: \n" + e )				}			}*/		});	}};handleSearchfield = function( evt ) {if( evt.which != 37 && evt.which != 39 ) {	if ( typeof( $request ) != "undefined" ) {		$request.abort();	}	_field = evt.currentTarget; //jquery dom element	savedVal = "";	$(_field).removeData('station').removeAttr( 'data-station' );	//console.log(  $( _field ).val().length )	if( $( _field ).val().length < 3 ) {		$( _field )			.removeClass( 'loading' )			//.removeData( 'station' )			//.removeAttr( 'data-station' )			.removeData( 'country' )			.removeAttr( 'data-country' );		$( '.resWrapper' ).css({"margin-top":""}).hide();		return;	}	try {		window.clearTimeout( tah_requestTimer );	} catch(e){}		tah_requestTimer = window.setTimeout( function(){		getResultsFromSearch( _field )	}, timeoutlength ); 	}		};tah_showStationInfo = function( obj ){	var _this = $(obj);	var _wrap = _this.parents('.resWrapper');	var _list = _this.parents('.reslist');		//_list.css( {'overflow':'auto','max-height':'350px'})	var $overlay = $('#tah_location_info');	var _data = _this.data( 'code' );		_list.mouseleave(function(){		$('#tah_location_info').hide();	});		if( 1 > $overlay.length ) {		$overlay = $('<div/>', {			"id": 'tah_location_info',			"css": {				"position": "absolute",				"top": _wrap.offset().top + "px",				"left": isRTL ? _wrap.offset().left - 224  : ( _wrap.offset().left + _wrap.outerWidth() ) + "px" 			}		}).appendTo( $( 'body' ) );	} else {		$overlay		.html('')		.css({			"position": "absolute",			"top": _wrap.offset().top + "px",			"left": isRTL ? _wrap.offset().left - 224  : ( _wrap.offset().left + _wrap.outerWidth() ) + "px"		}).show();	};	$overlay		.html( stationinfos[ _data ] );};tah_hideStationInfo = function( obj ){//	$('#tah_location_info').hide();	};tah_click = function( obj ) {	//console.log(obj)	TAH_log( obj );		var _obj = $(obj)	var searchform = _obj.parents('div.reslist').parents('div[id$="searchform"]:first');	var input = _obj.parents('div.reslist').parents('div.typeahead').find('input:first');	$('div.resWrapper:visible').hide();	//set input text 	inputtext = [];	_obj		.find('.name, .mne').each( function(idx,el){			inputtext.push( $(el).text() ) ;		});	if( _obj.hasClass( 'station' ) ) {		inputtext.push( _obj.prevAll('.ctyhead').text() )	} else {		inputtext.push( _obj.find('.ctyhead').text() )	}	input		.val( inputtext.join( ', ') )		.data( 'station', _obj.data( 'code' ) )		.data( 'country', _obj.data( 'ctr' ) )		.data( 'setmanually', "1" );			// prefill return location as well, if empty			if( input.attr('id') === 'sta_search' ) {		return_input = $('#ilc_search');//		if( !return_input.data('station') && !return_input.data('setmanually') ){		if( !return_input.data('setmanually') ){			//console.log($('#ilc_searchform_ro td.returnStation'));			$('#ilc_searchform_ro .returnStation').text( inputtext.join(', ') );			return_input				.val( inputtext.join( ', ') )				.data( 'station', _obj.data( 'code' ) )				.data( 'country', _obj.data( 'ctr' ) );		}	}}/*** renderResultList* PARAMS: *   target (DOM Target Element)*   results (JSON from Request)* DESC: renders resultlist from*/renderResultList = function( target, results ) {	TAH_log(results);		if( results['globals']['total'] === 0 ) {				$(target)			.next('.resWrapper')			.find('.reslist').html(				'<div class=noresults>' 					+ '<p>' + noResultsText + '</p>' 					+ '<p><a class="noreslink" href="' + noResultsLink + '">' + noResultsLinkText + '</a></p>' + 				'</div>'			).parent().andSelf().show().stop().find('.hint').hide();				/* HACKING FOR CHROME ON A MAC	IE9 IE7-Mode	*/	if( 		$('.resWrapper:visible').offset().top <= $('.resWrapper:visible').prev().offset().top + 5	) {		$('.resWrapper:visible').css({"top": $('.resWrapper:visible').prev().offset().top + $('.resWrapper:visible').prev().outerHeight(), position: "absolute"})	}			$('body').one('click', function(ev){								$('.resWrapper:visible').css({"margin-top":""}).hide();			})					return;	} else {		$(target)			.next('.resWrapper').css({"margin-top":""})			.find('.hint,.reslist')			.andSelf()			.show();	}		entries = results["list"];	//stationinfos = entries;		resultslist = $(target).parent().find('.reslist').empty(); 	// define vars before, unscoped to not need to create them new every iteration	var newCity, 		newText, 		newImg;	var c = 0;	//timestart = new Date();	for( c in entries ) {	/**		render cities	*/		_this = entries[c];		_onlyone = _this.sta.length;		if( 1 < _onlyone ) {			// more than one station: render normal header, not clickable			newCityString = '<div class="city"><div class="ctyhead" onmouseover="tah_hideStationInfo(this)">';		} else {			// only one station: render clickable header						newCityString = '<div class="city only-1" data-code="' + _this['sta'][0][1] + '" data-ctr="' + _this['sta'][0][2] + '"  onmouseover="tah_showStationInfo(this)" onmouseout="tah_hideStationInfo()" onclick="tah_click(this)"><div class="ctyhead">';		}		newCityString += '<img width=22 align=absmiddle src="' + '/budgetonline/images.nsf/CountryFlagImage/' + _this.flg + '.png/$FILE/' + _this.flg + '.png" />'		newCityString += '<span class="ctyname">' + _this.cty + '</span>';		newCityString += '</div>';				var newSta, newStaName, newStaMNE, newStaIcon, newText		for( s in _this.sta ) {			// numstations++; //DEBUG			// ["Flughafen Frankfurt-Hahn","MNEMONIC Code","CTR-Code",1,"zip", "Overlay Info"]						__this = _this.sta[ s ];						stationinfos [ __this[1] ] = __this[ 5 ];						if( 1 < _onlyone ){				newCityString += '<div class="station" data-code="' + __this[1] + '" data-ctr="' + __this[2] + '" onmouseover="tah_showStationInfo(this)" onmouseout="tah_hideStationInfo()" onclick="tah_click(this)">';			} else {				newCityString += '<div class="station" data-code="' + __this[1] + '" data-ctr="' + __this[2] + '" >';			}			if( 4 !== __this[3] ) {				// any special station (airport, port, rail)				newCityString += '<img class="staImg" src="' + gImagesURL + '/type_' + __this[3] + '.png" />'			}						newCityString += '<div class="name">' + __this[0] + '</div>';						if ( 1 === __this[3] ) {				// if airport station (type = 1)				newCityString += '<span class="mne">' + __this[1] + '</span>' ;			}			if ( 4 === __this[3] && __this[4] !== ''  ) {				// if downtown station (type = 4)				newCityString += '<span class="mne">' + __this[4] + '</span>' ;			}			newCityString += '</div>';		}		// finally append city and stations to 		newCityString += '</div>';				/**		*	Highlighting for Search results (just demo)		*	TODO: This needs some work to replace the case-correct texts		* /		search = new RegExp( ">.+"  + $(target).val() + ".+</", 'gi' );		console.log( newCityString )		newCityString = newCityString.replace(search, function(match, i) {	  	  return '<span class="hl" style="background-color:yellow">' + match + '</span>';		});		/**/				$(resultslist).append(newCityString).parent('div.resWrapper').show();	};	/* HACKING FOR CHROME ON A MAC	IE9 IE7-Mode	*/	if( 		$('.resWrapper:visible').offset().top <= $('.resWrapper:visible').prev().offset().top + 5	) {		$('.resWrapper:visible').css({"top": $('.resWrapper:visible').prev().offset().top + $('.resWrapper:visible').prev().outerHeight(), position: "absolute"})	}	// now, attach a global click event whcih will be executed ONE time:	$('body').one('click', function(ev){		//console.log(ev)		$('.resWrapper:visible').css({"margin-top":""}).hide();	})	/*	timeend = new Date();	$(target).parent().find('.resglobals').html(		"Rendering: " + ( timeend - timestart ) + "\n" + 		"Searchterm: " + $(target).val()	); 	*/}TAH_log = function ( el ) {/*INPUT :	CTR (mandatory): 2 letter website identifier	LNG (mandatory), default GB: 2 letter language code	Q (mandatory), search term to search for locations	T (madatory) , type of search, T=type ahead, D=dropdown, O=other (user clicked on link when no results have been found)	C (optional), number of all results (leave empty when otehr than type-ahead search is used)	P (optional), position of choosen location in result list (leave empty when otehr than type-ahead search is used)	S (optional) , 3 letter Mnemonic code of choosen location (leave empty when otehr than type-ahead search is used)*/	_this = $(el);		//loggingInfo.Q = $('#sta_search').val();	loggingInfo.T = $('.typeahead').is(':visible') && $('#sta_search').data('setmanually') ? 'T' : 'D';	if( el.globals ) {		//console.log('i can haz json')		loggingInfo.C = el.globals.total ? el.globals.total : 0;	}	if ( _this.hasClass( 'noreslink' ) ) {		// click link when no result is available		loggingInfo.T = 'O'	}	if ( _this.hasClass( 'station' ) || _this.hasClass( 'city' ) ) {		//loggingInfo.C set by request handler		loggingInfo.Q = $('#sta_search').val();		loggingInfo.P = (_this.prevAll('.station')).length + 1;		loggingInfo.S = _this.data('code')	} else {		loggingInfo.S = $('#sta_search').data('station');	}	if( loggingInfo.T == 'D' ) {				delete( loggingInfo.S );		loggingInfo.S = $('#etastation').val();	}	//console.log( loggingInfo.S );}// end
