how to send argument to ESP8266WebServer objects on function
Use server.arg() to pass commands from the web as GET params:

digitalWrite (5, relay1);

becomes

digitalWrite (server.arg("pin").toInt(), relay1);

where the URL is something like http://192.168.1.5/relay1?pin=15

Of course, the rest of your code probably needs to be adapted to manage the extra states, read/write all in one http call, etc.