function addToList(objectId, listType, positionType, itemId) {
	$.ajax({
			url: shop.baseUrl+"addToList",
			data: ({objectId: objectId, listType: listType, positionType: positionType.toLowerCase(), itemId: itemId}),
			cache: false,
			success: function( data ) {
				if (data.length > 0) {
					$('#action_'+listType+' .product_line').prepend(data);
					if ('1' == listType) {
						var count = parseInt($('#wishlist_count').html().substring(1,2))+1;
						$('#wishlist_count').html('('+count+')');
					}
				}
				AtHome.Actionbox.add_to_actionbox(listType);
			}
	});
}

function removeFromList(objectId, listType, positionType, actionBoxRemove) {
	$.ajax({
		url: shop.baseUrl+"listRemove",
		data: ({objectId: objectId, listType: listType, positionType: positionType.toLowerCase()}),
		cache: false,
		success: function () {
			var count;
			var updateType = 0;
			var updateTarget = "";
			if ($('#wishlist_content').size() > 0) {
				updateType = 1;
				updateTarget = '#wishlist_content';
			} else if ($('#product_compare_content').size() > 0) {
				updateType = 2;
				updateTarget = '#product_compare_content';
			} else if ($('#styleeditor_content').size() > 0) {
				updateType = 3;
				updateTarget = '#styleeditor_content';
			}
			// Für den Style-Editor gibt es (noch) keine Frames
			if ('3' != listType) {
				reloadFrames();
			}
			if (updateType == listType) {
				if (true != actionBoxRemove) {
					updateActionboxContent(updateType);
				} else {
					updatePage(updateType, updateTarget);
				}
				if ($('#article_count').size() > 0) {
					count = parseInt($('#article_count').html())-1;
					$('#article_count').html(count);
				}
			}
			if ('1' == listType) {
				count = parseInt($('#wishlist_count').html().substring(1,2))-1;
				$('#wishlist_count').html('('+count+')');
			}
		}
	});
	return false;
}

function clearList(listType) {
	$.ajax({
		url: shop.baseUrl+"listClear",
		data: ({listType: listType}),
		cache: false,
		success: function() {
			reloadFrames();
			updateActionboxContent(listType);
			$('#article_count').html(0);
			if ('1' == listType)
				$('#memo .normal').html('(0)');
		}
	});
}


function recommendProduct(objectId,actionId) {
	$('#content_thickbox_recommend').attr('src',actionId+'?objectId='+objectId);
	$('#content_thickbox_recommend').attr('href',actionId+'/recommend?objectId='+objectId);
	$('#content_thickbox_recommend').reload();
	return true;
}

function recommendProductADS(objectId,actionId){
  if($('#itemId').size() == 1){
    objectId = $('#itemId').val();
  }
  $('#content_thickbox_recommend').attr('src',actionId+'?objectId='+objectId);
  $('#content_thickbox_recommend').attr('href',actionId+'/recommend?objectId='+objectId);
  $('#content_thickbox_recommend').reload();
  return true;
}

function reloadFrames() {
	top.print_view_frame_01.location.reload();
	top.print_view_frame_02.location.reload();
}

function showAdvise(itemId,productId) {
  var productId = $("#productId").val();
  $('#content_thickbox_advise').attr('src',shop.baseUrl+'showAdvise?itemId=' + itemId + '&productId=' + productId);
  $('#content_thickbox_advise').attr('href',shop.baseUrl+'showAdvise?itemId=' + itemId + '&productId=' + productId);
  $('#content_thickbox_advise').reload();
  return true;
}

function closeThickbox() {
  parent.document.location="product/5156639?categoryName=wohnen-schlafsofas&itemId=4007082557";
}

function preparePrintView(itemID, infoString) {
  AtHome.ProductDetail.PrintView.openPrintView(itemID, infoString);
}

function updatePage(listType, target) {
	$.ajax({
		url: shop.baseUrl+"listContent",
		data: ({listType: listType}),
		cache: false,
		success: function(data) {
			$(target).html(data);
		}
	});
}

function updateActionboxContent(type) {
	$.ajax({
		url: shop.baseUrl+"actionboxContent",
		data: ({type: type}),
		cache: false,
		success: function(data) {
			$('#action_'+type).html(data);
		}
	});
}

function rateReview(reviewId, helpfull, productId){
  $.ajax({
    url: shop.baseUrl+"productdetail/rateReview",
    data: "reviewId="+reviewId+"&helpfull="+helpfull+"&productId="+productId,
    success: function(data) {
      $('#clientVoting_'+reviewId).html(data);
    }
  });
}

function closeThickbox(tbId , contentId,formId, targetId, buttonId){
  Common.Thickbox.closeThickbox($('#'+tbId) , $('#'+contentId) , true , false );
  var src = $('#'+contentId).attr('src');
  $('#'+contentId).attr('src',src);
  $('#'+buttonId).html("<button id='"+buttonId+"' class='btn_function' onclick='shopAction.submitRecommendForm(\""+formId+"\",\""+contentId +"\",\""+ targetId+"\",\""+ tbId+"\,\""+ buttonId+"\")'><span>NACHRICHT SENDEN</span></button>");
}

function closeMaterialOrderBox(tbId, contentId){
  Common.Thickbox.closeThickbox($('#'+tbId) , $('#'+contentId) , true , false );
}

function changeMaterialInfo(coverName, colorName, productId, fabricSample, index){
  $.ajax({
    url: shop.baseUrl+"materialInfo/change",
    data: "coverName="+coverName+"&colorName="+colorName+"&productId="+productId+"&fabricSample="+fabricSample+"&index="+index,
    success: function(data) {
      $('#material_info_div').html(data);
    }
  });
}


function exitFromEditStyle() {
  Common.Thickbox.closeThickbox($('#xxl_thickbox_TBinner') , $('#content_thickbox_style_editor') , true , false );
}

function redirectAfterEditStyle() {
  exitFromEditStyle();
}
