function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent('on'+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

function KeepOnPage(e) 
{

	    if(!e)
	        e = window.event;
	        
	    if(!e)
	        return;
	
		if( (!document.thisForm.alarm_hour.value)||(document.thisForm.alarm_hour.options[thisForm.alarm_hour.options.selectedIndex].text)=="OFF"||isAlarm==1 )
		{
			doWarn = 0;
		}
		else
		{
			doWarn = 1;
		}
	        
	     // cancelled, so cancel the event 
		 if(doWarn==1)
		 {
	     	e.cancelBubble = true; 
	     	e.returnValue = 'OnlineClock says:\n\nYou have an alarm set for: '+document.thisForm.alarm_hour.options[thisForm.alarm_hour.options.selectedIndex].text+' and '+document.thisForm.alarm_minute.options[thisForm.alarm_minute.options.selectedIndex].text+' minutes.\n\nNavigating away from this page will delete your alarm.'; 
		 }
		   if(e.stopPropagation) 
	       e.stopPropagation();
}


addEvent(window, 'beforeunload', KeepOnPage);




