Checking connection to the internet with titanium

a function for titanium to check if the device is connected to the internet.
function notConnectedAlert(){
  var alertDialog = Titanium.UI.createAlertDialog({
    title: 'Not connected to the internet',
    message: 'Sorry, but Screencasts could not connect to the internet, and could not access data.',
    buttonNames: ['Continue']
  });
  alertDialog.show();
}

if(!Ti.Network.online){
  notConnectedAlert();
}