function setPrevParam()
{	var line = window.document.location.search.substr(1);
	var array = line.split('&');
	var param0 = array[0].split('=');

	for (var i = 0; i < array.length; i++)
	{	var param = array[i].split('=');
		
		if (param[0] == 'sigm')
		{	var index = 0;
			if (param[1] == 100) index = 1;
			else if (param[1] == 10) index = 2;
			else if (param[1] == 1) index = 3;
			window.document.TmForm.sigm[index].checked = 1;
		}
		else if (param[0] == 'sigf')
		{	window.document.TmForm.sigf.selectedIndex = param[1] - 2;
		}
		else if (param[0] == 'tmo')
		{	var index = param[1] > -1 ? param[1] : 2;
			window.document.TmForm.tmo[index].checked = param[1] - 2;
		}
		else if (param[0] == 'rtype')
		{	var index = param[1];
			window.document.extraForm.txtOrTop[index].checked = 1;
		}
		else if (param[0] == 'search')
		{	window.document.TextForm.search.value = param[1];
			window.document.extraForm.search.value = param[1];
		}
	}
}
function checkTcQuery()
{	if (window.document.tcForm.tc0.selectedIndex > 1)
	{	var x = window.document.tcForm.tc0.selectedIndex;
		window.document.tcForm.tc.value = window.document.tcForm.tc0.options[x].value;
	}
	else if (window.document.tcForm.tc1.selectedIndex > 1)
	{	var x = window.document.tcForm.tc1.selectedIndex;
		window.document.tcForm.tc.value = window.document.tcForm.tc1.options[x].value;
	}
	else if (window.document.tcForm.tc2.selectedIndex > 1)
	{	var x = window.document.tcForm.tc2.selectedIndex;
		window.document.tcForm.tc.value = window.document.tcForm.tc2.options[x].value;
	}
	else if (window.document.tcForm.tc3.selectedIndex > 1)
	{	var x = window.document.tcForm.tc3.selectedIndex;
		window.document.tcForm.tc.value = window.document.tcForm.tc3.options[x].value;
	}
	else
	{  alert ("*** Select a single TC class (not a super class)...");
		return false;
	}
	/*var url = 'seq_view.ep?search=zinc&tc=' + window.document.tcForm.tc;
   window.open(url, 'newSearch', 'width=1280,height=1024,toolbar=yes,menubar=yes,scrollbars=yes,resizable=1');*/                  
	return true;
}
function checkCombiQuery(form)
{	
	var x = form.tmx.selectedIndex;
	var y = form.tmy.selectedIndex;
	if (form.topol.value == 1)
	{	if (x > y)
		{	form.tmy.options[y].value =
			form.tmx.options[x].value;	
		}
	}	
	
	var MIN_LENGTH = 3;
	var currDoc = form.search.value;
	var quot = /['"]/;
	if (form.term.value == 1)
	{	if (quot.test(currDoc))  
		{	alert ("*** Don't use any quotation marks.");
			form.search.focus(); 
			return false;
		}
		if (currDoc.length < MIN_LENGTH)
		{	alert ("*** Enter search text or AccNo or GeneName.");
			form.search.focus(); 
			return false;
		}
	}	

	return true;
}

function checkTextQuery()
{	var currSearch = window.document.textform.search.value;
	//var currComplex = window.document.textform.complex.value;
	var MIN_LENGTH = 3;
	/*
	var quot = /['"]/;
	if (quot.test(currDoc))  
	{	alert ("*** Don't use any quotation marks.");
		window.document.textform.search.focus(); 
		return false;
	}
	*/

	if (currSearch.length < MIN_LENGTH) //&& currComplex.length < MIN_LENGTH)
	{	alert ("*** Enter search text or protein name.\n*** Minimal length is 3 characters.");
		window.document.textform.search.value = '';
		//window.document.textform.complex.value = '';
		window.document.textform.search.focus(); 
		return false;
	}
	else
	{  return true;
		//window.document.textform.submit();
	}
}
 
function checkSeqQuery()
{       var currDoc = window.document.seqform.seqc.value;
		  currDoc = currDoc.replace(/\s+/g, "");
		  currDoc = currDoc.replace(/&/g,"&amp;");

		  if (currDoc.match(/^>/))
        {       alert ("*** Enter search sequence only - don't use the FASTA format.");
                return false;
        }
        else if (currDoc.length == 0)
        {       alert ("*** Enter nucleotide or protein sequence.");
                return false;
        }
        else if (currDoc.length < 7)
        {       alert ("*** The minimal length of a search sequence is 7 residues.");
                return false;
        }
		  
        return true;
}                    

function checkClusterFilter()
{	var all = new Array();
	for (var i = 0; i < window.document.filterform.orgid.length; i++)
	{	if (window.document.filterform.orgid[i].checked)
		{	all.push(window.document.filterform.orgid[i].value);
		}
	}
	window.document.filterform.orgids.value =  all.length == 0 ? '0' : all.join('-');
	return true;
}

function checkMultiAlign(refProteinID, limit)
{	window.document.multiAlign.multi.value = checkMultiple(refProteinID, limit);
	if (window.document.multiAlign.multi.value == 0) return false;
	else return true;
	//window.document.multiAlign.submit();
}
function checkMultiple(refProteinID, limit)
{	var all = new Array();
	var j = 0;

	// if only one relative exists
	if (window.document.multiAlign.proteins.checked)
	{	all[j] = window.document.multiAlign.proteins.value;
		j++;
	}
	// if more than one relative exist
	for (var i = 0; i < window.document.multiAlign.proteins.length; i++)
	{	if (window.document.multiAlign.proteins[i].checked)
		{	all[j] = window.document.multiAlign.proteins[i].value;
			j++;
		}
	}

	// adds the reference protein ID
	if (refProteinID > 0)
	{	all[j] = refProteinID;
	}
        
	if (all.length > limit) 
   {   alert ("*** Please don't select more than " + (limit - 1) + " proteins.");
	    return 0;	
	}
	if (all.length < 2)
	{	alert ("*** Please select 1.. " + (limit - 1) + " additional proteins to be aligned.");
		return 0;
	}
	return all.join('-');
}



