Every mortgage or trust deed in the nature of a mortgage shall, as to lands not registered under the provisions of an act entitled "An Act Concerning Land Titles," approved and in force May 1, 1897, as subsequently amended, from the time it is filed of record, and in the case of lands registered under the provisions of said act entitled "An Act Concerning Land Titles," approved and in force May 1, 1897, as subsequently amended, from the time it is registered, or from the time of the filing of a caveat as provided in said Act, be a lien upon the real estate thereby conveyed situated in the county in which such instrument is recorded or registered, for all monies advanced or applied or which may at any time thereafter be advanced or applied thereunder on account of the principal indebtedness which such mortgage or trust deed shall purport to secure and including such other monies which may at any time be advanced or applied as are authorized by the provisions of such mortgage or trust deed or as are authorized by law; provided, that as to subsequent purchasers and judgment creditors, every such mortgage or trust deed shall, as to the monies advanced or applied thereunder on account of the principal indebtedness evidenced by the notes, bonds or other instruments therein described and thereby secured, be a lien only from the time such monies are advanced or applied, unless such monies are advanced or applied within 18 months after the date of such recording or registration, or filing of such caveat, or unless the mortgagee is by contract obligated to make such advances or applications, and provided further, that nothing in this Act contained shall affect any lien arising or existing by virtue of the Mechanics Lien Act .
765 ILCS 5/39