$(document).ready(function(){
	
	$(".topmenuLink").hover(function(){
		$(this).css("background", "url('/images/design/da/Header/topmenuActiveBg.png') bottom center repeat-x");
	},function(){
		if($(this).attr("class").indexOf("topmenuActive") == -1){
			$(this).css("background", "none");
		}
	});
	
	if(location.href.indexOf("news-ALL") != -1){
		$(".topmenuLink").each(function(){
			$(this).removeClass("topmenuActive");
		});
		$(".topmenuLink:eq(2)").addClass("topmenuActive")
	}
	
	if(location.href.indexOf("/shop/frontpage.html") != -1){
		$(".topmenuLink").each(function(){
			$(this).removeClass("topmenuActive");
		});
		$(".topmenuLink:eq(0)").addClass("topmenuActive")
	}
	
	if($(".Frontpage_Custom_TBL").length > 0){
		$(".Frontpage_Custom_TBL td[width='25%']").parent("tr").each(function(){
			$(this).find("td[width='25%']").each(function(index){
				$(this).attr("width", "125");
				$(this).attr("align", "left");
				if(index == 2){
					$(this).css("padding", "0px 14px 0px 0px");
				} else if(index == 3){
					$(this).css("padding", "0px 0px 0px 0px");
				} else {
					$(this).css("padding", "0px 13px 0px 0px");
				}	
			});
		});
		$(".fronpageProdsInfoBtn img").attr("src", "/images/design/da/buttons/infoBtn2.jpg")
	}
	
	if($(".Related_Custom_TBL").length > 0){
		$(".Related_Custom_TBL td[width='25%']").parent("tr").each(function(){
			$(this).find("td[width='25%']").each(function(index){
				$(this).attr("width", "125");
				$(this).attr("align", "left");
				if(index == 2){
					$(this).css("padding", "0px 14px 0px 0px");
				} else if(index == 3){
					$(this).css("padding", "0px 0px 0px 0px");
				} else {
					$(this).css("padding", "0px 13px 0px 0px");
				}	
			});
		});
		$(".fronpageProdsInfoBtn img").attr("src", "/images/design/da/buttons/infoBtn2.jpg")
	}
	
	if($("#frontpageChossenPRodsHeader").length > 0){
		if($("#frontpageChossenPRodsHeader").html().length < 3){
			$("#ProdCardProdBox").next().remove();
		}
	}
	
	
	if($(".Price_ProductInfo").length > 0){
		$(".Price_ProductInfo").removeAttr("width");
	}
	
	if($("#likeWrapper").length > 0){
		time = new Date();
		$("#likeWrapper").load("/includes/like.asp?relid="+escape(location.href)+"&_="+time.getTime(), function(){
			setTimeout("styleSharBtn()", "300");
		});
	}
	
	if($("#needHelpBox .boxContent").length > 0 && $.browser.msie){
		$("#needHelpBox .boxContent").css("height", "140px");
	}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
var ua = $.browser;
if ( ua.webkit != true ){
	if($(".beforePrice").length > 0){
		$(".discount").each(function(index){
			if($(this).text().length > 0){
				discount = parseFloat($(this).text().replace(".", "").replace(",", "."));
				retail =  parseFloat($(".beforePrice:eq("+index+")").text().replace(".", "").replace(",", "."));
				save = Math.round((discount/retail)*100);
				$(this).html("<span>"+save+" %</span>");
			} else {
				$(this).html("0 %");
			}
		});
	}
	
	if($(".Savingsprice").length > 0){
		$(".Savingsprice").each(function(index){
			if($(this).text().length > 0){
				discount = parseFloat($(this).text().replace(".", "").replace(",", "."));
				retail =  parseFloat($(".RetailSalesprice:eq("+index+")").text().replace(".", "").replace(",", "."));
				save = Math.round((discount/retail)*100);
				$(this).html("<span>"+save+" %</span>");
			} else {
				$(this).html("0 %");
			}
		});
	}
} else {
	if($("#ShopMainLayOutTable .beforePrice").length > 0){
		$("#ShopMainLayOutTable .discount").each(function(index){
			if($(this).text().length > 0){
				discount = $(this).text().replace(".", "").replace(",", ".").replace("DKK", "");
				discount = trim(discount);
				discount = discount.replace("DKK", "");
				discount = parseFloat(discount);
				retail = $(".beforePrice:eq("+index+")").text().replace(".", "").replace(",", ".").replace("DKK", "");
				retail = trim(retail);
				retail = retail.replace("DKK", "");
				retail = parseFloat(retail);

				save = Math.round((discount/retail)*100);
				$(this).html("<span>"+save+" %</span>");
			} else {
				$(this).html("0 %");
			}
		});
	}
	if($(".Savingsprice").length > 0){
		$(".Savingsprice").each(function(index){
			if($(this).text().length > 0){
				discount = parseFloat($(this).text().replace(".", "").replace(",", "."));
				retail =  parseFloat($(".RetailSalesprice:eq("+index+")").text().replace(".", "").replace(",", "."));
				save = Math.round((discount/retail)*100);
				$(this).html("<span>"+save+" %</span>");
			} else {
				$(this).html("0 %");
			}
		});
	}
}
	$(".relatedProdsPrice").each(function(){
	    key= $(this).text().replace(/\s+/g," ");
	
	    $(this).text(key);
	})
	
	if($(".currentPrice").length > 0){
		$("#ShopMainLayOutTable .currentPrice").each(function(index){
			if($(this).html().length > 1){
				html = $(this).html();
				$("#ShopMainLayOutTable .frontpageprodPrice:eq("+index+")").html("<strong>"+html+"</strong>");
			}
		});
	}
	
	if($(".GroupBox").length > 0){
		counter = 1;
		$("#ShopMainLayOutTable .GroupBox").each(function(){
			if(counter == 4){
				counter = 1;
			} else if(counter == 3) {
				counter++;
				$(this).css("margin", "0px 13px 0px 0px");
			} else {
				counter++;
				$(this).css("margin", "0px 13px 0px 0px");
			}
		});
	}
	
	if($(".SubMenu_Productmenu_Table").length > 0){
		$(".SubMenu_Productmenu_Table").parent().css("background", "none")
		$(".SubMenu_Productmenu_Table").parent().parent().prev().children(".RootCategory_Productmenu").css("border-bottom", "none");
		$(".SubMenu_Productmenu_Table").parent().parent().prev().children(".RootCategory_Productmenu").css("background", "url('/images/design/da/productMenu/ArrowActive.png') no-repeat 2px 8px ");
	}
	
	if($(".Prices_Custom_TBL td").length > 0){
		$(".Prices_Custom_TBL td").attr("align", "right")
	}
	
	if($(".ProductInfo_MagixZoomPlus_MainImage_TABLE").length > 0){
		$(".ProductInfo_MagixZoomPlus_MainImage_TABLE").attr("align", "center");
	}

});

function setTopmenu(index){
	$(".topmenuLink").each(function(){
		$(this).removeClass("topmenuActive");
	});
	$(".topmenuLink:eq("+index+")").addClass("topmenuActive")
}

function styleSharBtn(){
	if($(".FBConnectButton_Small .FBConnectButton_Text").length > 0){
		if($.browser.msie){
		$(".FBConnectButton_Small .FBConnectButton_Text").css({
			"margin-left" : "17px",
			"padding" : "0px 6px 5px 6px"
		})
		} else {
			$(".FBConnectButton_Small .FBConnectButton_Text").css({
				"margin-left" : "17px",
				"padding" : "3px 6px 2px 6px"
			})
		}
		$(".FBConnectButton_Text").text("Del");
		
	} else {
		setTimeout("styleSharBtn()", "150");
	}
}

function checkNewsletter(frm){
	if($("#newsletterMail").val() == "E-mail" || $("#newsletterMail").val() == ""){
		alert("udfyld venligst en gyldig e-mail")
		return false;
	} else {
		return true;
	}
}


