function showShopLightBox() {
	document.getElementById("panel").style.display = 'block';
	document.getElementById("panel-content").style.display = 'block';
	window.scrollTo(0,0);
	if(document.getElementById("sizeSelect")) {
		document.getElementById("sizeSelect").style.display = "none";
	}

	for (var i=0; i < document.getElementsByTagName("select").length; i++)	{
		if(document.getElementsByTagName("select")[i]) {
			document.getElementsByTagName("select")[i].style.display = "none";
		}
	}

}

function setLightBoxSize() {
	if(document.getElementById("panel-inside").offsetHeight+70 > document.body.offsetHeight) {
		if(document.getElementById("body-holder").offsetHeight > document.getElementById("panel-inside").offsetHeight) {
			document.getElementById("panel-container").style.height = document.getElementById("body-holder").offsetHeight + "px";
		} else {
			document.getElementById("panel-container").style.height = document.getElementById("panel-inside").offsetHeight + 70 + "px";
		}
	} else {
		if(document.getElementById("body-holder").offsetHeight > document.body.offsetHeight) {
			document.getElementById("panel-container").style.height = document.getElementById("body-holder").offsetHeight + "px";
		} else {
			document.getElementById("panel-container").style.height = document.body.offsetHeight + "px";
		}
	}
	Cufon.refresh();
}

function hidePanel() {
	document.getElementById("panel-content").style.display = 'none';
	document.getElementById("panel").style.display = 'none';
	if(document.getElementById("sizeSelect")) {
		document.getElementById("sizeSelect").style.display = "inline";
	}
	for (var i=0; i < document.getElementsByTagName("select").length; i++)	{
		if(document.getElementsByTagName("select")[i]) {
			document.getElementsByTagName("select")[i].style.display = "inline";
		}
	}
	$("#panel-inside").css("width", "600px");
}





function showPasswordReminder() {
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "action=ShowPasswordReminder&rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: "/app/order.do",
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			$("div#content-container").html(msg);
			setLightBoxSize();
		}
	});
	
	showShopLightBox();
}

function sendPasswordReminder() {
	var ajaxParams = jQuery("#formPasswordReminder").serialize() + "&rand=" + Math.floor(Math.random()*100000000);
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	jQuery.ajax({
		type: "POST",
		url: "/app/order.do",
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			$("div#content-container").html(msg);
			setLightBoxSize();
		}
	});
}

function showPage(ajaxUrl) {
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: ajaxUrl,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			$("div#content-container").html(msg);
			setLightBoxSize();
		}
	});
	
	showShopLightBox();
}

function sendNewShippingAddress(ajaxUrl) {
	var ajaxParams = jQuery("#regForm").serialize();
	jQuery("div#content-container").html("<img src=\"/images/common/loading.gif\" alt=\"\" style=\"margin: 100px auto; display: block;\" />");
	jQuery.ajax({
		type: "POST",
		cache: false,
		url: ajaxUrl,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			setLightBoxSize();
		}
	});
}

function sendUpdateShippingAddress(ajaxUrl) {
	var ajaxParams = jQuery("#regForm").serialize();
	jQuery("div#content-container").html("<img src=\"/images/common/loading.gif\" alt=\"\" style=\"margin: 100px auto; display: block;\" />");
	jQuery.ajax({
		type: "POST",
		cache: false,
		url: ajaxUrl,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			setLightBoxSize();
		}
	});
}

function sendDeleteShippingAddress(screenName) {
	var ajaxParams = jQuery("#regForm").serialize();
	jQuery("div#content-container").html("<img src=\"/images/common/loading.gif\" alt=\"\" style=\"margin: 100px auto; display: block;\" />");
	jQuery.ajax({
		type: "POST",
		cache: false,
		url: screenName,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			setLightBoxSize();
		}
	});
}

function loadColorAlternative(productId) {
	document.getElementById("pd-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/navigation.do?action=ShowColorAlternative&productId=' + productId,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			$(".tooltip2").hide();
			$("#pd-container").html(msg);
			MagicZoom.refresh();
			Cufon.refresh();
		}
	});
}

function addToShoppingCart(addForm) {
	var ajaxParams = jQuery("#addProductForm").serialize();
	jQuery("div#content-container").html("<img src=\"/images/common/loading.gif\" alt=\"\" style=\"margin: 100px auto; display: block;\" />");
	jQuery.ajax({
		type: "POST",
		cache: false,
		url: '/app/shopping_cart.do',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			updateHeaderCart();
			setLightBoxSize();
			$("#panel-inside").css("width", "600px");
		}
	});
	
	showShopLightBox();
}

function updateHeaderCart() {
	ajaxParams = "rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		cache: false,
		url: '/app/header_cart.do',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("#header-cart").html(msg);
			Cufon.refresh();
		}
	});
}

function showChangeProduct(ajaxUrl, ajaxParams) {
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "action=ShowChangeProduct&" + ajaxParams + "&rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: ajaxUrl,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			//document.getElementById("content-container").innerHTML = msg;
			setLightBoxSize();
		}
	});
	
	showShopLightBox();
}

function prepareChangeForm() {
	var fieldsName = "productId_" + document.getElementById("sizeSelect")[document.getElementById("sizeSelect").selectedIndex].value;
	document.getElementById(fieldsName).value = $("#overAmout").val();
}

function showPSFinder(ajaxParams) {
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "action=ShowPSFinder&" + ajaxParams + "&rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/order.do',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			//document.getElementById("content-container").innerHTML = msg;
			setLightBoxSize();
		}
	});
	
	showShopLightBox();	
}

function showTAF(productId) {
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/navigation.do?action=ShowTAFScreen&productId=' + productId,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			//document.getElementById("content-container").innerHTML = msg;
			setLightBoxSize();
			$("#panel-inside").css("width", "600px");
		}
	});
	
	showShopLightBox();
}

function submitTAF() {
	var ajaxParams = jQuery("#formTAF").serialize() + "&rand=" + Math.floor(Math.random()*100000000);
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	jQuery.ajax({
		type: "POST",
		url: "/app/navigation.do",
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			$("div#content-container").html(msg);
			setLightBoxSize();
		}
	});
}

function showFilial( linkId ) {
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/filials.do',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			//document.getElementById("content-container").innerHTML = msg;
			$(".filial-block").css("display", "none");
			$("#" + linkId + "-container").css("display", "block");
			setLightBoxSize();
		}
	});
	
	showShopLightBox();
}

function showFilialsInCheckout() {
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "action=ShowFilials&rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/order.do',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			setLightBoxSize();
		}
	});
	
	showShopLightBox();
}

function selectFilial (addressId, titleId, firstName, lastName, address1, postalCode, city, countryName, countryId) {
	
	document.getElementById("selectedFilialAddress").innerHTML = firstName + " " + lastName + "<br/>";
	document.getElementById("selectedFilialAddress").innerHTML += address1 + "<br/>";
	document.getElementById("selectedFilialAddress").innerHTML += postalCode + " " + city + "<br/>";
	document.getElementById("selectedFilialAddress").innerHTML += countryName + "<br/><br/>";
	
	document.getElementById("regFormFILIAL").addressId.value = addressId;
	document.getElementById("regFormFILIAL").titleId.value = titleId;
	document.getElementById("regFormFILIAL").firstName.value = firstName;
	document.getElementById("regFormFILIAL").lastName.value = lastName;
	document.getElementById("regFormFILIAL").address1.value = address1;
	document.getElementById("regFormFILIAL").postalCode.value = postalCode;
	document.getElementById("regFormFILIAL").city.value = city;
	document.getElementById("regFormFILIAL").countryId.value = countryId;
	
	jQuery("#chooseFilialLink").html("Filiale ändern");
	
	hidePanel();
	
}

function hideError() {
	$("#pd-size-error-container").hide();
	$("#pd-amount-error-container").hide();
	$("#pd-amount-error-container_pds").hide();
}

var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

function showNavigationIcon(divId) {
	
	if(document.getElementById(divId)) {
		if ((version < 7) && (document.body.filters)) {
			document.getElementById(divId).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'/images/catalog-res/nav/" + divId + ".png\', sizingMethod=\'crop\')";
		} else {
			document.getElementById(divId).style.background = "url(/images/catalog-res/nav/" + divId + ".png) no-repeat";
		}
	}
}

function showCategoryHeaderImage(imgName) {
	
	$("#catHeaderImage").attr("src", "/images/catalog-res/headers/" + imgName + ".jpg");
	
}

function clearForm(formId) {
	$( "#" + formId + " input").val("");
	$( "#" + formId + " select").val("");
}

function showCfgZoom(productId) {
	document.getElementById("cfg-image-big-" + productId).innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "action=ShowCfgProductZoom&productId=" + productId + "&rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/navigation.do',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			$("#cfg-image-big-" + productId).html(msg);
			$("#cfg-left-" + productId).css("z-index", "200");
			$("#cfg-image-big-" + productId).show();
		}
	});
}

$(function(){

	$(".cfg-image-big").click(function(){
		$(this).hide();
		$(".cfg-left").css("z-index", "");
	});
	
	$(".cfg-image-big").mouseout(function(){
		$(this).hide();
		$(".cfg-left").css("z-index", "");
	});

});

function calculateCfgTotal() {
	
	var totalPrice = 0;
	
	$( '.productPrice').each(function(){
		if( $("#amount_" + $(this).attr("id").substring(12)).val() > 0 ) {
			totalPrice += parseFloat($(this).attr("value"))*$("#amount_" + $(this).attr("id").substring(12)).val();
		}
	}); 

	$("#cfg-total-price").html(totalPrice.toFixed(2));

}

function loadCfgColorAlternative(productId, originalProductId, defaultAmount, count) {
	document.getElementById("cfg_" + originalProductId).innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/navigation.do?action=ShowCfgColorAlternative&defaultAmount=' + defaultAmount + '&count=' + count + '&productId=' + productId,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			$("#cfg_" + originalProductId).html(msg);
			$("#cfg_" + originalProductId).attr("id", "cfg_" + productId);
			
			calculateCfgTotal();

			$(".cfg-amount2").change(function(){
				$("#selected_" + $(this).attr("id").substring(7)).attr("checked", "checked");
				calculateCfgTotal();
			});

			$(".productSelected").change(function(){
				if( !$(this).is(':checked') ) {
					$("#amount_" + $(this).attr("id").substring(9)).val("0");
					calculateCfgTotal();
				}
				if( $(this).is(':checked') ) {
					$("#amount_" + $(this).attr("id").substring(9)).val($(this).val());
					calculateCfgTotal();
				}
			});

			$(".cfg-color2-active").mouseenter(function(){
				$(".cfg-clr-alternatives", this).css("display", "block");
			});
		
			$(".cfg-color2-active").mouseleave(function(){
				$(".cfg-clr-alternatives", this).css("display", "none");
			});

			$(".cfg-image-big").click(function(){
				$(this).hide();
				$(".cfg-left").css("z-index", "");
			});
			
			$(".cfg-image-big").mouseout(function(){
				$(this).hide();
				$(".cfg-left").css("z-index", "");
			});

		}
	});
}

function loadNewsletterLightbox() {
	$("#newsletter-subscription").show();
	$("#nl-scr-middle").html("<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>");
	ajaxParams = "rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/newsletter_lightbox.do?action=SubscrStart',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#nl-scr-middle").html(msg);
		}
	});
}

function submitNewsletterLightbox() {
	var ajaxParams = jQuery("#subscriptionFormLightbox").serialize() + "&rand=" + Math.floor(Math.random()*100000000);
	document.getElementById("nl-scr-middle").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	jQuery.ajax({
		type: "POST",
		url: '/app/newsletter_lightbox.do',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#nl-scr-middle").html(msg);
			$(".error-fs").css("width", "330px");
		}
	});
}

function loadNewsletterLightbox2() {
	$("#newsletter-subscription").show();
	$("#nl-scr-middle").html("<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>");
	ajaxParams = "rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: '/app/newsletter_lightbox_2.do?action=SubscrStart',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#nl-scr-middle").html(msg);
		}
	});
}

function submitNewsletterLightbox2() {
	var ajaxParams = jQuery("#subscriptionFormLightbox").serialize() + "&rand=" + Math.floor(Math.random()*100000000);
	document.getElementById("nl-scr-middle").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	jQuery.ajax({
		type: "POST",
		url: '/app/newsletter_lightbox_2.do',
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#nl-scr-middle").html(msg);
			$(".error-fs").css("width", "330px");
		}
	});
}

function startGiftVoucher(ajaxUrl) {
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	ajaxParams = "action=StartGiftVoucher&rand=" + Math.floor(Math.random()*100000000);
	jQuery.ajax({
		type: "POST",
		url: ajaxUrl,
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			setLightBoxSize();
			jQuery("img#checkGiftVoucher").click(function(){
				checkGiftVoucher();
			});
		}
	});
	
	showShopLightBox();
}

function checkGiftVoucher() {
	if( document.getElementById("voucherUsedValue")) {
		document.getElementById("voucherUsedValue").value = document.getElementById("voucherUsedValue").value.replace(",", ".");
	}
	var ajaxParams = jQuery("#formGiftVoucher").serialize() + "&rand=" + Math.floor(Math.random()*100000000);
	document.getElementById("content-container").innerHTML = "<div style=\"text-align: center;\"><br/><br/><br/><br/><img src=\"/images/common/loading.gif\" alt=\"\"/><br/><br/><br/><br/></div>";
	jQuery.ajax({
		type: "POST",
		url: "/app/order.do",
		data: ajaxParams,
		dataType: "html",
		success: function(msg){
			jQuery("div#content-container").html(msg);
			setLightBoxSize();
			jQuery("img#checkGiftVoucher").click(function(){
				checkGiftVoucher();
			});
			if( document.getElementById("voucherUsedValue") && document.getElementById("voucherUsedValue").value == 0 ) {
				document.getElementById("voucherUsedValue").value = "";
			}
		}
	});
}
