When, as a result of personal observation and testimony in open court, any court has reasonable grounds to believe that a person appearing before it is subject to involuntary admission on an inpatient basis and in need of immediate hospitalization to protect such person or others from physical harm, the court may enter an order for the temporary detention and examination of such person. The order shall set forth in detail the facts which are the basis for its conclusion. The court may order a peace officer to take the person into custody and transport him to a mental health facility. The person may be detained for examination for no more than 24 hours to determine whether or not she or he is subject to involuntary admission and in need of immediate hospitalization. If a petition and certificate are executed within the 24 hours, the person may be admitted provided that the certificate states that the person is both subject to involuntary admission and in need of immediate hospitalization. If the certificate states that the person is subject to involuntary admission but not in need of immediate hospitalization, the person may remain in his or her place of residence pending a hearing on the petition unless he or she voluntarily agrees to inpatient treatment. The provisions of this Article shall apply to all petitions and certificates executed pursuant to this Section. If no petition or certificate is executed, the person shall be released.
405 ILCS 5/3-607