Its built in, just not easily found in the manual.
Looking at your code you want to 'share' the funtion "create_entity1"
Do so like this. (NO changes required in panel definition)
function create_entity1(var button_number)
{
// "button_number" now contains the button number that was pressed,
// starting with 1. In this case "1" would be the horse button.
...
}