What version of Sharepoint are you running?
alert('Your Session is about to expire, Save Now');
setTimeout(showAlert, 1000*60*60*20 );//20 hrs
You mentioned in a comment detecting if the user is active or not. I wouldn't take that effort, I believe that the infopath form timeout value is independent of the user's active status. I would that the form's timeout value, and set a page alert for just shy of that value, telling the user to save.
Here in my form the timeout is 1 day, so say after 20 hours I might popup an alert window.