var closeUnternehmenExtended;
var closeBewerberExtended;
var closeBewerberCategorySearch;
var submitFormUnt;
var submitFormBew;

$(document).ready(function(){

	/** Hinted Textboxes BEGIN **/
	$.each($('.inlineHint'), function(index, value) {
		$(value).tbHinter({
			text: $(this).attr('title'),
			classname: 'defaultText'
		});
	});
	/** Hinted Textboxes END **/

	/** Searchform BEGIN **/
	closeUnternehmenExtended = function() {
		$('.unternehmenExtended').hide();
		$('.defaultSearch').show();
		return false;
	}

	closeBewerberExtended = function() {
		$('.bewerberExtended').hide();
		$('.defaultSearch').show();
		return false;
	}

	closeBewerberCategorySearch = function() {
		$('.bewerberCategorySearch').hide();
		$('.defaultSearch').show();
		return false;
	}

	submitFormUnt = function() {
		if ($('#sword_unt').hasClass('defaultText')) {
			$('#sword_unt').val('');
		}
		if ($('#slocation_unt').hasClass('defaultText')) {
			$('#slocation_unt').val('');
		}

		$('#formUnt').submit();
		return false;
	}

	submitFormBew = function () {
		if ($('#sword_bew').hasClass('defaultText')) {
			$('#sword_bew').val('');
		}
		if ($('#slocation_bew').hasClass('defaultText')) {
			$('#slocation_bew').val('');
		}

		$('#formBew').submit();
		return false;
	}
	
	$('#unternehmenExtendedLink').click(function () {
		$('.defaultSearch').hide();
		pos   = $('#searchContainer').offset();
		height = $('#searchContainer').height();
		$('#unternehmenExtendedTable').css({ "left": (pos.left) + "px", "top":(pos.top+height) + "px" });
		if ($('#unternehmenExtended').html().length > 0) {
			$('.unternehmenExtended').show();
		} else {
			$.get('/dynContent/advanced_search_unt.php', function(data) {
				$('#unternehmenExtended').html(data);
				$('.unternehmenExtended').show();
			});
		}
		return false;
	});

	$('#bewerberExtendedLink').click(function () {
		$('.defaultSearch').hide();
		pos   = $('#searchContainer').offset();
		height = $('#searchContainer').height();
		$('#bewerberExtendedTable').css({ "left": (pos.left) + "px", "top":(pos.top+height) + "px" });
		if ($('#bewerberExtended').html().length > 0) {
			$('.bewerberExtended').show();
		} else {
			$.get('/dynContent/advanced_search_bew.php', function(data) {
				$('#bewerberExtended').html(data);
				$('.bewerberExtended').show();
			});
		}
		return false;
	});

	$('#bewerberCategoryLink').click(function () {
		if ($('#bewerberCategorySearch').html().length > 0) {
			$('.defaultSearch').hide();
			$('.bewerberCategorySearch').show();
		} else {
			$.get('/dynContent/category_search.php', function(data) {
				$('#bewerberCategorySearch').html(data);
				$('.defaultSearch').hide();
				$('.bewerberCategorySearch').show();
			});
		}
		return false;
	});

	$('.formUntSubmit').click(submitFormUnt);

	$('.formBewSubmit').click(submitFormBew);

	$('#sword_unt').autocomplete({
		minLength: 1,
		source: function(req, add){
			req.data = "sword_unt";
			$.getJSON("/dynContent/autocomplete.php?callback=?", req, function(data) {
				add(data);
			});
		}
	});

	$('#sword_bew').autocomplete({
		minLength: 1,
		source: function(req, add){
			req.data = "sword_bew";
			$.getJSON("/dynContent/autocomplete.php?callback=?", req, function(data) {
				add(data);
			});
		}
	});

	$('#slocation_unt').autocomplete({
		minLength: 1,
		source: function(req, add){
			req.data = "slocation_unt";
			$.getJSON("/dynContent/autocomplete.php?callback=?", req, function(data) {
				add(data);
			});
		}
	});

	$('#slocation_bew').autocomplete({
		minLength: 1,
		source: function(req, add){
			req.data = "slocation_bew";
			$.getJSON("/dynContent/autocomplete.php?callback=?", req, function(data) {
				add(data);
			});
		}
	});
	/** Searchform END **/
});
