I'm not sure what A is, but try to change:
Before:
Code: ags
After
Code: ags
you don't know if secondID is equal (or not) to firstID since you put secondID = A.ID in the line below.
Before:
else if (FirstID != 0){ //If is the second button clicked store its ID, loc & text in the appropriate variables
Ã, if (FirstID != SecondID){
Ã, Ã, SecondID = A.ID;
After
else { //If is the second button clicked store its ID, loc & text in the appropriate variables
Ã, if (FirstID != A.ID) {
Ã, Ã, Ã, SecondID = A.ID;
you don't know if secondID is equal (or not) to firstID since you put secondID = A.ID in the line below.