//Written by Paul Stothard, University of Alberta, Canada

function groupDna (theDocument) {	
	var newDna = "";
	var title = "";
	var maxInput = 100000;

	if (testScript() == false) {
		return false;
	}

	if ((checkFormElement (theDocument.forms[0].elements[0]) == false) || (checkSequenceLength(theDocument.forms[0].elements[0].value, maxInput) == false))	{
		return false;
	}

	openWindow("Group DNA");
	openPre();	
	var arrayOfFasta = getArrayOfFasta (theDocument.forms[0].elements[0].value);

	for (var i = 0; i < arrayOfFasta.length; i++)	{
		newDna = getSequenceFromFasta (arrayOfFasta[i]);
		title = getTitleFromFasta (arrayOfFasta[i]);

		newDna = removeNonDna(newDna);

		outputWindow.document.write(getInfoFromTitleAndSequence(title, newDna));

		writeGroupNumDna(newDna, "", theDocument.forms[0].elements[4].options[theDocument.forms[0].elements[4].selectedIndex].value, theDocument.forms[0].elements[5].options[theDocument.forms[0].elements[5].selectedIndex].value, 0, newDna.length, theDocument.forms[0].elements[6].options[theDocument.forms[0].elements[6].selectedIndex].value, theDocument.forms[0].elements[7].options[theDocument.forms[0].elements[7].selectedIndex].value);
		outputWindow.document.write ('\n\n');
	}


	closePre();
	closeWindow();
	return true;
}
