protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (tbxMessage.Text.Length > 255)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Your message cannot exceed 255 characters!')", true);
            return;
        }
        Dispute dis = DisputeDB.getDisputeforRental(Request["rentid"].ToString());



        if (dis.Status == "Resolved")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Your page has expired since your disputer has closed the case')", true);
            rptMessages.DataBind();
            setChatControls(false);
            tbxMessage.Text = "";
            return;
        }

        if (tbxMessage.Text != "")
        {
            if (dis.DisputeID == null)
            {
                if (ddlReason.SelectedValue != "")
                {
                    dis             = new Dispute();
                    dis.Reason      = ddlReason.SelectedItem.Value;
                    dis.Date        = DateTime.Now;
                    dis.Rental      = RentalDB.getRentalbyID(Request["rentid"].ToString());
                    dis.Status      = "Pending";
                    dis.SubmittedBy = MemberDB.getMemberbyEmail(Session["user"].ToString());
                    DisputeDB.addDispute(dis);

                    ddlReason.Enabled = false;
                }
                else
                {
                    return;
                }
            }

            dis = DisputeDB.getDisputeforRental(Request["rentid"].ToString());

            MessageDispute msgDis = new MessageDispute();

            msgDis.Date    = DateTime.Now;
            msgDis.Dispute = dis;
            msgDis.Member  = MemberDB.getMemberbyEmail(Session["user"].ToString());
            msgDis.Staff   = new Staff(null, null, null, null, 0, null, new DateTime());

            msgDis.Reply = tbxMessage.Text;
            MessageDisputeDB.addMsgDispute(msgDis);

            tbxMessage.Text = "";

            rptMessages.DataSource = MessageDisputeDB.getMsgforDispute(dis.DisputeID);
            rptMessages.DataBind();
        }
    }
    protected void btnResolve_Click(object sender, EventArgs e)
    {
        Dispute dis = DisputeDB.getDisputeforRental(Request["rentid"].ToString());

        if (dis.Status == "Resolved")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Your page has expired since your disputer has closed the case')", true);
            rptMessages.DataBind();
            setChatControls(false);
            tbxMessage.Text = "";
            return;
        }

        //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "confirmMessage", "confirm('You are about to close the dispute case. As the action is irreversible, are you sure?')", true);
        DisputeDB.resolveDispute(dis.DisputeID);

        MessageDispute msgDis = new MessageDispute();

        msgDis.Date    = DateTime.Now;
        msgDis.Dispute = dis;
        msgDis.Member  = MemberDB.getMemberbyEmail(Session["user"].ToString());
        msgDis.Staff   = new Staff(null, null, null, null, 0, null, new DateTime());

        msgDis.Reply = "==============The Dispute has been closed================";

        MessageDisputeDB.addMsgDispute(msgDis);

        setChatControls(false);
    }
    // posts message and updates database of the message posted
    private void submitMessage(string message, Dispute dis)
    {
        MessageDispute msgDis = new MessageDispute();

        msgDis.Date    = DateTime.Now;
        msgDis.Dispute = dis;
        msgDis.Member  = new Member(null, null, null, 0, null, null, 0, null, null, new DateTime(), new DateTime(), null, new DateTime(), null, null);
        msgDis.Staff   = StaffDB.getStaffbyEmail(Session["admin"].ToString());

        msgDis.Reply = message;
        MessageDisputeDB.addMsgDispute(msgDis);
    }