


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

        <ol class="breadcrumb">
            <li><a href="#">المنتجات</a></li>
            <li><a href="sizecolorController.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">


                <form class="nameToBeChecked form-horizontal" role="form" action="sizecolorController.php?do=add" method="post" id="spform"  enctype="multipart/form-data">
                    <div class="form-group">
                        <label class="col-lg-2 control-label">الاسم</label>
                        <div class="col-lg-4">
                            <input type="text" name="name" id="name" class="form-control"/>
                            <div id="nameError" style="display:none;"></div>
                        </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" />
                        </div>
                    </div>



                    <div class="form-group">
                        <label class="col-lg-2 control-label">النوع</label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input value="0"  class="noradioR" name="type"   checked="checked"  type="radio" />
                                    مقاس</label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input value="1"  class="radioR" name="type"   type="radio" />
                                    لون </label>
                            </div>
                        </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">
    $('#spbutton').live('click', function (e) {
        if ($('#spform').validate().form()) {
            //ckeck name
            var tableName = 'sizecolor';
            var inputName = 'name';
            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"))
                            {
                                $('#spbutton').addClass("processing");
                                myForm.submit();
                                //$('#spbutton').unbind('click');
                            }
                        }
                        //return true;
                    } else if (data == '1')
                    {
                        $("#" + inputName).val("");
                        $("#" + inputName).focus();
                        $("#nameError").css("display", "block");
                        return false;
                    }
                }});
        } else {
            e.preventDefault();
        }
    });



</script>
{/literal}

