// scripts for lepindex drill-down search and associated synonymic list generator
// initial variables and scripting in lepindex/scripts/dd_js_vars.txt as must be parsed by jdsml 

function validateSingleName() {
	if (document.forms['singleName'].elements['SCIENTIFIC_NAME_on_card'].value.length == 0) {
		alert('Please enter a search-term.');
		return false;
	} else {
		return true;
	}
}
function validateDrillDown() {
	if (waitPlease == true) {	// if loading, message to user to wait
		DDmessage('nomessage');
		return false;
	}
	if (document.forms['drillDown'].elements['Current_superfamily'].options[document.forms['drillDown'].elements['Current_superfamily'].selectedIndex].text.length < 1) {
		DDmessage('superfamily');
		return false;
	} else {
		return true;
	}
}
function changedSuperFamily(select) {
//alert(superfam);
	resetDropDown('drillDown','Current_family');
	resetDropDown('drillDown','Current_subfamily');
	resetDropDown('drillDown','Current_tribe');
	//resetDropDown('drillDown','Current_genus');
	if (famsLoaded == true) {
		document.forms['drillDown'].action = 'index.dsml';
		document.forms['drillDown'].submit();
	}
	//synListURL(select);
}
function changedFamily(select) {
//var famSelected = false;
	resetDropDown('drillDown','Current_subfamily');
	resetDropDown('drillDown','Current_tribe');
	//resetDropDown('drillDown','Current_genus');
	if (subFamsLoaded == true) {
		document.forms['drillDown'].action = 'index.dsml';
		document.forms['drillDown'].submit();
	}
	//synListURL(select);
}
function changedSubFamily(select) {
//var subFamSelected = false;
	resetDropDown('drillDown','Current_tribe');
	//resetDropDown('drillDown','Current_genus');
	if (tribesLoaded == true) {
		document.forms['drillDown'].action = 'index.dsml';
		document.forms['drillDown'].submit();
	}
	//synListURL(select);
}
/*
function changedTribe(select) {
//var tribeSelected = false;
	resetDropDown('drillDown','Current_genus');
	if (generaLoaded == true) {
		document.forms['drillDown'].action = 'index.dsml';
		document.forms['drillDown'].submit();
	}
	//synListURL(select,'Current_tribe');
}
function changedGenus() {
//var genusSelected = false;
	//synListURL(select);

}
*/
function synListURL(select) {
	//alert(select);
	curVal = select.options[select.selectedIndex].text;
	//alert(curVal);
	synonymicListURL = select.name + '=' + curVal;
	//alert(synonymicListURL);
}
function doSynonymicList() {
//alert(0);
	if (document.forms['drillDown'].elements['recLimit'].selectedIndex < 3) {
		document.forms['drillDown'].elements['recLimit'].selectedIndex = 3;
	}
	document.forms['drillDown'].action = 'checklist.dsml'
	document.forms['drillDown'].submit();

	// BETTER, should name the submits and take action depending on the value of the param, 
	// but since this drill-down process is js dependent anyway, maybe no point in changing it - miks
}
