var theNotes = new Array(); // holds the initial notes added and the notes added by the student
var gIDcounter = 0; // counter used to create unique IDs of notes added for this question

// adds a note to theNotes array, input is the NoteOctave from the xml input (adding via the xml initial data)
function addToNoteArrayUsingNote(NoteOctaveAccidental)
{
	var tmpYloc = hashNoteToLocation[NoteOctaveAccidental];
	if (tmpYloc != undefined)
	{
		gIDcounter++;
		var tmpArray = new Array(tmpYloc, NoteOctaveAccidental, gIDcounter);
		theNotes[theNotes.length] = tmpArray;
	}
}	


// adds a note to theNotes array, input is the Yloc (adding via the mouse)
function addToNoteArrayUsingYloc(Yloc)
{
	var tmpNoteOctave = hashLocationToNote[Yloc];
	if (tmpNoteOctave != undefined)
	{
		gIDcounter++;
		var tmpArray = new Array(Yloc, tmpNoteOctave, gIDcounter);
		theNotes[theNotes.length] = tmpArray;
	}
}


// utility to see what is in theNotes array
function showArray()
{
	for (var ii=0; ii<theNotes.length; ii++)
	{
		alert("Showing:" + theNotes[ii][0]+ "," + theNotes[ii][1] + "," +theNotes[ii][2] );
	}
}


// to remove a note that has been clicked by the user, the ID of the Image is theID
function removeArrayElement(theID)
{
	var indexToRemove = -1;
	var tmpID;
	for (var ii=0; ii<theNotes.length; ii++)
	{
		if (theID == theNotes[ii][2]) //id is located in 3rd element of noteLocationArray
		{
			indexToRemove = ii;
			break;
		}
	}
	
	if (indexToRemove != -1)
		theNotes.splice(indexToRemove,1);
}


// to empty theNotes array at the beginning of each problem before adding the initial notes
function emptyArray()
{
	theNotes = new Array();
}	

// utility method to enable the sort() method in javascript to sort by number rather than the default by alphabetically
function numSort(var1, var2)
{ 
	return(parseInt(var1) - parseInt(var2));
}

// sort array by first element (Yloc) from largest to smallest (lowest to highes pitch)
function sortArray()
{
	return (theNotes.sort(numSort).reverse());
}
