var weekendDelivery, today;
$(document).ready(function(){
	$('#ShopMainLayOutTable .productGroupsLinks a').each(function(){
		$(this).append('<img src="/images/design/da/productGroups/arrow.jpg" class="ppImg" border="0">');
	})
})

var salesDiscount = new Array("41RjeFtf01", "8x2bhfUR58", "NXtx9d3u31", "7aoPn2Gh00", "0c0gQBts35", "v3eQyDf611", "j3w7n0E0wS", "PqgElf4752", "vN34gVlq38", "TsV91pst68");
var shareDiscount  = false;

var isVariant = false;
function cal5_printSelection() {
    var sel = Calendar.selection.print("%Y-%m-%d", " ... ");
    if (sel.length == 0)
        sel = "No date selected";
    else
        sel = sel.join("\n");
    alert(sel);
};

$(function(){
	
	if($("#ShopMainLayOutTable .manufacturer a").length > 0){
		titleContent = $("#ShopMainLayOutTable .manufacturer a").attr("title")
		if(titleContent.indexOf("img") != -1){
			$("#ShopMainLayOutTable .manufacturer a").html($("#ShopMainLayOutTable .manufacturer a").attr("title"));
		}
	}
	if($("#information .Description_Productinfo").length > 0){
		if($("#information .Description_Productinfo").html().length < 1){
			$("#productTabs ul li:eq(1)").remove();
		}
	}
	
	$(".ProductInfo_MagixZoomPlus_MainImage_TABLE").attr("align", "center");

	$("#ShopLayOut_Topmenu_TD a").each(function(){
		if($(this).attr("id") != "noStyle"){
			$(this).wrap('<div class="topmenuLinks"></div>');
		}
	});
	$(".topmenuLinks:first").before('<div style="float:left;margin-top:10px;"><img src="/images/design/da/topmenu/leftBg.png"></div>');
	$(".topmenuLinks:last").after('<div style="float:left;margin-top:10px;"><img src="/images/design/da/topmenu/rightBg.png"></div>');
	$(".topmenuLinks:last").css("border-right", "none");
	$(".topmenuLinks:last").css("padding", "0px 15px 0px 20px");
	$(".topmenuLinks:first").css("padding", "0px 20px 0px 15px");
	
	if(location.href.indexOf("showbasket") == -1 && location.href.indexOf("order") == -1 && location.href.indexOf("pay.dandomain") == -1){
		$("#ShopMainLayOutTable #ContentContainer_DIV").before('<div id="searchBox"><form style="margin:0;" action="/shop/search-1.html" method="POST"><input type="hidden" value="1" name="InitSearch"><input type="text" id="serchfield" value="Søg produkter" onclick="if(this.value==\'Søg produkter\')this.value=\'\'" onblur="if(this.value==\'\')this.value=\'Søg produkter\'" maxlength="50" name="Keyword"> <input type="image" src="/images/design/da/searchBtn.jpg" id="searchBtn"></form></div>');
	}
	
	$(".Activ_Productmenu").parent().css("background", "url('/images/design/da/productMenu/level1BgActive.jpg') no-repeat 0px 0px");
	$(".SubMenu_Productmenu_Table").parent().parent().remove();
	
	//$(".RootCategory_Productmenu:last").parent().after('<tr><td class="RootCategory_Productmenu" style="background: url(&quot;/images/design/da/productMenu/level1BgActive.jpg&quot;) no-repeat scroll 0pt 0pt transparent;"><a href="/shop/vi-anbefaler-2782c1.html"><img src="/images/design/da/productMenu/showAllProds.jpg"></a><br></td></tr>');
	$(".RootCategory_Productmenu:last").css("padding", "0px");

	if($("#Field7_0 .TextInputField_Orderstep1").length > 0){
		$("#Field7_0 .TextInputField_Orderstep1").attr("id", "calenderInput");
		//$("#Field8_0 .TextInputField_Orderstep1").attr('disabled', true);
		$("#Field7_0 .TextInputField_Orderstep1").before('<div style="position:absolute;"><input type="hidden" id="calenderInputHidden"><input id="calendar-trigger" type="image" src="/images/design/da/ordersteps/calenderIcon.jpg" ></div>');
		//$("#Field8_0 .TextInputField_Orderstep1").before('<div style="position:absolute;"><div id="calendar-trigger"></div></div>');
		$("#calendar-trigger").click(function(event){
			event.preventDefault();
		});
		if(readCookie("weekendDelivery") == "true"){
			weekendDelivery = true;
		} else {
			weekendDelivery = false;
		}
		today = new Date();
		Calendar.setup({
			align 	   : "bR",
   	    	//cont    : "calendar-trigger",
			trigger    : "calendar-trigger",
  	    	inputField : "calenderInputHidden",
			onSelect   : function() { 
				this.hide(); 
				tmp = $("#calenderInputHidden").val().split("-");
				$("#calenderInput").val(tmp[2]+"-"+tmp[1]+"-"+tmp[0])
			},
			onBlur 	   : function(){return false},
		    disabled: function(date) {
				
				if(weekendDelivery){
					if(date < today){
						return true;
			    	} else {
			    		if(today.getDay() == 5 && today.getHours() >= 12 && date.getDay() == 6 && date.getDate()-1 == today.getDate() || today.getDay() == 5 && today.getHours() >= 12 && date.getDay() == 0 && date.getDate()-2 == today.getDate() ){
							return true;
						} else {
				    		return false;
						}
					}
				} else {
					if (date < today || date.getDay() == 0 || date.getDay() == 6) {
						return true;
			    	} else {
			    		return false;
					}
				}				
			}
    	});
		Calendar.setup({
			align 	   : "bR",
   	    	//cont    : "calendar-trigger",
			trigger    : "calenderInput",
  	    	inputField : "calenderInputHidden",
			onSelect   : function() { 
				this.hide(); 
				tmp = $("#calenderInputHidden").val().split("-");
				$("#calenderInput").val(tmp[2]+"-"+tmp[1]+"-"+tmp[0])
			},
			onBlur 	   : function(){return false},
			disabled: function(date) {
				
				if(weekendDelivery){
					if (date < today) {
						return true;
			    	} else {
						if(today.getDay() == 5 && today.getHours() >= 12 && date.getDay() == 6 && date.getDate()-1 == today.getDate() || today.getDay() == 5 && today.getHours() >= 12 && date.getDay() == 0 && date.getDate()-2 == today.getDate() ){
							return true;
						} else {
				    		return false;
						}
					}
				} else {
					if (date < today || date.getDay() == 0 || date.getDay() == 6) {
						return true;
			    	} else {
			    		return false;
					}
				}				
			}
    	});
	}
	$("input[name='useMailList']").parent().css("padding", "10px 0px 0px 0px");
	$(".RootCategory_Productmenu").hover(function(){
		$(this).css("background", "url('/images/design/da/productMenu/level1BgActive.jpg') no-repeat scroll 0 0 transparent");
	}, function(){
		$(this).css("background", "url('/images/design/da/productMenu/level1Bg.jpg') no-repeat scroll 0 0 transparent");
	});
	
	if(location.hash == "#loginOK"){
		$("#calenderInput").val("");
	}
	
	
	if($("#ShopMainLayOutTable #prodConfig  .OptionSelect_ProductInfo").length > 0){
		AjaxEncoding.init("/includes/");
		$("#ShopMainLayOutTable #prodConfig .OptionSelect_ProductInfo").each(function(){
			price = $(this).find("option:last").text().split("(")[1].split(")")[0];
			price = parseFloat($("#BaseProdPrice").val().replace(",", "."));
			if(price == 0){
				$("#Price_DIV").html('<table cellspacing="0" cellpadding="2" border="0" width="100%"><tbody><tr class="Price_ProductInfo_TR"><td width="0" class="PriceText_ProductInfo_TD"><span class="PriceText_ProductInfo_SPAN"><nobr>Din Pris</nobr> </span></td><td align="right" width="0" class="PriceAmount_ProductInfo_TD"><span class="PriceAmount_ProductInfo_SPAN"><nobr>1</nobr></span></td><td align="right" width="0" class="PriceUnit_ProductInfo_TD"><span class="PriceUnit_ProductInfo_SPAN"><nobr></nobr></span></td><td width="0" class="PriceBefore_ProductInfo_TD"> </td><td width="100%" class="Price_ProductInfo"><b><span class="Price_Productinfo">Ring for pris</span></b></td></tr><tr class="PriceDevider_ProductInfo_TR"><td colspan="5"><hr size="1" noshade="" class="TableLines_ProductInfo"></td></tr></tbody></table>');
				$(".UnitPriceBox:last").find("td:first").html('Din pris');
				$(".UnitPriceBox:last").find("td:last").html('<span class="Price_Productinfo">'+number_format(price, 2, ",", ".")+' DKK</span>')
				retailPrice = parseFloat($(".RetailPrice_Productinfo:last").text().replace(".", ""));
				saving = retailPrice-price;
				//alert(retailPrice+"-"+price)
			} else {
				$("#Price_DIV").html('<table cellspacing="0" cellpadding="2" border="0" width="100%"><tbody><tr class="Price_ProductInfo_TR"><td width="0" class="PriceText_ProductInfo_TD"><span class="PriceText_ProductInfo_SPAN"><nobr>Din Pris</nobr> </span></td><td align="right" width="0" class="PriceAmount_ProductInfo_TD"><span class="PriceAmount_ProductInfo_SPAN"><nobr>1</nobr></span></td><td align="right" width="0" class="PriceUnit_ProductInfo_TD"><span class="PriceUnit_ProductInfo_SPAN"><nobr></nobr></span></td><td width="0" class="PriceBefore_ProductInfo_TD"> </td><td width="100%" class="Price_ProductInfo"><b><span class="Price_Productinfo">'+number_format(price, 2, ",", ".")+' DKK</span></b></td></tr><tr class="PriceDevider_ProductInfo_TR"><td colspan="5"><hr size="1" noshade="" class="TableLines_ProductInfo"></td></tr></tbody></table>');
				$(".UnitPriceBox:last").find("td:first").html('Din pris');
				$(".UnitPriceBox:last").find("td:last").html('<span class="Price_Productinfo">'+number_format(price, 2, ",", ".")+' DKK</span>');
				retailPrice = parseFloat($(".RetailPrice_Productinfo:last").text().replace(".", ""));
				saving = retailPrice-price;
				//alert(retailPrice+"-"+price)
				$(".SavingsPriceBox").each(function(){
					$(this).find(".SavingsPrice_Productinfo:first").html('Spar');
					$(this).find(".SavingsPrice_Productinfo:last").html('<span class="Price_Productinfo">'+number_format(saving, 2, ",", ".")+'&nbsp;DKK</span>');
				});
			}
		});
		if($("#ShopMainLayOutTable #prodConfig .OptionSelect_ProductInfo").length > 0){
			var index = 0;
			
			$("body").append('<div id="loader" onclick="$(this).toggle();" style="left:0px;top:0px;border:2px solid #666666;width:250px;background:#FFFFFF;padding:10px;position:absolute;color:#000000;font-size:12px;">testetest</div>');
			var html = '<table cellspacing="0" cellpadding="0" border="0" width="100%"></tr><tr><td style="text-align:center;padding:0px 0px 10px 0px;"></td></tr><tr><td id="prodconfiguration"></td></tr></tbody></table>';
			$("#ShopMainLayOutTable .mBuyB").html('<input type="image" src="/includes/newBuyBtn.png" id="newBuyBtn"/>');
//					var BASket = $("#ShopMainLayOutTable #ShopLayOut_Basket_TD").html();
//					$("#ShopMainLayOutTable #ShopLayOut_SpaceTop_TD").append('<div style="float:left;_float:none;width:135px;height:97px;_display: inline;">'+BASket+'</div>');
				$("#ShopMainLayOutTable #ShopLayOut_SpaceTop_TD>table:eq(0)").attr("style","float:left;_float:none;_display:inline");
				$("#ShopMainLayOutTable #basket").parent().removeAttr("style");
				//$("#ShopMainLayOutTable #prodconfiguration>table>tbody>tr>td").css('background','/includes/prodCard/prodConfBack.png');
		}
		$("#costumProdConfig").append(html);
		$("#ShopMainLayOutTable #prodConfig .OptionSelect_ProductInfo").each(function(){
			$(this).parent().next().next().find("img").attr("src", "/includes/newInfo.png");
			$(this).parent().next().next().find("img").css("vertical-align", "middle");
			infobtn = '<img border="0" src="/includes/newInfo.png" style="vertical-align: middle;cursor:pointer;" id="infoBtn_'+index+'" class="infoBtn" onclick="getProductInfo('+index+')">'
			prodName = $(this).parent().parent().prev().find("td:first").text();
			price = $(this).find("option:last").text().split("(")[1].split(")")[0];
				$("#prodconfiguration").append('<table cellspacing="0" cellpadding="0" border="0" style=";width:100%;"><tr><td class="pCback" style="width:20px;padding:0px 5px;"><input type="checkbox" style="" value="'+$(this).find("option:last").attr("value")+'" class="prodconfigOption" index="'+index+'" id="prodconfigOption_'+index+'"></td><td class="pCback" style="width:220px;padding:0px 5px;"><b>'+prodName+'</b></td><td class="pCback" style="text-align:right;padding:0px 5px;">'+price+' DKK '+infobtn+'</td></tr></table>');
			//$("#prodconfiguration").append('<div style="overflow:hidden;height:50px;"><div style="float:left;height:25px;margin-right:2px;"></div><div style="float:left;height:50px;"></div><div style="float:right;height:50px;font-size:11px;"></div></div>')
			index++;
		});
		$(".prodconfigOption").click(function(){
			var checkMe = $(this).parent().next().text();
			if(checkMe == "Afhentning"){
				$("#prodconfiguration > table").each(function(){
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Weekendlevering"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Bortskaffelse"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Ø-levering"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
				});
			}
			if(checkMe == "Bortskaffelse"){
				$("#prodconfiguration > table").each(function(){
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Opbæring montering og bortskaffelse af gammel produkt"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							//$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							amountInput = $("#ShopMainLayOutTable .TextInputField_ProductInfo:eq("+id+")")
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Ø-levering"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							//$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							amountInput = $("#ShopMainLayOutTable .TextInputField_ProductInfo:eq("+id+")")
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Afhentning"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							//$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							amountInput = $("#ShopMainLayOutTable .TextInputField_ProductInfo:eq("+id+")")
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
				});
			}
			if(checkMe == "Opbæring montering og bortskaffelse af gammel produkt"){
				$("#prodconfiguration > table").each(function(){
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Bortskaffelse"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							//$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							amountInput = $("#ShopMainLayOutTable .TextInputField_ProductInfo:eq("+id+")")
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
				});
			}
			if(checkMe == "Weekendlevering"){
				$("#prodconfiguration > table").each(function(){
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Afhentning"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							//$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							amountInput = $("#ShopMainLayOutTable .TextInputField_ProductInfo:eq("+id+")")
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
				});
			}
			if(checkMe == "Ø-levering"){
				$("#prodconfiguration > table").each(function(){
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Afhentning"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							//$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
					
					if($(this).find("tbody:first > tr > td:eq(1)").text() == "Bortskaffelse"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							//$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
							var change = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("id");
							id = $(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").attr("index");
							$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
							if($selectBox.find("option:selected").val() == "0"){
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:last").attr("selected", "true");
							} else {
								$selectBox.find("option").removeAttr("selected");
								$selectBox.find("option:first").attr("selected", "true");
								$("#"+change).attr("checked",false);
							}
							count = parseFloat(id)+1;
							pcComboSelected(count);
						}
					}
				});
			}
			var g1 = new Array("Afhentning","Opbæring","Opbæring og montering","Opbæring og bortskaffelse af gammel produkt","Opbæring montering og bortskaffelse af gammel produkt", "Ø-levering");
			var g2 = new Array("4 års fuld forsikring");
			var g1 = new Array("Kantstens Levering","Afhentning","Opbæring","Opbæring og montering","Opbæring og bortskaffelse af gammel produkt","Opbæring montering og bortskaffelse af gammel produkt", "Ø-levering");

			id = $(this).attr("index");
			$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
			if($selectBox.find("option:selected").val() == "0"){
				$selectBox.find("option").removeAttr("selected");
				$selectBox.find("option:last").attr("selected", "true");
			} else {
				$selectBox.find("option").removeAttr("selected");
				$selectBox.find("option:first").attr("selected", "true");
			}
			count = parseFloat(id)+1
			pcComboSelected(count);
			for (var i = 1;i < 3;i++){
				var gToCheck = eval("g"+i);
				if (jQuery.inArray(checkMe,gToCheck) !== -1 ){
					var vPos = jQuery.inArray(checkMe,gToCheck);
					gToCheck[vPos] = " ";
					break;
				}
			}

			$(".prodconfigOption:checked").each(function(){
				if (jQuery.inArray($(this).parent().next().text(),gToCheck) >= 0){
					vPos = jQuery.inArray(checkMe,gToCheck);
					var change = $(this).attr("id");
					if ($(this).attr("id") == false){
						change = $(this).attr("Xid");
					}
					id = $(this).attr("index");
					$selectBox = $("#ShopMainLayOutTable .OptionSelect_ProductInfo:eq("+id+")");
					if($selectBox.find("option:selected").val() == "0"){
						$selectBox.find("option").removeAttr("selected");
						$selectBox.find("option:last").attr("selected", "true");
					} else {
						$selectBox.find("option").removeAttr("selected");
						$selectBox.find("option:first").attr("selected", "true");
						$("#"+change).attr("checked",false);
						var rPos = jQuery.inArray($(this).parent().next().text(),gToCheck);
						gToCheck[rPos] = " ";
					}
					count = parseFloat(id)+1;
					pcComboSelected(count);
					//return(false);
				}
			});
		});
			
		$("#loader").css({
			"display" : "none"
		});
	
		$("#newBuyBtn").click(function(event){
			event.preventDefault();
			$("#prodconfiguration > table").each(function(){
				if($(this).find("tbody:first > tr > td:eq(1)").text() == "Weekendlevering"){
					if(readCookie("weekendDelivery") != "true"){
						if($(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").is(":checked")){
							createCookie("weekendDelivery", "true", "0.2");
						} else {
							createCookie("weekendDelivery", "false", "0.2");
						}
					}
				}
			});
			
			$("#prodConfig #Total").prev().prev().click();
		});
		$("#prodconfiguration > table").each(function(){
			if($(this).find("tbody:first > tr > td:eq(1)").text() == "Kantstens Levering"){
				$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
			}
			if($(this).find("tbody:first > tr > td:eq(1)").text() == "Weekendlevering"){
				if(readCookie("weekendDelivery") == "true"){
					$(this).find("tbody:first > tr > td:eq(0) > .prodconfigOption").click();
				}
			}
		});
	};

	var name = "masterURL";
	var value = readCookie(name);
	var days = 1;
	
	// is it a product configurator?
/*		console.log("avNumVariants: "+window.avNumVariants);
		console.log("0-cookieVal:"+readCookie(name));*/
	if (window.avNumVariants !== undefined){
		if(avNumVariants != null ){
			//this is not advanced
			isVariant = false;
			value = "a";
/*												console.log("1-isVar?:"+isVariant);
												console.log("1-cVal:"+value);*/
			if(avNumVariants > 0){
				//this is an advanced variant
				isVariant = false;
				value = window.location.href;
/*												console.log('-- This is the master --');
												console.log("1.1-isVar?:"+isVariant);
												console.log("1.1-cVal:"+value);*/
			}
			createCookie(name,value,days);
		}
	} else {
		if(value != "a" && value != null){
			isVariant = true;
/*												console.log('-- This is a variant --');
												console.log("2-isVar?:"+isVariant);
												console.log("2-cVal:"+value);*/
		} else {
			//prod konfig
			value = "a";
			isVariant = false;
			createCookie(name,value,days);
/*												console.log("3-isVar?:"+isVariant);
												console.log("3-cVal:"+value);*/
		}
	}
/*												console.log("--------------------------------------------");
												console.log("isVar?:"+isVariant);
												console.log("cVal:"+value);
												console.log("avNumVariants: "+window.avNumVariants);
												console.log("2-cookieVal:"+readCookie(name));*/
												
	if (isVariant == true && readCookie(name) != "a"){
		$("#prCardVariantsHolder").css("display","block");
		$("#prCardVariantsHolder").css({"text-align" : "center", "margin" : "0px 10px 10px 10px"});
		$("#prCardVariantsHolder").html('<a id="nyVar" href="'+value+'"><img src="/images/design/da/chooseVariant.png" border="0" /></a>');
		value = "a";
		createCookie(name,value,days);
	} else if ( value == window.location.href ) {
		var name = "masterURL";
		var value = window.location.href;
		var days = 1;
		createCookie(name,value,days);
	}
		
	if($("#rabatSteps").length > 0){
		var prods = parseFloat($("#basketTotalProds").text());
		if(prods == 0){
			$("#rabatSteps").hide();
		}
	}
	if($(".module").length > 0){
		var prods = parseFloat($("#basketTotalProds").text());
		if(prods == 0){
			$(".module").hide();
		}
	}
	subProdCounter = 0;
	
	$("#ShopMainLayOutTable .ShowBasket_ChildProduct_SPAN").each(function(){

		var $this = $(this);
		var prodName = $this.text();
		var prodPrice = $this.parents(".showbasketProdukt").next().text();
		var prodTotalPrice = $this.parents(".showbasketProdukt").next().next().text();
		var prodAmount = $this.parents(".showbasketProdukt").next().next().next().text();
		//$this.parent().text("<b>+"+prodName+"</b>");
		if($this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".ShowBasket_ChildProduct_SPAN").length < 1){
			var parentProd = $this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".showbasketProdukt").find("td:last").html();
			var parentPrice = $this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".showbasketPrice").html();
			var parentTotalPrice = $this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".showbasketTotalPrice").html();
			var parentAmount = $this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".showbasketAmount").html();
			
			$this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".showbasketProdukt").find("td:last").html(parentProd+"<br><br><b>+ "+prodName+"</b>");
			$this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".showbasketPrice").html(parentPrice+"<br><br>"+prodPrice);
			$this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".showbasketTotalPrice").html(parentTotalPrice+"<br><br>"+prodTotalPrice);
			$this.parents(".BackgroundColor1_ShowBasket").parent().prev().find(".showbasketAmount").html(parentAmount+"<br><br>"+prodAmount);
		}
		if($this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".ShowBasket_ChildProduct_SPAN").length < 1){
			var parentProd = $this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".showbasketProdukt").find("td:last").html();
			var parentPrice = $this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".showbasketPrice").html();
			var parentTotalPrice = $this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".showbasketTotalPrice").html();
			var parentAmount = $this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".showbasketAmount").html();
			
			$this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".showbasketProdukt").find("td:last").html(parentProd+"<br><br><b>+ "+prodName+"</b>");
			$this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".showbasketPrice").html(parentPrice+"<br><br>"+prodPrice);
			$this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".showbasketTotalPrice").html(parentTotalPrice+"<br><br>"+prodTotalPrice);
			$this.parents(".BackgroundColor2_ShowBasket").parent().prev().find(".showbasketAmount").html(parentAmount+"<br><br>"+prodAmount);
		}
		
		
		$this.parents(".BackgroundColor2_ShowBasket").parent().remove();
		$this.parents(".BackgroundColor1_ShowBasket").parent().remove();
		
	});
	
	$(".cheaperPopUp").click(function(event) {
		event.preventDefault();
		url = window.location.pathname;
		url = url.substr(url.lastIndexOf("/")+1);
		url = url.substring(0,url.lastIndexOf("."));
		href = "/shop/cms-match-pris.html?hideinterface=1&URL="+url;
		//console.log(href);
		$.ajax({
			url: href,
			success: function(response){
				var $html = $(response);
				$("#ShopMainLayOutTable").before('<div id="overlay"></div>');
				var $overlay = $("#overlay");
				$overlay.css({
					"height" : $(document).height()+"px"
				})
				$overlay.append('<div id="popup"></div>');
				//alert($(window).height());
				var top = ($(window).height()-500)/2;
				var left = ($(window).width()-480)/2;
				var $popup = $("#popup");
				$popup.css({
					"left" : left+"px",
					"top" : top+"px"
				});
				$popup.html($html.find("#popupContent"));
				var ProdURl = location.href;
				$("#ProdUrl").val(ProdURl);
				$("#closeBtn").click(function(){
					$("#overlay").remove();
				});

			}
		});
		return false;
	});
	
	if(shareDiscount){
		$("#shareDiscountTxt").show();
	}
	
	if($("#basket #basketTotalProds").text() == "0"){
		eraseCookie("weekendDelivery");
	}
	
	$(".Description_Productinfo iframe").each(function(){
		if($(this).attr("src").indexOf("youtube") != -1){
			$(this).wrap("<div class='youtubeVideo' style='position:Relative;'></div>");
			$(this).attr("width", "250px");
			$(this).attr("height", "182px");
		}
	});
	$(".youtubeVideo").append('<div style="width:250px;height:182px;position:absolute;z-index:9990;top:0;left:0px;background:url(\'/includes/transparentBtn.png\');cursor:pointer" class="playVideo"></div>');
	
	$(".playVideo").each(function(){
		$(this).click(function(){
			var videoURL = $(this).parent().find("iframe").attr("src");
			playVideo(videoURL);
		});
	});
	$("#popupLinkKnowBeforeBuy").click(function(event){
		event.preventDefault();
		linkDialouge('/shop/cms-Info.html?hideinterface=1');
		return false;
	});
});

function linkDialouge(URL){
	$overlay = $('<div id="videoOverlay"></div>');
	$overlay.css("height", $(document).height());
	$overlay.hide();
	$videoContainer = $('<div id="pageContainer"></div>');
	$videoContainer.css("left", ($(document).width()-660)/2);
	$videoContainer.css("top", 100);
	$("body").append($overlay);
	$("body").append($videoContainer);
	menuYloc = parseInt($videoContainer.css("top").substring(0,$videoContainer.css("top").indexOf("px"))) ;
	var offset = menuYloc+$(document).scrollTop()+100+"px";  
	$videoContainer.animate({top:offset},{duration:500,queue:false});  
	$(window).scroll(function () {  
		var offset = menuYloc+$(document).scrollTop()+100+"px";  
		$videoContainer.animate({top:offset},{duration:500,queue:false});  
	}); 
	
	if($.browser.msie){
		$overlay.fadeTo(10, 0.50);
		$overlay.show();
		$.ajax({
			url: URL,
			success: function(response){
				$videoContainer.append($(response).find("#pageText").html());
				$("#closeBtn").click(function(){
					if($.browser.msie){
						$("#pageContainer, #videoOverlay").remove();
					} else {
						$("#pageContainer, #videoOverlay").fadeOut("slow", function(){
							$("#pageContainer, #videoOverlay").remove();
						});
					}
				});
			}
		});
	} else {
		$overlay.fadeTo("slow", 0.50, function(){
			$.ajax({
				url: URL,
				success: function(response){
						
					$videoContainer.append($(response).find("#pageText").html());
					$("#closeBtn").click(function(){
						if($.browser.msie){
							$("#pageContainer, #videoOverlay").remove();
						} else {
							$("#pageContainer, #videoOverlay").fadeOut("slow", function(){
								$("#pageContainer, #videoOverlay").remove();
							});
						}
					});
				}
			});
			
		});
	}
	$overlay.click(function(){
		if($.browser.msie){
			$("#pageContainer, #videoOverlay").remove();
		} else {
			$("#pageContainer, #videoOverlay").fadeOut("slow", function(){
				$("#pageContainer, #videoOverlay").remove();
			});
		}
	});
	
	$(window).resize(function(){
		left = ($(window).width()-660)/2;
		topPos = ($(window).height()-225)/2;
		$("#pageContainer").css({"left" : left});
		$("#videoOverlay").css({"height" : $(document).height(), "width" : $(window).width()})
		//menuYloc = parseInt($("#videContainer").css("top").substring(0,$("#videContainer").css("top").indexOf("px"))) ;
		//var offset = menuYloc+$(document).scrollTop()+100+"px";  
	    //$("#videContainer").animate({top:offset},{duration:500,queue:false});  
	});
	
}

function playVideo(videoURL){
	$overlay = $('<div id="videoOverlay"></div>');
	$overlay.css("height", $(document).height());
	$overlay.hide();
	$videoContainer = $('<div id="videContainer"></div>');
	$videoContainer.css("left", ($(document).width()-660)/2);
	$videoContainer.css("top", 100);
	$("body").append($overlay);
	$("body").append($videoContainer);
	menuYloc = parseInt($videoContainer.css("top").substring(0,$videoContainer.css("top").indexOf("px"))) ;
	var offset = menuYloc+$(document).scrollTop()+100+"px";  
	$videoContainer.animate({top:offset},{duration:500,queue:false});  
	$(window).scroll(function () {  
		var offset = menuYloc+$(document).scrollTop()+100+"px";  
		$videoContainer.animate({top:offset},{duration:500,queue:false});  
	}); 
	
	if($.browser.msie){
		$overlay.fadeTo(10, 0.50);
		$overlay.show();
		$.ajax({
			url: "/includes/video.asp?url="+videoURL,
			success: function(response){
				$videoContainer.append(response);
				$("#closeBtn").click(function(){
					if($.browser.msie){
						$("#videContainer, #videoOverlay").remove();
					} else {
						$("#videContainer, #videoOverlay").fadeOut("slow", function(){
							$("#videContainer, #videoOverlay").remove();
						});
					}
				});
			}
		});
	} else {
		$overlay.fadeTo("slow", 0.50, function(){
			$.ajax({
				url: "/includes/video.asp?url="+videoURL,
				success: function(response){
					$videoContainer.append(response);
					$("#closeBtn").click(function(){
						if($.browser.msie){
							$("#videContainer, #videoOverlay").remove();
						} else {
							$("#videContainer, #videoOverlay").fadeOut("slow", function(){
								$("#videContainer, #videoOverlay").remove();
							});
						}
					});
				}
			});
			
		});
	}
	$overlay.click(function(){
		if($.browser.msie){
			$("#videContainer, #videoOverlay").remove();
		} else {
			$("#videContainer, #videoOverlay").fadeOut("slow", function(){
				$("#videContainer, #videoOverlay").remove();
			});
		}
	});
	
	$(window).resize(function(){
		left = ($(window).width()-660)/2;
		topPos = ($(window).height()-225)/2;
		$("#videContainer").css({"left" : left});
		$("#videoOverlay").css({"height" : $(document).height(), "width" : $(window).width()})
		//menuYloc = parseInt($("#videContainer").css("top").substring(0,$("#videContainer").css("top").indexOf("px"))) ;
		//var offset = menuYloc+$(document).scrollTop()+100+"px";  
	    //$("#videContainer").animate({top:offset},{duration:500,queue:false});  
	});
}





function CheckForm(){
	$frm = $("#MatchPrice")
	var Valid  = true;
	if($frm.find("#myOffer").val() == ""){
		Valid = false;
		var fill = "Dit prisbud";
	}
	if($frm.find("#Mail").val() == ""){
		Valid = false;
		var fill = "email";
	}
	if(Valid == true){
		var dataString = 'ProdUrl='+ $("#ProdUrl").val() + '&Price=' + $("#Price").val() + '&Link=' + $("#Link").val() + '&Comment=' + $("#Comment").val() + '&Name=' + $("#Name").val() + '&Mail=' + $("#Mail").val() + '&myOffer=' + $("#myOffer").val() + '&Phone=' + $("#Phone").val(); 
		$.ajax({
			url: "/includes/sendMatchPris.asp",
			type: "POST",
			data: dataString,
			success: function(response){
				var $popup = $("#popup");
				$popup.html('<div id="popupContent"><div id="popupHeader"><div style="float: right"><img style="cursor: pointer" id="closeBtn" border="0" alt="" src="/includes/close.png" /></div>Match prisen</div><div id="popupDescription" style="height:430px;padding-top:20px;"><strong>Tak for din forespørgsel.</strong><br>Vi vil besvare dig hurtigst muligt.</div></div>');
				$("#closeBtn").click(function(){
					$("#overlay").remove();
				});
				return false;
			}
		});
	} else {
		alert('udfyld venligst: '+fill);
		return false;
	}
}
/*
$(window).resize(function(){
	top = ($(window).height()-500)/2
	left = ($(window).width()-480)/2
	var $popup = $("#popup");
	$popup.css({
		"left" : left+"px",
		"top" : top+"px"
	});
});
*/
// manage cookie

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else {
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function number_format (number, decimals, dec_point, thousands_sep) { 
	var n = number, prec = decimals; 
	var toFixedFix = function (n,prec) { 
    	var k = Math.pow(10,prec); 
    	return (Math.round(n*k)/k).toString(); 
	}; 
 
	n = !isFinite(+n) ? 0 : +n; 
	prec = !isFinite(+prec) ? 0 : Math.abs(prec); 
	var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep; 
	var dec = (typeof dec_point === 'undefined') ? '.' : dec_point; 
 
	var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0; 
 
	var abs = toFixedFix(Math.abs(n), prec); 
	var _, i; 
 
	if (abs >= 1000) { 
   		_ = abs.split(/\D/); 
    	i = _[0].length % 3 || 3; 
 
    	_[0] = s.slice(0,i + (n < 0)) + 
        _[0].slice(i).replace(/(\d{3})/g, sep+'$1'); 
    	s = _.join(dec); 
	} else { 
    	s = s.replace('.', dec); 
	} 
 
	var decPos = s.indexOf(dec); 
	if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) { 
   		s += new Array(prec-(s.length-decPos-1)).join(0)+'0'; 
	} 
	else if (prec >= 1 && decPos === -1) { 
   		s += dec+new Array(prec).join(0)+'0'; 
	} 
	return s;
} 
var oldBut;

function getProductInfo(input){
	xid = $("#prodconfigOption_"+input).val();
	xid = replace(escape(xid),"+","%2B");
	var position = $("#infoBtn_"+input).position();
	
	if (xid != 0){
		var side = "/shop/productinfo.asp?PrintThisSite=1&id="+xid;
		//alert(side)
		$("#loader").html('<center><img src="/includes/89.gif"></center>');
		$("#loader").css({
			"left" : position.left-250,
			"top" : position.top+16
		});
		if ($("#loader").css("display") != "block" || oldBut == input){
			$("#loader").toggle();
		}
		AjaxEncoding.load({
			url: side,
			success: function(xmlStr) {
				var $html = $(xmlStr);
				$("#loader").html($html.find(".Description_Productinfo"));
			}
		});
		oldBut = input;
	}
}

function hideMe(){
	$("#loader").css({
		"display" : "none"
	});
}

function sharePage(){
	FB.ui({
		method: 'feed',
		name: $(".productHeader .name").text(),
		link: location.href,
		description: $("#description .Description_Productinfo").find("i:first").next().next().next().text()
	},
	function(response) {
		
		if (response && response.post_id) {
			if(shareDiscount == true){
				if(readCookie("salesDiscount") == null || readCookie("salesDiscount") == ""){
					newValue = 1;
					createCookie("salesDiscount", newValue, 1);
					if($.browser.msie){
						location.href = "/includes/redirect.asp?location="+escape(location.href.split(".html")[0]+".html?SalesDiscountCode="+salesDiscount[0]);
					} else {
						location.href = location.href.split(".html")[0]+".html?SalesDiscountCode="+salesDiscount[0];
					}
					
				} else {
					salesCode = parseFloat(readCookie("salesDiscount"));
					newValue = salesCode+1;
					createCookie("salesDiscount", newValue, 1);
					if($.browser.msie){
						location.href = "/includes/redirect.asp?location="+escape(location.href.split(".html")[0]+".html?SalesDiscountCode="+salesDiscount[salesCode]);
					} else {
						location.href = location.href.split(".html")[0]+".html?SalesDiscountCode="+salesDiscount[salesCode];
					}
				}
			}
		} else {
			//alert('Post was not published.');
		}
	});
}
	
	
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(1*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function danishCharacters(txt){
	txt = txt.replace(/Ãƒâ€¦/g,"&Aring;");
	txt = txt.replace(/Ãƒâ€ /g,"&AElig;");
	txt = txt.replace(/ÃƒËœ/g,"&Oslash;");
	txt = txt.replace(/ÃƒÂ¥/g,"&aring;");
	txt = txt.replace(/ÃƒÂ¦/g,"&aelig;");
	txt = txt.replace(/ÃƒÂ¸/g,"&oslash;");
	return txt;
}

var timer = new Date();

function loadComments() {
	
	if($(".prNumb").length > 0){
		ProductNumber = $(".prNumb");
		ProductNumber = ProductNumber.find("SPAN");
		ProductNumber = ProductNumber.html();
		if (ProductNumber.indexOf("-") > -1 ) {
			ProductNumber = ProductNumber.substring(0,ProductNumber.indexOf("-"));
		}
	}
	
	var $commentsWrapper = $("#commentsWrapper");
	/*if ($commentsWrapper.length <= 0) {
		var $commentsWrapper = $("<div id='commentsWrapper' />");
		var $mainForm = $(".ProductInfo_TD").find("form[name=myform]");
		$mainForm.after($commentsWrapper);
	}*/ 
	
	var $loadingImg = $("<br />&nbsp;<p style='text-align:center;'><img src='/utils/images/ajax-load-large.gif' alt='Loading' /></p>");
	$commentsWrapper.html($loadingImg);
	
	$commentsWrapper.load("/utils/comments.asp?relid="+ProductNumber+"&_="+ timer.getTime(), function (){
		$(".star",$commentsWrapper).rating();
		$commentsWrapper.parent().css("display", "block");
	});
}



