

<div class="row">
    <div class="container">

        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li><a href="clientController.php?do=show">العملاء</a></li>
            <li class="active">اضافة عميل</li>
        </ol>


        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">اضافة عميل</h3>
            </div>
            <div class="panel-body">


                {literal}
                <form class="form-horizontal nameToBeChecked" role="form" action="clientController.php?do=add" method="post" id="spform">

                    {/literal}

                    <div class="form-group">
                        <span style="   font-size: 17px; color: red;text-align: center;margin-right: 211px;">  {if !empty($msg)}{$msg}{/if}</span>
                    </div>


                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">اسم العميل</label>
                        <div class="col-lg-4">

                            <span id="sprytextfield1">

                                <input type="text" name="txtName" id="txtName" class="form-control" placeholder="اسم العميل"/>
                                <span class="textfieldRequiredMsg">*</span></span>



                            <div id="nameError" class="alert alert-block alert-danger fade in" style="display:none">
                                <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <h4>رسالة خطا</h4>
                                <p>هذا الاسم مستخدم من قبل</p>

                                <div class="clearfix"></div>
                            </div>


                        </div>
                    </div>



                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">كود العميل</label>
                        <div class="col-lg-4">
                            <input type="text" name="clientcode" id="clientcode" class="form-control" placeholder="كود العميل"/>
                            <div id="clientcodeError" class="alert alert-block alert-danger fade in" style="display:none">
                                <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <h4>رسالة خطا</h4>
                                <p>هذا الكود مستخدم من قبل</p>

                                <div class="clearfix"></div>
                            </div>




                            <div class="clearfix"></div>
                        </div>


                    </div>

                    <!-- =================================================   -->


                    <div class="form-group">
                        <label for="txtAddress" class="col-lg-2 control-label">الشركة - المنطقة</label>
                        <div class="col-lg-4">
                            <span id="spryselect1">
                                <select name="clientareaid" id="clientareaid"  data-placeholder="اختر " class="select2 wdt100">


                                    <option value="0">اختر </option>
                                    {foreach $allclientarea as $myallclientarea}
                                    <option value="{$myallclientarea->id}">{$myallclientarea->name} </option>
                                    {/foreach}
                                </select>
                                <span class="selectInvalidMsg">اختر</span></span>

                        </div>
                    </div>
                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="txtAddress" class="col-lg-2 control-label">العنوان</label>
                        <div class="col-lg-4">
                            <input type="text" name="txtAddress" id="txtAddress" class="form-control" placeholder="العنوان"/>
                        </div>
                    </div>

                    <!-- =================================================   -->


                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">رقم التليفون</label>
                        <div class="col-lg-4">
                            <input type="text" name="txtPhone" id="txtPhone" class="form-control positiveNo" placeholder="رقم التليفون"/>
                        </div>
                    </div>

                    <!-- =================================================   -->

                    <div class="form-group">
                        <label for="txtMobile" class="col-lg-2 control-label">رقم الموبايل</label>
                        <div class="col-lg-4">
                            <input type="text" name="txtMobile" id="txtMobile" class="form-control positiveNo" placeholder="رقم الموبايل"/>
                        </div>
                    </div>

                    <!-- =================================================   -->



                    <div class="form-group">
                        <label for="txtDebt" class="col-lg-2 control-label">أصل المديونية</label>
                        <div class="col-lg-4">

                            <div class="input-group"> <span id="sprytextfield4">
                                    <input type="text" name="txtDebt" id="txtDebt"  class="form-control positiveNo" placeholder="اصل المديونية" />
                                    <span class="textfieldRequiredMsg">*</span><span class="textfieldInvalidFormatMsg">ادخل رقم </span></span><span class="input-group-addon">{$currency}</span>
                            </div>

                        </div>
                        <!--span style="   font-size: 17px; color: red;text-align: center;">  {if !empty($checkNo)}{$checkNo}{/if}</span-->
                    </div>

                    <!-- =================================================   -->

                    <div class="form-group">
                        <label for="textDetails" class="col-lg-2 control-label">التعليق</label>
                        <div class="col-lg-4">

                            <textarea  class="form-control" rows="3" name="textDetails" id="textDetails"></textarea>

                        </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 sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "real");
    var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {invalidValue: "0", isRequired: false});
</script>

{/literal}

{literal}
<script type="text/javascript">
    $('#spbutton').live('click', function (e) {
        //ckeck name
        var tableName = 'client';
        var inputName = 'txtName';
        var name = $("#" + inputName).val();
        $.ajax({
            url: 'checkRedundantNames.php?name=' + name + '&tablename=' + tableName,
            success: function (data) {
                //alert(data);
                if (data == '0')
                {
                    $("#nameError").css("display", "none");
                    //return true;
                    //check code
                    /*----------------------------------------------------*/
                    var tableName = 'clientcode';
                    var inputName = 'clientcode';
                    var name = $("#" + inputName).val();
                    $.ajax({
                        url: 'checkRedundantNames.php?name=' + name + '&tablename=' + tableName,
                        success: function (data) {
                            //alert(data);
                            if (data == '0')
                            {
                                $("#clientcodeError").css("display", "none");
                                //return true;

                                var myForm = document.getElementById("spform");
                                var SS = Spry.Widget.Form.validate(myForm);
                                if (SS == true) {
                                    if (!$('#spbutton').hasClass("processing"))
                                    {
                                        $('#spbutton').addClass("processing");
                                        myForm.submit();
                                        //$('#spbutton').unbind('click');
                                    }
                                }

                            }
                            else if (data == '1')
                            {
                                $("#" + inputName).val("");
                                $("#" + inputName).focus();
                                $("#clientcodeError").css("display", "block");
                                return false;
                            }
                        }});

                    /*----------------------------------------------------*/

                }
                else if (data == '1')
                {
                    $("#" + inputName).val("");
                    $("#" + inputName).focus();
                    $("#nameError").css("display", "block");
                    return false;
                }
            }});

    });
</script>
{/literal}
