<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__)
    .' is not allowed.' );


/**
 *
 * @package  MediaLibrary
 * @copyright 2021 Andrey Kvasnevskiy-OrdaSoft(akbet@mail.ru); Rob de Cleen(rob@decleen.com);
 * Homepage: https://ordasoft.com
 * @version: 4.6 Free
 * @license GNU General Public license version 2 or later; see LICENSE.txt
 *
 */

$doc = JFactory::getDocument();
$doc->addStyleSheet(JURI::root(true) . '/components/com_medialibrary/includes/jQuerMedia-ui.css');
$max_price = $params->get('max_price');
$min_price = $params->get('min_price');
?>

<?php positions_ml($params->get('allcategories01'));?>

<?php positions_ml($params->get('allcategories02'));?>

<?php positions_ml($params->get('allcategories03'));?>
<?php  if($params->get('show_search')){ ?>
    
    <?php
    if($params->get('search_fieldshow') || 1){?>
        <script type="text/javascript">
            jQuerMedia(function() {
                jQuerMedia(".form_search #ml_slider").slider({
                    min: <?php echo $min_price;?>,
                    max: <?php echo $max_price;?>,
                    values: [<?php echo $min_price;?>,<?php echo $max_price;?>],
                    range: true,
                    stop: function(event, ui) {
                        jQuerMedia(".form_search input#pricefrom").val(jQuerMedia(
                            ".form_search #ml_slider").slider("values",0));
                        jQuerMedia(".form_search input#priceto").val(jQuerMedia(
                            ".form_search #ml_slider").slider("values",1));
                    },
                    slide: function(event, ui){
                        jQuerMedia(".form_search input#pricefrom").val(jQuerMedia(
                            ".form_search #ml_slider").slider("values",0));
                        jQuerMedia(".form_search input#priceto").val(jQuerMedia(
                            ".form_search #ml_slider").slider("values",1));
                    }
                });

                jQuerMedia(".form_search input#pricefrom").change(function(){
                    var value1=jQuerMedia(".form_search input#pricefrom").val();
                    var value2=jQuerMedia(".form_search input#priceto").val();

                    if(parseInt(value1) > parseInt(value2)){
                        value1 = value2;
                        jQuerMedia(".form_search input#pricefrom").val(value1);
                    }
                    jQuerMedia(".form_search #ml_slider").slider("values",0,value1);
                });

                jQuerMedia(".form_search input#priceto").change(function(){
                    var value1=jQuerMedia(".form_search input#pricefrom").val();
                    var value2=jQuerMedia(".form_search input#priceto").val();

                    if(parseInt(value1) > parseInt(value2)){
                        value2 = value1;
                        jQuerMedia(".form_search input#priceto").val(value2);
                    }
                    if(value2 > <?php echo $max_price;?>){
                        jQuerMedia(".form_search input#priceto").val(<?php echo $max_price;?>)
                    }
                    jQuerMedia(".form_search #ml_slider").slider("values",1,value2);
                });
            });
        </script>
            
        <noscript>
            Javascript is required to use MediaLibrary 
            <a href="https://ordasoft.com/media-library-joomla-extension">
                Media Library Software for create modern library .
            </a>,
            <a href="https://ordasoft.com/media-library-joomla-extension">
                MediaLibrary create website for rent, sell media files
            </a>
        </noscript>


        <div id="medialibrary">
        <div class="componentheading<?php echo $params->get('pageclass_sfx'); ?>">
                        <?php echo $currentcat->header; ?>
        </div>

        <form action="<?php echo sefRelToAbs("index.php?option=com_medialibrary" ); ?>"
            method="get" name="mediaEditForm">
            <div class="form_search">
                <div class="ml-row">
                    <div class="ml-collumn-xs-12 ml-collumn-sm-6 ml-collumn-md-5 ml-collumn-lg-5">
                        <div class="keyword_container">
                            <div class="row_bck">
                                <div class="search_title">
                                        <?php echo _MEDIALIBRARY_LABEL_SEARCH_KEYWORD ; ?>
                                </div>
                                        <input class="inputbox" type="text" name="searchtext" size="20" maxlength="20"/>
                                        <input type="hidden" name="option" value="com_medialibrary"/>
                                        <input type="hidden" name="task" value="search"/>
                                        <input type="hidden" name="Itemid" value="<?php echo $Itemid;?>"/>

                            </div>

                            <div class="ck_r ck_ext">
                                <input id="ck_ext" type="checkbox" name="exactly" />
                                <label for="ck_ext" class="search_title">
                                    <?php echo _MEDIALIBRARY_SHOW_SEARCH_EXACTLY; ?>
                                </label>
                            </div>
                        </div>

                        <div class="ck_cat">
                        <div class="search_title">
                              <?php echo _MEDIALIBRARY_LABEL_MEDIALIBRARY_CATEGORY . '<br>'; ?>
                        </div>
                              <?php echo $clist; ?>
                        </div>
                    </div>

                    <div class="ml-collumn-xs-12 ml-collumn-sm-6 ml-collumn-md-6 ml-collumn-lg-6">

                        <div class="price_slider_container">
                            <div class="search_title">
                            <?php echo _MEDIALIBRARY_LABEL_PRICE; ?>
                            </div>

                            <div id="ml_slider" class="ui-slider ui-slider-horizontal ui-widget ui-widget-content
                            ui-corner-all">
                            </div>
                        </div>

                        <div class="ml-row">
                            <div class="pricefrom_2 ml-collumn-xs-12 ml-collumn-sm-6 ml-collumn-md-6 ml-collumn-lg-6">
                                <div class="search_title">
                                <?php echo _MEDIALIBRARY_LABEL_AVAILABLE_FOR_LEND_FROM; ?>
                                </div>
                                <input type="text" class="inputbox" id="pricefrom" name="pricefrom" 
                                       value="<?php echo $min_price;?>"/>
                            </div>
                            <div class="priceto_2 ml-collumn-xs-12 ml-collumn-sm-6 ml-collumn-md-6 ml-collumn-lg-6">
                                <div class="search_title">
                                <?php echo _MEDIALIBRARY_SHOW_SEARCH_PRICE_TO; ?>
                                </div>
                                <input type="text" class="inputbox" id="priceto" name="priceto" 
                                       value="<?php echo $max_price;?>"/>
                            </div>
                        </div>


                    </div>

                </div>

                <div class="all_checkbox_container panel-collapse collapse" id="all_checkbox_container">
                    <div class="search_inline ml_mod_search_general_checkbox"
                         style="display: inline-block; margin-right: 46px;">
                        <div class="box_from">
                            <script>
                            function titleon(){
                            var titlehidden = document.getElementById("titlehidden").getElementsByTagName('input');
                            for(var i=0;i<titlehidden.length;i++){
                            titlehidden[i].value = true;
                            }
                            };
                            function titleoff() {
                            var titlehidden = document.getElementById("titlehidden").getElementsByTagName('input');
                            for(var i=0;i<titlehidden.length;i++){
                            titlehidden[i].value = '';
                            }
                            };

                            </script>
                            Title:&nbsp;
                            <input type="checkbox" name="title" checked='checked' 
                                   onClick="if(this.checked) {titleon();} else{titleoff();}"/>
                                <div id="titlehidden">
                                    <input type='hidden' name="book-title" value='true'/>
                                    <input type='hidden' name="game-title"  value='true'/>
                                    <input type='hidden' name="music-title"  value='true'/>
                                    <input type='hidden' name="video-title" value='true'/>
                                </div>
                            </div>
                        <div class="box_from">
                            <script>
                            function commenton(){
                            var commenthidden = document.getElementById("commenthidden").getElementsByTagName('input');
                            for(var i=0;i<commenthidden.length;i++){
                            commenthidden[i].value = true;
                            }
                            };
                            function commentoff() {
                            var commenthidden = document.getElementById("commenthidden").getElementsByTagName('input');
                            for(var i=0;i<commenthidden.length;i++){
                            commenthidden[i].value = '';
                            }
                            };

                            </script>
                            Comment:&nbsp;<input type="checkbox" name="comment" checked='checked' onClick="if(this.checked) {commenton();} else{commentoff();}"/>
                                <div id="commenthidden">
                                    <input type='hidden' name="book-comment" value='true'/>
                                    <input type='hidden' name="game-comment"  value='true'/>
                                    <input type='hidden' name="music-comment"  value='true'/>
                                    <input type='hidden' name="video-comment" value='true'/>
                                </div>
                            </div>

                        <div class="box_from">
                            <script>
                            function languageon(){
                            var languagehidden = document.getElementById("languagehidden").getElementsByTagName('input');
                            for(var i=0;i<languagehidden.length;i++){
                            languagehidden[i].value = true;
                            }
                            };
                            function languageoff() {
                            var languagehidden = document.getElementById("languagehidden").getElementsByTagName('input');
                            for(var i=0;i<languagehidden.length;i++){
                            languagehidden[i].value = '';
                            }
                            };

                            </script>
                            Language:&nbsp;<input type="checkbox" name="language" checked='checked' onClick="if(this.checked) {languageon();} else{languageoff();}"/>
                                <div id="languagehidden">
                                    <input type='hidden' name="book-language" value='true'/>
                                    <input type='hidden' name="game-language"  value='true'/>
                                    <input type='hidden' name="music-language"  value='true'/>
                                    <input type='hidden' name="video-language" value='true'/>
                                </div>
                            </div>
                    
                        <script>
                            function idon(){
                                var idhidden = document.getElementById("idhidden").getElementsByTagName('input');
                                for(var i=0;i<idhidden.length;i++){
                                    idhidden[i].value = true;
                                }
                            };
                            function idoff() {
                                var idhidden = document.getElementById("idhidden").getElementsByTagName('input');
                                for(var i=0;i<idhidden.length;i++){
                                    idhidden[i].value = '';
                                }
                            };

                        </script>
                        ID:&nbsp;
                        <input type="checkbox" name="id" checked='checked' 
                            onClick="if(this.checked) {idon();} else{idoff();}"/>
                        <div id="idhidden">
                            <input type='hidden' name="book_id" value='true'/>
                            <input type='hidden' name="game_id" value='true'/>
                            <input type='hidden' name="music_id" value='true'/>
                            <input type='hidden' name="video_id" value='true'/>
                        </div>
                    </div>
                        
                </div>

                <div class="check">
                    <?php
                    $search_fields = get_search_fields_for_defoult();
                    HTML_medialibrary::create_search_tr($search_fields);
                    ?>
                </div>
            </div>
            <div class="ck_btr">
                <input type="submit" name="submit" value="<?php
                                echo _MEDIALIBRARY_LABEL_SEARCH_BUTTON; ?>" class="button" />
            </div>
        </form>
        

    <?php }?>
        
        <?php 
        }
        positions_ml($params->get('allcategories07'));
    if ($params->get('show_add_media')){
        HTML_medialibrary::showAddButton($params, 1, $catid, $Itemid);
    }
    positions_ml($params->get('allcategories08'));
if ($params->get('ownerslist_show')){
    HTML_medialibrary::showOwnersButton();
}


positions_ml($params->get('allcategories09'));
?>

<?php if ($params->get('back_button')!= '') {?>
            <div style="text-align: center;" class="back_button">
                <?php mosHTML::BackButton ( $params, $hide_js ); ?>
            </div>
<?php } ?>

</div>

