if ($) {
	$(document).ready(function () {

		var body = $('body');
		var tabs = $('.tabs');
		var win = $(window);

		function smallerTabs() {
			if (win.width() <= 1060) {
				body.addClass('small');
			}
		}

		win.bind({resize: smallerTabs});

		function getRandom() {
			return Math.floor((Math.random() * 500) + 1);
		}
		function getRandomStats($tab) {
			$(".tabs .tab").each(function () {
				var $tab = $(this);
				var live_parker = parseInt($tab.find(".c-Total_Live_Parkers").text().replace(/[^\d.]/g, '')),
						total_parker = parseInt($tab.find(".c-Total_Parkers").text().replace(/[^\d.]/g, '')),
						revanue = parseInt($tab.find(".c-Total_Revenue").text().replace(/[^\d.]/g, '')),
						daily_revanue = parseInt($tab.find(".c-Daily_Revenue").text().replace(/[^\d.]/g, '')),
						car_park = parseInt($tab.find(".c-Car_Parks").text().replace(/[^\d.]/g, ''));

				live_parker++;
				total_parker++;
				car_park++;

				if (live_parker > 250) {
					live_parker = 1;
				}
				if (total_parker > 500) {
					total_parker = 1;
				}
				if (car_park > 50) {
					car_park = 1
				}

				revanue = "£" + total_parker + "K";
				daily_revanue = "£" + parseInt(total_parker / 2.5) + "K";

				$tab.find(".c-Total_Live_Parkers").text(live_parker);
				$tab.find(".c-Total_Parkers").text(total_parker);
				$tab.find(".c-Total_Revenue").text(revanue);
				$tab.find(".c-Daily_Revenue").text(daily_revanue);
				$tab.find(".c-Car_Parks").text(car_park);
			});
		}
		setInterval(function () {
			getRandomStats();
		}, 2000);

		function callChart($el) {
			var data = {
				labels: ['CAR PARK', 'OFFENCES', 'ACTIONS', 'ALERTS', 'CARS', 'REPORTS', 'INSIGHTS'],
				series: [getRandom(), getRandom(), getRandom(), getRandom(), getRandom(), getRandom(), getRandom()]
			};

			var options = {
				seriesBarDistance: 15,
				distributeSeries: true
			};

			var responsiveOptions = [
				['screen and (min-width: 641px) and (max-width: 1024px)', {
						seriesBarDistance: 10,
						axisX: {
							labelInterpolationFnc: function (value) {
								return value;
							}
						}
					}],
				['screen and (max-width: 640px)', {
						seriesBarDistance: 5,
						axisX: {
							labelInterpolationFnc: function (value) {
								return value;
							}
						}
					}]
			];
			var chart = new Chartist.Bar($el, data, options, responsiveOptions).on("draw", function (bars) {
				bars.element.animate({
					y2: {
						begin: 0,
						dur: 450,
						from: bars.y1,
						to: bars.y2,
						fill: "freeze"
					}
				}, true);
			}).on('created', function () {
				chart.detach(); // it will detach resize and media query listeners
			});

			//then update the chart only when window.width() changes
			var width = $(window).width();
			$(window).resize(function () {
				if ($(window).width() != width) {
					width = $(window).width(); // update width
					chart.on("update", function (bars) {
						bars.element.animate({
							y2: {
								begin: 0,
								dur: 0,
								fill: "freeze"
							}
						}, true);
					});
				}
			});

		}


		tabs.find('.tab-reports .tab-content-nav  a').bind({
			click: function () {
				var target = $(this);
				if (!target.is('a')) {
					target = target.closest('a');
				}
				if (target.length > 0) {
					target.toggleClass('subscribed');
				}
				return false;
			}
		}).bind({
			tap: function () {
				return false;
			}
		});

		tabs.on('click tap', '*', function (e, from) {
			var source = $(this);
			if (source.hasClass("preventDefault") || source.parents(".preventDefault").length) {
				e.stopPropagation();
			} else {

				var tab = source.closest('.tab');
				var tabNav = tab.find('.tab-nav');
				var $datTab = tab.attr("data-tab");
				if (source.hasClass('icon-stats')) {
					source.toggleClass('icon-active');
					if (!source.hasClass('animating')) {
						source.addClass('animating');
						var stats = source.closest('.tab-nav').find('.stats');
						if (!source.hasClass('icon-active')) {
							source.trigger('blur');
							stats.animate({opacity: 0}, 500, function () {
								stats.css({
									opacity: 0,
									display: 'none'
								});
								if (win.width() <= 1060) {
									tabNav.animate({paddingBottom: 0}, 150, function () {
										source.removeClass('animating').closest('.tab-nav').toggleClass('hide-stats');
									})
								} else {
									source.removeClass('animating').closest('.tab-nav').toggleClass('hide-stats');
								}
							});

							if (!from) {
								source.removeClass('icon-stats-active');
								if ($datTab) {
									$.post("", {'stats': $datTab, "action": "remove"}, function (json) {
									}, 'json');
								}
							}
						} else {
							source.trigger('focus');
							if (win.width() <= 1060) {
								tabNav.animate({paddingBottom: 64}, 150, function () {
									stats.css({
										opacity: 0,
										display: 'block'
									}).animate({opacity: 1}, 500, function () {
										source.removeClass('animating').closest('.tab-nav').toggleClass('hide-stats');
									});
								});
							} else {
								stats.css({
									opacity: 0,
									display: 'block'
								}).animate({opacity: 1}, 500, function () {
									source.removeClass('animating').closest('.tab-nav').toggleClass('hide-stats');
								});
							}
							if (!from) {
								source.addClass('icon-stats-active');
								if ($datTab) {
									$.post("", {'stats': $datTab, "action": "set"}, function (json) {
									}, 'json');
								}
							}
						}
					}

				} else if (source.hasClass('icon-pin')) {

					if (source.hasClass('icon-pin-active')) {
						source.trigger('blur');
						source.removeClass('icon-pin-active');
						if ($datTab) {
							$.post("", {'pin': $datTab, "action": "remove"}, function (json) {
							}, 'json');
						}
					} else {
						source.trigger('focus');
						source.removeClass('icon-pin-active').addClass('icon-pin-active');

						if ($datTab) {
							$.post("", {'pin': $datTab, "action": "set"}, function (json) {
							}, 'json');
						}
					}

				} else if (0 === source.closest('.tab-container').length) {
					if (0 < tab.length) {
						var container = tab.find('.tab-container');
						if (0 < container.length && !container.hasClass('animating')) {
							container.addClass('animating');
							if (tab.hasClass('tab-opened')) {
								closeTab(tab, container);
							} else {
								var $chart = false;
								if (tab.hasClass("tab-reports")) {
									$chart = '.c-Chart-Reports';
								}
								openTab(tab, container, $chart);
								setTimeout(function(){
									touchcarouselInt();
								}, 1000);
								
							}
						}
					}

				} else {
					if (source.parents('.c-Switch').length) {
						var checkbox = source.parents('.c-Switch').find(".u-Switch-Checkbox");
						if (checkbox.prop('checked')) {
							checkbox.prop("checked", false);
						} else {
							checkbox.prop("checked", true);
						}
					}
				}
				//if(source.hasClass(".icon")){
				return false;
				/*}else{
				 return true;
				 }*/
			}
		});

		function closeTab(tab, container) {
			container.animate({opacity: 0}, 350, function () {
				container.animate({height: 0}, 350, function () {
					tab.removeClass('tab-opened');
					tab.find('.action-expand').removeClass("icon-dropdown2").addClass("icon-dropdown").trigger("blur");
					container.css({display: 'none', height: 'auto'}).removeClass('animating');

					if (tab.find(".c-TipHelp-Container").hasClass("active")) {
						tab.find(".u-TipHelp-trigger").trigger("click");
					}
				});
			});
		}
		function openTab(tab, container, $chart, $noanimation) {
			if(tab.hasClass("tab-whitelist")){
				$(".c-Car-Plate-Box .c-Car-Plate-Box-Message").hide();
				tab.find(".c-Search-Small-Block-Inner-Block-Status .u-answerSpan").remove();
				tab.find(".c-Search-Small-Block-Inner-Block-Status span").show();
				tab.find(".u-SearchWhiteList").trigger("keyup");
			}

			tab.css({height: 'auto'});

			var h = container.css({position: 'absolute', visibility: 'hidden', display: 'block'}).height();
			container.css({visibility: 'visible', position: 'relative', height: 0, opacity: 0}).animate({height: h}, 350, function () {
				container.animate({opacity: 1}, 350, function () {
					tab.addClass('tab-opened');
					tab.find('.action-expand').removeClass("icon-dropdown").addClass("icon-dropdown2");
					container.removeClass('animating');
					if ($chart) {
						//callChart($chart);
					}
					$('html, body').animate({scrollTop: tab.offset().top}, 800);

					/*if (!tab.find(".u-TipHelp-Container").hasClass("active")) {
						tab.find(".u-TipHelp-trigger").trigger("click");
						setTimeout(function () {
							if (tab.find(".c-TipHelp-Container").hasClass("active")) {
								tab.find(".u-TipHelp-trigger").trigger("click");
							}
						}, 5000);
					}*/


					/*if (tab.hasClass("tab-vrmsearch") && !tab.hasClass("vrm-added")) {
						setTimeout(function(){
							var $timeline = tab.find(".vrmsearch-timeline").first(),
							$timelineBlock = $timeline.find(".vrmsearch-timeline-items-block"),
							$template = $("#u-Vrmtimeline-Template").html();

							var $tmp = $($template).addClass("new-added");
							$timelineBlock.prepend($tmp);

							var $element = $timelineBlock.find(".new-added");
							$element
								.css('opacity', 0)
							  	.slideDown('slow', function(e){
							  		var ele = this
							  		setTimeout(function(){
							  			$element.animate(
										    { opacity: 1 },
										    { duration: 'slow' }
										);
							  		}, 800);
							  		container.height("auto");
								})
						}, 5000);
					}*/
					container.height("auto");
				});
			});
		}

		$('.icon').bind({
			blur: function () {
				$(this).css('color', '#373C3F');
			},
			focus: function () {
				$(this).css('color', '#ffffff');
			}
		});

		$('.icon-pin-active').next(".action-expand").trigger("click");
		/*$('.icon-stats-active').each(function(){
		 $(this).addClass("icon-active");*/
		/*$(this).parents(".tab-nav").find("ul.stats").css({opacity: 1, display: "block"});*/
		$('.icon-stats-active').trigger("click", "trigger");
		//});

		$(".c-DayTimes .c-TimerSelection-Input").inputmask("h:s", {"placeholder": "", "numeric": {allowPlus: true, allowMinus: true}});
		//$(".c-DayTimes .c-TimerSelection-Input").inputmask("h:s", {"placeholder": "00/00", "numeric": {allowPlus: true, allowMinus: true}});
		$(".c-PermitDuration-StartEndDateSelection #permit-add-day, #group-add-day").inputmask("d", {"placeholder": " "});
		$(".c-PermitDuration-StartEndDateSelection #permit-add-month, #group-add-month").inputmask("m", {"placeholder": " "});
		$(".c-PermitDuration-StartEndDateSelection #permit-add-year, #group-add-year").inputmask("y", {"placeholder": " "});


		function ordinal_suffix_of(i) {
			var j = i % 10,
					k = i % 100;
			if (j == 1 && k != 11) {
				return i + "st";
			}
			if (j == 2 && k != 12) {
				return i + "nd";
			}
			if (j == 3 && k != 13) {
				return i + "rd";
			}
			return i + "th";
		}
		function month_name(m) {
			var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "June", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
			return monthNames[(parseInt(m) - 1)];
		}

		$(".c-PermitDuration-Container .c-TimerSelection-Input").datepicker({
			dateFormat: "yy-mm-dd",
			'autoclose': true,
			beforeShow: function (input, event) {
				var $this = $(this),
						$parents = $this.parents(".option-container"),
						$CircleOption = $parents.find(".c-Circle-Option.c-hasActive"),
						$date_filter = $CircleOption.attr("data-date_filter"),
						$date_number = $CircleOption.attr("data-date_number");
				if ((undefined !== $date_filter) && $this.hasClass("c-TimerSelect-StartTime")) {
					//$parents.find("#c-Groups-TimerSelect-EndTime").attr("disabled", true);
				}
			},
			onSelect: function (dateText, inst) {
				var $this = $(this),
						$parents = $this.parents(".option-container"),
						$CircleOption = $parents.find(".c-Circle-Option.c-hasActive"),
						$date_filter = $CircleOption.attr("data-date_filter"),
						$date_number = $CircleOption.attr("data-date_number"),
						$startDate = "",
						$endDate = "";
				if ((undefined !== $date_filter) && $this.hasClass("c-TimerSelect-StartTime")) {
					var $end = moment(dateText).clone().add($date_filter, $date_number);
					$startDate = moment(dateText).format('YYYY/MM/DD');
					$endDate = $end.format('YYYY/MM/DD');
					$parents.find(".c-TimerSelect-EndTime").attr("data-date", $endDate).val($end.format("Do MMM YYYY"));
				} else if ($this.hasClass("c-TimerSelect-StartTime")) {
					$startDate = moment(dateText).format('YYYY/MM/DD');
				} else if ($this.hasClass("c-TimerSelect-EndTime")) {
					$endDate = moment(dateText).format('YYYY/MM/DD');
				}
				$this.attr("data-date", moment(dateText).format('YYYY/MM/DD')).val(moment(dateText).format("Do MMM YYYY"));

				//$CircleOption.attr({"data-startdate": moment($startDate).format('MM/DD/YYYY'), "data-enddate": moment($endDate).format('MM/DD/YYYY')});
			}
		});
		
		var $offsetsTimer;
		$(".c-TimerSelection-Input").hover(function (e) {
			var $this = $(this),
					$tooltip = $this.parents(".options").find(".tooltip"),
					$hasActive = $(".personvehiclepermit-overlay .c-Circle-Option.c-hasActive"),
					$set = $hasActive.attr("data-set");
			if ($this.hasClass("c-TimerSelect-StartTime")) {
				offsets = $(".personvehiclepermit-overlay .c-TimerSelect-StartTime").offset();
			} else if ($this.hasClass("c-TimerSelect-EndTime")) {
				offsets = $(".personvehiclepermit-overlay .c-TimerSelect-EndTime").offset();
			}
			var offsets = $this.offset(),
					$top = offsets.top,
					$left = offsets.left;
			if ($set == 1) {
				$top = -45;
			} else if ($set == 2) {
				$top = 100;
			} else if ($set == 3) {
				$top = 250;
			}

			$tooltip.css({"display": "block", "left": $left, "top": $top}).toggleClass('animation bounceIn');

			$offsetsTimer = setTimeout(function () {
				$tooltip.css("display", "none").removeClass('animation bounceIn');
			}, 5000);

			$this.trigger("focus");
			$this.get(0).setSelectionRange(0, 0);
		}, function () {
			clearTimeout($offsetsTimer);
			var $this = $(this),
					$tooltip = $this.parents(".options").find(".tooltip");
			$tooltip.css("display", "none").removeClass('animation bounceIn');
		});

		$(".c-PermitDuration-StartEndDateSelection .c-add-input").hover(function (e) {
			var $this = $(this),
					$tooltip = $this.parents(".options").find(".tooltip"),
					$date_text = $(".c-PermitDuration-StartEndSelection .c-add-input.active").attr("data-text"),
					$title = $this.attr("data-tip");
			$title = $title.replace("{date_text}", $date_text);

			$tooltip.find(".tooltip-content").html($title);

			var offsets = $this.offset(),
					$top = -60,
					$left = offsets.left - 42;
			$tooltip.css({"display": "block", "left": $left, "top": $top}).toggleClass('animation bounceIn');
			$offsetsTimer = setTimeout(function () {
				$tooltip.css("display", "none").removeClass('animation bounceIn');
			}, 5000);
		}, function () {
			clearTimeout($offsetsTimer);
			var $this = $(this),
					$tooltip = $this.parents(".options").find(".tooltip");
			$tooltip.css("display", "none").removeClass('animation bounceIn');
		});


		/* Dashboard Javascript */
		$(".tab-dashboard .c-Dashboard-Edit").on("click", function () {
			var $this = $(this),
					$tab_dashboard = $(".tab-dashboard");
			$tab_dashboard.find(".c-Dashboard-Button.stat-active").removeClass("stat-active").addClass("stat-actived");
			if (!$tab_dashboard.hasClass("u-Edit-Active")) {
				$tab_dashboard.addClass("u-Edit-Active")
				$this.find(".report-title").text("DONE");
				$tab_dashboard.find(".c-inactive").addClass("active");
				$tab_dashboard.find(".feed-item").hide();
			} else {
				$tab_dashboard.removeClass("u-Edit-Active");
				$this.find(".report-title").text("DASHBOARD EDITOR");
				$tab_dashboard.find(".c-inactive").removeClass("active");
				$tab_dashboard.find(".feed-item").show();
				$tab_dashboard.find(".c-Dashboard-Button.stat-actived").removeClass("stat-actived").addClass("stat-active")
			}

			$tab_dashboard.css({height: 'auto'});
			return false;
		});
		$(".tab-dashboard .c-Dashboard-Button").on("click", function () {
			var $this = $(this),
					$tab_dashboard = $(".tab-dashboard"),
					$subscribe = $this.find(".report-subscribe");
			$tab_dashboard.find(".c-Dashboard-Button.stat-active").removeClass("stat-active");
			if ($tab_dashboard.hasClass("u-Edit-Active")) {
				if ($this.hasClass("c-inactive")) {
					$this.removeClass("c-inactive active");
					$subscribe.text("HIDE");
				} else {
					$this.addClass("c-inactive active");
					$subscribe.text("SHOW");
				}
			} else {
				// load report
				$(".c-Dashbaord-Reports").html('');
				$this.addClass("stat-active");
				//callChart('.c-Dashbaord-Reports');
			}

			$tab_dashboard.css({height: 'auto'});
			return false;
		});

		setInterval(function () {
			$(".c-Footer").removeClass("hvr-buzz-out-active").addClass("hvr-buzz-out-hover");
			setTimeout(function () {
				$(".c-Footer").removeClass("hvr-buzz-out-hover");
			}, 500);
		}, 3000);

		setInterval(function () {
			var $overlayStepsActive = $(".navigation-overlay .u-setDone");
			if (!$overlayStepsActive.parents(".personvehiclepermit-overlay").length) {
				if ($overlayStepsActive.hasClass("hovered")) {
					$overlayStepsActive.removeClass("hovered");
				} else {
					$overlayStepsActive.addClass("hovered");
				}
			}
		}, 3000);


		$(".summary-bar-tabs .summary-bar-header").bind({
			click: function (e) {
				$(this).trigger('toggleDisplay');
				e.preventDefault();
				e.stopPropagation();
				return false;
			},
			tap: function (e) {
				$(this).trigger('toggleDisplay');
				e.preventDefault();
				e.stopPropagation();
				return false;
			},
			toggleDisplay: function (e) {
				var $this = $(this),
						_bar = $(this).closest('.summary-bar'),
						container = _bar.closest('.tab-container'),
						toggle_link = $this.find(".tab-dropdown-toggle"),
						target_id = toggle_link.attr("href"),
						target = container.find(target_id),
						summary_bar_tabs = target.parents(".summary-bar-tabs"),
						bar = summary_bar_tabs.find('.summary-bar-tabs-content'),
						animateTarget = target.find('.animate-target');


				container.css('height', 'auto');
				if (!container.hasClass('animating')) {

					if (target.hasClass("tab-active")) {
						console.log("1");
						toggle_link.removeClass("icon-dropdown2").addClass("icon-dropdown");
						$this.removeClass("summary-bar-header-active");
						animateTarget.animate({opacity: 0}, 150, function () {
							target.animate({height: 0}, 200, function () {
								bar.removeClass('show-summary-dropdown');
								bar.removeClass('animating-contents');
								container.removeClass('animating');
								bar.find(".tab-dropdown").hide();
								target.hide();
								target.removeClass("tab-active");
							});
						});
					} else {

						bar.addClass('animating-contents');
						if (bar.find(".tab-active").length) {
							summary_bar_tabs.find(".tab-dropdown-toggle").removeClass("icon-dropdown2").addClass("icon-dropdown");
							var _animateTarget = bar.find(".tab-active").find('.animate-target');
							summary_bar_tabs.find(".summary-bar-header-active").removeClass("summary-bar-header-active");
							console.log("3");
							_animateTarget.animate({opacity: 0}, 150, function () {
								bar.find(".tab-active").animate({height: 0}, 200, function () {
									bar.removeClass('show-summary-dropdown');
									bar.removeClass('animating-contents');
									container.removeClass('animating');
									bar.find(".tab-dropdown").hide();
									bar.find(".tab-active").hide();
									bar.find(".tab-active").removeClass("tab-active");
									$this.trigger("click");
								});
							});
						} else {
							toggle_link.removeClass("icon-dropdown").addClass("icon-dropdown2");
							$this.addClass("summary-bar-header-active");
							target.show();
							target.addClass("tab-active");
							bar.addClass('show-summary-dropdown');
							console.log("4");
							animateTarget.css({opacity: 0});
							var h = parseInt(target.height()) + parseInt(target.css("padding-top")) + parseInt(target.css("padding-bottom"));
							target.css({height: 0}).animate({height: h}, 200, function () {
								target.css({height: "auto"});
								animateTarget.animate({opacity: 1}, 150, function () {
									container.removeClass('animating');
								});
							});
						}
					}
				}
				e.preventDefault();
				e.stopPropagation();
			}
		});


		if ($(".overlay-trigger .c-overlay-step").length) {
			setInterval(function () {
				var $overlayStepsActive = $(".overlay-trigger .c-overlay-step.active"),
						$overlayStepsOne = $(".overlay-trigger .c-overlay-step[data-step=1]"),
						$overlayStepsSecond = $(".overlay-trigger .c-overlay-step[data-step=2]"),
						$step = $overlayStepsActive.attr("data-step");
				$overlayStepsActive.fadeOut(500, function () {
					$(".overlay-trigger .c-overlay-step").removeClass("active");
					if ($step == 1) {
						var $overlayStep = $(".overlay-trigger .c-overlay-step[data-step=2]");
					} else {
						var $overlayStep = $(".overlay-trigger .c-overlay-step[data-step=1]");
					}
					$overlayStep.fadeIn(function () {
						$overlayStep.addClass("active");
					});
				});
			}, 3000);
		}


		$(".u-TipHelp-trigger").click(function () {
			var $this = $(this),
					$parents = $this.parents(".tab"),
					$ContainerBox = $parents.find(".c-TipHelp-ContainerBox"),
					$helpConainer = $ContainerBox.find(".c-TipHelp-Container");	
			if ($helpConainer.hasClass("active")) {
				$helpConainer.fadeOut(500, function () {
					$helpConainer.removeClass("active");
				});
			} else {
				$helpConainer.fadeIn(500, function () {
					$helpConainer.addClass("active");
				});
			}
			return false;
		});
		$(".c-TipHelp-Close").on("click", function () {
			var $this = $(this),
					$parents = $this.parents(".tab"),
					$ContainerBox = $parents.find(".c-TipHelp-ContainerBox"),
					$helpConainer = $ContainerBox.find(".c-TipHelp-Container");	
			$helpConainer.fadeOut(500, function () {
				$helpConainer.removeClass("active");
			});
			return false;
		});

		$("a[rel^='prettyPhoto']").prettyPhoto();


		var $body = $("body"),
				$pinLogout = $(".pin-logout");
		$(".pin-logout").on('click', function (e) {
			var $this = $(this);

			$.post("", {'group-pin': true, "action": "logout"}, function (json) {
				if (json.status) {
					$pinLogout.removeClass("u-loggedIn");
					window.location.reload();
				}
			}, 'json');
			return false;
		});
		
		if ($body.attr("data-groupmasterpinaccepted") == "1" || $body.attr("data-groupreviewpinaccepted") == "1") {
			$pinLogout.addClass("u-loggedIn");
		}

		$(".c-AddPermit-Button").on("click", function () {
			var $this = $(this),
					$personvehiclepermit = $('.personvehiclepermit-overlay'),
					$options = $personvehiclepermit.find('.options'),
					$permitButton = $options.find(".option[data-option='permit']");
			$('.overlay-trigger:first').trigger("click");
			$('.personvehiclepermit-overlay').attr("action", "permit");
			$permitButton.addClass("active");
			//$permitButton.trigger("click");
			return false;
		});
		$(".c-Location-Button").on("click", function () {
			var $this = $(this);
			$('.c-LocationPopup-Button:first').trigger("click");
			return false;
		});


		$(".c-controlFilters-CustomTime-Input").datepicker({
			dateFormat: "yy-mm-dd",
			beforeShow: function (input, event) {
			},
			onSelect: function (dateText, inst) {
				var $this = $(this);
				$this.attr("data-date", moment(dateText).format('YYYY/MM/DD')).val(moment(dateText).format("Do MMM YYYY"));
			}
		}).on("mouseover", function () {
			$(this).trigger("focus");
		});

		$("#whitelist-controls").on("click", ".c-controlFilters-CustomTime .c-controlFilters-CustomTime-Save", function () {
			var $this = $(this),
					optioncontainer = $this.parents(".c-controlFilters-CustomTime"),
					$startInput = optioncontainer.find(".c-controlFilters-CustomTime-StartTime"),
					$start = $startInput.attr("data-date"),
					$endInput = optioncontainer.find(".c-controlFilters-CustomTime-EndTime"),
					$end = $endInput.attr("data-date");
			var $result = true;

			var DateError = function ($error) {
				optioncontainer.find(".input-Box-overlay").addClass("active").find(".c-Contentbox span").html($error);
				setTimeout(function () {
					optioncontainer.find(".input-Box-overlay").removeClass("active");
				}, 4000);
			};

			if ("" == $startInput.val() || "" == $start) {
				$result = false;
				DateError("Please enter start date!");
			} else if ("" == $endInput.val() || "" == $end) {
				$result = false;
				DateError("Please enter end date!");
			} else if (($end != $start) && !moment($end).isAfter($start)) {
				$result = false;
				DateError("Oops! End date needs to be after the start date..");
			}

			return false;
		});
		$(".input-Box-overlay").on("click", function () {
			var $this = $(this);
			$this.removeClass("active");
			return false;
		});

		var animationGroupTimeout = [];
		animateGroupCriteria = function () {
			if (animationGroupTimeout.length) {
				$.each(animationGroupTimeout, function (nth) {
					clearInterval(animationGroupTimeout[nth]);
				});
			}

			var $StepsCriteria = $(".c-Cycle-GroupDetails-Criteria");
			$.each($StepsCriteria, function (ele, th) {
				var $this = $(th);
				animationGroupTimeout[ele] = setInterval(function () {
					var $CriteriaSteps = $this.find(".c-Cycle-GroupDetails-Criteria-Step"),
							$LastCriteriaStep = $this.find(".c-Cycle-GroupDetails-Criteria-Step:last"),
							$CriteriaStep = $this.find(".c-Cycle-GroupDetails-Criteria-Step.CriteriaActive"),
							$LastStep = $LastCriteriaStep.attr("data-step"),
							$Step = $CriteriaStep.attr("data-step");
					if ($CriteriaStep.length) {
						if ($LastStep == $Step) {
							$Step = 1;
							$(".c-Cycle-GroupDetails-Criteria-Box.c-Animated a").addClass("u-Cycle-FirstStepActive");
						} else {
							$Step = parseInt($Step) + 1;
							$(".c-Cycle-GroupDetails-Criteria-Box.c-Animated a").removeClass("u-Cycle-FirstStepActive");
						}
						$CriteriaStep.fadeOut(300, function () {
							$(this).removeClass("CriteriaActive");
							$this.find(".c-Cycle-GroupDetails-Criteria-Step[data-step='" + $Step + "']").fadeIn(300).addClass("CriteriaActive");
							if ($Step > 1) {
								$this.parents(".c-Cycle-GroupDetails-Criteria-Box.c-Animated").addClass("c-Cycle-GroupDetails-Criteria-Animated");
							} else {
								$this.parents(".c-Cycle-GroupDetails-Criteria-Box.c-Animated").removeClass("c-Cycle-GroupDetails-Criteria-Animated");
							}
						});
					}
				}, 3000);
			});
		};
		animateGroupCriteria();


		/* on click time input if 00:00 then remove value so user can enter values */
		$(".c-DayTime-Options .c-TimerSelection-Input").bind({
			focus: function () {
				var $this = $(this),
						$val = $this.val();
				/*if ("00:00" == $val || "" == $val) {
				 $this.val("");
				 }*/
			},
			blur: function () {
				var $this = $(this),
						$val = $this.val();
				if ("" == $val) {
					//$this.val("blur ", "00:00");
				}
			}
		});

		// update total assign number
		setInterval(function () {
			var $number = $(".c-AssignContact-Contacts .c-AssignContact-Box-Contacts-List .c-AssignContact-Box-Contacts-Item").not(".u-Contact-Assigned").length;
			$(".u-Pending-Numbers").text($number);
		}, 1000);


		// the enter key code
		$('.c-add-input, .c-pin-input').keypress(function (e) {
			var key = e.which;
			if (key == 13) {
				var $this = $(this),
						$parents = $this.closest("div");
				if ($parents.find(".c-BtnSave")) {
					$parents.find(".c-BtnSave").trigger("click");
					return false;
				}
			}
		});

	});

}
