function Submit_Button(formName) {
	$(formName).submit();
}

// zarovnani objektu na stred
$.fn.vAlign = function() {
	return this.each(function(i){
	var h = $(this).height();
	var oh = $(this).outerHeight();
	var mt = (h + (oh - h)) / 2;	
	$(this).css("margin-top", "-" + mt + "px");	
	$(this).css("top", "50%");
	$(this).css("position", "absolute");	
	});	
};
$.fn.hAlign = function() {
	return this.each(function(i){
	var w = $(this).width();
	var ow = $(this).outerWidth();	
	var ml = (w + (ow - w)) / 2;	
	$(this).css("margin-left", "-" + ml + "px");
	$(this).css("left", "50%");
	$(this).css("position", "absolute");
	});
};

function add2cart(object) {
	var pro_id = $(object).attr("id");
	var pcf = "pcf_"+pro_id;

	var count = $("#proId"+pro_id).find("#"+pcf).val();
	if (count == undefined) {count = 1};
	var data = 'action=addtocart&'+pcf+'='+count;
	
 	$.ajax({
	  type: 'POST',
	  url: '/inshop/scripts/shop.aspx',
      beforeSend : function() {
	  	$(".product-list-container").addAjaxLoadScreen({show:true});
	  },
	  data: data,
	  success: function() {
		add2cartCatalogAnimation(pro_id);
	  },
	 complete: function(jqXHR, textStatus) {
	  	$(".product-list-container").addAjaxLoadScreen({hide:true});
			if (textStatus != 'success') {
			alert(textStatus);
			};
	  }
	});	
	
	
}
	
function addProduct2Cart() {
	$.ajax({
	  type: 'POST',
	  url: '/inshop/scripts/shop.aspx',
	  beforeSend : function() {
	  	
	  },
	  data: $(".FormaddProduct2Cart").serialize()+'&action=addtocart',
	  success: function() {
		add2CartProductAnimation();
	  },
	  complete: function(jqXHR, textStatus) {
	  	
	  }	
	});

}


function add2compare(link) {
	$.ajax({
	  url: link,
	  beforeSend : function() {
	  	$(".product-list-container").addAjaxLoadScreen({show:true});
	  },
	  success: function() {
		CallCompareUpdade();
	  },
   		complete : function(jqXHR, textStatus) {
	  	$(".product-list-container").addAjaxLoadScreen({hide:true});
		if (textStatus == 'success') {
			$.scrollTo(".block-container.Compare", 2000);
			alert("Zboží bylo přidáno do seznamu pro porovnání.");
		}
		else{alert(textStatus);}
		
	  }
	});
}

function CallCompareUpdade() {
	$(".block-container.Compare").addAjaxLoadScreen({show:true});
	$('.compare-sidebar').load('/inshop/scripts/shop.aspx?action=ViewTemplate&Path=/inshop/Layout/Templates/Robin/Blocks/AjaxCompare&IncludeLayout=0&LayoutNotIncluded=1');
}

function CallCartUpdate() {
	$(".block-container.Cart").addAjaxLoadScreen({show:true});
	$('.shopping-cart-container').load('/inshop/scripts/shop.aspx?action=ViewTemplate&Path=AjaxHeaderCart&IncludeLayout=0&LayoutNotIncluded=1');
	$(".card-sidebar").load('/inshop/scripts/shop.aspx?action=ViewTemplate&Path=/inshop/Layout/Templates/Robin/Blocks/CartAjax&IncludeLayout=0&LayoutNotIncluded=1');
}

function add2CartProductAnimation() {
	var cart  = $('ul.cart-navi').offset();
	var imgThumb = $(".product-thumbnail img");
	var imgPostion = imgThumb.offset();
	var imageSrc = imgThumb.attr("src");
	imgThumb.before('<img src="' + imageSrc+ '" id="temp" style="position: absolute; top: ' + imgPostion.top + 'px; left: ' + imgPostion.left + 'px;" />');
	
	params = {
				top : cart.top + 'px',
				left : cart.left + 'px',
				opacity : 0.0,
				width : $('ul.cart-navi').width(),  
				height : $('ul.cart-navi').height()
			};      


    $('#temp').animate(params, 'slow', false, function () {
		CallCartUpdate();
		$('#temp').remove();
    });
	
}


function add2cartCatalogAnimation(Id) {
	var proId = '#proId'+Id;
	var cart  = $('ul.cart-navi').offset();
	var imgThumb = $(proId).find(".thumb img");
	var imgPostion = imgThumb.offset();
	var imageSrc = imgThumb.attr("src");
	imgThumb.before('<img src="' + imageSrc+ '" id="temp" style="position: absolute; top: ' + imgPostion.top + 'px; left: ' + imgPostion.left + 'px;" />');
	
	params = {
				top : cart.top + 'px',
				left : cart.left + 'px',
				opacity : 0.0,
				width : $('ul.cart-navi').width(),  
				height : $('ul.cart-navi').height()
			};      


    $('#temp').animate(params, 'slow', false, function () {
		CallCartUpdate();
		$('#temp').remove();
    });

	
}



function ShowLoading(option) {
	var width = $(".ajax-loading").parent().width();
	var height = $(".ajax-loading").parent().height();
	var position = $(".ajax-loading").parent().offset();
	$(".ajax-loading").css({'width':width, 'height':height, 'top':position.top, 'left':position.left});
	
	if (option == 'show') {$(".ajax-loading").show();}
	else{$(".ajax-loading").hide();}
	
}

function Equeal_Height(source,class_name) {
	var height = 0;
	var	max_height = 0;
	$(source).find(class_name).each(function() {
		height = $(this).height();
		if (height > max_height) { max_height = height};
	});
	$(source).find(class_name).css("height", max_height);
}

$.fn.ValidationRequired = function() {
	var args = arguments[0] || {};
	// zjistuji zda je cover div "block" nebo "none"
	var display_option = $(this).css("display");
		if (display_option == 'none') {
			$(this).find(".required").toggleClass("willrequired required");
		}
		else{
			$(this).find(".willrequired").toggleClass("willrequired required");
		};
	
}
