$(document).ready(function() {
	
	$("#searchbox").focus();
	
	function getSortVal() {
		var strSort = "";
		if(document.getElementById('selectOrder').value) {
			strSort = document.getElementById('selectOrder').value;
		} else {
			strSort = "";
		}
		return strSort;
	}
													 
	$("#searchbox").keyup(function(){		
		$.get("assets/snippets/arztsuche/search.php",{query: $("#searchbox").val(), type: "count", crypt: getCrypt()}, function(data){		
			$("#submitbutton").val(data + " Treffer");		
		});
	});
	
	$("#searchbox").keypress(function(event){
		if(event.keyCode == "13")
		{
			event.preventDefault();
			getResults();
		}
	});
	
	
	$("#submitbutton").click(function(){	
		getResults();	
	});

	function getResults()
	{
		$.get("assets/snippets/arztsuche/search.php",{query: $("#searchbox").val(), type: "results", order: getSortVal(), crypt: getCrypt()}, function(data){		
			$("#aerztev_resultFrame").html(data);
			$("#aerztev_resultFrame").show("blind");
		});
			$("#aerztev_sortFrame").fadeIn(2000);
	}
	
	$("#selectOrder").change(function() {
		$.get("assets/snippets/arztsuche/search.php",{type: "reorder", order: getSortVal(), crypt: getCrypt()}, function(data){
			$("#aerztev_resultFrame").html(data);
			$("#aerztev_resultFrame").show("blind");
		});
	});


});


function findByKT(strKT) {
	var strSort = "";
	if(document.getElementById('selectOrder').value) {
		strSort = document.getElementById('selectOrder').value;
	} else {
		strSort = "";
	}

	$.get("assets/snippets/arztsuche/search.php",{query: strKT, type: "state", order: strSort, crypt: getCrypt()}, function(data){
		$("#aerztev_resultFrame").html(data);
		$("#aerztev_resultFrame").show("blind");
	});
	$("#aerztev_sortFrame").fadeIn(2000);
}

function findByFunktion(intID) {
	var strSort = "";
	if(document.getElementById('selectOrder').value) {
		strSort = document.getElementById('selectOrder').value;
	} else {
		strSort = "";
	}

	$.get("assets/snippets/arztsuche/search.php",{query: intID, type: "funktion", order: strSort, crypt: getCrypt()}, function(data){
		$("#aerztev_resultFrame").html(data);
		$("#aerztev_resultFrame").show("blind");
	});
	$("#aerztev_sortFrame").fadeIn(2000);
}	

function showDetail(intID) {
	$.get("assets/snippets/arztsuche/search.php",{query: intID, type: "detail", crypt: getCrypt()}, function(data){
		$("#aerztev_resultFrame").html(data);
		$("#aerztev_resultFrame").show("blind");
	});
	$("#aerztev_sortFrame").fadeOut(500);
}

function getCrypt() {
	if(document.getElementById('cryptThat')) {
		return document.getElementById('cryptThat').innerHTML;
	}
}

/***********************************************************************/


