// JavaScript Document
function afterAddToCart(responseText) {
	var pageHeight = $(document).height();
	$('body').append('<div id=\"add-to-cart-bg\" style=\"min-height: '+pageHeight+'px;\"></div><div id="add-to-cart-message">'+responseText+'</div>');
	$.ajax({
	    type: "POST",
	    url: PROJECT_ROOT+"/trilobit/moduly/orders/actions/updateCartInfo.php",
	    success: function(responseText){
	        $('#cartDetails').html(responseText);
	    }
	});
}
function showTradeTerms(id_article,e) {
	$.ajax({
	    type: "POST",
	    url: PROJECT_ROOT+"/trilobit/moduly/orders/actions/getTradeTerms.php",
	    data: {'id_article':id_article},
	    success: function(responseText){
	        if($('body').find('#tradeTerms').length==0)	{
	        	var pageHeight = $(document).height();
	        	$('body').append('<div id="tradeTermsBg" style=\"min-height: '+pageHeight+'px;\"></div>');
	        	$('body').append('<div id="tradeTerms"><div class=\"innerBox\">'+responseText+'</div></div>');	
			}
			if($('body').find('#tradeTerms').length>0 || $('body').find('#tradeTermsBg').length>0)	{
		        $(document).keydown(function(e) { 
				    var charCode = (e.which) ? e.which : e.charCode
      				if(charCode == 27) {
				        $('#tradeTerms').remove();
				        $('#tradeTermsBg').remove();				        
				        $(document).unbind('keypress');
				    }
				});
			}			
	    }
	});	
}
function afterRate(responseText) {
	alert(responseText);
}
function afterInsertComment(responseText) {
 if(responseText=='false') {
			showMessage("error", "Došlo k chybě při vkládání příspěvku! Zkontrolujte prosím, zda máte správně vyplněny všechny údaje.", 1);
	}else{
		showMessage("event", "Příspěvek byl úspěšně vložen.", 1);
		//$("#katalog-comments").prepend(responseText);
		var id_produktu = $('input#comment_id_produktu').attr('value');
		var woID = $('input#woID').attr('value');
		var back_uri = $('input#back_uri').attr('value');
		$("#katalogCommentsListDiv").load(PROJECT_ROOT+'/trilobit/moduly/katalog/webCommentsList.php?detail_produktu='+id_produktu+'&ajax=1&woID='+woID+'&back_uri='+back_uri);
		$("form#comment_form").resetForm();
	}
	$('img#scimg-commentSecure').attr('src', PROJECT_ROOT+'/sys/securimage/securimage_show.php?sid=' + Math.random());
}

$(document).ready(function()	{
	// js pro detail produktu
	$('.zmenit-variantu-button').hide();
	$('#id_varianty').change(function() {
			var id_varianty = $('#id_varianty').attr('value');
			var detail_produktu = $('input#detail_produktu').attr('value');
			location.href = '?id_varianty='+id_varianty;
	});
	
	$('#rate-button').hide();
	$caption = $("<span/>");
	$("#rate_form").stars({
  	inputType: "select",
  	oneVoteOnly: true,
  	captionEl: $caption,
		callback: function(ui, type, value)
		{
			var id_produktu_rate = $('input#id_produktu_rate').attr('value');
			$.post(PROJECT_ROOT+"/trilobit/moduly/katalog/actions/rateItem.php", {rate: value, id_produktu_rate: id_produktu_rate,ajax: 1}, function(data)
			{
				$("#ajax_response").html(data);
			});
		}
  });
  $caption.appendTo("#rate_form");      
});

			

