function showProduct() {
	if(!wBuchhandel)
		wBuchhandel = aBuchhandel;
	
	$.ajax({
		type: "POST",
		url: "fileadmin/scripts/php_classes/transaktion_misc.php",
		data: "wBuchhandel="+wBuchhandel+"&wBuchshop="+wBuchshop+"&wService="+wService+"&wUploadoption="+wUploadoption+"&wGutscheinCode="+wGutscheinCode+"&proj_pk="+proj_pk+"&objk_id="+objk_id+"&aProduktklasse="+aProduktklasse,
		success: function(data){
			if(data) {
				var tmp_data	= data.split(";");
				
				var title		= tmp_data[0];
				var currency	= tmp_data[1];
				var price		= tmp_data[2];
				var tax			= tmp_data[3];
				
				var tmp_price	= price.split(".");
				var euro		= tmp_price[0];
				var cent		= tmp_price[1];
				
				if(currency == "EUR") {
					currency = "&euro;";
				}
				
				if(lang == "en")
					cent = "&nbsp;";
				
				if(wGutscheinCode != "" && coupon_type == "tchibo") {
					$(".info .product").css("background-image", "url("+file_path+"images/bg_product_tchibo.jpg)");
					$(".info .tchibo_logo").fadeIn();
				}
				
				$(".info .product .right .title").html("BoD "+title);
				$(".info .product .price .euro").html(euro);
				$(".info .product .price .currency").html(currency);
				$(".info .product .price .syndetic .cent").html(cent);
				$(".info .product .price .syndetic .tax").html(tax);
				$(".info .product").fadeIn();
			}
		}
	});
}

function hideProduct() {
	$(".info .product").fadeOut();
}

var coupon_type;
function checkCoupon() {
	wGutscheinCode = $("#coupon_code").val();
	$.ajax({
		type: "POST",
		url: "fileadmin/scripts/php_classes/transaktion_misc.php",
		data: "MODE=wiz_checkcoupon&gutscheincode="+wGutscheinCode,
		success: function(data) {
			if(data != "[]") {
				data = data.replace(/\[(.*)\]/gi, '$1');
				eval('data='+data); //Parse JSON string to object
			}
			
			coupon_type = data.art;
			
			$(".wizzard .col4_big .next").css("background-image", "url("+file_path+"images/buttons/"+lang+"/next_big.gif)");
			
			if(data.art == "tchibo") { //Tchibo Gutschein
				wBuchhandel		= "";
				wBuchshop		= "";
				wService		= "";
				wUploadoption	= "";
				changeLanguage('de_tchibo');
				$(".info .coupon").fadeOut('normal', function() {
					$(".wizzard .col1").fadeOut('normal', function() {
						$(".info .product .wrapper .left").css("color", "#002148");
						$(".info .product .wrapper .right .title").css("color", "#002148");
						$(".info .product .wrapper .price .from").css("color", "#002148");
						$(".info .product .wrapper .price .currency").css("color", "#002148");
						$(".info .product .wrapper .price .euro").css("color", "#002148");
						$(".info .product .wrapper .price .syndetic .cent").css("color", "#002148");
						$(".info .product .wrapper .price .syndetic .tax").css("color", "#002148");
						$(".wizzard .col4_big .row1").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col4_row1.gif)");
						//$(".wizzard .col4_big .row1").show();
						$(".wizzard .col4_big .row1").hide();
						$(".wizzard .col4_big .row2").css({
							'background' : 'url('+file_path+'images/buttons/'+lang+'/col4_row2.gif)',
							'margin-left' : '200px'
						});
						$(".wizzard .col4_big .row2").show();
						$(".wizzard .col4_big .row3").css({
							'background' : 'url('+file_path+'images/buttons/'+lang+'/col4_row3.gif)',
							'margin-left' : '90px'
						});
						$(".wizzard .col4_big .row3").show();
						$(".wizzard .col4_big .help").show();
						$(".wizzard .col4_big").fadeIn();
						showProduct();
					});
				});
			} else if(data.art == "tchibo2") { //Tchibo2 Gutschein
				wBuchhandel		= "";
				wBuchshop		= "";
				wService		= "";
				wUploadoption	= "fotobook";
				
				window.location.href = "index.php?id=mybod_easybook_"+lang+"&proj_pk="+proj_pk+"&objk_id="+objk_id+"&wBuchhandel="+wBuchhandel+"&wBuchshop="+wBuchshop+"&wService="+wService+"&wUploadoption="+wUploadoption+"&wGutscheinCode="+wGutscheinCode+"&wCouponType=tchibo2&aProduktklasse=CLASSIC";
			} else if(data.art == "tchibo3") { //Tchibo3 Gutschein
				wBuchhandel		= "";
				wBuchshop		= "";
				wService		= "";
				wUploadoption	= "";
				aProduktklasse	= "CLASSIC";
				$(".info .coupon").fadeOut();
				$(".wizzard .col1").fadeOut('normal', function() {
					$(".wizzard .col4_big .row1").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col4_row1.gif)");
					$(".wizzard .col4_big .row1").show();
					$(".wizzard .col4_big .row2").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col4_row2.gif)");
					$(".wizzard .col4_big .row2").show();
					$(".wizzard .col4_big .row3").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col4_row3.gif)");
					$(".wizzard .col4_big .row3").show();
					$(".wizzard .col4_big").fadeIn();
				});
			} else if(data.art == "bookrix" || data.art == "gutschein-classic" || data.art == "marketing") { //bookrix Gutschein
				wBuchhandel		= "Y";
				wBuchshop		= "Y";
				wService		= "N";
				wUploadoption	= "";
				$(".info .coupon").fadeOut();
				$(".wizzard .col1").fadeOut('normal', function() {
					$(".wizzard .col4_big .row1").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col4_row1.gif)");
					$(".wizzard .col4_big .row1").show();
					$(".wizzard .col4_big .row2").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col4_row2.gif)");
					$(".wizzard .col4_big .row2").show();
					$(".wizzard .col4_big .row3").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col4_row3.gif)");
					$(".wizzard .col4_big .row3").show();
					$(".wizzard .col4_big").fadeIn();
				});
			} else if(data.art == "amazon" || data.art == "standard") { //Amazon Gutschein
				$(".info .coupon").fadeOut();
			} else if(!data) { //Aktion wenn kein Gutschein eingegeben wurde
				wGutscheinCode = "";
			} else { //Aktion wenn Gutschein ungültig
				if(data == "gutschein_not_valid") {
					showError(coupon_error1);
				} else if(data == "gutschein_in_use") {
					showError(coupon_error2);
				} else if(data == "gutschein_storno") {
					showError(coupon_error3);
				}
				wGutscheinCode = "";
			}
		}
	});
}

function changeLanguage(new_lang) {
	lang = new_lang;

	$(".wizzard .col1 .row1").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col1_row1.gif)");
	$(".wizzard .col1 .row2").css("background-image", "url("+file_path+"images/buttons/"+lang+"/col1_row2.gif)");
	$(".wizzard .col2 .back, .wizzard .col3 .back, .wizzard .col4 .back").css("background-image", "url("+file_path+"images/buttons/"+lang+"/back.gif)");
	$(".wizzard .col4 .next").css("background-image", "url("+file_path+"images/buttons/"+lang+"/next.gif)");
}

function flashButton(obj) {
	var speed = 600;
	$(obj).fadeTo(speed, 0.7, function() {
		$(obj).fadeTo(speed, 1, function() {
			if(!wBuchhandel)
				flashButton(obj);
		});
	});
}

/** DEBUG **/
$(document).click(function() {
	if(debug) {
		console.log("#### DEBUG START ####");
		console.log("var proj_pk: "+proj_pk);
		console.log("var objk_id: "+objk_id);
		console.log("var wService: "+wService);
		console.log("var wBuchhandel: "+wBuchhandel);
		console.log("var wBuchshop: "+wBuchshop);
		console.log("var wUploadoption: "+wUploadoption);
		console.log("var wGutscheinCode: "+wGutscheinCode);
		console.log("#### DEBUG END ####");
	}
});
