	
	var ajax = null;
	var searchcriteria = '';
	var init_remarks = //'<div id="right">' +
          '<h2><span><span>Remarks</span></span></h2>' +
          /*'<p><strong>This is a BETA version of the Router-DB, so it can happen that not all' +
          '  information are correct and not all related files are correctly linked. So if you have' +
          '  doubts please refer to the <a href="http://www.dd-wrt.com/wiki/index.php/Supported_Devices" target="_blank">'+
          '  supported device list</a> and/or the <a href="http://www.dd-wrt.com/dd-wrtv2/down.php">' +
          '  downloads section</a>.</strong></p>' +*/
          '<p>Please enter at least 3 characters to search for the router model, manufacturer' +
          '  and revision of the router you are seeking information/downloads about.</p>' +
          '<p>The list will continuous update while you are typing, so just try until the' +
          '  desired router model shows up.</p>' +
          '<p> If the router is not listed, please follow the instructions for <a href="router-detection">' +
          '  device detection</a> to find out if router support is possible.</p>'/* +
        '</div>'*/;
	
	/*Event.observe(window, 'load', function() {
		$('searchcriteria').observe('keyup', searchRouters);
		$('searchcriteria').observe('click', searchRouters);
	});*/
	// JQuery Syntax
	$(document).ready( function() {
		$("#searchcriteria").bind("click keyup", function() {
			//searchRouters();
			initSearch();
		});
		showRemarks( init_remarks );
	});
	
	var search_timeout = null;
	function initSearch() {
		clearTimeout( search_timeout );
		search_timeout = setTimeout( "searchRouters()", 800);
	}
	
	function searchRouters() {
		/*var url = 'routerResult.php';
		if( ajax == null && $F('searchcriteria').length > 2) {
			searchcriteria = $F('searchcriteria');
			ajax = new Ajax.Request(url, {
				method: 'post',
				parameters: { action: 'routerList', criteria: $F('searchcriteria') },
				onSuccess: function(transport) {
					$('routerlist').update(transport.responseText);
					},
				onComplete: function(transport) {
					ajax = null;
					if( searchcriteria != $F('searchcriteria')) {
						searchRouters();
						}
					}
				});
		} else if( ajax == null ) {
			var url = 'routerResult.php';
			ajax = new Ajax.Request(url, {
				method: 'post',
				onSuccess: function(transport) {
					$('routerlist').update(transport.responseText);
					},
				onComplete: function(transport) {
					ajax = null;
				}
			});
			//$('routerlist').update('<p style="margin: 0 0 10px 0;">Please enter at least 3 character of the router\'s name, manufacturer and/or revision.</p>');
		}*/
		// JQuery Syntax
		var url = '../../routerdb/de/routerResult.php';
		if( $("#searchcriteria").get(0).value.length > 2 ) {
			$.ajax({
				url: url,
				type: 'POST',
				data: ({
					action: 'routerList',
					criteria: $("#searchcriteria").get(0).value,
					site: 'drupal'
					}),
				dataType: 'html',
				async: false,
				//timeout: 1000,
				success: function( data ) {
					// form the resulting html string to a JQuery object
					result = $( data );
					// routerlist
					$('#routerlist').html( result.get(0) );
					// remarks
					showRemarks( result.get( result.size() - 1 ) );
					},
				complete: function( XMLHttpRequest, textStatus ) {
				//	alert( 'Ajax error: ' + textStatus );
					}
				}
			);
		} else {
			$.ajax({
				url: url,
				type: 'POST',
				data: ({
					site: 'drupal'
					}),
				success: function( data ) {
					// form the resulting html string to a JQuery object
					result = $( data );
					// routerlist
					$('#routerlist').html( result.get(0) );
					// remarks
					showRemarks( result.get( result.size() - 1 ) );
					}
				}
			);
		}
	}
	
	function showDetails( id ) {
		/*var url = 'routerResult.php';
		ajax = new Ajax.Request(url, {
			method: 'post',
			parameters: { action: 'routerDetail', id: id },
			onSuccess: function(transport) {
				$('routerlist').update(transport.responseText);
				},
			onComplete: function(transport) {
				ajax = null;
				}
			});*/
		var url = '../../routerdb/de/routerResult.php';
		$.ajax({
			url: url,
			type: 'POST',
			data: ({
				action: 'routerDetail',
				id: id,
				offset: '../../routerdb/de/',
				site: 'drupal'
				}),
			dataType: 'html',
			async: false,
			success: function( data ) {
				// form the resulting html string to a JQuery object
				result = $( data );
				// routerlist
				$('#routerlist').html( result.get(0) );
				// remarks
				showRemarks( result.get( result.size() - 1 ) );
				}
			}
		);
	}
	
	updateVersion = function() {
		/*var id = $F('id');
		var build = $F('build');
		//$('build_display').update( build );
		
		var url = 'routerResult.php';
		ajax = new Ajax.Request(url, {
			method: 'post',
			parameters: { action: 'routerFiles', id: id, build: build },
			onCreate: function() {
				$('build').disabled = true;
				loadingTimeout = window.setTimeout( 'showLoadingMessage()', 500 );
				},
			onSuccess: function(transport) {
				clearTimeout( loadingTimeout );
				var data = transport.responseText.evalJSON();
				$('filelist').update(urldecode(data.files));
				if( data.versionComment.length > 0 ) {
					$('versionComment').update(urldecode(data.versionComment));
				} else {
					$('versionComment').update('&nbsp;');
				}
				},
			onComplete: function(transport) {
				ajax = null;
				$('build').disabled = false;
				}
			});*/
		var id = $('#id').get(0).value;
		var build = $('#build').get(0).value;
		
		var url = '../../routerdb/de/routerResult.php';
		$.ajax({
			url: url,
			type: 'POST',
			data: ({
				action: 'routerFiles',
				id: id,
				build: build,
				offset: '../../routerdb/de/',
				site: 'drupal'
				}),
			dataType: 'json',
			async: false,
			success: function( data ) {
				$('#filelist').html( urldecode(data.files) );
				if( data.versionComment.length > 0 ) {
					$('#versionComment').html(urldecode( data.versionComment ));
				} else {
					$('#versionComment').html( '&nbsp;' );
				}
			}
		});
	}
	
	showRemarks = function( remarks ) {
		// check if the remarks div element exists
		/*var children = $('#content_right').children();
		if( children.length ) {
			$(remarks).css('padding-top', '0');
			if( $('h2', children[0]).text() != 'Remarks' ) {
				$('#content_right').prepend( remarks );
			} else {
				$( children[0] ).replaceWith( remarks );
			}
		}*/
		target = $('#router_db_notes');
		target.html(remarks);
		if( !target.hasClass('right_content') ) {
			target.addClass('right_content');
		}
	}
	
	function showLoadingMessage() {
		$('filelist').update('<div style="height: 300px;">Loading, please wait...</div>');
	}
	
	function openFileInPopup( id, filename ) {
		var url = '../../routerdb/de/download.php?file=' + id;
		var filePopup = window.open( url, 'preview', 'width=500,height=450,scrollbars=yes,resizable=yes' );
	}
	
	function urldecode( str ) {
		// http://kevin.vanzonneveld.net
		// +   original by: Philip Peterson
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +      input by: AJ
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +   improved by: Brett Zamir (http://brettz9.blogspot.com)
		// +      input by: travc
		// +      input by: Brett Zamir (http://brettz9.blogspot.com)
		// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
		// *     example 1: urldecode('Kevin+van+Zonneveld%21');
		// *     returns 1: 'Kevin van Zonneveld!'
		// *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
		// *     returns 2: 'http://kevin.vanzonneveld.net/'
		// *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
		// *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
		
		var histogram = {};
		var ret = str.toString();
		
		var replacer = function(search, replace, str) {
			var tmp_arr = [];
			tmp_arr = str.split(search);
			return tmp_arr.join(replace);
		};
		
		// The histogram is identical to the one in urlencode.
		histogram["'"]   = '%27';
		histogram['(']   = '%28';
		histogram[')']   = '%29';
		histogram['*']   = '%2A';
		histogram['~']   = '%7E';
		histogram['!']   = '%21';
		histogram['%20'] = '+';
		histogram['\u20AC'] = '%80';
		histogram['\u0081'] = '%81';
		histogram['\u201A'] = '%82';
		histogram['\u0192'] = '%83';
		histogram['\u201E'] = '%84';
		histogram['\u2026'] = '%85';
		histogram['\u2020'] = '%86';
		histogram['\u2021'] = '%87';
		histogram['\u02C6'] = '%88';
		histogram['\u2030'] = '%89';
		histogram['\u0160'] = '%8A';
		histogram['\u2039'] = '%8B';
		histogram['\u0152'] = '%8C';
		histogram['\u008D'] = '%8D';
		histogram['\u017D'] = '%8E';
		histogram['\u008F'] = '%8F';
		histogram['\u0090'] = '%90';
		histogram['\u2018'] = '%91';
		histogram['\u2019'] = '%92';
		histogram['\u201C'] = '%93';
		histogram['\u201D'] = '%94';
		histogram['\u2022'] = '%95';
		histogram['\u2013'] = '%96';
		histogram['\u2014'] = '%97';
		histogram['\u02DC'] = '%98';
		histogram['\u2122'] = '%99';
		histogram['\u0161'] = '%9A';
		histogram['\u203A'] = '%9B';
		histogram['\u0153'] = '%9C';
		histogram['\u009D'] = '%9D';
		histogram['\u017E'] = '%9E';
		histogram['\u0178'] = '%9F';
 		
		for (replace in histogram) {
			search = histogram[replace]; // Switch order when decoding
			ret = replacer(search, replace, ret) // Custom replace. No regexing   
		}
		
		// End with decodeURIComponent, which most resembles PHP's encoding functions
		ret = decodeURIComponent(ret);
		
		return ret;
	}