function QueryForm(inputId, formId) {
	this.$input = $('#'+inputId);
	this.$form = $('#'+formId);

	this.$input.data('myFormId', formId);
	this.$form.data('myInputId', inputId);
	if(this.$input.val()) this.$input.data('default', this.$input.val());
	this.$input.data('myTimeoutId', '');

	this.registerTextHider = function() {
		this.$input.focus(function() {
			//alert($(this).data('default') && $(this).data('default')==$(this).val());
			if($(this).data('default') && $(this).data('default')==$(this).val()) {
				
				$(this).css('color', '#909090');
				$(this).data('writing', false);
				
				$(this).caret({start:0, end:0});
				$(this).data('myTimeoutId', ($(this).data('myTimeoutId').length>0?$(this).data('myTimeoutId')+",":"")+setTimeout('$(\'#'+$(this).attr('id')+'\').keydown()', 5000));
			}
		});

		this.$input.keydown(function() {
			if(!$(this).data('writing')) {
				$(this).data('writing', true);
				$(this).val('');
				$(this).css('color', '#000000');
			}
		});

		this.$input.mousedown(function(ev) {
			if(ev.which==3) $(this).keydown();
		});

		this.$input.blur(function() {
			if($(this).val().length<1 && $(this).data('default')) $(this).val($(this).data('default'));
			$(this).css('color', '#000000');
			
			if($(this).data('myTimeoutId')) {
				var ids=$(this).data('myTimeoutId').split(",");
				for (var k in ids) {
					clearTimeout(ids[k]);
				}
				$(this).data('myTimeoutId', '');
			}
		});

		this.$form.submit(function() {
			if($(this).data('myInputId')) {
				if($("#"+$(this).data('myInputId'), $(this)).data('writing') === true) return true;
				else return false;
			}

			return false;
		});
	};

	this.registerTextAutoselect = function() {
		this.$input.focus(function() {
			$(this).select();
		});
	};

	this.registerAutocomplete = function() {
		this.$input.autocomplete("/getHint.php", {max: 10, image: "/img/hints.gif"}).result(function() {
			$(this).parents('form').get(0).submit();
		});
	};

	this.registerSyntaxHelper = function() {
		var chars = new Array();
		chars['+'] = "<li>Poprzedzenie słowa znakiem <strong>+</strong> oznacza, że słowo to koniecznie musi wystąpić w wynikach wyszukiwania.</li>";
		chars['-'] = "<li>Poprzedzenie jednego ze słów znakiem <strong>-</strong> oznacza, że chcesz znaleźć wszystko, co nie zawiera tego słowa.</li>";
		chars['"'] = "<li>Tekst zawarty w cudzysłowie zostanie wyszukany dokładnie tak, jak został w nim wpisany (w takiej kolejności i formie).</li>";

		this.$input.keyup(function(event) {
			var useful = false;
			var txt = new Array();
			$platform=$('.syntaxHelper');
			$text=$('#syntaxHelpText');

			i=0;
			for(var k in chars) {
				if($(this).val().indexOf(k)>-1) {
					useful = true;
					txt[i++] = chars[k];
				}
				
			}
			
			if($platform) {
				if(useful) {
					var txtJoined="Czy wiesz, że...|<ul>"+txt.join(" ")+"</ul>";
					$text.text(txtJoined);
					$platform.attr('title', txtJoined);
					$platform.show();
					
					$platform.cluetip();
				} else {
					$platform.hide();
				}
			}
		});
	};

	this.setFocus = function() {
		this.$input.focus();
	};
}

