function selectFamily(){
		if(document.searchForm.family.selectedIndex > 0){
			getSpeciesSelection(encodeURI(document.searchForm.family.options[document.searchForm.family.selectedIndex].value));
			}
		else
			getSpeciesSelection();
		document.searchForm.search.value = '';
}

function selectSpecies(){
	loadSpecies();
	updateCounter(document.searchForm.species.selectedIndex,document.searchForm.species.options.length);
}

function getSpeciesSelection(selection){

	if(document.searchForm.sort.selectedIndex == 0)
		sort='';
	else
		sort='&sort=true';

		if(document.searchForm.lang.selectedIndex == 0)
		lang='';
	else
		lang='&lang=common';
	
	if (document.searchForm.species.selectedIndex > 0)
		selectedSpecies="&selected="+encodeURI(document.searchForm.species.options[document.searchForm.species.selectedIndex].value);
	else
		selectedSpecies="";

	if (selection)
		$("div#speciesDiv").load("selection.php?"+test+"taxon=species&name="+selection+sort+lang+selectedSpecies,markSpecies);
	else
		$("div#speciesDiv").load("selection.php?"+test+"taxon=species"+sort+lang+selectedSpecies,markSpecies);
	}


function loadSpecies(){
	var selection = encodeURI(document.searchForm.species.options[document.searchForm.species.selectedIndex].value);
	$("form#detailsForm").load("details.php?"+test+"name="+selection);
    setButtonState();
	}

function markSpecies(){
	document.searchForm.species.focus();
	selectSpecies();
	};
	
function updateCounter(index,total){
	index=index+1;
	$("div#counter").html(index + ' / ' + total);
	}
			
function displayPopup(name,content){

	document.searchForm.species.focus();

	var fenster = open("",windowID(),"width=600,height=500,resizable=yes,scrollbars=yes,scrolling=yes");
	fenster.document.write('<html><body  BGCOLOR="#EEEEEE"><h2>'+name+'</h2>'+content+'<p><p><input type="button" value="Schlie&szlig;en" onclick="self.close()"></body></html>');

} // Ende Funktion displayPopup  BGCOLOR="#9BC4E1"

function windowID(){
 
	return ("window"+String(Math.random()).replace(/\./g,''));

} // Ende Funktion windowID


function resort(test){

	selectedFamily = '';
		
	if (varfind!=true){

		if(document.searchForm.sort.selectedIndex == 0)
			sort='';
		else
			sort='&sort=true';

		if(document.searchForm.lang.selectedIndex == 0)
			lang='';
		else
			lang='&lang=common';

		if(document.searchForm.family.selectedIndex > 0){
				getSpeciesSelection(encodeURI(document.searchForm.family.options[document.searchForm.family.selectedIndex].value));
				selectedFamily = '&selected='+encodeURI(document.searchForm.family.options[document.searchForm.family.selectedIndex].value);
				}
			else
				getSpeciesSelection();

		$("div#familyDiv").load("selection.php?taxon=family"+sort+lang+selectedFamily);
		}
	
	else
		find(selectedFamily);

	document.searchForm.species.focus();
}

function popupImage(name, ausrichtung, bild, autor, farbe){

	document.searchForm.species.focus();

	var fenster = open("",windowID(),"width="+screen.width+",height="+screen.height+"screenX=0,screenY=0,resizable=yes");
	fenster.document.write('<html><head><script language="JavaScript">window.moveTo(0,0);</script></head>'+
			'<body BGCOLOR="'+farbe+'" onKeyDown="self.close()"  onMouseDown="self.close()">'+
			'<div STYLE="position:absolute; left:5; top:5; color:'+((farbe=='#000000')?'white':'black')+'">'+
			name+( (autor != "") ? '<br>(c) '+autor : '')+'</div><center>'+
			'<img src="../media/'+bild+'" '+
//			((ausrichtung == 'H') ? 'width=97%': 'height=99%')+
			'height=99%'+
			'></center></body></html>');

} 


function back(){
	document.searchForm.search.value = '';
	document.searchForm.sort.selectedIndex = 0;
	document.searchForm.lang.selectedIndex = 0;
	window.location.href = "index.php";
}

function find(){

	if(document.searchForm.search.value == '') return (false);

	if(document.searchForm.sort.selectedIndex == 0)
		sort='';
	else
		sort='&sort=true';

		if(document.searchForm.lang.selectedIndex == 0)
		lang='';
	else
		lang='&lang=common';
	
	varfind=true;
	var search = '&search='+encodeURI(document.searchForm.search.value);
	
	if ((document.searchForm.species.selectedIndex > 0))
		selectedSpecies="&selected="+encodeURI(document.searchForm.species.options[document.searchForm.species.selectedIndex].value);
	else selectedSpecies = "";

	$("div#familyDiv").load("selection.php?taxon=family"+search+sort+lang);
	$("div#speciesDiv").load("selection.php?taxon=species"+search+sort+lang+selectedSpecies,markSpecies);
	
}

function navigate(direction) {
 
		select_no = document.searchForm.species.selectedIndex;
		select_max = document.searchForm.species.options.length;

	    switch (direction) {
	        case "next":
	            if(select_no < (select_max - 1 ))
		    	document.searchForm.species.selectedIndex=select_no + 1;
	            break;
	        case "previous":
	            if(select_no > 0)
			    document.searchForm.species.selectedIndex=select_no - 1;
	            break;
	        case "first":
	            document.searchForm.species.selectedIndex=0;
	            break;
	        case "last":
				document.searchForm.species.selectedIndex=select_max - 1;
	            break;
	    } // end switch
		selectSpecies();

		setButtonState();
 
 } // Ende Funktion navigatePlantList

 function setButtonState() {

		select_no = document.searchForm.species.selectedIndex;
		select_max = document.searchForm.species.options.length;
 
    if (select_no==0) {
	    document.nav.cmdMoveFirst.disabled = true;
        document.nav.cmdMovePrevious.disabled = true;
    }
    else {
        document.nav.cmdMoveFirst.disabled = false;
        document.nav.cmdMovePrevious.disabled = false;
    }

 	
	if (select_no >= (select_max-1) ) {
        //we're on the last record
        document.nav.cmdMoveLast.disabled = true;
        document.nav.cmdMoveNext.disabled = true;
    }
    else {
        document.nav.cmdMoveLast.disabled = false;
        document.nav.cmdMoveNext.disabled = false;
    }

	document.searchForm.species.focus();
}

function keyNavigation(ereignis){
 

	var taste;
	if(document.all)
		taste = window.event.keyCode;
	else
		taste = ereignis.which;

		switch(taste){
		case 13:	// return
			document.searchForm.species.focus();
			find();
			break;
	};
}
