jQuery(function($) {
    var $document      = $(document),
        documentHeight = $document.height(),
        documentWidth  = $document.width();
    
    // Create a cover <div> to catch click events.
    $('<div id="coverDiv" />')
        .css({ 'height': documentHeight + 'px',
               'width':  documentWidth  + 'px' })
        .click(function() { return false; })
        .prependTo(document.body);
    
    // Don’t let anything get focus by tabbing.
    $('a, area, button, input, object, select, textarea')
        .focus(function() { $(this).blur(); return false; })
        .attr('tabIndex',0);
    
    
    // Stop here if the page isn’t in a frame.
    if ( self === parent ) return;
    
    
    // Pass this page’s height to the parent window so it can set the correct
    // iframe height, while returning the user’s account details.
    var user = parent.deviceInit(document.location.pathname, documentHeight);
    
    // If the user isn’t logged in, there won’t be any account details.
    if ( user == null ) return;
    
    
    // Replace the selected inputs with the corresponding account data.
    $('input')
        .filter('.lp_fullName')
            .val( user.fullName )
            .end()
        .filter('.lp_voipUser_accountNumber')
            .val( user.voipUser.accountNumber )
            .end()
        .filter('.lp_voipUser_password')
            .val( user.voipUser.password );
});

