How I can detect if my application lost focus?

Hello people. I’m working in cocos2d-x with marmalade and a I need to do something like this: when the app is running, in any time, I have to go with another app, for example, the task killer. In this case, I have to detect that my app has lost the focus 'cause I have to run some action on the device if my app losses the focus. So, How I can detect this case?. Thanks

Hello, I also use Marmalade with cocos. I use these two functions in the appdelegate:

void Call_Suspend_Application()
{
CCDirector::sharedDirector()->stopAnimation();
CCDirector::sharedDirector()->pause();
// if you use SimpleAudioEngine, it must be pause
CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// Callback che viene chiamata quando il device riprende
void Call_Resume_Application()
{
CCDirector::sharedDirector()->stopAnimation();
CCDirector::sharedDirector()->resume();
CCDirector::sharedDirector()->startAnimation();
// if you use SimpleAudioEngine, it must resume here
CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

bool AppDelegate::applicationDidFinishLaunching()
{

s3eGLRegister(S3E_GL_SUSPEND, (s3eCallback)Call_Suspend_Application, NULL);
s3eGLRegister(S3E_GL_RESUME, (s3eCallback)Call_Resume_Application, NULL);
}