merging sketches help! please

Thanks for the reply and advice, code now in a code box.
Pin 4 output goes to a separate relay.