$(document).ready(function() {
/************************************************************* DOCUMENT READY START */

/************************************************************************** MAP */
if (document.getElementById('gmap')) {initialize();}

var busy=0;
if($("#product-list-bottom").length>0){
	$(window).scroll(function() {
		if($("#product-list-bottom").length>0){
			var page=$('#extra-products').data('page');
			var perpage=$('#extra-products').data('perpage');
			var category_id=$('#extra-products').data('category_id');
			var ordering=$('#extra-products').data('ordering');
			var link=$('#extra-products').data('link');
			var total_pages=$('#extra-products').data('total_pages');
		
			var end = $("#product-list-bottom").offset().top;
			var viewEnd = $(window).scrollTop() + $(window).height();
			var distance = end - viewEnd;
			if (page<=total_pages && busy==0 && distance > -300 && distance < 300) {
				busy=1;
				console.log('scrolled');
				$('#extra-products').append('<div id="extra-products-preloader" style="min-height:300px;text-align:center;"><img style="margin-top:100px;" src="https://cdn.utopia.gr/images/icons/preloaders/gallery_preloader.svg" alt=""></div>');
				$.post('https://aldigron.gr/scripts/ajax.php', {'get_extra_products':'true','page':page,'perpage':perpage,'category_id':category_id,'ordering':ordering,'link':link,'short_lang':js_short_lang}, function(data){
					$("#extra-products-preloader").remove();
					$('#extra-products').data('page',page+1);
					$('#extra-products').append(data);
					var mh = 0;
					$(".same-height").each(function(index){
						var h = $(this).height();
						if(h>mh){ mh=h; }
					});
					$(".same-height").each(function(index){
						$(this).height(mh-50);
					});
					busy=0;
				});
			}
		}	
	});
}	

/*********************************************************TABS */
$(".tab-title").click(function () {
	var category=$(this).data('category');
	$(".tab-title").removeClass('current');
	$(".tab-content").removeClass('current');
	$(this).addClass('current');
	$("#search-wrap.gifts-search").addClass('current');
	$("#tab-content-"+category).addClass('current');
	$('html, body').animate({scrollTop: $("#scroll-category").offset().top}, 300);
});

/*********************************************************scroll */
$(window).on('scroll', function() {
	if($('#ajax-quantity').length){
		var ofs = $('#ajax-quantity').offset();
		var wst = $(window).scrollTop();
		if(wst >= ofs.top) {
			$('#ajax-quantity').addClass('fixed');
		}else{
			$('#ajax-quantity').removeClass('fixed');
		}
	}
});

var mh = 0;
$(".same-height").each(function(index){
	var h = $(this).height();
	if(h>mh){ mh=h; }
});
$(".same-height").each(function(index){
	$(this).height(mh-50);
});

$(document).on("keypress",'form input', function(e) {
    return e.which !== 13;
});


if($('#flipbook-options').length){
	let touchstartX = 0;
	let touchstartY = 0;
	let touchendX = 0;
	let touchendY = 0;

	const gestureZone = $('.flipbook-wrap')[0];

	gestureZone.addEventListener('touchstart', function(event) {
		touchstartX = event.changedTouches[0].screenX;
	}, false);

	gestureZone.addEventListener('touchend', function(event) {
		touchendX = event.changedTouches[0].screenX;
		handleGesture();
	}, false);

	function handleGesture() {
		sensitivity=50;
		if (touchendX <= touchstartX-sensitivity) {
			//console.log(touchendX+'<='+touchstartX+'-'+sensitivity);
			$("#custom-next").trigger( "click" );
		}

		if (touchendX >= touchstartX+sensitivity) {
			//console.log(touchendX+'>='+touchstartX+'+'+sensitivity);
			$("#custom-prev").trigger( "click" );

		}
	}
	window.addEventListener("resize", initiate_flipbook);
	initiate_flipbook();
}

$(document).on('input','#filter', function() {
	var keyword=$('#filter').val();
	$(".category-big-tile-title").each(function() {
		var text=$(this).text();
		//if (text.length>0) $(".clearfix").css('display', 'none !important;'); else $(".clearfix").css('display', '');
		if (text.toLowerCase().indexOf(keyword.toLowerCase()) == -1) $(this).parent().parent().fadeOut(); else $(this).parent().parent().fadeIn();
	});
});
/*
//store the element
var $cache = $('#ajax-quantity');

//store the initial position of the element
var vTop = $cache.offset().top - parseFloat($cache.css('marginTop').replace(/auto/, 0));
  $(window).scroll(function (event) {
    // what the y position of the scroll is
    var y = $(this).scrollTop();

    // whether that's below the form
    if (y >= vTop) {
      // if so, ad the fixed class
      $('.total-price').addClass('fixed');
    } else {
      // otherwise remove it
      $('.total-price').removeClass('fixed');
    }
  });
*/
/*
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
if (js_short_lang=='gr'){
	s1.src='https://embed.tawk.to/59ad14ec4854b82732fee0be/1bp635mfa';
	s1.src='https://embed.tawk.to/59ad14ec4854b82732fee0be/1bp635mfa';
} else {
	s1.src='https://embed.tawk.to/59ad14ec4854b82732fee0be/default';
}
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
*/
/************************************************************* HOME C BOX */
$('.c-box').mouseenter(function(){
	$('.c-more',this).stop(true,true).slideDown(200);
});
$('.c-box').mouseleave(function(){
	$('.c-more',this).stop(true,true).slideUp(200);
});

/************************************************************* MSG */
if($(".msg")){
	$(".msg").delay(20000).slideUp(600,function(){
		$("#progress-info-gr").html('');
		$("#progress-info-en").html('');
		$("#progress-msg-gr").html('');
		$("#progress-msg-en").html('');
	});
}

var menu_timeout = null;
//$(".mega-menu-cats").hide();
$(".mega-menu-item").mouseover(function(){
	var id = $(this).attr('data-id');
	$(".mega-menu-item").removeClass("selected");
	$("#mega-menu-item-"+id).addClass("selected");
	menu_timeout = setTimeout(function() { expand_menu(id); }, 200);
});
$(".mega-menu-item").mouseout(function(){
	clearTimeout(menu_timeout);
});
$("#menu-bar-wrap").mouseleave(function(){
	$(".mega-menu-item").removeClass("selected");
	$("#mega-menu").slideUp(300);
});

function expand_menu(id){
	$(".mega-menu-cats").slideUp(200);
	$("#mega-menu-cats-"+id).slideDown(200);
	$("#mega-menu").slideDown(300);
}
/*
$(".mega-menu-block").hoverIntent(
	function(){
		var id = $(this).attr('data-id');
		$(".mega-menu-block-list-"+id).stop(true,false).slideDown(400);
		$(".mega-menu-block-img-"+id).stop(true,false).slideUp(400);
		$(".mega-menu-block-"+id).addClass("selected");
	},
	function(){
		$(".mega-menu-block-list").stop(true,false).slideUp(400);
		$(".mega-menu-block-img").stop(true,false).slideDown(400);
		$(".mega-menu-block").removeClass("selected");
	}
);
*/
// mobile menu
$(".mobile-section-link").click(function(){
	var id = $(this).attr('data-id');
	var list = ".mobile-category-list-"+id;
	var link = ".mobile-section-link-"+id;
	if($(list).hasClass('open')){

	}else{
		$(".mobile-category-list.open").slideUp('fast');
		$(".mobile-category-list.open").removeClass('open');
		$(".mobile-section-link.open").removeClass('open');
		$(list).slideDown('fast');
		$(list).addClass('open');
		$(link).addClass('open');

	}
});
$("#icon-menu").click(function(){
	$("#mobile-menu").slideToggle('fast');
});
$(".mobile-menu-close-icon").click(function(){
	$("#mobile-menu").slideUp('fast');
});

$(window).scroll(function () {
	if ($(this).scrollTop() > 200) {
		$('#scroll-top').fadeIn();
	} else {
		$('#scroll-top').fadeOut();
	}
	if ($(this).scrollTop() > 20) {
		$('#small-menu').addClass("scrolled");
	} else {
		$('#small-menu').removeClass("scrolled");
	}
});

$("#scroll-top").click(function(){
	$("html, body").animate({scrollTop:0}, "slow");
});

$(".scroller").click(function(event){
	event.preventDefault(); //remove hash
	var id = $(this).attr('href').replace("#","");
	$("html, body").animate({scrollTop:($('#'+id).offset().top)-160},"slow");
});

/************************************************************* TOOLTIPS */
/*
$('.tp').tooltip({
track: true,
delay: 0,
showURL: false,
extraClass: "descriptions-class",
fade: 300
});
*/
//************************************ tooltipster
$('.tooltip-top-right').each(function() {
	$(this).tooltipster({
		content: $(this).next('.tooltiptext').html(),
		contentAsHTML: true,
		speed: 200,
		position: 'top-right'
	});
});
$('.tooltip-top-left').each(function() {
	$(this).tooltipster({
		content: $(this).next('.tooltiptext').html(),
		contentAsHTML: true,
		speed: 200,
		position: 'top-left'
	});
});

//**************************************** tooltipster
$('.tipster-top').each(function() {			$(this).tooltipster({content:$(this).next('.tipstertext').html(),contentAsHTML:true,speed:50,position:'top'});});
$('.tipster-right').each(function() {		$(this).tooltipster({content:$(this).next('.tipstertext').html(),contentAsHTML:true,speed:50,position:'right'});});
$('.tipster-left').each(function() {		$(this).tooltipster({content:$(this).next('.tipstertext').html(),contentAsHTML:true,speed:50,position:'left'});});
$('.tipster-top-right').each(function() {	$(this).tooltipster({content:$(this).next('.tipstertext').html(),contentAsHTML:true,speed:50,position:'top-right'});});
//$('.tipster-top-left').each(function() {	$(this).tooltipster({content:$(this).next('.tipstertext').html(),contentAsHTML:true,speed:50,position:'top-left'});});

$('body').on('mouseenter', '.tipster-top-left:not(.tooltipstered)', function(){
    $(this)
        .tooltipster({ content:$(this).next('.tipstertext').html(),contentAsHTML:true,speed:50})
        .tooltipster('open');
});
$(".show-hide-content").hide();
$(".show-hide-content.current").slideDown(200);
/************************************************************* SHOW HIDE */
$(".show-hide-head").click(function(){
	if($(".show-hide-head").hasClass('hidea')) {
		var slideTime=200;
	} else {
		var slideTime=600;
	}
	var partial_h = 300;
	var parent = $(this).parent(".show-hide");
	var content = $(".show-hide-content",parent);
	var head = $(".show-hide-head",parent);
	if(content.hasClass("current")){
		content.removeClass("current");
		head.removeClass("current");
		if(content.hasClass("hidea")){
			content.addClass("current");
			head.addClass("current");
		} else if(content.hasClass("partial")){
			content.animate({height:partial_h});
			$(".show-hide-partial-mask",content).show();
		}else{
			content.slideUp(slideTime);
		}
	}else{
		if($(".show-hide-content").hasClass("current")){
			if(content.hasClass("hidea-color")){
				$(".show-hide-content.hidea.hidea-color").removeClass("current");
				$(".show-hide-head.hidea.hidea-color").removeClass("current");
				$(".show-hide-content.hidea.hidea-color").slideUp(slideTime);
			} else if(content.hasClass("hidea-print")){
				$(".show-hide-content.hidea.hidea-print").removeClass("current");
				$(".show-hide-head.hidea.hidea-print").removeClass("current");
				$(".show-hide-content.hidea.hidea-print").slideUp(slideTime);
			} else {
				$(".show-hide-content").removeClass("current");
				$(".show-hide-head").removeClass("current");
				$(".show-hide-content").slideUp(slideTime);
			}
		}
		content.addClass("current");
		head.addClass("current");
		if(content.hasClass("hidea")){
			if(content.hasClass("hidea-color")){
				$('input[name="hidea_color"]').prop('checked', false);
			}
			content.slideDown(slideTime);
			if(('.ums-radio-item.hidea-radio label:first').length){
				content.find('.ums-radio-item.hidea-radio label:first').trigger('click');
			}
		} else if(content.hasClass("partial")){
			content.slideDown(slideTime);
			content.css("height","auto");
			var h = content.height();
			content.css("height",partial_h+"px");
			content.animate({height:h});
			$(".show-hide-partial-mask",content).hide();
		}else{
			content.slideDown(slideTime);
		}
	}
	//$(this).slideUp("100");
});

$(".show-hide-all").click(function(){
	if($(".show-hide-all").hasClass("open")){
		$(".show-hide-all").removeClass("open");
		$(".show-hide-content").removeClass("current");
		$(".show-hide-head").removeClass("current");
		$(".show-hide-content").slideUp(600);
	}else{
		$(".show-hide-all").addClass("open");
		$(".show-hide-content").addClass("current");
		$(".show-hide-head").addClass("current");
		$(".show-hide-content").slideDown(600);
	}
});

//***************************************************************** FANCYBOX
/*
$(".gal").fancybox({
autoSize: true,
autoResize: true,
fitToView: true,
loop: false,
autoPlay: false,
playSpeed: 5000,
openEffect: 'elastic',
closeEffect: 'elastic',
nextEffect: 'fade',
prevEffect: 'fade',
openSpeed: 'slow',
closeSpeed: 'fast',
nextSpeed: 'slow',
prevSpeed: 'fast',
helpers: {
title: {type: 'inside'},
overlay: {css: {'background-color' : 'rgba(0, 0, 0, 0.6)'}}
},
beforeLoad: function(){
var temp=this.title.split('|');
if(!temp[1]){temp[1]=""};
this.title = '<h2 class="fbcustom-title">'+temp[0]+'</h2><p>'+temp[1]+'</p>';
}
});


$(".fancybox").fancybox({
	padding : 0,
	width : 770,
	autoHeight : true,
	loop: false,
	helpers: {
	overlay: {css: {'background-color' : 'rgba(0, 0, 0, 0.6)'}}
	}
});

$("[data-fancybox]").fancybox({
	image : {
		protect : true
	}
});
*/
$('.mockup-img').on('dragstart', function(event) { event.preventDefault(); });
$('.gal-single-link').on('dragstart', function(event) { event.preventDefault(); });
$("body").on("contextmenu", ".mockup-img", function(e) {
  return false;
});
$("body").on("contextmenu", ".gal-single-link", function(e) {
  return false;
});

//disable box preloader
/*
if($("#boxes").length>0){
	$("#boxes").hide();
	if (document.getElementById('preloader-boxes')) {
		$.preload(images, {
			init: function(loaded, total) {
				$("#preloader-boxes").html("<img src='https://commons.utopia.gr/images/icons/preloaders/load_light.gif' alt='preloader' />");
			},
			loaded_all: function(loaded, total) {
				$('#preloader-boxes').fadeOut('slow', function() {
					$("#boxes").show();
				});
			}
		});
	}
}
*/

/************************************************************* SUDOSLIDER */
if($("#slider").length>0){
	$("#slider").hide();
	if (document.getElementById('preloader')) {
	$.preload(images, {
	init: function(loaded, total) {
		$("#preloader").html("<img src='https://commons.utopia.gr/images/icons/preloaders/load_light.gif' alt='preloader' />");
	},
	loaded_all: function(loaded, total) {
	$('#preloader').fadeOut('slow', function() {
		$("#slider").show();
		var modal = document.getElementById('circle1');
		modal.style.display= "block";
		var sudoSlider1 = $("#slider").sudoSlider({
			responsive:true,
			touch:true,
			effect:'slide',
			prevNext:true,
			numeric:false,
			speed:600,
			auto:true,
			pause:4000,
			resumePause:4000,
			continuous:true,
			autowidth:false,
			autoheight:false,
			afterAnimation: function(slide){
					var modal = document.getElementById('circle'+slide);
					modal.style.display= "block";
			},
			beforeAnimation: function(slide){
				for (i = 1; i < 11; i++) {
						if(document.getElementById('circle'+i)) {
							var modal = document.getElementById('circle'+i);
							modal.style.display= "none";
						}
				}
			},
			controlsAttr:'id="slider-controls"',
			prevHtml:'<a href="#" class="sprite slider-prev"></a>',
			nextHtml:'<a href="#" class="sprite slider-next"></a>'
		});
		$("#slider").mouseenter(function(){sudoSlider1.stopAuto();});
		$("#slider").mouseleave(function(){sudoSlider1.startAuto();});
	});
	}
	})};
}


if($("#product-slider").length>0){
	var sudoSlider2 = $("#product-slider").sudoSlider({
		responsive:true,
		touch:true,
		effect:'slide',
		prevNext:true,
		numeric:false,
		speed:600,
		auto:true,
		pause:6000,
		resumePause:3000,
		continuous:true,
		autowidth:false,
		autoheight:false,
		controlsAttr:'id="product-slider-controls"',
		prevHtml:'<a href="#" class="sprite product-slider-prev"></a>',
		nextHtml:'<a href="#" class="sprite product-slider-next"></a>'
	});
	$("#product-slider").mouseenter(function(){sudoSlider2.stopAuto();});
	$("#product-slider").mouseleave(function(){sudoSlider2.startAuto();});
}

if($("#gallery-slider").length>0){
	var sudoSlider3 = $("#gallery-slider").sudoSlider({
		responsive:true,
		touch:true,
		effect:'slide',
		prevNext:true,
		numeric:false,
		speed:500,
		auto:true,
		pause:2000,
		resumePause:2000,
		continuous:true,
		autowidth:false,
		autoheight:false,
		slideCount:4,
		moveCount:4,
		controlsAttr:'id="gallery-slider-controls"',
		prevHtml:'<a href="#" class="sprite gallery-slider-prev"></a>',
		nextHtml:'<a href="#" class="sprite gallery-slider-next"></a>'
	});
	$("#gallery-slider").mouseenter(function(){sudoSlider3.stopAuto();});
	$("#gallery-slider").mouseleave(function(){sudoSlider3.startAuto();});
}

if($("#home-sections-slider").length>0){
var sudoSlider4 = $("#home-sections-slider").sudoSlider({
		responsive:true,
		touch:true,
		effect:'slide',
		prevNext:true,
		numeric:false,
		speed:600,
		auto:false,
		pause:4000,
		resumePause:4000,
		continuous:true,
		autowidth:false,
		autoheight:false,
		controlsAttr:'id="home-sections-slider-controls"',
		prevHtml:'<a href="#" class="sprite home-sections-slider-prev"></a>',
		nextHtml:'<a href="#" class="sprite home-sections-slider-next"></a>'
	});
}

function haccord(){
	if($(".haccord").length){
		$(".haccord").each(function( index ) {
			var no_parts = $(this).children('.haccord-part').length;
			var pw = ($(this).width() / no_parts);
			var iw=pw*4;
			$(this).css({"display":"block", "margin":"0 auto", "height":iw, "overflow":"hidden", "white-space":"nowrap"});
			$('.haccord-part',this).css({"width":pw, "display":"inline-block", "vertical-align":"top", "position":"relative", "box-shadow":"0px 0px 15px #000", "cursor":"pointer"});
			$('.haccord-img',this).css({"width":iw, "border":"1px solid #fff"});
			$('.haccord-title',this).css({"left":0, "bottom":0, "width":iw});
		});
	}
}
$('.haccord-part').mouseenter(function(){
	var par = $(this).parent('.haccord');
	var no_parts = par.children('.haccord-part').length;
	var pw = (par.width() / no_parts);
	$('.haccord-part',par).stop(true,false).animate({width: (pw)-(pw*3/no_parts)+"px"},400);
	$(this).stop(true,false).animate({width: (pw*4)+"px"},400);
});
$('.haccord').mouseleave(function(){
	var w = $('.haccord-img').width() + 2;
	$('.haccord-part').stop(true,false).animate({width: (w/4)+"px"},400);
});
haccord();
$(window).resize(function () {
	haccord();
});


$(".form-tab-head").click(function(){
	id=$(this).data('id');
	$(".form-tab-head").removeClass('current');
	$(".form-tab-content").removeClass('current');
	$(this).addClass('current');
	$(".form-tab-content").each(function() {
		if(id==$(this).data('id')) $(this).addClass('current');
	});
});


$("#product_version").change(function(){
	$('#price_selector').html("...");
	var key=$(this).val();
	var label = $("#product_version option:selected").text();
	if(key!=0 && prices[key]){
		var str = prices[key].toString();
		//alert(str);
		var pieces = str.split(",");
		var selector = '';
		selector += '<input type="hidden" name="product_version_label" value="'+label+'" />';
		selector += lang_pieces+':<br /><select class="input-line" name="product_pieces" id="product_pieces">';
		pieces.forEach(function(entry){
			str = entry.toString();
			var p_pieces = str.split(":");
			var info= p_pieces[0]+' '+lang_pieces+': '+p_pieces[1];
			if (p_pieces[0]=='1') var info=p_pieces[1];
			selector += '<option value="'+info+'">'+info+'</option>';
		});
		selector += '<option value="other">'+lang_other_quantity+'</option>';
		selector += '</select>';
		$('#price_selector').html(selector);
	}else if(key!=0){
		var selector = '';
		selector += '<input type="hidden" name="product_version_label" value="'+label+'" />';
		$('#price_selector').html(selector);
	} else {
		$('#price_selector').html('');
	}

});

$("#price_selector").change(function(){
		var html='';
	if (document.getElementById("product_pieces").value=='other') {
		html += lang_quantity+': <input class="input-line" name="price_input" type="text"/> &nbsp; ';
		html += '<br />';
		document.getElementById("price_input").innerHTML = html;
	} else {
		document.getElementById("price_input").innerHTML = '';
	}
});

if($("input[data-codes='mcr']").length>0){
	$("input[data-codes='mcr']").change(function(){
		if ($(this).is(':checked')){
			$('.mcr-info').show();
			$('.acr-info').hide();
		}
	});
	$("input[data-codes='acr']").change(function(){
		if ($(this).is(':checked')){
			$('.mcr-info').hide();
			$('.acr-info').show();
		}
	});
}

//************************************************************* AJAX FORM SELECTION
$(document).on("click", '.btn-guest', function() {
	var target = $(this).data('target');
	var selection = $(this).data('selection');
	var short_lang = $(this).data('short_lang');
	if(selection!='login') {$("#guest-login").hide();/*$("#guest-ajax-response").html("<div class=\"clearfix\"></div><div class=\"guest-preloader col-md-12\"><img src='https://commons.utopia.gr/images/icons/preloaders/gallery_preloader.svg' alt='preloader' /></div><div class=\"clearfix\"></div>");*/} else {$("#guest-login").show();$("#guest-ajax-response").html('');}
	if(selection!='register') {$("#guest-social-buttons").hide();} else {$("#guest-social-buttons").show();}
	if($(".ucart-choose-interest.selected").length && selection=='guest'){selection='guest-interest';}
	$(".btn-guest").each(function() {
	  $(this).removeClass("selected");
	});
	$('#'+target).addClass("selected");
	$("#guest-ajax-response").load("https://aldigron.gr/scripts/ajax.php",{selection:selection, short_lang:short_lang});
});

$(document).on("click", '.ucart-choose-button', function() {
	var selection = $(".btn-guest.selected").data('selection');
	var short_lang = $(".btn-guest.selected").data('short_lang');
	if(selection=='guest'){
		if($(this).hasClass('ucart-choose-interest')){
			$("#guest-ajax-response").load("https://aldigron.gr/scripts/ajax.php",{selection:'guest-interest', short_lang:short_lang});
		} else {
			$("#guest-ajax-response").load("https://aldigron.gr/scripts/ajax.php",{selection:selection, short_lang:short_lang});
		}
	}
});
//************************************************************* AJAX MAIL AVAILABILITY
$("input:text[name=email]").bind('input propertychange', function(){

	var RegExEmail = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/);
	if (js_short_lang=='gr'){
		var not_valid_email = "Μη αποδεκτό email"
		var lang_available2 = "Ο λογαριασμός χρησιμοποιείται ήδη";
		var lang_available3 = "Ο λογαριασμός είναι διαθέσιμος";
	} else {
		var not_valid_email = "Not a valid email address"
		var lang_available2 = "Email already in use";
		var lang_available3 = "Email available";
	}
	var value = $("input:text[name=email]").val();
	var user_id= $("input:hidden[name=user_id]").val();

	$("#email-msg").load("https://aldigron.gr/scripts/ajax.php?value="+value+"&id="+user_id , function(responseTxt,statusTxt,xhr){
		if( !value.match(RegExEmail) ){
			document.getElementById("email_validate").value = "";
			$("#email-msg").html(not_valid_email);
			$("#email-msg").css({"color":"red"});}
		else if(responseTxt == "e1"){
			document.getElementById("email_validate").value = "";
			$("#email-msg").html(lang_available2);
			$("#email-msg").css({"color":"red"});
		}else{
			document.getElementById("email_validate").value = "1";
			$("#email-msg").html(lang_available3);
			$("#email-msg").css({"color":"green"});
		}
	});

});

$("input:password[name=password_confirm]").bind('input propertychange', function(){
	if (js_short_lang=='gr'){
		var password_match = "Όμοιος Κωδικός";
		var no_password_match = "Ανόμοιος Κωδικός";
	}else {
		var password_match = "Passwords match";
		var no_password_match = "Passwords do not match";
	}
	var value1 = $("input:password[name=password]").val();
	var value2 = $("input:password[name=password_confirm]").val();

	if(value1==value2){
		document.getElementById("password_validate").value = "1";
		$("#password-msg").html(password_match);
		$("#password-msg").css({"color":"green"});
	}else{
		document.getElementById("password_validate").value = "";
		$("#password-msg").html(no_password_match);
		$("#password-msg").css({"color":"red"});
	}
});

$("input:password[name=password]").bind('input propertychange', function(){
	if (js_short_lang=='gr'){
		var password_match = "Όμοιος Κωδικός";
		var no_password_match = "Ανόμοιος Κωδικός";
	}else {
		var password_match = "Passwords match";
		var no_password_match = "Passwords do not match";
	}
	var value1 = $("input:password[name=password]").val();
	var value2 = $("input:password[name=password_confirm]").val();

	if(value1==value2){
		document.getElementById("password_validate").value = "1";
		$("#password-msg").html(password_match);
		$("#password-msg").css({"color":"green"});
	}else{
		document.getElementById("password_validate").value = "";
		$("#password-msg").html(no_password_match);
		$("#password-msg").css({"color":"red"});
	}
});


// UCART
if (document.getElementById('ucart-cart')) {ucart_motion(100);}

if ($('#input_code').length){
	var excludes=[];
	$("input[type=radio]:checked").each(function(){
		if($(this).data('excludes')!=null && $(this).data('excludes')!='') excludes=excludes+','+$(this).data('excludes');
	});
	$(':input').prop('disabled',false);
	$('option').prop('disabled',false);
	if(excludes!=''){
		var excludes_array=excludes.split(',');
		$.each(excludes_array,function(index,value){
			$('#'+value).prop('disabled', true);
		});
	}
	var codes=$('#input_code').val();
	$("input[type=radio]:checked").each(function(){
		if($(this).data('codes')!=null && $(this).data('codes')!='') codes=codes+'-'+$(this).data('codes');
	});
	$('#ajax-quantity').html('<div style="min-height:300px;text-align:center;"><img style="margin-top:100px;" src="https://cdn.utopia.gr/images/icons/preloaders/gallery_preloader.svg" alt=""></div>');
	$('#ajax-quantity').load('https://aldigron.gr/scripts/ajax.php', {'get_prices':'true','codes':codes,'short_lang':js_short_lang});
}
//FORMS
$('.pivot-radio-input').bind('change', function(){
	var excludes=[];
	$("input[type=radio]:checked").each(function(){
		if($(this).data('excludes')!=null && $(this).data('excludes')!='') excludes=excludes+','+$(this).data('excludes');
	});
	$(':input').prop('disabled',false);
	$('option').prop('disabled',false);
	if(excludes!=''){
		var excludes_array=excludes.split(',');
		$.each(excludes_array,function(index,value){
			$('#'+value).prop('disabled', true);
		});
	}
	var codes=$('#input_code').val();
	$("input[type=radio]:checked").each(function(){
		if($(this).data('codes')!=null && $(this).data('codes')!='') codes=codes+'-'+$(this).data('codes');
	});
	if($('.price-pivot-radio-input:checked').length){
		var selected_value=$('.price-pivot-radio-input:checked').val();
	} else {
		var selected_value=$('#perpiece_quantity').val();
	}
	$('#ajax-quantity').html('<div style="min-height:300px;text-align:center;"><img style="margin-top:100px;" src="https://cdn.utopia.gr/images/icons/preloaders/gallery_preloader.svg" alt=""></div>');
	$('#ajax-quantity').load('https://aldigron.gr/scripts/ajax.php', {'get_prices':'true','codes':codes,'short_lang':js_short_lang,'selected_value':selected_value,'selected_other_quantity':$('#other_quantity').val()});
});

$(document).on( "change", '.price-pivot-radio-input', function() {
	var codes=$('#input_code').val();
	$("input[type=radio]:checked").each(function(){
		if($(this).data('codes')!=null && $(this).data('codes')!='') codes=codes+'-'+$(this).data('codes');
	});
	$('#ajax-quantity').html('<div style="min-height:300px;text-align:center;"><img style="margin-top:100px;" src="https://cdn.utopia.gr/images/icons/preloaders/gallery_preloader.svg" alt=""></div>');
	$('#ajax-quantity').load('https://aldigron.gr/scripts/ajax.php', {'get_prices':'true','codes':codes,'short_lang':js_short_lang,'selected_value':$(this).val()});
});

$(document).on("input", "#perpiece_quantity", function() {
	var selected_quantity = this.value.replace(/[^\d\.\-]/g,'');
	if (js_short_lang=='gr'){
		var lang_pieces = " τεμάχια";
		var lang_piece = " τεμάχιο";
		var lang_perpiece = "ανά τεμ.";
	}else {
		var lang_pieces = " pieces";
		var lang_piece = " piece";
		var lang_perpiece = "per unt";
	}
	var previous_quantity=0;
	var current_price=0;
	$('.perpiece-prices').each(function() {
		if(selected_quantity>=previous_quantity && selected_quantity<$(this).data('quantity')) {
			current_price=$(this).data('price');
		}
		previous_quantity=$(this).data('quantity');
		previous_price=$(this).data('price');
	});
	if(selected_quantity>=previous_quantity){
		current_price=previous_price;
	}

	var current_price_float=0;
	current_price_float=parseFloat(current_price.toString().replace(',','.'));

	var price_total=parseFloat(selected_quantity) * current_price_float;
	if(selected_quantity==1) lang_pieces=lang_piece;
	if(price_total>0 && selected_quantity>=1) {
		perpiece_price=current_price_float;
		var price_per_piece_tag="<div id=\"price-perpiece-box\">"+perpiece_price.toFixed(2).toString().replace('.',',')+" €<br />"+lang_perpiece+"</div>\n";;
	} else {
		var price_per_piece_tag="";
	}
	$('#perpiece-response').html("<div class=\"total-price\"><span class=\"total-price-quantity\">"+selected_quantity+lang_pieces+":</span> <span class=\"total-price-actual\">"+price_total.toFixed(2).toString().replace('.',',')+" €</span>"+price_per_piece_tag+"</div></div><input type=\"hidden\" name=\"price\" id=\"price\" value=\""+selected_quantity+"|"+price_total.toFixed(2)+"\" />\n");
});

$(document).on("input", "#other_quantity", function() {
	if (js_short_lang=='gr'){
		var lang_pieces = " τεμάχια";
		var lang_piece = " τεμάχιο";
		var lang_perpiece = "ανά τεμ.";
		var lang_arr = "Με συννενόηση";
	}else {
		var lang_pieces = " pieces";
		var lang_piece = " piece";
		var lang_perpiece = "per unt";
		var lang_arr = "After arrangement";
	}
	var selected_quantity = this.value.replace(/[^\d\-]/g,'');
	var previous_quantity=0;
	var current_price=0;
	$(".price-pivot-radio-input").each(function() {
		if(selected_quantity>=previous_quantity && selected_quantity<=$(this).data('quantity')) {
			var variable_quantity=parseFloat($(this).data('quantity'))-parseFloat(previous_quantity);
			var extra_quantity=parseFloat(selected_quantity)-parseFloat(previous_quantity);
			var quantity_percent=extra_quantity/variable_quantity;
			var variable_price=parseFloat($(this).data('price'))-parseFloat(previous_price);
			var extra_price=variable_price*quantity_percent;
			current_price=(previous_price+extra_price)/selected_quantity;
		}
		if(!isNaN($(this).data('quantity'))) previous_quantity=$(this).data('quantity');
		if(!isNaN($(this).data('price'))) previous_price=$(this).data('price');
	});
	var price_total=parseFloat(selected_quantity) * current_price;
	if(selected_quantity==1) lang_pieces=lang_piece;
	var price_perpiece=price_total/selected_quantity;
	if(price_total>0 && selected_quantity>1) {
		var price_per_piece_tag="<div id=\"price-perpiece-box\">"+price_perpiece.toFixed(2).toString().replace('.',',')+" €<br />"+lang_perpiece+"</div>\n";;
	} else {
		var price_per_piece_tag="";
	}
	price_total_str=price_total.toFixed(2).toString().replace('.',',')+" €";
	if(price_total_str=='0,00 €') price_total_str=lang_arr;
	$('#other_quantity-response').html("<div class=\"total-price\"><span class=\"total-price-quantity\">"+selected_quantity+lang_pieces+":</span> <span class=\"total-price-actual\">"+price_total_str+"</span>"+price_per_piece_tag+"</div><input type=\"hidden\" name=\"other_quantity-price\" id=\"other_quantity-price\" value=\""+selected_quantity+"|"+price_total.toFixed(0)+"\" />\n");
});

$(document).on("input", ".hidea-pivot-range-input", function() {
	refresh_hidea_price();
});

$('#google_signup').oauthpopup({
        path: domain+'/scripts/login.php?google',
        width:450,
        height:450,
});
$('#facebook_signup').oauthpopup({
        path: domain+'/scripts/login.php?facebook',
        width:450,
        height:450,
});
$('#google_login').oauthpopup({
        path: domain+'/scripts/login.php?google',
        width:450,
        height:450,
});
$('#facebook_login').oauthpopup({
        path: domain+'/scripts/login.php?facebook',
        width:450,
        height:450,
});

/*
$(document).on("mouseover", ".eshop-submit", function() {
	if($('#fancy-designer').length){
		yourDesigner.getProductDataURL(function(dataURL) {
			$('#fancy_base64_url').val(dataURL);
		});
		if(productIsCustomized){
			$('#fpd_pivot').val('1');
		}
	}
});
*/


$(document).on("click", ".ga-event", function(event) {
	var category=$(this).data('category');
	var action=$(this).data('action');
	var label=$(this).data('label');
	//ga('send', 'event', category, action, label, 1);
	gtag('event', category+'_'+action+'_'+label, {
		'event_name': category+'_'+action+'_'+label,
	});
});

	/*save image on webserver


	//send image via mail
	$('#send-image-mail-php').click(function() {

		yourDesigner.getProductDataURL(function(dataURL) {
			$.post( fpd_scripts_url_path+"php/send_image_via_mail.php", { base64_image: dataURL} );
		});

	});*/

	$(document).on("keydown", "#search_form", function(event) {
	    return event.key != "Enter";
	});

	$(document).on("click", ".product-filters-item", function() {
		var filter=$(this).data('filter');
		$('.product-filters-item').removeClass('selected');
		$(this).addClass('selected');
		$('.filtered-product').hide();
		$('.filtered-product.'+filter).fadeIn(300);
		//$('html, body').animate({
		//	scrollTop: $(".row-eq-height").offset().top
		//}, 300);
	});
	$(document).on("click", "#product-filters-clear", function() {
		$('.product-filters-item').removeClass('selected');
		$('.filtered-product').fadeIn(300);
		$('.show-hide-head.filters').trigger('click');
		//$('html, body').animate({
		//	scrollTop: $(".row-eq-height").offset().top
		//}, 300);
	});


if($(".hidea-demo .ums-radio-wrap").length){
	const slider = document.querySelector(".hidea-demo .ums-radio-wrap");
	let isDown = false;
	let startX;
	let scrollLeft;
	slider.addEventListener("mousedown", e => {
	  isDown = true;
	  slider.classList.add("active");
	  startX = e.pageX - slider.offsetLeft;
	  scrollLeft = slider.scrollLeft;
	});
	slider.addEventListener("mouseleave", () => {
	  isDown = false;
	  slider.classList.remove("active");
	});
	slider.addEventListener("mouseup", () => {
	  isDown = false;
	  slider.classList.remove("active");
	});
	slider.addEventListener("mousemove", e => {
	  if (!isDown) return;
	  e.preventDefault();
	  const x = e.pageX - slider.offsetLeft;
	  const walk = x - startX;
	  slider.scrollLeft = scrollLeft - walk;
	});
}

/************************************************************* STRICKER DEMO */
$(document).on("click", ".color-item", function() {
	$('.color-item').removeClass('selected');
	$(this).addClass('selected');
	var hidea_id=$('#hidea_id').val();
	var color=$(this).data('color');
	$('#add-form-color').val(color);
	$('#optional-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_optional':'true','color':color,'hidea_id':hidea_id,'short_lang':js_short_lang},function(){
		if($('#optional_quantity_output').length==0){
			$('#stricker-optional-add').addClass('disabled');
		} else {
			$('#stricker-optional-add').removeClass('disabled');
		}
		if($('.size-item ').length){
			$('#stricker-optional-add').addClass('disabled');
		}
	});
});

$(document).on("click", ".size-item", function() {
	var hidea_id=$('#hidea_id').val();
	var color=$('#add-form-color').val();
	var size=$(this).data('size');
	$('#optional-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_optional':'true','color':color,'hidea_id':hidea_id,'size':size,'short_lang':js_short_lang},function(){
		if($('#optional_quantity_output').length==0){
			$('#stricker-optional-add').addClass('disabled');
		} else {
			$('#stricker-optional-add').removeClass('disabled');
		}
		if($('.size-item ').length){
			$('#stricker-optional-add').removeClass('disabled');
		}
	});
});

$(document).on("click", "#stricker-optional-add", function() {
	if($('#optional_quantity_output').length==0){
		if (js_short_lang=='gr'){
			alert('Δεν υπάρχει διαθεσιμότητα');
		} else {
			alert('No products available');
		}
	} else if($(this).hasClass('disabled')){
		if (js_short_lang=='gr'){
			alert('Δεν έχετε επιλέξει μέγεθος');
		} else {
			alert('Please select size');
		}
	} else {
		var optional_id=$('#optional_id').val();
		var optional_qty=$('#optional_quantity_output').val();
		if($(window).width()<993) $('html, body').animate({scrollTop: $(".customization-selector").offset().top-$(window).height()/4}, 300);
		var optional_qty=$('#optional_quantity_output').val();
		$('#purchase-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_add_optional':'true','optional_id':optional_id, 'optional_qty':optional_qty,'short_lang':js_short_lang},function(){
			$('.customization-selector').removeClass('disabled');
		});
	}
});

$(document).on("click", ".stricker-optional-remove", function() {
	var optional_id=$(this).data('optional_id');
	$('#purchase-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_remove_optional':'true','optional_id':optional_id,'short_lang':js_short_lang},function(){
		if(!$('.purchase-optional-row').length){
			$('.customization-selector').addClass('disabled');
		}
	});
});

$(document).on("click", ".component-item", function() {
	$('.component-item').removeClass('selected');
	$(this).addClass('selected');
	var hidea_id=$('#hidea_id').val();
	var component=$(this).data('component');
	$('#add-form-component').val(component);
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_customization':'true','component':component,'hidea_id':hidea_id,'short_lang':js_short_lang},function(){
		$('#stricker-customization-add').addClass('disabled');
	});
});

$(document).on("click", ".location-item", function() {
	var hidea_id=$('#hidea_id').val();
	var component=$('#add-form-component').val();
	var location=$(this).data('location');
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_customization':'true','component':component,'location':location,'hidea_id':hidea_id,'short_lang':js_short_lang},function(){
		$('#stricker-customization-add').addClass('disabled');
	});
});

$(document).on("click", ".type-item", function() {
	var hidea_id=$('#hidea_id').val();
	var component=$('#add-form-component').val();
	var location=$('#add-form-location').val();
	var type=$(this).data('type');
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_customization':'true','component':component,'location':location,'type':type,'hidea_id':hidea_id,'short_lang':js_short_lang},function(){
		$('#stricker-customization-add').addClass('disabled');
	});
});
$(document).on("click", ".colors-item", function() {
	var hidea_id=$('#hidea_id').val();
	var component=$('#add-form-component').val();
	var location=$('#add-form-location').val();
	var type=$('#add-form-type').val();
	var colors=$(this).data('colors');
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_customization':'true','component':component,'location':location,'type':type,'colors':colors,'hidea_id':hidea_id,'short_lang':js_short_lang},function(){
		$('#stricker-customization-add').addClass('disabled');
	});
});
$(document).on("click", ".dimensions-item", function() {
	var hidea_id=$('#hidea_id').val();
	var component=$('#add-form-component').val();
	var location=$('#add-form-location').val();
	var type=$('#add-form-type').val();
	var colors=$('#add-form-colors').val();
	var dimensions=$(this).data('dimensions');
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_customization':'true','component':component,'location':location,'type':type,'colors':colors,'dimensions':dimensions,'hidea_id':hidea_id,'short_lang':js_short_lang},function(){
		$('#stricker-customization-add').removeClass('disabled');
	});
});

$(document).on("click", "#stricker-customization-add", function() {
	if($(this).hasClass('disabled')){
		if (js_short_lang=='gr'){
			alert('Δεν έχετε επιλέξει διαστάσεις');
		} else {
			alert('Please select dimensions');
		}
	} else {
		if($(window).width()<993) $('html, body').animate({scrollTop: $(".purchase-block").offset().top-$(window).height()/4}, 300);
		var customization_id=$('#customization_id').val();
		$('#purchase-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_add_customization':'true','customization_id':customization_id, 'short_lang':js_short_lang});
	}
});

$(document).on("click", ".stricker-customization-remove", function() {
	var customization_id=$(this).data('customization_id');
	$('#purchase-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_remove_customization':'true','customization_id':customization_id,'short_lang':js_short_lang});
});

$(document).on("click", ".stricker-customization-fpd-launch", function() {
	var customization_id=$(this).data('customization_id');
	$('#stricker-customization-fpd-response').load('https://aldigron.gr/scripts/ajax.php', {'stricker_customization_fpd':'true','customization_id':customization_id,'short_lang':js_short_lang}, function() {
		$("#stricker-customization-fpd-response").fadeIn(200);
		//Fancybox.show([{ src: "#stricker-customization-fpd-response", type: "inline" }]);
		var $yourDesigner = $('#fancy-designer'),
		pluginOpts = {
			langJSON: fpd_path+'lang/'+js_short_lang+'.json',
			templatesDirectory: fpd_path+'html/',
			stageWidth: $('#fancy-designer').data('fpd_width'),
			stageHeight: $('#fancy-designer').data('fpd_height'),
			mainBarModules :['images','text'],
			editorMode: true,
			allowedImageTypes:['png', 'svg', 'pdf'],
			improvedResizeQuality: true,
			//productsJSON:products,
			fonts: [
				{name: 'Times New Roman'},
				{name: 'Arial'},
				//{name: 'Open Sans',  url: '/scripts/fancy_product_designer/fonts/OpenSans-Regular.ttf'},
				{name: 'EB Garamond',  url: '/scripts/fancy_product_designer/fonts/EBGaramond-Regular.ttf'},
				{name: 'Play',  url: '/scripts/fancy_product_designer/fonts/Play-Regular.ttf'},
				{name: 'Nova Mono',  url: '/scripts/fancy_product_designer/fonts/NovaMono.ttf'},
				{name: 'Cousine',  url: '/scripts/fancy_product_designer/fonts/Cousine-Regular.ttf'},
				{name: 'Advent Pro',  url: '/scripts/fancy_product_designer/fonts/AdventPro-Regular.ttf'},
				{name: 'Alegreya',  url: '/scripts/fancy_product_designer/fonts/Alegreya-Regular.ttf'},
				{name: 'Comfortaa',  url: '/scripts/fancy_product_designer/fonts/Comfortaa-Regular.ttf'},

			],
			customTextParameters: {
				colors: true,
				removable: true,
				resizable: true,
				draggable: true,
				rotatable: true,
				autoCenter: true,
				boundingBox: "Base"
			},
			customImageParameters: {
				draggable: true,
				removable: true,
				resizable: true,
				rotatable: true,
				colors: '#000',
				autoCenter: true,
				boundingBox: "Base"
			},
			//imageParameters: {
			//	resizeToW: 150
			//},
			actions:  {
				'bottom': ['undo','redo','reset-product','manage-layers'],
			}
		},

		yourDesigner = new FancyProductDesigner($yourDesigner, pluginOpts);
		$(document).on("click", "#fpd-preview-button", function() {
			yourDesigner.getProductDataURL(function(dataURL) {
				$('.design-image').css({"background-image": "url("+dataURL+")"});
			});
		});

		$(document).on("click", "#fpd-save-button", function() {
			yourDesigner.getProductDataURL(function(dataURL) {
				$('.design-image').css({"background-image": "url("+dataURL+")"});
				yourDesigner.getProductDataURL(function(dataURL) {
					$('#stricker_customization_baseurl_18').val(dataURL);
					$("#stricker-customization-fpd-response").fadeOut(200);
					$('#stricker-customization-fpd-response').html();
				});
			});
		});
  	});

	//var product=JSON.parse(localStorage.getItem("fpd_latest_product"));
	//if(product !="" ){
	//	yourDesigner.addView(product);
	//	yourDesigner.selectView(1);
	//	yourDesigner.addProduct(product);
	//	yourDesigner.selectProduct(1);
	//}
	//var products = new Object();
	//products = {[category:"default",products:{[localStorage.getItem("fpd_latest_product")]}]}
	//console.log(products);

});
/**************************************************************/

/************************************************************* GE DEMO */
$(document).on("click", ".ge-color-item", function() {
	$('.ge-color-item').removeClass('selected');
	$(this).addClass('selected');
	var ge_id=$('#ge_id').val();
	var color=$(this).data('color');
	$('#add-form-color').val(color);
	$('#optional-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_optional':'true','color':color,'ge_id':ge_id,'short_lang':js_short_lang},function(){
		if($('#optional_quantity_output').length==0){
			$('#ge-optional-add').addClass('disabled');
		} else {
			$('#ge-optional-add').removeClass('disabled');
		}
		if($('.ge-size-item ').length){
			$('#ge-optional-add').addClass('disabled');
		}
	});
});

$(document).on("click", ".ge-size-item", function() {
	var ge_id=$('#ge_id').val();
	var color=$('#add-form-color').val();
	var size=$(this).data('size');
	$('#optional-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_optional':'true','color':color,'ge_id':ge_id,'size':size,'short_lang':js_short_lang},function(){
		if($('#optional_quantity_output').length==0){
			$('#ge-optional-add').addClass('disabled');
		} else {
			$('#ge-optional-add').removeClass('disabled');
		}
		if($('.ge-size-item ').length){
			$('#ge-optional-add').removeClass('disabled');
		}
	});
});

$(document).on("click", "#ge-optional-add", function() {
	if($('#optional_quantity_output').length==0){
		if (js_short_lang=='gr'){
			alert('Δεν υπάρχει διαθεσιμότητα');
		} else {
			alert('No products available');
		}
	} else if($(this).hasClass('disabled')){
		if (js_short_lang=='gr'){
			alert('Δεν έχετε επιλέξει μέγεθος');
		} else {
			alert('Please select size');
		}
	} else {
		var optional_id=$('#optional_id').val();
		var optional_qty=$('#optional_quantity_output').val();
		if($(window).width()<993) $('html, body').animate({scrollTop: $(".customization-selector").offset().top-$(window).height()/4}, 300);
		var optional_qty=$('#optional_quantity_output').val();
		$('#purchase-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_add_optional':'true','optional_id':optional_id, 'optional_qty':optional_qty,'short_lang':js_short_lang},function(){
			$('.customization-selector').removeClass('disabled');
		});
	}
});

$(document).on("click", ".ge-optional-remove", function() {
	var optional_id=$(this).data('optional_id');
	$('#purchase-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_remove_optional':'true','optional_id':optional_id,'short_lang':js_short_lang},function(){
		if(!$('.purchase-optional-row').length){
			$('.customization-selector').addClass('disabled');
		}
	});
});

$(document).on("click", ".ge-location-item", function() {
	var ge_id=$('#ge_id').val();
	var location=$(this).data('location');
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_customization':'true','location':location,'ge_id':ge_id,'short_lang':js_short_lang},function(){
		$('#ge-customization-add').addClass('disabled');
	});
});

$(document).on("click", ".ge-type-item", function() {
	var ge_id=$('#ge_id').val();
	var location=$('#add-form-location').val();
	var type=$(this).data('type');
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_customization':'true','location':location,'type':type,'ge_id':ge_id,'short_lang':js_short_lang},function(){
		$('#ge-customization-add').addClass('disabled');
	});
});
$(document).on("click", ".ge-colors-item", function() {
	var ge_id=$('#ge_id').val();
	var location=$('#add-form-location').val();
	var type=$('#add-form-type').val();
	var colors=$(this).data('colors');
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_customization':'true','location':location,'type':type,'colors':colors,'ge_id':ge_id,'short_lang':js_short_lang},function(){
		$('#ge-customization-add').addClass('disabled');
	});
});
$(document).on("click", ".ge-dimensions-item", function() {
	var ge_id=$('#ge_id').val();
	var location=$('#add-form-location').val();
	var type=$('#add-form-type').val();
	var colors=$('#add-form-colors').val();
	var dimensions=$(this).data('dimensions');
	$('#customization-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_customization':'true','location':location,'type':type,'colors':colors,'dimensions':dimensions,'ge_id':ge_id,'short_lang':js_short_lang},function(){
		$('#ge-customization-add').removeClass('disabled');
	});
});

$(document).on("click", "#ge-customization-add", function() {
	if($(this).hasClass('disabled')){
		if (js_short_lang=='gr'){
			alert('Δεν έχετε επιλέξει διαστάσεις');
		} else {
			alert('Please select dimensions');
		}
	} else {
		if($(window).width()<993) $('html, body').animate({scrollTop: $(".purchase-block").offset().top-$(window).height()/4}, 300);
		var customization_id=$('#customization_id').val();
		$('#purchase-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_add_customization':'true','customization_id':customization_id, 'short_lang':js_short_lang});
	}
});

$(document).on("click", ".ge-customization-remove", function() {
	var customization_id=$(this).data('customization_id');
	$('#purchase-ajax-response').load('https://aldigron.gr/scripts/ajax.php', {'ge_stricker_remove_customization':'true','customization_id':customization_id,'short_lang':js_short_lang});
});


if ($('.tab-content').length>0) {
	$('.tab-content').hide();
}
/************************************************************* DOCUMENT READY END */
});

function create_new_item(short_lang,form_name){
	if (js_short_lang=='gr'){
		var lang_error = "Υπήρξε σφάλμα στο ανέβασμα του αρχείου σας. Παρακαλούμε επικοινωνήστε με την υποστήριξη";
		var lang_mcr = "Η επισύναψη αρχείου είναι υποχρεωτική λόγω των επιλογών που έχετε κάνει";
		var lang_submit = "Επόμενο";
	}else {
		var lang_error = "An error occured during your file upload. Please contact Technical Support";
		var lang_mcr = "Attaching a file is required according to your choices";
		var lang_submit = "Next";
	}
	if(validate(short_lang,form_name)!== false){
		//Validate file wtih own creative
		if($('*[data-codes="mcr"]').is(':checked') && $('#global_file').get(0).files.length === 0){
			alert(lang_mcr);
			return false;
		} else {
			$('.eshop-submit').html('<img src="https://commons.utopia.gr/images/icons/preloaders/gallery_preloader.svg" alt="" />');
			var url = "https://aldigron.gr/scripts/ajax.php"; // the script where you handle the form input.
			var form = $('form[name=pivot-form]')[0]; // You need to use standard javascript object here
			var formData = new FormData(form);
			formData.append('short_lang', short_lang);
			$.ajax({
					type: "POST",
					url: url,
					data: formData,
					contentType: false,
					processData: false,
					success: function(data)
					{
					}
			}).done(function(response) {
				if(response=='error') {
					alert(lang_error);
				}
				$('.eshop-submit').html('<a class="button" href="javascript:;" onclick="return create_new_item(\'$short_lang\',\'pivot-form\')">'+lang_submit+'</a>');
				//$('form[name=pivot-form]')[0].reset();
				ucart_action(short_lang,'refresh',0);
				if(document.getElementById("add_cart_popup")){
					$("#add_cart_popup").fadeIn(200);
				}
			});
			//e.preventDefault(); // avoid to execute the actual submit of the form.
		}
	} else {
		return false;
	}
}

function hidea_color_add(){
	if (js_short_lang=='gr'){
		var lang_error = "Δεν έχετε επιλέξει κάποιο χρώμα ή/και μέγεθος.";
	}else {
		var lang_error = "You have not selected any color and/or size";
	}
	if(!($("input[name=hidea_color]:checked").length)){
		alert(lang_error);
	} else {
		var url = "https://aldigron.gr/scripts/ajax.php"; // the script where you handle the form input.
		var selected_color=$('input[name=hidea_color]:checked').val();
		var product_id=$('#input_product_id').val();
		var codes=$('#input_code').val();
		$("input[type=radio]:checked").each(function(){
			if($(this).data('codes')!=null && $(this).data('codes')!='') codes=codes+'-'+$(this).data('codes');
		});
		var count=parseInt($('#hidea-ajax-color-extras').attr('data-count'));
		count=count+1;

		var item={hidea_color_add:1,short_lang:js_short_lang,selected_color:selected_color,product_id:product_id,codes:codes,count:count};
		var form_data = new FormData();
		for (var key in item){
			form_data.append(key, item[key]);
		}

		$.ajax({
			type: "POST",
			url: url,
			data: form_data,
			contentType: false,
			processData: false,
			success: function(data)
			{
				var color_content=$('input[name=hidea_color]:checked').closest('.show-hide-content.hidea.hidea-color');
				var color_showhide=$('input[name=hidea_color]:checked').closest('.show-hide.hidea.hidea-color');
				$('input[name=hidea_color]:checked').parent().remove();
				if(color_content.text().length<10){
					color_showhide.remove();
				}
				$("#hidea-ajax-color-extras").append(data);
				$('#hidea-ajax-color-extras').attr('data-count',count);
				if($("input[name=hidea_color]:first").length){
					//$(".show-hide-head.hidea.hidea-color:first").trigger('click');
					//$("input[name=hidea_color]:first").trigger('click');
				} else {
					$("#hidea_color-fieldset").hide();
					$("#hidea-color-buttons a:first").hide();
				}
				refresh_hidea_price();
				$('html, body').animate({scrollTop: $(".hidea-info").offset().top-$(window).height()/2}, 300);
			}
		})
	}
}

function hidea_color_next(){
	if (js_short_lang=='gr'){
		var lang_error = "Προσθέστε τουλάχιστον μία ποσότητα";
	}else {
		var lang_error = "Add at least one quantity";
	}
	var count=parseInt($('#hidea-ajax-color-extras').attr('data-count'));
	if(count<=0){
		alert(lang_error);
	} else {
		$('html, body').animate({scrollTop: $(".hidea-form-product-title").offset().top+150}, 300);
		$('#hidea_color-fieldset').slideUp(300);
		$('#hidea-color-buttons').hide();
		$('.aldigron-hidea-print').slideDown(300);
		refresh_hidea_price();
	}
}

function hidea_print_add(){
	if (js_short_lang=='gr'){
		var lang_error = "Δεν έχετε επιλέξει κάποιο χρώμα ή/και μέγεθος.";
	}else {
		var lang_error = "You have not selected any color and/or size";
	}
	if(!($("input[name=hidea_print]:checked").length)){
		alert(lang_error);
	} else {
		var url = "https://aldigron.gr/scripts/ajax.php"; // the script where you handle the form input.
		var selected_color=$('input[name=hidea_print]:checked').val();
		var product_id=$('#input_product_id').val();
		var codes=$('#input_code').val()+'-all-'+$("input[name=hidea_print]:checked").data('codes');
		var count=parseInt($('#hidea-ajax-print-extras').attr('data-count'));
		count=count+1;
		if(count==1){
			$("#hidea-ajax-print-extras").html('');
		}

		var item={hidea_print_add:1,short_lang:js_short_lang,selected_color:selected_color,product_id:product_id,codes:codes,count:count};
		var form_data = new FormData();
		for (var key in item){
			form_data.append(key, item[key]);
		}

		$.ajax({
			type: "POST",
			url: url,
			data: form_data,
			contentType: false,
			processData: false,
			success: function(data)
			{
				var slug=$('input[name=hidea_print]:checked').attr('data-location');
				$('.loc-'+slug).remove();
				$("#hidea-ajax-print-extras").append(data);
				$('#hidea-ajax-print-extras').attr('data-count',count);
				if($("input[name=hidea_print]:first").length){
					//$(".show-hide-head.hidea.hidea-print:first").trigger('click');
					//$("input[name=hidea_print]:first").trigger('click');
				} else {
					$("#hidea_print-fieldset").hide();
					$("#hidea-print-buttons a:first").hide();
				}
				$('html, body').animate({scrollTop: $("#hidea-ajax-print-extras").offset().top-$(window).height()/2}, 300);
				refresh_hidea_price();
			}
		});
	}
}


function hidea_print_next(){
	if (js_short_lang=='gr'){
		var lang_error = "Θέλετε να συνεχίσετε χωρίς εκτύπωση;";
	}else {
		var lang_error = "Do you wish to contintue without printing option";
	}
	var count=parseInt($('#hidea-ajax-print-extras').attr('data-count'));
	if(count<=0){
		if(confirm(lang_error)){
			$('html, body').animate({scrollTop: $(".hidea-form-product-title").offset().top+150}, 300);
			$('#hidea_print-fieldset').slideUp(300);
			$('#hidea-print-buttons').hide();
			$('.aldigron-hidea-final').slideDown(300);
			refresh_hidea_price();
		}
	} else {
		$('html, body').animate({scrollTop: $(".hidea-form-product-title").offset().top+150}, 300);
		$('#hidea_print-fieldset').slideUp(300);
		$('#hidea-print-buttons').hide();
		$('.aldigron-hidea-final').slideDown(300);
		refresh_hidea_price();
	}
}

function refresh_hidea_price(){

	if (js_short_lang=='gr'){
		var lang_pieces = " τεμάχια";
		var lang_piece = " τεμάχιο";
		var lang_perpiece = "ανά τεμ.";
	}else {
		var lang_pieces = " pieces";
		var lang_piece = " piece";
		var lang_perpiece = "per unt";
	}

	var selected_quantity = 0;
	$('.pivot-range-input').each(function() {
		var this_quantity=this.value.replace(/[^\d\.\-]/g,'');
		selected_quantity=selected_quantity+parseFloat(this_quantity.replace(',','.'));
	});

	var item_price=$('#hidea-ajax-print-extras').attr('data-item_price');
	var current_price_float=parseFloat(item_price.replace(',','.'));

	var hidea_extra_price=0
	var i=1;
	while ($('.hidea-perpiece-prices-'+i).length) {
		//console.log(i);
		var previous_price=0;
		var previous_quantity=0;
		var this_current_price=0;
		var this_current_price_float=0;
		$('.hidea-perpiece-prices-'+i).each(function() {
			if(selected_quantity>=previous_quantity && selected_quantity<$(this).data('quantity')) {
				this_current_price=$(this).data('price');
			}
			previous_quantity=$(this).data('quantity');
			previous_price=$(this).data('price');
		});
		if(selected_quantity>=previous_quantity){
			this_current_price=previous_price;
		}
		this_current_price_float=parseFloat(this_current_price.replace(',','.'))-item_price;
		current_price_float=current_price_float+this_current_price_float;
		i=i+1;
	}

	var price_total=parseFloat(selected_quantity) * current_price_float;
	if(selected_quantity==1) lang_pieces=lang_piece;
	var profit=1.45;
	if(price_total>0 && selected_quantity>1) {
		if(price_total<=60){
			profit=2;
		} else if(price_total<=100){
			profit=1.9;
		} else if(price_total<=200){
			profit=1.8;
		} else if(price_total<=300){
			profit=1.75;
		} else if(price_total<=400){
			profit=1.7;
		} else if(price_total<=800){
			profit=1.65;
		}else if(price_total<=1500){
			profit=1.6;
		}else if(price_total<=2000){
			profit=1.55;
		}else if(price_total<=2500){
			profit=1.5;
		}
		price_total=price_total*profit;
		perpiece_price=price_total/selected_quantity;
		var price_per_piece_tag="<div id=\"price-perpiece-box\">"+perpiece_price.toFixed(2).toString().replace('.',',')+" €<br />"+lang_perpiece+"</div>\n";;
	} else {
		price_total=price_total*2;
		var price_per_piece_tag="";
	}
	$('#hidea-price').html("<div class=\"total-price\"><span class=\"total-price-quantity\">"+selected_quantity+lang_pieces+":</span> <span class=\"total-price-actual\">"+price_total.toFixed(2).toString().replace('.',',')+" €</span>"+price_per_piece_tag+"</div></div><input type=\"hidden\" name=\"price\" id=\"price\" value=\""+selected_quantity+"|"+price_total.toFixed(2)+"\" />\n");
}


(function (jQuery) {
// We'll use this to cache the progress bar node
var pbar, pinfogr, pinfoen, info_html_gr, info_html_en, pmsggr, pmsgen, upload_msg_gr, upload_msg_en, progress;
var ajax_icon=' <img src="https://commons.utopia.gr/images/icons/ajax_dark.gif" alt="" />';
// This flag determines if the upload has started
var started = false;

jQuery(function () {
// Start progress tracking when the form is submitted
jQuery('#captchaform').submit(function() {

// Hide the form
// jQuery('#upload-form').hide();
// Cache the progress bar
pbar = jQuery('#progress-bar');
pinfogr = jQuery('#progress-info-gr');
pinfoen = jQuery('#progress-info-en');
pmsggr = jQuery('#progress-msg-gr');
pmsgen = jQuery('#progress-msg-en');
// Show the progress bar
pbar.progressbar();
// Initialize the jQuery UI plugin
//if (progress != 999) {pbar.progressbar();}
//pinfogr.show();
//pinfoen.show();

// We know the upload is complete when the frame loads
jQuery('#upload-frame').load(function () {
// This is to prevent infinite loop
// in case the upload is too fast
started = true;
// Do whatever you want when upload is complete
if (progress!=999) {upload_msg_gr="Επιτυχής αποστολή! Ενημερωτικό μήνυμα έχει σταλεί στο email σας."; upload_msg_en="Successfull upload! A notification has been sent to your email."; document.getElementById('captchaform').reset();}
else {upload_msg_gr="Πρόβλημα με τον τύπο ή το μέγεθος του αρχείου. Η αποστολή ΔΕΝ ολοκληρώθηκε."; upload_msg_en="File type or file size error. The upload was NOT completed.";}
pmsggr.html(upload_msg_gr).show();
pmsgen.html(upload_msg_en).show();

//pbar.fadeOut(13000);
//pinfogr.fadeOut(13000);
//pinfoen.fadeOut(13000);
//pmsggr.fadeOut(13000);
//pmsgen.fadeOut(13000);
pbar.delay(20000).slideUp(600);
pinfogr.delay(20000).slideUp(600);
pinfoen.delay(20000).slideUp(600);
pmsggr.delay(20000).slideUp(600);
pmsgen.delay(20000).slideUp(600);
jQuery('#loading-overlay').delay(2000).hide();

setTimeout(function(){started=false;}, 13100);
});

// Start updating progress after a 1 second delay
setTimeout(function () {
// We pass the upload identifier to our function
updateProgress(jQuery('#uid').val());
}, 1000);
});
});

function updateProgress(id) {
var time = new Date().getTime();
// Make a GET request to the server
// Pass our upload identifier as a parameter
// Also pass current time to prevent caching
jQuery.get('/scripts/ajax.php', { uid: id, t: time }, function (data) {
// Get the output as an integer
progress = parseInt(data, 10);
if (progress!=999 && (progress < 100 || !started)) {
// Determine if upload has started
started = progress < 100;
// If we aren't done or started, update again
updateProgress(id);
}
// Update the progress bar percentage
// But only if we have started
if (progress!=999) {pbar.css('height','2em'); info_html_gr='Ποσοστό που έχει μεταφερθεί: '+progress+'%'; info_html_en='Percentage uploaded: '+progress+'%';}
else {started=true; pbar.css('height',0); info_html_gr='<span class="red">Πρόβλημα κατά τη μεταφορά. Παρακαλώ περιμένετε.</span>'+ajax_icon; info_html_en='<span class="red">Problem during upload. Please wait.</span>'+ajax_icon;}
started && pbar.show().progressbar('value', progress) && pinfogr.html(info_html_gr).show() && pinfoen.html(info_html_en).show();
});
}
}(jQuery));

function initiate_flipbook(){
	var width=$('#flipbook-options').data('width')*2;
	var height=$('#flipbook-options').data('height');
	var aspect_ratio=width/height;
	var screenw=window.innerWidth;
	var screenh=window.innerHeight;
	if(screenw<width){
		var set_width=screenw-50;
		var set_height=screenw/aspect_ratio-23;
	} else {
		var set_width=width;
		var set_height=height-23;
	}
	$('.flipbook').booklet({
		 width:set_width,
		 height:set_height,
		 closed: true,
		 autoCenter: true,
		 overlays: true,
		 manual: false,
		 next: '#custom-next',
         prev: '#custom-prev',
         easing:  'easeInOutElastic',
         easeIn:  'easeInElastic',
         easeOut: 'easeOutElastic',
		 pagePadding: 0,
	});
}

$(window).load(function () {
    $(".button-approval").click(function(){
       $('#mockup_popup').show();
    });
    $('#mockup_popup').click(function(){
        $('#mockup_popup').hide();
    });
    $('.mockup_popup_closebutton').click(function(){
        $('#mockup_popup').hide();
    });
});

if($( "#search_input" ).length){
	$( function() {
		var cache = {};
		$( "#search_input" ).autocomplete({
		  select: function( event, ui ) {
			$("#search_input").val(ui.item.id);
			$("#search_form").submit();
		  },
		  minLength: 2,
		  source: function( request, response ) {
			var term = request.term;
			if ( term in cache ) {
			  response( cache[ term ] );
			  return;
			}
			$.getJSON( "/scripts/ajax.php", { term: term, short_lang: js_short_lang }, function( data, status, xhr ) {
			  cache[ term ] = data;
			  response( data );
			});
			}
		}).data("uiAutocomplete")._renderItem = function (ul, item) {
			return $("<li />")
				.data("item.autocomplete", item)
				.append("<a href='"+ item.url +"'><table class=\"search-table\"><tr><td><div class=\"search-thumb\" style=\"background-image:url('" + item.icon + "')\"></div></td><td><div class=\"search-label\">" + item.label +  item.hidea_id +"</div><div class=\"search-category\">" + item.category + "</div></td></tr></a>")
				.appendTo(ul);
		};
	});
}

function setCookie(cname, cvalue, exdays) {
  const d = new Date();
  d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  let expires = "expires="+d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
  let name = cname + "=";
  let ca = document.cookie.split(';');
  for(let i = 0; i < ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}
