How long do i have to transfer H1B in case my onsite project has ended

Hi,

I am currently working onsite for a US client. my project is about to end soon (couple of weeks) and i will be asked to travel back to India to the offshore location for a different project. I am on the lookout for a opportunity for another employer to avoid travelling back to India
Q1) How long do I have before I can transfer my H1B VISA to another company?

Q2) Will there be a problem if I initiate the transfer form India ( In case i need to move back before the transfer

Q3) if Q2 is not possible can I resign and risk staying in the US till my VISA transfer is done ( i guess my visa would be invalid as soon as I resign the job from my petitioner. but still asking to confirm if this is true)

Thanks