<?php
/*
 * @package Sj K2 Filter
 * @version 1.1.0
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2015 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 *
 */
defined('_JEXEC') or die;
?>

<script type="text/javascript">
//<![CDATA[
function isDate(txtDate){
    var reg = /^(\d{4})([\/-])(\d{1,2})\2(\d{1,2})$/;
    return reg.test(txtDate);
}

function validateDateRange(obj){
    if(obj.id == 'sdate_<?php echo $module->id; ?>' || obj.id == 'edate_<?php echo $module->id; ?>'){
        var sDate = $('sjk2filter<?php echo $module->id;?>').getElement('#sdate_<?php echo $module->id; ?>').get('value');
        var eDate = $('sjk2filter<?php echo $module->id;?>').getElement('#edate_<?php echo $module->id; ?>').get('value');
        if(sDate != '' && eDate != ''){
            if(isDate(sDate) && isDate(eDate)){
                obj.removeClass('date-error');
                $('<?php echo $formid; ?>').fireEvent('submit');
            }
            else{
                obj.addClass('date-error');
            }
        }
    }
    else{
        $('<?php echo $formid; ?>').fireEvent('submit');
    }
}

jQuery(document).ready(function($){
	;(function(element){
		var $element = $(element);
		
		$('.filter-field > div.filter-options-title', $element).on('click', function() {
			if ($(this).hasClass('collapsed')) {
				$(this).removeClass('collapsed');
				$(this).next().slideDown();
			}
			else {
				$(this).removeClass('collapsed').addClass('collapsed');
				$(this).next().slideUp();
			}
		});

		<?php if ($mod_layout == 'horizontal-layout') {?>
			$('#sjk2filter<?php echo $module->id?> li .filter-field .filter-options-title').each(function() {
				if ($(this).hasClass('collapsed')) {
					$(this).removeClass('collapsed');
					$(this).next().slideDown();
				}
				else {
					$(this).addClass('collapsed');
					$(this).next().slideUp();
				}
			})
		<?php }?>
	})('#<?php echo $uniqueid ; ?>');
});
//]]>
</script>