
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li><a href="shippercompaniesController.php?do=show">شركات الشحن</a></li>
            <li class="active">اضافة شركة</li>
        </ol>

        <h3>اضافة شركة شحن</h3>
        <hr/>

        {literal}
        <form class="nameToBeChecked form-horizontal" action="shippercompaniesController.php?do=add" method="post" id="spform">
            <!--validate the form before checking name-->
            {/literal}


            <div class="row">
                <div class="col-lg-8">


                    <div class="form-group">
                        <label for="companyName" class="col-lg-2 control-label">اسم الشركة</label>

                        <div class="col-lg-4">

                            <span id="name">
                                <span id="sprytextfield1">
                                    <input type="text" name="companyName" id="companyName" class="form-control" placeholder="اسم الشركة" />
                                    <span class="textfieldRequiredMsg">*</span></span><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="otherInfo" class="col-lg-2 control-label">بيانات أخرى</label>
                        <div class="col-lg-4">
                            <textarea  class="form-control" rows="3" name="otherInfo"></textarea>
                        </div>
                    </div>

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


                </div><!-- end of client info-->

            </div><!-- end of frist row-->








            <div class="row">
                <div class="row">
                    <hr/>
                    <div class="col-lg-6">
                        <h4>ال{if $Programsettingdata->delegate_seller eq 0} البائعين {elseif $Programsettingdata->delegate_seller == 1}المندوبين {elseif $Programsettingdata->delegate_seller == 2}الاطباء {/if}</h4>
                    </div>
                    <div class="col-lg-6">
                        <button type="button" name="addpro" id="addpro" class="btn btn-primary pull-left ft-nor"> اضافة جديد</button>
                    </div>
                </div><!-- end of title row-->
                <div class="table-responsive">
                    <table class="table billtable table-bordered" id="containerpros">
                        <thead>
                            <tr>

                                <th  class="wdt260">اسم ال{if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}</th>
                                <th class="wdt260">رقم التليفون</th>
                                <th  class="wdt260">بيانات أخرى</th>
                                <th> <input name="hidden_itr" id="hidden_itr" type="hidden" value="1" /> حذف</th>

                            </tr>
                        </thead>
                        <tbody>
                            <tr>

                                <td>
                                    <span id="spryName1">
                                        <input type="text" name="representativeName1" id="representativeName1"  class="form-control txt-nonraduis enteraction" tabindex="7"    placeholder="اسم ال{if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if}" />
                                        <span class="textfieldRequiredMsg">*</span></span>
                                </td>

                                <td>
                                    <span id="spryPhone1">
                                        <input type="text" id="representativePhone1" name="representativePhone1"  class="form-control txt-nonraduis positiveNo enteraction"  placeholder="رقم التليفون"  tabindex="7" />
                                        <span class="textfieldRequiredMsg">*</span></span>
                                </td>


                                <td >
                                    <textarea class="form-control txt-nonraduis enteraction" name="otherInfo1" id="otherInfo1" rows="1" tabindex="7"></textarea>
                                </td>


                                <td id="1">
                                    <button id="remove1" type="button" class="close flt-none removeicon removeproduct" aria-hidden="true">&times;</button>
                                </td>


                            </tr>
                        </tbody>
                    </table>
                </div>

            </div>

            <!-- end of second row-->



            <div class="row">
                <button type="button"  class="btn btn-primary" id="spbutton">حفظ</button>

            </div><!-- end of fifth row-->


        </form>
    </div><!-- end of container-->
</div><!-- end of main row-->



{literal}
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
</script>
{/literal}

{literal}
<script type="text/javascript">
    $('#spbutton').live('click', function (e) {
        //ckeck name
        var tableName = 'shippercompanies';
        var inputName = 'companyName';
        var name = $("#" + inputName).val();
        $.ajax({
            url: 'checkRedundantNames.php?name=' + name + '&tablename=' + tableName,
            success: function (data) {
                //alert(data);
                if (data == '0')
                {
                    $("#nameError").css("display", "none");
                    var myForm = document.getElementById("spform");
                    var SS = Spry.Widget.Form.validate(myForm);
                    if (SS == true) {
                        if (!$('#spbutton').hasClass("processing"))
                        {
                            var itr = $('#hidden_itr').val();
                            var i;
                            var arrName = [];
                            for (i = 1; i <= itr; i++) {
                                var representativeName = $("#representativeName" + i + "").val();
                                if (arrName.indexOf(representativeName) == -1)
                                {
                                    arrName.push(representativeName);
                                } else {
                                    alert('لا يجب ان يكون اسم ال{if $Programsettingdata->delegate_seller eq 0} بائع {elseif $Programsettingdata->delegate_seller == 1}مندوب {elseif $Programsettingdata->delegate_seller == 2}طبيب {/if} مكرر');
                                    return false;
                                }
                            }
                            $('#spbutton').addClass("processing");
                            myForm.submit();
                            //$('#spbutton').unbind('click');
                        }
                    }

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

    });
</script>
{/literal}

