<?php
session_start();
require_once("functions.php");
$id_category = $_GET['id'];
$category = get_category($id_category);
$map = get_map($category['id_map'],$_SESSION['id_user']);
$tmp_languages = get_languages_map();
$array_languages = $tmp_languages[0];
$default_language = $tmp_languages[1];
$count_markers = get_marker_count_category($id_category);
if(empty($category['markers_color_hex'])) $category['markers_color_hex']=$map['main_color_hex'];
if (is_ssl()) { $protocol = 'https'; } else { $protocol = 'http'; }
$link_cat = $protocol ."://". $_SERVER['SERVER_NAME'] . str_replace("backend/index.php","viewer/index.php?code=",$_SERVER['SCRIPT_NAME']);
$array_input_lang = array();
$query_lang = "SELECT * FROM sml_categories_lang WHERE id_category=$id_category;";
$result_lang = $mysqli->query($query_lang);
if($result_lang) {
    if ($result_lang->num_rows > 0) {
        while($row_lang = $result_lang->fetch_array(MYSQLI_ASSOC)) {
            $language = $row_lang['language'];
            unset($row_lang['id_category']);
            unset($row_lang['language']);
            $array_input_lang[$language]=$row_lang;
        }
    }
}
if(!empty($map['default_am_fields'])) {
    $default_am_fields = json_decode($map['default_am_fields'],true);
} else {
    $default_am_fields = array();
}
if(!empty($map['default_am_placeholders'])) {
    $default_am_placeholders = json_decode($map['default_am_placeholders'],true);
} else {
    $default_am_placeholders = array();
}
if(!empty($category['default_am_fields'])) {
    $override = true;
    $category_am_fields = json_decode($category['default_am_fields'],true);
} else {
    $override = false;
    $category_am_fields = array();
}
?>

<?php if(!$map): ?>
    <div class="text-center">
        <div class="error mx-auto" data-text="401">401</div>
        <p class="lead text-gray-800 mb-5"><?php echo _("Permission denied"); ?></p>
        <p class="text-gray-500 mb-0"><?php echo _("It looks like you found a glitch in the matrix..."); ?></p>
        <a href="index.php?p=dashboard">← <?php echo _("Back to Dashboard"); ?></a>
    </div>
    <script>
        $('.map_select_header').remove();
    </script>
<?php die(); endif; ?>

<div class="row">
    <div class="col-md-12">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-link"></i> <?php echo _("Direct Link"); ?></h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <input readonly type="text" class="form-control bg-white" id="link" value="<?php echo $link_cat.$map['code']."&cat=".$id_category; ?>" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-cog"></i> <?php echo _("Details"); ?></h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="name"><?php echo _("Name"); ?> *</label><?php echo print_language_input_selector($array_languages,$default_language,'name'); ?>
                            <input type="text" class="form-control" id="name" value="<?php echo $category['name']; ?>" />
                            <?php foreach ($array_languages as $lang) {
                                if($lang!=$default_language) : ?>
                                    <input style="display:none;" type="text" class="form-control input_lang" data-target-id="name" data-lang="<?php echo $lang; ?>" value="<?php echo $array_input_lang[$lang]['name']; ?>" />
                                <?php endif;
                            } ?>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="id_category_parent"><?php echo _("Parent Category"); ?></label>
                            <select class="form-control" id="id_category_parent">
                                <option id="0">--</option>
                                <?php echo get_parent_categories($category['id_map'],$category['id_category_parent'],$id_category); ?>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="default_selected"><?php echo _("Default selected"); ?></label> <i title="<?php echo _("the category will be automatically selected when the map starts"); ?>" class="help_t fas fa-question-circle"></i><br>
                            <input <?php echo ($category['default_selected']) ? 'checked' : '' ; ?> type="checkbox" id="default_selected" />
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="featured"><?php echo _("Featured"); ?></label> <i title="<?php echo _("featured categories will be displayed at the top left under the search bar"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                            <input <?php echo ($category['featured']) ? 'checked' : '' ; ?> type="checkbox" id="featured" />
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label for="add_from_map"><?php echo _("Add markers from Map"); ?></label> <i title="<?php echo _("display this category or not when adding a marker from the map"); ?>" class="help_t fas fa-question-circle"></i><br>
                            <input <?php echo ($category['add_from_map']) ? 'checked' : '' ; ?> type="checkbox" id="add_from_map" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-map-marker"></i> <?php echo _("Icon Style"); ?></h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                            <label><?php echo _("Type"); ?></label>
                            <select id="icon_type_c" onchange="change_icon_type_c();" class="form-control">
                                <option <?php echo ($category['icon']=='' && $category['icon_image']=='') ? 'selected' : '' ; ?> id="0"><?php echo _("Circle"); ?></option>
                                <option <?php echo ($category['icon']!='' && $category['icon_image']=='') ? 'selected' : '' ; ?> id="1"><?php echo _("Icon"); ?></option>
                                <option <?php echo ($category['icon_image']!='') ? 'selected' : '' ; ?> id="2"><?php echo _("Icon Library"); ?></option>
                            </select>
                        </div>
                    </div>
                    <div id="icon_type_c_1" class="col-md-3 <?php echo ($category['icon']!='' && $category['icon_image']=='') ? '' : 'd-none' ; ?>">
                        <div class="form-group">
                            <label><?php echo _("Icon"); ?></label><br>
                            <button class="btn btn-sm btn-primary" type="button" id="GetIconPicker_c" data-iconpicker-input="input#marker_icon_input_c" data-iconpicker-preview="i#marker_icon_c"><?php echo _("Select Icon"); ?></button>
                            <input readonly type="text" id="marker_icon_input_c" name="Icon_c" value="<?php echo $category['icon']; ?>" required="" placeholder="" autocomplete="off" spellcheck="false">
                            <div class="icon-preview d-inline-block ml-1" data-toggle="tooltip" title="">
                                <i id="marker_icon_c" class="<?php echo $category['icon']; ?>"></i>
                            </div>
                        </div>
                    </div>
                    <div id="icon_type_c_2" class="col-md-3 <?php echo ($category['icon_image']!='') ? '' : 'd-none' ; ?>">
                        <div class="form-group">
                            <label for="marker_library_icon_c"><?php echo _("Icon"); ?></label><br>
                            <button data-toggle="modal" data-target="#modal_library_icons_c" class="btn btn-sm btn-primary" type="button" id="btn_library_icon_c"><?php echo _("Select Library Icon"); ?></button>
                            <input type="hidden" id="marker_library_icon_c" value="<?php echo $category['id_icon_library']; ?>">
                            <img id="marker_library_icon_preview_c" style="height: 30px;display: <?php echo ($category['icon_image']=='') ? 'none':'inline-block'; ?>" src="../viewer/icons/<?php echo $category['icon_image']; ?>">
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group <?php echo ($category['icon_image']!='') ? 'disabled':''; ?>">
                            <label><?php echo _("Background"); ?></label>
                            <input type="text" class="form-control" id="color_hex_c" value="<?php echo $category['color_hex']; ?>" />
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="form-group <?php echo ($category['icon_image']!='' || ($category['icon']=='' && $category['icon_image']=='')) ? 'disabled':''; ?>">
                            <label><?php echo _("Color"); ?></label>
                            <input type="text" class="form-control" id="icon_color_hex_c" value="<?php echo $category['icon_color_hex']; ?>" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card shadow mb-4">
            <a href="#collapsePI" class="d-block card-header py-3 collapsed" data-toggle="collapse" role="button" aria-expanded="false" aria-controls="collapsePI">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-map-marker-alt"></i> <?php echo _("Bulk Assign Markers Icon"); ?></h6>
            </a>
            <div class="collapse" id="collapsePI">
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label><?php echo _("Type"); ?></label>
                                <select id="icon_type" onchange="change_icon_type();" class="form-control">
                                    <option <?php echo ($category['markers_icon']=='' && $category['markers_icon_image']=='') ? 'selected' : '' ; ?> id="0"><?php echo _("Circle"); ?></option>
                                    <option <?php echo ($category['markers_icon']!='' && $category['markers_icon_image']=='') ? 'selected' : '' ; ?> id="1"><?php echo _("Icon"); ?></option>
                                    <option <?php echo ($category['markers_icon_image']!='') ? 'selected' : '' ; ?> id="2"><?php echo _("Icon Library"); ?></option>
                                </select>
                            </div>
                        </div>
                        <div id="icon_type_1" class="col-md-4 <?php echo ($category['markers_icon']!='' && $category['markers_icon_image']=='') ? '' : 'd-none' ; ?>">
                            <div class="form-group">
                                <label><?php echo _("Icon"); ?></label><br>
                                <button class="btn btn-sm btn-primary" type="button" id="GetIconPicker" data-iconpicker-input="input#marker_icon_input" data-iconpicker-preview="i#marker_icon"><?php echo _("Select Icon"); ?></button>
                                <input readonly type="text" id="marker_icon_input" name="Icon" value="<?php echo $category['markers_icon']; ?>" required="" placeholder="" autocomplete="off" spellcheck="false">
                                <div class="icon-preview d-inline-block ml-1" data-toggle="tooltip" title="">
                                    <i id="marker_icon" class="<?php echo $category['markers_icon']; ?>"></i>
                                </div>
                            </div>
                        </div>
                        <div id="icon_type_2" class="col-md-4 <?php echo ($category['markers_icon_image']!='') ? '' : 'd-none' ; ?>">
                            <div class="form-group">
                                <label for="marker_library_icon"><?php echo _("Icon"); ?></label><br>
                                <button data-toggle="modal" data-target="#modal_library_icons" class="btn btn-sm btn-primary" type="button" id="btn_library_icon"><?php echo _("Select Library Icon"); ?></button>
                                <input type="hidden" id="marker_library_icon" value="<?php echo $category['markers_id_icon_library']; ?>">
                                <img id="marker_library_icon_preview" style="height: 30px;display: <?php echo ($category['markers_icon_image']=='') ? 'none':'inline-block'; ?>" src="../viewer/icons/<?php echo $category['markers_icon_image']; ?>">
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="markers_size"><?php echo _("Size"); ?> (<span id="markers_size_value"><?php echo $category['markers_size']; ?></span>)</label><br>
                                <input oninput="change_markers_size();" onchange="change_markers_size();" type="range" step="0.1" min="0.1" max="2.0" class="form-control-range" id="markers_size" value="<?php echo $category['markers_size']; ?>" />
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-3">
                            <div class="form-group <?php echo ($category['markers_icon_image']!='') ? 'disabled':''; ?>">
                                <label><?php echo _("Background"); ?></label>
                                <input type="text" class="form-control" id="color_hex" value="<?php echo $category['markers_color_hex']; ?>" />
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group <?php echo ($category['markers_icon_image']!='' || ($category['markers_icon']=='' && $category['markers_icon_image']=='')) ? 'disabled':''; ?>">
                                <label><?php echo _("Color"); ?></label>
                                <input type="text" class="form-control" id="icon_color_hex" value="<?php echo $category['markers_icon_color_hex']; ?>" />
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group <?php echo ($category['markers_icon_image']!='') ? 'disabled':''; ?>">
                                <label><?php echo _("Background (Hover / Active)"); ?></label>
                                <input type="text" class="form-control" id="color_hex_hover" value="<?php echo $category['markers_color_hex_hover']; ?>" />
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group <?php echo ($category['markers_icon_image']!='' || ($category['markers_icon']=='' && $category['markers_icon_image']=='')) ? 'disabled':''; ?>">
                                <label><?php echo _("Color (Hover / Active)"); ?></label>
                                <input type="text" class="form-control" id="icon_color_hex_hover" value="<?php echo $category['markers_icon_color_hex_hover']; ?>" />
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label style="opacity:0">.</label><br>
                                <button id="btn_assign_icons" onclick="assign_icon_to_markers('category',<?php echo $id_category; ?>)" class="btn btn-block btn-primary <?php echo ($demo) ? 'disabled':''; ?> <?php echo ($count_markers==0) ? 'disabled' : ''; ?>"><?php echo _("ASSIGN ICON TO")." ".$count_markers." "._("MARKERS"); ?></button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card shadow mb-4">
            <a href="#collapsePI2" class="d-block card-header py-3 collapsed" data-toggle="collapse" role="button" aria-expanded="false" aria-controls="collapsePI2">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-plus-circle"></i> <?php echo _("Add markers from Map")." - "._("Fields Enabled"); ?></h6>
            </a>
            <div class="collapse" id="collapsePI2">
                <div class="card-body">
                    <div style="padding: 0 15px;" class="row">
                        <label class="mb-0"><input id="add_markers_fields_override" <?php echo ($override) ? 'checked' : ''; ?> type="checkbox" />&nbsp;&nbsp;<?php echo _("Override"); ?></label>
                    </div>
                    <hr>
                    <div id="add_markers_fields" class="row <?php echo ($override) ? '' : 'disabled'; ?>">
                        <div class="form-group disabled">
                            <label><input type="checkbox" id="am_categories" <?php echo set_am_field_checked('categories',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Categories"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('street',$default_am_fields)) ? (($default_am_fields['street']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_street" <?php echo set_am_field_checked('street',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Street"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('city',$default_am_fields)) ? (($default_am_fields['city']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_city" <?php echo set_am_field_checked('city',$category_am_fields,$default_am_fields); ?> /> <?php echo _("City"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('state',$default_am_fields)) ? (($default_am_fields['state']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_state" <?php echo set_am_field_checked('state',$category_am_fields,$default_am_fields); ?> /> <?php echo _("State"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('postal_code',$default_am_fields)) ? (($default_am_fields['postal_code']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_postal_code" <?php echo set_am_field_checked('postal_code',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Postal Code"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('county',$default_am_fields)) ? (($default_am_fields['county']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_county" <?php echo set_am_field_checked('county',$category_am_fields,$default_am_fields); ?> /> <?php echo _("County"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('country',$default_am_fields)) ? (($default_am_fields['country']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_country" <?php echo set_am_field_checked('country',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Country"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('website',$default_am_fields)) ? (($default_am_fields['website']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_website" <?php echo set_am_field_checked('website',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Website"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('email',$default_am_fields)) ? (($default_am_fields['email']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_email" <?php echo set_am_field_checked('email',$category_am_fields,$default_am_fields); ?> /> <?php echo _("E-Mail"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('phone',$default_am_fields)) ? (($default_am_fields['phone']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_phone" <?php echo set_am_field_checked('phone',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Phone"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('whatsapp',$default_am_fields)) ? (($default_am_fields['whatsapp']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_whatsapp" <?php echo set_am_field_checked('whatsapp',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Whatsapp"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('description',$default_am_fields)) ? (($default_am_fields['description']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_description" <?php echo set_am_field_checked('description',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Description"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('hours',$default_am_fields)) ? (($default_am_fields['hours']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_hours" <?php echo set_am_field_checked('hours',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Hours"); ?></label>
                        </div>
                        <div class="form-group">
                            <label class="<?php echo (array_key_exists('images',$default_am_fields)) ? (($default_am_fields['images']==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_images" <?php echo set_am_field_checked('images',$category_am_fields,$default_am_fields); ?> /> <?php echo _("Images"); ?></label>
                        </div>
                        <div style="width:100%;clear:both"></div>
                        <?php for($i=1;$i<=10;$i++) { ?>
                            <div class="form-group">
                                <label class="<?php echo (array_key_exists('field_'.$i,$default_am_fields)) ? (($default_am_fields['field_'.$i]==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_field_<?php echo $i; ?>" <?php echo set_am_field_checked('field_'.$i,$category_am_fields,$default_am_fields); ?> /> <?php echo _("Field")." $i"; ?></label>
                            </div>
                        <?php } ?>
                        <?php for($i=11;$i<=20;$i++) { ?>
                            <div class="form-group">
                                <label class="<?php echo (array_key_exists('field_'.$i,$default_am_fields)) ? (($default_am_fields['field_'.$i]==1) ? '' : 'disabled') : ''; ?>"><input type="checkbox" id="am_field_<?php echo $i; ?>" <?php echo set_am_field_checked('field_'.$i,$category_am_fields,$default_am_fields); ?> /> <?php echo _("Field")." $i"; ?></label>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="modal_library_icons" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Library Icons"); ?></h5>
            </div>
            <div class="modal-body">
                <?php echo get_library_icons($map['id']); ?>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_library_icons_c" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Library Icons"); ?></h5>
            </div>
            <div class="modal-body">
                <?php echo get_library_icons_c($map['id']); ?>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_delete_category" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Delete Category"); ?></h5>
            </div>
            <div class="modal-body">
                <p><?php echo _("Are you sure you want to delete the category?"); ?></p>
            </div>
            <div class="modal-footer">
                <button <?php echo ($demo) ? 'disabled':''; ?> id="btn_delete_category" onclick="" type="button" class="btn btn-danger"><?php echo _("Yes, Delete"); ?></button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<script>
    (function($) {
        "use strict";
        window.id_category = <?php echo $id_category; ?>;
        window.color_hex_spectrum = null;
        window.icon_color_hex_spectrum = null;
        window.color_hex_c_spectrum = null;
        window.icon_color_hex_c_spectrum = null;
        window.color_hex_hover_spectrum = null;
        window.icon_color_hex_hover_spectrum = null;
        window.category_need_save = false;

        $(document).ready(function () {
            $('.help_t').tooltip();
            $('#add_markers_fields_override').on('input', function() {
               if($(this).is(':checked')) {
                   $('#add_markers_fields').removeClass('disabled');
               } else {
                   $('#add_markers_fields').addClass('disabled');
               }
            });
            IconPicker.Init({
                jsonUrl: 'vendor/iconpicker/iconpicker-7.2.0.json',
                searchPlaceholder: '<?php echo _("Search Icon"); ?>',
                showAllButton: '<?php echo _("Show All"); ?>',
                cancelButton: '<?php echo _("Cancel"); ?>',
                noResultsFound: '<?php echo _("No results found."); ?>',
                borderRadius: '20px',
            });
            IconPicker.Run('#GetIconPicker', function(){
                window.map_need_save = true;
            });
            IconPicker.Run('#GetIconPicker_c', function(){
                window.map_need_save = true;
            });
            window.color_hex_spectrum = $('#color_hex').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            window.icon_color_hex_spectrum = $('#icon_color_hex').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: false
            });
            window.color_hex_c_spectrum = $('#color_hex_c').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            window.icon_color_hex_c_spectrum = $('#icon_color_hex_c').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: false
            });
            window.color_hex_hover_spectrum = $('#color_hex_hover').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            window.icon_color_hex_hover_spectrum = $('#icon_color_hex_hover').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
        });

        $("input").change(function(){
            window.category_need_save = true;
        });

        $(window).on('beforeunload', function(){
            if(window.category_need_save) {
                var c=confirm();
                if(c) return true; else return false;
            }
        });
    })(jQuery);
</script>
