<style>
    .new_prices {
        border-right: 0;
        border-bottom-right-radius: 0;
        border-top-right-radius: 0;
        font-weight: bold;
        padding: 4px 12px;
        font-size: 14px;
        font-weight: bold;
        line-height: 1;
        text-align: center;
        background-color: #eee;
        border: 1px solid #ccc;
        border-radius: 4px;
        width: 66px;
        white-space: nowrap;
        vertical-align: middle;
        display: table-cell;
        border-radius: 0px;
        border-bottom-left-radius: 4px;
        border-top-left-radius: 4px;
    }
</style>
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">{$smarty.const.PRODUCTS}</a></li>
            <li><a href="productCatController.php?do=show">{$smarty.const.PRODUCTS_CATEGORIES}</a></li>
            <li class="active">{$smarty.const.EDIT_MAIN_CATEGORY}</li>
        </ol>
        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">{$smarty.const.EDIT_MAIN_CATEGORY}</h3>
            </div>
            <div class="panel-body"> {literal}
                <form class="nameToBeChecked form-horizontal" role="form" action="productCatController.php?do=update"
                    method="post" enctype="multipart/form-data" id="spform">
                    {/literal}
                    <div class="form-group">
                        <label for="parent" class="col-lg-2 control-label">{$smarty.const.MAIN_CATEGORY}</label>
                        <div class="col-lg-4">
                            <input type="hidden" name="parent" id="parent">
                            <input type="hidden" id="oldid" value="{$productCatparent->productCatId}">
                            <input type="hidden" id="oldname" value="{$productCatparent->productCatName}">

                            <!--                            <select class="select2 wdt100" name="parent" id="parent">
                                                            <option {if $productCatData->productCatParent  eq 0}selected{/if} value="0">{$smarty.const.NO_MAIN_CATEGORY}</option>
                                                            {if $parentid}
                                                            <option value="{$productCatparent->productCatId}" selected>{$productCatparent->productCatName}</option>
                                                            {/if}
                                                            {foreach $categories as $parent}
                                                            <option value="{$parent->productCatId}" >{$parent->productCatName}</option>
                                                              <option value="{$parent->productCatId}" {if $productCatData->productCatParent  eq $parent->productCatId}selected{/if}>{$parent->productCatName}</option>
                                                            {/foreach}


                                                        </select>-->
                        </div>
                    </div>

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

                    <div class="form-group">
                        <label for="productCatName" class="col-lg-2 control-label">{$smarty.const.CATEGORY_NAME}</label>
                        <div class="col-lg-4"> <span id="sprytextfield1">
                                <input type="text" name="productCatName" id="productCatName"
                                    placeholder="{$smarty.const.CATEGORY_NAME}" class="form-control"
                                    value="{$productCatData->productCatName}"
                                    onblur="checkNameWithId(event, 'productcat', 'productCatName', 'productCatId')" />
                                <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>{$smarty.const.WRONG_MESSAGE}</h4>
                                <p>{$smarty.const.NAME_ALREADY_TAKEN}</p>
                                <div class="clearfix"></div>
                            </div>
                        </div>
                    </div>
                    <!-- =================================================   -->
                    <div class="form-group">
                        <label class="col-lg-2 control-label">{$smarty.const.IN_MENU}</label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input value="0" class="radioR" {if $productCatData->inMenu==0}
                                    checked="checked"{/if} name="inMenu" type="radio">

                                    {$smarty.const.CATEGORY_YES} </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input value="1" class="noradioR" {if $productCatData->inMenu==1}
                                    checked="checked"{/if} name="inMenu" type="radio">
                                    {$smarty.const.CATEGORY_NO} </label>
                            </div>

                        </div>
                    </div>

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

                    <div class="form-group">
                        <label for="discounttype" class="col-lg-2 control-label">{$smarty.const.DISCOUNT_TYPE}</label>
                        <div class="col-lg-4">
                            <select class="select2 wdt100" name="discounttype" id="discounttype"
                                onchange="chechdata();">
                                <option {if {$productCatData->discounttype} eq -1} selected="selected" {/if}
                                    value="-1">{$smarty.const.CHOOSE_TYPE} </option>
                                <option {if {$productCatData->discounttype} eq 0} selected="selected" {/if}
                                    value="0">{$smarty.const.CATEGORY_DIRECT} </option>
                                <option {if {$productCatData->discounttype} eq 1} selected="selected" {/if}
                                    value="1">{$smarty.const.CATEGORY_RATE}</option>
                            </select>
                        </div>
                    </div>

                    <!-- =================================================   -->
                    <div class="form-group" {if $Programsettingdata->isOpticProg == 1}style="display:none;"{/if}>
                        <label for="discounttype"
                            class="col-lg-2 control-label">{$smarty.const.OPTICAL_SERVICES}</label>
                        <div class="col-lg-4">
                            <select class="select2 wdt100" name="opticServices[]" id="opticServices" multiple>
                                <option value="Single vision" {if strpos($productCatData->opticServices, 'Single
                                    vision') != false} selected{/if} >Single vision</option>
                                <option value="polycarbonate" {if strpos($productCatData->opticServices,
                                    'polycarbonate') != false} selected{/if}>polycarbonate</option>
                                <option value="Hi index" {if strpos($productCatData->opticServices, 'Hi index') !=
                                    false} selected{/if}>Hi index</option>
                                <option value="Contact lenses Plano" {if strpos($productCatData->opticServices, 'Contact
                                    lenses Plano') != false} selected{/if}>Contact lenses Plano</option>
                                <option value="Contact lenses power" {if strpos($productCatData->opticServices, 'Contact
                                    lenses power') != false} selected{/if}>Contact lenses power</option>
                                <option value="Sunglasses" {if strpos($productCatData->opticServices, 'Sunglasses') !=
                                    false} selected{/if}>Sunglasses</option>
                                <option value="Medical frame" {if strpos($productCatData->opticServices, 'Medical
                                    frame') != false} selected{/if}>Medical frame</option>
                                <option value="Reading" {if strpos($productCatData->opticServices, 'Reading') != false}
                                    selected{/if}>Reading</option>
                                <option value="Accessories" {if strpos($productCatData->opticServices, 'Accessories') !=
                                    false} selected{/if}>Accessories</option>
                                <option value="Bifocal" {if strpos($productCatData->opticServices, 'Bifocal') != false}
                                    selected{/if}>Bifocal</option>
                                <option value="Multifocal/Progressive" {if strpos($productCatData->opticServices,
                                    'Multifocal/Progressive') != false} selected{/if}>Multifocal/Progressive</option>
                            </select>
                        </div>
                    </div>
                    <!--==============================-->

                    <div class="form-group">
                        <label for="email" class="col-lg-2 control-label">{$smarty.const.CATEGORY_IMAGE}</label>
                        <div class="col-lg-4"> <img src="../views/default/images/cat_image/{$productCatData->logo}"
                                alt="" width="122" height="75" />
                            <input type="file" name="logo" id="logo" class="form-control"
                                placeholder="{$smarty.const.CATEGORY_IMAGE}" accept="image/*" />
                            <input type="hidden" name="oldlogo" id="oldlogo" value="{$productCatData->logo}" />
                        </div>
                    </div>

                    <input type="hidden" id="thecurrency" value="{$currency}" />
                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="selldiscount" class="col-lg-2 control-label">{$smarty.const.SALE_DISCOUNT}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="text" name="selldiscount" id="selldiscount"
                                    value="{$productCatData->selldiscount}" onKeyUp="chechdata();"
                                    class="form-control numberinput" placeholder="{$smarty.const.DISCOUNT_VALUE}" />
                                <span class="input-group-addon"> {if {$productCatData->discounttype} eq -1}
                                    {$currency}
                                    {elseif {$productCatData->discounttype} eq 0}
                                    {$currency}
                                    {elseif {$productCatData->discounttype} eq 1}
                                    %
                                    {/if} </span>
                            </div>
                        </div>
                    </div>

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

                    <div class="form-group">
                        <label for="buydiscount" class="col-lg-2 control-label">{$smarty.const.BUY_DISCOUNT}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="text" name="buydiscount" id="buydiscount"
                                    value="{$productCatData->buydiscount}" onKeyUp="chechdata();"
                                    class="form-control numberinput" placeholder="{$smarty.const.DISCOUNT_VALUE}" />
                                <span class="input-group-addon"> {if {$productCatData->discounttype} eq -1}
                                    {$currency}
                                    {elseif {$productCatData->discounttype} eq 0}
                                    {$currency}
                                    {elseif {$productCatData->discounttype} eq 1}
                                    %
                                    {/if} </span>
                            </div>
                        </div>
                    </div>

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

                    <div class="form-group">
                        <label for="buytotal" class="col-lg-2 control-label">{$smarty.const.ACTUAL_BUY_PRICE}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="buypricereal" id="buypricereal"
                                    value="{$productCatData->buypricereal}" value="0" style="width: 303px;"
                                    class="form-control numberinput" placeholder="{$smarty.const.ACTUAL_BUY_PRICE}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    <!-- =================================================   -->
                    {if $Programsettingdata->showpriceall == 1}
                    <div class="form-group">
                        <label for="buytotal" class="col-lg-2 control-label">{$smarty.const.WHOLESALE_PRICE}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="buytotal" id="buytotal" value="{$productCatData->buytotal}"
                                    value="0" style="width: 303px;" class="form-control numberinput"
                                    placeholder="{$smarty.const.WHOLESALE_PRICE} " />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showpricehalf == 1}
                    <div class="form-group">
                        <label for="buyhalf" class="col-lg-2 control-label">{$smarty.const.HALF_WHOLESALE_PRICE}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="buyhalf" id="buyhalf" value="{$productCatData->buyhalf}"
                                    value="0" style="width: 303px;" class="form-control numberinput"
                                    placeholder="{$smarty.const.HALF_WHOLESALE_PRICE}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showpriceunit == 1}
                    <div class="form-group">
                        <label for="buypart" class="col-lg-2 control-label">{$smarty.const.RETAIL_PRICE}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="buypart" id="buypart" value="{$productCatData->buypart}"
                                    value="0" style="width: 303px;" class="form-control numberinput"
                                    placeholder="{$smarty.const.RETAIL_PRICE}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice4 == 1}
                    <div class="form-group">
                        <label for="price4" class="col-lg-2 control-label">{$smarty.const.PRICE4}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price4" id="price4" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE4}"
                                    value="{$productCatData->price4}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice5 == 1}
                    <div class="form-group">
                        <label for="price5" class="col-lg-2 control-label">{$smarty.const.PRICE5}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price5" id="price5" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE5}"
                                    value="{$productCatData->price5}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice6 == 1}
                    <div class="form-group">
                        <label for="price6" class="col-lg-2 control-label">{$smarty.const.PRICE6}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price6" id="price6" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE6}"
                                    value="{$productCatData->price6}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice7 == 1}
                    <div class="form-group">
                        <label for="price7" class="col-lg-2 control-label">{$smarty.const.PRICE7}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price7" id="price7" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE7}"
                                    value="{$productCatData->price7}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice8 == 1}
                    <div class="form-group">
                        <label for="price8" class="col-lg-2 control-label">{$smarty.const.PRICE8}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price8" id="price8" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE8}"
                                    value="{$productCatData->price8}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice9 == 1}
                    <div class="form-group">
                        <label for="price9" class="col-lg-2 control-label">{$smarty.const.PRICE9}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price9" id="price9" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE9}"
                                    value="{$productCatData->price9}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice10 == 1}
                    <div class="form-group">
                        <label for="price10" class="col-lg-2 control-label">{$smarty.const.PRICE10}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price10" id="price10" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE10}"
                                    value="{$productCatData->price10}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice11 == 1}
                    <div class="form-group">
                        <label for="price11" class="col-lg-2 control-label">{$smarty.const.PRICE11}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price11" id="price11" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE11}"
                                    value="{$productCatData->price11}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice12 == 1}
                    <div class="form-group">
                        <label for="price12" class="col-lg-2 control-label">{$smarty.const.PRICE12}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price12" id="price12" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE12}"
                                    value="{$productCatData->price12}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    {if $Programsettingdata->showprice13 == 1}
                    <div class="form-group">
                        <label for="price13" class="col-lg-2 control-label">{$smarty.const.PRICE13}</label>
                        <div class="col-lg-4">
                            <div class="input-group">
                                <input type="number" name="price13" id="price13" style="width: 303px;"
                                    class="form-control main_input numberinput" placeholder="{$smarty.const.PRICE13}"
                                    value="{$productCatData->price13}" />
                                <span class="new_prices">%</span>
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!-- =================================================   -->
                    <div class="form-group">
                        <label class="col-lg-2 control-label">{$smarty.const.NEGATIVE_SALES_STOP}</label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input value="0" class="radioR" {if $productCatData->stopNegativeSale==0}
                                    checked="checked"{/if} name="stopNegativeSale" type="radio">

                                    {$smarty.const.CATEGORY_NO} </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input value="1" class="noradioR" {if $productCatData->stopNegativeSale==1}
                                    checked="checked"{/if} name="stopNegativeSale" type="radio">
                                    {$smarty.const.CATEGORY_YES} </label>
                            </div>

                        </div>
                    </div>

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

                    <div class="form-group">
                        <label for="productCatDescription"
                            class="col-lg-2 control-label">{$smarty.const.CATEGORY_COMMIT}</label>
                        <div class="col-lg-4">
                            <textarea class="form-control" rows="3"
                                name="productCatDescription">{$productCatData->productCatDescription}</textarea>
                        </div>
                    </div>

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

                    <input name="productCatId" id="productCatId" type="hidden"
                        value="{$productCatData->productCatId}" />
                    <input name="conditions" id="conditions" type="hidden" value="{$productCatData->conditions}" />

                    <!-- =================================================   -->
                    <!--------------------------------  adding units   ----------------------------->

                    <div id="cat_addUnitsDiv">
                        <div class="table-responsive">
                            <table id="cat_unitsTable" class="table table-black">
                                {assign var=j value=1}
                                {foreach $catUnitsData as $proUnit}
                                <tr>
                                    <td>
                                        <div class="form-group">
                                            <label class="col-lg-4 control-label">{$smarty.const.UNIT_NAME}</label>
                                            <div class="col-lg-8">
                                                <select name="productcatunit_disabled{$j}"
                                                    id="productcatunit_disabled{$j}" disabled="disabled"
                                                    data-placeholder="{$smarty.const.CHOOSE}"
                                                    class="select2 wdt100 aw_m1 chosenproduct" tabindex="12">
                                                    <option value="-1">{$smarty.const.CHOOSE_UNIT_NAME}</option>

                                                    {foreach $unitsData as $unit}

                                                    <option value="{$unit->unitId}" {if $proUnit->unitid eq
                                                        $unit->unitId}selected{/if}>{$unit->unitName}</option>

                                                    {/foreach}

                                                </select>
                                                <input name="productcatunit{$j}" id="productcatunit{$j}" type="hidden"
                                                    value="{$proUnit->unitid}" />

                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        <div class="form-group">
                                            <label class="col-lg-4 control-label">{$smarty.const.NUMBER_UNITS}</label>
                                            <div class="col-lg-8">
                                                <input name="cat_productnumber{$j}" id="cat_productnumber{$j}"
                                                    type="text" class="form-control numberinput"
                                                    value="{$proUnit->productnumber}" />
                                            </div>
                                        </div>
                                    </td>
                                    <td><a id="cat_remove{$j}" onClick="cat_removeUnits({$j});"
                                            class="cat_removeUnits">X</a></td>
                                </tr>
                                {capture assign=j}{$j+1}{/capture}
                                {/foreach}
                            </table>
                        </div>
                        <!--end cat_unitsTable-->
                    </div>
                    <input class="cat_addUnits btn btn-warning" onClick="cat_addUnits();" type="button"
                        value="{$smarty.const.ADD_UNITS_MEASURE}" />
                    <input name="cat_unitsItr" id="cat_unitsItr" type="hidden" value="{$countcatUnits}" />

                    <!-------------------------------- end adding units   -------------------------->

                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="button" class="btn btn-primary pull-left"
                                id="spbutton">{$smarty.const.SAVE_IT}</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div id="productUnitsDiv" style="display:none;">
    <option value="-1">{$smarty.const.CHOOSE_UNIT_NAME}</option>
    {foreach $unitsData as $unit}
    <option value="{$unit->unitId}">{$unit->unitName}</option>
    {/foreach}
</div>
{literal}
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    $('#spbutton').live('click', function (e) {
        if (!$('#spbutton').hasClass("processing")) {
            $('#spbutton').addClass("processing");
            $('#productCatName').trigger('blur');
            setTimeout(function () {
                var myForm = document.getElementById("spform");
                var SS = Spry.Widget.Form.validate(myForm);
                if (SS == true) {
                    myForm.submit();
                }
                else {
                    $('#spbutton').removeClass("processing");
                }
            }, 500);
        }
    });

    $(function () {
        $('#parent').select2({
            placeholder: "اختر تصنيف ",
            minimumInputLength: 0,
            //  minimumInputLength: 3,
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "productControllerAjax.php?do=getallcats",
                dataType: 'json',
                data: function (term, page) {
                    //  alert(term);
                    return {
                        term: term, //search term
                        page_limit: 30, // page size
                        withoutId:$('#productCatId').val(),
                    };
                },
                results: function (data) {
                    // alert(term);
                    return { results: data };
                }
            },
            formatResult: function (data) {
                return data.text;
            },
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = { id: item[0], text: item[1] };
                callback(data);
            }
        });
        $('#parent').select2('data', { id: $('#oldid').val(), text: $('#oldname').val() })
    });
</script>
{/literal}