
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li><a href="#">مراكز التكلفه</a></li>
            <li class="active">تعديل مراكز التكلفه</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">
                <h3 class="panel-title">تعديل مراكز التكلفه</h3>
            </div>
            <div class="panel-body"> {literal}
                <form class="nameToBeChecked form-horizontal" action="costcenterController.php?do=update" method="post" id="spform">
                    <!--validate the form before checking name-->
                    {/literal}
                    <div class="form-group">
                        <label class="col-lg-2 control-label">اسم مراكز التكلفه</label>
                        <div class="col-lg-4"> <span id="sprytextfield2">
                                <input type="text" name="name" id="name" class="form-control"  value="{$data->name}" />
                                <span class="textfieldRequiredMsg">يجب ادخال الاسم</span></span>

                            <input type="hidden" name="id" id="id" value="{$data->id}"/>
                            <!----------- start nameError alert -------------->
                            <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>
                            <!----------- end nameError alert ------------->


                        </div>
                    </div>

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


                    <div class="form-group">
                        <label class="col-lg-2 control-label">تفاصيل أخرى</label>
                        <div class="col-lg-4">
                            <textarea name="descripe"  id="descripe" class=" form-control" cols="45" rows="5">{$data->comment}</textarea>
                        </div>
                    </div>

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


                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <input name="type" type="hidden" value="{$type}" />
                            <button type="reset" class="btn btn-danger pull-left">إلغاء</button>

                            <button type="button" class="btn btn-primary pull-left" id="spbutton">إضافة</button>

                        </div>
                    </div>
                    <div class="clearfix"></div>
                </form>
            </div><!--panel-body-->
        </div><!--panel-->
    </div><!--container-->
</div><!--row-->
{literal}
<script type="text/javascript">
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
</script>
{/literal}
{literal}
<script type="text/javascript">
    $('#spbutton').live('click', function (e) {
        //ckeck name
        var tableName = 'costcenter';
        var inputName = 'name';
        var name = $("#" + inputName).val();
        var id = $("#id").val();
        $.ajax({
            url: 'checkRedundantNames.php?do=checkNameWithId&name=' + name + '&id=' + id + '&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"))
                        {
                            $('#spbutton').addClass("processing");
                            myForm.submit();
                            //$('#spbutton').unbind('click');
                        }
                    }

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

    });
</script>
{/literal}
