<?php
define('THEME_NAME','Directory Theme');
  
// SET THE THEME FOLDER
define('THEME_FOLDER','_directory'); 
define('THEME_KEY','dt');

// SET THE ADMIN LABEL
define('THEME_LISING_CAPTION', 'Listings');

// SET THE ADMIN PANEL BOX
define('THEME_LISING_IMAGES', true);

// SET THE ADMIN MAP PANEL
define('THEME_LISING_MAP', true);
define('GOOGLE-MAPS', true);

 
 
class widget_directory_nearby extends WP_Widget {
    function __construct(){
        // widget actual processes		
		$opts = array(
			'classname' => 'widget_directory_nearby',
			'description' => 'This will display the listing nearby box.' 
		);
		parent::__construct( 'widget_directory_nearby',  '[DT] - Nearby Listing' , $opts );		
    }
	function form($instance) {	
 		$defaults = array( 'showtitle'		=> '1' );		
		$instance = wp_parse_args( $instance, $defaults );  		
		echo '<br><br><input id="' . $this->get_field_id('showtitle') . '" 
		name="' . $this->get_field_name('showtitle') . '" 
		type="checkbox" ' . checked(isset($instance['showtitle'])? $instance['showtitle']: 0, true, false) . ' /> Show Widget Title ';		
	}
	function update( $new, $old )	{		
		$clean = $old;	  
		$clean['showtitle'] = isset( $new['showtitle'] ) ? '1' : '0';
		return $clean;
	}
    function widget($args, $instance) {
	global $settings;
	if(!isset($instance['showtitle'])){ $instance['showtitle'] = 1; }
	$settings['showtitle'] = $instance['showtitle'];		
	get_template_part( '_directory/widgets/widget', 'nearby' ); 
    }
} // END BLANK WIDGET
class widget_directory_callus extends WP_Widget {
    function __construct(){
        // widget actual processes		
		$opts = array(
			'classname' => 'widget_directory_callus',
			'description' => 'This will display the call us box.' 
		);
		parent::__construct( 'widget_directory_callus',  '[DT] - Contact Info' , $opts );		
    }
	function form($instance) {	
 		$defaults = array( 'showtitle'		=> '1' );		
		$instance = wp_parse_args( $instance, $defaults );  		
		echo '<br><br><input id="' . $this->get_field_id('showtitle') . '" 
		name="' . $this->get_field_name('showtitle') . '" 
		type="checkbox" ' . checked(isset($instance['showtitle'])? $instance['showtitle']: 0, true, false) . ' /> Show Widget Title ';		
	}
	function update( $new, $old )	{		
		$clean = $old;	  
		$clean['showtitle'] = isset( $new['showtitle'] ) ? '1' : '0';
		return $clean;
	}
    function widget($args, $instance) {
	global $settings;
	if(!isset($instance['showtitle'])){ $instance['showtitle'] = 1; }
	$settings['showtitle'] = $instance['showtitle'];		
	get_template_part( '_directory/widgets/widget', 'call' ); 
    }
} // END BLANK WIDGET

class widget_directory_rating extends WP_Widget {
    function __construct(){
        // widget actual processes		
		$opts = array(
			'classname' => 'widget_directory_rating',
			'description' => 'This will display the rating box.' 
		);
		parent::__construct( 'widget_directory_rating',  '[DT] - Rating Box' , $opts );		
    }
	function form($instance) {	
 		$defaults = array( 'showtitle'		=> '1' );		
		$instance = wp_parse_args( $instance, $defaults );  		
		echo '<br><br><input id="' . $this->get_field_id('showtitle') . '" 
		name="' . $this->get_field_name('showtitle') . '" 
		type="checkbox" ' . checked(isset($instance['showtitle'])? $instance['showtitle']: 0, true, false) . ' /> Show Widget Title ';		
	}
	function update( $new, $old )	{		
		$clean = $old;	  
		$clean['showtitle'] = isset( $new['showtitle'] ) ? '1' : '0';
		return $clean;
	}
    function widget($args, $instance) {
	global $settings;
	if(!isset($instance['showtitle'])){ $instance['showtitle'] = 1; }
	$settings['showtitle'] = $instance['showtitle'];		
	get_template_part( '_directory/widgets/widget', 'rating' ); 
    }
} // END BLANK WIDGET

class widget_directory_openinghours extends WP_Widget {
    function __construct(){
        // widget actual processes		
		$opts = array(
			'classname' => 'widget_directory_openinghours',
			'description' => 'This will display the opening hours box.' 
		);
		parent::__construct( 'widget_directory_openinghours',  '[DT] - Opening Hours' , $opts );		
    }
	function form($instance) {	
 		$defaults = array( 'showtitle'		=> '1' );		
		$instance = wp_parse_args( $instance, $defaults );  		
		echo '<br><br><input id="' . $this->get_field_id('showtitle') . '" 
		name="' . $this->get_field_name('showtitle') . '" 
		type="checkbox" ' . checked(isset($instance['showtitle'])? $instance['showtitle']: 0, true, false) . ' /> Show Widget Title ';		
	}
	function update( $new, $old )	{		
		$clean = $old;	  
		$clean['showtitle'] = isset( $new['showtitle'] ) ? '1' : '0';
		return $clean;
	}
    function widget($args, $instance) {
	global $settings;
	if(!isset($instance['showtitle'])){ $instance['showtitle'] = 1; }
	$settings['showtitle'] = $instance['showtitle'];		
	get_template_part( '_directory/widgets/widget', 'openinghours' ); 
    }
} // END BLANK WIDGET

class widget_directory_claimlisting extends WP_Widget {
    function __construct(){
        // widget actual processes		
		$opts = array(
			'classname' => 'widget_directory_claimlisting',
			'description' => 'This will display the claim listing box.' 
		);
		parent::__construct( 'widget_directory_claimlisting',  '[DT] - Claim Listing ' , $opts );		
    }
	function form($instance) {	
 		$defaults = array( 'showtitle'		=> '1' );		
		$instance = wp_parse_args( $instance, $defaults );  		
		echo '<br><br><input id="' . $this->get_field_id('showtitle') . '" 
		name="' . $this->get_field_name('showtitle') . '" 
		type="checkbox" ' . checked(isset($instance['showtitle'])? $instance['showtitle']: 0, true, false) . ' /> Show Widget Title ';		
	}
	function update( $new, $old )	{		
		$clean = $old;	  
		$clean['showtitle'] = isset( $new['showtitle'] ) ? '1' : '0';
		return $clean;
	}
    function widget($args, $instance) {
	global $settings;
	if(!isset($instance['showtitle'])){ $instance['showtitle'] = 1; }
	$settings['showtitle'] = $instance['showtitle'];			
	get_template_part( '_directory/widgets/widget', 'claimlisting' ); 
    }
} // END BLANK WIDGET

class widget_directory_contactform extends WP_Widget {
    function __construct(){
        // widget actual processes		
		$opts = array(
			'classname' => 'widget_directory_contactform',
			'description' => 'This will display the claim listing box.' 
		);
		parent::__construct( 'widget_directory_contactform',  '[DT] - Contact Form ' , $opts );		
    }
	function form($instance) {	
 		$defaults = array( 'showtitle'		=> '1' );		
		$instance = wp_parse_args( $instance, $defaults );  		
		echo '<br><br><input id="' . $this->get_field_id('showtitle') . '" 
		name="' . $this->get_field_name('showtitle') . '" 
		type="checkbox" ' . checked(isset($instance['showtitle'])? $instance['showtitle']: 0, true, false) . ' /> Show Widget Title ';		
	}
	function update( $new, $old )	{		
		$clean = $old;	  
		$clean['showtitle'] = isset( $new['showtitle'] ) ? '1' : '0';
		return $clean;
	}
    function widget($args, $instance) {
	global $settings;
	if(!isset($instance['showtitle'])){ $instance['showtitle'] = 1; }
	$settings['showtitle'] = $instance['showtitle'];			
	get_template_part( '_directory/widgets/widget', 'contactform' ); 
    }
} // END BLANK WIDGET
 
 
$CORE_DIRECTORY	= new core_directory;
class core_directory {

function _register_widgets(){ 
register_widget( 'widget_directory_callus' );
register_widget( 'widget_directory_rating' );
register_widget( 'widget_directory_openinghours' );
register_widget( 'widget_directory_claimlisting' );
register_widget( 'widget_directory_nearby' );

}


function _hook_v9_admin_elementor_templates($c){
 	
	$c['defaultlisting'] = array(
		"name" 			=> "Listing Page",
		"description" 	=> "Here you can install the listing page template file that can be modified using the Elementor page builder plugin.",
		"video" 		=> "",
		"file" 			=> __DIR__ ."/elementor/single-listing.json",
		"listingpage"	=> true,
		"page_template"	=> "elementor_header_footer",
		"noview" 		=> true,
	);

 	
	return $c;
}
 

	function __construct(){
	
	// REGISTER WIDGETS
	add_action( 'widgets_init', array($this, '_register_widgets' ) );

		// GLOBAL FUNCTIONS
		add_action('init', array($this, 	'_init' ) );	
	 
		if(is_admin()){		
			 
			// ADD ON DETAILS TAB
			add_action('hook_v9_admin_edit_options', array($this, 	'_admin_fields' ) );
					 
			add_action('save_post', array($this, '_custom_metabox_save1') );
			
			// HOOK CUSTOM ADMIN PAGES
			add_filter('hook_v9_admin_options', array($this, '_hook_v9_admin_options'),1 );	

			// ADD DEFAULT ELEMENTOR TEMPLATE TO ADMIN PABEL
			add_filter('hook_v9_admin_elementor_templates', array($this, '_hook_v9_admin_elementor_templates'),10 ); 
			
		} 
  
		
 		add_shortcode( 'LASTVIEWED',  array($this, 'ppt_shortcode_lastviewed' ) );
 		 
		// add in new custom fields for submisison page
	 	add_action('hook_add_fieldlist',  array($this, '_hook_customfields' ) );
		
		//AJAX SEARCH
		add_filter('init', array($this, 'ajax_code') ); 
		
		add_action('wp_footer',  array($this, '_wp_footer')  );  
		
	}
	
function ppt_shortcode_lastviewed( $atts = "", $content = null ) { global $userdata, $CORE, $wpdb, $post;   
 	
	extract( shortcode_atts( array(  'pid' => ''), $atts ) );
	
	if(isset($atts['pid'])){
	$post_id = $atts['pid'];
	}else{
	$post_id = $post->ID;
	}
	
	$lasttime = get_post_meta($post_id,'lastviewed', true);
	
	$vv = $CORE->date_timediff($lasttime);		 
	
	return $vv['string-small'];
	 

}
	
function _init(){ global $CORE, $userdata;

	if(isset($_POST['processclaim']) && $userdata->ID && get_post_meta($_POST['post_id'], "claimed", true) == "" ){

			// ALLOW CLAIM
			if(get_user_meta($userdata->ID, "claimed_listing",true) == ""){
			$my_post = array();
			$my_post['ID'] 					= $_POST['post_id'];
			$my_post['post_status']			= "publish";
			$my_post['post_author']			= $userdata->ID;	
			wp_update_post( $my_post  );
			
			// ADD CUSTOM FIELD SO WE KNOW IT WAS CLAIMED
			$_POST['title'] = get_the_title($_POST['post_id']);
			// SET USER FLAG
			update_user_meta($userdata->ID, "claimed_listing", array("title" => get_the_title($_POST['post_id']), "date" => date('Y-m-d')) );
			
			// ADD POST FLAG
			update_post_meta( $_POST['post_id'], 'claimed', date('Y-m-d') );
			
			// REMOVE CLAIM
			//$CORE->SENDEMAIL('admin','admin_newclaim');
			// ADD LOG ENTRY
			$CORE->ADDLOG("<a href='(ulink)'>".$userdata->user_nicename.'</a> claimed listing <b>['.$_POST['title'].']</b>', $userdata->ID, $_POST['post_id'] ,'label-important');
			
			// ERROR MESSAGE
			$GLOBALS['error_type'] = "success";
			$GLOBALS['error_title'] = __("Congratulations!","premiumpress");	
			$GLOBALS['error_message'] = __("You have successfully claimed this listing.","premiumpress");	
			}else{
			// ERROR MESSAGE
			$f = get_user_meta($userdata->ID, "claimed_listing",true);
			$GLOBALS['error_type'] = "error";
			$GLOBALS['error_title'] = __("You already claimed a listing!","premiumpress");	
			$GLOBALS['error_message'] = __("You cannot claim more than one listing per account. You have already claimed the listing <b>".$f['title']."</b> on ".hook_date($f['date']),"premiumpress");	
			}	
	
	}
}


	function ajax_code(){
	
		if(isset($_GET['qs'])){
			
			$ar = array();
			if(is_numeric($_GET['search'])){
			$args = array('post_type' => 'listing_type', 'paged'  => 1, 'p' =>  $_GET['search']  );
			}else{
			$args = array('posts_per_page' => 8, 'post_type' => 'listing_type', 'orderby' => 'name', 'order' => 'asc', 'paged'  => 1, 's' => esc_html($_GET['search']) );
			}
			
			 
			$custom_query = new WP_Query( $args );
		 
			if ( $custom_query->have_posts() ) :
			while( $custom_query->have_posts() ) : $custom_query->the_post(); 
			
			$name = get_the_title();
			if(is_numeric($_GET['search'])){
			$name = get_the_title()." (LOT ".$_GET['search'].")";
			}
			
			$ar['mylist'][] = array(
			'id' => $custom_query->post->ID, 
			'name' => $name, 
			'img' => do_shortcode('[IMAGE post_id="'.$custom_query->post->ID.'" link=0 pathonly=1]'), 
			'link' => get_permalink($custom_query->post->ID), 
			'text' => __("Category","premiumpress").": ".do_shortcode('[CATEGORY limit=1 link=0]'),
			 );  
			
			endwhile; endif;
			 
			echo json_encode($ar);
			die();
		}
	
	}
	
function _wp_footer(){ global $post; ?>
<div id="ajaxLoginModal" class="modal fade login-modal-wrapper" data-width="500" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
<div id="ajaxRegisterModal" class="modal fade login-modal-wrapper" data-width="500" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
<div id="ajaxSearchModal" class="modal fade search-modal-wrapper" data-width="500" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
<div id="ajaxRatingModal" class="modal fade search-modal-wrapper" data-width="500" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
<div id="ajaxClaimModal" class="modal fade search-modal-wrapper" data-width="500" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>

<script>

jQuery(document).ready(function() {

	jQuery("input.typeahead").typeahead({		 	
		onSelect: function(item) { 
		  window.location = item.extra;
		},
		ajax: {
			url: "<?php echo home_url(); ?>/?qs=1",
			timeout: 500,
			triggerLength: 1,
			method: "get",
			preDispatch: function (query) { 
				return {
					search: query
				}
			},
			preProcess: function (data) {
			 
				if (data.success === false) {
					// Hide the list, there was some error
					return false;
				}
			 
				return data.mylist;
			}
		},	
	});
 

	var $modal = jQuery('#ajaxLoginModal');

	jQuery(document).on('click', '.btn-ajax-login' ,function(){
		// create the backdrop and wait for next modal to be triggered
	  
		jQuery('body').modalmanager('loading');

		setTimeout(function(){
			 $modal.load('<?php echo home_url(); ?>/?core_aj=1&action=loginform', '', function(){
				$modal.modal();
			});
		}, 1000);
	});
	
	var $modal2 = jQuery('#ajaxRegisterModal');

	jQuery(document).on('click', '.btn-ajax-register' ,function(){
		// create the backdrop and wait for next modal to be triggered
	  
		jQuery('body').modalmanager('loading');

		setTimeout(function(){
			 $modal2.load('<?php echo home_url(); ?>/?core_aj=1&action=registerform', '', function(){
				$modal2.modal();
			});
		}, 1000);
	});

	
	
	var $modal1 = jQuery('#ajaxSearchModal');

	jQuery(document).on('click', '.btn-ajax-search' ,function(){
		// create the backdrop and wait for next modal to be triggered
	  
		jQuery('body').modalmanager('loading');

		setTimeout(function(){
			 $modal1.load('<?php echo home_url(); ?>/?core_aj=1&action=searchform', '', function(){
				$modal1.modal();
			});
		}, 1000);		
	}); 
		
	
	<?php if(isset($post->ID)){ ?>
	var $modal1 = jQuery('#ajaxRatingModal');

	jQuery(document).on('click', '.btn-ajax-rating' ,function(){
		// create the backdrop and wait for next modal to be triggered
	  
		jQuery('body').modalmanager('loading');

		setTimeout(function(){
			 $modal1.load('<?php echo home_url(); ?>/?core_aj=1&action=ratingform&pid=<?php echo $post->ID; ?>', '', function(){
				$modal1.modal();
				 
			});
		}, 1000);		
	}); 
	<?php } ?>
	
	<?php if(isset($_GET['elementor_library']) || ( _ppt('claimlisting') == '1' && get_post_meta($post->ID, "claimed", true) == "" && user_can($post->post_author, 'administrator')  ) ){  ?>
	var $modal1 = jQuery('#ajaxClaimModal');

	jQuery(document).on('click', '.btn-ajax-claimme' ,function(){
		// create the backdrop and wait for next modal to be triggered
	  
		jQuery('body').modalmanager('loading');

		setTimeout(function(){
			 $modal1.load('<?php echo home_url(); ?>/?core_aj=1&action=extraform&pid=<?php echo $post->ID; ?>', '', function(){
				$modal1.modal();
				 
			});
		}, 1000);		
	}); 
   <?php } ?>

});

</script>
    <?php }
	
 	function _hook_v9_admin_options($c){
	
		$new = array();
		$new["settings"] = array(	
			"name" => __("Directory Settings","premiumpress-admin"),
			"desc"	=> __("Here are additional options for the directory theme.","premiumpress-admin"),
			"icon" => "directory.png",
			"link" => "#",
			"path" => array(hook_theme_folder( array('directory-admin', 'settings', true) ),'settings'),
		); 
		
		if(!is_array($c)){ return $new; }
	
		return array_merge($c,$new);
	}
	
	
	function _custom_metabox_save1($post_id){  
	
			// BUSINESS HOURS
			if(isset($_POST['startTime']) && is_array($_POST['startTime'])){	 
			 
				$businesshours = array( 'start' => $_POST['startTime'], 'end' => $_POST['endTime'], 'active' => $_POST['isActive']  );
				update_post_meta($post_id,"businesshours", $businesshours);				 
			}
	
	}
	
 
	
	
	function _amenities(){
	
		$ami = array();
		$dtamenitites = get_option("dtamenitites"); 
		if(is_array($dtamenitites)){ $i=0; $setKeys = array(); $selectedcatlist = array();
			foreach($dtamenitites['name'] as $data){ 
				if($dtamenitites['name'][$i] != "" ){			
					$ami[$dtamenitites['key'][$i]] = $dtamenitites['name'][$i];			
					$i++; 
				} 
			}
		}			
		
		return $ami;
	
	}
	
	
 
	
	
	
	
	
	/*
		this function sets up all of the custom boxes for pages
		within the admin area
	*/
 
	
function _admin_fields(){ global $post, $CORE; 
	
	?> 
    
    
    <div class="box-admin">
        <label>Company Phone</label>
        <div class="input-group"> 
       <input class="form-control"name="custom[phone]" value="<?php if( isset($_GET['post']) ){  echo get_post_meta($post->ID, "phone", true); } ?>" />
        </div>
    </div> 
    
   <div class="box-admin">
        <label>Company Website</label>
        <div class="input-group"> 
       <input class="form-control" name="custom[website]" value="<?php if( isset($_GET['post']) ){  echo get_post_meta($post->ID, "website", true); } ?>" />
        </div>
    </div>  
 
    
   <div class="box-admin">
        <label>Company Email</label>
        <div class="input-group"> 
       <input class="form-control" name="custom[email]" value="<?php if( isset($_GET['post']) ){  echo get_post_meta($post->ID, "email", true); } ?>" />
        </div>
    </div>  
 
 
    <div class="box-admin">
        <label>Amenities</label>
        
        <div class="input-group"> 
        
        <select name="custom[amenities][]" class="form-control" style="height:200px;width:100%;" multiple="multiple">
        <?php
        	$myv = get_post_meta($_GET['post'], 'amenities', true);
			if(!is_array($myv)){ $myv = array(); }
            $values = $this->_amenities();
            
            ?>
             
            <?php foreach($values as $k => $v){ ?>
            <option value="<?php echo $k; ?>" <?php if(isset($_GET['post']) &&  in_array($k, $myv) ){ echo "selected=selected"; } ?>><?php echo $v; ?></option>
            <?php } ?>
        
        </select>
        </div>
        <div class="clear"></div>
    </div> 
    
    <div class="clear"></div>
 
 
<?php if(_ppt('businesshours') == '1'){  ?>
 

<script>

function SaveTheseChanges(){


	// BUSINESS HOURS PLUGIN
	jQuery('.startTime').attr('name', 'startTime[]');
	jQuery('.endTime').attr('name', 'endTime[]');
	jQuery('.isActive').attr('name', 'isActive[]');
	
	
	document.post.submit();

}

 
</script>

<?php 
 			$bh = array();
			if(isset($_GET['post']) ){
			$bh = get_post_meta($post->ID,'businesshours',true);
			} 
			?>

   <div class="box-admin-textrea" style="margin-top:20px;">
        <label>Opening Hours</label>
        <div class="input-group"> 
      <div id="businessHoursContainer3" style="margin-top:20px; float:left;"></div>
        </div>
    </div>  
        
            
      
            <script>
			
			jQuery(document).ready(function() {
			
			<?php if(is_array($bh) && !empty($bh) && isset($bh['active'][5]) ){ ?>
			var operationTime = [
			{"isActive":<?php echo $bh['active'][0]; ?>,"timeFrom":'<?php echo $bh['start'][0]; ?>',"timeTill":'<?php echo $bh['end'][0]; ?>'},
			{"isActive":<?php echo $bh['active'][1]; ?>,"timeFrom":'<?php echo $bh['start'][1]; ?>',"timeTill":'<?php echo $bh['end'][1]; ?>'},
			{"isActive":<?php echo $bh['active'][2]; ?>,"timeFrom":'<?php echo $bh['start'][2]; ?>',"timeTill":'<?php echo $bh['end'][2]; ?>'},
			{"isActive":<?php echo $bh['active'][3]; ?>,"timeFrom":'<?php echo $bh['start'][3]; ?>',"timeTill":'<?php echo $bh['end'][3]; ?>'},
			{"isActive":<?php echo $bh['active'][4]; ?>,"timeFrom":'<?php echo $bh['start'][4]; ?>',"timeTill":'<?php echo $bh['end'][4]; ?>'},
			{"isActive":<?php echo $bh['active'][5]; ?>,"timeFrom":'<?php echo $bh['start'][5]; ?>',"timeTill":'<?php echo $bh['end'][5]; ?>'},
			{"isActive":<?php echo $bh['active'][6]; ?>,"timeFrom":'<?php echo $bh['start'][6]; ?>',"timeTill":'<?php echo $bh['end'][6]; ?>'},
			];
			<?php }else{ ?>
			var operationTime;
			<?php } ?>
			
			 jQuery("#businessHoursContainer3").businessHours({
			 
			 		operationTime: operationTime,
                    postInit:function(){
                         jQuery('.operationTimeFrom, .operationTimeTill').timepicker({
                            'timeFormat': 'H:i',
                            'step': 15
                            });
                    },
					 
                    dayTmpl:'<div class="dayContainer" style="width: 80px;"> <input type="hidden" class="isActive" name="isActive" value="1"> ' +
                        '<div data-original-title="" class="colorBox"><input type="checkbox" class="invisible operationState"></div>' +
                        '<div class="weekday"></div>' +
                        '<div class="operationDayTimeContaine">' +
                        '<div class="input-group"><div class="operationTime  input-group-prepend"><span class="input-group-addon input-group-text"><i class="fa fa-sun-o"></i></span><input type="text" name="startTime" class="startTime mini-time form-control operationTimeFrom" value=""></div></div>' +
                        '<div class="input-group"><div class="operationTime input-group input-group-prepend"><span class="input-group-addon input-group-text"><i class="fa fa-moon-o"></i></span><input type="text" name="endTime" class="endTime mini-time form-control operationTimeTill" value=""></div></div>' +
                        '</div></div> '
                });
				
			});
			</script>
    
 
 
    
<script>
!function(a){"object"==typeof exports&&exports&&"object"==typeof module&&module&&module.exports===exports?a(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){function b(a){var b=a[0];return b.offsetWidth>0&&b.offsetHeight>0}function c(b){if(b.minTime&&(b.minTime=t(b.minTime)),b.maxTime&&(b.maxTime=t(b.maxTime)),b.durationTime&&"function"!=typeof b.durationTime&&(b.durationTime=t(b.durationTime)),"now"==b.scrollDefault)b.scrollDefault=function(){return b.roundingFunction(t(new Date),b)};else if(b.scrollDefault&&"function"!=typeof b.scrollDefault){var c=b.scrollDefault;b.scrollDefault=function(){return b.roundingFunction(t(c),b)}}else b.minTime&&(b.scrollDefault=function(){return b.roundingFunction(b.minTime,b)});if("string"===a.type(b.timeFormat)&&b.timeFormat.match(/[gh]/)&&(b._twelveHourTime=!0),b.showOnFocus===!1&&b.showOn.indexOf("focus")!=-1&&b.showOn.splice(b.showOn.indexOf("focus"),1),b.disableTimeRanges.length>0){for(var d in b.disableTimeRanges)b.disableTimeRanges[d]=[t(b.disableTimeRanges[d][0]),t(b.disableTimeRanges[d][1])];b.disableTimeRanges=b.disableTimeRanges.sort(function(a,b){return a[0]-b[0]});for(var d=b.disableTimeRanges.length-1;d>0;d--)b.disableTimeRanges[d][0]<=b.disableTimeRanges[d-1][1]&&(b.disableTimeRanges[d-1]=[Math.min(b.disableTimeRanges[d][0],b.disableTimeRanges[d-1][0]),Math.max(b.disableTimeRanges[d][1],b.disableTimeRanges[d-1][1])],b.disableTimeRanges.splice(d,1))}return b}function d(b){var c=b.data("timepicker-settings"),d=b.data("timepicker-list");if(d&&d.length&&(d.remove(),b.data("timepicker-list",!1)),c.useSelect){d=a("<select />",{"class":"ui-timepicker-select"});var g=d}else{d=a("<ul />",{"class":"ui-timepicker-list"});var g=a("<div />",{"class":"ui-timepicker-wrapper",tabindex:-1});g.css({display:"none",position:"absolute"}).append(d)}if(c.noneOption)if(c.noneOption===!0&&(c.noneOption=c.useSelect?"Time...":"None"),a.isArray(c.noneOption)){for(var i in c.noneOption)if(parseInt(i,10)==i){var k=e(c.noneOption[i],c.useSelect);d.append(k)}}else{var k=e(c.noneOption,c.useSelect);d.append(k)}if(c.className&&g.addClass(c.className),(null!==c.minTime||null!==c.durationTime)&&c.showDuration){"function"==typeof c.step?"function":c.step;g.addClass("ui-timepicker-with-duration"),g.addClass("ui-timepicker-step-"+c.step)}var l=c.minTime;"function"==typeof c.durationTime?l=t(c.durationTime()):null!==c.durationTime&&(l=c.durationTime);var n=null!==c.minTime?c.minTime:0,o=null!==c.maxTime?c.maxTime:n+v-1;o<n&&(o+=v),o===v-1&&"string"===a.type(c.timeFormat)&&c.show2400&&(o=v);var p=c.disableTimeRanges,w=0,x=p.length,z=c.step;"function"!=typeof z&&(z=function(){return c.step});for(var i=n,A=0;i<=o;A++,i+=60*z(A)){var B=i,C=s(B,c);if(c.useSelect){var D=a("<option />",{value:C});D.text(C)}else{var D=a("<li />");D.addClass(B%v<v/2?"ui-timepicker-am":"ui-timepicker-pm"),D.data("time",u(B,c)),D.text(C)}if((null!==c.minTime||null!==c.durationTime)&&c.showDuration){var E=r(i-l,c.step);if(c.useSelect)D.text(D.text()+" ("+E+")");else{var F=a("<span />",{"class":"ui-timepicker-duration"});F.text(" ("+E+")"),D.append(F)}}w<x&&(B>=p[w][1]&&(w+=1),p[w]&&B>=p[w][0]&&B<p[w][1]&&(c.useSelect?D.prop("disabled",!0):D.addClass("ui-timepicker-disabled"))),d.append(D)}if(g.data("timepicker-input",b),b.data("timepicker-list",g),c.useSelect)b.val()&&d.val(f(t(b.val()),c)),d.on("focus",function(){a(this).data("timepicker-input").trigger("showTimepicker")}),d.on("blur",function(){a(this).data("timepicker-input").trigger("hideTimepicker")}),d.on("change",function(){m(b,a(this).val(),"select")}),m(b,d.val(),"initial"),b.hide().after(d);else{var G=c.appendTo;"string"==typeof G?G=a(G):"function"==typeof G&&(G=G(b)),G.append(g),j(b,d),d.on("mousedown click","li",function(c){b.off("focus.timepicker"),b.on("focus.timepicker-ie-hack",function(){b.off("focus.timepicker-ie-hack"),b.on("focus.timepicker",y.show)}),h(b)||b[0].focus(),d.find("li").removeClass("ui-timepicker-selected"),a(this).addClass("ui-timepicker-selected"),q(b)&&(b.trigger("hideTimepicker"),d.on("mouseup.timepicker click.timepicker","li",function(a){d.off("mouseup.timepicker click.timepicker"),g.hide()}))})}}function e(b,c){var d,e,f;return"object"==typeof b?(d=b.label,e=b.className,f=b.value):"string"==typeof b?(d=b,f=""):a.error("Invalid noneOption value"),c?a("<option />",{value:f,"class":e,text:d}):a("<li />",{"class":e,text:d}).data("time",String(f))}function f(a,b){if(a=b.roundingFunction(a,b),null!==a)return s(a,b)}function g(b){if(b.target!=window){var c=a(b.target);c.closest(".ui-timepicker-input").length||c.closest(".ui-timepicker-wrapper").length||(y.hide(),a(document).unbind(".ui-timepicker"),a(window).unbind(".ui-timepicker"))}}function h(a){var b=a.data("timepicker-settings");return(window.navigator.msMaxTouchPoints||"ontouchstart"in document)&&b.disableTouchKeyboard}function i(b,c,d){if(!d&&0!==d)return!1;var e=b.data("timepicker-settings"),f=!1,d=e.roundingFunction(d,e);return c.find("li").each(function(b,c){var e=a(c);if("number"==typeof e.data("time"))return e.data("time")==d?(f=e,!1):void 0}),f}function j(a,b){b.find("li").removeClass("ui-timepicker-selected");var c=a.data("timepicker-settings"),d=t(l(a),c);if(null!==d){var e=i(a,b,d);if(e){var f=e.offset().top-b.offset().top;(f+e.outerHeight()>b.outerHeight()||f<0)&&b.scrollTop(b.scrollTop()+e.position().top-e.outerHeight()),(c.forceRoundTime||e.data("time")===d)&&e.addClass("ui-timepicker-selected")}}}function k(b,c){if("timepicker"!=c){var d=a(this);if(""===this.value)return void m(d,null,c);if(!d.is(":focus")||b&&"change"==b.type){var e=d.data("timepicker-settings"),f=t(this.value,e);if(null===f)return void d.trigger("timeFormatError");var g=!1;if(null!==e.minTime&&null!==e.maxTime&&(f<e.minTime||f>e.maxTime)&&(g=!0),a.each(e.disableTimeRanges,function(){if(f>=this[0]&&f<this[1])return g=!0,!1}),e.forceRoundTime){var h=e.roundingFunction(f,e);h!=f&&(f=h,c=null)}var i=s(f,e);g?(m(d,i,"error")||b&&"change"==b.type)&&d.trigger("timeRangeError"):m(d,i,c)}}}function l(a){return a.is("input")?a.val():a.data("ui-timepicker-value")}function m(a,b,c){if(a.is("input")){a.val(b);var d=a.data("timepicker-settings");d.useSelect&&"select"!=c&&a.data("timepicker-list").val(f(t(b),d))}return a.data("ui-timepicker-value")!=b?(a.data("ui-timepicker-value",b),"select"==c?a.trigger("selectTime").trigger("changeTime").trigger("change","timepicker"):["error","initial"].indexOf(c)==-1&&a.trigger("changeTime"),!0):(["error","initial"].indexOf(c)==-1&&a.trigger("selectTime"),!1)}function n(a){switch(a.keyCode){case 13:case 9:return;default:a.preventDefault()}}function o(c){var d=a(this),e=d.data("timepicker-list");if(!e||!b(e)){if(40!=c.keyCode)return!0;y.show.call(d.get(0)),e=d.data("timepicker-list"),h(d)||d.focus()}switch(c.keyCode){case 13:return q(d)&&(k.call(d.get(0),{type:"change"}),y.hide.apply(this)),c.preventDefault(),!1;case 38:var f=e.find(".ui-timepicker-selected");return f.length?f.is(":first-child")||(f.removeClass("ui-timepicker-selected"),f.prev().addClass("ui-timepicker-selected"),f.prev().position().top<f.outerHeight()&&e.scrollTop(e.scrollTop()-f.outerHeight())):(e.find("li").each(function(b,c){if(a(c).position().top>0)return f=a(c),!1}),f.addClass("ui-timepicker-selected")),!1;case 40:return f=e.find(".ui-timepicker-selected"),0===f.length?(e.find("li").each(function(b,c){if(a(c).position().top>0)return f=a(c),!1}),f.addClass("ui-timepicker-selected")):f.is(":last-child")||(f.removeClass("ui-timepicker-selected"),f.next().addClass("ui-timepicker-selected"),f.next().position().top+2*f.outerHeight()>e.outerHeight()&&e.scrollTop(e.scrollTop()+f.outerHeight())),!1;case 27:e.find("li").removeClass("ui-timepicker-selected"),y.hide();break;case 9:y.hide();break;default:return!0}}function p(c){var d=a(this),e=d.data("timepicker-list"),f=d.data("timepicker-settings");if(!e||!b(e)||f.disableTextInput)return!0;if("paste"===c.type||"cut"===c.type)return void setTimeout(function(){f.typeaheadHighlight?j(d,e):e.hide()},0);switch(c.keyCode){case 96:case 97:case 98:case 99:case 100:case 101:case 102:case 103:case 104:case 105:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:case 65:case 77:case 80:case 186:case 8:case 46:f.typeaheadHighlight?j(d,e):e.hide()}}function q(a){var b=a.data("timepicker-settings"),c=a.data("timepicker-list"),d=null,e=c.find(".ui-timepicker-selected");return!e.hasClass("ui-timepicker-disabled")&&(e.length&&(d=e.data("time")),null!==d&&("string"!=typeof d&&(d=s(d,b)),m(a,d,"select")),!0)}function r(a,b){a=Math.abs(a);var c,d,e=Math.round(a/60),f=[];return e<60?f=[e,w.mins]:(c=Math.floor(e/60),d=e%60,30==b&&30==d&&(c+=w.decimal+5),f.push(c),f.push(1==c?w.hr:w.hrs),30!=b&&d&&(f.push(d),f.push(w.mins))),f.join(" ")}function s(b,c){if("number"!=typeof b)return null;var d=parseInt(b%60),e=parseInt(b/60%60),f=parseInt(b/3600%24),g=new Date(1970,0,2,f,e,d,0);if(isNaN(g.getTime()))return null;if("function"===a.type(c.timeFormat))return c.timeFormat(g);for(var h,i,j="",k=0;k<c.timeFormat.length;k++)switch(i=c.timeFormat.charAt(k)){case"a":j+=g.getHours()>11?w.pm:w.am;break;case"A":j+=g.getHours()>11?w.PM:w.AM;break;case"g":h=g.getHours()%12,j+=0===h?"12":h;break;case"G":h=g.getHours(),b===v&&(h=c.show2400?24:0),j+=h;break;case"h":h=g.getHours()%12,0!==h&&h<10&&(h="0"+h),j+=0===h?"12":h;break;case"H":h=g.getHours(),b===v&&(h=c.show2400?24:0),j+=h>9?h:"0"+h;break;case"i":var e=g.getMinutes();j+=e>9?e:"0"+e;break;case"s":d=g.getSeconds(),j+=d>9?d:"0"+d;break;case"\\":k++,j+=c.timeFormat.charAt(k);break;default:j+=i}return j}function t(a,b){if(""===a||null===a)return null;if("object"==typeof a)return 3600*a.getHours()+60*a.getMinutes()+a.getSeconds();if("string"!=typeof a)return a;a=a.toLowerCase().replace(/[\s\.]/g,""),"a"!=a.slice(-1)&&"p"!=a.slice(-1)||(a+="m");var c="("+w.am.replace(".","")+"|"+w.pm.replace(".","")+"|"+w.AM.replace(".","")+"|"+w.PM.replace(".","")+")?",d=new RegExp("^"+c+"([0-9]?[0-9])\\W?([0-5][0-9])?\\W?([0-5][0-9])?"+c+"$"),e=a.match(d);if(!e)return null;var f=parseInt(1*e[2],10),g=e[1]||e[5],h=f,i=1*e[3]||0,j=1*e[4]||0;if(f<=12&&g){var k=g==w.pm||g==w.PM;h=12==f?k?12:0:f+(k?12:0)}else if(b){var l=3600*f+60*i+j;if(l>=v+(b.show2400?1:0)){if(b.wrapHours===!1)return null;h=f%24}}var m=3600*h+60*i+j;if(f<12&&!g&&b&&b._twelveHourTime&&b.scrollDefault){var n=m-b.scrollDefault();n<0&&n>=v/-2&&(m=(m+v/2)%v)}return m}function u(a,b){return a==v&&b.show2400?a:a%v}var v=86400,w={am:"am",pm:"pm",AM:"AM",PM:"PM",decimal:".",mins:"mins",hr:"hr",hrs:"hrs"},x={appendTo:"body",className:null,closeOnWindowScroll:!1,disableTextInput:!1,disableTimeRanges:[],disableTouchKeyboard:!1,durationTime:null,forceRoundTime:!1,maxTime:null,minTime:null,noneOption:!1,orientation:"l",roundingFunction:function(a,b){if(null===a)return null;if("number"!=typeof b.step)return a;var c=a%(60*b.step),d=b.minTime||0;return c-=d%(60*b.step),c>=30*b.step?a+=60*b.step-c:a-=c,u(a,b)},scrollDefault:null,selectOnBlur:!1,show2400:!1,showDuration:!1,showOn:["click","focus"],showOnFocus:!0,step:30,stopScrollPropagation:!1,timeFormat:"g:ia",typeaheadHighlight:!0,useSelect:!1,wrapHours:!0},y={init:function(b){return this.each(function(){var e=a(this),f=[];for(var g in x)e.data(g)&&(f[g]=e.data(g));var h=a.extend({},x,b,f);if(h.lang&&(w=a.extend(w,h.lang)),h=c(h),e.data("timepicker-settings",h),e.addClass("ui-timepicker-input"),h.useSelect)d(e);else{if(e.prop("autocomplete","off"),h.showOn)for(var i in h.showOn)e.on(h.showOn[i]+".timepicker",y.show);e.on("change.timepicker",k),e.on("keydown.timepicker",o),e.on("keyup.timepicker",p),h.disableTextInput&&e.on("keydown.timepicker",n),e.on("cut.timepicker",p),e.on("paste.timepicker",p),k.call(e.get(0),null,"initial")}})},show:function(c){var e=a(this),f=e.data("timepicker-settings");if(c&&c.preventDefault(),f.useSelect)return void e.data("timepicker-list").focus();h(e)&&e.blur();var k=e.data("timepicker-list");if(!e.prop("readonly")&&(k&&0!==k.length&&"function"!=typeof f.durationTime||(d(e),k=e.data("timepicker-list")),!b(k))){e.data("ui-timepicker-value",e.val()),j(e,k),y.hide(),k.show();var m={};f.orientation.match(/r/)?m.left=e.offset().left+e.outerWidth()-k.outerWidth()+parseInt(k.css("marginLeft").replace("px",""),10):m.left=e.offset().left+parseInt(k.css("marginLeft").replace("px",""),10);var n;n=f.orientation.match(/t/)?"t":f.orientation.match(/b/)?"b":e.offset().top+e.outerHeight(!0)+k.outerHeight()>a(window).height()+a(window).scrollTop()?"t":"b","t"==n?(k.addClass("ui-timepicker-positioned-top"),m.top=e.offset().top-k.outerHeight()+parseInt(k.css("marginTop").replace("px",""),10)):(k.removeClass("ui-timepicker-positioned-top"),m.top=e.offset().top+e.outerHeight()+parseInt(k.css("marginTop").replace("px",""),10)),k.offset(m);var o=k.find(".ui-timepicker-selected");if(!o.length){var p=t(l(e));null!==p?o=i(e,k,p):f.scrollDefault&&(o=i(e,k,f.scrollDefault()))}if(o.length&&!o.hasClass("ui-timepicker-disabled")||(o=k.find("li:not(.ui-timepicker-disabled):first")),o&&o.length){var q=k.scrollTop()+o.position().top-o.outerHeight();k.scrollTop(q)}else k.scrollTop(0);return f.stopScrollPropagation&&a(document).on("wheel.ui-timepicker",".ui-timepicker-wrapper",function(b){b.preventDefault();var c=a(this).scrollTop();a(this).scrollTop(c+b.originalEvent.deltaY)}),a(document).on("touchstart.ui-timepicker mousedown.ui-timepicker",g),a(window).on("resize.ui-timepicker",g),f.closeOnWindowScroll&&a(document).on("scroll.ui-timepicker",g),e.trigger("showTimepicker"),this}},hide:function(c){var d=a(this),e=d.data("timepicker-settings");return e&&e.useSelect&&d.blur(),a(".ui-timepicker-wrapper").each(function(){var c=a(this);if(b(c)){var d=c.data("timepicker-input"),e=d.data("timepicker-settings");e&&e.selectOnBlur&&q(d),c.hide(),d.trigger("hideTimepicker")}}),this},option:function(b,e){return"string"==typeof b&&"undefined"==typeof e?a(this).data("timepicker-settings")[b]:this.each(function(){var f=a(this),g=f.data("timepicker-settings"),h=f.data("timepicker-list");"object"==typeof b?g=a.extend(g,b):"string"==typeof b&&(g[b]=e),g=c(g),f.data("timepicker-settings",g),k.call(f.get(0),{type:"change"},"initial"),h&&(h.remove(),f.data("timepicker-list",!1)),g.useSelect&&d(f)})},getSecondsFromMidnight:function(){return t(l(this))},getTime:function(a){var b=this,c=l(b);if(!c)return null;var d=t(c);if(null===d)return null;a||(a=new Date);var e=new Date(a);return e.setHours(d/3600),e.setMinutes(d%3600/60),e.setSeconds(d%60),e.setMilliseconds(0),e},isVisible:function(){var a=this,c=a.data("timepicker-list");return!(!c||!b(c))},setTime:function(a){var b=this,c=b.data("timepicker-settings");if(c.forceRoundTime)var d=f(t(a),c);else var d=s(t(a),c);return a&&null===d&&c.noneOption&&(d=a),m(b,d,"initial"),k.call(b.get(0),{type:"change"},"initial"),b.data("timepicker-list")&&j(b,b.data("timepicker-list")),this},remove:function(){var a=this;if(a.hasClass("ui-timepicker-input")){var b=a.data("timepicker-settings");return a.removeAttr("autocomplete","off"),a.removeClass("ui-timepicker-input"),a.removeData("timepicker-settings"),a.off(".timepicker"),a.data("timepicker-list")&&a.data("timepicker-list").remove(),b.useSelect&&a.show(),a.removeData("timepicker-list"),this}}};a.fn.timepicker=function(b){return this.length?y[b]?this.hasClass("ui-timepicker-input")?y[b].apply(this,Array.prototype.slice.call(arguments,1)):this:"object"!=typeof b&&b?void a.error("Method "+b+" does not exist on jQuery.timepicker"):y.init.apply(this,arguments):this}});
(function($) {
    $.fn.businessHours = function(opts) {
        var defaults = {
            preInit: function() {
            },
            postInit: function() {
            },
            inputDisabled: false,
            checkedColorClass: "WorkingDayState",
            uncheckedColorClass: "RestDayState",
            colorBoxValContainerClass: "colorBoxContainer",
            weekdays: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            operationTime: [
                {},
                {},
                {},
                {},
                {},
                {isActive: false},
                {isActive: false}
            ],
            defaultOperationTimeFrom: '9:00',
            defaultOperationTimeTill: '18:00',
            defaultActive: true,
            //labelOn: "Working day",
            //labelOff: "Day off",
            //labelTimeFrom: "from:",
            //labelTimeTill: "till:",
            containerTmpl: '<div class="clean"/>',
            dayTmpl: '<div class="dayContainer">' +
            '<div data-original-title="" class="colorBox"><input type="checkbox" class="invisible operationState"/></div>' +
            '<div class="weekday"></div>' +
            '<div class="operationDayTimeContainer">' +
            '<div class="operationTime"><input type="text" name="startTime" class="mini-time operationTimeFrom" value=""/></div>' +
            '<div class="operationTime"><input type="text" name="endTime" class="mini-time operationTimeTill" value=""/></div>' +
            '</div></div>'
        };

        var container = $(this);

        function initTimeBox(timeBoxSelector, time, isInputDisabled) {
            timeBoxSelector.val(time);

            if(isInputDisabled) {
                timeBoxSelector.prop('readonly', true);
            }
        }

        var methods = {
            getValueOrDefault: function(val, defaultVal) {
                return (jQuery.type(val) === "undefined" || val == null) ? defaultVal : val;
            },
            init: function(opts) {
                this.options = $.extend(defaults, opts);
                container.html("");

                if(typeof this.options.preInit === "function") {
                    this.options.preInit();
                }

                this.initView(this.options);

                if(typeof this.options.postInit === "function") {
                    //$('.operationTimeFrom, .operationTimeTill').timepicker(options.timepickerOptions);
                    this.options.postInit();
                }

                return {
                    serialize: function() {
                        var data = [];

                        container.find(".operationState").each(function(num, item) {
                            var isWorkingDay = $(item).prop("checked");
                            var dayContainer = $(item).parents(".dayContainer");

                            data.push({
                                isActive: isWorkingDay,
                                timeFrom: isWorkingDay ? dayContainer.find("[name='startTime']").val() : null,
                                timeTill: isWorkingDay ? dayContainer.find("[name='endTime']").val() : null
                            });
                        });

                        return data;
                    }
                };
            },
            initView: function(options) {
                var stateClasses = [options.checkedColorClass, options.uncheckedColorClass];
                var subContainer = container.append($(options.containerTmpl));
                var $this = this;

                for(var i = 0; i < options.weekdays.length; i++) {
                    subContainer.append(options.dayTmpl);
                }

                $.each(options.weekdays, function(pos, weekday) {
                    // populate form
                    var day = options.operationTime[pos];
                    var operationDayNode = container.find(".dayContainer").eq(pos);
                    operationDayNode.find('.weekday').html(weekday);

                    var isWorkingDay = $this.getValueOrDefault(day.isActive, options.defaultActive);
                    operationDayNode.find('.operationState').prop('checked', isWorkingDay);

                    var timeFrom = $this.getValueOrDefault(day.timeFrom, options.defaultOperationTimeFrom);
                    initTimeBox(operationDayNode.find('[name="startTime"]'), timeFrom, options.inputDisabled);

                    var endTime = $this.getValueOrDefault(day.timeTill, options.defaultOperationTimeTill);
                    initTimeBox(operationDayNode.find('[name="endTime"]'), endTime, options.inputDisabled);
                });

                container.find(".operationState").change(function() {
                    var checkbox = $(this);
                    var boxClass = options.checkedColorClass;
                    var timeControlDisabled = false;
					
					
					checkbox.parents(".dayContainer").find(".isActive").val(1);
					
                    if(!checkbox.prop("checked")) {
                        // disabled
                        boxClass = options.uncheckedColorClass;
                        timeControlDisabled = true;
						
						checkbox.parents(".dayContainer").find(".isActive").val(0);
                    }

                    checkbox.parents(".colorBox").removeClass(stateClasses.join(' ')).addClass(boxClass);
                    checkbox.parents(".dayContainer").find(".operationTime").toggle(!timeControlDisabled);
                }).trigger("change");

                if(!options.inputDisabled) {
                    container.find(".colorBox").on("click", function() {
                        var checkbox = $(this).find(".operationState");
                        checkbox.prop("checked", !checkbox.prop('checked')).trigger("change");
                    });
                }
            }
        };

        return methods.init(opts);
    };
})(jQuery);


jQuery(document).ready(function($) {
	jQuery('#availabledate').datetimepicker();
});
 
</script>

<style>
 
.clean {
    clear: both;
}

.dayContainer {
    float: left;
    line-height: 20px;
    margin-right: 26px; margin-bottom:20px;
    width: 65px;
    font-size: 11px;
    font-weight: bold;
}

.colorBox {
    cursor: pointer;
    height: 45px;
    border: 2px solid #888;

}

.colorBox.WorkingDayState {
    border: 2px solid #4E8059;
    background-color: #8ade8f;
}

.colorBox.RestDayState {
    border: 2px solid #7a1c44;
    background-color: #de5962;
}

.operationTime .mini-time {
    width: 100%;
    padding: 3px;
    font-size: 12px;
    font-weight: normal;
}

.operationDayTimeContaine .form-control , .operationDayTimeContaine .input-group-text { border-radius:0px !important; }

.dayContainer .add-on {
    padding: 4px 2px;
}

.colorBoxLabel {
    clear: both;
    font-size: 12px;
    font-weight: bold;
}

.invisible {
    visibility: hidden;
}

.operationTime {
    margin-top: 5px;
}
.ui-timepicker-wrapper{overflow-y:auto;max-height:150px;width:6.5em;background:#fff;border:1px solid #ddd;-webkit-box-shadow:0 5px 10px rgba(0,0,0,.2);-moz-box-shadow:0 5px 10px rgba(0,0,0,.2);box-shadow:0 5px 10px rgba(0,0,0,.2);outline:0;z-index:10001;margin:0}.ui-timepicker-wrapper.ui-timepicker-with-duration{width:13em}.ui-timepicker-wrapper.ui-timepicker-with-duration.ui-timepicker-step-30,.ui-timepicker-wrapper.ui-timepicker-with-duration.ui-timepicker-step-60{width:11em}.ui-timepicker-list{margin:0;padding:0;list-style:none}.ui-timepicker-duration{margin-left:5px;color:#888}.ui-timepicker-list:hover .ui-timepicker-duration{color:#888}.ui-timepicker-list li{padding:3px 0 3px 5px;cursor:pointer;white-space:nowrap;color:#000;list-style:none;margin:0}.ui-timepicker-list:hover .ui-timepicker-selected{background:#fff;color:#000}li.ui-timepicker-selected,.ui-timepicker-list li:hover,.ui-timepicker-list .ui-timepicker-selected:hover{background:#1980EC;color:#fff}li.ui-timepicker-selected .ui-timepicker-duration,.ui-timepicker-list li:hover .ui-timepicker-duration{color:#ccc}.ui-timepicker-list li.ui-timepicker-disabled,.ui-timepicker-list li.ui-timepicker-disabled:hover,.ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled{color:#888;cursor:default}.ui-timepicker-list li.ui-timepicker-disabled:hover,.ui-timepicker-list li.ui-timepicker-selected.ui-timepicker-disabled{background:#f2f2f2}

</style>
<div class="clear"></div>
<?php } ?>
 


 

    
	
	<?php
	}
	
 
 	
	
	/*
		this function adds new fields
		to the submission form
	*/
	function _hook_customfields($c){ global $CORE;
	
		$o = 50;
				
		$c[$o]['title'] 	= __("Company Phone","premiumpress");
		$c[$o]['name'] 		= "phone";
		$c[$o]['type'] 		= "text";
		$c[$o]['class'] 	= "form-control";
		$o++;
		
		$c[$o]['title'] 	= __("Company Email","premiumpress");
		$c[$o]['name'] 		= "email";
		$c[$o]['type'] 		= "text";
		$c[$o]['class'] 	= "form-control";
		$o++;
		
		$c[$o]['title'] 	= __("Company Website","premiumpress");
		$c[$o]['name'] 		= "website";
		$c[$o]['type'] 		= "text";
		$c[$o]['class'] 	= "form-control";
		$o++; 
 
		if(_ppt('amenities') == 1){
		$c[$o]['title'] 	= __("Local Amenities","premiumpress");
		$c[$o]['name'] 		= "amenities";
		$c[$o]['type'] 		= "checkbox";
		$c[$o]['class'] 	= "form-control";		
		$c[$o]['listvalues'] = $this->_amenities();
		$c[$o]['fullspan'] = true;		
		$c[$o]['required'] 	= true;
		$o++;
		}
		
		if(_ppt('businesshours') == '1'){  
		$c[$o]['title'] 	= ""; //__("Working Hours","premiumpress");
		$c[$o]['name'] 		= "hours";
		$c[$o]['type'] 		= "businesshours";
		$c[$o]['class'] 	= "form-control";
		//$c[$o]['required'] 	= true;
		$c[$o]['fullspan'] = true;	
		$o++;	
		}
			
			
		return $c;
	}
	
	

}	// END CLASS
 
 

 
/* =============================================================================
COMMENTS WALKER
========================================================================== */

class ppt_comment_walker_directory_single extends Walker_Comment {
		var $tree_type = 'comment';
		var $db_fields = array( 'parent' => 'comment_parent', 'id' => 'comment_ID' );
 
		// constructor – wrapper for the comments list
		function __construct() { ?>
  
		 

		<?php }

		// start_lvl – wrapper for child comments list
		function start_lvl( &$output, $depth = 0, $args = array() ) {
			$GLOBALS['comment_depth'] = $depth + 2; ?>
	   
		 

		<?php }
	
		// end_lvl – closing wrapper for child comments list
		function end_lvl( &$output, $depth = 0, $args = array() ) {
			$GLOBALS['comment_depth'] = $depth + 2; ?>
 
		  

		<?php }

		// start_el – HTML for comment template
		function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
	 
			
			global $CORE, $post;
		 
			$depth++;
			$GLOBALS['comment_depth'] = $depth;
			$GLOBALS['comment'] = $comment;
			$parent_class = ( empty( $args['has_children'] ) ? '' : 'parent' ); 
	
			if ( 'article' == $args['style'] ) {
				$tag = 'article';
				$add_below = 'comment';
			} else {
				$tag = 'article';
				$add_below = 'comment';
			}
		  	 
			// GET POST AUTHOR
			if(isset($comment_ID)){
			$authorID = get_comment_author( $comment_ID );			
			$authora = get_user_by('email',$comment->comment_author_email);			
			$post_authorID = get_post_field( 'post_author', $comment_post_ID );
			}else{
			$authorID = 1;
			$authora = 1;
			$post_authorID = 1;
			}
		 
			 
			 ?>
             
<li class="clearfix"> 

<div <?php comment_class(empty( $args['has_children'] ) ? '' :'parent') ?> id="comment-<?php comment_ID() ?>" itemprop="comment" itemscope itemtype="http://schema.org/Comment"><div class="comment_wrap">
             
             
<div class="image img-circle d-none d-md-block">
    <a href="<?php echo get_author_posts_url( $post_authorID ); ?>">
    <?php echo get_avatar( $comment, 65  ); ?>
    </a>
</div>

														<div class="content">
														 
																<div class="row">
																	<div class="col-4">
																	 
																			<h5 class="h6"><?php comment_author(); ?></h5>
                                                                           
																			<span class="rating-from d-none d-md-block">
                                                                            
																			<?php echo get_comment_date(); ?>
                                                                            </span>
                                                                            
																	 
																	</div>
																	<div class="col-8">
																		<div class="text-right text-left-xs">
																			<div class="rating-total-score">
																				<div class="rating-wrapper">
																					<span class="d-none d-md-block"><?php echo __("Total scores:","premiumpress") ?></span>
																					<div class="rating-item">
																						<input type="hidden" class="rating" data-filled="fa fa-star rating-rated" data-empty="far fa-star" data-fractions="2" data-readonly value="<?php echo  get_comment_meta($comment->comment_ID, 'ratingtotal', true); ?>"/>
																					</div>
																				</div>
																			</div>
																			 
																		</div>
																	</div>
														 
															</div>
															
															<div class="review-entry">
															
																 
															 
																	<div class="row">
																		<div class="col-md-12">
																			<div class="GridLex-inner">
																
																				<?php comment_text() ?>
																				
																				 
																			</div>
																		</div>
                                                                        
                                                                        <?php if(get_comment_meta( $comment->comment_ID, 'rating1', true ) != ""){   ?>
																		<div class="col-md-12 d-none d-md-block">
                                                                        
                                                                        <div class="ratingboxes">
																	 
																				<div class="row">
																				
																					<div class="col-md-3 rating-wrapper">
																						<span class="review-label-top"><?php echo __("Location","premiumpress") ?></span>
																						<div class="rating-item">
																							<input type="hidden" class="rating" data-filled="fa fa-star rating-rated" data-empty="far fa-star" data-fractions="2" 
                                                                                            data-readonly value="<?php echo get_comment_meta( $comment->comment_ID, 'rating1', true ); ?>"/>
																						</div>
																					</div>
																					<div class="col-md-3 rating-wrapper">
																						<span class="review-label-top"><?php echo __("Service","premiumpress") ?></span>
																						<div class="rating-item">
																							<input type="hidden" class="rating" data-filled="fa fa-star rating-rated" data-empty="far fa-star" data-fractions="2" 
                                                                                            data-readonly value="<?php echo get_comment_meta( $comment->comment_ID, 'rating2', true ); ?>"/>
																						</div>
																					</div>
																					<div class="col-md-3 rating-wrapper">
																						<span class="review-label-top"><?php echo __("Staff","premiumpress") ?></span>
																						<div class="rating-item">
																							<input type="hidden" class="rating" data-filled="fa fa-star rating-rated" data-empty="far fa-star" data-fractions="2" 
                                                                                            data-readonly value="<?php echo get_comment_meta( $comment->comment_ID, 'rating3', true ); ?>"/>
																						</div>
																					</div>
																					<div class="col-md-3 rating-wrapper">
																						<span class="review-label-top"><?php echo __("Value","premiumpress") ?></span>
																						<div class="rating-item">
																							<input type="hidden" class="rating" data-filled="fa fa-star rating-rated" data-empty="far fa-star" data-fractions="2" 
                                                                                            data-readonly value="<?php echo get_comment_meta( $comment->comment_ID, 'rating4', true ); ?>"/>
																						</div>
																					</div>																		 
																			</div>
                                                                           
                                                                            
																				</div>
																			</div>
															 			</div>
																	 <?php } ?>
															</div>

														</div>
<div class="clearfix"></div>
</div>
                                                                
</li>
             
 
		<?php }

		// end_el – closing HTML for comment template
		function end_el(&$output, $comment, $depth = 0, $args = array() ) { ?> <?php }

		// destructor – closing wrapper for the comments list
		function __destruct() { ?> <?php }

}


?>