Computer simulations of the structure, stability and phase transitions of diatomic molecules physisorbed on ionic surfaces : the CO/MgO(001), N2/MgO(001) and N2/NaCl(001) systems