SearchText1 = 'Desværre ingen produkter at vise for denne søgning';
SearchText2 = 'Desværre ingen produkter i kategorien: <b>[[cn.CATEGORYNAME]]</b><p><a href="/shop/search-1.html?keyword=[[cn.CATEGORYNAME]]">Klik her for at prøve søge efter produkter</a></p>';

domReady(function(){


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	if (location.href.indexOf('p.html') != -1){
		$('.FaceBookTD').html('<iframe src="//www.facebook.com/plugins/like.php?href='+ $('link[rel=canonical]').attr('href') +'&amp;send=false&amp;layout=standard&amp;width=347&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:347px; height:35px;" allowTransparency="true"></iframe>')
//		$('.FaceBookTD').html('<iframe src="//www.facebook.com/plugins/like.php?send=false&amp;layout=standard&amp;width=347&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font=arial&amp;height=35&amp;href='+ $('link[rel=canonical]').attr('href') +'?utm_source=Facebook&utm_medium=Like&utm_campaign='+ ProductNumber +'" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:347px; height:35px;" allowTransparency="true"></iframe>')
	}
	
	
	
	
	
	var FreeShippingOnline = true
	if(parseInt(FreeShipping)==0){
		FreeShippingOnline = false
	}
	
	// Retter pris i vareliste
	$('#ShopMainLayOutTable .Prod').each(function(){
		$(this).html($(this).html().replace('</strike>8<strike></strike>8<strike>','88'))
		$(this).html($(this).html().replace('</STRIKE>8<STRIKE></STRIKE>8<STRIKE>','88'))
		$(this).html($(this).html().replace('</strike>8<strike>','8'))
		$(this).html($(this).html().replace('</STRIKE>8<STRIKE>','8'))
		$(this).html($(this).html().replace('</strike>&nbsp;</strike>','</strike>'))
		$(this).html($(this).html().replace('</STRIKE>&nbsp;</STRIKE>','</strike>'))
		$(this).html($(this).html().replace('</strike>8<strike>','8'))
		$(this).html($(this).html().replace('</STRIKE>8<STRIKE>','8'))
		
		
		if ($(this).find('.cell2 strike').text().length != 0){
			$(this).find('.cell2').css('color','#bd2228');

			if(parseInt($(this).find('.cell2:first').text().replace($(this).find('.cell2:first strike').text(),'').replace('.','').replace(',','.')) >= FreeShipping && FreeShippingOnline){
				$(this).before('<div align="left" class="labelFreeShipping"><img src="/images/template/label-free-shipping.png"></div>');	
			}

			if(parseInt($(this).find('.cell2:first').text().replace($(this).find('.cell2:first strike').text(),'').replace('.','').replace(',','.')) >= LimitForUnit){
				$(this).find('.Prices_Custom_TBL .cell1').html('');
			}
			
			if($(this).find('.ProductImage label img').length == 0){
				$(this).parent().find('.label:eq(0)').html('<img border="0" src="/images/template/label-tilbud.png">');
			}
			
			var strikecontent = parseFloat($(this).find('.cell2:last strike').text().replace('.','').replace(',','.'));
			var notstikecontent = parseFloat($(this).find('.cell2:last').text().replace($(this).find('.cell2:last strike').text(),'').replace('.','').replace(',','.'));
			var StrProcent = parseInt(100-((notstikecontent*100)/strikecontent));
			$(this).parent().find('.label').eq(0).before('<span class="labelprocent">'+ StrProcent +'%</span>');
		}else{
			if(parseInt($(this).find('.cell2:first').text().replace('.','').replace(',','.')) >= FreeShipping && FreeShippingOnline){
				$(this).before('<div align="left" class="labelFreeShipping"><img src="/images/template/label-free-shipping.png"></div>');	
			}
			if(parseInt($(this).find('.cell2:first').text().replace('.','').replace(',','.')) >= LimitForUnit){
				$(this).find('.Prices_Custom_TBL .cell1').html('');
			}
		};
	});

	if (location.href.indexOf('p.html') != -1){

		
		
		if ($('.Prices_Custom_TBL TR strike').text().length != 0){
			$('.Prices_Custom_TBL TR').css('color','#bd2228');
			var strikecontent = parseFloat($('.Prices_Custom_TBL TR:last strike').text().replace('.','').replace(',','.'));
			var notstikecontent = parseFloat($('.Prices_Custom_TBL TR:last .PriceCurrency').text().replace(' DKK','').replace('.','').replace(',','.'));
//			var StrProcent = parseInt(((strikecontent-notstikecontent)/strikecontent)*100);
			var StrProcent = parseInt(100-((notstikecontent*100)/strikecontent));
			$('.ProdInfoSpecielOfferImage').prepend('<span class="ProdLabelProcent">'+ StrProcent +'%</span>');
			
			if(parseInt($('.Prices_Custom_TBL TR:first .PriceCurrency').text().replace('.','').replace(',','.')) >= FreeShipping && FreeShippingOnline){
				$('.HeadTBL .cell1').prepend('<div align="left" class="labelFreeShippingProdInfo"><img src="/images/template/label-free-shipping.png"></div>');	
			}
			
		}else{
			if(parseInt($('.Prices_Custom_TBL tr:first .PriceCurrency').text().replace('.','').replace(',','.')) >= FreeShipping && FreeShippingOnline){
				$('.HeadTBL .cell1').prepend('<div align="left" class="labelFreeShippingProdInfo"><img src="/images/template/label-free-shipping.png"></div>');	
			}
		}
		
	}
	
	// Opretter subcats
	$('.SubCats_Prodlink').next('br').remove();
	
	if (location.href.indexOf('shop/showbasket.html') != -1)	{$('#ShowBasket_TD').prepend('<h1>'+ $('#ShowBasket_TD h1').text() +'</h1>');$('#ShowBasket_TD h1').eq(1).remove();}
	if (location.href.indexOf('shop/order1.html') != -1)		{$('#OrderStep1_TD').prepend('<h1>'+ $('#OrderStep1_TD h1').text() +'</h1>');$('.Heading_Orderstep1_TBL').remove();}
	if (location.href.indexOf('shop/order2.html') != -1)		{$('#OrderStep2_TD').prepend('<h1>'+ $('#OrderStep2_TD h1').text() +'</h1>');$('#OrderStep2_TD .BackgroundColor1_Orderstep2 tr').eq(0).remove();$('#OrderStep2_TD .BackgroundColor1_Orderstep2 tr').eq(0).find('td').html('<br>');}
	if (location.href.indexOf('shop/order3.html') != -1)		{$('#OrderStep3_TD').prepend('<h1>'+ $('#OrderStep3_TD h1').text() +'</h1>');$('#OrderStep3_TD .Heading_OrderStep3').remove();$('#OrderStep3_TD .CustomerInfo_OrderStep3 td').eq(0).find('br:lt(1)').remove();}
	if (location.href.indexOf('shop/order4.html') != -1)		{$('#OrderStep4_TD').prepend('<h1>'+ $('#OrderStep4_TD h1').text() +'</h1>');$('#OrderStep4_TD .BackGroundColor1_OrderStep4 tr').eq(0).remove();}
	
	if (location.href.indexOf('shop/order3.html') != -1){
		// Tildele table's ID'er i steps
		var i = 1;
		$('.CustomerInfo_OrderStep3 table').each(
			function() {
				$(this).attr('id', 'CustomerInfo_OrderStep3_Table'+i++)
			}
		)
		$('input[name=submitorder]').click(function(){return $('#acceptTermsBit').is(':checked');})
		
		$('.BackGroundColor1_OrderStep3 table table table td a').removeAttr('href')
		
		$('.CustomerInfo_OrderStep3 br').hide();
		$('.CustomerInfo_OrderStep3 table br').show();

	}

	// Skjul variantstreg hvis ingen variant er der...
	if ($('#ShopMainLayOutTable .Variants').length == 0){
		$('.VariantsLine').css('display', 'none');
	}

});

function TipProdLink(){window.location.href = "/shop/tip.html?productid="+ ProductNumber +"&VariantIdSelected=0";}






$(document).ready(function(){
	
	
	
	
	$("#ShopMainLayOutTable .Prod").hover( 
	  function () { 
		$(this).css('background-image','url(/images/template/background-prod-hover1.png)');
	  },  
	  function () { 
		$(this).css('background-image','url(/images/template/background-prod.png)');
	  } 
	); 


	$("#logoerTBL img").hover( 
	  function () { 
		$(this).attr('src',$(this).attr('src').replace('.png','-hover.png'))
	  },  
	  function () { 
		$(this).attr('src',$(this).attr('src').replace('-hover.png','.png'))
	  } 
	); 

	
	
	$('.descTD table a').each(function(){
		if($('.descTD .'+ $(this).attr('show')).text().length==0){
			$('.descTD .'+ $(this).attr('show')).remove();
			$(this).remove();
		}
	});

	$('.descTD table a').click(function() {
		$('.descTD table a').each(function(){
			$('.descTD .'+ $(this).attr('show')).hide();
			$(this).css('background','none')
		});
		$('.descTD .'+ $(this).attr('show')).css('display','block');
		$(this).css('background-color','#FFFFFF')
	});
	
	if ($('#navs a').length != 0){
		$('.XTopNav, .XBottomNav').html('Gå til: <a href="'+ $('.Paging_Pages a:first').attr('href').replace('%20','').replace('%20','') +'">Første side</a> | <a href="'+ $('.Paging_Pages a:last').attr('href') +'">Sidste side</a>');
	}

	$('.Prod, .prod').click(function() {
		location.href = $(this).find('a').eq(0).attr('href')
	});

	// Ved fejlside (tom vareliste)
	if ($('#ProductList_TD .Prod').length == 0 && $('#ProductList_TD').text().length <= 175 && $('#ProductList_TD form').length == 0 && $('#ProductList_TD').text().indexOf('SubCats_Prodlink')!=-1){
		if	(location.href.indexOf('search-1.html') != -1){					
			$('#ProductList_TD').html('<h1>Søgning: '+ Keyword +'</h1><div class="PriductListBackground" style="padding-top:40px;padding-bottom:30px;text-align:center;width:536px;">'+ SearchText1 +'</div>')
		}else{
			$('#ProductList_TD').html('<h1>[[cn.CATEGORYNAME]]</h1><div class="PriductListBackground" style="padding-top:40px;padding-bottom:30px;text-align:center;width:536px;">'+ SearchText2 +'</div>')
		}
	}
	
	// Ved fejlside skriver den Kategorinavn i stedet for [[CATEGORYNAME]] (tom vareliste)
	if (document.getElementById('ProductList_TD') != null){
		if ($('#ProductList_TD').html().indexOf('[[cn.CATEGORYNAME]]') != -1){
			
			if (Keyword != ''){$('.EmtyList a').css('display', 'none');}
			
			$('#ProductList_TD *').each(function(){
				if ($('#ProductList_TD').html().indexOf('[[cn.CATEGORYNAME]]') != -1){
					findreplace('#ProductList_TD','[[cn.CATEGORYNAME]]',$('.Activ_Productmenu').text());
				}
			})
		}
	}

	for (i=1; i<256; i++){
		var re = new RegExp('&#(' + i + ');', 'g');
		Keyword = Keyword.replace(re, String.fromCharCode(i))
	}
	
	// Sætter overskrifter
	$('#TipFriend_TD').html('<h1>Anbefal</h1>'+$('#TipFriend_TD').html());
	if (location.href.indexOf('news-ALL-1.html') != -1){$('#ProductList_TD').prepend('<h1>Nyheder</h1>');}
	if (location.href.indexOf('specialoffer-ALL-1.html') != -1){$('#ProductList_TD').prepend('<h1>Tilbud</h1>');}
	if (Keyword  != ''){$('#ProductList_TD h1').text('Søgning: '+Keyword);}
	
	// Hvis søgestring ikke er tom gemmer den, den i en cookie
	if (Keyword != ''){setCookie('seekform',Keyword,365);};
	
	SearchValue = "Hvad leder du efter?";
	$('#ShopMainLayOutTable form input.SearchField_SearchPage').val(SearchValue).click(function(){if($(this).attr('value') == SearchValue){$(this).val('')}}).blur(function(){if($(this).attr('value') == ''){$(this).val(SearchValue)}})

	// Hvis Formen bliver sendt tom sendes brugern til forsiden
	if (CurrencyReturnUrl == '/shop/search-1.html?keyword=' || Keyword==SearchValue || Keyword==' '){$('#ProductList_TD table').remove();old_alert('Du skal udfylde et søgeord');setCookie('seekform','',-1);location.href = '/';};
	
	// Sætter string ind i formen på siden
	if (getCookie('seekform') != ''){$('#ShopMainLayOutTable form input.SearchField_SearchPage').attr('value', getCookie('seekform'));};
	
	NewsletterValue = "Indtast din e-mail";
	$('.newsletter input.email').val(NewsletterValue).click(function(){if($(this).attr('value') == NewsletterValue){$(this).val('')}}).blur(function(){if($(this).attr('value') == ''){$(this).val(NewsletterValue)}})
});



function findreplace(el, find, rep)		{try{$(el).html($(el).html().replace(find, rep))}catch(e){};}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
	{
	c_start=c_start + c_name.length+1;
	c_end=document.cookie.indexOf(";",c_start);
	if (c_end==-1) c_end=document.cookie.length;
	return unescape(document.cookie.substring(c_start,c_end));
	}
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

