window.onload = function() {
    // TODO:: Do your initialization job

    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
    	 if( e.keyName === "back" ) {
             var activePopup = document.querySelector( '.ui-popup-active' ),
                 page = document.getElementsByClassName( 'ui-page-active' )[0],
                 pageid = page ? page.id : "";

             if( pageid === "main" && !activePopup ) {
                 try {
                     tizen.application.getCurrentApplication().exit();
                 } catch (ignore) {
                 }
             } else {
                 window.history.back();
             }
         }
    });
};