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

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

        {literal}
        <form class="nameToBeChecked form-horizontal" action="clientareaController.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="name" 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  class="col-lg-2 control-label">علامات مرتبطه </label>
                        <div class="col-lg-4">
                            <select name="associatedtag_id"   data-placeholder="اختر " class=" select2">
                                <option value=""></option>
                               {foreach $associatedtags as $single}
                                <option value="{$single.id}">{$single.tagname}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="webApiId" class="col-lg-2 control-label">id - الخارجي  </label>
                        <div class="col-lg-4">
                             <input type="text" name="webApiId" id="webApiId" class="form-control" placeholder="id - الخارجي    " />
                        </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="comment"></textarea>
                        </div>
                    </div>

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


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

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










            <!-- 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");
    $('#spbutton').live('click', function (e) {


        if ($('#spform').validate().form()) {
            //ckeck name
            var tableName = 'clientarea';
            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");
                        //return true;
                        //check code
                        /*----------------------------------------------------*/
                        var tableName = 'clientarea';
                        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");
                                    //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();
                        $("#nameError").css("display", "block");
                        return false;
                    }
                }});

        }
        else
        {
            // alert('xx');

            e.preventDefault();

        }




    });
</script>
{/literal}

