$(document).ready(function() {
/*********************************************
SET CONTENT TO PAGECOL HEIGHT
**********************************************/
$("#swLeftmenuDiv").height($(".swPageColMain").height());

/*********************************************
ADD CLASSES TO ELEMENTS WITH JQUERY SO THEY CAN
BE STYLED
**********************************************/
      
// add class to parent TR of auction form header
$(".auction-form-header").parent ().addClass("auction-form-header-tr"); 

// add class to TR parent which is TBODY
$(".auction-form-header-tr").parent ().addClass("auction-form-header-tbody");

// add class to TBODY parent which is the whole TABLE
$(".auction-form-header-tbody").parent ().addClass("auction-form-table");             


$("#ekspresLaanLink").append("(<a href=\"\" id=\"ekspresLaanLinkHref\">Ansøg her</a>)");
$("#ekspresLaanLinkHref").attr("href","https://online.handelsfinans.dk/dtansoeg/menu.asp?gsProdukt=HFA&gsNextObj=HFAnsoeg&ID=15379&T=E&Ident=TFLSBHUN&gsNextAkt=AnsoegMenu");
$("#ekspresLaanLinkHref").attr("target","_blank");
$("#swNavigation175019").attr('href','#');
/*********************************************
Create containers and load content with Ajax
**********************************************/
	$("#swPageDiv").append("<div id=\"BannerContainer\"></div>");
	
	$("#swPageDiv").append("<div id=\"BannerModuleContainer\"></div>");
	$("#banner_0_0").appendTo($("#BannerModuleContainer"));
	$("#banner_0_1").appendTo($("#BannerModuleContainer"));
	$("#banner_0_10").appendTo($("#BannerModuleContainer"));
	$("#banner_0_11").appendTo($("#BannerModuleContainer"));
	$("#banner_0_20").appendTo($("#BannerModuleContainer"));
	$("#banner_0_21").appendTo($("#BannerModuleContainer"));
	$("#banner_0_0").show();
	$("#banner_0_1").show();
	$("#banner_0_10").show();
	$("#banner_0_11").show();
	$("#banner_0_20").show();
	$("#banner_0_21").show();
	$.getScript('/sw/frontend/include/script/banner.js',function() {
		swBanner(1,8361,'BannerModuleContainer','swPageDiv'); //Trustpilot
	});
	
	// $("#BannerContainer").load("/sw/frontend/showslim-utf8.asp?parent=175067");
	
	// DeBusy Loan Start
	    $.getScript("/debusy/DebusyLoanCalculator.js", function() {
	      var loanCalculator = new DeBusyLoanCalculator();
	      loanCalculator.MonthDefault('24'); //Standard 
	      loanCalculator.Register(); 
	      loanCalculator.RegisterCart(); 
	    });
	// DeBusy Loan End

	// DeBusy Login Box
	if($("#debusyLoginBox").length>0)
	{
		var url = location.href.replace('//','////');
		if(url.indexOf('layout')<0)
		{
			if(url.indexOf('?')<0) {
				url+='?layout=0';
			}
			else {
				url+='&layout=0';
			}
		}
		url = url.replace('?layout=','?rnd=1&layout=');
		url+='&rnd=' + Math.random();
		$("#debusyLoginBox").load("/debusy/login.asp?404;"+url);
	}
	// DeBusy Login Box
	
	// GLS Pakke Shop START
	    $.getScript("/debusy/GLSPakkeShop.js", function() {
	      var pakkeShop = new GLSPakkeShop();
	      pakkeShop.LeveringId(58);
	      pakkeShop.Layout(0);
	      pakkeShop.Register();
	    });		
	// GLS Pakke Shop END
	
	  $('.commerce_show_attributegroup_div').each(function(){
	    if($(this).attr('id').indexOf('1165') > 0)
	    {
	      $(this).hide();
	    }
	  });
	});

$(document).ready(function(){
	$(".commerce-imgframe").parent().addClass("commerce-imgframe-container");
	$(".news-list-date").parent().addClass("news-list-date-container");
	var sSearch = $("#search").val();
	$("#search").click(function() { 
		if (sSearch == $("#search").val())
			$("#search").val('');
	});
	$("#search").blur(function() { 
		if ( "" == $("#search").val())
			$("#search").val(sSearch);
	});
	
	$("#search").parent().submit(function() {
		if($("#search").val().length == 2)
		{
			$("#search").val($("#search").val()+'%');
		}
		$("#search").val($("#search").val().replace(/[#+]/g,'%'));

	});
	
	$("input:text").each(function()  {
		if($(this).attr("name") == "search")
		{
			$(this).blur(function() {
				$(this).val($(this).val().replace(/[#+]/g,'%'));
			});
			
			$(this).keydown(function(evt) {
				if(evt.keyCode==13)
				{
					$(this).val($(this).val().replace(/[#+]/g,'%'));
				}
			});
		}
	});
	
	$(".swColumns .commerce").removeClass("commerce");
	
	if ((location.href.indexOf('checkout.asp') > 0 && (location.href.indexOf('step=1') > 0 || location.href.indexOf('step=2') > 0)) || (location.href.indexOf('parent=175216') > 0))
	{
		$('#username').attr('readonly',true);
		$('#tr_email').children(':last').children(':first').keyup(function() {
			$('#username').val($(this).val());
		});
		$('#tr_email').children(':last').children(':first').blur(function() {
			$('#username').val($(this).val());
		});
	}
	
	if(location.href.indexOf('show.asp') > 0 && (location.href.indexOf('parent=175216') > 0))
	{	
		if(document.getElementById('createuserElement')!=null)
		{
			document.getElementById('createuserElement').setAttribute('id','createuser');
		}

		$('#username').attr('readonly',true);
		$('#tr_email').children(':last').children(':first').keyup(function() {
			$('#username').val($(this).val());
		});
	}

});

function EncryptMail(name){
var domain = "debusy.dk";location.href="mai"+"lto"+":" + name + "@" + domain + "";
}

// Add tip friend button to shopping list
$(document).ready(function(){
	var sendTiplink = $("#swPageHeader img[@src='/sw/gfx/std_icon_sendtip.gif']").parent().attr("href");

	var sendTipContainer = $(".checkout-userinformation-box input[@name='doReordre']").parent();
	var sendTipHtml = "<input type='button' onclick='location.href=\""+ sendTiplink +"\"' value='Send indkøbsliste til en ven' />";
	sendTipContainer.prepend(sendTipHtml);

	if (location.href.indexOf('checkout.asp') > 0 && (location.href.indexOf('step=0') > 0 || location.href.indexOf('step') < 0)) {
		var sendTipContainer2 = $(".checkout-list .commerce-show-additem");
		var sendTipHtml2 = "» <a href=\""+sendTiplink+"\"> Send indkøbsliste til en ven </a>";
		sendTipContainer2.prepend(sendTipHtml2);
	}

});
