<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">الشئون القانونية</a></li>
            <li><a href="Cases.php?do=show"> قضايا</a></li>
            <li class="active">اضافة</li>
        </ol>
        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">اضافة</h3>
            </div>
            <div class="panel-body"> {literal}
                <form class="nameToBeChecked form-horizontal" role="form" action="Cases.php?do=add"
                      method="post" enctype="multipart/form-data" id="spform">
                    {/literal}

                    
                    <div class="form-group">
                        <label for="notes" class="col-lg-2 control-label">رقم الدعوي</label>
                        <div class="col-lg-4">
                            <input type="text" name="num" id="num" class="form-control">
                        </div>
                        <span class="textfieldRequiredMsg">*</span>
                    </div>
                    <!--==============================-->
                    <div class="form-group">
                        <label class="col-lg-2 control-label">أسماء الخصوم</label>
                        <div class="col-lg-4" id="opponents-container">
                            
                            <div class="opponent-row" style="margin-bottom: 10px;">
                                <input type="text" name="opponents[]" class="form-control opponent-input" placeholder="اسم الخصم الأول">
                            </div>

                            <div class="opponent-row" style="margin-bottom: 10px; display: none;">
                                <input type="text" name="opponents[]" class="form-control opponent-input" placeholder="اسم الخصم الثاني">
                            </div>

                            <div class="opponent-row" style="margin-bottom: 10px; display: none;">
                                <input type="text" name="opponents[]" class="form-control opponent-input" placeholder="اسم الخصم الثالث">
                            </div>
                            
                            </div>
                    </div>
                     <!--==============================-->
                    <div class="form-group">
                        <label for="lawyer_id" class="col-lg-2 control-label">المحامي المختص</label>
                        <div class="col-lg-4">
                            <select name="lawyer_id" id="lawyer_id" class="form-control select2" required>
                                <option value="-1">--- اختر المحامي المختص ---</option>
                                {foreach $lawyers as $lawyer}
                                    <option value="{$lawyer.id}">{$lawyer.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                     <!--==============================-->
                    <div class="form-group">
                        <label for="lawyer_id" class="col-lg-2 control-label">العضو</label>
                        <div class="col-lg-4">
                            <select name="member_id" id="member_id" class="form-control select2" required>
                                <option value="-1">--- اختر العضو ---</option>
                                {foreach $members as $member}
                                    <option value="{$member.id}">{$member.member_name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                     <!--==============================-->
                     <div class="form-group">
                        <label for="announcementEvaluation" class="col-lg-2 control-label">حالة القضية</label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input type="radio" name="status" id="status2" class="radioR" value="0" checked>
                                    جارية </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input type="radio" name="status" id="status1" class="radioR" value="1">
                                    تم الحكم فيها </label>
                            </div>
                        </div>
                    </div>
                    <!--==============================-->
                    <div class="form-group">
                        <label for="subject" class="col-lg-2 control-label">موضوع الدعوى</label>
                        <div class="col-lg-4">
                            <span id="sprytextarea1">
                                <textarea name="subject" id="subject" class="form-control" rows="5" placeholder="الموضوع.." required></textarea>
                            </span>
                        </div>
                    </div>
                     <!--==============================-->
                    <div class="form-group">
                        <label for="court_decision" class="col-lg-2 control-label">قرار المحكمة</label>
                        <div class="col-lg-4">
                            <textarea name="court_decision" id="court_decision" class="form-control" rows="4" ></textarea>
                        </div>
                    </div>
                    <!--==============================-->
                     
                       <div class="form-group">
                        <label for="announcementEvaluation" class="col-lg-2 control-label">مكان حفظ الملف</label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input type="radio" name="place" id="place" class="radioR" value="in" checked>
                                    داخل الجمعية </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input type="radio" name="place" id="place" class="radioR" value="out">
                                    خارج الجمعية </label>
                            </div>
                        </div>
                    </div>
                    <!--==============================-->
                    <div class="form-group">
                        <label for="notes" class="col-lg-2 control-label">ملاحظات</label>
                        <div class="col-lg-4">
                            <textarea name="notes" id="notes" class="form-control" rows="3" ></textarea>
                        </div>
                    </div>
                    <!--==============================-->
                    
                    <div class="form-group">
                        <label class="col-lg-2 control-label"> مرفقات</label>
                        <div class="col-lg-4">
                            <input type="file" name="image[]" id="image" multiple  accept=".jpg, .jpeg, .png, .pdf" />
                        </div>
                    </div>
                        <!-- =================================================   -->
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="button" class="btn btn-primary pull-left" id="spbutton">حفظ</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

{literal}
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
    $('#spbutton').live('click', function (e) {
        if (!$('#spbutton').hasClass("processing")) {
            $('#spbutton').addClass("processing");
            var myForm = document.getElementById("spform");
            var SS = Spry.Widget.Form.validate(myForm);
            if (SS == true) {
                myForm.submit();
            } else {
                $('#spbutton').removeClass("processing");
            }
        }
    });
$(document).ready(function() {
    $('#nature').on('change', function() {
        if ($(this).val() === 'other') {
            $('#other_input_container').show();
        } else {
            $('#other_input_container').hide(); 
            $('#other_nature').val(''); 
        }
    });
});
$(document).ready(function() {
    $(document).on('input', '.opponent-input', function() {
        let currentInput = $(this);
        let parentRow = currentInput.closest('.opponent-row');
        let nextRow = parentRow.next('.opponent-row');
        if (currentInput.val().trim() !== "") {
            nextRow.show(); 
        } else {
            if(nextRow.find('input').val() === "") {
             nextRow.hide(); 
            }
        }
    });
});

</script>
{/literal}